Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10805


Ignore:
Timestamp:
Nov 15, 2015, 4:47:35 PM (8 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

Location:
code/branches/AI_HS15
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/AI_HS15/data/levels/AITest.oxw

    r10803 r10805  
    11<LevelInfo
    2  name = "AI testing level"
    3  description = "A level with two opposing AI teams"
     2 name = "New AI testing level"
     3 description = "A level with two opposing new AI teams"
    44 tags = "test"
    55 screenshot = "emptylevel.png"
     
    3333    <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
    3434    <SpawnPoint team=0 position="-1000,-1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
    35     <!-->
    36 
     35    >
     36<!--
    3737    <?lua
    3838      for i = 0, 5, 1 do
    3939    ?>
    4040
    41     <StaticEntity position="0,-10000,0" direction="0,-1,0" >
    42      <controller>
    43         <FleetController team=1>
    44         </FleetController>
    45       </controller>
    46     </StaticEntity>
    47     <StaticEntity position="0,10000,0" direction="0,-1,0" >
    48      <controller>
    49         <FleetController team=2>
    50         </FleetController>
    51       </controller>
    52     </StaticEntity>
    53     <SpaceShip position="<?lua print(1600+i*200) ?>,<?lua print(3000-i*500) ?>, -1500 ?>" lookat="0,0,0">
    54       <templates>
    55         <Template link=spaceshipassff />
    56       </templates>
    57       <controller>
    58         <AIController accuracy=10 team=1>
    59         </AIController>
    60       </controller>
    61     </SpaceShip>
    62     <?lua end ?>
    63   </!-->
    64     <SpaceShip position="0,-10000,0" direction="0,-1,0" >
    65      <templates>
    66         <Template link=spaceshipassff />
    67       </templates>
    68      <controller>
    69         <FleetController team=1>
    70         </FleetController>
    71       </controller>
    72     </SpaceShip>
    73     <?lua
    74       for i = 0, 0, 1 do
    75     ?>
    76 
    77    
    78     <SpaceShip position="<?4000 ?>,<?lua print(1500+i*1000) ?>, -1000 ?>" lookat="0,0,0">
    79       <templates>
    80         <Template link=spaceshipassff />
    81       </templates>
    82       <controller>
    83         <DivisionController team=1 formationMode="DIAMOND">
    84         </DivisionController>
    85       </controller>
    86     </SpaceShip>
    87     <!-- <SpaceShip position="<?1000 ?>,<?lua print(1500+i*1000) ?>, -1600 ?>" lookat="0,0,0">
    88       <templates>
    89         <Template link=spaceshipassff />
    90       </templates>
    91       <controller>
    92         <WingmanController team=1>
    93         </WingmanController>
    94       </controller>
    95     </SpaceShip>
    96     <SpaceShip position="<?1000 ?>,<?lua print(1500+i*1000) ?>, -2200 ?>" lookat="0,0,0">
    97       <templates>
    98         <Template link=spaceshipassff />
    99       </templates>
    100       <controller>
    101         <WingmanController team=1>
    102         </WingmanController>
    103       </controller>
    104     </SpaceShip>
    105     <SpaceShip position="<?1000 ?>,<?lua print(1500+i*1000) ?>, -2800 ?>" lookat="0,0,0">
    106       <templates>
    107         <Template link=spaceshipassff />
    108       </templates>
    109       <controller>
    110         <SectionController team=1>
    111         </SectionController>
    112       </controller>
    113     </SpaceShip> -->
    114     <?lua end ?>
    115    <!--  <SpaceShip position="4000, 1500, -1300 ?>" lookat="0,0,0">
    116       <templates>
    117         <Template link=spaceshipassff />
    118       </templates>
    119       <controller>
    120         <WingmanController team=2>
    121         </WingmanController>
    122       </controller>
    123     </SpaceShip> -->
    124 <!--
    125     <?lua
    126       for i = 0, 0, 1 do
    127     ?>
    128 
    129     <StaticEntity position="1000,-10000,0" direction="0,-1,0" >
    130      <controller>
    131         <FleetController team=2>
    132         </FleetController>
    133       </controller>
    134     </StaticEntity>
    135     <SpaceShip position="<?50000 ?>,<?lua print(1500+i*1000) ?>, -1000 ?>" lookat="0,0,0">
    136       <templates>
    137         <Template link=spaceshipassff />
    138       </templates>
    139       <controller>
    140         <DivisionController team=2>
    141         </DivisionController>
    142       </controller>
    143     </SpaceShip>
    144     <SpaceShip position="<?50000 ?>,<?lua print(1500+i*1000) ?>, -1600 ?>" lookat="0,0,0">
    145       <templates>
    146         <Template link=spaceshipassff />
    147       </templates>
    148       <controller>
    149         <WingmanController team=2>
    150         </WingmanController>
    151       </controller>
    152     </SpaceShip>
    153     <SpaceShip position="<?50000 ?>,<?lua print(1500+i*1000) ?>, -2200 ?>" lookat="0,0,0">
    154       <templates>
    155         <Template link=spaceshipassff />
    156       </templates>
    157       <controller>
    158         <WingmanController team=2>
    159         </WingmanController>
    160       </controller>
    161     </SpaceShip>
    162     <SpaceShip position="<?50000 ?>,<?lua print(1500+i*1000) ?>, -2800 ?>" lookat="0,0,0">
    163       <templates>
    164         <Template link=spaceshipassff />
    165       </templates>
    166       <controller>
    167         <SectionController team=2>
    168         </SectionController>
    169       </controller>
    170     </SpaceShip>
    171     <?lua end ?> -->
    172 
    173 <!--
    174 
    175     <StaticEntity position = "-1000, -1000, -1000">
    176  
    177       <controller>
    178         <FleetController accuracy=10 team=1 >
    179         </FleetController>
    180       </controller>
    181     </StaticEntity>
    182    
    183     <SpaceShip position="1000, 1000, -1300 ?>" lookat="0,0,0">
    184       <templates>
    185         <Template link=spaceshipassff />
    186       </templates>
    187       <controller>
    188         <DivisionController team=1>
    189         </DivisionController>
    190       </controller>
    191     </SpaceShip>
    192     <SpaceShip position="1000, 1500, -1300 ?>" lookat="0,0,0">
    193       <templates>
    194         <Template link=spaceshipassff />
    195       </templates>
    196       <controller>
    197         <WingmanController team=1>
    198         </WingmanController>
    199       </controller>
    200     </SpaceShip>
    201     <SpaceShip position="1000, 1500, -1700 ?>" lookat="0,0,0">
    202       <templates>
    203         <Template link=spaceshipassff />
    204       </templates>
    205       <controller>
    206         <WingmanController team=1>
    207         </WingmanController>
    208       </controller>
    209     </SpaceShip>
    210     <SpaceShip position="1000, 1000, -1900 ?>" lookat="0,0,0">
    211       <templates>
    212         <Template link=spaceshipassff />
    213       </templates>
    214       <controller>
    215         <SectionController team=1>
    216         </SectionController>
    217       </controller>
    218     </SpaceShip>
    219 
    220 
    221       <StaticEntity position = "-1000, -1000, -2000">
    222  
    223       <controller>
    224         <FleetController accuracy=10 team=2 >
    225         </FleetController>
    226       </controller>
    227     </StaticEntity>
    228    
    229     <SpaceShip position="4000, 1000, -1300 ?>" lookat="0,0,0">
    230       <templates>
    231         <Template link=spaceshipassff />
    232       </templates>
    233       <controller>
    234         <DivisionController team=2>
    235         </DivisionController>
    236       </controller>
    237     </SpaceShip>
    238     <SpaceShip position="4000, 1500, -1300 ?>" lookat="0,0,0">
    239       <templates>
    240         <Template link=spaceshipassff />
    241       </templates>
    242       <controller>
    243         <WingmanController team=2>
    244         </WingmanController>
    245       </controller>
    246     </SpaceShip>
    247     <SpaceShip position="4000, 1500, -1700 ?>" lookat="0,0,0">
    248       <templates>
    249         <Template link=spaceshipassff />
    250       </templates>
    251       <controller>
    252         <WingmanController team=2>
    253         </WingmanController>
    254       </controller>
    255     </SpaceShip>
    256     <SpaceShip position="4000, 1000, -1900 ?>" lookat="0,0,0">
    257       <templates>
    258         <Template link=spaceshipassff />
    259       </templates>
    260       <controller>
    261         <SectionController team=2>
    262         </SectionController>
    263       </controller>
    264     </SpaceShip> -->
    265 
    266    
    267     <!-->
    268     <?lua
    269       for i = 0, 5, 1 do
    270     ?>
    271     <SpaceShip position="<?lua print(1600+i*200) ?>,3000, 6000 ?>" lookat="0,0,0">
     41   
     42    <SpaceShip position="<?lua print(-1600+i*200) ?>,<?lua print(-3000-i*500) ?>, -1500 ?>" lookat="0,0,0">
    27243      <templates>
    27344        <Template link=spaceshipassff />
     
    27849      </controller>
    27950    </SpaceShip>
    280     <?lua end ?>
    281     </!-->
     51    <?lua end ?> -->
     52 
     53   
     54    <SpaceShip position="4000, 1500, -1000" lookat="0,0,0">
     55      <templates>
     56        <Template link=spaceshipassff />
     57      </templates>
     58      <controller>
     59        <DivisionController team=1 formationMode="DIAMOND">
     60        </DivisionController>
     61      </controller>
     62    </SpaceShip>
     63    <SpaceShip position="4000 ,1500, -1600 " lookat="0,0,0">
     64      <templates>
     65        <Template link=spaceshipassff />
     66      </templates>
     67      <controller>
     68        <WingmanController team=1>
     69        </WingmanController>
     70      </controller>
     71    </SpaceShip>
     72    <SpaceShip position="4000, 1500, -2200" lookat="0,0,0">
     73      <templates>
     74        <Template link=spaceshipassff />
     75      </templates>
     76      <controller>
     77        <WingmanController team=1>
     78        </WingmanController>
     79      </controller>
     80    </SpaceShip>
     81    <SpaceShip position="6000, 1500, -2800" lookat="0,0,0">
     82      <templates>
     83        <Template link=spaceshipassff />
     84      </templates>
     85      <controller>
     86        <SectionController team=1>
     87        </SectionController>
     88      </controller>
     89    </SpaceShip>
     90    <SpaceShip position="6000, 1500, -1000" lookat="0,0,0">
     91      <templates>
     92        <Template link=spaceshipassff />
     93      </templates>
     94      <controller>
     95        <DivisionController team=1 formationMode="DIAMOND">
     96        </DivisionController>
     97      </controller>
     98    </SpaceShip>
     99    <SpaceShip position="6000 ,1500, -1600 " lookat="0,0,0">
     100      <templates>
     101        <Template link=spaceshipassff />
     102      </templates>
     103      <controller>
     104        <WingmanController team=1>
     105        </WingmanController>
     106      </controller>
     107    </SpaceShip>
     108    <SpaceShip position="6000, 1500, -2200" lookat="0,0,0">
     109      <templates>
     110        <Template link=spaceshipassff />
     111      </templates>
     112      <controller>
     113        <WingmanController team=1>
     114        </WingmanController>
     115      </controller>
     116    </SpaceShip>
     117    <SpaceShip position="6000, 1500, -2800" lookat="0,0,0">
     118      <templates>
     119        <Template link=spaceshipassff />
     120      </templates>
     121      <controller>
     122        <SectionController team=1>
     123        </SectionController>
     124      </controller>
     125    </SpaceShip>
     126 
     127   
     128    <SpaceShip position="-4000, 1500, -5000" lookat="0,0,0">
     129      <templates>
     130        <Template link=spaceshipassff />
     131      </templates>
     132      <controller>
     133        <DivisionController team=2 formationMode="FINGER4">
     134        </DivisionController>
     135      </controller>
     136    </SpaceShip>
     137    <SpaceShip position="-4000 , 1500, -5600" lookat="0,0,0">
     138      <templates>
     139        <Template link=spaceshipassff />
     140      </templates>
     141      <controller>
     142        <WingmanController team=2>
     143        </WingmanController>
     144      </controller>
     145    </SpaceShip>
     146    <SpaceShip position="-4000, 1500, -6200" lookat="0,0,0">
     147      <templates>
     148        <Template link=spaceshipassff />
     149      </templates>
     150      <controller>
     151        <WingmanController team=2>
     152        </WingmanController>
     153      </controller>
     154    </SpaceShip>
     155    <SpaceShip position="-4000, 1500, -6800 " lookat="0,0,0">
     156      <templates>
     157        <Template link=spaceshipassff />
     158      </templates>
     159      <controller>
     160        <SectionController team=2>
     161        </SectionController>
     162      </controller>
     163    </SpaceShip>
     164
     165       <SpaceShip position="-6000, 1500, -5000" lookat="0,0,0">
     166      <templates>
     167        <Template link=spaceshipassff />
     168      </templates>
     169      <controller>
     170        <DivisionController team=2 formationMode="FINGER4">
     171        </DivisionController>
     172      </controller>
     173    </SpaceShip>
     174    <SpaceShip position="-6000 , 1500, -5600" lookat="0,0,0">
     175      <templates>
     176        <Template link=spaceshipassff />
     177      </templates>
     178      <controller>
     179        <WingmanController team=2>
     180        </WingmanController>
     181      </controller>
     182    </SpaceShip>
     183    <SpaceShip position="-6000, 1500, -6200" lookat="0,0,0">
     184      <templates>
     185        <Template link=spaceshipassff />
     186      </templates>
     187      <controller>
     188        <WingmanController team=2>
     189        </WingmanController>
     190      </controller>
     191    </SpaceShip>
     192    <SpaceShip position="-6000, 1500, -6800 " lookat="0,0,0">
     193      <templates>
     194        <Template link=spaceshipassff />
     195      </templates>
     196      <controller>
     197        <SectionController team=2>
     198        </SectionController>
     199      </controller>
     200    </SpaceShip>
     201
     202
     203   
     204   
    282205
    283206  </Scene>
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc

    r10803 r10805  
    5555        this->executingManeuver_ = false;
    5656        this->executingMoveToPoint_ = false;
     57        this->action_ = Action::FLY;
    5758        this->stopLookingAtTarget();
    5859        this->maneuverType_ = ManeuverType::NONE;
     
    6364    CommonController::~CommonController()
    6465    {
     66        orxout(internal_error) << "I died, my Rank is " << rank_ << endl;
    6567    }
    6668
     
    118120        }
    119121    }
     122    Action::Value CommonController::getAction ()
     123    {
     124        return this->action_;
     125    }
     126
     127    void CommonController::setAction (Action::Value action, ControllableEntity* target)
     128    {
     129        this->action_ = action;
     130        if (action == Action::FIGHT)
     131        {   
     132            if (target)
     133                this->setTarget (target);
     134        }
     135        else if (action == Action::PROTECT)
     136        {
     137        }
     138    }
     139    void CommonController::setAction (Action::Value action, const Vector3& target)
     140    {
     141        this->action_ = action;
     142        if (action == Action::FLY)
     143        {
     144            this->setTargetPosition (target);
     145        }
     146        else if (action == Action::PROTECT)
     147        {
     148
     149        }
     150    }
     151    void CommonController::setAction (Action::Value action, const Vector3& target,  const Quaternion& orient )
     152    {
     153        this->action_ = action;
     154        if (action == Action::FLY)
     155        {
     156            this->setTargetPosition (target);
     157            this->setTargetOrientation (orient);
     158        }
     159        else if (action == Action::PROTECT)
     160        {
     161           
     162        }
     163    }
    120164    void CommonController::maneuver()
    121165    {
     
    145189
    146190            //bool bThisIsLookingAtTarget = this->isLooking ( getControllableEntity(), this->target_, math::pi/4 );
    147             bool bTargetIsLookingAtThis = this->isLooking ( this->target_, getControllableEntity(), math::pi/8.0f );
     191            bool bTargetIsLookingAtThis = this->isLooking ( this->target_, getControllableEntity(), math::pi/5.0f );
    148192           
    149193
    150194
    151195            //too far? well, come closer then
    152             if ( diffLength > 5000 )
     196            if ( diffLength > 3000 )
    153197            {
    154198                if (diffLength < 6000)
    155199                {
    156                     this->bEngaging_ = true;
     200
    157201                }
    158202                else
    159203                {
    160                     this->bEngaging_ = false;
    161204                }
    162205                this->setTargetPosition( this->positionOfTarget_ );
    163206            }
    164207            //too close? How do u expect to dodge anything? Just attack!
    165             else if ( diffLength < 600 )
     208            else if ( diffLength < 500 )
    166209            {   
    167210                //at this point, just look and shoot
    168                 if ( diffLength < 300 )
     211                if ( diffLength < 250 )
    169212                {
    170213                    this->stopMoving();
     
    205248        if ( this->getControllableEntity()  && !this->target_ )
    206249        {
    207             this->bEngaging_ = false;
     250
    208251            this->maneuverType_ = ManeuverType::NONE;
    209252        }
    210         orxout ( internal_error ) << "ManeuverType = " << this->maneuverType_ << endl;
     253        //orxout ( internal_error ) << "ManeuverType = " << this->maneuverType_ << endl;
    211254    }
    212255    ControllableEntity* CommonController::getTarget()
     
    305348    {
    306349        this->target_ = target;
    307         orxout ( internal_error ) << " TARGET SET " << endl;
     350        //orxout ( internal_error ) << " TARGET SET " << endl;
    308351       
    309352        if ( this->target_ )
     
    376419    void CommonController::moveToPosition( const Vector3& target, float dt )
    377420    {
    378         float factor = 1;
    379         if ( !this->getControllableEntity() )
    380             return;
    381         if ( this->rank_ == Rank::DIVISIONLEADER )
    382             factor = 0.9;
    383         if ( this->rank_ == Rank::SECTIONLEADER )
    384             factor = 0.95;
     421     
    385422       
    386423        //100 is ( so far )the smallest tolerance ( empirically found )that can be reached,
     
    421458            }
    422459
    423             this->getControllableEntity() ->moveFrontBack( SPEED*factor * dt );
     460            this->getControllableEntity() ->moveFrontBack( SPEED * dt );
    424461        }
    425462        else
     
    560597        float squaredDistance = squaredDistanceToTarget();
    561598
    562         if ( squaredDistance < 25000000.0f && this->isLookingAtTarget( math::pi / 10.0f)) {
     599        if ( squaredDistance < 9000000.0f && this->isLookingAtTarget( math::pi / 10.0f)) {
    563600            return true;
    564601        }
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.h

    r10803 r10805  
    6565        };
    6666
     67    }
     68    namespace Action
     69    { 
     70        enum Value
     71        {
     72            FLY, FIGHT, PROTECT
     73        };
    6774    }
    6875    //none for a formation flight
     
    121128            /*void spin();
    122129            void turn180();*/
    123 
     130            Action::Value getAction ();
     131            void setAction (Action::Value action, ControllableEntity* target);
     132            void setAction (Action::Value action, const Vector3& target);
     133            void setAction (Action::Value action, const Vector3& target,  const Quaternion& orient );
    124134
    125135        protected:
     
    158168            Quaternion targetOrientation_;
    159169
     170            Vector3 destination_;
     171            bool bHasDestination;
     172
     173
    160174            void stopMoving();
    161175            void setPositionOfTarget(const Vector3& target);
     
    170184            //WeakPtr<ControllableEntity> thisEntity_;
    171185
     186           
     187
     188            Action::Value action_;
    172189            bool bEngaging_;
    173190            bool bShooting_;
  • code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc

    r10803 r10805  
    5151    DivisionController::~DivisionController()
    5252    {
    53      
    5453    }
    5554
     
    7776    void DivisionController::action()
    7877    {
    79         this->maneuver();
    80         this->bShooting_ = this->canFire();
    81        
     78        if (!this->target_)
     79        {
     80            for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
     81            {
     82                if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())
     83                    continue;           
     84
     85               
     86                if (static_cast<ControllableEntity*>(*itP) != (this)->getControllableEntity() && !(this)->hasTarget()
     87                    && ((*itP)->getWorldPosition() - (this)->getControllableEntity()->getWorldPosition()).length() < 10000)
     88                {
     89                    (this)->setAction(Action::FIGHT, *itP);
     90                }   
     91            }
     92        }
     93       
     94        if (this->action_ == Action::FIGHT)
     95        {
     96            this->maneuver();
     97            this->bShooting_ = this->canFire();
     98            if (this->target_)
     99            {
     100                if (this->myWingman_)
     101                {
     102                    this->myWingman_->setAction (Action::FIGHT, this->target_);                   
     103                }
     104               
     105                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
     106                if (diffVector.length() > 3000)
     107                {
     108                    this->setTargetPositionOfWingman();
     109                    //this->setTargetPositionOfFollower();                   
     110                }   
     111            }
     112        }
     113        else if (this->action_ == Action::FLY)
     114        {
     115            this->setTargetPositionOfWingman();
     116            this->setTargetPositionOfFollower();
     117        }
     118        else if (this->action_ == Action::PROTECT)
     119        {
     120
     121        }
    82122
    83123    }
     
    116156        (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfWingman)));
    117157       
    118         myWingman_->setTargetOrientation(orient);
    119         myWingman_->setTargetPosition(targetAbsolutePositionOfWingman);
     158        myWingman_->setAction( Action::FLY, targetAbsolutePositionOfWingman, orient);
    120159       
    121160    }
     
    153192        (this->getControllableEntity()->getWorldOrientation()* (*targetRelativePositionOfFollower)));
    154193       
    155         myFollower_->setTargetOrientation(orient);
    156         myFollower_->setTargetPosition(targetAbsolutePositionOfFollower);
    157        
     194        myFollower_->setAction ( Action::FLY, targetAbsolutePositionOfFollower, orient );       
    158195    }
    159196
  • code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc

    r10793 r10805  
    8787            for(std::vector<WeakPtr<DivisionController> >::iterator it = divisions_.begin(); it != divisions_.end(); ++it)
    8888            {
    89                 if (static_cast<ControllableEntity*>(*itP) != (*it)->getControllableEntity() && !(*it)->hasTarget())
     89                if (static_cast<ControllableEntity*>(*itP) != (*it)->getControllableEntity() && !(*it)->hasTarget()
     90                    && ((*itP)->getWorldPosition() - (*it)->getControllableEntity()->getWorldPosition()).length() < 10000)
    9091                {
    91                     (*it)->setTarget(*itP);
     92                    (*it)->setAction(Action::FIGHT, *itP);
    9293                }
    9394               
     
    9596           
    9697        }
    97 
     98        /*for(std::vector<WeakPtr<DivisionController> >::iterator it = divisions_.begin(); it != divisions_.end(); ++it)
     99        {
     100            Vector3* target = new Vector3 (0, 0, 2000);
     101            (*it)->setAction (Action::FLY, *target);           
     102        }   
     103*/
    98104    }
    99105    void FleetController::tick(float dt)
  • 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    }
  • code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc

    r10789 r10805  
    111111    void WingmanController::tick(float dt)
    112112    {   
    113        
    114        
    115113        if (!this->isActive())
    116114            return;
    117         if (!this->target_)
    118         {
    119             //stay in formation
    120         }
    121         else
    122         {
    123 
    124         }
    125115        if (this->bHasTargetPosition_)
    126116        {
    127117            this->moveToTargetPosition(dt);
    128         }
    129        
    130         if (this->bShooting_)
    131             doFire();
     118        }
     119        else if (this->bLookAtTarget_)
     120        {
     121            this->lookAtTarget(dt);
     122        }
     123        if (bShooting_)
     124        {
     125            this->doFire();
     126        }
    132127       
    133128        SUPER(WingmanController, tick, dt);
     
    144139            else
    145140            {
    146                 //orxout(internal_error) << "0 leader" << endl;
    147                
     141                if (!this->target_){
     142                    for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
     143                    {
     144                        if (this->getControllableEntity()->getTeam() == static_cast<ControllableEntity*>(*itP)->getTeam())
     145                            continue;   
     146                        this->setAction(Action::FIGHT, (*itP));
     147                        break;
     148                    }
     149                }
    148150            }
    149151
     
    153155
    154156        }
    155         if (canFire())
    156            this->bShooting_ = true;
    157         else
    158             this->bShooting_ = false;
     157       
     158        if (this->action_ == Action::FIGHT)
     159        {
     160            this->maneuver();
     161            this->bShooting_ = this->canFire();
     162            if (this->target_)
     163            {
     164                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
     165                if (diffVector.length() > 5000)
     166                {
     167                 
     168                }   
     169            }
     170        }
     171        else if (this->action_ == Action::FLY)
     172        {
     173
     174        }
     175        else if (this->action_ == Action::PROTECT)
     176        {
     177
     178        }
    159179         
    160180    }
Note: See TracChangeset for help on using the changeset viewer.