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

Location:
branches/world_entities/src/world_entities/weapons
Files:
2 edited
2 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);
  • branches/world_entities/src/world_entities/weapons/aiming_turret.h

    r5526 r5527  
    11/*!
    2  * @file turret.h
     2 * @file aiming_turret.h
    33*/
    44
    55
    6 #ifndef _TURRET_H
    7 #define _TURRET_H
     6#ifndef _AIMING_TURRET_H
     7#define _AIMING_TURRET_H
    88
    99#include "weapon.h"
    1010
    11 class Turret : public Weapon
     11class AimingTurret : public Weapon
    1212  {
    1313  public:
    14     Turret (WeaponManager* weaponManager);
    15     Turret(const TiXmlElement* root);
    16     virtual ~Turret ();
     14    AimingTurret (WeaponManager* weaponManager);
     15    AimingTurret(const TiXmlElement* root);
     16    virtual ~AimingTurret ();
    1717
    1818    void init();
     
    2929
    3030  private:
     31    PNode*          target;
    3132  };
    3233
    33 #endif /* _TURRET_H */
     34#endif /* _AIMING_TURRET_H */
  • branches/world_entities/src/world_entities/weapons/weapon_manager.cc

    r5441 r5527  
    2323#include "crosshair.h"
    2424
     25#include "class_list.h"
    2526#include "load_param.h"
    2627#include "factory.h"
    27 #include "vector.h"
    2828#include "list.h"
    2929#include "t_animation.h"
    3030#include "null_parent.h"
     31
    3132
    3233using namespace std;
     
    109110  this->crossHairSizeAnim->addKeyFrame(100, .05, ANIM_LINEAR);
    110111  this->crossHairSizeAnim->addKeyFrame(50, .01, ANIM_LINEAR);
     112
     113  this->targetIterator = NULL;
    111114}
    112115
     
    140143
    141144  Weapon* newWeapon = dynamic_cast<Weapon*>(Factory::getFirst()->fabricate(element));
    142 
    143145
    144146
     
    334336    }
    335337  }
     338}
     339
     340
     341/**
     342 * Selects an Entity from the NPC-list, and returns the Target
     343 */
     344PNode* WeaponManager::getSomeTarget()
     345{
     346   if (this->targetIterator == NULL)
     347   {
     348     tList<BaseObject>* npcList = ClassList::getList(CL_NPC);
     349     if (npcList != NULL)
     350     {
     351       this->targetIterator = npcList->getIterator();
     352       this->targetIterator->firstElement();
     353     }
     354     else
     355       return NULL;
     356   }
     357
     358   PNode* retNode = dynamic_cast<PNode*>(targetIterator->nextElement());
     359   if (retNode == NULL && this->targetIterator->getList()->getSize() > 0)
     360     retNode =  dynamic_cast<PNode*>(targetIterator->firstElement());
     361
     362   return retNode;
     363}
     364
     365
     366/**
     367 * Selects an Entity from the Entity-List, that is near of the carrier PNode.
     368 * @param carrier: The PNode from which the distance should be measured
     369 * @param distance: The Maximum Distance to Return.
     370 */
     371PNode* WeaponManager::getDistanceTarget(const PNode* carrier, float distance)
     372{
     373  tList<BaseObject>* npcList = ClassList::getList(CL_NPC);
     374  if (npcList != NULL)
     375  {
     376    tIterator<BaseObject>* npcIT = npcList->getIterator();
     377    PNode* tmpNPC = dynamic_cast<PNode*>(npcIT->firstElement());
     378    while (tmpNPC != NULL)
     379    {
     380      if ((carrier->getAbsCoor() - tmpNPC->getAbsCoor()).len() < distance)
     381      {
     382        delete npcIT;
     383        return tmpNPC;
     384      }
     385      tmpNPC = dynamic_cast<PNode*>(npcIT->nextElement());
     386    }
     387    delete npcIT;
     388  }
     389  return this->getFixedTarget();
     390
    336391}
    337392
  • branches/world_entities/src/world_entities/weapons/weapon_manager.h

    r5453 r5527  
    1717// FORWARD DECLARATION
    1818template <class T> class tAnimation;
     19template <class T> class tIterator;
    1920
    2021
     
    7778
    7879    /** @returns a fixed target namely the Crosshair's 3D position */
    79     inline PNode* getFixedTarget() { return this->crosshair; };
     80    inline PNode* getFixedTarget() const { return this->crosshair; };
     81    PNode* getSomeTarget();
     82    PNode* getDistanceTarget(const PNode* carrier, float distance);
     83
    8084    void fire();
     85    //! @TODO: implement this function (maybe also in Weapon itself)
     86    void releaseFire();
    8187
    8288    void tick(float dt);
     
    102108    Crosshair*              crosshair;                                //!< an aim.
    103109    tAnimation<Crosshair>*  crossHairSizeAnim;                        //!< An animation for the crosshair (scaling)
     110
     111    tIterator<BaseObject>*  targetIterator;                           //!< An iterator for traversion lists of enemies.
    104112};
Note: See TracChangeset for help on using the changeset viewer.