Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6850


Ignore:
Timestamp:
May 3, 2010, 6:41:43 PM (14 years ago)
Author:
solex
Message:

master/slave interaction of bots now correct - getting closer to formation flight

Location:
code/branches/ai
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ai/data/levels/templates/spaceship_pirate.oxt

    r5781 r6850  
    6969   accelerationupdown    =  125
    7070  >
    71     <active>
     71    <EffectContainer condition="not idle">
    7272      <FadingBillboard mainstate=activity active=false scale=0.02 position=" 1.3, -4, -15" colour="1.0, 0.65, 0.2, 1.0" material="Examples/FlareZwei" turnontime=0.5 turnofftime=0.5 />
    7373      <FadingBillboard mainstate=activity active=false scale=0.02 position=" 0, -4, -15" colour="1.0, 0.65, 0.2, 1.0" material="Examples/FlareZwei" turnontime=0.5 turnofftime=0.5 />
    7474      <FadingBillboard mainstate=activity active=false scale=0.02 position="-1.3, -4, -15" colour="1.0, 0.65, 0.2, 1.0" material="Examples/FlareZwei" turnontime=0.5 turnofftime=0.5 />
    75     </active>
    76     <forward>
     75    </EffectContainer>
     76    <EffectContainer condition="normal or boost">
    7777      <Backlight mainstate=activity active=false scale=0.4 name=bltest position=" 13, -4,  9.5" colour="1.0, 0.65, 0.2, 1.0" width=8 length=800 lifetime=1 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" />
    7878      <Backlight mainstate=activity active=false scale=0.4 name=bltest position="-13, -4,  9.5" colour="1.0, 0.65, 0.2, 1.0" width=8 length=800 lifetime=1 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" />
    79     </forward>
    80     <boost>
     79    </EffectContainer>
     80    <EffectContainer condition="boost">
    8181      <Backlight mainstate=activity active=false scale=0.4 name=bltest position="  0,  5, 15.5" colour="1.0, 0.65, 0.2, 1.0" width=16 length=1600 lifetime=2 elements=50 trailmaterial="Trail/backlighttrail" turnontime=1 turnofftime=1 material="Flares/ThrusterFlare1" />
    82     </boost>
    83     <brake>
     82    </EffectContainer>
     83    <EffectContainer condition="brake">
    8484      <FadingBillboard mainstate=activity active=false scale=0.1 position=" 4.4, -5.5, 5" colour="0.8, 0.0, 0.0, 0.3" material="Examples/Flare" turnontime=0.5 turnofftime=0.5 />
    8585      <FadingBillboard mainstate=activity active=false scale=0.1 position="-4.4, -5.5, 5" colour="0.8, 0.0, 0.0, 0.3" material="Examples/Flare" turnontime=0.5 turnofftime=0.5 />
    86     </brake>
     86    </EffectContainer>
    8787  </MultiStateEngine>
    8888</Template>
  • code/branches/ai/src/orxonox/controllers/AIController.cc

    r6795 r6850  
    4949    AIController::~AIController()
    5050    {
    51 COUT(0) << "~AIController 1" << std::endl;
    52         if (this->state_ == MASTER) setNewMasterWithinFormation();
    53 COUT(0) << "~AIController 2" << std::endl;
    54         if (this->state_ == SLAVE) unregisterSlave();
    55 COUT(0) << "~AIController 3" << std::endl;
    56         this->slaves_.clear();
    57 COUT(0) << "~AIController 4" << std::endl;
    5851    }
    5952
     
    6356        float maxrand = 100.0f / ACTION_INTERVAL;
    6457
    65         if (this->state_ == FREE)//FREE
    66         {
    67 
    68             //this->state_ = MASTER;
    69             // search master
    70             //random = rnd(maxrand);
    71             //if (random < 101 && (!this->target_))
     58        if (this->state_ == FREE)
     59        {
     60
     61
     62            // return to Master after being forced free
     63            if (this->freedomCount_ == 1)   
     64            {
     65                this->state_ = SLAVE;
     66                this->freedomCount_ = 0;
     67            }
     68
     69            random = rnd(maxrand);
     70            if (random < 90 && (((!this->target_) || (random < 50 && this->target_)) && !this->forcedFree()))
    7271                this->searchNewMaster();
    7372
    74         }
    75 
    76         if (this->state_ == SLAVE)//SLAVE
    77         {
    78                // this->bShooting_ = true;
    79         }
    80 
    81         if (this->state_ == MASTER)//MASTER
    82         {
    83 
    84             // command slaves
    85             this->commandSlaves();
    86 
    87 
    88             // lose master status (only if less than 4 slaves in formation)
    89             random = rnd(maxrand);
    90             if(random < 5/(this->slaves_.size()+1) && this->slaves_.size() < 5 )
    91                 this->loseMasterState();
    92 
    93             // look out for outher masters if formation is small
    94             if(this->slaves_.size() < 3)
    95                 this->searchNewMaster();
    9673
    9774            // search enemy
     
    125102                this->searchRandomTargetPosition();
    126103
    127             // shoot
    128             /*random = rnd(maxrand);
     104
     105            random = rnd(maxrand);
    129106            if (random < 75 && (this->target_ && !this->bShooting_))
    130107                this->bShooting_ = true;
    131 */
     108
    132109            // stop shooting
    133110            random = rnd(maxrand);
    134111            if (random < 25 && (this->bShooting_))
    135112                this->bShooting_ = false;
    136         }
     113
     114        }
     115
     116        if (this->state_ == SLAVE)
     117        {
     118               // this->bShooting_ = true;
     119        }
     120
     121        if (this->state_ == MASTER)//MASTER
     122        {
     123
     124
     125            this->commandSlaves();
     126
     127
     128            // lose master status (only if less than 4 slaves in formation)
     129            random = rnd(maxrand);
     130            if(random < 15/(this->slaves_.size()+1) && this->slaves_.size() < 5 )
     131                this->loseMasterState();
     132
     133            // look out for outher masters if formation is small
     134            random = rnd(maxrand);
     135            if(this->slaves_.size() < 3 && random < 20)
     136                this->searchNewMaster();
     137
     138            // search enemy
     139            random = rnd(maxrand);
     140            if (random < 15 && (!this->target_))
     141                this->searchNewTarget();
     142
     143            // forget enemy
     144            random = rnd(maxrand);
     145            if (random < 5 && (this->target_))
     146                this->forgetTarget();
     147
     148            // next enemy
     149            random = rnd(maxrand);
     150            if (random < 10 && (this->target_))
     151                this->searchNewTarget();
     152
     153            // fly somewhere
     154            random = rnd(maxrand);
     155            if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
     156                this->searchRandomTargetPosition();
     157
     158
     159            // fly somewhere else
     160            random = rnd(maxrand);
     161            if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
     162                this->searchRandomTargetPosition();
     163
     164            // shoot
     165            random = rnd(maxrand);
     166            if (random < 5 && (this->target_ && !this->bShooting_))
     167            {
     168                this->bShooting_ = true;
     169                this->forceFreeSlaves();
     170            }
     171            // stop shooting
     172            random = rnd(maxrand);
     173            if (random < 25 && (this->bShooting_))
     174                this->bShooting_ = false;
     175        }
     176
    137177    }
    138178
     
    160200                this->moveToTargetPosition();
    161201
    162         //this->getControllableEntity()->fire(0);
    163 
     202        }
     203
     204         if (this->state_ == FREE)
     205        {
     206            if (this->target_)
     207                this->aimAtTarget();
     208
     209            if (this->bHasTargetPosition_)
     210                this->moveToTargetPosition();
     211
     212            if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
     213                this->getControllableEntity()->fire(0);
    164214        }
    165215
  • code/branches/ai/src/orxonox/controllers/ArtificialController.cc

    r6795 r6850  
    4545        this->target_ = 0;
    4646        this->myMaster_ = 0;
    47         //this->slaveNumber_ = -1;
    48         this->team_ = -1;//new
    49         this->state_ = FREE;//new
     47        this->freedomCount_ = 0;
     48        this->team_ = -1;
     49        this->state_ = FREE;
    5050        this->bShooting_ = false;
    5151        this->bHasTargetPosition_ = false;
    5252        this->targetPosition_ = Vector3::ZERO;
    53         //this->slaves_ = new std::list<ArtificialController*>;
    5453
    5554        this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this));
     
    6564
    6665        XMLPortParam(ArtificialController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(0);
     66    }
     67
     68// gets called when Bot dies
     69    void ArtificialController::changedControllableEntity()
     70    {
     71COUT(0) << "~changedControllableEntity 0" << std::endl;
     72        if(!getControllableEntity())
     73        {
     74COUT(0) << "~changedControllableEntity 1" << std::endl;
     75        if (this->state_ == SLAVE) unregisterSlave();
     76COUT(0) << "~changedControllableEntity 2" << std::endl;
     77         if (this->state_ == MASTER) setNewMasterWithinFormation();
     78COUT(0) << "~changedControllableEntity 3" << std::endl;
     79        this->slaves_.clear();
     80COUT(0) << "~changedControllableEntity 4" << std::endl;
     81        this->state_ = FREE;
     82COUT(0) << "~changedControllableEntity 5" << std::endl;
     83        }
    6784    }
    6885
     
    7794        if (this->target_ || distance > 10)
    7895        {
    79             // Multiply with 0.8 to make them a bit slower
    80             this->getControllableEntity()->rotateYaw(-0.8f * sgn(coord.x) * coord.x*coord.x);
    81             this->getControllableEntity()->rotatePitch(0.8f * sgn(coord.y) * coord.y*coord.y);
     96            // Multiply with rotateFactor to make them a bit slower
     97            float rotateFactor;
     98            if(this->state_ == SLAVE) rotateFactor = 1.0f;
     99            if(this->state_ == MASTER) rotateFactor = 0.4f;
     100            else rotateFactor = 0.8f;
     101
     102            this->getControllableEntity()->rotateYaw(-1.0f * rotateFactor * sgn(coord.x) * coord.x*coord.x);
     103            this->getControllableEntity()->rotatePitch(rotateFactor * sgn(coord.y) * coord.y*coord.y);
     104
     105
     106
    82107        }
    83108
    84109        if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
    85             this->getControllableEntity()->moveFrontBack(-0.5f); // They don't brake with full power to give the player a chance
    86         else
    87             this->getControllableEntity()->moveFrontBack(0.8f);
     110        {
     111            if(this->state_ == SLAVE) this->getControllableEntity()->moveFrontBack(-0.8f);
     112            else this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance
     113        } else {
     114            if(this->state_ == SLAVE) this->getControllableEntity()->moveFrontBack(2.5f);
     115            if(this->state_ == MASTER) this->getControllableEntity()->moveFrontBack(0.4f);
     116            else this->getControllableEntity()->moveFrontBack(0.8f);
     117        }
    88118    }
    89119
     
    102132        {
    103133            myMaster_->slaves_.remove(this);
     134COUT(0) << "~unregister slave" << std::endl;
    104135        }
    105136    }
     
    126157                continue;
    127158
    128             ArtificialController *controller = static_cast<ArtificialController*>(it->getController());
    129             if (!controller || controller->getState() != MASTER)
     159            ArtificialController *newMaster = static_cast<ArtificialController*>(it->getController());
     160
     161            if (!newMaster || newMaster->getState() != MASTER)
    130162                continue;
    131163
     
    133165            if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity()) //&& it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) < 1000
    134166            {
    135                 if(controller->slaves_.size() > 9) continue;
    136 
    137                 this->freeAllSlaves();
     167                if(newMaster->slaves_.size() > 6) continue;
     168
     169                //this->freeSlaves();
     170
     171                for(std::list<ArtificialController*>::iterator itSlave = this->slaves_.begin(); itSlave != this->slaves_.end(); itSlave++)
     172                {
     173                    (*itSlave)->myMaster_ = newMaster;
     174                    newMaster->slaves_.push_back(*itSlave);
     175                }
    138176                this->slaves_.clear();
    139177                this->state_ = SLAVE;
    140178
    141                 this->myMaster_ = controller;
    142                 controller->slaves_.push_back(this);
     179                this->myMaster_ = newMaster;
     180                newMaster->slaves_.push_back(this);
    143181
    144182                break;
     
    148186        //hasn't encountered any masters in range? -> become a master
    149187        if (state_!=SLAVE) state_ = MASTER; // keep in mind: what happens when two masters encounter eache other? -> has to be evaluated in the for loop within master mode in AIcontroller...
    150 
     188COUT(0) << "~searcheNewMaster" << std::endl;
    151189    }
    152190
     
    157195            (*it)->setTargetPosition(this->getControllableEntity()->getPosition());
    158196        }
    159 /*
    160         for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
    161         {
    162 
    163             if (!it->getController())
    164                 continue;
    165 
    166             ArtificialController *controller = static_cast<ArtificialController*>(it->getController());
    167             if (!controller || controller->getState() != SLAVE)
    168                 continue;
    169             //controller->setTargetPosition(this->getControllableEntity()->getPosition());
    170             controller->targetPosition_ = this->getControllableEntity()->getPosition();
    171             controller->bHasTargetPosition_ = true;
    172         }
    173 */
    174197    }
    175198
     
    190213        newMaster->state_ = MASTER;
    191214        newMaster->slaves_ = this->slaves_;
    192         //this->slaves_.clear();
     215        this->slaves_.clear();
    193216
    194217        this->state_ = SLAVE;
     
    205228    }
    206229
    207     void ArtificialController::freeAllSlaves()
    208     {
    209 
    210 
     230    void ArtificialController::freeSlaves()
     231    {
    211232        for(std::list<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
    212233        {
    213234            (*it)->state_ = FREE;
    214235        }
    215 /*
    216         for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
    217         {
    218             ArtificialController *controller = static_cast<ArtificialController*>(it->getController());
    219             if (controller && controller->getState() != SLAVE)
    220                 continue;
    221 
    222             controller->state_ = FREE;
    223         }
    224 */
     236        this->slaves_.clear();
     237    }
     238
     239    void ArtificialController::forceFreeSlaves()
     240    {
     241        for(std::list<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
     242        {
     243            (*it)->state_ = FREE;
     244            (*it)->forceFreedom();
     245            (*it)->targetPosition_ = this->targetPosition_;
     246            (*it)->bShooting_ = true;
     247            (*it)->getControllableEntity()->fire(0);
     248        }
    225249    }
    226250
    227251    void ArtificialController::loseMasterState()
    228252    {
    229         this->freeAllSlaves();
     253        this->freeSlaves();
    230254        this->state_ = FREE;
     255    }
     256
     257    void ArtificialController::forceFreedom()
     258    {
     259        this->freedomCount_ = 5;
     260    }
     261
     262    bool ArtificialController::forcedFree()
     263    {
     264        if(this->freedomCount_ > 0)
     265        {
     266            this->freedomCount_--;
     267            return true;
     268        } else return false;
    231269    }
    232270
  • code/branches/ai/src/orxonox/controllers/ArtificialController.h

    r6833 r6850  
    5151            inline int getTeam() const
    5252                { return this->team_; }
    53             //virtual void changedControllableEntity();
     53            virtual void changedControllableEntity();
    5454
    5555
    5656        protected:
     57
     58            int team_;
     59            int freedomCount_;
     60            enum State {SLAVE, MASTER, FREE};
     61            State state_;
     62            std::list<ArtificialController*> slaves_;
     63
    5764            void targetDied();
    5865
    5966            void moveToPosition(const Vector3& target);
     67            //void speedToTargetPosition(const Vector3& target);
    6068            void moveToTargetPosition();
    6169
    62             enum State {SLAVE, MASTER, FREE};
    6370            int getState();
    64             std::list<ArtificialController*> slaves_;
     71
    6572            void unregisterSlave();
    6673            void searchNewMaster();
    6774            void commandSlaves();
    6875            void setNewMasterWithinFormation();
    69             void freeAllSlaves();
     76            void freeSlaves();
     77            void forceFreeSlaves();
    7078            void loseMasterState();
     79            void forceFreedom();
     80            bool forcedFree();
    7181
    7282            ArtificialController *myMaster_;
     
    90100            bool bShooting_;
    91101
    92 
    93             State state_;
    94             int team_;
    95 
    96102        private:
    97103    };
  • code/branches/ai/src/orxonox/controllers/CMakeLists.txt

    r6782 r6850  
    88  WaypointController.cc
    99  WaypointPatrolController.cc
    10   DroneController.cc
     10 
    1111)
  • code/branches/ai/src/orxonox/worldentities/CMakeLists.txt

    r6782 r6850  
    55  MobileEntity.cc
    66  ControllableEntity.cc
    7   Drone.cc
    87  BigExplosion.cc
    98  EffectContainer.cc
Note: See TracChangeset for help on using the changeset viewer.