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_team.h" |
---|
17 | #include "swarm_gorel.h" |
---|
18 | #include "swarm_module.h" |
---|
19 | #include "debug.h" |
---|
20 | |
---|
21 | void AITeam::process(float dt) |
---|
22 | { |
---|
23 | std::map<int,SwarmModule*>::iterator it; |
---|
24 | for (it= swarms.begin(); it!= swarms.end(); it++ ){ |
---|
25 | |
---|
26 | if(it->second->taskDone()){ |
---|
27 | std::cout << "Task Done!\n"; |
---|
28 | changeSwarmModule(it, new SwarmGoRel); |
---|
29 | |
---|
30 | if(enemyList->size()>0){ |
---|
31 | 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); |
---|
37 | } |
---|
38 | } |
---|
39 | it->second->process(dt); |
---|
40 | } |
---|
41 | } |
---|
42 | |
---|
43 | void AITeam::changeSwarmModule(std::map<int,SwarmModule*>::iterator it,SwarmModule* newAI) |
---|
44 | { |
---|
45 | SwarmModule* oldAI = it->second; |
---|
46 | newAI->getAttributesFrom(oldAI); |
---|
47 | it->second=newAI; |
---|
48 | delete oldAI; |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | void AITeam::addAI(int swarmNumber, WorldEntity* npc) |
---|
53 | { |
---|
54 | std::pair<std::map<int,SwarmModule*>::iterator,bool> p; |
---|
55 | SwarmModule* newSwarm=new SwarmGoRel(); |
---|
56 | p=swarms.insert(std::make_pair(swarmNumber,newSwarm)); |
---|
57 | if(!p.second)delete newSwarm; |
---|
58 | p.first->second->addAI(npc); |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | void AITeam::removeAI(int swarmNumber, WorldEntity* npc) |
---|
63 | { |
---|
64 | std::map<int,SwarmModule*>::iterator it = swarms.find(swarmNumber); |
---|
65 | if(it==swarms.end())return; |
---|
66 | it->second->removeAI(npc); |
---|
67 | if(it->second->getSwarmSize()==0){ |
---|
68 | delete it->second; |
---|
69 | swarms.erase(it); |
---|
70 | } |
---|
71 | } |
---|