Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10667 in orxonox.OLD for branches/vs-enhencements/src


Ignore:
Timestamp:
Jun 1, 2007, 12:01:20 PM (18 years ago)
Author:
rennerc
Message:

ActionboxEnemy

Location:
branches/vs-enhencements/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/vs-enhencements/src/defs/include_paths.am

    r10376 r10667  
    3131
    3232AM_CXXFLAGS+=-I$(MAINSRCDIR)/../extern_libs
     33
     34AM_LDFLAGS+=-L$(MAINSRCDIR)/../extern_libs
  • branches/vs-enhencements/src/util/track/action_box.cc

    r10645 r10667  
    127127bool ActionBox::isPointInBox( const Vector & pos )
    128128{
    129   bool result = true; //TODO remove
    130129  for ( int i = 0; i<6; i++ )
    131130  {
    132131    if ( planes[i].distancePoint( pos ) < 0 )
    133132    {
    134       result = false; // TODO return false;
    135       printf("PLANE %i FAILED %f\n", i, planes[i].distancePoint( pos ) );
     133      return false;
    136134    }
    137135  }
    138   return result;  //TODO return true;
     136  return true;
    139137}
    140138
  • branches/vs-enhencements/src/world_entities/npcs/actionbox_enemy.cc

    r10662 r10667  
    4141  this->dPitch = 0.0;
    4242 
    43   this->maxSpeed = 10;
     43  this->maxSpeed = 30;
    4444  this->acceleration = 3;
    4545  this->speed = 0;
    4646 
     47  this->onEscape = false;
     48 
    4749  if ( root )
    4850    this->loadParams( root );
     
    6062void ActionboxEnemy::tick( float dt )
    6163{
     64  this->bFire = false;
     65 
     66  if ( !State::getPlayer() || !State::getPlayer()->getPlayable() )
     67    return;
     68 
     69  Vector playerDir = State::getPlayer()->getPlayable()->getAbsDir().apply( Vector(1, 0, 0) );
     70  Vector dist = this->getAbsCoor() - State::getPlayer()->getPlayable()->getAbsCoor();
     71 
     72  bool behindPlayer = playerDir.dot( dist ) < 0;
     73 
     74  if ( behindPlayer )
     75    return;
     76 
    6277  myDir = this->getAbsDir();
    6378  myCoor = this->getAbsCoor();
     
    7388  qPitch = Quaternion( pitch, Vector( 1, 0, 0 ) );
    7489 
    75   moveTowardsBox( NULL, dt );
    76    
    7790  if ( isActive && State::getActionBox() )
    7891  {
     
    8598    {
    8699      moveTowardsBox( box, dt );
     100      onEscape = false;
    87101    }
    88102  }
     
    96110void ActionboxEnemy::attackPlayer( ActionBox * box, float dt )
    97111{
    98 }
    99 
    100 void ActionboxEnemy::moveTowardsBox( ActionBox * box, float dt )
    101 {
    102   //Vector targetPos = State::getPlayer()->getPlayable()->getAbsCoor();
    103   static float time = 0;
    104   time += dt;
    105   Vector targetPos = State::getPlayer()->getPlayable()->getAbsCoor() + State::getPlayer()->getPlayable()->getAbsDir().apply(Vector(1, 0, 0))*50*(1.5 + sin(time/5));
    106   Vector targetDir = targetPos - myCoor;
    107  
     112  if ( !State::getPlayer() || !State::getPlayer()->getPlayable() || !box )
     113    return;
     114 
     115  float distance = (State::getPlayer()->getPlayable()->getAbsCoor() - getAbsCoor() ).len();
     116 
     117  if ( distance > box->getDepth()/4.0 && !onEscape )
     118  {
     119    Vector targetPos = State::getPlayer()->getPlayable()->getAbsCoor();
     120    Vector targetDir = State::getPlayer()->getPlayable()->getAbsCoor()-this->getAbsCoor();
     121    moveTowards( targetPos, targetDir, dt );
     122    if ( this->getAbsDir().apply( Vector(1, 0, 0) ).dot(targetDir) > 0.9 )
     123    {
     124      this->bFire = true;
     125      PRINTF(0)("FIRE\n");
     126    }
     127  }
     128  else
     129  {
     130    if ( !onEscape )
     131    {
     132      Vector ds = this->getAbsCoor() - State::getPlayer()->getPlayable()->getAbsCoor();
     133      float projy = box->getAbsDir().apply( Vector(0, 1, 0) ).dot( ds );
     134      float projz = box->getAbsDir().apply( Vector(0, 0, 1) ).dot( ds );
     135      this->escapePoint = Vector( 0, projy, projz );
     136      this->escapePoint.normalize();
     137      this->escapePoint*= 2*box->getWidth_2();
     138      PRINTF(0)("ESCAPE\n");
     139    }
     140    onEscape = true;
     141   
     142    Vector rEscapePoint = box->getAbsDir().apply(escapePoint);
     143    Vector targetPos = State::getPlayer()->getPlayable()->getAbsCoor() + rEscapePoint;
     144    Vector targetDir = State::getPlayer()->getPlayable()->getAbsCoor() + rEscapePoint - this->getAbsCoor();
     145    moveTowards( targetPos, targetDir, dt );   
     146  }
     147}
     148
     149void ActionboxEnemy::moveTowards( Vector targetPos, Vector targetDir, float dt )
     150{
    108151  Quaternion cur = myDir;
    109152  Quaternion rx( dt, Vector( 0, 0, 1 ) );
     
    144187}
    145188
     189void ActionboxEnemy::moveTowardsBox( ActionBox * box, float dt )
     190{
     191   
     192  Vector targetPos = box->getAbsCoor() + box->getAbsDir().apply( Vector( 1, 0, 0 ) )*box->getDepth()*0.66f;
     193  Vector targetDir = targetPos - myCoor;
     194 
     195  moveTowards(targetPos, targetDir, dt);
     196}
     197
    146198void ActionboxEnemy::draw( ) const
    147199{
  • branches/vs-enhencements/src/world_entities/npcs/actionbox_enemy.h

    r10662 r10667  
    3333    Vector     myCoor;
    3434   
     35    bool       bFire;
     36   
     37    Vector     escapePoint;
     38    bool       onEscape;
     39   
    3540    void attackPlayer( ActionBox* box, float dt );
    3641    void moveTowardsBox( ActionBox* box, float dt );
     42    void moveTowards( Vector targetPos, Vector targetDir, float dt );
    3743};
    3844
  • branches/vs-enhencements/src/world_entities/space_ships/space_ship.cc

    r10662 r10667  
    571571  if (!(State::getCamera()->getEventHandling()))
    572572  {
     573    //PRINTF(0)("\n\n\n\n\n\n\n\nSETCAMERA %x\n\n\n\n\n\n\n", State::getCamera());
    573574    if( event.type == KeyMapper::PEV_VIEW0)
    574575    {
     
    851852        //State::getCameraTargetNode()->setParentSoft(this);
    852853        //State::getCameraTargetNode()->setRelCoorSoft(0,0,0);
    853         this->setCameraMode(Camera::ViewNormal);
     854        //this->setCameraMode(Camera::ViewNormal);
    854855        State::getCamera()->setEventHandling(false);
     856       
     857        PRINTF(0)("\n\n\n\n\n\n\n\nSETCAMERA %x\n\n\n\n\n\n\n", State::getCamera());
     858        State::getCamera()->setViewMode(Camera::ViewNormal);
     859        State::getCameraTargetNode()->setParent(this);
     860        State::getCamera()->setParent(this);
     861
     862       
     863       
    855864        registerEvent(KeyMapper::PEV_VIEW0);
    856865        registerEvent(KeyMapper::PEV_VIEW1);
Note: See TracChangeset for help on using the changeset viewer.