sr2lua/bh10.lua

  1. -- bh10.lua 
  2. -- SR2 mission script 
  3. -- 3/28/07 
  4.  
  5. 	-- Debug -- 
  6. 	DEBUG_ENTER_WAREHOUSE = false 
  7. 	DEBUG_MAERO_FIGHT =		false 
  8.  
  9. 	DEBUG_TEXT_EXPLOIT =		1 
  10. 	DEBUG_TEXT_MAERO_AI =	2 
  11. 	DEBUG_TEXT_NUMBERS =		3 
  12. 	DEBUG_TEXT_SATCHELS =	4 
  13. 	DEBUG_TEXT_TARGETS =		5 
  14.  
  15. 	DEBUG_TEXT_ENABLED = { 
  16. 		[DEBUG_TEXT_EXPLOIT] =		false, 
  17. 		[DEBUG_TEXT_MAERO_AI] =		false, 
  18. 		[DEBUG_TEXT_NUMBERS] =		false, 
  19. 		[DEBUG_TEXT_SATCHELS] =		false, 
  20. 		[DEBUG_TEXT_TARGETS] =		false, 
  21. 	} 
  22.  
  23. 	-- Tweakable parameters 
  24. 	MAX_BH_NOTORIETY =							4		-- Maximum Brotherhood notoriety level 
  25. 	MAX_BH_NOTORIETY_COOP =						5		-- Maximum Brotherhood notoriety level 
  26. 	Maero_explosion_ratio =						.25	-- Portion of explosion damage that is applied Maero. 
  27. 	Maero_recover_damage_ratio =				.50	-- Portion of damage that is applied to Maero while he is recovering. 
  28. 	Maero_initial_health =						12000	-- Maero's initial health in Single player. 
  29. 	Maero_initial_health_coop_multiplier = 1.5	-- Multiplier applied to Maero's health in coop. 
  30. 	Maero_damage_multiplier =					.75   -- Mutliplier applied to damage that Maero deals to players 
  31.  
  32. 	-- Navpoints -- 
  33. 	NAV_PLAYER_START =		"bh10_$player_start" 
  34. 	NAV_REMOTE_START =		"bh10_$remote_start" 
  35. 	NAV_MAERO =					"bh10_$maero" 
  36. 	NAV_SAINTS_INITIAL_ENTRY = "bh10_$n064" 
  37. 	NAV_BIKE_START =			{"bh10_$n001", "bh10_$n002", "bh10_$n003", "bh10_$n004"} 
  38. 	NAV_WAREHOUSE_WAYPOINTS =			{"bh10_$n005", "bh10_$n006", "bh10_$n009", "bh10_$n007", "bh10_$n010", "bh10_$n008"} 
  39. 	NAV_PLAYER_START_MAERO = "bh10_$n_maero_test_local" 
  40. 	NAV_REMOTE_START_MAERO = "bh10_$n_maero_test_remote" 
  41.  
  42. 	-- Groups -- 
  43. 	GROUP_STANDARD_LIEUTENANTS =		"bh10_$standard_lieutenants" 
  44. 	GROUP_ROCKET_LIEUTENANTS =			"bh10_$rocket_lieutenants" 
  45. 	GROUP_WAREHOUSE_SOLDIERS =			"bh10_$warehouse_soldiers" 
  46. 	GROUP_WAREHOUSE_FLOOR_1 =			"bh10_$warehouse_floor_1" 
  47. 	GROUP_WAREHOUSE_FLOOR_2 =			"bh10_$warehouse_floor_2" 
  48. 	GROUP_WAREHOUSE_FLOOR_3 =			"bh10_$warehouse_floor_3" 
  49. 	GROUP_WAREHOUSE_FLOOR_4 =			"bh10_$warehouse_floor_4" 
  50. 	GROUP_WAREHOUSE_FLOOR_5 =			"bh10_$warehouse_floor_5" 
  51. 	GROUP_MAERO =							"bh10_$maero" 
  52. 	GROUP_PLAYER_HOMIES =				"bh10_$player_homies" 
  53. 	GROUP_SAINTS =							{"bh10_$saints1", "bh10_$saints2", "bh10_$saints3", "bh10_$saints4"} 
  54. 	GROUP_LOS_DUMMIES =					{"bh10_$los_dummies1", "bh10_$los_dummies2", "bh10_$los_dummies3"} 
  55. 	GROUP_EXPLOIT_BH =					"bh10_$maero_exploits" 
  56. 	GROUP_COURTESY_CAR =					"bh10_$courtesy_car" 
  57. 	GROUP_COURTESY_CAR_COOP =			"bh10_$courtesy_car_coop" 
  58. 	GROUP_GRENADES =						"bh10_$Ggrenades" 
  59.  
  60. 	-- Tables -- 
  61. 	TABLE_STANDARD_LIEUTENANTS =		 
  62. 		{"bh10_$c000", "bh10_$c001", "bh10_$c002", "bh10_$c003", "bh10_$c004", "bh10_$c005", "bh10_$c009", "bh10_$c010"} 
  63. 	TABLE_ROCKET_LIEUTENANTS =			 
  64. 		{"bh10_$c011", "bh10_$c012"} 
  65. 	TABLE_PLAYER_HOMIES =				 
  66. 		{"bh10_$c032", "bh10_$c033"} 
  67.  
  68. 	-- Checkpoints -- 
  69. 	CHECKPOINT_STAGING =					"bh10_checkpoint_staging" 
  70. 	CHECKPOINT_WAREHOUSE =				"bh10_checkpoint_warehouse" 
  71. 	CHECKPOINT_MAERO =					"bh10_checkpoint_maero" 
  72.  
  73. 	-- Vehicles -- 
  74. 	SAINTS_CAR =							{{"bh10_$v000"}, 
  75. 												 {"bh10_$v001"}, 
  76. 												 {"bh10_$v002"}, 
  77. 												 {"bh10_$v003", "bh10_$v004", "bh10_$v005", "bh10_$v006"}} 
  78.  
  79. 	-- Triggers -- 
  80. 	TRIGGER_TRIBAL_STAGING =			"bh10_$tribal_staging" 
  81. 	TRIGGER_WAREHOUSE_ENTRANCE =		"bh10_$waypoint_2" 
  82. 	TRIGGER_WAREHOUSE_ROOF =			"bh10_$waypoint_3" 
  83.  
  84. 	TRIGGER_LOW_GROUND =					"bh10_$t_low_ground" 
  85. 	TRIGGER_HIGH_GROUND =				"bh10_$t_high_ground" 
  86. 	TRIGGER_HIDING =						"bh10_$t_hiding" 
  87.  
  88. 	TRIGGER_WH_GROUP_01 =				"bh10_$trigger_warehouse_gp1" 
  89. 	TRIGGER_WH_GROUP_02 =				"bh10_$trigger_warehouse_gp2" 
  90. 	TRIGGER_WH_GROUP_03 =				"bh10_$trigger_warehouse_gp3" 
  91. 	TRIGGER_WH_GROUP_04 =				"bh10_$trigger_warehouse_gp4" 
  92. 	TRIGGER_WH_GROUP_05 =				"bh10_$trigger_warehouse_gp5" 
  93.  
  94. 	TRIGGER_EXPLOIT_AREA_1A =			"bh10_$t_exploit_area_1a"			 
  95. 	TRIGGER_EXPLOIT_AREA_1B =			"bh10_$t_exploit_area_1b"			 
  96. 	TRIGGER_EXPLOIT_AREA_1C =			"bh10_$t_exploit_area_1c"			 
  97. 	TRIGGER_EXPLOIT_AREA_2 =			"bh10_$t_exploit_area_2" 
  98. 	TRIGGER_EXPLOIT_AREA_3 =			"bh10_$t_exploit_area_3" 
  99. 	 
  100. 	TRIGGER_EXPLOIT_AREAS =				{	TRIGGER_EXPLOIT_AREA_1A, TRIGGER_EXPLOIT_AREA_1B, 
  101. 													TRIGGER_EXPLOIT_AREA_1C, 
  102. 													TRIGGER_EXPLOIT_AREA_2, TRIGGER_EXPLOIT_AREA_3} 
  103. 	TRIGGER_EXPLOIT_ENTRANCES =		{	"bh10_$t_exploit_enter_1", "bh10_$t_exploit_enter_2",  
  104. 													"bh10_$t_exploit_enter_3", "bh10_$t_exploit_enter_4"} 
  105. 	TRIGGER_EXPLOIT_EXITS =				{	"bh10_$t_exploit_exit_1", "bh10_$t_exploit_exit_2", 
  106. 													"bh10_$t_exploit_exit_3", "bh10_$t_exploit_exit_4"} 
  107.  
  108. 	EXPLOIT_SPAWN_INFO =  
  109. 	{  
  110. 		["A"] = 
  111. 		{ 
  112. 			["max_npcs"] = 2, 
  113. 			["max_npcs_coop"] = 4, 
  114. 			["spawn points"] =	{	"bh10_$n028", "bh10_$n029", "bh10_$n030",  
  115. 											"bh10_$n031", "bh10_$n032", "bh10_$n033"}, 
  116. 			--[[ 
  117. 			["attack points"] =	{	"bh10_$n034", "bh10_$n035", "bh10_$n036", 
  118. 											"bh10_$n037", "bh10_$n038", "bh10_$n039"}, 
  119. 			]] 
  120. 			["attack points"] =	{	"bh10_$n023", "bh10_$n014", "bh10_$n015", 
  121. 											"bh10_$n016", "bh10_$n017", "bh10_$n024"}, 
  122. 			["triggers"] =			{	"bh10_$t_exploit_spawn_a", "bh10_$t_exploit_spawn_a2"}, 
  123. 			["exploit_areas"] =	{	TRIGGER_EXPLOIT_AREA_1A, TRIGGER_EXPLOIT_AREA_1B, TRIGGER_EXPLOIT_AREA_2, 
  124. 											TRIGGER_EXPLOIT_AREA_3} 
  125. 		}, 
  126. 		["B"] = 
  127. 		{ 
  128. 			["max_npcs"] = 2, 
  129. 			["max_npcs_coop"] = 4, 
  130. 			["spawn points"] =	{	"bh10_$n040", "bh10_$n041", "bh10_$n042",  
  131. 											"bh10_$n043", "bh10_$n044", "bh10_$n045"}, 
  132. 			["attack points"] =	{	"bh10_$n046", "bh10_$n047", "bh10_$n048", 
  133. 											"bh10_$n049", "bh10_$n050", "bh10_$n051"}, 
  134. 			["triggers"] =			{	"bh10_$t_exploit_spawn_b"}, 
  135. 			["exploit_areas"] =	{	TRIGGER_EXPLOIT_AREA_1A, TRIGGER_EXPLOIT_AREA_1B, TRIGGER_EXPLOIT_AREA_1C} 
  136. 		}, 
  137. 		-- Yes, I know I skipped "C". 
  138. 		["D"] = 
  139. 		{ 
  140. 			["max_npcs"] = 2, 
  141. 			["max_npcs_coop"] = 4, 
  142. 			["spawn points"] =	{	"bh10_$n052", "bh10_$n053", "bh10_$n054",  
  143. 											"bh10_$n055", "bh10_$n056", "bh10_$n057"}, 
  144. 			["attack points"] =	{	"bh10_$n058", "bh10_$n059", "bh10_$n060", 
  145. 											"bh10_$n061", "bh10_$n062", "bh10_$n063", 
  146. 											"bh10_$n065"}, 
  147. 			["triggers"] =			{	"bh10_$t_exploit_spawn_d"}, 
  148. 			["exploit_areas"] =	{	TRIGGER_EXPLOIT_AREA_2, TRIGGER_EXPLOIT_AREA_3} 
  149. 		} 
  150.  
  151. 	} 
  152.  
  153. 	-- Characters -- 
  154. 	CHAR_MAERO =			"bh10_$maero" 
  155. 	CHAR_FIRST_ROCKETEER =	"bh10_$c011" 
  156. 	CHAR_FIRST_ROCKETEE =   "bh10_$c034" 
  157.  
  158. 	EXTRA_SAINTS =					{{"bh10_$c034", "bh10_$c035", "bh10_$c036", "bh10_$c037"},  
  159. 										 {"bh10_$c038", "bh10_$c039", "bh10_$c040", "bh10_$c041"}, 
  160. 										 {"bh10_$c042", "bh10_$c043", "bh10_$c044", "bh10_$c045"},  
  161. 										 {"bh10_$c046", "bh10_$c047", "bh10_$c048", "bh10_$c049"}} 
  162. 	 
  163. 	LOS_DUMMIES =					{"bh10_$c050", "bh10_$c051", "bh10_$c052"} 
  164.  
  165. 	EXPLOIT_BH =					{	"bh10_$c006", "bh10_$c007", "bh10_$c008", "bh10_$c013", 
  166. 											"bh10_$c014", "bh10_$c073", "bh10_$c089", "bh10_$c090", 
  167. 											"bh10_$c091", "bh10_$c092", "bh10_$c093", "bh10_$c094", 
  168. 											"bh10_$c095", "bh10_$c096", "bh10_$c097", "bh10_$c098", 
  169. 											"bh10_$c099", "bh10_$c100"} 
  170.  
  171. 	FLOOR_5_01 =					"bh10_$c101" 
  172. 	FLOOR_5_02 =					"bh10_$c102" 
  173. 	FLOOR_5_03 =					"bh10_$c103" 
  174. 	FLOOR_5_04 =					"bh10_$c104" 
  175. 	FLOOR_5_05 =					"bh10_$c105" 
  176.  
  177. 	FLOOR_3_1A =					"bh10_$c071" 
  178. 	FLOOR_3_1B =					"bh10_$c072" 
  179. 	FLOOR_3_2A =					"bh10_$c076" 
  180. 	FLOOR_3_2B =					"bh10_$c079" 
  181.  
  182. 	-- Cutscenes -- 
  183. 	CUTSCENE_IN =						"br10-1.bik" 
  184. 	CUTSCENE_OUT =						"br10-2.bik" 
  185.  
  186. 	-- Voice -- 
  187. 	VOICE_15_KILLS =					"PLAYER_BR10_15_KILLS" 
  188. 	VOICE_12_KILLS =					"PLAYER_BR10_12_KILLS" 
  189. 	VOICE_9_KILLS =					"PLAYER_BR10_9_KILLS" 
  190. 	VOICE_6_KILLS =					"PLAYER_BR10_6_KILLS" 
  191. 	VOICE_3_KILLS =					"PLAYER_BR10_3_KILLS" 
  192.  
  193. 	-- Mesh Movers -- 
  194.  
  195. 		-- Doors that should be locked until the player is sent into the warehouse 
  196. 		MM_STAIRWELL_DOOR_1 = "bh10_$MMdoor_stairwell_1" 
  197. 		MM_STAIRWELL_DOOR_2 = "bh10_$MMdoor_stairwell_2" 
  198.  
  199. 		-- Door to roof 
  200. 		MM_ROOF_DOOR =			"bh10_MMroof_door" 
  201.  
  202. 		-- Doors associated with exploit areas 
  203. 		MM_EXPLOIT_DOOR_1 =	"bh10_MMexploit_door_1" 
  204. 		MM_EXPLOIT_DOOR_2 =	"bh10_MMexploit_door_2" 
  205. 		MM_EXPLOIT_DOOR_3 =	"bh10_MMexploit_door_3" 
  206.  
  207. 		-- Doors that should be hidden when the player gains access to the warehouse 
  208. 		MM_HIDDEN_DOOR_1 = "bh10_$MMdoor_to_hide_3" 
  209. 		MM_HIDDEN_DOOR_2 = "bh10_$MMdoor_to_hide_4a" 
  210. 		MM_HIDDEN_DOOR_3 = "bh10_$MMdoor_to_hide_4b"  
  211. 		MM_HIDDEN_DOOR_4 = "bh10_$MMdoor_to_hide_5a" 
  212. 		MM_HIDDEN_DOOR_5 = "bh10_$MMdoor_to_hide_5b" 
  213.  
  214. 		-- List of all doors to hide. A couple doors have movers but aren't in this list.  
  215. 		-- That's because I couldnt' remember for sure which doors Bryan asked me to hide. 
  216. 		-- I put movers on some extras just in case. 
  217. 		MM_DOORS_TO_HIDE = {MM_HIDDEN_DOOR_1, MM_HIDDEN_DOOR_2, MM_HIDDEN_DOOR_5} 
  218.  
  219.  
  220. 	-- Other -- 
  221. 	CAR_NUM =					1 
  222. 	INITIAL_LIEUTENANTS =  sizeof_table(TABLE_STANDARD_LIEUTENANTS) + sizeof_table(TABLE_ROCKET_LIEUTENANTS) 
  223. 	Num_lieutenants_left = sizeof_table(TABLE_STANDARD_LIEUTENANTS) + sizeof_table(TABLE_ROCKET_LIEUTENANTS) 
  224. 	Saints_max_distance = 70 
  225. 	Min_saints_assisting =	2 
  226. 	Thrown_weapon =			"satchel" 
  227. 	IN_COOP = false 
  228. 	THREAD_NOTORIETY =	  -1 
  229. 	THREAD_LIEUTENANTS =	  -1 
  230. 	THREAD_ROOF =			  -1 
  231. 	THREAD_CLOSEST_NAV =   -1 
  232. 	THREAD_SAINTS_BACKUP = -1 
  233.  
  234. 	BH10_BROTHERHOOD_ATTACK_PERSONAS = { 
  235. 		["HM_Bro1"]	=	"HMBRO1", 
  236. 		["HM_Bro2"]	=	"HMBRO2", 
  237. 		["HM_Bro3"]	=	"HMBRO3", 
  238.  
  239. 		["HF_Bro2"]	=	"HFBRO2", 
  240.  
  241. 		["WM_Bro3"]	=	"WMBRO3", 
  242.  
  243. 		["WF_Bro1"]	=	"WFBRO1", 
  244. 		["WF_Bro2"]	=	"WFBRO2", 
  245. 	} 
  246.  
  247. 	BH10_SAINTS_ATTACK_PERSONAS = { 
  248. 		["AM_TSS2"]	=	"AMTSS2", 
  249. 		["AM_TSS3"]	=	"AMTSS3", 
  250.  
  251. 		["BM_TSS1"]	=	"BMTSS1", 
  252. 		["BM_TSS2"]	=	"BMTSS2", 
  253.  
  254. 		["BF_TSS1"]	=	"BFTSS1", 
  255. 		["BF_TSS2"]	=	"BFTSS2", 
  256.  
  257. 		["HM_TSS1"]	=	"HMTSS1", 
  258. 		["HM_TSS2"]	=	"HMTSS2", 
  259. 		["HM_TSS3"]	=	"HMTSS3", 
  260.  
  261. 		["HF_TSS3"]	=	"HFTSS3", 
  262.  
  263. 		["WM_TSS2"]	=	"WMTSS2", 
  264. 		["WM_TSS3"]	=	"WMTSS3", 
  265.  
  266. 		["WF_TSS1"]	=	"WFTSS1", 
  267. 		["WF_TSS2"]	=	"WFTSS2", 
  268. 		["WF_TSS3"]	=	"WFTSS3", 
  269. 	} 
  270.  
  271. 	OTHER_PLAYER = {[LOCAL_PLAYER] = REMOTE_PLAYER, [REMOTE_PLAYER] = LOCAL_PLAYER} 
  272.  
  273. function bh10_start(bh10_checkpoint, is_restart) 
  274.  
  275. 	if (bh10_checkpoint == MISSION_START_CHECKPOINT) then 
  276.  
  277. 		local start_groups = {GROUP_PLAYER_HOMIES, GROUP_COURTESY_CAR, GROUP_COURTESY_CAR_COOP} 
  278.  
  279. 		if (is_restart) then 
  280.  
  281. 			for i,group in pairs(start_groups) do 
  282. 				group_create(group, true) 
  283. 			end 
  284.  
  285. 			teleport_coop(NAV_PLAYER_START, NAV_REMOTE_START) 
  286.  
  287. 		else 
  288. 			cutscene_play("br10-01", start_groups, {NAV_PLAYER_START, NAV_REMOTE_START}, false) 
  289. 			for i,group in pairs(start_groups) do 
  290. 				group_show(group) 
  291. 			end 
  292. 		end 
  293.  
  294. 	end 
  295.  
  296. 	bh10_initialize(bh10_checkpoint) 
  297.  
  298. 	if(DEBUG_ENTER_WAREHOUSE) then 
  299. 		bh10_enter_warehouse() 
  300. 		while(true) do 
  301. 			thread_yield() 
  302. 		end 
  303. 	end 
  304.  
  305. 	if bh10_checkpoint == MISSION_START_CHECKPOINT then 
  306. 		if(DEBUG_MAERO_FIGHT) then 
  307. 			bh10_kill_maero(true) 
  308. 			while(true) do 
  309. 				thread_yield() 
  310. 			end 
  311. 		else 
  312. 			bh10_drive_to_staging_area() 
  313. 		end 
  314. 	elseif bh10_checkpoint == CHECKPOINT_STAGING then 
  315.  
  316. 		THREAD_NOTORIETY = thread_new("bh10_raise_tribal_notoriety") 
  317. 		THREAD_LIEUTENANTS = thread_new("bh10_get_to_tribal_hq") 
  318. 	elseif bh10_checkpoint == CHECKPOINT_WAREHOUSE then 
  319. 		bh10_enter_warehouse() 
  320. 	elseif bh10_checkpoint == CHECKPOINT_MAERO then 
  321. 		bh10_kill_maero(false) 
  322. 	end 
  323.  
  324. end 
  325.  
  326. function bh10_initialize(checkpoint) 
  327.  
  328. 	mission_start_fade_out(0.0) 
  329.  
  330. 	-- A few Global constants need to be set up, but shouldn't be changed after this function 
  331. 	-- rn02_setup_global_constants() 
  332.  
  333. 	bh10_initialize_common() 
  334.  
  335. 	bh10_initialize_checkpoint(checkpoint) 
  336.  
  337. 	mission_start_fade_in() 
  338.  
  339. end 
  340.  
  341. -- Initialization code shared by all checkpoints. 
  342. function bh10_initialize_common() 
  343.  
  344. 	-- Start trigger is hit...the activate button was hit 
  345. 	set_mission_author("Phillip Alexander and Aaron Hanson") 
  346.  
  347. 	if coop_is_active() then 
  348. 		IN_COOP = true 
  349. 		Maero_initial_health = Maero_initial_health * Maero_initial_health_coop_multiplier 
  350. 		MAX_BH_NOTORIETY = MAX_BH_NOTORIETY_COOP 
  351. 	end 
  352.  
  353. 	if coop_is_active() then 
  354. 		IN_COOP = true 
  355. 	end 
  356.  
  357. 	bh10_start_persona_overrides() 
  358.  
  359. end 
  360.  
  361. -- Initialization code specific to the checkpoint. 
  362. function bh10_initialize_checkpoint(checkpoint) 
  363.  
  364. 	if ( (checkpoint == MISSION_START_CHECKPOINT) or (checkpoint == CHECKPOINT_STAGING) ) then 
  365. 		bh10_lock_warehouse_doors(true) 
  366. 	else 
  367. 		bh10_lock_warehouse_doors(false) 
  368. 		bh10_hide_warehouse_doors() 
  369. 	end 
  370.  
  371. 	if (checkpoint == MISSION_START_CHECKPOINT) then 
  372. 		 
  373. 		if IN_COOP then 
  374. 			party_add(TABLE_PLAYER_HOMIES[2], REMOTE_PLAYER) 
  375. 		else 
  376. 			if (not DEBUG_MAERO_FIGHT) then 
  377. 				party_add(TABLE_PLAYER_HOMIES[2], LOCAL_PLAYER) 
  378. 			end 
  379. 		end 
  380. 		if ( (not DEBUG_MAERO_FIGHT) and (not DEBUG_ENTER_WAREHOUSE) ) then 
  381. 			party_add(TABLE_PLAYER_HOMIES[1], LOCAL_PLAYER) 
  382. 		end 
  383.  
  384. 		-- Teleport players to start locations -- 
  385. 		if (DEBUG_ENTER_WAREHOUSE) then 
  386. 			teleport_coop("bh10_$waypoint_2", "bh10_$waypoint_2") 
  387. 		end 
  388.  
  389. 		notoriety_set("Brotherhood", 0) 
  390. 		notoriety_force_no_spawn("Brotherhood", false) 
  391.  
  392. 	elseif ( checkpoint == CHECKPOINT_STAGING )then 
  393.  
  394. 		bh10_create_saints_and_los_dummies() 
  395.  
  396. 		notoriety_set("Brotherhood", MAX_BH_NOTORIETY) 
  397. 		notoriety_force_no_spawn("Brotherhood", false) 
  398.  
  399. 		on_trigger("",TRIGGER_TRIBAL_STAGING) 
  400. 		trigger_enable(TRIGGER_TRIBAL_STAGING,false) 
  401. 		marker_remove_trigger(TRIGGER_TRIBAL_STAGING, SYNC_ALL) 
  402. 		mission_waypoint_remove(SYNC_ALL) 
  403.  
  404. 	elseif ( checkpoint == CHECKPOINT_WAREHOUSE ) then 
  405.  
  406. 		notoriety_set_max("Brotherhood", MAX_BH_NOTORIETY) 
  407. 		notoriety_set("Brotherhood", MAX_BH_NOTORIETY) 
  408. 		notoriety_set_min("Brotherhood", MAX_BH_NOTORIETY) 
  409.  
  410. 	elseif (checkpoint == CHECKPOINT_MAERO) then 
  411. 		-- Normally Maero is created by the cutscene. We're skipping that so create him here. 
  412. 		group_create(GROUP_MAERO, true) 
  413. 		door_open(MM_ROOF_DOOR) 
  414. 		door_open(MM_EXPLOIT_DOOR_1) 
  415. 		door_open(MM_EXPLOIT_DOOR_2) 
  416. 		door_open(MM_EXPLOIT_DOOR_3) 
  417. 		bh10_setup_maero() 
  418. 		inv_item_equip("minigun", CHAR_MAERO) 
  419. 		bh10_exploits() 
  420. 		--thread_new("bh10_no_crouch") 
  421. 		thread_new("bh10_maero_ai") 
  422. 	end 
  423.  
  424. end 
  425.  
  426. function bh10_create_saints_and_los_dummies() 
  427.  
  428. 	group_create(GROUP_SAINTS[1], true) 
  429.  
  430. 	for i, group in pairs(GROUP_LOS_DUMMIES) do 
  431. 		group_create(group, true) 
  432. 	end 
  433.  
  434. 	for i, npc in pairs(LOS_DUMMIES) do 
  435. 		on_death("bh10_respawn_los_dummy", npc) 
  436. 		set_ignore_ai_flag(npc, true) 
  437. 		inv_item_remove_all(npc) 
  438. 		npc_combat_enable(npc, false) 
  439. 		npc_weapon_pickup_override(npc, false) 
  440. 	end 
  441.  
  442. 	for i, npc in pairs(EXTRA_SAINTS[CAR_NUM]) do 
  443. 		npc_combat_enable(npc, false) 
  444. 		if i > 1 then 
  445. 			vehicle_enter_teleport(npc, SAINTS_CAR[CAR_NUM][1], i-1) 
  446. 		end 
  447. 	end 
  448.  
  449. end 
  450.  
  451. -- Lock or unlock the stairwell doors that give access to the warehouse 
  452. function bh10_lock_warehouse_doors(lock) 
  453. 	door_lock(MM_STAIRWELL_DOOR_1, lock) 
  454. 	door_lock(MM_STAIRWELL_DOOR_2, lock) 
  455. 	door_lock(MM_ROOF_DOOR, lock) 
  456. end 
  457.  
  458. -- Hide a subset of the warehouse's doors 
  459. function bh10_hide_warehouse_doors() 
  460. 	for i,door in pairs(MM_DOORS_TO_HIDE) do 
  461. 		mesh_mover_hide(door) 
  462. 	end 
  463. end 
  464.  
  465. function bh10_start_persona_overrides() 
  466. 	persona_override_group_start(BH10_BROTHERHOOD_ATTACK_PERSONAS, POT_SITUATIONS[POT_ATTACK], "BR10_ATTACK") 
  467. 	persona_override_group_start(BH10_SAINTS_ATTACK_PERSONAS, POT_SITUATIONS[POT_ATTACK], "BR10_ATTACK") 
  468. end 
  469.  
  470. function bh10_stop_persona_overrides() 
  471. 	persona_override_group_stop(BROTHERHOOD_PERSONAS, POT_SITUATIONS[POT_ATTACK]) 
  472. 	persona_override_group_stop(SAINTS_PERSONAS, POT_SITUATIONS[POT_ATTACK]) 
  473. end 
  474.  
  475. function bh10_respawn_los_dummy(npc) 
  476. 	local group = "" 
  477. 	for i = 1, 3 do 
  478. 		if npc==LOS_DUMMIES[i] then 
  479. 			group = GROUP_LOS_DUMMIES[i] 
  480. 			i = 4 
  481. 		end 
  482. 	end 
  483. 	delay(3) 
  484. 	release_to_world(group) 
  485. 	group_create(group) 
  486. 	on_death("bh10_respawn_los_dummy", npc) 
  487. 	set_ignore_ai_flag(npc, true) 
  488. 	inv_item_remove_all(npc) 
  489. 	npc_combat_enable(npc, false) 
  490. 	npc_weapon_pickup_override(npc, false) 
  491. end 
  492.  
  493. function bh10_drive_to_staging_area() 
  494.  
  495. 	thread_new("bh10_create_saints_and_los_dummies") 
  496.  
  497. 	delay(2) 
  498. 	mission_help_table("bh10_drive_to_staging_area") 
  499. 	THREAD_NOTORIETY = thread_new("bh10_raise_tribal_notoriety") 
  500.  
  501. 	trigger_enable(TRIGGER_TRIBAL_STAGING, true) 
  502. 	marker_add_trigger(TRIGGER_TRIBAL_STAGING, MINIMAP_ICON_LOCATION, INGAME_EFFECT_VEHICLE_LOCATION, SYNC_ALL) 
  503. 	on_trigger("bh10_tribal_staging_reached", TRIGGER_TRIBAL_STAGING) 
  504. 	mission_waypoint_add(TRIGGER_TRIBAL_STAGING) 
  505.  
  506. end 
  507.  
  508. function bh10_tribal_staging_reached() 
  509. 	on_trigger("",TRIGGER_TRIBAL_STAGING) 
  510. 	trigger_enable(TRIGGER_TRIBAL_STAGING,false) 
  511. 	marker_remove_trigger(TRIGGER_TRIBAL_STAGING, SYNC_ALL) 
  512. 	mission_waypoint_remove(SYNC_ALL) 
  513.  
  514. 	THREAD_LIEUTENANTS = thread_new("bh10_get_to_tribal_hq") 
  515. end 
  516.  
  517. function bh10_num_saints_assisting() 
  518. 	local Num_saints = 0 
  519. 	for i, npc in pairs(EXTRA_SAINTS[CAR_NUM]) do 
  520. 		if not character_is_dead(npc) and (get_dist_char_to_char(LOCAL_PLAYER, npc) < Saints_max_distance or character_is_in_vehicle(npc)) then 
  521. 			Num_saints = Num_saints + 1 
  522. 		end 
  523. 	end 
  524. 	return Num_saints 
  525. end 
  526.  
  527. function bh10_initial_backup_run() 
  528. 	vehicle_enter(EXTRA_SAINTS[CAR_NUM][1], SAINTS_CAR[CAR_NUM][1], 0) 
  529.  
  530. 	for i, npc in pairs(EXTRA_SAINTS[CAR_NUM]) do 
  531. 		npc_combat_enable(npc, true) 
  532. 	end 
  533.  
  534. 	vehicle_pathfind_to(SAINTS_CAR[CAR_NUM][1], NAV_SAINTS_INITIAL_ENTRY, true, true) 
  535. 	force_fire_target(CHAR_FIRST_ROCKETEER, CHAR_FIRST_ROCKETEE, false) 
  536.  
  537. 	for i, npc in pairs(EXTRA_SAINTS[CAR_NUM]) do 
  538. 		if not character_is_dead(npc) and character_is_in_vehicle(npc) then  
  539. 			thread_new("vehicle_exit", npc) 
  540. 		end 
  541. 	end 
  542. end 
  543.  
  544. function bh10_select_backup_car() 
  545. 	local Car_found = false 
  546. 	local i = 0 
  547. 	while not Car_found do 
  548. 		thread_yield() 
  549. 		i = rand_int(2,4) 
  550. 		if not character_is_dead(LOS_DUMMIES[i-1]) and not los_check(LOCAL_PLAYER, LOS_DUMMIES[i-1]) and get_dist_char_to_nav(LOCAL_PLAYER, LOS_DUMMIES[i-1]) > 75 then 
  551. 			CAR_NUM = i 
  552. 			Car_found = true 
  553. 		end 
  554. 	end 
  555. end 
  556.  
  557. function bh10_saints_backup() 
  558. 	bh10_initial_backup_run() 
  559. 	delay(5) 
  560.  
  561. 	while bh10_num_saints_assisting() >= Min_saints_assisting do 
  562. 		thread_yield() 
  563. 	end 
  564.  
  565. 	while(1) do 
  566. 		thread_yield() 
  567. 		release_to_world(GROUP_SAINTS[CAR_NUM]) 
  568.  
  569. 		--determine next car to send 
  570. 		bh10_select_backup_car()		 
  571.  
  572. 		group_create(GROUP_SAINTS[CAR_NUM], true) 
  573.  
  574. 		if CAR_NUM == 4 then 
  575. 			for i, car in pairs(SAINTS_CAR[CAR_NUM]) do 
  576. 				vehicle_repair(car, 1.0) 
  577. 				--teleport_vehicle(car, NAV_BIKE_START[i]) 
  578. 				vehicle_enter_teleport(EXTRA_SAINTS[CAR_NUM][i], car, 0) 
  579. 				npc_combat_enable(EXTRA_SAINTS[CAR_NUM][i], true) 
  580. 				thread_new("bh10_backup_chase", car, LOCAL_PLAYER, true, false, true, true) 
  581. 			end 
  582. 		else 
  583. 			vehicle_repair(SAINTS_CAR[CAR_NUM][1], 1.0) 
  584. 			for i, npc in pairs(EXTRA_SAINTS[CAR_NUM]) do 
  585. 				vehicle_enter_teleport(npc, SAINTS_CAR[CAR_NUM][1], i-1) 
  586. 				npc_combat_enable(npc, true) 
  587. 			end 
  588. 			thread_new("bh10_backup_chase", SAINTS_CAR[CAR_NUM][1], LOCAL_PLAYER, true, false, true, true) 
  589. 		end 
  590.  
  591. 		while bh10_num_saints_assisting() >= Min_saints_assisting do 
  592. 			thread_yield() 
  593. 		end 
  594. 	end 
  595. end 
  596.  
  597. function bh10_backup_chase(car, target, b1, b2, b3, b4) 
  598. 	vehicle_chase(car, target, b1, b2, b3, b4) 
  599. end 
  600.  
  601.  
  602. function bh10_get_to_tribal_hq() 
  603. 	mission_set_checkpoint(CHECKPOINT_STAGING) 
  604. 	delay(1) 
  605. 	group_create(GROUP_STANDARD_LIEUTENANTS, true) 
  606. 	group_create(GROUP_ROCKET_LIEUTENANTS, true) 
  607.  
  608. 	THREAD_SAINTS_BACKUP = thread_new("bh10_saints_backup") 
  609.  
  610. 	for i, npc in pairs(TABLE_STANDARD_LIEUTENANTS) do 
  611. 		npc_combat_enable(npc,true) 
  612. 		npc_unholster_best_weapon(npc) 
  613. 		npc_leash_to_nav(npc, npc, 5) 
  614. 		marker_add_npc(npc, MINIMAP_ICON_KILL, INGAME_EFFECT_KILL, SYNC_ALL) 
  615. 		on_death("bh10_lieutenant_killed", npc) 
  616. 	end 
  617. 	for i, npc in pairs(TABLE_ROCKET_LIEUTENANTS) do 
  618. 		npc_combat_enable(npc,true) 
  619. 		inv_item_add("rpg_launcher",1,npc) 
  620. 		inv_item_equip("rpg_launcher",npc) 
  621. 		npc_leash_to_nav(npc, npc, 5) 
  622. 		marker_add_npc(npc, MINIMAP_ICON_KILL, INGAME_EFFECT_KILL, SYNC_ALL) 
  623. 		on_death("bh10_lieutenant_killed", npc) 
  624. 	end 
  625.  
  626. 	mission_help_table("bh10_kill_tribal_lieutenants") 
  627.  
  628. 	while Num_lieutenants_left > 0 do 
  629. 		thread_yield() 
  630. 		objective_text(0, "bh10_lieutenants_killed", (INITIAL_LIEUTENANTS - Num_lieutenants_left), INITIAL_LIEUTENANTS) 
  631. 	end 
  632.  
  633. 	thread_kill(THREAD_SAINTS_BACKUP) 
  634. 	objective_text(0, "bh10_lieutenants_killed", (INITIAL_LIEUTENANTS - Num_lieutenants_left), INITIAL_LIEUTENANTS) 
  635.  
  636. 	bh10_enter_warehouse() 
  637. end 
  638.  
  639. function bh10_lieutenant_killed(character) 
  640. 	Num_lieutenants_left = Num_lieutenants_left - 1 
  641. 	marker_remove_npc(character, SYNC_ALL) 
  642. 	on_death("", character) 
  643. 	if (Num_lieutenants_left == 0) then 
  644. 		delay(1) 
  645. 		audio_play_for_character(VOICE_15_KILLS, LOCAL_PLAYER, "voice") 
  646. 	elseif (Num_lieutenants_left == 2) then 
  647. 		delay(1) 
  648. 		audio_play_for_character(VOICE_12_KILLS, LOCAL_PLAYER, "voice") 
  649. 	elseif (Num_lieutenants_left == 4) then 
  650. 		delay(1) 
  651. 		audio_play_for_character(VOICE_9_KILLS, LOCAL_PLAYER, "voice") 
  652. 	elseif (Num_lieutenants_left == 6) then 
  653. 		delay(1) 
  654. 		audio_play_for_character(VOICE_6_KILLS, LOCAL_PLAYER, "voice") 
  655. 	elseif (Num_lieutenants_left == 8) then 
  656. 		delay(1) 
  657. 		audio_play_for_character(VOICE_3_KILLS, LOCAL_PLAYER, "voice") 
  658. 	end 
  659. end 
  660.  
  661. function bh10_enter_warehouse() 
  662.  
  663. 	bh10_lock_warehouse_doors(false) 
  664. 	bh10_hide_warehouse_doors() 
  665.  
  666. 	mission_set_checkpoint(CHECKPOINT_WAREHOUSE) 
  667. 	notoriety_force_no_spawn("Brotherhood", true) 
  668. 	delay(2) 
  669. 	objective_text_clear(0) 
  670. 	mission_help_table("bh10_get_into_warehouse") 
  671.  
  672. 	THREAD_ROOF = thread_new("bh10_get_to_warehouse_roof") 
  673.  
  674. end 
  675.  
  676. function bh10_get_to_warehouse_roof() 
  677. 	-- group_create(GROUP_WAREHOUSE_SOLDIERS, true) 
  678.  
  679. 	trigger_enable(TRIGGER_WH_GROUP_01, true) 
  680. 	on_trigger("bh10_warehouse_group_one", TRIGGER_WH_GROUP_01) 
  681. 	trigger_enable(TRIGGER_WH_GROUP_02, true) 
  682. 	on_trigger("bh10_warehouse_group_two", TRIGGER_WH_GROUP_02) 
  683. 	trigger_enable(TRIGGER_WH_GROUP_03, true) 
  684. 	on_trigger("bh10_warehouse_group_three", TRIGGER_WH_GROUP_03) 
  685. 	trigger_enable(TRIGGER_WH_GROUP_04, true) 
  686. 	on_trigger("bh10_warehouse_group_four", TRIGGER_WH_GROUP_04) 
  687. 	trigger_enable(TRIGGER_WH_GROUP_05, true) 
  688. 	on_trigger("bh10_warehouse_group_five", TRIGGER_WH_GROUP_05) 
  689.  
  690. 	-- group_create(GROUP_WAREHOUSE_FLOOR_1, true) 
  691. 	-- group_create(GROUP_WAREHOUSE_FLOOR_2, true) 
  692. 	-- group_create(GROUP_WAREHOUSE_FLOOR_3, true) 
  693. 	-- group_create(GROUP_WAREHOUSE_FLOOR_4, true) 
  694.  
  695. 	delay(2) 
  696.  
  697. 	for i, waypoint in pairs(NAV_WAREHOUSE_WAYPOINTS) do 
  698. 		thread_yield() 
  699. 		marker_add_navpoint(waypoint, MINIMAP_ICON_LOCATION, INGAME_EFFECT_LOCATION, SYNC_ALL) 
  700. 		while ((get_dist_char_to_nav(LOCAL_PLAYER, waypoint) > 5) and ((not IN_COOP) or get_dist_char_to_nav(REMOTE_PLAYER, waypoint) > 5)) do 
  701. 			thread_yield() 
  702. 		end 
  703. 		if (i==1) then 
  704. 			mission_help_table("bh10_get_to_warehouse_roof") 
  705. 		end 
  706. 		marker_remove_navpoint(waypoint, SYNC_ALL) 
  707. 	end 
  708.  
  709. 	trigger_enable(TRIGGER_WAREHOUSE_ROOF, true) 
  710. 	marker_add_trigger(TRIGGER_WAREHOUSE_ROOF, MINIMAP_ICON_LOCATION, INGAME_EFFECT_LOCATION, SYNC_ALL) 
  711. 	on_trigger("bh10_warehouse_roof_reached", TRIGGER_WAREHOUSE_ROOF) 
  712. 	mission_waypoint_add(TRIGGER_WAREHOUSE_ROOF) 
  713. end 
  714.  
  715. function bh10_warehouse_group_one() 
  716. 	group_create(GROUP_WAREHOUSE_FLOOR_1, true) 
  717. end 
  718.  
  719. function bh10_warehouse_group_two() 
  720. 	group_create(GROUP_WAREHOUSE_FLOOR_2, true) 
  721. end 
  722.  
  723. function bh10_warehouse_group_three() 
  724. 	group_create(GROUP_WAREHOUSE_FLOOR_3, true) 
  725. 	delay(1) 
  726. 	attack(FLOOR_3_1A, FLOOR_3_2A, true) 
  727. 	attack(FLOOR_3_1B, FLOOR_3_2B, true) 
  728. end 
  729.  
  730. function bh10_warehouse_group_four() 
  731. 	group_create(GROUP_WAREHOUSE_FLOOR_4, true) 
  732. end 
  733.  
  734. function bh10_warehouse_group_five() 
  735. 	group_create(GROUP_WAREHOUSE_FLOOR_5, true) 
  736. 	attack(FLOOR_5_01, LOCAL_PLAYER, true) 
  737. 	attack(FLOOR_5_02, LOCAL_PLAYER, true)		 
  738. 	attack(FLOOR_5_03, LOCAL_PLAYER, true)	 
  739. 	attack(FLOOR_5_04, LOCAL_PLAYER, true) 
  740. 	attack(FLOOR_5_05, LOCAL_PLAYER, true) 
  741. end 
  742.  
  743. function bh10_warehouse_roof_reached() 
  744. 	on_trigger("",TRIGGER_WAREHOUSE_ROOF) 
  745. 	trigger_enable(TRIGGER_WAREHOUSE_ROOF,false) 
  746. 	marker_remove_trigger(TRIGGER_WAREHOUSE_ROOF, SYNC_ALL) 
  747. 	mission_waypoint_remove(SYNC_ALL) 
  748.  
  749. 	bh10_kill_maero(true) 
  750. end 
  751.  
  752. In_high_ground = {[LOCAL_PLAYER] = true, [REMOTE_PLAYER] = true} 
  753. In_low_ground = {[LOCAL_PLAYER] = false, [REMOTE_PLAYER] = false} 
  754. Hiding = {[LOCAL_PLAYER] = false, [REMOTE_PLAYER] = false} 
  755.  
  756. function bh10_high_ground_entered(triggerer, trigger) 
  757. 	In_high_ground[triggerer] = true 
  758. end 
  759.  
  760. function bh10_high_ground_exited(triggerer, trigger) 
  761. 	In_high_ground[triggerer] = false 
  762. end 
  763.  
  764. function bh10_low_ground_entered(triggerer, trigger) 
  765. 	In_low_ground[triggerer] = true 
  766. end 
  767.  
  768. function bh10_low_ground_exited(triggerer, trigger) 
  769. 	In_low_ground[triggerer] = false 
  770. end 
  771.  
  772. function bh10_hiding_entered(triggerer, trigger) 
  773. 	Hiding[triggerer] = true 
  774. end 
  775.  
  776. function bh10_hiding_exited(triggerer, trigger) 
  777. 	Hiding[triggerer] = false 
  778. end 
  779.  
  780. function bh10_kill_maero(play_cutscene) 
  781.  
  782. 	-- Setup Maero's Script AI Triggers 
  783. 		trigger_enable(TRIGGER_HIGH_GROUND, true) 
  784. 		on_trigger("bh10_high_ground_entered",TRIGGER_HIGH_GROUND) 
  785. 		on_trigger_exit("bh10_high_ground_exited",TRIGGER_HIGH_GROUND) 
  786. 		trigger_set_delay_between_activations(TRIGGER_HIGH_GROUND,0) 
  787.  
  788. 		trigger_enable(TRIGGER_LOW_GROUND, true) 
  789. 		on_trigger("bh10_low_ground_entered",TRIGGER_LOW_GROUND) 
  790. 		on_trigger_exit("bh10_low_ground_exited",TRIGGER_LOW_GROUND) 
  791. 		trigger_set_delay_between_activations(TRIGGER_LOW_GROUND,0) 
  792.  
  793. 		trigger_enable(TRIGGER_HIDING, true) 
  794. 		on_trigger("bh10_hiding_entered",TRIGGER_HIDING) 
  795. 		on_trigger_exit("bh10_hiding_exited",TRIGGER_HIDING) 
  796. 		trigger_set_delay_between_activations(TRIGGER_HIDING,0) 
  797.  
  798. 	-- Add damage callbacks for players 
  799. 		on_take_damage("bh10_player_damaged", LOCAL_PLAYER) 
  800. 		turn_invulnerable(LOCAL_PLAYER) 
  801. 		if (IN_COOP) then 
  802. 			on_take_damage("bh10_player_damaged", REMOTE_PLAYER) 
  803. 			turn_invulnerable(REMOTE_PLAYER) 
  804. 		end 
  805.  
  806. 	-- Play the cutscene 
  807. 	if(play_cutscene) then 
  808. 		fade_out(0.0,{0,0,0}, SYNC_ALL) 
  809.  
  810. 		-- Disable player controls 
  811. 		player_controls_disable(LOCAL_PLAYER) 
  812. 		if (IN_COOP) then 
  813. 			player_controls_disable(REMOTE_PLAYER) 
  814. 		end 
  815.  
  816. 		group_destroy(GROUP_WAREHOUSE_FLOOR_1) 
  817. 		group_destroy(GROUP_WAREHOUSE_FLOOR_2) 
  818. 		group_destroy(GROUP_WAREHOUSE_FLOOR_3) 
  819. 		group_destroy(GROUP_WAREHOUSE_FLOOR_4) 
  820. 		group_destroy(GROUP_WAREHOUSE_FLOOR_5) 
  821.  
  822. 		-- Eliminate everyone in the existing party. Turn off ped. spawnin and repopulate the world 
  823. 		-- to eliminate any followers that you brought along. 
  824. 		party_dismiss_all() 
  825. 		party_set_recruitable(false) 
  826. 		group_destroy(GROUP_PLAYER_HOMIES) 
  827. 		spawning_pedestrians(false, true) 
  828.  
  829. 		cutscene_play("IG_bh10_scene1", nil, nil, false) 
  830.  
  831. 		-- Destroy the cutscene version of Maero and create a new one 
  832. 		group_destroy(GROUP_MAERO) 
  833. 		group_create(GROUP_MAERO, true) 
  834.  
  835. 		bh10_setup_maero() 
  836.  
  837. 		door_open(MM_ROOF_DOOR) 
  838. 		door_open(MM_EXPLOIT_DOOR_1) 
  839. 		door_open(MM_EXPLOIT_DOOR_2) 
  840. 		door_open(MM_EXPLOIT_DOOR_3) 
  841.  
  842. 		-- Teleport players to the start of the fight 
  843. 		teleport_coop(NAV_PLAYER_START_MAERO, NAV_REMOTE_START_MAERO) 
  844. 		fade_in(1.0, SYNC_ALL) 
  845.  
  846. 		mission_set_checkpoint(CHECKPOINT_MAERO) 
  847.  
  848. 		-- Reenable player controls 
  849. 		player_controls_enable(LOCAL_PLAYER) 
  850. 		if (IN_COOP) then 
  851. 			player_controls_enable(REMOTE_PLAYER) 
  852. 		end 
  853.  
  854. 		bh10_exploits() 
  855. 		--thread_new("bh10_no_crouch") 
  856. 		thread_new("bh10_maero_ai") 
  857.  
  858. 	end 
  859.  
  860. 	delay(1.0) 
  861.  
  862. 	mission_help_table("bh11_kill_maero") 
  863.  
  864. end 
  865.  
  866. function bh10_player_damaged(player, attacker, damage_percent) 
  867.  
  868. 	local old_hit_points = get_current_hit_points(player) 
  869. 	local new_hit_points = damage_percent * get_max_hit_points(player) 
  870. 	local damage = old_hit_points - new_hit_points	 
  871.  
  872. 	if (attacker == CHAR_MAERO) then 
  873. 		damage = damage * Maero_damage_multiplier 
  874. 	end 
  875.  
  876. 	if (damage < 1) then 
  877. 		damage = 1 
  878. 	end 
  879.  
  880. 	character_damage( player,damage ) 
  881. 	 
  882. end 
  883.  
  884. function bh10_setup_maero() 
  885.  
  886. 	group_create(GROUP_GRENADES) 
  887.  
  888. 	-- Setup Maero 
  889. 	character_allow_ragdoll(CHAR_MAERO, false) 
  890. 	set_never_crouch_flag(CHAR_MAERO, true) 
  891. 	character_prevent_explosion_fling(CHAR_MAERO, true) 
  892. 	character_prevent_flinching(CHAR_MAERO, true) 
  893. 	set_max_hit_points(CHAR_MAERO, Maero_initial_health) 
  894. 	set_current_hit_points(CHAR_MAERO, Maero_initial_health) 
  895.  
  896. 	-- Set always-on flags 
  897. 	character_set_cannot_be_grabbed(CHAR_MAERO, true) 
  898. 	set_perfect_aim(CHAR_MAERO, true) 
  899. 	set_ignore_burst_accuracy_flag(CHAR_MAERO, true) 
  900. 	set_trailing_aim_flag(CHAR_MAERO, true) 
  901.  
  902. 	-- Handle Maero taking damage in script 
  903. 	turn_invulnerable(CHAR_MAERO, false)  
  904. 	on_take_damage("bh10_maero_damaged",CHAR_MAERO) 
  905.  
  906. 	-- Setup Maero w/ some weapons 
  907. 	inv_item_add("minigun", 1, CHAR_MAERO) 
  908. 	inv_item_add(Thrown_weapon, 1, CHAR_MAERO) 
  909.  
  910. 	on_death("bh10_mission_complete", CHAR_MAERO)	 
  911.  
  912. 	damage_indicator_on(0,CHAR_MAERO,0.0, "bh11_maeros_health") 
  913. end 
  914.  
  915. function bh10_mission_complete() 
  916. 	turn_invulnerable(LOCAL_PLAYER, false) 
  917. 	if (IN_COOP) then 
  918. 		turn_invulnerable(REMOTE_PLAYER, false) 
  919. 	end 
  920. 	mission_end_success("bh10", "br10-02") 
  921. end 
  922.  
  923. Should_check_exploits	= {[LOCAL_PLAYER] = false, [REMOTE_PLAYER] = false} 
  924. In_exploit_area = {[LOCAL_PLAYER] = {}, [REMOTE_PLAYER] = {}} 
  925. In_spawn_area = {[LOCAL_PLAYER] = {}, [REMOTE_PLAYER] = {}} 
  926. function bh10_exploits() 
  927.  
  928. 	npc_respawn_dist_override(.01) 
  929.  
  930. 	-- Turn on general exploit area enter/exit functions 
  931. 	for i,trigger in pairs(TRIGGER_EXPLOIT_ENTRANCES) do 
  932. 		trigger_enable(trigger, true) 
  933. 		on_trigger("bh10_exploit_entered",trigger) 
  934. 		trigger_set_delay_between_activations(trigger,0)		 
  935. 	end 
  936. 	for i,trigger in pairs(TRIGGER_EXPLOIT_EXITS) do 
  937. 		trigger_enable(trigger, true) 
  938. 		on_trigger("bh10_exploit_exited",trigger) 
  939. 		trigger_set_delay_between_activations(trigger,0)		 
  940. 	end 
  941.  
  942. 	-- Turn on specific exploit area triggers 
  943. 	for i,trigger in pairs(TRIGGER_EXPLOIT_AREAS) do 
  944. 		trigger_enable(trigger, true) 
  945. 		In_exploit_area[LOCAL_PLAYER][trigger] = false 
  946. 		In_exploit_area[REMOTE_PLAYER][trigger] = false 
  947. 		on_trigger("bh10_exploit_area_entered",trigger) 
  948. 		on_trigger_exit("bh10_exploit_area_exited",trigger) 
  949. 		trigger_set_delay_between_activations(trigger,0)		 
  950. 	end 
  951.  
  952. 	-- Turn on spawn-area triggers 
  953. 	for name,spawn_info in pairs(EXPLOIT_SPAWN_INFO) do 
  954. 		for i,trigger in pairs(spawn_info["triggers"]) do 
  955. 			trigger_enable(trigger, true) 
  956. 			In_spawn_area[LOCAL_PLAYER][trigger] = 0 
  957. 			In_spawn_area[REMOTE_PLAYER][trigger] = 0 
  958. 			on_trigger("bh10_spawn_area_entered",trigger) 
  959. 			on_trigger_exit("bh10_spawn_area_exited",trigger) 
  960. 			trigger_set_delay_between_activations(trigger,0) 
  961. 		end 
  962. 		thread_new("bh10_exploit_spawn_area", name) 
  963. 	end 
  964.  
  965. 	group_create_hidden(GROUP_EXPLOIT_BH) 
  966.  
  967. end 
  968.  
  969. -- Spawn brotherhood for a specific spawn area 
  970. Living_exploit_spawns = {} 
  971. function bh10_exploit_spawn_area(name) 
  972. 	 
  973. 	while( not group_is_loaded(GROUP_EXPLOIT_BH) ) do 
  974. 		thread_yield() 
  975. 	end 
  976.  
  977. 	local triggers = EXPLOIT_SPAWN_INFO[name]["triggers"] 
  978.  
  979. 	local max_spawns = EXPLOIT_SPAWN_INFO[name]["max_npcs"] 
  980. 	if (IN_COOP) then 
  981. 		max_spawns = EXPLOIT_SPAWN_INFO[name]["max_npcs_coop"] 
  982. 	end 
  983. 	Living_exploit_spawns[name] = 0 
  984. 	local next_spawn_size = max_spawns 
  985.  
  986. 	while(true) do 
  987. 		thread_yield() 
  988. 	 
  989. 		-- Maybe check if we should spawn more Brotherhood at this location 
  990. 		if (Should_check_exploits[LOCAL_PLAYER] or IN_COOP) then 
  991.  
  992. 			-- Is the player in an associated exploit area? 
  993. 			local is_exploiting = false 
  994. 			for i, exploit in pairs(EXPLOIT_SPAWN_INFO[name]["exploit_areas"]) do 
  995. 				if(In_exploit_area[LOCAL_PLAYER][exploit] or In_exploit_area[REMOTE_PLAYER][exploit]) then 
  996. 					is_exploiting = true 
  997. 					break 
  998. 				end 
  999. 			end 
  1000.  
  1001. 			-- If an associated exploit is being used or we're in COOP, then maybe spawn more attackers 
  1002. 			if(is_exploiting or IN_COOP) then 
  1003.  
  1004. 				local space_available = (next_spawn_size + Living_exploit_spawns[name] <= max_spawns) 
  1005. 				local no_popping = true 
  1006. 				for i,trigger in pairs(triggers) do 
  1007. 					if ( (In_spawn_area[LOCAL_PLAYER][trigger] > 0) or (In_spawn_area[REMOTE_PLAYER][trigger] > 0)) then 
  1008. 						no_popping = false 
  1009. 					end 
  1010. 				end 
  1011. 				 
  1012. 				-- If all preconditions are met, then send the wave 
  1013. 				if(space_available and no_popping) then 
  1014.  
  1015. 					local num_spawned = bh10_send_wave(next_spawn_size, name) 
  1016. 					Living_exploit_spawns[name] = Living_exploit_spawns[name] + num_spawned 
  1017.  
  1018. 					next_spawn_size = rand_int(1,max_spawns - 1) 
  1019.  
  1020. 					-- Wait a bit before spawning any more attackers 
  1021. 					delay(rand_int(3,6)) 
  1022.  
  1023. 				end 
  1024. 			end 
  1025. 		end 
  1026.  
  1027. 	end 
  1028. end 
  1029.  
  1030. Exploit_spawn_origins = {} 
  1031.  
  1032. -- Send a wave of brotherhood to attack the players 
  1033. -- 
  1034. -- wave_size: number of attackers to send 
  1035. -- 
  1036. -- returns number of attackers successfully spawned 
  1037. function bh10_send_wave(wave_size, spawn_name) 
  1038.  
  1039. 	local num_spawned = 0 
  1040. 	local num_attack_points = sizeof_table(EXPLOIT_SPAWN_INFO[spawn_name]["attack points"]) 
  1041.  
  1042. 	-- For each npc to be spawned 
  1043. 	for i=1, wave_size, 1 do 
  1044.  
  1045. 		-- Get an npc to spawn and a safe spawning location.  
  1046. 		local npc = bh10_get_spawnable_exploit_bh() 
  1047. 		local spawn_navpoint = EXPLOIT_SPAWN_INFO[spawn_name]["spawn points"][i] 
  1048. 		if ( npc == nil ) then 
  1049. 			return num_spawned 
  1050. 		end 
  1051.  
  1052. 		-- We're gonna spawn this guy, do some book keeping. 
  1053. 		num_spawned = num_spawned + 1 
  1054. 		Exploit_spawn_origins[npc] = spawn_name 
  1055.  
  1056. 		-- Teleport to the spawn navpoint 
  1057. 		teleport(npc, spawn_navpoint) 
  1058.  
  1059. 		-- Tell the bh to respawn, override default respawn time 
  1060. 		npc_respawn_after_death(npc, true) 
  1061. 		npc_respawn_after_death_time_override(npc, 250, true) 
  1062. 		on_respawn("bh10_respawn_exploit_bh",npc) 
  1063.  
  1064. 		-- Show the npc and start its patrol 
  1065. 		character_show(npc) 
  1066. 		local attack_point = EXPLOIT_SPAWN_INFO[spawn_name]["attack points"][rand_int(1,num_attack_points)] 
  1067. 		thread_new("bh10_exploit_bh_attack", npc, attack_point) 
  1068.  
  1069. 		-- Delay a little bit, gives time to leave the spawn area and keeps congestion down. 
  1070. 		delay(.2,.5) 
  1071.  
  1072. 	end 
  1073.  
  1074. 	-- Return num of bh spawned 
  1075. 	return num_spawned 
  1076.  
  1077. end 
  1078.  
  1079. function bh10_exploit_bh_attack(bh, dest_navp) 
  1080. 	npc_respawn_after_death(bh, true) 
  1081. 	on_respawn("bh10_respawn_exploit_bh",bh) 
  1082.  
  1083. 	local force_complete = false 
  1084. 	local dist, player = get_dist_closest_player_to_object(dest_navp) 
  1085. 	if(dist > 40) then 
  1086. 		force_complete = true 
  1087. 	end 
  1088.  
  1089. 	move_to(bh,dest_navp,2,false, true) 
  1090. 	attack(bh) 
  1091. end 
  1092.  
  1093. -- Returns a spawnable bh if one is available, nil else. 
  1094. function bh10_get_spawnable_exploit_bh() 
  1095.  
  1096. 	for i, bh in pairs(EXPLOIT_BH) do 
  1097. 		if (Exploit_spawn_origins[bh] == nil) then 
  1098. 			return bh 
  1099. 		end 
  1100. 	end 
  1101.  
  1102. 	return nil 
  1103.  
  1104. end 
  1105.  
  1106. function bh10_respawn_exploit_bh(bh) 
  1107.  
  1108. 	local spawn_name = Exploit_spawn_origins[bh] 
  1109.  
  1110. 	-- Hide until needed 
  1111. 	character_hide(bh) 
  1112.  
  1113. 	-- Make available for spawning after a brief delay 
  1114. 	delay(.5) 
  1115. 	Exploit_spawn_origins[bh] = nil 
  1116. 	Living_exploit_spawns[spawn_name] = Living_exploit_spawns[spawn_name] - 1 
  1117. 	bh10_debug_text(spawn_name .. " killed, " .. Living_exploit_spawns[spawn_name] - 1 .. " remain", DEBUG_TEXT_EXPLOIT) 
  1118.  
  1119. end 
  1120.  
  1121. function bh10_exploit_entered(triggerer, trigger) 
  1122. 	Should_check_exploits[triggerer] = true 
  1123. end 
  1124. function bh10_exploit_exited(triggerer, trigger) 
  1125. 	Should_check_exploits[triggerer] = false 
  1126. end 
  1127. function bh10_exploit_area_entered(triggerer, trigger) 
  1128. 	In_exploit_area[triggerer][trigger] = true 
  1129. end 
  1130. function bh10_exploit_area_exited(triggerer, trigger) 
  1131. 	In_exploit_area[triggerer][trigger] = false 
  1132. end 
  1133. function bh10_spawn_area_entered(triggerer, trigger) 
  1134. 	In_spawn_area[triggerer][trigger] = In_spawn_area[triggerer][trigger] + 1 
  1135. end 
  1136. function bh10_spawn_area_exited(triggerer, trigger) 
  1137. 	In_spawn_area[triggerer][trigger] = In_spawn_area[triggerer][trigger] - 1 
  1138. end 
  1139.  
  1140. function bh10_no_crouch() 
  1141.  
  1142. 	set_never_crouch_flag(CHAR_MAERO, true) 
  1143.  
  1144. 	while(false) do 
  1145. 		if(crouch_is_crouching(CHAR_MAERO)) then 
  1146. 			crouch_stop(CHAR_MAERO, true) 
  1147. 		end 
  1148. 		thread_yield() 
  1149. 	end 
  1150.  
  1151. end 
  1152.  
  1153. -- MAERO_AI_MODES 
  1154. MAERO_AI_NONE =		"MAI_NONE" 
  1155. MAERO_AI_MINIGUN =	"MAI_MINIGUN" 
  1156. MAERO_AI_THROWN  =	"MAI_THROWN" 
  1157. MAERO_AI_HIDING  =	"MAI_HIDING" 
  1158. MAERO_AI_RECOVER =	"MAI_RECOVER" 
  1159.  
  1160. Maero_current_ai_mode = MAERO_AI_NONE 
  1161. Maero_knocked_down = false 
  1162. Maero_delayed_ai_mode = MAERO_AI_NONE 
  1163. Maero_delayed_ai_mode_time = 0 
  1164. Maero_throw_delay = 0 
  1165.  
  1166. function bh10_maero_ai() 
  1167.  
  1168. 	thread_new("bh10_maero_update_target") 
  1169.  
  1170. 	while(not character_is_dead(CHAR_MAERO)) do 
  1171.  
  1172. 		bh10_maero_ai_enter_mode(bh10_maero_get_ai_mode(), true)		 
  1173. 		bh10_maero_ai_process_mode(Maero_current_ai_mode) 
  1174.  
  1175. 		local frame_time = get_frame_time() 
  1176. 		if (Maero_delayed_ai_mode_time >= 0) then 
  1177. 			Maero_delayed_ai_mode_time = Maero_delayed_ai_mode_time - frame_time 
  1178. 		end 
  1179.  
  1180. 		if (Maero_throw_delay >= 0) then 
  1181. 			Maero_throw_delay = Maero_throw_delay - frame_time 
  1182. 		end 
  1183.  
  1184. 		thread_yield() 
  1185.  
  1186. 	end 
  1187. end 
  1188.  
  1189. Bh10_maero_target = LOCAL_PLAYER 
  1190. function bh10_maero_update_target() 
  1191.  
  1192. 	-- Target never changes in single player. Duh. 
  1193. 	if (not IN_COOP) then 
  1194. 		return 
  1195. 	end 
  1196.  
  1197. 	local delayed_target_update_time = 0 
  1198.  
  1199. 	-- This function checks if a player is exploiting 
  1200. 	--[[ 
  1201. 	local function is_exploiting(player) 
  1202. 		if (Should_check_exploits[player]) then 
  1203. 			for i, exploit in pairs(EXPLOIT_SPAWN_INFO[name]["exploit_areas"]) do 
  1204. 				if(In_exploit_area[player][exploit]) then 
  1205. 					return true 
  1206. 				end 
  1207. 			end 
  1208. 		else 
  1209. 			return false 
  1210. 		end 
  1211. 	end 
  1212. 	]] 
  1213. 	while(true) do 
  1214.  
  1215. 		thread_yield() 
  1216.  
  1217. 		if(character_exists(CHAR_MAERO) and (not character_is_dead(CHAR_MAERO))) then 
  1218.  
  1219. 			-- Switch immediately if current target is dead 
  1220. 			if (character_is_dead(Bh10_maero_target)) then 
  1221. 				mission_debug(Bh10_maero_target .. " is dead, switching to " .. OTHER_PLAYER[Bh10_maero_target], DEBUG_TEXT_TARGETS) 
  1222. 				Bh10_maero_target = OTHER_PLAYER[Bh10_maero_target] 
  1223. 			elseif (		Should_check_exploits[Bh10_maero_target]  
  1224. 							and (not Should_check_exploits[OTHER_PLAYER[Bh10_maero_target]]) 
  1225. 							and (not character_is_dead(OTHER_PLAYER[Bh10_maero_target])) 
  1226. 						) then 
  1227. 				-- Accumulate time that target_switching conditions have been met. 
  1228. 				if ( delayed_target_update_time  == 0) then 
  1229. 					bh10_debug_text("Considering switching targets", DEBUG_TEXT_TARGETS) 
  1230. 				end 
  1231. 				delayed_target_update_time = delayed_target_update_time + get_frame_time() 
  1232. 				if (delayed_target_update_time > 3) then 
  1233. 					Bh10_maero_target = OTHER_PLAYER[Bh10_maero_target] 
  1234. 					delayed_target_update_time = 0 
  1235. 					bh10_debug_text("Target switched to " .. Bh10_maero_target, DEBUG_TEXT_TARGETS) 
  1236. 				end 
  1237. 			else 
  1238. 			-- Switch conditions aren't met. Reset the switch countdown 
  1239. 				if (delayed_target_update_time ~= 0) then 
  1240. 					bh10_debug_text("No longer considering switching targets", DEBUG_TEXT_TARGETS) 
  1241. 				end 
  1242. 				delayed_target_update_time = 0 
  1243. 			end 
  1244.  
  1245. 		end 
  1246. 	end 
  1247.  
  1248. end 
  1249.  
  1250. function bh10_maero_get_ai_mode() 
  1251.  
  1252. 	if(Maero_knocked_down) then 
  1253. 		return MAERO_AI_RECOVER 
  1254. 	elseif(In_high_ground[Bh10_maero_target]) then 
  1255. 		return MAERO_AI_MINIGUN 
  1256. 	elseif(Hiding[Bh10_maero_target]) then 
  1257. 		return MAERO_AI_HIDING 
  1258. 	elseif(In_low_ground[Bh10_maero_target]) then 
  1259. 		return MAERO_AI_THROWN 
  1260. 	else 
  1261. 		return MAERO_AI_NONE 
  1262. 	end 
  1263.  
  1264. end 
  1265.  
  1266. Maero_throw_path_idx = 0 
  1267. Maero_hide_path_idx = 0 
  1268. function bh10_maero_ai_enter_mode(mode, delayed) 
  1269.  
  1270. 	-- If this is a delayed change & not enough time has passed, don't change modes. 
  1271. 	if ( delayed and (mode == Maero_delayed_ai_mode) and (Maero_delayed_ai_mode_time >= 0)) then 
  1272. 		return 
  1273. 	end 
  1274.  
  1275. 	-- A new delayed change has been requested, reset the timer and don't change modes 
  1276. 	if ( delayed and (mode ~= Maero_delayed_ai_mode) ) then 
  1277. 		Maero_delayed_ai_mode = mode 
  1278. 		Maero_delayed_ai_mode_time = 3 
  1279. 		return 
  1280. 	end 
  1281.  
  1282. 	-- Either Maero's AI will be changed or a request has been made to put him in his current 
  1283. 	-- AI mode. In either case, we can reset the delayed AI changes. 
  1284. 	Maero_delayed_ai_mode = MAERO_AI_NONE 
  1285. 	Maero_delayed_ai_mode_time = 0 
  1286.  
  1287. 	-- Already in this mode, nothing to see here. 
  1288. 	if (mode == Maero_current_ai_mode) then 
  1289. 		return 
  1290. 	end 
  1291.  
  1292. 	bh10_debug_text("Entering AI Mode " .. mode, DEBUG_TEXT_MAERO_AI) 
  1293.  
  1294. 	bh10_maero_ai_exit_mode(Maero_current_ai_mode) 
  1295. 	Maero_current_ai_mode = mode 
  1296.  
  1297. 	if (mode == MAERO_AI_NONE) then 
  1298. 		return 
  1299.  
  1300. 	elseif (mode == MAERO_AI_MINIGUN) then 
  1301. 		inv_item_add("minigun", 1, CHAR_MAERO) 
  1302. 		inv_item_equip("minigun", CHAR_MAERO) 
  1303.  
  1304. 	elseif (mode == MAERO_AI_THROWN) then 
  1305. 		inv_item_remove_all(CHAR_MAERO) 
  1306. 		inv_item_add(Thrown_weapon, 1, CHAR_MAERO) 
  1307. 		inv_item_equip(Thrown_weapon, CHAR_MAERO) 
  1308. 		Maero_throw_path_idx = move_to_do(CHAR_MAERO, "bh10_$n027", 2, true, true, false, 0) 
  1309. 		 
  1310. 	elseif (mode == MAERO_AI_RECOVER) then 
  1311. 		set_ignore_ai_flag( CHAR_MAERO, true ) 
  1312. 		inv_item_add("minigun", 1, CHAR_MAERO) 
  1313. 		inv_item_equip("minigun", CHAR_MAERO) 
  1314. 		action_play_non_blocking(CHAR_MAERO, "minigun fallover", nil, nil, true ) 
  1315.  
  1316. 	elseif (mode == MAERO_AI_HIDING) then 
  1317. 		inv_item_remove_all(CHAR_MAERO) 
  1318. 		inv_item_add(Thrown_weapon, 1, CHAR_MAERO) 
  1319. 		inv_item_equip(Thrown_weapon, CHAR_MAERO) 
  1320. 		Maero_hide_path_idx = move_to_do(CHAR_MAERO, "bh10_$n027", 2, true, true, false, 0) 
  1321. 	end 
  1322.  
  1323. end 
  1324.  
  1325. function bh10_maero_ai_exit_mode(mode) 
  1326.  
  1327. 	bh10_debug_text("bh10_maero_ai_exit_mode(" .. mode .. ")" , DEBUG_TEXT_MAERO_AI) 
  1328.  
  1329. 	bh10_maero_detonate_satchels() 
  1330.  
  1331. 	if (mode == MAERO_AI_NONE) then 
  1332. 	elseif (mode == MAERO_AI_MINIGUN) then 
  1333. 	elseif (mode == MAERO_AI_THROWN) then 
  1334. 	elseif (mode == MAERO_AI_HIDING) then 
  1335. 	elseif (mode == MAERO_AI_RECOVER) then 
  1336. 		inv_item_add("minigun", 1, CHAR_MAERO) 
  1337. 		inv_item_add(Thrown_weapon, 1, CHAR_MAERO) 
  1338. 		set_ignore_ai_flag( CHAR_MAERO, false) 
  1339. 		npc_combat_enable(CHAR_MAERO, true) 
  1340. 	end 
  1341.  
  1342. end 
  1343.  
  1344. Satchels_thrown = 0 
  1345. function bh10_maero_ai_process_mode(mode) 
  1346.  
  1347. 	if (mode == MAERO_AI_NONE) then 
  1348. 		return 
  1349. 	elseif (mode == MAERO_AI_MINIGUN) then 
  1350.  
  1351. 		if (force_ai_mode_check_done(CHAR_MAERO)) then 
  1352. 			force_fire_target_do(CHAR_MAERO, Bh10_maero_target, false) 
  1353. 		end 
  1354.  
  1355. 	elseif (mode == MAERO_AI_THROWN) then 
  1356.  
  1357. 		if (Maero_throw_path_idx ~= 0) then 
  1358. 			if not (move_to_check_done(Maero_throw_path_idx, CHAR_MAERO, "bh10_$n027", 2, true, true, false, 0)) then 
  1359. 				return 
  1360. 			end 
  1361. 			-- Reorient to face the same direction as the destination navpoint 
  1362. 			--turn_to(CHAR_MAERO, "bh10_$n027", true) 
  1363. 		end 
  1364. 		Maero_throw_path_idx = 0 
  1365.  
  1366. 		if (force_ai_mode_check_done(CHAR_MAERO)) then 
  1367. 			force_throw_char_do(CHAR_MAERO, Bh10_maero_target) 
  1368. 			Satchels_thrown = Satchels_thrown + 1 
  1369. 			Maero_throw_delay = 0.5 
  1370. 			bh10_debug_text("Satchels thrown = " .. Satchels_thrown, DEBUG_TEXT_SATCHELS) 
  1371. 		end 
  1372.  
  1373. 	elseif (mode == MAERO_AI_RECOVER) then 
  1374. 		if (action_play_is_finished(CHAR_MAERO, .70)) then 
  1375. 			Maero_knocked_down = false 
  1376. 		end 
  1377.  
  1378. 	elseif (mode == MAERO_AI_HIDING) then 
  1379.  
  1380. 		if (Maero_hide_path_idx ~= 0) then 
  1381. 			if not (move_to_check_done(Maero_hide_path_idx, CHAR_MAERO, "bh10_$n027", 2, true, true, false, 0)) then 
  1382. 				return 
  1383. 			end 
  1384. 		end 
  1385. 		Maero_hide_path_idx = 0 
  1386.  
  1387. 		if (force_ai_mode_check_done(CHAR_MAERO)) then 
  1388. 			bh10_maero_attack_hiding_player(Bh10_maero_target) 
  1389. 			Satchels_thrown = Satchels_thrown + 1 
  1390. 			Maero_throw_delay = 0.5 
  1391. 			bh10_debug_text("Satchels thrown = " .. Satchels_thrown, DEBUG_TEXT_SATCHELS) 
  1392. 		end 
  1393.  
  1394. 	end 
  1395.  
  1396. 	if (Satchels_thrown >= 3) then 
  1397. 		bh10_maero_detonate_satchels() 
  1398. 	end 
  1399.  
  1400. end 
  1401.  
  1402. function bh10_maero_detonate_satchels() 
  1403.  
  1404. 	if(Thrown_weapon == "satchel" and Satchels_thrown > 0) then 
  1405.  
  1406. 		bh10_debug_text("Entering bh10_maero_detonate_satchels", DEBUG_TEXT_SATCHELS) 
  1407.  
  1408. 		while( not force_ai_mode_check_done(CHAR_MAERO) ) do 
  1409. 			thread_yield() 
  1410. 		end 
  1411.  
  1412. 		set_ignore_ai_flag( CHAR_MAERO, true) 
  1413.  
  1414. 		if (Maero_throw_delay > 0) then 
  1415. 			delay(Maero_throw_delay) 
  1416. 		end 
  1417. 		for i=1, Satchels_thrown, 1 do 
  1418. 			inv_item_equip(Thrown_weapon, CHAR_MAERO) 
  1419. 			force_fire_pull_alt_trigger(CHAR_MAERO) 
  1420. 			delay(0.5) 
  1421. 		end 
  1422.  
  1423. 		set_ignore_ai_flag( CHAR_MAERO, false) 
  1424.  
  1425. 	end 
  1426.  
  1427. 	Satchels_thrown = 0 
  1428. 	Maero_throw_delay = 0 
  1429. end 
  1430.  
  1431. function bh10_maero_attack_hiding_player(player) 
  1432.  
  1433. 	local target_noise = 0.2 
  1434. 	local speed_noise = 0.1 
  1435. 	local angle_noise = 0.1 
  1436.  
  1437. 	local grenade_targets = {	"bh10_$n011", "bh10_$n012", "bh10_$n013", "bh10_$n014", "bh10_$n015", 
  1438. 										"bh10_$n016", "bh10_$n017", "bh10_$n018", "bh10_$n019", "bh10_$n020", 
  1439. 										"bh10_$n021", "bh10_$n022", "bh10_$n023", "bh10_$n024", "bh10_$n025", 
  1440. 										"bh10_$n026" 
  1441. 									} 
  1442.  
  1443. 	local target = "" 
  1444. 	local dist = 1000 
  1445. 	local message = "" 
  1446.  
  1447. 	if(rand_int(1,2) == 1) then 
  1448. 		-- Sometimes Maero picks a target near the player 
  1449. 		for i,navpoint in pairs(grenade_targets) do 
  1450. 			local cur_dist = get_dist(navpoint, player) 
  1451. 			cur_dist = cur_dist * rand_float(1.0 - target_noise, 1.0 + target_noise) 
  1452. 			if (cur_dist < dist) then 
  1453. 				dist = cur_dist 
  1454. 				target = navpoint 
  1455. 			end 
  1456. 		end 
  1457. 	else 
  1458. 		-- Othertimes, a random target is selected 
  1459. 		target = grenade_targets[rand_int(1,sizeof_table(grenade_targets))] 
  1460. 	end 
  1461. 	dist = get_dist(target,CHAR_MAERO) 
  1462.  
  1463. 	local angle = 60 * rand_float(1.0 - angle_noise, 1.0 + angle_noise) 
  1464. 	local speed = dist 
  1465.  
  1466. 	local alpha = 0 
  1467. 	if (dist > 16) then 
  1468. 		alpha = 1 
  1469. 	elseif(dist > 7) then 
  1470. 		alpha = (dist - 7) / 9 
  1471. 	end 
  1472.  
  1473. 	if (alpha > 0) then 
  1474. 		speed = 7 + alpha * 4.5 
  1475. 		angle = angle - alpha * 15 
  1476. 	end 
  1477.  
  1478. 	speed = speed  * rand_float(1.0 - speed_noise, 1.0 + speed_noise) 
  1479. 	if (speed > 11.5) then 
  1480. 		speed = 11.5 
  1481. 	end 
  1482. 	 
  1483. 	message = message .. "Angle = " .. angle .. " Speed = " .. speed ..  " Dist = " .. dist  
  1484. 	bh10_debug_text(message, DEBUG_TEXT_NUMBERS) 
  1485.  
  1486. 	force_throw_do(CHAR_MAERO, target, angle, speed) 
  1487. 	 
  1488. end 
  1489.  
  1490. function bh10_maero_damaged(maero, attacker, damage_percent, explosion) 
  1491.  
  1492. 	-- Maero can't damage himself. He's too cool. 
  1493. 	if(attacker == CHAR_MAERO) then 
  1494. 		return 
  1495. 	end 
  1496.  
  1497. 	local source = attacker 
  1498. 	if(not source) then 
  1499. 		source = "?" 
  1500. 	end 
  1501.  
  1502. 	local old_hit_points = get_current_hit_points(CHAR_MAERO) 
  1503. 	local new_hit_points = damage_percent * get_max_hit_points(CHAR_MAERO) 
  1504. 	local damage = old_hit_points - new_hit_points 
  1505.  
  1506. 	local msg = "" 
  1507. 	if(explosion) then 
  1508. 		damage = damage * Maero_explosion_ratio 
  1509. 		msg = msg .. "Explosion, " 
  1510.  
  1511. 		if(not Maero_knocked_down) then 
  1512. 			thread_new("bh10_maero_recover") 
  1513. 		end 
  1514. 	end 
  1515.  
  1516. 	if (Maero_knocked_down) then 
  1517. 		damage = damage * Maero_recover_damage_ratio 
  1518. 	end 
  1519.  
  1520. 	if(damage < 1) then 
  1521. 		damage = 1 
  1522. 	end 
  1523.  
  1524. 	bh10_debug_text(msg .. maero .. " at " .. damage_percent*100 .. "% health after attack by " .. source, DEBUG_TEXT_NUMBERS) 
  1525.  
  1526. 	set_current_hit_points(CHAR_MAERO, old_hit_points  - damage) 
  1527.  
  1528. end 
  1529.  
  1530. function bh10_maero_recover() 
  1531.  
  1532. 	Maero_knocked_down = true 
  1533. 	bh10_maero_ai_enter_mode(MAERO_AI_RECOVER, false) 
  1534.  
  1535. end 
  1536.  
  1537. function bh10_raise_tribal_notoriety() 
  1538. 	local phase_time = 0 
  1539. 	while(1) do 
  1540. 		thread_yield() 
  1541. 		phase_time = 0 
  1542. 		while (notoriety_get_decimal("Brotherhood") < MAX_BH_NOTORIETY) do 
  1543. 			thread_yield() 
  1544. 			local target_notoriety = MAX_BH_NOTORIETY 
  1545. 			phase_time = phase_time + get_frame_time() 
  1546. 			local pct = phase_time / 90 
  1547. 			local new_notoriety = pct * target_notoriety 
  1548. 			if new_notoriety > target_notoriety then 
  1549. 				new_notoriety = target_notoriety 
  1550. 			end 
  1551. 			notoriety_set_min("Brotherhood", new_notoriety) 
  1552. 			notoriety_set("Brotherhood", new_notoriety) 
  1553. 		end 
  1554. 	end 
  1555. end 
  1556.  
  1557. --[[ 
  1558. 	while(1) do 
  1559. 		thread_yield() 
  1560. 		delay(20) 
  1561. 		local new_bh_notoriety = notoriety_get("Brotherhood") + 1 
  1562. 		if new_bh_notoriety <= MAX_BH_NOTORIETY then 
  1563. 			notoriety_set_max("Brotherhood", new_bh_notoriety) 
  1564. 			notoriety_set("Brotherhood", new_bh_notoriety) 
  1565. 			notoriety_set_min("Brotherhood", new_bh_notoriety) 
  1566. 		end 
  1567. 	end 
  1568. end 
  1569. ]]-- 
  1570.  
  1571. function bh10_cleanup() 
  1572.  
  1573. 	damage_indicator_off(0) 
  1574.  
  1575. 	-- Cleanup mission here 
  1576.  
  1577. 	IN_COOP = coop_is_active() 
  1578.  
  1579. 	-- Allow follower recruiting 
  1580. 	party_set_recruitable(true) 
  1581.  
  1582. 	-- Start spawning peds again 
  1583. 	spawning_pedestrians(true) 
  1584.  
  1585. 	-- Remove damage callbacks for players 
  1586. 	turn_vulnerable(LOCAL_PLAYER) 
  1587. 	on_take_damage("", LOCAL_PLAYER) 
  1588. 	if (IN_COOP) then 
  1589. 		turn_vulnerable(REMOTE_PLAYER) 
  1590. 		on_take_damage("", REMOTE_PLAYER) 
  1591. 	end 
  1592.  
  1593. 	turn_vulnerable(LOCAL_PLAYER) 
  1594. 	if (IN_COOP) then 
  1595. 		turn_vulnerable(REMOTE_PLAYER) 
  1596. 	end 
  1597.  
  1598. 	bh10_lock_warehouse_doors(false)	 
  1599.  
  1600. 	npc_respawn_dist_reset() 
  1601.  
  1602. 	notoriety_force_no_spawn("Brotherhood", false) 
  1603.  
  1604. 	local TABLE_TRIGGERS =  
  1605. 	{	TRIGGER_TRIBAL_STAGING, TRIGGER_WAREHOUSE_ENTRANCE, TRIGGER_WAREHOUSE_ROOF, 
  1606. 		TRIGGER_LOW_GROUND, TRIGGER_HIGH_GROUND, TRIGGER_HIDING 
  1607. 	} 
  1608. 	for i, trigger in pairs(TABLE_TRIGGERS) do 
  1609. 		trigger_enable(trigger, false) 
  1610. 		on_trigger("",trigger) 
  1611. 		on_trigger_exit("",trigger)		 
  1612. 	end 
  1613. 	for i, trigger in pairs(TRIGGER_EXPLOIT_AREAS) do 
  1614. 		trigger_enable(trigger, false) 
  1615. 		on_trigger("",trigger) 
  1616. 		on_trigger_exit("",trigger)		 
  1617. 	end 
  1618. 	for i, trigger in pairs(TRIGGER_EXPLOIT_ENTRANCES) do 
  1619. 		trigger_enable(trigger, false) 
  1620. 		on_trigger("",trigger) 
  1621. 		on_trigger_exit("",trigger)		 
  1622. 	end 
  1623. 	for i, trigger in pairs(TRIGGER_EXPLOIT_EXITS) do 
  1624. 		trigger_enable(trigger, false) 
  1625. 		on_trigger("",trigger) 
  1626. 		on_trigger_exit("",trigger)		 
  1627. 	end 
  1628. 	for name,spawn_info in pairs(EXPLOIT_SPAWN_INFO) do 
  1629. 		for i,trigger in pairs(spawn_info["triggers"]) do 
  1630. 			trigger_enable(trigger, false) 
  1631. 			on_trigger("",trigger) 
  1632. 			on_trigger_exit("",trigger) 
  1633. 		end 
  1634. 	end 
  1635.  
  1636. 	trigger_enable(TRIGGER_HIGH_GROUND, false) 
  1637. 	on_trigger("",TRIGGER_HIGH_GROUND) 
  1638. 	on_trigger_exit("",TRIGGER_HIGH_GROUND) 
  1639.  
  1640. 	trigger_enable(TRIGGER_LOW_GROUND, false) 
  1641. 	on_trigger("",TRIGGER_LOW_GROUND) 
  1642. 	on_trigger_exit("",TRIGGER_LOW_GROUND) 
  1643.  
  1644. 	trigger_enable(TRIGGER_HIDING, false) 
  1645. 	on_trigger("",TRIGGER_HIDING) 
  1646. 	on_trigger_exit("",TRIGGER_HIDING) 
  1647.  
  1648. 	 
  1649.  
  1650. 	if THREAD_NOTORIETY ~= -1 then 
  1651. 		thread_kill(THREAD_NOTORIETY) 
  1652. 	end 
  1653. 	if THREAD_LIEUTENANTS ~= -1 then 
  1654. 		thread_kill(THREAD_LIEUTENANTS) 
  1655. 	end 
  1656. 	if THREAD_ROOF ~= -1 then 
  1657. 		thread_kill(THREAD_ROOF) 
  1658. 	end 
  1659. 	if THREAD_SAINTS_BACKUP ~= -1 then 
  1660. 		thread_kill(THREAD_SAINTS_BACKUP) 
  1661. 	end 
  1662.  
  1663. 	on_trigger("", TRIGGER_TRIBAL_STAGING) 
  1664. 	on_trigger("", TRIGGER_WAREHOUSE_ENTRANCE) 
  1665. 	on_trigger("", TRIGGER_WAREHOUSE_ROOF) 
  1666.  
  1667. 	for i, npc in pairs(TABLE_STANDARD_LIEUTENANTS) do 
  1668. 		on_death("", npc) 
  1669. 		marker_remove_npc(npc, SYNC_ALL) 
  1670. 	end 
  1671. 	for i, npc in pairs(TABLE_ROCKET_LIEUTENANTS) do 
  1672. 		on_death("", npc) 
  1673. 		marker_remove_npc(npc, SYNC_ALL) 
  1674. 	end 
  1675.  
  1676. 	mission_waypoint_remove(SYNC_ALL) 
  1677.  
  1678. 	for i, group in pairs(GROUP_SAINTS) do 
  1679. 		release_to_world(group) 
  1680. 	end 
  1681.  
  1682. 	bh10_stop_persona_overrides() 
  1683.  
  1684. end 
  1685.  
  1686. function bh10_success() 
  1687. 	-- Called when the mission has ended with success 
  1688. 	--bink_play_movie(CUTSCENE_OUT) 
  1689. end 
  1690.  
  1691. function bh10_debug_text(text, debug_type) 
  1692.  
  1693. 	if(DEBUG_TEXT_ENABLED[debug_type]) then 
  1694. 		--mission_help_table_nag(text) 
  1695. 		mission_debug(text, 10, debug_type) 
  1696. 	end 
  1697. --	delay(1.0) 
  1698.  
  1699. end 
  1700.