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;
29 bool Item_ItemsTime_Allow(entity e)
31 GameItem it = e.itemdef;
33 || it.instanceOfPowerup
34 || it == ITEM_ArmorMega || it == ITEM_ArmorLarge
35 || it == ITEM_HealthMega || it == ITEM_HealthLarge
36 || (e.weapons & WEPSET_SUPERWEAPONS)
40 float it_times[MAX_ITEMS];
42 void Item_ItemsTime_Init()
44 FOREACH(ITEMS, true, LAMBDA(
45 it_times[it.m_id] = -1;
49 STATIC_INIT(ItemsTime_Init) {
51 Item_ItemsTime_Init();
54 void Item_ItemsTime_ResetTimes()
56 FOREACH(ITEMS, true, LAMBDA(
57 it_times[it.m_id] = (it_times[it.m_id] == -1) ? -1 : 0;
61 void Item_ItemsTime_ResetTimesForPlayer(entity e)
63 FOREACH(ITEMS, true, LAMBDA(
64 IT_Write(e, it.m_id, (it_times[it.m_id] == -1) ? -1 : 0);
68 void Item_ItemsTime_SetTimesForPlayer(entity e)
70 FOREACH(ITEMS, true, LAMBDA(
71 IT_Write(e, it.m_id, it_times[it.m_id]);
75 void Item_ItemsTime_SetTime(entity e, float t)
77 if (!autocvar_sv_itemstime)
80 GameItem item = e.itemdef;
81 it_times[item.m_id] = t;
84 void Item_ItemsTime_SetTimesForAllPlayers()
87 FOR_EACH_REALCLIENT(e) if (warmup_stage || !IS_PLAYER(e))
88 Item_ItemsTime_SetTimesForPlayer(e);
91 float Item_ItemsTime_UpdateTime(entity e, float t)
93 bool isavailable = (t == 0);
94 if (e.weapons & WEPSET_SUPERWEAPONS)
96 for (entity head = world; (head = nextent(head)); )
98 if (clienttype(head) != CLIENTTYPE_NOTACLIENT || !(head.weapons & WEPSET_SUPERWEAPONS) || head.classname == "weapon_info")
103 if (head.scheduledrespawntime <= time)
105 else if (t == 0 || head.scheduledrespawntime < t)
106 t = head.scheduledrespawntime;
111 for (entity head = world; (head = nextent(head)); )
113 if (head.itemdef != e.itemdef)
118 if (head.scheduledrespawntime <= time)
120 else if (t == 0 || head.scheduledrespawntime < t)
121 t = head.scheduledrespawntime;
125 t = -t; // let know the client there's another available item
129 MUTATOR_HOOKFUNCTION(itemstime, reset_map_global) {
130 Item_ItemsTime_ResetTimes();
133 MUTATOR_HOOKFUNCTION(itemstime, MakePlayerObserver) {
134 Item_ItemsTime_SetTimesForPlayer(self);
137 MUTATOR_HOOKFUNCTION(itemstime, PlayerSpawn) {
138 if (warmup_stage) return;
139 Item_ItemsTime_ResetTimesForPlayer(self);
146 void DrawItemsTimeItem(vector myPos, vector mySize, float ar, entity item, float item_time, bool item_available, float item_availableTime)
149 vector color = '0 0 0';
152 if (autocvar_hud_panel_itemstime_hidespawned == 2)
154 else if (item_available)
156 float BLINK_FACTOR = 0.15;
157 float BLINK_BASE = 0.85;
158 float BLINK_FREQ = 5;
159 picalpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
163 t = floor(item_time - time + 0.999);
171 vector picpos, numpos;
172 if (autocvar_hud_panel_itemstime_iconalign)
175 picpos = myPos + eX * (ar - 1) * mySize_y;
179 numpos = myPos + eX * mySize_y;
183 if (t > 0 && autocvar_hud_panel_itemstime_progressbar)
185 vector p_pos, p_size;
186 if (autocvar_hud_panel_itemstime_progressbar_reduced)
189 p_size = eX * ((ar - 1)/ar) * mySize_x + eY * mySize_y;
196 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);
199 if (t > 0 && autocvar_hud_panel_itemstime_text)
200 drawstring_aspect(numpos, ftos(t), eX * ((ar - 1)/ar) * mySize_x + eY * mySize_y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
202 picpos.x = myPos.x + mySize.x / 2 - mySize.y / 2;
203 if (item_availableTime)
204 drawpic_aspect_skin_expanding(picpos, item.m_icon, '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL, item_availableTime);
205 drawpic_aspect_skin(picpos, item.m_icon, '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL);
210 if (!autocvar__hud_configure)
213 (autocvar_hud_panel_itemstime == 1 && spectatee_status != 0)
214 || (autocvar_hud_panel_itemstime == 2 && (spectatee_status != 0 || warmup_stage))
219 ItemsTime_time[ITEM_ArmorMega.m_id] = time + 0;
220 ItemsTime_time[ITEM_HealthMega.m_id] = time + 8;
221 ItemsTime_time[ITEM_Strength.m_id] = time + 0;
222 ItemsTime_time[ITEM_Shield.m_id] = time + 4;
227 if (autocvar_hud_panel_itemstime_hidespawned == 1)
228 for (i = 0; i < MAX_ITEMS; ++i)
229 count += (ItemsTime_time[i] > time || -ItemsTime_time[i] > time);
230 else if (autocvar_hud_panel_itemstime_hidespawned == 2)
231 for (i = 0; i < MAX_ITEMS; ++i)
232 count += (ItemsTime_time[i] > time);
234 for (i = 0; i < MAX_ITEMS; ++i)
235 count += (ItemsTime_time[i] != -1);
239 HUD_Panel_UpdateCvars();
245 if (panel_bg_padding)
247 pos += '1 1 0' * panel_bg_padding;
248 mySize -= '2 2 0' * panel_bg_padding;
252 float ar = max(2, autocvar_hud_panel_itemstime_ratio) + 1;
253 rows = HUD_GetRowCount(count, mySize, ar);
254 columns = ceil(count/rows);
256 vector itemstime_size = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
258 vector offset = '0 0 0';
260 if (autocvar_hud_panel_itemstime_dynamicsize)
262 if (autocvar__hud_configure)
263 if (menu_enabled != 2)
264 HUD_Panel_DrawBg(1); // also draw the bg of the entire panel
266 // reduce panel to avoid spacing items
267 if (itemstime_size.x / itemstime_size.y < ar)
269 newSize = rows * itemstime_size.x / ar;
270 pos.y += (mySize.y - newSize) / 2;
272 itemstime_size.y = mySize.y / rows;
276 newSize = columns * itemstime_size.y * ar;
277 pos.x += (mySize.x - newSize) / 2;
279 itemstime_size.x = mySize.x / columns;
281 panel_pos = pos - '1 1 0' * panel_bg_padding;
282 panel_size = mySize + '2 2 0' * panel_bg_padding;
286 if (itemstime_size.x/itemstime_size.y > ar)
288 newSize = ar * itemstime_size.y;
289 offset.x = itemstime_size.x - newSize;
291 itemstime_size.x = newSize;
295 newSize = 1/ar * itemstime_size.x;
296 offset.y = itemstime_size.y - newSize;
298 itemstime_size.y = newSize;
304 float row = 0, column = 0;
306 FOREACH(ITEMS, ItemsTime_time[i] != -1, LAMBDA(
307 float item_time = ItemsTime_time[i];
310 item_available = true;
311 item_time = -item_time;
314 item_available = (item_time <= time);
316 if (ItemsTime_time[i] >= 0)
318 if (time <= ItemsTime_time[i])
319 ItemsTime_availableTime[i] = 0;
320 else if (ItemsTime_availableTime[i] == 0)
321 ItemsTime_availableTime[i] = time;
323 else if (ItemsTime_availableTime[i] == 0)
324 ItemsTime_availableTime[i] = time;
326 float f = (time - ItemsTime_availableTime[i]) * 2;
327 f = (f > 1) ? 0 : bound(0, f, 1);
329 if (autocvar_hud_panel_itemstime_hidespawned == 1)
330 if (!(ItemsTime_time[i] > time || -ItemsTime_time[i] > time))
333 if (autocvar_hud_panel_itemstime_hidespawned == 2)
334 if (!(ItemsTime_time[i] > time))
337 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);