Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10759


Ignore:
Timestamp:
Nov 2, 2015, 4:48:27 PM (8 years ago)
Author:
gania
Message:

small fixes

Location:
code/branches/AI_HS15
Files:
8 edited

Legend:

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

    r10731 r10759  
    6262    <?lua end ?>
    6363  </!-->
     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
    6477   
     78    <SpaceShip position="<?1000 ?>,<?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
    65175    <StaticEntity position = "-1000, -1000, -1000">
    66176 
     
    108218    </SpaceShip>
    109219
     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
    110266   
    111267    <!-->
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc

    r10737 r10759  
    2727 */
    2828#include "controllers/CommonController.h"
    29 /*
     29#include "core/XMLPort.h"
     30
    3031#include "weaponsystem/WeaponMode.h"
    3132#include "weaponsystem/WeaponPack.h"
     
    3435#include "weaponsystem/WeaponSlot.h"
    3536#include "worldentities/pawns/SpaceShip.h"
    36 */
     37
    3738
    3839namespace orxonox
     
    4041
    4142    RegisterClass(CommonController);
    42     static const float SPEED = 0.6f;
    43     static const float ROTATEFACTOR = 0.2f;
     43    float SPEED = 0.7f;
     44    float ROTATEFACTOR = 0.3f;
    4445
    4546    CommonController::CommonController(Context* context) : Controller(context)
    4647    {
    47         //this->bSetupWorked = false;
     48        this->bSetupWorked = false;
    4849
    4950        RegisterObject(CommonController);
     
    5556    }
    5657
    57 
    58 
     58    void CommonController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     59    {
     60        SUPER(CommonController, XMLPort, xmlelement, mode);
     61        XMLPortParam(CommonController, "formationMode", setFormationModeXML, getFormationModeXML,  xmlelement, mode);
     62
     63    }
     64    void CommonController::setFormationModeXML(std::string val)
     65    {
     66        const std::string valUpper = getUppercase(val);
     67        FormationMode::Value value;
     68        if (valUpper == "VEE")
     69            value = FormationMode::VEE;
     70        else if (valUpper == "WALL")
     71            value = FormationMode::WALL;
     72        else if (valUpper == "FINGER4")
     73            value = FormationMode::FINGER4;
     74        else if (valUpper == "DIAMOND")
     75            value = FormationMode::DIAMOND;
     76        else
     77            ThrowException(ParseError, std::string("Attempting to set an unknown FormationMode: '") + val + "'.");
     78        this->setFormationMode(value);
     79       
     80    }
     81    std::string CommonController::getFormationModeXML()
     82    {
     83        switch (this->formationMode_)
     84        {
     85            case FormationMode::VEE:
     86            {
     87                return "VEE";
     88                break;
     89            }
     90            case FormationMode::WALL:
     91            {
     92                return "WALL";
     93                break;
     94            }
     95            case FormationMode::FINGER4:
     96            {
     97                return "FINGER4";
     98                break;
     99            }
     100            case FormationMode::DIAMOND:
     101            {
     102                return "DIAMOND";
     103                break;
     104            }
     105            default:
     106                return "DIAMOND";
     107                break;
     108
     109        }
     110    }
    59111
    60112    bool CommonController::setWingman (CommonController* wingman)
     
    67119        return true;
    68120    }
    69 
     121    void CommonController::setTarget(ControllableEntity* target)
     122    {
     123        this->target_ = target;
     124        orxout (internal_error) << " TARGET SET " << endl;
     125        if (target)
     126            this->targetPosition_ = target->getPosition();
     127    }
    70128
    71129
     
    113171        while(diff>math::twoPi) diff-=math::twoPi;
    114172        while(diff<-math::twoPi) diff+=math::twoPi;
    115         this->getControllableEntity()->rotateRoll(-diff);
     173        this->getControllableEntity()->rotateRoll(diff*ROTATEFACTOR);
    116174    }
    117175    void CommonController::copyTargetOrientation()
     
    134192        if (!this->getControllableEntity())
    135193            return;
     194        if (this->rank_ == Rank::DIVISIONLEADER)
     195            SPEED *= 0.8;
     196        if (this->rank_ == Rank::SECTIONLEADER)
     197            SPEED *= 0.9;
    136198       
    137199        //100 is (so far) the smallest tolerance (empirically found) that can be reached,
    138200        //with smaller distance spaceships can't reach position and go circles around it instead
    139         int tolerance = 100;
     201        int tolerance = 60;
    140202
    141203        ControllableEntity* entity = this->getControllableEntity();
     
    160222
    161223            //300 works, maybe less is better
    162             if (distance < 300)
     224            if (distance < 400)
    163225            {
    164226                //Change roll when close. When Spaceship faces target, roll doesn't affect it's trajectory
     
    180242    }
    181243
    182 /*
     244
    183245    int CommonController::getFiremode(std::string name)
    184246    {
     
    227289    void CommonController::doFire()
    228290    {
    229         if(!this->bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ...
     291          if(!this->bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ...
    230292        {
    231293            this->setupWeapons();
    232294        }
    233         else if(this->getControllableEntity() &&
    234             weaponModes_.size()&&
    235             this->bShooting_ &&
    236             this->isCloseAtTarget((3)*1000) &&
    237             this->isLookingAtTarget(math::pi / 20.0f))
     295        else if(this->getControllableEntity() && weaponModes_.size()&&this->bShooting_ &&
     296            this->isCloseAtTarget((1 + 2)*1000) && this->isLookingAtTarget(math::pi / 20.0f))
    238297        {
    239298            int firemode;
     
    246305            else if ((firemode = getFiremode("HsW01")) > -1 ) //LASER: default weapon
    247306                this->getControllableEntity()->fire(firemode);
     307       
    248308        }
    249309    }
     
    269329        if (pawn)
    270330            pawn->setAimPosition(aimPosition);
    271     }*/
     331    }
    272332   
    273333 
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.h

    r10737 r10759  
    3333#include "controllers/Controller.h"
    3434#include "worldentities/ControllableEntity.h"
    35 /*#include "worldentities/pawns/Pawn.h"
    36 */
     35#include "worldentities/pawns/Pawn.h"
     36
    3737
    3838namespace orxonox
    3939{
     40
     41    namespace FormationMode
     42    {
     43        enum Value
     44        {
     45            VEE, FINGER4, DIAMOND, WALL
     46        };
     47    }
     48    namespace Rank
     49    {
     50        enum Value
     51        {
     52            NONE, SECTIONLEADER, DIVISIONLEADER, WINGMAN
     53        };
     54
     55    }
     56
    4057    class _OrxonoxExport CommonController : public Controller
    4158    {
     
    5067
    5168
    52             enum FormationMode { VEE, FINGER4, DIAMOND, WALL };
    53             virtual void setFormationMode(FormationMode val)
     69
     70
     71            virtual void setFormationMode(FormationMode::Value val)
    5472                { this->formationMode_ = val; }
    55             inline FormationMode getFormationMode() const
     73            inline FormationMode::Value getFormationMode() const
    5674                { return this->formationMode_; }
     75            virtual void setFormationModeXML(std::string val);
     76            virtual std::string getFormationModeXML();
    5777
    58             enum Rank { NONE, SECTIONLEADER, DIVISIONLEADER, WINGMAN };
    59             virtual void setRank(Rank val)
     78            virtual void setRank(Rank::Value val)
    6079                { this->rank_ = val; }
    61             inline Rank getRank() const
     80            inline Rank::Value getRank() const
    6281                { return this->rank_; }
    6382
     83            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    6484
    6585
     
    6888            virtual bool hasWingman();
    6989
     90            void setTarget(ControllableEntity* target);
    7091
    7192            void setTargetOrientation(const Quaternion& orient);
     
    87108            void copyTargetOrientation();
    88109
    89           /*  bool isCloseAtTarget(float distance) const;
     110            bool isCloseAtTarget(float distance) const;
    90111            void doFire();
    91112            void aimAtTarget();
     
    99120            bool bSetupWorked; //<! If false, setupWeapons() is called.
    100121            int getFiremode(std::string name);
    101 */
     122
    102123
    103124            bool bHasTargetPosition_;
     
    111132
    112133
    113             FormationMode formationMode_;
    114             Rank rank_;
     134            FormationMode::Value formationMode_;
     135            Rank::Value rank_;
    115136
    116137
  • code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc

    r10737 r10759  
    3838    {
    3939        RegisterObject(DivisionController);
    40         this->setFormationMode(WALL);
     40       
     41        this->setFormationMode(FormationMode::DIAMOND);
    4142
    4243        this->myFollower_ = 0;
    4344        this->myWingman_ = 0;
    4445        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DivisionController::action, this)));
    45         this->rank_ = DIVISIONLEADER;
    46 
    47         Vector3* pos = new Vector3(500,500,-500);
     46        this->rank_ = Rank::DIVISIONLEADER;
     47
     48        Vector3* pos = new Vector3(-4000,-1000,-2000);
    4849        this->setTargetPosition(*pos);
    4950
     
    5859    void DivisionController::tick(float dt)
    5960    {
    60         if (this->target_)
    61         {
    62             //this->aimAtTarget();
    63             //this->doFire();
    64             //this->bShooting_ = true;
    65         }
     61        /*if (this->target_)
     62        {
     63            this->aimAtTarget();
     64            this->doFire();
     65            this->bShooting_ = true;
     66        }*/
    6667     
    6768        if (this->bHasTargetPosition_)
     
    7778        setTargetPositionOfFollower();
    7879        setTargetPositionOfWingman();
    79 /*
     80
     81       
     82        if (this->myFollower_ && this->target_)
     83            this->myFollower_->setTarget(this->target_);
     84        if (this->target_ && this->myWingman_)
     85            this->myWingman_->setTarget(this->target_);
     86    /*           
    8087        for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it)
    8188        {
    82             if (this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam())
    83             {
    84                 this->target_=it->getControllableEntity();
    85                 this->setTargetPosition(this->target_->getWorldPosition());
     89            if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) && (it)->getControllableEntity()->getTeam() != 0)
     90            {
     91                this->setTargetPosition(it->getControllableEntity()->getWorldPosition());
     92                             
    8693                break;
    8794            }
    88         }*/
    89            
     95        }
     96           */
    9097     
    9198    }
     
    99106        Vector3* targetRelativePositionOfWingman;
    100107        switch (this->formationMode_){
    101             case WALL:
     108            case FormationMode::WALL:
    102109            {
    103110                targetRelativePositionOfWingman = new Vector3 (400, 0, 0); 
    104111                break;
    105112            }
    106             case FINGER4:
    107             {
    108                 break;
    109             }
    110             case VEE:
    111             {
    112                 break;
    113             }
    114             case DIAMOND:
    115             {
     113            case FormationMode::FINGER4:
     114            {
     115                targetRelativePositionOfWingman = new Vector3 (400, 0, -200); 
     116                break;
     117            }
     118            case FormationMode::VEE:
     119            {
     120                break;
     121            }
     122            case FormationMode::DIAMOND:
     123            {
     124                targetRelativePositionOfWingman = new Vector3 (400, 0, -200);                 
    116125                break;
    117126            }
     
    130139        if (!this->myFollower_)
    131140            return;
     141        this->myFollower_->setFormationMode(this->formationMode_);
     142
    132143        Vector3* targetRelativePositionOfFollower;
    133144        switch (this->formationMode_){
    134             case WALL:
     145            case FormationMode::WALL:
    135146            {
    136147                targetRelativePositionOfFollower = new Vector3 (-400, 0, 0);   
    137148                break;
    138149            }
    139             case FINGER4:
    140             {
    141                 break;
    142             }
    143             case VEE:
    144             {
    145                 break;
    146             }
    147             case DIAMOND:
    148             {
     150            case FormationMode::FINGER4:
     151            {
     152                targetRelativePositionOfFollower = new Vector3 (-400, 0, -200);   
     153                break;
     154            }
     155            case FormationMode::VEE:
     156            {
     157                break;
     158            }
     159            case FormationMode::DIAMOND:
     160            {
     161                targetRelativePositionOfFollower = new Vector3 (-400, 0, -200);                   
    149162                break;
    150163            }
  • code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc

    r10731 r10759  
    4444        this->goalProtect_ = NULL;*/
    4545       
    46         //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&FleetController::action, this)));
     46        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&FleetController::action, this)));
    4747    }
    4848
     
    5656    void FleetController::action()
    5757    {
    58 
     58        this->divisions_.clear();
     59       
     60        /*for (ObjectList<DivisionController>::iterator it = ObjectList<DivisionController>::begin(); it; ++it)
     61        {
     62            if ((this->getControllableEntity()->getTeam() == (it)->getControllableEntity()->getTeam()))
     63            {
     64                this->divisions_.push_back(*(it));
     65            }
     66        }
     67        for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it)
     68        {
     69            if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) && (it)->getControllableEntity()->getTeam() != 0)
     70            {
     71                for(std::vector<WeakPtr<DivisionController> >::iterator it2 = divisions_.begin(); it2 != divisions_.end(); ++it2) {
     72                    (*it2)->setTarget(it->getControllableEntity());   
     73                }               
     74                break;
     75            }
     76        }*/
    5977
    6078    }
  • code/branches/AI_HS15/src/orxonox/controllers/FleetController.h

    r10731 r10759  
    5656    {
    5757        public:
     58                      static const float ACTION_INTERVAL = 1.0f;
     59
    5860          FleetController(Context* context);
    5961          virtual ~FleetController();
     
    7476
    7577        protected:
     78            virtual void action(); //<! action() is called in regular intervals managing the bot's behaviour ~ setting targets.
    7679
    7780           
     
    8184            WeakPtr<Pawn> goalProtect_;
    8285
    83             virtual void action();
    8486        private:
    8587       
    8688            std::vector<WeakPtr<DivisionController> > divisions_;
    87             //Timer actionTimer_; //<! Regularly calls action().
     89            Timer actionTimer_; //<! Regularly calls action().
    8890
    8991    };
  • code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc

    r10731 r10759  
    3737    {
    3838        RegisterObject(SectionController);
    39         this->setFormationMode(WALL);
     39        this->setFormationMode(FormationMode::FINGER4);
    4040
    4141        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&SectionController::action, this)));
    4242        this->myWingman_ = 0;
    4343        this->myDivisionLeader_ = 0;
    44         this->rank_ = SECTIONLEADER;
     44        this->rank_ = Rank::SECTIONLEADER;
    4545
    4646        orxout(internal_error) << this << "Was created" << endl;
     
    5858            return;
    5959       
     60        /*if (this->target_)
     61        {
     62            this->aimAtTarget();
     63            this->doFire();
     64            this->bShooting_ = true;
     65        }*/
    6066        if (this->bHasTargetPosition_)
    6167        {
     
    7682            if (newDivisionLeader)
    7783                orxout(internal_error) << "new DivisionLeader set" << endl;
     84            else
     85            {
     86               
     87            }
    7888
    7989        }
    8090        setTargetPositionOfWingman();
     91        if (this->target_ && this->myWingman_)
     92            this->myWingman_->setTarget(this->target_);
     93               
    8194
    8295    }
     
    88101        Vector3* targetRelativePositionOfWingman;
    89102        switch (this->formationMode_){
    90             case WALL:
     103            case FormationMode::WALL:
    91104            {
    92105                targetRelativePositionOfWingman = new Vector3 (-400, 0, 0); 
    93106                break;
    94107            }
    95             case FINGER4:
    96             {
    97                 break;
    98             }
    99             case VEE:
    100             {
    101                 break;
    102             }
    103             case DIAMOND:
    104             {
     108            case FormationMode::FINGER4:
     109            {
     110                targetRelativePositionOfWingman = new Vector3 (-400, 0, -200); 
     111                break;
     112            }
     113            case FormationMode::VEE:
     114            {
     115                break;
     116            }
     117            case FormationMode::DIAMOND:
     118            {
     119                targetRelativePositionOfWingman = new Vector3 (400, -200, 0);                 
    105120                break;
    106121            }
     
    127142        {
    128143            //0ptr or not DivisionController?
    129             if (!(it) || !((it)->getRank() == DIVISIONLEADER) || !(it->getControllableEntity()))
     144            if (!(it) || !((it)->getRank() == Rank::DIVISIONLEADER) || !(it->getControllableEntity()))
    130145                continue;
    131146            //same team?
  • code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc

    r10731 r10759  
    4141        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&WingmanController::action, this)));
    4242        this->myLeader_ = 0;
    43         this->rank_ = WINGMAN;
     43        this->rank_ = Rank::WINGMAN;
    4444
    4545    }
     
    5353    {   
    5454        //-------------------------------------------------------
    55            
     55       /* if (this->target_)
     56        {
     57            this->aimAtTarget();
     58            this->doFire();
     59            this->bShooting_ = true;
     60        }*/
    5661       
    5762        if (!this->isActive())
     
    8893                orxout(internal_error) << "new Leader set" << endl;
    8994            else
    90                 orxout(internal_error) << "0 leader" << endl;
     95            {
     96                //orxout(internal_error) << "0 leader" << endl;
     97               
     98            }
    9199
    92100        }
     
    113121            //0ptr?
    114122            if (!it ||
    115                 (it->getRank() != SECTIONLEADER && it->getRank() != DIVISIONLEADER) ||
     123                (it->getRank() != Rank::SECTIONLEADER && it->getRank() != Rank::DIVISIONLEADER) ||
    116124                !(it->getControllableEntity()))
    117125                continue;
Note: See TracChangeset for help on using the changeset viewer.