Implement harvest worker AI

This commit is contained in:
2023-12-17 14:20:13 +01:00
parent 5564df4768
commit 33b28b620d
14 changed files with 338 additions and 40 deletions

View File

@@ -2,7 +2,10 @@
#include "game_state.h"
void updateUnitActions(ecs_iter_t *it) {
#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);
@@ -11,3 +14,31 @@ void updateUnitActions(ecs_iter_t *it) {
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);
}
}