combat: rewrite in Zig; add basic damage types and weapon archetypes

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ic8055a1cf6bdad1aca13673ea171b4b46a6a6964
This commit is contained in:
raf 2026-04-05 20:11:06 +03:00
commit 22ab6fc6eb
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
15 changed files with 802 additions and 158 deletions

View file

@ -3,6 +3,7 @@
#include "common.h"
#include "items.h"
#include "map.h"
#include "settings.h"
#include "utils.h"
#include <stdlib.h>
#include <string.h>
@ -18,6 +19,8 @@ void player_init(Player *p, int x, int y) {
p->step_count = 0;
p->speed = 100;
p->cooldown = 0;
p->dodge = PLAYER_BASE_DODGE;
p->block = PLAYER_BASE_BLOCK;
p->has_weapon = 0;
p->has_armor = 0;
memset(&p->equipped_weapon, 0, sizeof(Item));
@ -25,8 +28,8 @@ void player_init(Player *p, int x, int y) {
p->equipped_weapon.picked_up = 1;
p->equipped_armor.picked_up = 1; // mark as invalid
p->inventory_count = 0;
p->dmg_variance_min = 80;
p->dmg_variance_max = 120;
p->effect_count = 0;
memset(p->effects, 0, sizeof(p->effects));
// Initialize inventory to empty
for (int i = 0; i < MAX_INVENTORY; i++) {
@ -70,7 +73,11 @@ int player_move(Player *p, int dx, int dy, Map *map, Enemy *enemies, int enemy_c
p->x = new_x;
p->y = new_y;
p->step_count += 1;
if (p->step_count % 15 == 0 && p->hp < p->max_hp) {
// Regen suppressed while poisoned, bleeding, or burning
if (p->step_count % REGEN_STEP_INTERVAL == 0 && p->hp < p->max_hp &&
!combat_has_effect(p->effects, p->effect_count, EFFECT_POISON) &&
!combat_has_effect(p->effects, p->effect_count, EFFECT_BLEED) &&
!combat_has_effect(p->effects, p->effect_count, EFFECT_BURN)) {
p->hp += 1;
}
return 1;
@ -188,16 +195,6 @@ int player_equip_item(Player *p, int inv_index) {
p->equipped_weapon = *item;
p->has_weapon = 1;
p->attack += item->power;
// Adjust damage variance based on weapon power
// Higher power = wider range (more swingy but higher potential)
int min_var = 100 - (item->power * 3);
int max_var = 100 + (item->power * 5);
if (min_var < 60)
min_var = 60;
if (max_var > 150)
max_var = 150;
p->dmg_variance_min = min_var;
p->dmg_variance_max = max_var;
// Remove from inventory
player_remove_inventory_item(p, inv_index);
return 1;
@ -207,11 +204,15 @@ int player_equip_item(Player *p, int inv_index) {
// Unequip current armor first
if (p->has_armor) {
p->defense -= p->equipped_armor.power;
p->block -= p->equipped_armor.power / 2;
if (p->block < PLAYER_BASE_BLOCK)
p->block = PLAYER_BASE_BLOCK;
}
// Equip new armor
p->equipped_armor = *item;
p->has_armor = 1;
p->defense += item->power;
p->block += item->power / 2; // armor grants block bonus
// Remove from inventory
player_remove_inventory_item(p, inv_index);
return 1;