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 | #include "list.h" |
---|
22 | |
---|
23 | #include "primitive_model.h" |
---|
24 | |
---|
25 | #include "factory.h" |
---|
26 | #include "load_param.h" |
---|
27 | |
---|
28 | using namespace std; |
---|
29 | |
---|
30 | CREATE_FACTORY(ParamPowerUp, CL_PARAM_POWER_UP); |
---|
31 | |
---|
32 | const char* ParamPowerUp::paramTypes[] = { |
---|
33 | "shield" |
---|
34 | }; |
---|
35 | |
---|
36 | ParamPowerUp::ParamPowerUp () : PowerUp(0.0, 1.0, 0.0) |
---|
37 | { |
---|
38 | this->init(); |
---|
39 | } |
---|
40 | |
---|
41 | ParamPowerUp::ParamPowerUp(const TiXmlElement* root) : PowerUp(0.0, 1.0, 0.0) |
---|
42 | { |
---|
43 | this->init(); |
---|
44 | this->loadParams(root); |
---|
45 | } |
---|
46 | |
---|
47 | |
---|
48 | ParamPowerUp::~ParamPowerUp () |
---|
49 | { |
---|
50 | } |
---|
51 | |
---|
52 | |
---|
53 | void ParamPowerUp::init() |
---|
54 | { |
---|
55 | this->value = 0; |
---|
56 | this->max_value = 0; |
---|
57 | this->min_value = 0; |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | void ParamPowerUp::loadParams(const TiXmlElement* root) |
---|
62 | { |
---|
63 | static_cast<PowerUp*>(this)->loadParams(root); |
---|
64 | LoadParam(root, "type", this, ParamPowerUp, setType); |
---|
65 | if(root->FirstChildElement("value") != NULL) { |
---|
66 | LoadParam(root, "value", this, ParamPowerUp, setValue); |
---|
67 | } |
---|
68 | else { |
---|
69 | LoadParam(root, "max-value", this, ParamPowerUp, setMaxValue); |
---|
70 | LoadParam(root, "min-value", this, ParamPowerUp, setMinValue); |
---|
71 | respawn(); |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | void ParamPowerUp::setValue(int value) |
---|
76 | { |
---|
77 | this->value = value; |
---|
78 | } |
---|
79 | |
---|
80 | void ParamPowerUp::setType(const char* type) |
---|
81 | { |
---|
82 | for(int i = 0; i < PARAM_size; ++i) { |
---|
83 | if(strcmp(type, paramTypes[i]) == 0) { |
---|
84 | this->type = (EnumParamPowerUpType)i; |
---|
85 | break; |
---|
86 | } |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | void ParamPowerUp::setMaxValue(int value) |
---|
91 | { |
---|
92 | this->max_value = value; |
---|
93 | } |
---|
94 | |
---|
95 | void ParamPowerUp::setMinValue(int value) |
---|
96 | { |
---|
97 | this->min_value = value; |
---|
98 | } |
---|
99 | |
---|
100 | int ParamPowerUp::getValue() |
---|
101 | { |
---|
102 | return this->value; |
---|
103 | } |
---|
104 | |
---|
105 | EnumParamPowerUpType ParamPowerUp::getType() |
---|
106 | { |
---|
107 | return this->type; |
---|
108 | } |
---|
109 | |
---|
110 | void ParamPowerUp::respawn() |
---|
111 | { |
---|
112 | if(this->min_value != this->max_value) |
---|
113 | { |
---|
114 | value = this->min_value + (int)(rand() * (this->max_value - this->min_value)); |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | |
---|