Skip to content

Commit

Permalink
C4Landscape::DrawMap() extended to allow access to named overlays fro…
Browse files Browse the repository at this point in the history
…m the MapCreator if kept
  • Loading branch information
TeaElKay committed Oct 11, 2024
1 parent a08f927 commit 418431c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/C4Landscape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<C4MapCreatorS2> MapCreator;
// If KeepMapCreator=1 we copy the existing creator to gain access to the named overlays
if (!pMapCreator)
MapCreator = std::make_unique<C4MapCreatorS2>(&FakeLS, &Game.TextureMap, &Game.Material, Game.Parameters.StartupPlayerCount);
else
MapCreator = std::make_unique<C4MapCreatorS2>(*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);
Expand Down
23 changes: 21 additions & 2 deletions src/C4MapCreatorS2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/C4MapCreatorS2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 418431c

Please sign in to comment.