Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/ai/swarm_gorel.cc @ 10737

Last change on this file since 10737 was 10698, checked in by snellen, 18 years ago

merged adm, hud, vs-enhancements : beni's responsible for this commit. blame him!

File size: 2.8 KB
RevLine 
[10244]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_gorel.h"
17#include "ai_module.h"
18#include "movement_module.h"
19
20void SwarmGoRel::initialize()
21{
22        std::map<WorldEntity*,AIModule*>::iterator it;
[10266]23
[10244]24        //calculate  movement parameters..
[10698]25        float averageRadius = 0;
[10244]26        for (it=members.begin(); it!= members.end(); it++ ){
27                averageRadius+=it->second->getNPCRadius();
28        }
29        averageRadius=averageRadius/members.size();
[10290]30        aMax=80;//400/averageRadius;
[10349]31        vMax=maxSpeed;//1000/averageRadius;//300/averageRadius;
[10249]32        viewChangeMax=90/averageRadius;
[10266]33
[10244]34        //load correct ai-module..
35        for (it= members.begin(); it!= members.end(); it++ ){
36                changeAIModule(it, new MovementModule());
37        }
[10266]38
[10249]39        //get swarm position..
40        //position=this->getPosition();
[10244]41}
42
43void SwarmGoRel::process(float dt)
44{
45        std::map<WorldEntity*,AIModule*>::iterator it;
46
[10249]47        //Vector swarmPosition=this->getPosition();
[10244]48        Vector correction=Vector(0,0,0);
49        Vector destination;
[10618]50       
51        WorldEntity* taskRelObject = NULL;
52        if ( taskRelObjectName != "" )
53          taskRelObject = dynamic_cast<WorldEntity*>(WorldEntity::objectList().getBaseObject( taskRelObjectName ));
[10266]54
[10244]55        if(taskRelObject!=NULL && taskMaxTime>0){
56                destination=taskRelObject->getAbsCoor()+taskRelPos;
[10249]57                correction=(destination-position)-view*speed;
[10244]58                correction.y=0;
59                taskMaxTime-=dt;
60        }else{
61                taskComplete=true;
62        }
[10266]63
[10244]64        float correctionLen=correction.len();
65        if(correctionLen>aMax*dt)correction=correction/correctionLen*aMax*dt;
66
67        //std::cout << angleRad(correction,movement) << "\n";
68        Vector movement=view*speed+correction;
69
70        float movementLen=movement.len();
71        if(movementLen>vMax)movement=movement/movementLen*vMax;
[10266]72
[10249]73        float newSpeed=movement.len();
74        Vector newView=movement.getNormalized();
[10266]75
[10283]76        /*if((newSpeed<=taskSpeed && speed>=taskSpeed)||(newSpeed>=taskSpeed && speed<=taskSpeed)){
[10249]77                newSpeed=taskSpeed;
78        }else if((newSpeed>speed && speed<taskSpeed) || (newSpeed < speed && speed < taskSpeed)){
79                newSpeed=taskSpeed;
[10283]80        }*/
[10266]81
[10275]82        /*if(angleDeg(view,newView)>viewChangeMax){
[10249]83                std::cout << "alarm\n";
[10275]84        }*/
[10283]85        if(newSpeed<40)newSpeed=40;
86        if(newSpeed>vMax)newSpeed=vMax;
[10275]87
[10249]88        speed=newSpeed;
89        view=newView;
90        position=position+view*speed*dt;
[10244]91
92        //tell orders to swarm-members...
93        for (it= members.begin(); it!= members.end(); it++ ){
[10249]94                it->second->setDestination(position);
95                it->second->setDestinationMovement(view*speed);
[10244]96                it->second->process(dt);
97        }
[10266]98
[10244]99        //check if destination reached
100        if(!taskComplete){
[10249]101                //swarmPosition=this->getPosition();
[10275]102                if((destination-position).len()<10)taskComplete=true;
[10244]103        }
104}
Note: See TracBrowser for help on using the repository browser.