/* 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){ float attackDistance=it->second->getAttackDistance(); Vector targetPos=target->getAbsCoor(); float distanceToPlayer=(targetPos-position).len(); // int zNorm=(position.z>targetPos.z)?1:-1; // unused var if(distanceToPlayer60){ //go to start position std::cout << "Go Start Position\n"; changeSwarmModule(it, new SwarmGoRel); zNorm=1-(rand()%2)*2; //1 or -1 newPosition=Vector(attackDistance+60,0,zNorm*10); speed=60; }else if(position.x > targetPos.x+attackDistance+40){ //go to attack position std::cout << "Go Attack Position\n"; changeSwarmModule(it, new SwarmGoRel); newPosition=Vector(attackDistance+30,0,0) speed=60; }else if(position.x > targetPos.x+attackDistance+20){ //go to attack mode; std::cout << "Go Attack Mode \n";*/ std::cout << "AI Attacks \n"; changeSwarmModule(it, new SwarmAttack); newPosition=Vector(attackDistance,0,0); speed=60; maxTime=(1000);//rand()%11)+4;//4-14 Sekunden /*}else{ //go to fallback point std::cout << "Go Fallback Point\n"; changeSwarmModule(it, new SwarmGoRel); newPosition=Vector(80,0,zNorm*90); speed=80;*/ } //}else{ } speed=0; 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, float maxSpeed, float attackDistance) { 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, maxSpeed, attackDistance); } 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); } }