Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

tired

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                //add player to enemys (player belongs to team 0)
33                if(it->first!=0){
34                        Player* pl = State::getPlayer();
35                        if(pl != NULL)enemyList->push_back(pl->getPlayable());
36                }
37       
38                //find other enemys for this team
39                for(ObjectList<NPC2>::const_iterator npc = NPC2::objectList().begin(); npc != NPC2::objectList().end(); ++npc)
40                        if((*npc)->getTeam() != it->first)enemyList->push_back(*npc);
41
42                //process the team
43                it->second->setEnemyList(enemyList);
44                it->second->process(dt);
45                enemyList->clear();
46        }
47
48        delete enemyList;
49}
50
51void AIEngine::addAI(int teamNumber, int swarmNumber, WorldEntity* npc)
52{
53        std::pair<std::map<int,AITeam*>::iterator,bool> p;
54        AITeam* newTeam=new AITeam();
55        p=teams.insert(std::make_pair(teamNumber,newTeam));
56        if(!p.second)delete newTeam;
57        p.first->second->addAI(swarmNumber, npc);
58}
59
60void AIEngine::removeAI(int teamNumber, int swarmNumber, WorldEntity* npc)
61{
62        std::map<int,AITeam*>::iterator it = teams.find(swarmNumber);
63        if(it==teams.end())return;
64        it->second->removeAI(swarmNumber,npc);
65        if(it->second->getTeamSize()==0){
66                delete it->second;
67                teams.erase(it);
68        }
69}
70
Note: See TracBrowser for help on using the repository browser.