Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 14, 2007, 5:33:43 PM (17 years ago)
Author:
snellen
Message:

merged adm, hud, vs-enhancements : beni's responsible for this commit. blame him!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/creatures/fps_player.cc

    r10618 r10698  
    1919#include "interactive_model.h"
    2020#include "state.h"
     21#include "tools/camera.h"
     22#include "player.h"
    2123
    2224#include "src/lib/util/loading/factory.h"
     
    5153                            ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY))
    5254                            ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ))
     55                            ->addMethod("displayHUDText", Executor1<FPSPlayer, lua_State*, const std::string&>(&FPSPlayer::displayHUDText))
    5356                       );
    5457
     
    9598  this->bPosBut = false;
    9699  this->bFire = false;
     100  this->bFire2 = false;
     101  this->changeZoom = true;
     102  this->inZoomMode = false;
     103  this->changingZoom = false;
    97104
    98105  this->xMouse = 0.0f;
     
    116123  registerEvent(KeyMapper::PEV_RIGHT);
    117124  registerEvent(KeyMapper::PEV_FIRE1);
     125  registerEvent(KeyMapper::PEV_FIRE2);
    118126  registerEvent(KeyMapper::PEV_JUMP);
     127  registerEvent(KeyMapper::PEV_CROUCH);
    119128  registerEvent(EV_MOUSE_MOTION);
    120129
     
    149158
    150159  this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode);
    151   this->getWeaponManager().getFixedTarget()->setRelCoor(1000,0,0);
     160  this->getWeaponManager().getFixedTarget()->setParentMode(PNODE_ALL);
     161  this->getWeaponManager().getFixedTarget()->setRelCoor(10,0,0);
    152162
    153163
     
    179189}
    180190
    181 
     191/**
     192 * was probabably designed for setting direction of FPSPlayer
     193 * but hey, this connot work like this, can it?
     194 */
    182195void FPSPlayer::setPlayDirection(const Quaternion& quat, float speed)
    183196{
     
    186199}
    187200
    188 
     201/**
     202 * Resets FPSPlayer stats and freezes its moving directions
     203 *
     204 */
    189205void FPSPlayer::reset()
    190206{
     
    195211  this->xMouse = 0.0f;
    196212  this->yMouse = 0.0f;
     213  this->inZoomMode = false;
    197214
    198215  this->setHealth(80);
    199216}
    200217
    201 
     218/**
     219 * Defines what happens to camera and other important elements when changing
     220 * into FPS-view
     221 */
    202222void FPSPlayer::enter()
    203223{
     
    206226  State::getCameraNode()->setParentSoft(&this->cameraNode);
    207227  State::getCameraTargetNode()->setParentSoft(&this->cameraNode);
    208 
    209   this->getWeaponManager().getFixedTarget()->setParent(State::getCameraTargetNode());
    210   this->getWeaponManager().getFixedTarget()->setRelCoor(0,0,0);
     228 
     229  State::getCamera()->setViewMode(Camera::ViewFPS);
     230 
     231  this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode);
     232  //this->getWeaponManager().getFixedTarget()->setParentMode(PNODE_ALL);
     233  //this->getWeaponManager().getFixedTarget()->setRelCoor(100,0,0);
    211234
    212235  if ( !State::isOnline() )
     
    216239}
    217240
     241/**
     242 * Defines what happens if active player leaves FPSPlayer
     243 * (basicly hides crosshair and frees camera)
     244 */
    218245void FPSPlayer::leave()
    219246{
     
    230257void FPSPlayer::tick (float time)
    231258{
    232 
     259     // Second init-step
    233260  if ( !this->initWeapon )
    234261  {
     
    239266    this->getWeaponManager().getParentNode()->setParentMode(PNODE_ROTATE_AND_MOVE);
    240267    this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode);
    241     this->getWeaponManager().getFixedTarget()->setParentMode(PNODE_ROTATE_AND_MOVE);
     268    //this->getWeaponManager().getFixedTarget()->setParentMode(PNODE_ROTATE_AND_MOVE);
     269    State::getCamera()->setViewMode(Camera::ViewFPS);
    242270
    243271
     
    251279    }
    252280
    253 
    254     AABB* box = this->getModelAABB();
    255     if( box != NULL)
    256     {
     281  }
     282  // end of second init-step
     283 
     284  // This box represents the dimension of the used model
     285  AABB* box = this->getModelAABB();
     286
     287  if( box != NULL)
     288  {
    257289      float f = 1.0;
     290      if( this->bCrouch )
     291          f = 0.3*f;
     292     
    258293      this->cameraNode.setRelCoor(0, box->halfLength[1] * f, 0);
    259 //       this->cameraNode.setRelCoor(10, box->halfLength[1] * f, 0);
    260 
    261       float v = 0.1f;
    262       this->getWeaponManager().setSlotPosition(0, Vector(-8.0, box->halfLength[1] * v, 1.1));
    263       this->getWeaponManager().setSlotPosition(1, Vector(5.0, box->halfLength[1] * v, 0.0));
    264     }
    265   }
    266 
     294//      this->cameraNode.setRelCoor(10, box->halfLength[1] * f, 0);
     295     float v = 0.1f;
     296     this->getWeaponManager().setSlotPosition(0, Vector(-8.0, box->halfLength[1] * v, 1.1));
     297     this->getWeaponManager().setSlotPosition(1, Vector(5.0, box->halfLength[1] * v, 0.0));
     298  }
     299 
     300  /*
     301  if( this->bFire2 )
     302  {
     303     
     304      // to change Zoom on click
     305      if( this->changeZoom )
     306      {
     307          this->changeZoom = false;
     308          if( this->inZoomMode )
     309          {
     310              State::getCamera()->setViewMode(Camera::ViewFPS);
     311              this->inZoomMode = false;
     312          }
     313          else
     314          {
     315              State::getCamera()->setViewMode(Camera::ViewFPSZoom);
     316              this->inZoomMode = true;
     317          }
     318         
     319      }
     320     
     321  }
     322  else
     323  {
     324      this->changeZoom = true;
     325  }*/
     326  if( this->bFire2 )
     327  {
     328      if( this->changeZoom )
     329      {
     330          if( !this->inZoomMode || this->changingZoom )
     331          {
     332              this->inZoomMode = true;
     333              this->changingZoom = true;
     334              float fovy = State::getCamera()->getFovy();
     335              if( fovy > 30 )
     336                  State::getCamera()->setFovy( fovy - 10*time );
     337          }
     338          else
     339          {
     340                State::getCamera()->setViewMode(Camera::ViewFPS);
     341                this->inZoomMode = false;
     342                this->changeZoom = false;
     343          }
     344      }
     345  }
     346  else
     347  {
     348      this->changeZoom = true;
     349      this->changingZoom = false;
     350  }
    267351
    268352  this->getWeaponManager().tick(time);
     
    301385    xMouse *= time ;
    302386    yMouse *= time ;
    303 
    304     heading -= xMouse/5.;
    305     attitude-= yMouse/5.;
     387   
     388    float amount;
     389   
     390    if( this->inZoomMode )
     391        amount = 2.;
     392    else
     393        amount = 5.;
     394
     395    heading -= xMouse/amount;
     396    attitude-= yMouse/amount;
    306397
    307398
     
    346437    }*/
    347438
    348   velocity *= 100;
     439  int speed;
     440  if( this->bCrouch )
     441      speed = 50;
     442  else
     443      speed = 100;
     444  velocity *= speed;
    349445
    350446  if( this->getModel( 0) != NULL && this->getModel(0)->isA(InteractiveModel::staticClassID()))
    351447  {
    352     if( this->bJump)
    353     {
    354       if( this->jumpAcceleration < 1.0f)
     448      if( this->bJump)
    355449      {
    356         this->jumpAcceleration = 300.0f;
    357 
    358         if( ((InteractiveModel*)this->getModel(0))->getAnimation() != JUMP)
    359           ((InteractiveModel*)this->getModel(0))->setAnimation(JUMP);
    360       }
    361     }
    362     else if(velocity.len() != 0.0f)
    363     {
    364       if( ((InteractiveModel*)this->getModel(0))->getAnimation() != RUN)
    365         ((InteractiveModel*)this->getModel(0))->setAnimation(RUN);
    366     }
    367     else
    368     {
    369       if( ((InteractiveModel*)this->getModel(0))->getAnimation() != STAND)
    370         ((InteractiveModel*)this->getModel(0))->setAnimation(STAND);
    371     }
     450          if( this->jumpAcceleration < 1.0f)
     451          {
     452              this->jumpAcceleration = 300.0f;
     453
     454              if( ((InteractiveModel*)this->getModel(0))->getAnimation() != JUMP)
     455                  ((InteractiveModel*)this->getModel(0))->setAnimation(JUMP);
     456          }
     457       }
     458       else if(velocity.len() != 0.0f)
     459       {
     460            if( this->bCrouch )
     461            {
     462                if( ((InteractiveModel*)this->getModel(0))->getAnimation() != CROUCH_WALK)
     463                    ((InteractiveModel*)this->getModel(0))->setAnimation(CROUCH_WALK);
     464            }
     465            else
     466            {
     467                if( ((InteractiveModel*)this->getModel(0))->getAnimation() != RUN)
     468                    ((InteractiveModel*)this->getModel(0))->setAnimation(RUN);
     469            }
     470                 
     471       }
     472       else
     473       {
     474           if( this->bCrouch )
     475           {
     476               if( ((InteractiveModel*)this->getModel(0))->getAnimation() != CROUCH_STAND)
     477                   ((InteractiveModel*)this->getModel(0))->setAnimation(CROUCH_STAND);
     478           }
     479           else
     480           {
     481               if( ((InteractiveModel*)this->getModel(0))->getAnimation() != STAND)
     482                   ((InteractiveModel*)this->getModel(0))->setAnimation(STAND);
     483           }
     484       }
     485       
     486       if( this->bFire )
     487       {
     488           if( this->bCrouch )
     489           {
     490               if( ((InteractiveModel*)this->getModel(0))->getAnimation() != CROUCH_ATTACK)
     491                   ((InteractiveModel*)this->getModel(0))->setAnimation(CROUCH_ATTACK);
     492           }
     493           else
     494           {
     495               if( ((InteractiveModel*)this->getModel(0))->getAnimation() != ATTACK)
     496                   ((InteractiveModel*)this->getModel(0))->setAnimation(ATTACK);
     497           }
     498       }
    372499  }
    373500
     
    390517    this->fallVelocity = 0.0f;
    391518  }
    392   if((velocity *time).len() < 10.0f) this->shiftCoor( velocity*time );
    393   else{ 
     519  if((velocity * time).len() < 10.0f) this->shiftCoor( velocity*time );
     520  else
     521  {     
    394522         velocity.normalize();
    395523         velocity *= 10.0f;
    396524         this->shiftCoor( velocity );
    397        }
    398 
    399 
     525  }
    400526
    401527
     
    409535  if( this->aimingSystem != NULL)
    410536    this->aimingSystem->flushList();
     537   
    411538}
    412539
     
    426553
    427554/**
    428  * process
     555 * checks events
    429556 */
    430557void FPSPlayer::process(const Event &event)
     
    440567  else if( event.type == KeyMapper::PEV_BACKWARD)
    441568    this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0);
     569  else if( event.type == KeyMapper::PEV_JUMP)
     570    this->bJump = event.bPressed;
     571  else if( event.type == KeyMapper::PEV_FIRE1)
     572    this->bFire = event.bPressed;
     573  else if( event.type == KeyMapper::PEV_FIRE2)
     574    this->bFire2 = event.bPressed;
     575  else if( event.type == KeyMapper::PEV_CROUCH)
     576    this->bCrouch = event.bPressed;
    442577  else if( event.type == EV_MOUSE_MOTION)
    443578  {
     
    445580    this->yMouse += event.yRel;
    446581  }
    447   else if( event.type == KeyMapper::PEV_JUMP)
    448   {
    449     this->bJump = event.bPressed;
    450   }
    451   else if( event.type == KeyMapper::PEV_FIRE1)
    452   {
    453     this->bFire = event.bPressed;
    454   }
    455 }
    456 
    457 
     582}
     583
     584/**
     585 * respawns FPSplayer
     586 */
    458587void FPSPlayer::respawn( )
    459588{
     
    466595}
    467596
    468 
     597/**
     598 * Kills the FPSplayer defining its killer
     599 */
    469600void FPSPlayer::destroy( WorldEntity* killer )
    470601{
     
    474605}
    475606
     607void FPSPlayer::displayHUDText( const std::string& message )
     608{
     609        State::getPlayer()->hud().notifyUser(message);
     610}
Note: See TracChangeset for help on using the changeset viewer.