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 Sep 26, 2024
1 parent a08f927 commit 609950b
Show file tree
Hide file tree
Showing 3 changed files with 32 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::unique_ptr<C4MapCreatorS2>(pMapCreator->clone(nullptr, &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(C4MCNode *pOwner, C4MapCreatorS2 &rTemplate, C4SLandscape *pLandscape, bool fClone) : C4MCNode(pOwner, rTemplate, fClone)
{
// 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
3 changes: 3 additions & 0 deletions src/C4MapCreatorS2.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,11 @@ class C4MapCreatorS2 : public C4MCNode
{
public:
C4MapCreatorS2(C4SLandscape *pLandscape, C4TextureMap *pTexMap, C4MaterialMap *pMatMap, int iPlayerCount);
C4MapCreatorS2(C4MCNode *pOwner, C4MapCreatorS2 &rTemplate, C4SLandscape *pLandscape, bool fClone); // construct of template
~C4MapCreatorS2();

C4MapCreatorS2 *clone(C4MCNode *pToNode, C4SLandscape *pLandscape) { return new C4MapCreatorS2(pToNode, *this, pLandscape, true); }

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 609950b

Please sign in to comment.