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