From 76534b920bb0c836ff333bf1de3de5af3bce908a Mon Sep 17 00:00:00 2001
From: secsome <302702960@qq.com>
Date: Fri, 3 Mar 2023 19:15:20 +0800
Subject: [PATCH] MapValidator now validates the overlapping structures
---
CHANGELOG.md | 2 +
DOCUMENT.md | 1 +
FA2pp | 2 +-
FA2sp.vcxproj | 3 ++
FA2sp.vcxproj.filters | 15 +++++++
FA2sp/Ext/CAITriggerTypes/Body.cpp | 3 +-
FA2sp/Ext/CMapValidator/Body.cpp | 20 +++++++++
FA2sp/Ext/CMapValidator/Body.h | 10 +++++
FA2sp/Ext/CMapValidator/Hooks.cpp | 65 ++++++++++++++++++++++++++++++
FA2sp/FA2sp.Constants.h | 4 +-
10 files changed, 121 insertions(+), 4 deletions(-)
create mode 100644 FA2sp/Ext/CMapValidator/Body.cpp
create mode 100644 FA2sp/Ext/CMapValidator/Body.h
create mode 100644 FA2sp/Ext/CMapValidator/Hooks.cpp
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 913cf00..9ff518f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/DOCUMENT.md b/DOCUMENT.md
index b2d04be..e32c3da 100644
--- a/DOCUMENT.md
+++ b/DOCUMENT.md
@@ -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
diff --git a/FA2pp b/FA2pp
index 00b2faf..de7a476 160000
--- a/FA2pp
+++ b/FA2pp
@@ -1 +1 @@
-Subproject commit 00b2faf21b574bfbf9b6cc541efef8fd14ba0dfd
+Subproject commit de7a4760782533670bd66eff61a2ff6d5f92cd27
diff --git a/FA2sp.vcxproj b/FA2sp.vcxproj
index 1348ae5..18607f4 100644
--- a/FA2sp.vcxproj
+++ b/FA2sp.vcxproj
@@ -163,6 +163,8 @@
+
+
@@ -244,6 +246,7 @@
+
diff --git a/FA2sp.vcxproj.filters b/FA2sp.vcxproj.filters
index b009630..c14078b 100644
--- a/FA2sp.vcxproj.filters
+++ b/FA2sp.vcxproj.filters
@@ -183,6 +183,9 @@
头文件
+
+ 头文件
+
@@ -479,6 +482,18 @@
源文件
+
+ 源文件
+
+
+ 源文件
+
+
+ 源文件
+
+
+ 源文件
+
diff --git a/FA2sp/Ext/CAITriggerTypes/Body.cpp b/FA2sp/Ext/CAITriggerTypes/Body.cpp
index efcd58d..a79536c 100644
--- a/FA2sp/Ext/CAITriggerTypes/Body.cpp
+++ b/FA2sp/Ext/CAITriggerTypes/Body.cpp
@@ -6,6 +6,7 @@
#include "../../Helpers/Translations.h"
#include "..\CMapData\Body.h"
#include "..\CFinalSunApp\Body.h"
+#include "Body.h"
void CAITriggerTypesExt::ProgramStartupInit()
{
@@ -118,4 +119,4 @@ void CAITriggerTypesExt::OnBNCloneAITriggerClicked()
this->SetDlgItemText(1010, name); // update the name huh
}
-}
\ No newline at end of file
+}
diff --git a/FA2sp/Ext/CMapValidator/Body.cpp b/FA2sp/Ext/CMapValidator/Body.cpp
new file mode 100644
index 0000000..c9557a5
--- /dev/null
+++ b/FA2sp/Ext/CMapValidator/Body.cpp
@@ -0,0 +1,20 @@
+#include "Body.h"
+
+#include "../../Helpers/Translations.h"
+
+#include
+
+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);
+}
\ No newline at end of file
diff --git a/FA2sp/Ext/CMapValidator/Body.h b/FA2sp/Ext/CMapValidator/Body.h
new file mode 100644
index 0000000..c401e34
--- /dev/null
+++ b/FA2sp/Ext/CMapValidator/Body.h
@@ -0,0 +1,10 @@
+#pragma once
+
+#include
+
+class CMapValidatorExt : public CMapValidator
+{
+public:
+ ppmfc::CString FetchLanguageString(const char* Key, const char* def);
+ void InsertString(const char* String, bool IsWarning);
+};
\ No newline at end of file
diff --git a/FA2sp/Ext/CMapValidator/Hooks.cpp b/FA2sp/Ext/CMapValidator/Hooks.cpp
new file mode 100644
index 0000000..96df39a
--- /dev/null
+++ b/FA2sp/Ext/CMapValidator/Hooks.cpp
@@ -0,0 +1,65 @@
+#include "Body.h"
+
+#include
+
+#include
+
+#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 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;
+}
\ No newline at end of file
diff --git a/FA2sp/FA2sp.Constants.h b/FA2sp/FA2sp.Constants.h
index 79f15b8..6257c41 100644
--- a/FA2sp/FA2sp.Constants.h
+++ b/FA2sp/FA2sp.Constants.h
@@ -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)