Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10266 in orxonox.OLD


Ignore:
Timestamp:
Jan 17, 2007, 4:53:23 PM (17 years ago)
Author:
tfahrni
Message:

fixed segfault

Location:
branches/ai/src/ai
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/ai/src/ai/Makefile.am

    r10244 r10266  
    1414                        swarm_module.cc\
    1515                        swarm_wait.cc\
    16                         swarm_gorel.cc
     16                        swarm_gorel.cc\
     17                        swarm_attack.cc
    1718
    1819noinst_HEADERS =        \
     
    2627                        swarm_module.h\
    2728                        swarm_wait.h\
    28                         swarm_gorel.h
     29                        swarm_gorel.h\
     30                        swarm_attack.h
  • branches/ai/src/ai/ai_engine.cc

    r10244 r10266  
    3333                if(it->first!=0){
    3434                        Player* pl = State::getPlayer();
    35                         if(pl != NULL)enemyList->push_back(pl->getPlayable());
     35                        if( pl!=NULL && pl->getPlayable()!=NULL )
     36                                enemyList->push_back(pl->getPlayable());
    3637                }
    37        
     38
    3839                //find other enemys for this team
    3940                for(ObjectList<NPC2>::const_iterator npc = NPC2::objectList().begin(); npc != NPC2::objectList().end(); ++npc)
     
    6061void AIEngine::removeAI(int teamNumber, int swarmNumber, WorldEntity* npc)
    6162{
    62         std::map<int,AITeam*>::iterator it = teams.find(swarmNumber);
     63        std::map<int,AITeam*>::iterator it = teams.find(teamNumber);
    6364        if(it==teams.end())return;
    6465        it->second->removeAI(swarmNumber,npc);
  • branches/ai/src/ai/ai_team.cc

    r10249 r10266  
    1818#include "swarm_module.h"
    1919#include "swarm_wait.h"
     20#include "swarm_attack.h"
    2021#include "debug.h"
    2122#include "player.h"
     
    2728        std::map<int,SwarmModule*>::iterator it;
    2829        for (it= swarms.begin(); it!= swarms.end(); it++ ){
    29        
     30
    3031                if(it->second->taskDone()){
    3132                        std::cout << "Swarm Task Complete!\n";
    32                                        
     33
    3334                        if(enemyList->size()==0){
    3435                                changeSwarmModule(it, new SwarmWait);
     
    3738                                continue;
    3839                        }
    39                        
     40
    4041                        Vector position=it->second->getPosition();
    4142                        Vector newPosition;
    4243                        WorldEntity* target=enemyList->at(0);
    43                        
     44
    4445                        //check if enemy is the player..
    4546                        bool isPlayer=(State::getPlayer()->getPlayable()==target);
    4647                        float speed;
    47                        
     48                        float maxTime=10;
     49
    4850                        //find new Position
    4951                        if(isPlayer){
    50                                 float x=(target->getAbsCoor()).x;
    51                                 float z=(target->getAbsCoor()).z;
    52                                 int zNorm=(position.z>z)?1:-1;
    53                                
    54                                 if(x+100 > position.x && x+20 < position.x){
    55                                         newPosition=Vector(0,0,zNorm*80);               //just go away
     52                                Vector targetPos=target->getAbsCoor();
     53                                int zNorm=(position.z>targetPos.z)?1:-1;
     54
     55                                if((position.z-targetPos.z)*zNorm>80){  //go to start position
     56                                        std::cout << "Go Start Position\n";
     57                                        changeSwarmModule(it, new SwarmGoRel);
     58                                        newPosition=Vector(220,0,zNorm*60);
     59                                        speed=100;
     60                                }else if(position.x > targetPos.x+150){ //go to attack position
     61                                        std::cout << "Go Attack Position\n";
     62                                        changeSwarmModule(it, new SwarmGoRel);
     63                                        newPosition=Vector(100,0,0);
     64                                        speed=60;
     65                                }else if(position.x > targetPos.x+90){  //go to attack mode
     66                                        std::cout << "Go Attack Mode\n";
     67                                        changeSwarmModule(it, new SwarmAttack);
     68                                        newPosition=Vector(80,0,0);
    5669                                        speed=80;
    57                                 }else if(x+100 < position.x){
    58                                         newPosition=Vector(80,0,zNorm*30);      //attack
    59                                         speed=70;
    60                                 }else{
    61                                         zNorm=1-2*(rand()%2); //-1 or 1
    62                                         newPosition=Vector(200,0,zNorm*80);     //go to attack position
    63                                         speed=100;
     70                                        maxTime=(rand()%11);//0-10 Sekunden
     71                                }else{                                                                                          //go to fallback point
     72                                        std::cout << "Go  Fallback Point\n";
     73                                        changeSwarmModule(it, new SwarmGoRel);
     74                                        newPosition=Vector(0,0,zNorm*150);
     75                                        speed=60;
    6476                                }
    6577                        }else{
    66                        
     78
    6779                        }
    6880
    69                         changeSwarmModule(it, new SwarmGoRel);
    70                
     81
     82
    7183                        if(enemyList->size()>0){
    7284                                it->second->setEnemyList(enemyList);
     
    7587                                it->second->orderSpeed(speed);
    7688                                //it->second->orderView(Vector(0,0,1));
    77                                 it->second->orderMaxTime((rand()%6)+5); //5-10
     89                                it->second->orderMaxTime(maxTime); //5-10
    7890                                //it->second->newOrder();
    7991                        }
  • branches/ai/src/ai/attack_module.cc

    r10244 r10266  
    114114
    115115        Vector correction=              playerCollision*50*3
    116                                                                 +       npcCollision*50*3
     116                                                                +       npcCollision*50*3 *6/myRadius
    117117                                                                +       destinationMovement*2//-movement
    118118                                                                +       (vectorToDestination-movement)*3
  • branches/ai/src/ai/movement_module.cc

    r10244 r10266  
    6464        Player* pl = State::getPlayer();
    6565        if( pl == NULL)return;
     66        WorldEntity* playable = pl->getPlayable();
     67        if( playable == NULL)return;
     68
    6669        Vector playerPosition = pl->getPlayable()->getAbsCoor();
    6770        float playerRadius=getRadius( pl->getPlayable() );
    68 
    6971
    7072        //get information about myself
     
    104106
    105107        Vector correction=              playerCollision*50*3
    106                                                                 +       npcCollision*50*3
     108                                                                +       npcCollision*50*3 *6/myRadius
    107109                                                                +       Vector(0,0,0)
    108110                                                                +       destinationMovement*2//-movement
  • branches/ai/src/ai/swarm_gorel.cc

    r10249 r10266  
    2121{
    2222        std::map<WorldEntity*,AIModule*>::iterator it;
    23        
     23
    2424        //calculate  movement parameters..
    2525        float averageRadius;
     
    3131        vMax=500/averageRadius;
    3232        viewChangeMax=90/averageRadius;
    33        
     33
    3434        //load correct ai-module..
    3535        for (it= members.begin(); it!= members.end(); it++ ){
    3636                changeAIModule(it, new MovementModule());
    3737        }
    38        
     38
    3939        //get swarm position..
    4040        //position=this->getPosition();
     
    4848        Vector correction=Vector(0,0,0);
    4949        Vector destination;
    50        
     50
    5151        if(taskRelObject!=NULL && taskMaxTime>0){
    5252                destination=taskRelObject->getAbsCoor()+taskRelPos;
     
    5757                taskComplete=true;
    5858        }
    59        
     59
    6060        float correctionLen=correction.len();
    6161        if(correctionLen>aMax*dt)correction=correction/correctionLen*aMax*dt;
     
    6666        float movementLen=movement.len();
    6767        if(movementLen>vMax)movement=movement/movementLen*vMax;
    68        
     68
    6969        float newSpeed=movement.len();
    7070        Vector newView=movement.getNormalized();
    71        
     71
    7272        if((newSpeed<=taskSpeed && speed>=taskSpeed)||(newSpeed>=taskSpeed && speed<=taskSpeed)){
    7373                newSpeed=taskSpeed;
     
    7575                newSpeed=taskSpeed;
    7676        }
    77        
     77
    7878        if(angleDeg(view,newView)>viewChangeMax){
    7979                std::cout << "alarm\n";
     
    8989                it->second->process(dt);
    9090        }
    91        
     91
    9292        //check if destination reached
    9393        if(!taskComplete){
    9494                //swarmPosition=this->getPosition();
    95                 if((destination-position).len()<10)taskComplete=true;
     95                if((destination-position).len()<5)taskComplete=true;
    9696        }
    9797}
Note: See TracChangeset for help on using the changeset viewer.