Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 1, 2015, 9:10:08 AM (9 years ago)
Author:
gania
Message:

nothing really changed

Location:
code/branches/AI_HS15/src/orxonox/controllers
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/AI_HS15/src/orxonox/controllers/ArtificialController.cc

    r10717 r10737  
    8282    void ArtificialController::changedControllableEntity()
    8383    {
     84        FormationController::changedControllableEntity(); // super
     85
    8486        if (!this->getControllableEntity())
    8587            this->removeFromFormation();
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc

    r10731 r10737  
    2727 */
    2828#include "controllers/CommonController.h"
     29/*
     30#include "weaponsystem/WeaponMode.h"
     31#include "weaponsystem/WeaponPack.h"
     32#include "weaponsystem/Weapon.h"
     33#include "weaponsystem/WeaponSlot.h"
     34#include "weaponsystem/WeaponSlot.h"
     35#include "worldentities/pawns/SpaceShip.h"
     36*/
    2937
    3038namespace orxonox
     
    3745    CommonController::CommonController(Context* context) : Controller(context)
    3846    {
     47        //this->bSetupWorked = false;
    3948
    4049        RegisterObject(CommonController);
     
    170179        }
    171180    }
     181
     182/*
     183    int CommonController::getFiremode(std::string name)
     184    {
     185        for (std::map< std::string, int >::iterator it = this->weaponModes_.begin(); it != this->weaponModes_.end(); ++it)
     186        {
     187            if (it->first == name)
     188                return it->second;
     189        }
     190        return -1;
     191    }
     192    bool CommonController::isCloseAtTarget(float distance) const
     193    {
     194        if (!this->getControllableEntity())
     195            return false;
     196
     197        if (!this->target_)
     198            return (this->getControllableEntity()->getPosition().squaredDistance(this->targetPosition_) < distance*distance);
     199        else
     200            return (this->getControllableEntity()->getPosition().squaredDistance(this->target_->getPosition()) < distance*distance);
     201    }
     202    void CommonController::setupWeapons() //TODO: Make this function generic!! (at the moment is is based on conventions)
     203    {
     204        this->bSetupWorked = false;
     205        if(this->getControllableEntity())
     206        {
     207            Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
     208            if(pawn && pawn->isA(Class(SpaceShip))) //fix for First Person Mode: check for SpaceShip
     209            {
     210                this->weaponModes_.clear(); // reset previous weapon information
     211                WeaponSlot* wSlot = 0;
     212                for(int l=0; (wSlot = pawn->getWeaponSlot(l)) ; l++)
     213                {
     214                    WeaponMode* wMode = 0;
     215                    for(int i=0; (wMode = wSlot->getWeapon()->getWeaponmode(i)) ; i++)
     216                    {
     217                        std::string wName = wMode->getIdentifier()->getName();
     218                        if(this->getFiremode(wName) == -1) //only add a weapon, if it is "new"
     219                            weaponModes_[wName] = wMode->getMode();
     220                    }
     221                }
     222                if(weaponModes_.size())//at least one weapon detected
     223                    this->bSetupWorked = true;
     224            }//pawn->weaponSystem_->getMunition(SubclassIdentifier< Munition > *identifier)->getNumMunition (WeaponMode *user);
     225        }
     226    }
    172227    void CommonController::doFire()
    173228    {
    174          if (this->isLookingAtTarget(math::pi / 20.0f))
    175             this->getControllableEntity()->fire(0); //ai uses lens flare if they're close enough to the target
     229        if(!this->bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ...
     230        {
     231            this->setupWeapons();
     232        }
     233        else if(this->getControllableEntity() &&
     234            weaponModes_.size()&&
     235            this->bShooting_ &&
     236            this->isCloseAtTarget((3)*1000) &&
     237            this->isLookingAtTarget(math::pi / 20.0f))
     238        {
     239            int firemode;
     240            float random = rnd(1);//
     241            if (this->isCloseAtTarget(130) && (firemode = getFiremode("LightningGun")) > -1 )
     242            {//LENSFLARE: short range weapon
     243                this->getControllableEntity()->fire(firemode); //ai uses lens flare if they're close enough to the target
     244            }
     245           
     246            else if ((firemode = getFiremode("HsW01")) > -1 ) //LASER: default weapon
     247                this->getControllableEntity()->fire(firemode);
     248        }
    176249    }
    177250    bool CommonController::isLookingAtTarget(float angle) const
     
    196269        if (pawn)
    197270            pawn->setAimPosition(aimPosition);
    198     }
     271    }*/
    199272   
    200273 
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.h

    r10731 r10737  
    3333#include "controllers/Controller.h"
    3434#include "worldentities/ControllableEntity.h"
    35 #include "worldentities/pawns/Pawn.h"
    36 
     35/*#include "worldentities/pawns/Pawn.h"
     36*/
    3737
    3838namespace orxonox
     
    8181            void moveToPosition(const Vector3& target);
    8282            void moveToTargetPosition();
     83            //enum Mode {ROCKET, ATTACK, MOVE, HOLD};//TODO; implement DEFENCE, MOVING modes
    8384
    84 
     85            //Mode mode_;
    8586            void copyOrientation(const Quaternion& orient);
    8687            void copyTargetOrientation();
    8788
     89          /*  bool isCloseAtTarget(float distance) const;
    8890            void doFire();
    8991            void aimAtTarget();
    9092            bool isLookingAtTarget(float angle) const;
     93
     94
     95            std::map<std::string, int> weaponModes_; //<! Links each "weapon" to it's weaponmode - managed by setupWeapons()
     96            //std::vector<int> projectiles_; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons()
     97            float timeout_; //<! Timeout for rocket usage. (If a rocket misses, a bot should stop using it.)
     98            void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed.
     99            bool bSetupWorked; //<! If false, setupWeapons() is called.
     100            int getFiremode(std::string name);
     101*/
    91102
    92103            bool bHasTargetPosition_;
  • code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc

    r10731 r10737  
    6060        if (this->target_)
    6161        {
    62             this->aimAtTarget();
    63             this->doFire();
     62            //this->aimAtTarget();
     63            //this->doFire();
     64            //this->bShooting_ = true;
    6465        }
    6566     
     
    7677        setTargetPositionOfFollower();
    7778        setTargetPositionOfWingman();
    78 
     79/*
    7980        for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it)
    8081        {
     
    8586                break;
    8687            }
    87         }
     88        }*/
    8889           
    8990     
  • code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc

    r10719 r10737  
    10871087    }
    10881088
     1089    void FormationController::changedControllableEntity()
     1090    {
     1091        Controller::changedControllableEntity(); // super
     1092
     1093        // when changing the controllable entity, ensure that the controller does not use the new entity as target
     1094        if (this->target_ && this->getControllableEntity() == static_cast<ControllableEntity*>(this->target_))
     1095            this->forgetTarget();
     1096    }
    10891097}
  • code/branches/AI_HS15/src/orxonox/controllers/FormationController.h

    r10717 r10737  
    9999      FormationController* getSlave( void ) { return this->slaves_.back(); }
    100100
     101      virtual void changedControllableEntity();
     102
    101103  protected:
    102104      bool formationFlight_;
Note: See TracChangeset for help on using the changeset viewer.