Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/ai/ai_engine.cc

Last change on this file was 10376, checked in by patrick, 17 years ago

merged branche ai to trunk

File size: 1.9 KB
RevLine 
[10029]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:
[10137]12   main-programmer: Thomas Fahrni
[10029]13   co-programmer:
14*/
[10040]15#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_AI
[10029]16#include "ai_engine.h"
[10040]17#include "debug.h"
[10138]18#include "npcs/npc_test.h"
19#include "player.h"
20#include "playable.h"
21#include "state.h"
[10029]22
[10040]23AIEngine* AIEngine::singletonRef = NULL;
[10029]24
[10137]25void AIEngine::tick(float dt)
[10135]26{
[10137]27        std::map<int,AITeam*>::iterator it;
[10138]28        std::vector<WorldEntity*>* enemyList=new std::vector<WorldEntity*>;
[10226]29
[10138]30        for (it=teams.begin(); it!= teams.end(); it++ )
31        {
32                //add player to enemys (player belongs to team 0)
33                if(it->first!=0){
34                        Player* pl = State::getPlayer();
[10266]35                        if( pl!=NULL && pl->getPlayable()!=NULL )
36                                enemyList->push_back(pl->getPlayable());
[10138]37                }
[10266]38
[10244]39                //find other enemys for this team
40                for(ObjectList<NPC2>::const_iterator npc = NPC2::objectList().begin(); npc != NPC2::objectList().end(); ++npc)
41                        if((*npc)->getTeam() != it->first)enemyList->push_back(*npc);
[10226]42
[10138]43                //process the team
44                it->second->setEnemyList(enemyList);
[10137]45                it->second->process(dt);
[10138]46                enemyList->clear();
47        }
[10226]48
[10138]49        delete enemyList;
[10135]50}
[10029]51
[10349]52void AIEngine::addAI(int teamNumber, int swarmNumber, WorldEntity* npc, float maxSpeed, float attackDistance)
[10135]53{
[10137]54        std::pair<std::map<int,AITeam*>::iterator,bool> p;
55        AITeam* newTeam=new AITeam();
56        p=teams.insert(std::make_pair(teamNumber,newTeam));
57        if(!p.second)delete newTeam;
[10349]58        p.first->second->addAI(swarmNumber, npc, maxSpeed, attackDistance);
[10135]59}
[10040]60
[10226]61void AIEngine::removeAI(int teamNumber, int swarmNumber, WorldEntity* npc)
[10135]62{
[10266]63        std::map<int,AITeam*>::iterator it = teams.find(teamNumber);
[10137]64        if(it==teams.end())return;
[10226]65        it->second->removeAI(swarmNumber,npc);
[10137]66        if(it->second->getTeamSize()==0){
67                delete it->second;
68                teams.erase(it);
69        }
[10135]70}
[10041]71
Note: See TracBrowser for help on using the repository browser.