| 1 | /* | 
|---|
| 2 |    orxonox - the future of 3D-vertical-scrollers | 
|---|
| 3 |  | 
|---|
| 4 |    Copyright (C) 2004 orx | 
|---|
| 5 |  | 
|---|
| 6 |    This program is free software; you can redistribute it and/or modify | 
|---|
| 7 |    it under the terms of the GNU General Public License as published by | 
|---|
| 8 |    the Free Software Foundation; either version 2, or (at your option) | 
|---|
| 9 |    any later version. | 
|---|
| 10 |  | 
|---|
| 11 |    ### File Specific: | 
|---|
| 12 |    main-programmer: Manuel Leuenberger | 
|---|
| 13 |    co-programmer: ... | 
|---|
| 14 | */ | 
|---|
| 15 |  | 
|---|
| 16 | #include "ground_turret.h" | 
|---|
| 17 | #include "model.h" | 
|---|
| 18 | #include "world_entities/weapons/turret.h" | 
|---|
| 19 |  | 
|---|
| 20 | #include "state.h" | 
|---|
| 21 | #include "playable.h" | 
|---|
| 22 | #include "player.h" | 
|---|
| 23 |  | 
|---|
| 24 |  | 
|---|
| 25 | #include "util/loading/factory.h" | 
|---|
| 26 | #include "network_game_manager.h" | 
|---|
| 27 | #include "util/loading/load_param.h" | 
|---|
| 28 |  | 
|---|
| 29 | #include "effects/explosion.h" | 
|---|
| 30 |  | 
|---|
| 31 | #include "class_id_DEPRECATED.h" | 
|---|
| 32 |  | 
|---|
| 33 | ObjectListDefinitionID(GroundTurret, CL_GROUND_TURRET); | 
|---|
| 34 | CREATE_FACTORY(GroundTurret); | 
|---|
| 35 |  | 
|---|
| 36 |  | 
|---|
| 37 | /** | 
|---|
| 38 |  * constructs and loads a GroundTurret from a XML-element | 
|---|
| 39 |  * @param root the XML-element to load from | 
|---|
| 40 |  */ | 
|---|
| 41 | GroundTurret::GroundTurret(const TiXmlElement* root) | 
|---|
| 42 |     : NPC(root) | 
|---|
| 43 | { | 
|---|
| 44 |   this->init(); | 
|---|
| 45 |   if (root != NULL) | 
|---|
| 46 |     this->loadParams(root); | 
|---|
| 47 | } | 
|---|
| 48 |  | 
|---|
| 49 |  | 
|---|
| 50 | /** | 
|---|
| 51 |  * standard deconstructor | 
|---|
| 52 |  */ | 
|---|
| 53 | GroundTurret::~GroundTurret () | 
|---|
| 54 | { | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|
| 57 |  | 
|---|
| 58 | /** | 
|---|
| 59 |  * initializes the GroundTurret | 
|---|
| 60 |  * @todo change this to what you wish | 
|---|
| 61 |  */ | 
|---|
| 62 | void GroundTurret::init() | 
|---|
| 63 | { | 
|---|
| 64 |   this->registerObject(this, GroundTurret::_objectList); | 
|---|
| 65 |   this->loadModel("models/ground_turret_#.obj", 5); | 
|---|
| 66 |   this->left = NULL; | 
|---|
| 67 |   this->right = NULL; | 
|---|
| 68 |  | 
|---|
| 69 |   this->setHealthMax(300); | 
|---|
| 70 |   this->setHealth(300); | 
|---|
| 71 |  | 
|---|
| 72 |   this->weaponHolder[0].addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); | 
|---|
| 73 |   this->weaponHolder[1].addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); | 
|---|
| 74 |  | 
|---|
| 75 |   this->weaponHolder[0].setRelCoor(0,25,0); | 
|---|
| 76 |   this->weaponHolder[0].setParent(this); | 
|---|
| 77 |   this->weaponHolder[1].setParent(this); | 
|---|
| 78 | } | 
|---|
| 79 |  | 
|---|
| 80 |  | 
|---|
| 81 | /** | 
|---|
| 82 |  * @brief loads a GroundTurret from a XML-element | 
|---|
| 83 |  * @param root the XML-element to load from | 
|---|
| 84 |  * @todo make the class Loadable | 
|---|
| 85 |  */ | 
|---|
| 86 | void GroundTurret::loadParams(const TiXmlElement* root) | 
|---|
| 87 | { | 
|---|
| 88 |   // all the clases this Entity is directly derived from must be called in this way, to load all settings. | 
|---|
| 89 |   NPC::loadParams(root); | 
|---|
| 90 |  | 
|---|
| 91 |   /** | 
|---|
| 92 |    * @todo: make the class Loadable | 
|---|
| 93 |    */ | 
|---|
| 94 |   const TiXmlElement* element; | 
|---|
| 95 |  | 
|---|
| 96 |   element = root->FirstChildElement("weapon-left"); | 
|---|
| 97 |   if (element != NULL) element = element->FirstChildElement(); | 
|---|
| 98 |   this->left = dynamic_cast<Weapon*>( Factory::fabricate( element) ); | 
|---|
| 99 |   if (this->left) | 
|---|
| 100 |   { | 
|---|
| 101 |     this->left->setParent(this); | 
|---|
| 102 |     this->left->toList(this->getOMListNumber()); | 
|---|
| 103 |     this->left->setRelCoor(0,10,-5); | 
|---|
| 104 |     this->left->requestAction( WA_ACTIVATE); | 
|---|
| 105 |     this->left->setParent(&this->weaponHolder[0]); | 
|---|
| 106 |   } | 
|---|
| 107 |  | 
|---|
| 108 |   element = root->FirstChildElement("weapon-right"); | 
|---|
| 109 |   if (element != NULL)  if (element != NULL) element = element->FirstChildElement(); | 
|---|
| 110 |   this->right = dynamic_cast<Weapon*>( Factory::fabricate( element) ); | 
|---|
| 111 |   if (this->right) | 
|---|
| 112 |   { | 
|---|
| 113 |     this->right->setParent(this); | 
|---|
| 114 |     this->right->toList(this->getOMListNumber()); | 
|---|
| 115 |     this->right->setRelCoor(0,10,5); | 
|---|
| 116 |     this->left->requestAction( WA_ACTIVATE); | 
|---|
| 117 |     this->right->setParent(&this->weaponHolder[0]); | 
|---|
| 118 |   } | 
|---|
| 119 | } | 
|---|
| 120 |  | 
|---|
| 121 | /** | 
|---|
| 122 |  * advances the GroundTurret about time seconds | 
|---|
| 123 |  * @param time the Time to step | 
|---|
| 124 |  */ | 
|---|
| 125 | void GroundTurret::tick(float dt) | 
|---|
| 126 | { | 
|---|
| 127 |   if(this->getHealth() > 0.0f | 
|---|
| 128 |     ) // HACK <--- YOU ARE THE MOTHERFUCKER | 
|---|
| 129 |   { | 
|---|
| 130 |     if (likely(this->left != NULL)) | 
|---|
| 131 |     { | 
|---|
| 132 |       //    this->left->tickW(dt); | 
|---|
| 133 |       this->left->requestAction(WA_SHOOT); | 
|---|
| 134 |     } | 
|---|
| 135 |     if (likely(this->right != NULL)) | 
|---|
| 136 |     { | 
|---|
| 137 |       //    this->right->tickW(dt); | 
|---|
| 138 |       this->right->requestAction(WA_SHOOT); | 
|---|
| 139 |     } | 
|---|
| 140 |   } | 
|---|
| 141 | } | 
|---|
| 142 |  | 
|---|
| 143 | /** | 
|---|
| 144 |  * draws this worldEntity | 
|---|
| 145 |  */ | 
|---|
| 146 | void GroundTurret::draw () const | 
|---|
| 147 | { | 
|---|
| 148 |   WorldEntity::draw(); | 
|---|
| 149 |  | 
|---|
| 150 |   if (this->left != NULL) | 
|---|
| 151 |     this->left->draw(); | 
|---|
| 152 |   if (this->right != NULL) | 
|---|
| 153 |     this->right->draw(); | 
|---|
| 154 | } | 
|---|
| 155 |  | 
|---|
| 156 |  | 
|---|
| 157 |  | 
|---|
| 158 | /** | 
|---|
| 159 |  * | 
|---|
| 160 |  * | 
|---|
| 161 |  */ | 
|---|
| 162 | void GroundTurret::postSpawn () | 
|---|
| 163 | { | 
|---|
| 164 | } | 
|---|
| 165 |  | 
|---|
| 166 | /** | 
|---|
| 167 |  * | 
|---|
| 168 |  * | 
|---|
| 169 |  */ | 
|---|
| 170 | void GroundTurret::leftWorld () | 
|---|
| 171 | { | 
|---|
| 172 | } | 
|---|
| 173 |  | 
|---|
| 174 | void GroundTurret::destroy(WorldEntity* killer) | 
|---|
| 175 | { | 
|---|
| 176 |   this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90); | 
|---|
| 177 |   Explosion::explode(this, Vector(10,10,10)); | 
|---|
| 178 |  | 
|---|
| 179 |   this->toList(OM_DEAD); | 
|---|
| 180 | } | 
|---|