Fix harvesting and add resource depositing
This commit is contained in:
@@ -23,8 +23,6 @@ ECS_COMPONENT_DECLARE(TextureRegion);
|
||||
ECS_COMPONENT_DECLARE(Animation);
|
||||
ECS_COMPONENT_DECLARE(Easing);
|
||||
|
||||
ECS_COMPONENT_DECLARE(HarvestEvent);
|
||||
|
||||
ECS_COMPONENT_DECLARE(UnitAI);
|
||||
ECS_COMPONENT_DECLARE(UnitAction);
|
||||
|
||||
@@ -61,8 +59,6 @@ void initComponentIDs(ecs_world_t *ecs) {
|
||||
ECS_COMPONENT_DEFINE(ecs, Animation);
|
||||
ECS_COMPONENT_DEFINE(ecs, Easing);
|
||||
|
||||
ECS_COMPONENT_DEFINE(ecs, HarvestEvent);
|
||||
|
||||
ECS_COMPONENT_DEFINE(ecs, UnitAI);
|
||||
ECS_COMPONENT_DEFINE(ecs, UnitAction);
|
||||
|
||||
|
||||
@@ -149,7 +149,9 @@ typedef struct EntityArms {
|
||||
typedef struct HarvestEvent {
|
||||
i32 amount;
|
||||
} HarvestEvent;
|
||||
extern ECS_COMPONENT_DECLARE(HarvestEvent);
|
||||
typedef struct DepositEvent {
|
||||
i32 amount;
|
||||
} DepositEvent;
|
||||
|
||||
/**********************************************************
|
||||
* Gameplay components
|
||||
|
||||
@@ -26,3 +26,6 @@ i32 harvestEvent(ecs_entity_t entity, HarvestEvent event) {
|
||||
|
||||
return event.amount;
|
||||
}
|
||||
|
||||
void depositEvent(ecs_entity_t entity, DepositEvent event) {
|
||||
}
|
||||
|
||||
@@ -126,7 +126,8 @@ void renderDebugPath(ecs_iter_t *it);
|
||||
* Event Systems
|
||||
**********************************/
|
||||
|
||||
i32 harvestEvent(ecs_entity_t entity, HarvestEvent event);
|
||||
i32 harvestEvent(ecs_entity_t entity, HarvestEvent event);
|
||||
void depositEvent(ecs_entity_t entity, DepositEvent event);
|
||||
|
||||
|
||||
/**********************************
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user