1 REGISTER_MUTATOR(itemstime, true);
4 void IT_Write(entity e, int i, float f) {
5 if (!IS_REAL_CLIENT(e)) return;
7 WriteByte(MSG_ONE, SVC_TEMPENTITY);
8 WriteMutator(MSG_ONE, itemstime);
10 WriteFloat(MSG_ONE, f);
15 float ItemsTime_time[MAX_ITEMS];
16 float ItemsTime_availableTime[MAX_ITEMS];
17 MUTATOR_HOOKFUNCTION(itemstime, CSQC_Parse_TempEntity) {
18 if (MUTATOR_RETURNVALUE) return false;
19 if (!ReadMutatorEquals(mutator_argv_int_0, itemstime)) return false;
21 float f = ReadFloat();
22 ItemsTime_time[i] = f;
28 int autocvar_hud_panel_itemstime = 2;
29 float autocvar_hud_panel_itemstime_dynamicsize = 1;
30 float autocvar_hud_panel_itemstime_ratio = 2;
31 int autocvar_hud_panel_itemstime_iconalign;
32 bool autocvar_hud_panel_itemstime_progressbar = 0;
33 float autocvar_hud_panel_itemstime_progressbar_maxtime = 30;
34 string autocvar_hud_panel_itemstime_progressbar_name = "progressbar";
35 float autocvar_hud_panel_itemstime_progressbar_reduced;
36 bool autocvar_hud_panel_itemstime_hidespawned = 1;
37 bool autocvar_hud_panel_itemstime_hidelarge = false;
38 int autocvar_hud_panel_itemstime_text = 1;
39 #define hud_panel_itemstime_hidelarge autocvar_hud_panel_itemstime_hidelarge
41 #define hud_panel_itemstime_hidelarge false
44 bool Item_ItemsTime_SpectatorOnly(GameItem it)
47 || it == ITEM_ArmorMega || (it == ITEM_ArmorLarge && !hud_panel_itemstime_hidelarge)
48 || it == ITEM_HealthMega || (it == ITEM_HealthLarge && !hud_panel_itemstime_hidelarge)
52 bool Item_ItemsTime_Allow(GameItem it, WepSet _weapons)
55 || it.instanceOfPowerup
56 || Item_ItemsTime_SpectatorOnly(it)
57 || (_weapons & WEPSET_SUPERWEAPONS)
63 float it_times[MAX_ITEMS];
65 void Item_ItemsTime_Init()
67 FOREACH(ITEMS, true, LAMBDA(
68 it_times[it.m_id] = -1;
72 STATIC_INIT(ItemsTime_Init) {
74 Item_ItemsTime_Init();
77 void Item_ItemsTime_ResetTimes()
79 FOREACH(ITEMS, true, LAMBDA(
80 it_times[it.m_id] = (it_times[it.m_id] == -1) ? -1 : 0;
84 void Item_ItemsTime_ResetTimesForPlayer(entity e)
86 FOREACH(ITEMS, true, LAMBDA(
87 IT_Write(e, it.m_id, (it_times[it.m_id] == -1) ? -1 : 0);
91 void Item_ItemsTime_SetTimesForPlayer(entity e)
93 FOREACH(ITEMS, true, LAMBDA(
94 IT_Write(e, it.m_id, it_times[it.m_id]);
98 void Item_ItemsTime_SetTime(entity e, float t)
100 if (!autocvar_sv_itemstime)
103 GameItem item = e.itemdef;
104 it_times[item.m_id] = t;
107 void Item_ItemsTime_SetTimesForAllPlayers()
110 FOR_EACH_REALCLIENT(e) if (warmup_stage || !IS_PLAYER(e))
111 Item_ItemsTime_SetTimesForPlayer(e);
114 float Item_ItemsTime_UpdateTime(entity e, float t)
116 bool isavailable = (t == 0);
117 if (e.weapons & WEPSET_SUPERWEAPONS)
119 for (entity head = world; (head = nextent(head)); )
121 if (clienttype(head) != CLIENTTYPE_NOTACLIENT || !(head.weapons & WEPSET_SUPERWEAPONS) || head.classname == "weapon_info")
126 if (head.scheduledrespawntime <= time)
128 else if (t == 0 || head.scheduledrespawntime < t)
129 t = head.scheduledrespawntime;
134 for (entity head = world; (head = nextent(head)); )
136 if (head.itemdef != e.itemdef)
141 if (head.scheduledrespawntime <= time)
143 else if (t == 0 || head.scheduledrespawntime < t)
144 t = head.scheduledrespawntime;
148 t = -t; // let know the client there's another available item
152 MUTATOR_HOOKFUNCTION(itemstime, reset_map_global) {
153 Item_ItemsTime_ResetTimes();
154 // ALL the times need to be reset before .reset()ing each item
155 // since Item_Reset schedules respawn of superweapons and powerups
156 for (self = world; (self = nextent(self)); )
157 if (IS_NOT_A_CLIENT(self))
160 Item_ItemsTime_SetTime(self, 0);
162 Item_ItemsTime_SetTimesForAllPlayers();
165 MUTATOR_HOOKFUNCTION(itemstime, MakePlayerObserver) {
166 Item_ItemsTime_SetTimesForPlayer(self);
169 MUTATOR_HOOKFUNCTION(itemstime, PlayerSpawn) {
170 if (warmup_stage) return;
171 Item_ItemsTime_ResetTimesForPlayer(self);
178 void DrawItemsTimeItem(vector myPos, vector mySize, float ar, entity item, float item_time, bool item_available, float item_availableTime)
181 vector color = '0 0 0';
184 if (autocvar_hud_panel_itemstime_hidespawned == 2)
186 else if (item_available)
188 float BLINK_FACTOR = 0.15;
189 float BLINK_BASE = 0.85;
190 float BLINK_FREQ = 5;
191 picalpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
195 t = floor(item_time - time + 0.999);
203 vector picpos, numpos;
204 if (autocvar_hud_panel_itemstime_iconalign)
207 picpos = myPos + eX * (ar - 1) * mySize_y;
211 numpos = myPos + eX * mySize_y;
215 if (t > 0 && autocvar_hud_panel_itemstime_progressbar)
217 vector p_pos, p_size;
218 if (autocvar_hud_panel_itemstime_progressbar_reduced)
221 p_size = eX * ((ar - 1)/ar) * mySize_x + eY * mySize_y;
228 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);
231 if(autocvar_hud_panel_itemstime_text)
234 drawstring_aspect(numpos, ftos(t), eX * ((ar - 1)/ar) * mySize_x + eY * mySize_y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
235 else if(precache_pic("gfx/hud/default/checkmark")) // COMPAT: check if this image exists, as 0.8.1 clients lack it
236 drawpic_aspect_skin(numpos, "checkmark", eX * (ar - 1) * mySize_y + eY * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL);
237 else // legacy code, if the image is missing just center the icon
238 picpos.x = myPos.x + mySize.x / 2 - mySize.y / 2;
240 if (item_availableTime)
241 drawpic_aspect_skin_expanding(picpos, item.m_icon, '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL, item_availableTime);
242 drawpic_aspect_skin(picpos, item.m_icon, '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL);
247 if (!autocvar__hud_configure)
250 (autocvar_hud_panel_itemstime == 1 && spectatee_status != 0)
251 || (autocvar_hud_panel_itemstime == 2 && (spectatee_status != 0 || warmup_stage))
256 ItemsTime_time[ITEM_ArmorMega.m_id] = time + 0;
257 ItemsTime_time[ITEM_HealthMega.m_id] = time + 8;
258 ItemsTime_time[ITEM_Strength.m_id] = time + 0;
259 ItemsTime_time[ITEM_Shield.m_id] = time + 4;
263 if (autocvar_hud_panel_itemstime_hidespawned == 1)
264 FOREACH(ITEMS, Item_ItemsTime_Allow(it, '0 0 0'), LAMBDA(
265 count += (ItemsTime_time[i] > time || -ItemsTime_time[i] > time);
267 else if (autocvar_hud_panel_itemstime_hidespawned == 2)
268 FOREACH(ITEMS, Item_ItemsTime_Allow(it, '0 0 0'), LAMBDA(
269 count += (ItemsTime_time[i] > time);
272 FOREACH(ITEMS, Item_ItemsTime_Allow(it, '0 0 0'), LAMBDA(
273 count += (ItemsTime_time[i] != -1);
278 HUD_Panel_UpdateCvars();
284 if (panel_bg_padding)
286 pos += '1 1 0' * panel_bg_padding;
287 mySize -= '2 2 0' * panel_bg_padding;
291 float ar = max(2, autocvar_hud_panel_itemstime_ratio) + 1;
292 rows = HUD_GetRowCount(count, mySize, ar);
293 columns = ceil(count/rows);
295 vector itemstime_size = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
297 vector offset = '0 0 0';
299 if (autocvar_hud_panel_itemstime_dynamicsize)
301 if (autocvar__hud_configure)
302 if (menu_enabled != 2)
303 HUD_Panel_DrawBg(1); // also draw the bg of the entire panel
305 // reduce panel to avoid spacing items
306 if (itemstime_size.x / itemstime_size.y < ar)
308 newSize = rows * itemstime_size.x / ar;
309 pos.y += (mySize.y - newSize) / 2;
311 itemstime_size.y = mySize.y / rows;
315 newSize = columns * itemstime_size.y * ar;
316 pos.x += (mySize.x - newSize) / 2;
318 itemstime_size.x = mySize.x / columns;
320 panel_pos = pos - '1 1 0' * panel_bg_padding;
321 panel_size = mySize + '2 2 0' * panel_bg_padding;
325 if (itemstime_size.x/itemstime_size.y > ar)
327 newSize = ar * itemstime_size.y;
328 offset.x = itemstime_size.x - newSize;
330 itemstime_size.x = newSize;
334 newSize = 1/ar * itemstime_size.x;
335 offset.y = itemstime_size.y - newSize;
337 itemstime_size.y = newSize;
343 float row = 0, column = 0;
345 FOREACH(ITEMS, Item_ItemsTime_Allow(it, '0 0 0') && ItemsTime_time[i] != -1, LAMBDA(
346 float item_time = ItemsTime_time[i];
349 item_available = true;
350 item_time = -item_time;
353 item_available = (item_time <= time);
355 if (ItemsTime_time[i] >= 0)
357 if (time <= ItemsTime_time[i])
358 ItemsTime_availableTime[i] = 0;
359 else if (ItemsTime_availableTime[i] == 0)
360 ItemsTime_availableTime[i] = time;
362 else if (ItemsTime_availableTime[i] == 0)
363 ItemsTime_availableTime[i] = time;
365 float f = (time - ItemsTime_availableTime[i]) * 2;
366 f = (f > 1) ? 0 : bound(0, f, 1);
368 if (autocvar_hud_panel_itemstime_hidespawned == 1)
369 if (!(ItemsTime_time[i] > time || -ItemsTime_time[i] > time))
372 if (autocvar_hud_panel_itemstime_hidespawned == 2)
373 if (!(ItemsTime_time[i] > time))
376 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);