]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'master' into martin-t/okc
authorMartin Taibr <taibr.martin@gmail.com>
Sun, 27 Aug 2017 15:04:58 +0000 (17:04 +0200)
committerMartin Taibr <taibr.martin@gmail.com>
Sun, 27 Aug 2017 15:04:58 +0000 (17:04 +0200)
1  2 
qcsrc/common/mutators/mutator/nades/nades.qc
qcsrc/common/t_items.qc
qcsrc/common/t_items.qh

index 11926b36d025b263032e2c1cf6355094c1305802,62b0fcf79dfde23b3d0ff10a500b210e9f7e9dd6..18edd482d3c5b942092032ae2bf1371be5d2a2cf
@@@ -889,18 -889,20 +889,18 @@@ void toss_nade(entity e, bool set_owner
        delete(e.fake_nade);
        e.fake_nade = NULL;
  
 +      Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_NADES);
 +
        makevectors(e.v_angle);
  
        // NOTE: always throw from first weapon entity?
        W_SetupShot(e, _nade.weaponentity_fld, false, false, SND_Null, CH_WEAPON_A, 0);
  
 -      Kill_Notification(NOTIF_ONE_ONLY, e, MSG_CENTER, CPID_NADES);
 -
        vector offset = (v_forward * autocvar_g_nades_throw_offset.x)
 -                                + (v_right * autocvar_g_nades_throw_offset.y)
 -                                + (v_up * autocvar_g_nades_throw_offset.z);
 -      if(autocvar_g_nades_throw_offset == '0 0 0')
 -              offset = '0 0 0';
 +                    + (v_right * autocvar_g_nades_throw_offset.y)
 +                    + (v_up * autocvar_g_nades_throw_offset.z);
  
 -      setorigin(_nade, w_shotorg + offset + (v_right * 25) * -1);
 +      setorigin(_nade, w_shotorg + offset);
        //setmodel(_nade, MDL_PROJECTILE_NADE);
        //setattachment(_nade, NULL, "");
        PROJECTILE_MAKETRIGGER(_nade);
@@@ -1238,7 -1240,7 +1238,7 @@@ MUTATOR_HOOKFUNCTION(nades, PlayerPreTh
                        FOR_EACH_KH_KEY(key) if(key.owner == player) { ++key_count; }
  
                        float time_score;
-                       if(player.flagcarried || player.ballcarried) // this player is important
+                       if(GameRules_scoring_is_vip(player))
                                time_score = autocvar_g_nades_bonus_score_time_flagcarrier;
                        else
                                time_score = autocvar_g_nades_bonus_score_time;
@@@ -1377,7 -1379,7 +1377,7 @@@ MUTATOR_HOOKFUNCTION(nades, PlayerDies
  
                if (SAME_TEAM(frag_attacker, frag_target) || frag_attacker == frag_target)
                        nades_RemoveBonus(frag_attacker);
-               else if(frag_target.flagcarried)
+               else if(GameRules_scoring_is_vip(frag_target))
                        nades_GiveBonus(frag_attacker, autocvar_g_nades_bonus_score_medium);
                else if(autocvar_g_nades_bonus_score_spree && CS(frag_attacker).killcount > 1)
                {
diff --combined qcsrc/common/t_items.qc
index 2c42e472847794b4440be0d2675886ebd0014bca,e47b98a663c7b498db2baa37c5bdae224daafcf2..674793bca16c70ef4bb53c3a21032f2623e3b640
@@@ -631,35 -631,12 +631,35 @@@ void Item_ScheduleRespawnIn(entity e, f
        }
  }
  
 +AUTOCVAR(g_pickup_respawntime_scaling_reciprocal, float, 0.0, "Multiply respawn time by `reciprocal / (p + offset) + linear` where `p` is the current number of players, takes effect with 2 or more players present, `reciprocal` (with `offset` and `linear` set to 0) can be used to achieve a constant number of items spawned *per player*");
 +AUTOCVAR(g_pickup_respawntime_scaling_offset, float, 0.0, "Multiply respawn time by `reciprocal / (p + offset) + linear` where `p` is the current number of players, takes effect with 2 or more players present, `offset` offsets the curve left or right - the results are not intuitive and I recommend plotting the respawn time and the number of items per player to see what's happening");
 +AUTOCVAR(g_pickup_respawntime_scaling_linear, float, 1.0, "Multiply respawn time by `reciprocal / (p + offset) + linear` where `p` is the current number of players, takes effect with 2 or more players present, `linear` can be used to simply scale the respawn time linearly");
  void Item_ScheduleRespawn(entity e)
  {
        if(e.respawntime > 0)
        {
                Item_Show(e, 0);
 -              Item_ScheduleRespawnIn(e, ITEM_RESPAWNTIME(e));
 +
 +              CheckAllowedTeams(NULL);
 +              GetTeamCounts(NULL);
 +              int players = 0;
 +              if (c1 != -1) players += c1;
 +              if (c2 != -1) players += c2;
 +              if (c3 != -1) players += c3;
 +              if (c4 != -1) players += c4;
 +              float adjusted_respawntime;
 +              if (players >= 2) {
 +                      float a = autocvar_g_pickup_respawntime_scaling_reciprocal;
 +                      float b = autocvar_g_pickup_respawntime_scaling_offset;
 +                      float c = autocvar_g_pickup_respawntime_scaling_linear;
 +                      adjusted_respawntime = e.respawntime * (a / (players + b) + c);
 +              } else {
 +                      adjusted_respawntime = e.respawntime;
 +              }
 +              //LOG_INFOF("item %s will respawn in %f\n", e.classname, adjusted_respawntime);
 +              // range: adjusted_respawntime - respawntimejitter .. adjusted_respawntime + respawntimejitter
 +              float actual_time = adjusted_respawntime + crandom() * e.respawntimejitter;
 +              Item_ScheduleRespawnIn(e, actual_time);
        }
        else // if respawntime is -1, this item does not respawn
                Item_Show(e, -1);
@@@ -671,7 -648,119 +671,119 @@@ void Item_ScheduleInitialRespawn(entit
        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;
        {
                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)
                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)
                        }
                }
        }
-       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;
diff --combined qcsrc/common/t_items.qh
index b92aceb8d0b342028f8c64f3aca50f3e975c8c78,c7287b67a67b3a1ebc285ad1119f868965e4988f..f557e10308cc0d961df222bcb9a021dc4fd33399
@@@ -4,6 -4,9 +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
@@@ -67,6 -70,8 +70,6 @@@ bool have_pickup_item(entity this)
  
  const float ITEM_RESPAWN_TICKS = 10;
  
 -#define ITEM_RESPAWNTIME(i)         ((i).respawntime + crandom() * (i).respawntimejitter)
 -      // range: respawntime - respawntimejitter .. respawntime + respawntimejitter
  #define ITEM_RESPAWNTIME_INITIAL(i) (ITEM_RESPAWN_TICKS + random() * ((i).respawntime + (i).respawntimejitter - ITEM_RESPAWN_TICKS))
        // range: 10 .. respawntime + respawntimejitter
  
@@@ -83,11 -88,40 +86,40 @@@ void Item_ScheduleRespawnIn(entity e, f
  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);