Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10177 in orxonox.OLD for branches/ai/src/ai/movement_module.cc


Ignore:
Timestamp:
Jan 3, 2007, 6:39:09 PM (17 years ago)
Author:
tfahrni
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ai/src/ai/movement_module.cc

    r10158 r10177  
    2828SHELL_COMMAND(setDistanceToNPC, MovementModule, setDistanceToNPC);
    2929SHELL_COMMAND(setMaxAccleartion, MovementModule, setMaxAccleartion);
     30SHELL_COMMAND(setTestValue, MovementModule, setTestValue);
     31SHELL_COMMAND(setTestValue2, MovementModule, setTestValue2);
    3032
    3133float MovementModule::distanceToPlayer=15;
    3234float MovementModule::distanceToNPC=2;
    33 float MovementModule::maxAccleration=200.0f;
     35float MovementModule::maxAccleration=300.0f;
     36float MovementModule::testValue=2;
     37float MovementModule::testValue2=40;
    3438
    3539void MovementModule::setDistanceToPlayer(float newValue){ distanceToPlayer=newValue; }
    3640void MovementModule::setDistanceToNPC(float newValue){ distanceToNPC=newValue; }
    3741void MovementModule::setMaxAccleartion(float newValue){ maxAccleration=newValue; }
     42void MovementModule::setTestValue(float newValue){ testValue=newValue; }
     43void MovementModule::setTestValue2(float newValue){ testValue2=newValue; }
    3844
    39 
    40 
    41 
    42 
    43 
    44 // std::vector<Vector>  MovementModule::hidingPoint;
    45 // std::vector<float>   MovementModule::hidingPointSize;
    46 //
    47 // std::vector<NPC2*> MovementModule::npcList;
    48 // std::vector<Vector> MovementModule::npcPosition;
    49 // std::vector<float> MovementModule::npcRadius;
    50 // std::vector<int> MovementModule::npcSwarm;
    51 // std::vector<int> MovementModule::npcTeam;
    52 //
    53 // Vector MovementModule::playerPosition;
    54 // Vector MovementModule::playerMovement;
    55 // float MovementModule::playerRadius;
    56 //
    57 // std::vector<Vector> MovementModule::swarmCenter;
    58 // std::vector<int> MovementModule::swarmMemberCount;
    59 //
    60 //
    61 //
    62 //
    63 //
     45MovementModule::MovementModule()
     46{
     47        tickCount=0;
     48        randomFreq=100;
     49}
    6450
    6551
     
    8268
    8369
    84 
    85 
    86 // void MovementModule::collectInformation(float dt)
    87 // {
    88 //      //return if already processed..
    89 //      if(dt==this->oldDT)return;
    90 //      this->oldDT=dt;
    91 //
    92 //
    93 //      //clear old Information..
    94 //      hidingPoint.clear();
    95 //      hidingPointSize.clear();
    96 //
    97 //      npcList.clear();
    98 //      npcPosition.clear();
    99 //      npcRadius.clear();
    100 //      npcSwarm.clear();
    101 //      npcTeam.clear();
    102 //
    103 //      swarmCenter.clear();
    104 //      swarmMemberCount.clear();
    105 //
    106 //
    107 //      //get all NPCs..
    108 //      for(ObjectList<NPC2>::const_iterator it = NPC2::objectList().begin(); it != NPC2::objectList().end(); ++it)
    109 //      {
    110 //              npcList.push_back(*it);
    111 //              npcRadius.push_back(getRadius(*it));
    112 //              npcPosition.push_back((*it)->getAbsCoor());
    113 //              npcSwarm.push_back((*it)->swarm);
    114 //              npcTeam.push_back((*it)->team);
    115 //      }
    116 //
    117 //
    118 //      //Swarm Information
    119 //      unsigned int tmpSwarm;
    120 //      for(unsigned int i=0;i<npcList.size();i++){
    121 //              tmpSwarm = npcSwarm.at(i);
    122 //              if(tmpSwarm > swarmMemberCount.size()){
    123 //                      //swarmMemberCount.insert(swarmMemberCount.size(), tmpSwarm - swarmMemberCount.size(), 0);
    124 //                      //swarmCenter.insert(swarmCenter.size(), tmpSwarm - swarmCenter.size(), Vector(0,0,0));
    125 //              }
    126 //              //swarmMemberCount.at(tmpSwarm)++;
    127 //              //swarmCenter.at(tmpSwarm)=swarmCenter.at(tmpSwarm)+npcPosition.at(i);
    128 //      }
    129 //      for(unsigned int i=0;i<swarmCenter.size();i++){
    130 //              //swarmCenter.at(i)=swarmCenter.at(i)/swarmMemberCount.at(i);
    131 //      }
    132 //
    133 //
    134 //      //get information about Player
    135 //      Player* pl = State::getPlayer();
    136 //      if( pl != NULL){
    137 //              playerPosition = pl->getPlayable()->getAbsCoor();
    138 //              playerRadius=getRadius( pl->getPlayable() );
    139 //              //PRINTF(0)("Player Radius: %f\n",playerRadius);
    140 //      }
    141 //
    142 //
    143 //      //calculate hiding Points..
    144 //
    145 // }
    146 
    147 
    14870void MovementModule::process(float dt)
    14971{
    15072        if(myNPC == NULL)return;
    15173
    152         //get information about Player
     74        Vector tmpVector;
     75        float tmpFloat;
     76        Vector npcCollision;
     77        Vector playerCollision;
     78        bool autoRotate=true;
     79        target=enemyList->at(0);
     80
     81        weight=1;
     82        speedMax=1000.0f;
     83
     84
     85        //get information about player
    15386        Player* pl = State::getPlayer();
    15487        if( pl == NULL)return;
    15588        Vector playerPosition = pl->getPlayable()->getAbsCoor();
    15689        float playerRadius=getRadius( pl->getPlayable() );
    157        
     90
    15891
    15992        //get information about myself
     
    16295
    16396
     97        //anti player collision
    16498        Vector vectorToPlayer = playerPosition - myPosition;
    16599
    166         Vector tmpVector;
    167         float tmpFloat;
    168        
    169         Vector npcCollision;
    170         Vector playerCollision;
    171 
    172 
    173 
    174         //float a=200.0f;
    175         float vMax=200.0f;
    176         //float maxAccleration=300.0f;
    177         //float safetyDistance=2.0f;
    178 
    179 
    180         //Anti Player Collision
    181100        tmpFloat=vectorToPlayer.len()-playerRadius-myRadius-distanceToPlayer;
    182101        if(tmpFloat<0.1)tmpFloat=0.1;
     
    184103
    185104
    186         //Anti NPC Collision
     105        //anti NPC collision
    187106        for(ObjectList<WorldEntity>::const_iterator it = WorldEntity::objectList().begin(); it != WorldEntity::objectList().end(); ++it)
    188107        {
     
    199118
    200119
     120        //random movement
     121        //randomFreq=testValue2;
     122        if(++tickCount>=randomFreq && movement.len()<60){
     123                tickCount=0;
     124                int x = (rand()%101)-50;                        //-50-50
     125                int z = (rand()%101)-50;                        //-50-50
     126                randomVector=Vector(x,0,z);
     127                randomFreq=(rand()%81)+70;                      //70-150 Ticks
     128        }
    201129
     130
     131        //calculate correction vector
    202132        Vector vectorToDestination=destination-myPosition;
    203133
     
    205135                                                                +       npcCollision*50*3
    206136                                                                +       Vector(0,0,0)
    207                                                                 +       destinationMovement*2//-myMovement
    208                                                                 +       (vectorToDestination-myMovement)*3;
     137                                                                +       destinationMovement*2//-movement
     138                                                                +       (vectorToDestination-movement)*3;
     139
     140        if(movement.len()<testValue2){
     141        //if(testValue2){
     142                correction=correction + randomVector * testValue;
     143                autoRotate=false;
     144        }
    209145
    210146        correction.y=0;
     147
     148
     149        //limit accleration
    211150        float correctionLen=correction.len();
    212151        if(correctionLen>maxAccleration*dt)correction=correction/correctionLen*maxAccleration*dt;
    213         myMovement+=correction;
     152        movement+=correction;
    214153
    215         float movementLen=myMovement.len();
    216         if(movementLen>vMax)myMovement/movementLen*vMax;
    217154
    218         //Move NPC...
    219         myNPC->shiftCoor(myMovement * dt);
     155        //limit speed
     156        float movementLen=movement.len();
     157        if(movementLen>speedMax)movement=movement/movementLen*speedMax;
    220158
    221         //Rotate NPC
    222         Vector view = myMovement;
    223         //if(vectorToPlayer.dot(v)<0){
    224         //      view = v.cross( Vector(0,1,0) ).getNormalized();
    225         //}else{
    226         view = myMovement.cross( Vector(0,1,0) ).getNormalized();
    227         //}
    228         //if(dist<keepDist)view=view*-1;
    229         //myNPC->setAbsDir( Quaternion( view, Vector(0,1,0)));
     159
     160        //move NPC...
     161        myNPC->shiftCoor(movement * dt);
     162
     163
     164        //rotate NPC
     165        Vector view;
     166        if(autoRotate){
     167                view = movement.cross( Vector(0,1,0) ).getNormalized();
     168        }else{
     169                view = target->getAbsCoor()-myPosition;
     170                view = view.cross( Vector(0,1,0) ).getNormalized();
     171        }
    230172        myNPC->setAbsDirSoft( Quaternion( view, Vector(0,1,0)),3);
    231         movement=myMovement;
     173
    232174}
    233175
Note: See TracChangeset for help on using the changeset viewer.