]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/items/items.qc
Merge branch 'master' into LegendaryGuard/cyber
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / items / items.qc
index ade4795c523e420e56c77f4f5b5164cbc8250179..27e5a20ea666ace5d5d4a782a8b81c2ddff17649 100644 (file)
@@ -216,6 +216,8 @@ void Item_Respawn(entity this)
 
 void Item_RespawnCountdown(entity this)
 {
+       if(game_timeout) { this.nextthink = time + 1; return; }
+       
        if(this.item_respawncounter >= ITEM_RESPAWN_TICKS)
        {
                if(this.waypointsprite_attached)
@@ -225,7 +227,11 @@ void Item_RespawnCountdown(entity this)
        else
        {
                this.nextthink = time + 1;
-               this.item_respawncounter += 1;
+               this.item_respawncounter = floor((time - game_starttime) - (this.scheduledrespawntime - ITEM_RESPAWN_TICKS)) + 1;
+               //this.item_respawncounter += 1;
+               //LOG_INFOF("Respawncounter: %d", this.item_respawncounter);
+               if(this.item_respawncounter < 1) return;
+               
                if(this.item_respawncounter == 1)
                {
                        do {
@@ -274,12 +280,14 @@ void Item_RespawnCountdown(entity this)
 
 void Item_RespawnThink(entity this)
 {
-       this.nextthink = time;
+       this.nextthink = time + 1;
        if(this.origin != this.oldorigin)
                ItemUpdate(this);
-
-       if(time >= this.wait)
+       
+       if(!game_timeout && time - game_starttime >= this.wait)
                Item_Respawn(this);
+       
+       //LOG_INFOF("time until respawn %d", (this.wait) - (time - game_starttime));
 }
 
 void Item_ScheduleRespawnIn(entity e, float t)
@@ -288,9 +296,12 @@ void Item_ScheduleRespawnIn(entity e, float t)
        if ((Item_ItemsTime_Allow(e.itemdef) || (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS) || MUTATOR_CALLHOOK(Item_ScheduleRespawn, e, t)) && (t - ITEM_RESPAWN_TICKS) > 0)
        {
                setthink(e, Item_RespawnCountdown);
-               e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
-               e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS;
+               //e.nextthink = time - timeout_total_time + max(0, t - ITEM_RESPAWN_TICKS);
+               //e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS;
+               e.nextthink = time;
+               e.scheduledrespawntime = time - game_starttime + t;
                e.item_respawncounter = 0;
+               
                if(Item_ItemsTime_Allow(e.itemdef) || (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS))
                {
                        t = Item_ItemsTime_UpdateTime(e, e.scheduledrespawntime);
@@ -302,8 +313,8 @@ void Item_ScheduleRespawnIn(entity e, float t)
        {
                setthink(e, Item_RespawnThink);
                e.nextthink = time;
-               e.scheduledrespawntime = time + t;
-               e.wait = time + t;
+               e.scheduledrespawntime = time - game_starttime + t;
+               e.wait = time - game_starttime + t;
 
                if(Item_ItemsTime_Allow(e.itemdef) || (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS))
                {
@@ -475,6 +486,15 @@ bool Item_GiveAmmoTo(entity item, entity player, int res_type, float ammomax)
        return true;
 }
 
+void Item_NotifyWeapon(entity player, int wep)
+{
+       if(IS_REAL_CLIENT(player)) {
+               msg_entity = player;
+               WriteHeader(MSG_ONE, TE_CSQC_WEAPONPICKUP);
+               WriteByte(MSG_ONE, wep);
+       }
+}
+
 bool Item_GiveTo(entity item, entity player)
 {
        // if nothing happens to player, just return without taking the item
@@ -509,23 +529,31 @@ bool Item_GiveTo(entity item, entity player)
        pickedup |= Item_GiveAmmoTo(item, player, RES_FUEL, g_pickup_fuel_max);
        if (item.itemdef.instanceOfWeaponPickup)
        {
-               WepSet w;
+               WepSet w, wp;
                w = STAT(WEAPONS, item);
-               w &= ~STAT(WEAPONS, player);
+               wp = w & ~STAT(WEAPONS, player);
 
                if (w || (item.spawnshieldtime && item.pickup_anyway > 0))
                {
                        pickedup = true;
                        FOREACH(Weapons, it != WEP_Null, {
-                               if(w & (it.m_wepset))
+                               Weapon wep = it;
+                               
+                               if(w & (wep.m_wepset)) {
+                                       // z411 Seriously find a better way to do this
+                                       Item_NotifyWeapon(player, wep.m_id);
+                                       FOREACH_CLIENT(IS_SPEC(it) && it.enemy == player, { Item_NotifyWeapon(it, wep.m_id); });
+                               }
+                               
+                               if(wp & (wep.m_wepset))
                                {
                                        for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
                                        {
                                                .entity weaponentity = weaponentities[slot];
                                                if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
-                                                       W_DropEvent(wr_pickup, player, it.m_id, item, weaponentity);
+                                                       W_DropEvent(wr_pickup, player, wep.m_id, item, weaponentity);
                                        }
-                                       W_GiveWeapon(player, it.m_id);
+                                       W_GiveWeapon(player, wep.m_id);
                                }
                        });
                }