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 "map.h"
#include "rng.h"
#include <string.h>
// Forward declaration
int is_enemy_at(const Enemy *enemies, int count, int x, int y);
@ -39,10 +40,12 @@ void enemy_spawn(Enemy enemies[], int *count, Map *map, Player *p, int floor) {
// Create enemy
Enemy e;
memset(&e, 0, sizeof(Enemy));
e.x = ex;
e.y = ey;
e.alive = 1;
e.type = rng_int(ENEMY_GOBLIN, max_type);
e.effect_count = 0;
// Stats based on type and floor
switch (e.type) {
@ -51,24 +54,56 @@ void enemy_spawn(Enemy enemies[], int *count, Map *map, Player *p, int floor) {
e.hp = e.max_hp;
e.attack = ENEMY_BASE_ATTACK;
e.speed = 55 + rng_int(0, 10);
e.dodge = 15;
e.block = 0;
e.dmg_class = DMG_POISON;
e.status_chance = 15;
e.resistance[DMG_SLASH] = 0;
e.resistance[DMG_IMPACT] = 0;
e.resistance[DMG_PIERCE] = 0;
e.resistance[DMG_FIRE] = -25;
e.resistance[DMG_POISON] = 50;
break;
case ENEMY_SKELETON:
e.max_hp = ENEMY_BASE_HP + floor + 2;
e.hp = e.max_hp;
e.attack = ENEMY_BASE_ATTACK + 1;
e.speed = 70 + rng_int(0, 10);
e.dodge = 5;
e.block = 0;
e.dmg_class = DMG_SLASH;
e.status_chance = 10;
e.resistance[DMG_SLASH] = -25;
e.resistance[DMG_IMPACT] = -50;
e.resistance[DMG_PIERCE] = 50;
e.resistance[DMG_FIRE] = 25;
e.resistance[DMG_POISON] = 100;
break;
case ENEMY_ORC:
e.max_hp = ENEMY_BASE_HP + floor + 4;
e.hp = e.max_hp;
e.attack = ENEMY_BASE_ATTACK + 2;
e.speed = 85 + rng_int(0, 10);
e.dodge = 0;
e.block = 3;
e.dmg_class = DMG_IMPACT;
e.status_chance = 20;
e.resistance[DMG_SLASH] = 0;
e.resistance[DMG_IMPACT] = 25;
e.resistance[DMG_PIERCE] = -25;
e.resistance[DMG_FIRE] = 0;
e.resistance[DMG_POISON] = 0;
break;
default:
e.max_hp = ENEMY_BASE_HP;
e.hp = e.max_hp;
e.attack = ENEMY_BASE_ATTACK;
e.speed = 60;
e.dodge = 0;
e.block = 0;
e.dmg_class = DMG_IMPACT;
e.status_chance = 0;
memset(e.resistance, 0, sizeof(e.resistance));
break;
}
e.cooldown = e.speed;
@ -137,6 +172,10 @@ void enemy_act(Enemy *e, Player *p, Map *map, Enemy *all_enemies, int enemy_coun
if (!e->alive)
return;
// Stunned enemies skip their action
if (combat_has_effect(e->effects, e->effect_count, EFFECT_STUN))
return;
// Check if adjacent to player - attack
if (can_see_player(e, p)) {
combat_enemy_attack(e, p);