Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 25, 2015, 1:51:10 PM (8 years ago)
Author:
gania
Message:

introduced loops

File:
1 edited

Legend:

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

    r10854 r10855  
    6969        this->stopLookingAtTarget();
    7070        this->attackRange_ = 2500;
     71        this->bInLoop_ = false;
     72        this->bLoop_ = false;
    7173        RegisterObject( CommonController );
    7274    }
     
    159161        Vector3 position;
    160162        std::string targetName;
     163        bool inLoop;
    161164        Point p;
    162165        if (static_cast<Actionpoint*> (actionpoint))
     
    166169            targetName = ap->getName();
    167170            position = ap->getWorldPosition();
     171
     172            if (!this->bInLoop_ && ap->getStartLoop())
     173            {
     174                this->bInLoop_ = true;
     175            }
     176            if (this->bInLoop_ && ap->getEndLoop())
     177            {
     178                this->bInLoop_ = false;
     179            }
     180            inLoop = this->bInLoop_;
    168181
    169182            Action::Value value;
     
    183196            else
    184197                ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ actionName + "'." );
    185             p.action = value; p.name = targetName; p.position = position;
     198            p.action = value; p.name = targetName; p.position = position; p.inLoop = inLoop;
    186199            parsedActionpoints_.push_back(p);
    187200        }
    188201        else
    189202        {
    190             p.action = Action::FLY; p.name = ""; p.position = actionpoint->getWorldPosition();
     203            p.action = Action::FLY; p.name = ""; p.position = actionpoint->getWorldPosition(); p.inLoop = inLoop;
    191204        }
    192205            parsedActionpoints_.push_back(p);
     
    752765                        <= this->attackRange_ )
    753766                {
    754                     Point p = { Action::FIGHT, this->getName(newTarget), Vector3::ZERO };
     767                    Point p = { Action::FIGHT, this->getName(newTarget), Vector3::ZERO, false };
    755768                    this->parsedActionpoints_.push_back(p);
    756769                    this->executeActionpoint();
     
    768781    void CommonController::executeActionpoint()
    769782    {
    770         if (!this->parsedActionpoints_.empty())
    771         {
    772             this->action_ = this->parsedActionpoints_.back().action;
    773 
    774             switch ( this->action_ )
    775             {
    776                 case Action::FIGHT:
     783        if (this->bLoop_)
     784        {
     785            if (!this->loopActionpoints_.empty())
     786            {
     787                this->action_ = this->loopActionpoints_.back().action;
     788                switch ( this->action_ )
    777789                {
    778                     std::string targetName = this->parsedActionpoints_.back().name;
    779                     if (targetName == "")
    780                     {
    781                         break;
    782                     }
    783                     for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
    784                     {
    785                         if (CommonController::getName(*itP) == targetName)
    786                         {
    787                             this->setTarget (static_cast<ControllableEntity*>(*itP));
     790                    case Action::FIGHT:
     791                    {
     792                        std::string targetName = this->loopActionpoints_.back().name;
     793                        if (targetName == "")
     794                        {
     795                            break;
    788796                        }
    789                     }         
    790                     break;
     797                        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
     798                        {
     799                            if (CommonController::getName(*itP) == targetName)
     800                            {
     801                                this->setTarget (static_cast<ControllableEntity*>(*itP));
     802                            }
     803                        }         
     804                        break;
     805                    }
     806                    case Action::FLY:
     807                    {
     808                        this->setTargetPosition( this->loopActionpoints_.back().position );
     809                        if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
     810                        {
     811                            this->nextActionpoint();
     812                            this->executeActionpoint();
     813                        }
     814                        break;
     815                    }
     816                    case Action::PROTECT:
     817                    {
     818                        std::string protectName = this->loopActionpoints_.back().name;
     819
     820                        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
     821                        {
     822                            if (CommonController::getName(*itP) == protectName)
     823                            {
     824                                this->setProtect (static_cast<ControllableEntity*>(*itP));
     825                            }
     826                        }
     827                        if (!this->getProtect())
     828                        {
     829                            this->nextActionpoint();
     830                            this->executeActionpoint();
     831                        }
     832                        break;
     833                    }
     834                    case Action::NONE:
     835                    {
     836                        break;
     837                    }
     838                    case Action::FIGHTALL:
     839                    {
     840                        break;
     841                    }
     842                    case Action::ATTACK:
     843                    {
     844                        std::string targetName = this->loopActionpoints_.back().name;
     845
     846                        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
     847                        {
     848                            if (CommonController::getName(*itP) == targetName)
     849                            {
     850                                this->setTarget (static_cast<ControllableEntity*>(*itP));
     851                            }
     852                        }
     853                        if (!this->hasTarget())
     854                        {
     855                            this->nextActionpoint();
     856                            this->executeActionpoint();
     857                        }
     858                        break;
     859                    }
     860                    default:
     861                        break;
    791862                }
    792                 case Action::FLY:
     863            }
     864            else
     865            {
     866                this->bLoop_ = false;
     867            }
     868        }
     869        else
     870        {
     871            if (!this->parsedActionpoints_.empty())
     872            {
     873                if (this->parsedActionpoints_.back().inLoop)
    793874                {
    794                     this->setTargetPosition( this->parsedActionpoints_.back().position );
    795                     if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
    796                     {
    797                         this->nextActionpoint();
    798                         this->executeActionpoint();
    799                     }
    800                     break;
     875                    //MOVES all points that are in loop to a loop vector
     876                    this->fillLoop();
     877                    this->bLoop_ = true;
     878                    executeActionpoint();
     879                    return;
    801880                }
    802                 case Action::PROTECT:
     881                this->action_ = this->parsedActionpoints_.back().action;
     882                switch ( this->action_ )
    803883                {
    804                     std::string protectName = this->parsedActionpoints_.back().name;
    805 
    806                     for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
    807                     {
    808                         if (CommonController::getName(*itP) == protectName)
    809                         {
    810                             this->setProtect (static_cast<ControllableEntity*>(*itP));
     884                    case Action::FIGHT:
     885                    {
     886                        std::string targetName = this->parsedActionpoints_.back().name;
     887                        if (targetName == "")
     888                        {
     889                            break;
    811890                        }
    812                     }
    813                     if (!this->getProtect())
    814                     {
    815                         this->nextActionpoint();
    816                         this->executeActionpoint();
    817                     }
    818                     break;
     891                        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
     892                        {
     893                            if (CommonController::getName(*itP) == targetName)
     894                            {
     895                                this->setTarget (static_cast<ControllableEntity*>(*itP));
     896                            }
     897                        }         
     898                        break;
     899                    }
     900                    case Action::FLY:
     901                    {
     902                        this->setTargetPosition( this->parsedActionpoints_.back().position );
     903                        if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
     904                        {
     905                            this->nextActionpoint();
     906                            this->executeActionpoint();
     907                        }
     908                        break;
     909                    }
     910                    case Action::PROTECT:
     911                    {
     912                        std::string protectName = this->parsedActionpoints_.back().name;
     913
     914                        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
     915                        {
     916                            if (CommonController::getName(*itP) == protectName)
     917                            {
     918                                this->setProtect (static_cast<ControllableEntity*>(*itP));
     919                            }
     920                        }
     921                        if (!this->getProtect())
     922                        {
     923                            this->nextActionpoint();
     924                            this->executeActionpoint();
     925                        }
     926                        break;
     927                    }
     928                    case Action::NONE:
     929                    {
     930                        break;
     931                    }
     932                    case Action::FIGHTALL:
     933                    {
     934                        break;
     935                    }
     936                    case Action::ATTACK:
     937                    {
     938                        std::string targetName = this->parsedActionpoints_.back().name;
     939
     940                        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
     941                        {
     942                            if (CommonController::getName(*itP) == targetName)
     943                            {
     944                                this->setTarget (static_cast<ControllableEntity*>(*itP));
     945                            }
     946                        }
     947                        if (!this->hasTarget())
     948                        {
     949                            this->nextActionpoint();
     950                            this->executeActionpoint();
     951                        }
     952                        break;
     953                    }
     954                    default:
     955                        break;
    819956                }
    820                 case Action::NONE:
    821                 {
    822                     break;
    823                 }
    824                 case Action::FIGHTALL:
    825                 {
    826                     break;
    827                 }
    828                 case Action::ATTACK:
    829                 {
    830                     std::string targetName = this->parsedActionpoints_.back().name;
    831 
    832                     for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
    833                     {
    834                         if (CommonController::getName(*itP) == targetName)
    835                         {
    836                             this->setTarget (static_cast<ControllableEntity*>(*itP));
    837                         }
    838                     }
    839                     if (!this->hasTarget())
    840                     {
    841                         this->nextActionpoint();
    842                         this->executeActionpoint();
    843                     }
    844                     break;
    845                 }
    846                 default:
    847                     break;
    848             }
    849         }
    850         else
    851         {
    852             this->setTarget(0);
    853             this->setTargetPosition(this->getControllableEntity()->getWorldPosition());
    854             this->action_ = Action::NONE;
    855         }
     957            }
     958            else
     959            {
     960                this->setTarget(0);
     961                this->setTargetPosition(this->getControllableEntity()->getWorldPosition());
     962                this->action_ = Action::NONE;
     963            }
     964        }
     965
    856966    }
    857967    void CommonController::stayNearProtect()
     
    865975    void CommonController::nextActionpoint()
    866976    {
    867         if (!this->parsedActionpoints_.empty())
    868         {
    869             this->parsedActionpoints_.pop_back();
     977        if (this->bLoop_)
     978        {
     979            if (!this->loopActionpoints_.empty())
     980            {
     981                this->moveBackToTop();
     982            }
     983        }
     984        else
     985        {
     986            if (!this->parsedActionpoints_.empty())
     987            {
     988                this->parsedActionpoints_.pop_back();
     989            }           
    870990        }
    871991        this->setAction(Action::NONE);
     992    }
     993    void CommonController::moveBackToTop()
     994    {
     995        Point temp = loopActionpoints_.back();
     996        loopActionpoints_.pop_back();
     997        std::reverse (loopActionpoints_.begin(), loopActionpoints_.end());
     998        loopActionpoints_.push_back(temp);
     999        std::reverse (loopActionpoints_.begin(), loopActionpoints_.end());
     1000    }
     1001    void CommonController::fillLoop()
     1002    {
     1003        loopActionpoints_.clear();
     1004        fillLoopReversed();
     1005        std::reverse (loopActionpoints_.begin(), loopActionpoints_.end());
     1006    }
     1007    void CommonController::fillLoopReversed()
     1008    {
     1009        if (parsedActionpoints_.back().inLoop)
     1010        {
     1011            loopActionpoints_.push_back(parsedActionpoints_.back());
     1012            parsedActionpoints_.pop_back();
     1013        }
     1014        if (parsedActionpoints_.back().inLoop)
     1015        {
     1016            fillLoopReversed();
     1017        }
    8721018    }
    8731019    void CommonController::action()
Note: See TracChangeset for help on using the changeset viewer.