From 71854144c0c066f137eb8c1a180f7f970da059be Mon Sep 17 00:00:00 2001 From: Trsdy <914137150@qq.com> Date: Sun, 18 Feb 2024 23:30:55 +0800 Subject: [PATCH] Move TypeConvertGroup out of Misc folder --- Phobos.vcxproj | 4 +- YRpp | 2 +- src/Ext/BuildingType/Hooks.cpp | 12 +-- src/Ext/Bullet/Hooks.DetonateLogics.cpp | 7 +- src/Ext/SWType/Body.cpp | 37 +------- src/Ext/SWType/Body.h | 2 +- src/Ext/SWType/FireSuperWeapon.cpp | 2 +- src/Ext/Techno/Body.Visuals.cpp | 10 +- src/Ext/TechnoType/Hooks.cpp | 4 +- src/Ext/WarheadType/Body.cpp | 38 +------- src/Ext/WarheadType/Body.h | 2 +- src/Ext/WarheadType/Detonate.cpp | 2 +- src/Misc/FlyingStrings.cpp | 4 +- src/Misc/TypeConvertHelper.cpp | 50 ---------- src/New/Type/Affiliated/TypeConvertGroup.cpp | 92 +++++++++++++++++++ .../Type/Affiliated/TypeConvertGroup.h} | 9 +- 16 files changed, 118 insertions(+), 159 deletions(-) delete mode 100644 src/Misc/TypeConvertHelper.cpp create mode 100644 src/New/Type/Affiliated/TypeConvertGroup.cpp rename src/{Misc/TypeConvertHelper.h => New/Type/Affiliated/TypeConvertGroup.h} (60%) diff --git a/Phobos.vcxproj b/Phobos.vcxproj index 4f29bf9076..f51d06a1e9 100644 --- a/Phobos.vcxproj +++ b/Phobos.vcxproj @@ -152,7 +152,7 @@ - + @@ -199,7 +199,7 @@ - + diff --git a/YRpp b/YRpp index dd9c4cf1d7..b6cd27087f 160000 --- a/YRpp +++ b/YRpp @@ -1 +1 @@ -Subproject commit dd9c4cf1d742d0b6db6a5edd8d715b8dd15ce1b9 +Subproject commit b6cd27087fb0e9f2a1c666f6d84f4377e1a16d02 diff --git a/src/Ext/BuildingType/Hooks.cpp b/src/Ext/BuildingType/Hooks.cpp index eea7ef6bf7..99f79b6820 100644 --- a/src/Ext/BuildingType/Hooks.cpp +++ b/src/Ext/BuildingType/Hooks.cpp @@ -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; diff --git a/src/Ext/Bullet/Hooks.DetonateLogics.cpp b/src/Ext/Bullet/Hooks.DetonateLogics.cpp index a4d7332e31..3219e5fcfa 100644 --- a/src/Ext/Bullet/Hooks.DetonateLogics.cpp +++ b/src/Ext/Bullet/Hooks.DetonateLogics.cpp @@ -4,10 +4,9 @@ #include #include #include +#include #include -#include -#include #include DEFINE_HOOK(0x4692BD, BulletClass_Logics_ApplyMindControl, 0x6) @@ -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; } diff --git a/src/Ext/SWType/Body.cpp b/src/Ext/SWType/Body.cpp index 6a5a8aa664..18366f0f45 100644 --- a/src/Ext/SWType/Body.cpp +++ b/src/Ext/SWType/Body.cpp @@ -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 convertFrom; - Nullable convertTo; - Nullable 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 convertFrom; - Nullable convertTo; - Nullable 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"); } diff --git a/src/Ext/SWType/Body.h b/src/Ext/SWType/Body.h index 7ad71d13b4..945cd2154a 100644 --- a/src/Ext/SWType/Body.h +++ b/src/Ext/SWType/Body.h @@ -8,7 +8,7 @@ #include #include -#include +#include class SWTypeExt { diff --git a/src/Ext/SWType/FireSuperWeapon.cpp b/src/Ext/SWType/FireSuperWeapon.cpp index 72bdbf453b..dbbd8d376b 100644 --- a/src/Ext/SWType/FireSuperWeapon.cpp +++ b/src/Ext/SWType/FireSuperWeapon.cpp @@ -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); } diff --git a/src/Ext/Techno/Body.Visuals.cpp b/src/Ext/Techno/Body.Visuals.cpp index cd501805f6..91a0d4f183 100644 --- a/src/Ext/Techno/Body.Visuals.cpp +++ b/src/Ext/Techno/Body.Visuals.cpp @@ -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) @@ -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); diff --git a/src/Ext/TechnoType/Hooks.cpp b/src/Ext/TechnoType/Hooks.cpp index f43f30779c..7ff4262782 100644 --- a/src/Ext/TechnoType/Hooks.cpp +++ b/src/Ext/TechnoType/Hooks.cpp @@ -107,8 +107,8 @@ DEFINE_HOOK(0x73CCE1, UnitClass_DrawSHP_TurretOffest, 0x6) auto res = Matrix3D::MatrixMultiply(mtx, Vector3D::Empty); auto location = CoordStruct { static_cast(res.X), static_cast(-res.Y), static_cast(res.Z) }; - Point2D temp; - pos += *TacticalClass::Instance()->CoordsToScreen(&temp, &location); + + pos += TacticalClass::CoordsToScreen(location); return 0; } diff --git a/src/Ext/WarheadType/Body.cpp b/src/Ext/WarheadType/Body.cpp index 75c6bdc2c4..bc177cb1de 100644 --- a/src/Ext/WarheadType/Body.cpp +++ b/src/Ext/WarheadType/Body.cpp @@ -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 convertFrom; - Nullable convertTo; - Nullable 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 convertFrom; - Nullable convertTo; - Nullable 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"); diff --git a/src/Ext/WarheadType/Body.h b/src/Ext/WarheadType/Body.h index cee1e1e485..f8936a3fec 100644 --- a/src/Ext/WarheadType/Body.h +++ b/src/Ext/WarheadType/Body.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include class WarheadTypeExt { diff --git a/src/Ext/WarheadType/Detonate.cpp b/src/Ext/WarheadType/Detonate.cpp index 92a744b397..d65c58f719 100644 --- a/src/Ext/WarheadType/Detonate.cpp +++ b/src/Ext/WarheadType/Detonate.cpp @@ -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) diff --git a/src/Misc/FlyingStrings.cpp b/src/Misc/FlyingStrings.cpp index d715bcb16c..8e3a6fe868 100644 --- a/src/Misc/FlyingStrings.cpp +++ b/src/Misc/FlyingStrings.cpp @@ -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; diff --git a/src/Misc/TypeConvertHelper.cpp b/src/Misc/TypeConvertHelper.cpp deleted file mode 100644 index 6fe3cdd680..0000000000 --- a/src/Misc/TypeConvertHelper.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "Misc/TypeConvertHelper.h" - -void TypeConvertHelper::Convert(FootClass* pTargetFoot, const std::vector& 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(this)->Serialize(stm); -} - -template -bool TypeConvertGroup::Serialize(T& stm) -{ - return stm - .Process(this->FromTypes) - .Process(this->ToType) - .Process(this->AppliedTo) - .Success(); -} diff --git a/src/New/Type/Affiliated/TypeConvertGroup.cpp b/src/New/Type/Affiliated/TypeConvertGroup.cpp new file mode 100644 index 0000000000..9cd91be5c7 --- /dev/null +++ b/src/New/Type/Affiliated/TypeConvertGroup.cpp @@ -0,0 +1,92 @@ +#include +#include "TypeConvertGroup.h" + +void TypeConvertGroup::Convert(FootClass* pTargetFoot, const std::vector& 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(this)->Serialize(stm); +} + +void TypeConvertGroup::Parse(std::vector& list, INI_EX& exINI, const char* pSection,AffectedHouse defaultAffectHouse) +{ + for (size_t i = 0; ; ++i) + { + char tempBuffer[32]; + ValueableVector convertFrom; + Nullable convertTo; + Nullable 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 convertFrom; + Nullable convertTo; + Nullable 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 +bool TypeConvertGroup::Serialize(T& stm) +{ + return stm + .Process(this->FromTypes) + .Process(this->ToType) + .Process(this->AppliedTo) + .Success(); +} diff --git a/src/Misc/TypeConvertHelper.h b/src/New/Type/Affiliated/TypeConvertGroup.h similarity index 60% rename from src/Misc/TypeConvertHelper.h rename to src/New/Type/Affiliated/TypeConvertGroup.h index 033845711e..e4e40b6508 100644 --- a/src/Misc/TypeConvertHelper.h +++ b/src/New/Type/Affiliated/TypeConvertGroup.h @@ -1,7 +1,6 @@ #pragma once #include -#include class TypeConvertGroup { @@ -13,12 +12,12 @@ class TypeConvertGroup bool Load(PhobosStreamReader& stm, bool registerForChange); bool Save(PhobosStreamWriter& stm) const; + static void Parse(std::vector& list,INI_EX& exINI, const char* section,AffectedHouse defaultAffectHouse); + + static void Convert(FootClass* pTargetFoot, const std::vector& convertPairs, HouseClass* pOwner); + private: template bool Serialize(T& stm); }; -namespace TypeConvertHelper -{ - void Convert(FootClass* pTargetFoot, const std::vector& convertPairs, HouseClass* pOwner); -}