Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

terraininfo.cpp

Go to the documentation of this file.
00001 /*
00002      This file is part of Advanced Strategic Command; http://www.asc-hq.de
00003      Copyright (C) 1994-1999  Martin Bickel  and  Marc Schellenberger
00004  
00005      This program is free software; you can redistribute it and/or modify
00006      it under the terms of the GNU General Public License as published by
00007      the Free Software Foundation; either version 2 of the License, or
00008      (at your option) any later version.
00009  
00010      This program is distributed in the hope that it will be useful,
00011      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013      GNU General Public License for more details.
00014  
00015      You should have received a copy of the GNU General Public License
00016      along with this program; see the file COPYING. If not, write to the 
00017      Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00018      Boston, MA  02111-1307  USA
00019 */
00020 
00021 
00022 #include "../global.h"
00023 
00024 #include "../typen.h"
00025 #include "../mapfield.h"
00026 #include "../gamemap.h"
00027 #include "terraininfo.h"
00028 
00029 #include "../widgets/textrenderer.h"
00030 
00031 
00032 void appendTerrainBits ( ASCString& text, const TerrainBits* bdt )
00033 {
00034    for (int i = 0; i < terrainPropertyNum ; i++) {
00035       TerrainBits bts;
00036       bts.set ( i );
00037 
00038       if ( (*bdt & bts).any() ) {
00039          text += "- " ;
00040          text += terrainProperty[i];
00041          text += "\n";
00042       }
00043    } /* endfor */
00044 }
00045 
00046 
00047 void viewterraininfo ( GameMap* gamemap, const MapCoordinate& pos, bool fullVisibility )
00048 {
00049    tfield* fld = gamemap->getField( pos );
00050 
00051    if ( !fld )
00052       return;
00053 
00054    ASCString text;
00055 
00056    text += "#fontsize=18#Field Information (";
00057    text += ASCString::toString(pos.x) + "/" + ASCString::toString(pos.y) + ")\n";
00058 
00059    
00060    text += "#fontsize=14#Terrain#aeinzug20##eeinzug20##fontsize=12##aeinzug30#\n";
00061    
00062 
00063    text += "ID: " + ASCString::toString( fld->typ->terraintype->id ) + "\n";
00064 
00065    text += "Weather: " + ASCString(cwettertypen[fld->getweather() ]) + "\n";
00066 
00067 
00068    ASCString sub;
00069    float ab = fld->getattackbonus();
00070    float db = fld->getdefensebonus();
00071    sub.format( "Attack Bonus: %.1f\nDefense Bonus: %.1f\n", ab/8, db/8 );
00072 
00073    text += sub;
00074 
00075    text += "Base Jamming: " + ASCString::toString( fld->getjamming() ) + "\n";
00076    text += "terrain filename: " + fld->typ->terraintype->location  + "\n";
00077    
00078 
00079    appendTerrainBits ( text, &fld->bdt );
00080 
00081 
00082    text += "\n\n#eeinzug0##fontsize=14#Visibility#eeinzug20##fontsize=12#\n";
00083 
00084    int view = 0;
00085    int jamming = 0; 
00086    for ( int i = 0; i < gamemap->getPlayerCount(); ++i ) 
00087       if ( gamemap->getPlayer(i).diplomacy.sharesView( gamemap->getPlayerView() )) {
00088          view += fld->view[i].view;
00089          jamming += fld->view[i].jamming;
00090       }
00091 
00092    text += "View: " + ASCString::toString( view ) + "\n";
00093    text += "Jamming: " + ASCString::toString( jamming ) + "\n";
00094    text += "Terrain view obstruction (basejamming): " + ASCString::toString( fld->getjamming() ) + "\n";
00095 
00096 
00097    text += "\n#eeinzug0##fontsize=14#Movemali#eeinzug20##fontsize=12#\n";
00098 
00099 
00100    for ( int i = 0; i < cmovemalitypenum; i++ ) {
00101       if ( fld->vehicle && fld->vehicle->typ->movemalustyp == i )
00102          text +=  "#fontcolor=0xffd658#";
00103       text += cmovemalitypes[i] + ASCString(": ") + ASCString::toString( fld->getmovemalus(i) );
00104       
00105       if ( fld->vehicle && fld->vehicle->typ->movemalustyp == i )
00106          text += "#fontcolor=default#";
00107 
00108       text += "\n";
00109    }
00110 
00111    int mines[4] = { 0, 0, 0, 0 };
00112    int mineDissolve[4] = { maxint, maxint, maxint, maxint };
00113 
00114    for ( tfield::MineContainer::iterator m = fld->mines.begin(); m != fld->mines.end(); ++m )
00115       if ( m->player == gamemap->actplayer || fullVisibility ) {
00116          mines[m->type-1]++;
00117          int lifetime = gamemap->getgameparameter( GameParameter(cgp_antipersonnelmine_lifetime + m->type-1 ));
00118          if ( lifetime > 0)
00119             mineDissolve[m->type-1] = min( m->lifetimer, mineDissolve[m->type-1]);
00120       }
00121 
00122    if ( mines[0] || mines[1] || mines[2] || mines[3] ) {
00123       text += "#eeinzug0##fontsize=14#Mine Information#fontsize=12##eeinzug20##aeinzug30#\n";
00124       text += "On this field are #aeinzug50# \n" ;
00125 
00126       for ( int i = 0; i < 4; i++ ) {
00127          text += " " + ASCString::toString( mines[i] ) + " " + MineNames[i];
00128          if ( mines[i] > 1 )
00129             text += "s";
00130 
00131          if ( mineDissolve[i] >= 0 && mineDissolve[i] < maxint ) 
00132             text += ", next mine will dissolve in " + ASCString::toString ( mineDissolve[i]) + " turns.";
00133          
00134          text += "\n";
00135       }
00136    }
00137    
00138    if  ( fld->vehicle ) {
00139       text += "#aeinzug0##eeinzug0#\n#fontsize=14#Vehicle Information:#fontsize=12##aeinzug30##eeinzug20#\n" ;
00140 
00141       const Vehicletype* typ = fld->vehicle->typ;
00142 
00143       text += "Unit name: ";
00144       if ( !typ->name.empty() )
00145          text += typ->name.c_str() ;
00146       else
00147          text += typ->description;
00148       text += "\n";
00149 
00150       text += "Unit ID: " + ASCString::toString( typ->id ) + "\n";
00151       text += "Internal Unit Identification: " + ASCString::toString( fld->vehicle->networkid ) + "\n";
00152 
00153       if ( !typ->filename.empty() )
00154          text += "File Name: " + typ->location + "\n";
00155 
00156       text += "the unit can drive onto the following fields:\n" ;
00157       appendTerrainBits ( text, &typ->terrainaccess.terrain );
00158 
00159       text += "\n\nthese bits must be set:\n" ;
00160       appendTerrainBits ( text, &typ->terrainaccess.terrainreq );
00161 
00162       text += "\n\nthese bits must NOT be set:\n" ;
00163       appendTerrainBits ( text, &typ->terrainaccess.terrainnot );
00164 
00165       text += "\n\nthe unit ist killed by:\n";
00166       appendTerrainBits ( text, &typ->terrainaccess.terrainkill );
00167       text += "\n";
00168    }
00169 
00170    if ( !fld->objects.empty() )
00171       text += "#aeinzug0##eeinzug0#\n#fontsize=14#Object Information:#fontsize=12##aeinzug30##eeinzug20#\n" ;
00172 
00173    for ( tfield::ObjectContainer::iterator i = fld->objects.begin(); i != fld->objects.end(); i++ ) 
00174       text += i->typ->location + "\n";
00175 
00176 
00177    if ( fld->building ) {
00178       text += "#aeinzug0##eeinzug0#\n#fontsize=14#Building Information:#fontsize=12##aeinzug30##eeinzug20#\n";
00179       text += fld->building->typ->location + "\n";
00180       text += "Owner: " + gamemap->player[fld->building->getOwner()].getName() + "\n";
00181    }
00182 
00183 
00184    if ( !fld->objects.empty() ) {
00185       text += "#aeinzug0##eeinzug0#\n#fontsize=14#Object Details:#aeinzug30##eeinzug20#";
00186       for ( tfield::ObjectContainer::iterator i = fld->objects.begin(); i != fld->objects.end(); i++ ) {
00187          const TerrainAccess* ta = &i->typ->getFieldModification( fld->getweather() ).terrainaccess;
00188          text += "#aeinzug30##eeinzug20##fontsize=12#\n";
00189          text += i->typ->name + "#aeinzug50##eeinzug40##fontsize=10#\n";
00190 
00191          text += "the object can be placed onto the following fields:\n" ;
00192          appendTerrainBits ( text, &ta->terrain );
00193 
00194          text += "\nthese bits must be set:\n" ;
00195          appendTerrainBits ( text, &ta->terrainreq );
00196 
00197          text += "\nthese bits must NOT be set:\n" ;
00198          appendTerrainBits ( text, &ta->terrainnot );
00199 
00200          text += "\nthe object ist killed by:\n";
00201          appendTerrainBits ( text, &ta->terrainkill );
00202 
00203          text += "\nremaining lifetime:";
00204          text += ASCString::toString( i->lifetimer ) + "\n";
00205       }
00206    }
00207 
00208    ViewFormattedText vft( "Field Information", text, PG_Rect( -1, -1, 420, 600 ));
00209    vft.Show();
00210    vft.RunModal();
00211 }
00212 
00213 
00214 

Generated on Tue Jun 24 01:27:53 2008 for Advanced Strategic Command by  doxygen 1.4.2