Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7346 in orxonox.OLD


Ignore:
Timestamp:
Apr 19, 2006, 1:17:46 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: extreme cleanup in Playable

Location:
trunk/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/story_entities/multi_player_world_data.cc

    r7337 r7346  
    213213        playable->toList(OM_GROUP_00);
    214214        playable->setAbsCoor(213.37, 57.71, -47.98);
    215         playable->setStartDirection(Quaternion(M_PI, Vector(0.0, 1.0, 0.0)));
     215        playable->setPlayDirection(Quaternion(M_PI, Vector(0.0, 1.0, 0.0)));
    216216      }
    217217    }
  • trunk/src/world_entities/creatures/md2_creature.h

    r7337 r7346  
    2424
    2525    virtual void loadParams(const TiXmlElement* root);
    26     virtual void setStartDirection(const Quaternion& rot) {/* FIXME */};
     26    virtual void setPlayDirection(const Quaternion& rot, float speed = 0.0f) {/* FIXME */};
    2727
    2828    virtual void enter();
  • trunk/src/world_entities/playable.cc

    r7345 r7346  
    6363
    6464
    65 
     65/**
     66 * @brief destroys the Playable
     67 */
    6668Playable::~Playable()
    6769{
     
    7274}
    7375
    74 
     76/**
     77 * @brief loads Playable parameters onto the Playable
     78 * @param root the XML-root to load from
     79 */
    7580void Playable::loadParams(const TiXmlElement* root)
    7681{
    7782  WorldEntity::loadParams(root);
    7883
    79   LoadParam(root, "abs-dir", this, Playable, setStartDirection);
    80 }
    81 
    82 void Playable::addWeapon(Weapon* weapon, int configID, int slotID)
    83 {
    84   this->weaponMan.addWeapon(weapon, configID, slotID);
    85 
    86   this->weaponConfigChanged();
    87 }
    88 
    89 
    90 void Playable::removeWeapon(Weapon* weapon)
    91 {
    92   this->weaponMan.removeWeapon(weapon);
    93 
    94   this->weaponConfigChanged();
    95 }
    96 
    97 
    98 void Playable::nextWeaponConfig()
    99 {
    100   this->weaponMan.nextWeaponConfig();
    101   this->weaponConfigChanged();
    102 }
    103 
    104 
    105 void Playable::previousWeaponConfig()
    106 {
    107   this->weaponMan.previousWeaponConfig();
    108   this->weaponConfigChanged();
    109 }
    110 
    111 
    112 void Playable::weaponConfigChanged()
    113 {
    114   if (this->currentPlayer != NULL)
    115     this->currentPlayer->weaponConfigChanged();
    116 }
    117 
    118 /**
    119  * @brief sets the CameraMode.
    120  * @param cameraMode: the Mode to switch to.
    121  */
    122 void Playable::setCameraMode(unsigned int cameraMode)
    123 {}
    124 
    125 /**
    126  * @brief sets the Playmode
    127  * @param playmode the Playmode
    128  * @returns true on success, false otherwise
    129  */
    130 bool Playable::setPlaymode(Playable::Playmode playmode)
    131 {
    132   if (!this->playmodeSupported(playmode))
    133     return false;
    134   else
    135   {
    136     this->playmode = playmode;
    137     return true;
    138   }
    139 }
    140 
    141 
    142 /**
    143  * @brief helps us colliding Playables
    144  */
    145 void Playable::collidesWith(WorldEntity* entity, const Vector& location)
    146 {
    147   if (entity == collider)
    148     return;
    149   collider = entity;
    150 
    151   if ( entity->isA(CL_PROJECTILE) && ( !State::isOnline() || SharedNetworkData::getInstance()->isGameServer() ) )
    152   {
    153     this->decreaseHealth(entity->getHealth() *(float)rand()/(float)RAND_MAX);
    154     // EXTREME HACK
    155     if (this->getHealth() <= 0.0f)
    156     {
    157       this->die();
    158     }
    159   }
    160 }
    161 
    162 
    163 void Playable::respawn()
    164 {
    165   PRINTF(0)("Playable respawn\n");
    166   // only if this is the spaceship of the player
    167   if( this == State::getPlayer()->getPlayable())
    168     State::getGameRules()->onPlayerSpawn();
    169 
    170 
    171   if( this->getOwner() % 2 == 0)
    172   {
    173     //     this->toList(OM_GROUP_00);
    174     this->setAbsCoor(213.37, 57.71, -47.98);
    175     this->setAbsDir(0, 0, 1, 0);
    176   }
    177   else
    178   { // red team
    179     //     this->toList(OM_GROUP_01);
    180     this->setAbsCoor(-314.450, 40.701, 83.554);
    181     this->setAbsDir(1.0, -0.015, -0.012, 0.011);
    182   }
    183   this->reset();
    184   this->bDead = false;
    185 }
    186 
    187 
    188 
    189 void Playable::die()
    190 {
    191   Explosion::explode(dynamic_cast<PNode*>(this), Vector(1.0f, 1.0f, 1.0f));
    192 
    193 
    194   if( !this->bDead)
    195   {
    196     PRINTF(0)("Playable dies\n");
    197     // only if this is the spaceship of the player
    198     if (State::isOnline())
    199     {
    200       if( this == State::getPlayer()->getPlayable())
    201         State::getGameRules()->onPlayerDeath();
    202 
    203       //     this->toList(OM_GROUP_05);
    204       //HACK: moves the entity to an unknown place far far away: in the future, GameRules will look for that
    205       this->setAbsCoor(-2000.0, -2000.0, -2000.0);
    206 
    207       //explosion hack
    208 
    209     }
    210     this->bDead = true;
    211   }
    212 }
    213 
    214 
    215 /**
    216  * subscribe to all events the controllable needs
    217  * @param player the player that shall controll this Playable
    218  */
    219 bool Playable::setPlayer(Player* player)
    220 {
    221   // if we already have a Player inside do nothing
    222   if (this->currentPlayer != NULL && player != NULL)
    223   {
    224     return false;
    225   }
    226 
    227   // eject the Player if player == NULL
    228   if (this->currentPlayer != NULL && player == NULL)
    229   {
    230     PRINTF(4)("Player gets ejected\n");
    231 
    232     // unsubscibe all events.
    233     EventHandler* evh = EventHandler::getInstance();
    234     std::vector<int>::iterator ev;
    235     for (ev = this->events.begin(); ev != events.end(); ev++)
    236       evh->unsubscribe( ES_GAME, (*ev));
    237 
    238     // leave the entity
    239     this->leave();
    240 
    241     // eject the current Player.
    242     Player* ejectPlayer = this->currentPlayer;
    243     this->currentPlayer = NULL;
    244     // eject the Player.
    245     ejectPlayer->setPlayable(NULL);
    246 
    247     return true;
    248   }
    249 
    250   // get the new Player inside
    251   if (this->currentPlayer == NULL && player != NULL)
    252   {
    253     PRINTF(4)("New Player gets inside\n");
    254     this->currentPlayer = player;
    255     if (this->currentPlayer->getPlayable() != this)
    256       this->currentPlayer->setPlayable(this);
    257 
    258     /*EventHandler*/
    259     EventHandler* evh = EventHandler::getInstance();
    260     std::vector<int>::iterator ev;
    261     for (ev = this->events.begin(); ev != events.end(); ev++)
    262       evh->subscribe(player, ES_GAME, (*ev));
    263 
    264     this->enter();
    265     return true;
    266   }
    267 
    268   return false;
    269 }
    270 
    271 
     84  LoadParam(root, "abs-dir", this, Playable, setPlayDirection);
     85}
     86
     87/**
     88 * @brief picks up a powerup
     89 * @param powerUp the PowerUp that should be picked.
     90 * @returns true on success (pickup was picked, false otherwise)
     91 *
     92 * This function also checks if the Pickup can be picked up by this Playable
     93 */
    27294bool Playable::pickup(PowerUp* powerUp)
    27395{
     
    293115
    294116/**
    295  * add an event to the event list of events this Playable can capture
     117 * @brief adds a Weapon to the Playable.
     118 * @param weapon the Weapon to add.
     119 * @param configID the Configuration ID to add this weapon to.
     120 * @param slotID the slotID to add the Weapon to.
     121 */
     122void Playable::addWeapon(Weapon* weapon, int configID, int slotID)
     123{
     124  this->weaponMan.addWeapon(weapon, configID, slotID);
     125
     126  this->weaponConfigChanged();
     127}
     128
     129/**
     130 * @brief removes a Weapon.
     131 * @param weapon the Weapon to remove.
     132 */
     133void Playable::removeWeapon(Weapon* weapon)
     134{
     135  this->weaponMan.removeWeapon(weapon);
     136
     137  this->weaponConfigChanged();
     138}
     139
     140/**
     141 * @brief jumps to the next WeaponConfiguration
     142 */
     143void Playable::nextWeaponConfig()
     144{
     145  this->weaponMan.nextWeaponConfig();
     146  this->weaponConfigChanged();
     147}
     148
     149/**
     150 * @brief moves to the last WeaponConfiguration
     151 */
     152void Playable::previousWeaponConfig()
     153{
     154  this->weaponMan.previousWeaponConfig();
     155  this->weaponConfigChanged();
     156}
     157
     158/**
     159 * @brief tells the Player, that the Weapon-Configuration has changed.
     160 *
     161 * TODO remove this
     162 * This function is needed, so that the WeponManager of this Playable can easily update the HUD
     163 */
     164void Playable::weaponConfigChanged()
     165{
     166  if (this->currentPlayer != NULL)
     167    this->currentPlayer->weaponConfigChanged();
     168}
     169
     170
     171/**
     172 * @brief subscribe to all events the controllable needs
     173 * @param player the player that shall controll this Playable
     174 * @returns false on error true otherwise.
     175 */
     176bool Playable::setPlayer(Player* player)
     177{
     178  // if we already have a Player inside do nothing
     179  if (this->currentPlayer != NULL && player != NULL)
     180  {
     181    return false;
     182  }
     183
     184  // eject the Player if player == NULL
     185  if (this->currentPlayer != NULL && player == NULL)
     186  {
     187    PRINTF(4)("Player gets ejected\n");
     188
     189    // unsubscibe all events.
     190    EventHandler* evh = EventHandler::getInstance();
     191    std::vector<int>::iterator ev;
     192    for (ev = this->events.begin(); ev != events.end(); ev++)
     193      evh->unsubscribe( ES_GAME, (*ev));
     194
     195    // leave the entity
     196    this->leave();
     197
     198    // eject the current Player.
     199    Player* ejectPlayer = this->currentPlayer;
     200    this->currentPlayer = NULL;
     201    // eject the Player.
     202    ejectPlayer->setPlayable(NULL);
     203
     204    return true;
     205  }
     206
     207  // get the new Player inside
     208  if (this->currentPlayer == NULL && player != NULL)
     209  {
     210    PRINTF(4)("New Player gets inside\n");
     211    this->currentPlayer = player;
     212    if (this->currentPlayer->getPlayable() != this)
     213      this->currentPlayer->setPlayable(this);
     214
     215    /*EventHandler*/
     216    EventHandler* evh = EventHandler::getInstance();
     217    std::vector<int>::iterator ev;
     218    for (ev = this->events.begin(); ev != events.end(); ev++)
     219      evh->subscribe(player, ES_GAME, (*ev));
     220
     221    this->enter();
     222    return true;
     223  }
     224
     225  return false;
     226}
     227
     228/**
     229 * @brief attaches the current Camera to this Playable
     230 *
     231 * this function can be derived, so that any Playable can make the attachment differently.
     232 */
     233void Playable::attachCamera()
     234{
     235  State::getCameraNode()->setParentSoft(this);
     236  State::getCameraTargetNode()->setParentSoft(this);
     237
     238}
     239
     240/**
     241 * @brief detaches the Camera
     242 * @see void Playable::attachCamera()
     243 */
     244void  Playable::detachCamera()
     245{}
     246
     247
     248/**
     249 * @brief sets the CameraMode.
     250 * @param cameraMode: the Mode to switch to.
     251 */
     252void Playable::setCameraMode(unsigned int cameraMode)
     253{}
     254
     255
     256/**
     257 * @brief sets the Playmode
     258 * @param playmode the Playmode
     259 * @returns true on success, false otherwise
     260 */
     261bool Playable::setPlaymode(Playable::Playmode playmode)
     262{
     263  if (!this->playmodeSupported(playmode))
     264    return false;
     265  else
     266  {
     267    this->playmode = playmode;
     268    return true;
     269  }
     270}
     271
     272/**
     273 * @brief This function look, that the Playable rotates to the given rotation.
     274 * @param angle the Angle around
     275 * @param dirX directionX
     276 * @param dirY directionY
     277 * @param dirZ directionZ
     278 * @param speed how fast to turn there.
     279 */
     280void Playable::setPlayDirection(float angle, float dirX, float dirY, float dirZ, float speed)
     281{
     282  this->setPlayDirection(Quaternion(angle, Vector(dirX, dirY, dirZ)), speed);
     283}
     284
     285/**
     286 * @brief all Playable will enter the Playmode Differently, say here how to do it.
     287 * @param playmode the Playmode to enter.
     288 *
     289 * In this function all the actions that are required to enter the Playmode are described.
     290 * e.g: camera, rotation, wait cycle and so on...
     291 */
     292void Playable::enterPlaymode(Playable::Playmode playmode)
     293{
     294
     295}
     296
     297/**
     298 * @brief helps us colliding Playables
     299 * @param entity the Entity to collide
     300 * @param location where the collision occured.
     301 */
     302void Playable::collidesWith(WorldEntity* entity, const Vector& location)
     303{
     304  if (entity == collider)
     305    return;
     306  collider = entity;
     307
     308  if ( entity->isA(CL_PROJECTILE) && ( !State::isOnline() || SharedNetworkData::getInstance()->isGameServer() ) )
     309  {
     310    this->decreaseHealth(entity->getHealth() *(float)rand()/(float)RAND_MAX);
     311    // EXTREME HACK
     312    if (this->getHealth() <= 0.0f)
     313    {
     314      this->die();
     315    }
     316  }
     317}
     318
     319
     320void Playable::respawn()
     321{
     322  PRINTF(0)("Playable respawn\n");
     323  // only if this is the spaceship of the player
     324  if( this == State::getPlayer()->getPlayable())
     325    State::getGameRules()->onPlayerSpawn();
     326
     327
     328  if( this->getOwner() % 2 == 0)
     329  {
     330    //     this->toList(OM_GROUP_00);
     331    this->setAbsCoor(213.37, 57.71, -47.98);
     332    this->setAbsDir(0, 0, 1, 0);
     333  }
     334  else
     335  { // red team
     336    //     this->toList(OM_GROUP_01);
     337    this->setAbsCoor(-314.450, 40.701, 83.554);
     338    this->setAbsDir(1.0, -0.015, -0.012, 0.011);
     339  }
     340  this->reset();
     341  this->bDead = false;
     342}
     343
     344
     345
     346void Playable::die()
     347{
     348  Explosion::explode(dynamic_cast<PNode*>(this), Vector(1.0f, 1.0f, 1.0f));
     349
     350
     351  if( !this->bDead)
     352  {
     353    PRINTF(0)("Playable dies\n");
     354    // only if this is the spaceship of the player
     355    if (State::isOnline())
     356    {
     357      if( this == State::getPlayer()->getPlayable())
     358        State::getGameRules()->onPlayerDeath();
     359
     360      //     this->toList(OM_GROUP_05);
     361      //HACK: moves the entity to an unknown place far far away: in the future, GameRules will look for that
     362      this->setAbsCoor(-2000.0, -2000.0, -2000.0);
     363
     364      //explosion hack
     365
     366    }
     367    this->bDead = true;
     368  }
     369}
     370
     371
     372
     373
     374
     375/**
     376 * @brief add an event to the event list of events this Playable can capture
    296377 * @param eventType the Type of event to add
    297378 */
     
    346427
    347428
    348 
    349 void  Playable::attachCamera()
    350 {
    351   State::getCameraNode()->setParentSoft(this);
    352   State::getCameraTargetNode()->setParentSoft(this);
    353 
    354 }
    355 
    356 
    357 
    358 
    359 void  Playable::detachCamera()
    360 {}
    361 
    362429#define DATA_FLAGS    1
    363430#define DATA_SCORE    2
     
    436503
    437504
     505/**
     506 * @brief converts a string into a Playable::Playmode.
     507 * @param playmode the string naming the Playable::Playmode to convert.
     508 * @returns the Playable::Playmode converted from playmode.
     509 */
    438510Playable::Playmode Playable::stringToPlaymode(const std::string& playmode)
    439511{
     
    450522}
    451523
     524
     525/**
     526 * @brief converts a playmode into a string.
     527 * @param playmode the Playable::Playmode to convert.
     528 * @returns the String.
     529 */
    452530const char* Playable::playmodeToString(Playable::Playmode playmode)
    453531{
  • trunk/src/world_entities/playable.h

    r7339 r7346  
    2727{
    2828public:
     29  //! Defines the Playmode of an Entity.
    2930  typedef enum {
    30     Vertical         = 1,
    31     Horizontal       = 2,
    32     FromBehind       = 4,
    33     Full3D           = 8,
     31    Vertical         = 1,       //!< Vertical (seen from left or right/move in x-z)
     32    Horizontal       = 2,       //!< Horizontal (seet from the top/move in x-y)
     33    FromBehind       = 4,       //!< Seen from behind (move in z-y)
     34    Full3D           = 8,       //!< Full featured 3D-mode. (move in all directions x-y-z)
    3435  } Playmode;
    3536
     
    4041  virtual void loadParams(const TiXmlElement* root);
    4142
    42   virtual void die();
    43   virtual void respawn();
    44 
     43  // Weapon and Pickups
    4544  virtual bool pickup(PowerUp* powerUp);
    46 
    4745  void addWeapon(Weapon* weapon, int configID = -1, int slotID = -1);
    4846  void removeWeapon(Weapon* weapon);
    4947  void nextWeaponConfig();
    5048  void previousWeaponConfig();
    51 
    5249  inline WeaponManager& getWeaponManager() { return this->weaponMan; };
    5350  void weaponConfigChanged();
    5451
    5552
     53  // Player Settup
    5654  bool setPlayer(Player* player);
    5755  Player* getCurrentPlayer() const { return this->currentPlayer; };
     56  /** @return a List of Events in PEV_* sytle */
     57  inline const std::vector<int>& getEventList() { return this->events; };
    5858
     59  // Camera and Playmode
    5960  void attachCamera();
    6061  void detachCamera();
     
    6364  bool setPlaymode(Playable::Playmode playmode);
    6465  Playable::Playmode getPlaymode() const { return this->playmode; };
     66  virtual void setPlayDirection(const Quaternion& rot, float speed = 0.0f) = 0;
     67  void setPlayDirection(float angle, float dirX, float dirY, float dirZ, float speed = 0.0f);
    6568
     69  inline void setScore( int score ) { this->score = score; }
     70  inline int  getScore() { return this->score; }
     71
     72
     73  // WorldEntity Extensions
     74  virtual void die();
     75  virtual void respawn();
    6676  virtual void collidesWith(WorldEntity* entity, const Vector& location);
    6777  virtual void process(const Event &event);
    68 
    6978  virtual void tick(float dt);
    7079
    71   /** @return a List of Events in PEV_* sytle */
    72   inline const std::vector<int>& getEventList() { return this->events; };
    73 
     80  // NETWORK
    7481  int       writeSync(const byte* data, int length, int sender);
    7582  int       readSync(byte* data, int maxLength );
    7683  bool      needsReadSync();
    77 
    78 
    79   //
    80   virtual void setStartDirection(const Quaternion& rot) = 0;
    81   void setStartDirection(float angle, float dirX, float dirY, float dirZ) { this->setStartDirection(Quaternion(angle, Vector(dirX, dirY, dirZ))); }
    82 
    83   inline void setScore( int score ) { this->score = score; }
    84   inline int  getScore() { return this->score; }
    8584
    8685
     
    9190  Playable();
    9291
     92  // Player Setup
    9393  virtual void enter() = 0;
    9494  virtual void leave() = 0;
     95  // Playmode
     96  void setSupportedPlaymodes(short playmodes) { this->supportedPlaymodes = playmodes; };
     97  virtual void enterPlaymode(Playable::Playmode playmode);
    9598
    96   void setSupportedPlaymodes(short playmodes) { this->supportedPlaymodes = playmodes; };
    97 
     99  // Events.
    98100  void registerEvent(int eventType);
    99101  void unregisterEvent(int eventType);
  • trunk/src/world_entities/space_ships/helicopter.h

    r7337 r7346  
    2222
    2323    virtual void loadParams(const TiXmlElement* root);
    24     virtual void setStartDirection(const Quaternion& rot){/* FIXME */};
     24    virtual void setPlayDirection(const Quaternion& rot, float speed = 0.0f) {/* FIXME */};
    2525
    2626    virtual void enter();
  • trunk/src/world_entities/space_ships/hover.h

    r7337 r7346  
    1919
    2020    virtual void loadParams(const TiXmlElement* root);
    21     virtual void setStartDirection(const Quaternion& rot) {/* FIXME */};
     21    virtual void setPlayDirection(const Quaternion& rot, float speed = 0.0f) {/* FIXME */};
    2222
    2323    virtual void enter();
  • trunk/src/world_entities/space_ships/space_ship.cc

    r7337 r7346  
    248248}
    249249
    250 void SpaceShip::setStartDirection(const Quaternion& quat)
     250void SpaceShip::setPlayDirection(const Quaternion& quat, float speed)
    251251{
    252252  this->mouseDir = quat;
  • trunk/src/world_entities/space_ships/space_ship.h

    r7337 r7346  
    2727    virtual void loadParams(const TiXmlElement* root);
    2828
    29     virtual void setStartDirection(const Quaternion& rot);
     29    virtual void setPlayDirection(const Quaternion& rot, float speed = 0.0f);
    3030
    3131    virtual void enter();
  • trunk/src/world_entities/space_ships/turbine_hover.cc

    r7345 r7346  
    103103  this->setClassID(CL_TURBINE_HOVER, "TurbineHover");
    104104
    105   this->setSupportedPlaymodes(Playable::Full3D | Playable::Horizontal);
     105  this->setSupportedPlaymodes(Playable::Full3D | Playable::Horizontal | Playable::Vertical);
    106106
    107107  this->loadModel("models/ships/hoverglider_wing.obj", 1.0f, 3);
     
    393393      }
    394394      break;
     395
     396    case Playable::Vertical:
     397    {
     398      accel.z = 0;
     399      Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration);
     400      accelerationDir.z=0;
     401
     402        // this is the air friction (necessary for a smooth control)
     403      Vector damping = (this->velocity * this->airFriction);
     404
     405      this->velocity += (accelerationDir - damping)* dt;
     406      this->shiftCoor (this->velocity * dt);
     407
     408      this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5);
     409
     410      this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5);
     411      this->rotorNodeLeft.setRelDirSoft(Quaternion(-accel.x * .07+this->rotation + cameraLook, Vector(0,0,1)), 5);
     412
     413      this->wingNodeRight.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5);
     414      this->rotorNodeRight.setRelDirSoft(Quaternion(-accel.x*.07 -this->rotation + cameraLook, Vector(0,0,1)), 5);
     415    }
     416    break;
    395417  }
    396418}
  • trunk/src/world_entities/space_ships/turbine_hover.h

    r7339 r7346  
    2222
    2323    virtual void loadParams(const TiXmlElement* root);
    24     virtual void setStartDirection(const Quaternion& rot) {/* FIXME */};
     24    virtual void setPlayDirection(const Quaternion& rot, float speed = 0.0f) {/* FIXME */};
    2525    virtual void enter();
    2626    virtual void leave();
Note: See TracChangeset for help on using the changeset viewer.