Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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
File:
1 edited

Legend:

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