Implement harvest worker AI

This commit is contained in:
2023-12-17 14:20:13 +01:00
parent 5564df4768
commit 33b28b620d
14 changed files with 338 additions and 40 deletions

View File

@@ -4,6 +4,8 @@
#include "game_state.h"
#include "map_layers.h"
#include <raymath.h>
bool canPlaceBuilding(BzTileMap *map, BuildingType type, BzTile tileX, BzTile tileY) {
i32 sizeX, sizeY;
getBuildingSize(type, &sizeX, &sizeY);
@@ -73,3 +75,20 @@ ecs_entity_t placeBuilding(BzTileMap *map, BuildingType type, BzTile tileX, BzTi
return e;
}
Vector2 getPositionNearBuilding(ecs_entity_t building, Vector2 fromPos) {
BZ_ASSERT(ecs_is_alive(ECS, building));
BZ_ASSERT(ecs_has(ECS, building, Position));
BZ_ASSERT(ecs_has(ECS, building, Size));
Vector2 pos = *ecs_get(ECS, building, Position);
Vector2 size = *ecs_get(ECS, building, Size);
size = Vector2SubtractValue(size, 10.0f);
Vector2 dir = Vector2Normalize(Vector2Subtract(fromPos, pos));
dir = Vector2Multiply(dir, size);
pos = Vector2Add(pos, dir);
return pos;
}