Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10847


Ignore:
Timestamp:
Nov 24, 2015, 11:54:47 AM (8 years ago)
Author:
gania
Message:

I hope that you don't code today, that version is not compilable just yet

Location:
code/branches/campaignHS15
Files:
7 edited

Legend:

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

    r10843 r10847  
    5151    <?lua end ?> -->
    5252 
    53    
    54     <SpaceShip position="4000, 1500, -1000" lookat="0,0,0" team=0>
     53<!--                 <ActionPoint position="12,34,56" action="FIGHT" enemy="ss" />
     54 -->
     55    <SpaceShip position="2000, 1500, -1000" lookat="0,0,0" team=0 name="ss1">
    5556      <templates>
    5657        <Template link=spaceshipassff />
     
    6162      </controller>
    6263    </SpaceShip>
     64    <SpaceShip position="0, 1500, -1000" lookat="0,0,0" team=0 name="ss2">
     65      <templates>
     66        <Template link=spaceshipassff />
     67      </templates>
     68      <controller>
     69        <DivisionController team=12>
     70          <actionpoints>
     71            <Actionpoint position="12,34,56" action="PROTECT" protectMe=true />
     72            <Actionpoint position="12,34,56" action="FLY" />
     73          </actionpoints>
     74        </DivisionController>
     75      </controller>
     76    </SpaceShip>
     77   
    6378   <!--  <SpaceShip position="4000 ,1500, -1600 " lookat="0,0,0" team=0>
    6479      <templates>
  • code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc

    r10843 r10847  
    6060        this->action_ = Action::FLY;
    6161        this->stopLookingAtTarget();
    62        
     62        this->attackRange_ = 2500;
    6363        RegisterObject( CommonController );
    6464    }
     
    6969        //orxout(internal_error) << "I died, my Rank is " << rank_ << endl;
    7070    }
    71    
     71    void CommonController::backupAction()
     72    {
     73        this->actionpoints_.push_back (this->currentActionpoint_);
     74    }
     75    void CommonController::restoreAction()
     76    {
     77        this->currentActionpoint_ = this->actionpoints_.back();
     78        this->actionpoints_.pop_back();
     79    }
     80    void CommonController::popAction()
     81    {
     82        this->currentActionpoint_ = actionpoints_.back();
     83        actionpoints_.pop_back();
     84    }
     85
    7286    void CommonController::XMLPort( Element& xmlelement, XMLPort::Mode mode )
    7387    {
    7488        SUPER( CommonController, XMLPort, xmlelement, mode );
    7589        XMLPortParam( CommonController, "formationMode", setFormationModeXML, getFormationModeXML,  xmlelement, mode );
    76         XMLPortParam( CommonController, "action", setActionXML, getActionXML,  xmlelement, mode );
    77         XMLPortParam ( CommonController, "protect", setProtectXML, getProtectXML,  xmlelement, mode );
     90        //XMLPortParam( CommonController, "action", setActionXML, getActionXML,  xmlelement, mode );
     91        //XMLPortParam ( CommonController, "protect", setProtectXML, getProtectXML,  xmlelement, mode );
    7892        //XMLPortParam ( CommonController, "enemy", setEnemyXML, getEnemyXML,  xmlelement, mode );
     93        XMLPortObject(CommonController, WorldEntity, "actionpoints", addActionpoint, getActionpoint,  xmlelement, mode);
     94
    7995    }
    8096    void CommonController::setProtectXML( std::string val )
     
    104120        if (!this->getProtect())
    105121            return "noProtectWasSet";
    106         return this->getProtect()->getName();
    107     }
    108 
     122        return CommonController::getName (this->getProtect());
     123    }
     124    std::string CommonController::getName(ControllableEntity* entity)
     125    {
     126        std::string name = entity->getName();
     127        if (name == "")
     128        {
     129            const void * address = static_cast<const void*>(entity);
     130            std::stringstream ss;
     131            ss << address; 
     132            name = ss.str();           
     133        }
     134        return name;
     135
     136    }
    109137    void CommonController::setProtect (ControllableEntity* protect)
    110138    {
     
    126154        else if ( valUpper == "PROTECT" )
    127155            value = Action::PROTECT;
     156        else if ( valUpper == "NONE" )
     157            value = Action::NONE;
     158        else if ( valUpper == "FIGHTALL" )
     159            value = Action::FIGHTALL;
     160        else if ( valUpper == "ATTACK" )
     161            value = Action::ATTACK;
    128162        else
    129163            ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ val + "'." );
     
    149183                break;
    150184            }
     185            case Action::NONE:
     186            {
     187                return "NONE";
     188                break;
     189            }
     190            case Action::FIGHTALL:
     191            {
     192                return "FIGHTALL";
     193                break;
     194            }
     195            case Action::ATTACK:
     196            {
     197                return "ATTACK";
     198                break;
     199            }
    151200            default:
    152                 return "FIGHT";
     201                return "NONE";
    153202                break;
    154203        }
     
    237286       
    238287    }
     288    void CommonController::addActionpoint(WorldEntity* actionpoint)
     289    {
     290        std::string actionName;
     291        Vector3 position;
     292        std::string targetName;
     293        this->actionpoints_.push_back(actionpoint);
     294        if (static_cast<Actionpoint*> (actionpoint))
     295        {
     296            Actionpoint* ap = static_cast<Actionpoint*> (actionpoint);
     297            actionName = ap->getActionXML();
     298            targetName = ap->get
     299            Action::Value value;
     300           
     301            if ( valUpper == "FIGHT" )
     302            {
     303                value = Action::FIGHT;
     304
     305            }
     306            else if ( valUpper == "FLY" )
     307            {
     308                value = Action::FLY;
     309
     310            }
     311            else if ( valUpper == "PROTECT" )
     312            {
     313                value = Action::PROTECT;
     314
     315            }
     316            else if ( valUpper == "NONE" )
     317            {
     318                value = Action::NONE;
     319
     320            }
     321            else if ( valUpper == "FIGHTALL" )
     322            {
     323                value = Action::FIGHTALL;
     324
     325            }
     326            else if ( valUpper == "ATTACK" )
     327            {
     328                value = Action::ATTACK;
     329
     330            }
     331            else
     332                ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ val + "'." );
     333            this->setAction( value );
     334        }
     335        else
     336        {
     337            actionName = "FLY";
     338        }
     339       
     340    }
     341
     342    WorldEntity* CommonController::getActionpoint(unsigned int index) const
     343    {
     344        if (index < this->actionpoints_.size())
     345            return this->actionpoints_[index];
     346        else
     347            return 0;
     348    }
    239349    void CommonController::setClosestTarget()
    240350    {
     351        this->setTarget (closestTarget());
     352    }
     353    ControllableEntity* CommonController::closestTarget()
     354    {
    241355        if (!this->getControllableEntity())
    242             return;
     356            return 0;
    243357
    244358        Pawn* closestTarget = 0;
     
    259373        if (closestTarget)
    260374        {
    261            (this)->setTarget(static_cast<ControllableEntity*>(closestTarget));
    262         }   
     375           return static_cast<ControllableEntity*>(closestTarget);
     376        }
     377        return 0; 
    263378    }
    264379    void CommonController::maneuver()
  • code/branches/campaignHS15/src/orxonox/controllers/CommonController.h

    r10843 r10847  
    3939#include "tools/interfaces/Tickable.h"
    4040#include <limits>
    41 
     41#include "worldentities/Actionpoint.h"
    4242
    4343namespace orxonox
     
    6363        enum Value
    6464        {
    65             FLY, FIGHT, PROTECT
     65            NONE, FLY, FIGHT, PROTECT, FIGHTALL, ATTACK
    6666        };
    6767    }
     
    111111                    ControllableEntity* getProtect ();
    112112                //----[/Protect data]----
     113                //----[Actionpoint data]----
     114                    void addActionpoint(WorldEntity* waypoint);
     115                    WorldEntity* getActionpoint(unsigned int index) const;
     116                //----[/Actionpoint data]----
    113117            //----[/XML data]----
    114118
     
    134138                static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt);
    135139                static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ;
     140                static std::string getName( ControllableEntity* entity ) ;
    136141
    137142                float squaredDistanceToTarget() const;
     
    166171                void doFire();
    167172                void setClosestTarget();
     173                ControllableEntity* closestTarget();
    168174
    169175                bool bShooting_;
     
    177183                Quaternion targetOrientation_;
    178184               
    179                 Vector3 destination_;
    180                 bool bHasDestination;
     185               
    181186            //----[/where-to-fly information]----
    182187            //----[protect information]----
     
    185190            //----[who-to-kill information]----
    186191                WeakPtr<ControllableEntity> target_;
    187                 WeakPtr<ControllableEntity> enemy_;
    188 
     192               
    189193                bool bHasPositionOfTarget_;
    190194                Vector3 positionOfTarget_;
     
    193197            //----[/who-to-kill information]----
    194198
     199            //----[Actionpoint information]----
     200                std::vector<WeakPtr<WorldEntity> > actionpoints_;
     201                float squaredaccuracy_;
     202                <tuple<Action::Value ,std::string ,Vector3 > > currentActionpoint_;
     203                std::vector<tuple<Action::Value ,std::string ,Vector3 > > parsedActionpoints_;
     204            //----[/Actionpoint information]----
    195205            //----["Private" variables]----
    196206                FormationMode::Value formationMode_;
     
    198208                std::string protectName_;
    199209                Action::Value action_;
     210                int attackRange_;
     211               
    200212            //----[/"Private" variables]----               
    201213    };
  • code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc

    r10843 r10847  
    7676
    7777       
    78         if (this->action_ == Action::FIGHT)
     78  /*      if (this->target_)
     79        {
     80            if (CommonController::distance (this->getControllableEntity(), newTarget) <
     81                CommonController::distance (this->getControllableEntity(), target_))
     82            {
     83                Actionpoint* ap = new Actionpoint(this->getContext());
     84                ap->setPosition (0, 0, 0);
     85                ap->setActionXML ("FIGHT");
     86                //ap->setEnemyXML(CommonController::getName(newTarget));
     87                this->addActionpoint (ap);
     88            }
     89
     90        }*/
     91        //----Whatever ship is doing, if there are targets close to it and its own target is far away, fight them----
     92        //analog to attack move
     93        if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
     94        {
     95            if ((this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_) ||
     96             !this->target_)
     97            {
     98                ControllableEntity* newTarget = this->closestTarget();
     99                if (newTarget && CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
     100                {
     101                    this->backupAction();
     102                    this->setAction (Action::FIGHT, newTarget);
     103                }
     104            }
     105        }
     106        //action is NONE whenever ships finishes current action,
     107        //if it was fighting before because enemies were close, resume what it was doing
     108        //otherwise try to execute next action
     109        if (this->action_ == Action::NONE)
     110        {
     111            if (this->bBackuped_)
     112            {
     113                this->restoreAction();
     114            } else if (!this->actionpoints_.empty())
     115            {
     116                this->popAction();
     117            }
     118        }
     119        if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL)
    79120        {
    80121            if (!this->hasTarget())
    81122            {
    82123                //----find a target----
    83                 this->setClosestTarget();
    84             }
    85             else
     124                if (this->action_ == Action::FIGHT)
     125                {
     126                    ControllableEntity* newTarget = this->closestTarget();
     127                    if (newTarget && CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
     128                    {
     129                        this->setAction (Action::FIGHT, newTarget);
     130                    }
     131                    else
     132                    {
     133                        this->setAction (Action::NONE);
     134                    }
     135                }
     136                else if (this->action_ == Action::FIGHTALL)
     137                {
     138                    this->setClosestTarget();                     
     139                }
     140
     141            }
     142            else if (this->hasTarget())
    86143            {
    87144                //----fly in formation if far enough----
    88145                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
    89                 if (diffVector.length() > 3000)
     146                if (diffVector.length() > this->attackRange_)
    90147                {
    91148                    this->setTargetPositionOfWingman();
     
    131188                        this->setProtect (static_cast<ControllableEntity*>(*itP));
    132189                    }
     190                }
     191                if (!this->getProtect())
     192                {
     193                    this->setAction (Action::NONE);
    133194                }
    134195            }
  • code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.cc

    r10844 r10847  
    2727 */
    2828
    29 #include "ActionPoint.h"
     29#include "Actionpoint.h"
    3030
    3131#include "core/CoreIncludes.h"
     
    3434namespace orxonox
    3535{
    36     RegisterClass(ActionPoint);
     36    RegisterClass(Actionpoint);
    3737
    38     ActionPoint::ActionPoint(Context* context) : StaticEntity(context)
     38    Actionpoint::Actionpoint(Context* context) : StaticEntity(context)
    3939    {
    40         RegisterObject(ActionPoint);
     40        RegisterObject(Actionpoint);
    4141
    4242    }
    4343    //usage:
    4444    // <DivisionController team=12>
    45     //     <actionpoints>
    46     //          <ActionPoint position="12,34,56" action="FIGHT" enemy="enemyName" />, position irrelevant
    47     //          <ActionPoint position="12,34,56" action="PROTECT" protect="protectName" />, position irrelevant
    48     //          <ActionPoint position="12,34,56" action="FLY" />, position relevant: makes ship fly to the position of ActionPoint
    49     //     </actionpoints>
     45    //     <Actionpoints>
     46    //          <Actionpoint position="12,34,56" action="FIGHT" enemy="enemyName" />, position irrelevant
     47    //          <Actionpoint position="12,34,56" action="PROTECT" protect="protectName" />, position irrelevant
     48    //          <Actionpoint position="12,34,56" action="FLY" />, position relevant: makes ship fly to the position of Actionpoint
     49    //     </Actionpoints>
    5050    // </DivisonController>
    5151    //DivisionController will firstly fight enemy that it will find by name "enemyName", if finds nothing or when beats enemy,
     
    5656    //another usage:
    5757    // <DivisionController team=12>
    58     //     <actionpoints>
    59     //          <ActionPoint position="12,34,56" action="PROTECT" protectMe=true />, position irrelevant
    60     //          <ActionPoint position="12,34,56" action="FIGHT" fightAll=true />, position irrelevant
    61     //     </actionpoints>
     58    //     <Actionpoints>
     59    //          <Actionpoint position="12,34,56" action="PROTECT" protectMe=true />, position irrelevant
     60    //          <Actionpoint position="12,34,56" action="FIGHT" fightAll=true />, position irrelevant
     61    //     </Actionpoints>
    6262    // </DivisonController>
    6363    //DivisionController will protect the first NewHumanController it finds, when it dies or if no controller found,
    6464    //it will fight closest enemies one after another
    65     void ActionPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     65    void Actionpoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    6666    {
    67         SUPER(ActionPoint, XMLPort, xmlelement, mode);
     67        SUPER(Actionpoint, XMLPort, xmlelement, mode);
    6868       
    69         XMLPortParam( ActionPoint, "action", setActionXML, getActionXML,  xmlelement, mode );
    70         XMLPortParam( ActionPoint, "protect", setProtectXML, getProtectXML,  xmlelement, mode );
    71         XMLPortParam( ActionPoint, "enemy", setEnemyXML, getEnemyXML,  xmlelement, mode );
    72         XMLPortParam( ActionPoint, "protectMe", setProtectMeXML, getProtectMeXML,  xmlelement, mode ).defaultValues(false);
    73         XMLPortParam( ActionPoint, "fightAll", setFightAllXML, getFightAllXML,  xmlelement, mode ).defaultValues(false);
     69        XMLPortParam( Actionpoint, "action", setActionXML, getActionXML,  xmlelement, mode );
     70        XMLPortParam( Actionpoint, "protect", setProtectXML, getProtectXML,  xmlelement, mode );
     71        XMLPortParam( Actionpoint, "enemy", setEnemyXML, getEnemyXML,  xmlelement, mode );
     72        XMLPortParam( Actionpoint, "protectMe", setProtectMeXML, getProtectMeXML,  xmlelement, mode ).defaultValues(false);
     73        XMLPortParam( Actionpoint, "fightAll", setFightAllXML, getFightAllXML,  xmlelement, mode ).defaultValues(false);
    7474
    7575    }
    76     void ActionPoint::setActionXML( std::string val)
     76    void Actionpoint::setActionXML( std::string val)
    7777    {
    7878        this->actionName_ = getUppercase( val );
     79        orxout(internal_error) << "action = " << this->actionName_ << endl;
    7980    }
    8081
    81     std::string ActionPoint::getActionXML()
     82    std::string Actionpoint::getActionXML()
    8283    {
    8384        return this->actionName_;
    8485    }
    85     void ActionPoint::setProtectXML( std::string val)
     86    void Actionpoint::setProtectXML( std::string val)
    8687    {
    8788        this->protectName_ = getUppercase( val );
    8889    }
    8990
    90     std::string ActionPoint::getProtectXML()
     91    std::string Actionpoint::getProtectXML()
    9192    {
    9293        return this->protectName_;
    9394    }
    94     void ActionPoint::setEnemyXML( std::string val)
     95    void Actionpoint::setEnemyXML( std::string val)
    9596    {
    9697        this->enemyName_ = getUppercase( val );
    9798    }
    9899
    99     std::string ActionPoint::getEnemyXML()
     100    std::string Actionpoint::getEnemyXML()
    100101    {
    101102        return this->enemyName_;
    102103    }
    103 
    104     void ActionPoint::setTargetPosition(const Vector3& target)
     104    void Actionpoint::setProtect( ControllableEntity* protect)
     105    {
     106        this->protect_ = protect;
     107    }
     108    ControllableEntity* Actionpoint::getProtect()
     109    {
     110        return this->protect_;
     111    }
     112    void Actionpoint::setEnemy( ControllableEntity* enemy)
     113    {
     114        this->enemy_ = enemy;
     115    }
     116    ControllableEntity* Actionpoint::getEnemy()
     117    {
     118        return this->enemy_;
     119    }
     120    void Actionpoint::setTargetPosition(const Vector3& target)
    105121    {
    106122        this->targetPosition_ = target;
    107123    }
    108     Vector3 ActionPoint::getTargetPosition ()
     124    Vector3 Actionpoint::getTargetPosition ()
    109125    {
    110126        return this->targetPosition_;
  • code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.h

    r10844 r10847  
    3333*/
    3434
    35 #ifndef _ActionPoint_H__
    36 #define _ActionPoint_H__
     35#ifndef _Actionpoint_H__
     36#define _Actionpoint_H__
    3737
    3838#include "OrxonoxPrereqs.h"
     
    4545{
    4646 
    47     class _OrxonoxExport ActionPoint : public StaticEntity
     47    class _OrxonoxExport Actionpoint : public StaticEntity
    4848    {
    4949        public:
    50             ActionPoint(Context* context);
    51             virtual ~ActionPoint() {}
     50            Actionpoint(Context* context);
     51            virtual ~Actionpoint() {}
    5252
    5353            //----[XML data]----
     
    8787                //----[/FightAll data]----
    8888            //----[/XML data]----
    89 
     89                void setProtect( ControllableEntity* protect);
     90                ControllableEntity* getProtect();
     91                void setEnemy( ControllableEntity* enemy);
     92                ControllableEntity* getEnemy();
    9093            //----["Waypoints" data]----
    9194                void setTargetPosition(const Vector3& target);
     
    98101            std::string protectName_;
    99102            std::string enemyName_;
     103            WeakPtr<ControllableEntity> protect_;
     104            WeakPtr<ControllableEntity> enemy_;
     105
    100106            bool protectMe_;
    101107            bool fightAll_;
     
    104110}
    105111
    106 #endif /* _ActionPoint_H__ */
     112#endif /* _Actionpoint_H__ */
  • code/branches/campaignHS15/src/orxonox/worldentities/CMakeLists.txt

    r10843 r10847  
    1212  SpawnPoint.cc
    1313  TeamSpawnPoint.cc
    14   ActionPoint.cc
     14  Actionpoint.cc
    1515)
    1616
Note: See TracChangeset for help on using the changeset viewer.