[5596] | 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" |
---|
[5739] | 17 | #include "model.h" |
---|
[6432] | 18 | #include "world_entities/weapons/turret.h" |
---|
[5596] | 19 | |
---|
[7076] | 20 | #include "state.h" |
---|
| 21 | #include "playable.h" |
---|
| 22 | #include "player.h" |
---|
| 23 | |
---|
| 24 | |
---|
[7193] | 25 | #include "util/loading/factory.h" |
---|
[6341] | 26 | #include "network_game_manager.h" |
---|
[7193] | 27 | #include "util/loading/load_param.h" |
---|
[5795] | 28 | |
---|
[7103] | 29 | #include "effects/explosion.h" |
---|
| 30 | |
---|
[5739] | 31 | |
---|
[10114] | 32 | |
---|
| 33 | ObjectListDefinition(GroundTurret); |
---|
[9869] | 34 | CREATE_FACTORY(GroundTurret); |
---|
[5596] | 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) |
---|
[9656] | 42 | : NPC(root) |
---|
[5596] | 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 | { |
---|
[9869] | 64 | this->registerObject(this, GroundTurret::_objectList); |
---|
[7103] | 65 | this->loadModel("models/ground_turret_#.obj", 5); |
---|
[5795] | 66 | this->left = NULL; |
---|
| 67 | this->right = NULL; |
---|
| 68 | |
---|
[7076] | 69 | this->setHealthMax(300); |
---|
| 70 | this->setHealth(300); |
---|
| 71 | |
---|
[7102] | 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); |
---|
[5596] | 78 | } |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | /** |
---|
[9656] | 82 | * @brief loads a GroundTurret from a XML-element |
---|
[5596] | 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. |
---|
[6512] | 89 | NPC::loadParams(root); |
---|
[5596] | 90 | |
---|
| 91 | /** |
---|
| 92 | * @todo: make the class Loadable |
---|
| 93 | */ |
---|
[5819] | 94 | const TiXmlElement* element; |
---|
| 95 | |
---|
| 96 | element = root->FirstChildElement("weapon-left"); |
---|
| 97 | if (element != NULL) element = element->FirstChildElement(); |
---|
[5982] | 98 | this->left = dynamic_cast<Weapon*>( Factory::fabricate( element) ); |
---|
[5819] | 99 | if (this->left) |
---|
| 100 | { |
---|
| 101 | this->left->setParent(this); |
---|
[6142] | 102 | this->left->toList(this->getOMListNumber()); |
---|
[5819] | 103 | this->left->setRelCoor(0,10,-5); |
---|
[6433] | 104 | this->left->requestAction( WA_ACTIVATE); |
---|
[7102] | 105 | this->left->setParent(&this->weaponHolder[0]); |
---|
[5819] | 106 | } |
---|
| 107 | |
---|
| 108 | element = root->FirstChildElement("weapon-right"); |
---|
| 109 | if (element != NULL) if (element != NULL) element = element->FirstChildElement(); |
---|
[5982] | 110 | this->right = dynamic_cast<Weapon*>( Factory::fabricate( element) ); |
---|
[5819] | 111 | if (this->right) |
---|
| 112 | { |
---|
| 113 | this->right->setParent(this); |
---|
[6142] | 114 | this->right->toList(this->getOMListNumber()); |
---|
[5819] | 115 | this->right->setRelCoor(0,10,5); |
---|
[6433] | 116 | this->left->requestAction( WA_ACTIVATE); |
---|
[7102] | 117 | this->right->setParent(&this->weaponHolder[0]); |
---|
[5819] | 118 | } |
---|
[5596] | 119 | } |
---|
| 120 | |
---|
| 121 | /** |
---|
| 122 | * advances the GroundTurret about time seconds |
---|
| 123 | * @param time the Time to step |
---|
| 124 | */ |
---|
[6433] | 125 | void GroundTurret::tick(float dt) |
---|
[5739] | 126 | { |
---|
[9656] | 127 | if(this->getHealth() > 0.0f |
---|
| 128 | ) // HACK <--- YOU ARE THE MOTHERFUCKER |
---|
[7076] | 129 | { |
---|
[9656] | 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 | } |
---|
[6433] | 140 | } |
---|
[5739] | 141 | } |
---|
| 142 | |
---|
[5596] | 143 | /** |
---|
| 144 | * draws this worldEntity |
---|
| 145 | */ |
---|
| 146 | void GroundTurret::draw () const |
---|
| 147 | { |
---|
[6424] | 148 | WorldEntity::draw(); |
---|
[5596] | 149 | |
---|
[5819] | 150 | if (this->left != NULL) |
---|
[5795] | 151 | this->left->draw(); |
---|
| 152 | if (this->right != NULL) |
---|
| 153 | this->right->draw(); |
---|
[5596] | 154 | } |
---|
| 155 | |
---|
| 156 | |
---|
[5680] | 157 | |
---|
| 158 | /** |
---|
| 159 | * |
---|
| 160 | * |
---|
| 161 | */ |
---|
| 162 | void GroundTurret::postSpawn () |
---|
| 163 | { |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | /** |
---|
| 167 | * |
---|
| 168 | * |
---|
| 169 | */ |
---|
| 170 | void GroundTurret::leftWorld () |
---|
| 171 | { |
---|
| 172 | } |
---|
[6341] | 173 | |
---|
[9235] | 174 | void GroundTurret::destroy(WorldEntity* killer) |
---|
[7076] | 175 | { |
---|
| 176 | this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90); |
---|
[7105] | 177 | Explosion::explode(this, Vector(10,10,10)); |
---|
[8777] | 178 | |
---|
| 179 | this->toList(OM_DEAD); |
---|
[7076] | 180 | } |
---|