Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10137 in orxonox.OLD for branches/ai/src/ai/ai_team.cc


Ignore:
Timestamp:
Dec 21, 2006, 3:49:51 PM (17 years ago)
Author:
tfahrni
Message:

discoverd std::map and std::set

File:
1 edited

Legend:

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

    r10135 r10137  
    1 
    2 
    31/*
    42   orxonox - the future of 3D-vertical-scrollers
     
    1614*/
    1715#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_AI
    18 
    1916#include "ai_team.h"
    20 
    21 AITeam::AITeam(){
    22         for(int i=0; i < maxSwarms; i++ )swarms[i]=NULL;
    23 }
    24 
    25 
    26 AISwarm* AITeam::getSwarm(int swarmNumber)
    27 {
    28         if(swarmNumber>maxSwarms || swarmNumber<0)return NULL;
    29         return swarms[swarmNumber];
    30 }
    31 
    32 
    33 AISwarm* 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 
    41 void AITeam::addSwarm(int swarmNumber)
    42 {
    43         if(swarmNumber>maxSwarms || swarmNumber<0)return;
    44         swarms[swarmNumber]=new AISwarm();
    45 }
    46 
    47 
    48 void AITeam::removeSwarm(int swarmNumber)
    49 {
    50         if(swarmNumber>maxSwarms || swarmNumber<0)return;
    51         swarms[swarmNumber]=NULL;
    52 }
    53 
     17#include "debug.h"
    5418
    5519void AITeam::process(float dt)
    5620{
    57         for(int i=0; i < maxSwarms; i++ ){
    58                 if(swarms[i]!=NULL)swarms[i]->process(dt);
     21        std::map<int,AISwarm*>::iterator it;
     22        for (it= swarms.begin(); it!= swarms.end(); it++ )
     23                it->second->process(dt);
     24}
     25
     26void AITeam::addAI(int swarmNumber, AIModule* aiModule)
     27{
     28        std::pair<std::map<int,AISwarm*>::iterator,bool> p;
     29        AISwarm* newSwarm=new AISwarm();
     30        p=swarms.insert(std::make_pair(swarmNumber,newSwarm));
     31        if(!p.second)delete newSwarm;
     32        p.first->second->addAI(aiModule);
     33}
     34
     35void AITeam::removeAI(int swarmNumber, AIModule* aiModule)
     36{
     37        std::map<int,AISwarm*>::iterator it = swarms.find(swarmNumber);
     38        if(it==swarms.end())return;
     39        it->second->removeAI(aiModule);
     40        if(it->second->getSwarmSize()==0){
     41                delete it->second;
     42                swarms.erase(it);
    5943        }
    6044}
    6145
    62 
     46int AITeam::getTeamSize()
     47{
     48        return swarms.size();
     49}
Note: See TracChangeset for help on using the changeset viewer.