Skip to content

Commit

Permalink
added DrawCreatorMap() function
Browse files Browse the repository at this point in the history
  • Loading branch information
TeaElKay committed Jan 18, 2024
1 parent a08f927 commit 9f703b9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/C4Landscape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/C4Landscape.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
7 changes: 7 additions & 0 deletions src/C4Script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9f703b9

Please sign in to comment.