home *** CD-ROM | disk | FTP | other *** search
- #include "Weapon.h"
-
- #include "Game.h"
- #include "Laser.h"
- #include "Chaingun.h"
- #include "Railgun.h"
- #include "Rocketlauncher.h"
- #include "Plasmagun.h"
-
- Weapon::Weapon(Vehicle* vehicle, vec3_t mountPoint){
- this->vehicle = vehicle;
- this->type = GAME_WEAPON_NO_WEAPON;
- this->model = NULL;
- this->name = "Unknown";
-
- this->maxAmmo = 0;
- this->ammo = 0;
- this->ammoCosts = 0;
- this->maxEnergy = 0;
- this->energy = 0.0f;
- this->energyCosts = 0;
-
- vectorCopy3d(mountPoint, this->mountPoint);
- vectorInit3d(0.0f, 0.0f, 0.0f, muzzlePoint);
- lastFiredMillis = 0;
- fireIntervalMillis = 0;
-
- this->animator = NULL;
- }
-
- Weapon::~Weapon(){
- if( animator != NULL )
- delete animator;
- }
-
- bool Weapon::isReadyToFire(){
- return ammo >= ammoCosts && energy >= energyCosts && SDL_GetTicks() >= lastFiredMillis+fireIntervalMillis;
- }
-
- void Weapon::fire(){
- energy -= energyCosts;
- if( energy < 0.0f )
- energy = 0.0f;
-
- ammo -= ammoCosts;
- if( ammo < 0 )
- ammo = 0;
-
- Shot* s = Shot::createShotForWeapon(this);
- vehicle->client->sendShotSpawn(s);
- delete s;
-
- lastFiredMillis = SDL_GetTicks();
- }
-
-
-
-
-
- Weapon* Weapon::createWeaponForVehicle(Vehicle* vehicle, vec3_t mountPoint, int type){
- Weapon* ret = NULL;
-
- switch( type ){
- case GAME_WEAPON_LASER:
- ret = new Laser(vehicle, mountPoint);
- break;
-
- case GAME_WEAPON_CHAINGUN:
- ret = new Chaingun(vehicle, mountPoint);
- break;
-
- case GAME_WEAPON_RAILGUN:
- ret = new Railgun(vehicle, mountPoint);
- break;
-
- case GAME_WEAPON_ROCKETLAUNCHER:
- ret = new Rocketlauncher(vehicle, mountPoint);
- break;
-
- case GAME_WEAPON_PLASMAGUN:
- ret = new Plasmagun(vehicle, mountPoint);
- break;
-
- case GAME_WEAPON_NO_WEAPON:
- default:
- break;
- }
-
- return ret;
- }
-