Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10558 was 10376, checked in by patrick, 18 years ago

merged branche ai to trunk

File size: 2.6 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..
25        float averageRadius;
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;
[10266]50
[10244]51        if(taskRelObject!=NULL && taskMaxTime>0){
52                destination=taskRelObject->getAbsCoor()+taskRelPos;
[10249]53                correction=(destination-position)-view*speed;
[10244]54                correction.y=0;
55                taskMaxTime-=dt;
56        }else{
57                taskComplete=true;
58        }
[10266]59
[10244]60        float correctionLen=correction.len();
61        if(correctionLen>aMax*dt)correction=correction/correctionLen*aMax*dt;
62
63        //std::cout << angleRad(correction,movement) << "\n";
64        Vector movement=view*speed+correction;
65
66        float movementLen=movement.len();
67        if(movementLen>vMax)movement=movement/movementLen*vMax;
[10266]68
[10249]69        float newSpeed=movement.len();
70        Vector newView=movement.getNormalized();
[10266]71
[10283]72        /*if((newSpeed<=taskSpeed && speed>=taskSpeed)||(newSpeed>=taskSpeed && speed<=taskSpeed)){
[10249]73                newSpeed=taskSpeed;
74        }else if((newSpeed>speed && speed<taskSpeed) || (newSpeed < speed && speed < taskSpeed)){
75                newSpeed=taskSpeed;
[10283]76        }*/
[10266]77
[10275]78        /*if(angleDeg(view,newView)>viewChangeMax){
[10249]79                std::cout << "alarm\n";
[10275]80        }*/
[10283]81        if(newSpeed<40)newSpeed=40;
82        if(newSpeed>vMax)newSpeed=vMax;
[10275]83
[10249]84        speed=newSpeed;
85        view=newView;
86        position=position+view*speed*dt;
[10244]87
88        //tell orders to swarm-members...
89        for (it= members.begin(); it!= members.end(); it++ ){
[10249]90                it->second->setDestination(position);
91                it->second->setDestinationMovement(view*speed);
[10244]92                it->second->process(dt);
93        }
[10266]94
[10244]95        //check if destination reached
96        if(!taskComplete){
[10249]97                //swarmPosition=this->getPosition();
[10275]98                if((destination-position).len()<10)taskComplete=true;
[10244]99        }
100}
Note: See TracBrowser for help on using the repository browser.