Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

still not compilable

File:
1 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    {
Note: See TracChangeset for help on using the changeset viewer.