X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Fmutators%2Fmutator%2Fitemstime.qc;h=4f4f81fb6d5088d4e4fc1ae4a635ffecee765c29;hb=f41d9f31538bef0259d2b2c74536bb977901f99d;hp=f0db281af8c522f3d23e06898f6f745fca7fa69d;hpb=05bba0fbdbc13bda89061dfdf46ab3b48b62b265;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/mutators/mutator/itemstime.qc b/qcsrc/common/mutators/mutator/itemstime.qc index f0db281af..4f4f81fb6 100644 --- a/qcsrc/common/mutators/mutator/itemstime.qc +++ b/qcsrc/common/mutators/mutator/itemstime.qc @@ -1,47 +1,82 @@ +#ifdef IMPLEMENTATION REGISTER_MUTATOR(itemstime, true); +REGISTER_NET_TEMP(itemstime) + #ifdef SVQC void IT_Write(entity e, int i, float f) { if (!IS_REAL_CLIENT(e)) return; msg_entity = e; - WriteByte(MSG_ONE, SVC_TEMPENTITY); - WriteMutator(MSG_ONE, itemstime); + WriteHeader(MSG_ONE, itemstime); WriteByte(MSG_ONE, i); WriteFloat(MSG_ONE, f); } #endif #ifdef CSQC -float ItemsTime_time[MAX_ITEMS]; -float ItemsTime_availableTime[MAX_ITEMS]; -MUTATOR_HOOKFUNCTION(itemstime, CSQC_Parse_TempEntity) { - if (MUTATOR_RETURNVALUE) return false; - if (!ReadMutatorEquals(mutator_argv_int_0, itemstime)) return false; +float ItemsTime_time[Items_MAX]; +float ItemsTime_availableTime[Items_MAX]; +NET_HANDLE(itemstime, bool isNew) +{ int i = ReadByte(); float f = ReadFloat(); + return = true; ItemsTime_time[i] = f; - return true; } #endif -#ifdef SVQC +#ifdef CSQC +void Item_ItemsTime_Init() +{ + FOREACH(Items, true, LAMBDA( + ItemsTime_time[it.m_id] = -1; + )); +} + +STATIC_INIT(ItemsTime_Init) { + Item_ItemsTime_Init(); +} + +int autocvar_hud_panel_itemstime = 2; +float autocvar_hud_panel_itemstime_dynamicsize = 1; +float autocvar_hud_panel_itemstime_ratio = 2; +int autocvar_hud_panel_itemstime_iconalign; +bool autocvar_hud_panel_itemstime_progressbar = 0; +float autocvar_hud_panel_itemstime_progressbar_maxtime = 30; +string autocvar_hud_panel_itemstime_progressbar_name = "progressbar"; +float autocvar_hud_panel_itemstime_progressbar_reduced; +bool autocvar_hud_panel_itemstime_hidespawned = 1; +bool autocvar_hud_panel_itemstime_hidelarge = false; +int autocvar_hud_panel_itemstime_text = 1; +#define hud_panel_itemstime_hidelarge autocvar_hud_panel_itemstime_hidelarge +#else +#define hud_panel_itemstime_hidelarge false +#endif -bool Item_ItemsTime_Allow(entity e) +bool Item_ItemsTime_SpectatorOnly(GameItem it) { - GameItem it = e.itemdef; - return (false - || it.instanceOfPowerup - || it == ITEM_ArmorMega || it == ITEM_ArmorLarge - || it == ITEM_HealthMega || it == ITEM_HealthLarge - || (e.weapons & WEPSET_SUPERWEAPONS) - ); + return (false + || it == ITEM_ArmorMega || (it == ITEM_ArmorLarge && !hud_panel_itemstime_hidelarge) + || it == ITEM_HealthMega || (it == ITEM_HealthLarge && !hud_panel_itemstime_hidelarge) + ); } -float it_times[MAX_ITEMS]; +bool Item_ItemsTime_Allow(GameItem it, WepSet _weapons) +{ + return (false + || it.instanceOfPowerup + || Item_ItemsTime_SpectatorOnly(it) + || (_weapons & WEPSET_SUPERWEAPONS) + ); +} + +#ifdef SVQC + +float it_times[Items_MAX]; void Item_ItemsTime_Init() { - FOREACH(ITEMS, true, LAMBDA( + FOREACH(Items, true, LAMBDA( it_times[it.m_id] = -1; )); } @@ -53,21 +88,21 @@ STATIC_INIT(ItemsTime_Init) { void Item_ItemsTime_ResetTimes() { - FOREACH(ITEMS, true, LAMBDA( + FOREACH(Items, true, LAMBDA( it_times[it.m_id] = (it_times[it.m_id] == -1) ? -1 : 0; )); } void Item_ItemsTime_ResetTimesForPlayer(entity e) { - FOREACH(ITEMS, true, LAMBDA( + FOREACH(Items, true, LAMBDA( IT_Write(e, it.m_id, (it_times[it.m_id] == -1) ? -1 : 0); )); } void Item_ItemsTime_SetTimesForPlayer(entity e) { - FOREACH(ITEMS, true, LAMBDA( + FOREACH(Items, true, LAMBDA( IT_Write(e, it.m_id, it_times[it.m_id]); )); } @@ -78,63 +113,61 @@ void Item_ItemsTime_SetTime(entity e, float t) return; GameItem item = e.itemdef; - it_times[item.m_id] = t; + if (item.instanceOfGameItem && !item.instanceOfWeaponPickup) + { + it_times[item.m_id] = t; + } } void Item_ItemsTime_SetTimesForAllPlayers() { - entity e; - FOR_EACH_REALCLIENT(e) if (warmup_stage || !IS_PLAYER(e)) - Item_ItemsTime_SetTimesForPlayer(e); + FOREACH_CLIENT(IS_REAL_CLIENT(it) && (warmup_stage || !IS_PLAYER(it)), LAMBDA(Item_ItemsTime_SetTimesForPlayer(it))); } float Item_ItemsTime_UpdateTime(entity e, float t) { bool isavailable = (t == 0); - if (e.weapons & WEPSET_SUPERWEAPONS) - { - for (entity head = world; (head = nextent(head)); ) - { - if (clienttype(head) != CLIENTTYPE_NOTACLIENT || !(head.weapons & WEPSET_SUPERWEAPONS) || head.classname == "weapon_info") - continue; - if (e == head) - continue; - - if (head.scheduledrespawntime <= time) - isavailable = true; - else if (t == 0 || head.scheduledrespawntime < t) - t = head.scheduledrespawntime; - } - } - else - { - for (entity head = world; (head = nextent(head)); ) - { - if (head.itemdef != e.itemdef) - continue; - if (e == head) - continue; - - if (head.scheduledrespawntime <= time) - isavailable = true; - else if (t == 0 || head.scheduledrespawntime < t) - t = head.scheduledrespawntime; - } - } + FOREACH_ENTITY(it.itemdef == e.itemdef || ((it.weapons & WEPSET_SUPERWEAPONS) && clienttype(it) == CLIENTTYPE_NOTACLIENT), LAMBDA( + if (e == it) continue; + if (it.scheduledrespawntime <= time) + isavailable = true; + else if (t == 0 || it.scheduledrespawntime < t) + t = it.scheduledrespawntime; + )); if (isavailable) t = -t; // let know the client there's another available item return t; } -MUTATOR_HOOKFUNCTION(itemstime, reset_map_global) { +MUTATOR_HOOKFUNCTION(itemstime, reset_map_global) +{SELFPARAM(); Item_ItemsTime_ResetTimes(); + // ALL the times need to be reset before .reset()ing each item + // since Item_Reset schedules respawn of superweapons and powerups + FOREACH_ENTITY(IS_NOT_A_CLIENT(it), LAMBDA( + if (it.reset) Item_ItemsTime_SetTime(it, 0); + )); + Item_ItemsTime_SetTimesForAllPlayers(); } -MUTATOR_HOOKFUNCTION(itemstime, MakePlayerObserver) { +MUTATOR_HOOKFUNCTION(itemstime, MakePlayerObserver) +{SELFPARAM(); Item_ItemsTime_SetTimesForPlayer(self); } -MUTATOR_HOOKFUNCTION(itemstime, PlayerSpawn) { +MUTATOR_HOOKFUNCTION(itemstime, ClientConnect, CBC_ORDER_LAST) +{SELFPARAM(); + if(IS_PLAYER(self)) + { + // client became player on connection skipping putObserverInServer step + if (IS_REAL_CLIENT(self)) + if (warmup_stage) + Item_ItemsTime_SetTimesForPlayer(self); + } +} + +MUTATOR_HOOKFUNCTION(itemstime, PlayerSpawn) +{SELFPARAM(); if (warmup_stage) return; Item_ItemsTime_ResetTimesForPlayer(self); } @@ -196,10 +229,15 @@ void DrawItemsTimeItem(vector myPos, vector mySize, float ar, entity item, float 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); } - if (t > 0 && autocvar_hud_panel_itemstime_text) - drawstring_aspect(numpos, ftos(t), eX * ((ar - 1)/ar) * mySize_x + eY * mySize_y, color, panel_fg_alpha, DRAWFLAG_NORMAL); - else - picpos.x = myPos.x + mySize.x / 2 - mySize.y / 2; + if(autocvar_hud_panel_itemstime_text) + { + if(t > 0) + drawstring_aspect(numpos, ftos(t), eX * ((ar - 1)/ar) * mySize_x + eY * mySize_y, color, panel_fg_alpha, DRAWFLAG_NORMAL); + else if(precache_pic("gfx/hud/default/checkmark")) // COMPAT: check if this image exists, as 0.8.1 clients lack it + drawpic_aspect_skin(numpos, "checkmark", eX * (ar - 1) * mySize_y + eY * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL); + else // legacy code, if the image is missing just center the icon + picpos.x = myPos.x + mySize.x / 2 - mySize.y / 2; + } if (item_availableTime) drawpic_aspect_skin_expanding(picpos, item.m_icon, '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL, item_availableTime); drawpic_aspect_skin(picpos, item.m_icon, '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL); @@ -222,17 +260,19 @@ void HUD_ItemsTime() ItemsTime_time[ITEM_Shield.m_id] = time + 4; } - float i; - float count = 0; + int count = 0; if (autocvar_hud_panel_itemstime_hidespawned == 1) - for (i = 0; i < MAX_ITEMS; ++i) - count += (ItemsTime_time[i] > time || -ItemsTime_time[i] > time); + FOREACH(Items, Item_ItemsTime_Allow(it, '0 0 0'), LAMBDA( + count += (ItemsTime_time[it.m_id] > time || -ItemsTime_time[it.m_id] > time); + )); else if (autocvar_hud_panel_itemstime_hidespawned == 2) - for (i = 0; i < MAX_ITEMS; ++i) - count += (ItemsTime_time[i] > time); + FOREACH(Items, Item_ItemsTime_Allow(it, '0 0 0'), LAMBDA( + count += (ItemsTime_time[it.m_id] > time); + )); else - for (i = 0; i < MAX_ITEMS; ++i) - count += (ItemsTime_time[i] != -1); + FOREACH(Items, Item_ItemsTime_Allow(it, '0 0 0'), LAMBDA( + count += (ItemsTime_time[it.m_id] != -1); + )); if (count == 0) return; @@ -303,8 +343,8 @@ void HUD_ItemsTime() float row = 0, column = 0; bool item_available; - FOREACH(ITEMS, ItemsTime_time[i] != -1, LAMBDA( - float item_time = ItemsTime_time[i]; + FOREACH(Items, Item_ItemsTime_Allow(it, '0 0 0') && ItemsTime_time[it.m_id] != -1, LAMBDA( + float item_time = ItemsTime_time[it.m_id]; if (item_time < -1) { item_available = true; @@ -313,25 +353,25 @@ void HUD_ItemsTime() else item_available = (item_time <= time); - if (ItemsTime_time[i] >= 0) + if (ItemsTime_time[it.m_id] >= 0) { - if (time <= ItemsTime_time[i]) - ItemsTime_availableTime[i] = 0; - else if (ItemsTime_availableTime[i] == 0) - ItemsTime_availableTime[i] = time; + if (time <= ItemsTime_time[it.m_id]) + ItemsTime_availableTime[it.m_id] = 0; + else if (ItemsTime_availableTime[it.m_id] == 0) + ItemsTime_availableTime[it.m_id] = time; } - else if (ItemsTime_availableTime[i] == 0) - ItemsTime_availableTime[i] = time; + else if (ItemsTime_availableTime[it.m_id] == 0) + ItemsTime_availableTime[it.m_id] = time; - float f = (time - ItemsTime_availableTime[i]) * 2; + float f = (time - ItemsTime_availableTime[it.m_id]) * 2; f = (f > 1) ? 0 : bound(0, f, 1); if (autocvar_hud_panel_itemstime_hidespawned == 1) - if (!(ItemsTime_time[i] > time || -ItemsTime_time[i] > time)) + if (!(ItemsTime_time[it.m_id] > time || -ItemsTime_time[it.m_id] > time)) continue; if (autocvar_hud_panel_itemstime_hidespawned == 2) - if (!(ItemsTime_time[i] > time)) + if (!(ItemsTime_time[it.m_id] > time)) continue; 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); @@ -345,3 +385,4 @@ void HUD_ItemsTime() } #endif +#endif