Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10135 in orxonox.OLD for branches


Ignore:
Timestamp:
Dec 20, 2006, 7:47:45 PM (18 years ago)
Author:
tfahrni
Message:
 
Location:
branches/ai/src
Files:
2 added
12 edited

Legend:

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

    r10045 r10135  
    88                        ai_module.cc \
    99                        ai_team.cc \
     10                        ai_swarm.cc \
    1011                        ai_team_member.cc \
    1112                        movement_module.cc \
     
    1617                        ai_module.h \
    1718                        ai_team.h \
     19                        ai_swarm.h \
    1820                        ai_team_member.h \
    1921                        movement_module.h \
  • branches/ai/src/ai/ai_engine.cc

    r10045 r10135  
    2222AIEngine* AIEngine::singletonRef = NULL;
    2323
     24AIEngine::AIEngine(){
     25        for(int i=0; i < maxTeams; i++ )teams[i]=NULL;
     26}
    2427
    25 AIEngine::AIEngine()
    26 {}
     28AITeam* AIEngine::getTeam(int teamNumber)
     29{
     30        if(teamNumber>maxTeams || teamNumber<0)return NULL;
     31        return teams[teamNumber];
     32}
    2733
    28 AIEngine::~AIEngine()
    29 {}
    30 
    31 
    32 
    33 /*AITeam* AIEngine::newTeam()
     34AITeam* AIEngine::getCreateTeam(int teamNumber)
    3435{
    35         AITeam* newTeam=new AITeam;
    36         teams.push_back(newTeam);
    37         return newTeam;
    38 }*/
    39 int AIEngine::newTeam()
    40 {
    41         AITeam* newTeam=new AITeam;
    42         teams.push_back(newTeam);
    43         return teams.size()-1;
     36        if(teamNumber>maxTeams || teamNumber<0)return NULL;
     37        if(teams[teamNumber]==NULL)teams[teamNumber]=new AITeam();
     38        return teams[teamNumber];
    4439}
    4540
    4641
    47 
    48 AITeam* AIEngine::getTeam(int aiTeamNumber)
     42void AIEngine::addTeam(int teamNumber)
    4943{
    50         //if(teams.size()>aiTeamNumber)
    51         return teams.at(aiTeamNumber);
    52         //return NULL;
     44        if(teamNumber>maxTeams || teamNumber<0)return;
     45        teams[teamNumber]=new AITeam();
    5346}
    5447
    5548
     49void AIEngine::removeTeam(int teamNumber)
     50{
     51        if(teamNumber>maxTeams || teamNumber<0)return;
     52        teams[teamNumber]=NULL;
     53}
    5654
    57 void AIEngine::tick(float dtS)
     55
     56void AIEngine::tick(float dt)
    5857{
    59         this->dtS=dtS;
    60         int teamCount=teams.size();
    61         for(int i=0; i < teamCount; i++ )
    62         {
    63                 //std::cout << "hello";
    64         //std::cout << "DT " << dtS <<  "...\n";
    65         teams.at(i)->process();
    66         }
     58        for(int i=0; i < maxTeams; i++ )
     59                if(teams[i]!=NULL)teams[i]->process(dt);
    6760}
     61
     62
     63void AIEngine::rebuildAIVector(){
     64        //AIVector.clear();
     65
     66        //for(int i=0; i < maxTeams; i++ )
     67                //if(teams[i]!=NULL)AIVector.push_back(teams[i]);
     68}
  • branches/ai/src/ai/ai_engine.h

    r10045 r10135  
    99class AIEngine{
    1010 public:
    11    ~AIEngine();
     11        ~AIEngine(){}
    1212
    1313   static AIEngine* getInstance() { if( singletonRef == NULL) singletonRef = new AIEngine(); return singletonRef; }
    1414
    15    void tick(float dtS);
    16    AITeam* getTeam(int);
    17         int newTeam();
    18         float dtS;
     15   void tick(float dt);
     16
     17        void addTeam(int teamNumber);
     18        void removeTeam(int teamNumber);
     19        AITeam* getTeam(int teamNumber);
     20        AITeam* getCreateTeam(int teamNumber);
     21
    1922 private:
     23        void rebuildAIVector();
     24
     25        std::vector<AIModule*> AIVector;
     26
     27        static const int maxTeams=32;
     28        AITeam* teams[32];
    2029        AIEngine();
    2130
    22  private:
    23    std::vector<AITeam*> teams;
    24 
    25    static AIEngine* singletonRef;
    26 
     31        static AIEngine* singletonRef;
    2732};
    2833
  • branches/ai/src/ai/ai_module.h

    r10112 r10135  
    99
    1010
    11 class AIModule{
     11class AIModule {
    1212 public:
    1313   AIModule();
    1414   virtual ~AIModule() {}
     15
    1516   virtual void process() {}
    1617   virtual void process(float dt) {}
     18
    1719   void setDifficulty(int newDifficulty);
    1820   void setOwner(AITeamMember* newOwner);
     21
     22
    1923 protected:
    2024   int difficulty;
     25        int myTeam;
     26        int mySwarm;
     27
    2128   AITeamMember* owner;
    2229   NPC2* myNPC;
     30        WorldEntity* myWorldEnity;
    2331};
    2432
  • branches/ai/src/ai/ai_team.cc

    r10045 r10135  
    1919#include "ai_team.h"
    2020
    21 AITeam::AITeam()
    22 {}
     21AITeam::AITeam(){
     22        for(int i=0; i < maxSwarms; i++ )swarms[i]=NULL;
     23}
    2324
    24 AITeam::~AITeam()
    25 {}
    2625
    27 void AITeam::process()
     26AISwarm* AITeam::getSwarm(int swarmNumber)
    2827{
    29         int teamSize=teamMembers.size();
    30         for(int i=0; i < teamSize; i++ )
    31         {
    32         //std::cout << "Processing TeamMember " << i <<  "...\n";
    33         teamMembers.at(i)->process();
     28        if(swarmNumber>maxSwarms || swarmNumber<0)return NULL;
     29        return swarms[swarmNumber];
     30}
     31
     32
     33AISwarm* AITeam::getCreateSwarm(int swarmNumber)
     34{
     35        if(swarmNumber>maxSwarms || swarmNumber<0)return NULL;
     36        if(swarms[swarmNumber]==NULL)swarms[swarmNumber]=new AISwarm();
     37        return swarms[swarmNumber];
     38}
     39
     40
     41void AITeam::addSwarm(int swarmNumber)
     42{
     43        if(swarmNumber>maxSwarms || swarmNumber<0)return;
     44        swarms[swarmNumber]=new AISwarm();
     45}
     46
     47
     48void AITeam::removeSwarm(int swarmNumber)
     49{
     50        if(swarmNumber>maxSwarms || swarmNumber<0)return;
     51        swarms[swarmNumber]=NULL;
     52}
     53
     54
     55void AITeam::process(float dt)
     56{
     57        for(int i=0; i < maxSwarms; i++ ){
     58                if(swarms[i]!=NULL)swarms[i]->process(dt);
    3459        }
    3560}
    3661
    3762
    38 void AITeam::addMember(AITeamMember* newMember)
    39 {
    40         teamMembers.push_back(newMember);
    41 }
    42 
    43 
    44 AITeamMember* AITeam::getTeamMember(int teamMemberID)
    45 {
    46         return teamMembers.at(teamMemberID);
    47 }
  • branches/ai/src/ai/ai_team.h

    r10041 r10135  
    33#define _AI_TEAM_H
    44
    5 //class AITeamMember;
    6 #include "ai_team_member.h"
     5#include "ai_swarm.h"
    76
    87class AITeam{
    98 public:
    10    AITeam();
    11    ~AITeam();
    12    void process();
    13    void addMember(AITeamMember*);
    14    AITeamMember* getTeamMember(int);
     9        ~AITeam(){};
     10        AITeam();
     11   void process(float dt);
     12
     13        void addSwarm(int swarmNumber);
     14        void removeSwarm(int swarmNumber);
     15        AISwarm* getSwarm(int swarmNumber);
     16        AISwarm* getCreateSwarm(int swarmNumber);
     17
    1518 private:
    16    std::vector<AITeamMember*> teamMembers;
     19        AISwarm* swarms[32];
     20        static const int maxSwarms=32;
    1721};
    1822
  • branches/ai/src/ai/ai_team_member.cc

    r10071 r10135  
    1414*/
    1515
    16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_AI
    17 #include "ai_team_member.h"
    18 #include "movement_module.h"
    19 #include "ai_engine.h"
    20 #include "debug.h"
    21 
    22 
    23 AITeamMember::AITeamMember()
    24 {}
    25 
    26 AITeamMember::~AITeamMember()
    27 {}
    28 
    29 
    30 
    31 void AITeamMember::process()
    32 {
    33         int moduleCount=modules.size();
    34         for(int i=0; i < moduleCount; i++ )
    35         {
    36         //std::cout << "Processing AIModule " << i << " (" << moduleCount << ")\n";
    37         modules.at(i)->process();
    38         }
    39 }
    40 
    41 
    42 
    43 
    44 void AITeamMember::addToTeam(int aiTeamNumber)
    45 {
    46         //macht nicht so ganz das was es eigntlich machen sollte..
    47         AIEngine* aiEngine=AIEngine::getInstance();
    48         int teamNumber=aiEngine->newTeam();
    49         aiEngine->getTeam(teamNumber)->addMember(this);
    50 
    51         MovementModule* nMod=new MovementModule;
    52         addModule(nMod);
    53         //nMod->testModule=nMod;
    54 }
    55 
    56 
    57 
    58 
    59 void AITeamMember::addModule(AIModule* newModule)
    60 {
    61                 std::cout << "AIModule added\n";
    62                 modules.push_back(newModule);
    63                 newModule->setOwner(this);
    64 }
     16// #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_AI
     17// #include "ai_team_member.h"
     18// #include "movement_module.h"
     19// #include "ai_engine.h"
     20// #include "debug.h"
     21//
     22//
     23//
     24// void AITeamMember::process()
     25// {
     26//      int moduleCount=modules.size();
     27//      for(int i=0; i < moduleCount; i++ )
     28//      {
     29//      //std::cout << "Processing AIModule " << i << " (" << moduleCount << ")\n";
     30//      modules.at(i)->process();
     31//      }
     32// }
     33//
     34//
     35//
     36//
     37// void AITeamMember::addToTeam(int aiTeamNumber)
     38// {
     39//      //macht nicht so ganz das was es eigntlich machen sollte..
     40//      AIEngine* aiEngine=AIEngine::getInstance();
     41//      int teamNumber=aiEngine->newTeam();
     42//      aiEngine->getTeam(teamNumber)->addMember(this);
     43//
     44//      MovementModule* nMod=new MovementModule;
     45//      addModule(nMod);
     46//      //nMod->testModule=nMod;
     47// }
     48//
     49//
     50//
     51//
     52// void AITeamMember::addModule(AIModule* newModule)
     53// {
     54//              std::cout << "AIModule added\n";
     55//              modules.push_back(newModule);
     56//              newModule->setOwner(this);
     57// }
  • branches/ai/src/ai/ai_team_member.h

    r10045 r10135  
    88//class AIModule;
    99
    10 class AITeamMember : public WorldEntity{
    11  public:
    12    AITeamMember();
    13    ~AITeamMember();
    14 
    15    void process();
    16    void addToTeam(int);
    17    void addModule(AIModule*);
    18  private:
    19    std::vector<AIModule*>          modules;
     10class AITeamMember : public WorldEntity {
     11//  public:
     12//      AITeamMember(){};
     13//      ~AITeamMember(){};
     14//
     15//    void process();
     16//    void addToTeam(int);
     17//    void addModule(AIModule*);
     18//
     19//      inline void setTeamNumber(int teamNumber){this->teamNumber=teamNumber;}
     20//      inline int getTeamNumber(){return this->teamNumber;}
     21//      inline void setSwarmNumber(int swarmNumber){this->swarmNumber=swarmNumber;}
     22//      inline int getSwarmNumber(){return this->swarmNumber;}
     23//
     24//  private:
     25//       AIModule* aiModule;
     26//       int teamNumber;
     27//       int swarmNumber;
     28//       int difficulty;
    2029};
    2130
  • branches/ai/src/ai/movement_module.cc

    r10112 r10135  
    2525
    2626#include "shell_command.h"
    27 SHELL_COMMAND(setDistanceToPlayer, MovementModule, setDistanceToPlayer);
    28 SHELL_COMMAND(setDistanceToNPC, MovementModule, setDistanceToNPC);
    29 SHELL_COMMAND(setMaxAccleartion, MovementModule, setMaxAccleartion);
    30 
    31 float MovementModule::distanceToPlayer=15;
    32 float MovementModule::distanceToNPC=2;
    33 float MovementModule::maxAccleration=200.0f;
    34 
    35 void MovementModule::setDistanceToPlayer(float newValue){ distanceToPlayer=newValue; }
    36 void MovementModule::setDistanceToNPC(float newValue){ distanceToNPC=newValue; }
    37 void MovementModule::setMaxAccleartion(float newValue){ maxAccleration=newValue; }
    38 
    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 
     27// SHELL_COMMAND(setDistanceToPlayer, MovementModule, setDistanceToPlayer);
     28// SHELL_COMMAND(setDistanceToNPC, MovementModule, setDistanceToNPC);
     29// SHELL_COMMAND(setMaxAccleartion, MovementModule, setMaxAccleartion);
     30//
     31// float MovementModule::distanceToPlayer=15;
     32// float MovementModule::distanceToNPC=2;
     33// float MovementModule::maxAccleration=200.0f;
     34//
     35// void MovementModule::setDistanceToPlayer(float newValue){ distanceToPlayer=newValue; }
     36// void MovementModule::setDistanceToNPC(float newValue){ distanceToNPC=newValue; }
     37// void MovementModule::setMaxAccleartion(float newValue){ maxAccleration=newValue; }
     38//
     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//
    6464MovementModule::MovementModule(NPC2* object){ this->myNPC=object; }
    6565MovementModule::~MovementModule(){}
     
    7272        AABB* aabb = object->getModelAABB();
    7373        if( aabb == NULL)return -1;
    74        
     74
    7575        float a = aabb->halfLength[0];
    7676        float b = aabb->halfLength[1];
     
    8787
    8888
    89 void MovementModule::collectInformation(float dt)
     89// void MovementModule::collectInformation(float dt)
     90// {
     91//      //return if already processed..
     92//      if(dt==this->oldDT)return;
     93//      this->oldDT=dt;
     94//
     95//
     96//      //clear old Information..
     97//      hidingPoint.clear();
     98//      hidingPointSize.clear();
     99//
     100//      npcList.clear();
     101//      npcPosition.clear();
     102//      npcRadius.clear();
     103//      npcSwarm.clear();
     104//      npcTeam.clear();
     105//
     106//      swarmCenter.clear();
     107//      swarmMemberCount.clear();
     108//
     109//
     110//      //get all NPCs..
     111//      for(ObjectList<NPC2>::const_iterator it = NPC2::objectList().begin(); it != NPC2::objectList().end(); ++it)
     112//      {
     113//              npcList.push_back(*it);
     114//              npcRadius.push_back(getRadius(*it));
     115//              npcPosition.push_back((*it)->getAbsCoor());
     116//              npcSwarm.push_back((*it)->swarm);
     117//              npcTeam.push_back((*it)->team);
     118//      }
     119//
     120//
     121//      //Swarm Information
     122//      unsigned int tmpSwarm;
     123//      for(unsigned int i=0;i<npcList.size();i++){
     124//              tmpSwarm = npcSwarm.at(i);
     125//              if(tmpSwarm > swarmMemberCount.size()){
     126//                      //swarmMemberCount.insert(swarmMemberCount.size(), tmpSwarm - swarmMemberCount.size(), 0);
     127//                      //swarmCenter.insert(swarmCenter.size(), tmpSwarm - swarmCenter.size(), Vector(0,0,0));
     128//              }
     129//              //swarmMemberCount.at(tmpSwarm)++;
     130//              //swarmCenter.at(tmpSwarm)=swarmCenter.at(tmpSwarm)+npcPosition.at(i);
     131//      }
     132//      for(unsigned int i=0;i<swarmCenter.size();i++){
     133//              //swarmCenter.at(i)=swarmCenter.at(i)/swarmMemberCount.at(i);
     134//      }
     135//
     136//
     137//      //get information about Player
     138//      Player* pl = State::getPlayer();
     139//      if( pl != NULL){
     140//              playerPosition = pl->getPlayable()->getAbsCoor();
     141//              playerRadius=getRadius( pl->getPlayable() );
     142//              //PRINTF(0)("Player Radius: %f\n",playerRadius);
     143//      }
     144//
     145//
     146//      //calculate hiding Points..
     147//
     148// }
     149
     150
     151void MovementModule::process(float dt)
    90152{
    91         //return if already processed..
    92         if(dt==this->oldDT)return;
    93         this->oldDT=dt;
    94        
    95        
    96         //clear old Information..
    97         hidingPoint.clear();
    98         hidingPointSize.clear();
    99 
    100         npcList.clear();
    101         npcPosition.clear();
    102         npcRadius.clear();
    103         npcSwarm.clear();
    104         npcTeam.clear();
    105        
    106         swarmCenter.clear();
    107         swarmMemberCount.clear();
    108        
    109        
    110         //get all NPCs..
    111         for(ObjectList<NPC2>::const_iterator it = NPC2::objectList().begin(); it != NPC2::objectList().end(); ++it)
    112         {
    113                 npcList.push_back(*it);
    114                 npcRadius.push_back(getRadius(*it));
    115                 npcPosition.push_back((*it)->getAbsCoor());
    116                 npcSwarm.push_back((*it)->swarm);
    117                 npcTeam.push_back((*it)->team);
    118         }
    119        
    120        
    121         //Swarm Information
    122         unsigned int tmpSwarm;
    123         for(unsigned int i=0;i<npcList.size();i++){
    124                 tmpSwarm = npcSwarm.at(i);
    125                 if(tmpSwarm > swarmMemberCount.size()){
    126                         //swarmMemberCount.insert(swarmMemberCount.size(), tmpSwarm - swarmMemberCount.size(), 0);
    127                         //swarmCenter.insert(swarmCenter.size(), tmpSwarm - swarmCenter.size(), Vector(0,0,0));
    128                 }
    129                 //swarmMemberCount.at(tmpSwarm)++;
    130                 //swarmCenter.at(tmpSwarm)=swarmCenter.at(tmpSwarm)+npcPosition.at(i);
    131         }
    132         for(unsigned int i=0;i<swarmCenter.size();i++){
    133                 //swarmCenter.at(i)=swarmCenter.at(i)/swarmMemberCount.at(i);
    134         }
    135        
    136        
     153        if(myNPC == NULL)return;
     154
    137155        //get information about Player
    138156        Player* pl = State::getPlayer();
    139         if( pl != NULL){
    140                 playerPosition = pl->getPlayable()->getAbsCoor();
    141                 playerRadius=getRadius( pl->getPlayable() );
    142                 //PRINTF(0)("Player Radius: %f\n",playerRadius);
    143         }
    144        
    145        
    146         //calculate hiding Points..
    147        
    148 }
    149 
    150 
    151 
    152 
    153 
    154 
    155 
    156 
    157 
    158 
    159 
    160 
    161 
    162 
    163 void MovementModule::process()
    164 {
    165         this->process(AIEngine::getInstance()->dtS);
    166 }
    167 
    168 
    169 void MovementModule::process(float dt)
    170 {
    171         collectInformation(dt);
    172        
    173         if(myNPC == NULL)return;
    174        
     157        if( pl == NULL)return;
     158
     159        Vector playerPosition = pl->getPlayable()->getAbsCoor();
     160        float playerRadius=getRadius( pl->getPlayable() );
     161
     162
     163// collectInformation(dt);
     164
    175165        Vector myPosition = myNPC->getAbsCoor();
    176166        float myRadius = getRadius(myNPC);
    177         int mySwarm = myNPC->swarm;
    178         int myTeam = myNPC->team;
    179        
     167
     168
    180169        Vector vectorToPlayer = playerPosition - myPosition;
    181        
     170
    182171        Vector tmpVector;
    183172        float tmpFloat;
    184        
    185         Vector npcCollision;
    186         Vector swarmVector;
     173
     174//      Vector npcCollision;
     175//      Vector swarmVector;
    187176        Vector playerCollision;
    188        
     177
    189178
    190179
    191180        //float a=200.0f;
    192181        float vMax=200.0f;
     182        float maxAccleration=300.0f;
    193183        //float safetyDistance=2.0f;
    194184
    195185
    196186        //Anti Player Collision
    197         tmpFloat=vectorToPlayer.len()-playerRadius-myRadius-distanceToPlayer;
     187        tmpFloat=vectorToPlayer.len()-playerRadius-myRadius-30;//distanceToPlayer;
    198188        if(tmpFloat<0.1)tmpFloat=0.1;
    199189        playerCollision=vectorToPlayer/(tmpFloat*tmpFloat)*(-1);
    200        
    201        
    202        
    203         for (unsigned int i=0;i<npcList.size();i++)
    204         {
    205                 if(npcList.at(i)==myNPC)continue;
    206                
    207                 //Anti NPC Collision
    208                 tmpVector=myPosition-npcPosition.at(i);
    209                 tmpFloat=tmpVector.len()-myRadius-npcRadius.at(i)-distanceToNPC;
    210                
    211                 if(tmpFloat<0.1)tmpFloat=0.1;
    212                 tmpVector=tmpVector/(tmpFloat*tmpFloat);
    213                
    214                 npcCollision=npcCollision+tmpVector;
    215                
    216                 //Schwarmverhalten
    217                 if(npcSwarm.at(i) == mySwarm){
    218                
    219                
    220                 }
    221         }
    222 
    223 
    224 
    225        
    226        
    227         Vector correction=playerCollision*50+npcCollision*50+vectorToPlayer-myMovement;
     190
     191
     192
     193//      for (unsigned int i=0;i<npcList.size();i++)
     194//      {
     195//              if(npcList.at(i)==myNPC)continue;
     196//
     197//              //Anti NPC Collision
     198//              tmpVector=myPosition-npcPosition.at(i);
     199//              tmpFloat=tmpVector.len()-myRadius-npcRadius.at(i)-distanceToNPC;
     200//
     201//              if(tmpFloat<0.1)tmpFloat=0.1;
     202//              tmpVector=tmpVector/(tmpFloat*tmpFloat);
     203//
     204//              npcCollision=npcCollision+tmpVector;
     205//
     206//              //Schwarmverhalten
     207//              if(npcSwarm.at(i) == mySwarm){
     208//
     209//
     210//              }
     211//      }
     212
     213
     214
     215
     216
     217        //Vector correction=playerCollision*50+npcCollision*50+vectorToPlayer+Vector(70,0,0)-myMovement;
     218        Vector correction=playerCollision*50+vectorToPlayer+Vector(50,0,0)-myMovement;
     219
    228220        correction.y=0;
    229221        float correctionLen=correction.len();
  • branches/ai/src/ai/movement_module.h

    r10112 r10135  
    1111
    1212class MovementModule : public AIModule{
    13        
    14  public:
    15    MovementModule() {}
    16    MovementModule(NPC2* object);
    17    virtual ~MovementModule();
    18    virtual void process();
    19    virtual void process(float dt);
    2013
    21    static void setDistanceToPlayer(float newValue);
    22    static void setDistanceToNPC(float newValue);
    23    static void setMaxAccleartion(float newValue);
    24    
    25  private:
    26         void collectInformation(float dt);
    27        
    28        
    29         static std::vector<Vector>      hidingPoint;
    30         static std::vector<float>       hidingPointSize;
    31        
    32         static std::vector<NPC2*> npcList;
    33         static std::vector<Vector> npcPosition;
    34         static std::vector<float> npcRadius;
    35         static std::vector<int> npcSwarm;
    36         static std::vector<int> npcTeam;
    37        
    38         static Vector playerPosition;
    39         static Vector playerMovement;
    40         static float playerRadius;
    41        
    42         static std::vector<Vector> swarmCenter;
    43         static std::vector<int> swarmMemberCount;
    44        
    45         Vector myMovement;
    46         float myMaxAccleration;
    47         float myMaxSpeed;
    48        
    49        
    50         float getRadius(WorldEntity* object);
    51         static float aa;
    52         float oldDT;
    53        
    54         static float maxAccleration;
    55         static float distanceToPlayer;
    56         static float distanceToNPC;
     14        public:
     15                MovementModule() {}
     16                MovementModule(NPC2* object);
     17                virtual ~MovementModule();
     18                virtual void process(float dt);
     19
     20//    static void setDistanceToPlayer(float newValue);
     21//    static void setDistanceToNPC(float newValue);
     22//    static void setMaxAccleartion(float newValue);
     23//
     24        private:
     25//      void collectInformation(float dt);
     26//
     27//
     28//      static std::vector<Vector>      hidingPoint;
     29//      static std::vector<float>       hidingPointSize;
     30//
     31//      static std::vector<NPC2*> npcList;
     32//      static std::vector<Vector> npcPosition;
     33//      static std::vector<float> npcRadius;
     34//      static std::vector<int> npcSwarm;
     35//      static std::vector<int> npcTeam;
     36//
     37//      static Vector playerPosition;
     38//      static Vector playerMovement;
     39//      static float playerRadius;
     40//
     41//      static std::vector<Vector> swarmCenter;
     42//      static std::vector<int> swarmMemberCount;
     43
     44                Vector myMovement;
     45                float myMaxAccleration;
     46                float myMaxSpeed;
     47
     48
     49                float getRadius(WorldEntity* object);
     50//      static float aa;
     51//      float oldDT;
     52//
     53//      static float maxAccleration;
     54//      static float distanceToPlayer;
     55//      static float distanceToNPC;
    5756};
    5857
  • branches/ai/src/world_entities/npcs/npc_test.cc

    r10112 r10135  
    1919
    2020#include "npc_test.h"
    21 
     21#include <stdio.h>
    2222
    2323#include "state.h"
     
    3434#include "movement_module.h"
    3535#include "ai_module.h"
    36 
     36#include "ai_team.h"
     37#include "ai_swarm.h"
     38#include "ai_engine.h"
    3739
    3840ObjectListDefinitionID(NPC2, CL_NPC_TEST2);
     
    4345{
    4446        this->registerObject(this, NPC2::_objectList);
    45         if (root != NULL)this->loadParams(root);
    46        
    47         this->aiModule=new MovementModule(this);
     47
     48        if (root != NULL)
     49                this->loadParams(root);
     50
     51        std::cout << "Team Number: " << teamNumber << "\n";
     52        std::cout << "Swarm Number:" << swarmNumber << "\n";
     53
     54        AITeam* myTeam=AIEngine::getInstance()->getCreateTeam(teamNumber);
     55        //std::cout << "Testpoint 4: " << myTeam << "\n";
     56        AISwarm* mySwarm=myTeam->getCreateSwarm(swarmNumber);
     57        //std::cout << "Testpoint 5: " << mySwarm << "\n";
     58        mySwarm->addToSwarm(new MovementModule(this));
     59
    4860}
    4961
    50 
    51 NPC2::~NPC2 ()
    52 {}
    5362
    5463
     
    5665{
    5766  NPC::loadParams(root);
     67
     68  LoadParam(root, "team", this, NPC2, setTeamNumber)
     69                .describe("this sets the team number")
     70                .defaultValues(0);
     71
     72  LoadParam(root, "swarm", this, NPC2, setSwarmNumber)
     73                .describe("this sets the swarm number")
     74                .defaultValues(0);
    5875}
    5976
     
    6582        if( likely(this->getModel(0) != NULL) && this->getModel(0)->isA(MD2Model::staticClassID()))
    6683                ((MD2Model*)this->getModel(0))->tick(dt);
    67 
    68         // processing AI
    69         //PRINTF(0)("Processing NPC\n");
    70         if(this->aiModule!=NULL)this->aiModule->process(dt);
    7184}
    7285
  • branches/ai/src/world_entities/npcs/npc_test.h

    r10112 r10135  
    1111
    1212class NPC2 : public NPC {
    13   ObjectListDeclaration(NPC2);
     13        ObjectListDeclaration(NPC2);
    1414
    15  public:
    16   NPC2 (const TiXmlElement* root);
    17   virtual ~NPC2 ();
    18   virtual void loadParams(const TiXmlElement* root);
    19   virtual void tick(float dt);
     15        public:
     16                NPC2 (const TiXmlElement* root);
     17                virtual ~NPC2 (){};
     18                virtual void loadParams(const TiXmlElement* root);
     19                virtual void tick(float dt);
    2020
    21         int team;
    22         int swarm;
    23         int difficulty;
    24         AIModule* aiModule;
     21
     22        private:
     23                inline void setTeamNumber(int number){teamNumber=number;}
     24                inline void setSwarmNumber(int number){swarmNumber=number;}
     25
     26                int teamNumber;
     27                int swarmNumber;
     28                int difficulty;
     29
     30                AIModule* aiModule;
    2531};
    2632
Note: See TracChangeset for help on using the changeset viewer.