From: Mario Date: Sat, 1 Oct 2016 07:15:43 +0000 (+1000) Subject: Make auto switch functional for both weapon slots X-Git-Tag: xonotic-v0.8.2~326^2~79 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=931ebbddef3e593cfcbd2dcb1b1da8493d4e22e0;p=xonotic%2Fxonotic-data.pk3dir.git Make auto switch functional for both weapon slots --- diff --git a/qcsrc/common/t_items.qc b/qcsrc/common/t_items.qc index 3c80ae01b..a9e3400b3 100644 --- a/qcsrc/common/t_items.qc +++ b/qcsrc/common/t_items.qc @@ -672,23 +672,30 @@ LABEL(YEAH) float Item_GiveTo(entity item, entity player) { - float _switchweapon; float pickedup; - .entity weaponentity = weaponentities[0]; // TODO: unhardcode - // if nothing happens to player, just return without taking the item pickedup = false; - _switchweapon = false; + int _switchweapon = 0; // in case the player has autoswitch enabled do the following: // if the player is using their best weapon before items are given, they // probably want to switch to an even better weapon after items are given - if (player.autoswitch) - if (player.(weaponentity).m_switchweapon == w_getbestweapon(player, weaponentity)) - _switchweapon = true; - if (!(player.weapons & WepSet_FromWeapon(player.(weaponentity).m_switchweapon))) - _switchweapon = true; + if(player.autoswitch) + { + for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) + { + .entity weaponentity = weaponentities[slot]; + if(player.(weaponentity).m_weapon != WEP_Null || slot == 0) + { + if(player.(weaponentity).m_switchweapon == w_getbestweapon(player, weaponentity)) + _switchweapon |= BIT(slot); + + if(!(player.weapons & WepSet_FromWeapon(player.(weaponentity).m_switchweapon))) + _switchweapon |= BIT(slot); + } + } + } 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); @@ -711,7 +718,12 @@ float Item_GiveTo(entity item, entity player) FOREACH(Weapons, it != WEP_Null, { if(w & (it.m_wepset)) { - W_DropEvent(wr_pickup, player, it.m_id, item, weaponentity); + 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_GiveWeapon(player, it.m_id); } }); @@ -762,13 +774,25 @@ LABEL(skip) // crude hack to enforce switching weapons if(g_cts && item.itemdef.instanceOfWeaponPickup) { - W_SwitchWeapon_Force(player, Weapons_from(item.weapon), weaponentity); + for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) + { + .entity weaponentity = weaponentities[slot]; + if(player.(weaponentity).m_weapon != WEP_Null || slot == 0) + W_SwitchWeapon_Force(player, Weapons_from(item.weapon), weaponentity); + } return 1; } - if (_switchweapon) - if (player.(weaponentity).m_switchweapon != w_getbestweapon(player, weaponentity)) - W_SwitchWeapon_Force(player, w_getbestweapon(player, weaponentity), weaponentity); + if(_switchweapon) + { + for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) + { + .entity weaponentity = weaponentities[slot]; + if(_switchweapon & BIT(slot)) + if(player.(weaponentity).m_switchweapon != w_getbestweapon(player, weaponentity)) + W_SwitchWeapon_Force(player, w_getbestweapon(player, weaponentity), weaponentity); + } + } return 1; } @@ -1647,7 +1671,6 @@ void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .floa float GiveItems(entity e, float beginarg, float endarg) { float got, i, val, op; - float _switchweapon; string cmd; val = 999; @@ -1655,12 +1678,18 @@ float GiveItems(entity e, float beginarg, float endarg) got = 0; - .entity weaponentity = weaponentities[0]; // TODO: unhardcode + int _switchweapon = 0; - _switchweapon = false; - if (e.autoswitch) - if (e.(weaponentity).m_switchweapon == w_getbestweapon(e, weaponentity)) - _switchweapon = true; + if(e.autoswitch) + { + for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) + { + .entity weaponentity = weaponentities[slot]; + if(e.(weaponentity).m_weapon != WEP_Null || slot == 0) + if(e.(weaponentity).m_switchweapon == w_getbestweapon(e, weaponentity)) + _switchweapon |= BIT(slot); + } + } e.strength_finished = max(0, e.strength_finished - time); e.invincible_finished = max(0, e.invincible_finished - time); @@ -1825,10 +1854,23 @@ float GiveItems(entity e, float beginarg, float endarg) else e.superweapons_finished += time; - if (!(e.weapons & WepSet_FromWeapon(e.(weaponentity).m_switchweapon))) - _switchweapon = true; + for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) + { + .entity weaponentity = weaponentities[slot]; + if(e.(weaponentity).m_weapon != WEP_Null || slot == 0) + if(!(e.weapons & WepSet_FromWeapon(e.(weaponentity).m_switchweapon))) + _switchweapon |= BIT(slot); + } + if(_switchweapon) - W_SwitchWeapon_Force(e, w_getbestweapon(e, weaponentity), weaponentity); + { + for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) + { + .entity weaponentity = weaponentities[slot]; + if(_switchweapon & BIT(slot)) + W_SwitchWeapon_Force(e, w_getbestweapon(e, weaponentity), weaponentity); + } + } return got; } diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index e8b32c804..0237a75ad 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -448,9 +448,15 @@ void GetCvars(entity this, int f) // fixup of switchweapon (needed for LMS or when spectating is disabled, as PutClientInServer comes too early) if (f > 0) { - .entity weaponentity = weaponentities[0]; // TODO: unhardcode if (s == "cl_weaponpriority") - if (this.(weaponentity)) this.(weaponentity).m_switchweapon = w_getbestweapon(this, weaponentity); + { + for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) + { + .entity weaponentity = weaponentities[slot]; + if (this.(weaponentity) && (this.(weaponentity).m_weapon != WEP_Null || slot == 0)) + this.(weaponentity).m_switchweapon = w_getbestweapon(this, weaponentity); + } + } if (s == "cl_allow_uidtracking") PlayerStats_GameReport_AddPlayer(this); }