Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Ext/TechnoType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@ class TechnoTypeExt : public ObjectTypeExt
void ApplyTurretOffset(Matrix3D* mtx, double factor = 1.0);
void CalculateSpawnerRange();
bool IsSecondary(int nWeaponIndex) const;
const std::string GetGunnerID(int idx) const;

int SelectForceWeapon(TechnoClass* pThis, AbstractClass* pTarget) const;
int SelectMultiWeapon(TechnoClass* const pThis, AbstractClass* const pTarget) const;
Expand Down
33 changes: 20 additions & 13 deletions src/Misc/Selection.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <Utilities/AresHelper.h>
#include <Ext/Techno/Body.h>

#include <format>

class ExtSelection
{
public:
Expand All @@ -26,7 +28,7 @@ class ExtSelection
} Array {};

static inline bool ProcessingIDMatches = false;
static inline std::vector<const char*> IFVGroups;
static inline std::vector<std::string> IFVGroups;

// Reversed from Is_Selectable, w/o Select call
static bool ObjectClass_IsSelectable(ObjectClass* pThis)
Expand Down Expand Up @@ -135,12 +137,9 @@ class ExtSelection

if (pTechnoType->Gunner && !ExtSelection::IFVGroups.empty())
{
char* gunnerID = pTypeExt->WeaponGroupAs[pTechno->CurrentWeaponNumber];

if (!GeneralUtils::IsValidString(gunnerID))
sprintf_s(gunnerID, 0x20, "%d", RulesExt::Global()->TypeSelectUseIFVMode && Phobos::Config::TypeSelectUseIFVMode ? pTechno->CurrentWeaponNumber + 1 : 0);
const std::string gunnerID = pTypeExt->GetGunnerID(pTechno->CurrentWeaponNumber);

if (std::ranges::none_of(ExtSelection::IFVGroups, [gunnerID](const char* pID) { return !_stricmp(pID, gunnerID); }))
if (std::ranges::none_of(ExtSelection::IFVGroups, [gunnerID](const std::string& id) { return !_stricmp(id.c_str(), gunnerID.c_str()); }))
break;
}

Expand Down Expand Up @@ -186,10 +185,21 @@ DEFINE_FUNCTION_JUMP(CALL, 0x4ABCEB, ExtSelection::Tactical_MakeFilteredSelectio
// Replace vanilla function. For in case another module tries to call the vanilla function at offset
DEFINE_FUNCTION_JUMP(LJMP, 0x6D9FF0, ExtSelection::Tactical_MakeFilteredSelection)

DEFINE_HOOK(0x73298D, TypeSelectExecute_UseIFVMode, 0x5)
const std::string TechnoTypeExt::GetGunnerID(int idx) const
{
const bool useIFVMode = RulesExt::Global()->TypeSelectUseIFVMode && Phobos::Config::TypeSelectUseIFVMode;
if (idx < static_cast<int>(this->WeaponGroupAs.size()))
{
const char* pWeaponGroup = this->WeaponGroupAs[idx];

if (GeneralUtils::IsValidString(pWeaponGroup))
return std::string(pWeaponGroup);
}

return std::format("{}", RulesExt::Global()->TypeSelectUseIFVMode && Phobos::Config::TypeSelectUseIFVMode ? idx + 1 : 0);
}

DEFINE_HOOK(0x73298D, TypeSelectExecute_UseIFVMode, 0x5)
{
for (const auto pObject : ObjectClass::CurrentObjects)
{
const auto pTechno = abstract_cast<TechnoClass*, true>(pObject);
Expand All @@ -203,12 +213,9 @@ DEFINE_HOOK(0x73298D, TypeSelectExecute_UseIFVMode, 0x5)
continue;

const auto pTypeExt = TechnoTypeExt::Fetch(pTechnoType);
char* gunnerID = pTypeExt->WeaponGroupAs[pTechno->CurrentWeaponNumber];

if (!GeneralUtils::IsValidString(gunnerID))
sprintf_s(gunnerID, 0x20, "%d", useIFVMode ? pTechno->CurrentWeaponNumber + 1 : 0);
const std::string gunnerID = pTypeExt->GetGunnerID(pTechno->CurrentWeaponNumber);

if (std::ranges::none_of(ExtSelection::IFVGroups, [gunnerID](const char* pID) { return !_stricmp(pID, gunnerID); }))
if (std::ranges::none_of(ExtSelection::IFVGroups, [gunnerID](const std::string& id) { return !_stricmp(id.c_str(), gunnerID.c_str()); }))
ExtSelection::IFVGroups.emplace_back(gunnerID);
}

Expand Down
Loading