Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 19, 2015, 4:01:54 PM (9 years ago)
Author:
gania
Message:

hold position in formation with waypoints

File:
1 edited

Legend:

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

    r10654 r10670  
    8686        }
    8787
     88
    8889        if (this->state_ == SLAVE && this->formationMode_ == ATTACK)
    8990        {
     
    108109            //-------------------------------------------------------
    109110            //collect data for AI behaviour
    110             Vector3 meanOfEnemies;
    111             Vector3 meanOfAllies;
     111            Vector3* meanOfEnemiesPtr = new Vector3(0.0,0.0,0.0);
     112            Vector3* meanOfAlliesPtr  = new Vector3(0.0,0.0,0.0);
     113            Vector3 meanOfAllies = *meanOfAlliesPtr;
     114            Vector3 meanOfEnemies = *meanOfEnemiesPtr;
     115
    112116
    113117            for (ObjectList<AIController>::iterator it = ObjectList<AIController>::begin(); it; ++it)
     
    121125                if (!FormationController::sameTeam(this->getControllableEntity(), it->getControllableEntity(),gt))
    122126                {
    123                     enemies.push_back(*it);
     127                    enemies_.push_back(*it);
    124128                }
    125129                else {
    126                     allies.push_back(*it);
     130                    allies_.push_back(*it);
    127131                }
    128132            }
    129             if (enemies.size() != 0 && allies.size() != 0){
    130             for (std::vector<AIController*>::iterator it = enemies.begin() ; it != enemies.end(); ++it)
    131                 meanOfEnemies += (*it)->getControllableEntity()->getPosition();
    132             meanOfEnemies /= enemies.size();
    133             for (std::vector<AIController*>::iterator it = allies.begin() ; it != allies.end(); ++it)
    134                 meanOfAllies += (*it)->getControllableEntity()->getPosition();
    135             meanOfAllies /= allies.size();
    136             //orxout(internal_error) << "There are " << enemiesCounter << " enemies, mean position is " << meanOfEnemies << endl;
    137             orxout(internal_error) << "Distance is " << (meanOfEnemies-meanOfAllies).length() << endl;
    138             orxout(internal_error) << "mean of Allies is " << meanOfAllies << ", with a size " << allies.size() << endl;
    139             orxout(internal_error) << "mean of Enemies is " << meanOfEnemies << ", with a size " << enemies.size() << endl;
     133            if (enemies_.size() != 0 && allies_.size() != 0){
     134                for (std::vector<WeakPtr<AIController> >::iterator it = enemies_.begin() ; it != enemies_.end(); ++it)
     135                    meanOfEnemies += (*it)->getControllableEntity()->getWorldPosition();
     136
     137                meanOfEnemies /= enemies_.size();
     138
     139                for (std::vector<WeakPtr<AIController> >::iterator it = allies_.begin() ; it != allies_.end(); ++it)
     140                    meanOfAllies += (*it)->getControllableEntity()->getWorldPosition();
     141
     142                meanOfAllies /= allies_.size();
     143
     144                //orxout(internal_error) << "There are " << enemies_Counter << " enemies_, mean position is " << meanOfEnemies << endl;
     145                orxout(internal_error) << "Distance is " << (meanOfEnemies-meanOfAllies).length() << endl;
     146                orxout(internal_error) << "mean of allies_ is " << meanOfAllies << ", with a size " << allies_.size() << endl;
     147                orxout(internal_error) << "mean of enemies_ is " << meanOfEnemies << ", with a size " << enemies_.size() << endl;
    140148            }
    141149            //-------------------------------------------------------
    142150           
    143 
     151            //Decide which formationMode to choose
    144152            this->setFormationMode(ATTACK);
    145            
    146             this->commandSlaves();
     153            this->setDesiredPositionOfSlaves();
     154
     155            //this->commandSlaves();
    147156
    148157            if  (this->specificMasterAction_ != NONE)
     
    184193            }
    185194        }
    186         allies.clear();
    187         enemies.clear();
     195        allies_.clear();
     196        enemies_.clear();
    188197    }
    189198
     
    196205        float maxrand = 100.0f / ACTION_INTERVAL;
    197206        ControllableEntity* controllable = this->getControllableEntity();
     207        if (this->state_ == SLAVE)
     208        {
     209            Vector3 desiredAbsolutePosition = this->myMaster_->getControllableEntity()->getWorldPosition() + this->myMaster_->getControllableEntity()->getWorldOrientation()*desiredRelativePosition_;
     210           
     211            orxonox::WeakPtr<MovableEntity> waypoint = new MovableEntity(this->center_->getContext());
     212            waypoint->setPosition(desiredAbsolutePosition);
     213           
     214            this->addWaypoint(waypoint);
     215        }
    198216        //DOES: Either move to the waypoint or search for a Point of interest
    199217        if (controllable && this->mode_ == DEFAULT)// bot is ready to move to a target
Note: See TracChangeset for help on using the changeset viewer.