00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdio.h>
00022 #include <cstring>
00023 #include <cmath>
00024
00025 #include "global.h"
00026 #include "ascstring.h"
00027 #include "stringtokenizer.h"
00028 #include "misc.h"
00029 #include "typen.h"
00030 #include "graphicset.h"
00031
00032
00033 #include "vehicletype.h"
00034 #include "buildingtype.h"
00035 #include "textfileparser.h"
00036 #include "textfile_evaluation.h"
00037
00039 const char* choehenstufen[choehenstufennum] = {"deep submerged", "submerged", "floating", "ground level", "low-level flight", "flight", "high-level flight", "orbit"};
00040
00041
00042
00043 const char* cmovemalitypes[cmovemalitypenum] = { "default",
00044 "light tracked vehicle", "medium tracked vehicle", "heavy tracked vehicle",
00045 "light wheeled vehicle", "medium wheeled vehicle", "heavy wheeled vehicle",
00046 "trooper", "rail vehicle", "medium aircraft",
00047 "medium ship", "building / turret / object", "light aircraft",
00048 "heavy aircraft", "light ship", "heavy ship", "helicopter",
00049 "hoovercraft" };
00050
00051 const char* moveMaliTypeIcons[cmovemalitypenum] = { "pad_symbol_default.png",
00052 "pad_symbol_lighttracked.png",
00053 "pad_symbol_mediumtracked.png",
00054 "pad_symbol_heavytracked.png",
00055 "pad_symbol_lightwheeled.png",
00056 "pad_symbol_mediumwheeled.png",
00057 "pad_symbol_heavywheeled.png",
00058 "pad_symbol_trooper.png",
00059 "pad_symbol_rail.png",
00060 "pad_symbol_mediumair.png",
00061 "pad_symbol_mediumship.png",
00062 "pad_symbol_turret.png",
00063 "pad_symbol_lightair.png",
00064 "pad_symbol_heavyair.png",
00065 "pad_symbol_lightship.png",
00066 "pad_symbol_heavyship.png",
00067 "pad_symbol_helicopter.png",
00068 "pad_symbol_hoovercraft.png" };
00069
00070
00071 const char* cnetcontrol[cnetcontrolnum] = { "store energy", "store material", "store fuel",
00072 "move out all energy", "move out all material", "move out all fuel",
00073 "stop storing energy", "stop storing material", "stop storing fuel",
00074 "stop energy extraction", "stop material extraction", "stop fuelextraction" };
00075 const char* cgeneralnetcontrol[4] = { "store", "move out", "stop storing", "stop using" };
00076
00077
00078 const char* cwettertypen[cwettertypennum] = {"dry (standard)","light rain", "heavy rain", "few snow", "lot of snow", "lot of snow + ice"};
00079 const char* resourceNames[3] = {"energy", "material", "fuel"};
00080
00082 const int experienceDecreaseDamageBoundaries[experienceDecreaseDamageBoundaryNum] = { 80, 60, 40, 20 };
00083
00084 const int directionangle [ sidenum ] =
00085 { 0, -53, -127, -180, -180 -53 , -180 -127 };
00086
00087
00088
00089
00090 const int csolarkraftwerkleistung[cwettertypennum] = { 1024, 512, 256, 756, 384, 384 };
00091
00092
00093
00094
00095 ResourceMatrix :: ResourceMatrix ( )
00096 {
00097 for ( int i = 0; i < resourceTypeNum; i++ )
00098 for ( int j = 0; j < resourceTypeNum; j++ )
00099 if ( i == j )
00100 e[i][j] = 1;
00101 else
00102 e[i][j] = 0;
00103 }
00104
00105 ResourceMatrix :: ResourceMatrix ( const float* f )
00106 {
00107 int num = 0;
00108 for ( int i = 0; i < resourceTypeNum; i++ )
00109 for ( int j = 0; j < resourceTypeNum; j++ )
00110 e[i][j] = f[num++];
00111 }
00112
00113
00114
00115 Resources ResourceMatrix :: operator* ( const Resources& r ) const
00116 {
00117 Resources res;
00118 for ( int i = 0; i < resourceTypeNum; i++ )
00119 for ( int j = 0; j < resourceTypeNum; j++ )
00120 res.resource(i) += int( e[i][j] * r.resource(j));
00121
00122 return res;
00123 }
00124
00125 void ResourceMatrix :: read ( tnstream& stream )
00126 {
00127 stream.readInt();
00128 for ( int i = 0; i < resourceTypeNum; i++ )
00129 for ( int j = 0; j < resourceTypeNum; j++ )
00130 e[i][j] = stream.readFloat();
00131 }
00132
00133 void ResourceMatrix :: write ( tnstream& stream ) const
00134 {
00135 stream.writeInt(1);
00136 for ( int i = 0; i < resourceTypeNum; i++ )
00137 for ( int j = 0; j < resourceTypeNum; j++ )
00138 stream.writeFloat( e[i][j] );
00139 }
00140
00141 void ResourceMatrix :: runTextIO ( const ASCString& name, PropertyContainer& pc )
00142 {
00143 vector<double> values;
00144 if ( !pc.isReading())
00145 for ( int i = 0; i < resourceTypeNum; i++ )
00146 for ( int j = 0; j < resourceTypeNum; j++ )
00147 values.push_back( e[j][i] );
00148
00149 pc.addDFloatArray(name, values);
00150 if ( pc.isReading()) {
00151 if ( values.size() != 9 )
00152 pc.error("invalid element number of " + name);
00153
00154 int pos = 0;
00155 for ( int i = 0; i < resourceTypeNum; i++ )
00156 for ( int j = 0; j < resourceTypeNum; j++ )
00157 e[j][i] = values[pos++];
00158 }
00159 }
00160
00161 void ResourceMatrix :: runTextIO ( const ASCString& name, PropertyContainer& pc, const ResourceMatrix& defaultValue )
00162 {
00163 if ( pc.isReading()) {
00164 if ( pc.find(name))
00165 runTextIO(name,pc);
00166 else
00167 for ( int i = 0; i < resourceTypeNum; i++ )
00168 for ( int j = 0; j < resourceTypeNum; j++ )
00169 e[i][j] = defaultValue.e[i][j];;
00170
00171 } else
00172 runTextIO(name,pc);
00173 }
00174
00175
00176
00177 const char* Resources::name( int r )
00178 {
00179 return resourceNames[r];
00180 }
00181
00182 void Resources :: read ( tnstream& stream )
00183 {
00184 for ( int i = 0; i< resourceTypeNum; i++ )
00185 resource(i) = stream.readInt();
00186 }
00187
00188 void Resources :: write ( tnstream& stream ) const
00189 {
00190 for ( int i = 0; i< resourceTypeNum; i++ )
00191 stream.writeInt( resource(i) );
00192 }
00193
00194
00195 Resources operator- ( const Resources& res1, const Resources& res2 )
00196 {
00197 Resources res = res1;
00198 res -= res2;
00199 return res;
00200 }
00201
00202 Resources operator+ ( const Resources& res1, const Resources& res2 )
00203 {
00204 Resources res = res1;
00205 res += res2;
00206 return res;
00207 }
00208
00209 Resources operator* ( const Resources& res1, float a )
00210 {
00211 Resources res = res1;
00212 for ( int r = 0; r < resourceTypeNum; r++ )
00213 res.resource(r) = int( res.resource(r) * a );
00214 return res;
00215 }
00216
00217 Resources operator/ ( const Resources& res1, float a )
00218 {
00219 Resources res = res1;
00220 for ( int r = 0; r < resourceTypeNum; r++ )
00221 res.resource(r) = int( res.resource(r) / a );
00222 return res;
00223 }
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 void Resources::runTextIO ( PropertyContainer& pc )
00236 {
00237 pc.addInteger ( "Energy", energy );
00238 pc.addInteger ( "Material", material );
00239 pc.addInteger ( "fuel", fuel );
00240 }
00241
00242 void Resources::runTextIO ( PropertyContainer& pc, const Resources& defaultValue )
00243 {
00244 pc.addInteger ( "Energy", energy, defaultValue.energy );
00245 pc.addInteger ( "Material", material, defaultValue.material );
00246 pc.addInteger ( "fuel", fuel, defaultValue.fuel );
00247 }
00248
00249 ASCString Resources::toString()
00250 {
00251 ASCString s;
00252 int cnt = 0;
00253 for ( int r = 0; r < 3; r++ )
00254 if ( resource(r) )
00255 cnt++;
00256
00257 int ps = 0;
00258 for ( int r = 0; r < 3; r++ )
00259 if ( resource(r) ) {
00260 ps++;
00261 ASCString txt3;
00262 txt3.format( "%d %s", resource(r), resourceNames[r] );
00263 if ( ps>1 && ps < cnt )
00264 s += ", ";
00265 if ( ps>1 && ps == cnt )
00266 s += " and ";
00267 s += txt3;
00268 }
00269 return s;
00270 }
00271
00272
00273 void MapCoordinate::move(int width, int height) {
00274 x +=width;
00275 y +=height;
00276 }
00277
00278 ASCString MapCoordinate::toString() const
00279 {
00280 ASCString s;
00281 s.format( "#coord(%d/%d)#", x, y);
00282 return s;
00283 }
00284
00285
00286 vector<IntRange> String2IntRangeVector( const ASCString& t )
00287 {
00288 vector<IntRange> irv;
00289
00290 StringSplit st ( t, ";, " );
00291 ASCString s = st.getNextToken();
00292 while ( !s.empty() ) {
00293
00294 if ( s.find ( "-",1 ) != ASCString::npos ) {
00295 ASCString from = s.substr ( 0, s.find ( "-", 1 ) );
00296 ASCString to = s.substr ( s.find ( "-",1 )+1 );
00297 irv.push_back ( IntRange ( atoi ( from.c_str() ), atoi ( to.c_str() )));
00298 } else {
00299 irv.push_back ( IntRange ( atoi ( s.c_str() ), atoi ( s.c_str() )));
00300 }
00301 s = st.getNextToken();
00302 }
00303 return irv;
00304 }
00305
00306
00307 void IntRange::read ( tnstream& stream )
00308 {
00309 stream.readInt();
00310 from = stream.readInt();
00311 to = stream.readInt();
00312 }
00313
00314 void IntRange::write ( tnstream& stream ) const
00315 {
00316 stream.writeInt(1);
00317 stream.writeInt( from );
00318 stream.writeInt( to );
00319 }
00320
00322
00323