Advanced Strategic Command
infodialogs.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * This program is free software; you can redistribute it and/or modify *
4  * it under the terms of the GNU General Public License as published by *
5  * the Free Software Foundation; either version 2 of the License, or *
6  * (at your option) any later version. *
7  * *
8  ***************************************************************************/
9 
10 #include <iostream>
11 
12 #ifdef WIN32
13 # include<direct.h>
14 #endif
15 
16 #include "../loadbi3.h"
17 #include "../unitset.h"
18 #include "../statistics.h"
19 
20 #include "unitcounting.h"
21 #include "../widgets/textrenderer.h"
22 #include "../containerbase-functions.h"
23 #include "../memory-measurement.h"
24 
25 #include "../spfst-legacy.h"
26 #include "../i18n.h"
27 
28 #include "../iconrepository.h"
29 
31 {
32 
33  ASCString s = "#fontsize=17#ASC search path#fontsize=13#\n";
34  for ( int i = 0; i < getSearchPathNum(); ++i )
35  s += getSearchPath ( i ) + "\n";
36 
37  s += "\n";
38  s += "Configuration file used: \n";
39  s += getConfigFileName();
40 
41 #ifdef WIN32
42  char buffer[_MAX_PATH];
43 
44  if( _getcwd( buffer, _MAX_PATH ) ) {
45  s += "\n#fontsize=17#Current working directory#fontsize=13#\n";
46  s += buffer;
47  }
48 #endif
49 
50  s += "\n\n#fontsize=17#Mounted archive files#fontsize=13#\n";
51  s += listContainer();
52 
53 
54  ViewFormattedText vft("ASC directories", s, PG_Rect( -1, -1, 400, 400 ));
55  vft.Show();
56  vft.RunModal();
57 }
58 
60  ASCString s;
61 
62  s += "BitsPerPixel: " + ASCString::toString( surface.getBaseSurface()->format->BitsPerPixel ) + "\n";
63  s += "BytesPerPixel: " + ASCString::toString( surface.getBaseSurface()->format->BytesPerPixel ) + "\n";
64  s += "Rloss: " + ASCString::toString( surface.getBaseSurface()->format->Rloss ) + "\n";
65  s += "Gloss: " + ASCString::toString( surface.getBaseSurface()->format->Gloss ) + "\n";
66  s += "Bloss: " + ASCString::toString( surface.getBaseSurface()->format->Bloss ) + "\n";
67  s += "Aloss: " + ASCString::toString( surface.getBaseSurface()->format->Aloss ) + "\n";
68  s += "Rshift: " + ASCString::toString( surface.getBaseSurface()->format->Rshift ) + "\n";
69  s += "Gshift: " + ASCString::toString( surface.getBaseSurface()->format->Gshift ) + "\n";
70  s += "Bshift: " + ASCString::toString( surface.getBaseSurface()->format->Bshift ) + "\n";
71  s += "Ashift: " + ASCString::toString( surface.getBaseSurface()->format->Ashift ) + "\n";
72  s += "Rmask: " + ASCString::toString( surface.getBaseSurface()->format->Rmask ) + "\n";
73  s += "Gmask: " + ASCString::toString( surface.getBaseSurface()->format->Gmask ) + "\n";
74  s += "Bmask: " + ASCString::toString( surface.getBaseSurface()->format->Bmask ) + "\n";
75  s += "Amask: " + ASCString::toString( surface.getBaseSurface()->format->Amask ) + "\n";
76  s += "colorkey: " + ASCString::toString( surface.getBaseSurface()->format->colorkey ) + "\n";
77  s += "Alpha: " + ASCString::toString( surface.getBaseSurface()->format->alpha ) + "\n";
78 
79  return s;
80 }
81 
83 {
84  ASCString s;
85  s += "#fontsize=18#SDL versions#fontsize=14#\n";
86  char buf[1000];
87  SDL_version compiled;
88  SDL_VERSION(&compiled);
89  sprintf(buf, "\nCompiled with SDL version: %d.%d.%d\n", compiled.major, compiled.minor, compiled.patch);
90  s += buf;
91 
92  sprintf(buf, "Linked with SDL version: %d.%d.%d\n", SDL_Linked_Version()->major, SDL_Linked_Version()->minor, SDL_Linked_Version()->patch);
93  s += buf;
94 
95  s += "Byte order is ";
96 #if SDL_BYTEORDER==SDL_LIL_ENDIAN
97  s += "little endian\n";
98 #else
99 #if SDL_BYTEORDER==SDL_BIG_ENDIAN
100  s += "big endian\n";
101 #else
102  s += "undefined\n";
103 #endif
104 #endif
105 
106  s += "Graphics backend: ";
107  s += SDL_VideoDriverName( buf, 1000 );
108  s += "\n";
109 
110 
111  const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo();
112  s += "VideoInfo: \n";
113 
114  s += "Hardware surfaces available: ";
115  s += videoInfo->hw_available ? "yes" : "no";
116 
117 
118  s += "\nScreen uses hardware surface: ";
119  s += PG_Application::GetScreen()->flags & SDL_HWSURFACE ? "yes" : "no";
120 
121  s += "\nWindow manager available: ";
122  s += videoInfo->wm_available ? "yes" : "no";
123 
124  s += "\nhardware to hardware blits accelerated: ";
125  s += videoInfo->blit_hw ? "yes" : "no";
126 
127  s += "\nhardware to hardware colorkey blits accelerated: ";
128  s += videoInfo->blit_hw_CC ? "yes" : "no";
129 
130  s += "\nhardware to hardware alpha blits accelerated: ";
131  s += videoInfo->blit_hw_A ? "yes" : "no";
132 
133  s += "\nsoftware to hardware blits accelerated: ";
134  s += videoInfo->blit_sw ? "yes" : "no";
135 
136  s += "\nsoftware to hardware colorkey blits accelerated: ";
137  s += videoInfo->blit_sw_CC ? "yes" : "no";
138 
139  s += "\nsoftware to hardware alpha blits accelerated: ";
140  s += videoInfo->blit_sw_A ? "yes" : "no";
141 
142  s += "\ncolor fills accelerated: ";
143  s += videoInfo->blit_fill ? "yes" : "no";
144 
145  s += "\nVideo memory: ";
146  s += ASCString::toString( int(videoInfo->video_mem ));
147 
148  s += "\n\nLanguage: ";
149  Locale locale;
150  s += locale.getLang();
151 
152  s += "\n\nInformation for gamebackground.png:\n";
153  s += showSurfaceInfo( IconRepository::getIcon("gamebackground.png"));
154 
155  s += "\n\nInformation for curshex.png: \n";
156  s += showSurfaceInfo( IconRepository::getIcon("curshex.png"));
157 
158  ViewFormattedText vft( "SDL Settings", s, PG_Rect(-1,-1,450,550));
159  vft.Show();
160  vft.RunModal();
161 }
162 
163 
164 
165 
166 void ammoCounter( const ContainerBase* c, map<int,int>& amount )
167 {
168  for ( int i = 0; i < weaponTypeNum; ++i )
169  if ( weaponAmmo[i] )
170  amount[i] += c->getAmmo(i,maxint );
171 
172  for ( int i = 1000; i < 1003; ++i )
173  amount[i] += c->getAvailableResource( maxint, i-1000, 0 );
174 
175  for ( ContainerBase::Cargo::const_iterator i = c->getCargo().begin(); i != c->getCargo().end(); ++i )
176  if ( *i )
177  ammoCounter( *i, amount );
178 }
179 
180 
182 {
183  if ( !fld->vehicle ) {
184  infoMessage( "Please select a unit");
185  return;
186  }
187 
190  map<int,int> ammo;
191  ammoCounter( fld->vehicle, ammo );
192  ASCString s;
193  for ( int i = 0; i < weaponTypeNum; ++i )
194  if ( weaponAmmo[i] )
195  s += ASCString(cwaffentypen[i]) + ": " + ASCString::toString( ammo[i] ) + "\n";
196 
197  s += "\n";
198  for ( int i = 1000; i < 1003; ++i )
199  s += ASCString(Resources::name(i-1000)) + ": " + ASCString::toString( ammo[i] ) + "\n";
200 
201  s += "\n";
202  s += "Strength index: " + ASCString::toString( StatisticsCalculator::strength(fld->vehicle, true ));
203 
204 
205  ViewFormattedText vft("Ammo summary", s, PG_Rect( -1, -1, 300, 300 ));
206  vft.Show();
207  vft.RunModal();
208  } else
209  infoMessage( "The unit is not yours");
210 
211 }
212 
213 
214 class FontViewer : public ASC_PG_Dialog {
215  static const int spacing = 30;
216  public:
217  FontViewer() : ASC_PG_Dialog( NULL, PG_Rect( -1, -1, 18 * spacing, 19 * spacing ), "view character set" )
218  {
219  for ( int i = 32; i < 255; ++i ) {
220  ASCString s;
221  s += char(i);
222  new PG_Label ( this, PG_Rect( (i % 16 + 1) * spacing, (i / 16 + 2) * spacing, spacing, spacing ), s );
223  }
224  };
225 };
226 
227 void viewFont()
228 {
229  FontViewer fv;
230  fv.Show();
231  fv.RunModal();
232 }
233 
234 
235 
237 {
238  ASCString s;
239  Resources total;
240  for ( Player::BuildingList::iterator j = actmap->player[actmap->actplayer].buildingList.begin(); j != actmap->player[actmap->actplayer].buildingList.end() ; j++ ) {
241  Resources res = (*j)->getResource( Resources(maxint,maxint,maxint), true, 0 );
242  MapCoordinate pos = (*j)->getPosition();
243  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";
244  total += res;
245  }
246  s += "\nTotal:\n";
247 
248  for ( int r = 0; r < 3; ++r)
249  if ( actmap->isResourceGlobal(r))
251  s += total.toString();
252 
253  s += "\nIncluding units:\n";
254  for ( Player::VehicleList::iterator j = actmap->player[actmap->actplayer].vehicleList.begin(); j != actmap->player[actmap->actplayer].vehicleList.end() ; j++ )
255  total += (*j)->getResource( Resources(maxint,maxint,maxint), true, 0 );
256 
257  s += total.toString();
258 
259  ViewFormattedText vft("Resource Analysis", s, PG_Rect( -1, -1, 600, 550 ));
260  vft.Show();
261  vft.RunModal();
262 }
263 
265 {
266 
267  vector<VehicleType*> units;
268  for ( int i = 0; i < vehicleTypeRepository.getNum(); ++i ) {
269  VehicleType* vt = vehicleTypeRepository.getObject_byPos(i);
270  if ( vt && (vt->movemalustyp == MoveMalusType::medium_aircraft ||
274  units.push_back( vt );
275  }
276  sort( units.begin(), units.end(), vehicleComp );
277 
278  ASCString s;
279  for ( vector<VehicleType*>::iterator i = units.begin(); i != units.end(); ++i )
280  {
281  ASCString u;
282  ASCString range;
283  if ( (*i)->fuelConsumption )
284  range = ASCString::toString( (*i)->getStorageCapacity(0).fuel / (*i)->fuelConsumption);
285  else
286  range = "-";
287 
288  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) );
289  s += u;
290  }
291 
292  ViewFormattedText vft("Unit Endurance", s, PG_Rect( -1, -1, 650, 550 ));
293  vft.Show();
294  vft.RunModal();
295 }
296 
297 
299 {
301  mm.measureTypes();
302  mm.measure( actmap );
303  mm.measureIcons();
304 
305  ViewFormattedText vft("Memory Usage", mm.getResult(), PG_Rect( -1, -1, 750, 550 ));
306  vft.Show();
307  vft.RunModal();
308 }
309 
310 
312 {
313  typedef map<const ContainerBaseType*,ASCString> InfoMap;
314  InfoMap info;
315 
316  for ( Player::BuildingList::iterator i = actmap->getCurrentPlayer().buildingList.begin(); i != actmap->getCurrentPlayer().buildingList.end(); ++i )
317  if ( (*i)->baseType->hasFunction( ContainerBaseType::MiningStation )) {
318  int power = 0;
319  int output = 0;
320  MiningStation miningStation ( *i, true );
321  for ( int r = 0; r < 3; ++r )
322  if ( (*i)->maxplus.resource(r) ) {
323  power = 100 * (*i)->plus.resource(r) / (*i)->maxplus.resource(r) ;
324  break;
325  }
326 
327  for ( int r = 0; r < 3; ++r )
328  if ( miningStation.getPlus().resource(r) ) {
329  output = miningStation.getPlus().resource(r);
330  break;
331  }
332 
333  ASCString txt = ASCString::toString(output) + " (" + ASCString::toString(power) + "%) " + (*i)->getPosition().toString() + " " + (*i)->baseType->name + "\n";
334  info[(*i)->baseType] += txt;
335  }
336 
337  ASCString fullText = "Mining Station Statistics\n\n";
338  for ( InfoMap::iterator i = info.begin(); i != info.end(); ++i )
339  fullText += i->second;
340 
341 
342  ViewFormattedText vft("Mining Stations", fullText, PG_Rect( -1, -1, 750, 550 ));
343  vft.Show();
344  vft.RunModal();
345 
346 }
347 
348 
350 {
351  cout << "name;id;unitset id;new cost E;new cost M;old cost E;old cost M\n";
352  for ( int i = 0; i < vehicleTypeRepository.getNum(); ++i ) {
353  VehicleType* v = vehicleTypeRepository.getObject_byPos(i);
354  Resources oldc = v->calcProductionCost();
355  Resources newc = v->calcProductionCost();
356 
357  cout << v->getName() << ";" << v->id << ";" << getUnitSetID( v) << ";" << newc.energy << ";" << newc.material << ";" << oldc.energy << ";" << oldc.material << "\n";
358  }
359 }
int fuel
Definition: typen.h:101
Player & getCurrentPlayer()
Definition: gamemap.h:268
void showMemoryFootprint()
ASCString getSearchPath(int i)
Definition: basestrm.cpp:2539
Vehicle * vehicle
Definition: mapfield.h:89
#define weaponTypeNum
Definition: vehicletype.h:63
int energy
Definition: typen.h:99
ASCString toString() const
Definition: typen.cpp:268
DiplomaticStateVector diplomacy
Definition: player.h:209
const char * cwaffentypen[weaponTypeNum]
Definition: vehicletype.cpp:71
bool vehicleComp(const VehicleType *v1, const VehicleType *v2)
Definition: unitset.cpp:234
const bool weaponAmmo[weaponTypeNum]
Definition: vehicletype.cpp:92
ASCString toString(bool coordinates=false) const
Definition: typen.cpp:304
ASCString getName() const
a single field of the map
Definition: mapfield.h:26
ASCString & format(const charT *pFormat,...)
Definition: ascstring.cpp:78
void showCargoSummary(MapField *fld)
SDL_Surface * getBaseSurface()
Definition: surface.h:116
void viewMiningPower()
static const char * name(int r)
Definition: typen.cpp:190
ASCString getConfigFileName()
Definition: sgstream.cpp:361
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
virtual int getAvailableResource(int amount, int resourcetype, int scope=1) const =0
static double strength(const ContainerBase *c, bool recurse)
Definition: statistics.cpp:32
virtual Resources getPlus()
The class describing properties that are common to all vehicles of a certain kind.
Definition: vehicletype.h:177
static ASCString toString(int i)
converts the parameter to a String
Definition: ascstring.cpp:193
static int getEndurance(const Vehicle *veh)
calculates the time until the unit crashes because of lack of fuel
Definition: vehicle.cpp:1816
VehicleList vehicleList
a list of all units
Definition: player.h:135
ItemRepositoryLoader< VehicleType > vehicleTypeRepository("vehicletype")
Resources bi_resource[8]
in BI resource mode ( see _resourcemode , isResourceGlobal ) , this is where the globally available r...
Definition: gamemap.h:416
void showSDLInfo()
Definition: infodialogs.cpp:82
int getSearchPathNum()
Definition: basestrm.cpp:2534
ASCString getLang()
Definition: i18n.cpp:43
Resources calcProductionCost()
Coordinate on the twodimensional map.
Definition: typen.h:202
Adapter class for using Paragui Dialogs in ASC. This class transfers the event control from ASC to Pa...
Definition: paradialog.h:127
int movemalustyp
The category of the unit. Original used only to distinguish only between different movement costs for...
Definition: vehicletype.h:206
bool isResourceGlobal(int resource)
Definition: gamemap.cpp:1024
int material
Definition: typen.h:100
signed char actplayer
the player who is currently making his moves (may be human or AI)
Definition: gamemap.h:232
int getUnitSetID(const VehicleType *veh)
Definition: unitset.cpp:216
Player player[9]
Definition: gamemap.h:253
void showUnitEndurance()
ASCString listContainer()
Definition: basestrm.cpp:1052
BuildingList buildingList
a list of all units
Definition: player.h:139
void showUnitCargoSummary(ContainerBase *cb)
int & resource(int type)
Definition: typen.h:105
bool isAllied(PlayerID towardsPlayer) const
Definition: player.h:82
static Surface & getIcon(const ASCString &name)
virtual int getAmmo(int type, int num, bool queryOnly)=0
#define maxint
Definition: typen.h:462
GameMap * actmap
Definition: spfst.cpp:64
ASCString showSurfaceInfo(Surface &surface)
Definition: infodialogs.cpp:59
void createUnitCostList()
The parent class of Vehicle and Building; The name Container originates from Battle Isle...
Definition: containerbase.h:40
Resources are basically the currency of ASC.
Definition: typen.h:97
void showSearchPath()
Definition: infodialogs.cpp:30
const Cargo & getCargo() const
void ammoCounter(const ContainerBase *c, map< int, int > &amount)
void viewFont()
void infoMessage(const ASCString &string)
Definition: i18n.h:28
void resourceAnalysis()