Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 30, 2006, 11:08:47 AM (18 years ago)
Author:
bensch
Message:

orxonox/proxy: added a new Turret for better network synchronisation

File:
1 copied

Legend:

Unmodified
Added
Removed
  • branches/proxy/src/world_entities/npcs/network_turret.cc

    r9606 r9608  
    1414*/
    1515
    16 #include "ground_turret.h"
     16#include "network_turret.h"
    1717#include "model.h"
    1818#include "world_entities/weapons/turret.h"
     
    2929#include "effects/explosion.h"
    3030
    31 CREATE_FACTORY(GroundTurret, CL_GROUND_TURRET);
     31#include "weapons/targeting_turret.h"
     32
     33CREATE_FACTORY(NetworkTurret, CL_NETWORK_TURRET);
    3234
    3335
     
    3537
    3638/**
    37  * constructs and loads a GroundTurret from a XML-element
     39 * constructs and loads a NetworkTurret from a XML-element
    3840 * @param root the XML-element to load from
    3941 */
    40 GroundTurret::GroundTurret(const TiXmlElement* root)
     42NetworkTurret::NetworkTurret(const TiXmlElement* root)
    4143    : NPC(root)
    4244{
     
    5052 * standard deconstructor
    5153 */
    52 GroundTurret::~GroundTurret ()
     54NetworkTurret::~NetworkTurret ()
     55{}
     56
     57
     58/**
     59 * initializes the NetworkTurret
     60 * @todo change this to what you wish
     61 */
     62void NetworkTurret::init()
    5363{
     64  this->setClassID(CL_NETWORK_TURRET, "NetworkTurret");
     65  this->loadModel("models/network_turret_#.obj", 5);
     66  this->weapon = new TargetingTurret();
     67  this->weapon->loadModel("models/guns/turret2.obj", 10);
     68
     69  this->setHealthMax(300);
     70  this->setHealth(300);
     71
     72  this->weaponHolder.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
     73
     74  this->weaponHolder.setRelCoor(0,25,0);
     75  this->weaponHolder.setParent(this);
    5476}
    5577
    5678
    5779/**
    58  * initializes the GroundTurret
    59  * @todo change this to what you wish
    60  */
    61 void GroundTurret::init()
    62 {
    63   this->setClassID(CL_GROUND_TURRET, "GroundTurret");
    64   this->loadModel("models/ground_turret_#.obj", 5);
    65   this->left = NULL;
    66   this->right = NULL;
    67 
    68   this->setHealthMax(300);
    69   this->setHealth(300);
    70 
    71   this->weaponHolder[0].addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
    72   this->weaponHolder[1].addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
    73 
    74   this->weaponHolder[0].setRelCoor(0,25,0);
    75   this->weaponHolder[0].setParent(this);
    76   this->weaponHolder[1].setParent(this);
    77 }
    78 
    79 
    80 /**
    81  * @brief loads a GroundTurret from a XML-element
     80 * @brief loads a NetworkTurret from a XML-element
    8281 * @param root the XML-element to load from
    8382 * @todo make the class Loadable
    8483 */
    85 void GroundTurret::loadParams(const TiXmlElement* root)
     84void NetworkTurret::loadParams(const TiXmlElement* root)
    8685{
    8786  // all the clases this Entity is directly derived from must be called in this way, to load all settings.
    8887  NPC::loadParams(root);
    89 
    90   /**
    91    * @todo: make the class Loadable
    92    */
    93   const TiXmlElement* element;
    94 
    95   element = root->FirstChildElement("weapon-left");
    96   if (element != NULL) element = element->FirstChildElement();
    97   this->left = dynamic_cast<Weapon*>( Factory::fabricate( element) );
    98   if (this->left)
    99   {
    100     this->left->setParent(this);
    101     this->left->toList(this->getOMListNumber());
    102     this->left->setRelCoor(0,10,-5);
    103     this->left->requestAction( WA_ACTIVATE);
    104     this->left->setParent(&this->weaponHolder[0]);
    105   }
    106 
    107   element = root->FirstChildElement("weapon-right");
    108   if (element != NULL)  if (element != NULL) element = element->FirstChildElement();
    109   this->right = dynamic_cast<Weapon*>( Factory::fabricate( element) );
    110   if (this->right)
    111   {
    112     this->right->setParent(this);
    113     this->right->toList(this->getOMListNumber());
    114     this->right->setRelCoor(0,10,5);
    115     this->left->requestAction( WA_ACTIVATE);
    116     this->right->setParent(&this->weaponHolder[0]);
    117   }
    11888}
    11989
    12090/**
    121  * advances the GroundTurret about time seconds
     91 * advances the NetworkTurret about time seconds
    12292 * @param time the Time to step
    12393 */
    124 void GroundTurret::tick(float dt)
     94void NetworkTurret::tick(float dt)
    12595{
    12696  if(this->getHealth() > 0.0f
    12797    ) // HACK <--- YOU ARE THE MOTHERFUCKER
    12898  {
    129     if (likely(this->left != NULL))
     99    if (likely(this->weapon != NULL))
    130100    {
    131101      //    this->left->tickW(dt);
    132       this->left->requestAction(WA_SHOOT);
    133     }
    134     if (likely(this->right != NULL))
    135     {
    136       //    this->right->tickW(dt);
    137       this->right->requestAction(WA_SHOOT);
     102      this->weapon->requestAction(WA_SHOOT);
    138103    }
    139104  }
     
    143108 * draws this worldEntity
    144109 */
    145 void GroundTurret::draw () const
     110void NetworkTurret::draw () const
    146111{
    147112  WorldEntity::draw();
    148113
    149   if (this->left != NULL)
    150     this->left->draw();
    151   if (this->right != NULL)
    152     this->right->draw();
     114  if (this->weapon != NULL)
     115    this->weapon->draw();
    153116}
    154117
     
    159122 *
    160123 */
    161 void GroundTurret::postSpawn ()
    162 {
    163 }
     124void NetworkTurret::postSpawn ()
     125{}
    164126
    165127/**
     
    167129 *
    168130 */
    169 void GroundTurret::leftWorld ()
    170 {
    171 }
     131void NetworkTurret::leftWorld ()
     132{}
    172133
    173 void GroundTurret::destroy(WorldEntity* killer)
     134void NetworkTurret::destroy(WorldEntity* killer)
    174135{
    175136  this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90);
Note: See TracChangeset for help on using the changeset viewer.