Fix pop consuming
This commit is contained in:
@@ -99,7 +99,7 @@ ecs_entity_t placeBuilding(Game *game, BuildingType type,
|
|||||||
.slots[0] = {
|
.slots[0] = {
|
||||||
.entityType = ENTITY_WORKER,
|
.entityType = ENTITY_WORKER,
|
||||||
.numRecruiting = 0,
|
.numRecruiting = 0,
|
||||||
.recruitTime = 5.0f,
|
.recruitTime = 4.0f,
|
||||||
.elapsed = 0.0f,
|
.elapsed = 0.0f,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -55,40 +55,40 @@ void updateTextureOwnerTile(ecs_iter_t *it) {
|
|||||||
void buildingAddPopCapacity(ecs_iter_t *it) {
|
void buildingAddPopCapacity(ecs_iter_t *it) {
|
||||||
Game *game = ecs_singleton_get_mut(ECS, Game);
|
Game *game = ecs_singleton_get_mut(ECS, Game);
|
||||||
AddPopCapacity *addPop = ecs_field(it, AddPopCapacity, 1);
|
AddPopCapacity *addPop = ecs_field(it, AddPopCapacity, 1);
|
||||||
Owner *owner = ecs_field(it, Owner, 2);
|
|
||||||
|
|
||||||
for (i32 i = 0; i < it->count; i++) {
|
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;
|
res->popCapacity += addPop[i].amount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void buildingRemovePopCapacity(ecs_iter_t *it) {
|
void buildingRemovePopCapacity(ecs_iter_t *it) {
|
||||||
Game *game = ecs_singleton_get_mut(ECS, Game);
|
Game *game = ecs_singleton_get_mut(ECS, Game);
|
||||||
AddPopCapacity *addPop = ecs_field(it, AddPopCapacity, 1);
|
AddPopCapacity *addPop = ecs_field(it, AddPopCapacity, 1);
|
||||||
Owner *owner = ecs_field(it, Owner, 2);
|
|
||||||
|
|
||||||
for (i32 i = 0; i < it->count; i++) {
|
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;
|
res->popCapacity -= addPop[i].amount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void entityConsumePopCapacity(ecs_iter_t *it) {
|
void entityConsumePopCapacity(ecs_iter_t *it) {
|
||||||
Game *game = ecs_singleton_get_mut(ECS, Game);
|
Game *game = ecs_singleton_get_mut(ECS, Game);
|
||||||
ConsumePopCapacity *pop = ecs_field(it, ConsumePopCapacity, 1);
|
ConsumePopCapacity *pop = ecs_field(it, ConsumePopCapacity, 1);
|
||||||
Owner *owner = ecs_field(it, Owner, 2);
|
|
||||||
|
|
||||||
for (i32 i = 0; i < it->count; i++) {
|
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;
|
res->pop += pop[i].amount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void entityUnConsumePopCapacity(ecs_iter_t *it) {
|
void entityUnConsumePopCapacity(ecs_iter_t *it) {
|
||||||
Game *game = ecs_singleton_get_mut(ECS, Game);
|
Game *game = ecs_singleton_get_mut(ECS, Game);
|
||||||
ConsumePopCapacity *pop = ecs_field(it, ConsumePopCapacity, 1);
|
ConsumePopCapacity *pop = ecs_field(it, ConsumePopCapacity, 1);
|
||||||
Owner *owner = ecs_field(it, Owner, 2);
|
|
||||||
|
|
||||||
for (i32 i = 0; i < it->count; i++) {
|
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;
|
res->pop -= pop[i].amount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -260,7 +260,8 @@ void updateBuildingRecruitment(ecs_iter_t *it) {
|
|||||||
slot->elapsed += dt;
|
slot->elapsed += dt;
|
||||||
if (slot->elapsed >= slot->recruitTime) {
|
if (slot->elapsed >= slot->recruitTime) {
|
||||||
slot->elapsed = 0;
|
slot->elapsed = 0;
|
||||||
bzLogInfo("spawned");
|
PlayerResources *playerRes = &game->playerResources[player];
|
||||||
|
playerRes->pop--;
|
||||||
entityRecruit(slot->entityType, placePos, player, game);
|
entityRecruit(slot->entityType, placePos, player, game);
|
||||||
slot->numRecruiting--;
|
slot->numRecruiting--;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -207,6 +207,7 @@ void drawGameUI(Game *game, f32 dt) {
|
|||||||
if (selected) {
|
if (selected) {
|
||||||
i32 res[RES_COUNT] = {0,};
|
i32 res[RES_COUNT] = {0,};
|
||||||
getEntityCost(slot->entityType, res);
|
getEntityCost(slot->entityType, res);
|
||||||
|
playerRes->pop++;
|
||||||
playerRes->food -= res[RES_FOOD];
|
playerRes->food -= res[RES_FOOD];
|
||||||
playerRes->wood -= res[RES_WOOD];
|
playerRes->wood -= res[RES_WOOD];
|
||||||
playerRes->gold -= res[RES_GOLD];
|
playerRes->gold -= res[RES_GOLD];
|
||||||
|
|||||||
@@ -94,8 +94,8 @@ void setupSystems() {
|
|||||||
ECS_OBSERVER(ECS, buildingAddPopCapacity, EcsOnSet, AddPopCapacity, Owner);
|
ECS_OBSERVER(ECS, buildingAddPopCapacity, EcsOnSet, AddPopCapacity, Owner);
|
||||||
ECS_OBSERVER(ECS, buildingRemovePopCapacity, EcsOnRemove, AddPopCapacity, Owner);
|
ECS_OBSERVER(ECS, buildingRemovePopCapacity, EcsOnRemove, AddPopCapacity, Owner);
|
||||||
|
|
||||||
ECS_OBSERVER(ECS, entityConsumePopCapacity, EcsOnSet, ConsumePopCapacity, Owner);
|
ECS_OBSERVER(ECS, entityConsumePopCapacity, EcsOnSet, ConsumePopCapacity);
|
||||||
ECS_OBSERVER(ECS, entityUnConsumePopCapacity, EcsOnRemove, ConsumePopCapacity, Owner);
|
ECS_OBSERVER(ECS, entityUnConsumePopCapacity, EcsOnRemove, ConsumePopCapacity);
|
||||||
|
|
||||||
ECS_SYSTEM(ECS, entityUpdateSpatialID, EcsOnUpdate, Position, HitBox, Velocity, SpatialGridID);
|
ECS_SYSTEM(ECS, entityUpdateSpatialID, EcsOnUpdate, Position, HitBox, Velocity, SpatialGridID);
|
||||||
ECS_SYSTEM(ECS, entityUpdateKinematic, EcsOnUpdate, Position, Velocity, Steering, Unit);
|
ECS_SYSTEM(ECS, entityUpdateKinematic, EcsOnUpdate, Position, Velocity, Steering, Unit);
|
||||||
|
|||||||
@@ -91,13 +91,11 @@ void buildingRemovePopCapacity(ecs_iter_t *it);
|
|||||||
/* Observer (for consuming pop capacity)
|
/* Observer (for consuming pop capacity)
|
||||||
* 0: Game (singleton)
|
* 0: Game (singleton)
|
||||||
* 1: ConsumePopCapacity
|
* 1: ConsumePopCapacity
|
||||||
* 2: Owner
|
|
||||||
*/
|
*/
|
||||||
void entityConsumePopCapacity(ecs_iter_t *it);
|
void entityConsumePopCapacity(ecs_iter_t *it);
|
||||||
/* Observer (for unconsuming pop capacity)
|
/* Observer (for unconsuming pop capacity)
|
||||||
* 0: Game (singleton)
|
* 0: Game (singleton)
|
||||||
* 1: ConsumePopCapacity
|
* 1: ConsumePopCapacity
|
||||||
* 2: Owner
|
|
||||||
*/
|
*/
|
||||||
void entityUnConsumePopCapacity(ecs_iter_t *it);
|
void entityUnConsumePopCapacity(ecs_iter_t *it);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user