diff --git a/src/C4Landscape.cpp b/src/C4Landscape.cpp index c0cda0f74..e13221588 100644 --- a/src/C4Landscape.cpp +++ b/src/C4Landscape.cpp @@ -2699,6 +2699,34 @@ bool C4Landscape::DrawDefMap(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, return fSuccess; } +bool C4Landscape::DrawCreatorMap(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, const char *szMapDef) +{ + // safety + if (!szMapDef || !pMapCreator) return false; + // clip to landscape size + if (!ClipRect(iX, iY, iWdt, iHgt)) return false; + // get needed map size + int32_t iMapWdt = (iWdt - 1) / MapZoom + 1; + int32_t iMapHgt = (iHgt - 1) / MapZoom + 1; + bool fSuccess = false; + // this will also append to the MapCreator Tree + pMapCreator->ReadScript(szMapDef); + C4MCMap *pMap = pMapCreator->GetMap(nullptr); + if (!pMap) return false; + pMap->SetSize(iMapWdt, iMapHgt); + // pMapCreator->Render() will use the last map in the MapCreator tree + CSurface8 *sfcMap = pMapCreator->Render(nullptr); + if (sfcMap) + { + // map to landscape + fSuccess = MapToLandscape(sfcMap, 0, 0, iMapWdt, iMapHgt, iX, iY); + } + // cleanup + delete sfcMap; + // done + return fSuccess; +} + bool C4Landscape::ClipRect(int32_t &rX, int32_t &rY, int32_t &rWdt, int32_t &rHgt) { // clip by bounds diff --git a/src/C4Landscape.h b/src/C4Landscape.h index b26e66879..23d4483ec 100644 --- a/src/C4Landscape.h +++ b/src/C4Landscape.h @@ -196,6 +196,7 @@ class C4Landscape bool DrawMap(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, const char *szMapDef); // creates and draws a map section using MapCreatorS2 bool ClipRect(int32_t &rX, int32_t &rY, int32_t &rWdt, int32_t &rHgt); // clip given rect by landscape size; return whether anything is left unclipped bool DrawDefMap(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, const char *szMapDef); // creates and draws a map section using MapCreatorS2 and a map from the loaded Landscape.txt + bool DrawCreatorMap(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, const char *szMapDef); // creates and appends a map to the loaded Landscape.txt and uses the MapCreatorS2 to draw it bool SetModulation(uint32_t dwWithClr) // adjust the way the landscape is blitted { diff --git a/src/C4Script.cpp b/src/C4Script.cpp index 6629989a6..d8c2279fe 100644 --- a/src/C4Script.cpp +++ b/src/C4Script.cpp @@ -4846,6 +4846,12 @@ static C4ValueInt FnDrawDefMap(C4AulContext *cctx, C4ValueInt iX, C4ValueInt iY, return Game.Landscape.DrawDefMap(iX, iY, iWdt, iHgt, FnStringPar(szMapDef)); } +static C4ValueInt FnDrawCreatorMap(C4AulContext *cctx, C4ValueInt iX, C4ValueInt iY, C4ValueInt iWdt, C4ValueInt iHgt, C4String *szMapDef) +{ + // draw it! + return Game.Landscape.DrawCreatorMap(iX, iY, iWdt, iHgt, FnStringPar(szMapDef)); +} + static bool FnCreateParticle(C4AulContext *cthr, C4String *szName, C4ValueInt iX, C4ValueInt iY, C4ValueInt iXDir, C4ValueInt iYDir, C4ValueInt a, C4ValueInt b, C4Object *pObj, bool fBack) { // safety @@ -6930,6 +6936,7 @@ void InitFunctionMap(C4AulScriptEngine *pEngine) AddFunc(pEngine, "UnselectCrew", FnUnselectCrew); AddFunc(pEngine, "DrawMap", FnDrawMap); AddFunc(pEngine, "DrawDefMap", FnDrawDefMap); + AddFunc(pEngine, "DrawCreatorMap", FnDrawCreatorMap); AddFunc(pEngine, "CreateParticle", FnCreateParticle); AddFunc(pEngine, "CastParticles", FnCastParticles); AddFunc(pEngine, "CastBackParticles", FnCastBackParticles);