Advanced Strategic Command
terraininfo.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Advanced Strategic Command; http://www.asc-hq.de
3  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; see the file COPYING. If not, write to the
17  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  Boston, MA 02111-1307 USA
19 */
20 
21 
22 #include "../global.h"
23 
24 #include "../typen.h"
25 #include "../mapfield.h"
26 #include "../gamemap.h"
27 #include "terraininfo.h"
28 
29 #include "../widgets/textrenderer.h"
30 
31 
32 
33 
34 void viewterraininfo ( GameMap* gamemap, const MapCoordinate& pos, bool fullVisibility )
35 {
36  MapField* fld = gamemap->getField( pos );
37 
38  if ( !fld )
39  return;
40 
41  ASCString text;
42 
43  text += "#fontsize=18#Field Information (";
44  text += ASCString::toString(pos.x) + "/" + ASCString::toString(pos.y) + ")\n";
45 
46 
47  text += "#fontsize=14#Terrain#aeinzug20##eeinzug20##fontsize=12##aeinzug30#\n";
48 
49 
50  text += "ID: " + ASCString::toString( fld->typ->terraintype->id ) + "\n";
51 
52  text += "Weather: " + ASCString(cwettertypen[fld->getWeather() ]) + "\n";
53 
54 
55  ASCString sub;
56  float ab = fld->getattackbonus();
57  float db = fld->getdefensebonus();
58  sub.format( "Attack Bonus: %.1f\nDefense Bonus: %.1f\n", ab/8, db/8 );
59 
60  text += sub;
61 
62  text += "Base Jamming: " + ASCString::toString( fld->getjamming() ) + "\n";
63  text += "terrain filename: " + fld->typ->terraintype->location + "\n";
64 
65 
66  fld->bdt.appendToString( text );
67 
68  text += "\n\n#eeinzug0##fontsize=14#Visibility#eeinzug20##fontsize=12#\n";
69 
70  int view = 0;
71  int jamming = 0;
72  for ( int i = 0; i < gamemap->getPlayerCount(); ++i )
73  if ( gamemap->getPlayer(i).diplomacy.sharesView( gamemap->getPlayerView() )) {
74  view += fld->view[i].view;
75  jamming += fld->view[i].jamming;
76  }
77 
78  text += "View: " + ASCString::toString( view ) + "\n";
79  text += "Jamming: " + ASCString::toString( jamming ) + "\n";
80  text += "Terrain view obstruction (basejamming): " + ASCString::toString( fld->getjamming() ) + "\n";
81 
82 
83  text += "\n#eeinzug0##fontsize=14#Movemali#eeinzug20##fontsize=12#\n";
84 
85 
86  for ( int i = 0; i < cmovemalitypenum; i++ ) {
87  if ( fld->vehicle && fld->vehicle->typ->movemalustyp == i )
88  text += "#fontcolor=0xffd658#";
89  text += cmovemalitypes[i] + ASCString(": ") + ASCString::toString( fld->getmovemalus(i) );
90 
91  if ( fld->vehicle && fld->vehicle->typ->movemalustyp == i )
92  text += "#fontcolor=default#";
93 
94  text += "\n";
95  }
96 
97  int mines[4] = { 0, 0, 0, 0 };
98  int mineDissolve[4] = { maxint, maxint, maxint, maxint };
99 
100  for ( MapField::MineContainer::iterator m = fld->mines.begin(); m != fld->mines.end(); ++m )
101  if ( m->player == gamemap->actplayer || fullVisibility ) {
102  mines[m->type-1]++;
103  int lifetime = gamemap->getgameparameter( GameParameter(cgp_antipersonnelmine_lifetime + m->type-1 ));
104  if ( lifetime > 0)
105  mineDissolve[m->type-1] = min( m->lifetimer, mineDissolve[m->type-1]);
106  }
107 
108  if ( mines[0] || mines[1] || mines[2] || mines[3] ) {
109  text += "#eeinzug0##fontsize=14#Mine Information#fontsize=12##eeinzug20##aeinzug30#\n";
110  text += "On this field are #aeinzug50# \n" ;
111 
112  for ( int i = 0; i < 4; i++ ) {
113  text += " " + ASCString::toString( mines[i] ) + " " + MineNames[i];
114  if ( mines[i] > 1 )
115  text += "s";
116 
117  if ( mineDissolve[i] >= 0 && mineDissolve[i] < maxint )
118  text += ", next mine will dissolve in " + ASCString::toString ( mineDissolve[i]) + " turns.";
119 
120  text += "\n";
121  }
122  }
123 
124  if ( fld->vehicle ) {
125  text += "#aeinzug0##eeinzug0#\n#fontsize=14#Vehicle Information:#fontsize=12##aeinzug30##eeinzug20#\n" ;
126 
127  const VehicleType* typ = fld->vehicle->typ;
128 
129  text += "Unit name: ";
130  if ( !typ->name.empty() )
131  text += typ->name.c_str() ;
132  else
133  text += typ->description;
134  text += "\n";
135 
136  text += "Unit ID: " + ASCString::toString( typ->id ) + "\n";
137  text += "Internal Unit Identification: " + ASCString::toString( fld->vehicle->networkid ) + "\n";
138 
139  if ( !typ->filename.empty() )
140  text += "File Name: " + typ->location + "\n";
141 
142  text += "Offensive experience (raw value): " + ASCString::toString( fld->vehicle->getExperience_offensive_raw()) + "\n";
143  text += "Defensive experience (raw value): " + ASCString::toString( fld->vehicle->getExperience_defensive_raw()) + "\n";
144 
145 
146  text += "Terrain access:\n" + typ->terrainaccess.toString() + "\n";
147  }
148 
149  if ( !fld->objects.empty() )
150  text += "#aeinzug0##eeinzug0#\n#fontsize=14#Object Information:#fontsize=12##aeinzug30##eeinzug20#\n" ;
151 
152  for ( MapField::ObjectContainer::iterator i = fld->objects.begin(); i != fld->objects.end(); i++ )
153  text += i->typ->location + "\n";
154 
155 
156  if ( fld->building ) {
157  text += "#aeinzug0##eeinzug0#\n#fontsize=14#Building Information:#fontsize=12##aeinzug30##eeinzug20#\n";
158  text += fld->building->typ->location + "\n";
159  text += "Owner: " + gamemap->player[fld->building->getOwner()].getName() + "\n";
160  }
161 
162 
163  if ( !fld->objects.empty() ) {
164  text += "#aeinzug0##eeinzug0#\n#fontsize=14#Object Details:#aeinzug30##eeinzug20#";
165  for ( MapField::ObjectContainer::iterator i = fld->objects.begin(); i != fld->objects.end(); i++ ) {
166  const TerrainAccess* ta = &i->typ->getFieldModification( fld->getWeather() ).terrainaccess;
167  text += "#aeinzug30##eeinzug20##fontsize=12#\n";
168  text += i->typ->name + "#aeinzug50##eeinzug40##fontsize=10#\n";
169  text += "Type ID: " + ASCString::toString(i->typ->id) + "\n";
170  text += "Location: " + i->typ->location + "\n";
171 
172  text += "Terrain access:\n" + ta->toString() + "\n";
173 
174  text += "\nremaining lifetime:";
175  text += ASCString::toString( i->lifetimer ) + "\n";
176 
177  text += "\nremaining child spawn counter:";
178  text += ASCString::toString( i->remainingGrowthTime ) + "\n";
179 
180  }
181  }
182 
183  ViewFormattedText vft( "Field Information", text, PG_Rect( -1, -1, 420, 600 ));
184  vft.Show();
185  vft.RunModal();
186 }
187 
188 
189 
TerrainType::Weather * typ
the terraintype of the field
Definition: mapfield.h:38
int getExperience_offensive_raw() const
Definition: vehicle.cpp:263
ASCString filename
The name of the file from which the item was loaded.
Definition: typen.h:290
Player & getPlayer(PlayerID p)
Definition: gamemap.h:257
int getattackbonus(void)
the attack bonus that unit get when they are attacking
Definition: mapfield.cpp:490
const BuildingType * typ
Definition: buildings.h:48
Vehicle * vehicle
Definition: mapfield.h:89
const char * cwettertypen[cwettertypennum]
the names of the different weather
Definition: typen.cpp:78
ASCString getName() const
returns the name of the player
Definition: player.cpp:274
TerrainType * terraintype
pointer to the outer structure
Definition: terraintype.h:128
DiplomaticStateVector diplomacy
Definition: player.h:209
int getOwner() const
returns the number of the player this vehicle/building belongs to
struct MapField::View view[8]
const char * cmovemalitypes[cmovemalitypenum]
the names of the different MoveMalusTypes
Definition: typen.cpp:43
const char * MineNames[cminenum]
Definition: objects.cpp:38
int getExperience_defensive_raw() const
Definition: vehicle.cpp:268
void appendToString(ASCString &text) const
bool sharesView(PlayerID receivingPlayer) const
Definition: player.h:81
a single field of the map
Definition: mapfield.h:26
if(!yyg->yy_init)
Definition: scanner.cpp:695
pbuilding ab
Definition: history.cpp:96
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
ASCString description
short description of the units role, for example "strategic bomber"
int getWeather()
the weather that is on this field
Definition: mapfield.cpp:370
int getPlayerView() const
the player which is currently viewing the map.
Definition: gamemap.cpp:1007
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
This class is used by buildings, vehicles and objects to specify which terrain it can move to / be bu...
Definition: terraintype.h:42
ASCString toString(bool brief=true) const
Coordinate on the twodimensional map.
Definition: typen.h:202
int movemalustyp
The category of the unit. Original used only to distinguish only between different movement costs for...
Definition: vehicletype.h:206
const int cmovemalitypenum
The number of vehicle categories; Each category has its own move malus.
Definition: typen.h:384
signed char actplayer
the player who is currently making his moves (may be human or AI)
Definition: gamemap.h:232
Player player[9]
Definition: gamemap.h:253
GameParameter
Definition: gamemap.h:77
TerrainBits bdt
the terraintype properties. They determine which units can move over the field. This variable is reca...
Definition: mapfield.h:161
MineContainer mines
Definition: mapfield.h:117
int getgameparameter(GameParameter num) const
Definition: gamemap.cpp:1047
void viewterraininfo(GameMap *gamemap, const MapCoordinate &pos, bool fullVisibility)
Definition: terraininfo.cpp:34
const VehicleType * typ
Definition: vehicle.h:83
Building * building
Definition: mapfield.h:102
int getjamming(void)
the radar jamming that is on this field
Definition: mapfield.cpp:537
#define maxint
Definition: typen.h:462
ASCString location
The filename and location on disk (including containerfiles) of the object.
Definition: typen.h:296
const T & min(const T &a, const T &b, const T &c)
Definition: misc.h:80
int getdefensebonus(void)
the defense bonus that unit get when they are attacked
Definition: mapfield.cpp:506
TerrainAccess terrainaccess
the terrain this unit can move to
Definition: vehicletype.h:221
int getPlayerCount() const
Definition: gamemap.h:255
int getmovemalus(const Vehicle *veh)
Definition: mapfield.cpp:552
int networkid
a unique identification of the unit that is used everywhere in ASC (and not only the network protocol...
Definition: vehicle.h:140
ASCString name
a short name, for example B-52
ObjectContainer objects
Definition: mapfield.h:124
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
MapField * getField(int x, int y)
Definition: gamemap.h:465