1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
|
/*
This file is part of Advanced Strategic Command; http://www.asc-hq.de
Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <cstring>
#include <cmath>
#include "global.h"
#include "ascstring.h"
#include "stringtokenizer.h"
#include "misc.h"
#include "typen.h"
#include "graphicset.h"
// #include "basegfx.h"
#include "vehicletype.h"
#include "buildingtype.h"
#include "textfileparser.h"
#include "textfile_evaluation.h"
//! The different levels of height
const char* choehenstufen[choehenstufennum] = {"deep submerged", "submerged", "floating", "ground level", "low-level flight", "flight", "high-level flight", "orbit"};
const char* cmovemalitypes[cmovemalitypenum] = { "default",
"light tracked vehicle", "medium tracked vehicle", "heavy tracked vehicle",
"light wheeled vehicle", "medium wheeled vehicle", "heavy wheeled vehicle",
"trooper", "rail vehicle", "medium aircraft",
"medium ship", "building / turret / object", "light aircraft",
"heavy aircraft", "light ship", "heavy ship", "helicopter",
"hoovercraft" };
const char* moveMaliTypeIcons[cmovemalitypenum] = { "pad_symbol_default.png",
"pad_symbol_lighttracked.png",
"pad_symbol_mediumtracked.png",
"pad_symbol_heavytracked.png",
"pad_symbol_lightwheeled.png",
"pad_symbol_mediumwheeled.png",
"pad_symbol_heavywheeled.png",
"pad_symbol_trooper.png",
"pad_symbol_rail.png",
"pad_symbol_mediumair.png",
"pad_symbol_mediumship.png",
"pad_symbol_turret.png",
"pad_symbol_lightair.png",
"pad_symbol_heavyair.png",
"pad_symbol_lightship.png",
"pad_symbol_heavyship.png",
"pad_symbol_helicopter.png",
"pad_symbol_hoovercraft.png" };
const char* cnetcontrol[cnetcontrolnum] = { "store energy", "store material", "store fuel",
"move out all energy", "move out all material", "move out all fuel",
"stop storing energy", "stop storing material", "stop storing fuel",
"stop energy extraction", "stop material extraction", "stop fuelextraction" };
const char* cgeneralnetcontrol[4] = { "store", "move out", "stop storing", "stop using" };
// Functionen in Gebuden ....
const char* cwettertypen[cwettertypennum] = {"dry (standard)","light rain", "heavy rain", "few snow", "lot of snow", "lot of snow + ice"};
const char* resourceNames[3] = {"energy", "material", "fuel"};
//! when repairing a unit, the experience of the unit is decreased by one when passing each of these damage levels
const int experienceDecreaseDamageBoundaries[experienceDecreaseDamageBoundaryNum] = { 80, 60, 40, 20 };
const int directionangle [ sidenum ] =
{ 0, -53, -127, -180, -180 -53 , -180 -127 };
const int csolarkraftwerkleistung[cwettertypennum] = { 1024, 512, 256, 756, 384, 384 }; // 1024 ist Maximum
int getheightdelta ( int height1, int height2 )
{
int ah = height1;
int dh = height2;
int hd = dh - ah;
if ( ah >= 3 && dh <= 2 )
hd++;
if (dh >= 3 && ah <= 2 )
hd--;
return hd;
}
ResourceMatrix :: ResourceMatrix ( )
{
for ( int i = 0; i < resourceTypeNum; i++ )
for ( int j = 0; j < resourceTypeNum; j++ )
if ( i == j )
e[i][j] = 1;
else
e[i][j] = 0;
}
ResourceMatrix :: ResourceMatrix ( const float* f )
{
int num = 0;
for ( int i = 0; i < resourceTypeNum; i++ )
for ( int j = 0; j < resourceTypeNum; j++ )
e[i][j] = f[num++];
}
Resources ResourceMatrix :: operator* ( const Resources& r ) const
{
Resources res;
for ( int i = 0; i < resourceTypeNum; i++ )
for ( int j = 0; j < resourceTypeNum; j++ )
res.resource(i) += int( e[i][j] * r.resource(j));
return res;
}
void ResourceMatrix :: read ( tnstream& stream )
{
stream.readInt(); // version
for ( int i = 0; i < resourceTypeNum; i++ )
for ( int j = 0; j < resourceTypeNum; j++ )
e[i][j] = stream.readFloat();
}
void ResourceMatrix :: write ( tnstream& stream ) const
{
stream.writeInt(1);
for ( int i = 0; i < resourceTypeNum; i++ )
for ( int j = 0; j < resourceTypeNum; j++ )
stream.writeFloat( e[i][j] );
}
void ResourceMatrix :: runTextIO ( const ASCString& name, PropertyContainer& pc )
{
vector<double> values;
if ( !pc.isReading())
for ( int i = 0; i < resourceTypeNum; i++ )
for ( int j = 0; j < resourceTypeNum; j++ )
values.push_back( e[j][i] );
pc.addDFloatArray(name, values);
if ( pc.isReading()) {
if ( values.size() != 9 )
pc.error("invalid element number of " + name);
int pos = 0;
for ( int i = 0; i < resourceTypeNum; i++ )
for ( int j = 0; j < resourceTypeNum; j++ )
e[j][i] = values[pos++];
}
}
void ResourceMatrix :: runTextIO ( const ASCString& name, PropertyContainer& pc, const ResourceMatrix& defaultValue )
{
if ( pc.isReading()) {
if ( pc.find(name))
runTextIO(name,pc);
else
for ( int i = 0; i < resourceTypeNum; i++ )
for ( int j = 0; j < resourceTypeNum; j++ )
e[i][j] = defaultValue.e[i][j];;
} else
runTextIO(name,pc);
}
const char* Resources::name( int r )
{
return resourceNames[r];
}
void Resources :: read ( tnstream& stream )
{
for ( int i = 0; i< resourceTypeNum; i++ )
resource(i) = stream.readInt();
}
void Resources :: write ( tnstream& stream ) const
{
for ( int i = 0; i< resourceTypeNum; i++ )
stream.writeInt( resource(i) );
}
Resources operator- ( const Resources& res1, const Resources& res2 )
{
Resources res = res1;
res -= res2;
return res;
}
Resources operator- ( const Resources& res1 )
{
return Resources ( -res1.energy, -res1.material, -res1.fuel );
}
Resources operator+ ( const Resources& res1, const Resources& res2 )
{
Resources res = res1;
res += res2;
return res;
}
Resources operator* ( const Resources& res1, float a )
{
Resources res = res1;
for ( int r = 0; r < resourceTypeNum; r++ )
res.resource(r) = int( res.resource(r) * a );
return res;
}
Resources operator/ ( const Resources& res1, float a )
{
Resources res = res1;
for ( int r = 0; r < resourceTypeNum; r++ )
res.resource(r) = int( res.resource(r) / a );
return res;
}
/*
Resources Resources::operator* ( double d )
{
Resources rs;
for ( int i = 0; i < resourceTypeNum; i++ )
rs.resource(i) = int( resource(i)*d );
return rs;
}
*/
void Resources::runTextIO ( PropertyContainer& pc )
{
pc.addInteger ( "Energy", energy );
pc.addInteger ( "Material", material );
pc.addInteger ( "fuel", fuel );
}
void Resources::runTextIO ( PropertyContainer& pc, const Resources& defaultValue )
{
pc.addInteger ( "Energy", energy, defaultValue.energy );
pc.addInteger ( "Material", material, defaultValue.material );
pc.addInteger ( "fuel", fuel, defaultValue.fuel );
}
ASCString Resources::toString() const
{
ASCString s;
int cnt = 0;
for ( int r = 0; r < 3; r++ )
if ( resource(r) )
cnt++;
int ps = 0;
for ( int r = 0; r < 3; r++ )
if ( resource(r) ) {
ps++;
ASCString txt3;
txt3.format( "%d %s", resource(r), resourceNames[r] );
if ( ps>1 && ps < cnt )
s += ", ";
if ( ps>1 && ps == cnt )
s += " and ";
s += txt3;
}
return s;
}
MapCoordinate& MapCoordinate::operator+=( const MapCoodinateVector& delta )
{
x += delta.dx;
y += delta.dy;
return *this;
}
void MapCoordinate::move(int width, int height) {
x +=width;
y +=height;
}
ASCString MapCoordinate::toString(bool coordinates) const
{
ASCString s;
if ( coordinates )
s.format( "%d/%d", x, y);
else
s.format( "#coord(%d/%d)#", x, y);
return s;
}
ASCString MapCoordinate3D::toString(bool coordinates) const
{
ASCString s;
if ( coordinates )
s.format( "%d/%d/%d", x, y, getNumericalHeight());
else
s.format( "#coord(%d/%d)#", x, y);
return s;
}
vector<IntRange> String2IntRangeVector( const ASCString& t )
{
vector<IntRange> irv;
StringSplit st ( t, ";, " );
ASCString s = st.getNextToken();
while ( !s.empty() ) {
// we have to take care about negative numbers , which have the - at index 0
if ( s.find ( "-",1 ) != ASCString::npos ) {
ASCString from = s.substr ( 0, s.find ( "-", 1 ) );
ASCString to = s.substr ( s.find ( "-",1 )+1 );
irv.push_back ( IntRange ( atoi ( from.c_str() ), atoi ( to.c_str() )));
} else {
irv.push_back ( IntRange ( atoi ( s.c_str() ), atoi ( s.c_str() )));
}
s = st.getNextToken();
}
return irv;
}
void IntRange::read ( tnstream& stream )
{
stream.readInt();
from = stream.readInt();
to = stream.readInt();
}
void IntRange::write ( tnstream& stream ) const
{
stream.writeInt(1);
stream.writeInt( from );
stream.writeInt( to );
}
////////////////////////////////////////////////////////////////////
ASCString Properties::getValue( const ASCString& key )
{
return data[key];
}
void Properties::setValue( const ASCString& key, const ASCString& value )
{
data[key] = value;
}
void Properties::write( tnstream& stream ) const
{
stream.writeInt(1);
stream.writeInt( data.size() );
for ( std::map<ASCString, ASCString>::const_iterator i = data.begin(); i != data.end(); ++i ) {
stream.writeString( i->first, true );
stream.writeString( i->second, true );
}
}
void Properties::read( tnstream& stream )
{
stream.readInt();
int count = stream.readInt();
for ( int i = 0; i < count; ++i ) {
ASCString key, value;
stream.readTextString(key, true );
stream.readTextString(value, true );
data[key] = value;
}
}
ASCString heightToString( int bitmappedHeight )
{
ASCString s;
for ( int i = 0; i < 8; ++i )
if ( bitmappedHeight & (1 << i )) {
if ( !s.empty() )
s += " ";
s += choehenstufen[i];
}
return s;
}
|