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 | #include "network_game_manager.h" |
---|
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 | { |
---|
56 | this->setClassID(CL_PARAM_POWER_UP, "ParamPowerUp"); |
---|
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); |
---|
67 | |
---|
68 | if( root != NULL && root->FirstChildElement("value") != NULL) { |
---|
69 | |
---|
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 | |
---|
122 | int ParamPowerUp::writeBytes( const byte * data, int length, int sender ) |
---|
123 | { |
---|
124 | setRequestedSync( false ); |
---|
125 | setIsOutOfSync( false ); |
---|
126 | |
---|
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 ); |
---|
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 | |
---|
162 | SYNCHELP_WRITE_FKT( PowerUp::readState ); |
---|
163 | |
---|
164 | int i = this->type; |
---|
165 | SYNCHELP_WRITE_INT( i ); |
---|
166 | SYNCHELP_WRITE_INT( this->value ); |
---|
167 | |
---|
168 | if ( this->value != 0 ) |
---|
169 | { |
---|
170 | SYNCHELP_WRITE_INT( this->min_value ); |
---|
171 | SYNCHELP_WRITE_INT( this->max_value ); |
---|
172 | } |
---|
173 | |
---|
174 | return SYNCHELP_WRITE_N; |
---|
175 | } |
---|
176 | |
---|
177 | *reciever = 0; |
---|
178 | return 0; |
---|
179 | } |
---|
180 | |
---|