Fix harvesting and add resource depositing

This commit is contained in:
2023-12-29 14:54:13 +01:00
parent 31a9289770
commit 681080f3ed
5 changed files with 27 additions and 8 deletions

View File

@@ -31,7 +31,7 @@ void actionCollectResource(ecs_entity_t entity, Action *action, Game *game) {
ecs_entity_t target = action->as.collectResource.entity;
bool targetAlive = ecs_is_alive(ECS, target);
action->finished = !targetAlive;
action->finished |= !targetAlive;
if (!action->finished && action->elapsed > worker->collectSpeed) {
i32 spareCapacity = worker->carryCapacity - worker->carry;
@@ -44,8 +44,25 @@ void actionCollectResource(ecs_entity_t entity, Action *action, Game *game) {
}
void actionDepositResource(ecs_entity_t entity, Action *action, Game *game) {
if (action->elapsed > 0.2f)
if (action->finished) return;
BZ_ASSERT(ecs_has(ECS, entity, Worker));
Worker *worker = ecs_get_mut(ECS, entity, Worker);
if (worker->carry == 0) {
action->finished = true;
}
ecs_entity_t target = action->as.depositResource.entity;
bool targetAlive = ecs_is_alive(ECS, target);
action->finished |= !targetAlive;
if (!action->finished && action->elapsed > worker->depositSpeed) {
depositEvent(target, (DepositEvent) {
.amount = worker->carry
});
worker->carry = 0;
action->finished = true;
}
}
void handleAction(ecs_entity_t entity, UnitAction *unitAction, Game *game) {