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