Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

small fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.