Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8723 for code/branches/ai2


Ignore:
Timestamp:
Jul 1, 2011, 12:54:47 AM (13 years ago)
Author:
jo
Message:

'Stable' update. Merging by hand.

Location:
code/branches/ai2/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ai2/src/modules/weapons/projectiles/Rocket.cc

    r8706 r8723  
    5858        this->localAngularVelocity_ = 0;
    5959        this->lifetime_ = 100;
     60        this->bIsRocket=true;
    6061
    6162        if (GameMode::isMaster())
     
    116117        if(this->isInitialized())
    117118        {
     119            this->bIsRocket=false;
    118120            if (GameMode::isMaster())
    119121            {
  • code/branches/ai2/src/orxonox/controllers/ArtificialController.cc

    r8706 r8723  
    4444#include "controllers/NewHumanController.h"
    4545#include "controllers/DroneController.h"
     46#include "weaponsystem/WeaponMode.h"
     47#include "weaponsystem/WeaponPack.h"
     48#include "weaponsystem/Weapon.h"
    4649
    4750namespace orxonox
     
    5255    SetConsoleCommand("ArtificialController", "passivebehaviour", &ArtificialController::passivebehaviour);
    5356    SetConsoleCommand("ArtificialController", "formationsize",    &ArtificialController::formationsize);
     57    SetConsoleCommand("ArtificialController", "setbotlevel",      &ArtificialController::setAllBotLevel);
    5458
    5559    static const unsigned int STANDARD_MAX_FORMATION_SIZE = 7;
     
    8488
    8589        this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this));
     90        this->bSetupWorked = false;
     91        this->numberOfWeapons = 0;
     92        this->botlevel_ = 1.0f;
     93        this->mode_ = DEFAULT;////Vector-implementation: mode_.push_back(DEFAULT);
     94        this->timeout_=0;
    8695    }
    8796
     
    8998    {
    9099        if (this->isInitialized())
    91         {
     100        {//Vector-implementation: mode_.erase(mode_.begin(),mode_.end());
    92101            this->removeFromFormation();
    93102
     
    10201029        return (team1 == team2 && team1 != -1);
    10211030    }
     1031
     1032    /**
     1033        @brief DoFire is called when a bot should shoot and decides which weapon is used and whether the bot shoots at all.
     1034    */
     1035    void ArtificialController::doFire()
     1036    {
     1037        if(!bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ...
     1038        {
     1039            this->setupWeapons();
     1040            if(numberOfWeapons>0)
     1041                bSetupWorked=true;
     1042        }
     1043        else if(this->getControllableEntity()&&(numberOfWeapons>0)&&this->bShooting_ && this->isCloseAtTarget((1 + 2*botlevel_)*1000) && this->isLookingAtTarget(math::pi / 20.0f))
     1044        {
     1045            if (this->isCloseAtTarget(130) &&(weapons[1]==1) )
     1046            {//LENSFLARE: short range weapon     
     1047                this->getControllableEntity()->fire(1); //ai uses lens flare if they're close enough to the target
     1048            }
     1049            else if((weapons[3]==3)&& this->isCloseAtTarget(400) /*&&projectiles[3]*/ )
     1050            {//ROCKET: mid range weapon
     1051                //TODO: Which weapon is the rocket? How many rockets are available?
     1052                this->mode_ = ROCKET;//Vector-implementation: mode_.push_back(ROCKET);
     1053                this->getControllableEntity()->fire(3);//launch rocket
     1054                if(this->getControllableEntity()&&this->target_)//after fire(3) getControllableEntity() refers to the rocket!
     1055                {
     1056                    float speed = this->getControllableEntity()->getVelocity().length() - target_->getVelocity().length();
     1057                    if(!speed) speed = 0.1f;
     1058                    float distance = target_->getPosition().length() - this->getControllableEntity()->getPosition().length();
     1059                    this->timeout_= distance/speed*sgn(speed*distance) + 1.8f;//predicted time of target hit (+ tolerance)
     1060                }
     1061                else
     1062                    this->timeout_ = 4.0f;//TODO: find better default value
     1063               
     1064                this->projectiles[3]-=1;//decrease ammo !!
     1065            }
     1066            else if ((weapons[0]==0))//LASER: default weapon
     1067                this->getControllableEntity()->fire(0);
     1068        }
     1069    }
     1070
     1071    /**
     1072        @brief Information gathering: Which weapons are ready to use?
     1073    */
     1074    void ArtificialController::setupWeapons() //TODO: Make this function generic!! (at the moment is is based on conventions)
     1075    {
     1076        if(this->getControllableEntity())
     1077        {
     1078            Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
     1079            if(pawn)
     1080            {
     1081                for(unsigned int i=0; i<WeaponSystem::MAX_WEAPON_MODES; i++)
     1082                {
     1083                    const std::string wpn = getWeaponname(i, pawn); COUT(0)<<wpn<< std::endl;//Temporary debug info.
     1084                    /*if(wpn=="")
     1085                        weapons[i]=-1;
     1086                    else if(wpn=="LaserMunition")//other munitiontypes are not defined yet :-(
     1087                        weapons[0]=0;
     1088                    else if(wpn=="FusionMunition")
     1089                        weapons[1]=1;
     1090                    else if(wpn=="TargetSeeking Rockets")
     1091                        weapons[2]=2;
     1092                    else if(wpn=="ROCKET")//TODO: insert right munition name
     1093                        weapons[3]=3;
     1094                    */
     1095                    if(pawn->getWeaponSet(i)) //main part: find which weapons a pawn can use; hard coded at the moment!
     1096                    {
     1097                        weapons[i]=i;
     1098                        projectiles[i]=1;//TODO: how to express infinite ammo? how to get data?? getWeaponmode(i)->getMunition()->getNumMunition(WeaponMode* user)
     1099                          numberOfWeapons++;
     1100                    }
     1101                    else
     1102                        weapons[i]=-1;
     1103                }
     1104                 //pawn->weaponSystem_->getMunition(SubclassIdentifier< Munition > *identifier)->getNumMunition (WeaponMode *user);
     1105            }
     1106        }
     1107    }
     1108
     1109    const std::string& ArtificialController::getWeaponname(int i, Pawn* pawn)
     1110    {//is there a way to minimize this long if-return structure, without triggering nullpointer exceptions?
     1111        if(!pawn) return "";
     1112        WeaponPack* wPack = pawn->getWeaponPack(i);
     1113        if(!wPack) return "";
     1114        Weapon* wpn = wPack->getWeapon(i);
     1115        if(!wpn) return "";
     1116        WeaponMode* wMode = wpn->getWeaponmode(i);
     1117        if(!wMode) return "";
     1118        return wMode->getMunitionName();
     1119    }//pawn->getWeaponpack(i)->getWeapon(i)->getWeaponmode(i)->getMunitionName()
     1120
     1121   
     1122    void ArtificialController::setBotLevel(float level)
     1123    {
     1124        if (level < 0.0f)
     1125            this->botlevel_ = 0.0f;
     1126        else if (level > 1.0f)
     1127            this->botlevel_ = 1.0f;
     1128        else
     1129            this->botlevel_ = level;
     1130    }
     1131   
     1132    void ArtificialController::setAllBotLevel(float level)
     1133    {
     1134        for (ObjectList<ArtificialController>::iterator it = ObjectList<ArtificialController>::begin(); it != ObjectList<ArtificialController>::end(); ++it)
     1135            it->setBotLevel(level);
     1136    }
     1137
     1138    void ArtificialController::setPreviousMode()
     1139    {
     1140        this->mode_ = DEFAULT; //Vector-implementation: mode_.pop_back();
     1141    }
     1142   
    10221143}
  • code/branches/ai2/src/orxonox/controllers/ArtificialController.h

    r8706 r8723  
    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();
     82            void setBotLevel(float level=1.0f);
     83            inline float getBotLevel() const
     84                { return this->botlevel_; }
     85            static void setAllBotLevel(float level);
    7986
    8087        protected:
     
    141148            bool bShooting_;
    142149
     150            int numberOfWeapons; //< Used for weapon init function. Displayes number of weapons available for a bot.
     151            int weapons[WeaponSystem::MAX_WEAPON_MODES];
     152            int projectiles[WeaponSystem::MAX_WEAPON_MODES];
     153            float botlevel_; //< Makes the level of a bot configurable.
     154            float timeout_; //< Timeout for rocket usage. (If a rocket misses, a bot should stop using it.)
     155
     156            enum Mode {DEFAULT, ROCKET, DEFENCE, MOVING};//TODO; implement DEFENCE, MOVING modes
     157            Mode mode_; //TODO: replace single value with stack-like implementation: std::vector<Mode> mode_;
     158            void setPreviousMode();
     159
    143160        private:
     161            void setupWeapons();
     162            const std::string& getWeaponname(int i, Pawn* pawn);
     163            bool bSetupWorked;
    144164    };
    145165}
  • code/branches/ai2/src/orxonox/controllers/DroneController.cc

    r7284 r8723  
    103103                    this->isShooting_ = true;
    104104                    this->aimAtTarget();
    105                     this->getDrone()->fire(0);
     105                    if(!this->friendlyFire())
     106                        this->getDrone()->fire(0);
    106107                }
    107108            }
     
    147148            this->destroy();
    148149    }
     150
     151    bool DroneController::friendlyFire()
     152    {   ControllableEntity* droneEntity_ = this->getControllableEntity();
     153        if (!droneEntity_) return false;
     154        if(!owner_) return false;
     155        if(this->bHasTargetPosition_)
     156        {
     157            Vector3 ownerPosition_ = owner_->getPosition();
     158            Vector3 toOwner_ = owner_->getPosition() - droneEntity_->getPosition();
     159            Vector3 toTarget_ = targetPosition_ - droneEntity_->getPosition();
     160            if(toTarget_.length() < toOwner_.length()) return false; //owner is far away = in safty
     161            float angleToOwner = getAngle(droneEntity_->getPosition(), droneEntity_->getOrientation() * WorldEntity::FRONT, ownerPosition_);
     162            float angleToTarget = getAngle(droneEntity_->getPosition(), droneEntity_->getOrientation() * WorldEntity::FRONT, targetPosition_);
     163            float angle = angleToOwner - angleToTarget;//angle between target and owner, observed by the drone
     164            if(std::sin(angle)*toOwner_.length() < 5.0f)//calculate owner's distance to shooting line
     165            return true;
     166        }
     167        return false;//Default return value: Usually there is no friendlyFire
     168    }
    149169}
  • code/branches/ai2/src/orxonox/controllers/DroneController.h

    r7163 r8723  
    6666            virtual void action();
    6767            void ownerDied();
     68            bool friendlyFire(); //< returns true if the owner_ would be hit.
    6869            bool isShooting_;
    6970
  • code/branches/ai2/src/orxonox/worldentities/ControllableEntity.h

    r8706 r8723  
    163163                { return this->target_.get(); }
    164164            void setTargetInternal( uint32_t targetID );
     165            inline bool getRocket() const
     166                { return this-> bIsRocket; }
    165167
    166168        protected:
     
    181183
    182184            Ogre::SceneNode* cameraPositionRootNode_;
     185            bool bIsRocket; //Workaround to see, if the controllable entity is a Rocket.
    183186
    184187        private:
Note: See TracChangeset for help on using the changeset viewer.