Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/ai/src/ai/ai_swarm.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.3 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_swarm.h"
17#include "debug.h"
18
19void AISwarm::process(float dt)
20{
21        std::set<AIModule*>::iterator it;
22        it= swarmMembers.begin();
23        Vector leaderPosition=(*it)->getPosition();
24        (*it)->setDestination(destination);
25        (*it)->setEnemyList(enemyList);
26        (*it)->process(dt);
27               
28        for (it++; it!= swarmMembers.end(); it++ ){
29                (*it)->setDestination(leaderPosition);
30                (*it)->setEnemyList(enemyList);
31                (*it)->process(dt);
32        }
33}
34
35void AISwarm::addAI(AIModule* aiModule)
36{
37        swarmMembers.insert(aiModule);
38}
39
40void AISwarm::removeAI(AIModule* aiModule)
41{
42        std::set<AIModule*>::iterator it=swarmMembers.find(aiModule);
43        if(it==swarmMembers.end())return;
44        delete (*it);
45}
46
47Vector AISwarm::getPosition()
48{
49        Vector center=Vector(0,0,0);
50        std::set<AIModule*>::iterator it;
51        for (it= swarmMembers.begin(); it!= swarmMembers.end(); it++ )
52                center=center+(*it)->getPosition();
53
54        return center/swarmMembers.size();
55}
Note: See TracBrowser for help on using the repository browser.