mirror of
https://github.com/electronicarts/CNC_TS_and_RA2_Mission_Editor.git
synced 2025-07-25 08:34:45 -04:00
Fix: now building node under house type is corrected, related function refactored .
This commit is contained in:
parent
ea4c214b04
commit
a91ff89091
12 changed files with 154 additions and 79 deletions
|
@ -134,4 +134,15 @@ inline CString WaypointToString(int num)
|
|||
ret += firstChar;
|
||||
ret += secondChar;
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline void GetNodeID(CString& name, int n)
|
||||
{
|
||||
name.Format("%03d", n);
|
||||
}
|
||||
inline CString GetNodeID(int n)
|
||||
{
|
||||
CString ret;
|
||||
GetNodeID(ret, n);
|
||||
return ret;
|
||||
}
|
|
@ -61,7 +61,6 @@ static char THIS_FILE[] = __FILE__;
|
|||
|
||||
/* Externals */
|
||||
extern ACTIONDATA AD;
|
||||
void GetNodeName(CString& name, int n);
|
||||
/* --------- */
|
||||
|
||||
/* Overlay picture table (maximum overlay count=0xFF) */
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "Structs.h"
|
||||
#include "Tube.h"
|
||||
#include "IniMega.h"
|
||||
#include "Helpers.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#undef THIS_FILE
|
||||
|
@ -50,10 +51,6 @@ void DoEvents()
|
|||
}*/
|
||||
}
|
||||
|
||||
|
||||
void GetNodeName(CString& name, int n);
|
||||
|
||||
|
||||
CString GetFree(const char* sectionName)
|
||||
{
|
||||
auto const ini = Map->GetIniFile();
|
||||
|
@ -1768,7 +1765,7 @@ void CMapData::UpdateNodes(BOOL bSave)
|
|||
int nodeCount = sec.GetInteger("NodeCount");
|
||||
for (auto idx = 0; idx < nodeCount; idx++) {
|
||||
CString nodeName;
|
||||
GetNodeName(nodeName, idx);
|
||||
GetNodeID(nodeName, idx);
|
||||
auto const& nodeVal = sec.GetString(nodeName);
|
||||
CString type, sx, sy;
|
||||
type = GetParam(nodeVal, 0);
|
||||
|
@ -2034,26 +2031,9 @@ void CMapData::DeleteTerrain(DWORD dwIndex)
|
|||
|
||||
}
|
||||
|
||||
void CMapData::DeleteNode(LPCTSTR lpHouse, DWORD dwIndex)
|
||||
void CMapData::DeleteNode(const CString& house, const int dwIndex)
|
||||
{
|
||||
CString nodeName; // p is last node
|
||||
auto const nodeCount = m_mapfile.GetInteger(lpHouse, "NodeCount");
|
||||
GetNodeName(nodeName, nodeCount - 1);
|
||||
|
||||
for (auto i = dwIndex; i < nodeCount - 1; i++) {
|
||||
CString prevNodeName, nextNodeName;
|
||||
GetNodeName(prevNodeName, i);
|
||||
GetNodeName(nextNodeName, i + 1);
|
||||
m_mapfile.SetString(lpHouse, prevNodeName, m_mapfile.GetString(lpHouse, nextNodeName));
|
||||
}
|
||||
|
||||
auto const& pSec = m_mapfile.TryGetSection(lpHouse);
|
||||
pSec->RemoveAt(dwIndex);
|
||||
|
||||
char nodeCountStr[50];
|
||||
itoa(nodeCount - 1, nodeCountStr, 10);
|
||||
m_mapfile.SetString(lpHouse, "NodeCount", nodeCountStr);
|
||||
|
||||
DeleteBuildingNodeFrom(house, dwIndex, m_mapfile);
|
||||
UpdateNodes(FALSE);
|
||||
}
|
||||
|
||||
|
@ -2168,7 +2148,7 @@ BOOL CMapData::AddNode(NODE* lpNode, WORD dwPos)
|
|||
|
||||
nodeCount--;
|
||||
CString p;
|
||||
GetNodeName(p, nodeCount);
|
||||
GetNodeID(p, nodeCount);
|
||||
|
||||
auto&& nodeRecord = node.type
|
||||
+ "," + node.y + "," + node.x;
|
||||
|
|
|
@ -264,7 +264,7 @@ public:
|
|||
CString GetStructureData(DWORD dwIndex, STRUCTURE* lpStructure) const;
|
||||
BOOL AddWaypoint(CString lpID, DWORD dwPos);
|
||||
|
||||
void DeleteNode(LPCTSTR lpHouse, DWORD dwIndex);
|
||||
void DeleteNode(const CString& house, const int index);
|
||||
void DeleteTerrain(DWORD dwIndex);
|
||||
void DeleteAircraft(DWORD dwIndex);
|
||||
void DeleteStructure(DWORD dwIndex);
|
||||
|
|
|
@ -1320,27 +1320,7 @@ CString GetFreeID()
|
|||
return "";
|
||||
}
|
||||
|
||||
void GetNodeName(CString& name, int n)
|
||||
{
|
||||
char c[5];
|
||||
char p[6];
|
||||
memset(p, 0, 6);
|
||||
_itoa_s(n, c, 10);
|
||||
strcpy_s(p, c);
|
||||
|
||||
if (strlen(c) == 1) {
|
||||
memcpy(c, "00", 2);
|
||||
strcpy_s(c + 2, sizeof(c) - 2, p);
|
||||
} else if (strlen(c) == 2) {
|
||||
memcpy(c, "0", 1);
|
||||
strcpy_s(c + 1, sizeof(c) - 1, p);
|
||||
} else if (strlen(c) == 3) {
|
||||
strcpy_s(c, p);
|
||||
}
|
||||
|
||||
name = c;
|
||||
}
|
||||
|
||||
// UNUSED
|
||||
int GetNodeAt(CString& owner, CString& buildingTypeID, int x, int y)
|
||||
{
|
||||
CIniFile& ini = Map->GetIniFile();
|
||||
|
@ -1362,7 +1342,7 @@ int GetNodeAt(CString& owner, CString& buildingTypeID, int x, int y)
|
|||
|
||||
for (auto i = 0; i < nodeCount; i++) {
|
||||
CString nodeName;
|
||||
GetNodeName(nodeName, i);
|
||||
GetNodeID(nodeName, i);
|
||||
|
||||
CString sx, sy;
|
||||
buildingTypeID = GetParam(ownerSection.GetString(nodeName), 0);
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include <array>
|
||||
#include "Helpers.h"
|
||||
|
||||
class CIniFile;
|
||||
class CSliderCtrl;
|
||||
using std::string;
|
||||
|
||||
bool deleteFile(const std::string& u8FilePath);
|
||||
|
@ -56,9 +58,28 @@ std::string utf16ToUtf8(const std::wstring& utf16);
|
|||
std::string utf16ToACP(const std::wstring& utf16);
|
||||
|
||||
// map functions
|
||||
int GetNodeAt(string& owner, string& type, int x, int y);
|
||||
int SetNodeAt(string owner, string type, int x, int y);
|
||||
void ClearNode(int n, string owner);
|
||||
inline void DeleteBuildingNodeFrom(const CString& house, const int index, CIniFile& ini)
|
||||
{
|
||||
auto const nodeCount = ini.GetInteger(house, "NodeCount");
|
||||
ASSERT(nodeCount > 0);
|
||||
// override value from current ID
|
||||
CString prevNodeName, nextNodeName, lastData;
|
||||
for (auto i = index; i < nodeCount - 1; i++) {
|
||||
GetNodeID(prevNodeName, i);
|
||||
GetNodeID(nextNodeName, i + 1);
|
||||
lastData = ini.GetString(house, nextNodeName);
|
||||
ini.SetString(house, prevNodeName, lastData);
|
||||
}
|
||||
auto const& pSec = ini.TryGetSection(house);
|
||||
ASSERT(pSec != nullptr);
|
||||
if (pSec) {
|
||||
// always remove the last one
|
||||
auto const result = pSec->RemoveByKey(GetNodeID(nodeCount - 1));
|
||||
ASSERT(result == true);
|
||||
}
|
||||
ini.SetInteger(house, "NodeCount", nodeCount - 1);
|
||||
}
|
||||
|
||||
CString GetFreeID();
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue