Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10071 in orxonox.OLD for branches/ai


Ignore:
Timestamp:
Dec 13, 2006, 6:59:23 PM (18 years ago)
Author:
tfahrni
Message:

made some ai changes..

Location:
branches/ai/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/ai/src/ai/ai_team_member.cc

    r10045 r10071  
    3434        for(int i=0; i < moduleCount; i++ )
    3535        {
    36         std::cout << "Processing AIModule " << i << " (" << moduleCount << ")\n";
     36        //std::cout << "Processing AIModule " << i << " (" << moduleCount << ")\n";
    3737        modules.at(i)->process();
    3838        }
     
    4848        int teamNumber=aiEngine->newTeam();
    4949        aiEngine->getTeam(teamNumber)->addMember(this);
     50
    5051        MovementModule* nMod=new MovementModule;
    51         nMod->process();
    52         modules.push_back(nMod);
    53         modules.at(0)->process();
     52        addModule(nMod);
     53        //nMod->testModule=nMod;
    5454}
    5555
  • branches/ai/src/ai/movement_module.cc

    r10045 r10071  
    1919#include "state.h"
    2020#include "debug.h"
     21#include "player.h"
     22#include "playable.h"
     23#include "aabb.h"
     24#include "npcs/npc_test.h"
     25
     26#include "shell_command.h"
     27/*SHELL_COMMAND(model, WorldEntity, loadModel)
     28->describe("sets the Model of the WorldEntity")
     29->defaultValues("models/ships/fighter.obj", 1.0f);*/
     30
    2131
    2232//class AIEngine;
     
    3040
    3141
    32 void MovementModule::process()
     42float MovementModule::getSize(WorldEntity* object)
    3343{
    34         //float dt=AIEngine::getInstance()->dtS;
    35         std::cout << "///////////////////Processing Movement Module/////////////////////\n";
     44        AABB* aabb = object->getModelAABB();
     45        Vector a = aabb->getAxisX();
     46        Vector b = aabb->getAxisY();
     47        Vector c = aabb->getAxisZ();
    3648
    37         //How does the Module know the AITeamMember it belongs to??
    38         //partialy solved...
    39         /*
    40         Vector absPosition = owner->getAbsCoor();
     49        float da=a.len();
     50        float db=b.len();
     51        float dc=c.len();
     52        float size;
    4153
    42         PRINTF(0)(" npc abs coor: %f, %f, %f\n", absPosition.x, absPosition.y, absPosition.z);
     54        if(da>db){
     55                size=(dc>da)?dc:da;
     56        }else{
     57                size=(dc>db)?dc:db;
     58        }
    4359
    44         //Player* pl = State::getPlayer();
    45         /*Vector playerAbsPos = pl->getPlayable()->getAbsCoor();
    46 
    47         //PRINTF(0)(" player abs coor: %f, %f, %f\n", playerAbsPos.x, playerAbsPos.y, playerAbsPos.z);
    48 
    49 
    50   // intelligent reaction
    51 
    52         Vector distanceVector = playerAbsPos - absPosition;
    53         distanceVector.normalize();
    54 
    55         float speed = 10.0f;
    56 
    57         owner->shiftCoor( distanceVector * speed * dt);*/
     60        return size;
    5861}
    5962
    6063
     64
     65
     66void MovementModule::process()
     67{
     68        float dt=AIEngine::getInstance()->dtS;
     69        if( owner == NULL) return;
     70        Vector myAbsPos = owner->getAbsCoor();
     71
     72        //PRINTF(0)(" NPC abs coor: %f, %f, %f\n", myAbsPos.x, myAbsPos.y, myAbsPos.z);
     73
     74        Player* pl = State::getPlayer();
     75        if( pl == NULL) return;
     76        Vector playerAbsPos = pl->getPlayable()->getAbsCoor();
     77
     78        //PRINTF(0)(" Player abs coor: %f, %f, %f\n", playerAbsPos.x, playerAbsPos.y, playerAbsPos.z);
     79
     80        ////////////
     81
     82        float a=50.0f;
     83        float keepDist= this->getSize(owner);//+ this->getSize(pl->getPlayable());
     84        std::cout << "Distance: " << keepDist << "\n";
     85
     86
     87        Vector vectorToPlayer = playerAbsPos - myAbsPos;
     88        float dist=vectorToPlayer.len();
     89        Vector nVectorToPlayer=vectorToPlayer/dist*(dist-keepDist);
     90
     91
     92
     93
     94
     95        // std::vector<Vector> collisonCorrection;
     96        // get all npcs
     97
     98        Vector tempNPCpos;
     99        Vector tempCorrectionVect;
     100        Vector antiCollision;
     101
     102        for (ObjectList<NPC2>::const_iterator it = NPC2::objectList().begin();
     103                         it != NPC2::objectList().end();
     104                         ++it)
     105        {
     106                if(*it==owner)continue;
     107                tempNPCpos=(*it)->getAbsCoor();
     108                tempCorrectionVect = myAbsPos-tempNPCpos;
     109                tempCorrectionVect=tempCorrectionVect*1/(tempCorrectionVect.len());
     110                //PRINTF(0)("class: %s\n", (*it)->getCName());
     111                antiCollision=antiCollision+tempCorrectionVect;
     112        }
     113
     114
     115
     116        Vector correction=antiCollision+nVectorToPlayer-v;
     117        //Vector nCorrection=
     118        correction.y=0;
     119        float correctionLen=correction.len();
     120        if(correctionLen>a*dt)correction=correction/correctionLen*a*dt;
     121        v+=correction;
     122
     123
     124        //Move NPC...
     125        owner->shiftCoor(v*dt);
     126
     127        //Rotate NPC
     128        Vector view = v+correction;
     129        //if(vectorToPlayer.dot(view)<0){
     130                //view = v.cross( Vector(0,1,0) ).getNormalized();
     131        //}else{
     132                view = v.cross( Vector(0,-1,0) ).getNormalized();
     133        //}
     134        //if(dist<keepDist)view=view*-1;
     135        owner->setAbsDir( Quaternion( view, Vector(0,1,0)));
     136        //owner->setAbsDirSoft( Quaternion( view, Vector(0,1,0)),1.5);
     137}
     138
     139
  • branches/ai/src/ai/movement_module.h

    r10045 r10071  
    44
    55#include "ai_module.h"
     6#include "player.h"
     7#include "playable.h"
    68
    79class MovementModule : public AIModule{
     
    1113   virtual void process();
    1214 private:
    13         //AITeamMember* owner;
     15         Vector v;
     16         float getSize(WorldEntity* object);
    1417};
    1518
  • branches/ai/src/world_entities/npcs/npc_test.cc

    r10045 r10071  
    6161{
    6262  // animating the md2 model
    63   if( likely(this->getModel(0) != NULL))
     63        if( likely(this->getModel(0) != NULL) && this->getModel(0)->isA(MD2Model::staticClassID()))
    6464    ((MD2Model*)this->getModel(0))->tick(dt);
    6565}
Note: See TracChangeset for help on using the changeset viewer.