resource renewal tests

This commit is contained in:
Connor
2026-02-15 23:01:19 +09:00
parent 5534b169d6
commit 01eaebeb71
2 changed files with 121 additions and 9 deletions

View File

@@ -37,9 +37,7 @@ inline void Flecs_Resource(flecs::world& world)
world.component<ResourceHealth>()
.member<uint16_t>("MaxHealth")
.member<uint16_t>("Health")
.member<uint16_t>("RenewalTicks")
.member<uint16_t>("Renewal");
.member<uint16_t>("Health");
world.component<ResourceTick>()
.is_a<TickAccumulator>();
@@ -50,9 +48,6 @@ inline void Flecs_Resource(flecs::world& world)
world.component<Renewing>()
.add<Freezes, ResourceTick>();
world.component<Renewing>()
.add<Freezes, ResourceTick>();
// harvesting resource to world inventory
world.system<const ResourceInfo, const ResourceTick, WorldInventory>()
.kind(flecs::OnUpdate)
@@ -70,11 +65,10 @@ inline void Flecs_Resource(flecs::world& world)
});
// decrease health if ResourceHealth component
world.system<const ResourceHealth, const ResourceTick>()
world.system<ResourceHealth, const ResourceTick>()
.kind(flecs::OnUpdate)
.without<Renewing>()
.each([](ResourceHealth& health, ResourceTick tick){
if (tick.)
health.Health -= tick.Finished();
});
@@ -91,7 +85,17 @@ inline void Flecs_Resource(flecs::world& world)
});
// finish renewing
world.system<ResourceHealth, RenewingTick>("Finish Renewing")
.kind(flecs::OnUpdate)
.with<Renewing>()
.each([](flecs::entity entity, ResourceHealth& health, RenewingTick& tick) {
if (tick.Finished()) {
health.Health = health.MaxHealth;
entity.remove<Renewing>();
entity.add<FullyGrown>();
entity.ensure<ResourceTick>().AccumulatedTick = 0;
}
});
}
inline void Resource_Ore_Helper(const flecs::entity& entity, uint16_t resourceID, uint16_t gatherTicks)
@@ -104,4 +108,21 @@ inline void Resource_Ore_Helper(const flecs::entity& entity, uint16_t resourceID
entity.set<ResourceInfo>(info);
entity.set<ResourceTick>(tick);
}
inline void Resource_Tree_Helper(const flecs::entity& entity, uint16_t resourceID,
uint16_t gatherTicks, uint16_t maxHealth, uint16_t renewalTicks)
{
Resource_Ore_Helper(entity, resourceID, gatherTicks);
ResourceHealth health{};
health.MaxHealth = maxHealth;
health.Health = maxHealth;
RenewingTick tick{};
tick.MaxTick = renewalTicks;
entity.set<ResourceHealth>(health);
entity.set<RenewingTick>(tick);
entity.add<FullyGrown>();
}