Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


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

Legend:

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

    r10158 r10177  
    1818#include <stdio.h>
    1919
     20AISwarm::AISwarm()
     21{
     22        tickCount=0;
     23        randomFreq=100;
     24}
     25
     26
    2027void AISwarm::process(float dt)
    2128{
     29        if(tickCount>=randomFreq && movement.len()<60){
     30                tickCount=0;
     31                int x = (rand()%141)+10;                                //10-150
     32                int z = (rand()%241)-120;                       //-120-120
     33                randomVector=Vector(x,0,z);
     34
     35                std::cout << "change to: ||" << randomVector.x << "   ==" << randomVector.z << "\n";
     36        }
     37        tickCount++;
     38
     39
    2240        std::set<AIModule*>::iterator it;
    2341        Vector swarmPosition=this->getPosition();
    2442        //std::cout << swarmPosition.x << " " << swarmPosition.z << "\n";
    25        
     43
    2644        float aMax=70.0f;
    2745        float vMax=1000.0f;
    28        
    29         Vector correction=(destination-swarmPosition)-movement;
     46
     47        Vector correction=(destination+randomVector-swarmPosition)-movement;
    3048        correction.y=0;
    31        
     49
    3250        float correctionLen=correction.len();
    3351        if(correctionLen>aMax*dt)correction=correction/correctionLen*aMax*dt;
    34        
     52
    3553        //std::cout << angleRad(correction,movement) << "\n";
    3654        movement+=correction;
    37        
     55
    3856        float movementLen=movement.len();
    3957        if(movementLen>vMax)movement=movement/movementLen*vMax;
    40        
    41        
     58
     59
    4260        for (it= swarmMembers.begin(); it!= swarmMembers.end(); it++ ){
    4361                (*it)->setDestination(swarmPosition);
     
    4866}
    4967
     68
    5069void AISwarm::addAI(AIModule* aiModule)
    5170{
    5271        swarmMembers.insert(aiModule);
    5372}
     73
    5474
    5575void AISwarm::removeAI(AIModule* aiModule)
     
    5979        delete (*it);
    6080}
     81
    6182
    6283Vector AISwarm::getPosition()
Note: See TracChangeset for help on using the changeset viewer.