Properly set building owner + apply building pop capacity
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user