45 lines
1.2 KiB
C
45 lines
1.2 KiB
C
#include "systems.h"
|
|
|
|
#include "game_state.h"
|
|
|
|
#include "unit_ai.h"
|
|
#include "unit_actions.h"
|
|
|
|
void handleUnitActionsSystem(ecs_iter_t *it) {
|
|
Game *game = ecs_singleton_get_mut(ECS, Game);
|
|
UnitAction *action = ecs_field(it, UnitAction, 1);
|
|
|
|
for (i32 i = 0; i < it->count; i++) {
|
|
ecs_entity_t entity = it->entities[i];
|
|
handleAction(entity, &action[i], game);
|
|
}
|
|
}
|
|
|
|
void updateUnitAISystem(ecs_iter_t *it) {
|
|
Game *game = ecs_singleton_get_mut(ECS, Game);
|
|
UnitAI *unitAI = ecs_field(it, UnitAI, 1);
|
|
UnitAction *action = ecs_field(it, UnitAction, 2);
|
|
|
|
for (i32 i = 0; i < it->count; i++) {
|
|
ecs_entity_t entity = it->entities[i];
|
|
|
|
Action *firstAction = action[i].first;
|
|
if (firstAction)
|
|
unitAI[i].action = firstAction;
|
|
else
|
|
unitAI[i].action = NULL;
|
|
|
|
updateUnitAI(entity, &unitAI[i], game);
|
|
}
|
|
}
|
|
|
|
void updateUnitActionsSystem(ecs_iter_t *it) {
|
|
Game *game = ecs_singleton_get_mut(ECS, Game);
|
|
UnitAction *action = ecs_field(it, UnitAction, 1);
|
|
|
|
for (i32 i = 0; i < it->count; i++) {
|
|
ecs_entity_t entity = it->entities[i];
|
|
updateAction(&action[i], game);
|
|
}
|
|
}
|