Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3049


Ignore:
Timestamp:
May 25, 2009, 3:26:43 AM (15 years ago)
Author:
landauf
Message:
  • Added option to add a Controller to a ControllableEntity in the XML file
  • Added two new classes: WaypointController (follows waypoints) and WaypointPatrolController (follows waypoints and kills enemies within a given radius)
  • Radarpoints in TeamDeathmatch are now coloured
Location:
code/trunk/src
Files:
4 added
10 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/OrxonoxPrereqs.h

    r3033 r3049  
    196196    class AIController;
    197197    class ScriptController;
     198    class WaypointController;
     199    class WaypointPatrolController;
    198200    class PongAI;
    199201
  • code/trunk/src/orxonox/objects/controllers/AIController.cc

    r2896 r3049  
    108108
    109109        if (this->bHasTargetPosition_)
    110             this->moveToTargetPosition(dt);
     110            this->moveToTargetPosition();
    111111
    112         if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(500) && this->isLookingAtTarget(Ogre::Math::PI / 20.0))
     112        if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0))
    113113            this->getControllableEntity()->fire(WeaponMode::fire);
    114114
  • code/trunk/src/orxonox/objects/controllers/ArtificialController.cc

    r2662 r3049  
    3434#include "objects/worldentities/pawns/Pawn.h"
    3535
     36#include "objects/gametypes/TeamDeathmatch.h"
     37#include "objects/controllers/WaypointPatrolController.h"
     38
    3639namespace orxonox
    3740{
     
    5053    }
    5154
    52     void ArtificialController::moveToTargetPosition(float dt)
     55    void ArtificialController::moveToPosition(const Vector3& target)
    5356    {
    5457        if (!this->getControllableEntity())
    5558            return;
    5659
    57         Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_);
    58         float distance = (this->targetPosition_ - this->getControllableEntity()->getPosition()).length();
     60        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
     61        float distance = (target - this->getControllableEntity()->getPosition()).length();
    5962
    6063        if (this->target_ || distance > 10)
     
    7174    }
    7275
     76    void ArtificialController::moveToTargetPosition()
     77    {
     78        this->moveToPosition(this->targetPosition_);
     79    }
     80
     81    void ArtificialController::setTargetPosition(const Vector3& target)
     82    {
     83        this->targetPosition_ = target;
     84        this->bHasTargetPosition_ = true;
     85    }
     86
    7387    void ArtificialController::searchRandomTargetPosition()
    7488    {
     
    7791    }
    7892
     93    void ArtificialController::setTarget(Pawn* target)
     94    {
     95        this->target_ = target;
     96
     97        if (target)
     98            this->targetPosition_ = target->getPosition();
     99    }
     100
    79101    void ArtificialController::searchNewTarget()
    80102    {
     
    87109        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
    88110        {
    89 //            if (it->getTeamNr() != this->getTeamNr())
     111            if (ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
     112                continue;
     113
    90114            if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity())
    91115            {
     
    147171        }
    148172    }
     173
     174    bool ArtificialController::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
     175    {
     176        if (entity1 == entity2)
     177            return true;
     178
     179        int team1 = -1;
     180        int team2 = -1;
     181
     182        if (entity1->getXMLController())
     183        {
     184            WaypointPatrolController* wpc = dynamic_cast<WaypointPatrolController*>(entity1->getXMLController());
     185            if (wpc)
     186                team1 = wpc->getTeam();
     187        }
     188        if (entity2->getXMLController())
     189        {
     190            WaypointPatrolController* wpc = dynamic_cast<WaypointPatrolController*>(entity2->getXMLController());
     191            if (wpc)
     192                team2 = wpc->getTeam();
     193        }
     194
     195        TeamDeathmatch* tdm = dynamic_cast<TeamDeathmatch*>(gametype);
     196        if (tdm)
     197        {
     198            if (entity1->getPlayer())
     199                team1 = tdm->getTeam(entity1->getPlayer());
     200
     201            if (entity2->getPlayer())
     202                team2 = tdm->getTeam(entity2->getPlayer());
     203        }
     204
     205        return (team1 == team2 && team1 != -1);
     206    }
    149207}
  • code/trunk/src/orxonox/objects/controllers/ArtificialController.h

    r2662 r3049  
    4747
    4848        protected:
    49             void moveToTargetPosition(float dt);
     49            void moveToPosition(const Vector3& target);
     50            void moveToTargetPosition();
     51
     52            void setTargetPosition(const Vector3& target);
    5053            void searchRandomTargetPosition();
     54
     55            void setTarget(Pawn* target);
    5156            void searchNewTarget();
    5257            void forgetTarget();
     
    5560            bool isCloseAtTarget(float distance) const;
    5661            bool isLookingAtTarget(float angle) const;
     62
     63            static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack
    5764
    5865            bool bHasTargetPosition_;
  • code/trunk/src/orxonox/objects/controllers/CMakeLists.txt

    r2839 r3049  
    55  AIController.cc
    66  ScriptController.cc
     7  WaypointController.cc
     8  WaypointPatrolController.cc
    79  PongAI.cc
    810)
  • code/trunk/src/orxonox/objects/gametypes/TeamDeathmatch.cc

    r3033 r3049  
    164164            if (pawn)
    165165            {
     166                pawn->setRadarObjectColour(this->teamcolours_[it_player->second]);
     167
    166168                std::set<WorldEntity*> pawnAttachments = pawn->getAttachedObjects();
    167169                for (std::set<WorldEntity*>::iterator it = pawnAttachments.begin(); it != pawnAttachments.end(); ++it)
  • code/trunk/src/orxonox/objects/gametypes/TeamDeathmatch.h

    r3033 r3049  
    5555            virtual void playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn);
    5656
     57            int getTeam(PlayerInfo* player);
     58
    5759            inline const ColourValue& getTeamColour(int teamnr) const
    5860                { return this->teamcolours_[teamnr]; }
     
    6163            virtual SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
    6264            bool pawnsAreInTheSameTeam(Pawn* pawn1, Pawn* pawn2);
    63             int getTeam(PlayerInfo* player);
    6465
    6566            std::map<PlayerInfo*, int> teamnumbers_;
  • code/trunk/src/orxonox/objects/worldentities/ControllableEntity.cc

    r3038 r3049  
    4040#include "objects/Scene.h"
    4141#include "objects/infos/PlayerInfo.h"
     42#include "objects/controllers/Controller.h"
    4243#include "objects/worldentities/Camera.h"
    4344#include "objects/worldentities/CameraPosition.h"
     
    6162        this->hud_ = 0;
    6263        this->camera_ = 0;
     64        this->xmlcontroller_ = 0;
    6365        this->bDestroyWhenPlayerLeft_ = false;
    6466        this->cameraPositionRootNode_ = this->node_->createChildSceneNode();
     
    9395                this->getPlayer()->stopControl();
    9496
     97            if (this->xmlcontroller_)
     98                delete this->xmlcontroller_;
     99
    95100            if (this->hud_)
    96101                delete this->hud_;
     
    115120
    116121        XMLPortObject(ControllableEntity, CameraPosition, "camerapositions", addCameraPosition, getCameraPosition, xmlelement, mode);
     122        XMLPortObject(ControllableEntity, Controller,     "controller",      setXMLController,  getXMLController,  xmlelement, mode);
    117123    }
    118124
     
    304310    }
    305311
     312    void ControllableEntity::setXMLController(Controller* controller)
     313    {
     314        if (!this->xmlcontroller_)
     315        {
     316            this->xmlcontroller_ = controller;
     317            this->bHasLocalController_ = true;
     318            this->xmlcontroller_->setControllableEntity(this);
     319        }
     320        else
     321            COUT(2) << "Warning: ControllableEntity \"" << this->getName() << "\" already has a Controller." << std::endl;
     322    }
     323
    306324    void ControllableEntity::parentChanged()
    307325    {
  • code/trunk/src/orxonox/objects/worldentities/ControllableEntity.h

    r3038 r3049  
    130130                { return this->mouseLookSpeed_; }
    131131
     132            inline Controller* getXMLController() const
     133                { return this->xmlcontroller_; }
     134
    132135        protected:
    133136            virtual void setPlayer(PlayerInfo* player); // don't call this directly, use friend class PlayerInfo instead
     
    142145
    143146        private:
     147            void setXMLController(Controller* controller);
     148
    144149            void overwrite();
    145150            void processOverwrite();
     
    188193            std::list<CameraPosition*> cameraPositions_;
    189194            std::string cameraPositionTemplate_;
     195            Controller* xmlcontroller_;
    190196    };
    191197}
  • code/trunk/src/util/Math.cc

    r2171 r3049  
    129129
    130130        float projectionlength = projection.length();
    131         if (projectionlength == 0) return orxonox::Vector2(0, 0);
     131        if (projectionlength == 0)
     132        {
     133            if (myposition.dotProduct(otherposition) >= 0)
     134                return orxonox::Vector2(0, 0);
     135            else
     136                return orxonox::Vector2(0, 1);
     137        }
     138
    132139        float angle = acos(clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1));
    133140
     
    161168
    162169        float projectionlength = projection.length();
    163         if (projectionlength == 0) return orxonox::Vector2(0, 0);
     170        if (projectionlength == 0)
     171        {
     172            if (myposition.dotProduct(otherposition) >= 0)
     173                return orxonox::Vector2(0, 0);
     174            else
     175                return orxonox::Vector2(0, 1);
     176        }
    164177        float angle = acos(clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1));
    165178
Note: See TracChangeset for help on using the changeset viewer.