| 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 | |
|---|
| 20 | void 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 | |
|---|
| 30 | void SwarmAttack::process(float dt) |
|---|
| 31 | { |
|---|
| 32 | std::map<WorldEntity*,AIModule*>::iterator it; |
|---|
| 33 | |
|---|
| 34 | Vector sideL=taskRelPos.cross(Vector(0,1,0)).getNormalized(); |
|---|
| 35 | Vector sideR=sideL*-1; |
|---|
| 36 | Vector posL=Vector(0,0,0); |
|---|
| 37 | Vector posR=Vector(0,0,0); |
|---|
| 38 | |
|---|
| 39 | //tell positions to swarm-members... |
|---|
| 40 | float radius; |
|---|
| 41 | Vector objectPos=taskRelObject->getAbsCoor(); |
|---|
| 42 | |
|---|
| 43 | for (it=members.begin(); it!= members.end(); it++ ){ |
|---|
| 44 | radius=it->second->getNPCRadius(); |
|---|
| 45 | posR=posR+sideR*radius*1.5; |
|---|
| 46 | it->second->setDestination(objectPos+taskRelPos+posR); |
|---|
| 47 | it->second->setDestinationMovement(Vector(0,0,0)); |
|---|
| 48 | it->second->setTarget(taskRelObject); |
|---|
| 49 | it->second->process(dt); |
|---|
| 50 | posR=posR+sideR*radius*1.5; |
|---|
| 51 | |
|---|
| 52 | it++; |
|---|
| 53 | if(it==members.end())break; |
|---|
| 54 | radius=it->second->getNPCRadius(); |
|---|
| 55 | posL=posL+sideL*radius*1.5; |
|---|
| 56 | it->second->setDestination(objectPos+taskRelPos+posL); |
|---|
| 57 | it->second->setDestinationMovement(Vector(0,0,0)); |
|---|
| 58 | it->second->setTarget(taskRelObject); |
|---|
| 59 | it->second->process(dt); |
|---|
| 60 | posL=posL+sideL*radius*1.5; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | //check time.. |
|---|
| 64 | taskMaxTime-=dt; |
|---|
| 65 | if(taskMaxTime<0)taskComplete=true; |
|---|
| 66 | } |
|---|