Implement farming
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -88,17 +88,26 @@ ecs_entity_t placeBuilding(Game *game, BuildingType type,
|
|||||||
region.rec.height *= sizeY;
|
region.rec.height *= sizeY;
|
||||||
ecs_set_ptr(ECS, building, TextureRegion, ®ion);
|
ecs_set_ptr(ECS, building, TextureRegion, ®ion);
|
||||||
|
|
||||||
bzTileMapSetCollisions(&game->map, true, COLL_LAYER_BUILDINGS, posX, posY, sizeX, sizeY);
|
bool hasCollision = true;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case BUILDING_KEEP:
|
case BUILDING_KEEP:
|
||||||
ecs_set(ECS, building, AddPopCapacity, {10});
|
ecs_set(ECS, building, AddPopCapacity, {10});
|
||||||
ecs_add_id(ECS, building, Storage);
|
ecs_add_id(ECS, building, Storage);
|
||||||
break;
|
break;
|
||||||
|
case BUILDING_WHEAT_0:
|
||||||
|
case BUILDING_WHEAT_1:
|
||||||
|
hasCollision = false;
|
||||||
|
ecs_add_id(ECS, building, Harvestable);
|
||||||
|
ecs_set(ECS, building, Resource, {RES_FOOD, INFINITY});
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasCollision)
|
||||||
|
bzTileMapSetCollisions(&game->map, true, COLL_LAYER_BUILDINGS, posX, posY, sizeX, sizeY);
|
||||||
|
|
||||||
return building;
|
return building;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -166,12 +175,14 @@ Vector2 getPositionNearBuilding(ecs_entity_t building, Vector2 fromPos) {
|
|||||||
Vector2 pos = *ecs_get(ECS, building, Position);
|
Vector2 pos = *ecs_get(ECS, building, Position);
|
||||||
HitBox hitbox = *ecs_get(ECS, building, HitBox);
|
HitBox hitbox = *ecs_get(ECS, building, HitBox);
|
||||||
|
|
||||||
|
Vector2 center = entityGetCenter(pos, hitbox);
|
||||||
|
|
||||||
Vector2 size = {hitbox.width, hitbox.height};
|
Vector2 size = {hitbox.width, hitbox.height};
|
||||||
size = Vector2SubtractValue(size, 10.0f);
|
size = Vector2SubtractValue(size, 10.0f);
|
||||||
|
|
||||||
Vector2 dir = Vector2Normalize(Vector2Subtract(fromPos, pos));
|
Vector2 dir = Vector2Normalize(Vector2Subtract(fromPos, center));
|
||||||
dir = Vector2Multiply(dir, size);
|
dir = Vector2Multiply(dir, size);
|
||||||
|
|
||||||
pos = Vector2Add(pos, dir);
|
center = Vector2Add(center, dir);
|
||||||
return pos;
|
return center;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,11 +208,10 @@ typedef struct Building {
|
|||||||
Vec2i pos;
|
Vec2i pos;
|
||||||
Vec2i size;
|
Vec2i size;
|
||||||
} Building;
|
} Building;
|
||||||
extern ECS_COMPONENT_DECLARE(Building);
|
|
||||||
extern ECS_TAG_DECLARE(Storage);
|
extern ECS_TAG_DECLARE(Storage);
|
||||||
|
extern ECS_COMPONENT_DECLARE(Building);
|
||||||
extern ECS_TAG_DECLARE(Harvestable);
|
extern ECS_TAG_DECLARE(Harvestable);
|
||||||
extern ECS_TAG_DECLARE(Buildable);
|
extern ECS_TAG_DECLARE(Buildable);
|
||||||
extern ECS_TAG_DECLARE(Workable);
|
|
||||||
extern ECS_TAG_DECLARE(Attackable);
|
extern ECS_TAG_DECLARE(Attackable);
|
||||||
|
|
||||||
void initComponentIDs(ecs_world_t *ecs);
|
void initComponentIDs(ecs_world_t *ecs);
|
||||||
|
|||||||
@@ -37,8 +37,6 @@ static OwnerType getOwnerType(BzTileID tile) {
|
|||||||
typedef enum TerrainType {
|
typedef enum TerrainType {
|
||||||
TERRAIN_NONE = -1,
|
TERRAIN_NONE = -1,
|
||||||
TERRAIN_GOLD_ORE,
|
TERRAIN_GOLD_ORE,
|
||||||
TERRAIN_WHEAT_0,
|
|
||||||
TERRAIN_WHEAT_1,
|
|
||||||
TERRAIN_COUNT,
|
TERRAIN_COUNT,
|
||||||
} TerrainType;
|
} TerrainType;
|
||||||
|
|
||||||
@@ -295,6 +293,8 @@ typedef enum BuildingType {
|
|||||||
BUILDING_MARKET,
|
BUILDING_MARKET,
|
||||||
BUILDING_MILL,
|
BUILDING_MILL,
|
||||||
BUILDING_WAREHOUSE,
|
BUILDING_WAREHOUSE,
|
||||||
|
BUILDING_WHEAT_0,
|
||||||
|
BUILDING_WHEAT_1,
|
||||||
BUILDING_COUNT,
|
BUILDING_COUNT,
|
||||||
} BuildingType;
|
} BuildingType;
|
||||||
|
|
||||||
@@ -307,6 +307,10 @@ static BuildingType getTileBuilding(BzTileID tile) {
|
|||||||
case 5910:
|
case 5910:
|
||||||
case 5911:
|
case 5911:
|
||||||
return BUILDING_KEEP;
|
return BUILDING_KEEP;
|
||||||
|
case 6400:
|
||||||
|
return BUILDING_WHEAT_1;
|
||||||
|
case 6401:
|
||||||
|
return BUILDING_WHEAT_0;
|
||||||
case 6405:
|
case 6405:
|
||||||
case 6406:
|
case 6406:
|
||||||
return BUILDING_ARCHERY_RANGE;
|
return BUILDING_ARCHERY_RANGE;
|
||||||
@@ -345,6 +349,8 @@ static BzTileID getBuildingTile(BuildingType type) {
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case BUILDING_BARRACKS: return 5638;
|
case BUILDING_BARRACKS: return 5638;
|
||||||
case BUILDING_KEEP: return 5654;
|
case BUILDING_KEEP: return 5654;
|
||||||
|
case BUILDING_WHEAT_1: return 6400;
|
||||||
|
case BUILDING_WHEAT_0: return 6401;
|
||||||
case BUILDING_ARCHERY_RANGE: return 6405;
|
case BUILDING_ARCHERY_RANGE: return 6405;
|
||||||
case BUILDING_WAREHOUSE: return 6433;
|
case BUILDING_WAREHOUSE: return 6433;
|
||||||
case BUILDING_HOUSE_01: return 6666;
|
case BUILDING_HOUSE_01: return 6666;
|
||||||
@@ -367,6 +373,8 @@ static const char *getBuildingStr(BuildingType type) {
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case BUILDING_BARRACKS: return "barracks";
|
case BUILDING_BARRACKS: return "barracks";
|
||||||
case BUILDING_KEEP: return "keep";
|
case BUILDING_KEEP: return "keep";
|
||||||
|
case BUILDING_WHEAT_1: return "wheat_1";
|
||||||
|
case BUILDING_WHEAT_0: return "wheat_0";
|
||||||
case BUILDING_ARCHERY_RANGE: return "archery_range";
|
case BUILDING_ARCHERY_RANGE: return "archery_range";
|
||||||
case BUILDING_WAREHOUSE: return "warehouse";
|
case BUILDING_WAREHOUSE: return "warehouse";
|
||||||
case BUILDING_HOUSE_01: return "house_01";
|
case BUILDING_HOUSE_01: return "house_01";
|
||||||
@@ -395,6 +403,14 @@ static BuildingType getBuildingSize(BuildingType type, i32 *outWidth, i32 *outHe
|
|||||||
if (outWidth) *outWidth = 2;
|
if (outWidth) *outWidth = 2;
|
||||||
if (outHeight) *outHeight = 2;
|
if (outHeight) *outHeight = 2;
|
||||||
break;
|
break;
|
||||||
|
case BUILDING_WHEAT_1:
|
||||||
|
if (outWidth) *outWidth = 1;
|
||||||
|
if (outHeight) *outHeight = 1;
|
||||||
|
break;
|
||||||
|
case BUILDING_WHEAT_0:
|
||||||
|
if (outWidth) *outWidth = 1;
|
||||||
|
if (outHeight) *outHeight = 1;
|
||||||
|
break;
|
||||||
case BUILDING_ARCHERY_RANGE:
|
case BUILDING_ARCHERY_RANGE:
|
||||||
if (outWidth) *outWidth = 2;
|
if (outWidth) *outWidth = 2;
|
||||||
if (outHeight) *outHeight = 1;
|
if (outHeight) *outHeight = 1;
|
||||||
@@ -1707,8 +1723,6 @@ static bool hasEntityHitBoxRec(BzTile tile) {
|
|||||||
case 5891:
|
case 5891:
|
||||||
case 6146:
|
case 6146:
|
||||||
case 6147:
|
case 6147:
|
||||||
case 6400:
|
|
||||||
case 6401:
|
|
||||||
case 6402:
|
case 6402:
|
||||||
case 6403:
|
case 6403:
|
||||||
case 6656:
|
case 6656:
|
||||||
@@ -1734,8 +1748,6 @@ static Rectangle getEntityHitBoxRec(BzTile tile) {
|
|||||||
case 5891: return (Rectangle) {6, 2, 4, 10};
|
case 5891: return (Rectangle) {6, 2, 4, 10};
|
||||||
case 6146: return (Rectangle) {6, 2, 4, 10};
|
case 6146: return (Rectangle) {6, 2, 4, 10};
|
||||||
case 6147: return (Rectangle) {6, 2, 4, 10};
|
case 6147: return (Rectangle) {6, 2, 4, 10};
|
||||||
case 6400: return (Rectangle) {4, 2, 8, 10};
|
|
||||||
case 6401: return (Rectangle) {4, 2, 8, 10};
|
|
||||||
case 6402: return (Rectangle) {6, 2, 4, 10};
|
case 6402: return (Rectangle) {6, 2, 4, 10};
|
||||||
case 6403: return (Rectangle) {6, 2, 4, 10};
|
case 6403: return (Rectangle) {6, 2, 4, 10};
|
||||||
case 6656: return (Rectangle) {6, 2, 4, 10};
|
case 6656: return (Rectangle) {6, 2, 4, 10};
|
||||||
|
|||||||
@@ -553,7 +553,6 @@ void igInspectWindow(ecs_entity_t entity, bool *open) {
|
|||||||
igTagCheckbox("Selected", ECS, entity, Selected);
|
igTagCheckbox("Selected", ECS, entity, Selected);
|
||||||
igTagCheckbox("Storage", ECS, entity, Storage);
|
igTagCheckbox("Storage", ECS, entity, Storage);
|
||||||
igTagCheckbox("Harvestable", ECS, entity, Harvestable);
|
igTagCheckbox("Harvestable", ECS, entity, Harvestable);
|
||||||
igTagCheckbox("Workable", ECS, entity, Workable);
|
|
||||||
igTagCheckbox("Attackable", ECS, entity, Attackable);
|
igTagCheckbox("Attackable", ECS, entity, Attackable);
|
||||||
}
|
}
|
||||||
if (ecs_has(ECS, entity, BzBTState) &&
|
if (ecs_has(ECS, entity, BzBTState) &&
|
||||||
|
|||||||
@@ -106,13 +106,20 @@ void inputUnitAction(Game *game, InputState *input) {
|
|||||||
ecs_entity_t entity = it.entities[i];
|
ecs_entity_t entity = it.entities[i];
|
||||||
Position target = *ecs_get(ECS, taskEntity, Position);
|
Position target = *ecs_get(ECS, taskEntity, Position);
|
||||||
|
|
||||||
|
f32 proximity = 6.0f;
|
||||||
|
if (resource.type == RES_FOOD)
|
||||||
|
proximity = 2.0f;
|
||||||
|
|
||||||
|
Worker *worker = ecs_get_mut(ECS, entity, Worker);
|
||||||
|
worker->carryRes = resource.type;
|
||||||
|
|
||||||
setAIBehaviour(entity, game->BTs.workerHarvest, &(AIBlackboard) {
|
setAIBehaviour(entity, game->BTs.workerHarvest, &(AIBlackboard) {
|
||||||
.as.worker = {
|
.as.worker = {
|
||||||
.harvestType = resource.type,
|
.harvestType = resource.type,
|
||||||
.harvestTarget = taskEntity,
|
.harvestTarget = taskEntity,
|
||||||
.harvestPos = target,
|
.harvestPos = target,
|
||||||
},
|
},
|
||||||
.proximity = 6.0f,
|
.proximity = proximity,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ void drawGameUI(Game *game, f32 dt) {
|
|||||||
BUILDING_WAREHOUSE,
|
BUILDING_WAREHOUSE,
|
||||||
BUILDING_MARKET,
|
BUILDING_MARKET,
|
||||||
BUILDING_MILL,
|
BUILDING_MILL,
|
||||||
BUILDING_HOUSE_02, // placeholder for farm
|
BUILDING_WHEAT_0,
|
||||||
BUILDING_BARRACKS,
|
BUILDING_BARRACKS,
|
||||||
BUILDING_ARCHERY_RANGE
|
BUILDING_ARCHERY_RANGE
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7859,32 +7859,9 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id":6400,
|
"id":6400,
|
||||||
"objectgroup":
|
|
||||||
{
|
|
||||||
"draworder":"index",
|
|
||||||
"id":2,
|
|
||||||
"name":"",
|
|
||||||
"objects":[
|
|
||||||
{
|
|
||||||
"height":10,
|
|
||||||
"id":1,
|
|
||||||
"name":"hitbox",
|
|
||||||
"rotation":0,
|
|
||||||
"type":"",
|
|
||||||
"visible":true,
|
|
||||||
"width":8,
|
|
||||||
"x":4,
|
|
||||||
"y":4
|
|
||||||
}],
|
|
||||||
"opacity":1,
|
|
||||||
"type":"objectgroup",
|
|
||||||
"visible":true,
|
|
||||||
"x":0,
|
|
||||||
"y":0
|
|
||||||
},
|
|
||||||
"properties":[
|
"properties":[
|
||||||
{
|
{
|
||||||
"name":"terrain",
|
"name":"building",
|
||||||
"type":"string",
|
"type":"string",
|
||||||
"value":""
|
"value":""
|
||||||
}],
|
}],
|
||||||
@@ -7892,32 +7869,9 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id":6401,
|
"id":6401,
|
||||||
"objectgroup":
|
|
||||||
{
|
|
||||||
"draworder":"index",
|
|
||||||
"id":2,
|
|
||||||
"name":"",
|
|
||||||
"objects":[
|
|
||||||
{
|
|
||||||
"height":10,
|
|
||||||
"id":1,
|
|
||||||
"name":"hitbox",
|
|
||||||
"rotation":0,
|
|
||||||
"type":"",
|
|
||||||
"visible":true,
|
|
||||||
"width":8,
|
|
||||||
"x":4,
|
|
||||||
"y":4
|
|
||||||
}],
|
|
||||||
"opacity":1,
|
|
||||||
"type":"objectgroup",
|
|
||||||
"visible":true,
|
|
||||||
"x":0,
|
|
||||||
"y":0
|
|
||||||
},
|
|
||||||
"properties":[
|
"properties":[
|
||||||
{
|
{
|
||||||
"name":"terrain",
|
"name":"building",
|
||||||
"type":"string",
|
"type":"string",
|
||||||
"value":""
|
"value":""
|
||||||
}],
|
}],
|
||||||
|
|||||||
@@ -2894,19 +2894,13 @@
|
|||||||
</tile>
|
</tile>
|
||||||
<tile id="6400" type="wheat_1">
|
<tile id="6400" type="wheat_1">
|
||||||
<properties>
|
<properties>
|
||||||
<property name="terrain" value=""/>
|
<property name="building" value=""/>
|
||||||
</properties>
|
</properties>
|
||||||
<objectgroup draworder="index" id="2">
|
|
||||||
<object id="1" name="hitbox" x="4" y="4" width="8" height="10"/>
|
|
||||||
</objectgroup>
|
|
||||||
</tile>
|
</tile>
|
||||||
<tile id="6401" type="wheat_0">
|
<tile id="6401" type="wheat_0">
|
||||||
<properties>
|
<properties>
|
||||||
<property name="terrain" value=""/>
|
<property name="building" value=""/>
|
||||||
</properties>
|
</properties>
|
||||||
<objectgroup draworder="index" id="2">
|
|
||||||
<object id="1" name="hitbox" x="4" y="4" width="8" height="10"/>
|
|
||||||
</objectgroup>
|
|
||||||
</tile>
|
</tile>
|
||||||
<tile id="6402">
|
<tile id="6402">
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="80" height="50" tilewidth="16" tileheight="16" infinite="0" nextlayerid="10" nextobjectid="8">
|
<map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="80" height="50" tilewidth="16" tileheight="16" infinite="0" nextlayerid="10" nextobjectid="20">
|
||||||
<editorsettings>
|
<editorsettings>
|
||||||
<export target="maps/map_01.tmj" format="json"/>
|
<export target="maps/map_01.tmj" format="json"/>
|
||||||
</editorsettings>
|
</editorsettings>
|
||||||
@@ -393,5 +393,41 @@
|
|||||||
<object id="1" name="camera" x="1119" y="571.5">
|
<object id="1" name="camera" x="1119" y="571.5">
|
||||||
<point/>
|
<point/>
|
||||||
</object>
|
</object>
|
||||||
|
<object id="8" name="spawn" x="91.3333" y="665.333">
|
||||||
|
<point/>
|
||||||
|
</object>
|
||||||
|
<object id="9" name="p1" x="150" y="510">
|
||||||
|
<point/>
|
||||||
|
</object>
|
||||||
|
<object id="10" name="p2" x="226" y="353.333">
|
||||||
|
<point/>
|
||||||
|
</object>
|
||||||
|
<object id="11" name="p3" x="331.333" y="254">
|
||||||
|
<point/>
|
||||||
|
</object>
|
||||||
|
<object id="12" name="p4" x="458" y="214.667">
|
||||||
|
<point/>
|
||||||
|
</object>
|
||||||
|
<object id="13" name="p5" x="613.333" y="198.667">
|
||||||
|
<point/>
|
||||||
|
</object>
|
||||||
|
<object id="14" name="p6" x="744" y="226.667">
|
||||||
|
<point/>
|
||||||
|
</object>
|
||||||
|
<object id="15" name="p7" x="830.667" y="266.667">
|
||||||
|
<point/>
|
||||||
|
</object>
|
||||||
|
<object id="16" name="p8" x="912" y="325.333">
|
||||||
|
<point/>
|
||||||
|
</object>
|
||||||
|
<object id="17" name="p9" x="982" y="389.333">
|
||||||
|
<point/>
|
||||||
|
</object>
|
||||||
|
<object id="18" name="p10" x="1038.67" y="465.333">
|
||||||
|
<point/>
|
||||||
|
</object>
|
||||||
|
<object id="19" name="p11" x="1098.67" y="530">
|
||||||
|
<point/>
|
||||||
|
</object>
|
||||||
</objectgroup>
|
</objectgroup>
|
||||||
</map>
|
</map>
|
||||||
|
|||||||
Reference in New Issue
Block a user