Skip to content

Commit

Permalink
temporary tank-finding algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
z-adams committed Jan 30, 2021
1 parent dbda6c0 commit d0f4f7b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/adera/Machines/Rocket.cpp
Expand Up @@ -244,7 +244,25 @@ Machine& SysMachineRocket::instantiate(ActiveEnt ent, PrototypeMachine config,
DependRes<ShipResourceType> fuel = pkg.get<ShipResourceType>("fuel");
if (!fuel.empty())
{
ActiveEnt fuelSource = static_cast<ActiveEnt>(13);
// TMP: finds the first non-empty fuel tank in the ship
// Only works as long as the fuselage is added before the engine

ActiveEnt foundTank = entt::null;
auto find_fuel = [this, &foundTank](ActiveEnt e)
{
if (auto* fuel = this->m_scene.reg_try_get<MachineContainer>(e);
fuel != nullptr && fuel->check_contents().m_quantity > 0)
{
foundTank = e;
return EHierarchyTraverseStatus::Stop;
}
return EHierarchyTraverseStatus::Continue;
};
auto const& parent = m_scene.reg_get<ACompHierarchy>(ent);
m_scene.hierarchy_traverse(parent.m_parent, find_fuel);
// endTMP

ActiveEnt fuelSource = foundTank;
MachineRocket::ResourceInput input = {std::move(fuel), 1.0f, fuelSource};
inputs.push_back(std::move(input));
}
Expand Down

0 comments on commit d0f4f7b

Please sign in to comment.