Ammo struct to better represent Ammo

This commit is contained in:
Raildex 2021-01-25 13:58:23 +01:00
parent 2a2c52674f
commit d45db30cd9
6 changed files with 105 additions and 50 deletions

View file

@ -126,7 +126,7 @@ void LaraCheatGetStuff() // (F) (D)
Lara.Weapons[WEAPON_REVOLVER].SelectedAmmo = WEAPON_AMMO1;
Lara.Weapons[WEAPON_REVOLVER].HasLasersight = false;
Lara.Weapons[WEAPON_REVOLVER].HasSilencer = false;
Lara.Weapons[WEAPON_REVOLVER].Ammo[WEAPON_AMMO1] = -1;
Lara.Weapons[WEAPON_REVOLVER].Ammo[WEAPON_AMMO1].isInfinite = true;
}
if (Objects[ID_UZI_ITEM].loaded)
@ -135,7 +135,7 @@ void LaraCheatGetStuff() // (F) (D)
Lara.Weapons[WEAPON_UZI].SelectedAmmo = WEAPON_AMMO1;
Lara.Weapons[WEAPON_UZI].HasLasersight = false;
Lara.Weapons[WEAPON_UZI].HasSilencer = false;
Lara.Weapons[WEAPON_UZI].Ammo[WEAPON_AMMO1] = -1;
Lara.Weapons[WEAPON_UZI].Ammo[WEAPON_AMMO1].isInfinite = true;
}
if (Objects[ID_SHOTGUN_ITEM].loaded)
@ -144,7 +144,7 @@ void LaraCheatGetStuff() // (F) (D)
Lara.Weapons[WEAPON_SHOTGUN].SelectedAmmo = WEAPON_AMMO1;
Lara.Weapons[WEAPON_SHOTGUN].HasLasersight = false;
Lara.Weapons[WEAPON_SHOTGUN].HasSilencer = false;
Lara.Weapons[WEAPON_SHOTGUN].Ammo[WEAPON_AMMO1] = -1;
Lara.Weapons[WEAPON_SHOTGUN].Ammo[WEAPON_AMMO1].isInfinite = true;
}
if (Objects[ID_HARPOON_ITEM].loaded)
@ -153,7 +153,7 @@ void LaraCheatGetStuff() // (F) (D)
Lara.Weapons[WEAPON_HARPOON_GUN].SelectedAmmo = WEAPON_AMMO1;
Lara.Weapons[WEAPON_HARPOON_GUN].HasLasersight = false;
Lara.Weapons[WEAPON_HARPOON_GUN].HasSilencer = false;
Lara.Weapons[WEAPON_HARPOON_GUN].Ammo[WEAPON_AMMO1] = -1;
Lara.Weapons[WEAPON_HARPOON_GUN].Ammo[WEAPON_AMMO1].isInfinite = true;
}
if (Objects[ID_GRENADE_GUN_ITEM].loaded)
@ -161,9 +161,9 @@ void LaraCheatGetStuff() // (F) (D)
Lara.Weapons[WEAPON_GRENADE_LAUNCHER].Present = true;
Lara.Weapons[WEAPON_GRENADE_LAUNCHER].SelectedAmmo = WEAPON_AMMO1;
Lara.Weapons[WEAPON_GRENADE_LAUNCHER].HasSilencer = false;
Lara.Weapons[WEAPON_GRENADE_LAUNCHER].Ammo[WEAPON_AMMO1] = -1;
Lara.Weapons[WEAPON_GRENADE_LAUNCHER].Ammo[WEAPON_AMMO2] = -1;
Lara.Weapons[WEAPON_GRENADE_LAUNCHER].Ammo[WEAPON_AMMO3] = -1;
Lara.Weapons[WEAPON_GRENADE_LAUNCHER].Ammo[WEAPON_AMMO1].isInfinite = true;
Lara.Weapons[WEAPON_GRENADE_LAUNCHER].Ammo[WEAPON_AMMO2].isInfinite = true;
Lara.Weapons[WEAPON_GRENADE_LAUNCHER].Ammo[WEAPON_AMMO3].isInfinite = true;
}
if (Objects[ID_ROCKET_LAUNCHER_ITEM].loaded)
@ -172,7 +172,7 @@ void LaraCheatGetStuff() // (F) (D)
Lara.Weapons[WEAPON_ROCKET_LAUNCHER].SelectedAmmo = WEAPON_AMMO1;
Lara.Weapons[WEAPON_ROCKET_LAUNCHER].HasLasersight = false;
Lara.Weapons[WEAPON_ROCKET_LAUNCHER].HasSilencer = false;
Lara.Weapons[WEAPON_ROCKET_LAUNCHER].Ammo[WEAPON_AMMO1] = -1;
Lara.Weapons[WEAPON_ROCKET_LAUNCHER].Ammo[WEAPON_AMMO1].isInfinite = true;
}
if (Objects[ID_HK_ITEM].loaded)
@ -181,7 +181,7 @@ void LaraCheatGetStuff() // (F) (D)
Lara.Weapons[WEAPON_HK].SelectedAmmo = WEAPON_AMMO1;
Lara.Weapons[WEAPON_HK].HasLasersight = false;
Lara.Weapons[WEAPON_HK].HasSilencer = false;
Lara.Weapons[WEAPON_HK].Ammo[WEAPON_AMMO1] = -1;
Lara.Weapons[WEAPON_HK].Ammo[WEAPON_AMMO1].isInfinite = true;
}
if (Objects[ID_CROSSBOW_ITEM].loaded)
@ -190,9 +190,9 @@ void LaraCheatGetStuff() // (F) (D)
Lara.Weapons[WEAPON_CROSSBOW].SelectedAmmo = WEAPON_AMMO1;
Lara.Weapons[WEAPON_CROSSBOW].HasLasersight = false;
Lara.Weapons[WEAPON_CROSSBOW].HasSilencer = false;
Lara.Weapons[WEAPON_CROSSBOW].Ammo[WEAPON_AMMO1] = -1;
Lara.Weapons[WEAPON_CROSSBOW].Ammo[WEAPON_AMMO2] = -1;
Lara.Weapons[WEAPON_CROSSBOW].Ammo[WEAPON_AMMO3] = -1;
Lara.Weapons[WEAPON_CROSSBOW].Ammo[WEAPON_AMMO1].isInfinite = true;
Lara.Weapons[WEAPON_CROSSBOW].Ammo[WEAPON_AMMO2].isInfinite = true;
Lara.Weapons[WEAPON_CROSSBOW].Ammo[WEAPON_AMMO3].isInfinite = true;
}
g_Inventory.LoadObjects(false);

View file

@ -258,7 +258,7 @@ bool MonksAttackLara;
ITEM_INFO* LastTargets[8];
ITEM_INFO* TargetList[8];
int WeaponObject(int weaponType) // (F) (D)
GAME_OBJECT_ID WeaponObject(int weaponType) // (F) (D)
{
switch (weaponType)
{
@ -522,7 +522,7 @@ void LaraGun() // (F) (D)
if (TrInput & IN_ACTION)
{
if (!*GetAmmo(Lara.gunType))
if (!GetAmmo(Lara.gunType))
{
Lara.requestGunType = Objects[ID_PISTOLS_ITEM].loaded ? WEAPON_PISTOLS : WEAPON_NONE;
return;
@ -594,9 +594,8 @@ void LaraGun() // (F) (D)
}
}
short* GetAmmo(int weaponType)
{
return &Lara.Weapons[weaponType].Ammo[Lara.Weapons[weaponType].SelectedAmmo];
Ammo& GetAmmo(int weaponType){
return Lara.Weapons[weaponType].Ammo[Lara.Weapons[weaponType].SelectedAmmo];
}
void InitialiseNewWeapon()
@ -651,8 +650,7 @@ void InitialiseNewWeapon()
}
}
int WeaponObjectMesh(int weaponType)
{
GAME_OBJECT_ID WeaponObjectMesh(int weaponType) {
switch (weaponType)
{
case WEAPON_REVOLVER:
@ -724,11 +722,11 @@ void HitTarget(ITEM_INFO* item, GAME_VECTOR* hitPos, int damage, int flag)
FireWeaponType FireWeapon(int weaponType, ITEM_INFO* target, ITEM_INFO* src, short* angles) // (F) (D)
{
short* ammo = GetAmmo(weaponType);
if (*ammo == 0)
Ammo& ammo = GetAmmo(weaponType);
if (ammo.count == 0 && !ammo.isInfinite)
return FW_NOAMMO;
if (*ammo != -1)
*ammo--;
if (!ammo.isInfinite)
ammo--;
WEAPON_INFO* weapon = &Weapons[weaponType];
int r;

View file

@ -36,11 +36,11 @@ constexpr auto WSTATE_UW_UNAIM = 7;
extern WEAPON_INFO Weapons[static_cast<int>(LARA_WEAPON_TYPE::NUM_WEAPONS)];
void SmashItem(short itemNum);
int WeaponObject(int weaponType);
GAME_OBJECT_ID WeaponObject(int weaponType);
void LaraGun();
short* GetAmmo(int weaponType);
Ammo& GetAmmo(int weaponType);
void InitialiseNewWeapon();
int WeaponObjectMesh(int weaponType);
GAME_OBJECT_ID WeaponObjectMesh(int weaponType);
void AimWeapon(WEAPON_INFO* winfo, LARA_ARM* arm);
void HitTarget(ITEM_INFO* item, GAME_VECTOR* hitPos, int damage, int flag);
FireWeaponType FireWeapon(int weaponType, ITEM_INFO* target, ITEM_INFO* src, short* angles);

View file

@ -35,8 +35,8 @@ extern GameFlow* g_GameFlow;
void FireHarpoon()
{
short* ammos = GetAmmo(WEAPON_CROSSBOW);
if (*ammos != 0)
Ammo& ammos = GetAmmo(WEAPON_CROSSBOW);
if (ammos.count != 0)
{
Lara.hasFired = true;
@ -44,8 +44,8 @@ void FireHarpoon()
short itemNumber = CreateItem();
if (itemNumber != NO_ITEM)
{
if (*ammos != -1)
(*ammos)--;
if (!ammos.isInfinite)
(ammos)--;
GAME_VECTOR pos;
ITEM_INFO* item = &g_Level.Items[itemNumber];
@ -292,8 +292,8 @@ void FireGrenade()
int y = 0;
int z = 0;
short* ammo = GetAmmo(WEAPON_GRENADE_LAUNCHER);
if (*ammo != 0)
Ammo& ammo = GetAmmo(WEAPON_GRENADE_LAUNCHER);
if (ammo != 0)
{
Lara.hasFired = true;
@ -365,8 +365,8 @@ void FireGrenade()
AddActiveItem(itemNumber);
if (*ammo != -1)
(*ammo)--;
if (!ammo.isInfinite)
(ammo)--;
item->itemFlags[0] = Lara.Weapons[WEAPON_GRENADE_LAUNCHER].SelectedAmmo;
@ -1516,8 +1516,8 @@ void RifleHandler(int weaponType)
void FireCrossbow(PHD_3DPOS* pos)
{
short* ammos = GetAmmo(WEAPON_CROSSBOW);
if (*ammos != 0)
Ammo& ammos = GetAmmo(WEAPON_CROSSBOW);
if (ammos)
{
Lara.hasFired = true;
@ -1542,8 +1542,8 @@ void FireCrossbow(PHD_3DPOS* pos)
}
else
{
if (*ammos != -1)
(*ammos)--;
if (!ammos.isInfinite)
(ammos)--;
PHD_VECTOR jointPos;
jointPos.x = 0;
@ -1600,9 +1600,8 @@ void FireCrossbow(PHD_3DPOS* pos)
void FireRocket()
{
short* ammos = GetAmmo(WEAPON_ROCKET_LAUNCHER);
if (*ammos != 0)
{
Ammo& ammos = GetAmmo(WEAPON_ROCKET_LAUNCHER);
if (ammos) {
Lara.hasFired = true;
short itemNumber = CreateItem();
@ -1612,8 +1611,8 @@ void FireRocket()
item->objectNumber = ID_ROCKET;
item->roomNumber = LaraItem->roomNumber;
if (*ammos != -1)
(*ammos)--;
if (!ammos.isInfinite)
(ammos)--;
PHD_VECTOR jointPos;
jointPos.x = 0;

View file

@ -827,11 +827,69 @@ struct HolsterInfo {
HOLSTER_SLOT rightHolster;
HOLSTER_SLOT backHolster;
};
struct Ammo {
unsigned short count;
bool isInfinite;
Ammo operator --() {
Ammo tmp;
tmp.isInfinite = this->isInfinite;
tmp.count = static_cast<unsigned int>(--this->count);
return tmp;
}
Ammo operator --(int) {
Ammo tmp;
tmp.isInfinite = this->isInfinite;
tmp.count = --this->count;
return tmp;
}
Ammo operator ++() {
Ammo tmp;
tmp.isInfinite = this->isInfinite;
tmp.count = ++this->count;
return tmp;
}
Ammo operator ++(int) {
Ammo tmp;
tmp.isInfinite = this->isInfinite;
tmp.count = ++this->count;
return tmp;
}
Ammo& operator =(unsigned val) {
this->count = static_cast<unsigned short>(val);
return *this;
}
Ammo& operator +(unsigned val) {
int tmp = this->count + val;
this->count = static_cast<unsigned short>(tmp);
return *this;
}
Ammo& operator +=(unsigned val) {
int tmp = this->count + val;
this->count = static_cast<unsigned short>(tmp);
return *this;
}
Ammo& operator -=(unsigned val) {
int tmp = this->count - val;
this->count = static_cast<unsigned short>(tmp);
return *this;
}
operator bool() {
return isInfinite || (count > 0);
}
};
typedef struct CarriedWeaponInfo
{
bool Present;
short Ammo[MAX_AMMOTYPE];
Ammo Ammo[MAX_AMMOTYPE];
int SelectedAmmo; // WeaponAmmoType_enum
bool HasLasersight;
bool HasSilencer;

View file

@ -1315,9 +1315,9 @@ void BinocularCamera(ITEM_INFO* item)
if (LaserSight)
{
int firing = 0;
short* ammo = GetAmmo(Lara.gunType);
Ammo& ammo = GetAmmo(Lara.gunType);
if (!(InputBusy & IN_ACTION) || WeaponDelay || !*ammo)
if (!(InputBusy & IN_ACTION) || WeaponDelay || !ammo)
{
if (!(InputBusy & IN_ACTION))
{
@ -1334,8 +1334,8 @@ void BinocularCamera(ITEM_INFO* item)
firing = 1;
WeaponDelay = 16;
Savegame.Game.AmmoUsed++;
if (*ammo != -1)
(*ammo)--;
if (!ammo.isInfinite)
(ammo)--;
}
else if (Lara.gunType == WEAPON_CROSSBOW)
{
@ -1426,8 +1426,8 @@ void BinocularCamera(ITEM_INFO* item)
Camera.bounce = -16 - (GetRandomControl() & 0x1F);
}
if (*ammo != -1)
(*ammo)--;
if (!ammo.isInfinite)
(ammo)--;
}
}