[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(const TiXmlElement* root) : PowerUp(1.0, 1.0, 0.0) |
---|
| 34 | { |
---|
| 35 | this->init(); |
---|
[7065] | 36 | this->loadPickupSound("sound/powerups/whats this2.wav"); |
---|
[6695] | 37 | if( root != NULL) |
---|
| 38 | this->loadParams(root); |
---|
[6113] | 39 | } |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | WeaponPowerUp::~WeaponPowerUp () |
---|
| 43 | { |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | void WeaponPowerUp::init() |
---|
| 48 | { |
---|
[6547] | 49 | this->setClassID(CL_WEAPON_POWER_UP, "WeaponPowerUp"); |
---|
| 50 | this->weaponXML = NULL; |
---|
| 51 | this->weapon = NULL; |
---|
[6113] | 52 | } |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | void WeaponPowerUp::loadParams(const TiXmlElement* root) |
---|
| 56 | { |
---|
[6512] | 57 | PowerUp::loadParams(root); |
---|
[6113] | 58 | const TiXmlElement* elem = root->FirstChildElement("weapon"); |
---|
| 59 | if(elem != NULL && (elem = elem->FirstChildElement()) != NULL) |
---|
| 60 | { |
---|
| 61 | this->weaponXML = elem; |
---|
[6973] | 62 | newWeapon(); |
---|
[6113] | 63 | } |
---|
| 64 | else |
---|
| 65 | { |
---|
| 66 | LoadParam(root, "weaponID", this, WeaponPowerUp, setWeaponClass); |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | Weapon* WeaponPowerUp::getWeapon() |
---|
| 71 | { |
---|
| 72 | return this->weapon; |
---|
| 73 | } |
---|
| 74 | |
---|
[6973] | 75 | bool WeaponPowerUp::process(WeaponManager* manager) |
---|
[6113] | 76 | { |
---|
[6973] | 77 | if(manager->addWeapon(this->weapon)) { |
---|
| 78 | newWeapon(); |
---|
| 79 | } |
---|
| 80 | else { |
---|
| 81 | manager->increaseAmmunition(this->weapon->getProjectileType(), this->weapon->getEnergy()); |
---|
| 82 | } |
---|
| 83 | return true; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | void WeaponPowerUp::newWeapon() |
---|
| 87 | { |
---|
[6113] | 88 | this->weapon = dynamic_cast<Weapon*>((weaponXML == NULL) |
---|
[6973] | 89 | ? Factory::fabricate(static_cast<ClassID>(this->weapon->getLeafClassID())) |
---|
[6710] | 90 | : Factory::fabricate((TiXmlElement*)this->getXmlElem()->FirstChildElement("weapon"))); |
---|
| 91 | this->model = this->weapon->getModel(0); |
---|
[6113] | 92 | } |
---|
| 93 | |
---|
| 94 | void WeaponPowerUp::setWeaponClass(const char* name) |
---|
| 95 | { |
---|
| 96 | this->weapon = dynamic_cast<Weapon*>(Factory::fabricate(name)); |
---|
[6710] | 97 | this->model = this->weapon->getModel(0); |
---|
[6113] | 98 | } |
---|
[6424] | 99 | |
---|
| 100 | int WeaponPowerUp::writeBytes( const byte * data, int length, int sender ) |
---|
| 101 | { |
---|
| 102 | setRequestedSync( false ); |
---|
| 103 | setIsOutOfSync( false ); |
---|
| 104 | |
---|
| 105 | SYNCHELP_READ_BEGIN(); |
---|
| 106 | |
---|
[6815] | 107 | SYNCHELP_READ_FKT( PowerUp::writeState, NWT_WPU_WE_STATE ); |
---|
[6424] | 108 | |
---|
| 109 | //TODO: sync weapon class ( see loadParams ) |
---|
| 110 | |
---|
| 111 | return SYNCHELP_READ_N; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | int WeaponPowerUp::readBytes( byte * data, int maxLength, int * reciever ) |
---|
| 117 | { |
---|
| 118 | if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() ) |
---|
| 119 | { |
---|
| 120 | (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() ); |
---|
| 121 | setRequestedSync( true ); |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | int rec = this->getRequestSync(); |
---|
| 125 | if ( rec > 0 ) |
---|
| 126 | { |
---|
| 127 | *reciever = rec; |
---|
| 128 | |
---|
| 129 | SYNCHELP_WRITE_BEGIN(); |
---|
| 130 | |
---|
[6815] | 131 | SYNCHELP_WRITE_FKT( PowerUp::readState, NWT_WPU_WE_STATE ); |
---|
[6424] | 132 | |
---|
| 133 | //TODO: sync weapon class ( see loadParams ) |
---|
| 134 | |
---|
| 135 | return SYNCHELP_WRITE_N; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | *reciever = 0; |
---|
| 139 | return 0; |
---|
| 140 | } |
---|