[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" |
---|
[5740] | 18 | #include "turret.h" |
---|
[5596] | 19 | |
---|
[5795] | 20 | #include "factory.h" |
---|
| 21 | #include "load_param.h" |
---|
| 22 | |
---|
[5739] | 23 | CREATE_FACTORY(GroundTurret, CL_GROUND_TURRET); |
---|
| 24 | |
---|
[5596] | 25 | using namespace std; |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | /** |
---|
| 29 | * constructs and loads a GroundTurret from a XML-element |
---|
| 30 | * @param root the XML-element to load from |
---|
| 31 | */ |
---|
| 32 | GroundTurret::GroundTurret(const TiXmlElement* root) |
---|
| 33 | { |
---|
| 34 | this->init(); |
---|
| 35 | if (root != NULL) |
---|
| 36 | this->loadParams(root); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | /** |
---|
| 41 | * standard deconstructor |
---|
| 42 | */ |
---|
| 43 | GroundTurret::~GroundTurret () |
---|
| 44 | { |
---|
| 45 | |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | /** |
---|
| 50 | * initializes the GroundTurret |
---|
| 51 | * @todo change this to what you wish |
---|
| 52 | */ |
---|
| 53 | void GroundTurret::init() |
---|
| 54 | { |
---|
[5679] | 55 | this->setClassID(CL_GROUND_TURRET, "GroundTurret"); |
---|
[5739] | 56 | this->loadModel("models/ground_turret.obj", 5); |
---|
[5795] | 57 | this->left = NULL; |
---|
| 58 | this->right = NULL; |
---|
| 59 | |
---|
| 60 | /* left = new Turret(); |
---|
[5740] | 61 | left->setParent(this); |
---|
| 62 | left->setRelCoor(0,10,0); |
---|
| 63 | right = new Turret(); |
---|
| 64 | right->setParent(this); |
---|
[5795] | 65 | right->setRelCoor(0,10,0);*/ |
---|
[5596] | 66 | } |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | /** |
---|
| 70 | * loads a GroundTurret from a XML-element |
---|
| 71 | * @param root the XML-element to load from |
---|
| 72 | * @todo make the class Loadable |
---|
| 73 | */ |
---|
| 74 | void GroundTurret::loadParams(const TiXmlElement* root) |
---|
| 75 | { |
---|
| 76 | // all the clases this Entity is directly derived from must be called in this way, to load all settings. |
---|
[5739] | 77 | static_cast<NPC*>(this)->loadParams(root); |
---|
[5596] | 78 | |
---|
| 79 | |
---|
| 80 | /** |
---|
| 81 | * @todo: make the class Loadable |
---|
| 82 | */ |
---|
[5819] | 83 | const TiXmlElement* element; |
---|
| 84 | |
---|
| 85 | element = root->FirstChildElement("weapon-left"); |
---|
| 86 | if (element != NULL) element = element->FirstChildElement(); |
---|
[5982] | 87 | this->left = dynamic_cast<Weapon*>( Factory::fabricate( element) ); |
---|
[5819] | 88 | if (this->left) |
---|
| 89 | { |
---|
| 90 | this->left->setParent(this); |
---|
[6142] | 91 | this->left->toList(this->getOMListNumber()); |
---|
[5819] | 92 | this->left->setRelCoor(0,10,-5); |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | element = root->FirstChildElement("weapon-right"); |
---|
| 96 | if (element != NULL) if (element != NULL) element = element->FirstChildElement(); |
---|
[5982] | 97 | this->right = dynamic_cast<Weapon*>( Factory::fabricate( element) ); |
---|
[5819] | 98 | if (this->right) |
---|
| 99 | { |
---|
| 100 | this->right->setParent(this); |
---|
[6142] | 101 | this->right->toList(this->getOMListNumber()); |
---|
[5819] | 102 | this->right->setRelCoor(0,10,5); |
---|
| 103 | } |
---|
[5596] | 104 | } |
---|
| 105 | |
---|
| 106 | /** |
---|
| 107 | * advances the GroundTurret about time seconds |
---|
| 108 | * @param time the Time to step |
---|
| 109 | */ |
---|
[5739] | 110 | void GroundTurret::tick(float time) |
---|
| 111 | { |
---|
[5596] | 112 | |
---|
[5739] | 113 | } |
---|
| 114 | |
---|
[5596] | 115 | /** |
---|
| 116 | * draws this worldEntity |
---|
| 117 | */ |
---|
| 118 | void GroundTurret::draw () const |
---|
| 119 | { |
---|
| 120 | glMatrixMode(GL_MODELVIEW); |
---|
| 121 | glPushMatrix(); |
---|
| 122 | float matrix[4][4]; |
---|
| 123 | |
---|
| 124 | /* translate */ |
---|
| 125 | glTranslatef (this->getAbsCoor ().x, |
---|
| 126 | this->getAbsCoor ().y, |
---|
| 127 | this->getAbsCoor ().z); |
---|
| 128 | /* rotate */ |
---|
| 129 | this->getAbsDir().matrix(matrix); |
---|
| 130 | glMultMatrixf((float*)matrix); |
---|
| 131 | |
---|
[5994] | 132 | if (this->getModel()) |
---|
| 133 | this->getModel()->draw(); |
---|
[5819] | 134 | |
---|
| 135 | glPopMatrix(); |
---|
| 136 | if (this->left != NULL) |
---|
[5795] | 137 | this->left->draw(); |
---|
| 138 | if (this->right != NULL) |
---|
| 139 | this->right->draw(); |
---|
[5596] | 140 | } |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | /** |
---|
| 144 | * |
---|
| 145 | * |
---|
| 146 | */ |
---|
| 147 | void GroundTurret::collidesWith (WorldEntity* entity, const Vector& location) |
---|
| 148 | { |
---|
[5915] | 149 | if (entity->isA(CL_PROJECTILE)) |
---|
| 150 | this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90); |
---|
[5596] | 151 | } |
---|
[5680] | 152 | |
---|
| 153 | /** |
---|
| 154 | * |
---|
| 155 | * |
---|
| 156 | */ |
---|
| 157 | void GroundTurret::postSpawn () |
---|
| 158 | { |
---|
[5795] | 159 | |
---|
[5680] | 160 | } |
---|
| 161 | |
---|
| 162 | /** |
---|
| 163 | * |
---|
| 164 | * |
---|
| 165 | */ |
---|
| 166 | void GroundTurret::leftWorld () |
---|
| 167 | { |
---|
[5795] | 168 | |
---|
[5680] | 169 | } |
---|