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