Rename BUILDINGS to BuildingType, add owner component to entities
This commit is contained in:
@@ -13,4 +13,8 @@ typedef struct TileSize {
|
||||
BzTile h;
|
||||
} TileSize;
|
||||
|
||||
typedef struct Owner {
|
||||
BuildingType playerID;
|
||||
} Owner;
|
||||
|
||||
#endif //PIXELDEFENSE_COMPONENTS_H
|
||||
|
||||
@@ -49,6 +49,7 @@ ecs_entity_t *entityMap = NULL;
|
||||
bool prepareBuildings(BzTileLayer *layer, BzTile *data, i32 dataCount) {
|
||||
ECS_COMPONENT(ECS, TilePosition);
|
||||
ECS_COMPONENT(ECS, TileSize);
|
||||
ECS_COMPONENT(ECS, Owner);
|
||||
|
||||
entityMap = bzCalloc(sizeof(*entityMap), layer->width * layer->height);
|
||||
|
||||
@@ -74,6 +75,9 @@ bool prepareBuildings(BzTileLayer *layer, BzTile *data, i32 dataCount) {
|
||||
ecs_entity_t e = ecs_new_id(ECS);
|
||||
ecs_set(ECS, e, TilePosition, {.x=x, .y=y});
|
||||
ecs_set(ECS, e, TileSize, {.w=size.w, .h=size.h});
|
||||
ownerTile = bzTilesetGetTile(buildingTileset, ownerTile);
|
||||
ownerTile = getTileBuilding(ownerTile);
|
||||
ecs_set(ECS, e, Owner, {.playerID=ownerTile});
|
||||
|
||||
for (i32 yIdx = y; yIdx < y + size.h; yIdx++) {
|
||||
for (i32 xIdx = x; xIdx < x + size.w; xIdx++) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <string.h>
|
||||
|
||||
|
||||
typedef enum BUILDINGS {
|
||||
typedef enum BuildingType {
|
||||
BUILDINGS_NONE,
|
||||
BUILDINGS_KEEP,
|
||||
BUILDINGS_GRANARY,
|
||||
@@ -14,7 +14,9 @@ typedef enum BUILDINGS {
|
||||
BUILDINGS_BARACKS,
|
||||
BUILDINGS_ORCHARD,
|
||||
BUILDINGS_ANIMAL_FARM,
|
||||
BUILDINGS_PLAYER_RED,
|
||||
BUILDINGS_FLETCHER,
|
||||
BUILDINGS_PLAYER_BLUE,
|
||||
BUILDINGS_SMITHY,
|
||||
BUILDINGS_WORKSHOP,
|
||||
BUILDINGS_FARM,
|
||||
@@ -24,10 +26,10 @@ typedef enum BUILDINGS {
|
||||
BUILDINGS_TOWER,
|
||||
BUILDINGS_SMALL_TOWER,
|
||||
BUILDINGS_COUNT
|
||||
} BUILDINGS;
|
||||
} BuildingType;
|
||||
|
||||
|
||||
static BUILDINGS getTileBuilding(BzTile tile) {
|
||||
static BuildingType getTileBuilding(BzTile tile) {
|
||||
switch (tile) {
|
||||
case 0:
|
||||
case 1:
|
||||
@@ -65,9 +67,13 @@ static BUILDINGS getTileBuilding(BzTile tile) {
|
||||
case 44:
|
||||
case 45:
|
||||
return BUILDINGS_ANIMAL_FARM;
|
||||
case 31:
|
||||
return BUILDINGS_PLAYER_RED;
|
||||
case 35:
|
||||
case 36:
|
||||
return BUILDINGS_FLETCHER;
|
||||
case 63:
|
||||
return BUILDINGS_PLAYER_BLUE;
|
||||
case 67:
|
||||
case 68:
|
||||
return BUILDINGS_SMITHY;
|
||||
@@ -94,7 +100,7 @@ static BUILDINGS getTileBuilding(BzTile tile) {
|
||||
}
|
||||
}
|
||||
|
||||
static BUILDINGS getBuildingFromStr(const char *str) {
|
||||
static BuildingType getBuildingFromStr(const char *str) {
|
||||
if (strncmp("keep", str, 4) == 0) return BUILDINGS_KEEP;
|
||||
if (strncmp("granary", str, 7) == 0) return BUILDINGS_GRANARY;
|
||||
if (strncmp("armory", str, 6) == 0) return BUILDINGS_ARMORY;
|
||||
@@ -103,7 +109,9 @@ static BUILDINGS getBuildingFromStr(const char *str) {
|
||||
if (strncmp("baracks", str, 7) == 0) return BUILDINGS_BARACKS;
|
||||
if (strncmp("orchard", str, 7) == 0) return BUILDINGS_ORCHARD;
|
||||
if (strncmp("animal_farm", str, 11) == 0) return BUILDINGS_ANIMAL_FARM;
|
||||
if (strncmp("player_red", str, 10) == 0) return BUILDINGS_PLAYER_RED;
|
||||
if (strncmp("fletcher", str, 8) == 0) return BUILDINGS_FLETCHER;
|
||||
if (strncmp("player_blue", str, 11) == 0) return BUILDINGS_PLAYER_BLUE;
|
||||
if (strncmp("smithy", str, 6) == 0) return BUILDINGS_SMITHY;
|
||||
if (strncmp("workshop", str, 8) == 0) return BUILDINGS_WORKSHOP;
|
||||
if (strncmp("farm", str, 4) == 0) return BUILDINGS_FARM;
|
||||
@@ -114,7 +122,7 @@ static BUILDINGS getBuildingFromStr(const char *str) {
|
||||
if (strncmp("small_tower", str, 11) == 0) return BUILDINGS_SMALL_TOWER;
|
||||
else return BUILDINGS_NONE;
|
||||
}
|
||||
static void getBuildingSize(BUILDINGS type, BzTile *outWidth, BzTile *outHeight) {
|
||||
static void getBuildingSize(BuildingType type, BzTile *outWidth, BzTile *outHeight) {
|
||||
switch (type) {
|
||||
case BUILDINGS_KEEP:
|
||||
if (outWidth) *outWidth = 3;
|
||||
@@ -148,10 +156,18 @@ static void getBuildingSize(BUILDINGS type, BzTile *outWidth, BzTile *outHeight)
|
||||
if (outWidth) *outWidth = 2;
|
||||
if (outHeight) *outHeight = 2;
|
||||
break;
|
||||
case BUILDINGS_PLAYER_RED:
|
||||
if (outWidth) *outWidth = 1;
|
||||
if (outHeight) *outHeight = 1;
|
||||
break;
|
||||
case BUILDINGS_FLETCHER:
|
||||
if (outWidth) *outWidth = 2;
|
||||
if (outHeight) *outHeight = 1;
|
||||
break;
|
||||
case BUILDINGS_PLAYER_BLUE:
|
||||
if (outWidth) *outWidth = 1;
|
||||
if (outHeight) *outHeight = 1;
|
||||
break;
|
||||
case BUILDINGS_SMITHY:
|
||||
if (outWidth) *outWidth = 2;
|
||||
if (outHeight) *outHeight = 1;
|
||||
|
||||
Reference in New Issue
Block a user