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

@@ -8,6 +8,8 @@
#include "map_init.h"
#include "map_layers.h"
#include "buildings.h"
#include "unit_ai.h"
#include "unit_actions.h"
#include "pathfinding.h"
@@ -112,7 +114,7 @@ bool init(void *userData) {
.objectsPerPage = 512
});
game->pools.actions = bzObjectPoolCreate(&(BzObjectPoolDesc) {
.objectSize = sizeof(UnitAction),
.objectSize = sizeof(Action),
.objectsPerPage = 1024,
});
@@ -176,7 +178,10 @@ bool init(void *userData) {
ECS_SYSTEM(ECS, entityFollowPath, EcsOnUpdate, Path);
//ECS_SYSTEM(ECS, entityHarvestTaskSystem, EcsOnUpdate, Position, Rotation, HarvestTask);
ECS_SYSTEM(ECS, updateUnitActions, EcsOnUpdate, UnitAction);
ECS_SYSTEM(ECS, handleUnitActionsSystem, EcsOnUpdate, UnitAction);
ECS_SYSTEM(ECS, updateUnitAISystem, EcsOnUpdate, UnitAI, UnitAction);
// Needs to be called after AI update, since it removes finished actions
ECS_SYSTEM(ECS, updateUnitActionsSystem, EcsOnUpdate, UnitAction);
//ECS_SYSTEM(ECS, entityUpdateAnimationState, EcsOnUpdate, Velocity, AnimationType);
ECS_SYSTEM(ECS, entityUpdateAnimation, EcsOnUpdate, Animation, TextureRegion);
@@ -306,7 +311,16 @@ void imguiRender(float dt, void *userData) {
while (ecs_iter_next(&it)) {
for (i32 i = 0; i < it.count; i++) {
ecs_entity_t entity = it.entities[i];
igText("\tEntity %llu", entity);
igText("Entity %llu", entity);
igText("Actions:");
const Action *pAction = NULL;
if (ecs_has(ECS, entity, UnitAction)) {
pAction = ecs_get(ECS, entity, UnitAction)->first;
}
while (pAction) {
igText("\t%d: %s", pAction->type, actionTypeToPrettyStr(pAction->type));
pAction = pAction->next;
}
}
}
break;