Change Storage to tag (since we have global storage)
This commit is contained in:
@@ -29,15 +29,14 @@ ECS_COMPONENT_DECLARE(UnitAction);
|
||||
ECS_TAG_DECLARE(Selectable);
|
||||
ECS_TAG_DECLARE(Selected);
|
||||
|
||||
ECS_TAG_DECLARE(Unit);
|
||||
ECS_COMPONENT_DECLARE(Worker);
|
||||
ECS_TAG_DECLARE(Unit);
|
||||
ECS_TAG_DECLARE(Storage);
|
||||
ECS_TAG_DECLARE(Harvestable);
|
||||
ECS_TAG_DECLARE(Buildable);
|
||||
ECS_TAG_DECLARE(Workable);
|
||||
ECS_TAG_DECLARE(Attackable);
|
||||
|
||||
ECS_COMPONENT_DECLARE(Storage);
|
||||
|
||||
void initComponentIDs(ecs_world_t *ecs) {
|
||||
ECS_COMPONENT_DEFINE(ecs, Resource);
|
||||
|
||||
@@ -65,12 +64,12 @@ void initComponentIDs(ecs_world_t *ecs) {
|
||||
ECS_TAG_DEFINE(ecs, Selectable);
|
||||
ECS_TAG_DEFINE(ecs, Selected);
|
||||
|
||||
ECS_TAG_DEFINE(ecs, Unit);
|
||||
ECS_COMPONENT_DEFINE(ecs, Worker);
|
||||
ECS_TAG_DEFINE(ecs, Unit);
|
||||
ECS_TAG_DEFINE(ecs, Storage);
|
||||
ECS_TAG_DEFINE(ecs, Harvestable);
|
||||
ECS_TAG_DEFINE(ecs, Buildable);
|
||||
ECS_TAG_DEFINE(ecs, Workable);
|
||||
ECS_TAG_DEFINE(ecs, Attackable);
|
||||
|
||||
ECS_COMPONENT_DEFINE(ecs, Storage);
|
||||
}
|
||||
|
||||
@@ -163,10 +163,6 @@ extern ECS_COMPONENT_DECLARE(UnitAI);
|
||||
extern ECS_TAG_DECLARE(Selectable);
|
||||
extern ECS_TAG_DECLARE(Selected);
|
||||
|
||||
// Unit can:
|
||||
// - Attack
|
||||
extern ECS_TAG_DECLARE(Unit);
|
||||
|
||||
// Worker can:
|
||||
// - Harvest
|
||||
// - Build
|
||||
@@ -183,19 +179,15 @@ typedef struct Worker {
|
||||
} Worker;
|
||||
extern ECS_COMPONENT_DECLARE(Worker);
|
||||
|
||||
// Unit can:
|
||||
// - Attack
|
||||
extern ECS_TAG_DECLARE(Unit);
|
||||
extern ECS_TAG_DECLARE(Storage);
|
||||
extern ECS_TAG_DECLARE(Harvestable);
|
||||
extern ECS_TAG_DECLARE(Buildable);
|
||||
extern ECS_TAG_DECLARE(Workable);
|
||||
extern ECS_TAG_DECLARE(Attackable);
|
||||
|
||||
typedef struct Storage {
|
||||
int capacity[RES_COUNT];
|
||||
int amount[RES_COUNT];
|
||||
int reserved[RES_COUNT];
|
||||
int pending[RES_COUNT];
|
||||
} Storage;
|
||||
extern ECS_COMPONENT_DECLARE(Storage);
|
||||
|
||||
void initComponentIDs(ecs_world_t *ecs);
|
||||
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ bool initBuildingsLayer(BzTileMap *map, BzTileLayer *layer) {
|
||||
// ecs_set(ECS, e, Storage, {});
|
||||
//}
|
||||
if (buildingTile == BUILDING_KEEP) {
|
||||
ecs_set(ECS, e, Storage, {.capacity[RES_WOOD] = 1000});
|
||||
ecs_add_id(ECS, e, Storage);
|
||||
}
|
||||
|
||||
//bzTileMapUpdateCollider(&GAME.map, x, y);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
static ecs_entity_t findNearestStorage(Position pos, ResourceType type, Position *outPos) {
|
||||
ecs_filter_t *storageFilter = ecs_filter(ECS, {
|
||||
.terms = {{ecs_id(Storage)}, {ecs_id(Position)} }
|
||||
.terms = {{ecs_id(Position)}, {ecs_id(Storage)}},
|
||||
});
|
||||
ecs_iter_t it = ecs_filter_iter(ECS, storageFilter);
|
||||
|
||||
@@ -15,12 +15,11 @@ static ecs_entity_t findNearestStorage(Position pos, ResourceType type, Position
|
||||
f32 closestDst = INFINITY;
|
||||
Position closestPos = Vector2Zero();
|
||||
while (ecs_filter_next(&it)) {
|
||||
Storage *storage = ecs_field(&it, Storage, 1);
|
||||
Position *storagePos = ecs_field(&it, Position, 2);
|
||||
Position *storagePos = ecs_field(&it, Position, 1);
|
||||
|
||||
for (i32 i = 0; i < it.count; i++) {
|
||||
f32 dst = Vector2Distance(pos, storagePos[i]);
|
||||
if (storage[i].capacity[type] && dst < closestDst) {
|
||||
if (dst < closestDst) {
|
||||
closest = it.entities[i];
|
||||
closestDst = dst;
|
||||
closestPos = storagePos[i];
|
||||
|
||||
Reference in New Issue
Block a user