From 20ee2aaab2f5dd2f5a29e4498c8ec0d57a958d9f Mon Sep 17 00:00:00 2001
From: ariclone <>
Date: Wed, 26 Jul 2000 16:12:36 +0000
Subject: [PATCH] Custom Game menu tileset selection code

---
 src/stratagus/pud.cpp | 38 +++++++++++++++++++++-----------------
 src/ui/menus.cpp      | 22 +++++++++++++++++++++-
 2 files changed, 42 insertions(+), 18 deletions(-)

diff --git a/src/stratagus/pud.cpp b/src/stratagus/pud.cpp
index b5524c165..94d105dc6 100644
--- a/src/stratagus/pud.cpp
+++ b/src/stratagus/pud.cpp
@@ -801,23 +801,27 @@ global void LoadPud(const char* pud,WorldMap* map)
 		int t;
 
 		t=PudReadWord(input);
-		switch( t ) {
-		    case TilesetSummer:
-			DebugLevel3("\tTerrain: SUMMER\n");
-			break;
-		    case TilesetWinter:
-			DebugLevel3("\tTerrain: WINTER\n");
-			break;
-		    case TilesetWasteland:
-			DebugLevel3("\tTerrain: WASTELAND\n");
-			break;
-		    case TilesetSwamp:
-			DebugLevel3("\tTerrain: SWAMP\n");
-			break;
-		    default:
-			DebugLevel1("Unknown terrain %d\n",t);
-			t=TilesetSummer;
-			break;
+		if (GameSettings.Terrain == SettingsPresetMapDefault) {
+		    switch( t ) {
+			case TilesetSummer:
+			    DebugLevel3("\tTerrain: SUMMER\n");
+			    break;
+			case TilesetWinter:
+			    DebugLevel3("\tTerrain: WINTER\n");
+			    break;
+			case TilesetWasteland:
+			    DebugLevel3("\tTerrain: WASTELAND\n");
+			    break;
+			case TilesetSwamp:
+			    DebugLevel3("\tTerrain: SWAMP\n");
+			    break;
+			default:
+			    DebugLevel1("Unknown terrain %d\n",t);
+			    t=TilesetSummer;
+			    break;
+		    }
+		} else {
+		    t = GameSettings.Terrain;
 		}
 		map->Terrain=t;
 		continue;
diff --git a/src/ui/menus.cpp b/src/ui/menus.cpp
index 762d72600..7bec5af04 100644
--- a/src/ui/menus.cpp
+++ b/src/ui/menus.cpp
@@ -77,6 +77,7 @@ local void CustomGameStart(void);
 local void CustomGameDrawFunc(Menuitem *mi);
 
 local void CustomGameRCSAction(Menuitem *mi, int i);
+local void CustomGameTSSAction(Menuitem *mi, int i);
 
 /*----------------------------------------------------------------------------
 --	Variables
@@ -289,7 +290,7 @@ local Menuitem CustomGameMenuItems[] = {
     { MI_TYPE_TEXT, 220, 10+300-20, 0, GameFont, NULL, NULL,
 	{ text:{ "~<Map Tileset:~>", 0} } },
     { MI_TYPE_PULLDOWN, 220, 10+300, 0, GameFont, NULL, NULL,
-	{ pulldown:{ cgtssoptions, 152, 20, MBUTTON_PULLDOWN, NULL, 5, 0, 0, 0} } },
+	{ pulldown:{ cgtssoptions, 152, 20, MBUTTON_PULLDOWN, CustomGameTSSAction, 5, 0, 0, 0} } },
 };
 
 /**
@@ -1170,6 +1171,13 @@ local void CustomGameRCSAction (Menuitem *mi __attribute__((unused)), int i)
     GameSettings.Presets[0].Race = v[i];
 }
 
+local void CustomGameTSSAction (Menuitem *mi __attribute__((unused)), int i)
+{
+    int v[] = { SettingsPresetMapDefault, TilesetSummer, TilesetWinter, TilesetWasteland, TilesetSwamp };
+
+    GameSettings.Terrain = v[i];
+}
+
 /*----------------------------------------------------------------------------
 --	Menu operation functions
 ----------------------------------------------------------------------------*/
@@ -1723,6 +1731,18 @@ global void InitMenus(unsigned int race)
     buf = alloca(strlen(file) + 9 + 1);
     file = strcat(strcpy(buf, "graphic/"), file);
     MenuButtonGfx.Sprite = LoadSprite(file, 0, 144);
+
+    strcpy(ScenSelectPath, FreeCraftLibPath);
+    if (ScenSelectPath[0]) {
+	strcat(ScenSelectPath, "/");
+    }
+    strcat(ScenSelectPath, "swamp.rgb");
+    if (access(ScenSelectPath, F_OK) != 0) {
+	// ARI FIXME: Hack to disable Expansion Gfx..
+	// also shows how to add new tilesets....
+	CustomGameMenuItems[14].d.pulldown.noptions = 4;
+	
+    }
 }
 
 //@}