Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 15, 2015, 4:47:35 PM (9 years ago)
Author:
gania
Message:

Finished groundwork: AI fights enemies like I want it to. TODO implement all the functionality of old AI, like Waypoints, XMLPort

File:
1 edited

Legend:

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

    r10789 r10805  
    5555    void SectionController::tick(float dt)
    5656    {
    57         if (!this->isActive())
     57         if (!this->isActive())
    5858            return;
    59        
    60        
    6159        if (this->bHasTargetPosition_)
    6260        {
    6361            this->moveToTargetPosition(dt);
    6462        }
    65         if (this->bShooting_)
    66             doFire();
     63        else if (this->bLookAtTarget_)
     64        {
     65            this->lookAtTarget(dt);
     66        }
     67        if (bShooting_)
     68        {
     69            this->doFire();
     70        }
    6771       
    6872        SUPER(SectionController, tick, dt);
     
    8084            else
    8185            {
    82                
    83             }
    84 
    85         }
    86         setTargetPositionOfWingman();
    87         if (this->target_ && this->myWingman_)
    88             this->myWingman_->setTarget(this->target_);
    89         if (canFire())
    90            this->bShooting_ = true;
     86                for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
     87                {
     88                    if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())
     89                        continue;           
     90
     91                    if (!this->myDivisionLeader_)
     92                    {
     93                        this->setAction(Action::FIGHT, (*itP));
     94                        break;
     95                    }
     96                   
     97                }
     98            }
     99
     100        }
    91101        else
    92             this->bShooting_ = false;
     102        {
     103            if (this->myDivisionLeader_->getAction() == Action::FIGHT)
     104            {
     105                if (this->myDivisionLeader_->hasTarget())
     106                {
     107                    if (this->myDivisionLeader_->hasWingman() && (!this->hasTarget() || this->getTarget() == this->myDivisionLeader_->getTarget()))
     108                    {
     109                        bool foundTarget = false;
     110                        Vector3 divisionTargetPosition = this->myDivisionLeader_->getTarget()->getWorldPosition();
     111                        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
     112                        {
     113                            if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())
     114                                continue;           
     115
     116                            if (((*itP)->getWorldPosition() - divisionTargetPosition).length() < 3000 &&
     117                                ((*itP)->getWorldPosition() - divisionTargetPosition).length() > 1000 &&
     118                                (*itP) != this->myDivisionLeader_->getTarget())
     119                            {
     120                                foundTarget = true;
     121                                this->setAction(Action::FIGHT, (*itP));
     122                                orxout(internal_error) << "Found target" << endl;
     123                                break;
     124                            }
     125                        }
     126                        if (!foundTarget)
     127                        {
     128                            this->setAction(Action::FIGHT, this->myDivisionLeader_->getTarget());
     129                        }
     130
     131                    }
     132                }
     133            }   
     134        }
     135       
     136        if (this->action_ == Action::FIGHT)
     137        {
     138            this->maneuver();
     139            this->bShooting_ = this->canFire();
     140            if (this->target_)
     141            {
     142                if (this->myWingman_)
     143                {
     144                    this->myWingman_->setAction (Action::FIGHT, this->target_);                   
     145                }
     146                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
     147                if (diffVector.length() > 3000)
     148                {
     149                    this->setTargetPositionOfWingman();
     150                }   
     151            }
     152        }
     153        else if (this->action_ == Action::FLY)
     154        {
     155            this->setTargetPositionOfWingman();
     156        }
     157        else if (this->action_ == Action::PROTECT)
     158        {
     159
     160        }
    93161               
    94162
     
    126194        (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman)));
    127195       
    128         myWingman_->setTargetOrientation(orient);
    129         myWingman_->setTargetPosition(targetAbsolutePositionOfWingman);
     196        myWingman_->setAction (Action::FLY, targetAbsolutePositionOfWingman, orient);
    130197       
    131198    }
Note: See TracChangeset for help on using the changeset viewer.