Skip to content
Permalink
Browse files

game: refactor a bit Pickup_Weapon

  • Loading branch information...
Aranud committed Sep 9, 2019
1 parent b6a56ac commit 404b0047183c46c6247d131932a9e31352036127
Showing with 46 additions and 45 deletions.
  1. +46 −45 src/game/g_items.c
@@ -494,14 +494,17 @@ int Pickup_Weapon(gentity_t *ent, gentity_t *other)
{
Add_Ammo(other, ent->item->giWeapon, quantity, qfalse);

// secondary weapon ammo
// secondary weapon ammo (riflenade)
if (ent->delay != 0.f)
{
Add_Ammo(other, GetWeaponTableData(ent->item->giWeapon)->weapAlts, ent->delay, qfalse);
}
}
else
{
weapon_t primaryWeapon;
qboolean canPickup;

if (level.time - other->client->dropWeaponTime < 1000)
{
return 0;
@@ -514,63 +517,61 @@ int Pickup_Weapon(gentity_t *ent, gentity_t *other)
}

// see if we can pick it up
if (G_CanPickupWeapon(ent->item->giWeapon, other))
{
weapon_t primaryWeapon;
canPickup = G_CanPickupWeapon(ent->item->giWeapon, other);

if (other->client->sess.playerType == PC_SOLDIER && other->client->sess.skill[SK_HEAVY_WEAPONS] >= 4)
{
primaryWeapon = G_GetPrimaryWeaponForClientSoldier(ent->item->giWeapon, other->client);
}
else
{
primaryWeapon = G_GetPrimaryWeaponForClient(other->client);
}

// drop our primary weapon if one exist
if (primaryWeapon)
{
G_DropWeapon(other, primaryWeapon);
}
if (!canPickup)
{
return 0;
}

// now pickup the other one
other->client->dropWeaponTime = level.time;
if (other->client->sess.playerType == PC_SOLDIER && other->client->sess.skill[SK_HEAVY_WEAPONS] >= 4)
{
primaryWeapon = G_GetPrimaryWeaponForClientSoldier(ent->item->giWeapon, other->client);
}
else
{
primaryWeapon = G_GetPrimaryWeaponForClient(other->client);
}

// add the weapon
COM_BitSet(other->client->ps.weapons, ent->item->giWeapon);
// drop our primary weapon if one exist
if (primaryWeapon)
{
G_DropWeapon(other, primaryWeapon);
}

// fixup mauser/sniper issues
if (GetWeaponTableData(ent->item->giWeapon)->weapAlts)
{
weapon_t weapAlts = GetWeaponTableData(ent->item->giWeapon)->weapAlts;
// now pickup the other one
other->client->dropWeaponTime = level.time;

if (GetWeaponTableData(weapAlts)->type & (WEAPON_TYPE_RIFLENADE | WEAPON_TYPE_SCOPED | WEAPON_TYPE_SET))
{
COM_BitSet(other->client->ps.weapons, weapAlts);
}
}
// add the weapon
COM_BitSet(other->client->ps.weapons, ent->item->giWeapon);

other->client->ps.ammoclip[GetWeaponTableData(ent->item->giWeapon)->clipIndex] = 0;
other->client->ps.ammo[GetWeaponTableData(ent->item->giWeapon)->ammoIndex] = 0;
// fixup mauser/sniper issues
if (GetWeaponTableData(ent->item->giWeapon)->weapAlts)
{
weapon_t weapAlts = GetWeaponTableData(ent->item->giWeapon)->weapAlts;

if (GetWeaponTableData(ent->item->giWeapon)->useClip)
{
other->client->ps.ammoclip[GetWeaponTableData(ent->item->giWeapon)->clipIndex] = quantity;
}
else
if (GetWeaponTableData(weapAlts)->type & (WEAPON_TYPE_RIFLENADE | WEAPON_TYPE_SCOPED | WEAPON_TYPE_SET))
{
other->client->ps.ammo[GetWeaponTableData(ent->item->giWeapon)->clipIndex] = quantity;
COM_BitSet(other->client->ps.weapons, weapAlts);
}
}

// secondary weapon ammo (riflenade)
if (ent->delay != 0.f)
{
other->client->ps.ammo[GetWeaponTableData(ent->item->giWeapon)->weapAlts] = ent->delay;
}
other->client->ps.ammoclip[GetWeaponTableData(ent->item->giWeapon)->clipIndex] = 0;
other->client->ps.ammo[GetWeaponTableData(ent->item->giWeapon)->ammoIndex] = 0;

if (GetWeaponTableData(ent->item->giWeapon)->useClip)
{
other->client->ps.ammoclip[GetWeaponTableData(ent->item->giWeapon)->clipIndex] = quantity;
}
else
{
return 0;
other->client->ps.ammo[GetWeaponTableData(ent->item->giWeapon)->clipIndex] = quantity;
}

// secondary weapon ammo (riflenade)
if (ent->delay != 0.f)
{
other->client->ps.ammo[GetWeaponTableData(ent->item->giWeapon)->weapAlts] = ent->delay;
}
}

0 comments on commit 404b004

Please sign in to comment.
You can’t perform that action at this time.