Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7832


Ignore:
Timestamp:
Jan 27, 2011, 3:58:04 PM (13 years ago)
Author:
jo
Message:

Now the ai use lensflare if the weapon is on board and if they are close enough to the target. Hardcoded version!

Location:
code/branches/ai/src/orxonox/controllers
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ai/src/orxonox/controllers/AIController.cc

    r7284 r7832  
    220220                    this->moveToTargetPosition();
    221221
    222                 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f))
    223                     this->getControllableEntity()->fire(0);
     222                this->doFire();
    224223            }
    225224
     
    241240        }
    242241
    243          if (this->state_ == FREE)
     242        if (this->state_ == FREE)
    244243        {
    245244            if (this->target_)
     
    253252                this->moveToTargetPosition();
    254253
    255             if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f))
    256                 this->getControllableEntity()->fire(0);
     254            this->doFire();
    257255        }
    258256
  • code/branches/ai/src/orxonox/controllers/ArtificialController.cc

    r7401 r7832  
    8484
    8585        this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this));
     86        this->bSetupWorked = false;
     87        this->numberOfWeapons = 0;
    8688    }
    8789
     
    10161018        return (team1 == team2 && team1 != -1);
    10171019    }
     1020   
     1021    void ArtificialController::doFire()
     1022    {
     1023        if(!bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ...
     1024        {
     1025            this->setupWeapons();
     1026            if(numberOfWeapons>0)
     1027                bSetupWorked=true;
     1028        }
     1029        else if(this->getControllableEntity()&&(numberOfWeapons>0)&&this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f))
     1030        {
     1031            if (this->isCloseAtTarget(140) && this->isLookingAtTarget(math::pi / 20.0f)&&(weapons[1]==1) )
     1032                this->getControllableEntity()->fire(1); //ai uses lens flare if they're close enough to the target
     1033
     1034          //default fire (laser)
     1035          else if ((weapons[0]==0))
     1036               this->getControllableEntity()->fire(0);
     1037        }
     1038    }
     1039    void ArtificialController::setupWeapons()
     1040    {
     1041        if(this->getControllableEntity())
     1042        {
     1043            Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
     1044            if(pawn)
     1045            {
     1046                 for(unsigned int i=0; i<WeaponSystem::MAX_WEAPON_MODES; i++)
     1047                 {
     1048                      if(pawn->getWeaponSet(i)) //main part: find which weapons a pawn can use; hard coded at the moment!
     1049                      {
     1050                          weapons[i]=i;
     1051                          numberOfWeapons++;
     1052                      }
     1053                      else
     1054                          weapons[i]=-1;
     1055                 }
     1056            }
     1057        }
     1058    }
    10181059}
  • code/branches/ai/src/orxonox/controllers/ArtificialController.h

    r7163 r7832  
    3737#include "Controller.h"
    3838#include "controllers/NewHumanController.h"
     39#include "weaponsystem/WeaponSystem.h"
    3940
    4041namespace orxonox
     
    7778            static void passivebehaviour(const bool passive);
    7879            static void formationsize(const int size);
     80           
     81            virtual void doFire();
    7982
    8083        protected:
     
    138141            WeakPtr<Pawn> target_;
    139142            bool bShooting_;
     143           
     144            int numberOfWeapons;
     145            int weapons[WeaponSystem::MAX_WEAPON_MODES];
    140146
    141147        private:
     148            void setupWeapons();
     149            bool bSetupWorked;
    142150    };
    143151}
Note: See TracChangeset for help on using the changeset viewer.