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 2001-2019 by Lutz Sammer, Jimmy Salmon, Pali Rohár and Andrettin
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26--
27
28InitFuncs:add(function()
29	speedcheat = false
30	godcheat = false
31end)
32
33function HandleCheats(str)
34	local resources = {"copper", "lumber", "oil", "iron", "stone", "coal", "research", "prestige", "gold", "silver", "mithril", "limestone", "jewelry", "furniture", "leather", "diamonds", "emeralds", "leadership", "trade"}
35
36	if (str == "im a lumberjack and its ok") then
37		SetSpeedResourcesHarvest("lumber", 25)
38	elseif (str == "otters ransom") then
39		for i = 0, (PlayerMax - 2) do
40			SetPlayerData(i, "Resources", "copper", GetPlayerData(i, "Resources", "copper") + 12000)
41			SetPlayerData(i, "Resources", "lumber", GetPlayerData(i, "Resources", "lumber") + 10000)
42			SetPlayerData(i, "Resources", "oil", GetPlayerData(i, "Resources", "oil") + 10000)
43			SetPlayerData(i, "Resources", "stone", GetPlayerData(i, "Resources", "stone") + 10000)
44			SetPlayerData(i, "Resources", "coal", GetPlayerData(i, "Resources", "coal") + 10000)
45		end
46		AddMessage("Resources increased!")
47	elseif (str == "showpath") then -- reveals the map only to person players
48		RevealMap(true)
49		AddMessage("Map revealed")
50	elseif (str == "heimdall") then -- reveals the map to all players
51		RevealMap(false)
52		AddMessage("Map revealed to all players")
53	elseif (str == "fow on") then
54		SetFogOfWar(true)
55	elseif (str == "fow off") then
56		SetFogOfWar(false)
57	elseif (str == "fow") then
58		if (GetFogOfWar() == true) then
59			SetFogOfWar(false)
60		else
61			SetFogOfWar(true)
62		end
63	elseif (str == "fast debug") then
64		for i = 1,table.getn(resources) do
65			SetSpeedResourcesHarvest(resources[i], 10)
66			SetSpeedResourcesReturn(resources[i], 10)
67		end
68		SetSpeedBuild(10)
69		SetSpeedTrain(10)
70		SetSpeedUpgrade(10)
71		SetSpeedResearch(10)
72		AddMessage("FAST DEBUG SPEED")
73	elseif (str == "normal debug") then
74		for i = 1,table.getn(resources) do
75			SetSpeedResourcesHarvest(resources[i], 1)
76			SetSpeedResourcesReturn(resources[i], 1)
77		end
78		SetSpeedBuild(1)
79		SetSpeedTrain(1)
80		SetSpeedUpgrade(1)
81		SetSpeedResearch(1)
82		AddMessage("NORMAL DEBUG SPEED")
83	elseif (str == "hermes") then
84		if (speedcheat) then
85			speedcheat = false
86			for i = 0,PlayerMax - 1 do
87				for j = 1,table.getn(resources) do
88					SetPlayerData(i, "SpeedResourcesHarvest", resources[j], GetPlayerData(i, "SpeedResourcesHarvest", resources[j]) / 10)
89					SetPlayerData(i, "SpeedResourcesReturn", resources[j], GetPlayerData(i, "SpeedResourcesReturn", resources[j]) / 10)
90				end
91				SetPlayerData(i, "SpeedBuild", GetPlayerData(i, "SpeedBuild") / 10)
92				SetPlayerData(i, "SpeedTrain", GetPlayerData(i, "SpeedTrain") / 10)
93				SetPlayerData(i, "SpeedUpgrade", GetPlayerData(i, "SpeedUpgrade") / 10)
94				SetPlayerData(i, "SpeedResearch", GetPlayerData(i, "SpeedResearch") / 10)
95			end
96			AddMessage(_("Faster disabled!"))
97		else
98			speedcheat = true
99			for i = 0,PlayerMax - 1 do
100				for j = 1,table.getn(resources) do
101					SetPlayerData(i, "SpeedResourcesHarvest", resources[j], GetPlayerData(i, "SpeedResourcesHarvest", resources[j]) * 10)
102					SetPlayerData(i, "SpeedResourcesReturn", resources[j], GetPlayerData(i, "SpeedResourcesReturn", resources[j]) * 10)
103				end
104				SetPlayerData(i, "SpeedBuild", GetPlayerData(i, "SpeedBuild") * 10)
105				SetPlayerData(i, "SpeedTrain", GetPlayerData(i, "SpeedTrain") * 10)
106				SetPlayerData(i, "SpeedUpgrade", GetPlayerData(i, "SpeedUpgrade") * 10)
107				SetPlayerData(i, "SpeedResearch", GetPlayerData(i, "SpeedResearch") * 10)
108			end
109			AddMessage(_("Faster enabled!"))
110		end
111	elseif (str == "valhalla") then
112		ActionVictory()
113	elseif (str == "ragnarok") then
114		ActionDefeat()
115	elseif (str == "fenrir") then
116		KillUnitAt("any", GetThisPlayer(), GetPlayerData(GetThisPlayer(), "TotalNumUnits"), {0, 0}, {512, 512})
117	elseif (str == "hroptatyr") then
118		if (godcheat) then
119			godcheat = false
120			SetGodMode(false)
121			AddMessage("God Mode Off")
122		else
123			godcheat = true
124			SetGodMode(true)
125			AddMessage("God Mode On")
126		end
127	elseif (str == "fill mana") then
128		t = GetUnits("this");
129		for i = 1,table.getn(t) do
130			SetUnitMana(t[i], 255)
131		end
132	elseif (str == "mead of wisdom") then
133		AddMessage("All Technologies Allowed")
134		for i, unitName in ipairs(Units) do
135			for j=0,(PlayerMax - 1) do
136				if (((string.find(unitName, "upgrade-") ~= nil and GetUpgradeData(unitName, "Civilization") == GetPlayerData(j, "RaceName")) or (string.find(unitName, "upgrade-") == nil and GetUnitTypeData(unitName, "Civilization") == GetPlayerData(j, "RaceName"))) and GetPlayerData(j, "Allow", unitName) ~= "R") then
137					SetPlayerData(j, "Allow", unitName, "A")
138				end
139			end
140		end
141	elseif (str == "colossus of rhodes") then -- acquire all bronze age technologies
142		AddMessage("Acquired Bronze Age Technologies")
143		local bronze_upgrades = {
144			"upgrade-wood-plow",
145			"upgrade-dwarven-broad-axe", "upgrade-dwarven-long-spear", "upgrade-dwarven-shield-1", "upgrade-dwarven-sharp-throwing-axe",
146			"upgrade-germanic-broad-sword", "upgrade-germanic-long-spear", "upgrade-germanic-bronze-shield", "upgrade-germanic-barbed-arrow",
147			"upgrade-goblin-broad-sword", "upgrade-goblin-rimmed-shield", "upgrade-goblin-long-spear", "upgrade-goblin-barbed-arrow"
148		}
149		for i, unitName in ipairs(bronze_upgrades) do
150			for j=0,PlayerMax - 2 do
151				if (Players[j].Type ~= PlayerNobody and unitName == GetFactionClassUnitType(GetUpgradeData(unitName, "Class"), GetPlayerData(j, "Faction"))) then
152					SetPlayerData(j, "Allow", unitName, "R")
153				end
154			end
155		end
156	elseif (str == "dawn") then
157		SetTimeOfDay("dawn")
158	elseif (string.sub(str, 0, 4) == "dawn") then
159		SetTimeOfDay("dawn", tonumber(string.sub(str, 6)))
160	elseif (str == "alsvid") then
161		SetTimeOfDay("morning")
162	elseif (string.sub(str, 0, 6) == "alsvid") then
163		SetTimeOfDay("morning", tonumber(string.sub(str, 8)))
164	elseif (str == "dusk") then
165		SetTimeOfDay("dusk")
166	elseif (string.sub(str, 0, 4) == "dusk") then
167		SetTimeOfDay("dusk", tonumber(string.sub(str, 6)))
168	elseif (str == "nightly terrors") then
169		SetTimeOfDay("midnight")
170	elseif (string.sub(str, 0, 15) == "nightly terrors") then
171		SetTimeOfDay("midnight", tonumber(string.sub(str, 17)))
172	elseif (str == "dream of spring") then
173		SetSeason("spring")
174	elseif (string.sub(str, 0, 15) == "dream of spring") then
175		SetSeason("spring", tonumber(string.sub(str, 17)))
176	elseif (str == "summer child") then
177		SetSeason("summer")
178	elseif (string.sub(str, 0, 12) == "summer child") then
179		SetSeason("summer", tonumber(string.sub(str, 14)))
180	elseif (str == "winds of winter") then
181		SetSeason("winter")
182	elseif (string.sub(str, 0, 15) == "winds of winter") then
183		SetSeason("winter", tonumber(string.sub(str, 17)))
184	elseif (str == "fly me to the moon") then
185		SetTimeOfDaySchedule("lunar-schedule")
186		SetSeasonSchedule("lunar-schedule")
187	elseif (string.sub(str, 0, 18) == "fly me to the moon") then
188		SetTimeOfDaySchedule("lunar-schedule", tonumber(string.sub(str, 20)))
189		SetSeasonSchedule("lunar-schedule", tonumber(string.sub(str, 20)))
190	elseif (str == "king of the galactic seas") then
191		SetTimeOfDaySchedule("neptunian-schedule")
192		SetSeasonSchedule("neptunian-schedule")
193	elseif (string.sub(str, 0, 25) == "king of the galactic seas") then
194		SetTimeOfDaySchedule("neptunian-schedule", tonumber(string.sub(str, 27)))
195		SetSeasonSchedule("neptunian-schedule", tonumber(string.sub(str, 27)))
196	elseif (string.sub(str, 0, 7) == "bifrost") then
197		ChangeCurrentMapLayer(tonumber(string.sub(str, 9)))
198	elseif (string.sub(str, 0, 19) == "numunitsconstructed") then
199		local message_player = tonumber(string.sub(str, 21))
200		AddMessage("Player " .. message_player .. " has " .. Players[message_player].NumBuildingsUnderConstruction .. " under construction buildings.")
201	elseif (str == "shield wall") then
202		local infantry_type = GetFactionClassUnitType("infantry", GetPlayerData(GetThisPlayer(), "Faction"))
203		if (infantry_type) then
204			unit = CreateUnit(infantry_type, GetThisPlayer(), {Players[GetThisPlayer()].StartPos.x, Players[GetThisPlayer()].StartPos.y})
205		end
206	elseif (str == "swordskill") then
207		local veteran_infantry_type = GetFactionClassUnitType("veteran-infantry", GetPlayerData(GetThisPlayer(), "Faction"))
208		if (veteran_infantry_type) then
209			unit = CreateUnit(veteran_infantry_type, GetThisPlayer(), {Players[GetThisPlayer()].StartPos.x, Players[GetThisPlayer()].StartPos.y})
210		end
211	elseif (str == "artemis") then
212		local shooter_type = GetFactionClassUnitType("shooter", GetPlayerData(GetThisPlayer(), "Faction"))
213		if (shooter_type) then
214			unit = CreateUnit(shooter_type, GetThisPlayer(), {Players[GetThisPlayer()].StartPos.x, Players[GetThisPlayer()].StartPos.y})
215		end
216	elseif (str == "fire and steel") then
217		local gunpowder_infantry_type = GetFactionClassUnitType("gunpowder-infantry", GetPlayerData(GetThisPlayer(), "Faction"))
218		if (gunpowder_infantry_type) then
219			unit = CreateUnit(gunpowder_infantry_type, GetThisPlayer(), {Players[GetThisPlayer()].StartPos.x, Players[GetThisPlayer()].StartPos.y})
220		end
221	elseif (str == "piety") then
222		local priest_type = GetFactionClassUnitType("priest", GetPlayerData(GetThisPlayer(), "Faction"))
223		if (priest_type) then
224			unit = CreateUnit(priest_type, GetThisPlayer(), {Players[GetThisPlayer()].StartPos.x, Players[GetThisPlayer()].StartPos.y})
225		end
226	elseif (str == "archimedes") then
227		local siege_engine_type = GetFactionClassUnitType("siege-engine", GetPlayerData(GetThisPlayer(), "Faction"))
228		if (siege_engine_type) then
229			unit = CreateUnit(siege_engine_type, GetThisPlayer(), {Players[GetThisPlayer()].StartPos.x, Players[GetThisPlayer()].StartPos.y})
230		end
231	elseif (str == "ahoy") then
232		local transport_ship_type = GetFactionClassUnitType("transport-ship", GetPlayerData(GetThisPlayer(), "Faction"))
233		if (transport_ship_type) then
234			unit = CreateUnit(transport_ship_type, GetThisPlayer(), {Players[GetThisPlayer()].StartPos.x, Players[GetThisPlayer()].StartPos.y})
235		end
236	elseif (str == "skidbladnir") then
237		local siege_warship_type = GetFactionClassUnitType("siege-warship", GetPlayerData(GetThisPlayer(), "Faction"))
238		if (siege_warship_type) then
239			unit = CreateUnit(siege_warship_type, GetThisPlayer(), {Players[GetThisPlayer()].StartPos.x, Players[GetThisPlayer()].StartPos.y})
240		end
241	elseif (str == "jotun") then
242		unit = CreateUnit("unit-ettin", GetThisPlayer(), {Players[GetThisPlayer()].StartPos.x, Players[GetThisPlayer()].StartPos.y})
243	elseif (str == "backstab") then
244		unit = CreateUnit("unit-goblin-thief", GetThisPlayer(), {Players[GetThisPlayer()].StartPos.x, Players[GetThisPlayer()].StartPos.y})
245	elseif (str == "marius") then
246		unit = CreateUnit("unit-latin-legionary", GetThisPlayer(), {Players[GetThisPlayer()].StartPos.x, Players[GetThisPlayer()].StartPos.y})
247	elseif (str == "peruns shield") then
248		unit = CreateUnit("unit-slavic-swordsman", GetThisPlayer(), {Players[GetThisPlayer()].StartPos.x, Players[GetThisPlayer()].StartPos.y})
249	elseif (str == "lodbrok") then
250		unit = CreateUnit("unit-norse-longship", GetThisPlayer(), {Players[GetThisPlayer()].StartPos.x, Players[GetThisPlayer()].StartPos.y})
251	elseif (str == "volund") then
252		unit = CreateUnit("unit-elven-swordsman", GetThisPlayer(), {Players[GetThisPlayer()].StartPos.x, Players[GetThisPlayer()].StartPos.y})
253	elseif (str == "vingethor") then
254		unit = CreateUnit("unit-dwarven-gryphon-rider", GetThisPlayer(), {Players[GetThisPlayer()].StartPos.x, Players[GetThisPlayer()].StartPos.y})
255	elseif (str == "tyr") then
256		unit = CreateUnit("unit-norse-swordsman", GetThisPlayer(), {Players[GetThisPlayer()].StartPos.x, Players[GetThisPlayer()].StartPos.y})
257	elseif (str == "trollheim") then
258		unit = CreateUnit("unit-troll-warrior", GetThisPlayer(), {Players[GetThisPlayer()].StartPos.x, Players[GetThisPlayer()].StartPos.y})
259	else
260		return false
261	end
262	return true
263end
264