Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed DrawMap() function to allow access to named objects of the MapCreator if kept #114

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading