# HG changeset patch
# User David Dormagen <czapper@gmx.de>
# Date 1328906928 -3600
# Node ID 3bb643ab45aea4ba4c76b00120064bf30be4ef74
# Parent  66f10f71b01f36d202b24caaa88e39228fa98913
added parameter for DrawMap and DrawDefMap to retain old material if sky is drawn

diff -r 66f10f71b01f -r 3bb643ab45ae src/game/landscape/C4Landscape.cpp
--- a/src/game/landscape/C4Landscape.cpp	Fri Feb 10 01:18:15 2012 +0100
+++ b/src/game/landscape/C4Landscape.cpp	Fri Feb 10 21:48:48 2012 +0100
@@ -1837,11 +1837,12 @@
 	return true;
 }
 
-bool C4Landscape::MapToSurface(CSurface8 * sfcMap, int32_t iMapX, int32_t iMapY, int32_t iMapWdt, int32_t iMapHgt, int32_t iToX, int32_t iToY, int32_t iToWdt, int32_t iToHgt, int32_t iOffX, int32_t iOffY)
+bool C4Landscape::MapToSurface(CSurface8 * sfcMap, int32_t iMapX, int32_t iMapY, int32_t iMapWdt, int32_t iMapHgt, int32_t iToX, int32_t iToY, int32_t iToWdt, int32_t iToHgt, int32_t iOffX, int32_t iOffY, bool noClear)
 {
 
 	// Clear surface
-	Surface8->ClearBox8Only(iToX, iToY, iToWdt, iToHgt);
+	if(!noClear)
+		Surface8->ClearBox8Only(iToX, iToY, iToWdt, iToHgt);
 
 	// assign clipper
 	Surface8->Clip(iToX,iToY,iToX+iToWdt-1,iToY+iToHgt-1);
@@ -1866,7 +1867,7 @@
 	return true;
 }
 
-bool C4Landscape::MapToLandscape(CSurface8 * sfcMap, int32_t iMapX, int32_t iMapY, int32_t iMapWdt, int32_t iMapHgt, int32_t iOffsX, int32_t iOffsY)
+bool C4Landscape::MapToLandscape(CSurface8 * sfcMap, int32_t iMapX, int32_t iMapY, int32_t iMapWdt, int32_t iMapHgt, int32_t iOffsX, int32_t iOffsY, bool noClear)
 {
 	assert(Surface8);
 	// Clip to map/landscape segment
@@ -1888,7 +1889,7 @@
 	To.Hgt = iMapHgt*MapZoom;
 
 	PrepareChange(To);
-	MapToSurface(sfcMap, iMapX, iMapY, iMapWdt, iMapHgt, To.x, To.y, To.Wdt, To.Hgt, iOffsX, iOffsY);
+	MapToSurface(sfcMap, iMapX, iMapY, iMapWdt, iMapHgt, To.x, To.y, To.Wdt, To.Hgt, iOffsX, iOffsY, noClear);
 	FinishChange(To);
 	return true;
 }
@@ -1992,7 +1993,7 @@
 	return iMax;
 }
 // Nearest free above semi solid
-bool AboveSemiSolid(int32_t &rx, int32_t &ry) 
+bool AboveSemiSolid(int32_t &rx, int32_t &ry)
 {
 	int32_t cy1=ry,cy2=ry;
 	bool UseUpwardsNextFree=false,UseDownwardsNextSolid=false;
@@ -2019,7 +2020,7 @@
 }
 
 // Nearest free directly above solid
-bool AboveSolid(int32_t &rx, int32_t &ry) 
+bool AboveSolid(int32_t &rx, int32_t &ry)
 {
 	int32_t cy1=ry,cy2=ry;
 
@@ -2043,7 +2044,7 @@
 }
 
 // Nearest free/semi above solid
-bool SemiAboveSolid(int32_t &rx, int32_t &ry) 
+bool SemiAboveSolid(int32_t &rx, int32_t &ry)
 {
 	int32_t cy1=ry,cy2=ry;
 
@@ -3052,7 +3053,7 @@
 /* ++++++++++++++++++ Functions for Script interface +++++++++++++++++++++++ */
 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
 
-bool C4Landscape::DrawMap(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, const char *szMapDef)
+bool C4Landscape::DrawMap(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, const char *szMapDef, bool ignoreSky)
 {
 	// safety
 	if (!szMapDef) return false;
@@ -3072,14 +3073,14 @@
 	CSurface8 * sfcMap=MapCreator.Render(NULL);
 	if (!sfcMap) return false;
 	// map it to the landscape
-	bool fSuccess=MapToLandscape(sfcMap, 0, 0, iMapWdt, iMapHgt, iX, iY);
+	bool fSuccess=MapToLandscape(sfcMap, 0, 0, iMapWdt, iMapHgt, iX, iY, ignoreSky);
 	// cleanup
 	delete sfcMap;
 	// return whether successful
 	return fSuccess;
 }
 
-bool C4Landscape::DrawDefMap(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, const char *szMapDef)
+bool C4Landscape::DrawDefMap(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, const char *szMapDef, bool ignoreSky)
 {
 	// safety
 	if (!szMapDef || !pMapCreator) return false;
@@ -3097,7 +3098,7 @@
 	if (sfcMap)
 	{
 		// map to landscape
-		fSuccess=MapToLandscape(sfcMap, 0, 0, iMapWdt, iMapHgt, iX, iY);
+		fSuccess=MapToLandscape(sfcMap, 0, 0, iMapWdt, iMapHgt, iX, iY, ignoreSky);
 		// cleanup
 		delete sfcMap;
 	}
diff -r 66f10f71b01f -r 3bb643ab45ae src/game/landscape/C4Landscape.h
--- a/src/game/landscape/C4Landscape.h	Fri Feb 10 01:18:15 2012 +0100
+++ b/src/game/landscape/C4Landscape.h	Fri Feb 10 21:48:48 2012 +0100
@@ -66,7 +66,7 @@
 	DWORD MatCount[C4MaxMaterial]; // NoSave //
 	DWORD EffectiveMatCount[C4MaxMaterial]; // NoSave //
 	uint8_t *BridgeMatConversion[C4MaxMaterial]; // NoSave //
-	
+
 	bool NoScan; // ExecuteScan() disabled
 	int32_t ScanX,ScanSpeed; // SyncClearance-NoSave //
 	int32_t LeftOpen,RightOpen,TopOpen,BottomOpen;
@@ -192,9 +192,9 @@
 
 	int32_t AreaSolidCount(int32_t x, int32_t y, int32_t wdt, int32_t hgt);
 	int32_t ExtractMaterial(int32_t fx, int32_t fy);
-	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 DrawMap(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, const char *szMapDef, bool ignoreSky = false); // 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 DrawDefMap(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, const char *szMapDef, bool ignoreSky = false); // creates and draws a map section using MapCreatorS2 and a map from the loaded Landscape.txt
 	bool SetModulation(DWORD dwWithClr) // adjust the way the landscape is blitted
 	{ Modulation=dwWithClr; return true; }
 	DWORD GetModulation() { return Modulation; }
@@ -217,8 +217,8 @@
 	void ChunkOZoom(CSurface8 * sfcMap, int32_t iMapX, int32_t iMapY, int32_t iMapWdt, int32_t iMapHgt, int32_t iTexture,int32_t iOffX=0,int32_t iOffY=0);
 	bool GetTexUsage(CSurface8 * sfcMap, int32_t iMapX, int32_t iMapY, int32_t iMapWdt, int32_t iMapHgt, DWORD *dwpTextureUsage);
 	bool TexOZoom(CSurface8 * sfcMap, int32_t iMapX, int32_t iMapY, int32_t iMapWdt, int32_t iMapHgt, DWORD *dwpTextureUsage, int32_t iToX=0,int32_t iToY=0);
-	bool MapToSurface(CSurface8 * sfcMap, int32_t iMapX, int32_t iMapY, int32_t iMapWdt, int32_t iMapHgt, int32_t iToX, int32_t iToY, int32_t iToWdt, int32_t iToHgt, int32_t iOffX, int32_t iOffY);
-	bool MapToLandscape(CSurface8 * sfcMap, int32_t iMapX, int32_t iMapY, int32_t iMapWdt, int32_t iMapHgt, int32_t iOffsX = 0, int32_t iOffsY = 0); // zoom map segment to surface (or sector surfaces)
+	bool MapToSurface(CSurface8 * sfcMap, int32_t iMapX, int32_t iMapY, int32_t iMapWdt, int32_t iMapHgt, int32_t iToX, int32_t iToY, int32_t iToWdt, int32_t iToHgt, int32_t iOffX, int32_t iOffY, bool noClear = false);
+	bool MapToLandscape(CSurface8 * sfcMap, int32_t iMapX, int32_t iMapY, int32_t iMapWdt, int32_t iMapHgt, int32_t iOffsX = 0, int32_t iOffsY = 0, bool noClear = false); // zoom map segment to surface (or sector surfaces)
 	bool GetMapColorIndex(const char *szMaterial, const char *szTexture, bool fIFT, BYTE &rbyCol);
 	bool SkyToLandscape(int32_t iToX, int32_t iToY, int32_t iToWdt, int32_t iToHgt, int32_t iOffX, int32_t iOffY);
 	CSurface8 * CreateMap(); // create map by landscape attributes
diff -r 66f10f71b01f -r 3bb643ab45ae src/game/script/C4GameScript.cpp
--- a/src/game/script/C4GameScript.cpp	Fri Feb 10 01:18:15 2012 +0100
+++ b/src/game/script/C4GameScript.cpp	Fri Feb 10 21:48:48 2012 +0100
@@ -1650,16 +1650,16 @@
 	return ::Landscape.DrawChunks(tx, ty, twdt, thgt, icntx, icnty, FnStringPar(strMaterial), FnStringPar(strTexture), bIFT != 0);
 }
 
-static long FnDrawMap(C4AulContext *cctx, long iX, long iY, long iWdt, long iHgt, C4String *szMapDef)
+static long FnDrawMap(C4AulContext *cctx, long iX, long iY, long iWdt, long iHgt, C4String *szMapDef, bool ignoreSky)
 {
 	// draw it!
-	return ::Landscape.DrawMap(iX, iY, iWdt, iHgt, FnStringPar(szMapDef));
+	return ::Landscape.DrawMap(iX, iY, iWdt, iHgt, FnStringPar(szMapDef), ignoreSky);
 }
 
-static long FnDrawDefMap(C4AulContext *cctx, long iX, long iY, long iWdt, long iHgt, C4String *szMapDef)
+static long FnDrawDefMap(C4AulContext *cctx, long iX, long iY, long iWdt, long iHgt, C4String *szMapDef, bool ignoreSky)
 {
 	// draw it!
-	return ::Landscape.DrawDefMap(iX, iY, iWdt, iHgt, FnStringPar(szMapDef));
+	return ::Landscape.DrawDefMap(iX, iY, iWdt, iHgt, FnStringPar(szMapDef), ignoreSky);
 }
 
 static bool FnCreateParticle(C4AulContext *cthr, C4String *szName, long iX, long iY, long iXDir, long iYDir, long a, long b, C4Object *pObj, bool fBack)
@@ -2659,7 +2659,7 @@
 	{ "C4FO_Controller"           ,C4V_Int,     C4FO_Controller     },
 	{ "C4FO_Func"                 ,C4V_Int,     C4FO_Func           },
 	{ "C4FO_Layer"                ,C4V_Int,     C4FO_Layer          },
-	
+
 	{ "MD_DragSource"             ,C4V_Int,     C4MC_MD_DragSource  },
 	{ "MD_DropTarget"             ,C4V_Int,     C4MC_MD_DropTarget  },
 	{ "MD_NoClick"                ,C4V_Int,     C4MC_MD_NoClick     },
