[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 | CREATE_FACTORY(GroundTurret, CL_GROUND_TURRET); |
---|
| 32 | |
---|
[5596] | 33 | using namespace std; |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | /** |
---|
| 37 | * constructs and loads a GroundTurret from a XML-element |
---|
| 38 | * @param root the XML-element to load from |
---|
| 39 | */ |
---|
| 40 | GroundTurret::GroundTurret(const TiXmlElement* root) |
---|
| 41 | { |
---|
| 42 | this->init(); |
---|
| 43 | if (root != NULL) |
---|
| 44 | this->loadParams(root); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | /** |
---|
| 49 | * standard deconstructor |
---|
| 50 | */ |
---|
| 51 | GroundTurret::~GroundTurret () |
---|
| 52 | { |
---|
| 53 | |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | /** |
---|
| 58 | * initializes the GroundTurret |
---|
| 59 | * @todo change this to what you wish |
---|
| 60 | */ |
---|
| 61 | void GroundTurret::init() |
---|
| 62 | { |
---|
[5679] | 63 | this->setClassID(CL_GROUND_TURRET, "GroundTurret"); |
---|
[7103] | 64 | this->loadModel("models/ground_turret_#.obj", 5); |
---|
[5795] | 65 | this->left = NULL; |
---|
| 66 | this->right = NULL; |
---|
| 67 | |
---|
[7076] | 68 | this->setHealthMax(300); |
---|
| 69 | this->setHealth(300); |
---|
| 70 | |
---|
[7102] | 71 | this->weaponHolder[0].addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
| 72 | this->weaponHolder[1].addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
| 73 | |
---|
| 74 | this->weaponHolder[0].setRelCoor(0,25,0); |
---|
| 75 | this->weaponHolder[0].setParent(this); |
---|
| 76 | this->weaponHolder[1].setParent(this); |
---|
[5596] | 77 | } |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | /** |
---|
| 81 | * loads a GroundTurret from a XML-element |
---|
| 82 | * @param root the XML-element to load from |
---|
| 83 | * @todo make the class Loadable |
---|
| 84 | */ |
---|
| 85 | void GroundTurret::loadParams(const TiXmlElement* root) |
---|
| 86 | { |
---|
| 87 | // all the clases this Entity is directly derived from must be called in this way, to load all settings. |
---|
[6512] | 88 | NPC::loadParams(root); |
---|
[5596] | 89 | |
---|
| 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 | { |
---|
[7076] | 127 | if(this->getHealth() > 0.0f && State::getPlayer() && |
---|
| 128 | State::getPlayer()->getPlayable() && |
---|
[7104] | 129 | State::getPlayer()->getPlayable()->distance(this) < 120) // HACK |
---|
[7076] | 130 | { |
---|
[6433] | 131 | if (likely(this->left != NULL)) |
---|
| 132 | { |
---|
[6736] | 133 | // this->left->tickW(dt); |
---|
[6433] | 134 | this->left->requestAction(WA_SHOOT); |
---|
| 135 | } |
---|
| 136 | if (likely(this->right != NULL)) |
---|
| 137 | { |
---|
[6736] | 138 | // this->right->tickW(dt); |
---|
[6433] | 139 | this->right->requestAction(WA_SHOOT); |
---|
| 140 | } |
---|
[7076] | 141 | } |
---|
[5739] | 142 | } |
---|
| 143 | |
---|
[5596] | 144 | /** |
---|
| 145 | * draws this worldEntity |
---|
| 146 | */ |
---|
| 147 | void GroundTurret::draw () const |
---|
| 148 | { |
---|
[6424] | 149 | WorldEntity::draw(); |
---|
[5596] | 150 | |
---|
[5819] | 151 | if (this->left != NULL) |
---|
[5795] | 152 | this->left->draw(); |
---|
| 153 | if (this->right != NULL) |
---|
| 154 | this->right->draw(); |
---|
[5596] | 155 | } |
---|
| 156 | |
---|
| 157 | |
---|
[5680] | 158 | |
---|
| 159 | /** |
---|
| 160 | * |
---|
| 161 | * |
---|
| 162 | */ |
---|
| 163 | void GroundTurret::postSpawn () |
---|
| 164 | { |
---|
[5795] | 165 | |
---|
[5680] | 166 | } |
---|
| 167 | |
---|
| 168 | /** |
---|
| 169 | * |
---|
| 170 | * |
---|
| 171 | */ |
---|
| 172 | void GroundTurret::leftWorld () |
---|
| 173 | { |
---|
[5795] | 174 | |
---|
[5680] | 175 | } |
---|
[6341] | 176 | |
---|
[7076] | 177 | void GroundTurret::destroy() |
---|
| 178 | { |
---|
| 179 | this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90); |
---|
[7105] | 180 | Explosion::explode(this, Vector(10,10,10)); |
---|
[7076] | 181 | } |
---|