[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 "param_power_up.h" |
---|
| 19 | #include "factory.h" |
---|
| 20 | #include "state.h" |
---|
| 21 | |
---|
| 22 | #include "primitive_model.h" |
---|
| 23 | |
---|
| 24 | #include "factory.h" |
---|
| 25 | #include "load_param.h" |
---|
[6424] | 26 | #include "network_game_manager.h" |
---|
[6113] | 27 | |
---|
| 28 | using namespace std; |
---|
| 29 | |
---|
| 30 | CREATE_FACTORY(ParamPowerUp, CL_PARAM_POWER_UP); |
---|
| 31 | |
---|
| 32 | const char* ParamPowerUp::paramTypes[] = { |
---|
[6547] | 33 | "shield", |
---|
| 34 | "max-shield", |
---|
| 35 | "health", |
---|
| 36 | "max-health", |
---|
[6113] | 37 | }; |
---|
| 38 | |
---|
| 39 | ParamPowerUp::ParamPowerUp(const TiXmlElement* root) : PowerUp(0.0, 1.0, 0.0) |
---|
| 40 | { |
---|
| 41 | this->init(); |
---|
[7065] | 42 | this->loadPickupSound("sound/powerups/power_up_6.wav"); |
---|
[6695] | 43 | if( root != NULL) |
---|
| 44 | this->loadParams(root); |
---|
[6113] | 45 | } |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | ParamPowerUp::~ParamPowerUp () |
---|
| 49 | { |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | void ParamPowerUp::init() |
---|
| 54 | { |
---|
[6424] | 55 | this->setClassID(CL_PARAM_POWER_UP, "ParamPowerUp"); |
---|
[6113] | 56 | this->value = 0; |
---|
| 57 | this->max_value = 0; |
---|
| 58 | this->min_value = 0; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | void ParamPowerUp::loadParams(const TiXmlElement* root) |
---|
| 63 | { |
---|
[6512] | 64 | PowerUp::loadParams(root); |
---|
[6113] | 65 | LoadParam(root, "type", this, ParamPowerUp, setType); |
---|
[6424] | 66 | |
---|
| 67 | if( root != NULL && root->FirstChildElement("value") != NULL) { |
---|
| 68 | |
---|
[6113] | 69 | LoadParam(root, "value", this, ParamPowerUp, setValue); |
---|
| 70 | } |
---|
| 71 | else { |
---|
| 72 | LoadParam(root, "max-value", this, ParamPowerUp, setMaxValue); |
---|
| 73 | LoadParam(root, "min-value", this, ParamPowerUp, setMinValue); |
---|
| 74 | respawn(); |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | |
---|
[6547] | 78 | void ParamPowerUp::setValue(float value) |
---|
[6113] | 79 | { |
---|
| 80 | this->value = value; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | void ParamPowerUp::setType(const char* type) |
---|
| 84 | { |
---|
[6547] | 85 | for(int i = 0; i < POWERUP_PARAM_size; ++i) { |
---|
[6113] | 86 | if(strcmp(type, paramTypes[i]) == 0) { |
---|
| 87 | this->type = (EnumParamPowerUpType)i; |
---|
| 88 | break; |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | |
---|
[6547] | 93 | void ParamPowerUp::setMaxValue(float value) |
---|
[6113] | 94 | { |
---|
| 95 | this->max_value = value; |
---|
| 96 | } |
---|
| 97 | |
---|
[6547] | 98 | void ParamPowerUp::setMinValue(float value) |
---|
[6113] | 99 | { |
---|
| 100 | this->min_value = value; |
---|
| 101 | } |
---|
| 102 | |
---|
[6547] | 103 | float ParamPowerUp::getValue() |
---|
[6113] | 104 | { |
---|
| 105 | return this->value; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | EnumParamPowerUpType ParamPowerUp::getType() |
---|
| 109 | { |
---|
| 110 | return this->type; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | void ParamPowerUp::respawn() |
---|
| 114 | { |
---|
| 115 | if(this->min_value != this->max_value) |
---|
| 116 | { |
---|
[6547] | 117 | this->value = this->min_value + rand() * (this->max_value - this->min_value); |
---|
[6113] | 118 | } |
---|
| 119 | } |
---|
| 120 | |
---|
[6424] | 121 | int ParamPowerUp::writeBytes( const byte * data, int length, int sender ) |
---|
| 122 | { |
---|
| 123 | setRequestedSync( false ); |
---|
| 124 | setIsOutOfSync( false ); |
---|
[6113] | 125 | |
---|
[6424] | 126 | SYNCHELP_READ_BEGIN(); |
---|
| 127 | |
---|
[6815] | 128 | SYNCHELP_READ_FKT( PowerUp::writeState, NWT_PPU_WE_STATE ); |
---|
[6424] | 129 | |
---|
| 130 | int i; |
---|
[6815] | 131 | SYNCHELP_READ_INT( i, NWT_PPU_TYPE ); |
---|
[6424] | 132 | this->type = (EnumParamPowerUpType)i; |
---|
[6815] | 133 | SYNCHELP_READ_FLOAT( this->value, NWT_PPU_VALUE ); |
---|
[6424] | 134 | |
---|
| 135 | if ( this->value != 0 ) |
---|
| 136 | { |
---|
[6815] | 137 | SYNCHELP_READ_FLOAT( this->min_value, NWT_PPU_MINVALUE ); |
---|
| 138 | SYNCHELP_READ_FLOAT( this->max_value, NWT_PPU_MAXVALUE ); |
---|
[6498] | 139 | respawn(); |
---|
[6424] | 140 | } |
---|
| 141 | |
---|
| 142 | return SYNCHELP_READ_N; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | int ParamPowerUp::readBytes( byte * data, int maxLength, int * reciever ) |
---|
| 148 | { |
---|
| 149 | if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() ) |
---|
| 150 | { |
---|
| 151 | (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() ); |
---|
| 152 | setRequestedSync( true ); |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | int rec = this->getRequestSync(); |
---|
| 156 | if ( rec > 0 ) |
---|
| 157 | { |
---|
| 158 | *reciever = rec; |
---|
| 159 | |
---|
| 160 | SYNCHELP_WRITE_BEGIN(); |
---|
| 161 | |
---|
[6815] | 162 | SYNCHELP_WRITE_FKT( PowerUp::readState, NWT_PPU_WE_STATE ); |
---|
[6424] | 163 | |
---|
[6498] | 164 | int i = (int)this->type; |
---|
[6815] | 165 | SYNCHELP_WRITE_INT( i, NWT_PPU_TYPE ); |
---|
| 166 | SYNCHELP_WRITE_FLOAT( this->value, NWT_PPU_VALUE ); |
---|
[6424] | 167 | |
---|
| 168 | if ( this->value != 0 ) |
---|
| 169 | { |
---|
[6815] | 170 | SYNCHELP_WRITE_FLOAT( this->min_value, NWT_PPU_MINVALUE ); |
---|
| 171 | SYNCHELP_WRITE_FLOAT( this->max_value, NWT_PPU_MAXVALUE ); |
---|
[6424] | 172 | } |
---|
| 173 | |
---|
| 174 | return SYNCHELP_WRITE_N; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | *reciever = 0; |
---|
| 178 | return 0; |
---|
| 179 | } |
---|
| 180 | |
---|