Open api-Hypernova opened 7 years ago
Changes:
On second thoughts: We should be setting up ammo by ammo types! Not ammo-per-attack. Each attack should have a pointer to which kind of ammo it uses. gameent should have an array of size NUMAMMOTYPES. Shooting simply does: d->ammo[atk]-=atk->sub; This way the ammo is kept synchronized over different ammo types and weapons that use the same ammo. This data could also drive the HUD when it's looking for what to render (multiple ammo types per weapon, or just one). To find which firing mode is being used in the current attack: int gun = d->gunselect, act = d->attacking, atk = guns[gun].attacks[act]; This is yet another reason to remove the server verification code for now.
Blocked by #48 (remove server correctness checks).
Gameent changes are done. Added a new enum/struct combo in game.h for storing ammo types: enum { AMMO_NONE=0, AMMO_SHELLS, AMMO_PULSE, AMMO_556, //M4 ammo AMMO_357, AMMO_9MM, AMMO_IMPACTNADE, //smg grenade AMMO_ORB, AMMO_ELECTROBOLT, AMMO_CELLS, //electrobolt lightning AMMO_SHOCK, //shockrifle AMMO_MISSILE, NUMAMMOTYPES }; static struct _ammodata { int add, max; const char *icon; } ammodata[NUMAMMOTYPES] = { //index with enum above { 1, 1, "infinite" }, { 6, 30, "shells" }, { 30, 90, "pulse" }, { 20, 40, "556" }, { 6, 24, "357" }, { 12, 48, "9mm" }, { 1, 10, "smgnade" }, { 1, 3, "orb" }, { 5, 30, "electrobolt" }, { 40, 120, "lightning" }, { 5, 15, "shock" }, { 1, 10, "rpg_missile" } };
The gamestate->ammo[] is now defined as:
int ammo[NUMAMMOTYPES];
Also added a new macro to shared/tools.h for grabbing the size of a raw array:
#define ARRSIZE(x) (sizeof(x) / sizeof((x)[0]))
Gamestate->hasammo() is now:
bool hasammo(int gun, int exclude = -1) { loopi(ARRSIZE(guns[gun].attacks)) { if(ammo[guns[gun].attacks[i]]) return validgun(gun) && gun != exclude; } return false; }
and etc. All that's left is to update the usages everywhere.
Checking if player has ammo (either fire mode) for a gun:
player->hasammo(gun)
Checking amount of ammo left for particular fire mode:
player->ammo[ATKAMMOTYPE(attack)]
The system is functioning, however there seems to be a bug with player->hasammo(gun) not retuning always correctly. Disabling this check in game::gunselect() allows switching to weapons which have ammo, while hasammo() was denying it.
Standing bugs:
Add a basic ammo system where the player spawns with a certain amount of ammo for each weapon, and firing reduces the ammo count by the amount specified in the gun metadata struct. Adding ammo via pickups will come later (after Bullet Physics integration).