diff --git a/src/C4Landscape.cpp b/src/C4Landscape.cpp index c0cda0f74..c4d1e8a01 100644 --- a/src/C4Landscape.cpp +++ b/src/C4Landscape.cpp @@ -2659,11 +2659,16 @@ bool C4Landscape::DrawMap(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, co FakeLS.MapWdt.Set(iMapWdt, 0, iMapWdt, iMapWdt); FakeLS.MapHgt.Set(iMapHgt, 0, iMapHgt, iMapHgt); // create map creator - C4MapCreatorS2 MapCreator(&FakeLS, &Game.TextureMap, &Game.Material, Game.Parameters.StartupPlayerCount); + std::unique_ptr MapCreator; + // If KeepMapCreator=1 we copy the existing creator to gain access to the named overlays + if (!pMapCreator) + MapCreator = std::make_unique(&FakeLS, &Game.TextureMap, &Game.Material, Game.Parameters.StartupPlayerCount); + else + MapCreator = std::make_unique(*pMapCreator, &FakeLS); // read file - MapCreator.ReadScript(szMapDef); + MapCreator->ReadScript(szMapDef); // render map - CSurface8 *sfcMap = MapCreator.Render(nullptr); + CSurface8 *sfcMap = MapCreator->Render(nullptr); if (!sfcMap) return false; // map it to the landscape bool fSuccess = MapToLandscape(sfcMap, 0, 0, iMapWdt, iMapHgt, iX, iY); diff --git a/src/C4MapCreatorS2.cpp b/src/C4MapCreatorS2.cpp index 4067aa1c3..bac90b39e 100644 --- a/src/C4MapCreatorS2.cpp +++ b/src/C4MapCreatorS2.cpp @@ -141,8 +141,12 @@ C4MCNode::C4MCNode(C4MCNode *pOwner, C4MCNode &rTemplate, bool fClone) // copy children from template for (C4MCNode *pChild = rTemplate.Child0; pChild; pChild = pChild->Next) pChild->clone(this); - // no name - *Name = 0; + + // Preserve the name if pOwner is a MCN_Node, which is only the case if pOwner is a C4MapCreatorS2 + if (pOwner && pOwner->Type() == MCN_Node) + SCopy(rTemplate.Name, Name, C4MaxName); + else + *Name = 0; // Default behavior: reset the name } C4MCNode::~C4MCNode() @@ -694,6 +698,21 @@ C4MapCreatorS2::C4MapCreatorS2(C4SLandscape *pLandscape, C4TextureMap *pTexMap, Default(); } +C4MapCreatorS2::C4MapCreatorS2(C4MapCreatorS2 &rTemplate, C4SLandscape *pLandscape) : C4MCNode(nullptr, rTemplate, true) +{ + // me r b creator + MapCreator = this; + // store members + Landscape = pLandscape; TexMap = rTemplate.TexMap; MatMap = rTemplate.MatMap; + PlayerCount = rTemplate.PlayerCount; + // set engine field for default stuff + DefaultMap.MapCreator = this; + DefaultOverlay.MapCreator = this; + DefaultPoint.MapCreator = this; + // default to landscape settings + Default(); +} + C4MapCreatorS2::~C4MapCreatorS2() { // clear fields diff --git a/src/C4MapCreatorS2.h b/src/C4MapCreatorS2.h index b59f13606..611cb7423 100644 --- a/src/C4MapCreatorS2.h +++ b/src/C4MapCreatorS2.h @@ -349,8 +349,10 @@ class C4MapCreatorS2 : public C4MCNode { public: C4MapCreatorS2(C4SLandscape *pLandscape, C4TextureMap *pTexMap, C4MaterialMap *pMatMap, int iPlayerCount); + C4MapCreatorS2(C4MapCreatorS2 &rTemplate, C4SLandscape *pLandscape); // construct of template ~C4MapCreatorS2(); + void Default(); // set default data void Clear(); // clear any data bool ReadFile(const char *szFilename, C4Group *pGrp); // read defs of file