Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 1, 2008, 1:10:46 AM (17 years ago)
Author:
rgrieder
Message:

SVN doesn't seem to like me. Reverted some really badly converted line endings.

Location:
code/branches/network/src/orxonox/objects
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/orxonox/objects/Camera.h

    r1494 r1495  
    1 /* *   ORXONOX - the hottest 3D action shooter ever to exist *                    > www.orxonox.net < * * *   License notice: * *   This program is free software; you can redistribute it and/or *   modify it under the terms of the GNU General Public License *   as published by the Free Software Foundation; either version 2 *   of the License, or (at your option) any later version. * *   This program is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY; without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *   GNU General Public License for more details. * *   You should have received a copy of the GNU General Public License *   along with this program; if not, write to the Free Software *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. * *   Author: *      Fabian 'x3n' Landau *   Co-authors: *      Benjamin Knecht * */#ifndef _Camera_H__#define _Camera_H__#include <OgrePrerequisites.h>#include <OgreSceneNode.h>#include <OgreCamera.h>#include "OrxonoxPrereqs.h"namespace orxonox{    class _OrxonoxExport Camera    {      friend class CameraHandler;      public:        Camera(Ogre::SceneNode* node = NULL);        virtual ~Camera();        void setPositionNode(Ogre::SceneNode* node);        inline Ogre::SceneNode* getCameraNode() { return this->positionNode_; }        // maybe also BaseObject        void setTargetNode(Ogre::SceneNode* obj);
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Fabian 'x3n' Landau
     24 *   Co-authors:
     25 *      Benjamin Knecht
     26 *
     27 */
     28
     29#ifndef _Camera_H__
     30#define _Camera_H__
     31
     32#include <OgrePrerequisites.h>
     33#include <OgreSceneNode.h>
     34#include <OgreCamera.h>
     35
     36#include "OrxonoxPrereqs.h"
     37
     38namespace orxonox
     39{
     40    class _OrxonoxExport Camera
     41    {
     42      friend class CameraHandler;
     43      public:
     44        Camera(Ogre::SceneNode* node = NULL);
     45        virtual ~Camera();
     46
     47        void setPositionNode(Ogre::SceneNode* node);
     48        inline Ogre::SceneNode* getCameraNode() { return this->positionNode_; }
     49        // maybe also BaseObject
     50        void setTargetNode(Ogre::SceneNode* obj);
     51
    252        Ogre::Camera* cam_;
    3         void tick(float dt);        void update();        inline bool hasFocus() { return this->bHasFocus_; }      private:        void removeFocus();        void setFocus(Ogre::Camera* ogreCam);      private:        Ogre::SceneNode* targetNode_;        Ogre::SceneNode* positionNode_;        Ogre::SceneNode* cameraNode_;        Ogre::Vector3 oldPos;        bool bHasFocus_;    };}#endif /* _Camera_H__ */
     53
     54        void tick(float dt);
     55        void update();
     56        inline bool hasFocus() { return this->bHasFocus_; }
     57
     58      private:
     59        void removeFocus();
     60        void setFocus(Ogre::Camera* ogreCam);
     61
     62      private:
     63        Ogre::SceneNode* targetNode_;
     64        Ogre::SceneNode* positionNode_;
     65        Ogre::SceneNode* cameraNode_;
     66        Ogre::Vector3 oldPos;
     67        bool bHasFocus_;
     68    };
     69}
     70
     71#endif /* _Camera_H__ */
  • code/branches/network/src/orxonox/objects/SpaceShipAI.cc

    r1494 r1495  
    1 /* *   ORXONOX - the hottest 3D action shooter ever to exist *                    > www.orxonox.net < * * *   License notice: * *   This program is free software; you can redistribute it and/or *   modify it under the terms of the GNU General Public License *   as published by the Free Software Foundation; either version 2 *   of the License, or (at your option) any later version. * *   This program is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY; without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *   GNU General Public License for more details. * *   You should have received a copy of the GNU General Public License *   along with this program; if not, write to the Free Software *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. * *   Author: *      Fabian 'x3n' Landau *   Co-authors: *      ... * */#include "OrxonoxStableHeaders.h"
    2 #include "SpaceShipAI.h"#include <OgreMath.h>#include "Projectile.h"#include "core/CoreIncludes.h"#include "core/Iterator.h"#include "core/Executor.h"#include "core/ConsoleCommand.h"#include "core/XMLPort.h"#define ACTION_INTERVAL 1.0fnamespace orxonox{    SetConsoleCommand(SpaceShipAI, createEnemy, true).setDefaultValue(0, 1);    SetConsoleCommand(SpaceShipAI, killEnemies, true).setDefaultValue(0, 0);    CreateFactory(SpaceShipAI);    SpaceShipAI::SpaceShipAI()    {        RegisterObject(SpaceShipAI);        this->alive_ = true;        this->setPosition(Vector3(rnd(-1000, 1000), rnd(-1000, 1000), rnd(-1000, 0000)));        this->target_ = 0;        this->bShooting_ = 0;        this->bHasTargetPosition_ = false;        this->setTeamNr((int)rnd(NUM_AI_TEAMS) % NUM_AI_TEAMS + 1);        if (NUM_AI_TEAMS > 0)            this->teamColours_[1] = ColourValue(1, 0, 0, 1);        if (NUM_AI_TEAMS > 1)            this->teamColours_[2] = ColourValue(0, 1, 0, 1);        if (NUM_AI_TEAMS > 2)            this->teamColours_[3] = ColourValue(0, 0, 1, 1);        for (int i = 4; i <= NUM_AI_TEAMS; ++i)            this->teamColours_[i] = ColourValue(rnd(), rnd(), rnd(), 1);    }    void SpaceShipAI::XMLPort(Element& xmlelement, XMLPort::Mode mode)    {        SpaceShip::XMLPort(xmlelement, mode);        myShip_=true;        this->actionTimer_.setTimer(ACTION_INTERVAL, true, this, createExecutor(createFunctor(&SpaceShipAI::action)));    }    void SpaceShipAI::createEnemy(int num)    {        for (int i = 0; i < num; ++i)        {            SpaceShipAI* newenemy = new SpaceShipAI();            newenemy->setMesh("assff.mesh");//            newenemy->setPosition(0, 0, 0);            newenemy->setScale(10);            newenemy->setMaxSpeed(500);            newenemy->setMaxSideAndBackSpeed(50);            newenemy->setMaxRotation(1.0);            newenemy->setTransAcc(200);            newenemy->setRotAcc(3.0);            newenemy->setTransDamp(75);            newenemy->setRotDamp(1.0);            Element xmlelement;            newenemy->XMLPort(xmlelement, XMLPort::LoadObject);        }    }    void SpaceShipAI::killEnemies(int num)    {        int i = 0;        for (Iterator<SpaceShipAI> it = ObjectList<SpaceShipAI>::begin(); it; )        {            delete *(it++);            ++i;            if (num && i >= num)                break;        }    }    ColourValue SpaceShipAI::getProjectileColour() const    {        return this->teamColours_[this->getTeamNr()];    }    void SpaceShipAI::action()    {        float random;        float maxrand = 100.0f / ACTION_INTERVAL;        // search enemy        random = rnd(maxrand);//std::cout << "search enemy: " << random << std::endl;        if (random < 20 && (!this->target_))        {            this->searchNewTarget();        }        // forget enemy        random = rnd(maxrand);//std::cout << "forget enemy: " << random << std::endl;        if (random < 5 && (this->target_))        {            this->forgetTarget();        }        // next enemy        random = rnd(maxrand);//std::cout << "next enemy: " << random << std::endl;        if (random < 10 && (this->target_))        {            this->searchNewTarget();        }        // fly somewhere        random = rnd(maxrand);//std::cout << "fly somewhere: " << random << std::endl;        if (random < 40 && (!this->bHasTargetPosition_ && !this->target_))        {            this->searchNewTargetPosition();        }        // stop flying        random = rnd(maxrand);//std::cout << "stop flying: " << random << std::endl;        if (random < 10 && (this->bHasTargetPosition_ && !this->target_))        {            this->bHasTargetPosition_ = false;        }        // fly somewhere else        random = rnd(maxrand);//std::cout << "fly somewhere else: " << random << std::endl;        if (random < 30 && (this->bHasTargetPosition_ && !this->target_))        {            this->searchNewTargetPosition();        }        // shoot        random = rnd(maxrand);//std::cout << "shoot: " << random << std::endl;        if (random < 75 && (this->target_ && !this->bShooting_))        {            this->bShooting_ = true;        }        // stop shooting        random = rnd(maxrand);//std::cout << "stop shooting: " << random << std::endl;        if (random < 25 && (this->bShooting_))        {            this->bShooting_ = false;        }    }    void SpaceShipAI::tick(float dt)    {        if (this->target_)            this->aimAtTarget();        if (this->bHasTargetPosition_)            this->moveToTargetPosition(dt);        if (this->bShooting_ && this->isCloseAtTarget(2000) && this->isLookingAtTarget(Ogre::Math::PI / 10.0f))            this->doFire();        SpaceShip::tick(dt);    }    void SpaceShipAI::moveToTargetPosition(float dt)    {        static Radian RadianZERO(0);//        float dotprod = (this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(this->targetPosition_ - this->getPosition());        Quaternion rotation = (this->getOrientation() * Ogre::Vector3::UNIT_X).getRotationTo(this->targetPosition_ - this->getPosition());/*std::cout << "scalprod: " << dotprod << std::endl;std::cout << "dist: " << this->targetPosition_ - this->getPosition() << std::endl;std::cout << "yaw: " << rotation.getYaw().valueRadians() << std::endl;std::cout << "pitch: " << rotation.getPitch().valueRadians() << std::endl;std::cout << "roll: " << rotation.getRoll().valueRadians() << std::endl;*/        this->setMoveYaw(-rotation.getRoll().valueRadians());        this->setMovePitch(rotation.getYaw().valueRadians());        if ((this->targetPosition_ - this->getPosition()).length() > 100)        {            this->setMoveLongitudinal(1);        }    }    void SpaceShipAI::searchNewTargetPosition()    {        this->targetPosition_ = Vector3(rnd(-5000,5000), rnd(-5000,5000), rnd(-5000,5000));        this->bHasTargetPosition_ = true;    }    void SpaceShipAI::searchNewTarget()    {        this->targetPosition_ = this->getPosition();        this->forgetTarget();        for (Iterator<SpaceShip> it = ObjectList<SpaceShip>::begin(); it; ++it)        {            if (it->getTeamNr() != this->getTeamNr())            {                float speed = this->getVelocity().length();                Vector3 distanceCurrent = this->targetPosition_ - this->getPosition();                Vector3 distanceNew = it->getPosition() - this->getPosition();                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))                        < this->targetPosition_.squaredDistance(this->getPosition()) * (1.5f + acos((this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / (2 * Ogre::Math::PI)))                {                    this->target_ = (*it);                    this->targetPosition_ = it->getPosition();                }            }        }   }    void SpaceShipAI::forgetTarget()    {        this->target_ = 0;        this->bShooting_ = false;    }    void SpaceShipAI::aimAtTarget()    {        if (!this->target_)            return;/*        Vector3 enemymovement = this->target_->getVelocity();        Vector3 distance_normalised = this->target_->getPosition() - this->getPosition();        distance_normalised.normalise();        float scalarprod = enemymovement.dotProduct(distance_normalised);        float aimoffset = scalarprod*scalarprod + Projectile::getSpeed() * Projectile::getSpeed() - this->target_->getVelocity().squaredLength();        if (aimoffset < 0)        {            this->bHasTargetPosition_ = false;            return;        }        aimoffset = -scalarprod + sqrt(aimoffset);        this->targetPosition_ = enemymovement + distance_normalised * aimoffset;        this->bHasTargetPosition_ = true;        std::cout << "targetpos: " << this->targetPosition_ << std::endl;*/        this->targetPosition_ = this->target_->getPosition();        this->bHasTargetPosition_ = true;    }    bool SpaceShipAI::isCloseAtTarget(float distance)    {        return (this->getPosition().squaredDistance(this->targetPosition_) < distance*distance);    }    bool SpaceShipAI::isLookingAtTarget(float angle)    {        return (this->getOrientation() * Ogre::Vector3::UNIT_X).directionEquals(this->targetPosition_ - this->getPosition(), Radian(angle));    }}
     1/*
     2 *   ORXONOX - the hottest 3D action shooter ever to exist
     3 *                    > www.orxonox.net <
     4 *
     5 *
     6 *   License notice:
     7 *
     8 *   This program is free software; you can redistribute it and/or
     9 *   modify it under the terms of the GNU General Public License
     10 *   as published by the Free Software Foundation; either version 2
     11 *   of the License, or (at your option) any later version.
     12 *
     13 *   This program is distributed in the hope that it will be useful,
     14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 *   GNU General Public License for more details.
     17 *
     18 *   You should have received a copy of the GNU General Public License
     19 *   along with this program; if not, write to the Free Software
     20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     21 *
     22 *   Author:
     23 *      Fabian 'x3n' Landau
     24 *   Co-authors:
     25 *      ...
     26 *
     27 */
     28
     29#include "OrxonoxStableHeaders.h"
     30#include "SpaceShipAI.h"
     31
     32#include <OgreMath.h>
     33#include "Projectile.h"
     34#include "core/CoreIncludes.h"
     35#include "core/Iterator.h"
     36#include "core/Executor.h"
     37#include "core/ConsoleCommand.h"
     38#include "core/XMLPort.h"
     39
     40#define ACTION_INTERVAL 1.0f
     41
     42namespace orxonox
     43{
     44    SetConsoleCommand(SpaceShipAI, createEnemy, true).setDefaultValue(0, 1);
     45    SetConsoleCommand(SpaceShipAI, killEnemies, true).setDefaultValue(0, 0);
     46
     47    CreateFactory(SpaceShipAI);
     48
     49    SpaceShipAI::SpaceShipAI()
     50    {
     51        RegisterObject(SpaceShipAI);
     52
     53        this->alive_ = true;
     54        this->setPosition(Vector3(rnd(-1000, 1000), rnd(-1000, 1000), rnd(-1000, 0000)));
     55        this->target_ = 0;
     56        this->bShooting_ = 0;
     57        this->bHasTargetPosition_ = false;
     58
     59        this->setTeamNr((int)rnd(NUM_AI_TEAMS) % NUM_AI_TEAMS + 1);
     60
     61        if (NUM_AI_TEAMS > 0)
     62            this->teamColours_[1] = ColourValue(1, 0, 0, 1);
     63        if (NUM_AI_TEAMS > 1)
     64            this->teamColours_[2] = ColourValue(0, 1, 0, 1);
     65        if (NUM_AI_TEAMS > 2)
     66            this->teamColours_[3] = ColourValue(0, 0, 1, 1);
     67
     68        for (int i = 4; i <= NUM_AI_TEAMS; ++i)
     69            this->teamColours_[i] = ColourValue(rnd(), rnd(), rnd(), 1);
     70    }
     71
     72    void SpaceShipAI::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     73    {
     74        SpaceShip::XMLPort(xmlelement, mode);
     75        myShip_=true;
     76
     77        this->actionTimer_.setTimer(ACTION_INTERVAL, true, this, createExecutor(createFunctor(&SpaceShipAI::action)));
     78    }
     79
     80    void SpaceShipAI::createEnemy(int num)
     81    {
     82        for (int i = 0; i < num; ++i)
     83        {
     84            SpaceShipAI* newenemy = new SpaceShipAI();
     85            newenemy->setMesh("assff.mesh");
     86//            newenemy->setPosition(0, 0, 0);
     87            newenemy->setScale(10);
     88            newenemy->setMaxSpeed(500);
     89            newenemy->setMaxSideAndBackSpeed(50);
     90            newenemy->setMaxRotation(1.0);
     91            newenemy->setTransAcc(200);
     92            newenemy->setRotAcc(3.0);
     93            newenemy->setTransDamp(75);
     94            newenemy->setRotDamp(1.0);
     95            Element xmlelement;
     96            newenemy->XMLPort(xmlelement, XMLPort::LoadObject);
     97        }
     98    }
     99
     100    void SpaceShipAI::killEnemies(int num)
     101    {
     102        int i = 0;
     103        for (Iterator<SpaceShipAI> it = ObjectList<SpaceShipAI>::begin(); it; )
     104        {
     105            delete *(it++);
     106            ++i;
     107            if (num && i >= num)
     108                break;
     109        }
     110    }
     111
     112    ColourValue SpaceShipAI::getProjectileColour() const
     113    {
     114        return this->teamColours_[this->getTeamNr()];
     115    }
     116
     117    void SpaceShipAI::action()
     118    {
     119        float random;
     120        float maxrand = 100.0f / ACTION_INTERVAL;
     121
     122        // search enemy
     123        random = rnd(maxrand);
     124//std::cout << "search enemy: " << random << std::endl;
     125        if (random < 20 && (!this->target_))
     126        {
     127            this->searchNewTarget();
     128        }
     129
     130        // forget enemy
     131        random = rnd(maxrand);
     132//std::cout << "forget enemy: " << random << std::endl;
     133        if (random < 5 && (this->target_))
     134        {
     135            this->forgetTarget();
     136        }
     137
     138        // next enemy
     139        random = rnd(maxrand);
     140//std::cout << "next enemy: " << random << std::endl;
     141        if (random < 10 && (this->target_))
     142        {
     143            this->searchNewTarget();
     144        }
     145
     146        // fly somewhere
     147        random = rnd(maxrand);
     148//std::cout << "fly somewhere: " << random << std::endl;
     149        if (random < 40 && (!this->bHasTargetPosition_ && !this->target_))
     150        {
     151            this->searchNewTargetPosition();
     152        }
     153
     154        // stop flying
     155        random = rnd(maxrand);
     156//std::cout << "stop flying: " << random << std::endl;
     157        if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
     158        {
     159            this->bHasTargetPosition_ = false;
     160        }
     161
     162        // fly somewhere else
     163        random = rnd(maxrand);
     164//std::cout << "fly somewhere else: " << random << std::endl;
     165        if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
     166        {
     167            this->searchNewTargetPosition();
     168        }
     169
     170        // shoot
     171        random = rnd(maxrand);
     172//std::cout << "shoot: " << random << std::endl;
     173        if (random < 75 && (this->target_ && !this->bShooting_))
     174        {
     175            this->bShooting_ = true;
     176        }
     177
     178        // stop shooting
     179        random = rnd(maxrand);
     180//std::cout << "stop shooting: " << random << std::endl;
     181        if (random < 25 && (this->bShooting_))
     182        {
     183            this->bShooting_ = false;
     184        }
     185    }
     186
     187    void SpaceShipAI::tick(float dt)
     188    {
     189        if (this->target_)
     190            this->aimAtTarget();
     191
     192        if (this->bHasTargetPosition_)
     193            this->moveToTargetPosition(dt);
     194
     195        if (this->bShooting_ && this->isCloseAtTarget(2000) && this->isLookingAtTarget(Ogre::Math::PI / 10.0f))
     196            this->doFire();
     197
     198        SpaceShip::tick(dt);
     199    }
     200
     201    void SpaceShipAI::moveToTargetPosition(float dt)
     202    {
     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/*
     208std::cout << "scalprod: " << dotprod << std::endl;
     209std::cout << "dist: " << this->targetPosition_ - this->getPosition() << std::endl;
     210std::cout << "yaw: " << rotation.getYaw().valueRadians() << std::endl;
     211std::cout << "pitch: " << rotation.getPitch().valueRadians() << std::endl;
     212std::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        {
     219            this->setMoveLongitudinal(1);
     220        }
     221
     222    }
     223
     224    void SpaceShipAI::searchNewTargetPosition()
     225    {
     226        this->targetPosition_ = Vector3(rnd(-5000,5000), rnd(-5000,5000), rnd(-5000,5000));
     227        this->bHasTargetPosition_ = true;
     228    }
     229
     230    void SpaceShipAI::searchNewTarget()
     231    {
     232        this->targetPosition_ = this->getPosition();
     233        this->forgetTarget();
     234
     235        for (Iterator<SpaceShip> it = ObjectList<SpaceShip>::begin(); it; ++it)
     236        {
     237            if (it->getTeamNr() != this->getTeamNr())
     238            {
     239                float speed = this->getVelocity().length();
     240                Vector3 distanceCurrent = this->targetPosition_ - this->getPosition();
     241                Vector3 distanceNew = it->getPosition() - this->getPosition();
     242                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)))
     244                {
     245                    this->target_ = (*it);
     246                    this->targetPosition_ = it->getPosition();
     247                }
     248            }
     249        }
     250   }
     251
     252    void SpaceShipAI::forgetTarget()
     253    {
     254        this->target_ = 0;
     255        this->bShooting_ = false;
     256    }
     257
     258    void SpaceShipAI::aimAtTarget()
     259    {
     260        if (!this->target_)
     261            return;
     262/*
     263        Vector3 enemymovement = this->target_->getVelocity();
     264        Vector3 distance_normalised = this->target_->getPosition() - this->getPosition();
     265        distance_normalised.normalise();
     266
     267        float scalarprod = enemymovement.dotProduct(distance_normalised);
     268        float aimoffset = scalarprod*scalarprod + Projectile::getSpeed() * Projectile::getSpeed() - this->target_->getVelocity().squaredLength();
     269        if (aimoffset < 0)
     270        {
     271            this->bHasTargetPosition_ = false;
     272            return;
     273        }
     274        aimoffset = -scalarprod + sqrt(aimoffset);
     275        this->targetPosition_ = enemymovement + distance_normalised * aimoffset;
     276        this->bHasTargetPosition_ = true;
     277
     278        std::cout << "targetpos: " << this->targetPosition_ << std::endl;
     279*/
     280        this->targetPosition_ = this->target_->getPosition();
     281        this->bHasTargetPosition_ = true;
     282    }
     283
     284    bool SpaceShipAI::isCloseAtTarget(float distance)
     285    {
     286        return (this->getPosition().squaredDistance(this->targetPosition_) < distance*distance);
     287    }
     288
     289    bool SpaceShipAI::isLookingAtTarget(float angle)
     290    {
     291        return (this->getOrientation() * Ogre::Vector3::UNIT_X).directionEquals(this->targetPosition_ - this->getPosition(), Radian(angle));
     292    }
     293}
  • code/branches/network/src/orxonox/objects/weapon/BaseWeapon.h

    r1494 r1495  
    11/*
    22 *   ORXONOX - the hottest 3D action shooter ever to exist
    3  *                    > www.orxonox.net < *
     3 *                    > www.orxonox.net <
     4 *
    45 *
    56 *   License notice:
     
    2526 *
    2627 */
    27 #ifndef _BaseWeapon_H__#define _BaseWeapon_H__#include "OrxonoxPrereqs.h"#include <OgrePrerequisites.h>#include "../Model.h"namespace orxonox {  class _OrxonoxExport BaseWeapon : public Model  {  public:    enum Action {      NOTHING  = 0,      RELOAD   = 1,      CHANGE_AMMO  = 2,      SPECIAL  = 3    };  protected:    enum State {      IDLE = 0,      PRIMARY_FIRE = 1,      SECONDARY_FIRE = 2,      RELOADING = 3,      CHANGING_AMMO = 4,    };  public:    BaseWeapon();          virtual ~BaseWeapon();    bool addAction(const Action);    void primaryFireRequest();    void secondaryFireRequest();    int getAmmoState();    void setAmmoDump(AmmunitionDump*);    inline virtual void loadParams(TiXmlElement* xmlElem) { Model::loadParams(xmlElem); };    virtual void tick(float dt);  protected:    virtual void primaryFire() = 0;    virtual void primaryFiring(float) = 0;    virtual void secondaryFire() = 0;    virtual void secondaryFiring(float) = 0;    virtual void registerAllVariables() { };  public:  protected:    Ogre::SceneManager *sceneMgr_;    int bulletCounter_;    BulletManager *bulletManager_;    AmmunitionDump *ammoDump_;    bool primaryFireRequest_;    bool secondaryFireRequest_;    float totalTime_;    float actionStartTime_;    State currentState_;    bool secondaryFired_;    Action nextAction_;    bool actionAdded_;    float timeSinceNextActionAdded_;    static float nextActionValidityPeriod_s;    // weapon properties    int leftAmmo_;    float primaryFirePower_;    float secondaryFirePower_;    float primaryFiringRate_;    float secondaryFiringRate_;    Real primaryBulletSpeed_;    Real secondaryBulletSpeed_;    int magazineSize_;  };}#endif /* _BaseWeapon_H__ */
     28
     29
     30#ifndef _BaseWeapon_H__
     31#define _BaseWeapon_H__
     32
     33#include "OrxonoxPrereqs.h"
     34
     35#include <OgrePrerequisites.h>
     36
     37#include "../Model.h"
     38
     39
     40namespace orxonox {
     41  class _OrxonoxExport BaseWeapon : public Model
     42  {
     43  public:
     44    enum Action {
     45      NOTHING  = 0,
     46      RELOAD   = 1,
     47      CHANGE_AMMO  = 2,
     48      SPECIAL  = 3
     49    };
     50
     51  protected:
     52    enum State {
     53      IDLE = 0,
     54      PRIMARY_FIRE = 1,
     55      SECONDARY_FIRE = 2,
     56      RELOADING = 3,
     57      CHANGING_AMMO = 4,
     58    };
     59
     60  public:
     61    BaseWeapon();
     62          virtual ~BaseWeapon();
     63
     64    bool addAction(const Action);
     65
     66    void primaryFireRequest();
     67
     68    void secondaryFireRequest();
     69
     70    int getAmmoState();
     71
     72    void setAmmoDump(AmmunitionDump*);
     73
     74    inline virtual void loadParams(TiXmlElement* xmlElem) { Model::loadParams(xmlElem); };
     75
     76    virtual void tick(float dt);
     77
     78  protected:
     79    virtual void primaryFire() = 0;
     80
     81    virtual void primaryFiring(float) = 0;
     82
     83    virtual void secondaryFire() = 0;
     84
     85    virtual void secondaryFiring(float) = 0;
     86
     87    virtual void registerAllVariables() { };
     88
     89  public:
     90
     91  protected:
     92    Ogre::SceneManager *sceneMgr_;
     93
     94    int bulletCounter_;
     95    BulletManager *bulletManager_;
     96
     97    AmmunitionDump *ammoDump_;
     98
     99    bool primaryFireRequest_;
     100    bool secondaryFireRequest_;
     101
     102    float totalTime_;
     103    float actionStartTime_;
     104
     105    State currentState_;
     106    bool secondaryFired_;
     107
     108    Action nextAction_;
     109    bool actionAdded_;
     110    float timeSinceNextActionAdded_;
     111    static float nextActionValidityPeriod_s;
     112
     113    // weapon properties
     114    int leftAmmo_;
     115    float primaryFirePower_;
     116    float secondaryFirePower_;
     117    float primaryFiringRate_;
     118    float secondaryFiringRate_;
     119    Real primaryBulletSpeed_;
     120    Real secondaryBulletSpeed_;
     121
     122    int magazineSize_;
     123
     124  };
     125}
     126
     127#endif /* _BaseWeapon_H__ */
Note: See TracChangeset for help on using the changeset viewer.