sw-battle-test-c

Interesting test task in C instead of C++
git clone git://bsandro.tech/sw-battle-test-c
Log | Files | Refs | README

commit 93cd8e56f562a79df4eb478c3dcb87ed92796f5e
parent 529ba76fc59fbfcc018e8983943901d2b123b990
Author: bsandro <email@bsandro.tech>
Date:   Wed, 30 Sep 2026 02:25:42 +0300

sync distance function with Vadim's implementation

Diffstat:
Mactions/attack_ranged.c | 5+++--
Mcommands/CREATE_MAP.c | 2+-
2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/actions/attack_ranged.c b/actions/attack_ranged.c @@ -1,6 +1,7 @@ #include <stdlib.h> #include <stdbool.h> #include <stdio.h> +#include "sys/param.h" #include "stb_ds.h" #include "actions/attack_ranged.h" #include "components/ranged.h" @@ -15,8 +16,8 @@ bool Action_Attack_Ranged(Entity *e, World *w) { for (int i=0;i<arrlen(w->entities);++i) { if (w->entities[i].id==e->id) continue; Position pe = Entity_Find_Component(&w->entities[i], COMPONENT_POSITION)->position; - // taxicab distance to keep it simple for now - int dist = abs(pe.x-p.x) + abs(pe.y-p.y); + // used to be taxicab distance to keep it simple for now + int dist = MAX(abs(pe.x-p.x), abs(pe.y-p.y)); if (dist>=2&&dist<=r.range) { //printf("found enemy for ranged attack %d\n", w->entities[i].id); Entity_Find_Component(&w->entities[i], COMPONENT_HEALTH)->health.hp -= r.agility; diff --git a/commands/CREATE_MAP.c b/commands/CREATE_MAP.c @@ -3,7 +3,7 @@ static void create_map(World *w, int width, int height) { //printf("create_map(%p,%d,%d)\n", (void *)w, width, height); Map_Init(&w->map, width, height); - printf("CREATE_MAP width=%d height=%d\n", width, height); + printf("MAP_CREATED width=%d height=%d\n", width, height); } bool cmd_create_map(World *w, int argc, char **argv) {