add tree station spawning and removing

This commit is contained in:
Rokas Puzonas 2026-07-17 02:41:44 +03:00
parent b4173ec95b
commit 2de74dfa36

View File

@ -224,6 +224,7 @@ const Upgrades = struct {
minion_carry_capacity: u32 = 1, minion_carry_capacity: u32 = 1,
minion_walk: MinionWalkStats = .{}, minion_walk: MinionWalkStats = .{},
tree_station_count: u32 = 0,
tree_health: u32 = 10, tree_health: u32 = 10,
tree_respawn_duration: Nanoseconds = std.time.ns_per_s, tree_respawn_duration: Nanoseconds = std.time.ns_per_s,
tree_wood_amount: u32 = 1, tree_wood_amount: u32 = 1,
@ -309,8 +310,6 @@ pub fn init(self: *App, plt: Platform.Init) !?u8 {
.upgrades = .{} .upgrades = .{}
}; };
self.spawnWoodStation(-100);
self.spawnWoodStation(-150);
self.spawnBurnStation(100); self.spawnBurnStation(100);
self.spawnBurnStation(150); self.spawnBurnStation(150);
@ -729,6 +728,17 @@ fn removeMinion(self: *App, minion_id: EntityId) void {
self.entities.removeAssumeExists(minion_id); self.entities.removeAssumeExists(minion_id);
} }
fn removeWoodStation(self: *App, id: EntityId) void {
const wood_station = self.entities.get(id) orelse return;
assert(wood_station.type == .wood_station);
if (wood_station.station_owned_tree) |tree_id| {
self.entities.removeAssumeExists(tree_id);
}
self.entities.removeAssumeExists(id);
}
fn getBurnMultiplier(self: *App) u32 { fn getBurnMultiplier(self: *App) u32 {
const stack_size = self.countEternalFlameStackSize(); const stack_size = self.countEternalFlameStackSize();
@ -786,6 +796,41 @@ pub fn frame(self: *App, plt: Platform.Frame) !void {
} }
} }
{ // Spawn in or delete wood stations
var station_count: u32 = 0;
{
var wood_station_iter = self.initEntityIteratorByType(.wood_station);
while (wood_station_iter.next()) |_| {
station_count += 1;
}
}
const wood_station_first_pos = -100;
const wood_station_step = -50;
if (station_count > self.upgrades.tree_station_count) {
for (self.upgrades.tree_station_count..station_count) |i| {
// Remove the last wood station that was added
var wood_station_iter = self.initEntityIteratorByType(.wood_station);
while (wood_station_iter.next()) |wood_station_id| {
const wood_station = self.entities.getAssumeExists(wood_station_id);
const i_f32: f32 = @floatFromInt(i);
const expected_x = wood_station_first_pos + wood_station_step * i_f32;
if (wood_station.pos.x == expected_x) {
self.removeWoodStation(wood_station_id);
break;
}
}
}
} else if (station_count < self.upgrades.tree_station_count) {
for (station_count..self.upgrades.tree_station_count) |i| {
const i_f32: f32 = @floatFromInt(i);
self.spawnWoodStation(wood_station_first_pos + wood_station_step * i_f32);
}
}
}
{ // Spawn trees at wood station on a cooldown { // Spawn trees at wood station on a cooldown
var wood_station_iter = self.initEntityIteratorByType(.wood_station); var wood_station_iter = self.initEntityIteratorByType(.wood_station);
while (wood_station_iter.next()) |wood_station_id| { while (wood_station_iter.next()) |wood_station_id| {
@ -1164,6 +1209,7 @@ pub fn frame(self: *App, plt: Platform.Frame) !void {
ImGUI.separator(); ImGUI.separator();
_ = ImGUI.text("Tree upgrades", .{}); _ = ImGUI.text("Tree upgrades", .{});
_ = ImGUI.inputU32("station_count", &self.upgrades.tree_station_count);
_ = ImGUI.inputU32("health", &self.upgrades.tree_health); _ = ImGUI.inputU32("health", &self.upgrades.tree_health);
_ = ImGUI.inputU32("wood_amount", &self.upgrades.tree_wood_amount); _ = ImGUI.inputU32("wood_amount", &self.upgrades.tree_wood_amount);
_ = ImGUI.inputDuration("respawn_duration", &self.upgrades.tree_respawn_duration); _ = ImGUI.inputDuration("respawn_duration", &self.upgrades.tree_respawn_duration);