2 REGISTER_MUTATOR(itemstime, true);
4 REGISTER_NET_TEMP(itemstime)
7 void IT_Write(entity e, int i, float f) {
8 if (!IS_REAL_CLIENT(e)) return;
10 WriteHeader(MSG_ONE, itemstime);
11 WriteByte(MSG_ONE, i);
12 WriteFloat(MSG_ONE, f);
17 float ItemsTime_time[Items_MAX];
18 float ItemsTime_availableTime[Items_MAX];
19 NET_HANDLE(itemstime, bool isNew)
22 float f = ReadFloat();
24 ItemsTime_time[i] = f;
29 void Item_ItemsTime_Init()
31 FOREACH(Items, true, LAMBDA(
32 ItemsTime_time[it.m_id] = -1;
36 STATIC_INIT(ItemsTime_Init) {
37 Item_ItemsTime_Init();
40 int autocvar_hud_panel_itemstime = 2;
41 float autocvar_hud_panel_itemstime_dynamicsize = 1;
42 float autocvar_hud_panel_itemstime_ratio = 2;
43 int autocvar_hud_panel_itemstime_iconalign;
44 bool autocvar_hud_panel_itemstime_progressbar = 0;
45 float autocvar_hud_panel_itemstime_progressbar_maxtime = 30;
46 string autocvar_hud_panel_itemstime_progressbar_name = "progressbar";
47 float autocvar_hud_panel_itemstime_progressbar_reduced;
48 bool autocvar_hud_panel_itemstime_hidespawned = 1;
49 bool autocvar_hud_panel_itemstime_hidelarge = false;
50 int autocvar_hud_panel_itemstime_text = 1;
51 #define hud_panel_itemstime_hidelarge autocvar_hud_panel_itemstime_hidelarge
53 #define hud_panel_itemstime_hidelarge false
56 bool Item_ItemsTime_SpectatorOnly(GameItem it)
59 || it == ITEM_ArmorMega || (it == ITEM_ArmorLarge && !hud_panel_itemstime_hidelarge)
60 || it == ITEM_HealthMega || (it == ITEM_HealthLarge && !hud_panel_itemstime_hidelarge)
64 bool Item_ItemsTime_Allow(GameItem it, WepSet _weapons)
67 || it.instanceOfPowerup
68 || Item_ItemsTime_SpectatorOnly(it)
69 || (_weapons & WEPSET_SUPERWEAPONS)
75 float it_times[Items_MAX];
77 void Item_ItemsTime_Init()
79 FOREACH(Items, Item_ItemsTime_Allow(it, '0 0 0'), LAMBDA(
80 it_times[it.m_id] = -1;
84 STATIC_INIT(ItemsTime_Init) {
86 Item_ItemsTime_Init();
89 void Item_ItemsTime_ResetTimes()
91 FOREACH(Items, Item_ItemsTime_Allow(it, '0 0 0'), LAMBDA(
92 it_times[it.m_id] = (it_times[it.m_id] == -1) ? -1 : 0;
96 void Item_ItemsTime_ResetTimesForPlayer(entity e)
98 FOREACH(Items, Item_ItemsTime_Allow(it, '0 0 0'), LAMBDA(
99 IT_Write(e, it.m_id, (it_times[it.m_id] == -1) ? -1 : 0);
103 void Item_ItemsTime_SetTimesForPlayer(entity e)
105 FOREACH(Items, Item_ItemsTime_Allow(it, '0 0 0'), LAMBDA(
106 IT_Write(e, it.m_id, it_times[it.m_id]);
110 void Item_ItemsTime_SetTime(entity e, float t)
112 if (!autocvar_sv_itemstime)
115 GameItem item = e.itemdef;
116 if (item.instanceOfGameItem && !item.instanceOfWeaponPickup)
118 it_times[item.m_id] = t;
122 void Item_ItemsTime_SetTimesForAllPlayers()
124 FOREACH_CLIENT(IS_REAL_CLIENT(it) && (warmup_stage || !IS_PLAYER(it)), LAMBDA(Item_ItemsTime_SetTimesForPlayer(it)));
127 float Item_ItemsTime_UpdateTime(entity e, float t)
129 bool isavailable = (t == 0);
130 FOREACH_ENTITY(it.itemdef == e.itemdef || ((it.weapons & WEPSET_SUPERWEAPONS) && clienttype(it) == CLIENTTYPE_NOTACLIENT), LAMBDA(
131 if (e == it) continue;
132 if (it.scheduledrespawntime <= time)
134 else if (t == 0 || it.scheduledrespawntime < t)
135 t = it.scheduledrespawntime;
138 t = -t; // let know the client there's another available item
142 MUTATOR_HOOKFUNCTION(itemstime, reset_map_global)
144 Item_ItemsTime_ResetTimes();
145 // ALL the times need to be reset before .reset()ing each item
146 // since Item_Reset schedules respawn of superweapons and powerups
147 FOREACH_ENTITY(IS_NOT_A_CLIENT(it), LAMBDA(
148 if (it.reset) Item_ItemsTime_SetTime(it, 0);
150 Item_ItemsTime_SetTimesForAllPlayers();
153 MUTATOR_HOOKFUNCTION(itemstime, MakePlayerObserver)
155 Item_ItemsTime_SetTimesForPlayer(self);
158 MUTATOR_HOOKFUNCTION(itemstime, ClientConnect, CBC_ORDER_LAST)
162 // client became player on connection skipping putObserverInServer step
163 if (IS_REAL_CLIENT(self))
165 Item_ItemsTime_SetTimesForPlayer(self);
169 MUTATOR_HOOKFUNCTION(itemstime, PlayerSpawn)
171 if (warmup_stage) return;
172 Item_ItemsTime_ResetTimesForPlayer(self);
179 void DrawItemsTimeItem(vector myPos, vector mySize, float ar, entity item, float item_time, bool item_available, float item_availableTime)
182 vector color = '0 0 0';
185 if (autocvar_hud_panel_itemstime_hidespawned == 2)
187 else if (item_available)
189 float BLINK_FACTOR = 0.15;
190 float BLINK_BASE = 0.85;
191 float BLINK_FREQ = 5;
192 picalpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
196 t = floor(item_time - time + 0.999);
204 vector picpos, numpos;
205 if (autocvar_hud_panel_itemstime_iconalign)
208 picpos = myPos + eX * (ar - 1) * mySize_y;
212 numpos = myPos + eX * mySize_y;
216 if (t > 0 && autocvar_hud_panel_itemstime_progressbar)
218 vector p_pos, p_size;
219 if (autocvar_hud_panel_itemstime_progressbar_reduced)
222 p_size = eX * ((ar - 1)/ar) * mySize_x + eY * mySize_y;
229 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);
232 if(autocvar_hud_panel_itemstime_text)
235 drawstring_aspect(numpos, ftos(t), eX * ((ar - 1)/ar) * mySize_x + eY * mySize_y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
236 else if(precache_pic("gfx/hud/default/checkmark")) // COMPAT: check if this image exists, as 0.8.1 clients lack it
237 drawpic_aspect_skin(numpos, "checkmark", eX * (ar - 1) * mySize_y + eY * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL);
238 else // legacy code, if the image is missing just center the icon
239 picpos.x = myPos.x + mySize.x / 2 - mySize.y / 2;
241 if (item_availableTime)
242 drawpic_aspect_skin_expanding(picpos, item.m_icon, '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL, item_availableTime);
243 drawpic_aspect_skin(picpos, item.m_icon, '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL);
248 if (!autocvar__hud_configure)
251 (autocvar_hud_panel_itemstime == 1 && spectatee_status != 0)
252 || (autocvar_hud_panel_itemstime == 2 && (spectatee_status != 0 || warmup_stage))
257 ItemsTime_time[ITEM_ArmorMega.m_id] = time + 0;
258 ItemsTime_time[ITEM_HealthMega.m_id] = time + 8;
259 ItemsTime_time[ITEM_Strength.m_id] = time + 0;
260 ItemsTime_time[ITEM_Shield.m_id] = time + 4;
264 if (autocvar_hud_panel_itemstime_hidespawned == 1)
265 FOREACH(Items, Item_ItemsTime_Allow(it, '0 0 0'), LAMBDA(
266 count += (ItemsTime_time[it.m_id] > time || -ItemsTime_time[it.m_id] > time);
268 else if (autocvar_hud_panel_itemstime_hidespawned == 2)
269 FOREACH(Items, Item_ItemsTime_Allow(it, '0 0 0'), LAMBDA(
270 count += (ItemsTime_time[it.m_id] > time);
273 FOREACH(Items, Item_ItemsTime_Allow(it, '0 0 0'), LAMBDA(
274 count += (ItemsTime_time[it.m_id] != -1);
279 HUD_Panel_UpdateCvars();
285 if (panel_bg_padding)
287 pos += '1 1 0' * panel_bg_padding;
288 mySize -= '2 2 0' * panel_bg_padding;
292 float ar = max(2, autocvar_hud_panel_itemstime_ratio) + 1;
293 rows = HUD_GetRowCount(count, mySize, ar);
294 columns = ceil(count/rows);
296 vector itemstime_size = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
298 vector offset = '0 0 0';
300 if (autocvar_hud_panel_itemstime_dynamicsize)
302 if (autocvar__hud_configure)
303 if (menu_enabled != 2)
304 HUD_Panel_DrawBg(1); // also draw the bg of the entire panel
306 // reduce panel to avoid spacing items
307 if (itemstime_size.x / itemstime_size.y < ar)
309 newSize = rows * itemstime_size.x / ar;
310 pos.y += (mySize.y - newSize) / 2;
312 itemstime_size.y = mySize.y / rows;
316 newSize = columns * itemstime_size.y * ar;
317 pos.x += (mySize.x - newSize) / 2;
319 itemstime_size.x = mySize.x / columns;
321 panel_pos = pos - '1 1 0' * panel_bg_padding;
322 panel_size = mySize + '2 2 0' * panel_bg_padding;
326 if (itemstime_size.x/itemstime_size.y > ar)
328 newSize = ar * itemstime_size.y;
329 offset.x = itemstime_size.x - newSize;
331 itemstime_size.x = newSize;
335 newSize = 1/ar * itemstime_size.x;
336 offset.y = itemstime_size.y - newSize;
338 itemstime_size.y = newSize;
344 float row = 0, column = 0;
346 FOREACH(Items, Item_ItemsTime_Allow(it, '0 0 0') && ItemsTime_time[it.m_id] != -1, LAMBDA(
347 float item_time = ItemsTime_time[it.m_id];
350 item_available = true;
351 item_time = -item_time;
354 item_available = (item_time <= time);
356 if (ItemsTime_time[it.m_id] >= 0)
358 if (time <= ItemsTime_time[it.m_id])
359 ItemsTime_availableTime[it.m_id] = 0;
360 else if (ItemsTime_availableTime[it.m_id] == 0)
361 ItemsTime_availableTime[it.m_id] = time;
363 else if (ItemsTime_availableTime[it.m_id] == 0)
364 ItemsTime_availableTime[it.m_id] = time;
366 float f = (time - ItemsTime_availableTime[it.m_id]) * 2;
367 f = (f > 1) ? 0 : bound(0, f, 1);
369 if (autocvar_hud_panel_itemstime_hidespawned == 1)
370 if (!(ItemsTime_time[it.m_id] > time || -ItemsTime_time[it.m_id] > time))
373 if (autocvar_hud_panel_itemstime_hidespawned == 2)
374 if (!(ItemsTime_time[it.m_id] > time))
377 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);