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

death.c (582B)


      1 #include <stdbool.h>
      2 #include <stdio.h>
      3 #include "stb_ds.h"
      4 #include "core/ecs/entity.h"
      5 #include "systems/actions.h"
      6 #include "core/world.h"
      7 
      8 bool death_run(World *w) {
      9     //printf("death_run world %p\n", (void *)w);
     10     for (int i=0;i<arrlen(w->entities);++i) {
     11         Component *c = Entity_Find_Component(&w->entities[i], COMPONENT_HEALTH);
     12         if (c==NULL) continue;
     13         if (c->health.hp<=0) {
     14             printf("[%d] UNIT_DIED unitId=%d\n", w->turn, w->entities[i].id);
     15             arrdel(w->entities, i);
     16             i--; // wtf
     17         }
     18     }
     19     return false;
     20 }