Properly set building owner + apply building pop capacity

This commit is contained in:
2024-01-23 18:39:53 +01:00
parent 547a1ca583
commit 2d11bb4675
14 changed files with 195 additions and 105 deletions

View File

@@ -57,6 +57,26 @@ void updateTextureOwnerTile(ecs_iter_t *it) {
tex[i].rec.y += offset.y;
}
}
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];
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];
res->popCapacity -= addPop[i].amount;
}
}
void entityUpdateSpatialID(ecs_iter_t *it) {
Game *game = ecs_singleton_get_mut(ECS, Game);

View File

@@ -252,7 +252,7 @@ void updatePlayerInput() {
getBuildingSize(input->building, &sizeX, &sizeY);
bool canPlace = canPlaceBuilding(game, input->building, tileX, tileY);
if (canPlace && isInputBtnDown(input, primaryBtn)) {
placeBuilding(game, input->building, tileX, tileY, (Owner) {PLAYER_BLUE});
placeBuilding(game, input->building, tileX, tileY, game->player);
}
input->buildingCanPlace = canPlace;
input->buildingPos = (Vec2i) {tileX, tileY};

View File

@@ -109,6 +109,9 @@ void setupSystems() {
ECS_OBSERVER(ECS, updateTextureOwnerTile, EcsOnSet, TextureRegion, Owner);
ECS_OBSERVER(ECS, buildingAddPopCapacity, EcsOnSet, AddPopCapacity, Owner);
ECS_OBSERVER(ECS, buildingRemovePopCapacity, EcsOnRemove, AddPopCapacity, Owner);
ECS_SYSTEM(ECS, entityUpdateSpatialID, EcsOnUpdate, Position, Size, Velocity, SpatialGridID);
ECS_SYSTEM(ECS, entityUpdateKinematic, EcsOnUpdate, Position, Velocity, Steering, Unit);

View File

@@ -62,6 +62,19 @@ void entityPathRemove(ecs_iter_t *it);
void updateTextureOwnerTile(ecs_iter_t *it);
/* Observer (for adding pop capacity)
* 0: Game (singleton)
* 1: AddPopCapacity
* 2: Owner
*/
void buildingAddPopCapacity(ecs_iter_t *it);
/* Observer (for removing pop capacity)
* 0: Game (singleton)
* 1: AddPopCapacity
* 2: Owner
*/
void buildingRemovePopCapacity(ecs_iter_t *it);
/*
* 0: Game (singleton) for entity map
* 1: Position