1-- _________ __ __ 2-- / _____// |_____________ _/ |______ ____ __ __ ______ 3-- \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ 4-- / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ \ 5-- /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > 6-- \/ \/ \//_____/ \/ 7-- ______________________ ______________________ 8-- T H E W A R B E G I N S 9-- Stratagus - A free fantasy real time strategy game engine 10-- 11-- (c) Copyright 2013 by Kyran Jackson 12-- 13-- This program is free software; you can redistribute it and/or modify 14-- it under the terms of the GNU General Public License as published by 15-- the Free Software Foundation; either version 2 of the License, or 16-- (at your option) any later version. 17-- 18-- This program is distributed in the hope that it will be useful, 19-- but WITHOUT ANY WARRANTY; without even the implied warranty of 20-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21-- GNU General Public License for more details. 22-- 23-- You should have received a copy of the GNU General Public License 24-- along with this program; if not, write to the Free Software 25-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26-- 27 28OldRunSinglePlayerGameMenu = RunSinglePlayerGameMenu 29 30function CleanCustomGame_Lua() 31 RunSinglePlayerGameMenu = OldRunSinglePlayerGameMenu 32 33 BlueLeader = nil 34 UnitFootmanNum = nil 35 UnitArcherNum = nil 36 UnitRangerNum = nil 37 UnitBallistaNum = nil 38 UnitPaladinNum = nil 39 UnitKnightNum = nil 40 UnitMageNum = nil 41 UnitDwarvesNum = nil 42 43 Blue2Temp_x = nil 44 Blue2Temp_y = nil 45 Blue2Step = nil 46 Blue2Mana = nil 47 Blue1Temp_x = nil 48 Blue1Temp_y = nil 49 Blue1Step = nil 50 Blue1Mana = nil 51 BlueTemp = nil 52 BlueTeam1 = nil 53 BlueTeam2 = nil 54 BlueTemp_x1 = nil 55 BlueTemp_y1 = nil 56 BlueTemp_x2 = nil 57 BlueTemp_y2 = nil 58 BlueTeam1_x1 = nil 59 BlueTeam1_y1 = nil 60 BlueTeam1_x2 = nil 61 BlueTeam1_y2 = nil 62 BlueTeam2_x1 = nil 63 BlueTeam2_y1 = nil 64 BlueTeam2_x2 = nil 65 BlueTeam2_y2 = nil 66 blueribbon_stepping = nil 67 BlueBarracks1_x = nil 68 BlueBarracks1_y = nil 69 BlueBarracks2_x = nil 70 BlueBarracks2_y = nil 71 BlueBarracks3_x = nil 72 BlueBarracks3_y = nil 73 BlueBarracks4_x = nil 74 BlueBarracks4_y = nil 75 BlueInventor_x = nil 76 BlueInventor_y = nil 77 BlueMageTower_x = nil 78 BlueMageTower_y = nil 79 80 UnitGruntNum = nil 81 UnitAxethrowerNum = nil 82 UnitBerserkerNum = nil 83 UnitCatapultNum = nil 84 UnitOgreMageNum = nil 85 UnitOgreNum = nil 86 UnitDeathKnightNum = nil 87 UnitGoblinSappersNum = nil 88 89 redribbon_stepping = nil 90 91 RedLeader = nil 92 Red1Mana = nil 93 Red1Mana = nil 94 95 RedTemp = nil 96 RedTemp_x1 = nil 97 RedTemp_y1 = nil 98 RedTemp_x2 = nil 99 RedTemp_y2 = nil 100 Red2Temp_x = nil 101 Red2Temp_y = nil 102 Red2Step = nil 103 Red2Mana = nil 104 Red1Temp_x = nil 105 Red1Temp_y = nil 106 Red1Step = nil 107 Red1Mana = nil 108 RedTeam1 = nil 109 RedTeam2 = nil 110 RedTeam1_x1 = nil 111 RedTeam1_y1 = nil 112 RedTeam1_x2 = nil 113 RedTeam1_y2 = nil 114 RedTeam2_x1 = nil 115 RedTeam2_y1 = nil 116 RedTeam2_x2 = nil 117 RedTeam2_y2 = nil 118 119 RedBarracks1_x = nil 120 RedBarracks1_y = nil 121 RedBarracks2_x = nil 122 RedBarracks2_y = nil 123 RedBarracks3_x = nil 124 RedBarracks3_y = nil 125 RedBarracks4_x = nil 126 RedBarracks4_y = nil 127 RedInventor_x = nil 128 RedInventor_y = nil 129 RedMageTower_x = nil 130 RedMageTower_y = nil 131 132 -- Resetting the default map. 133 mapname = "maps/skirmish/(2)timeless-isle.smp.gz" 134 local buttonStatut = 0 -- 0:not initialised, 1: Ok, 2: Cancel 135 mapinfo = { 136 playertypes = {nil, nil, nil, nil, nil, nil, nil, nil}, 137 description = "", 138 nplayers = 1, 139 w = 32, 140 h = 32, 141 id = 0 142} 143-- Resetting the default map directory. 144function RunSelectScenarioMenu() 145 buttonStatut = 0 146 local menu = WarMenu(nil, panel(5), false) 147 menu:setSize(352, 352) 148 menu:setPosition((Video.Width - 352) / 2, (Video.Height - 352) / 2) 149 menu:setDrawMenusUnder(true) 150 151 menu:addLabel(_("Select scenario"), 176, 8) 152 153 local browser = menu:addBrowser("maps/skirmish", "^.*%.smp%.?g?z?$", 154 24, 140, 300, 108, mapname) 155 156 local l = menu:addLabel(browser:getSelectedItem(), 24, 260, Fonts["game"], false) 157 158 local function cb(s) 159 l:setCaption(browser:getSelectedItem()) 160 l:adjustSize() 161 end 162 browser:setActionCallback(cb) 163 164 menu:addHalfButton("~!OK", "o", 48, 318, 165 function() 166 local cap = l:getCaption() 167 168 if (browser:getSelected() < 0) then 169 return 170 end 171 buttonStatut = 1 172 mapname = browser.path .. cap 173 menu:stop() 174 end) 175 menu:addHalfButton(_("~!Cancel"), "c", 198, 318, 176 function() buttonStatut = 2; menu:stop() end) 177 178 menu:run() 179end 180end 181 182function StartCustomGame_Lua() 183 RunSinglePlayerGameMenu = NewRunSinglePlayerGameMenu 184 185 -- Selecting the default map. 186 mapname = "maps/fl/(8)rockfort-arena.smp" 187 local buttonStatut = 0 -- 0:not initialised, 1: Ok, 2: Cancel 188 mapinfo = { 189 playertypes = {nil, nil, nil, nil, nil, nil, nil, nil}, 190 description = "", 191 nplayers = 1, 192 w = 32, 193 h = 32, 194 id = 0 195} 196-- Selecting the map directory. 197function RunSelectScenarioMenu() 198 buttonStatut = 0 199 local menu = WarMenu(nil, panel(5), false) 200 menu:setSize(352, 352) 201 menu:setPosition((Video.Width - 352) / 2, (Video.Height - 352) / 2) 202 menu:setDrawMenusUnder(true) 203 204 menu:addLabel(_("Select scenario"), 176, 8) 205 206 local browser = menu:addBrowser("maps/fl", "^.*%.smp%.?g?z?$", 207 24, 140, 300, 108, mapname) 208 209 local l = menu:addLabel(browser:getSelectedItem(), 24, 260, Fonts["game"], false) 210 211 local function cb(s) 212 l:setCaption(browser:getSelectedItem()) 213 l:adjustSize() 214 end 215 browser:setActionCallback(cb) 216 217 menu:addHalfButton("~!OK", "o", 48, 318, 218 function() 219 local cap = l:getCaption() 220 221 if (browser:getSelected() < 0) then 222 return 223 end 224 buttonStatut = 1 225 mapname = browser.path .. cap 226 menu:stop() 227 end) 228 menu:addHalfButton(_("~!Cancel"), "c", 198, 318, 229 function() buttonStatut = 2; menu:stop() end) 230 231 menu:run() 232end 233end 234 235function NewRunSinglePlayerGameMenu() 236 local menu = WarMenu() 237 local offx = (Video.Width - 640) / 2 238 local offy = (Video.Height - 480) / 2 239 local d 240 local race 241 local resources 242 local opponents 243 local numunits 244 local gametype 245 local mapl 246 local descriptionl 247 local tilesetdd 248 249 menu:addLabel(wargus.Name .. " V" .. wargus.Version .. ", " .. wargus.Copyright, offx + 320, (Video.Height - 90) + 18*4, Fonts["small"]) -- Copyright information. 250 251 menu:addLabel(_("Scenario:"), offx + 16, offy + 360, Fonts["game"], false) 252 mapl = menu:addLabel(string.sub(mapname, 6), offx + 16, offy + 360 + 24, Fonts["game"], false) 253 descriptionl = menu:addLabel("descriptionl", offx + 16 + 70, offy + 360, Fonts["game"], false) 254 255 menu:addLabel(_("~<Single Player Game Setup~>"), offx + 640/2 + 12, offy + 192) 256 menu:addFullButton(_("S~!elect Scenario"), "e", offx + 640 - 224 - 16, offy + 360 + 36*0, 257 function() 258 local oldmapname = mapname 259 RunSelectScenarioMenu() 260 if (mapname ~= oldmapname) then 261 GetMapInfo(mapname) 262 MapChanged() 263 end 264 end) 265 menu:addFullButton(_("~!Start Game"), "s", offx + 640 - 224 - 16, offy + 360 + 36*1, 266 function() 267 local tilesetFilename = {nil, "summer.lua", "swamp.lua", "wasteland.lua", "winter.lua"}; 268 GameSettings.Resources = resources:getSelected() 269 GameSettings.Tileset = tilesetFilename[tilesetdd:getSelected() + 1] 270 RunMap(mapname, nil, wc2.preferences.FogOfWar, 0) 271 menu:stop() 272 end) 273 menu:addFullButton(_("~!Cancel Game"), "c", offx + 640 - 224 - 16, offy + 360 + 36*2, function() CleanCustomGame_Lua(); menu:stop(1); RunSinglePlayerTypeMenu() end) 274 275 menu:addLabel(_("~<Resources:~>"), offx + 40, offy + (10 + 240) - 20, Fonts["game"], false) 276 resources = menu:addDropDown({_("Map Default"), _("Low"), _("Medium"), _("High")}, offx + 40, offy + 10 + 240, 277 function(dd) end) 278 resources:setSize(152, 20) 279 280 menu:addLabel(_("~<Tileset:~>"), offx + 220, offy + (10 + 240) - 20, Fonts["game"], false) 281 tilesetdd = menu:addDropDown({_("Map Default"), _("Summer"), _("Swamp"), _("Wasteland"), _("Winter")}, offx + 220, offy + 10 + 240, 282 function(dd) end) 283 tilesetdd:setSize(190, 20) 284 285 function MapChanged() 286 mapl:setCaption(string.sub(mapname, 6)) 287 mapl:adjustSize() 288 289 descriptionl:setCaption(mapinfo.description .. 290 " (" .. mapinfo.w .. " x " .. mapinfo.h .. ")") 291 descriptionl:adjustSize() 292 293 end 294 295 GetMapInfo(mapname) 296 MapChanged() 297 298 menu:run() 299end 300 301 302StartCustomGame_Lua() 303 304RunSinglePlayerGameMenu() 305