[6113] | 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: Benjamin Grauer |
---|
| 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
| 17 | |
---|
| 18 | #include "weapon_power_up.h" |
---|
| 19 | #include "factory.h" |
---|
| 20 | #include "state.h" |
---|
[6243] | 21 | #include "list.h" |
---|
[6424] | 22 | #include "network_game_manager.h" |
---|
[6113] | 23 | |
---|
| 24 | #include "primitive_model.h" |
---|
| 25 | |
---|
| 26 | #include "factory.h" |
---|
| 27 | #include "load_param.h" |
---|
| 28 | |
---|
| 29 | using namespace std; |
---|
| 30 | |
---|
| 31 | CREATE_FACTORY(WeaponPowerUp, CL_WEAPON_POWER_UP); |
---|
| 32 | |
---|
| 33 | WeaponPowerUp::WeaponPowerUp () : PowerUp(1.0, 1.0, 0.0) |
---|
| 34 | { |
---|
| 35 | this->init(); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | WeaponPowerUp::WeaponPowerUp(const TiXmlElement* root) : PowerUp(1.0, 1.0, 0.0) |
---|
| 39 | { |
---|
| 40 | this->init(); |
---|
[6695] | 41 | if( root != NULL) |
---|
| 42 | this->loadParams(root); |
---|
[6113] | 43 | } |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | WeaponPowerUp::~WeaponPowerUp () |
---|
| 47 | { |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | void WeaponPowerUp::init() |
---|
| 52 | { |
---|
[6547] | 53 | this->setClassID(CL_WEAPON_POWER_UP, "WeaponPowerUp"); |
---|
| 54 | this->weaponXML = NULL; |
---|
[6710] | 55 | this->weaponID = CL_NULL; |
---|
[6547] | 56 | this->weapon = NULL; |
---|
[6113] | 57 | } |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | void WeaponPowerUp::loadParams(const TiXmlElement* root) |
---|
| 61 | { |
---|
[6512] | 62 | PowerUp::loadParams(root); |
---|
[6113] | 63 | const TiXmlElement* elem = root->FirstChildElement("weapon"); |
---|
| 64 | if(elem != NULL && (elem = elem->FirstChildElement()) != NULL) |
---|
| 65 | { |
---|
| 66 | this->weaponXML = elem; |
---|
| 67 | respawn(); |
---|
| 68 | } |
---|
| 69 | else |
---|
| 70 | { |
---|
| 71 | LoadParam(root, "weaponID", this, WeaponPowerUp, setWeaponClass); |
---|
| 72 | } |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | Weapon* WeaponPowerUp::getWeapon() |
---|
| 76 | { |
---|
| 77 | return this->weapon; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | void WeaponPowerUp::respawn() |
---|
| 81 | { |
---|
| 82 | this->weapon = dynamic_cast<Weapon*>((weaponXML == NULL) |
---|
[6710] | 83 | ? Factory::fabricate(static_cast<ClassID>(weaponID)) |
---|
| 84 | : Factory::fabricate((TiXmlElement*)this->getXmlElem()->FirstChildElement("weapon"))); |
---|
| 85 | this->model = this->weapon->getModel(0); |
---|
[6113] | 86 | } |
---|
| 87 | |
---|
| 88 | void WeaponPowerUp::setWeaponClass(const char* name) |
---|
| 89 | { |
---|
| 90 | this->weapon = dynamic_cast<Weapon*>(Factory::fabricate(name)); |
---|
[6710] | 91 | this->weaponID = (ClassID)this->weapon->getLeafClassID(); |
---|
| 92 | this->model = this->weapon->getModel(0); |
---|
[6113] | 93 | } |
---|
[6424] | 94 | |
---|
| 95 | int WeaponPowerUp::writeBytes( const byte * data, int length, int sender ) |
---|
| 96 | { |
---|
| 97 | setRequestedSync( false ); |
---|
| 98 | setIsOutOfSync( false ); |
---|
| 99 | |
---|
| 100 | SYNCHELP_READ_BEGIN(); |
---|
| 101 | |
---|
| 102 | SYNCHELP_READ_FKT( PowerUp::writeState ); |
---|
| 103 | |
---|
| 104 | //TODO: sync weapon class ( see loadParams ) |
---|
| 105 | |
---|
| 106 | return SYNCHELP_READ_N; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | int WeaponPowerUp::readBytes( byte * data, int maxLength, int * reciever ) |
---|
| 112 | { |
---|
| 113 | if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() ) |
---|
| 114 | { |
---|
| 115 | (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() ); |
---|
| 116 | setRequestedSync( true ); |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | int rec = this->getRequestSync(); |
---|
| 120 | if ( rec > 0 ) |
---|
| 121 | { |
---|
| 122 | *reciever = rec; |
---|
| 123 | |
---|
| 124 | SYNCHELP_WRITE_BEGIN(); |
---|
| 125 | |
---|
| 126 | SYNCHELP_WRITE_FKT( PowerUp::readState ); |
---|
| 127 | |
---|
| 128 | //TODO: sync weapon class ( see loadParams ) |
---|
| 129 | |
---|
| 130 | return SYNCHELP_WRITE_N; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | *reciever = 0; |
---|
| 134 | return 0; |
---|
| 135 | } |
---|