Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10925


Ignore:
Timestamp:
Dec 7, 2015, 9:41:38 AM (9 years ago)
Author:
gania
Message:

synchronized AI with a static tick counter

Location:
code/branches/campaignHS15
Files:
5 edited

Legend:

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

    r10923 r10925  
    9292<!-- HERE STARTS DEMO FOR THE ACTIONPOINTS.
    9393P.S. Never set protectMe in the first actionpoint: if human didn't spawn, that actionpoint will be skipped -->
    94        
     94       <!--
    9595    <Model mesh="cube.mesh" scale=8 position="0,0,0" />
    9696
     
    153153      </templates>
    154154    </SpaceShip>
    155  
     155  -->
    156156   
    157157<!-- HERE ENDS DEMO FOR THE ACTIONPOINTS -->
    158158<!-- HERE STARTS DEMO FOR FIGHTING -->
    159     <!--
     159   
    160160
    161161    <SpaceShip position="-4000, 1500, -1000" lookat="0,0,0" team=0 name="d1sd1">
     
    202202      </templates>
    203203      <controller>
    204         <DivisionController team=1 formationMode="WALL">
     204        <DivisionController team=1 formationMode="DIAMOND">
    205205
    206206        </DivisionController>
     
    234234      </controller>
    235235    </SpaceShip>
    236  -->
     236
    237237<!-- HERE ENDS DEMO FOR FIGHTING -->
    238238<!-- HERE STARTS DEMO FOR FORMATIONS -->
  • code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc

    r10924 r10925  
    110110        }
    111111
     112        if (!this || !this->getControllableEntity())
     113            return;
     114
    112115        if (this->ticks_ == 1)
    113116        {
     
    143146            this->lookAtTarget(dt);
    144147        }
    145         if (this->bShooting_)
    146         {
    147             this->doFire();
    148         }
     148       
    149149
    150150        if (!this || !this->getControllableEntity())
     
    159159        if (timeout_ <= 0)
    160160            this->bFiredRocket_ = false;
    161         if (!this || !this->getControllableEntity())
    162             return;
     161       
    163162
    164163        if (!this || !this->getControllableEntity())
    165164            return;
    166165        if (this->timeout_ > 0 && this->bFiredRocket_)
    167             {
    168                 this->timeout_ -= dt;
    169             }
    170             if (this->bStartedDodging_)
    171             {
    172                 this->timeDodged_ += dt;
    173             }
    174             maneuverCounter_ += dt;
     166        {
     167            this->timeout_ -= dt;
     168        }
     169        if (this->bStartedDodging_)
     170        {
     171            this->timeDodged_ += dt;
     172        }
     173        maneuverCounter_ += dt;
     174
    175175        if (!this || !this->getControllableEntity())
    176176            return;
    177177        //maneuver every 0.25 sec ->
    178178        int step =  4;
    179         if (this->hasTarget() && ActionpointController::sTicks_ % 100 == step * (this->actionpointControllerId_))
    180         {
    181            
    182         }
    183179        if (ActionpointController::sTicks_ % 100 == step * this->actionpointControllerId_ + 1)
    184180        {
     181            //orxout (internal_error) << "Team " << this->getControllableEntity()->getTeam() << (this->hasTarget() ? ", got " : ", don't have") << " target" << endl;
    185182            this->action();
    186183        }
    187         if (!this || !this->getControllableEntity())
    188             return;
    189 
    190        
    191         if (this->hasTarget() &&  ActionpointController::sTicks_ % ActionpointController::nextActionpointControllerId_ == (this->actionpointControllerId_))
     184
     185
     186        if (!this || !this->getControllableEntity())
     187            return;
     188
     189        if (this->hasTarget() &&  ActionpointController::sTicks_ % (ActionpointController::nextActionpointControllerId_ + 1) == (this->actionpointControllerId_))
    192190        {
    193191            if (maneuverCounter_ > 6.0f)
    194                 maneuverCounter_ = 0;
     192                this->maneuverCounter_ = 0;
    195193            if (this->bStartedDodging_ &&  this->timeDodged_ > 4.0f)
    196194            {
     
    199197            }
    200198            if (!this || !this->getControllableEntity())
    201             return;
     199                return;
    202200            this->maneuver();
    203201            if (!this || !this->getControllableEntity())
    204             return;
     202                return;
    205203            this->bShooting_ = this->canFire();
    206         }
    207         if (!this || !this->getControllableEntity())
    208             return;
     204
     205            if (!this || !this->getControllableEntity())
     206                return;
     207
     208            if (this->bShooting_)
     209            {
     210                this->doFire();
     211            }
     212            this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp;
     213            this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth();
     214        }
    209215       
    210216
     
    227233            return;
    228234
    229         this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp;
    230         this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth();
     235
    231236        if (!this || !this->getControllableEntity())
    232237            return;
     
    514519        }
    515520        this->setAction (p.action);
     521        if (!this || !this->getControllableEntity())
     522            return;
     523
    516524        switch (this->action_)
    517525        {
     
    654662    void ActionpointController::moveBackToTop()
    655663    {
     664        if (!this || !this->getControllableEntity())
     665            return;
     666
    656667        Point temp = loopActionpoints_.back();
    657668        loopActionpoints_.pop_back();
  • code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc

    r10923 r10925  
    211211                                                           hardcoded_projectile_speed, this->target_->getWorldPosition(),
    212212                                                           this->target_->getVelocity());
     213        if (!this->target_ || !this->getControllableEntity())
     214            return false;
    213215        //Vector3.isNaN() is what I used on my machine and it worked...
    214216        if (!(std::isnan(newPositionOfTarget.x) || std::isnan(newPositionOfTarget.y) || std::isnan(newPositionOfTarget.z)))
  • code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc

    r10923 r10925  
    9595        {
    9696            ActionpointController* newDivisionLeader = findNewDivisionLeader();
     97            if (!this || !this->getControllableEntity())
     98                return;
     99
    97100            this->myDivisionLeader_ = newDivisionLeader;
    98101            //spread copyOrientation called equally among the division
     
    128131            else if (!this->myDivisionLeader_->bKeepFormation_)
    129132            {
     133                if (!this || !this->getControllableEntity())
     134                    return;
     135
    130136                if (!this->hasTarget())
    131137                {
  • code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc

    r10923 r10925  
    120120        {
    121121            ActionpointController* newLeader = (findNewLeader());
     122            if (!this || !this->getControllableEntity())
     123                return;
     124
    122125            this->myLeader_ = newLeader;
    123126            if (this->myLeader_)
     
    147150            else if (!this->myLeader_->bKeepFormation_)
    148151            {
     152                if (!this || !this->getControllableEntity())
     153                    return;
     154
    149155                if (!this->hasTarget())
    150156                {
     
    175181    Vector3 WingmanController::getFormationPosition ()
    176182    {
     183
     184
    177185        this->setFormationMode( this->myLeader_->getFormationMode() );
    178186        Vector3* targetRelativePosition;
Note: See TracChangeset for help on using the changeset viewer.