home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 March / ENTER.ISO / files / fwp-0.0.6-win32-installer.exe / Weapon.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-01-01  |  1.8 KB  |  91 lines

  1. #include "Weapon.h"
  2.  
  3. #include "Game.h"
  4. #include "Laser.h"
  5. #include "Chaingun.h"
  6. #include "Railgun.h"
  7. #include "Rocketlauncher.h"
  8. #include "Plasmagun.h"
  9.  
  10. Weapon::Weapon(Vehicle* vehicle, vec3_t mountPoint){
  11.     this->vehicle = vehicle;
  12.     this->type = GAME_WEAPON_NO_WEAPON;
  13.     this->model = NULL;
  14.     this->name = "Unknown";
  15.  
  16.     this->maxAmmo = 0;
  17.     this->ammo = 0;
  18.     this->ammoCosts = 0;
  19.     this->maxEnergy = 0;
  20.     this->energy = 0.0f;
  21.     this->energyCosts = 0;
  22.  
  23.     vectorCopy3d(mountPoint, this->mountPoint);
  24.     vectorInit3d(0.0f, 0.0f, 0.0f, muzzlePoint);
  25.     lastFiredMillis = 0;
  26.     fireIntervalMillis = 0;
  27.  
  28.     this->animator = NULL;
  29. }
  30.  
  31. Weapon::~Weapon(){
  32.     if( animator != NULL )
  33.         delete animator;
  34. }
  35.  
  36. bool Weapon::isReadyToFire(){
  37.     return ammo >= ammoCosts && energy >= energyCosts && SDL_GetTicks() >= lastFiredMillis+fireIntervalMillis;
  38. }
  39.  
  40. void Weapon::fire(){
  41.     energy -= energyCosts;
  42.     if( energy < 0.0f )
  43.         energy = 0.0f;
  44.  
  45.     ammo -= ammoCosts;
  46.     if( ammo < 0 )
  47.         ammo = 0;
  48.  
  49.     Shot* s = Shot::createShotForWeapon(this);
  50.     vehicle->client->sendShotSpawn(s);
  51.     delete s;
  52.  
  53.     lastFiredMillis = SDL_GetTicks();
  54. }
  55.  
  56.  
  57.  
  58.  
  59.  
  60. Weapon* Weapon::createWeaponForVehicle(Vehicle* vehicle, vec3_t mountPoint, int type){
  61.     Weapon* ret = NULL;
  62.  
  63.     switch( type ){
  64.         case GAME_WEAPON_LASER:
  65.             ret = new Laser(vehicle, mountPoint);
  66.             break;
  67.  
  68.         case GAME_WEAPON_CHAINGUN:
  69.             ret = new Chaingun(vehicle, mountPoint);
  70.             break;
  71.  
  72.         case GAME_WEAPON_RAILGUN:
  73.             ret = new Railgun(vehicle, mountPoint);
  74.             break;
  75.  
  76.         case GAME_WEAPON_ROCKETLAUNCHER:
  77.             ret = new Rocketlauncher(vehicle, mountPoint);
  78.             break;
  79.  
  80.         case GAME_WEAPON_PLASMAGUN:
  81.             ret = new Plasmagun(vehicle, mountPoint);
  82.             break;
  83.  
  84.         case GAME_WEAPON_NO_WEAPON:
  85.         default:
  86.             break;
  87.     }
  88.  
  89.     return ret;
  90. }
  91.