Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 6, 2008, 5:31:58 PM (17 years ago)
Author:
landauf
Message:

several improvements:

  • AI works properly now - add enemies with 'createEnemy x' where x is the number of enemies to add, default is 1. You can remove AI ships with 'killEnemies'.
  • Added new explosion (with smoke)
  • Added new projectile (with trail)
  • Added new thruster emitter
  • AI ships are destroyable - they start with 100 hp, each hit makes 15 hp damage, this value is configurable in the config-file: [Projectile] damage_
  • Added AI ship spawn and explosion effects
Location:
code/trunk/src/orxonox/objects
Files:
6 added
2 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/objects/Model.cc

    r1511 r1552  
    4545    CreateFactory(Model);
    4646
    47     Model::Model()
     47    Model::Model() : meshSrc_("")
    4848    {
    4949        RegisterObject(Model);
     
    5353    Model::~Model()
    5454    {
     55        if ((this->meshSrc_ != "") && (this->meshSrc_.size() > 0))
     56            this->detachObject(this->mesh_.getEntity());
    5557    }
    5658
  • code/trunk/src/orxonox/objects/Projectile.cc

    r1505 r1552  
    3535#include "core/Executor.h"
    3636#include "core/ConfigValueIncludes.h"
     37#include "particle/ParticleInterface.h"
    3738
    38 #include "SpaceShip.h"
    39 #include "Explosion.h"
     39#include "SpaceShipAI.h"
     40#include "ParticleSpawner.h"
    4041#include "Model.h"
    4142
    4243namespace orxonox
    4344{
    44     CreateFactory(Projectile);
     45    float Projectile::speed_ = 2000;
    4546
    46     float Projectile::speed_ = 0;
    47 
    48     Projectile::Projectile(SpaceShip* owner) :
    49       owner_(owner)
     47    Projectile::Projectile(SpaceShip* owner) : owner_(owner)
    5048    {
    5149        RegisterObject(Projectile);
    5250
    5351        this->setConfigValues();
    54 
    55         this->billboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1);
    56         this->attachObject(this->billboard_.getBillboardSet());
    57         this->scale(0.5);
     52        this->explosionTemplateName_ = "Orxonox/explosion1";
     53        this->smokeTemplateName_ = "Orxonox/smoke3";
    5854
    5955        if (this->owner_)
     
    6359            this->setPosition(this->owner_->getPosition());
    6460            this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL);
    65             this->setVelocity(Vector3(1, 0, 0) * this->speed_);
     61            this->setVelocity(this->owner_->getInitialDir() * this->speed_);
    6662        }
    6763
    6864        this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
    69 //        COUT(3) << this->classID << std::endl;
    7065    }
    7166
     
    7671    void Projectile::setConfigValues()
    7772    {
    78         SetConfigValue(lifetime_, 10.0).description("The time in seconds a projectile stays alive");
     73        SetConfigValue(damage_, 15.0).description("The damage caused by the projectile");
     74        SetConfigValue(lifetime_, 5.0).description("The time in seconds a projectile stays alive");
    7975        SetConfigValue(speed_, 2000.0).description("The speed of a projectile in units per second");
    8076
    81         this->setVelocity(Vector3(1, 0, 0) * this->speed_);
     77        this->setVelocity(this->owner_->getInitialDir() * this->speed_);
    8278    }
    8379
     
    9591                if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius))
    9692                {
    97                     Explosion *exp = new Explosion(this);
    98                     exp->create();
     93                    // hit
     94                    if (it->isA(Class(SpaceShipAI)))
     95                        ((SpaceShipAI*)(*it))->damage(this->damage_);
     96                    ParticleSpawner* explosion = new ParticleSpawner(this->explosionTemplateName_, 2.0);
     97                    explosion->setPosition(this->getPosition());
     98                    explosion->create();
     99                    ParticleSpawner* smoke = new ParticleSpawner(this->smokeTemplateName_, 6.0, 0.0);
     100                    smoke->setPosition(this->getPosition());
     101                    smoke->getParticleInterface()->setSpeedFactor(3.0);
     102                    smoke->create();
    99103                    delete this;
    100104                    return;
     
    108112        delete this;
    109113    }
    110 
    111     void Projectile::setColour(const ColourValue& colour)
    112     {
    113         this->billboard_.getBillboardSet()->getBillboard(0)->setColour(colour);
    114     }
    115114}
  • code/trunk/src/orxonox/objects/Projectile.h

    r1505 r1552  
    3333
    3434#include "WorldEntity.h"
    35 #include "../tools/BillboardSet.h"
    36 #include "../tools/Timer.h"
    37 #include "util/Math.h"
     35#include "tools/Timer.h"
    3836
    3937namespace orxonox
     
    4240    {
    4341        public:
    44             Projectile(SpaceShip* owner = 0);
    4542            virtual ~Projectile();
    4643            void setConfigValues();
    4744            void destroyObject();
    4845            virtual void tick(float dt);
    49             virtual bool create(){return WorldEntity::create();}
    50             void setColour(const ColourValue& colour);
    5146
    5247            static float getSpeed()
     
    5449
    5550        protected:
     51            Projectile(SpaceShip* owner = 0);
    5652            SpaceShip* owner_;
    5753
    5854        private:
    59             BillboardSet billboard_;
     55            std::string explosionTemplateName_;
     56            std::string smokeTemplateName_;
    6057            static float speed_;
    6158            float lifetime_;
     59            float damage_;
    6260            Timer<Projectile> destroyTimer_;
    6361    };
  • code/trunk/src/orxonox/objects/RotatingProjectile.cc

    r1505 r1552  
    3737    CreateFactory(RotatingProjectile);
    3838
    39     RotatingProjectile::RotatingProjectile(SpaceShip* owner) : Projectile(owner)
     39    RotatingProjectile::RotatingProjectile(SpaceShip* owner) : BillboardProjectile(owner)
    4040    {
    4141        RegisterObject(RotatingProjectile);
  • code/trunk/src/orxonox/objects/RotatingProjectile.h

    r1505 r1552  
    22#define _RotatingProjectile_H__
    33
    4 #include "../OrxonoxPrereqs.h"
     4#include "OrxonoxPrereqs.h"
    55#include "util/Math.h"
    6 #include "Projectile.h"
     6#include "BillboardProjectile.h"
    77
    88namespace orxonox
    99{
    10     class _OrxonoxExport RotatingProjectile : public Projectile/*, public network::Synchronisable*/
     10    class _OrxonoxExport RotatingProjectile : public BillboardProjectile
    1111    {
    1212        public:
     
    1515            void setConfigValues();
    1616            virtual void tick(float dt);
    17             virtual bool create(){return Projectile::create();}
    1817
    1918        private:
  • code/trunk/src/orxonox/objects/SpaceShip.cc

    r1535 r1552  
    4444#include "core/input/InputManager.h"
    4545#include "particle/ParticleInterface.h"
    46 #include "Projectile.h"
    4746#include "RotatingProjectile.h"
     47#include "ParticleProjectile.h"
    4848#include "core/XMLPort.h"
    4949#include "core/ConsoleCommand.h"
     
    6969    SpaceShip* SpaceShip::instance_s;
    7070
    71    
     71
    7272    SpaceShip *SpaceShip::getLocalShip(){
    7373      Iterator<SpaceShip> it;
     
    8888      cam_(0),
    8989      camName_("CamNode"),
    90       tt_(0),
     90      tt1_(0),
     91      tt2_(0),
    9192      redNode_(0),
    9293      greenNode_(0),
     
    111112      mouseX_(0.0f),
    112113      mouseY_(0.0f),
    113       emitterRate_(0.0f),
    114114      myShip_(false),
    115115      teamNr_(0),
     
    138138    SpaceShip::~SpaceShip()
    139139    {
    140         if (this->tt_)
    141             delete this->tt_;
     140        if (this->tt1_)
     141            delete this->tt1_;
     142        if (this->tt2_)
     143            delete this->tt2_;
    142144        if(setMouseEventCallback_)
    143145          InputManager::removeMouseHandler("SpaceShip");
     
    180182    {
    181183        // START CREATING THRUSTER
    182         this->tt_ = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow");
    183         this->tt_->getParticleSystem()->setParameter("local_space","true");
    184         this->tt_->newEmitter();
    185 /*
    186         this->tt_->setDirection(Vector3(0,0,1));
    187         this->tt_->setPositionOfEmitter(0, Vector3(20,-1,-15));
    188         this->tt_->setPositionOfEmitter(1, Vector3(-20,-1,-15));
    189 */
    190         this->tt_->setDirection(Vector3(-1,0,0));
    191         this->tt_->setPositionOfEmitter(0, Vector3(-15,20,-1));
    192         this->tt_->setPositionOfEmitter(1, Vector3(-15,-20,-1));
    193         this->tt_->setVelocity(50);
    194 
    195         emitterRate_ = tt_->getRate();
    196 
    197         Ogre::SceneNode* node2 = this->getNode()->createChildSceneNode(this->getName() + "particle2");
    198         node2->setInheritScale(false);
    199         tt_->addToSceneNode(node2);
     184        this->tt1_ = new ParticleInterface("Orxonox/thruster1");
     185        this->tt1_->createNewEmitter();
     186        this->tt1_->getAllEmitters()->setDirection(-this->getInitialDir());
     187        this->tt1_->getEmitter(0)->setPosition(Vector3(-15, 20, -1));
     188        this->tt1_->getEmitter(1)->setPosition(Vector3(-15, -20, -1));
     189        this->tt1_->setSpeedFactor(3.0);
     190
     191        Ogre::SceneNode* node2a = this->getNode()->createChildSceneNode(this->getName() + "particle2a");
     192        node2a->setInheritScale(false);
     193        node2a->setScale(1, 1, 1);
     194        tt1_->addToSceneNode(node2a);
     195
     196        this->tt2_ = new ParticleInterface("Orxonox/thruster2");
     197        this->tt2_->createNewEmitter();
     198        this->tt2_->getAllEmitters()->setDirection(Vector3(-1, 0, 0));
     199        this->tt2_->getEmitter(0)->setPosition(Vector3(-30, 40, -2));
     200        this->tt2_->getEmitter(1)->setPosition(Vector3(-30, -40, -2));
     201
     202        Ogre::SceneNode* node2b = this->getNode()->createChildSceneNode(this->getName() + "particle2b");
     203        node2b->setInheritScale(false);
     204        node2b->setScale(0.5, 0.5, 0.5);
     205        tt2_->addToSceneNode(node2b);
    200206        // END CREATING THRUSTER
    201207
     
    266272      this->camNode_ = this->getNode()->createChildSceneNode(camName_);
    267273      COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl;
    268       this->camNode_->setPosition(Vector3(-50,0,10));
     274      this->camNode_->setPosition(Vector3(-25,0,5));
    269275//      Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0));
    270276//      Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1));
     
    339345    }
    340346
    341     Vector3 SpaceShip::getDir() {
    342         return currentDir_;
    343     }
    344 
    345     Vector3 SpaceShip::getOrth(){
    346         return currentOrth_;
    347     }
    348 
    349     float SpaceShip::getMaxSpeed() { return maxSpeed_; }
    350 
    351347    void SpaceShip::tick(float dt)
    352348    {
     
    374370        {
    375371
    376             Projectile *p;
    377             if (this->isExactlyA(Class(SpaceShip)))
    378                 p = new RotatingProjectile(this);
    379             else
    380                 p = new Projectile(this);
    381             p->setColour(this->getProjectileColour());
    382             p->create();
    383             if(p->classID==0)
     372            BillboardProjectile* projectile = new ParticleProjectile(this);
     373            projectile->setColour(this->getProjectileColour());
     374            projectile->create();
     375            if (projectile->classID == 0)
     376            {
    384377              COUT(3) << "generated projectile with classid 0" <<  std::endl; // TODO: remove this output
    385 
    386             p->setBacksync(true);
     378            }
     379
     380            projectile->setBacksync(true);
    387381            this->timeToReload_ = this->reloadTime_;
    388382        }
     
    464458
    465459        if (this->acceleration_.x > 0)
    466             this->tt_->setRate(emitterRate_);
     460        {
     461            this->tt1_->setEnabled(true);
     462            this->tt2_->setEnabled(true);
     463        }
    467464        else
    468             this->tt_->setRate(0);
     465        {
     466            this->tt1_->setEnabled(false);
     467            this->tt2_->setEnabled(false);
     468        }
    469469
    470470        if( myShip_ )
  • code/trunk/src/orxonox/objects/SpaceShip.h

    r1535 r1552  
    4343    {
    4444        public:
    45          
    46 
    4745            static SpaceShip *getLocalShip();
    4846
     
    6664            void getFocus();
    6765
     66            inline float getMaxSpeed() const
     67                { return this->maxSpeed_; }
     68            inline float getMaxSideAndBackSpeed() const
     69                { return this->maxSideAndBackSpeed_; }
     70            inline float getMaxRotation() const
     71                { return this->maxRotation_; }
     72            inline float getTransAcc() const
     73                { return this->translationAcceleration_; }
     74            inline float getRotAcc() const
     75                { return this->rotationAcceleration_; }
     76            inline float getTransDamp() const
     77                { return this->translationDamping_; }
     78            inline float getRotDamp() const
     79                { return this->rotationDamping_; }
     80
    6881            static std::string whereAmI();
    6982            static void setMaxSpeedTest(float value)
     
    8396            void doFire();
    8497
    85             float getMaxSpeed();
    86             Vector3 getDir();
    87             Vector3 getOrth();
     98            inline const Vector3& getDir() const
     99                { return this->currentDir_; }
     100            inline const Vector3& getInitialDir() const
     101                { return this->initialDir_; }
     102            inline const Vector3& getOrth() const
     103                { return this->currentOrth_; }
     104            inline const Vector3& getInitialOrth() const
     105                { return this->initialOrth_; }
     106
    88107            Camera* getCamera();
    89108
    90109            int getTeamNr() const
    91110                { return this->teamNr_; }
    92             int getHealth() const
     111            float getHealth() const
    93112                { return this->health_; }
    94113
     
    118137            std::string camName_;
    119138
    120 
    121             ParticleInterface* tt_;
     139            ParticleInterface* tt1_;
     140            ParticleInterface* tt2_;
    122141
    123142            BillboardSet redBillboard_;
     
    153172            float mouseY_;
    154173
    155             float emitterRate_;
    156 
    157174        protected:
    158175            bool myShip_;
    159176
    160177            int teamNr_;
    161             int health_;
     178            float health_;
    162179
    163180            static SpaceShip* instance_s;
  • code/trunk/src/orxonox/objects/SpaceShipAI.cc

    r1505 r1552  
    3232#include <OgreMath.h>
    3333#include "Projectile.h"
     34#include "ParticleSpawner.h"
    3435#include "core/CoreIncludes.h"
    3536#include "core/Iterator.h"
     
    3738#include "core/ConsoleCommand.h"
    3839#include "core/XMLPort.h"
     40#include "particle/ParticleInterface.h"
    3941
    4042#define ACTION_INTERVAL 1.0f
     
    5153        RegisterObject(SpaceShipAI);
    5254
    53         this->alive_ = true;
    54         this->setPosition(Vector3(rnd(-1000, 1000), rnd(-1000, 1000), rnd(-1000, 0000)));
    5555        this->target_ = 0;
    5656        this->bShooting_ = 0;
     
    7070    }
    7171
     72    SpaceShipAI::~SpaceShipAI()
     73    {
     74        for (Iterator<SpaceShipAI> it = ObjectList<SpaceShipAI>::begin(); it; ++it)
     75            it->shipDied(this);
     76    }
     77
    7278    void SpaceShipAI::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    7379    {
    7480        SpaceShip::XMLPort(xmlelement, mode);
    75         myShip_=true;
    76 
     81
     82        this->myShip_=true;
    7783        this->actionTimer_.setTimer(ACTION_INTERVAL, true, this, createExecutor(createFunctor(&SpaceShipAI::action)));
    7884    }
     
    8591            newenemy->setMesh("assff.mesh");
    8692//            newenemy->setPosition(0, 0, 0);
     93            newenemy->setPosition(Vector3(rnd(-3000, 3000), rnd(-3000, 3000), rnd(-3000, 3000)));
    8794            newenemy->setScale(10);
    8895            newenemy->setMaxSpeed(500);
     
    95102            Element xmlelement;
    96103            newenemy->XMLPort(xmlelement, XMLPort::LoadObject);
     104
     105            ParticleSpawner* spawneffect = new ParticleSpawner("Orxonox/fairytwirl", 2.0, 0.0, newenemy->getOrth());
     106            spawneffect->setPosition(newenemy->getPosition() - newenemy->getOrth() * 50);
     107            spawneffect->create();
    97108        }
    98109    }
     
    103114        for (Iterator<SpaceShipAI> it = ObjectList<SpaceShipAI>::begin(); it; )
    104115        {
    105             delete *(it++);
    106             ++i;
     116            (it++)->kill();
    107117            if (num && i >= num)
    108118                break;
     
    122132        // search enemy
    123133        random = rnd(maxrand);
    124 //std::cout << "search enemy: " << random << std::endl;
    125134        if (random < 20 && (!this->target_))
    126         {
    127135            this->searchNewTarget();
    128         }
    129136
    130137        // forget enemy
    131138        random = rnd(maxrand);
    132 //std::cout << "forget enemy: " << random << std::endl;
    133139        if (random < 5 && (this->target_))
    134         {
    135140            this->forgetTarget();
    136         }
    137141
    138142        // next enemy
    139143        random = rnd(maxrand);
    140 //std::cout << "next enemy: " << random << std::endl;
    141144        if (random < 10 && (this->target_))
    142         {
    143145            this->searchNewTarget();
    144         }
    145146
    146147        // fly somewhere
    147148        random = rnd(maxrand);
    148 //std::cout << "fly somewhere: " << random << std::endl;
    149149        if (random < 40 && (!this->bHasTargetPosition_ && !this->target_))
    150         {
    151150            this->searchNewTargetPosition();
    152         }
    153151
    154152        // stop flying
    155153        random = rnd(maxrand);
    156 //std::cout << "stop flying: " << random << std::endl;
    157154        if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
    158         {
    159155            this->bHasTargetPosition_ = false;
    160         }
    161156
    162157        // fly somewhere else
    163158        random = rnd(maxrand);
    164 //std::cout << "fly somewhere else: " << random << std::endl;
    165159        if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
    166         {
    167160            this->searchNewTargetPosition();
    168         }
    169161
    170162        // shoot
    171163        random = rnd(maxrand);
    172 //std::cout << "shoot: " << random << std::endl;
    173164        if (random < 75 && (this->target_ && !this->bShooting_))
    174         {
    175165            this->bShooting_ = true;
    176         }
    177166
    178167        // stop shooting
    179168        random = rnd(maxrand);
    180 //std::cout << "stop shooting: " << random << std::endl;
    181169        if (random < 25 && (this->bShooting_))
    182         {
    183170            this->bShooting_ = false;
    184         }
     171    }
     172
     173    void SpaceShipAI::damage(float damage)
     174    {
     175        this->health_ -= damage;
     176        if (this->health_ <= 0)
     177        {
     178            this->kill();
     179            SpaceShipAI::createEnemy(1);
     180        }
     181    }
     182
     183    void SpaceShipAI::kill()
     184    {
     185        ParticleSpawner* explosion = new ParticleSpawner("Orxonox/BigExplosion1part1", 3.0);
     186        explosion->setPosition(this->getPosition());
     187        explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true);
     188        explosion->setScale(4);
     189        explosion->create();
     190
     191        explosion = new ParticleSpawner("Orxonox/BigExplosion1part2", 3.0);
     192        explosion->setPosition(this->getPosition());
     193        explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true);
     194        explosion->setScale(4);
     195        explosion->create();
     196
     197        Vector3 ringdirection = Vector3(rnd(), rnd(), rnd());
     198        ringdirection.normalise();
     199        explosion = new ParticleSpawner("Orxonox/BigExplosion1part3", 3.0, 0.5, ringdirection);
     200        explosion->setPosition(this->getPosition());
     201        explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true);
     202        explosion->setScale(4);
     203        explosion->create();
     204
     205        delete this;
    185206    }
    186207
     
    193214            this->moveToTargetPosition(dt);
    194215
    195         if (this->bShooting_ && this->isCloseAtTarget(2000) && this->isLookingAtTarget(Ogre::Math::PI / 10.0f))
     216        if (this->bShooting_ && this->isCloseAtTarget(2500) && this->isLookingAtTarget(Ogre::Math::PI / 10))
    196217            this->doFire();
    197218
     
    201222    void SpaceShipAI::moveToTargetPosition(float dt)
    202223    {
    203         static Radian RadianZERO(0);
    204 
    205 //        float dotprod = (this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(this->targetPosition_ - this->getPosition());
    206         Quaternion rotation = (this->getOrientation() * Ogre::Vector3::UNIT_X).getRotationTo(this->targetPosition_ - this->getPosition());
    207 /*
    208 std::cout << "scalprod: " << dotprod << std::endl;
    209 std::cout << "dist: " << this->targetPosition_ - this->getPosition() << std::endl;
    210 std::cout << "yaw: " << rotation.getYaw().valueRadians() << std::endl;
    211 std::cout << "pitch: " << rotation.getPitch().valueRadians() << std::endl;
    212 std::cout << "roll: " << rotation.getRoll().valueRadians() << std::endl;
    213 */
    214         this->setMoveYaw(-rotation.getRoll().valueRadians());
    215         this->setMovePitch(rotation.getYaw().valueRadians());
    216 
    217         if ((this->targetPosition_ - this->getPosition()).length() > 100)
    218         {
     224        Vector3 proj = Ogre::Plane(this->getDir(), this->getPosition()).projectVector(this->targetPosition_ - this->getPosition());
     225        float angle = acos((this->getOrth().dotProduct(proj)) / (this->getOrth().length()*proj.length()));
     226
     227        if ((this->getDir().crossProduct(this->getOrth())).dotProduct(this->targetPosition_ - this->getPosition()) > 0)
     228            this->setMoveYaw(sgn(sin(angle)));
     229        else
     230            this->setMoveYaw(-sgn(sin(angle)));
     231        this->setMovePitch(sgn(cos(angle)));
     232
     233        if ((this->targetPosition_ - this->getPosition()).length() > 300)
    219234            this->setMoveLongitudinal(1);
    220         }
    221 
     235
     236        if (this->isCloseAtTarget(300) && this->target_)
     237        {
     238            if (this->getVelocity().length() > this->target_->getVelocity().length())
     239                this->setMoveLongitudinal(-1);
     240        }
    222241    }
    223242
     
    241260                Vector3 distanceNew = it->getPosition() - this->getPosition();
    242261                if (!this->target_ || it->getPosition().squaredDistance(this->getPosition()) * (1.5f + acos((this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(distanceNew) / speed / distanceNew.length()) / (2 * Ogre::Math::PI))
    243                         < this->targetPosition_.squaredDistance(this->getPosition()) * (1.5f + acos((this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / (2 * Ogre::Math::PI)))
     262                        < this->targetPosition_.squaredDistance(this->getPosition()) * (1.5f + acos((this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / (2 * Ogre::Math::PI)) + rnd(-250, 250))
    244263                {
    245264                    this->target_ = (*it);
     
    248267            }
    249268        }
    250    }
     269    }
    251270
    252271    void SpaceShipAI::forgetTarget()
     
    260279        if (!this->target_)
    261280            return;
    262 /*
     281
    263282        Vector3 enemymovement = this->target_->getVelocity();
    264283        Vector3 distance_normalised = this->target_->getPosition() - this->getPosition();
     
    267286        float scalarprod = enemymovement.dotProduct(distance_normalised);
    268287        float aimoffset = scalarprod*scalarprod + Projectile::getSpeed() * Projectile::getSpeed() - this->target_->getVelocity().squaredLength();
     288
    269289        if (aimoffset < 0)
    270290        {
     
    273293        }
    274294        aimoffset = -scalarprod + sqrt(aimoffset);
    275         this->targetPosition_ = enemymovement + distance_normalised * aimoffset;
     295        this->targetPosition_ = this->getPosition() + enemymovement + distance_normalised * aimoffset;
    276296        this->bHasTargetPosition_ = true;
    277 
    278         std::cout << "targetpos: " << this->targetPosition_ << std::endl;
    279 */
    280         this->targetPosition_ = this->target_->getPosition();
    281         this->bHasTargetPosition_ = true;
    282297    }
    283298
    284299    bool SpaceShipAI::isCloseAtTarget(float distance)
    285300    {
    286         return (this->getPosition().squaredDistance(this->targetPosition_) < distance*distance);
     301        if (!this->target_)
     302            return (this->getPosition().squaredDistance(this->targetPosition_) < distance*distance);
     303        else
     304            return (this->getPosition().squaredDistance(this->target_->getPosition()) < distance*distance);
    287305    }
    288306
    289307    bool SpaceShipAI::isLookingAtTarget(float angle)
    290308    {
    291         return (this->getOrientation() * Ogre::Vector3::UNIT_X).directionEquals(this->targetPosition_ - this->getPosition(), Radian(angle));
     309        Vector3 dist = this->targetPosition_ - this->getPosition();
     310        return (acos((this->getDir().dotProduct(dist)) / (dist.length() * this->getDir().length())) < angle);
     311    }
     312
     313    void SpaceShipAI::shipDied(SpaceShipAI* ship)
     314    {
     315        this->forgetTarget();
     316        this->searchNewTargetPosition();
    292317    }
    293318}
  • code/trunk/src/orxonox/objects/SpaceShipAI.h

    r1505 r1552  
    4444        public:
    4545            SpaceShipAI();
     46            virtual ~SpaceShipAI();
     47
    4648            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4749            static void createEnemy(int num);
    4850            static void killEnemies(int num);
     51            void shipDied(SpaceShipAI* ship);
     52            void damage(float damage);
     53            void kill();
    4954
    5055        private:
     
    6469            Timer<SpaceShipAI> actionTimer_;
    6570
    66             bool alive_;
    6771            bool bHasTargetPosition_;
    6872            Vector3 targetPosition_;
  • code/trunk/src/orxonox/objects/WorldEntity.cc

    r1505 r1552  
    6666        }
    6767    }
    68    
     68
    6969
    7070    WorldEntity::~WorldEntity()
    7171    {
    72       // just to make sure we clean out all scene nodes
    73       if(this->getNode())
    74         this->getNode()->removeAndDestroyAllChildren();
     72        // just to make sure we clean out all scene nodes
     73        if(this->getNode())
     74        {
     75            this->getNode()->removeAndDestroyAllChildren();
     76            GraphicsEngine::getSingleton().getSceneManager()->destroySceneNode(this->getName());
     77        }
    7578    }
    7679
     
    9598        create();
    9699    }
    97    
     100
    98101
    99102    void WorldEntity::setYawPitchRoll(const Degree& yaw, const Degree& pitch, const Degree& roll)
     
    122125
    123126        XMLPortObject(WorldEntity, WorldEntity, "attached", attachWorldEntity, getAttachedWorldEntity, xmlelement, mode, false, true);
    124        
     127
    125128        WorldEntity::create();
    126129    }
Note: See TracChangeset for help on using the changeset viewer.