]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'master' into Lyberta/GivePlayerAmmo
authorMario <mario@smbclan.net>
Sun, 27 Aug 2017 12:41:08 +0000 (22:41 +1000)
committerMario <mario@smbclan.net>
Sun, 27 Aug 2017 12:41:08 +0000 (22:41 +1000)
qcsrc/common/mutators/mutator/vampire/sv_vampire.qc
qcsrc/common/t_items.qc
qcsrc/common/t_items.qh
qcsrc/server/client.qc

index 3a435c5ed1dea13ad797e4097e1a79c749b319cf..92c5943c3d75455f7bc3d41b6f95184df7ba8555 100644 (file)
@@ -12,8 +12,7 @@ MUTATOR_HOOKFUNCTION(vampire, PlayerDamage_SplitHealthArmor)
        if(frag_target != frag_attacker)
        if(!IS_DEAD(frag_target))
        {
-               frag_attacker.health += bound(0, damage_take, frag_target.health);
-               frag_attacker.health = bound(0, frag_attacker.health, autocvar_g_balance_health_limit);
+               GivePlayerHealth(frag_attacker, bound(0, damage_take, frag_target.health));
        }
 }
 
index f5b3b2c19f7122bc0cfbe45cf10b1dfa8e9e0f22..e47b98a663c7b498db2baa37c5bdae224daafcf2 100644 (file)
@@ -648,7 +648,119 @@ void Item_ScheduleInitialRespawn(entity e)
        Item_ScheduleRespawnIn(e, max(0, game_starttime - time) + ((e.respawntimestart) ? e.respawntimestart : ITEM_RESPAWNTIME_INITIAL(e)));
 }
 
-float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax, float mode)
+void GivePlayerResource(entity player, .float resource_type, float amount)
+{
+       if (amount == 0)
+       {
+               return;
+       }
+       switch (resource_type)
+       {
+               case health:
+               {
+                       // Ugly hack. We do not check if health goes beyond hard limit since
+                       // currently it is done in player_regen. We need to bring back this
+                       // check when other code is ported to this function.
+                       player.health = bound(player.health, player.health + amount,
+                               autocvar_g_balance_health_limit);
+                       // Correct code:
+                       //player.health = bound(player.health, player.health + amount,
+                       //      min(autocvar_g_balance_health_limit,
+                       //      RESOURCE_AMOUNT_HARD_LIMIT));
+                       player.pauserothealth_finished = max(player.pauserothealth_finished,
+                               time + autocvar_g_balance_pause_health_rot);
+                       return;
+               }
+               case armorvalue:
+               {
+                       // Ugly hack. We do not check if armor goes beyond hard limit since
+                       // currently it is done in player_regen. We need to bring back this
+                       // check when other code is ported to this function.
+                       player.armorvalue = bound(player.armorvalue, player.armorvalue +
+                               amount, autocvar_g_balance_armor_limit);
+                       // Correct code:
+                       //player.armorvalue = bound(player.armorvalue, player.armorvalue +
+                       //      amount, min(autocvar_g_balance_armor_limit,
+                       //      RESOURCE_AMOUNT_HARD_LIMIT));
+                       player.pauserotarmor_finished = max(player.pauserotarmor_finished,
+                               time + autocvar_g_balance_pause_armor_rot);
+                       return;
+               }
+               case ammo_shells:
+               case ammo_nails:
+               case ammo_rockets:
+               case ammo_cells:
+               case ammo_plasma:
+               {
+                       GivePlayerAmmo(player, resource_type, amount);
+                       return;
+               }
+               case ammo_fuel:
+               {
+                       player.ammo_fuel = bound(player.ammo_fuel, player.ammo_fuel +
+                               amount, min(g_pickup_fuel_max, RESOURCE_AMOUNT_HARD_LIMIT));
+                       player.pauserotfuel_finished = max(player.pauserotfuel_finished,
+                               time + autocvar_g_balance_pause_fuel_rot);
+                       return;
+               }
+       }
+}
+
+void GivePlayerHealth(entity player, float amount)
+{
+       GivePlayerResource(player, health, amount);
+}
+
+void GivePlayerArmor(entity player, float amount)
+{
+       GivePlayerResource(player, armorvalue, amount);
+}
+
+void GivePlayerAmmo(entity player, .float ammotype, float amount)
+{
+       if (amount == 0)
+       {
+               return;
+       }
+       float maxvalue = RESOURCE_AMOUNT_HARD_LIMIT;
+       switch (ammotype)
+       {
+               case ammo_shells:
+               {
+                       maxvalue = g_pickup_shells_max;
+                       break;
+               }
+               case ammo_cells:
+               {
+                       maxvalue = g_pickup_cells_max;
+                       break;
+               }
+               case ammo_rockets:
+               {
+                       maxvalue = g_pickup_rockets_max;
+                       break;
+               }
+               case ammo_plasma:
+               {
+                       maxvalue = g_pickup_plasma_max;
+                       break;
+               }
+               case ammo_nails:
+               {
+                       maxvalue = g_pickup_nails_max;
+                       break;
+               }
+       }
+       player.(ammotype) = min(player.(ammotype) + amount,
+               min(maxvalue, RESOURCE_AMOUNT_HARD_LIMIT));
+}
+
+void GivePlayerFuel(entity player, float amount)
+{
+       GivePlayerResource(player, ammo_fuel, amount);
+}
+
+float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax)
 {
        if (!item.(ammotype))
                return false;
@@ -657,8 +769,13 @@ float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax
        {
                if ((player.(ammotype) < ammomax) || item.pickup_anyway > 0)
                {
-                       player.(ammotype) = bound(player.(ammotype), ammomax, player.(ammotype) + item.(ammotype));
-                       goto YEAH;
+                       float amount = item.(ammotype);
+                       if ((player.(ammotype) + amount) > ammomax)
+                       {
+                               amount = ammomax - player.(ammotype);
+                       }
+                       GivePlayerResource(player, ammotype, amount);
+                       return true;
                }
        }
        else if(g_weapon_stay == 2)
@@ -666,29 +783,11 @@ float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax
                float mi = min(item.(ammotype), ammomax);
                if (player.(ammotype) < mi)
                {
-                       player.(ammotype) = mi;
-                       goto YEAH;
+                       GivePlayerResource(player, ammotype, mi - player.(ammotype));
                }
+               return true;
        }
-
        return false;
-
-LABEL(YEAH)
-       switch(mode)
-       {
-               case ITEM_MODE_FUEL:
-                       player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
-                       break;
-               case ITEM_MODE_HEALTH:
-                       player.pauserothealth_finished = max(player.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
-                       break;
-               case ITEM_MODE_ARMOR:
-                       player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + autocvar_g_balance_pause_armor_rot);
-                       break;
-               default:
-                       break;
-       }
-       return true;
 }
 
 float Item_GiveTo(entity item, entity player)
@@ -717,16 +816,14 @@ float Item_GiveTo(entity item, entity player)
                        }
                }
        }
-
-       pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
-       pickedup |= Item_GiveAmmoTo(item, player, ammo_shells, g_pickup_shells_max, ITEM_MODE_NONE);
-       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);
-
+       pickedup |= Item_GiveAmmoTo(item, player, health, item.max_health);
+       pickedup |= Item_GiveAmmoTo(item, player, armorvalue, item.max_armorvalue);
+       pickedup |= Item_GiveAmmoTo(item, player, ammo_shells, g_pickup_shells_max);
+       pickedup |= Item_GiveAmmoTo(item, player, ammo_nails, g_pickup_nails_max);
+       pickedup |= Item_GiveAmmoTo(item, player, ammo_rockets, g_pickup_rockets_max);
+       pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, g_pickup_cells_max);
+       pickedup |= Item_GiveAmmoTo(item, player, ammo_plasma, g_pickup_plasma_max);
+       pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max);
        if (item.itemdef.instanceOfWeaponPickup)
        {
                WepSet w;
index e52604d994e97c1bf970394d083e1357550f31e6..c7287b67a67b3a1ebc285ad1119f868965e4988f 100644 (file)
@@ -4,6 +4,9 @@
 #include <server/defs.qh>
 #endif
 
+/// \brief Unconditional maximum amount of resources the player can have.
+const int RESOURCE_AMOUNT_HARD_LIMIT = 999;
+
 const int AMMO_COUNT = 4; // amount of ammo types to show in the inventory panel
 
 // item networking
@@ -85,11 +88,40 @@ void Item_ScheduleRespawnIn(entity e, float t);
 void Item_ScheduleRespawn(entity e);
 
 void Item_ScheduleInitialRespawn(entity e);
-float ITEM_MODE_NONE = 0;
-float ITEM_MODE_HEALTH = 1;
-float ITEM_MODE_ARMOR = 2;
-float ITEM_MODE_FUEL = 3;
-float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax, float mode);
+
+/// \brief Gives player a resource such as health, armor or ammo.
+/// \param[in,out] player Player to give resource to.
+/// \param[in] resource_type Type of the resource.
+/// \param[in] amount Amount of resource to give.
+/// \return No return.
+void GivePlayerResource(entity player, .float resource_type, float amount);
+
+/// \brief Gives health to the player.
+/// \param[in,out] player Player to give health to.
+/// \param[in] amount Amount of health to give.
+/// \return No return.
+void GivePlayerHealth(entity player, float amount);
+
+/// \brief Gives armor to the player.
+/// \param[in,out] player Player to give armor to.
+/// \param[in] amount Amount of armor to give.
+/// \return No return.
+void GivePlayerArmor(entity player, float amount);
+
+/// \brief Gives ammo of the specified type to the player.
+/// \param[in,out] player Player to give ammo to.
+/// \param[in] type Ammo type property.
+/// \param[in] amount Amount of ammo to give.
+/// \return No return.
+void GivePlayerAmmo(entity player, .float ammotype, float amount);
+
+/// \brief Gives fuel to the player.
+/// \param[in,out] player Player to give fuel to.
+/// \param[in] amount Amount of fuel to give.
+/// \return No return.
+void GivePlayerFuel(entity player, float amount);
+
+float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax);
 
 float Item_GiveTo(entity item, entity player);
 
index db0e478201de2df4385e257042a8c952019f8aca..4417515cf4e27e0132380ca8a571a39e98cc3566 100644 (file)
@@ -1620,7 +1620,6 @@ void player_regen(entity this)
        regen_health_stable = M_ARGV(9, float);
        regen_health_rotstable = M_ARGV(10, float);
 
-
        if(!mutator_returnvalue)
        if(!STAT(FROZEN, this))
        {
@@ -1659,6 +1658,18 @@ void player_regen(entity this)
 
                this.ammo_fuel = CalcRotRegen(this.ammo_fuel, minf, autocvar_g_balance_fuel_regen, autocvar_g_balance_fuel_regenlinear, frametime * (time > this.pauseregen_finished) * ((this.items & ITEM_JetpackRegen.m_itemid) != 0), maxf, autocvar_g_balance_fuel_rot, autocvar_g_balance_fuel_rotlinear, frametime * (time > this.pauserotfuel_finished), limitf);
        }
+       // Ugly hack to make sure the haelth and armor don't go beyond hard limit.
+       // TODO: Remove this hack when all code uses GivePlayerHealth and
+       // GivePlayerArmor.
+       if (this.health > RESOURCE_AMOUNT_HARD_LIMIT)
+       {
+               this.health = RESOURCE_AMOUNT_HARD_LIMIT;
+       }
+       if (this.armorvalue > RESOURCE_AMOUNT_HARD_LIMIT)
+       {
+               this.armorvalue = RESOURCE_AMOUNT_HARD_LIMIT;
+       }
+       // End hack.
 }
 
 bool zoomstate_set;