./hud_predator.lua

  1. local PREDATOR_MODE_OFF 			= 0 
  2. local PREDATOR_MODE_OVERHEAD 		= 1 
  3. local PREDATOR_MODE_GUIDED 		= 2 
  4. local PREDATOR_MODE_RC 				= 3 
  5.  
  6. local PREDATOR_MODE_RC_DESTRUCT	= 20 
  7.  
  8. local HUD_PREDATOR_BASE_STATIC_LEVEL = .05 
  9. local HUD_PREDATOR_MAX_STATIC_LEVEL = .3 
  10. ------------------------------------------------------------------------------- 
  11. -- Intialize Predator 
  12. ------------------------------------------------------------------------------- 
  13. local Hud_predator_static_alpha = 0 
  14. local Hud_predator_doc = -1 
  15. local Predator_static_thread_on = false 
  16. local Predator_thread = -1  
  17. local Hud_predator_static_tiles = {} 
  18. local Predator_cloned_objects 
  19. local Guided_cloned_objects 
  20. local Rc_cloned_objects 
  21. local Predator_mode = -1 
  22.  
  23. local Predator_hint_bar 
  24. local Predator_hint_bar_x 
  25. local Predator_hint_bar_y 
  26.  
  27. local Hud_predator_rc = {} 
  28. local Hud_predator_satellite = {} 
  29.  
  30. Hud_predator_rc_signal_txt_h = 0 
  31.  
  32. -- Guided missle stuff... 
  33. local Hud_predator_guided = {} 
  34. Hud_predator_guided.left_lines = {} 
  35. Hud_predator_guided.left_text = {} 
  36. Hud_predator_guided.right_lines = {} 
  37. Hud_predator_guided.right_text = {} 
  38. Hud_predator_guided.line_h = 0 
  39. Hud_predator_guided.alt_txt_h = 0 
  40. Hud_predator_guided.guided_right_grp_h = 0 
  41.  
  42.  
  43. local Predator_btn_hints = { 
  44. 	[PREDATOR_MODE_OFF] = false, 
  45. 	[PREDATOR_MODE_OVERHEAD] = { 
  46. 		{CTRL_BUTTON_LT, "SATELLITE_GUIDED_MISSILE", game_get_key_name_for_action("CBA_SWC_FIRE_GUIDED")}, 
  47. 		{CTRL_BUTTON_RT, "SATELLITE_FIRE_MISSILE", game_get_key_name_for_action("CBA_SWC_FIRE_FREE")}, 
  48. 		{CTRL_MENU_BUTTON_B, "SATELLITE_MODE_EXIT", game_get_key_name_for_action("CBA_SWC_EXIT_SATELLITE_MODE")}, 
  49. 	}, 
  50. 	[PREDATOR_MODE_GUIDED] = { 
  51. 		{CTRL_BUTTON_LT, "SATELLITE_SLOW_DOWN", game_get_key_name_for_action("CBA_SWC_MISSILE_DECELERATE")}, 
  52. 		{CTRL_BUTTON_RT, "SATLLITE_SPEED_UP", game_get_key_name_for_action("CBA_SWC_MISSILE_ACCELERATE")}, 
  53. 		{CTRL_MENU_BUTTON_B, "SATELLITE_EXIT_GUIDED_MODE", game_get_key_name_for_action("CBA_SWC_EXIT_SATELLITE_MODE")}, 
  54. 	}, 
  55. 	[PREDATOR_MODE_RC] = { 
  56. 		{CTRL_MENU_BUTTON_B, "SATELLITE_EXIT_RC_MODE", game_get_key_name_for_action("CBA_VDC_RC_ABORT")}, 
  57. 	}, 
  58. 	[PREDATOR_MODE_RC_DESTRUCT] = { 
  59. 		{CTRL_BUTTON_Y, "SATELLITE_RC_MODE_DESTRUCT", game_get_key_name_for_action("CBA_VDC_RC_SELF_DESTRUCT")}, 
  60. 		{CTRL_MENU_BUTTON_B, "SATELLITE_EXIT_RC_MODE", game_get_key_name_for_action("CBA_VDC_RC_ABORT")}, 
  61. 	}, 
  62. } 
  63.  
  64. --Hint bar coloring... 
  65. local PREDATOR_HINT_COLOR_OVERHEAD 	= 	{ R=183/255, G=211/255,B=141/255} 
  66. local PREDATOR_HINT_COLOR_NORMAL 	= 	{ R=158/255, G=211/255,B=78/255} 
  67.  
  68. local Predator_btn_hints_colors = { 
  69. 	[PREDATOR_MODE_OFF] 				= PREDATOR_HINT_COLOR_NORMAL, 
  70. 	[PREDATOR_MODE_OVERHEAD]		= PREDATOR_HINT_COLOR_OVERHEAD, 
  71. 	[PREDATOR_MODE_GUIDED] 			= PREDATOR_HINT_COLOR_OVERHEAD, 
  72. 	[PREDATOR_MODE_RC] 				= PREDATOR_HINT_COLOR_NORMAL, 
  73. 	[PREDATOR_MODE_RC_DESTRUCT] 	= PREDATOR_HINT_COLOR_NORMAL, 
  74. } 
  75.  
  76. --Target coloring... 
  77. local PREDATOR_TARGET_FRIENDLY	= 0  
  78. local PREDATOR_TARGET_HOSTILE		= 1 
  79. local PREDATOR_TARGET_NORMAL 		= 2 
  80.  
  81. local Predator_color_targets = { 
  82. 	--[PREDATOR_TARGET_NORMAL]			= 	{ R=0/255, G=142/255,	B=220/255}, 
  83. 	[PREDATOR_TARGET_NORMAL]			= 	{ R=0/255, G=142/255,	B=220/255}, 
  84. 	[PREDATOR_TARGET_HOSTILE]        = 	{ R=197/255, G=36/255,	B=0/255	}, 
  85. 	[PREDATOR_TARGET_FRIENDLY]       = 	{ R=136/255, G=211/255,	B=24/255}, 
  86. } 
  87.  
  88. local Hud_predator_input_tracker  
  89.  
  90. function hud_predator_init() 
  91. 	Hud_predator_doc = vint_document_find("hud_predator") 
  92. 	 
  93. 	-- subscribe to common inputs 
  94. 	Hud_predator_input_tracker = Vdo_input_tracker:new() 
  95. 	Hud_predator_input_tracker:add_input("map", "hud_predator_ignore_input", 50) 
  96. 	Hud_predator_input_tracker:subscribe(false) 
  97. 	 
  98. 	--Button Hints... 
  99. 	Predator_hint_bar = Vdo_hint_bar:new("btn_hints") 
  100. 	Predator_hint_bar_x, Predator_hint_bar_y = vint_get_property(Predator_hint_bar.handle, "anchor") 
  101. 	Predator_hint_bar:enable_text_shadow(true) 
  102. 	Predator_hint_bar:set_hints(Predator_btn_hints[PREDATOR_MODE_GUIDED]) 
  103. 	 
  104. 	Predator_cloned_objects = clone_table_create() 
  105. 	Rc_cloned_objects 		= clone_table_create() 
  106. 	Guided_cloned_objects 	= clone_table_create() 
  107.  
  108. 	--Setup guided interface... 
  109. 	Hud_predator_guided.main_h = vint_object_find("guided") 
  110. 	Hud_predator_guided.guided_lines_h = vint_object_find("guided_lines", Hud_predator_guided.main_h) 
  111. 	Hud_predator_guided.line_h = vint_object_find("guided_line_bmp", Hud_predator_guided.guided_lines_h) 
  112. 	Hud_predator_guided.alt_txt_h = vint_object_find("alt_txt", Hud_predator_guided.guided_lines_h) 
  113. 	Hud_predator_guided.guided_right_grp_h = vint_object_find("guided_right_grp") 
  114. 	vint_set_property(Hud_predator_guided.line_h, "visible", false) 
  115. 	vint_set_property(Hud_predator_guided.alt_txt_h, "visible", false) 
  116. 	 
  117. 	--Reticule... 
  118. 	Hud_predator_guided.reticule_h = vint_object_find("reticule_h", Hud_predator_guided.main_h) 
  119. 	Hud_predator_guided.reticule_friend_h = vint_object_find("reticule_friend_h", Hud_predator_guided.main_h) 
  120. 	 
  121. 	--Setup meter... 
  122. 	local rc_meter_bg_h = vint_object_find("rc_meter_bg") 
  123. 	local rc_meter_fill_h = vint_object_find("rc_meter_fill") 
  124. 	Hud_predator_rc.meter_bg_h = rc_meter_bg_h 
  125. 	Hud_predator_rc.meter_fill_h = rc_meter_fill_h 
  126. 	Hud_predator_rc.meter_max_scale_x, Hud_predator_rc.meter_max_scale_y = vint_get_property(rc_meter_bg_h, "scale") 
  127. 	Hud_predator_rc.meter_max_width, Hud_predator_rc.meter_max_height = element_get_actual_size(rc_meter_bg_h) 
  128. 	Hud_predator_rc.signal_txt_h = vint_object_find("signal_txt")	 
  129. 	 
  130. 	--Hide guided parts...	 
  131. 	vint_set_property(Hud_predator_guided.main_h, "visible", false) 
  132. 	 
  133. 	--Hide satellite parts... 
  134. 	Hud_predator_satellite.main_h = vint_object_find("satellite") 
  135. 	Hud_predator_satellite.dumb_ammo_count_txt_h 	= vint_object_find("dumb_ammo_count_txt", Hud_predator_satellite.main_h) 
  136. 		--Reticule... 
  137. 	Hud_predator_satellite.reticule_h = vint_object_find("reticule_h", Hud_predator_satellite.main_h) 
  138. 	Hud_predator_satellite.reticule_friend_h = vint_object_find("reticule_friend_h", Hud_predator_satellite.main_h) 
  139. 	vint_set_property(Hud_predator_satellite.main_h, "visible", false) 
  140. 	 
  141. 	--Hide RC parts... 
  142. 	Hud_predator_rc.main_h = vint_object_find("rc_car") 
  143. 	vint_set_property(Hud_predator_rc.main_h, "visible", false) 
  144. 	 
  145. 	--All parts are setup. 
  146. 	--Now subscribe to data and get the show on the road. 
  147. 	vint_dataitem_add_subscription("sr2_local_player_satellite_weapon", "update", "hud_predator_update") 
  148. 	vint_dataitem_add_subscription("game_paused_item", "update", "hud_predator_game_paused")	--to check if game is paused... 
  149. end 
  150.  
  151. function hud_predator_cleanup() 
  152. 	Predator_static_thread_on = false 
  153. end 
  154.  
  155.  
  156. ----------------------------------------------------------------------------------------- 
  157. -- Update from C++ 
  158. ----------------------------------------------------------------------------------------- 
  159. function hud_predator_update(di_h) 
  160. 	local satellite_mode, param1, param2, param3, param4, param5, param6, param7, param8, param9 = vint_dataitem_get(di_h) 
  161.  
  162. 	if satellite_mode == PREDATOR_MODE_OFF then 
  163. 		--Turn off anything... 
  164. 		if Predator_mode ~= PREDATOR_MODE_OFF then 
  165. 			hud_predator_satellite_hide() 
  166. 			hud_predator_guided_hide()		--hide guided missile stuff 
  167. 			hud_predator_rc_hide() 
  168. 			 
  169. 			hud_predator_static_stop() 
  170. 			hud_predator_set_hints(satellite_mode) 
  171. 			hud_predator_vignette_show(false) 
  172. 			Predator_mode = PREDATOR_MODE_OFF 
  173. 		end 
  174. 		Hud_predator_input_tracker:subscribe(false) 
  175. 	elseif satellite_mode == PREDATOR_MODE_OVERHEAD then 
  176. 	 
  177. 		if Predator_mode ~= PREDATOR_MODE_OVERHEAD then 
  178. 			hud_predator_satellite_hide()	--clear out satellite elements 
  179. 			hud_predator_guided_hide()		--hide guided missile stuff 
  180. 			hud_predator_rc_hide()			--hide rc 
  181. 			hud_predator_static_stop()		--stop static 
  182. 			 
  183. 		 
  184. 			hud_predator_satellite_show()	--show satellite elements 
  185. 			hud_predator_static_start()	--restart static... 
  186. 			hud_predator_set_hints(satellite_mode) 
  187. 			hud_predator_vignette_show(true) 
  188. 			 
  189. 			Hud_predator_input_tracker:subscribe(true) 
  190. 			Predator_mode = PREDATOR_MODE_OVERHEAD 
  191. 		end 
  192. 		 
  193. 		hud_predator_satelite_update(param1, param2, param3, param4, param5, param6, param7, param8, param9) 
  194. 	elseif satellite_mode == PREDATOR_MODE_GUIDED then 
  195. 		if Predator_mode ~= PREDATOR_MODE_GUIDED then 
  196. 			hud_predator_satellite_hide() 
  197. 			hud_predator_rc_hide() 
  198. 			hud_predator_static_stop() 
  199. 			hud_predator_set_hints(satellite_mode) 
  200. 			hud_predator_vignette_show(true) 
  201. 			 
  202. 			hud_predator_guided_show() 
  203. 			 
  204. 			Hud_predator_input_tracker:subscribe(true) 
  205. 			Predator_mode = PREDATOR_MODE_GUIDED 
  206. 		end 
  207. 		hud_predator_guided_update(param1, param2, param3, param4, param5, param6, param7, param8, param9) 
  208. 	elseif satellite_mode == PREDATOR_MODE_RC then 
  209. 	 
  210. 		 
  211. 		if Predator_mode ~= PREDATOR_MODE_RC then 
  212. 			hud_predator_rc_show() 
  213. 			hud_predator_static_start() 
  214. 			 
  215. 			--Determine if we are gonna show the health or not... 
  216. 			local show_help = param5 
  217. 			local show_self_destruct_hint = param6 
  218.  
  219. 			if show_help ~= 0 then 
  220. 				if show_self_destruct_hint ~= 0 then 
  221. 					hud_predator_set_hints(PREDATOR_MODE_RC_DESTRUCT) 
  222. 				else 
  223. 					--Set hints.. 
  224. 					hud_predator_set_hints(satellite_mode) 
  225. 				end 
  226. 			else  
  227. 				--Hide hints... 
  228. 				hud_predator_set_hints(PREDATOR_MODE_OFF) 
  229. 			end 
  230. 			 
  231. 			hud_predator_vignette_show(true) 
  232. 			 
  233. 			Hud_predator_input_tracker:subscribe(true) 
  234. 			Predator_mode = PREDATOR_MODE_RC 
  235. 		end 
  236. 		--speed, Max Speed, Acceleration , Signal Strength % 
  237. 		hud_predator_rc_update(param1, param2, param3, param4) 
  238. 	end 
  239. 	 
  240. 	--Upda 
  241. 	--[[ 
  242. 			VINT_PROP_TYPE_INT,				 
  243. 			// Satellite mode 0..3 
  244. 			// 0 - off 
  245. 			// 1 - satellite overhead 
  246. 			// 2 - satellite guided 
  247. 			// 3 - rc gun 
  248.  
  249. 			VINT_PROP_TYPE_FLOAT, 
  250. 			// Satellite Drone Overhead		- Static % 
  251. 			// Satellite Drone Missile		- Static % 
  252. 			// RC Gun						- Speed 
  253.  
  254. 			VINT_PROP_TYPE_FLOAT, 
  255. 			// Satellite Drone Overhead		- Angle heading in radians 
  256. 			// Satellite Drone Missile		- Bank angle 
  257. 			// RC Gun						- Max Speed 
  258.  
  259. 			VINT_PROP_TYPE_FLOAT, 
  260. 			// Satellite Drone Overhead		- Distance to ground along camera 
  261. 			// Satellite Drone Missile		- Altitude 
  262. 			// RC Gun						- Acceleration from 0 to 1 
  263.  
  264. 			VINT_PROP_TYPE_FLOAT, 
  265. 			// Satellite Drone Overhead		- Time to reload % (0=ready) 
  266. 			// Satellite Drone Missile		- Target info (0=nothing, 1=bogey, 2 = friendly) 
  267. 			// RC Gun						- Signal Strength % 
  268.  
  269. 			VINT_PROP_TYPE_FLOAT, 
  270. 			// Satellite Drone Overhead		- Target info (0=nothing, 1=bogey, 2 = friendly) 
  271. 			// Satellite Drone Missile		- n/a 
  272. 			// RC Gun						- 		Show exit Rc mode (bool) 
  273.  
  274. 			VINT_PROP_TYPE_FLOAT, 
  275. 			// Satellite Drone Overhead		- Outer Circle X (from -1 to 1) 
  276. 			// Satellite Drone Missile		- n/a 
  277. 			// RC Gun						- is self destruct...(bool) 
  278.  
  279. 			VINT_PROP_TYPE_FLOAT, 
  280. 			// Satellite Drone Overhead		- Outer Circle Y (from -1 to 1) 
  281. 			// Satellite Drone Missile		- n/a 
  282. 			// RC Gun						- n/a 
  283.  
  284. 			VINT_PROP_TYPE_INT, 
  285. 			// Satellite Drone Overhead		- Dumbfire ammo	 
  286. 			// Satellite Drone Missile		- n/a 
  287. 			// RC Gun						- n/a 
  288.  
  289. 			VINT_PROP_TYPE_INT, 
  290. 			// Satellite Drone Overhead		- Guided ammo 
  291. 			// Satellite Drone Missile		- n/a 
  292. 			// RC Gun						- n/a 
  293. 		 
  294. 	]] 
  295. end 
  296.  
  297. local HUD_PREDATOR_OVERHEAD_RING_RADIUS = 100 
  298.  
  299. local HUD_PREADTOR_GUIDED_LINE_SPACING 	= 20		--spacing between lines... 
  300. local HUD_PREADTOR_GUIDED_RANGE			 	= 16		--Range of numbers 
  301. local HUD_PREADTOR_GUIDED_MAX_ALT		 	= 180		--Maximum altitude 
  302.  
  303. function hud_predator_guided_show() 
  304. 	--show guided hud... 
  305. 	vint_set_property(Hud_predator_guided.main_h, "visible", true) 
  306. 	 
  307. 	local inner_ring_h = vint_object_create("inner_ring", "group", Hud_predator_guided.main_h) 
  308. 	local inner_ring_bmp = vint_object_find("inner_ring_bmp", Hud_predator_guided.main_h) 
  309. 	vint_set_property(inner_ring_bmp, "visible", false) 
  310.  
  311. 	local item_count = 8 
  312. 	local rotation_spacing = PI2/item_count 
  313. 	for i = 0, item_count - 1 do  
  314. 		local ring_h = vint_object_clone(inner_ring_bmp) 
  315. 		vint_object_set_parent(ring_h, inner_ring_h) 
  316. 		vint_set_property(ring_h, "rotation", rotation_spacing * i ) 
  317. 		vint_set_property(ring_h, "visible", true) 
  318. 		clone_table_add(Guided_cloned_objects, ring_h) 
  319. 	end 
  320.  
  321. 	Hud_predator_guided.inner_ring_h = inner_ring_h 
  322. 	 
  323. 	--Add our created group to clone table for cleanup. 
  324. 	clone_table_add(Guided_cloned_objects, inner_ring_h) 
  325. end 
  326.  
  327. function hud_predator_guided_hide() 
  328.  
  329. 	--hide items... 
  330. 		vint_set_property(Hud_predator_guided.main_h, "visible", false) 
  331.  
  332. 	--delete everything out of range 
  333. 	for i = -HUD_PREADTOR_GUIDED_RANGE, HUD_PREADTOR_GUIDED_MAX_ALT do 
  334. 		if Hud_predator_guided.left_lines[i] ~= nil then 
  335. 			vint_object_destroy(Hud_predator_guided.left_lines[i]) 
  336. 			Hud_predator_guided.left_lines[i] = nil 
  337. 			 
  338. 			vint_object_destroy(Hud_predator_guided.right_lines[i]) 
  339. 			Hud_predator_guided.right_lines[i] = nil 
  340. 		end 
  341. 		if Hud_predator_guided.left_text[i] ~= nil then 
  342. 			vint_object_destroy(Hud_predator_guided.left_text[i]) 
  343. 			Hud_predator_guided.left_text[i] = nil 
  344. 			 
  345. 			vint_object_destroy(Hud_predator_guided.right_text[i]) 
  346. 			Hud_predator_guided.right_text[i] = nil 
  347. 		end 
  348. 	end 
  349.  
  350. 	clone_table_clear(Guided_cloned_objects) 
  351. end 
  352.  
  353. function hud_predator_guided_update(static_pct, bank_angle, altitude, target_info) 
  354.  
  355. 	--adjust angles of our elements... 
  356. 	vint_set_property(Hud_predator_guided.main_h, "rotation", -bank_angle) 
  357. 	vint_set_property(Hud_predator_guided.inner_ring_h, "rotation", -bank_angle) 
  358. 	 
  359. 	--Arrange elements on screen... 
  360. 	altitude = (altitude * .1) 
  361. 	local altitude_rounded = floor(altitude + .5) 
  362. 	local half_range = floor(HUD_PREADTOR_GUIDED_RANGE *.5) 
  363. 	local lines_lower_limit = altitude_rounded - half_range 
  364. 	local lines_upper_limit = altitude_rounded + half_range 
  365. 	 
  366. 	local total_lines_on_screen = 0 
  367. 	for i = -HUD_PREADTOR_GUIDED_RANGE, HUD_PREADTOR_GUIDED_MAX_ALT do 
  368. 		if i >= lines_lower_limit and i <= lines_upper_limit then 
  369. 			if Hud_predator_guided.left_lines[i] == nil then 
  370. 				local left_line_h = vint_object_clone(Hud_predator_guided.line_h) 
  371. 				local x, y = vint_get_property(Hud_predator_guided.line_h, "anchor") 
  372. 				 
  373. 				local right_line_h = vint_object_clone(Hud_predator_guided.line_h) 
  374. 				vint_object_set_parent(right_line_h, Hud_predator_guided.guided_right_grp_h) 
  375. 				 
  376. 				y = HUD_PREADTOR_GUIDED_LINE_SPACING  * i 
  377. 				 
  378. 				if i % 5 == 0 then 
  379. 					element_set_actual_size(left_line_h, 35, 2) 
  380. 					element_set_actual_size(right_line_h, 35, 2) 
  381. 					local text_h = vint_object_clone(Hud_predator_guided.alt_txt_h) 
  382. 					local altitude_text = i * 10 
  383. 					vint_set_property(text_h, "visible", true) 
  384. 					vint_set_property(text_h, "text_tag", altitude_text) 
  385. 					vint_set_property(text_h, "anchor", x - 7, y + 1) 
  386. 					Hud_predator_guided.left_text[i] = text_h 
  387. 					 
  388. 					local text_h = vint_object_clone(Hud_predator_guided.alt_txt_h) 
  389. 					vint_object_set_parent(text_h, Hud_predator_guided.guided_right_grp_h)  
  390. 					vint_set_property(text_h, "visible", true) 
  391. 					vint_set_property(text_h, "text_tag", altitude_text) 
  392. 					vint_set_property(text_h, "auto_offset", "w") 
  393. 					vint_set_property(text_h, "anchor", x + 7, y) 
  394. 					Hud_predator_guided.right_text[i] = text_h 
  395. 				end 
  396. 				 
  397. 				vint_set_property(left_line_h, "anchor", x, y) 
  398. 				vint_set_property(left_line_h, "visible", true) 
  399. 				Hud_predator_guided.left_lines[i] = left_line_h 
  400. 				 
  401. 				vint_set_property(right_line_h, "visible", true) 
  402. 				vint_set_property(right_line_h, "anchor", x, y) 
  403. 				vint_set_property(right_line_h, "auto_offset", "e") 
  404. 	 
  405. 				Hud_predator_guided.right_lines[i] = right_line_h 
  406. 			end 
  407. 			total_lines_on_screen = total_lines_on_screen + 1 
  408. 		else 
  409. 			--delete everything out of range... 
  410. 			if Hud_predator_guided.left_lines[i] ~= nil then 
  411. 				vint_object_destroy(Hud_predator_guided.left_lines[i]) 
  412. 				Hud_predator_guided.left_lines[i] = nil 
  413. 				 
  414. 				vint_object_destroy(Hud_predator_guided.right_lines[i]) 
  415. 				Hud_predator_guided.right_lines[i] = nil 
  416. 			end 
  417. 			if Hud_predator_guided.left_text[i] ~= nil then 
  418. 				vint_object_destroy(Hud_predator_guided.left_text[i]) 
  419. 				Hud_predator_guided.left_text[i] = nil 
  420. 				 
  421. 				vint_object_destroy(Hud_predator_guided.right_text[i]) 
  422. 				Hud_predator_guided.right_text[i] = nil 
  423. 			end 
  424. 		end 
  425. 	end 
  426. 	 
  427. 	--set global group of guided missle lines ... 
  428. 	local y =  -(altitude * HUD_PREADTOR_GUIDED_LINE_SPACING) + ((HUD_PREADTOR_GUIDED_RANGE * HUD_PREADTOR_GUIDED_LINE_SPACING)*.5) 
  429. 	vint_set_property(Hud_predator_guided.guided_lines_h, "anchor", 0, y) 
  430. 	 
  431. 	if target_info ~= Hud_predator_guided.target_info then 
  432. 		hud_predator_set_color(Hud_predator_guided.main_h, target_info) 
  433. 		Hud_predator_guided.target_info = target_info 
  434. 	end 
  435. 	 
  436. 	--set static percent... 
  437. 	hud_predator_static_set(static_pct) 
  438. end 
  439.  
  440. 	 
  441. function hud_predator_satelite_update(static_pct, angle_heading_radians, distance_to_ground, time_to_reload_pct, target_info, outer_circle_x, outer_circle_y, dumbfire_ammo, guided_ammo) 
  442. 	--Static 
  443.  
  444. 	--Hud_predator_static_alpha = static_pct + .2 
  445. 	--Directional Indicator 
  446.  
  447. 	--Apply rotation... 
  448. 	vint_set_property(Hud_predator_satellite.inner_ring_h, "rotation", angle_heading_radians) 
  449. 	 
  450. 	local inner_ring_direction_bmp_h = vint_object_find("inner_ring_direction_bmp") 
  451. 	vint_set_property(Hud_predator_satellite.inner_ring_h, "rotation", angle_heading_radians) 
  452. 	vint_set_property(Hud_predator_satellite.outer_ring_h, "rotation", -angle_heading_radians) 
  453. 	vint_set_property(inner_ring_direction_bmp_h, "rotation", angle_heading_radians) 
  454. 	 
  455. 	local satelite_degrees_txt_h = vint_object_find("satelite_degrees_txt") 
  456. 	local ssatelite_degrees_grp_h = vint_object_find("satelite_degrees_grp") 
  457. 	vint_set_property(satelite_degrees_txt_h, "rotation", -angle_heading_radians) 
  458. 	vint_set_property(ssatelite_degrees_grp_h, "rotation", angle_heading_radians) 
  459. 	local degrees = floor( (angle_heading_radians / DEG_TO_RAD) ) 
  460. 	vint_set_property(satelite_degrees_txt_h, "text_tag", degrees ) 
  461. 	 
  462. 	--Outer Ring Indicator... 
  463. 	local x = HUD_PREDATOR_OVERHEAD_RING_RADIUS * outer_circle_x 
  464. 	local y = HUD_PREDATOR_OVERHEAD_RING_RADIUS * outer_circle_y 
  465. 	vint_set_property(Hud_predator_satellite.outer_ring_h, "anchor", x, y) 
  466. 	 
  467. 	--Set color based on target info...	 
  468. 	if target_info ~= Hud_predator_satellite.target_info then 
  469. 		hud_predator_set_color(Hud_predator_satellite.main_h, target_info) 
  470. 		Hud_predator_satellite.target_info = target_info 
  471. 	end 
  472. 	 
  473. 	--ammo is the sum of dumbfire and guided 
  474. 	local ammo = dumbfire_ammo + guided_ammo 
  475. 	 
  476. 	if ammo ~= Hud_predator_satellite.ammo then 
  477. 		if ammo < 0 then 
  478. 			vint_set_property(Hud_predator_satellite.dumb_ammo_count_txt_h, "text_tag", "[image:ui_text_infinity]") 
  479. 		else 
  480. 			vint_set_property(Hud_predator_satellite.dumb_ammo_count_txt_h, "text_tag", ammo) 
  481. 		end 
  482. 		Hud_predator_satellite.ammo = ammo 
  483. 	end 
  484. 	 
  485. 	hud_predator_static_set(static_pct) 
  486. end 
  487.  
  488. ----------------------------------------------------------------------------------------- 
  489. -- Builds satellite elements 
  490. -- 
  491. function hud_predator_satellite_show() 
  492. 	local satellite_h = vint_object_find("satellite") 
  493. 	 
  494. 	local inner_ring_h = vint_object_create("inner_ring", "group", satellite_h) 
  495. 	local outer_ring_h = vint_object_create("outer_ring", "group", satellite_h) 
  496. 	 
  497. 	local inner_ring_bmp = vint_object_find("inner_ring_bmp", satellite_h) 
  498. 	local outer_ring_bmp = vint_object_find("outer_ring_bmp", satellite_h) 
  499. 	 
  500. 	vint_set_property(inner_ring_bmp, "visible", false) 
  501. 	vint_set_property(outer_ring_bmp, "visible", false) 
  502. 	 
  503. 	local item_count = 9 
  504. 	local rotation_spacing = PI2/item_count 
  505. 	for i = 0, item_count - 1 do  
  506. 		local ring_h = vint_object_clone(outer_ring_bmp) 
  507. 		vint_object_set_parent(ring_h, outer_ring_h) 
  508. 		vint_set_property(ring_h, "rotation", rotation_spacing * i ) 
  509. 		vint_set_property(ring_h, "visible", true) 
  510. 		clone_table_add(Predator_cloned_objects, ring_h) 
  511. 	end 
  512. 	 
  513. 	local item_count = 8 
  514. 	local rotation_spacing = PI2/item_count 
  515. 	for i = 0, item_count - 1 do  
  516. 		local ring_h = vint_object_clone(inner_ring_bmp) 
  517. 		vint_object_set_parent(ring_h, inner_ring_h) 
  518. 		vint_set_property(ring_h, "rotation", rotation_spacing * i ) 
  519. 		vint_set_property(ring_h, "visible", true) 
  520. 		clone_table_add(Predator_cloned_objects, ring_h) 
  521. 	end 
  522. 	 
  523. 	--Add our created groups to clone table for cleanup. 
  524. 	clone_table_add(Guided_cloned_objects, inner_ring_h) 
  525. 	clone_table_add(Guided_cloned_objects, outer_ring_h) 
  526. 	 
  527. 	--Store satellite stuff... 
  528. 	Hud_predator_satellite.inner_ring_h = inner_ring_h 
  529. 	Hud_predator_satellite.outer_ring_h = outer_ring_h 
  530.  
  531. 	--Show Hud... 
  532. 	local satellite_h = vint_object_find("satellite") 
  533. 	vint_set_property(satellite_h, "visible", true) 
  534. end 
  535.  
  536. ----------------------------------------------------------------------------------------- 
  537. -- Destroys Satelite elements and hides any remaining elements. 
  538. -- 
  539. function hud_predator_satellite_hide() 
  540. 	clone_table_clear(Predator_cloned_objects) 
  541. 	 
  542. 	--hide hud... 
  543. 	local satellite_h = vint_object_find("satellite") 
  544. 	vint_set_property(satellite_h, "visible", false) 
  545. end 
  546.  
  547. ----------------------------------------------------------------------------------------- 
  548. -- Builds RC Elements 
  549. -- 
  550. function hud_predator_rc_show() 
  551. 	local corner_ne_h = vint_object_find("corner_ne") 
  552. 	local item_count = 3 
  553. 	local rotation_spacing = PI/2 
  554. 	for i = 1, item_count do  
  555. 		local corner_h = vint_object_clone(corner_ne_h) 
  556. 		vint_set_property(corner_h, "rotation", rotation_spacing * i ) 
  557. 		vint_set_property(corner_h, "visible", true) 
  558. 		clone_table_add(Rc_cloned_objects, corner_h) 
  559. 	end 
  560. 	 
  561. 	--Show the base element... 
  562. 	vint_set_property(Hud_predator_rc.main_h, "visible", true) 
  563. end 
  564.  
  565. ----------------------------------------------------------------------------------------- 
  566. -- STATIC! 
  567. ----------------------------------------------------------------------------------------- 
  568.  
  569.  
  570. ----------------------------------------------------------------------------------------- 
  571. -- Builds RC Elements 
  572. ----------------------------------------------------------------------------------------- 
  573. function hud_predator_rc_hide() 
  574. 	--Hide all parts 
  575. 	vint_set_property(Hud_predator_rc.main_h, "visible", false) 
  576. 	 
  577. 	clone_table_clear(Rc_cloned_objects) 
  578. end 
  579.  
  580. --Updats RC... 
  581. function hud_predator_rc_update(speed, speed_max, accelleration, signal_strength_pct) 
  582. 	local pct = signal_strength_pct  
  583. 	pct = limit(pct, 0, 1) 
  584. 	local pct_invert = 1.0 - pct 
  585. 	local x_scale = Hud_predator_rc.meter_max_scale_x * (pct) 
  586. 	vint_set_property(Hud_predator_rc.meter_fill_h, "scale", x_scale, Hud_predator_rc.meter_max_scale_y) 
  587. 	 
  588. 	local signal_strength_pct_txt = floor(pct * 100) 
  589. 	 
  590. 	local first_digit = "0." 
  591. 	local second_digit = signal_strength_pct_txt 
  592. 	 
  593. 	if signal_strength_pct_txt < 10 then 
  594. 		second_digit = "0" .. signal_strength_pct_txt 
  595. 	end 
  596.  
  597. 	local values = { [0] = first_digit .. second_digit } 
  598. 	local signal_strength_pct_txt = vint_insert_values_in_string("SATELLITE_RC_SIGNAL_STRENGTH", values)	 
  599. 	vint_set_property(Hud_predator_rc.signal_txt_h, "text_tag", signal_strength_pct_txt) 
  600. 	 
  601. 	local static_pct = HUD_PREDATOR_BASE_STATIC_LEVEL + (pct_invert * (HUD_PREDATOR_MAX_STATIC_LEVEL - HUD_PREDATOR_BASE_STATIC_LEVEL)) 
  602. 	hud_predator_static_set(static_pct) 
  603. end 
  604.  
  605.  
  606. ----------------------------------------------------------------------------------------- 
  607. -- STATIC! 
  608. ----------------------------------------------------------------------------------------- 
  609.  
  610. ----------------------------------------------------------------------------------------- 
  611. --Starts up static... 
  612. -- 
  613. function hud_predator_static_start() 
  614. 	--Start Static... 
  615. 	if Predator_static_thread_on == false then 
  616. 		Predator_static_thread_on = true 
  617. 		Predator_thread = thread_new("hud_predator_static_thread") 
  618. 	end 
  619. end 
  620.  
  621. ----------------------------------------------------------------------------------------- 
  622. -- Stops static... 
  623. -- 
  624. function hud_predator_static_stop() 
  625. 	Predator_static_thread_on = false 
  626. 	thread_kill(Predator_thread) 
  627. 	 
  628. 	--Destroy all tiles 
  629. 	for idx, val in pairs(Hud_predator_static_tiles) do 
  630. 		vint_object_destroy(val) 
  631. 	end 
  632. end 
  633.  
  634. --Static thread for predator drone... 
  635. function hud_predator_static_thread() 
  636. 	while Predator_static_thread_on do 
  637. 		hud_predator_static_fill_frame() 
  638. 		thread_yield() 
  639. 	end 
  640. end 
  641.  
  642. function hud_predator_static_set(pct) 
  643. 	Hud_predator_static_alpha = pct 
  644. end 
  645.  
  646. function hud_predator_static_fill_frame() 
  647. 	--grid size 
  648. 	local tiles_width = 9 
  649. 	local tiles_height = 7 
  650. 	local tile_size = 190 
  651. 	local tile_size_varient = 30 
  652. 	local tile_uv_varient = 30 
  653. 	 
  654. 	for idx, val in pairs(Hud_predator_static_tiles) do 
  655. 		vint_object_destroy(val) 
  656. 	end 
  657. 	 
  658. 	Hud_predator_static_tiles = {} 
  659. 	local safe_frame_h = vint_object_find("safe_frame") 
  660. 	local static_h = vint_object_create("static_grp", "group", safe_frame_h) 
  661. 	vint_set_property(static_h, "anchor", rand_int(-25, -10), rand_int(-25, -10)) 
  662. 	vint_set_property(static_h, "alpha", Hud_predator_static_alpha) --vint_object_create("static_grp", "group", safe_frame_h) 
  663.  
  664. 	Hud_predator_static_tiles.static_h = static_h 
  665. 	local tile_count = 0 
  666. 	local cur_y = 0 
  667. 	local tile_size_base = tile_size 
  668. 	for tile_y = 0, tiles_height - 1 do 
  669. 		tile_size = tile_size_base - rand_int(0, tile_size_varient) 
  670. 		for tile_x = 0, tiles_width - 1 do  
  671. 			local bitmap_h = vint_object_create("static_image", "bitmap", static_h) 
  672. 			vint_set_property(bitmap_h, "image", "ui_static") 
  673. 			 
  674. 			--Change UV Mapping 
  675. 			local uv_x_varient = rand_int(0, tile_uv_varient) 
  676. 			local uv_y_varient = rand_int(0, tile_uv_varient) 
  677. 			vint_set_property(bitmap_h, "source_nw", uv_x_varient, uv_y_varient) 
  678. 			vint_set_property(bitmap_h, "source_se", tile_size , tile_size) 
  679. 			 
  680. 			--position... 
  681. 			local x = tile_x * tile_size 
  682. 			local y = cur_y  
  683. 			 
  684. 			--Flip UV 
  685. 			local flip_x = rand_int(0,1) 
  686. 			local flip_y = rand_int(0,1) 
  687. 			if flip_x == 0 then 
  688. 				flip_x = -1 
  689. 				x = x + tile_size 
  690. 			end 
  691. 			if flip_y == 0 then 
  692. 				flip_y = -1 
  693. 				y = y + tile_size 
  694. 			end 
  695. 			 
  696. 			 
  697. 			vint_set_property(bitmap_h, "anchor", x, y) 
  698. 			vint_set_property(bitmap_h, "scale", flip_x, flip_y) 
  699. 			Hud_predator_static_tiles[tile_count] = bitmap_h 
  700. 			tile_count = tile_count + 1 
  701. 		end 
  702. 		--Increment y positon... 
  703. 		cur_y = cur_y + tile_size  
  704. 	end 
  705. end 
  706.  
  707. -- Changes position of retecules in screen space 
  708. -- (x, y) screen space values(pre-translated for screen resolution) 
  709. -- Update call from hud.lua 
  710. function hud_predator_change_position(x, y) 
  711. 	vint_set_property(Hud_predator_guided.main_h, "anchor", x, y) 
  712. 	vint_set_property(Hud_predator_satellite.main_h, "anchor", x, y) 
  713. 	vint_set_property(Hud_predator_rc.main_h, "anchor", x, y) 
  714. end 
  715.  
  716. function hud_predator_set_hints(mode) 
  717. 	Predator_hint_bar:set_hints(Predator_btn_hints[mode]) 
  718. 	--Predator_hint_bar:set_color(Predator_btn_hints_colors[mode])		--DO not color hints, just looks bad...(JMH 7/11/2011) 
  719. 	local width, height = Predator_hint_bar:get_size() 
  720. 	local x = Predator_hint_bar_x - (width/2) 
  721. 	vint_set_property(Predator_hint_bar.handle, "anchor", x, Predator_hint_bar_y) 
  722. 	 
  723. 	Predator_hint_bar:enable_text_shadow(true) 
  724. end 
  725.  
  726. ------------------------------------------------------------------------------- 
  727. -- Sets the color of an element based on target info. 
  728. -- 
  729. function hud_predator_set_color(item_h, target_info) 
  730. 	local color_r = Predator_color_targets[target_info].R 
  731. 	local color_g = Predator_color_targets[target_info].G 
  732. 	local color_b = Predator_color_targets[target_info].B 
  733. 	vint_set_property(item_h, "tint", color_r, color_g, color_b) 
  734. 	 
  735. 	if target_info == PREDATOR_TARGET_HOSTILE or target_info == PREDATOR_TARGET_NORMAL then 
  736. 		vint_set_property(Hud_predator_guided.reticule_h, 			"visible", true) 
  737. 		vint_set_property(Hud_predator_guided.reticule_friend_h, "visible", false) 
  738. 		 
  739. 		vint_set_property(Hud_predator_satellite.reticule_h, 			"visible", true) 
  740. 		vint_set_property(Hud_predator_satellite.reticule_friend_h, "visible", false) 
  741. 	else 
  742. 		vint_set_property(Hud_predator_guided.reticule_h, 			"visible", false) 
  743. 		vint_set_property(Hud_predator_guided.reticule_friend_h, "visible", true)	 
  744. 		 
  745. 		vint_set_property(Hud_predator_satellite.reticule_h, 			"visible", false) 
  746. 		vint_set_property(Hud_predator_satellite.reticule_friend_h, "visible", true) 
  747. 	end 
  748. end 
  749.  
  750. function hud_predator_vignette_show(is_visible) 
  751. 	local h = vint_object_find("vignette") 
  752. 	vint_set_property(h, "visible", is_visible) 
  753. end 
  754.  
  755.  
  756. ------------------------------------------------------------------------------- 
  757. -- When the game is paused we will hide certain elements of the screen... 
  758. -- 
  759. function hud_predator_game_paused(di_h) 
  760. 	local is_paused = vint_dataitem_get(di_h) 
  761. 	local alpha = 1 
  762. 	if is_paused == true then 
  763. 		alpha = 0 
  764. 	end 
  765. 	--Using alpha here so we don't overlap with anything that the hud is normally doing... 
  766. 	if Predator_mode == PREDATOR_MODE_RC then		 
  767. 		vint_set_property(Hud_predator_rc.main_h, "alpha", alpha) 
  768. 	elseif Predator_mode == PREDATOR_MODE_GUIDED then		 
  769. 		vint_set_property(Hud_predator_guided.main_h, "alpha", alpha) 
  770. 	elseif Predator_mode == PREDATOR_MODE_OVERHEAD then 
  771. 		vint_set_property(Hud_predator_satellite.main_h, "alpha", alpha) 
  772. 	end 
  773. 	if Predator_mode ~= PREDATOR_MODE_OFF then 
  774. 		Predator_hint_bar:set_alpha(alpha) 
  775. 	end 
  776. end 
  777.  
  778.  
  779.  
  780.  
  781. ------------------------------------------------------------------------------- 
  782. -- Ignore any unwanted input... 
  783. ------------------------------------------------------------------------------- 
  784. function hud_predator_ignore_input(event) 
  785. end 
  786.  
  787. function clone_table_create() 
  788. 	local clone_table = {} 
  789. 	clone_table.item_count = 0 
  790. 	return clone_table 
  791. end 
  792.  
  793. function clone_table_add(clone_table, handle_h) 
  794. 	clone_table[clone_table.item_count] = handle_h 
  795. 	clone_table.item_count = clone_table.item_count + 1 
  796. end 
  797.  
  798. function clone_table_clear(clone_table) 
  799. 	for i = 0, clone_table.item_count - 1 do 
  800. 		vint_object_destroy(clone_table[i]) 
  801. 	end 
  802. 	clone_table.item_count = 0 
  803. end