Consume pop capacity + evade AI boiler plate
This commit is contained in:
@@ -11,8 +11,8 @@
|
||||
|
||||
ecs_entity_t queryEntity(BzSpatialGrid *entityGrid, Vector2 point, ecs_entity_t tag);
|
||||
|
||||
bool selectEntity(BzSpatialGrid *entityGrid, Vector2 point, ecs_entity_t tag);
|
||||
void selectUnits(BzSpatialGrid *entityGrid, Rectangle area);
|
||||
bool selectEntity(BzSpatialGrid *entityGrid, Vector2 point, ecs_entity_t tag, Player player);
|
||||
void selectUnits(BzSpatialGrid *entityGrid, Rectangle area, Player player);
|
||||
|
||||
void addEntityToInspected(ecs_entity_t entity, Game *game);
|
||||
|
||||
@@ -43,7 +43,7 @@ void inputPrimaryAction(Game *game, InputState *input) {
|
||||
end.y = tmp;
|
||||
}
|
||||
input->pickArea = (Rectangle) {start.x, start.y, end.x - start.x, end.y - start.y};
|
||||
selectUnits(game->entityGrid, input->pickArea);
|
||||
selectUnits(game->entityGrid, input->pickArea, game->player);
|
||||
}
|
||||
i32 selectedCount = ecs_query_entity_count(input->queries.selected);
|
||||
if (isInputBtnJustDragged(input, primaryBtn) && selectedCount > 0) {
|
||||
@@ -55,11 +55,11 @@ void inputPrimaryAction(Game *game, InputState *input) {
|
||||
if (entity) addEntityToInspected(entity, game);
|
||||
} else if (isInputBtnJustUp(input, primaryBtn)) {
|
||||
InputType type = input->state;
|
||||
if (selectEntity(game->entityGrid, input->mouseDownWorld, ecs_id(Unit)))
|
||||
if (selectEntity(game->entityGrid, input->mouseDownWorld, ecs_id(Unit), game->player))
|
||||
type = INPUT_SELECTED_UNITS;
|
||||
else if (selectEntity(game->entityGrid, input->mouseDownWorld, ecs_id(Harvestable)))
|
||||
else if (selectEntity(game->entityGrid, input->mouseDownWorld, ecs_id(Harvestable), PLAYER_COUNT))
|
||||
type = INPUT_SELECTED_OBJECT;
|
||||
else if (selectEntity(game->entityGrid, input->mouseDownWorld, ecs_id(Building)))
|
||||
else if (selectEntity(game->entityGrid, input->mouseDownWorld, ecs_id(Building), game->player))
|
||||
type = INPUT_SELECTED_BUILDING;
|
||||
selectedCount = ecs_query_entity_count(input->queries.selected);
|
||||
if (selectedCount > 0) {
|
||||
@@ -232,6 +232,10 @@ void updatePlayerInput() {
|
||||
const MouseButton primaryBtn = input->mapping.primaryBtn;
|
||||
const MouseButton secondaryBtn = input->mapping.secondaryBtn;
|
||||
|
||||
i32 count = ecs_query_entity_count(input->queries.selected);
|
||||
if (count > 0)
|
||||
input->state = INPUT_SELECTED_UNITS;
|
||||
|
||||
switch (input->state) {
|
||||
case INPUT_NONE: {
|
||||
inputPrimaryAction(game, input);
|
||||
@@ -304,9 +308,7 @@ void drawPlayerInputUIGround() {
|
||||
Size *size = ecs_field(&it, Size, 2);
|
||||
for (i32 i = 0; i < it.count; i++) {
|
||||
ecs_entity_t entity = it.entities[i];
|
||||
f32 radius = size[i].x;
|
||||
if (size[i].y > radius)
|
||||
radius = size[i].y;
|
||||
f32 radius = BZ_MIN(size[i].x, size[i].y);
|
||||
radius *= 0.5f;
|
||||
const f32 lineThickness = 1.0f;
|
||||
if (ecs_has(ECS, entity, Building)) {
|
||||
@@ -379,21 +381,29 @@ ecs_entity_t queryEntity(BzSpatialGrid *entityGrid, Vector2 point, ecs_entity_t
|
||||
return closest;
|
||||
}
|
||||
|
||||
bool selectEntity(BzSpatialGrid *entityGrid, Vector2 point, ecs_entity_t tag) {
|
||||
bool selectEntity(BzSpatialGrid *entityGrid, Vector2 point, ecs_entity_t tag, Player player) {
|
||||
ecs_remove_all(ECS, Selected);
|
||||
const ecs_entity_t entity = queryEntity(entityGrid, point, tag);
|
||||
if (entity) {
|
||||
ecs_add(ECS, entity, Selected);
|
||||
return true;
|
||||
if (!entity) return false;
|
||||
if (player != PLAYER_COUNT) {
|
||||
if (!ecs_has(ECS, entity, Owner)) return false;
|
||||
Owner owner = *ecs_get(ECS, entity, Owner);
|
||||
if (player != owner.player) return false;
|
||||
}
|
||||
return false;
|
||||
ecs_add(ECS, entity, Selected);
|
||||
return true;
|
||||
}
|
||||
|
||||
void selectUnits(BzSpatialGrid *entityGrid, Rectangle area) {
|
||||
void selectUnits(BzSpatialGrid *entityGrid, Rectangle area, Player player) {
|
||||
ecs_remove_all(ECS, Selected);
|
||||
BzSpatialGridIter it = bzSpatialGridIter(entityGrid, area.x, area.y, area.width, area.height);
|
||||
while (bzSpatialGridQueryNext(&it)) {
|
||||
ecs_entity_t entity = *(ecs_entity_t *) it.data;
|
||||
if (player != PLAYER_COUNT) {
|
||||
if (!ecs_has(ECS, entity, Owner)) continue;
|
||||
Owner owner = *ecs_get(ECS, entity, Owner);
|
||||
if (owner.player != player) continue;
|
||||
}
|
||||
if (!ecs_has_id(ECS, entity, ecs_id(Unit))) continue;
|
||||
Rectangle bounds;
|
||||
if (!getEntityBounds(entity, NULL, NULL, &bounds)) continue;
|
||||
|
||||
Reference in New Issue
Block a user