[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 | |
---|
[5795] | 20 | #include "factory.h" |
---|
[6341] | 21 | #include "network_game_manager.h" |
---|
[5795] | 22 | #include "load_param.h" |
---|
| 23 | |
---|
[5739] | 24 | CREATE_FACTORY(GroundTurret, CL_GROUND_TURRET); |
---|
| 25 | |
---|
[5596] | 26 | using namespace std; |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | * constructs and loads a GroundTurret from a XML-element |
---|
| 31 | * @param root the XML-element to load from |
---|
| 32 | */ |
---|
| 33 | GroundTurret::GroundTurret(const TiXmlElement* root) |
---|
| 34 | { |
---|
| 35 | this->init(); |
---|
| 36 | if (root != NULL) |
---|
| 37 | this->loadParams(root); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | /** |
---|
| 42 | * standard deconstructor |
---|
| 43 | */ |
---|
| 44 | GroundTurret::~GroundTurret () |
---|
| 45 | { |
---|
| 46 | |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | /** |
---|
| 51 | * initializes the GroundTurret |
---|
| 52 | * @todo change this to what you wish |
---|
| 53 | */ |
---|
| 54 | void GroundTurret::init() |
---|
| 55 | { |
---|
[5679] | 56 | this->setClassID(CL_GROUND_TURRET, "GroundTurret"); |
---|
[5739] | 57 | this->loadModel("models/ground_turret.obj", 5); |
---|
[5795] | 58 | this->left = NULL; |
---|
| 59 | this->right = NULL; |
---|
| 60 | |
---|
| 61 | /* left = new Turret(); |
---|
[5740] | 62 | left->setParent(this); |
---|
| 63 | left->setRelCoor(0,10,0); |
---|
| 64 | right = new Turret(); |
---|
| 65 | right->setParent(this); |
---|
[5795] | 66 | right->setRelCoor(0,10,0);*/ |
---|
[5596] | 67 | } |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | /** |
---|
| 71 | * loads a GroundTurret from a XML-element |
---|
| 72 | * @param root the XML-element to load from |
---|
| 73 | * @todo make the class Loadable |
---|
| 74 | */ |
---|
| 75 | void GroundTurret::loadParams(const TiXmlElement* root) |
---|
| 76 | { |
---|
| 77 | // all the clases this Entity is directly derived from must be called in this way, to load all settings. |
---|
[5739] | 78 | static_cast<NPC*>(this)->loadParams(root); |
---|
[5596] | 79 | |
---|
| 80 | |
---|
| 81 | /** |
---|
| 82 | * @todo: make the class Loadable |
---|
| 83 | */ |
---|
[5819] | 84 | const TiXmlElement* element; |
---|
| 85 | |
---|
| 86 | element = root->FirstChildElement("weapon-left"); |
---|
| 87 | if (element != NULL) element = element->FirstChildElement(); |
---|
[5982] | 88 | this->left = dynamic_cast<Weapon*>( Factory::fabricate( element) ); |
---|
[5819] | 89 | if (this->left) |
---|
| 90 | { |
---|
| 91 | this->left->setParent(this); |
---|
[6142] | 92 | this->left->toList(this->getOMListNumber()); |
---|
[5819] | 93 | this->left->setRelCoor(0,10,-5); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | element = root->FirstChildElement("weapon-right"); |
---|
| 97 | if (element != NULL) if (element != NULL) element = element->FirstChildElement(); |
---|
[5982] | 98 | this->right = dynamic_cast<Weapon*>( Factory::fabricate( element) ); |
---|
[5819] | 99 | if (this->right) |
---|
| 100 | { |
---|
| 101 | this->right->setParent(this); |
---|
[6142] | 102 | this->right->toList(this->getOMListNumber()); |
---|
[5819] | 103 | this->right->setRelCoor(0,10,5); |
---|
| 104 | } |
---|
[5596] | 105 | } |
---|
| 106 | |
---|
| 107 | /** |
---|
| 108 | * advances the GroundTurret about time seconds |
---|
| 109 | * @param time the Time to step |
---|
| 110 | */ |
---|
[5739] | 111 | void GroundTurret::tick(float time) |
---|
| 112 | { |
---|
[5596] | 113 | |
---|
[5739] | 114 | } |
---|
| 115 | |
---|
[5596] | 116 | /** |
---|
| 117 | * draws this worldEntity |
---|
| 118 | */ |
---|
| 119 | void GroundTurret::draw () const |
---|
| 120 | { |
---|
[6424] | 121 | WorldEntity::draw(); |
---|
[5596] | 122 | |
---|
[5819] | 123 | if (this->left != NULL) |
---|
[5795] | 124 | this->left->draw(); |
---|
| 125 | if (this->right != NULL) |
---|
| 126 | this->right->draw(); |
---|
[5596] | 127 | } |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | /** |
---|
| 131 | * |
---|
| 132 | * |
---|
| 133 | */ |
---|
| 134 | void GroundTurret::collidesWith (WorldEntity* entity, const Vector& location) |
---|
| 135 | { |
---|
[5915] | 136 | if (entity->isA(CL_PROJECTILE)) |
---|
| 137 | this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90); |
---|
[5596] | 138 | } |
---|
[5680] | 139 | |
---|
| 140 | /** |
---|
| 141 | * |
---|
| 142 | * |
---|
| 143 | */ |
---|
| 144 | void GroundTurret::postSpawn () |
---|
| 145 | { |
---|
[5795] | 146 | |
---|
[5680] | 147 | } |
---|
| 148 | |
---|
| 149 | /** |
---|
| 150 | * |
---|
| 151 | * |
---|
| 152 | */ |
---|
| 153 | void GroundTurret::leftWorld () |
---|
| 154 | { |
---|
[5795] | 155 | |
---|
[5680] | 156 | } |
---|
[6341] | 157 | |
---|
| 158 | /** |
---|
| 159 | * Writes data from network containing information about the state |
---|
| 160 | * @param data pointer to data |
---|
| 161 | * @param length length of data |
---|
| 162 | * @param sender hostID of sender |
---|
| 163 | */ |
---|
| 164 | int GroundTurret::writeBytes( const byte * data, int length, int sender ) |
---|
| 165 | { |
---|
| 166 | setRequestedSync( false ); |
---|
| 167 | setIsOutOfSync( false ); |
---|
| 168 | |
---|
| 169 | SYNCHELP_READ_BEGIN(); |
---|
| 170 | |
---|
| 171 | SYNCHELP_READ_FKT( WorldEntity::writeState ); |
---|
| 172 | |
---|
| 173 | return SYNCHELP_READ_N; |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | /** |
---|
| 177 | * data copied in data will bee sent to another host |
---|
| 178 | * @param data pointer to data |
---|
| 179 | * @param maxLength max length of data |
---|
| 180 | * @return the number of bytes writen |
---|
| 181 | */ |
---|
| 182 | int GroundTurret::readBytes( byte * data, int maxLength, int * reciever ) |
---|
| 183 | { |
---|
| 184 | SYNCHELP_WRITE_BEGIN(); |
---|
| 185 | |
---|
| 186 | if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() ) |
---|
| 187 | { |
---|
| 188 | (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() ); |
---|
| 189 | setRequestedSync( true ); |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | int rec = this->getRequestSync(); |
---|
| 193 | if ( rec > 0 ) |
---|
| 194 | { |
---|
| 195 | *reciever = rec; |
---|
| 196 | |
---|
| 197 | SYNCHELP_WRITE_FKT( WorldEntity::readState ); |
---|
| 198 | |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | *reciever = 0; |
---|
| 202 | return SYNCHELP_WRITE_N; |
---|
| 203 | } |
---|