Original Post
Hi there. I am in the process of implementing a weapon/ammo system for my 3D game. I just wanted to ask some questions and give my thoughts about how I'm thinking of doing this. I want it to be as clean as possible. This is in C++. Any suggestions/advice is gladly welcome: 1) I'm going to have several types of weapons in the game, from simple pistols to machine guns, to grenades, to melee weapons like lead pipes, etc. So I was thinking of having a CWeapon base class for _all_ weapons. This class would have virtual functions for Fire(), Reload(), Shoot(), etc. Probably make this an abstract base class. Then, for each weapon, make a new class derived from CWeapon and implement the virtual functions and any specific data needed. Any comments on this design? Pretty self-explanatory, right? 2) Now also, different weapon types have different ammo types. Pistols have a simple bullet, while a grenade actually throws a grenade :), etc. So should I go the same route as above by having an abstract base class called CAmmo or something and derive a new specific class for each ammo type? 3) Lastly, and this is where I need the most advice. When the player shoots a pistol, for example, bullets go off into the distance. When the player throws a grenade, a grenade is launched into the world. Obviously, I have to alert the class that handles the map that there is a new bullet or grenade in the world. Who handles what here? Do I simply have a dynamic vector of bullets/grenades/whatever that are currently in the map? So in my pistol's shoot method, I would have to tell the map class to add a new bullet into the world? So then the map class probably loops over all active bullets/whatver and calls its Update() method? Thanks.