[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[] = { |
---|
| 34 | "shield" |
---|
| 35 | }; |
---|
| 36 | |
---|
| 37 | ParamPowerUp::ParamPowerUp () : PowerUp(0.0, 1.0, 0.0) |
---|
| 38 | { |
---|
| 39 | this->init(); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | ParamPowerUp::ParamPowerUp(const TiXmlElement* root) : PowerUp(0.0, 1.0, 0.0) |
---|
| 43 | { |
---|
| 44 | this->init(); |
---|
| 45 | this->loadParams(root); |
---|
| 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 | { |
---|
| 65 | static_cast<PowerUp*>(this)->loadParams(root); |
---|
| 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 | |
---|
| 79 | void ParamPowerUp::setValue(int value) |
---|
| 80 | { |
---|
| 81 | this->value = value; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | void ParamPowerUp::setType(const char* type) |
---|
| 85 | { |
---|
| 86 | for(int i = 0; i < PARAM_size; ++i) { |
---|
| 87 | if(strcmp(type, paramTypes[i]) == 0) { |
---|
| 88 | this->type = (EnumParamPowerUpType)i; |
---|
| 89 | break; |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | void ParamPowerUp::setMaxValue(int value) |
---|
| 95 | { |
---|
| 96 | this->max_value = value; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | void ParamPowerUp::setMinValue(int value) |
---|
| 100 | { |
---|
| 101 | this->min_value = value; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | int ParamPowerUp::getValue() |
---|
| 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 | { |
---|
| 118 | value = this->min_value + (int)(rand() * (this->max_value - this->min_value)); |
---|
| 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 | |
---|
| 129 | SYNCHELP_READ_FKT( PowerUp::writeState ); |
---|
| 130 | |
---|
| 131 | int i; |
---|
| 132 | SYNCHELP_READ_INT( i ); |
---|
| 133 | this->type = (EnumParamPowerUpType)i; |
---|
| 134 | SYNCHELP_READ_INT( this->value ); |
---|
| 135 | |
---|
| 136 | if ( this->value != 0 ) |
---|
| 137 | { |
---|
| 138 | SYNCHELP_READ_INT( this->min_value ); |
---|
| 139 | SYNCHELP_READ_INT( this->max_value ); |
---|
[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 | |
---|
| 163 | SYNCHELP_WRITE_FKT( PowerUp::readState ); |
---|
| 164 | |
---|
[6498] | 165 | int i = (int)this->type; |
---|
[6424] | 166 | SYNCHELP_WRITE_INT( i ); |
---|
| 167 | SYNCHELP_WRITE_INT( this->value ); |
---|
| 168 | |
---|
| 169 | if ( this->value != 0 ) |
---|
| 170 | { |
---|
| 171 | SYNCHELP_WRITE_INT( this->min_value ); |
---|
| 172 | SYNCHELP_WRITE_INT( this->max_value ); |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | return SYNCHELP_WRITE_N; |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | *reciever = 0; |
---|
| 179 | return 0; |
---|
| 180 | } |
---|
| 181 | |
---|