2 REGISTER_MUTATOR(itemstime, true);
5 void IT_Write(entity e, int i, float f) {
6 if (!IS_REAL_CLIENT(e)) return;
8 WriteByte(MSG_ONE, SVC_TEMPENTITY);
9 WriteMutator(MSG_ONE, itemstime);
10 WriteByte(MSG_ONE, i);
11 WriteFloat(MSG_ONE, f);
16 float ItemsTime_time[Items_MAX];
17 float ItemsTime_availableTime[Items_MAX];
18 MUTATOR_HOOKFUNCTION(itemstime, CSQC_Parse_TempEntity) {
19 if (MUTATOR_RETURNVALUE) return false;
20 if (!ReadMutatorEquals(mutator_argv_int_0, itemstime)) return false;
22 float f = ReadFloat();
23 ItemsTime_time[i] = f;
29 int autocvar_hud_panel_itemstime = 2;
30 float autocvar_hud_panel_itemstime_dynamicsize = 1;
31 float autocvar_hud_panel_itemstime_ratio = 2;
32 int autocvar_hud_panel_itemstime_iconalign;
33 bool autocvar_hud_panel_itemstime_progressbar = 0;
34 float autocvar_hud_panel_itemstime_progressbar_maxtime = 30;
35 string autocvar_hud_panel_itemstime_progressbar_name = "progressbar";
36 float autocvar_hud_panel_itemstime_progressbar_reduced;
37 bool autocvar_hud_panel_itemstime_hidespawned = 1;
38 bool autocvar_hud_panel_itemstime_hidelarge = false;
39 int autocvar_hud_panel_itemstime_text = 1;
40 #define hud_panel_itemstime_hidelarge autocvar_hud_panel_itemstime_hidelarge
42 #define hud_panel_itemstime_hidelarge false
45 bool Item_ItemsTime_SpectatorOnly(GameItem it)
48 || it == ITEM_ArmorMega || (it == ITEM_ArmorLarge && !hud_panel_itemstime_hidelarge)
49 || it == ITEM_HealthMega || (it == ITEM_HealthLarge && !hud_panel_itemstime_hidelarge)
53 bool Item_ItemsTime_Allow(GameItem it, WepSet _weapons)
56 || it.instanceOfPowerup
57 || Item_ItemsTime_SpectatorOnly(it)
58 || (_weapons & WEPSET_SUPERWEAPONS)
64 float it_times[Items_MAX];
66 void Item_ItemsTime_Init()
68 FOREACH(Items, true, LAMBDA(
69 it_times[it.m_id] = -1;
73 STATIC_INIT(ItemsTime_Init) {
75 Item_ItemsTime_Init();
78 void Item_ItemsTime_ResetTimes()
80 FOREACH(Items, true, LAMBDA(
81 it_times[it.m_id] = (it_times[it.m_id] == -1) ? -1 : 0;
85 void Item_ItemsTime_ResetTimesForPlayer(entity e)
87 FOREACH(Items, true, LAMBDA(
88 IT_Write(e, it.m_id, (it_times[it.m_id] == -1) ? -1 : 0);
92 void Item_ItemsTime_SetTimesForPlayer(entity e)
94 FOREACH(Items, true, LAMBDA(
95 IT_Write(e, it.m_id, it_times[it.m_id]);
99 void Item_ItemsTime_SetTime(entity e, float t)
101 if (!autocvar_sv_itemstime)
104 GameItem item = e.itemdef;
105 it_times[item.m_id] = t;
108 void Item_ItemsTime_SetTimesForAllPlayers()
111 FOR_EACH_REALCLIENT(e) if (warmup_stage || !IS_PLAYER(e))
112 Item_ItemsTime_SetTimesForPlayer(e);
115 float Item_ItemsTime_UpdateTime(entity e, float t)
117 bool isavailable = (t == 0);
118 if (e.weapons & WEPSET_SUPERWEAPONS)
120 for (entity head = world; (head = nextent(head)); )
122 if (clienttype(head) != CLIENTTYPE_NOTACLIENT || !(head.weapons & WEPSET_SUPERWEAPONS) || head.instanceOfWeapon)
127 if (head.scheduledrespawntime <= time)
129 else if (t == 0 || head.scheduledrespawntime < t)
130 t = head.scheduledrespawntime;
135 for (entity head = world; (head = nextent(head)); )
137 if (head.itemdef != e.itemdef)
142 if (head.scheduledrespawntime <= time)
144 else if (t == 0 || head.scheduledrespawntime < t)
145 t = head.scheduledrespawntime;
149 t = -t; // let know the client there's another available item
153 MUTATOR_HOOKFUNCTION(itemstime, reset_map_global)
155 Item_ItemsTime_ResetTimes();
156 // ALL the times need to be reset before .reset()ing each item
157 // since Item_Reset schedules respawn of superweapons and powerups
158 for (entity e = NULL; (e = nextent(e)); )
159 if (IS_NOT_A_CLIENT(e))
163 Item_ItemsTime_SetTime(self, 0);
165 Item_ItemsTime_SetTimesForAllPlayers();
168 MUTATOR_HOOKFUNCTION(itemstime, MakePlayerObserver)
170 Item_ItemsTime_SetTimesForPlayer(self);
173 MUTATOR_HOOKFUNCTION(itemstime, PlayerSpawn)
175 if (warmup_stage) return;
176 Item_ItemsTime_ResetTimesForPlayer(self);
183 void DrawItemsTimeItem(vector myPos, vector mySize, float ar, entity item, float item_time, bool item_available, float item_availableTime)
186 vector color = '0 0 0';
189 if (autocvar_hud_panel_itemstime_hidespawned == 2)
191 else if (item_available)
193 float BLINK_FACTOR = 0.15;
194 float BLINK_BASE = 0.85;
195 float BLINK_FREQ = 5;
196 picalpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
200 t = floor(item_time - time + 0.999);
208 vector picpos, numpos;
209 if (autocvar_hud_panel_itemstime_iconalign)
212 picpos = myPos + eX * (ar - 1) * mySize_y;
216 numpos = myPos + eX * mySize_y;
220 if (t > 0 && autocvar_hud_panel_itemstime_progressbar)
222 vector p_pos, p_size;
223 if (autocvar_hud_panel_itemstime_progressbar_reduced)
226 p_size = eX * ((ar - 1)/ar) * mySize_x + eY * mySize_y;
233 HUD_Panel_DrawProgressBar(p_pos, p_size, autocvar_hud_panel_itemstime_progressbar_name, t/autocvar_hud_panel_itemstime_progressbar_maxtime, 0, autocvar_hud_panel_itemstime_iconalign, color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
236 if(autocvar_hud_panel_itemstime_text)
239 drawstring_aspect(numpos, ftos(t), eX * ((ar - 1)/ar) * mySize_x + eY * mySize_y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
240 else if(precache_pic("gfx/hud/default/checkmark")) // COMPAT: check if this image exists, as 0.8.1 clients lack it
241 drawpic_aspect_skin(numpos, "checkmark", eX * (ar - 1) * mySize_y + eY * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL);
242 else // legacy code, if the image is missing just center the icon
243 picpos.x = myPos.x + mySize.x / 2 - mySize.y / 2;
245 if (item_availableTime)
246 drawpic_aspect_skin_expanding(picpos, item.m_icon, '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL, item_availableTime);
247 drawpic_aspect_skin(picpos, item.m_icon, '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL);
252 if (!autocvar__hud_configure)
255 (autocvar_hud_panel_itemstime == 1 && spectatee_status != 0)
256 || (autocvar_hud_panel_itemstime == 2 && (spectatee_status != 0 || warmup_stage))
261 ItemsTime_time[ITEM_ArmorMega.m_id] = time + 0;
262 ItemsTime_time[ITEM_HealthMega.m_id] = time + 8;
263 ItemsTime_time[ITEM_Strength.m_id] = time + 0;
264 ItemsTime_time[ITEM_Shield.m_id] = time + 4;
268 if (autocvar_hud_panel_itemstime_hidespawned == 1)
269 FOREACH(Items, Item_ItemsTime_Allow(it, '0 0 0'), LAMBDA(
270 count += (ItemsTime_time[it.m_id] > time || -ItemsTime_time[it.m_id] > time);
272 else if (autocvar_hud_panel_itemstime_hidespawned == 2)
273 FOREACH(Items, Item_ItemsTime_Allow(it, '0 0 0'), LAMBDA(
274 count += (ItemsTime_time[it.m_id] > time);
277 FOREACH(Items, Item_ItemsTime_Allow(it, '0 0 0'), LAMBDA(
278 count += (ItemsTime_time[it.m_id] != -1);
283 HUD_Panel_UpdateCvars();
289 if (panel_bg_padding)
291 pos += '1 1 0' * panel_bg_padding;
292 mySize -= '2 2 0' * panel_bg_padding;
296 float ar = max(2, autocvar_hud_panel_itemstime_ratio) + 1;
297 rows = HUD_GetRowCount(count, mySize, ar);
298 columns = ceil(count/rows);
300 vector itemstime_size = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
302 vector offset = '0 0 0';
304 if (autocvar_hud_panel_itemstime_dynamicsize)
306 if (autocvar__hud_configure)
307 if (menu_enabled != 2)
308 HUD_Panel_DrawBg(1); // also draw the bg of the entire panel
310 // reduce panel to avoid spacing items
311 if (itemstime_size.x / itemstime_size.y < ar)
313 newSize = rows * itemstime_size.x / ar;
314 pos.y += (mySize.y - newSize) / 2;
316 itemstime_size.y = mySize.y / rows;
320 newSize = columns * itemstime_size.y * ar;
321 pos.x += (mySize.x - newSize) / 2;
323 itemstime_size.x = mySize.x / columns;
325 panel_pos = pos - '1 1 0' * panel_bg_padding;
326 panel_size = mySize + '2 2 0' * panel_bg_padding;
330 if (itemstime_size.x/itemstime_size.y > ar)
332 newSize = ar * itemstime_size.y;
333 offset.x = itemstime_size.x - newSize;
335 itemstime_size.x = newSize;
339 newSize = 1/ar * itemstime_size.x;
340 offset.y = itemstime_size.y - newSize;
342 itemstime_size.y = newSize;
348 float row = 0, column = 0;
350 FOREACH(Items, Item_ItemsTime_Allow(it, '0 0 0') && ItemsTime_time[it.m_id] != -1, LAMBDA(
351 float item_time = ItemsTime_time[it.m_id];
354 item_available = true;
355 item_time = -item_time;
358 item_available = (item_time <= time);
360 if (ItemsTime_time[it.m_id] >= 0)
362 if (time <= ItemsTime_time[it.m_id])
363 ItemsTime_availableTime[it.m_id] = 0;
364 else if (ItemsTime_availableTime[it.m_id] == 0)
365 ItemsTime_availableTime[it.m_id] = time;
367 else if (ItemsTime_availableTime[it.m_id] == 0)
368 ItemsTime_availableTime[it.m_id] = time;
370 float f = (time - ItemsTime_availableTime[it.m_id]) * 2;
371 f = (f > 1) ? 0 : bound(0, f, 1);
373 if (autocvar_hud_panel_itemstime_hidespawned == 1)
374 if (!(ItemsTime_time[it.m_id] > time || -ItemsTime_time[it.m_id] > time))
377 if (autocvar_hud_panel_itemstime_hidespawned == 2)
378 if (!(ItemsTime_time[it.m_id] > time))
381 DrawItemsTimeItem(pos + eX * column * (itemstime_size.x + offset.x) + eY * row * (itemstime_size.y + offset.y), itemstime_size, ar, it, item_time, item_available, f);