sr2lua/rn03.lua

  1. -- rn03.lua 
  2. -- SR2 mission script 
  3. -- 3/28/07 
  4.  
  5. -- Global constants ( ALL_CAPS means that they shouldn't be modified in running code, except for maybe in a setup function ) 
  6.  
  7. -- 21 - 23 
  8.  
  9. 	-- KNOBS_TO_TURN -- 
  10.  
  11. 		-- If set to TRUE, Ronin bikes are automatically detonated if their driver is killed 
  12. 			AUTO_DETONATE_RIDERLESS_BIKES	= false 
  13. 			-- Before detonating the bike, we make it start smoking and then catch on fire. These params control that process. 
  14. 				BIKE_SMOKE_TO_FIRE_DELAY_S		= .50		-- Delay between starting a bike smoking and catching it on fire 
  15. 				BIKE_FIRE_TO_EXPLODE_DELAY_S	= .50		-- Delay between the bike starting on fire, and it exploding	 
  16.  
  17. 		-- Maximum Ronin notoriety throughout the mission 
  18. 			RONIN_NOTORIETY_MAX				= 2 
  19. 			POLICE_NOTORIETY_MAX			= 2 
  20.  
  21. 		-- Hit points of player bike(s) 
  22. 			PLAYER_BIKE_HIT_POINTS			= 3000 
  23.  
  24. 		-- Stage 1: fight initial convoy 
  25.  
  26.  
  27. 			--[[ *** READ ME *** 
  28. 			 
  29. 				In Coop, the players can chose to drive separately or ride together. If they chose the latter option, 
  30. 				then the passenger is free to concentrate on shooting, which makes the mission much easier. For this reason, 
  31. 				I've decided to create three sets of parameters for each wave: one for single player, one for coop on  
  32. 				separate vehicles, and one for coop on the same vehicle. 
  33.  
  34. 				Whenever a script function looks up a wave parameter, a naming convention is used to select the appropriate value. 
  35. 				Parameter values for single player missions can use any name, say "PARAMETER_1" for example. If you wish to have 
  36. 				a different value for that parameter in coop, then prepend "COOP" to the parameter name. In this case, we get 
  37. 				"COOP_PARAMETER_1". If yet another value is desired for coop missions when both players are on the same bike, then 
  38. 				use the prefix "COOP_SAME_BIKE", which gives us "COOP_SAME_BIKE_PARAMETER_1". 
  39.  
  40. 				When a mission function needs to access "PARAMETER_1", it will search for the appropriate overloaded values first: 
  41.  
  42. 					*	Single player will use the value stored in "PARAMETER_1". 
  43. 				 
  44. 					*	Different-vehicle coop will use the value stored in "COOP_PARAMETER_1", if it exists. Otherwise it will use the 
  45. 						default single player value stored in "PARAMETER_1". 
  46. 				 
  47. 					*	Same-vehicle adds another step, looking for "COOP_SAME_BIKE_PARAMETER_1", then "COOP_PARAMETER_1", then  
  48. 						"PARAMETER_1" 
  49.  
  50. 				In some situations, you may want a parametr to have the same value in single player and normal coop, but a different 
  51. 				value if both players are on the same bike. I've done this with the "TRAFFIC_DENSITY" parameter by adding  
  52. 				"COOP_SAME_BIKE_TRAFFIC_DENSITY". When both players are on the same bike, one player can concentrate on driving  
  53. 				while the other player concentrates on shooting, so I think it makes sense to increase the traffic density. If you  
  54. 				want the same density no matter, what, just remove the "COOP_SAME_BIKE_TRAFFIC_DENSITY" entry in the WAVE_PARAMETERS 
  55. 				table. No other code changes are needed. 
  56.  
  57. 				In a coop mission, if the players play for a while on separate bikes, and then switch to the same bike, or vice versa, 
  58. 				only some of the parameters will be adjusted dynamically. Traffic density, for example, is set whenever a new wave 
  59. 				is created. If the players get to the start of a new wave on the same bike, and subsequently split up, then they will 
  60. 				have to deal with the higher traffic density. If this becomes a problem, then I could add code to remedy the 
  61. 				situation. Here is the list of parameters, and whether or not they are dynamically updated: 
  62.  
  63. 				"START_DIST_M"			no 
  64. 				"TRAFFIC_DENSITY"		yes 
  65. 				"SLOW_SPEED"			yes 
  66. 				"FAST_SPEED"			yes 
  67. 				"CLOSE_RANGE_M"		yes 
  68. 				"BIKE_HP"				no 
  69. 				"DRIVER_HP"				no 
  70. 				"MAX_RONIN"				no 
  71.  
  72. 			 ]] 
  73.  
  74. 			TEST_PATH	= 
  75. 			{ 
  76. 				"rn03_$n000"; 
  77. 				{	 
  78. 					"rn03_$n046", 
  79. 					"rn03_$n047", 
  80. 				}; 
  81. 			} 
  82.  
  83. 			-- Wave parameters 
  84. 			WAVE_PARAMETERS	=  
  85. 				{	 
  86. 					["wave_1"]	=	{	 
  87. 											-- A wave of bikers starts pathfinding when a player gets too close or too far to the 
  88. 											-- first bike's location 
  89. 											["START_DIST_NEAR_M"]= 150,	-- Start wave pathfinding when a player gets this close 
  90. 											["START_DIST_FAR_M"]	= 200,	-- Start wave pathfinding when a player gets this far 
  91.  
  92. 											["TRAFFIC_DENSITY"]	= .40,	-- Traffic density during wave. (1.00 is normal) 
  93. 											["SLOW_SPEED"]			= 50,		-- Speed of Ronin when player is in close range 
  94. 											["FAST_SPEED"]			= 65,		-- Speed of Ronin when player is not in close range 
  95. 											["CLOSE_RANGE_M"]		= 50,		-- Distance considered to be close range 
  96. 											["BIKE_HP"]				= 500,	-- Bike's Hit Points 
  97. 											["DRIVER_HP"]			= 250,	-- Driver's Hit Points 
  98. 											["MAX_RONIN"]			= 0,		-- The maximum number of Ronin that can be on non-disabled 
  99. 																					-- bikes after this wave spawns. If the number is 0, then 
  100. 																					-- all Ronin in the current wave will spawn regardless of the 
  101. 																					-- number of Ronin already active. 
  102. 											["BIKES"]				= {	"rn03_$v000", "rn03_$v001", "rn03_$v002", "rn03_$v007"}, -- Bikes in this wave 
  103. 											["DRIVERS"]				= {	"rn03_$c000", "rn03_$c001", "rn03_$c002", "rn03_$c004"}, -- Drivers in this wave 
  104. 											["PASSENGERS"]			= {	"rn03_$c003", "rn03_$c012", "rn03_$c013", "rn03_$c014"},	-- Passengers in this wave 
  105.  
  106. 											["PATH"]					= {	{	"rn03_$n003", "rn03_$n004", "rn03_$n021", "rn03_$n022", "rn03_$n023"}, 
  107. 																				{  "rn03_$n024", "rn03_$n025", "rn03_$n026", "rn03_$n027", "rn03_$n028"}, 
  108. 																				{	"rn03_$n029", "rn03_$n030", "rn03_$n031", "rn03_$n032", "rn03_$n033"},  
  109. 																				{	"rn03_$n034", "rn03_$n035", "rn03_$n036", "rn03_$n037", "rn03_$n038"},  
  110. 																				{	"rn03_$n039", "rn03_$n040", "rn03_$n041", "rn03_$n042", "rn03_$n043"}, 
  111. 																			}, 
  112.  
  113. 											-- coop values 
  114. 											["COOP_BIKE_HP"]				= 1000, 
  115. 											["COOP_DRIVER_HP"]			= 500, 
  116.  
  117. 											-- coop, on same bike values 
  118. 											["COOP_SAME_BIKE_TRAFFIC_DENSITY"]	= .60 
  119. 										}; 
  120.  
  121. 					["wave_2"]	=	{	["START_DIST_NEAR_M"]		= 150,	 
  122. 											["TRAFFIC_DENSITY"]	= .60,  
  123. 											["SLOW_SPEED"]			= 50,   
  124. 											["FAST_SPEED"]			= 65,   
  125. 											["CLOSE_RANGE_M"]		= 65,   
  126. 											["BIKE_HP"]				= 1000,	-- Bike's Hit Points 
  127. 											["DRIVER_HP"]			= 500,	-- Driver's Hit Points 
  128. 											["MAX_RONIN"]			= 5, 
  129. 											["BIKES"]				= {	"rn03_$v003", "rn03_$v004", "rn03_$v006"}, 
  130. 											["DRIVERS"]				= {	"rn03_$c005", "rn03_$c006", "rn03_$c008"}, 
  131. 											["PASSENGERS"]			= {	"rn03_$c009", "rn03_$c010", "rn03_$c011"}, 
  132. 											["PATH"]					= {	{	"rn03_$n004", "rn03_$n021", "rn03_$n022", "rn03_$n023", "rn03_$n024" }, 
  133. 																			{	"rn03_$n025", "rn03_$n026", "rn03_$n027" },  
  134. 																			{	"rn03_$n028", "rn03_$n029", "rn03_$n030", "rn03_$n031", "rn03_$n032" }, 
  135. 																			{	"rn03_$n033", "rn03_$n034", "rn03_$n035" }, 
  136. 																			{	"rn03_$n036", "rn03_$n037", "rn03_$n038", "rn03_$n039", "rn03_$n040" }, 
  137. 																			{	"rn03_$n041", "rn03_$n042", "rn03_$n043" } 
  138. 																			}, 
  139. 											-- coop values 
  140. 											["COOP_BIKE_HP"]				= 1200, 
  141. 											["COOP_DRIVER_HP"]			= 600, 
  142.  
  143. 											-- coop, on same bike values 
  144. 											["COOP_SAME_BIKE_TRAFFIC_DENSITY"]	= .80 
  145. 										} 
  146. 				} 
  147.  
  148. 	-- COOP MISSION? --  
  149. 		IN_COOP	= false 
  150.  
  151. 	-- CHARACTERS -- 
  152.  
  153. 	-- CHECKPOINTS 
  154. 		 
  155. 		CHECKPOINT_START						= MISSION_START_CHECKPOINT		-- defined in ug_lib.lua 
  156. 		CHECKPOINT_LIEUTENANTS				= "rn03_checkpoint_lieutenants" 
  157.  
  158. 	-- GROUPS -- 
  159.  
  160. 		GROUP_PLAYER_BIKE_1	= "rn03_$Gplayer_bike_1" 
  161. 		GROUP_PLAYER_BIKE_2	= "rn03_$Gplayer_bike_2" 
  162. 		GROUP_RONIN_WAVE_1	= "rn03_$Gronin_wave_1" 
  163. 		GROUP_RONIN_WAVE_2	= "rn03_$Gronin_wave_2" 
  164.  
  165. 		-- List of all groups, makes cleaning up more convenient 
  166. 		TABLE_ALL_GROUPS			= {	GROUP_PLAYER_BIKE_1, GROUP_RONIN_WAVE_1, GROUP_RONIN_WAVE_2} 
  167.  
  168. 		TABLE_ALL_COOP_GROUPS	= {	GROUP_PLAYER_BIKE_2} 
  169.  
  170. 	-- GROUP MEMBER TABLES --  
  171.  
  172. 	-- HELPTEXT 
  173.  
  174. 		-- localized helptext messages 
  175. 		HELPTEXT_PROMPT_BIKE					= "rn03_prompt_bike"					-- "Use the bike to intercept the Ronin." 
  176. 		HELPTEXT_PROMPT_KILL_RONIN			= "rn03_prompt_kill_ronin"			-- "Take out the Ronin before they get to your turf!"  
  177. 		HELPTEXT_PROMPT_WARNING				= "rn03_prompt_warning"				-- "You have X targets left, hurry and take them out before they get away!"  
  178. 		HELPTEXT_PROMPT_KILL_LIEUTENANTS = "rn03_prompt_kill_lieutenants" -- "Chase the Ronin lieutenants down and kill them."  
  179. 		HELPTEXT_PROMPT_ANOTHER_GROUP		= "rn03_prompt_another_group"		-- "Careful, there's another group of Ronin ahead" 
  180. 		HELPTEXT_PROMPT_MORE_RONIN			= "rn03_prompt_more_ronin"			--	"More Ronin have joined the fight!" 
  181. 		HELPTEXT_PROMPT_REINFORCEMENTS	= "rn03_prompt_ronin_reinforcements" -- Intercept the Ronin reinforcements downtown. 
  182. 		HELPTEXT_PROMPT_BIKE_DESTROYED	= "rn03_prompt_bike_destroyed"	-- "Ronin bike disabled!"  
  183. 		HELPTEXT_PROMPT_CROSSING_BRIDGE	= "rn03_prompt_crossing_bridge"	-- "The Ronin are crossing the bridge to Saints HQ!" 
  184. 		HELPTEXT_PROMPT_ALMOST_THERE		= "rn03_prompt_almost_there"			-- "The Ronin are almost at Saints HQ!" 
  185. 		HELPTEXT_PROMPT_REENTER_BIKE		= "rn03_prompt_reenter_bike"		-- "Get back on the bike" 
  186.  
  187. 		HELPTEXT_FAILURE_DISTANCE			= "rn03_failure_distance"			-- "You let too many Ronin get past you." 
  188. 		HELPTEXT_FAILURE_RANGE				= "rn03_failure_range"				-- "You let the Ronin get away." 
  189. 		HELPTEXT_FAILURE_BIKE_DESTROYED  = "rn03_failure_bike_destroyed"  -- "Motorcycle destroyed." 
  190. 		HELPTEXT_FAILURE_BIKE_TIME			= "rn03_failure_bike_time"			-- "You didn't get on the bike in time." 
  191.  
  192. 		HELPTEXT_OBJECTIVE_BIKE				= "rn03_objective_bike"				-- "Get on the bike." 
  193. 		HELPTEXT_OBJECTIVE_KILL_RONIN		= "rn03_objective_kill_ronin"		-- "%s of %s Ronin bikes disabled" 
  194.  
  195.  
  196. 	-- MOVERS 
  197.  
  198. 	-- NAVPOINTS 
  199.  
  200. 		NAVPOINT_LOCAL_PLAYER_START		= "mission_start_sr2_city_$rn03" 
  201. 		NAVPOINT_REMOTE_PLAYER_START		= "rn03_$Nremote_player_start" 
  202.  
  203. 	-- TRIGGERS --  
  204.  
  205. 		-- List of all triggers, makes cleaning up more convenient 
  206. 		TABLE_ALL_TRIGGERS		= {	}		 
  207.  
  208. 	-- VEHICLES -- 
  209. 		VEHICLE_PLAYER_BIKE_1	= "rn03_$Vplayer_bike_1" 
  210. 		VEHICLE_PLAYER_BIKE_2	= "rn03_$Vplayer_bike_2" 
  211.  
  212. 	-- MISC 
  213. 			 
  214. 		OFF_BIKE_TIME_LIMIT_S	= 15	-- How long a player can be off of a bike before triggering mission failure. 
  215.  
  216. 		PLAYER_SYNC								= 
  217. 			{ 
  218. 				[LOCAL_PLAYER]					= SYNC_LOCAL, 
  219. 				[REMOTE_PLAYER]				= SYNC_ALL, 
  220. 			} 
  221.  
  222. 		WAVE_LIST								= {"wave_1", "wave_2"} -- List of all the waves of bikes 
  223.  
  224. 		RN03_RONIN_PERSONAS	=  
  225. 		{ 
  226. 			["AM_Ron2"]	=	"AMRON2", 
  227.  
  228. 			["AF_Ron1"]	=	"AFRON1", 
  229.  
  230. 			["WM_Ron1"]	=	"WMRON1", 
  231.  
  232. 			["WF_Ron2"]	=	"WFRON2", 
  233. 		} 
  234.  
  235. 		FREE_WEAPON_GUN						= "tec9" 
  236. 		 
  237. -- Progress flags 
  238. 	Warning_1_played					= false 
  239. 	Warning_2_played					= false 
  240.  
  241. -- Misc 
  242.  
  243. 	-- Vehicles that the players are in/on.  
  244. 	Player_vehicles			= {[LOCAL_PLAYER] = "", 
  245. 										[REMOTE_PLAYER]= ""} 
  246.  
  247. 	Players_in_same_vehicle	= false 	-- Are the players in/on the same vehicle? 
  248. 	Bikes_disabled		= {}				-- Maps from bike name -> bool (true if bike is disabled, false else)	 
  249. 	Bikes_remaining	= 0				-- Number of bikes remaining from all waves combined. 
  250. 	Bikes_to_kill = 0						-- In the "Kill X/Y Bikes" objective, the Y value. 
  251. 	Driver_to_bike_mapping	= {}		-- Maps from the Driver to his bike 
  252. 	Bike_to_wave_mapping		= {}		-- Maps from the bike to its wave 
  253. 	Last_wave					= "" 		-- The most recently spawned wave. 
  254. 	Current_wave_index		= 1		-- The next wave of bikes that will be spawned. 
  255.  
  256. 	Rn03_bike_to_passenger = {} 
  257. 	Weapons_received							= false 
  258.  
  259. function rn03_start(rn03_checkpoint, is_restart) 
  260.  
  261. 	mission_start_fade_out() 
  262.  
  263. 	if(rn03_checkpoint == CHECKPOINT_START) then 
  264. 		if (not is_restart) then 
  265. 			cutscene_play("ro03-01", "", {NAVPOINT_LOCAL_PLAYER_START, NAVPOINT_REMOTE_PLAYER_START}, false) 
  266. 		else 
  267. 			teleport_coop(NAVPOINT_LOCAL_PLAYER_START, NAVPOINT_REMOTE_PLAYER_START) 
  268. 		end 
  269. 		fade_out(0) 
  270. 	end 
  271.  
  272. 	rn03_initialize(rn03_checkpoint) 
  273.  
  274. 	if(rn03_checkpoint == CHECKPOINT_START) then 
  275.  
  276. 		-- Warn players as the Ronin get closer to the Saints HQ 
  277. 		thread_new("rn03_proximity_warnings") 
  278.  
  279. 		-- Start throttling bike speeds 
  280. 		thread_new("rn03_bike_speed_throttle") 
  281.  
  282. 		-- Provide a gps path to the closest bike 
  283. 		thread_new("rn03_gps") 
  284.  
  285. 		-- Process waves of attacking Ronin 
  286. 		mission_help_table(HELPTEXT_PROMPT_KILL_RONIN) 
  287. 		rn03_process_waves() 
  288.  
  289. 	end -- ends CHECKPOINT_START 
  290.  
  291. 	-- Mission ends 
  292. 	rn03_complete() 
  293.  
  294. end 
  295.  
  296. function rn03_initialize(checkpoint) 
  297.  
  298. 	rn03_initialize_common() 
  299.  
  300. 	rn03_initialize_checkpoint(checkpoint) 
  301.  
  302. 	mission_start_fade_in() 
  303.  
  304. end 
  305.  
  306. -- Initialization code shared by all checkpoints. 
  307. function rn03_initialize_common() 
  308.  
  309. 	-- Start trigger is hit...the activate button was hit 
  310. 	set_mission_author("Phillip Alexander") 
  311.  
  312. 	if coop_is_active() then 
  313. 		IN_COOP = true 
  314. 	end 
  315.  
  316. 	-- Set the maximum notoriety 
  317. 	notoriety_set_max("Ronin",RONIN_NOTORIETY_MAX) 
  318. 	notoriety_set_max("Police",POLICE_NOTORIETY_MAX)	 
  319.  
  320. 	-- Override persona lines for attacking Ronin. 
  321. 	persona_override_group_start(RN03_RONIN_PERSONAS,POT_SITUATIONS[POT_ATTACK], "RO03_ATTACK") 
  322. 	 
  323. 	--give the player a sub machine gun with unlimited ammo 
  324. 	inv_weapon_add_temporary(LOCAL_PLAYER, FREE_WEAPON_GUN, 1, true, true) 
  325. 	if (IN_COOP) then 
  326. 		inv_weapon_add_temporary(REMOTE_PLAYER, FREE_WEAPON_GUN, 1, true, true) 
  327. 	end 
  328. 	Weapons_received	= true 
  329.  
  330. end 
  331.  
  332. -- Initialization code specific to the checkpoint. 
  333. function rn03_initialize_checkpoint(checkpoint) 
  334.  
  335. 	if(checkpoint == CHECKPOINT_START) then 
  336.  
  337. 		-- Start loading groups 
  338. 		group_create(GROUP_PLAYER_BIKE_1, true) 
  339. 		if (IN_COOP) then 
  340. 			group_create(GROUP_PLAYER_BIKE_2, true) 
  341. 		end 
  342. 		group_create_hidden(GROUP_RONIN_WAVE_1) 
  343. 		group_create_hidden(GROUP_RONIN_WAVE_2) 
  344.  
  345. 		-- add callbacks to players for vehicle enter/exit, tracks if players in the same vehicle (only for COOP) 
  346. 		if (IN_COOP) then 
  347. 			on_vehicle_enter("rn03_player_entered_vehicle", LOCAL_PLAYER) 
  348. 			on_vehicle_exit("rn03_player_exited_vehicle", LOCAL_PLAYER)	 
  349. 			on_vehicle_enter("rn03_player_entered_vehicle", REMOTE_PLAYER) 
  350. 			on_vehicle_exit("rn03_player_exited_vehicle", REMOTE_PLAYER) 
  351. 		end 
  352.  
  353. 		-- place players in bikes 
  354. 		vehicle_enter_teleport(LOCAL_PLAYER,VEHICLE_PLAYER_BIKE_1,0) 
  355. 		if (IN_COOP) then 
  356. 			vehicle_enter_teleport(REMOTE_PLAYER,VEHICLE_PLAYER_BIKE_2,0)				 
  357. 		end 
  358.  
  359. 		-- Setup the players' bikes 
  360. 		vehicle_never_flatten_tires(VEHICLE_PLAYER_BIKE_1, true) 
  361. 		set_max_hit_points(VEHICLE_PLAYER_BIKE_1, PLAYER_BIKE_HIT_POINTS) 
  362. 		if (IN_COOP) then 
  363. 			vehicle_never_flatten_tires(VEHICLE_PLAYER_BIKE_2, true)	 
  364. 			set_max_hit_points(VEHICLE_PLAYER_BIKE_2, PLAYER_BIKE_HIT_POINTS) 
  365. 		end 
  366.  
  367.  
  368. 	end -- ends CHECKPOINT_START 
  369.  
  370. end 
  371.  
  372. -- Plays warnings that Ronin are getting close/arrived at Saints HQ. 
  373. function rn03_proximity_warnings() 
  374.  
  375. 	while(true) do 
  376.  
  377. 		-- Play a warning when the first bike is crossing the bridge 
  378. 		if(not Warning_1_played) then 
  379. 			for bike,disabled in pairs(Bikes_disabled) do 
  380. 				if (not disabled) then 
  381. 					local dist = get_dist(bike, "rn03_$n033") 
  382. 					if (dist < 50.0) then 
  383. 						mission_help_table(HELPTEXT_PROMPT_CROSSING_BRIDGE) 
  384. 						Warning_1_played = true 
  385. 					end 
  386. 				end 
  387. 			end 
  388. 		end 
  389.  
  390. 		-- Play a warning when a bike is nearing the saint's HQ 
  391. 		if(not Warning_2_played) then 
  392. 			for bike,disabled in pairs(Bikes_disabled) do 
  393. 				if (not disabled) then 
  394. 					local dist = get_dist(bike, "rn03_$n043") 
  395. 					if (dist < 300.0) then 
  396. 						mission_help_table(HELPTEXT_PROMPT_ALMOST_THERE) 
  397. 						-- It shouldn't be possible, but if a Ronin manages to get this close to HQ w/out crossing the bridge, then 
  398. 						-- the bridge message shouldn't be played. 
  399. 						Warning_1_played = true 
  400. 						Warning_2_played = true 
  401. 					end 
  402. 				end 
  403. 			end 
  404. 		end 
  405.  
  406. 		-- Fail the mission if a bike gets too close to the Saint's hq 
  407. 		for bike,disabled in pairs(Bikes_disabled) do 
  408. 			if (not disabled) then 
  409. 				local dist = get_dist(bike, "rn03_$n043") 
  410. 				if (dist < 50.0) then 
  411. 					rn03_failure_ronin_in_row() 
  412. 				end 
  413. 			end 
  414. 		end 
  415.  
  416. 		thread_yield() 
  417.  
  418. 	end 
  419. end 
  420.  
  421. function rn03_player_entered_vehicle(player, vehicle) 
  422. 	Player_vehicles[player] = vehicle 
  423.  
  424. 	-- Don't need to special case both player's vehicle being "" because we know someone just entered a vehicle 
  425. 	if ( Players_in_same_vehicle ~= (Player_vehicles[player] == Player_vehicles[rn03_get_other_player(player)] )) then 
  426. 		Players_in_same_vehicle = not Players_in_same_vehicle 
  427.  
  428. 		-- Update the traffic density 
  429. 		set_traffic_density(rn03_wave_parameter(Last_wave,"TRAFFIC_DENSITY")) 
  430. 	end 
  431. end 
  432.  
  433. function rn03_player_exited_vehicle(player, vehicle) 
  434. 	Player_vehicles[player] = "" 
  435.  
  436. 	if (Players_in_same_vehicle ~= false) then 
  437. 		Players_in_same_vehicle = false 
  438.  
  439. 		-- Update the traffic density 
  440. 		set_traffic_density(rn03_wave_parameter(Last_wave,"TRAFFIC_DENSITY")) 
  441. 	end 
  442.  
  443. end 
  444.  
  445. function rn03_get_other_player(player) 
  446. 	if (player == LOCAL_PLAYER) then 
  447. 		return REMOTE_PLAYER 
  448. 	else 
  449. 		return LOCAL_PLAYER 
  450. 	end 
  451. end 
  452.  
  453. function rn03_process_waves() 
  454.  
  455. 	-- Setup all bikes in all waves 
  456. 	for i, wave_name in pairs(WAVE_LIST) do 
  457. 		rn03_setup_wave_bikes(wave_name) 
  458. 	end 
  459.  
  460. 	-- Send waves one at a time, sending the next wave when a player is too close or 
  461. 	-- too far from the first bike. If all of the previously spawned bikes are disabled,  
  462. 	-- add a waypoint to the next wave's position. 
  463.  
  464. 	local last_wave_index = sizeof_table(WAVE_LIST) 
  465. 	while(Current_wave_index <= last_wave_index) do 
  466.  
  467. 		local wave_name = WAVE_LIST[Current_wave_index] 
  468.  
  469. 		-- Monitor distance to the first bike in the wave. 
  470. 		local first_bike = rn03_wave_parameter(wave_name,"BIKES",1) 
  471. 		local start_dist_near = rn03_wave_parameter(wave_name,"START_DIST_NEAR_M") 
  472. 		local start_dist_far = rn03_wave_parameter(wave_name,"START_DIST_FAR_M") 
  473. 		if (start_dist_far == nil) then 
  474. 			start_dist_far = 99999 
  475. 		end 
  476. 		local dist = (start_dist_near + start_dist_far) / 2 
  477.  
  478. 		while( dist > start_dist_near and dist < start_dist_far) do  
  479.  
  480. 			dist = get_dist_closest_player_to_object(first_bike) 
  481. 			thread_yield() 
  482.  
  483. 		end 
  484.  
  485. 		-- Keep track of the most recently spawned wave 
  486. 		Last_wave = wave_name 
  487.  
  488. 		-- Set the traffic density for this wave 
  489. 		set_traffic_density(rn03_wave_parameter(wave_name,"TRAFFIC_DENSITY")) 
  490. 		 
  491. 		rn03_send_wave(HELPTEXT_PROMPT_MORE_RONIN, wave_name) 
  492.  
  493. 		Current_wave_index = Current_wave_index + 1 
  494.  
  495. 	end 
  496.  
  497. 	while(Bikes_remaining > 0) do 
  498. 		thread_yield() 
  499. 	end 
  500.  
  501. end 
  502.  
  503. -- Keep the gps path updated 
  504. function rn03_gps() 
  505.  
  506. 	local current_gps_mode = 0 
  507. 	local gps_mode_location = 1 
  508. 	local gps_mode_bikes = 2 
  509. 	 
  510. 	-- Wait for the first wave of bikes to spawn. 
  511. 	while(Bikes_remaining == 0) do 
  512. 		thread_yield() 
  513. 	end 
  514.  
  515. 	while(true) do 
  516.  
  517. 		-- What should our new gps mode be? 
  518. 		local new_gps_mode = gps_mode_location 
  519. 		if(Bikes_remaining > 0) then 
  520. 			new_gps_mode = gps_mode_bikes 
  521. 		end 
  522.  
  523. 		-- If we've changed gps modes 
  524. 		if(current_gps_mode ~= new_gps_mode) then 
  525.  
  526. 			current_gps_mode = new_gps_mode 
  527.  
  528. 			-- Call the new mode's gps function 
  529. 			if(current_gps_mode == gps_mode_bikes) then 
  530. 				rn03_bike_gps_path() 
  531. 			else 
  532. 				rn03_wave_gps_path() 
  533. 			end 
  534. 		end 
  535.  
  536. 		thread_yield() 
  537.  
  538. 	end 
  539.  
  540. end 
  541.  
  542. -- Add a GPS path to the start of the next wave 
  543. function rn03_wave_gps_path() 
  544.  
  545. 	if (Current_wave_index > sizeof_table(WAVE_LIST)) then 
  546. 		return 
  547. 	elseif (Current_wave_index > 1) then 
  548. 		mission_help_table(HELPTEXT_PROMPT_REINFORCEMENTS) 
  549. 	end 
  550.  
  551. 	local wave_name = WAVE_LIST[Current_wave_index] 
  552. 	local first_bike = rn03_wave_parameter(wave_name,"BIKES",1)			 
  553.  
  554. 	mission_waypoint_add(first_bike, SYNC_ALL) 
  555. 	marker_add_navpoint(first_bike,MINIMAP_ICON_LOCATION,INGAME_EFFECT_LOCATION,SYNC_ALL) 
  556.  
  557. 	while(Bikes_remaining == 0) do 
  558. 		thread_yield() 
  559. 	end 
  560.  
  561. 	mission_waypoint_remove(SYNC_ALL) 
  562. 	marker_remove_navpoint(first_bike, SYNC_ALL) 
  563.  
  564. end 
  565.  
  566. -- Keep a GPS path to the closest bike. 
  567. function rn03_bike_gps_path() 
  568.  
  569. 	local min_gps_dist = 100 
  570. 	local gps_bike = {[LOCAL_PLAYER] = "", [REMOTE_PLAYER] = ""} 
  571.  
  572. 	-- Get the bike that the GPS should point the player to 
  573. 	local function get_new_gps_bike(player) 
  574.  
  575. 		local closest_bike = "" 
  576. 		local closest_dist = 0 
  577.  
  578. 		if (Bikes_remaining > 0) then 
  579. 			for bike, disabled in pairs(Bikes_disabled) do 
  580. 				if( not disabled) then 
  581. 					local dist = get_dist(player, bike) 
  582. 					if( (closest_bike == "") or (dist < closest_dist) ) then 
  583. 						closest_bike = bike 
  584. 						closest_dist = dist 
  585. 					end 
  586. 				end	 
  587. 			end 
  588. 		end 
  589. 		 
  590. 		if (closest_dist >= min_gps_dist) then 
  591. 			return closest_bike 
  592. 		else 
  593. 			return "" 
  594. 		end 
  595.  
  596. 	end 
  597.  
  598. 	-- Update the gps for the input player 
  599. 	local function update_bike_gps(player) 
  600. 		local new_gps_bike = get_new_gps_bike(player) 
  601. 		if (new_gps_bike ~= gps_bike[player]) then 
  602. 			if(gps_bike[player] ~= "") then 
  603. 				mission_waypoint_remove(PLAYER_SYNC[player]) 
  604. 			end 
  605. 			gps_bike[player] = new_gps_bike 
  606. 			if(new_gps_bike ~= "") then 
  607. 				mission_waypoint_add(new_gps_bike, PLAYER_SYNC[player]) 
  608. 			end 
  609. 		end 
  610. 	end 
  611.  
  612. 	-- Update the gps for both players 
  613. 	while(Bikes_remaining > 0) do 
  614. 		update_bike_gps(LOCAL_PLAYER) 
  615. 		if(IN_COOP) then 
  616. 			update_bike_gps(REMOTE_PLAYER) 
  617. 		end 
  618. 		thread_yield() 
  619. 	end 
  620.  
  621. 	-- Clear up any existing waypoints 
  622. 	mission_waypoint_remove(SYNC_ALL) 
  623.  
  624. end 
  625.  
  626. -- Make bikes invulnerable, teleport ronin onto the bike 
  627. function rn03_setup_wave_bikes(wave_name) 
  628.  
  629. 	-- Setup the bikes 
  630. 	for i,bike in pairs(rn03_wave_parameter(wave_name,"BIKES")) do 
  631.  
  632. 		local driver = rn03_wave_parameter(wave_name,"DRIVERS",i) 
  633. 		attack(driver) 
  634. 		turn_invulnerable(driver, false) 
  635. 		turn_invulnerable(bike,false) 
  636. 		 
  637. 		-- place the driver (and possibly passenger) on the bike 
  638. 		vehicle_enter_teleport(driver,bike,0) 
  639. 		local passenger = rn03_wave_parameter(wave_name,"PASSENGERS",i) 
  640. 		if (passenger) then 
  641. 			attack(passenger) 
  642. 			vehicle_enter_teleport(passenger,bike,1) 
  643. 			turn_invulnerable(passenger,false) 
  644. 			Rn03_bike_to_passenger[bike] = passenger 
  645. 		end 
  646.  
  647. 	end 
  648.  
  649. end 
  650.  
  651. -- Send a wave of ronin on their route to the Saints' HQ 
  652. -- 
  653. -- params: 
  654. --		helptext_more_ronin	Helptext message played if these bikes are joining the fight. 
  655. --		wave_name Name of this wave of attackers (used to grab the correct set of parameters) 
  656. -- 
  657. function rn03_send_wave(helptext_more_ronin, wave_name) 
  658.  
  659. 	-- Determine the number of Bikes that we can spawn 
  660. 	local bikes_to_spawn = sizeof_table(rn03_wave_parameter(wave_name,"BIKES")) 
  661. 	local max_bikes_allowed = rn03_wave_parameter(wave_name,"MAX_RONIN") 
  662. 	if (max_bikes_allowed > 0) then 
  663. 		bikes_to_spawn = max_bikes_allowed - Bikes_remaining 
  664. 	end 
  665.  
  666. 	-- If we still have bikes around, then tell the player that more ronin have joined in. 
  667. 	-- (If all bikes are gone, then the waypoint thread will have already displayed this message) 
  668. 	if ( (Bikes_remaining > 0) and (bikes_to_spawn > 0) and helptext_more_ronin) then 
  669. 		mission_help_table(helptext_more_ronin)		 
  670. 	end 
  671.  
  672. 	-- loop over all of the bikes in the wave 
  673. 	for i,bike in pairs(rn03_wave_parameter(wave_name,"BIKES")) do 
  674. 		if (i <= bikes_to_spawn) then 
  675. 	 
  676. 			-- Set max hit points for the bike 
  677. 			set_max_hit_points(bike, rn03_wave_parameter(wave_name,"BIKE_HP"))  
  678.  
  679. 			-- Associate the bike with this wave 
  680. 			Bike_to_wave_mapping[bike] = wave_name 
  681.  
  682. 			-- Note that this bike is not disabled 
  683. 			Bikes_disabled[bike] = false 
  684. 			Bikes_remaining = Bikes_remaining + 1 
  685. 			Bikes_to_kill = Bikes_to_kill + 1 
  686.  
  687. 			thread_new("rn03_send_bike", bike, i) 
  688.  
  689. 			delay(rand_float(0.3,0.7)) 
  690. 		end 
  691. 	end 
  692.  
  693. 	-- Update the objective text 
  694. 	objective_text(0, HELPTEXT_OBJECTIVE_KILL_RONIN, Bikes_to_kill - Bikes_remaining, Bikes_to_kill) 
  695. end 
  696.  
  697. -- Send a bike on its route to the Ronin HQ 
  698. -- 
  699. -- Sets various flags and builds a ranom route if needed 
  700. -- 
  701. -- params: 
  702. --		bike	The motorcycle that should start pathfinding. 
  703. --		i		The index of this bike in its wave. 
  704. function rn03_send_bike(bike, i) 
  705.  
  706. 	-- add marker, in game effect 
  707. 	marker_add_vehicle(bike,MINIMAP_ICON_KILL,INGAME_EFFECT_VEHICLE_KILL,SYNC_ALL) 
  708.  
  709. 	-- convenience variables 
  710. 	local wave_name = Bike_to_wave_mapping[bike] 
  711. 	local driver = rn03_wave_parameter(wave_name,"DRIVERS",i) 
  712.  
  713. 	-- Set max hit points for the driver 
  714. 	set_max_hit_points(driver, rn03_wave_parameter(wave_name,"DRIVER_HP"))  
  715.  
  716. 	-- Keep track of who is driving this bike 
  717. 	Driver_to_bike_mapping[driver] = bike 
  718.  
  719. 	-- Set a bunch of flags 
  720. 	vehicle_never_flatten_tires(bike, true) 
  721. 	vehicle_suppress_npc_exit(bike, true) 
  722. 	vehicle_prevent_explosion_fling(bike,true) 
  723. 	set_seatbelt_flag(driver,true) 
  724. 	vehicle_set_allow_ram_ped(bike,true) 
  725. 	vehicle_set_crazy(bike,true) 
  726. 	vehicle_set_use_short_cuts(bike,true) 
  727. 	 
  728. 	-- Add bike-disabled callbacks for bike being destroyed and driver being killed 
  729. 	on_death("rn03_bike_driver_killed", driver) 
  730. 	on_vehicle_destroyed("rn03_bike_destroyed", bike) 
  731.  
  732. 	-- Make everything visible and vulnerable 
  733. 	turn_vulnerable(bike) 
  734. 	vehicle_show(bike) 
  735. 	turn_vulnerable(driver) 
  736. 	character_show(driver) 
  737. 	local passenger = rn03_wave_parameter(wave_name,"PASSENGERS",i) 
  738. 	if (passenger) then 
  739. 		turn_vulnerable(passenger) 
  740. 		character_show(passenger) 
  741. 	end 
  742.  
  743. 	-- Send the bike on its way. If the bike is in the first wave, build a random path. 
  744. 	if (wave_name == "wave_1") then 
  745.  
  746. 		local path_tree	= 
  747. 		{ 
  748. 			[0]	= {1,2}; 
  749. 			[1]	= {5,6}; 
  750. 			[2]	= {3,8}; 
  751. 			[3]	= {4,7}; 
  752. 			[4]	= {5,6}; 
  753. 			[5]	= {9}; 
  754. 			[6]	= {9,10}; 
  755. 			[7]	= {9,10}; 
  756. 			[8]	= {9,10,17}; 
  757. 			[9]	= {17}; 
  758. 			[10]	= {17}; 
  759. 			[17]  = {18}; 
  760. 		} 
  761.  
  762. 		local path_node_names =  
  763. 		{ 
  764. 			[1]	= "rn03_$n048"; 
  765. 			[2]	= "rn03_$n052"; 
  766. 			[3]	= "rn03_$n053"; 
  767. 			[4]	= "rn03_$n055"; 
  768. 			[5]	= "rn03_$n049"; 
  769. 			[6]	= "rn03_$n056"; 
  770. 			[7]	= "rn03_$n057"; 
  771. 			[8]	= "rn03_$n054"; 
  772. 			[9]	= "rn03_$n050"; 
  773. 			[10]	= "rn03_$n058"; 
  774. 			[17]	= "rn03_$n051"; 
  775. 			[18]	= "rn03_$n059"; 
  776. 		} 
  777.  
  778. 		local my_path = rn03_get_random_path2(path_tree, path_node_names) 
  779.  
  780. 		vehicle_turret_base_to(bike, my_path, false) 
  781. 	end 
  782.  
  783. 	local num_paths = sizeof_table(rn03_wave_parameter(wave_name,"PATH")) 
  784. 	for i=1, num_paths, 1 do 
  785. 		local stop = false 
  786. 		if(i == num_paths) then 
  787. 			stop = true 
  788. 		end 
  789. 		vehicle_turret_base_to(bike, rn03_wave_parameter(wave_name,"PATH")[i], stop) 
  790. 	end 
  791.  
  792. 	-- If a bike arrives at the HQ, then the player loses 
  793. 	delay(0.5) 
  794. 	if (not Bikes_disabled[bike]) then 
  795.  
  796. 		-- Check the distance to the path's end... if the bike got stuck for some reason, 
  797. 		-- just blow it up. 
  798. 		local dist = get_dist(bike, "rn03_$n043") 
  799. 		if (dist > 100.0) then 
  800. 			vehicle_detonate(bike) 
  801. 		else 
  802. 			rn03_failure_ronin_in_row() 
  803. 		end	 
  804.  
  805. 	end 
  806.  
  807. end 
  808.  
  809. -- Throttle the speed of all bikes based on their distance to the player 
  810. function rn03_bike_speed_throttle() 
  811.  
  812. 	local Bike_in_range = {} 
  813. 	 
  814. 	while (true) do 
  815.  
  816. 		for bike, disabled in pairs(Bikes_disabled) do 
  817.  
  818. 			-- If the bike isn't disabled, throttle its speed 
  819. 			if (not disabled) then 
  820.  
  821. 				-- Get parameter values for this bike's wave 
  822. 				local wave_name	= Bike_to_wave_mapping[bike] 
  823. 				local range			= rn03_wave_parameter(wave_name,"CLOSE_RANGE_M") 
  824. 				local speed_slow	= rn03_wave_parameter(wave_name,"SLOW_SPEED") 
  825. 				local speed_fast	= rn03_wave_parameter(wave_name,"FAST_SPEED") 
  826.  
  827. 				-- Was the bike in range the last time we looked at it? 
  828. 				local in_range		= Bike_in_range[bike] 
  829.  
  830. 				-- Get distance to closest player 
  831. 				local dist = get_dist_closest_player_to_object(bike) 
  832.  
  833. 				-- Do some set up if the throttling thread hadn't seen this bike before 
  834. 				if (in_range == nil) then 
  835.  
  836. 					-- Set initial speed 
  837. 					if (dist < range) then 
  838. 						Bike_in_range[bike] = true 
  839. 						vehicle_speed_override(bike, speed_fast) 
  840. 					else 
  841. 						Bike_in_range[bike] = false 
  842. 						vehicle_speed_override(bike, speed_slow) 
  843. 					end 
  844.  
  845. 				-- Otherwise, only change speed if in-close-range status has changed 
  846. 				else 
  847.  
  848. 					-- If in-range status has changed, set new speed 
  849. 					if (dist < range ~= in_range) then 
  850.  
  851. 						Bike_in_range[bike] = not in_range 
  852.  
  853. 						if (Bike_in_range[bike]) then 
  854. 							vehicle_speed_override(bike, speed_fast) 
  855. 						else 
  856. 							vehicle_speed_override(bike, speed_slow) 
  857. 						end 
  858.  
  859. 					end -- Ends if (in-range status changed) 
  860.  
  861. 				end -- Ends else (only change speed if in-range status has changed) 
  862. 				 
  863. 			end -- Ends if (not disabled) 
  864.  
  865. 			-- Its not urgent that the speed is immediately updated, so yield after each bike 
  866. 			thread_yield() 
  867.  
  868. 		end -- Ends loop over bikes 
  869.  
  870. 		-- Yield here as well, or we'll have problems when all bikes are disabled 
  871. 		thread_yield() 
  872. 	 
  873. 	end 
  874.  
  875. end 
  876.  
  877. -- Handle the death of one of the Ronin drivers. 
  878. function rn03_bike_driver_killed(driver) 
  879. 	local bike = Driver_to_bike_mapping[driver] 
  880. 	rn03_bike_disabled(bike) 
  881.  
  882. 	delay(0.5) 
  883. 	local passenger = Rn03_bike_to_passenger[bike] 
  884. 	if (character_exists(passenger) and (not character_is_dead(passenger)) ) then 
  885. 		if ( vehicle_exists(bike) and (not vehicle_is_destroyed(bike)) and character_is_in_vehicle(passenger)) then 
  886. 			vehicle_suppress_npc_exit(bike, false) 
  887. 			vehicle_exit(passenger) 
  888. 			attack(passenger) 
  889. 		end 
  890. 	end 
  891.  
  892. 	if (AUTO_DETONATE_RIDERLESS_BIKES and (not vehicle_is_destroyed(bike))) then 
  893.  
  894. 		-- Check if bike is smoking and if it is on fire 
  895. 		local smoking, on_fire = vehicle_get_smoke_and_fire_state(bike) 
  896.  
  897. 		-- Start the bike smoking if it isn't already doing so, then delay a bit 
  898. 		if (not smoking) then 
  899. 			vehicle_set_smoke_and_fire_state(bike,true,on_fire) 
  900. 			delay(BIKE_SMOKE_TO_FIRE_DELAY_S) 
  901. 		end 
  902.  
  903. 		-- If the bike isn't on fire, set it on fire and wait a bit before it explodes 
  904. 		if (not smoking) then 
  905. 			vehicle_set_smoke_and_fire_state(bike,true,true) 
  906. 			delay(BIKE_SMOKE_TO_FIRE_DELAY_S) 
  907. 		end 
  908. 		 
  909. 		vehicle_detonate(bike) 
  910.  
  911. 	end 
  912.  
  913. end 
  914.  
  915. -- Handle the destruction of on of the Ronin's bikes 
  916. function rn03_bike_destroyed(bike) 
  917. 	rn03_bike_disabled(bike) 
  918. end 
  919.  
  920. -- Called when one of the Ronin bike's is disabled 
  921. --  
  922. -- Does book keeping and updates objective text. 
  923. function rn03_bike_disabled(bike) 
  924. 	if (not Bikes_disabled[bike]) then 
  925.  
  926. 		Bikes_disabled[bike] = true 
  927. 		Bikes_remaining = Bikes_remaining - 1 
  928.  
  929. 		marker_remove_vehicle(bike) 
  930.  
  931. 		-- Update the objective text 
  932. 		objective_text(0, HELPTEXT_OBJECTIVE_KILL_RONIN, Bikes_to_kill - Bikes_remaining, Bikes_to_kill) 
  933.  
  934. 		--log that we've destroyed a bike 
  935. 		--gamelog_log_event("MISSION_EVENT", "bike destroyed", (Bikes_to_kill - Bikes_remaining)) 
  936.  
  937. 		-- Tell the player that they disabled the bike  
  938. 		-- (unless its the last in which case another wave will spawn, or the mission ends) 
  939. 		if(Bikes_remaining > 0) then 
  940. 			mission_help_table(HELPTEXT_PROMPT_BIKE_DESTROYED) 
  941. 		end 
  942. 	 
  943. 	end 
  944. end 
  945.  
  946. -- Cleanup when mission is exited or restarted. 
  947. function rn03_cleanup() 
  948.  
  949. 	IN_COOP = coop_is_active() 
  950.  
  951. 	-- reset global variables 
  952. 		set_traffic_density(1.00) 
  953.  
  954. 	-- remove markers 
  955.  
  956. 		-- Player bike(s) 
  957. 		marker_remove_vehicle(VEHICLE_PLAYER_BIKE_1, SYNC_ALL) 
  958. 		if (IN_COOP) then 
  959. 			marker_remove_vehicle(VEHICLE_PLAYER_BIKE_2, SYNC_ALL) 
  960. 		end 
  961.  
  962. 		-- Wave bikes 
  963. 		for bike, disabled in pairs(Bikes_disabled) do 
  964. 			marker_remove_vehicle(bike) 
  965. 		end 
  966.  
  967. 		-- GPS 
  968. 		mission_waypoint_remove() 
  969.  
  970. 	-- remove callbacks 
  971.  
  972. 		-- Player enter/exit player bike(s) 
  973. 		on_vehicle_enter("",VEHICLE_PLAYER_BIKE_1) 
  974. 		on_vehicle_exit("",VEHICLE_PLAYER_BIKE_1) 
  975. 		if (IN_COOP) then 
  976. 			on_vehicle_enter("",VEHICLE_PLAYER_BIKE_2) 
  977. 			on_vehicle_exit("",VEHICLE_PLAYER_BIKE_2) 
  978. 		end 
  979.  
  980. 		-- Player enter/exit vehicle 
  981. 		on_vehicle_enter("", LOCAL_PLAYER) 
  982. 		on_vehicle_exit("", LOCAL_PLAYER)	 
  983. 		if (IN_COOP) then 
  984. 			on_vehicle_enter("", REMOTE_PLAYER) 
  985. 			on_vehicle_exit("", REMOTE_PLAYER) 
  986. 		end 
  987.  
  988. 		-- Wave bikes, drivers 
  989. 		for bike, disabled in pairs(Bikes_disabled) do 
  990. 			on_vehicle_destroyed("", bike) 
  991. 		end 
  992. 		for driver, bike in pairs (Driver_to_bike_mapping) do 
  993. 			on_death("", driver) 
  994. 		end 
  995.  
  996. 		-- Stop persona overrides 
  997. 		persona_override_group_stop(RONIN_PERSONAS,POT_SITUATIONS[POT_ATTACK]) 
  998. 		 
  999. 	if (Weapons_received) then 
  1000. 		inv_weapon_remove_temporary(LOCAL_PLAYER, FREE_WEAPON_GUN) 
  1001. 		if ( IN_COOP ) then 
  1002. 			inv_weapon_remove_temporary(REMOTE_PLAYER, FREE_WEAPON_GUN) 
  1003. 		end 
  1004. 	end 
  1005. end 
  1006.  
  1007. -- Get a wave parameter value 
  1008. -- 
  1009. -- params: 
  1010. --		wave The name of the wave. 
  1011. --		parameter The name of the parameter. 
  1012. --		i If the parameter's value is a table, then the index to the entry to return. 
  1013. function rn03_wave_parameter(wave, parameter, i) 
  1014.  
  1015. 	local return_val = nil 
  1016.  
  1017. 	-- Check for an overloaded value for coop missions when both players are on the same bike. 
  1018. 	if (Players_in_same_vehicle) then 
  1019. 		if (i) then 
  1020. 			if (WAVE_PARAMETERS[wave]["COOP_SAME_BIKE_" .. parameter] ~= nil) then 
  1021. 				return_val = WAVE_PARAMETERS[wave]["COOP_SAME_BIKE_" .. parameter][i] 
  1022. 			end 
  1023. 		else 
  1024. 			return_val = WAVE_PARAMETERS[wave]["COOP_SAME_BIKE_" .. parameter] 
  1025. 		end 
  1026. 	end 
  1027.  
  1028. 	-- Check for an overloaded value for coop missions. 
  1029. 	if (IN_COOP and return_val == nil) then 
  1030. 		if (i) then 
  1031. 			if (WAVE_PARAMETERS[wave]["COOP_" .. parameter] ~= nil) then 
  1032. 				return_val = WAVE_PARAMETERS[wave]["COOP_" .. parameter][i] 
  1033. 			end 
  1034. 		else 
  1035. 			return_val = WAVE_PARAMETERS[wave]["COOP_" .. parameter] 
  1036. 		end 
  1037. 	end 
  1038.  
  1039. 	-- Get the standard value 
  1040. 	if (return_val == nil) then 
  1041. 		if (i) then 
  1042. 			if (WAVE_PARAMETERS[wave][parameter] ~= nil) then 
  1043. 				return_val = WAVE_PARAMETERS[wave][parameter][i] 
  1044. 			end 
  1045. 		else 
  1046. 			return_val = WAVE_PARAMETERS[wave][parameter] 
  1047. 		end 
  1048. 	end 
  1049.  
  1050. 	return return_val 
  1051. end 
  1052.  
  1053. function rn03_complete() 
  1054. 	--bink_play_movie("ro03-2.bik") 
  1055. 	mission_end_success("rn03", "ro03-02") 
  1056. end 
  1057.  
  1058. function rn03_success() 
  1059. 	-- Called when the mission has ended with success 
  1060. end 
  1061.  
  1062. -- MISSION FAILURE FUNCTIONS -------------------------------- 
  1063.  
  1064. -- End the mission, player's bike destroyed 
  1065. function rn03_failure_bike_destroyed() 
  1066. 	mission_end_failure("rn03", HELPTEXT_FAILURE_BIKE_DESTROYED) 
  1067. end 
  1068.  
  1069. -- End the mission, Ronin made it to the saint's district 
  1070. function rn03_failure_ronin_in_row() 
  1071. 	mission_end_failure("rn03", HELPTEXT_FAILURE_RANGE) 
  1072. end 
  1073.  
  1074. -- Build a random path 
  1075. -- 
  1076. -- params: 
  1077. --		path_tree A table describing the tree. 
  1078. --		node_names The names of the navpoints corresponding to each node. 
  1079. -- 
  1080. --	returns: 
  1081. --		A random path along the tree. 
  1082. -- 
  1083. -- e.g. The following diagram represents a path w/ 3 routes from 1->6: 
  1084. -- 
  1085. --		 2--------- 
  1086. --		/			   \ 
  1087. --	1-<	  4---6   \ 
  1088. --		\	 /     \   \ 
  1089. --		 3-<	     >---- 7 
  1090. --			 \     / 
  1091. --			  5---- 
  1092. --  
  1093. -- Its path_tree table would be as follows: 
  1094. -- 
  1095. --	path_tree =  
  1096. -- {  
  1097. --		[0] = {1}	-- 0 indexes the starting point(s) 
  1098. --		[1] = {2,3}	-- From node 1, the path can progress to node 2 or 3 
  1099. --		[2] = {7}	-- From node 2, the only possible next node is 7 
  1100. --		[3] = {4,5} 
  1101. --		[4] = {6} 
  1102. --		[5] = {7} 
  1103. --		[6] = {7} 
  1104. -- } 
  1105. -- 
  1106. -- The three possible routes are: 
  1107. --		(1,2,7) 
  1108. --		(1,3,4,6,7) 
  1109. --		(1,3,5,7) 
  1110.  
  1111. function rn03_get_random_path2(path_tree, node_names) 
  1112.  
  1113. 	local function get_next_node_id(current_node_id) 
  1114. 		if(path_tree[current_node_id] == nil) then 
  1115. 			return nil 
  1116. 		else 
  1117. 			local num_choices = sizeof_table(path_tree[current_node_id]) 
  1118. 			return path_tree[current_node_id][rand_int(1,num_choices)] 
  1119. 		end 
  1120. 	end 
  1121.  
  1122. 	local current_id = get_next_node_id(0) 
  1123. 	local num_nodes = 0 
  1124. 	local rand_path = {} 
  1125.  
  1126. 	while (current_id ~= nil) do 
  1127. 		num_nodes = num_nodes + 1 
  1128. 		--rand_path[num_nodes] = current_id 
  1129. 		rand_path[num_nodes] = node_names[current_id] 
  1130. 		current_id = get_next_node_id(current_id) 
  1131. 	end 
  1132.  
  1133. 	return rand_path 
  1134.  
  1135. end 
  1136.  
  1137. -- add all entries of the tail table onto the end of the head table 
  1138. function rn03_table_concat(head_table, tail_table) 
  1139. 	local offset = sizeof_table(head_table) 
  1140. 	for i, tail_entry_i in pairs(tail_table) do 
  1141. 		head_table[offset+i] = tail_entry_i 
  1142. 	end 
  1143. end