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