1---------------------------------------------------------------------
2-- This file is part of Freedroid
3--
4-- Freedroid is free software; you can redistribute it and/or modify
5-- it under the terms of the GNU General Public License as published by
6-- the Free Software Foundation; either version 2 of the License, or
7-- (at your option) any later version.
8--
9-- Freedroid is distributed in the hope that it will be useful,
10-- but WITHOUT ANY WARRANTY; without even the implied warranty of
11-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-- GNU General Public License for more details.
13--
14-- You should have received a copy of the GNU General Public License
15-- along with Freedroid; see the file COPYING. If not, write to the
16-- Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
17-- MA 02111-1307 USA
18----------------------------------------------------------------------
19--[[WIKI
20PURPOSE = "$$NAME$$ is a character used for Debug purposes",
21WIKI]]--
22
23local Npc = FDrpg.get_npc()
24local Tux = FDrpg.get_tux()
25
26local function guy_fail(test, ...)
27	print(FDutils.text.highlight("ERROR! The following test failed:", "red"))
28	print(FDutils.text.highlight(test, "red"))
29	npc_says("%s failed!" ,test , "NO_WAIT")
30	end_dialog()
31	exit_game(1)
32end
33
34return {
35	FirstTime = function()
36---------------------------------------------------------- HAS_MET
37		if (not Tux:has_met("Guy")) then
38			Npc:says("HAS MET test 1 succeeded", "NO_WAIT")
39		else
40			guy_fail("HAS MET")
41		end
42
43		if (not Tux:has_quest("24_guy_death_quest")) then
44			Tux:add_quest("24_guy_death_quest", "Quest to check if droid markers work.")
45		end
46
47		Npc:says("This text is only shown as you speak to this character the first time.")
48	end,
49
50	EveryTime = function()
51
52		Guy_dialog_executing = true
53
54		-- Tux:says_random..
55		Tux:says_random("1", "2", "3", "4", "5", "NO_WAIT")
56		Tux:says_random("1", "2", "3", "4", "5", "NO_WAIT")
57		Tux:says_random("1", "2", "3", "4", "5", "NO_WAIT")
58		Tux:says_random("1", "2", "3", "4", "5", "NO_WAIT")
59		Tux:says_random("1", "2", "3", "4", "5", "NO_WAIT")
60		Tux:says_random("1", "2", "3", "4", "5", "NO_WAIT")
61
62		Tux:says("Tux:says()", "NO_WAIT")
63		Npc:says("Npc:says()", "NO_WAIT")
64		cli_says("cli_says()", "NO_WAIT")
65		Npc:says("", "NO_WAIT") -- extra linebreak for cli_says()
66
67		GuyArray = {"one", "two", "three"}
68		for var in ipairs(GuyArray) do
69			Npc:says(GuyArray[var], "NO_WAIT")
70		end
71
72		next("node0")
73	end,
74
75	{
76		id = "node0",
77		text = "RUNNING TEST NODE",
78		code = function()
79			show("node0")
80			hide("node0")
81---------------------------------------------------------- ITEM
82			Tux:add_item("Laser Scalpel")
83			Tux:add_item(".22 Automatic", 2)
84			if (Tux:has_item(".22 Automatic")) then
85				Npc:says("ADD ITEM test 1 succeeded", "NO_WAIT")
86			else
87				guy_fail("ADD ITEM 1")
88			end
89
90			if (Tux:has_item_backpack(".22 Automatic")) then
91				Npc:says("ADD ITEM test 2 succeeded", "NO_WAIT")
92			else
93				guy_fail("ADD ITEM 2")
94			end
95
96			if (Tux:has_item_equipped("Laser Scalpel")) then
97				Npc:says("ADD ITEM test 3 succeeded", "NO_WAIT")
98			else
99				guy_fail("ADD ITEM 3")
100			end
101
102			-- ru654
103			--[[ NOTE we need del_item_equipped() or unequipp_item()
104			Tux:del_item("Laser Scalpel")
105			if (not Tux:has_item("Laser Scalpel")) then
106				Npc:says("DEL ITEM 1 test succeeded", "NO_WAIT")
107			else
108				guy_fail("DEL ITEM 1")
109			end
110			]]--
111
112			Tux:del_item_backpack(".22 Automatic", 2)
113			if (not Tux:has_item_backpack(".22 Automatic")) then
114				Npc:says("DEL ITEM test 2 succeeded", "NO_WAIT")
115			else
116				guy_fail("DEL ITEM 2")
117			end
118---------------------------------------------------------- FACTION
119			npc_faction("self", "Guy - self")
120			npc_faction("ms", "Guy - ms")
121			npc_faction("redguard", "Guy - redguard" )
122			npc_faction("resistance", "Guy - resistance")
123			npc_faction("civilian", "Guy - civilian")
124			npc_faction("crazy", "Guy - crazy")
125			npc_faction("singularity", "Guy - singularity")
126			npc_faction("neutral", "Guy - neutral")
127---------------------------------------------------------- HEALTH
128			Tux:heal()
129			Tux:hurt(1)
130			Tux:hurt(-1)
131			if (Tux:get_hp() == 60) then
132				Npc:says("HEALTH test 1 succeeded", "NO_WAIT")
133			else
134				guy_fail("HEALTH 1")
135			end
136
137			if (Tux:get_max_hp() == 60) then
138				Npc:says("HEALTH test 2 succeeded", "NO_WAIT")
139			else
140				guy_fail("HEALTH 2")
141			end
142---------------------------------------------------------- COOL
143			Tux:heat(1)
144			Tux:heat(-1)
145			if (Tux:get_cool() == 100) then
146				Npc:says("COOL test 1 succeeded", "NO_WAIT")
147			else
148				guy_fail("COOL 1")
149			end
150---------------------------------------------------------- TELEPORT
151			Tux:teleport("24-tux1")
152			Tux:teleport("24-tux2")
153			Npc:teleport("24-guy1")
154			Npc:teleport("24-guy2")
155			Dude:teleport("24-dude1")
156			Dude:teleport("24-dude2")
157---------------------------------------------------------- SKILLS
158			--Npc:says(Tux:get_skill("programming"))
159			if (not Tux:has_met("Guy")) then
160				Tux:improve_skill("programming")
161				if (Tux:get_skill("programming") == 1) then
162					Npc:says("SKILL test 1 succeeded", "NO_WAIT")
163				else
164					guy_fail("SKILL 1")
165				end
166			else
167				Tux:says("Skipping SKILL test 1 due to missing possibility to downgrade skills!")
168			end
169---------------------------------------------------------- PROGRAMMS
170			Tux:improve_program("Ricer CFLAGS")
171			Tux:downgrade_program("Ricer CFLAGS")
172			if (Tux:get_program_revision("Ricer CFLAGS") == 0) then
173				Npc:says("PROGRAMM test 1 succeeded", "NO_WAIT")
174			else
175				guy_fail("PROGRAMM 1")
176			end
177---------------------------------------------------------- QUESTS
178			if (not Tux:has_met("Guy")) then
179				if (not Tux:has_quest("24_dude_test_quest")) then
180					Npc:says("QUEST test 1 succeeded", "NO_WAIT")
181				else
182					guy_fail("QUEST 1")
183				end
184				Tux:add_quest("24_dude_test_quest", "Add 24 dude quest.")
185			else
186				Tux:says("Skipping QUEST test 1 due to missing possibility to remove quests!")
187			end
188
189			if (Tux:has_quest("24_dude_test_quest")) then
190				Npc:says("QUEST test 2 succeeded", "NO_WAIT")
191			else
192				guy_fail("QUEST 2")
193			end
194			Tux:update_quest("24_dude_test_quest", "Update 24 dude quest.")
195
196			if (not Tux:has_met("Guy")) then
197				if (not Tux:done_quest("24_dude_test_quest")) then
198					Npc:says("QUEST test 3 succeeded", "NO_WAIT")
199				else
200					guy_fail("QUEST 3")
201				end
202
203				Tux:end_quest("24_dude_test_quest", "Complete 24 dude quest.")
204				if (Tux:done_quest("24_dude_test_quest")) then
205					Npc:says("QUEST test 4 succeeded", "NO_WAIT")
206				else
207					guy_fail("QUEST 4")
208				end
209			else
210				Tux:says("Skipping QUEST test 3 due to missing possibility to remove quests!")
211				Tux:says("Skipping QUEST test 4 due to missing possibility to remove quests!")
212			end
213
214			if (Tux:has_met("Guy")) then -- need to have met guy to let the DeadGuy die...
215				if (Tux:done_quest("24_guy_death_quest")) then -- check droid markers
216					Npc:says("QUEST test 5 succeeded","NO_WAIT")
217				else
218					guy_fail("QUEST 5")
219				end
220			else
221				Tux:says("Skipping QUEST test 5, we need to have met Guy...")
222			end
223
224---------------------------------------------------------- OBSTACLES
225
226			change_obstacle_message("24_guy_sign", _"Guy signmessage B")
227			display_big_message("Sign message changed from")
228			display_big_message("Guy signmessage A' to 'Guy signmessage B'")
229
230			if (cmp_obstacle_state("24_guy_door", "opened")) then
231				Npc:says("OBSTACLE test 1 succeeded", "NO_WAIT")
232			else
233				guy_fail("OBSTACLE 1")
234			end
235			change_obstacle_state("24_guy_door", "closed")
236			if (cmp_obstacle_state("24_guy_door", "closed")) then
237				Npc:says("OBSTACLE test 2 succeeded", "NO_WAIT")
238			else
239				guy_fail("OBSTACLE 2")
240			end
241			change_obstacle_state("24_guy_door", "opened") -- 6 = door
242			change_obstacle_type("24_guy_door", "1")
243			if (get_obstacle_type("24_guy_door") == 1) then
244				Npc:says("OBSTACLE test 3 succeeded", "NO_WAIT")
245			else
246				guy_fail("OBSTACLE 3")
247			end
248			change_obstacle_type("24_guy_door", "6") -- set it back to door
249
250---------------------------------------------------------- NPC DEATH TEST
251			if (not Tux:has_met("Guy")) then
252				if (not DeadGuy:is_dead()) then
253					Npc:says("NPC DEATH test 1 succeeded", "NO_WAIT")
254				else
255					guy_fail("NPC DEATH 1")
256				end
257
258				DeadGuy:drop_dead() -- kill Dude
259			end
260
261			if not (running_benchmark()) then -- remember: our dialog validator is quite dump :(
262				if (DeadGuy:is_dead()) then
263					Npc:says("NPC DEATH test 2 succeeded", "NO_WAIT")
264				else
265					guy_fail("NPC DEATH 2")
266				end
267			end
268
269			-- one day we might be able to revive DeadGuy
270
271			--[[ if (not Dude:is_dead()) then
272			Npc:says("NPC DEATH test 3 succeeded", "NO_WAIT")
273		else
274			guy_fail("NPC DEATH 3")
275			end ]]--
276---------------------------------------------------------- FACTION DEATH TEST
277			if (not Tux:has_met("Guy")) then
278				if (not FactionDeadBot:is_dead()) then  -- it's alive
279					Npc:says("FACTION DEATH test 1 succeeded", "NO_WAIT")
280				else
281					guy_fail("FACTION DEATH 1")
282				end
283
284				kill_faction("test") -- kill test faction
285
286				if not (running_benchmark()) then -- remember: our dialog validator is quite dump :(
287					if (FactionDeadBot:is_dead()) then -- we killed it, it's dead
288						Npc:says("FACTION DEATH test 2 succeeded", "NO_WAIT")
289					else
290						guy_fail("FACTION DEATH 2")
291					end
292				end
293				-- @TODO: implement revive and additional checks
294				respawn_level(24) --respawn level, now check if bot is alive again
295				if not (running_benchmark()) then -- remember: our dialog validator is quite dump :(
296					if (not FactionDeadBot:is_dead()) then --it's alive again
297						Npc:says("FACTION DEATH test 3 succeeded", "NO_WAIT")
298					else
299						guy_fail("FACTION DEATH 3")
300					end
301				end
302				-- now check if kill_faction with no_respawn works
303				kill_faction("test", "no_respawn")
304				if not (running_benchmark()) then -- remember: our dialog validator is quite dump :(
305					if (FactionDeadBot:is_dead()) then -- we killed it, it's dead
306						Npc:says("FACTION DEATH test 4 succeeded", "NO_WAIT")
307					else
308						guy_fail("FACTION DEATH 4")
309					end
310				end
311					-- now respawn and check if its still dead.
312				respawn_level(24)
313				if not (running_benchmark()) then -- remember: our dialog validator is quite dump :(
314					if (FactionDeadBot:is_dead()) then -- we killed it, no_respawn was given, it should still be dead
315						Npc:says("FACTION DEATH test 5 succeeded", "NO_WAIT")
316					else
317						guy_fail("FACTION DEATH 5")
318					end
319				end
320			end
321---------------------------------------------------------- EVENTS
322			if not (running_benchmark()) then
323				if (l24_event_test == "works" ) then
324					Npc:says("EVENT test 1 (map label) succeeded", "NO_WAIT")
325				else
326					guy_fail("EVENT test 1 (map label)")
327				end
328			end
329
330			if not (running_benchmark()) then
331				if (DeadGuy_death_trigger == "works" ) then
332					Npc:says("EVENT test 2 (death event) succeeded", "NO_WAIT")
333				else
334					guy_fail("EVENT test 2 (death event)")
335				end
336			end
337
338			Guy_24_to_70_passed = false --reset these here.
339			Guy_70_to_24_passed = false -- needed because we might have walked around manually
340			if not (running_benchmark()) then
341				-- tux is on lvl 24 currently
342				teleport("24-exit-level-70") -- teleport from level 24 to level 70, to a label
343				if (Guy_24_to_70_passed) then -- the from24to70 event worked!    the event also teleport tux back to level 24 (from70to24!)...
344					Npc:says("EVENT test 3 (Entering 70, exiting 24) succeeded", "NO_WAIT")
345				else
346					guy_fail("EVENT test 3 (Entering 70, exiting 24)")
347				end
348
349				if (Guy_70_to_24_passed) then -- ... which sets this as true.   tux is also teleported to label 24-tux2
350					Npc:says("EVENT test 4 (Entering 24, exiting 70) succeeded", "NO_WAIT")
351				else
352					guy_fail("EVENT test 4 (Entering 24, exiting 70)")
353				end
354			end
355
356
357
358
359---------------------------------------------------------- Gold
360			if (Tux:get_gold() == 0) then
361				Npc:says("GOLD test 1 succeed", "NO_WAIT")
362			else
363				guy_fail("GOLD 1")
364			end
365
366			Tux:add_gold(100)
367			if (Tux:get_gold() == 100) then
368				Npc:says("GOLD test 2 succeed", "NO_WAIT")
369			else
370				guy_fail("GOLD 2")
371			end
372
373			if (not Tux:del_gold(1000)) then
374				Npc:says("GOLD test 3 succeed", "NO_WAIT")
375			else
376				guy_fail("GOLD 3")
377			end
378
379			if (Tux:get_gold() == 100) then -- check if gold changed, just to be sure...
380				Npc:says("GOLD test 4 succeed", "NO_WAIT")
381			else
382				guy_fail("GOLD 4")
383			end
384
385			if (Tux:del_gold(100)) then
386				Npc:says("GOLD test 5 succeed", "NO_WAIT")
387			else
388				guy_fail("GOLD 5")
389			end
390
391			Tux:add_gold(100)
392			Tux:add_gold(-100)
393			if (Tux:get_gold() == 0) then
394				Npc:says("GOLD test 6 succeed")
395			else
396				guy_fail("GOLD 6")
397			end
398
399
400---------------------------------------------------------- RUSH TUX
401			if (not Tux:has_met("Guy")) then
402				if not (Npc:get_rush_tux()) then
403					Npc:says("RUSH TUX test 1 succeed", "NO_WAIT")
404				else
405					guy_fail("RUSH TUX 1")
406				end
407			else
408				Tux:says("Skipping RUSH TUX test 1 because it would fail since we directly rush tux on second time we call the dialog.")
409			end
410
411			Npc:set_rush_tux(true)
412
413			if (Npc:get_rush_tux()) then
414				Npc:says("RUSH TUX test 2 succeed", "NO_WAIT")
415			else
416				guy_fail("RUSH TUX 2")
417			end
418---------------------------------------------------------- OTHER
419			-- print some useless colorful foo
420
421			Guy_colors={"black", "red", "green", "yellow", "blue", "purple", "cyan", "white"}
422			if (running_benchmark()) then -- for nodes we use printf which has no linebreak at the end.
423				print("")				  -- "black" would get appended directly to a node but this avoids it.
424			end
425
426			for k, color in ipairs(Guy_colors) do
427				print(FDutils.text.highlight(color, color))
428			end
429
430			Npc:set_death_item("Pandora's Cube")
431			Npc:says("")
432			display_big_message("Big Message")
433			display_console_message("Console message, [b]blue[/b], not blue.")
434			end_dialog()
435			Guy_dialog_executing = false
436		end,
437	},
438	{
439		id = "node99",
440		text = "logout",
441		code = function()
442			end_dialog()
443		end,
444	},
445}
446