[1847] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
[1859] | 5 | * TUTORIAL |
---|
[1847] | 6 | */ |
---|
| 7 | |
---|
| 8 | // for precompiled header files. Has to be first! |
---|
| 9 | #include "OrxonoxStableHeaders.h" |
---|
[1857] | 10 | // always include this class's header file first so that |
---|
| 11 | // it compiles on its own too. |
---|
[1847] | 12 | #include "TutorialShip.h" |
---|
| 13 | |
---|
| 14 | // Additional includes |
---|
[1862] | 15 | #include <OgreEntity.h> |
---|
| 16 | #include <OgreSceneNode.h> |
---|
| 17 | #include <OgreSceneManager.h> |
---|
| 18 | #include <OgreLight.h> |
---|
[1847] | 19 | #include "util/Convert.h" |
---|
| 20 | #include "util/Debug.h" |
---|
| 21 | #include "core/ConfigValueIncludes.h" |
---|
| 22 | #include "core/ConsoleCommand.h" |
---|
| 23 | #include "core/CoreIncludes.h" |
---|
| 24 | #include "core/input/InputManager.h" |
---|
| 25 | #include "core/XMLPort.h" |
---|
[1862] | 26 | #include "GraphicsEngine.h" |
---|
[1847] | 27 | |
---|
| 28 | namespace orxonox |
---|
| 29 | { |
---|
[1857] | 30 | // Specify a console command that can be used in |
---|
| 31 | // the shell or as key binding. |
---|
| 32 | SetConsoleCommand(TutorialShip, fire, true) |
---|
| 33 | .keybindMode(KeybindMode::OnHold); |
---|
[1847] | 34 | |
---|
[1857] | 35 | // Make sure we can create an object of this class by XML |
---|
[1855] | 36 | CreateFactory(TutorialShip); |
---|
| 37 | |
---|
[1857] | 38 | // Constructor |
---|
[1847] | 39 | TutorialShip::TutorialShip() |
---|
| 40 | { |
---|
| 41 | RegisterObject(TutorialShip); |
---|
| 42 | |
---|
| 43 | // reset variables |
---|
[1855] | 44 | this->hasSpecialEffects_ = false; |
---|
| 45 | |
---|
| 46 | // set config values |
---|
| 47 | this->setConfigValues(); |
---|
[1847] | 48 | } |
---|
| 49 | |
---|
[1857] | 50 | // Destructor |
---|
| 51 | TutorialShip::~TutorialShip() |
---|
[1852] | 52 | { |
---|
| 53 | } |
---|
| 54 | |
---|
[1857] | 55 | // Sets the configurable member variables. |
---|
| 56 | // They can be found later in orxonox.ini directly. |
---|
[1852] | 57 | void TutorialShip::setConfigValues() |
---|
[1847] | 58 | { |
---|
[1857] | 59 | SetConfigValue(reloadTime_, 0.125) |
---|
| 60 | .description("The reload time of the weapon in seconds"); |
---|
[1847] | 61 | } |
---|
| 62 | |
---|
[1857] | 63 | // Called when loading an object of this class with XML |
---|
| 64 | // You don't have to know what exactly xmlelement is. |
---|
| 65 | // And mode is not important yet (load/save). |
---|
[1852] | 66 | void TutorialShip::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
[1847] | 67 | { |
---|
[1857] | 68 | // Load our parameter "specialEffects". Case sensitive! |
---|
| 69 | XMLPortParam(TutorialShip, "specialEffects", setSpecialEffects, |
---|
| 70 | hasSpecialEffects, xmlelement, mode); |
---|
[1855] | 71 | |
---|
[1857] | 72 | // Calls SpaceShip::XMLPort so that the SpaceShip XML parameters |
---|
| 73 | // are loaded too. |
---|
[1847] | 74 | SUPER(TutorialShip, XMLPort, xmlelement, mode); |
---|
[1859] | 75 | |
---|
| 76 | // Display a message in shell/logfile/console |
---|
| 77 | COUT(3) << "TutorialShip was loaded." << std::endl; |
---|
[1862] | 78 | |
---|
| 79 | // Additional tutorial expedition |
---|
| 80 | //Ogre::SceneNode* shipNode = this->getNode(); |
---|
| 81 | //Ogre::SceneManager* mgr = GraphicsEngine::getInstance().getLevelSceneManager(); |
---|
| 82 | //Ogre::SceneNode* newNode = shipNode->createChildSceneNode("newNode"); |
---|
| 83 | //Ogre::BillboardSet* bbset = mgr->createBillboardSet("TutBBS"); |
---|
| 84 | //bbset->createBillboard(Vector3(0,0,0), ColourValue(1,1,1)); |
---|
| 85 | //bbset->setMaterialName("Examples/Flare"); |
---|
| 86 | //newNode->setPosition(Vector3(30,0,0)); |
---|
| 87 | //newNode->scale(Vector3(0.1)); |
---|
| 88 | //newNode->attachObject(bbset); |
---|
[1855] | 89 | } |
---|
[1847] | 90 | |
---|
[1857] | 91 | // XML save function. Also used by back end class SpaceShip |
---|
| 92 | // to show or hide the special effects. |
---|
[1855] | 93 | bool TutorialShip::hasSpecialEffects() |
---|
| 94 | { |
---|
| 95 | return this->hasSpecialEffects_; |
---|
[1847] | 96 | } |
---|
| 97 | |
---|
[1857] | 98 | // XML load function. Called by the XML macro above. |
---|
[1855] | 99 | void TutorialShip::setSpecialEffects(bool value) |
---|
| 100 | { |
---|
| 101 | this->hasSpecialEffects_ = value; |
---|
| 102 | } |
---|
| 103 | |
---|
[1859] | 104 | /*** NOT SO IMPORTATANT... ***/ |
---|
[1855] | 105 | |
---|
[1857] | 106 | // run time update method. Gets called every frame with the delta time that |
---|
| 107 | // has passed since the last frame. |
---|
[1852] | 108 | void TutorialShip::tick(float dt) |
---|
[1847] | 109 | { |
---|
[1857] | 110 | // Also call the tick() method of the base clas. |
---|
[1847] | 111 | SUPER(TutorialShip, tick, dt); |
---|
| 112 | } |
---|
| 113 | |
---|
[1859] | 114 | // virtual function used by back end class SpaceShip. |
---|
| 115 | float TutorialShip::getReloadTime() |
---|
| 116 | { |
---|
| 117 | return this->reloadTime_; |
---|
| 118 | } |
---|
| 119 | |
---|
[1857] | 120 | // Fire a projectile. Delegated to the back end class SpaceShip. |
---|
| 121 | // Function content is insignificant for the tutorial. |
---|
[1852] | 122 | void TutorialShip::fire() |
---|
| 123 | { |
---|
[1855] | 124 | SpaceShip::getLocalShip()->doFire(); |
---|
[1852] | 125 | } |
---|
[1847] | 126 | } |
---|