]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/items/items.qc
Merge branch 'master' into z411/bai-server
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / items / items.qc
index ed8ba9a52e7dbe79a801f088dec2a5a3cc2c845b..86ede0b7bd20cd481dc0830905737dfb188d70d6 100644 (file)
@@ -36,6 +36,24 @@ bool ItemSend(entity this, entity to, int sf)
        else
                sf &= ~ISF_DROP;
 
+       // if this item is being spawned (in CSQC's perspective)
+       // reuse ISF_SIZE and ISF_SIZE2 to also tell CSQC its bbox size
+       if(sf & ISF_SIZE)
+       {
+               if(this.maxs == ITEM_S_MAXS) // Small
+               {
+                       sf |= ISF_SIZE;
+                       sf &= ~ISF_SIZE2;
+               }
+               else if(this.maxs == ITEM_L_MAXS) // Large
+               {
+                       sf &= ~ISF_SIZE;
+                       sf |= ISF_SIZE2;
+               }
+               else // Default
+                       sf |= ISF_SIZE | ISF_SIZE2;
+       }
+
        WriteHeader(MSG_ENTITY, ENT_CLIENT_ITEM);
        WriteByte(MSG_ENTITY, sf);
 
@@ -50,13 +68,10 @@ bool ItemSend(entity this, entity to, int sf)
                WriteAngleVector(MSG_ENTITY, this.angles);
        }
 
-       // sets size on the client, unused on server
-       //if(sf & ISF_SIZE)
-
        if(sf & ISF_STATUS)
                WriteByte(MSG_ENTITY, this.ItemStatus);
 
-       if(sf & ISF_MODEL)
+       if(sf & ISF_SIZE || sf & ISF_SIZE2) // always true when it's spawned (in CSQC's perspective)
        {
                WriteShort(MSG_ENTITY, bound(0, this.fade_end, 32767));
 
@@ -242,6 +257,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)
@@ -251,7 +268,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 {
@@ -300,12 +321,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)
@@ -314,9 +337,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);
@@ -328,8 +354,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))
                {
@@ -542,6 +568,13 @@ bool Item_GiveTo(entity item, entity player)
        pickedup |= Item_GiveAmmoTo(item, player, RES_CELLS, g_pickup_cells_max);
        pickedup |= Item_GiveAmmoTo(item, player, RES_PLASMA, g_pickup_plasma_max);
        pickedup |= Item_GiveAmmoTo(item, player, RES_FUEL, g_pickup_fuel_max);
+       
+       // for RJZ
+       if (autocvar_rjz_count_shards && !warmup_stage && item.itemdef == ITEM_ArmorSmall) {
+               total_shards++;
+               send_TotalShardsAll();
+       }
+       
        if (item.itemdef.instanceOfWeaponPickup)
        {
                WepSet w, wp;
@@ -577,8 +610,8 @@ bool Item_GiveTo(entity item, entity player)
                        Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_JETPACK_GOT);
        }
 
-       int its;
-       if((its = (item.items - ((item.items & player.items)) & IT_PICKUPMASK)))
+       int its = (item.items - (item.items & player.items)) & IT_PICKUPMASK;
+       if (its)
        {
                pickedup = true;
                player.items |= its;
@@ -1046,6 +1079,9 @@ void StartItem(entity this, entity def)
                        this.nextthink = max(this.strength_finished, this.invincible_finished, this.superweapons_finished);
                }
 
+               // most loot items have a bigger horizontal size than a player
+               nudgeoutofsolid(this);
+
                // don't drop if in a NODROP zone (such as lava)
                traceline(this.origin, this.origin, MOVE_NORMAL, this);
                if (trace_dpstartcontents & DPCONTENTS_NODROP)
@@ -1082,11 +1118,19 @@ void StartItem(entity this, entity def)
                if(this.angles != '0 0 0')
                        this.SendFlags |= ISF_ANGLES;
 
-               if(q3compat && !this.team)
+               if(q3compat)
                {
-                       string t = GetField_fullspawndata(this, "team");
-                       // bones_was_here: this hack is cheaper than changing to a .string strcmp()
-                       if(t) this.team = crc16(false, t);
+                       if (!this.team)
+                       {
+                               string t = GetField_fullspawndata(this, "team");
+                               // bones_was_here: this hack is cheaper than changing to a .string strcmp()
+                               if(t) this.team = crc16(false, t);
+                       }
+
+                       // In Q3 the origin is in the middle of the bbox ("radius" 15), in Xon it's at the bottom
+                       // so we need to offset vertically (only for items placed by the mapper).
+                       this.origin.z += -15 - this.mins.z;
+                       setorigin(this, this.origin);
                }
 
                // it's a level item
@@ -1099,8 +1143,6 @@ void StartItem(entity this, entity def)
                // do item filtering according to game mode and other things
                if (this.noalign <= 0)
                {
-                       // first nudge it off the floor a little bit to avoid math errors
-                       setorigin(this, this.origin + '0 0 1');
                        // note droptofloor returns false if stuck/or would fall too far
                        if (!this.noalign)
                                droptofloor(this);
@@ -1251,7 +1293,7 @@ void setItemGroup(entity this)
 
 void setItemGroupCount()
 {
-       for (int k = 1; k <= group_count; k++)
+       for (int k = 1; k <= group_count; ++k)
        {
                int count = 0;
                IL_EACH(g_items, IS_SMALL(it.itemdef) && it.item_group == k, { count++; });