Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 10, 2005, 12:33:31 AM (19 years ago)
Author:
bensch
Message:

world_entities: new AimingTurret added.
This turret aims a Target that is the nearest one, and shoots in its direction

File:
1 copied

Legend:

Unmodified
Added
Removed
  • branches/world_entities/src/world_entities/weapons/aiming_turret.cc

    r5526 r5527  
    1515#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
    1616
    17 #include "turret.h"
     17#include "aiming_turret.h"
    1818
    1919#include "weapon_manager.h"
     
    3030#include "factory.h"
    3131
    32 CREATE_FACTORY(Turret);
     32CREATE_FACTORY(AimingTurret);
    3333
    3434using namespace std;
     
    4040   creates a new weapon
    4141*/
    42 Turret::Turret (WeaponManager* weaponManager)
     42AimingTurret::AimingTurret (WeaponManager* weaponManager)
    4343  : Weapon(weaponManager)
    4444{
     
    5454
    5555
    56 Turret::Turret(const TiXmlElement* root)
     56AimingTurret::AimingTurret(const TiXmlElement* root)
    5757{
    5858  this->init();
     
    6363 *  standard deconstructor
    6464*/
    65 Turret::~Turret ()
     65AimingTurret::~AimingTurret ()
    6666{
    6767  // model will be deleted from WorldEntity-destructor
    6868}
    6969
    70 void Turret::init()
     70void AimingTurret::init()
    7171{
    72   this->setClassID(CL_TURRET, "Turret");
     72  this->setClassID(CL_AIMING_TURRET, "AimingTurret");
    7373
    7474  Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
     
    9898  this->setEmissionPoint(1.684, 0.472, 0);
    9999  //this->getProjectileFactory()->prepare(100);
     100
     101  this->target = NULL;
    100102}
    101103
    102 void Turret::loadParams(const TiXmlElement* root)
     104void AimingTurret::loadParams(const TiXmlElement* root)
    103105{
    104106  static_cast<Weapon*>(this)->loadParams(root);
     
    106108}
    107109
    108 void Turret::activate()
     110void AimingTurret::activate()
    109111{
    110112}
    111113
    112 void Turret::deactivate()
     114void AimingTurret::deactivate()
    113115{
    114116}
    115117
    116 void Turret::tick(float dt)
     118void AimingTurret::tick(float dt)
    117119{
    118120  Quaternion quat;
    119   Vector direction = this->getWeaponManager()->getFixedTarget()->getAbsCoor() - this->getAbsCoor();
     121  if (this->target == NULL)
     122    this->target = this->getWeaponManager()->getDistanceTarget(this, 50);
     123  Vector direction = this->target->getAbsCoor() - this->getAbsCoor();
    120124
    121125  direction.normalize();
     
    126130    quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
    127131
    128   this->setAbsDirSoft(quat, 5);
     132  this->setAbsDirSoft(quat, 20);
    129133}
    130134
    131 void Turret::fire()
     135void AimingTurret::fire()
    132136{
    133137  Projectile* pj = this->getProjectile();
     
    139143  if (target != NULL)
    140144  {
    141     pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*100.0 + VECTOR_RAND(13)
     145    pj->setVelocity(/*this->getVelocity()+*/(this->getAbsDir().apply(Vector(1,0,0))*100.0 + VECTOR_RAND(13)
    142146            /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
    143147  }
     
    149153  pj->setAbsDir(this->getAbsDir());
    150154  pj->activate();
     155  this->target = this->getWeaponManager()->getDistanceTarget(this, 50);
    151156}
    152157
    153 void Turret::destroy ()
     158void AimingTurret::destroy ()
    154159{}
    155160
    156161/**
    157  * draws the Turret
     162 * draws the AimingTurret
    158163*/
    159 void Turret::draw () const
     164void AimingTurret::draw () const
    160165{
    161166  this->getWeaponManager()->getFixedTarget()->debugDraw(10);
Note: See TracChangeset for help on using the changeset viewer.