]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/t_items.qc
Merge branch 'master' into terencehill/music_player
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / t_items.qc
index 493ca337dc4822c6bb9d5a1a2b0519db2a359d96..03081ff4b1526e5f3cc0a486aec68f50c874ee23 100644 (file)
@@ -67,6 +67,17 @@ void ItemRead(float _IsNew)
         self.move_angles = self.angles;
     }
 
+    if(sf & ISF_SIZE)
+    {
+        self.mins_x = ReadCoord();
+        self.mins_y = ReadCoord();
+        self.mins_z = ReadCoord();
+        self.maxs_x = ReadCoord();
+        self.maxs_y = ReadCoord();
+        self.maxs_z = ReadCoord();
+        setsize(self, self.mins, self.maxs);
+    }
+
     if(sf & ISF_STATUS) // need to read/write status frist so model can handle simple, fb etc.
     {
         self.ItemStatus = ReadByte();
@@ -110,7 +121,7 @@ void ItemRead(float _IsNew)
     if(sf & ISF_MODEL)
     {
         self.drawmask  = MASK_NORMAL;
-        self.movetype  = MOVETYPE_NOCLIP;
+        self.movetype  = MOVETYPE_TOSS;
         self.draw       = ItemDraw;
 
         if(self.mdl)
@@ -126,14 +137,14 @@ void ItemRead(float _IsNew)
 
 
 
-            if(fexists(sprintf("%s%s.md3", _fn2, autocvr_cl_simpleitems_postfix)))
-                self.mdl = strzone(sprintf("%s%s.md3", _fn2, autocvr_cl_simpleitems_postfix));
-            else if(fexists(sprintf("%s%s.dpm", _fn2, autocvr_cl_simpleitems_postfix)))
-                self.mdl = strzone(sprintf("%s%s.dpm", _fn2, autocvr_cl_simpleitems_postfix));
-            else if(fexists(sprintf("%s%s.iqm", _fn2, autocvr_cl_simpleitems_postfix)))
-                self.mdl = strzone(sprintf("%s%s.iqm", _fn2, autocvr_cl_simpleitems_postfix));
-            else if(fexists(sprintf("%s%s.obj", _fn2, autocvr_cl_simpleitems_postfix)))
-                self.mdl = strzone(sprintf("%s%s.obj", _fn2, autocvr_cl_simpleitems_postfix));
+            if(fexists(sprintf("%s%s.md3", _fn2, autocvar_cl_simpleitems_postfix)))
+                self.mdl = strzone(sprintf("%s%s.md3", _fn2, autocvar_cl_simpleitems_postfix));
+            else if(fexists(sprintf("%s%s.dpm", _fn2, autocvar_cl_simpleitems_postfix)))
+                self.mdl = strzone(sprintf("%s%s.dpm", _fn2, autocvar_cl_simpleitems_postfix));
+            else if(fexists(sprintf("%s%s.iqm", _fn2, autocvar_cl_simpleitems_postfix)))
+                self.mdl = strzone(sprintf("%s%s.iqm", _fn2, autocvar_cl_simpleitems_postfix));
+            else if(fexists(sprintf("%s%s.obj", _fn2, autocvar_cl_simpleitems_postfix)))
+                self.mdl = strzone(sprintf("%s%s.obj", _fn2, autocvar_cl_simpleitems_postfix));
             else
             {
                 self.draw = ItemDraw;
@@ -158,7 +169,7 @@ void ItemRead(float _IsNew)
     if(sf & ISF_DROP)
     {
         self.gravity = 1;
-        self.move_angles = '0 0 0';
+        //self.move_angles = '0 0 0';
         self.move_movetype = MOVETYPE_TOSS;
         self.move_velocity_x = ReadCoord();
         self.move_velocity_y = ReadCoord();
@@ -213,6 +224,16 @@ float ItemSend(entity to, float sf)
         WriteCoord(MSG_ENTITY, self.angles_z);
     }
 
+    if(sf & ISF_SIZE)
+    {
+        WriteCoord(MSG_ENTITY, self.mins_x);
+        WriteCoord(MSG_ENTITY, self.mins_y);
+        WriteCoord(MSG_ENTITY, self.mins_z);
+        WriteCoord(MSG_ENTITY, self.maxs_x);
+        WriteCoord(MSG_ENTITY, self.maxs_y);
+        WriteCoord(MSG_ENTITY, self.maxs_z);
+    }
+
     if(sf & ISF_STATUS)
         WriteByte(MSG_ENTITY, self.ItemStatus);
 
@@ -260,54 +281,12 @@ float have_pickup_item(void)
                if(autocvar_g_pickup_items == 0)
                        return FALSE;
                if(g_weaponarena)
-                       if(self.weapons || (self.items & IT_AMMO))
+                       if(self.weapons || (self.items & IT_AMMO)) // no item or ammo pickups in weaponarena
                                return FALSE;
        }
        return TRUE;
 }
 
-floatfield Item_CounterField(float it)
-{
-       switch(it)
-       {
-               case IT_SHELLS:      return ammo_shells;
-               case IT_NAILS:       return ammo_nails;
-               case IT_ROCKETS:     return ammo_rockets;
-               case IT_CELLS:       return ammo_cells;
-               case IT_FUEL:        return ammo_fuel;
-               case IT_5HP:         return health;
-               case IT_25HP:        return health;
-               case IT_HEALTH:      return health;
-               case IT_ARMOR_SHARD: return armorvalue;
-               case IT_ARMOR:       return armorvalue;
-               // add more things here (health, armor)
-               default:             error("requested item has no counter field");
-       }
-#ifdef GMQCC
-       // should never happen
-       return health;
-#endif
-}
-
-string Item_CounterFieldName(float it)
-{
-       switch(it)
-       {
-               case IT_SHELLS:      return "shells";
-               case IT_NAILS:       return "nails";
-               case IT_ROCKETS:     return "rockets";
-               case IT_CELLS:       return "cells";
-               case IT_FUEL:        return "fuel";
-
-               // add more things here (health, armor)
-               default:             error("requested item has no counter field name");
-       }
-#ifdef GMQCC
-       // should never happen
-       return string_null;
-#endif
-}
-
 /*
 float Item_Customize()
 {
@@ -392,6 +371,16 @@ void Item_Show (entity e, float mode)
     e.SendFlags |= ISF_STATUS;
 }
 
+void Item_Think()
+{
+       self.nextthink = time;
+       if(self.origin != self.oldorigin)
+       {
+               self.oldorigin = self.origin;
+               ItemUpdate(self);
+       }
+}
+
 void Item_Respawn (void)
 {
        Item_Show(self, 1);
@@ -404,6 +393,9 @@ void Item_Respawn (void)
                sound (self, CH_TRIGGER, "misc/itemrespawn.wav", VOL_BASE, ATTEN_NORM); // play respawn sound
        setorigin (self, self.origin);
 
+       self.think = Item_Think;
+       self.nextthink = time;
+       
        //pointparticles(particleeffectnum("item_respawn"), self.origin + self.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
        pointparticles(particleeffectnum("item_respawn"), self.origin + 0.5 * (self.mins + self.maxs), '0 0 0', 1);
 }
@@ -442,7 +434,7 @@ void Item_RespawnCountdown (void)
                                entity wi = get_weaponinfo(self.weapon);
                                if(wi)
                                {
-                                       name = wi.model2;
+                                       name = wi.wpmodel;
                                        rgb = '1 0 0';
                                }
                        }
@@ -467,6 +459,19 @@ void Item_RespawnCountdown (void)
        }
 }
 
+void Item_RespawnThink()
+{
+       self.nextthink = time;
+       if(self.origin != self.oldorigin)
+       {
+               self.oldorigin = self.origin;
+               ItemUpdate(self);
+       }
+
+       if(time >= self.wait)
+               Item_Respawn();
+}
+
 void Item_ScheduleRespawnIn(entity e, float t)
 {
        if((e.flags & FL_POWERUP) || (e.weapons & WEPSET_SUPERWEAPONS))
@@ -477,8 +482,9 @@ void Item_ScheduleRespawnIn(entity e, float t)
        }
        else
        {
-               e.think = Item_Respawn;
-               e.nextthink = time + t;
+               e.think = Item_RespawnThink;
+               e.nextthink = time;
+               e.wait = time + t;
        }
 }
 
@@ -499,25 +505,25 @@ void Item_ScheduleInitialRespawn(entity e)
        Item_ScheduleRespawnIn(e, game_starttime - time + ITEM_RESPAWNTIME_INITIAL(e));
 }
 
-float Item_GiveAmmoTo(entity item, entity player, .float ammofield, float ammomax, float mode)
+float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax, float mode)
 {
-       if (!item.ammofield)
+       if (!item.ammotype)
                return FALSE;
 
        if (item.spawnshieldtime)
        {
-               if ((player.ammofield < ammomax) || item.pickup_anyway)
+               if ((player.ammotype < ammomax) || item.pickup_anyway)
                {
-                       player.ammofield = bound(player.ammofield, ammomax, player.ammofield + item.ammofield);
+                       player.ammotype = bound(player.ammotype, ammomax, player.ammotype + item.ammotype);
                        goto YEAH;
                }
        }
        else if(g_weapon_stay == 2)
        {
-               float mi = min(item.ammofield, ammomax);
-               if (player.ammofield < mi)
+               float mi = min(item.ammotype, ammomax);
+               if (player.ammotype < mi)
                {
-                       player.ammofield = mi;
+                       player.ammotype = mi;
                        goto YEAH;
                }
        }
@@ -567,6 +573,7 @@ float Item_GiveTo(entity item, entity player)
        pickedup |= Item_GiveAmmoTo(item, player, ammo_nails, g_pickup_nails_max, ITEM_MODE_NONE);
        pickedup |= Item_GiveAmmoTo(item, player, ammo_rockets, g_pickup_rockets_max, ITEM_MODE_NONE);
        pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, g_pickup_cells_max, ITEM_MODE_NONE);
+       pickedup |= Item_GiveAmmoTo(item, player, ammo_plasma, g_pickup_plasma_max, ITEM_MODE_NONE);
        pickedup |= Item_GiveAmmoTo(item, player, health, item.max_health, ITEM_MODE_HEALTH);
        pickedup |= Item_GiveAmmoTo(item, player, armorvalue, item.max_armorvalue, ITEM_MODE_ARMOR);
 
@@ -581,7 +588,10 @@ float Item_GiveTo(entity item, entity player)
                        pickedup = TRUE;
                        for(i = WEP_FIRST; i <= WEP_LAST; ++i)
                        if(it & WepSet_FromWeapon(i))
+                       {
+                               W_DropEvent(WR_PICKUP, player, i, item);
                                W_GiveWeapon(player, i);
+                       }
                }
        }
 
@@ -640,12 +650,16 @@ void Item_Touch (void)
 
        if (!IS_PLAYER(other))
                return;
+       if (other.frozen)
+               return;
        if (other.deadflag)
                return;
        if (self.solid != SOLID_TRIGGER)
                return;
        if (self.owner == other)
                return;
+       if (time < self.item_spawnshieldtime)
+               return;
 
        switch(MUTATOR_CALLHOOK(ItemTouch))
        {
@@ -712,8 +726,8 @@ void Item_Reset()
 
        if(self.classname != "droppedweapon")
        {
-               self.think = func_null;
-               self.nextthink = 0;
+               self.think = Item_Think;
+               self.nextthink = time;
 
                if(self.waypointsprite_attached)
                        WaypointSprite_Kill(self.waypointsprite_attached);
@@ -775,7 +789,7 @@ float weapon_pickupevalfunc(entity player, entity item)
                // If I can pick it up
                if(!item.spawnshieldtime)
                        c = 0;
-               else if(player.ammo_cells || player.ammo_shells || player.ammo_nails || player.ammo_rockets)
+               else if(player.ammo_cells || player.ammo_shells || player.ammo_plasma || player.ammo_nails || player.ammo_rockets)
                {
                        // Skilled bots will grab more
                        c = bound(0, skill / 10, 1) * 0.5;
@@ -818,7 +832,7 @@ float weapon_pickupevalfunc(entity player, entity item)
 float commodity_pickupevalfunc(entity player, entity item)
 {
        float c, i;
-       float need_shells = FALSE, need_nails = FALSE, need_rockets = FALSE, need_cells = FALSE, need_fuel = FALSE;
+       float need_shells = FALSE, need_nails = FALSE, need_rockets = FALSE, need_cells = FALSE, need_plasma = FALSE, need_fuel = FALSE;
        entity wi;
        c = 0;
 
@@ -838,8 +852,10 @@ float commodity_pickupevalfunc(entity player, entity item)
                        need_rockets = TRUE;
                else if(wi.items & IT_CELLS)
                        need_cells = TRUE;
+               else if(wi.items & IT_PLASMA)
+                       need_plasma = TRUE;
                else if(wi.items & IT_FUEL)
-                       need_cells = TRUE;
+                       need_fuel = TRUE;
        }
 
        // TODO: figure out if the player even has the weapon this ammo is for?
@@ -861,6 +877,10 @@ float commodity_pickupevalfunc(entity player, entity item)
        if (item.ammo_cells)
        if (player.ammo_cells < g_pickup_cells_max)
                c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
+       if (need_plasma)
+       if (item.ammo_plasma)
+       if (player.ammo_plasma < g_pickup_plasma_max)
+               c = c + max(0, 1 - player.ammo_plasma / g_pickup_plasma_max);
        if (need_fuel)
        if (item.ammo_fuel)
        if (player.ammo_fuel < g_pickup_fuel_max)
@@ -967,9 +987,6 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime,
                        return;
                }
 
-               if(self.angles != '0 0 0')
-            self.SendFlags |= ISF_ANGLES;
-
                self.reset = Item_Reset;
                // it's a level item
                if(self.spawnflags & 1)
@@ -988,6 +1005,7 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime,
                                setsize (self, '-16 -16 0', '16 16 48');
                        else
                                setsize (self, '-16 -16 0', '16 16 32');
+
                        // note droptofloor returns FALSE if stuck/or would fall too far
                        droptofloor();
                        waypoint_spawnforitem(self);
@@ -1091,6 +1109,10 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime,
                Item_Reset();
 
     Net_LinkEntity(self, FALSE, 0, ItemSend);
+       
+       self.SendFlags |= ISF_SIZE;
+       if(self.angles)
+               self.SendFlags |= ISF_ANGLES;
 
        // call this hook after everything else has been done
        if(MUTATOR_CALLHOOK(Item_Spawn))
@@ -1135,6 +1157,15 @@ void spawnfunc_item_cells (void) {
        StartItem ("models/items/a_cells.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "cells", IT_CELLS, 0, 0, commodity_pickupevalfunc, 2000);
 }
 
+void spawnfunc_item_plasma()
+{
+       if(!self.ammo_plasma)
+               self.ammo_plasma = g_pickup_plasma;
+       if(!self.pickup_anyway)
+               self.pickup_anyway = g_pickup_ammo_anyway;
+       StartItem ("models/items/a_cells.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "plasma", IT_PLASMA, 0, 0, commodity_pickupevalfunc, 2000);
+}
+
 void spawnfunc_item_shells (void) {
        if(!weaponswapping)
        if(autocvar_sv_q3acompat_machineshotgunswap)
@@ -1377,6 +1408,7 @@ void spawnfunc_target_items (void)
                if(self.ammo_nails != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_nails), "nails");
                if(self.ammo_rockets != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_rockets), "rockets");
                if(self.ammo_cells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_cells), "cells");
+               if(self.ammo_plasma != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_plasma), "plasma");
                if(self.ammo_fuel != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_fuel), "fuel");
                if(self.health != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "health");
                if(self.armorvalue != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "armor");
@@ -1575,6 +1607,7 @@ float GiveItems(entity e, float beginarg, float endarg)
        PREGIVE(e, superweapons_finished);
        PREGIVE(e, ammo_nails);
        PREGIVE(e, ammo_cells);
+       PREGIVE(e, ammo_plasma);
        PREGIVE(e, ammo_shells);
        PREGIVE(e, ammo_rockets);
        PREGIVE(e, ammo_fuel);
@@ -1628,6 +1661,7 @@ float GiveItems(entity e, float beginarg, float endarg)
                                }
                        case "allammo":
                                got += GiveValue(e, ammo_cells, op, val);
+                               got += GiveValue(e, ammo_plasma, op, val);
                                got += GiveValue(e, ammo_shells, op, val);
                                got += GiveValue(e, ammo_nails, op, val);
                                got += GiveValue(e, ammo_rockets, op, val);
@@ -1660,6 +1694,9 @@ float GiveItems(entity e, float beginarg, float endarg)
                        case "cells":
                                got += GiveValue(e, ammo_cells, op, val);
                                break;
+                       case "plasma":
+                               got += GiveValue(e, ammo_plasma, op, val);
+                               break;
                        case "shells":
                                got += GiveValue(e, ammo_shells, op, val);
                                break;
@@ -1716,6 +1753,7 @@ float GiveItems(entity e, float beginarg, float endarg)
        POSTGIVE_VALUE(e, invincible_finished, 1, "misc/powerup_shield.wav", "misc/poweroff.wav");
        POSTGIVE_VALUE(e, ammo_nails, 0, "misc/itempickup.wav", string_null);
        POSTGIVE_VALUE(e, ammo_cells, 0, "misc/itempickup.wav", string_null);
+       POSTGIVE_VALUE(e, ammo_plasma, 0, "misc/itempickup.wav", string_null);
        POSTGIVE_VALUE(e, ammo_shells, 0, "misc/itempickup.wav", string_null);
        POSTGIVE_VALUE(e, ammo_rockets, 0, "misc/itempickup.wav", string_null);
        POSTGIVE_VALUE_ROT(e, ammo_fuel, 1, pauserotfuel_finished, autocvar_g_balance_pause_fuel_rot, pauseregen_finished, autocvar_g_balance_pause_fuel_regen, "misc/itempickup.wav", string_null);