[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) |
---|
[8724] | 41 | : NPC(root) |
---|
[5596] | 42 | { |
---|
| 43 | this->init(); |
---|
| 44 | if (root != NULL) |
---|
| 45 | this->loadParams(root); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | /** |
---|
| 50 | * standard deconstructor |
---|
| 51 | */ |
---|
| 52 | GroundTurret::~GroundTurret () |
---|
| 53 | { |
---|
| 54 | |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | /** |
---|
| 59 | * initializes the GroundTurret |
---|
| 60 | * @todo change this to what you wish |
---|
| 61 | */ |
---|
| 62 | void GroundTurret::init() |
---|
| 63 | { |
---|
[5679] | 64 | this->setClassID(CL_GROUND_TURRET, "GroundTurret"); |
---|
[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 | /** |
---|
| 82 | * 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. |
---|
[6512] | 89 | NPC::loadParams(root); |
---|
[5596] | 90 | |
---|
| 91 | |
---|
| 92 | /** |
---|
| 93 | * @todo: make the class Loadable |
---|
| 94 | */ |
---|
[5819] | 95 | const TiXmlElement* element; |
---|
| 96 | |
---|
| 97 | element = root->FirstChildElement("weapon-left"); |
---|
| 98 | if (element != NULL) element = element->FirstChildElement(); |
---|
[5982] | 99 | this->left = dynamic_cast<Weapon*>( Factory::fabricate( element) ); |
---|
[5819] | 100 | if (this->left) |
---|
| 101 | { |
---|
| 102 | this->left->setParent(this); |
---|
[6142] | 103 | this->left->toList(this->getOMListNumber()); |
---|
[5819] | 104 | this->left->setRelCoor(0,10,-5); |
---|
[6433] | 105 | this->left->requestAction( WA_ACTIVATE); |
---|
[7102] | 106 | this->left->setParent(&this->weaponHolder[0]); |
---|
[5819] | 107 | } |
---|
| 108 | |
---|
| 109 | element = root->FirstChildElement("weapon-right"); |
---|
| 110 | if (element != NULL) if (element != NULL) element = element->FirstChildElement(); |
---|
[5982] | 111 | this->right = dynamic_cast<Weapon*>( Factory::fabricate( element) ); |
---|
[5819] | 112 | if (this->right) |
---|
| 113 | { |
---|
| 114 | this->right->setParent(this); |
---|
[6142] | 115 | this->right->toList(this->getOMListNumber()); |
---|
[5819] | 116 | this->right->setRelCoor(0,10,5); |
---|
[6433] | 117 | this->left->requestAction( WA_ACTIVATE); |
---|
[7102] | 118 | this->right->setParent(&this->weaponHolder[0]); |
---|
[5819] | 119 | } |
---|
[5596] | 120 | } |
---|
| 121 | |
---|
| 122 | /** |
---|
| 123 | * advances the GroundTurret about time seconds |
---|
| 124 | * @param time the Time to step |
---|
| 125 | */ |
---|
[6433] | 126 | void GroundTurret::tick(float dt) |
---|
[5739] | 127 | { |
---|
[7076] | 128 | if(this->getHealth() > 0.0f && State::getPlayer() && |
---|
| 129 | State::getPlayer()->getPlayable() && |
---|
[7104] | 130 | State::getPlayer()->getPlayable()->distance(this) < 120) // HACK |
---|
[7076] | 131 | { |
---|
[6433] | 132 | if (likely(this->left != NULL)) |
---|
| 133 | { |
---|
[6736] | 134 | // this->left->tickW(dt); |
---|
[6433] | 135 | this->left->requestAction(WA_SHOOT); |
---|
| 136 | } |
---|
| 137 | if (likely(this->right != NULL)) |
---|
| 138 | { |
---|
[6736] | 139 | // this->right->tickW(dt); |
---|
[6433] | 140 | this->right->requestAction(WA_SHOOT); |
---|
| 141 | } |
---|
[7076] | 142 | } |
---|
[5739] | 143 | } |
---|
| 144 | |
---|
[5596] | 145 | /** |
---|
| 146 | * draws this worldEntity |
---|
| 147 | */ |
---|
| 148 | void GroundTurret::draw () const |
---|
| 149 | { |
---|
[6424] | 150 | WorldEntity::draw(); |
---|
[5596] | 151 | |
---|
[5819] | 152 | if (this->left != NULL) |
---|
[5795] | 153 | this->left->draw(); |
---|
| 154 | if (this->right != NULL) |
---|
| 155 | this->right->draw(); |
---|
[5596] | 156 | } |
---|
| 157 | |
---|
| 158 | |
---|
[5680] | 159 | |
---|
| 160 | /** |
---|
| 161 | * |
---|
| 162 | * |
---|
| 163 | */ |
---|
| 164 | void GroundTurret::postSpawn () |
---|
| 165 | { |
---|
[5795] | 166 | |
---|
[5680] | 167 | } |
---|
| 168 | |
---|
| 169 | /** |
---|
| 170 | * |
---|
| 171 | * |
---|
| 172 | */ |
---|
| 173 | void GroundTurret::leftWorld () |
---|
| 174 | { |
---|
[5795] | 175 | |
---|
[5680] | 176 | } |
---|
[6341] | 177 | |
---|
[7076] | 178 | void GroundTurret::destroy() |
---|
| 179 | { |
---|
| 180 | this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90); |
---|
[7105] | 181 | Explosion::explode(this, Vector(10,10,10)); |
---|
[8777] | 182 | |
---|
| 183 | this->toList(OM_DEAD); |
---|
[7076] | 184 | } |
---|