Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 25, 2015, 12:07:22 PM (8 years ago)
Author:
gania
Message:

Fixed some bugs, only DivisionController works for now

File:
1 edited

Legend:

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

    r10851 r10854  
    6565        this->squaredaccuracy_ = 10000;
    6666        this->bFirstTick_ = true;
    67         this->tolerance_ = 65;
     67        this->tolerance_ = 50;
    6868        this->action_ = Action::NONE;
    6969        this->stopLookingAtTarget();
     
    7373    CommonController::~CommonController()
    7474    {
    75         for (size_t i = 0; i < this->actionpoints_.size(); ++i)
    76         {
    77             if(this->actionpoints_[i])
    78                 this->actionpoints_[i]->destroy();
    79         }
    80         this->parsedActionpoints_.clear();
    81         this->actionpoints_.clear();
     75       
    8276    }
    8377    void CommonController::tick(float dt)
     
    492486                }
    493487            }
    494             if (distance > 200 || (rotateX > -0.1 && rotateX < 0.1 && rotateY > -0.1 && rotateY < 0.1))
     488            if (distance > this->tolerance_*1.5f || (rotateX > -0.01 && rotateX < 0.01 && rotateY > -0.01 && rotateY < 0.01))
    495489                this->getControllableEntity() ->moveFrontBack( SPEED * dt );
    496490        }
     
    746740        return 0; 
    747741    }
    748     bool CommonController::startAttackingEnemiesThatAreClose()
     742    void CommonController::startAttackingEnemiesThatAreClose()
    749743    {
    750744        if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
     
    761755                    this->parsedActionpoints_.push_back(p);
    762756                    this->executeActionpoint();
    763                     return true;
    764                 }
    765             }
    766         }
    767         return false;
     757                }
     758            }
     759        }
    768760    }
    769761
     
    783775            {
    784776                case Action::FIGHT:
    785                 {               
     777                {
     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));
     788                        }
     789                    }         
    786790                    break;
    787791                }
     
    851855        }
    852856    }
     857    void CommonController::stayNearProtect()
     858    {
     859        Vector3* targetRelativePosition;
     860        targetRelativePosition = new Vector3 (0, 300, 300); 
     861        Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) +
     862            (this->getProtect()->getWorldOrientation()* (*targetRelativePosition)));
     863        this->setTargetPosition(targetAbsolutePosition);
     864    }
    853865    void CommonController::nextActionpoint()
    854866    {
     
    859871        this->setAction(Action::NONE);
    860872    }
     873    void CommonController::action()
     874    {
     875        this->startAttackingEnemiesThatAreClose();
     876        //No action -> pop one from stack
     877        if (this->action_ == Action::NONE)
     878        {
     879            this->executeActionpoint();
     880        }
     881        //Action fightall -> fight till nobody alive
     882        if (this->action_ == Action::FIGHTALL)
     883        {
     884            if (!this->hasTarget())
     885            {
     886                //----find a target----
     887                ControllableEntity* newTarget = this->closestTarget();   
     888                if (newTarget)
     889                {
     890                    this->setAction (Action::FIGHTALL, newTarget);
     891                }
     892                else
     893                {
     894                    this->nextActionpoint();
     895                    return;
     896                }
     897            }
     898            else if (this->hasTarget())
     899            {
     900
     901            }
     902        }
     903        //Action fight -> fight as long as enemies in range
     904        else if (this->action_ == Action::FIGHT)
     905        {
     906            if (!this->hasTarget())
     907            {
     908                //----find a target----
     909                ControllableEntity* newTarget = this->closestTarget();   
     910                if (newTarget &&
     911                        CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
     912                {
     913                    this->setAction (Action::FIGHT, newTarget);
     914                }
     915                else
     916                {
     917                    this->nextActionpoint();
     918                    return;
     919                }
     920            }
     921            else if (this->hasTarget())
     922            {
     923                //----fly in formation if far enough----
     924                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
     925                   
     926                if (diffVector.length() > this->attackRange_)
     927                {
     928                    ControllableEntity* newTarget = this->closestTarget();
     929                   
     930                    if (newTarget &&
     931                        CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
     932                    {
     933                        this->setAction (Action::FIGHT, newTarget);
     934                    }
     935                    else
     936                    {
     937                        this->nextActionpoint();
     938                        return;
     939                    }
     940                }
     941            }
     942        }
     943        else if (this->action_ == Action::FLY)
     944        {
     945            if (this->squaredDistanceToTarget() <= this->squaredaccuracy_)
     946            {
     947                this->nextActionpoint();   
     948                return;
     949            }
     950        }
     951        else if (this->action_ == Action::PROTECT)
     952        {
     953            if (!this->getProtect())
     954            {
     955                this->nextActionpoint();
     956                return;
     957            }
     958            this->stayNearProtect();
     959        }
     960        else if (this->action_ == Action::ATTACK)
     961        {   
     962            if (!this->hasTarget())
     963            {
     964                this->nextActionpoint();
     965                return;
     966            }
     967        }
     968        if (this->hasTarget())
     969        {
     970            //----choose where to go----
     971            this->maneuver();
     972            //----fire if you can----
     973            this->bShooting_ = this->canFire();               
     974        }
     975    }
    861976}
Note: See TracChangeset for help on using the changeset viewer.