./hud_diversion.lua

  1. -- vint_meter_type 
  2. local HDM_NONE                = -1 
  3. local HDM_DISTANCE            = 0 
  4. local HDM_XY                  = 1 
  5. local HDM_COUNTER             = 2 
  6. local HDM_TIME                = 3 
  7. local HDM_PERCENT             = 4 
  8. local HDM_TEXT                = 5 
  9. local HDM_QTE                	= 6 
  10.  
  11. -- diversion_status 
  12. local HDIS_IN_PROGRESS              = 0 
  13. local HDIS_CANCELLED                = 1 
  14. local HDIS_COMPLETE                 = 2 
  15. local HDIS_COMPLETE_DO_NOT_SHOW_HUD = 3 
  16.  
  17. -- Message Type 
  18. local HDT_NONE	= -1 
  19.  
  20. -- Challenge Diversion Type 
  21. local DT_CHALLENGE = 1 
  22.  
  23. -- Invalid enums 
  24. local STATS_INVALID = -1 
  25. local DT_NONE = -1 
  26.  
  27. local DIVERSION_ANCHOR_OFFSET = 60 
  28. local DIVERSION_MAX_STEPS = 3 
  29. local DIVERSION_METER_PCT_FUDGE = 0.02 
  30. local DIVERSION_MAX = 5 
  31. local DIVERSIONS_MAX_FIRE = 14 
  32.  
  33. local CHAL_TITLE_X = 100 
  34. local CHAL_TITLE_NO_IMAGE_X = 11 
  35. local CHAL_TITLE_Y = -36 
  36. --local CHAL_METER_MAX = 204 
  37.  
  38. local Hud_challenge_data = {} 
  39. local Hud_diversions = {} 
  40. local Div_slots = {} 
  41. local Num_divs = 0 
  42. local Meter_max = 0 
  43. local Meter_height = 0 
  44.  
  45. Hud_diversion_doc = 0  
  46.  
  47. Hud_diversion_is_paused = false 
  48.  
  49. function hud_diversion_init() 
  50. 	Hud_diversion_doc = vint_document_find("hud_diversion") 
  51. 	 
  52. 	-- hide base group 
  53. 	local div_base = Vdo_base_object:new("div_base") 
  54. 	div_base:set_visible(false) 
  55. 	 
  56. 	local meter_fill = Vdo_base_object:new("meter_fill", div_base.handle) 
  57. 	meter_fill:set_color(COLOR_RESPECT_METER.R, COLOR_RESPECT_METER.G, COLOR_RESPECT_METER.B) 
  58. 	 
  59. 	local chal_grp = Vdo_base_object:new("chal_grp") 
  60. 	chal_grp:set_visible(false) 
  61. 	chal_grp:set_alpha(0) 
  62. 	 
  63. 	local chal_meter_fill = Vdo_base_object:new("chal_meter_fill") 
  64. 	Meter_max, Meter_height = chal_meter_fill:get_actual_size() 
  65. 	 
  66. 	-- subscriptions 
  67. 	vint_dataitem_add_subscription("hud_challenge", "update", "hud_diversion_chal_data_item_update") 
  68. 	vint_datagroup_add_subscription("hud_diversion", "update", "hud_diversion_data_item_update") 
  69. end 
  70.  
  71. function hud_diversion_data_item_update(di_h) 
  72. 	--[[ 
  73. 		Hud Diversions datagroup members: 
  74. 		VINT_PROP_TYPE_INT            - Meter type 
  75. 		VINT_PROP_TYPE_UINT           - Line one message crc or string to display in the meter (diversion name) 
  76. 		VINT_PROP_TYPE_UINT           - Line two message crc to display in the meter (diversion name) 
  77. 		VINT_PROP_TYPE_FLOAT          - Current value/time/distance 
  78. 		VINT_PROP_TYPE_FLOAT          - Min value/time/distance 
  79. 		VINT_PROP_TYPE_FLOAT          - Max value/time/distance 
  80. 		VINT_PROP_TYPE_BOOL           - Whether the meter should be descending or not. 
  81. 		VINT_PROP_TYPE_INT            - Diversion status 
  82. 		VINT_PROP_TYPE_INT            - Respect 
  83. 		VINT_PROP_TYPE_FLOAT          - Cash 
  84. 		VINT_PROP_TYPE_INT            - Diversion Type 
  85. 		VINT_PROP_TYPE_INT            - Respect Stat 
  86. 		VINT_PROP_TYPE_INT            - Type of message, passed directly back to code on removal 
  87. 	]] 
  88.  
  89. 	local meter_type, message_one, message_two, cur_value, min_value, max_value, descending, status, respect, cash, div_type, respect_stat, message_type = vint_dataitem_get(di_h) 
  90. 	hud_diversion_update(di_h, meter_type, message_one, message_two, cur_value, min_value, max_value, descending, status, respect, cash, div_type, respect_stat, message_type) 
  91. end 
  92.  
  93. function hud_diversion_update(index, meter_type, message_one, message_two, cur_value, min_value, max_value, descending, status, respect, cash, div_type, respect_stat, message_type)	 
  94. 	 
  95. 	--If this item has't been created, make a new one and set it up 
  96. 	if Hud_diversions[index] == nil then	 
  97. 				 
  98. 		if Num_divs == DIVERSION_MAX then 
  99. 			return 
  100. 		end 
  101. 		 
  102. 		-- clone new object 
  103. 		local div_base = Vdo_base_object:new("div_base") 
  104. 		local div_anim_in = Vdo_anim_object:new("div_anim_in") 
  105. 		local div_anim_complete = Vdo_anim_object:new("div_anim_complete") 
  106. 		local div_anim_shift_up = Vdo_anim_object:new("div_anim_shift_up") 
  107. 		local div_anim_multi = Vdo_anim_object:new("div_anim_multi") 
  108. 		local div_anim_fire_scale = Vdo_anim_object:new("div_anim_fire_scale") 
  109. 		 
  110. 		div_base:set_visible(false) 
  111. 		 
  112. 		local grp = Vdo_base_object:clone(div_base.handle) 
  113. 		local anim_in = Vdo_anim_object:clone(div_anim_in.handle) 
  114. 		local anim_complete = Vdo_anim_object:clone(div_anim_complete.handle) 
  115. 		local anim_shift_up = Vdo_anim_object:clone(div_anim_shift_up.handle) 
  116. 		local anim_multi = Vdo_anim_object:clone(div_anim_multi.handle) 
  117. 		local anim_fire_scale = Vdo_anim_object:clone(div_anim_fire_scale.handle) 
  118. 		 
  119. 		local div_respect = Vdo_base_object:new("div_respect", grp.handle) 
  120. 		--local div_clip_resize_twn = Vdo_tween_object:new("div_clip_resize_twn", anim_complete.handle) 
  121. 		 
  122. 		grp:set_visible(true) 
  123. 		anim_in:set_target_handle(grp.handle)		 
  124. 		anim_complete:set_target_handle(grp.handle)		 
  125. 		anim_shift_up:set_target_handle(grp.handle) 
  126. 		anim_multi:set_target_handle(grp.handle) 
  127. 		anim_fire_scale:set_target_handle(grp.handle) 
  128. 		 
  129. 		local shift_up_grp = Vdo_base_object:new("div_shift_up_grp", grp.handle) 
  130. 		local shift_up_x, shift_up_y = shift_up_grp:get_anchor() 
  131. 		shift_up_grp:set_anchor(shift_up_x, DIVERSION_ANCHOR_OFFSET * Num_divs)		 
  132. 		 
  133. 		local div_in_twn = Vdo_tween_object:new("div_in_twn", anim_in.handle) 
  134. 		local start_value_x, start_value_y = div_in_twn:get_start_value() 
  135. 		local end_value_x, end_value_y = div_in_twn:get_end_value() 
  136. 		--div_in_twn:set_property("start_value", start_value_x, start_value_y)  
  137. 		div_in_twn:set_property("end_value", end_value_x, start_value_y) 
  138. 		 
  139. 		local fire_scale_twn = Vdo_tween_object:new("fire_scale_twn", anim_fire_scale.handle) 
  140. 		local fire_scale_x_start, fire_scale_y_start = fire_scale_twn:get_start_value() 
  141. 		local fire_scale_x_end, fire_scale_y_end = fire_scale_twn:get_end_value() 
  142. 		 
  143. 		anim_in:play(0)		 
  144.  
  145. 		--div_clip_resize_twn:set_property("end_value",-180, 50) 
  146. 		 
  147. 		Hud_diversions[index] = { 
  148. 			index              = index, 
  149. 			grp                = grp, 
  150. 			anim_in            = anim_in, 
  151. 			anim_complete      = anim_complete, 
  152. 			anim_shift_up      = anim_shift_up, 
  153. 			anim_multi         = anim_multi, 
  154. 			anim_fire_scale    = anim_fire_scale, 
  155. 			fire_scale_x_start = fire_scale_x_start, 
  156. 			fire_scale_y_start = fire_scale_y_start, 
  157. 			fire_scale_x_end   = fire_scale_x_end, 
  158. 			fire_scale_y_end   = fire_scale_y_end, 
  159. 			div_level          = 0, 
  160. 			fire        	   = Vdo_base_object:new("fire", grp.handle), 
  161. 			cash               = 0, 
  162. 			respect            = 0, 
  163. 			div_type           = -1, 
  164. 			respect_stat       = -1, 
  165. 			message_type       = -1 
  166. 		} 
  167. 		 
  168. 		hud_diversion_add_slot(index) 
  169. 		 
  170. 	end 
  171. 	 
  172. 	Hud_diversions[index].cash         = cash 
  173. 	Hud_diversions[index].respect      = respect 
  174. 	Hud_diversions[index].div_type     = div_type 
  175. 	Hud_diversions[index].respect_stat = respect_stat 
  176. 	Hud_diversions[index].message_type = message_type 
  177. 	 
  178. 	local grp = Hud_diversions[index].grp 
  179. 	local div_title = Vdo_base_object:new("div_title", grp.handle) 
  180. 	 
  181. 	-- set title 
  182. 	if type(message_one) == "string" then 
  183. 		div_title:set_text(message_one, false) 
  184. 	elseif type(message_one) == "number" then 
  185. 		div_title:set_text_crc(message_one) 
  186. 	end 
  187. 	 
  188. 	-- Based on our status, check if we have an early out case. 
  189. 	if status == HDIS_CANCELLED then 
  190. 		hud_diversion_remove(index) 
  191. 		return 
  192. 	 
  193. 	elseif status >= HDIS_COMPLETE then 
  194. 		-- Handles HDIS_COMPLETE and HDIS_COMPLETE_DO_NOT_SHOW_HUD cases. 
  195. 		hud_diversion_complete(index, status == HDIS_COMPLETE_DO_NOT_SHOW_HUD) 
  196. 		return 
  197. 	end 
  198. 	 
  199. 	local meter_fill = Vdo_base_object:new("meter_fill", grp.handle) 
  200. 	local div_value = Vdo_base_object:new("div_value", grp.handle)	 
  201. 	local div_fleur = Vdo_base_object:new("div_fleur", grp.handle)	 
  202. 	local div_meter_bg = Vdo_base_object:new("meter_bg", grp.handle) 
  203. 	local div_multi = Vdo_base_object:new("div_multi", grp.handle) 
  204. 	 
  205. 	-- Get the floored current value, used in several meters. 
  206. 	local cur_value_floor = 0 
  207. 	if cur_value ~= nil then 
  208. 		cur_value_floor = floor(cur_value) 
  209. 	end 
  210. 	 
  211. 	-- Set the current value for the meter. 
  212. 	if meter_type == HDM_NONE or meter_type == nil then 
  213. 		grp:set_visible(false) 
  214. 		return 
  215. 		 
  216. 	elseif meter_type == HDM_DISTANCE then 
  217. 		if type(message_two) == "number" and message_two ~= 0 then 
  218. 			local insert = { [0] = message_two, [1] = format_distance(cur_value) } 
  219. 			local body = vint_insert_values_in_string("DIVERSION_TEXT_PROGRESS", insert) 
  220.  
  221. 			div_value:set_text(body) 
  222. 		else 
  223. 			div_value:set_text(format_distance(cur_value)) 
  224. 		end 
  225. 	elseif meter_type == HDM_XY then 
  226. 		if type(message_two) == "number" and message_two ~= 0 then 
  227. 			local insert = { [0] = message_two, [1] = cur_value_floor.."/"..max_value } 
  228. 			local body = vint_insert_values_in_string("DIVERSION_TEXT_PROGRESS", insert) 
  229.  
  230. 			div_value:set_text(body) 
  231. 		else 
  232. 			div_value:set_text(cur_value_floor.."/"..max_value) 
  233. 		end 
  234. 	elseif meter_type == HDM_COUNTER then 
  235. 		if type(message_two) == "number" and message_two ~= 0 then 
  236. 			local insert = { [0] = message_two, [1] = cur_value_floor } 
  237. 			local body = vint_insert_values_in_string("DIVERSION_TEXT_PROGRESS", insert) 
  238.  
  239. 			div_value:set_text(body) 
  240. 		else 
  241. 			div_value:set_text(var_to_string(cur_value_floor)) 
  242. 		end 
  243. 	elseif meter_type == HDM_TIME then 
  244. 		-- Time is in milliseconds 
  245. 		-- format_clock accepts time in seconds 
  246. 		if type(message_two) == "number" and message_two ~= 0 then 
  247. 			local insert = { [0] = message_two, [1] = format_time(cur_value_floor / 1000, false, true) } 
  248. 			local body = vint_insert_values_in_string("DIVERSION_TEXT_PROGRESS", insert) 
  249.  
  250. 			div_value:set_text(body) 
  251. 		else 
  252. 			div_value:set_text(format_time(cur_value_floor / 1000, false, true)) 
  253. 		end 
  254. 		 
  255. 	elseif meter_type == HDM_PERCENT then 
  256. 		-- always 0 - 100 
  257. 		if type(message_two) == "number" and message_two ~= 0 then 
  258. 			local insert = { [0] = message_two, [1] = cur_value_floor.."%%" } 
  259. 			local body = vint_insert_values_in_string("DIVERSION_TEXT_PROGRESS", insert) 
  260.  
  261. 			div_value:set_text(body) 
  262. 		else 
  263. 			div_value:set_text(cur_value_floor.."%%") 
  264. 		end 
  265. 		 
  266. 	elseif meter_type == HDM_TEXT then 
  267. 		-- This gets a string 
  268. 		-- Hide everything except the fire and the fleur 
  269. 		div_fleur:set_visible(true) 
  270. 		meter_fill:set_visible(false) 
  271. 		div_meter_bg:set_visible(false)		 
  272. 		div_multi:set_visible(false) 
  273. 		 
  274. 		hud_diversion_start_fire(index)	 
  275. 		 
  276. 		div_value:set_property("force_case", "upper") 
  277. 		 
  278. 		if type(message_two) == "number" and message_two ~= 0 then 
  279. 			div_value:set_text_crc(message_two) 
  280. 		else 
  281. 			div_value:set_visible(false) 
  282. 		end 
  283. 		 
  284. 		return 
  285. 	elseif meter_type == HDM_QTE then 
  286. 		-- always 0 - 100 
  287. 		if type(message_two) == "number" and message_two ~= 0 then 
  288. 			local insert = { [0] = message_two, [1] = cur_value_floor.."%%" } 
  289. 			local body = vint_insert_values_in_string("DIVERSION_TEXT_PROGRESS", insert) 
  290.  
  291. 			div_value:set_text(body) 
  292. 		else 
  293. 			div_value:set_text(cur_value_floor.."%%") 
  294. 		end		 
  295. 	end	 
  296. 	 
  297. 	-- Because the descending types are filled in reverse, we must calculate our fill differently. 
  298. 	local fill = 0 
  299. 	if descending then 
  300. 		local diff = min_value - max_value 
  301. 		if cur_value < min_value and diff > 0 then 
  302. 			fill = ((min_value - cur_value) * DIVERSION_MAX_STEPS) / diff 
  303. 		elseif diff == 0 then 
  304. 			fill = DIVERSION_MAX_STEPS 
  305. 		end 
  306. 	else 
  307. 		local diff = max_value - min_value 
  308. 		if  cur_value > min_value and diff > 0 then 
  309. 			fill = ((cur_value - min_value) * DIVERSION_MAX_STEPS) / diff 
  310. 		elseif diff == 0 then 
  311. 			fill = DIVERSION_MAX_STEPS 
  312. 		end 
  313. 	end 
  314. 	 
  315. 	-- Overwrite diversion steps for HUD_QTE type 
  316. 	if meter_type == HDM_QTE then 
  317. 		local diff = max_value - min_value 
  318. 		if  cur_value > min_value and diff > 0 then 
  319. 			fill = (cur_value - min_value) / diff 
  320. 		end 
  321. 	end 
  322. 	 
  323. 	-- Set our current diversion level and meter fill percent, based on the overall fill level. 
  324. 	local div_level = floor(fill) 
  325. 	 
  326. 	-- If we are at max, we need to hardcode the meter fill to full. 
  327. 	local meter_fill_pct = 0 
  328. 	if div_level >= DIVERSION_MAX_STEPS then 
  329. 		meter_fill_pct = 6.30 -- = 2PI (6.28) + fudge to make sure the bar is full with no gaps. 
  330. 	else 
  331. 		-- Otherwise the fill percent is the decimal of the fill 
  332. 		meter_fill_pct = (fill - div_level) * 6.28	 
  333. 	end 
  334. 	 
  335. 	-- If the level changed, and we aren't at the default level, setup the fire/text 
  336. 	local play_anim_multi = false 
  337. 	if div_level ~= Hud_diversions[index].div_level then 
  338. 		-- Start our fire playing if it isn't already. 
  339. 		if hud_diversion_is_fire_playing(index) == false and div_level > 0 then 
  340. 			hud_diversion_start_fire(index)		 
  341. 		end 
  342. 		 
  343. 		-- If we get here, the div_level went down, remove the multiplier text and fire. 
  344. 		if div_level == 0 then 
  345. 			div_multi:set_text("") 
  346. 			hud_diversion_stop_fire(index) 
  347. 			 
  348. 			local div_gradient_grp = Vdo_base_object:new("div_gradient_grp", grp.handle) 
  349. 			div_gradient_grp:set_alpha(0) 
  350. 		 
  351. 		elseif div_level == 1 then 
  352. 			div_multi:set_text("2X") 
  353. 			play_anim_multi = true 
  354. 			 
  355. 			Hud_diversions[index].anim_fire_scale:stop() 
  356. 			 
  357. 		elseif div_level == 2 then 
  358. 			div_multi:set_text("3X") 
  359. 			play_anim_multi = true 
  360. 			 
  361. 			Hud_diversions[index].anim_fire_scale:play(0) 
  362. 			 
  363. 			local anim = Hud_diversions[index].anim_fire_scale 
  364. 			local fire_scale_twn = Vdo_tween_object:new("fire_scale_twn", anim.handle) 
  365. 			 
  366. 			-- Force the scale to default, this handles cases where we went from 3 -> 2, 
  367. 			-- or went from 3 -> 1 -> 2, by forcing the scale to be at initial values. 
  368. 			fire_scale_twn:set_property("start_value", Hud_diversions[index].fire_scale_x_start, Hud_diversions[index].fire_scale_y_start) 
  369. 			fire_scale_twn:set_property("end_value", Hud_diversions[index].fire_scale_x_end, Hud_diversions[index].fire_scale_y_end) 
  370. 			 
  371. 		elseif div_level >= 3 then 
  372. 			div_multi:set_text("MAX") 
  373. 			play_anim_multi = true 
  374. 			 
  375. 			local anim = Hud_diversions[index].anim_fire_scale 
  376. 			local fire_scale_twn = Vdo_tween_object:new("fire_scale_twn", anim.handle) 
  377. 			 
  378. 			local x, y = fire_scale_twn:get_property("end_value") 
  379. 			 
  380. 			fire_scale_twn:set_property("start_value", 1, 1) 
  381. 			fire_scale_twn:set_property("end_value", 2.2, 2.2) 
  382. 			 
  383. 			anim:play(0) 
  384. 			 
  385. 			play_anim_multi = true 
  386. 		end 
  387. 	end 
  388. 	 
  389. 	-- Save our current diversion level 
  390. 	Hud_diversions[index].div_level = div_level 
  391. 	 
  392. 	-- If we should play the animation multiplier, do so. 
  393. 	if play_anim_multi == true then 
  394. 		Hud_diversions[index].anim_multi:play(0)	 
  395. 		play_anim_multi = false 
  396. 	end 
  397.  
  398. 	-- Set our fill. 
  399. 	meter_fill:set_property("end_angle", meter_fill_pct) 
  400. end 
  401.  
  402. function hud_diversion_complete(index, hide_completion_anim) 
  403. 	 
  404. 	local div_respect	= Vdo_base_object:new("div_respect", Hud_diversions[index].grp.handle) 
  405.  
  406. 	-- Trigger reward and cash 
  407. 	if Hud_diversions[index].respect > 0 then 
  408. 		game_award_respect(Hud_diversions[index].respect, Hud_diversions[index].respect_stat, Hud_diversions[index].div_type) 
  409. 		 
  410. 		local insert = { [0] = floor(Hud_diversions[index].respect) } 
  411. 		local body = vint_insert_values_in_string("DIVERSIONS_RESPECT", insert) 
  412. 		 
  413. 		div_respect:set_text(body) 
  414. 	elseif Hud_diversions[index].cash > 0 then 
  415. 		local insert = { [0] = "{GAME_CASH}" .. format_cash(floor(Hud_diversions[index].cash)) } 
  416. 		local body = vint_insert_values_in_string("DIVERSIONS_CASH", insert)	 
  417. 	 
  418. 		game_award_cash(Hud_diversions[index].cash, Hud_diversions[index].div_type)			 
  419. 		div_respect:set_text(body) 
  420. 	else 
  421. 		hud_diversion_remove(index) 
  422. 		return 
  423. 	end	 
  424. 	 
  425. 	local anim_complete = Hud_diversions[index].anim_complete 
  426. 	local div_end_event = Vdo_tween_object:new("div_end_event", anim_complete.handle) 
  427.  
  428. 	-- Since you can't pass parameters through end events have 
  429. 	-- end event find handle to remove 
  430. 	div_end_event:set_end_event("hud_diversion_remove_complete") 
  431. 	 
  432. 	--set animation start time... 
  433. 	if Hud_diversion_is_paused or hide_completion_anim then 
  434. 		-- We are paused so skip the animation. The code will do the callback and completed itself... 
  435. 		anim_complete:play(-10) 
  436. 	else 
  437. 		anim_complete:play(0) 
  438. 	end 
  439. end 
  440.  
  441. function hud_diversion_remove_complete(tween_handle) 
  442. 	 
  443. 	local anim = vint_object_parent(tween_handle) 
  444. 				 
  445. 	for idx, val in pairs(Hud_diversions) do 
  446. 		if anim == val.anim_complete.handle then				 
  447. 			hud_diversion_remove(idx)				 
  448. 			break 
  449. 		end 
  450. 	end 
  451. end 
  452.  
  453. function hud_diversion_remove(index) 
  454. 	--Destroy objects, animation and values 
  455. 	if Hud_diversions[index] ~= nil then 
  456. 		--Destroy group object 
  457. 		Hud_diversions[index].grp:object_destroy() 
  458. 		 
  459. 		--Destory anim objects	 
  460. 		Hud_diversions[index].anim_in:object_destroy() 
  461. 		Hud_diversions[index].anim_complete:object_destroy() 
  462. 		Hud_diversions[index].anim_shift_up:object_destroy() 
  463. 		Hud_diversions[index].anim_multi:object_destroy() 
  464. 		Hud_diversions[index].anim_fire_scale:object_destroy() 
  465. 		 
  466. 		-- Callback we are done 
  467. 		hud_diversion_remove_callback(Hud_diversions[index].message_type) 
  468. 		 
  469. 		--Destroy stored values 
  470. 		hud_diversion_remove_slot(index)	 
  471. 		Hud_diversions[index] = nil	 
  472. 	end 
  473. end 
  474.  
  475. function hud_diversion_cleanup() 
  476.  
  477. end 
  478.  
  479. function hud_diversion_add_slot(index) 
  480. 	 
  481. 	for i = 0, Num_divs do 
  482. 	 
  483. 		if Div_slots[i] == nil then 
  484. 			Div_slots[i] = index 
  485. 		end 
  486. 	 
  487. 	end	 
  488. 	 
  489. 	Num_divs = Num_divs + 1		 
  490.  
  491. end 
  492.  
  493. function hud_diversion_remove_slot(index) 
  494. 	 
  495. 	for i = 0, Num_divs do 
  496. 	 
  497. 		if Div_slots[i] == index then 
  498. 			Div_slots[i] = nil 
  499. 		end 
  500. 	 
  501. 	end	 
  502. 	 
  503. 	-- step through slot array and shift everything up 
  504. 	-- check if any anchor twns are running first	 
  505. 	local shift_up = false 
  506. 	for i = 0, Num_divs  do 
  507. 	 
  508. 		if Div_slots[i] == nil and Div_slots[i+1] ~= nil then			 
  509. 			shift_up = true 
  510. 		end	 
  511. 		 
  512. 		if shift_up == true then 
  513. 			Div_slots[i] = Div_slots[i+1] 
  514. 		end 
  515. 		 
  516. 		if Div_slots[i] ~= nil then 
  517. 			hud_diversion_shift_up(i) 
  518. 		end 
  519. 	 
  520. 	end	 
  521. 	 
  522. 	Num_divs = Num_divs - 1	 
  523. 	 
  524. end 
  525.  
  526. function hud_diversion_shift_up(slot) 
  527.  
  528. 	local index = Div_slots[slot] 
  529. 	local grp = Hud_diversions[index].grp 
  530. 	local shift_up_grp  = Vdo_base_object:new("div_shift_up_grp",grp.handle) 
  531. 	local anim_shift_up = Hud_diversions[index].anim_shift_up 
  532. 	 
  533. 	local div_shift_up_twn = Vdo_tween_object:new("div_shift_up_twn", anim_shift_up.handle) 
  534.  
  535. 	--local start_value_x, start_value_y = div_shift_up_twn:get_start_value() 
  536. 	local shift_up_grp_x, shift_up_grp_y = shift_up_grp:get_anchor() 
  537. 	div_shift_up_twn:set_property("start_value", shift_up_grp_x, shift_up_grp_y) 
  538. 	div_shift_up_twn:set_property("end_value", shift_up_grp_x, slot * DIVERSION_ANCHOR_OFFSET)	 
  539. 	 
  540. 	anim_shift_up:play(0) 
  541. 	 
  542. end 
  543.  
  544. function hud_diversion_start_fire(index) 
  545.  
  546. 	local fire = Hud_diversions[index].fire 
  547. 	fire:set_visible(true) 
  548. 	fire:set_alpha(1.0) 
  549.  
  550. 	local fire_frames_table = {	"ui_hud_diversion_fire1", "ui_hud_diversion_fire2", "ui_hud_diversion_fire3", "ui_hud_diversion_fire4", "ui_hud_diversion_fire5", "ui_hud_diversion_fire6", "ui_hud_diversion_fire7",  
  551. 								"ui_hud_diversion_fire8", "ui_hud_diversion_fire9", "ui_hud_diversion_fire10", "ui_hud_diversion_fire11", "ui_hud_diversion_fire12", "ui_hud_diversion_fire13", "ui_hud_diversion_fire14"} 
  552. 	vint_bitmap_animator_register_animation(--[[target handle]]fire.handle, --[[loop type see game_ui_globals.lua]]ANIMATED_BITMAP_PLAYBACK_TYPE_LOOPING, --[[playback reverse]] false, 
  553. 											--[[frametime]]1/15, --[[duration (negative means forever)]]-1.0, --[[start paused]]false, --[[starting frame]] 1, --[[frames table]]fire_frames_table, --[[end event]] "") 
  554.  
  555. end 
  556.  
  557. function hud_diversion_is_fire_playing(index) 
  558.  
  559. 	return vint_bitmap_animator_animation_is_playing(Hud_diversions[index].fire.handle) 
  560.  
  561. end 
  562.  
  563. function hud_diversion_stop_fire(index) 
  564.  
  565. 	Hud_diversions[index].anim_fire_scale:stop() 
  566. 	 
  567. 	local fire = Hud_diversions[index].fire 
  568. 	fire:set_visible(false) 
  569. 	vint_bitmap_animator_unregister_animation(fire.handle)	 
  570. end 
  571.  
  572.  
  573. ------------------------------------------------------------------------------- 
  574. -- Challenges fucntions 
  575. ------------------------------------------------------------------------------- 
  576.  
  577. function hud_diversion_chal_data_item_update(di_h) 
  578. 	--[[ 
  579. 		Hud Challenge dataitem members: 
  580. 		VINT_PROP_TYPE_UINT           - Message crc to display in the meter (title) 
  581. 		VINT_PROP_TYPE_FLOAT          - Current progress for the challenge 
  582. 		VINT_PROP_TYPE_FLOAT          - Goal for the challenge 
  583. 		VINT_PROP_TYPE_UINT           - crc value for the units, if any 
  584. 		VINT_PROP_TYPE_FLOAT          - The cash to reward the player with, if any 
  585. 		VINT_PROP_TYPE_INT            - The respect to reward the player with, if any 
  586. 		VINT_PROP_TYPE_BOOL           - If the respect/cash should be saved for mission restarts, passed back to code on reward. 
  587. 		VINT_PROP_TYPE_BOOL           - If this is an achievement updated 
  588. 		VINT_PROP_TYPE_BITMAP         - The image, if one exists. 
  589. 		VINT_PROP_TYPE_INT            - The message type, passed back to code as a callback so it knows the hud is clear 
  590. 	]] 
  591.  
  592. 	local title, cur_val, max_val, val_units, cash_reward, respect_reward, save_in_mission, is_achievement, image, message_type = vint_dataitem_get(di_h) 
  593. 	hud_diversion_chal_update(title, cur_val, max_val, val_units, cash_reward, respect_reward, save_in_mission, is_achievement, image, message_type) 
  594. end 
  595.  
  596. function hud_diversion_chal_update(title, cur_val, max_val, val_units, cash_reward, respect_reward, save_in_mission, is_achievement, image, message_type) 
  597. 	--No data... Abort Challenge screen. 
  598. 	if title == 0 or title == nil then 
  599. 		return 
  600. 	end 
  601. 	 
  602. 	--Queue up any data into memory... 
  603. 	Hud_challenge_data = { 
  604. 		title = title, 
  605. 		cur_val = cur_val,  
  606. 		max_val = max_val,  
  607. 		val_units = val_units,  
  608. 		cash_reward = cash_reward,  
  609. 		respect_reward = respect_reward, 
  610. 		is_achievement = is_achievement,  
  611. 		image = image,  
  612. 		message_type = message_type, 
  613. 		save_in_mission = save_in_mission, 
  614. 	} 
  615.  
  616. 	if is_achievement == true then 
  617. 		game_peg_load_with_cb("hud_diversion_chal_show", 1, image) 
  618. 	else 
  619. 		hud_diversion_chal_show() 
  620. 	end 
  621. end 
  622.  
  623. function hud_diversion_chal_show()  
  624. 	local chal_grp = Vdo_base_object:new("chal_grp") 
  625. 	local chal_bg = Vdo_base_object:new("chal_bg") 
  626. 	local chal_title = Vdo_base_object:new("chal_title") 
  627. 	local chal_xy = Vdo_base_object:new("chal_xy") 
  628. 	local chal_image = Vdo_base_object:new("chal_image") 
  629. 	local chal_meter_fill = Vdo_base_object:new("chal_meter_fill") 
  630. 	local chal_anim = Vdo_anim_object:new("chal_anim_in") 
  631. 	local end_event = Vdo_tween_object:new("chal_end_event_twn", chal_anim.handle) 
  632. 	 
  633. 	chal_title:set_text_crc(Hud_challenge_data.title)	 
  634. 	 
  635. 	-- Handle units 
  636. 	if Hud_challenge_data.cur_val < 0 then 
  637. 		chal_xy:set_visible(false) 
  638. 	else 
  639. 		chal_xy:set_visible(true) 
  640. 		if Hud_challenge_data.val_units ~= 0 then 
  641. 			local insert = { 	[0] = format_cash(floor(Hud_challenge_data.cur_val)), 
  642. 									[1] = format_cash(floor(Hud_challenge_data.max_val)), [2] = Hud_challenge_data.val_units } 
  643. 			local body = vint_insert_values_in_string("DIVERSION_CHALLENGES_UNITS", insert) 
  644.  
  645. 			chal_xy:set_text(body) 
  646. 		else 
  647. 			chal_xy:set_text(floor(Hud_challenge_data.cur_val).."/"..floor(Hud_challenge_data.max_val)) 
  648. 		end	 
  649. 	end 
  650. 		 
  651. 	if Hud_challenge_data.is_achievement == true then 
  652. 		chal_image:set_image(Hud_challenge_data.image) 		 
  653. 		chal_image:set_visible(true) 
  654. 		--chal_title:set_anchor(CHAL_TITLE_X, CHAL_TITLE_Y) 
  655. 		--chal_title:set_property("wrap_width", 265) 
  656. 	else 
  657. 		-- Hide image and move text over to compensate 
  658. 		chal_image:set_visible(false) 
  659. 		--chal_title:set_anchor(CHAL_TITLE_NO_IMAGE_X, CHAL_TITLE_Y)		 
  660. 	end 
  661. 	 
  662. 	chal_title:set_property("wrap_width", 345) 
  663. 	chal_title:set_property("word_wrap", true) 
  664.  
  665. 	local chal_bg_width, chal_bg_height = chal_bg:get_actual_size() 
  666. 	local chal_title_width, chal_title_height = chal_title:get_actual_size() 
  667. 	local new_bg_height = (CHAL_TITLE_Y - chal_title_height) * -1 
  668. 	chal_bg:set_actual_size(chal_bg_width, new_bg_height) 
  669. 	 
  670. 	end_event:set_end_event("hud_diversion_chal_complete") 
  671. 	chal_anim:play(0)	 
  672. 	chal_grp:set_visible(true) 
  673. 	 
  674. 	-- Handle meter fill 
  675. 	local final_pct = Hud_challenge_data.cur_val / Hud_challenge_data.max_val 
  676. 	local fill = final_pct * Meter_max 
  677. 	if final_pct ~= 1 then --if 1 then set it to full 
  678. 		local incriment = Meter_max/46 
  679. 		 
  680. 		for i = 0, Meter_max, incriment do 
  681. 			if fill >= i and fill < (i + incriment) then 
  682. 				fill = i 
  683. 			end 
  684. 		end 
  685. 	end 
  686. 	chal_meter_fill:set_actual_size(fill, Meter_height) 
  687. end 
  688.  
  689. function hud_diversion_chal_complete() 
  690.  
  691. 	-- Reward the player with cash/respect 
  692. 	if Hud_challenge_data.respect_reward > 0 then 
  693. 		game_award_respect(Hud_challenge_data.respect_reward, STATS_INVALID, DT_CHALLENGE) 
  694. 	end 
  695. 	if Hud_challenge_data.cash_reward > 0 then 
  696. 		game_award_cash(Hud_challenge_data.cash_reward, DT_CHALLENGE) 
  697. 	end 
  698. 	 
  699. 	hud_diversion_remove_callback(Hud_challenge_data.message_type) 
  700. 	if Hud_challenge_data.is_achievement == true then 
  701. 		game_peg_unload(Hud_challenge_data.image) 
  702. 	end 
  703. end 
  704.  
  705. ------------------------------------------------------------------------------- 
  706. -- Causes the diversion hud to go into a paused state... 
  707. ------------------------------------------------------------------------------- 
  708. function hud_diversion_pause(is_paused) 
  709. 	Hud_diversion_is_paused = is_paused 
  710. end 
  711.  
  712. ------------------------------------------------------------------------ 
  713. --Forces diversions to hide with transition... 
  714. ------------------------------------------------------------------------------- 
  715. function hud_diversion_hide() 
  716. 	local anim_h = vint_object_find("div_fade_all_out_anim", 0, Hud_diversion_doc) 
  717. 	lua_play_anim(anim_h) 
  718. 	hud_diversion_pause(true) 
  719. end 
  720.  
  721. ------------------------------------------------------------------------------- 
  722. --Forces diversions to show with transition...  
  723. ------------------------------------------------------------------------------- 
  724. function hud_diversion_show() 
  725. 	local anim_h = vint_object_find("div_fade_all_in_anim", 0, Hud_diversion_doc) 
  726. 	lua_play_anim(anim_h) 
  727. 	hud_diversion_pause(false) 
  728. end 
  729.  
  730. ------------------------------------------------------------------------------- 
  731. --	Meter Testing code 
  732. ------------------------------------------------------------------------------- 
  733.  
  734. Diversion_test_thread = -1  
  735. Diversion_test_data = {} 
  736. Diversion_test_data_count = 0 
  737.  
  738. function hud_diversion_test_thread() 
  739. 	--Just test one meter at a time... 
  740. 	local doing_thread = true 
  741. 	local di 
  742. 	while doing_thread do 
  743. 		--Process specific data  
  744. 		for idx, val in pairs(Diversion_test_data) do 
  745. 			di = val.data_item 
  746. 			local current_time = vint_get_time_index()  
  747. 			local interp = (current_time - val.start_time )/ val.duration 
  748. 			local cur_value = floor(test_interp_linear(interp, val.start_value, val.end_value -  val.start_value)) 
  749. 			 
  750. 			--Finished interpolation... 
  751. 			local status = di.status 
  752. 			 
  753. 			if cur_value >= val.end_value then 
  754. 				cur_value = val.end_value 
  755. 				--Transition Complete! 
  756. 				status = HDIS_COMPLETE 
  757. 			end 
  758. 			 
  759. 			di.cur_value = cur_value 
  760. 			if Diversion_test_data[idx] == nil then 
  761. 				--No Update 
  762. 			else 
  763. 				hud_diversion_update(idx, di.meter_type, di.message_one, di.message_two, cur_value, di.min_value, di.max_value, di.descending, status, di.respect, di.cash, di.div_type, di.respect_stat, di.message_type)	 
  764. 			end 
  765. 			 
  766. 			if status == HDIS_COMPLETE then 
  767. 				--Wipe out diverion from test data... 
  768. 				Diversion_test_data[idx] = nil 
  769. 			end 
  770. 		end 
  771. 		 
  772. 		--Hold Frame... 
  773. 		thread_yield() 
  774. 	end 
  775. end 
  776.  
  777. function hud_challenge_test_add(unit_type) 
  778.  
  779.  
  780. 	--Initialize values... 
  781. 	local title					= 0 
  782. 	local cur_val				= 0 
  783. 	local max_val				= 0 
  784. 	local val_units			= 0 
  785. 	local cash_reward			= 0 
  786. 	local respect_reward		= 0 
  787. 	local is_achievement		= false 
  788. 	local message_type		= HDT_NONE 
  789.  
  790. 	-- Display the type of hud they want 
  791. 	if unit_type == nil or unit_type == "" then 
  792. 		title				= get_localized_crc_for_tag("DIVERSION_CHALLENGES_DESTROY_MORNINGSTAR_VEHICLES") 
  793. 		cur_val			= 20000 
  794. 		max_val			= 20000 
  795. 		val_units		= 0 
  796. 		cash_reward		= 1500 
  797. 		respect_reward	= 750 
  798. 		 
  799. 	elseif unit_type == "meters" then 
  800. 		title				= get_localized_crc_for_tag("DIVERSION_CHALLENGES_BAILOUT_DISTANCE") 
  801. 		cur_val			= 500 
  802. 		max_val			= 500 
  803. 		val_units		= get_localized_crc_for_tag("HUD_METERS_ABR") 
  804. 		cash_reward		= 1500 
  805. 		respect_reward	= 750 
  806. 		 
  807. 	elseif unit_type == "feet" then 
  808. 		title				= get_localized_crc_for_tag("DIVERSION_CHALLENGES_BAILOUT_DISTANCE") 
  809. 		cur_val			= 500 * FEET_PER_METER 
  810. 		max_val			= 500 * FEET_PER_METER 
  811. 		val_units		= get_localized_crc_for_tag("HUD_FEET_ABR") 
  812. 		cash_reward		= 1500 
  813. 		respect_reward	= 750 
  814. 		 
  815. 	elseif unit_type == "miles" then 
  816. 		title				= get_localized_crc_for_tag("DIVERSION_CHALLENGES_ONCOMING_LANE") 
  817. 		cur_val			= 10 
  818. 		max_val			= 10 
  819. 		val_units		= get_localized_crc_for_tag("HUD_MILES_ABR") 
  820. 		cash_reward		= 1600 
  821. 		respect_reward	= 800 
  822. 	 
  823. 	elseif unit_type == "seconds" then 
  824. 		title				= get_localized_crc_for_tag("DIVERSION_CHALLENGES_POWERSLIDE_TIME") 
  825. 		cur_val			= 600 
  826. 		max_val			= 600 
  827. 		val_units		= get_localized_crc_for_tag("HUD_SECONDS_ABR") 
  828. 		cash_reward		= 1500 
  829. 		respect_reward	= 750 
  830. 		 
  831. 	elseif unit_type == "minutes" then 
  832. 		title				= get_localized_crc_for_tag("DIVERSION_CHALLENGES_POWERSLIDE_TIME") 
  833. 		cur_val			= 10 
  834. 		max_val			= 10 
  835. 		val_units		= get_localized_crc_for_tag("HUD_MINUTES_ABR") 
  836. 		cash_reward		= 1500 
  837. 		respect_reward	= 750 
  838. 		 
  839. 	elseif unit_type == "hours" then 
  840. 		title				= get_localized_crc_for_tag("DIVERSION_CHALLENGES_POWERSLIDE_TIME") 
  841. 		cur_val			= 1 
  842. 		max_val			= 1 
  843. 		val_units		= get_localized_crc_for_tag("HUD_HOURS_ABR") 
  844. 		cash_reward		= 1500 
  845. 		respect_reward	= 750 
  846. 		 
  847. 	else 
  848. 		title				= get_localized_crc_for_tag("DIVERSION_CHALLENGES_VEHICLE_MODDING") 
  849. 		cur_val			= 20000 
  850. 		max_val			= 20000 
  851. 		val_units		= 0 
  852. 		cash_reward		= 1500 
  853. 		respect_reward	= 750 
  854. 	end 
  855. 	 
  856. 	-- Display the hud 
  857. 	hud_diversion_chal_update(title, cur_val, max_val, val_units, cash_reward, respect_reward, false, is_achievement, nil, message_type) 
  858. end 
  859.  
  860. function hud_diversion_test_add() 
  861.  
  862. 	--Initialize values... 
  863. 	local status 				= HDIS_IN_PROGRESS 
  864. 	local meter_type 			= HDM_TIME 
  865. 	local message_one	 		= "POWER SLIDE" 
  866. 	local message_two			= 0 
  867.  
  868. 	local start_value 		= 0									--Start value for the meter to start 
  869. 	local end_value			= 80000--rand_int(5000,10000)			--End value for the meter... 
  870. 	 
  871. 	local min_value         = 0 
  872. 	local max_value			= 80000							--Maximum that the meter can reach... 
  873. 	local descending        = false 
  874. 	local duration				= 8 -- rand_int(4,8)				--Time in seconds 
  875. 	 
  876. 	--Reward 
  877. 	local respect				= 120				--respect 
  878. 	local cash 					= 0				--cash 
  879. 	 
  880. 	--Diversion info 
  881. 	local div_type          = -1				--What is the type of the diversion 
  882. 	local respect_stat      = -1				--What is the stat that should be incremented for awarding respect 
  883. 	local message_type      = HDT_NONE      --What is the type of message 
  884. 	 
  885. 	--Build test data table... 
  886. 	-- status, meter_type, cur_value, max_value, message_crc, message_wide, respect, cash, new_record)	 
  887. 	Diversion_test_data[Diversion_test_data_count] = { 
  888. 		data_item = { 
  889. 			meter_type = meter_type, 
  890. 			message_one = message_one, 
  891. 			message_two = message_two, 
  892. 			cur_value = start_value, 
  893. 			min_value = min_value, 
  894. 			max_value = max_value, 
  895. 			descending = descending, 
  896. 			status = status, 
  897. 			respect = respect, 
  898. 			cash = cash, 
  899. 			div_type = div_type, 
  900. 			respect_stat = respect_stat, 
  901. 			message_type = message_type, 
  902. 		}, 
  903. 		start_value = start_value, 
  904. 		end_value = end_value, 
  905. 		start_time = vint_get_time_index(), 
  906. 		duration = duration 
  907. 	} 
  908. 	 
  909. 	Diversion_test_data_count = Diversion_test_data_count + 1  
  910. 	 
  911. 	if Diversion_test_thread == -1 then 
  912. 		Diversion_test_thread = thread_new("hud_diversion_test_thread") 
  913. 	end 
  914. end 
  915.  
  916. --Randomly cancels one of the diversions... 
  917. function hud_diversion_test_cancel() 
  918. 	--removes the first diversion this thing can find... 
  919. 	for idx, val in pairs(Diversion_test_data) do 
  920. 		local di = val.data_item 
  921. 		hud_diversion_update(idx, di.meter_type, di.message_one. di.message_two, di.cur_value, di.min_value, di.max_value, di.descending, HDIS_CANCELLED, di.respect, di.cash, di.div_type, di.respect_stat, di.message_type) 
  922. 		Diversion_test_data[idx] = nil 
  923. 		if true then 
  924. 			return 
  925. 		end 
  926. 	end 
  927. end 
  928.  
  929. --Randomly cancels one of the diversions... 
  930. function hud_diversion_test_complete() 
  931. 	--removes the first diversion this thing can find... 
  932. 	for idx, val in pairs(Diversion_test_data) do 
  933. 		local di = val.data_item 
  934. 		hud_diversion_update(idx, di.meter_type, di.message_one. di.message_two, di.cur_value, di.min_value, di.max_value, di.descending, HDIS_COMPLETE, di.respect, di.cash, di.div_type, di.respect_stat, di.message_type) 
  935. 		Diversion_test_data[idx] = nil 
  936. 		if true then 
  937. 			return 
  938. 		end 
  939. 	end 
  940. end 
  941.