Skip to content

Commit

Permalink
Implement autoload hotkey
Browse files Browse the repository at this point in the history
  • Loading branch information
psi-cmd committed Dec 14, 2024
1 parent 0e604e4 commit 7bc526b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Phobos.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<ClCompile Include="src\Commands\ToggleDesignatorRange.cpp" />
<ClCompile Include="src\Commands\ToggleDigitalDisplay.cpp" />
<ClCompile Include="src\Commands\SaveVariablesToFile.cpp" />
<ClCompile Include="src\Commands\AutoLoad.cpp" />
<ClCompile Include="src\Ext\Anim\Body.cpp" />
<ClCompile Include="src\Ext\Anim\Hooks.cpp" />
<ClCompile Include="src\Ext\Anim\Hooks.AnimCreateUnit.cpp" />
Expand Down Expand Up @@ -195,6 +196,7 @@
<ClInclude Include="src\Commands\ToggleDesignatorRange.h" />
<ClInclude Include="src\Commands\ToggleDigitalDisplay.h" />
<ClInclude Include="src\Commands\SaveVariablesToFile.h" />
<ClInclude Include="src\Commands\AutoLoad.h" />
<ClInclude Include="src\Ext\Bullet\Trajectories\BombardTrajectory.h" />
<ClInclude Include="src\Ext\Bullet\Trajectories\PhobosTrajectory.h" />
<ClInclude Include="src\Ext\Bullet\Trajectories\StraightTrajectory.h" />
Expand Down
15 changes: 6 additions & 9 deletions src/Commands/AutoLoad.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// for selected units, pair the loadable vehicle and units.
// first only apply to infantry.
// For selected units, pair the loadable vehicle and infantry.
// 1. If transport can load vehicle, it won't load if the vehicle can be paired with infantry.
// 2. It will always try to load the unit type with least amount of units, eg. 2 GI and 3 GGI, it will match 2 GI to transport first.
// 3. For transport with multiple seats, it will try to fill the seats diversely.

#include "AutoLoad.h"
#include "Utilities/GeneralUtils.h"
Expand Down Expand Up @@ -66,7 +68,6 @@ void SpreadPassengersToTransports(std::vector<P>& pPassengers, std::vector<std::
passengerMap[pID].push_back(pPassenger);
}

DebugPrintPassenger(pPassengers);

while (true)
{
Expand Down Expand Up @@ -94,7 +95,7 @@ void SpreadPassengersToTransports(std::vector<P>& pPassengers, std::vector<std::
pPassenger->QueueMission(Mission::Enter, false);
pPassenger->SetTarget(nullptr);
pPassenger->SetDestination(pTransport, true);
tTransports[index].second += static_cast<int>(pPassenger->GetTechnoType()->Size); // increase the virtual size of transport
tTransports[index].second += abstract_cast<TechnoClass*>(pPassenger)->GetTechnoType()->Size; // increase the virtual size of transport
}
}
passengerMap[leastpID].erase(passengerMap[leastpID].begin(), passengerMap[leastpID].begin() + index);
Expand All @@ -107,7 +108,6 @@ void SpreadPassengersToTransports(std::vector<P>& pPassengers, std::vector<std::
}),
tTransports.end()
);
DebugPrintTransport(tTransports);

if (passengerMap[leastpID].size() == 0)
{
Expand Down Expand Up @@ -141,17 +141,15 @@ void AutoLoadCommandClass::Execute(WWKey eInput) const
// full vehicle may be passenger.
std::vector<TechnoClass*> mayBePassengerArray;
// get current selected units.
Debug::Log("AutoLoadCommandClass::Execute: Selected units count: %d\n", ObjectClass::CurrentObjects->Count);
for (int i = 0; i < ObjectClass::CurrentObjects->Count; i++)
{
auto pUnit = ObjectClass::CurrentObjects->GetItem(i);
// try to cast to TechnoClass
TechnoClass* pTechno = static_cast<TechnoClass*>(pUnit);
TechnoClass* pTechno = abstract_cast<TechnoClass*>(pUnit);

if (pTechno && pTechno->WhatAmI() == AbstractType::Infantry && !pTechno->IsInAir())
{
infantryIndexArray.push_back(pTechno);
Debug::Log("AutoLoadCommandClass::Execute: Infantry index: %d\n", i);
}
else if (pTechno && pTechno->WhatAmI() == AbstractType::Unit && !pTechno->IsInAir())
{
Expand All @@ -163,7 +161,6 @@ void AutoLoadCommandClass::Execute(WWKey eInput) const
if (pTechno->GetTechnoType()->SizeLimit > 2)
{
largeVehicleIndexArray.push_back(std::make_pair(pTechno, pTechno->Passengers.GetTotalSize()));
Debug::Log("AutoLoadCommandClass::Execute: Large Vehicle index: %d, Passengers: %d\n", i, pTechno->Passengers.GetTotalSize());
}
else
{
Expand Down

0 comments on commit 7bc526b

Please sign in to comment.