Add gold mining

This commit is contained in:
2024-01-23 18:55:56 +01:00
parent d2ea703ea9
commit efd241d950
3 changed files with 29 additions and 28 deletions

View File

@@ -11,7 +11,6 @@
extern ECS_TAG_DECLARE(GameEntity);
typedef enum ResourceType {
RES_IRON,
RES_WOOD,
RES_GOLD,
RES_FOOD,
@@ -20,7 +19,6 @@ typedef enum ResourceType {
static const char *getResourceTypePrettyName(ResourceType type) {
switch (type) {
case RES_IRON: return "Iron";
case RES_WOOD: return "Wood";
case RES_GOLD: return "Gold";
case RES_FOOD: return "Food";

View File

@@ -45,6 +45,7 @@ typedef struct InputState {
enum {
CURSOR_NONE,
CURSOR_COLLECT_WOOD,
CURSOR_COLLECT_GOLD,
} cursor;
// INPUT_BUILDING

View File

@@ -82,41 +82,37 @@ void inputUnitAction(Game *game, InputState *input) {
input->cursor = CURSOR_NONE;
ecs_entity_t taskEntity;
if ((taskEntity = queryEntity(game->entityGrid, input->mouseWorld, Harvestable))) {
input->cursor = CURSOR_COLLECT_WOOD;
Resource resource = *ecs_get(ECS, taskEntity, Resource);
switch (resource.type) {
case RES_WOOD:
input->cursor = CURSOR_COLLECT_WOOD;
break;
case RES_GOLD:
input->cursor = CURSOR_COLLECT_GOLD;
break;
case RES_FOOD:
//input->cursor = CURSOR_COLLECT_FOOD;
break;
default:;
}
if (isInputBtnJustUp(input, actionBtn)) {
ecs_defer_begin(ECS);
ecs_iter_t it = ecs_query_iter(ECS, query);
while (ecs_query_next(&it)) {
for (i32 i = 0; i < it.count; i++) {
const ecs_entity_t entity = it.entities[i];
const Position target = *ecs_get(ECS, taskEntity, Position);
ecs_entity_t entity = it.entities[i];
Position target = *ecs_get(ECS, taskEntity, Position);
setAIBehaviour(entity, game->BTs.workerHarvest, &(AIBlackboard) {
.as.worker = {
.harvestType = RES_WOOD,
.harvestTarget = taskEntity,
.harvestPos = target,
},
.proximity = 6.0f,
.as.worker = {
.harvestType = resource.type,
.harvestTarget = taskEntity,
.harvestPos = target,
},
.proximity = 6.0f,
});
/*
setUnitAI(entity, game, &(const UnitAI) {
.type = AI_WORKER_HARVEST,
.as.workerHarvest.resource = RES_WOOD,
.as.workerHarvest.target = taskEntity,
.as.workerHarvest.targetPosition = target
});
*/
//addAction(entity, game, &(const Action) {
// .type = ACTION_MOVE_TO,
// .as.moveTo.target = target,
// .as.moveTo.proximityThreshold = 10.0f,
//});
//ecs_set(ECS, entity, HarvestTask, {taskEntity});
goto while_break;
}
}
while_break:
ecs_iter_fini(&it);
ecs_defer_end(ECS);
}
return;
@@ -348,6 +344,12 @@ void drawPlayerInputUI() {
DrawText("Collect wood", point.x, point.y, 10.0f, RED);
break;
}
case CURSOR_COLLECT_GOLD: {
const Vector2 point = input->mouseWorld;
DrawCircle(point.x, point.y, 2.0f, RED);
DrawText("Collect gold", point.x, point.y, 10.0f, RED);
break;
}
default: break;
}