Fix pop consuming

This commit is contained in:
2024-02-07 12:00:02 +01:00
parent c625f566bc
commit e41837001e
5 changed files with 14 additions and 14 deletions

View File

@@ -99,7 +99,7 @@ ecs_entity_t placeBuilding(Game *game, BuildingType type,
.slots[0] = {
.entityType = ENTITY_WORKER,
.numRecruiting = 0,
.recruitTime = 5.0f,
.recruitTime = 4.0f,
.elapsed = 0.0f,
}
});

View File

@@ -55,40 +55,40 @@ void updateTextureOwnerTile(ecs_iter_t *it) {
void buildingAddPopCapacity(ecs_iter_t *it) {
Game *game = ecs_singleton_get_mut(ECS, Game);
AddPopCapacity *addPop = ecs_field(it, AddPopCapacity, 1);
Owner *owner = ecs_field(it, Owner, 2);
for (i32 i = 0; i < it->count; i++) {
PlayerResources *res = &game->playerResources[owner[i].player];
Player player = ecs_get(ECS, it->entities[i], Owner)->player;
PlayerResources *res = &game->playerResources[player];
res->popCapacity += addPop[i].amount;
}
}
void buildingRemovePopCapacity(ecs_iter_t *it) {
Game *game = ecs_singleton_get_mut(ECS, Game);
AddPopCapacity *addPop = ecs_field(it, AddPopCapacity, 1);
Owner *owner = ecs_field(it, Owner, 2);
for (i32 i = 0; i < it->count; i++) {
PlayerResources *res = &game->playerResources[owner->player];
Player player = ecs_get(ECS, it->entities[i], Owner)->player;
PlayerResources *res = &game->playerResources[player];
res->popCapacity -= addPop[i].amount;
}
}
void entityConsumePopCapacity(ecs_iter_t *it) {
Game *game = ecs_singleton_get_mut(ECS, Game);
ConsumePopCapacity *pop = ecs_field(it, ConsumePopCapacity, 1);
Owner *owner = ecs_field(it, Owner, 2);
for (i32 i = 0; i < it->count; i++) {
PlayerResources *res = &game->playerResources[owner[i].player];
Player player = ecs_get(ECS, it->entities[i], Owner)->player;
PlayerResources *res = &game->playerResources[player];
res->pop += pop[i].amount;
}
}
void entityUnConsumePopCapacity(ecs_iter_t *it) {
Game *game = ecs_singleton_get_mut(ECS, Game);
ConsumePopCapacity *pop = ecs_field(it, ConsumePopCapacity, 1);
Owner *owner = ecs_field(it, Owner, 2);
for (i32 i = 0; i < it->count; i++) {
PlayerResources *res = &game->playerResources[owner[i].player];
Player player = ecs_get(ECS, it->entities[i], Owner)->player;
PlayerResources *res = &game->playerResources[player];
res->pop -= pop[i].amount;
}
}
@@ -260,7 +260,8 @@ void updateBuildingRecruitment(ecs_iter_t *it) {
slot->elapsed += dt;
if (slot->elapsed >= slot->recruitTime) {
slot->elapsed = 0;
bzLogInfo("spawned");
PlayerResources *playerRes = &game->playerResources[player];
playerRes->pop--;
entityRecruit(slot->entityType, placePos, player, game);
slot->numRecruiting--;
}

View File

@@ -207,6 +207,7 @@ void drawGameUI(Game *game, f32 dt) {
if (selected) {
i32 res[RES_COUNT] = {0,};
getEntityCost(slot->entityType, res);
playerRes->pop++;
playerRes->food -= res[RES_FOOD];
playerRes->wood -= res[RES_WOOD];
playerRes->gold -= res[RES_GOLD];

View File

@@ -94,8 +94,8 @@ void setupSystems() {
ECS_OBSERVER(ECS, buildingAddPopCapacity, EcsOnSet, AddPopCapacity, Owner);
ECS_OBSERVER(ECS, buildingRemovePopCapacity, EcsOnRemove, AddPopCapacity, Owner);
ECS_OBSERVER(ECS, entityConsumePopCapacity, EcsOnSet, ConsumePopCapacity, Owner);
ECS_OBSERVER(ECS, entityUnConsumePopCapacity, EcsOnRemove, ConsumePopCapacity, Owner);
ECS_OBSERVER(ECS, entityConsumePopCapacity, EcsOnSet, ConsumePopCapacity);
ECS_OBSERVER(ECS, entityUnConsumePopCapacity, EcsOnRemove, ConsumePopCapacity);
ECS_SYSTEM(ECS, entityUpdateSpatialID, EcsOnUpdate, Position, HitBox, Velocity, SpatialGridID);
ECS_SYSTEM(ECS, entityUpdateKinematic, EcsOnUpdate, Position, Velocity, Steering, Unit);

View File

@@ -91,13 +91,11 @@ void buildingRemovePopCapacity(ecs_iter_t *it);
/* Observer (for consuming pop capacity)
* 0: Game (singleton)
* 1: ConsumePopCapacity
* 2: Owner
*/
void entityConsumePopCapacity(ecs_iter_t *it);
/* Observer (for unconsuming pop capacity)
* 0: Game (singleton)
* 1: ConsumePopCapacity
* 2: Owner
*/
void entityUnConsumePopCapacity(ecs_iter_t *it);