Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5968 in orxonox.OLD for branches/network/src/world_entities


Ignore:
Timestamp:
Dec 7, 2005, 4:16:51 PM (19 years ago)
Author:
patrick
Message:

network: merged the trunk into the network with the command svn merge -r5824:HEAD ../trunk network, changes changed… bla bla..

Location:
branches/network/src/world_entities
Files:
16 edited
5 copied

Legend:

Unmodified
Added
Removed
  • branches/network/src/world_entities/Makefile.am

    r5750 r5968  
    77                  world_entity.cc \
    88                  camera.cc \
    9                   player.cc \
     9                  playable.cc \
     10                  player.cc \
    1011                  npc.cc \
    1112                  npc2.cc \
     
    1718                  character_attributes.cc \
    1819                  test_entity.cc \
     20                  space_ships/space_ship.cc \
    1921                  weapons/weapon_manager.cc \
    2022                  weapons/weapon.cc \
     
    3537                 world_entity.h \
    3638                 camera.h \
    37                  player.h \
     39                 playable.h \
     40                 player.h \
    3841                 npc.h \
    3942                 npc2.h \
     
    4548                 character_attributes.h \
    4649                 test_entity.h \
     50                 space_ships/space_ship.h \
    4751                 weapons/weapon_manager.h \
    4852                 weapons/weapon.h \
  • branches/network/src/world_entities/player.cc

    r5833 r5968  
    1010
    1111   ### File Specific:
    12    main-programmer: Patrick Boenzli
    13    co-programmer: Christian Meyer
     12   main-programmer: Silvan Nellen
     13   co-programmer: Benjamin Knecht
    1414*/
    1515
    16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
    17 
    18 
    19 #include "executor/executor.h"
    2016#include "player.h"
    21 
    22 #include "track_manager.h"
    23 #include "objModel.h"
    24 #include "resource_manager.h"
    25 #include "factory.h"
    26 
    27 #include "weapons/weapon_manager.h"
    28 #include "weapons/test_gun.h"
    29 #include "weapons/turret.h"
    30 #include "weapons/cannon.h"
    31 
    32 #include "list.h"
     17#include "playable.h"
    3318
    3419#include "event_handler.h"
    3520
    36 #include "event.h"
    37 
    3821using namespace std;
    39 
    40 CREATE_FACTORY(Player, CL_PLAYER);
    41 
    42 
    43 
    44 #define UP    0
    45 #define DOWN  1
    46 #define RIGHT 2
    47 #define LEFT  3
    48 #define TIME  4
    4922
    5023
    5124/**
    5225 * creates a new Player
    53  * @param isFree if the player is free
    5426*/
    5527Player::Player()
     
    5830}
    5931
    60 /**
    61  * loads a Players information from a specified file.
    62  * @param fileName the name of the File to load the player from (absolute path)
    63  */
    64 Player::Player(const char* fileName)
    65 {
    66   this->init();
    67   TiXmlDocument doc(fileName);
    68 
    69   if(!doc.LoadFile())
    70   {
    71     PRINTF(2)("Loading file %s failed for player.\n", fileName);
    72     return;
    73   }
    74 
    75   this->loadParams(doc.RootElement());
    76 }
    77 
    78 /**
    79  *  creates a new Player from Xml Data
    80  * @param root the xml element containing player data
    81 
    82    @todo add more parameters to load
    83 */
    84 Player::Player(const TiXmlElement* root)
    85 {
    86   this->init();
    87   if (root != NULL)
    88     this->loadParams(root);
    89 
    90   //weapons:
    91   Weapon* wpRight = new TestGun(0);
    92   wpRight->setName("testGun Right");
    93   Weapon* wpLeft = new TestGun(1);
    94   wpLeft->setName("testGun Left");
    95   Weapon* cannon = dynamic_cast<Weapon*>(Factory::getFirst()->fabricate(CL_CANNON));
    96 
    97   cannon->setName("BFG");
    98 
    99   this->weaponMan->addWeapon(wpLeft, 1, 0);
    100   this->weaponMan->addWeapon(wpRight,1 ,1);
    101   this->weaponMan->addWeapon(cannon, 0, 6);
    102 
    103   //this->weaponMan->addWeapon(turret, 3, 0);
    104 
    105   this->weaponMan->changeWeaponConfig(1);
    106 }
    10732
    10833/**
     
    11136Player::~Player ()
    11237{
    113   /* do not delete the weapons, they are contained in the pnode tree
    114   and will be deleted there.
    115   this only frees the memory allocated to save the list.
    116   */
    117   delete this->weaponMan;
    118   if( this->outData)
    119     delete[] this->outData;
    120   if( this->inData)
    121     delete[] this->inData;
    12238}
    12339
    124 //#include "glgui_pushbutton.h"
    12540
    12641/**
     
    13348
    13449  PRINTF(4)("PLAYER INIT\n");
    135   travelSpeed = 15.0;
    136   bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
    137   bFire = false;
    138   acceleration = 10.0;
    13950
    140 //   GLGuiButton* button = new GLGuiPushButton();
    141 //   button->show();
    142 //   button->setLabel("orxonox");
    143 //   button->setBindNode(this);
    144 
    145   this->weaponMan = new WeaponManager(this);
    146   this->weaponMan->setSlotCount(7);
    147 
    148   this->weaponMan->setSlotPosition(0, Vector(-2.6, .1, -3.0));
    149   this->weaponMan->setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
    150 
    151   this->weaponMan->setSlotPosition(1, Vector(-2.6, .1, 3.0));
    152   this->weaponMan->setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
    153 
    154   this->weaponMan->setSlotPosition(2, Vector(-1.5, .5, -.5));
    155   this->weaponMan->setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0)));
    156 
    157   this->weaponMan->setSlotPosition(3, Vector(-1.5, .5, .5));
    158   this->weaponMan->setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0)));
    159 
    160   this->weaponMan->setSlotPosition(4, Vector(-1.5, -.5, .5));
    161   this->weaponMan->setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0)));
    162 
    163   this->weaponMan->setSlotPosition(5, Vector(-1.5, -.5, -.5));
    164   this->weaponMan->setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0)));
    165 //
    166    this->weaponMan->setSlotPosition(6, Vector(-1, 0.0, 0));
    167    this->weaponMan->setSlotCapability(6, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
    168    //
    169 //   this->weaponMan->setSlotPosition(8, Vector(-2.5, -0.3, -2.0));
    170 //   this->weaponMan->setSlotDirection(8, Quaternion(-M_PI, Vector(1,0,0)));
    171 //
    172 //   this->weaponMan->setSlotPosition(9, Vector(-2.5, -0.3, 2.0));
    173 //   this->weaponMan->setSlotDirection(9, Quaternion(+M_PI, Vector(1,0,0)));:
    174 
    175   this->outBufferLength = 100;
    176   this->outLength = 0;
    177   this->recLength = 0;
    178   this->inBufferLength = 100;
    179   this->inLength = 0;
    180   this->sentLength = 0;
    181   this->outData = new byte[this->outBufferLength];
    182   this->inData = new byte[this->inBufferLength];
     51  this->controllable = NULL;
    18352}
    18453
    18554
    186 /**
    187  * loads the Settings of a Player from an XML-element.
    188  * @param root the XML-element to load the Player's properties from
    189  */
    190 void Player::loadParams(const TiXmlElement* root)
     55bool Player::setControllable(Playable* controllable)
    19156{
    192   static_cast<WorldEntity*>(this)->loadParams(root);
    193 
    194 
    195 
     57  if(controllable != NULL && controllable->subscribePlayer(this))
     58  {
     59      this->controllable = controllable;
     60      return true;
     61  }
     62  else
     63    return false;
    19664}
    19765
    198 /**
    199  * adds a weapon to the weapon list of player
    200  * @param weapon to add
    201 */
    202 void Player::addWeapon(Weapon* weapon)
    203 {
    204   this->weaponMan->addWeapon(weapon);
    205 }
     66bool Player::disconnectControllable()
     67 {
     68   if(this->controllable == NULL) return true;
    20669
     70   if(this->controllable->unsubscribePlayer(this))
     71   {
     72     this->controllable = NULL;
     73     return true;
     74   }
     75   else
     76     return false;
     77 }
    20778
    208 /**
    209  *  removes a weapon from the player
    210  * @param weapon to remove
    211 */
    212 void Player::removeWeapon(Weapon* weapon)
    213 {
    214   this->weaponMan->removeWeapon(weapon);
    215 }
     79 void Player::process(const Event &event)
     80 {
     81   if (likely(this->controllable != NULL))
     82     this->controllable->process(event);
     83 }
    21684
    217 
    218 /**
    219  *  effect that occurs after the player is spawned
    220 */
    221 void Player::postSpawn ()
    222 {
    223   //setCollision(new CollisionCluster(1.0, Vector(0,0,0)));
    224 }
    225 
    226 
    227 /**
    228  *  the action occuring if the player left the game
    229 */
    230 void Player::leftWorld ()
    231 {}
    232 
    233 
    234 WorldEntity* ref = NULL;
    235 /**
    236  *  this function is called, when two entities collide
    237  * @param entity: the world entity with whom it collides
    238  *
    239  * Implement behaviour like damage application or other miscellaneous collision stuff in this function
    240  */
    241 void Player::collidesWith(WorldEntity* entity, const Vector& location)
    242 {
    243   if (entity->isA(CL_TURRET_POWER_UP) && entity != ref)
    244   {
    245     this->ADDWEAPON();
    246     ref = entity;
    247     }
    248 //  PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z);
    249 }
    250 
    251 /**
    252  *  draws the player after transforming him.
    253 */
    254 void Player::draw () const
    255 {
    256   glMatrixMode(GL_MODELVIEW);
    257   glPushMatrix();
    258   /* translate */
    259   glTranslatef (this->getAbsCoor ().x,
    260                 this->getAbsCoor ().y,
    261                 this->getAbsCoor ().z);
    262   /* rotate */
    263   Vector tmpRot = this->getAbsDir().getSpacialAxis();
    264   glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
    265   this->model->draw();
    266   glPopMatrix();
    267 
    268   this->weaponMan->draw();
    269 
    270   //this->debug(0);
    271 }
    272 
    273 
    274 /**
    275  *  the function called for each passing timeSnap
    276  * @param time The timespan passed since last update
    277 */
    278 void Player::tick (float time)
    279 {
    280   // player controlled movement
    281   this->move(time);
    282 
    283   this->weaponMan->tick(time);
    284   // weapon system manipulation
    285   this->weaponAction();
    286 }
    287 
    288 
    289 /**
    290  *  action if player moves
    291  * @param time the timeslice since the last frame
    292 */
    293 void Player::move (float time)
    294 {
    295   Vector accel(0.0, 0.0, 0.0);
    296   Vector rot(0.0, 0.0, 0.0);
    297   float rotVal = 0.0;
    298   /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
    299   /* calculate the direction in which the craft is heading  */
    300   Vector direction (1.0, 0.0, 0.0);
    301   //direction = this->absDirection.apply (direction);
    302   Vector orthDirection (0.0, 0.0, 1.0);
    303   //orthDirection = orthDirection.cross (direction);
    304 
    305 
    306   if( this->outLength >= this->outBufferLength) return;
    307 
    308   if( this->bUp || this->bDown || this->bRight || this->bLeft)
    309   {
    310     this->outData[this->outLength++] = TIME;
    311     this->outData[this->outLength++] = (byte)(lround(time * 100.0f));
    312 
    313     PRINTF(0)("Writing TIME = %i, or %f\n", this->outData[this->outLength-1], time);
    314   }
    315 
    316   if( this->bUp && this->getRelCoor().x < 20)
    317   {
    318     accel += direction;
    319     this->outData[this->outLength++] = UP;
    320   }
    321   if( this->bDown && this->getRelCoor().x > -5)
    322   {
    323     accel -= direction;
    324     this->outData[this->outLength++] = DOWN;
    325   }
    326   if( this->bLeft && TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2)
    327   {
    328     accel -=(orthDirection);
    329     rot +=Vector(1,0,0);
    330     rotVal -= .4;
    331     this->outData[this->outLength++] = LEFT;
    332   }
    333   if( this->bRight && TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2)
    334   {
    335     accel += orthDirection;
    336     rot += Vector(1,0,0);
    337     rotVal += .4;
    338     this->outData[this->outLength++] = RIGHT;
    339   }
    340   if (this->bAscend )
    341   {
    342     accel += Vector(0,1,0);
    343     rot += Vector(0,0,1);
    344     rotVal += .4;
    345   }
    346   if (this->bDescend )
    347   {
    348     accel -= Vector(0,1,0);
    349     rot += Vector(0,0,1);
    350     rotVal -= .4;
    351   }
    352 
    353 
    354   Vector move = accel * time *acceleration;
    355 
    356 /*  if (accel.z < 0)
    357     this->setRelDirSoft(Quaternion(-.4, accel), 5);
    358   else if (accel.z > 0)
    359     this->setRelDirSoft(Quaternion(.4, accel), 5);
    360   else*/
    361   rot.normalize();
    362   this->setRelDirSoft(Quaternion(rotVal, rot), 5);
    363   this->shiftCoor (move);
    364 
    365 
    366 }
    367 
    368 
    369 /**
    370  * weapon manipulation by the player
    371 */
    372 void Player::weaponAction()
    373 {
    374   if( this->bFire)
    375     {
    376       this->weaponMan->fire();
    377     }
    378 }
    379 
    380 /**
    381  * @todo switch statement ??
    382  */
    383 void Player::process(const Event &event)
    384 {
    385   if( event.type == KeyMapper::PEV_UP)
    386       this->bUp = event.bPressed;
    387   else if( event.type == KeyMapper::PEV_DOWN)
    388       this->bDown = event.bPressed;
    389   else if( event.type == KeyMapper::PEV_RIGHT)
    390       this->bRight= event.bPressed;
    391   else if( event.type == KeyMapper::PEV_LEFT)
    392       this->bLeft = event.bPressed;
    393   else if( event.type == KeyMapper::PEV_FIRE1)
    394       this->bFire = event.bPressed;
    395   else if( event.type == KeyMapper::PEV_NEXT_WEAPON && event.bPressed)
    396     this->weaponMan->nextWeaponConfig();//if( !event.bPressed) this->bWeaponChange = !this->bWeaponChange;
    397   else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed)
    398     this->weaponMan->previousWeaponConfig();
    399 
    400   else if( event.type == SDLK_PAGEUP)
    401     this->bAscend = event.bPressed; //this->shiftCoor(0,.1,0);
    402   else if( event.type == SDLK_PAGEDOWN)
    403     this->bDescend = event.bPressed; //this->shiftCoor(0,-.1,0);
    404 }
    405 
    406 #include "weapons/aiming_turret.h"
    407 // FIXME THIS MIGHT BE CONSIDERED EITHER A FEATURE, OR A BUG
    408 void Player::ADDWEAPON()
    409 {
    410   Weapon* turret = NULL;
    411 
    412   if ((float)rand()/RAND_MAX < .1)
    413   {
    414     //if (this->weaponMan->hasFreeSlot(2, WTYPE_TURRET))
    415     {
    416       turret = new Turret();
    417       this->weaponMan->addWeapon(turret, 2);
    418       this->weaponMan->changeWeaponConfig(2);
    419     }
    420   }
    421   else
    422   {
    423     //if (this->weaponMan->hasFreeSlot(3))
    424     {
    425       turret = new AimingTurret();
    426       this->weaponMan->addWeapon(turret, 3);
    427 
    428       this->weaponMan->changeWeaponConfig(3);
    429     }
    430   }
    431 
    432   if(turret != NULL)
    433   {
    434     turret->setName("Turret");
    435     turret->setStateDuration(WS_SHOOTING, (float)rand()/RAND_MAX*.5+.1);
    436   }
    437 }
    438 
    439 
    440 
    441 
    442 /**
    443  *  write data to Synchronizeable
    444  */
    445 void Player::writeBytes(const byte* data, int length)
    446 {
    447  // PRINTF(0)("Player: got %i bytes of data\n", length);
    448   this->inLength = length;
    449 
    450   /*
    451    bytes:  | 0  |  1  |
    452            CODE  DIST
    453 
    454 
    455   CODE:
    456        0 :   Up
    457        1 :   Down
    458        2 :   Right
    459        3 :   Left
    460        4 :   TIME
    461 
    462   DIST:
    463       Coordinate diff multiplied by 100 and casted to a byte: byte a = (byte)(x * 100)
    464 
    465   */
    466 
    467   float time = 0.0f;
    468 
    469   Vector accel(0.0, 0.0, 0.0);
    470   Vector direction (1.0, 0.0, 0.0);
    471   Vector orthDirection (0.0, 0.0, 1.0);
    472 
    473   byte code = 0;
    474 
    475   /* iterate through all bytes */
    476   for( int i = 0; i < length; i++)
    477   {
    478    
    479     code = data[i];
    480 
    481     //PRINTF(0)("got byte: %u\n", data[i]);
    482     /* is it a time code? */
    483     if( code == TIME)
    484     {
    485       /* is it the first time */
    486      
    487       /* read out new movement */
    488       time = (float)(data[++i] / 100.0f);
    489       //PRINTF(0)("Got time: %f msec\n", time);
    490     }
    491    
    492     else if( code == UP && this->getRelCoor().x < 20)
    493       accel = accel+(direction*acceleration);
    494     else if( code == DOWN && this->getRelCoor().x > -5)
    495       accel = accel -(direction*acceleration);
    496     else if( code == LEFT && TrackManager::getInstance()->getWidth() > -this->getRelCoor().z*2)
    497       accel = accel - (orthDirection*acceleration);
    498     else if( code == RIGHT && TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2)
    499       accel = accel + (orthDirection*acceleration);
    500  
    501     if( time > 0.0f )
    502     {
    503       /* apply movement */
    504       Vector move = accel * time;
    505 
    506       if (accel.z < 0)
    507         this->setRelDirSoft(Quaternion(-.4, Vector(1,0,0)), 5);
    508       else if (accel.z > 0)
    509         this->setRelDirSoft(Quaternion(.4, Vector(1,0,0)), 5);
    510       else
    511         this->setRelDirSoft(Quaternion(0, Vector(1,0,0)), 5);
    512       this->shiftCoor (move);
    513     }
    514 
    515   }
    516 
    517  
    518 
    519 
    520 
    521   /* and debug output */
    522   this->writeDebug();
    523 }
    524 
    525 
    526 /**
    527  *  read data from Synchronizeable
    528  */
    529 int Player::readBytes(byte* data)
    530 {
    531  // PRINTF(0)("Player: sent %i bytes of data\n", this->sentLength);
    532 
    533   /* copy data */
    534   for( int i = 0; i < this->outLength; ++i)
    535     data[i] = this->outData[i];
    536 
    537 
    538 
    539   /* debug msg */
    540   this->readDebug();
    541 
    542   int length = this->outLength;
    543   this->outLength = 0;
    544   /* return the length of the test */
    545   return length;
    546 }
    547 
    548 
    549 void Player::writeDebug() const
    550 {
    551 
    552 }
    553 
    554 
    555 void Player::readDebug() const
    556 {
    557 
    558 }
    559 
  • branches/network/src/world_entities/player.h

    r5829 r5968  
    77#define _PLAYER_H
    88
    9 #include "world_entity.h"
    10 #include "physics_interface.h"
    119#include "event_listener.h"
    1210
    13 template<class T>
    14 class tList;
    15 class Weapon;
    16 class WeaponManager;
    17 class Vector;
    18 class Event;
     11/* Forward Declaration */
     12class Playable;
    1913
    2014//! Basic controllable WorldEntity
     
    2418     the player.cc for debug also
    2519*/
    26 class Player : public WorldEntity, public EventListener
     20class Player : public EventListener
    2721{
    28     friend class World;
    2922
    3023  public:
    3124    Player();
    32     Player(const char* fileName);
    33     Player(const TiXmlElement* root);
    3425    virtual ~Player();
    3526
    36     void init();
    37     void loadParams(const TiXmlElement* root);
     27    bool              setControllable(Playable* controllalble);
     28    inline Playable*  getControllable() { return this->controllable; };
    3829
    39     void addWeapon(Weapon* weapon);
    40     void removeWeapon(Weapon* weapon);
     30    bool              disconnectControllable();
    4131
    42     /* WorldEntity functions */
    43     virtual void postSpawn();
    44     virtual void leftWorld();
    45 
    46     virtual void collidesWith(WorldEntity* entity, const Vector& location);
    47     virtual void tick(float time);
    48     virtual void draw() const;
    49 
    50     virtual void process(const Event &event);
    51 
    52     /* Synchronizeable functions */
    53     virtual void writeBytes(const byte* data, int length);
    54     virtual int readBytes(byte* data);
     32    // eventListener extension.
     33    virtual void      process(const Event &event);
    5534
    5635  private:
    57     void move(float time);
    58     void weaponAction();
     36    void              init();
    5937
    60     /* Synchronizeable functions */
    61     virtual void writeDebug() const;
    62     virtual void readDebug() const;
    63 
    64     // !! temporary !!
    65     void ADDWEAPON();
    6638
    6739  private:
    68     bool                  bUp;                //!< up button pressed.
    69     bool                  bDown;              //!< down button pressed.
    70     bool                  bLeft;              //!< left button pressed.
    71     bool                  bRight;             //!< right button pressed.
    72     bool                  bAscend;            //!< ascend button pressed.
    73     bool                  bDescend;           //!< descend button presses.
    74     bool                  bFire;              //!< fire button pressed.
    75 
    76     WeaponManager*        weaponMan;          //!< the weapon manager: managing a list of weapon to wepaon-slot mapping
    77 
    78     Vector                velocity;           //!< the velocity of the player.
    79     float                 travelSpeed;        //!< the current speed of the player (to make soft movement)
    80     float                 acceleration;       //!< the acceleration of the player.
    81 
    82     byte*                 inData;
    83     int                   inLength;
    84     int                   inBufferLength;
    85     int                   recLength;
    86     byte*                 outData;
    87     int                   outLength;
    88     int                   outBufferLength;
    89     int                   sentLength;
    90 
     40    Playable*         controllable;                  //!< The one we controll or NULL if none
    9141};
    9242
  • branches/network/src/world_entities/power_ups/laser_power_up.cc

    r5750 r5968  
    7979{
    8080 // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z);
    81  if (entity->isA(CL_PLAYER))
     81 if (entity->isA(CL_PLAYABLE))
    8282  State::getWorldEntityList()->remove(this);
    8383}
  • branches/network/src/world_entities/power_ups/turret_power_up.cc

    r5750 r5968  
    7979{
    8080 // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z);
    81  if (entity->isA(CL_PLAYER))
     81 if (entity->isA(CL_PLAYABLE))
    8282  State::getWorldEntityList()->remove(this);
    8383}
  • branches/network/src/world_entities/weapons/aiming_turret.cc

    r5819 r5968  
    2626
    2727#include "animation3d.h"
    28 #include "sound_engine.h"
    2928
    3029#include "factory.h"
     
    9392
    9493  this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET);
    95   this->setProjectileType(CL_ROCKET);
     94  this->setProjectileType(CL_GUIDED_MISSILE);
    9695
    9796
     
    142141    return;
    143142
    144     pj->setVelocity(/*this->getVelocity()+*/(this->getAbsDir().apply(Vector(1,0,0))*250.0 + VECTOR_RAND(13)
     143  pj->setVelocity(/*this->getVelocity()+*/(this->getAbsDir().apply(Vector(1,0,0))*250.0 + VECTOR_RAND(13)
    145144            /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
    146145
     146  pj->setTarget(this->target->getParent());
    147147  pj->setParent(NullParent::getInstance());
    148148  pj->setAbsCoor(this->getEmissionPoint());
  • branches/network/src/world_entities/weapons/bomb.cc

    r5769 r5968  
    1717#include "glincl.h"
    1818#include "state.h"
     19#include "model.h"
     20#include "primitive_model.h"
     21
     22#include "fast_factory.h"
    1923#include "list.h"
    20 #include "model.h"
    21 #include "vector.h"
    22 #include "fast_factory.h"
    2324
     25#include "object_manager.h"
    2426
    2527#include "particle_engine.h"
     
    5961Bomb::~Bomb ()
    6062{
     63  delete this->detonationSphere;
     64  delete this->detonationMaterial;
    6165
    6266}
     
    7175  this->setClassID(CL_BOMB, "Bomb");
    7276
     77
     78  this->detonationSphere = new PrimitiveModel(PRIM_SPHERE);
     79  this->detonationMaterial = new Material();
     80  this->detonationMaterial->setDiffuse(1, 0, 0);
     81  //   this->detonationMaterial->setTransparency(.1);
    7382  /**
    7483   * @todo: Write CL_PROTO_WORLD_ENTITY INTO THE src/defs/class_id.h (your own definition)
     
    101110void Bomb::tick(float time)
    102111{
    103   //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
    104   Vector v = this->velocity * (time);
    105   this->shiftCoor(v);
    106 
    107112  this->lifeCycle += time/this->lifeSpan;
    108113  if( this->lifeCycle >= 1.0)
     
    114119      this->deactivate();
    115120    }
     121  else if (this->lifeCycle > 0.9f)
     122    this->detonate ((this->lifeCycle-.89) *1000.0);
     123  else
     124  {
     125    Vector v = this->velocity * (time);
     126    this->shiftCoor(v);
     127  }
    116128}
    117129
     
    133145  glMultMatrixf((float*)matrix);
    134146
    135   if (model)
    136     model->draw();
     147  if (this->lifeCycle < .9)
     148  {
     149    if (model)
     150      model->draw();
     151  }
     152  else
     153  {
     154    glScalef((this->lifeCycle-.89) *1000.0,
     155              (this->lifeCycle-.89) *1000.0,
     156              (this->lifeCycle-.89) *1000.0);
     157    this->detonationMaterial->select();
     158    this->detonationSphere->draw();
     159  }
    137160  glPopMatrix();
    138161}
     
    145168void Bomb::collidesWith (WorldEntity* entity, const Vector& location)
    146169{
    147         this->detonate();
     170  if (this->lifeCycle < .9f && entity->isA(CL_NPC))
     171    this->lifeCycle = 0.9f;
    148172}
    149173
     
    157181{
    158182  State::getWorldEntityList()->remove(this);
     183  this->lifeCycle = 0.0f;
    159184  Bomb::fastFactory->kill(this);
    160185}
    161186
    162 void Bomb::detonate()
     187void Bomb::detonate(float size)
    163188{
    164   tIterator<WorldEntity>* it = State::getWorldEntityList()->getIterator();
    165   WorldEntity* lm = it->firstElement();
    166 
    167   while(lm != NULL)
     189  std::list<WorldEntity*>* detonationList = ObjectManager::distanceFromObject(*this, size, CL_NPC);
     190  if (detonationList != NULL)
    168191  {
    169 
    170     lm = it->nextElement();
     192    while( !detonationList->empty() )
     193    {
     194      detonationList->front()->collidesWith(this, Vector(0,0,0));
     195      detonationList->pop_front();
     196    }
     197    delete detonationList;
    171198  }
    172199}
  • branches/network/src/world_entities/weapons/bomb.h

    r5750 r5968  
    88
    99#include "projectile.h"
     10
    1011class FastFactory;
    1112class ParticleSystem;
    1213class ParticleEmitter;
     14class Material;
    1315
    1416//! A Class to ...
     
    3133  virtual void collidesWith (WorldEntity* entity, const Vector& location);
    3234  virtual void activate();
    33   virtual void detonate();
    3435  virtual void deactivate();
     36
     37  void detonate(float size);
    3538
    3639 private:
     
    4043
    4144  ParticleEmitter*                  emitter;
    42 
     45  Model*                            detonationSphere;
     46  Material*                         detonationMaterial;
    4347};
    4448
  • branches/network/src/world_entities/weapons/cannon.cc

    r5819 r5968  
    3232#include "list.h"
    3333#include "animation3d.h"
    34 #include "sound_engine.h"
    3534
    3635#include "null_parent.h"
     
    8382  this->setStateDuration(WS_DEACTIVATING, .4);
    8483
    85   this->setMaximumEnergy(100, 1);
    86   this->increaseEnergy(30);
     84  this->setMaximumEnergy(100, 20);
     85  this->increaseEnergy(100);
    8786  //this->minCharge = 2;
    8887
  • branches/network/src/world_entities/weapons/ground_turret.cc

    r5819 r5968  
    145145void GroundTurret::collidesWith (WorldEntity* entity, const Vector& location)
    146146{
    147 
     147  if (entity->isA(CL_PROJECTILE))
     148    this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90);
    148149}
    149150
  • branches/network/src/world_entities/weapons/guided_missile.cc

    r5779 r5968  
    4848  this->energyMin = 1;
    4949  this->energyMax = 10;
    50   this->lifeSpan = 5;
    51   this->agility = 5;
     50  this->lifeSpan = 5.0;
     51  this->agility = 5.0;
    5252  this->maxVelocity = 100;
    5353
  • branches/network/src/world_entities/weapons/test_gun.cc

    r5819 r5968  
    3232#include "list.h"
    3333#include "animation3d.h"
    34 #include "sound_engine.h"
    3534
    3635#include "null_parent.h"
  • branches/network/src/world_entities/weapons/turret.cc

    r5819 r5968  
    2626#include "list.h"
    2727#include "animation3d.h"
    28 #include "sound_engine.h"
    2928
    3029#include "factory.h"
  • branches/network/src/world_entities/weapons/weapon.cc

    r5750 r5968  
    2828#include "load_param.h"
    2929#include "state.h"
    30 #include "sound_engine.h"
    3130#include "animation3d.h"
    3231#include "vector.h"
     32
     33#include "sound_source.h"
     34#include "sound_buffer.h"
    3335
    3436////////////////////
  • branches/network/src/world_entities/weapons/weapon_manager.cc

    r5779 r5968  
    110110  this->crossHairSizeAnim->addKeyFrame(100, .05, ANIM_LINEAR);
    111111  this->crossHairSizeAnim->addKeyFrame(50, .01, ANIM_LINEAR);
    112 
    113   this->targetIterator = NULL;
    114112}
    115113
     
    337335    }
    338336  }
    339 }
    340 
    341 
    342 /**
    343  * Selects an Entity from the NPC-list, and returns the Target
    344  */
    345 PNode* WeaponManager::getSomeTarget()
    346 {
    347    if (this->targetIterator == NULL)
    348    {
    349      std::list<BaseObject*>* npcList = ClassList::getList(CL_NPC);
    350      if (npcList != NULL)
    351      {
    352        this->targetIterator = npcList->begin();
    353      }
    354      else
    355        return NULL;
    356    }
    357 
    358    ///FIXME
    359 //   this->targetIterator++;
    360    PNode* retNode = dynamic_cast<PNode*>((*targetIterator));
    361 //   if (retNode == NULL && this->targetIterator->getList()->getSize() > 0)
    362 //     retNode =  dynamic_cast<PNode*>(targetIterator->firstElement());
    363 
    364    return retNode;
    365 }
    366 
    367 
    368 /**
    369  * Selects an Entity from the Entity-List, that is near of the carrier PNode.
    370  * @param carrier: The PNode from which the distance should be measured
    371  * @param distance: The Maximum Distance to Return.
    372  */
    373 PNode* WeaponManager::getDistanceTarget(const PNode* carrier, float distance)
    374 {
    375   std::list<BaseObject*>* npcList = ClassList::getList(CL_NPC);
    376   if (npcList != NULL)
    377   {
    378     list<BaseObject*>::iterator node;
    379     for (node= npcList->begin(); node != npcList->end(); node++)
    380       if ((carrier->getAbsCoor() - dynamic_cast<PNode*>(*node)->getAbsCoor()).len() < distance)
    381         return dynamic_cast<PNode*>(*node);
    382   }
    383   return this->getFixedTarget();
    384337}
    385338
  • branches/network/src/world_entities/weapons/weapon_manager.h

    r5779 r5968  
    8080    /** @returns a fixed target namely the Crosshair's 3D position */
    8181    inline PNode* getFixedTarget() const { return this->crosshair; };
    82     PNode* getSomeTarget();
    83     PNode* getDistanceTarget(const PNode* carrier, float distance);
    8482
    8583    void fire();
     
    109107    Crosshair*              crosshair;                                //!< an aim.
    110108    tAnimation<Crosshair>*  crossHairSizeAnim;                        //!< An animation for the crosshair (scaling)
    111 
    112     std::list<BaseObject*>::iterator  targetIterator;                           //!< An iterator for traversion lists of enemies.
    113109};
Note: See TracChangeset for help on using the changeset viewer.