Move systems into subdirectory, add tree shake animation

This commit is contained in:
2023-12-29 14:46:11 +01:00
parent aa3bfbf823
commit 31a9289770
15 changed files with 352 additions and 105 deletions

View File

@@ -1,7 +1,7 @@
#include "unit_actions.h"
#include "game_state.h"
#include "components.h"
#include "systems.h"
#include "systems/systems.h"
#include <raymath.h>
@@ -22,10 +22,24 @@ void actionMoveTo(ecs_entity_t entity, Action *action, Game *game) {
}
void actionCollectResource(ecs_entity_t entity, Action *action, Game *game) {
if (action->finished) return;
if (action->elapsed > 2.0f) {
BZ_ASSERT(ecs_has(ECS, entity, Worker));
Worker *worker = ecs_get_mut(ECS, entity, Worker);
if (worker->carry >= worker->carryCapacity) {
action->finished = true;
ecs_entity_t target = action->as.collectResource.entity;
ecs_delete(ECS, target);
}
ecs_entity_t target = action->as.collectResource.entity;
bool targetAlive = ecs_is_alive(ECS, target);
action->finished = !targetAlive;
if (!action->finished && action->elapsed > worker->collectSpeed) {
i32 spareCapacity = worker->carryCapacity - worker->carry;
i32 collected = harvestEvent(target, (HarvestEvent) {
.amount = BZ_MIN(1, spareCapacity),
});
worker->carry += collected;
action->elapsed = 0;
}
}
@@ -107,6 +121,20 @@ void addAction(ecs_entity_t entity, Game *game, const Action *action) {
unitAction->last = newAction;
}
}
void prependAction(ecs_entity_t entity, Game *game, const Action *action) {
BZ_ASSERT(action);
BZ_ASSERT(ecs_has(ECS, entity, UnitAction));
UnitAction *unitAction = ecs_get_mut(ECS, entity, UnitAction);
BzObjectPool *pool = game->pools.actions;
Action *newAction = bzObjectPool(pool);
BZ_ASSERT(newAction);
*newAction = *action;
newAction->next = unitAction->first;
unitAction->first = newAction;
}
const char *actionTypeToPrettyStr(ActionType type) {
switch (type) {