00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <iostream>
00011
00012 #ifdef WIN32
00013 # include<direct.h>
00014 #endif
00015
00016 #include "../loadbi3.h"
00017 #include "../unitset.h"
00018 #include "../statistics.h"
00019
00020 #include "unitcounting.h"
00021 #include "../widgets/textrenderer.h"
00022 #include "../containerbase-functions.h"
00023 #include "../memory-measurement.h"
00024
00025 #include "../spfst-legacy.h"
00026 #include "../i18n.h"
00027
00028 void showSearchPath()
00029 {
00030
00031 ASCString s = "#fontsize=17#ASC search path#fontsize=13#\n";
00032 for ( int i = 0; i < getSearchPathNum(); ++i )
00033 s += getSearchPath ( i ) + "\n";
00034
00035 s += "\n";
00036 s += "Configuration file used: \n";
00037 s += getConfigFileName();
00038
00039 #ifdef WIN32
00040 char buffer[_MAX_PATH];
00041
00042 if( _getcwd( buffer, _MAX_PATH ) ) {
00043 s += "\n#fontsize=17#Current working directory#fontsize=13#\n";
00044 s += buffer;
00045 }
00046 #endif
00047
00048 s += "\n\n#fontsize=17#Mounted archive files#fontsize=13#\n";
00049 s += listContainer();
00050
00051
00052 ViewFormattedText vft("ASC directories", s, PG_Rect( -1, -1, 400, 400 ));
00053 vft.Show();
00054 vft.RunModal();
00055 }
00056
00057
00058 void showSDLInfo()
00059 {
00060 ASCString s;
00061 s += "#fontsize=18#SDL versions#fontsize=14#\n";
00062 char buf[1000];
00063 SDL_version compiled;
00064 SDL_VERSION(&compiled);
00065 sprintf(buf, "\nCompiled with SDL version: %d.%d.%d\n", compiled.major, compiled.minor, compiled.patch);
00066 s += buf;
00067
00068 sprintf(buf, "Linked with SDL version: %d.%d.%d\n", SDL_Linked_Version()->major, SDL_Linked_Version()->minor, SDL_Linked_Version()->patch);
00069 s += buf;
00070
00071 s += "Byte order is ";
00072 #if SDL_BYTEORDER==SDL_LIL_ENDIAN
00073 s += "little endian\n";
00074 #else
00075 #if SDL_BYTEORDER==SDL_BIG_ENDIAN
00076 s += "big endian\n";
00077 #else
00078 s += "undefined\n";
00079 #endif
00080 #endif
00081
00082 s += "Graphics backend: ";
00083 s += SDL_VideoDriverName( buf, 1000 );
00084 s += "\n";
00085
00086
00087 const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo();
00088 s += "VideoInfo: \n";
00089
00090 s += "Hardware surfaces available: ";
00091 s += videoInfo->hw_available ? "yes" : "no";
00092
00093
00094 s += "\nScreen uses hardware surface: ";
00095 s += PG_Application::GetScreen()->flags & SDL_HWSURFACE ? "yes" : "no";
00096
00097 s += "\nWindow manager available: ";
00098 s += videoInfo->wm_available ? "yes" : "no";
00099
00100 s += "\nhardware to hardware blits accelerated: ";
00101 s += videoInfo->blit_hw ? "yes" : "no";
00102
00103 s += "\nhardware to hardware colorkey blits accelerated: ";
00104 s += videoInfo->blit_hw_CC ? "yes" : "no";
00105
00106 s += "\nhardware to hardware alpha blits accelerated: ";
00107 s += videoInfo->blit_hw_A ? "yes" : "no";
00108
00109 s += "\nsoftware to hardware blits accelerated: ";
00110 s += videoInfo->blit_sw ? "yes" : "no";
00111
00112 s += "\nsoftware to hardware colorkey blits accelerated: ";
00113 s += videoInfo->blit_sw_CC ? "yes" : "no";
00114
00115 s += "\nsoftware to hardware alpha blits accelerated: ";
00116 s += videoInfo->blit_sw_A ? "yes" : "no";
00117
00118 s += "\ncolor fills accelerated: ";
00119 s += videoInfo->blit_fill ? "yes" : "no";
00120
00121 s += "\nVideo memory: ";
00122 s += ASCString::toString( int(videoInfo->video_mem ));
00123
00124 s += "\n\nLanguage: ";
00125 Locale locale;
00126 s += locale.getLang();
00127
00128 ViewFormattedText vft( "SDL Settings", s, PG_Rect(-1,-1,450,550));
00129 vft.Show();
00130 vft.RunModal();
00131 }
00132
00133
00134
00135
00136 void ammoCounter( const ContainerBase* c, map<int,int>& amount )
00137 {
00138 for ( int i = 0; i < weaponTypeNum; ++i )
00139 if ( weaponAmmo[i] )
00140 amount[i] += c->getAmmo(i,maxint );
00141
00142 for ( int i = 1000; i < 1003; ++i )
00143 amount[i] += c->getAvailableResource( maxint, i-1000, 0 );
00144
00145 for ( ContainerBase::Cargo::const_iterator i = c->getCargo().begin(); i != c->getCargo().end(); ++i )
00146 if ( *i )
00147 ammoCounter( *i, amount );
00148 }
00149
00150
00151 void showCargoSummary( MapField* fld )
00152 {
00153 if ( !fld->vehicle ) {
00154 infoMessage( "Please select a unit");
00155 return;
00156 }
00157
00158 if ( actmap->getCurrentPlayer().diplomacy.isAllied( fld->vehicle )) {
00159 showUnitCargoSummary( fld->vehicle );
00160 map<int,int> ammo;
00161 ammoCounter( fld->vehicle, ammo );
00162 ASCString s;
00163 for ( int i = 0; i < weaponTypeNum; ++i )
00164 if ( weaponAmmo[i] )
00165 s += ASCString(cwaffentypen[i]) + ": " + ASCString::toString( ammo[i] ) + "\n";
00166
00167 s += "\n";
00168 for ( int i = 1000; i < 1003; ++i )
00169 s += ASCString(Resources::name(i-1000)) + ": " + ASCString::toString( ammo[i] ) + "\n";
00170
00171 s += "\n";
00172 s += "Strength index: " + ASCString::toString( StatisticsCalculator::strength(fld->vehicle, true ));
00173
00174
00175 ViewFormattedText vft("Ammo summary", s, PG_Rect( -1, -1, 300, 300 ));
00176 vft.Show();
00177 vft.RunModal();
00178 } else
00179 infoMessage( "The unit is not yours");
00180
00181 }
00182
00183
00184 class FontViewer : public ASC_PG_Dialog {
00185 static const int spacing = 30;
00186 public:
00187 FontViewer() : ASC_PG_Dialog( NULL, PG_Rect( -1, -1, 18 * spacing, 19 * spacing ), "view character set" )
00188 {
00189 for ( int i = 32; i < 255; ++i ) {
00190 ASCString s;
00191 s += char(i);
00192 new PG_Label ( this, PG_Rect( (i % 16 + 1) * spacing, (i / 16 + 2) * spacing, spacing, spacing ), s );
00193 }
00194 };
00195 };
00196
00197 void viewFont()
00198 {
00199 FontViewer fv;
00200 fv.Show();
00201 fv.RunModal();
00202 }
00203
00204
00205
00206 void resourceAnalysis()
00207 {
00208 ASCString s;
00209 Resources total;
00210 for ( Player::BuildingList::iterator j = actmap->player[actmap->actplayer].buildingList.begin(); j != actmap->player[actmap->actplayer].buildingList.end() ; j++ ) {
00211 Resources res = (*j)->getResource( Resources(maxint,maxint,maxint), true, 0 );
00212 MapCoordinate pos = (*j)->getPosition();
00213 s += (*j)->getName() + " #pos150#(" + ASCString::toString( pos.x ) + "/" + ASCString::toString( pos.y) + pos.toString() + ") : #pos300#" + ASCString::toString(res.energy) + "#pos400#" + ASCString::toString(res.material) + "#pos500#" + ASCString::toString(res.fuel) + "\n";
00214 total += res;
00215 }
00216 s += "\nTotal:\n";
00217
00218 for ( int r = 0; r < 3; ++r)
00219 if ( actmap->isResourceGlobal(r))
00220 total.resource(r) = actmap->bi_resource[actmap->actplayer].resource(r);
00221 s += total.toString();
00222
00223 s += "\nIncluding units:\n";
00224 for ( Player::VehicleList::iterator j = actmap->player[actmap->actplayer].vehicleList.begin(); j != actmap->player[actmap->actplayer].vehicleList.end() ; j++ )
00225 total += (*j)->getResource( Resources(maxint,maxint,maxint), true, 0 );
00226
00227 s += total.toString();
00228
00229 ViewFormattedText vft("Resource Analysis", s, PG_Rect( -1, -1, 600, 550 ));
00230 vft.Show();
00231 vft.RunModal();
00232 }
00233
00234 void showUnitEndurance()
00235 {
00236
00237 vector<VehicleType*> units;
00238 for ( int i = 0; i < vehicleTypeRepository.getNum(); ++i ) {
00239 VehicleType* vt = vehicleTypeRepository.getObject_byPos(i);
00240 if ( vt && (vt->movemalustyp == MoveMalusType::medium_aircraft ||
00241 vt->movemalustyp == MoveMalusType::light_aircraft ||
00242 vt->movemalustyp == MoveMalusType::heavy_aircraft ||
00243 vt->movemalustyp == MoveMalusType::helicopter))
00244 units.push_back( vt );
00245 }
00246 sort( units.begin(), units.end(), vehicleComp );
00247
00248 ASCString s;
00249 for ( vector<VehicleType*>::iterator i = units.begin(); i != units.end(); ++i )
00250 {
00251 ASCString u;
00252 ASCString range;
00253 if ( (*i)->fuelConsumption )
00254 range = ASCString::toString( (*i)->getStorageCapacity(0).fuel / (*i)->fuelConsumption);
00255 else
00256 range = "-";
00257
00258 u.format( "#vehicletype=%d# %s : %d fuel ; %s fields range ; %d turns endurance \n", (*i)->id, (*i)->getName().c_str(), (*i)->getStorageCapacity(0).fuel, range.c_str(), UnitHooveringLogic::getEndurance(*i) );
00259 s += u;
00260 }
00261
00262 ViewFormattedText vft("Unit Endurance", s, PG_Rect( -1, -1, 650, 550 ));
00263 vft.Show();
00264 vft.RunModal();
00265 }
00266
00267
00268 void showMemoryFootprint()
00269 {
00270 MemoryMeasurement mm;
00271 mm.measureTypes();
00272 mm.measure( actmap );
00273 mm.measureIcons();
00274
00275 ViewFormattedText vft("Memory Usage", mm.getResult(), PG_Rect( -1, -1, 750, 550 ));
00276 vft.Show();
00277 vft.RunModal();
00278 }
00279
00280
00281 void viewMiningPower()
00282 {
00283 typedef map<const ContainerBaseType*,ASCString> InfoMap;
00284 InfoMap info;
00285
00286 for ( Player::BuildingList::iterator i = actmap->getCurrentPlayer().buildingList.begin(); i != actmap->getCurrentPlayer().buildingList.end(); ++i )
00287 if ( (*i)->baseType->hasFunction( ContainerBaseType::MiningStation )) {
00288 int power = 0;
00289 int output = 0;
00290 MiningStation miningStation ( *i, true );
00291 for ( int r = 0; r < 3; ++r )
00292 if ( (*i)->maxplus.resource(r) ) {
00293 power = 100 * (*i)->plus.resource(r) / (*i)->maxplus.resource(r) ;
00294 break;
00295 }
00296
00297 for ( int r = 0; r < 3; ++r )
00298 if ( miningStation.getPlus().resource(r) ) {
00299 output = miningStation.getPlus().resource(r);
00300 break;
00301 }
00302
00303 ASCString txt = ASCString::toString(output) + " (" + ASCString::toString(power) + "%) " + (*i)->getPosition().toString() + " " + (*i)->baseType->name + "\n";
00304 info[(*i)->baseType] += txt;
00305 }
00306
00307 ASCString fullText = "Mining Station Statistics\n\n";
00308 for ( InfoMap::iterator i = info.begin(); i != info.end(); ++i )
00309 fullText += i->second;
00310
00311
00312 ViewFormattedText vft("Mining Stations", fullText, PG_Rect( -1, -1, 750, 550 ));
00313 vft.Show();
00314 vft.RunModal();
00315
00316 }
00317
00318
00319 void createUnitCostList()
00320 {
00321 cout << "name;id;unitset id;new cost E;new cost M;old cost E;old cost M\n";
00322 for ( int i = 0; i < vehicleTypeRepository.getNum(); ++i ) {
00323 VehicleType* v = vehicleTypeRepository.getObject_byPos(i);
00324 Resources oldc = v->calcProductionCost();
00325 Resources newc = v->calcProductionCost();
00326
00327 cout << v->getName() << ";" << v->id << ";" << getUnitSetID( v) << ";" << newc.energy << ";" << newc.material << ";" << oldc.energy << ";" << oldc.material << "\n";
00328 }
00329 }