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;
|
||||
ecs_set_ptr(ECS, building, TextureRegion, ®ion);
|
||||
|
||||
bzTileMapSetCollisions(&game->map, true, COLL_LAYER_BUILDINGS, posX, posY, sizeX, sizeY);
|
||||
bool hasCollision = true;
|
||||
|
||||
switch (type) {
|
||||
case BUILDING_KEEP:
|
||||
ecs_set(ECS, building, AddPopCapacity, {10});
|
||||
ecs_add_id(ECS, building, Storage);
|
||||
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:
|
||||
break;
|
||||
}
|
||||
|
||||
if (hasCollision)
|
||||
bzTileMapSetCollisions(&game->map, true, COLL_LAYER_BUILDINGS, posX, posY, sizeX, sizeY);
|
||||
|
||||
return building;
|
||||
|
||||
}
|
||||
@@ -166,12 +175,14 @@ Vector2 getPositionNearBuilding(ecs_entity_t building, Vector2 fromPos) {
|
||||
Vector2 pos = *ecs_get(ECS, building, Position);
|
||||
HitBox hitbox = *ecs_get(ECS, building, HitBox);
|
||||
|
||||
Vector2 center = entityGetCenter(pos, hitbox);
|
||||
|
||||
Vector2 size = {hitbox.width, hitbox.height};
|
||||
size = Vector2SubtractValue(size, 10.0f);
|
||||
|
||||
Vector2 dir = Vector2Normalize(Vector2Subtract(fromPos, pos));
|
||||
Vector2 dir = Vector2Normalize(Vector2Subtract(fromPos, center));
|
||||
dir = Vector2Multiply(dir, size);
|
||||
|
||||
pos = Vector2Add(pos, dir);
|
||||
return pos;
|
||||
center = Vector2Add(center, dir);
|
||||
return center;
|
||||
}
|
||||
|
||||
@@ -208,11 +208,10 @@ typedef struct Building {
|
||||
Vec2i pos;
|
||||
Vec2i size;
|
||||
} Building;
|
||||
extern ECS_COMPONENT_DECLARE(Building);
|
||||
extern ECS_TAG_DECLARE(Storage);
|
||||
extern ECS_COMPONENT_DECLARE(Building);
|
||||
extern ECS_TAG_DECLARE(Harvestable);
|
||||
extern ECS_TAG_DECLARE(Buildable);
|
||||
extern ECS_TAG_DECLARE(Workable);
|
||||
extern ECS_TAG_DECLARE(Attackable);
|
||||
|
||||
void initComponentIDs(ecs_world_t *ecs);
|
||||
|
||||
@@ -37,8 +37,6 @@ static OwnerType getOwnerType(BzTileID tile) {
|
||||
typedef enum TerrainType {
|
||||
TERRAIN_NONE = -1,
|
||||
TERRAIN_GOLD_ORE,
|
||||
TERRAIN_WHEAT_0,
|
||||
TERRAIN_WHEAT_1,
|
||||
TERRAIN_COUNT,
|
||||
} TerrainType;
|
||||
|
||||
@@ -295,6 +293,8 @@ typedef enum BuildingType {
|
||||
BUILDING_MARKET,
|
||||
BUILDING_MILL,
|
||||
BUILDING_WAREHOUSE,
|
||||
BUILDING_WHEAT_0,
|
||||
BUILDING_WHEAT_1,
|
||||
BUILDING_COUNT,
|
||||
} BuildingType;
|
||||
|
||||
@@ -307,6 +307,10 @@ static BuildingType getTileBuilding(BzTileID tile) {
|
||||
case 5910:
|
||||
case 5911:
|
||||
return BUILDING_KEEP;
|
||||
case 6400:
|
||||
return BUILDING_WHEAT_1;
|
||||
case 6401:
|
||||
return BUILDING_WHEAT_0;
|
||||
case 6405:
|
||||
case 6406:
|
||||
return BUILDING_ARCHERY_RANGE;
|
||||
@@ -345,6 +349,8 @@ static BzTileID getBuildingTile(BuildingType type) {
|
||||
switch (type) {
|
||||
case BUILDING_BARRACKS: return 5638;
|
||||
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_WAREHOUSE: return 6433;
|
||||
case BUILDING_HOUSE_01: return 6666;
|
||||
@@ -367,6 +373,8 @@ static const char *getBuildingStr(BuildingType type) {
|
||||
switch (type) {
|
||||
case BUILDING_BARRACKS: return "barracks";
|
||||
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_WAREHOUSE: return "warehouse";
|
||||
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 (outHeight) *outHeight = 2;
|
||||
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:
|
||||
if (outWidth) *outWidth = 2;
|
||||
if (outHeight) *outHeight = 1;
|
||||
@@ -1707,8 +1723,6 @@ static bool hasEntityHitBoxRec(BzTile tile) {
|
||||
case 5891:
|
||||
case 6146:
|
||||
case 6147:
|
||||
case 6400:
|
||||
case 6401:
|
||||
case 6402:
|
||||
case 6403:
|
||||
case 6656:
|
||||
@@ -1734,8 +1748,6 @@ static Rectangle getEntityHitBoxRec(BzTile tile) {
|
||||
case 5891: return (Rectangle) {6, 2, 4, 10};
|
||||
case 6146: 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 6403: 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("Storage", ECS, entity, Storage);
|
||||
igTagCheckbox("Harvestable", ECS, entity, Harvestable);
|
||||
igTagCheckbox("Workable", ECS, entity, Workable);
|
||||
igTagCheckbox("Attackable", ECS, entity, Attackable);
|
||||
}
|
||||
if (ecs_has(ECS, entity, BzBTState) &&
|
||||
|
||||
@@ -106,13 +106,20 @@ void inputUnitAction(Game *game, InputState *input) {
|
||||
ecs_entity_t entity = it.entities[i];
|
||||
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) {
|
||||
.as.worker = {
|
||||
.harvestType = resource.type,
|
||||
.harvestTarget = taskEntity,
|
||||
.harvestPos = target,
|
||||
},
|
||||
.proximity = 6.0f,
|
||||
.proximity = proximity,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ void drawGameUI(Game *game, f32 dt) {
|
||||
BUILDING_WAREHOUSE,
|
||||
BUILDING_MARKET,
|
||||
BUILDING_MILL,
|
||||
BUILDING_HOUSE_02, // placeholder for farm
|
||||
BUILDING_WHEAT_0,
|
||||
BUILDING_BARRACKS,
|
||||
BUILDING_ARCHERY_RANGE
|
||||
};
|
||||
|
||||
@@ -7859,32 +7859,9 @@
|
||||
},
|
||||
{
|
||||
"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":[
|
||||
{
|
||||
"name":"terrain",
|
||||
"name":"building",
|
||||
"type":"string",
|
||||
"value":""
|
||||
}],
|
||||
@@ -7892,32 +7869,9 @@
|
||||
},
|
||||
{
|
||||
"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":[
|
||||
{
|
||||
"name":"terrain",
|
||||
"name":"building",
|
||||
"type":"string",
|
||||
"value":""
|
||||
}],
|
||||
|
||||
@@ -2894,19 +2894,13 @@
|
||||
</tile>
|
||||
<tile id="6400" type="wheat_1">
|
||||
<properties>
|
||||
<property name="terrain" value=""/>
|
||||
<property name="building" value=""/>
|
||||
</properties>
|
||||
<objectgroup draworder="index" id="2">
|
||||
<object id="1" name="hitbox" x="4" y="4" width="8" height="10"/>
|
||||
</objectgroup>
|
||||
</tile>
|
||||
<tile id="6401" type="wheat_0">
|
||||
<properties>
|
||||
<property name="terrain" value=""/>
|
||||
<property name="building" value=""/>
|
||||
</properties>
|
||||
<objectgroup draworder="index" id="2">
|
||||
<object id="1" name="hitbox" x="4" y="4" width="8" height="10"/>
|
||||
</objectgroup>
|
||||
</tile>
|
||||
<tile id="6402">
|
||||
<properties>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?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>
|
||||
<export target="maps/map_01.tmj" format="json"/>
|
||||
</editorsettings>
|
||||
@@ -393,5 +393,41 @@
|
||||
<object id="1" name="camera" x="1119" y="571.5">
|
||||
<point/>
|
||||
</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>
|
||||
</map>
|
||||
|
||||
Reference in New Issue
Block a user