Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10848


Ignore:
Timestamp:
Nov 24, 2015, 1:47:43 PM (8 years ago)
Author:
gania
Message:

still not compilable

Location:
code/branches/campaignHS15/src/orxonox
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc

    r10847 r10848  
    122122        return CommonController::getName (this->getProtect());
    123123    }
    124     std::string CommonController::getName(ControllableEntity* entity)
     124    std::string CommonController::getName(Pawn* entity)
    125125    {
    126126        std::string name = entity->getName();
     
    291291        Vector3 position;
    292292        std::string targetName;
    293         this->actionpoints_.push_back(actionpoint);
     293
    294294        if (static_cast<Actionpoint*> (actionpoint))
    295295        {
    296296            Actionpoint* ap = static_cast<Actionpoint*> (actionpoint);
     297           
    297298            actionName = ap->getActionXML();
    298             targetName = ap->get
     299            targetName = ap->getName();
     300            position = ap->getWorldPosition();
     301
    299302            Action::Value value;
    300303           
    301             if ( valUpper == "FIGHT" )
     304            if ( actionName == "FIGHT" )
    302305            {
    303306                value = Action::FIGHT;
    304307
    305308            }
    306             else if ( valUpper == "FLY" )
     309            else if ( actionName == "FLY" )
    307310            {
    308311                value = Action::FLY;
    309312
    310313            }
    311             else if ( valUpper == "PROTECT" )
     314            else if ( actionName == "PROTECT" )
    312315            {
    313316                value = Action::PROTECT;
    314317
    315318            }
    316             else if ( valUpper == "NONE" )
     319            else if ( actionName == "NONE" )
    317320            {
    318321                value = Action::NONE;
    319322
    320323            }
    321             else if ( valUpper == "FIGHTALL" )
     324            else if ( actionName == "FIGHTALL" )
    322325            {
    323326                value = Action::FIGHTALL;
    324327
    325328            }
    326             else if ( valUpper == "ATTACK" )
     329            else if ( actionName == "ATTACK" )
    327330            {
    328331                value = Action::ATTACK;
     332
    329333
    330334            }
    331335            else
    332336                ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ val + "'." );
    333             this->setAction( value );
    334         }
    335         else
    336         {
    337             actionName = "FLY";
    338         }
     337            //this->setAction( value );
     338            parsedActionpoints_.push_back( std::make_tuple (value, targetName, position) );
     339        }
     340        else
     341        {
     342            parsedActionpoints_.push_back(
     343                std::make_tuple (Action::FLY, "", actionpoint->getWorldPosition()) );
     344        }
     345            this->actionpoints_.push_back(actionpoint);
     346
    339347       
    340348    }
     
    377385        return 0; 
    378386    }
     387    //POST: this starts doing what was asked by the last element of parsedActionpoints_,
     388    //if last element was failed to be parsed, next element will be executed.
     389    void CommonController::executeActionpoint()
     390    {
     391        if (!this->parsedActionpoints_.empty())
     392        {
     393            this->action_ = std::get<0>( this->parsedActionpoints_.back() );
     394
     395            switch ( this->action_ )
     396            {
     397                case Action::FIGHT:
     398                {               
     399                    break;
     400                }
     401                case Action::FLY:
     402                {
     403                    this->setTargetPosition(std::get<2>( this->parsedActionpoints_.back() ));
     404                    if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
     405                    {
     406                        this->nextActionpoint();
     407                        this->executeActionpoint();
     408                    }
     409                    break;
     410                }
     411                case Action::PROTECT:
     412                {
     413                    std::string protectName = std::get<1>( this->parsedActionpoints_.back() );
     414
     415                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
     416                    {
     417                        if (CommonController::getName(*itP) == protectName)
     418                        {
     419                            this->setProtect (static_cast<ControllableEntity*>(*itP));
     420                        }
     421                    }
     422                    if (!this->getProtect())
     423                    {
     424                        this->nextActionpoint();
     425                        this->executeActionpoint();
     426                    }
     427                    break;
     428                }
     429                case Action::NONE:
     430                {
     431                    break;
     432                }
     433                case Action::FIGHTALL:
     434                {
     435                    break;
     436                }
     437                case Action::ATTACK:
     438                {
     439                    std::string targetName = std::get<1>( this->parsedActionpoints_.back() );
     440
     441                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
     442                    {
     443                        if (CommonController::getName(*itP) == targetName)
     444                        {
     445                            this->setTarget (static_cast<ControllableEntity*>(*itP));
     446                        }
     447                    }
     448                    if (!this->getTarget())
     449                    {
     450                        this->nextActionpoint();
     451                        this->executeActionpoint();
     452                    }
     453                    break;
     454                }
     455                default:
     456                    break;
     457            }
     458           
     459
     460        }
     461        else
     462        {
     463            this->setTarget(0);
     464            this->setTargetPosition(this->getControllableEntity()->getWorldPosition());
     465            this->action_ = Action::NONE;
     466        }
     467    }
     468    void CommonController::nextActionpoint()
     469    {
     470        if (!this->parsedActionpoints_.empty())
     471        {
     472            this->parsedActionpoints_.pop_back();
     473        }
     474        this->setAction(Action::NONE);
     475    }
     476
    379477    void CommonController::maneuver()
    380478    {
  • code/branches/campaignHS15/src/orxonox/controllers/CommonController.h

    r10847 r10848  
    138138                static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt);
    139139                static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ;
    140                 static std::string getName( ControllableEntity* entity ) ;
     140                static std::string getName( Pawn* entity ) ;
    141141
    142142                float squaredDistanceToTarget() const;
     
    207207                Rank::Value rank_;
    208208                std::string protectName_;
     209                std::string targetName_;
    209210                Action::Value action_;
    210211                int attackRange_;
  • code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc

    r10847 r10848  
    9797            {
    9898                ControllableEntity* newTarget = this->closestTarget();
    99                 if (newTarget && CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
    100                 {
    101                     this->backupAction();
    102                     this->setAction (Action::FIGHT, newTarget);
    103                 }
    104             }
    105         }
     99                if ( newTarget &&
     100                    CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_ )
     101                {
     102                    // this->backupAction();
     103                    // this->setAction (Action::FIGHT, newTarget);
     104                    this->parsedActionpoints_.push_back(
     105                        std::make_tuple (Action::FIGHT, CommonController::getName(newTarget), Vector3::ZERO) );
     106                }
     107            }
     108        }
     109
    106110        //action is NONE whenever ships finishes current action,
    107111        //if it was fighting before because enemies were close, resume what it was doing
     
    109113        if (this->action_ == Action::NONE)
    110114        {
    111             if (this->bBackuped_)
    112             {
    113                 this->restoreAction();
    114             } else if (!this->actionpoints_.empty())
    115             {
    116                 this->popAction();
    117             }
    118         }
     115
     116        }
     117
     118        this->executeActionpoint();
     119
     120        //this->action_ is what I am actually executing, this->target_ is what I am
     121        //actually attacking, etc.
     122
     123        //after action is finished, .pop_back() is to be called.
    119124        if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL)
    120125        {
     
    122127            {
    123128                //----find a target----
     129                ControllableEntity* newTarget = this->closestTarget();
    124130                if (this->action_ == Action::FIGHT)
    125131                {
    126                     ControllableEntity* newTarget = this->closestTarget();
    127132                    if (newTarget && CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
    128133                    {
     
    131136                    else
    132137                    {
    133                         this->setAction (Action::NONE);
     138                        this->nextActionpoint();
     139                        return;
    134140                    }
    135141                }
    136142                else if (this->action_ == Action::FIGHTALL)
    137143                {
    138                     this->setClosestTarget();                     
     144                    if (newTarget)
     145                    {
     146                        this->setAction (Action::FIGHTALL, newTarget);
     147                    }
     148                    else
     149                    {
     150                        this->nextActionpoint();
     151                        return;
     152                    }
    139153                }
    140154
     
    146160                if (diffVector.length() > this->attackRange_)
    147161                {
    148                     this->setTargetPositionOfWingman();
    149                     this->setTargetPositionOfFollower();                   
     162                    if (this->action_ == Action::FIGHT)
     163                    {
     164                        this->nextActionpoint();
     165                        return;
     166                    }
     167                    else
     168                    {
     169                        this->setTargetPositionOfWingman();
     170                        this->setTargetPositionOfFollower();                   
     171                    }
     172
    150173                }
    151174                else
     
    154177                    if (this->myWingman_)
    155178                    {
    156                         this->myWingman_->setAction (Action::FIGHT, this->target_);     
     179                        this->myWingman_->setAction (this->action_, this->target_);     
    157180                    }
    158181                    if (this->myFollower_)
    159182                    {
    160                         this->myFollower_->setAction (Action::FIGHT);                                   
     183                        this->myFollower_->setAction (this->action_);                                   
    161184                    }
    162185
     
    180203        else if (this->action_ == Action::PROTECT)
    181204        {
    182             if (!this->getProtect())
    183             {
    184                 for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
    185                 {
    186                     if ((*itP)->getName() == this->protectName_)
    187                     {
    188                         this->setProtect (static_cast<ControllableEntity*>(*itP));
    189                     }
    190                 }
    191                 if (!this->getProtect())
    192                 {
    193                     this->setAction (Action::NONE);
    194                 }
    195             }
    196             else
    197             {
    198                /* if (this->myWingman_)
    199                     this->myWingman_->setAction (Action::PROTECT, this->getProtect());
    200                 if (this->myFollower_)
    201                     this->myFollower_->setAction (Action::PROTECT, this->getProtect());
    202                 */
    203                 Vector3* targetRelativePosition;
    204                    
    205                 targetRelativePosition = new Vector3 (0, 0, 500); 
    206      
    207                 Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) +
    208                     (this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));
    209                 this->setTargetPosition(targetAbsolutePosition);
     205           /* if (this->myWingman_)
     206                this->myWingman_->setAction (Action::PROTECT, this->getProtect());
     207            if (this->myFollower_)
     208                this->myFollower_->setAction (Action::PROTECT, this->getProtect());
     209            */
     210            Vector3* targetRelativePosition;
    210211               
    211                 this->setTargetPositionOfWingman();
    212                 this->setTargetPositionOfFollower();
    213             }           
    214 
     212            targetRelativePosition = new Vector3 (0, 0, 500); 
     213 
     214            Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) +
     215                (this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));
     216            this->setTargetPosition(targetAbsolutePosition);
     217           
     218            this->setTargetPositionOfWingman();
     219            this->setTargetPositionOfFollower();
     220        }
     221        else if (this->action_ == Action::ATTACK)
     222        {   
     223            if (this->hasTarget())
     224            {
     225                //----fly in formation if far enough----
     226                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
     227                if (diffVector.length() > this->attackRange_)
     228                {
     229                    this->setTargetPositionOfWingman();
     230                    this->setTargetPositionOfFollower();                   
     231                }
     232                else
     233                {
     234                    //----wingmans shall support the fire of their leaders----
     235                    if (this->myWingman_)
     236                    {
     237                        this->myWingman_->setAction (this->action_, this->target_);     
     238                    }
     239                    if (this->myFollower_)
     240                    {
     241                        this->myFollower_->setAction (this->action_);                                   
     242                    }
     243
     244                }
     245               
     246            }
     247            if (this->hasTarget())
     248            {
     249                //----choose where to go----
     250                this->maneuver();
     251                //----fire if you can----
     252                this->bShooting_ = this->canFire();               
     253            }
    215254        }
    216255
  • code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.h

    r10847 r10848  
    9191                void setEnemy( ControllableEntity* enemy);
    9292                ControllableEntity* getEnemy();
     93                std::string getName()
     94                {
     95                    if (actionName_ != "")
     96                        return actionName_;
     97                    else if (protectName_ != "")
     98                        return protectName_;
     99                    else if (enemyName_ != "")
     100                        return enemyName_;
     101                    else
     102                        return "";
     103                }
    93104            //----["Waypoints" data]----
    94105                void setTargetPosition(const Vector3& target);
Note: See TracChangeset for help on using the changeset viewer.