Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
MapValidator now validates the overlapping structures
Browse files Browse the repository at this point in the history
  • Loading branch information
secsome committed Mar 3, 2023
1 parent 0329c92 commit 76534b9
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# FINALALERT2 - SP CHANGELOG

## RELEASE 1.6.0 (2023-XX-XX)
- **ONLY YURI's REVENGE WILL BE SUPPORTED SINCE FA2SP 1.6.0**
- Reimplemented file reading system
- Support Ares Custom Foundation
- Map validator now checks overlapping structures, raise an error instead of warning for now. String can be modified by `MV_OverlapStructures`

## RELEASE 1.5.2 (2023-03-03)
- Fixed the bug that money calculation is incorrect
Expand Down
1 change: 1 addition & 0 deletions DOCUMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ NOTICE THAT UNDOREDO AND COPYPASTE HASN'T BEEN SUPPORTED YET!
[CURRENTLANGUAGE-TranslationsRA2]
[CURRENTLANGUAGE-Translations]
; Those four are all acceptable, just write under one of them is okey
MV_OverlapStructures = TEXT(%1 for count, %2 for X, %3 for Y)
TabPages.TilePlacement = TEXT
TabPages.TriggerSort = TEXT
Menu.File = TEXT
Expand Down
2 changes: 1 addition & 1 deletion FA2pp
Submodule FA2pp updated 1 files
+25 −0 MFC/ppmfc_cstring.h
3 changes: 3 additions & 0 deletions FA2sp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@
<ClCompile Include="FA2sp\Ext\CMapData\Hooks.cpp" />
<ClCompile Include="FA2sp\Ext\CMapData\Body.Pack.cpp" />
<ClCompile Include="FA2sp\Ext\CMapD\Hooks.cpp" />
<ClCompile Include="FA2sp\Ext\CMapValidator\Body.cpp" />
<ClCompile Include="FA2sp\Ext\CMapValidator\Hooks.cpp" />
<ClCompile Include="FA2sp\Ext\CMinimap\Hooks.cpp" />
<ClCompile Include="FA2sp\Ext\CPropertyAircraft\Body.cpp" />
<ClCompile Include="FA2sp\Ext\CPropertyAircraft\Hooks.cpp" />
Expand Down Expand Up @@ -244,6 +246,7 @@
<ClInclude Include="FA2sp\Ext\CLighting\Body.h" />
<ClInclude Include="FA2sp\Ext\CLoading\Body.h" />
<ClInclude Include="FA2sp\Ext\CMapData\Body.h" />
<ClInclude Include="FA2sp\Ext\CMapValidator\Body.h" />
<ClInclude Include="FA2sp\Ext\CPropertyAircraft\Body.h" />
<ClInclude Include="FA2sp\Ext\CPropertyBuilding\Body.h" />
<ClInclude Include="FA2sp\Ext\CPropertyInfantry\Body.h" />
Expand Down
15 changes: 15 additions & 0 deletions FA2sp.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@
<ClInclude Include="FA2sp\Algorithms\lcw.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="FA2sp\Ext\CMapValidator\Body.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="FA2sp\FA2sp.cpp">
Expand Down Expand Up @@ -479,6 +482,18 @@
<ClCompile Include="FA2sp\Ext\CLoading\Hooks.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="FA2sp\Ext\CMapData\Hooks.BuildingTypeDatas.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="FA2sp\Miscs\PlaceHolder.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="FA2sp\Ext\CMapValidator\Body.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="FA2sp\Ext\CMapValidator\Hooks.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="FA2sp\FA2sp.rc">
Expand Down
3 changes: 2 additions & 1 deletion FA2sp/Ext/CAITriggerTypes/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../../Helpers/Translations.h"
#include "..\CMapData\Body.h"
#include "..\CFinalSunApp\Body.h"
#include "Body.h"

void CAITriggerTypesExt::ProgramStartupInit()
{
Expand Down Expand Up @@ -118,4 +119,4 @@ void CAITriggerTypesExt::OnBNCloneAITriggerClicked()

this->SetDlgItemText(1010, name); // update the name huh
}
}
}
20 changes: 20 additions & 0 deletions FA2sp/Ext/CMapValidator/Body.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "Body.h"

#include "../../Helpers/Translations.h"

#include <CMapData.h>

ppmfc::CString CMapValidatorExt::FetchLanguageString(const char* Key, const char* def)
{
ppmfc::CString buffer;

if (!Translations::GetTranslationItem(Key, buffer))
buffer = def;

return buffer;
}

void CMapValidatorExt::InsertString(const char* String, bool IsWarning)
{
CLCResults.InsertItem(LVIF_TEXT | LVIF_IMAGE, CLCResults.GetItemCount(), String, NULL, NULL, IsWarning, NULL);
}
10 changes: 10 additions & 0 deletions FA2sp/Ext/CMapValidator/Body.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <CMapValidator.h>

class CMapValidatorExt : public CMapValidator
{
public:
ppmfc::CString FetchLanguageString(const char* Key, const char* def);
void InsertString(const char* String, bool IsWarning);
};
65 changes: 65 additions & 0 deletions FA2sp/Ext/CMapValidator/Hooks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "Body.h"

#include <Helpers/Macro.h>

#include <CMapData.h>

#include "../../Helpers/STDHelpers.h"
#include "../../Ext/CMapData/Body.h"

DEFINE_HOOK(4D19A0, CMapValidator_DoValidator_Extra, 5)
{
GET(CMapValidatorExt*, pThis, EDI);
REF_STACK(BOOL, result, STACK_OFFS(0x200, 0x168));

// Check for overlapped buildings
{
std::vector<int> Occupied;
int length = CMapData::Instance->MapWidthPlusHeight;
length *= length;
Occupied.resize(length);

if (auto pSection = CMapData::Instance->INI.GetSection("Structures"))
{
for (const auto& [_, Data] : pSection->GetEntities())
{
const auto splits = STDHelpers::SplitString(Data, 4);
const int Index = CMapData::Instance->GetBuildingTypeID(splits[1]);
const int Y = atoi(splits[3]);
const int X = atoi(splits[4]);
const auto& DataExt = CMapDataExt::BuildingDataExts[Index];

if (!DataExt.IsCustomFoundation())
{
for (int dx = 0; dx < DataExt.Height; ++dx)
{
for (int dy = 0; dy < DataExt.Width; ++dy)
++Occupied[CMapData::Instance->GetCoordIndex(X + dx, Y + dy)];
}
}
else
{
for (const auto& block : *DataExt.Foundations)
++Occupied[CMapData::Instance->GetCoordIndex(X + block.Y, Y + block.X)];
}
}
}

ppmfc::CString Format = pThis->FetchLanguageString(
"MV_OverlapStructures", "%1 structures overlap at (%2, %3)");
for (int i = 0; i < length; ++i)
{
if (Occupied[i] > 1)
{
result = FALSE;
auto buffer = Format;
buffer.ReplaceNumString(1, Occupied[i]);
buffer.ReplaceNumString(2, CMapData::Instance->GetYFromCoordIndex(i));
buffer.ReplaceNumString(3, CMapData::Instance->GetXFromCoordIndex(i));
pThis->InsertString(buffer, false);
}
}
}

return 0;
}
4 changes: 2 additions & 2 deletions FA2sp/FA2sp.Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#define __str_(x) #x

#define PRODUCT_MAJOR 1
#define PRODUCT_MINOR 5
#define PRODUCT_REVISION 2
#define PRODUCT_MINOR 6
#define PRODUCT_REVISION 0

#ifdef NDEBUG
#define PRODUCT_STR __str(PRODUCT_MAJOR) "." __str(PRODUCT_MINOR) "." __str(PRODUCT_REVISION)
Expand Down

0 comments on commit 76534b9

Please sign in to comment.