Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10249 in orxonox.OLD


Ignore:
Timestamp:
Jan 17, 2007, 12:23:35 PM (17 years ago)
Author:
tfahrni
Message:
 
Location:
branches/ai/src/ai
Files:
6 edited

Legend:

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

    r10244 r10249  
    1717#include "swarm_gorel.h"
    1818#include "swarm_module.h"
     19#include "swarm_wait.h"
    1920#include "debug.h"
     21#include "player.h"
     22#include "playable.h"
     23#include "state.h"
    2024
    2125void AITeam::process(float dt)
     
    2529       
    2630                if(it->second->taskDone()){
    27                         std::cout << "Task Done!\n";
     31                        std::cout << "Swarm Task Complete!\n";
     32                                       
     33                        if(enemyList->size()==0){
     34                                changeSwarmModule(it, new SwarmWait);
     35                                it->second->orderMaxTime(2);    //sleep 2 seconds..
     36                                it->second->process(dt);
     37                                continue;
     38                        }
     39                       
     40                        Vector position=it->second->getPosition();
     41                        Vector newPosition;
     42                        WorldEntity* target=enemyList->at(0);
     43                       
     44                        //check if enemy is the player..
     45                        bool isPlayer=(State::getPlayer()->getPlayable()==target);
     46                        float speed;
     47                       
     48                        //find new Position
     49                        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
     56                                        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;
     64                                }
     65                        }else{
     66                       
     67                        }
     68
    2869                        changeSwarmModule(it, new SwarmGoRel);
    2970               
    3071                        if(enemyList->size()>0){
    3172                                it->second->setEnemyList(enemyList);
    32                                 it->second->orderRelObject(enemyList->at(0));
    33                                 it->second->orderRelPos(Vector(60,0,0));
    34                                 it->second->orderSpeed(50);
    35                                 it->second->orderView(Vector(0,0,1));
    36                                 it->second->orderMaxTime(5);
     73                                it->second->orderRelObject(target);
     74                                it->second->orderRelPos(newPosition);
     75                                it->second->orderSpeed(speed);
     76                                //it->second->orderView(Vector(0,0,1));
     77                                it->second->orderMaxTime((rand()%6)+5); //5-10
     78                                //it->second->newOrder();
    3779                        }
    3880                }
  • branches/ai/src/ai/swarm_gorel.cc

    r10244 r10249  
    2828        }
    2929        averageRadius=averageRadius/members.size();
    30         aMax=1000/averageRadius;
    31         vMax=1000/averageRadius;
     30        aMax=500/averageRadius;
     31        vMax=500/averageRadius;
     32        viewChangeMax=90/averageRadius;
    3233       
    3334        //load correct ai-module..
     
    3637        }
    3738       
     39        //get swarm position..
     40        //position=this->getPosition();
    3841}
    3942
     
    4245        std::map<WorldEntity*,AIModule*>::iterator it;
    4346
    44         Vector swarmPosition=this->getPosition();
     47        //Vector swarmPosition=this->getPosition();
    4548        Vector correction=Vector(0,0,0);
    4649        Vector destination;
     
    4851        if(taskRelObject!=NULL && taskMaxTime>0){
    4952                destination=taskRelObject->getAbsCoor()+taskRelPos;
    50                 correction=(destination-swarmPosition)-view*speed;
     53                correction=(destination-position)-view*speed;
    5154                correction.y=0;
    5255                taskMaxTime-=dt;
     
    6467        if(movementLen>vMax)movement=movement/movementLen*vMax;
    6568       
    66         speed=movement.len();
    67         view=movement.getNormalized();
     69        float newSpeed=movement.len();
     70        Vector newView=movement.getNormalized();
     71       
     72        if((newSpeed<=taskSpeed && speed>=taskSpeed)||(newSpeed>=taskSpeed && speed<=taskSpeed)){
     73                newSpeed=taskSpeed;
     74        }else if((newSpeed>speed && speed<taskSpeed) || (newSpeed < speed && speed < taskSpeed)){
     75                newSpeed=taskSpeed;
     76        }
     77       
     78        if(angleDeg(view,newView)>viewChangeMax){
     79                std::cout << "alarm\n";
     80        }
     81        speed=newSpeed;
     82        view=newView;
     83        position=position+view*speed*dt;
    6884
    6985        //tell orders to swarm-members...
    7086        for (it= members.begin(); it!= members.end(); it++ ){
    71                 it->second->setDestination(swarmPosition);
    72                 it->second->setDestinationMovement(movement);
     87                it->second->setDestination(position);
     88                it->second->setDestinationMovement(view*speed);
    7389                it->second->process(dt);
    7490        }
     
    7692        //check if destination reached
    7793        if(!taskComplete){
    78                 swarmPosition=this->getPosition();
    79                 if((destination-swarmPosition).len()<10)taskComplete=true;
     94                //swarmPosition=this->getPosition();
     95                if((destination-position).len()<10)taskComplete=true;
    8096        }
    8197}
  • branches/ai/src/ai/swarm_gorel.h

    r10244 r10249  
    1717                float vMax;
    1818                float aMax;
     19                float viewChangeMax;
    1920};
    2021
  • branches/ai/src/ai/swarm_module.cc

    r10244 r10249  
    4444}
    4545
    46 Vector SwarmModule::getPosition()
     46Vector SwarmModule::getSwarmPosition()
    4747{
    4848        Vector center=Vector(0,0,0);
     
    7676        this->view=other->getView();
    7777        this->enemys=other->getEnemyList();
     78        this->position=other->getPosition();
    7879       
    7980        this->initialize();
  • branches/ai/src/ai/swarm_module.h

    r10244 r10249  
    1919        inline void setEnemyList(std::vector<WorldEntity*>* enemys){this->enemys=enemys;}       
    2020       
     21        inline void newOrder(){this->taskComplete=false;}
    2122        inline void orderRelPos(Vector taskRelPos){this->taskRelPos=taskRelPos;}
    2223        inline void orderAbsPos(Vector taskAbsPos){this->taskAbsPos=taskAbsPos;}
     
    2627        inline void orderMaxTime(float taskMaxTime){this->taskMaxTime=taskMaxTime;}
    2728
    28         Vector getPosition();
     29        Vector getSwarmPosition();
     30        inline Vector getPosition(){return position;}
    2931        inline float getSpeed(){return speed;}
    3032        inline Vector getView(){return view;}
     
    4547       
    4648        Vector view;
     49        Vector position;
    4750        float speed;
    4851       
  • branches/ai/src/ai/swarm_wait.h

    r10244 r10249  
    88class SwarmWait : public SwarmModule{
    99        public:
    10                 SwarmWait();
     10                SwarmWait(){}
    1111                virtual ~SwarmWait(){}
    1212                virtual void process(float dt);
Note: See TracChangeset for help on using the changeset viewer.