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

actions.c (750B)


      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 actions_run(World *w) {
      9     //printf("actions_run world %p\n", (void *)w);
     10     bool ret = false;
     11     if (arrlen(w->entities)<=1) return ret; // finish condition = 1 or no units left alive.
     12     for (int i=0;i<arrlen(w->entities);++i) {
     13         Component *c = Entity_Find_Component(&w->entities[i], COMPONENT_ACTIONS);
     14         if (c==NULL) continue;
     15         for (int j=0;j<arrlen(c->actions.items);++j) {
     16             if (c->actions.items[j].run(&w->entities[i], w)) {
     17                 //puts("action ok");
     18                 ret = true;
     19                 break;
     20             }
     21         }
     22     }
     23     return ret;
     24 }