Skip to content

Commit

Permalink
Move TypeConvertGroup out of Misc folder
Browse files Browse the repository at this point in the history
  • Loading branch information
chaserli committed Feb 18, 2024
1 parent 68b3481 commit 7185414
Show file tree
Hide file tree
Showing 16 changed files with 118 additions and 159 deletions.
4 changes: 2 additions & 2 deletions Phobos.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
<ClCompile Include="src\Misc\Hooks.LaserDraw.cpp" />
<ClCompile Include="src\Misc\Hooks.Timers.cpp" />
<ClCompile Include="src\Misc\Hooks.INIInheritance.cpp" />
<ClCompile Include="src\Misc\TypeConvertHelper.cpp" />
<ClCompile Include="src\New\Type\Affiliated\TypeConvertGroup.cpp" />
<ClCompile Include="src\Ext\BuildingType\Hooks.Upgrade.cpp" />
<ClCompile Include="src\Phobos.COM.cpp" />
<ClCompile Include="src\Phobos.CRT.cpp" />
Expand Down Expand Up @@ -199,7 +199,7 @@
<ClInclude Include="src\Misc\FlyingStrings.h" />
<ClInclude Include="src\Misc\PhobosToolTip.h" />
<ClInclude Include="src\Misc\SyncLogging.h" />
<ClInclude Include="src\Misc\TypeConvertHelper.h" />
<ClInclude Include="src\New\Type\Affiliated\TypeConvertGroup.h" />
<ClInclude Include="src\New\Type\DigitalDisplayTypeClass.h" />
<ClInclude Include="src\New\Type\RadTypeClass.h" />
<ClInclude Include="src\New\Type\ShieldTypeClass.h" />
Expand Down
2 changes: 1 addition & 1 deletion YRpp
12 changes: 5 additions & 7 deletions src/Ext/BuildingType/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,15 @@ DEFINE_HOOK(0x6D528A, TacticalClass_DrawPlacement_PlacementPreview, 0x6)
nImageFrame = Math::clamp(pTypeExt->PlacementPreview_ShapeFrame.Get(nImageFrame), 0, (int)pImage->Frames);
}

Point2D nPoint = { 0, 0 };
{

CoordStruct offset = pTypeExt->PlacementPreview_Offset;
int nHeight = offset.Z + pCell->GetFloorHeight({ 0, 0 });
TacticalClass::Instance->CoordsToClient(
CellClass::Cell2Coord(pCell->MapCoords, nHeight),
&nPoint
);
Point2D nPoint = TacticalClass::Instance->CoordsToClient(
CellClass::Cell2Coord(pCell->MapCoords, nHeight)
).first;
nPoint.X += offset.X;
nPoint.Y += offset.Y;
}


BlitterFlags blitFlags = pTypeExt->PlacementPreview_Translucency.Get(pRules->PlacementPreview_Translucency) |
BlitterFlags::Centered | BlitterFlags::Nonzero | BlitterFlags::MultiPass;
Expand Down
7 changes: 3 additions & 4 deletions src/Ext/Bullet/Hooks.DetonateLogics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
#include <Ext/CaptureManager/Body.h>
#include <Ext/WarheadType/Body.h>
#include <Ext/WeaponType/Body.h>
#include <Ext/Techno/Body.h>

#include <AircraftClass.h>
#include <BuildingClass.h>
#include <InfantryClass.h>
#include <TacticalClass.h>

DEFINE_HOOK(0x4692BD, BulletClass_Logics_ApplyMindControl, 0x6)
Expand All @@ -31,9 +30,9 @@ DEFINE_HOOK(0x4690D4, BulletClass_Logics_ScreenShake, 0x6)

if (auto const pExt = WarheadTypeExt::ExtMap.Find(pWarhead))
{
Point2D screenCoords;
auto&& [_, visible] = TacticalClass::Instance->CoordsToClient(*pCoords);

if (pExt->ShakeIsLocal && !TacticalClass::Instance->CoordsToClient(*pCoords, &screenCoords))
if (pExt->ShakeIsLocal && !visible)
return SkipShaking;
}

Expand Down
37 changes: 1 addition & 36 deletions src/Ext/SWType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,42 +141,7 @@ void SWTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->Detonate_AtFirer.Read(exINI, pSection, "Detonate.AtFirer");

// Convert.From & Convert.To
for (size_t i = 0; ; ++i)
{
ValueableVector<TechnoTypeClass*> convertFrom;
Nullable<TechnoTypeClass*> convertTo;
Nullable<AffectedHouse> convertAffectedHouses;
_snprintf_s(tempBuffer, sizeof(tempBuffer), "Convert%d.From", i);
convertFrom.Read(exINI, pSection, tempBuffer);
_snprintf_s(tempBuffer, sizeof(tempBuffer), "Convert%d.To", i);
convertTo.Read(exINI, pSection, tempBuffer);
_snprintf_s(tempBuffer, sizeof(tempBuffer), "Convert%d.AffectedHouses", i);
convertAffectedHouses.Read(exINI, pSection, tempBuffer);

if (!convertTo.isset())
break;

if (!convertAffectedHouses.isset())
convertAffectedHouses = AffectedHouse::Owner;

this->Convert_Pairs.push_back({ convertFrom, convertTo, convertAffectedHouses });
}
ValueableVector<TechnoTypeClass*> convertFrom;
Nullable<TechnoTypeClass*> convertTo;
Nullable<AffectedHouse> convertAffectedHouses;
convertFrom.Read(exINI, pSection, "Convert.From");
convertTo.Read(exINI, pSection, "Convert.To");
convertAffectedHouses.Read(exINI, pSection, "Convert.AffectedHouses");
if (convertTo.isset())
{
if (!convertAffectedHouses.isset())
convertAffectedHouses = AffectedHouse::Owner;

if (this->Convert_Pairs.size())
this->Convert_Pairs[0] = { convertFrom, convertTo, convertAffectedHouses };
else
this->Convert_Pairs.push_back({ convertFrom, convertTo, convertAffectedHouses });
}
TypeConvertGroup::Parse(this->Convert_Pairs, exINI, pSection, AffectedHouse::Owner);

this->ShowDesignatorRange.Read(exINI, pSection, "ShowDesignatorRange");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ext/SWType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <Utilities/TemplateDef.h>

#include <Ext/Building/Body.h>
#include <Misc/TypeConvertHelper.h>
#include <New/Type/Affiliated/TypeConvertGroup.h>

class SWTypeExt
{
Expand Down
2 changes: 1 addition & 1 deletion src/Ext/SWType/FireSuperWeapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,5 +312,5 @@ void SWTypeExt::ExtData::ApplyTypeConversion(SuperClass* pSW)
return;

for (const auto pTargetFoot : *FootClass::Array)
TypeConvertHelper::Convert(pTargetFoot, this->Convert_Pairs, pSW->Owner);
TypeConvertGroup::Convert(pTargetFoot, this->Convert_Pairs, pSW->Owner);
}
10 changes: 2 additions & 8 deletions src/Ext/Techno/Body.Visuals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,7 @@ void TechnoExt::DrawInsignia(TechnoClass* pThis, Point2D* pLocation, RectangleSt

Point2D TechnoExt::GetScreenLocation(TechnoClass* pThis)
{
CoordStruct absolute = pThis->GetCoords();
Point2D position = { 0,0 };
TacticalClass::Instance->CoordsToScreen(&position, &absolute);
position -= TacticalClass::Instance->TacticalPos;

return position;
return TacticalClass::Instance->CoordsToClient(pThis->GetCoords()).first;
}

Point2D TechnoExt::GetFootSelectBracketPosition(TechnoClass* pThis, Anchor anchor)
Expand Down Expand Up @@ -264,9 +259,8 @@ Point2D TechnoExt::GetBuildingSelectBracketPosition(TechnoClass* pThis, Building
Point2D position = GetScreenLocation(pThis);
CoordStruct dim2 = CoordStruct::Empty;
pBuildingType->Dimension2(&dim2);
Point2D positionFix = Point2D::Empty;
dim2 = { -dim2.X / 2, dim2.Y / 2, dim2.Z };
TacticalClass::Instance->CoordsToScreen(&positionFix, &dim2);
Point2D positionFix = TacticalClass::CoordsToScreen(dim2);

const int foundationWidth = pBuildingType->GetFoundationWidth();
const int foundationHeight = pBuildingType->GetFoundationHeight(false);
Expand Down
4 changes: 2 additions & 2 deletions src/Ext/TechnoType/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ DEFINE_HOOK(0x73CCE1, UnitClass_DrawSHP_TurretOffest, 0x6)

auto res = Matrix3D::MatrixMultiply(mtx, Vector3D<float>::Empty);
auto location = CoordStruct { static_cast<int>(res.X), static_cast<int>(-res.Y), static_cast<int>(res.Z) };
Point2D temp;
pos += *TacticalClass::Instance()->CoordsToScreen(&temp, &location);

pos += TacticalClass::CoordsToScreen(location);

return 0;
}
Expand Down
38 changes: 1 addition & 37 deletions src/Ext/WarheadType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,44 +197,8 @@ void WarheadTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->DetonateOnAllMapObjects_AffectTypes.Read(exINI, pSection, "DetonateOnAllMapObjects.AffectTypes");
this->DetonateOnAllMapObjects_IgnoreTypes.Read(exINI, pSection, "DetonateOnAllMapObjects.IgnoreTypes");

char tempBuffer[32];
// Convert.From & Convert.To
for (size_t i = 0; ; ++i)
{
ValueableVector<TechnoTypeClass*> convertFrom;
Nullable<TechnoTypeClass*> convertTo;
Nullable<AffectedHouse> convertAffectedHouses;
_snprintf_s(tempBuffer, sizeof(tempBuffer), "Convert%d.From", i);
convertFrom.Read(exINI, pSection, tempBuffer);
_snprintf_s(tempBuffer, sizeof(tempBuffer), "Convert%d.To", i);
convertTo.Read(exINI, pSection, tempBuffer);
_snprintf_s(tempBuffer, sizeof(tempBuffer), "Convert%d.AffectedHouses", i);
convertAffectedHouses.Read(exINI, pSection, tempBuffer);

if (!convertTo.isset())
break;

if (!convertAffectedHouses.isset())
convertAffectedHouses = AffectedHouse::All;

this->Convert_Pairs.push_back({ convertFrom, convertTo, convertAffectedHouses });
}
ValueableVector<TechnoTypeClass*> convertFrom;
Nullable<TechnoTypeClass*> convertTo;
Nullable<AffectedHouse> convertAffectedHouses;
convertFrom.Read(exINI, pSection, "Convert.From");
convertTo.Read(exINI, pSection, "Convert.To");
convertAffectedHouses.Read(exINI, pSection, "Convert.AffectedHouses");
if (convertTo.isset())
{
if (!convertAffectedHouses.isset())
convertAffectedHouses = AffectedHouse::All;

if (this->Convert_Pairs.size())
this->Convert_Pairs[0] = { convertFrom, convertTo, convertAffectedHouses };
else
this->Convert_Pairs.push_back({ convertFrom, convertTo, convertAffectedHouses });
}
TypeConvertGroup::Parse(this->Convert_Pairs, exINI, pSection, AffectedHouse::All);

#ifdef LOCO_TEST_WARHEADS // Enable warheads parsing
this->InflictLocomotor.Read(exINI, pSection, "InflictLocomotor");
Expand Down
2 changes: 1 addition & 1 deletion src/Ext/WarheadType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <Utilities/TemplateDef.h>
#include <New/Type/ShieldTypeClass.h>
#include <Ext/Bullet/Body.h>
#include <Misc/TypeConvertHelper.h>
#include <New/Type/Affiliated/TypeConvertGroup.h>

class WarheadTypeExt
{
Expand Down
2 changes: 1 addition & 1 deletion src/Ext/WarheadType/Detonate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ void WarheadTypeExt::ExtData::ApplyConvert(HouseClass* pHouse, TechnoClass* pTar
if (!pTargetFoot || this->Convert_Pairs.size() == 0)
return;

TypeConvertHelper::Convert(pTargetFoot, this->Convert_Pairs, pHouse);
TypeConvertGroup::Convert(pTargetFoot, this->Convert_Pairs, pHouse);
}

void WarheadTypeExt::ExtData::ApplyLocomotorInfliction(TechnoClass* pTarget)
Expand Down
4 changes: 1 addition & 3 deletions src/Misc/FlyingStrings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ void FlyingStrings::UpdateAll()
{
auto& dataItem = Data[i];

Point2D point;

TacticalClass::Instance->CoordsToClient(dataItem.Location, &point);
auto [point,visible] = TacticalClass::Instance->CoordsToClient(dataItem.Location);

point += dataItem.PixelOffset;

Expand Down
50 changes: 0 additions & 50 deletions src/Misc/TypeConvertHelper.cpp

This file was deleted.

92 changes: 92 additions & 0 deletions src/New/Type/Affiliated/TypeConvertGroup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include <Ext/Techno/Body.h>
#include "TypeConvertGroup.h"

void TypeConvertGroup::Convert(FootClass* pTargetFoot, const std::vector<TypeConvertGroup>& convertPairs, HouseClass* pOwner)
{
for (const auto& [fromTypes, toType, affectedHouses] : convertPairs)
{
if (!toType.isset() || !toType.Get()) continue;

if (!EnumFunctions::CanTargetHouse(affectedHouses, pOwner, pTargetFoot->Owner))
continue;

if (fromTypes.size())
{
for (const auto& from : fromTypes)
{
// Check if the target matches upgrade-from TechnoType and it has something to upgrade to
if (from == pTargetFoot->GetTechnoType())
{
TechnoExt::ConvertToType(pTargetFoot, toType);
break;
}
}
}
else
{
TechnoExt::ConvertToType(pTargetFoot, toType);
}
}
}


bool TypeConvertGroup::Load(PhobosStreamReader& stm, bool registerForChange)
{
return this->Serialize(stm);
}

bool TypeConvertGroup::Save(PhobosStreamWriter& stm) const
{
return const_cast<TypeConvertGroup*>(this)->Serialize(stm);
}

void TypeConvertGroup::Parse(std::vector<TypeConvertGroup>& list, INI_EX& exINI, const char* pSection,AffectedHouse defaultAffectHouse)
{
for (size_t i = 0; ; ++i)
{
char tempBuffer[32];
ValueableVector<TechnoTypeClass*> convertFrom;
Nullable<TechnoTypeClass*> convertTo;
Nullable<AffectedHouse> convertAffectedHouses;
_snprintf_s(tempBuffer, sizeof(tempBuffer), "Convert%d.From", i);
convertFrom.Read(exINI, pSection, tempBuffer);
_snprintf_s(tempBuffer, sizeof(tempBuffer), "Convert%d.To", i);
convertTo.Read(exINI, pSection, tempBuffer);
_snprintf_s(tempBuffer, sizeof(tempBuffer), "Convert%d.AffectedHouses", i);
convertAffectedHouses.Read(exINI, pSection, tempBuffer);

if (!convertTo.isset())
break;

if (!convertAffectedHouses.isset())
convertAffectedHouses = defaultAffectHouse;

list.emplace_back(convertFrom, convertTo, convertAffectedHouses);
}
ValueableVector<TechnoTypeClass*> convertFrom;
Nullable<TechnoTypeClass*> convertTo;
Nullable<AffectedHouse> convertAffectedHouses;
convertFrom.Read(exINI, pSection, "Convert.From");
convertTo.Read(exINI, pSection, "Convert.To");
convertAffectedHouses.Read(exINI, pSection, "Convert.AffectedHouses");
if (convertTo.isset())
{
if (!convertAffectedHouses.isset())
convertAffectedHouses = defaultAffectHouse;

if (list.size())
list[0] = { convertFrom, convertTo, convertAffectedHouses };
else
list.emplace_back(convertFrom, convertTo, convertAffectedHouses);
}
}

template <typename T>
bool TypeConvertGroup::Serialize(T& stm)
{
return stm
.Process(this->FromTypes)
.Process(this->ToType)
.Process(this->AppliedTo)
.Success();
}
Loading

0 comments on commit 7185414

Please sign in to comment.