Improve unit recruiting
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "../game_state.h"
|
||||
#include "../input.h"
|
||||
#include "../pathfinding.h"
|
||||
#include "../entity_factory.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <raymath.h>
|
||||
@@ -236,6 +237,38 @@ void entityFollowPath(ecs_iter_t *it) {
|
||||
}
|
||||
}
|
||||
|
||||
void updateBuildingRecruitment(ecs_iter_t *it) {
|
||||
Game *game = ecs_singleton_get_mut(ECS, Game);
|
||||
Owner *owner = ecs_field(it, Owner, 1);
|
||||
Building *building = ecs_field(it, Building, 2);
|
||||
BuildingRecruitInfo *info = ecs_field(it, BuildingRecruitInfo, 3);
|
||||
|
||||
f32 dt = GetFrameTime();
|
||||
for (i32 i = 0; i < it->count; i++) {
|
||||
Player player = owner[i].player;
|
||||
Vector2 placePos = {
|
||||
(building[i].pos.x + building[i].size.x * 0.5f) * 16.0f,
|
||||
(building[i].pos.y + building->size.y + 0.5f) * 16.0f
|
||||
};
|
||||
placePos.x += GetRandomValue(-building[i].size.x, building[i].size.x);
|
||||
placePos.y += GetRandomValue(-4, 4);
|
||||
|
||||
for (i32 slotIdx = 0; slotIdx < info[i].numSlots; i++) {
|
||||
BuildingRecruitSlot *slot = &info[i].slots[slotIdx];
|
||||
|
||||
if (slot->numRecruiting <= 0) continue;
|
||||
slot->elapsed += dt;
|
||||
if (slot->elapsed >= slot->recruitTime) {
|
||||
slot->elapsed = 0;
|
||||
bzLogInfo("spawned");
|
||||
entityRecruit(slot->entityType, placePos, player, game);
|
||||
slot->numRecruiting--;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void renderColliders(ecs_iter_t *it) {
|
||||
Position *pos = ecs_field(it, Position, 1);
|
||||
HitBox *hitbox = ecs_field(it, HitBox , 2);
|
||||
|
||||
Reference in New Issue
Block a user