Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/ai/src/ai/ai_engine.cc @ 10138

Last change on this file since 10138 was 10138, checked in by tfahrni, 17 years ago

startet to implement swarming

File size: 1.9 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Thomas Fahrni
13   co-programmer:
14*/
15#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_AI
16#include "ai_engine.h"
17#include "debug.h"
18#include "npcs/npc_test.h"
19#include "player.h"
20#include "playable.h"
21#include "state.h"
22
23AIEngine* AIEngine::singletonRef = NULL;
24
25void AIEngine::tick(float dt)
26{
27        std::map<int,AITeam*>::iterator it;
28        std::vector<WorldEntity*>* enemyList=new std::vector<WorldEntity*>;
29       
30        for (it=teams.begin(); it!= teams.end(); it++ )
31        {
32                //find enemys for the team
33                for(ObjectList<NPC2>::const_iterator npc = NPC2::objectList().begin(); npc != NPC2::objectList().end(); ++npc)
34                        if((*npc)->getTeam() != it->first)enemyList->push_back(*npc);
35               
36                //add player to enemys (player belongs to team 0)
37                if(it->first!=0){
38                        //std::cout << "adding player to enemyList\n";
39                        Player* pl = State::getPlayer();
40                        if(pl != NULL)enemyList->push_back(pl->getPlayable());
41                }
42               
43                //process the team
44                it->second->setEnemyList(enemyList);
45                it->second->process(dt);
46                enemyList->clear();
47        }
48       
49        delete enemyList;
50}
51
52void AIEngine::addAI(int teamNumber, int swarmNumber, AIModule* aiModule)
53{
54        std::pair<std::map<int,AITeam*>::iterator,bool> p;
55        AITeam* newTeam=new AITeam();
56        p=teams.insert(std::make_pair(teamNumber,newTeam));
57        if(!p.second)delete newTeam;
58        p.first->second->addAI(swarmNumber, aiModule);
59}
60
61void AIEngine::removeAI(int teamNumber, int swarmNumber, AIModule* aiModule)
62{
63        std::map<int,AITeam*>::iterator it = teams.find(swarmNumber);
64        if(it==teams.end())return;
65        it->second->removeAI(swarmNumber,aiModule);
66        if(it->second->getTeamSize()==0){
67                delete it->second;
68                teams.erase(it);
69        }
70}
71
Note: See TracBrowser for help on using the repository browser.