ref: a8b8cbaf242fff3ea37888ef4ce0577564cc5925
parent: dbfdc2fba9c9eb2951ff08b8faacacbb8bb96967
author: LTCHIPS <ltchips994@gmail.com>
date: Sat May 19 22:33:07 EDT 2018
cleaned up ammo pickup code...now with 75% less unnecessary casting!
--- a/rott/rt_game.c
+++ b/rott/rt_game.c
@@ -1358,19 +1358,27 @@
M_LINKSTATE(ob, pstate);
- signed char * playerCurrentAmmo = (signed char *) (int)pstate->ammo;
- signed char * ammoInItem = (signed char *) (int)item_pickup->ammo;
- signed char * maxAmmoInWeapon = (signed char *) (int)stats[item_pickup->itemnumber].ammo;
- signed char * newAmmoAmount = (signed char *)((int)ammoInItem + (int)playerCurrentAmmo);
+ int playerCurrentAmmo = (int) pstate->ammo;
+
+ int ammoInItem = (int) item_pickup->ammo;
+
+ int maxAmmoInWeapon = (int)stats[item_pickup->itemnumber].ammo;
+
+
+ //printf("playerCurrentAmmo: %d \n", playerCurrentAmmo);
+ //printf("ammoInItem: %d \n", ammoInItem);
+ //printf("maxAmmoInWeapon: %d \n", maxAmmoInWeapon);
+
+ int newAmmoAmount = ammoInItem + playerCurrentAmmo;
if (newAmmoAmount > maxAmmoInWeapon)
{
- ammoInItem = (signed char *)((int)newAmmoAmount - (int)maxAmmoInWeapon);
+ ammoInItem = newAmmoAmount - maxAmmoInWeapon;
if (ammoInItem < 0)
{
Error("Ammo in item cannot be set to a negative number!");
}
- item_pickup->ammo = (int) ammoInItem;
+ item_pickup->ammo = ammoInItem;
newAmmoAmount = maxAmmoInWeapon;
}
else
@@ -1377,7 +1385,7 @@
{
ammoInItem = 0;
}
- pstate->ammo = (int)newAmmoAmount;
+ pstate->ammo = newAmmoAmount;
if (pstate->ammo &&
(pstate->missileweapon != -1) &&
@@ -1403,7 +1411,7 @@
}
//update ammo count on missile weapon on ground
- LASTSTAT->ammo = (int)ammoInItem;
+ LASTSTAT->ammo = ammoInItem;
EnableOldWeapon(pstate);
}
}