[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" |
---|
[7193] | 19 | #include "util/loading/factory.h" |
---|
[6113] | 20 | #include "state.h" |
---|
| 21 | |
---|
| 22 | #include "primitive_model.h" |
---|
| 23 | |
---|
[7193] | 24 | #include "util/loading/factory.h" |
---|
| 25 | #include "util/loading/load_param.h" |
---|
[6424] | 26 | #include "network_game_manager.h" |
---|
[6113] | 27 | |
---|
| 28 | |
---|
[10114] | 29 | |
---|
| 30 | ObjectListDefinition(ParamPowerUp); |
---|
[9869] | 31 | CREATE_FACTORY(ParamPowerUp); |
---|
[9406] | 32 | |
---|
[6113] | 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); |
---|
[9656] | 46 | |
---|
| 47 | registerVar( new SynchronizeableInt( (int*)&type, (int*)&type, "type", PERMISSION_MASTER_SERVER ) ); |
---|
| 48 | registerVar( new SynchronizeableFloat( &value, &value, "value", PERMISSION_MASTER_SERVER ) ); |
---|
| 49 | registerVar( new SynchronizeableFloat( &max_value, &max_value, "max_value", PERMISSION_MASTER_SERVER ) ); |
---|
| 50 | registerVar( new SynchronizeableFloat( &min_value, &min_value, "min_value", PERMISSION_MASTER_SERVER ) ); |
---|
[6113] | 51 | } |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | ParamPowerUp::~ParamPowerUp () |
---|
| 55 | { |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | void ParamPowerUp::init() |
---|
| 60 | { |
---|
[9869] | 61 | this->registerObject(this, ParamPowerUp::_objectList); |
---|
[6113] | 62 | this->value = 0; |
---|
| 63 | this->max_value = 0; |
---|
| 64 | this->min_value = 0; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | void ParamPowerUp::loadParams(const TiXmlElement* root) |
---|
| 69 | { |
---|
[6512] | 70 | PowerUp::loadParams(root); |
---|
[6113] | 71 | LoadParam(root, "type", this, ParamPowerUp, setType); |
---|
[6424] | 72 | |
---|
| 73 | if( root != NULL && root->FirstChildElement("value") != NULL) { |
---|
| 74 | |
---|
[6113] | 75 | LoadParam(root, "value", this, ParamPowerUp, setValue); |
---|
| 76 | } |
---|
| 77 | else { |
---|
| 78 | LoadParam(root, "max-value", this, ParamPowerUp, setMaxValue); |
---|
| 79 | LoadParam(root, "min-value", this, ParamPowerUp, setMinValue); |
---|
| 80 | respawn(); |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | |
---|
[6547] | 84 | void ParamPowerUp::setValue(float value) |
---|
[6113] | 85 | { |
---|
| 86 | this->value = value; |
---|
| 87 | } |
---|
| 88 | |
---|
[7221] | 89 | void ParamPowerUp::setType(const std::string& type) |
---|
[6113] | 90 | { |
---|
[6547] | 91 | for(int i = 0; i < POWERUP_PARAM_size; ++i) { |
---|
[7221] | 92 | if(type == paramTypes[i]) { |
---|
[6113] | 93 | this->type = (EnumParamPowerUpType)i; |
---|
| 94 | break; |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | |
---|
[6547] | 99 | void ParamPowerUp::setMaxValue(float value) |
---|
[6113] | 100 | { |
---|
| 101 | this->max_value = value; |
---|
| 102 | } |
---|
| 103 | |
---|
[6547] | 104 | void ParamPowerUp::setMinValue(float value) |
---|
[6113] | 105 | { |
---|
| 106 | this->min_value = value; |
---|
| 107 | } |
---|
| 108 | |
---|
[6547] | 109 | float ParamPowerUp::getValue() |
---|
[6113] | 110 | { |
---|
| 111 | return this->value; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | EnumParamPowerUpType ParamPowerUp::getType() |
---|
| 115 | { |
---|
| 116 | return this->type; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | void ParamPowerUp::respawn() |
---|
| 120 | { |
---|
| 121 | if(this->min_value != this->max_value) |
---|
| 122 | { |
---|
[6547] | 123 | this->value = this->min_value + rand() * (this->max_value - this->min_value); |
---|
[6113] | 124 | } |
---|
| 125 | } |
---|
| 126 | |
---|