/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Thomas Fahrni co-programmer: */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_AI #include "ai_team.h" #include "swarm_gorel.h" #include "swarm_module.h" #include "swarm_wait.h" #include "swarm_attack.h" #include "debug.h" #include "player.h" #include "playable.h" #include "state.h" void AITeam::process(float dt) { std::map::iterator it; for (it= swarms.begin(); it!= swarms.end(); it++ ){ if(it->second->taskDone()){ std::cout << "Swarm Task Complete!\n"; if(enemyList->size()==0){ changeSwarmModule(it, new SwarmWait); it->second->orderMaxTime(2); //sleep 2 seconds.. it->second->process(dt); continue; } Vector position=it->second->getPosition(); Vector newPosition; WorldEntity* target=enemyList->at(0); //check if enemy is the player.. bool isPlayer=(State::getPlayer()->getPlayable()==target); float speed; float maxTime=10; //find new Position if(isPlayer){ Vector targetPos=target->getAbsCoor(); int zNorm=(position.z>targetPos.z)?1:-1; if((position.z-targetPos.z)*zNorm>80){ //go to start position std::cout << "Go Start Position\n"; changeSwarmModule(it, new SwarmGoRel); newPosition=Vector(220,0,zNorm*60); speed=100; }else if(position.x > targetPos.x+150){ //go to attack position std::cout << "Go Attack Position\n"; changeSwarmModule(it, new SwarmGoRel); newPosition=Vector(100,0,0); speed=60; }else if(position.x > targetPos.x+90){ //go to attack mode std::cout << "Go Attack Mode\n"; changeSwarmModule(it, new SwarmAttack); newPosition=Vector(80,0,0); speed=80; maxTime=(rand()%11);//0-10 Sekunden }else{ //go to fallback point std::cout << "Go Fallback Point\n"; changeSwarmModule(it, new SwarmGoRel); newPosition=Vector(0,0,zNorm*150); speed=60; } }else{ } if(enemyList->size()>0){ it->second->setEnemyList(enemyList); it->second->orderRelObject(target); it->second->orderRelPos(newPosition); it->second->orderSpeed(speed); //it->second->orderView(Vector(0,0,1)); it->second->orderMaxTime(maxTime); //5-10 //it->second->newOrder(); } } it->second->process(dt); } } void AITeam::changeSwarmModule(std::map::iterator it,SwarmModule* newAI) { SwarmModule* oldAI = it->second; newAI->getAttributesFrom(oldAI); it->second=newAI; delete oldAI; } void AITeam::addAI(int swarmNumber, WorldEntity* npc) { std::pair::iterator,bool> p; SwarmModule* newSwarm=new SwarmGoRel(); p=swarms.insert(std::make_pair(swarmNumber,newSwarm)); if(!p.second)delete newSwarm; p.first->second->addAI(npc); } void AITeam::removeAI(int swarmNumber, WorldEntity* npc) { std::map::iterator it = swarms.find(swarmNumber); if(it==swarms.end())return; it->second->removeAI(npc); if(it->second->getSwarmSize()==0){ delete it->second; swarms.erase(it); } }