Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/hud/src/ai/swarm_attack.cc @ 10671

Last change on this file since 10671 was 10618, checked in by bknecht, 18 years ago

merged cleanup into trunk (only improvements)

File size: 2.1 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 "swarm_attack.h"
17#include "ai_module.h"
18#include "attack_module.h"
19
20void SwarmAttack::initialize()
21{
22        std::map<WorldEntity*,AIModule*>::iterator it;
23
24        //load correct ai-module..
25        for (it= members.begin(); it!= members.end(); it++ ){
26                changeAIModule(it, new AttackModule());
27        }
28}
29
30void SwarmAttack::process(float dt)
31{
32  WorldEntity* taskRelObject = NULL;
33  if ( taskRelObjectName != "" )
34  {
35    taskRelObject = dynamic_cast<WorldEntity*>(WorldEntity::objectList().getBaseObject( taskRelObjectName ));
36         
37         
38    std::map<WorldEntity*,AIModule*>::iterator it;
39    Vector sideL=taskRelPos.cross(Vector(0,1,0)).getNormalized();
40    Vector sideR=sideL*-1;
41    Vector posL=Vector(0,0,0);
42    Vector posR=Vector(0,0,0);
43       
44
45       
46        //tell positions to swarm-members...
47    float radius;
48    Vector objectPos=taskRelObject->getAbsCoor();
49
50    for (it=members.begin(); it!= members.end(); it++ ){
51      radius=it->second->getNPCRadius();
52      posR=posR+sideR*radius*1.5;
53      it->second->setDestination(objectPos+taskRelPos+posR);
54      it->second->setDestinationMovement(Vector(0,0,0));
55      it->second->setTarget(taskRelObject);
56      it->second->process(dt);
57      posR=posR+sideR*radius*1.5;
58
59      it++;
60      if(it==members.end())break;
61      radius=it->second->getNPCRadius();
62      posL=posL+sideL*radius*1.5;
63      it->second->setDestination(objectPos+taskRelPos+posL);
64      it->second->setDestinationMovement(Vector(0,0,0));
65      it->second->setTarget(taskRelObject);
66      it->second->process(dt);
67      posL=posL+sideL*radius*1.5;
68    }
69
70        //check time..
71    taskMaxTime-=dt;
72    if(taskMaxTime<0)taskComplete=true;
73  }
74}
Note: See TracBrowser for help on using the repository browser.