Skip to content

Commit 365dc44

Browse files
authored
Merge pull request #114 from TeaElKay/master
changed DrawMap() function to allow access to named objects of the MapCreator if kept
2 parents b6a3886 + 418431c commit 365dc44

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

src/C4Landscape.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -2659,11 +2659,16 @@ bool C4Landscape::DrawMap(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, co
26592659
FakeLS.MapWdt.Set(iMapWdt, 0, iMapWdt, iMapWdt);
26602660
FakeLS.MapHgt.Set(iMapHgt, 0, iMapHgt, iMapHgt);
26612661
// create map creator
2662-
C4MapCreatorS2 MapCreator(&FakeLS, &Game.TextureMap, &Game.Material, Game.Parameters.StartupPlayerCount);
2662+
std::unique_ptr<C4MapCreatorS2> MapCreator;
2663+
// If KeepMapCreator=1 we copy the existing creator to gain access to the named overlays
2664+
if (!pMapCreator)
2665+
MapCreator = std::make_unique<C4MapCreatorS2>(&FakeLS, &Game.TextureMap, &Game.Material, Game.Parameters.StartupPlayerCount);
2666+
else
2667+
MapCreator = std::make_unique<C4MapCreatorS2>(*pMapCreator, &FakeLS);
26632668
// read file
2664-
MapCreator.ReadScript(szMapDef);
2669+
MapCreator->ReadScript(szMapDef);
26652670
// render map
2666-
CSurface8 *sfcMap = MapCreator.Render(nullptr);
2671+
CSurface8 *sfcMap = MapCreator->Render(nullptr);
26672672
if (!sfcMap) return false;
26682673
// map it to the landscape
26692674
bool fSuccess = MapToLandscape(sfcMap, 0, 0, iMapWdt, iMapHgt, iX, iY);

src/C4MapCreatorS2.cpp

+21-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,12 @@ C4MCNode::C4MCNode(C4MCNode *pOwner, C4MCNode &rTemplate, bool fClone)
141141
// copy children from template
142142
for (C4MCNode *pChild = rTemplate.Child0; pChild; pChild = pChild->Next)
143143
pChild->clone(this);
144-
// no name
145-
*Name = 0;
144+
145+
// Preserve the name if pOwner is a MCN_Node, which is only the case if pOwner is a C4MapCreatorS2
146+
if (pOwner && pOwner->Type() == MCN_Node)
147+
SCopy(rTemplate.Name, Name, C4MaxName);
148+
else
149+
*Name = 0; // Default behavior: reset the name
146150
}
147151

148152
C4MCNode::~C4MCNode()
@@ -694,6 +698,21 @@ C4MapCreatorS2::C4MapCreatorS2(C4SLandscape *pLandscape, C4TextureMap *pTexMap,
694698
Default();
695699
}
696700

701+
C4MapCreatorS2::C4MapCreatorS2(C4MapCreatorS2 &rTemplate, C4SLandscape *pLandscape) : C4MCNode(nullptr, rTemplate, true)
702+
{
703+
// me r b creator
704+
MapCreator = this;
705+
// store members
706+
Landscape = pLandscape; TexMap = rTemplate.TexMap; MatMap = rTemplate.MatMap;
707+
PlayerCount = rTemplate.PlayerCount;
708+
// set engine field for default stuff
709+
DefaultMap.MapCreator = this;
710+
DefaultOverlay.MapCreator = this;
711+
DefaultPoint.MapCreator = this;
712+
// default to landscape settings
713+
Default();
714+
}
715+
697716
C4MapCreatorS2::~C4MapCreatorS2()
698717
{
699718
// clear fields

src/C4MapCreatorS2.h

+2
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,10 @@ class C4MapCreatorS2 : public C4MCNode
351351
{
352352
public:
353353
C4MapCreatorS2(C4SLandscape *pLandscape, C4TextureMap *pTexMap, C4MaterialMap *pMatMap, int iPlayerCount);
354+
C4MapCreatorS2(C4MapCreatorS2 &rTemplate, C4SLandscape *pLandscape); // construct of template
354355
~C4MapCreatorS2();
355356

357+
356358
void Default(); // set default data
357359
void Clear(); // clear any data
358360
bool ReadFile(const char *szFilename, C4Group *pGrp); // read defs of file

0 commit comments

Comments
 (0)