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

edglobal.cpp

Go to the documentation of this file.
00001 
00005 /*
00006     This file is part of Advanced Strategic Command; http://www.asc-hq.de
00007     Copyright (C) 1994-1999  Martin Bickel  and  Marc Schellenberger
00008 
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU General Public License for more details.
00018 
00019     You should have received a copy of the GNU General Public License
00020     along with this program; see the file COPYING. If not, write to the
00021     Free Software Foundation, Inc., 59 Temple Place, Suite 330,
00022     Boston, MA  02111-1307  USA
00023 */
00024 
00025 #include <stdarg.h>
00026 #include "global.h"
00027 #include "vehicletype.h"
00028 #include "buildingtype.h"
00029 #include "edmisc.h"
00030 #include "loadbi3.h"
00031 #include "edgen.h"
00032 #include "edselfnt.h"
00033 #include "edglobal.h"
00034 #include "gameoptions.h"
00035 #include "mapdisplay.h"
00036 #include "itemrepository.h"
00037 #include "clipboard.h"
00038 #include "resourceplacementdialog.h"
00039 #ifdef WEATHERGENERATOR
00040 # include "weatherdialog.h"
00041 #endif
00042 #include "maped-mainscreen.h"
00043 #include "attack.h"
00044 #include "mapimageexport.h"
00045 #include "viewcalculation.h"
00046 
00047 #include "dialogs/unitinfodialog.h"
00048 #include "dialogs/editmapparam.h"   
00049 #include "dialogs/alliancesetup.h"
00050 #include "dialogs/playersetup.h"
00051 #include "dialogs/editgameoptions.h"
00052 #include "dialogs/admingame.h"
00053 #include "dialogs/eventeditor.h"
00054 #include "dialogs/newmap.h"
00055 #include "dialogs/terraininfo.h"
00056 #include "widgets/textrenderer.h"
00057 #include "dialogs/exchangegraphics.h"
00058 #include "dialogs/fileselector.h"
00059 #include "dialogs/importbi3map.h"
00060 #include "stack.h"
00061 
00062    
00063    const char* execactionnames[execactionscount] = {
00064         "End MapEdit",
00065         "Help",
00066         "Goto EditMode",
00067         "Select terrain",
00068         "Select terrainAll",
00069         "Select unit",
00070         "Select color",
00071         "Select building",
00072         "Select object",
00073         "Select objectAll",
00074         "Select mine",
00075         "Select weather",
00076         "Setup alliances",
00077         "Setup Players",
00078         "Toggle ResourceMode",
00079         "Change UnitDirection",
00080         "Asc-Resource Mode",
00081         "Write Map2PCX",
00082         "Load map",
00083         "Change players",
00084         "New map",
00085         "Goto PolygonMode",
00086         "Rebuild Display",
00087         "Open UnitInfo",
00088         "View map",
00089         "About",
00090         "Create resources",
00091         "View/Change cargo",
00092         "View/Change resources",
00093         "Change TerrainDirection",
00094         "View/Change Events",
00095         "Toggle Fillmode",
00096         "Mapgenerator",
00097         "Use active field values as selection",
00098         "Delete active thing",
00099         "Show palette",
00100         "View/Change minestrength",
00101         "View/Change mapvalues",
00102         "View/Change production",
00103         "Save map",
00104         "View/Change item Values",
00105         "Mirror CX-Pos",
00106         "Mirror CY-Pos",
00107         "Place mine",
00108         "Place active thing",
00109         "Delete Unit",
00110         "Delete building",
00111         "Delete selected object",
00112         "Delete topmost object",
00113         "Delete all objects",
00114         "Delete mine",
00115         "AboutBox",
00116         "Save map as ...",
00117         "End PolygonMode",
00118         "Smooth coasts",
00119         "Import BI-Map",
00120         "SEPERATOR",
00121         "BI-Resource Mode",
00122         "Resize map",
00123         "Insert BI map",
00124         "Set zoom level",
00125         "Move Building",
00126         "set weather of whole map",
00127         "set map parameters",
00128         "terrain info",
00129         "set unit filter",
00130         "select graphic set",
00131         "unitset transformation",
00132         "Unitset Information",
00133         "switch maps",
00134         "transform map",
00135         "Edit Map Archival Information",
00136         "Display Resource Comparison",
00137         "specify unit production",
00138         "Paste",
00139         "Copy",
00140         "Cut",
00141         "Save Clipboard",
00142         "Load Clipboard",
00143         "Set Turn Number",
00144         "Show Pipeline Net",
00145         "Edit Technologies",
00146         "Edit ResearchPoints",
00147         "Generate TechTree",
00148         "Edit TechAdapter",
00149         "Reset Player Data...",
00150         "Fill map with resources",
00151         "setup weather generation",
00152         "Primary action",
00153         "Reset Player Data...",
00154         "View Player Strength",
00155         "Increase Zoom",
00156         "Decrease Zoom",
00157         "Edit Preferences",
00158         "Clear Mineral Resources",
00159         "Dump Building definition",
00160         "Dump Vehicle definition",
00161         "Dump Object definition",
00162         "PBP statistics",
00163         "Exchange Graphics",
00164         "Open Ctrl-key panel",
00165         "Close Ctrl-key panel",
00166         "Dump all vehicle definitions",
00167         "Clear Selection",
00168         "Dump all building definitions",
00169         "Mirror map",
00170         "Copy Area",
00171         "Paste Area",
00172         "Crash mapeditor",
00173         "Test Debug Function"
00174          };
00175 
00176 
00177 
00178 SelectionHolder selection;
00179 
00180 void SelectionHolder::setSelection( const MapComponent& component ) 
00181 {
00182    delete currentItem;
00183    currentItem = component.clone();
00184    selectionChanged( currentItem );
00185 }
00186 
00187 void SelectionHolder::setPlayer( int player )
00188 {
00189    actplayer = player;
00190    playerChanged( player );
00191    if ( currentItem )
00192       selectionChanged( currentItem );
00193 }
00194 
00195 void SelectionHolder::clear()
00196 { 
00197    currentItem = NULL;       
00198    selectionChanged( NULL ); 
00199 }; 
00200 
00201 void SelectionHolder::setWeather( int weather )
00202 {
00203    currentWeather = weather;
00204    if ( currentItem )
00205       selectionChanged( currentItem );
00206 }
00207 
00208 
00209 const MapComponent* SelectionHolder::getSelection()
00210 {
00211    return currentItem;
00212 }
00213 
00214 void SelectionHolder::pickup ( tfield* fld )
00215 {
00216    if ( fld->vehicle ) {
00217       VehicleItem v ( fld->vehicle->typ );
00218       actplayer = fld->vehicle->getOwner();
00219       setSelection( v );
00220    } else
00221    if ( fld->building ) {
00222       BuildingItem b ( fld->building->typ );
00223       actplayer = fld->building->getOwner();
00224       setSelection( b );
00225    } else
00226    if ( !fld->objects.empty() ) {
00227       ObjectItem o ( fld->objects.begin()->typ );
00228       setSelection( o );
00229    } else {
00230       TerrainItem t ( fld->typ->terraintype );
00231       setSelection( t );
00232    }
00233 }
00234 
00235 
00236       
00237         
00238 // � Infomessage
00239 
00240 int infomessage( char* formatstring, ... )
00241 {
00242    char stringtooutput[200];
00243    char* b;
00244    char* c = new char[200];
00245    // int linenum = 0;
00246 
00247    memset (stringtooutput, 0, sizeof ( stringtooutput ));
00248 
00249    b = stringtooutput;
00250 
00251    va_list paramlist;
00252    va_start ( paramlist, formatstring );
00253 
00254    vsprintf ( stringtooutput, formatstring, paramlist );
00255 
00256    va_end ( paramlist );
00257 
00258    npush ( activefontsettings );
00259    activefontsettings.justify = lefttext;
00260    activefontsettings.font = schriften.smallarial;
00261    activefontsettings.color = lightgray;
00262    activefontsettings.markcolor = red;
00263    activefontsettings.background = 0;
00264    activefontsettings.length = agmp->resolutionx - ( 640 - 387);
00265 
00266    int yy = agmp->resolutiony - ( 480 - 450 );
00267    showtext3c( stringtooutput, 37, yy );
00268 
00269    npop( activefontsettings );
00270 
00271    if ( formatstring == NULL  ||  formatstring[0] == 0 )
00272       lastdisplayedmessageticker = 0xffffff;
00273    else
00274       lastdisplayedmessageticker = ticker;
00275 
00276 
00277    delete ( c );
00278 
00279    return ++actdisplayedmessage;
00280 }
00281 
00282 
00283 ASCString getbipath ( void )
00284 {
00285    ASCString filename = getbi3path();
00286    appendbackslash( filename );
00287    filename += "mis";
00288    filename += pathdelimitterstring;
00289    filename += "*.dat";
00290 
00291    int cnt = 0;
00292 
00293    while ( !exist ( filename )) {
00294       filename = editString("enter Battle Isle path", filename );
00295       if ( filename.empty() )
00296          return "";
00297 
00298       appendbackslash(filename);
00299       
00300       CGameOptions::Instance()->BI3directory = filename;
00301       CGameOptions::Instance()->setChanged ( 1 );
00302 
00303       filename += "mis";
00304       filename += pathdelimitterstring;
00305       filename += "*.dat";
00306       
00307       cnt++;
00308       #if CASE_SENSITIVE_FILE_NAMES == 1
00309       if (!exist ( filename ) && cnt == 1 )
00310          displaymessage("The 'mis' and 'ger' / 'eng' directories must be lower case to import files from them !", 1 );
00311       #endif
00312    }
00313 
00314    return getbi3path();
00315 }
00316 
00317 
00318 double unitStrengthValue( Vehicle* veh )
00319 {
00320    double s = veh->typ->productionCost.energy + veh->typ->productionCost.material;
00321    AttackFormula af;
00322    s *= (af.strength_experience( veh->experience) + af.defense_experience( veh->experience))/2 + 1.0 ;
00323    s *= af.strength_damage( veh->damage );
00324    return s;
00325 }
00326 
00327 
00328 ASCString getVisibilityStatistics( GameMap* actmap )
00329 {
00330    ASCString msg;
00331 
00332    computeview ( actmap, 0, true );
00333 
00334    for ( int i = 0; i < actmap->getPlayerCount(); i++ ) {
00335       if ( actmap->player[i].exist() ) {
00336          msg += ASCString("#fontsize=14#Player ") + ASCString::toString( i ) + ": "+  actmap->player[i].getName() +  "#fontsize=12#\n" ;
00337          int notVisible = 0;
00338          int fogOfWar = 0;
00339          int visible = 0;
00340          for ( int x = 0; x < actmap->xsize; x++ )
00341             for ( int y = 0; y < actmap->ysize; y++ ) {
00342                 VisibilityStates vs = fieldVisibility  ( actmap->getField ( x, y ), i );
00343                 switch ( vs ) {
00344                    case visible_not: ++notVisible;
00345                    break;
00346                    case visible_ago: ++fogOfWar;
00347                    break;
00348                    default: ++visible;
00349                 }
00350             }
00351          msg += ASCString("  not visible: ") + ASCString::toString(notVisible ) + " fields\n";
00352          msg += ASCString("  fog of war: ")  + ASCString::toString(fogOfWar ) + " fields\n";
00353          msg += ASCString("  visible: ")     + ASCString::toString(visible ) + " fields\n\n";
00354       } 
00355    }
00356 
00357    computeview ( actmap, 0 , false );
00358 
00359    return msg;
00360 }
00361 
00362 ASCString getPlayerStrength( GameMap* gamemap )
00363 {
00364    ASCString message;
00365    for ( int i = 0; i< gamemap->getPlayerCount(); ++i ) {
00366       double strength = 0;
00367       Resources r;
00368       Resources total;
00369       for ( Player::VehicleList::iterator j = actmap->player[i].vehicleList.begin(); j != actmap->player[i].vehicleList.end(); ++j ) {
00370          strength += unitStrengthValue( *j );
00371          r += (*j)->typ->productionCost;
00372          total += (*j)->typ->productionCost;
00373          total += (*j)->getResource( Resources(maxint,maxint,maxint), true, 0, i );
00374       }
00375 
00376       for ( Player::BuildingList::iterator j = actmap->player[i].buildingList.begin(); j != actmap->player[i].buildingList.end(); ++j ) {
00377          total += (*j)->getResource( Resources(maxint,maxint,maxint), true, 0, i );
00378          total += (*j)->typ->productionCost;
00379       }
00380 
00381       message += ASCString("#fontsize=14#Player ") + ASCString::toString( i ) + ": "+  actmap->player[i].getName() +  "#fontsize=12#\n" ;
00382       message += "strength: ";
00383       ASCString s;
00384       s.format("%9.0f", ceil(strength/10000) );
00385       message += s + "\n";
00386       message += "Unit production cost ";
00387       for ( int k = 1; k < 2; ++k ) { // just material
00388          message += resourceNames[k];
00389          message += ": " + ASCString::toString(r.resource(k)/1000 ) + "k\n";
00390       }
00391       message += "Unit count: " + ASCString::toString( int( actmap->player[i].vehicleList.size())) + "\n";
00392       message += "Material index: " + ASCString::toString( total.material/1000 ) + "k\n";
00393       message += "\n\n";
00394 
00395    }
00396    return message;
00397 }
00398 
00399 
00400 
00401 void pbpplayerstatistics( GameMap* gamemap )
00402 {
00403    ASCString msg;
00404    { 
00405       StatusMessageWindowHolder smw = MessagingHub::Instance().infoMessageWindow( "calculating... " );
00406 
00407       msg = "#fontsize=18#Map Statistics for " + gamemap->maptitle + "#fontsize=12#\n\n"; 
00408       
00409       msg += "#fontsize=16#Visibility#fontsize=12#\n";
00410       msg += getVisibilityStatistics( gamemap );
00411       
00412       msg += "#fontsize=16#Strength#fontsize=12#\n";
00413       msg += getPlayerStrength( gamemap );
00414    }
00415    
00416    ViewFormattedText vft ( "Map Statistics", msg, PG_Rect(-1,-1,600,600));
00417    vft.Show();
00418    vft.RunModal();
00419 }
00420 
00421 
00422 class PlayerColorPanel : public PG_Widget {
00423       int openTime;
00424    public:
00425       PlayerColorPanel() : PG_Widget(NULL, PG_Rect(20,20,320,40))
00426       {
00427          int width = 30;
00428          int gap = 5;
00429          for ( int i = 0; i < max(actmap->getPlayerCount(),9); ++i ) {
00430             PG_Widget* bar = new ColoredBar( actmap->getPlayer(i).getColor(), this, PG_Rect( gap + i * (width+gap), gap, width, width ));
00431             PG_Label* lab = new PG_Label( bar, PG_Rect(5,5,width-10,width-10), ASCString::toString(i));
00432             lab->SetFontSize(15);
00433          }
00434 
00435          PG_Application::GetApp()->sigAppIdle.connect( SigC::slot( *this, &PlayerColorPanel::idler ));
00436       }
00437 
00438       void Show( bool fade = false )
00439       {
00440          openTime = ticker;
00441          PG_Widget::Show(fade);
00442       }
00443 
00444       void Hide( bool fade = false )
00445       {
00446          openTime = 0;
00447          PG_Widget::Hide(fade);
00448       }
00449 
00450 
00451       bool eventKeyDown(const SDL_KeyboardEvent* key)
00452       {
00453          if ( key->keysym.sym >= '0' && key->keysym.sym <= '9' ) {
00454             selection.setPlayer( key->keysym.sym - '0' );
00455             return true;
00456          }
00457          Hide();
00458          return false;
00459       }
00460 
00461       bool idler()
00462       {
00463          if ( !IsVisible() )
00464             return false;
00465 
00466          if ( !openTime )
00467             return false;
00468 
00469          if ( ticker > openTime + 200 ) {
00470             Hide();
00471             return true;
00472          } else
00473             return false;
00474 
00475       }
00476 
00477 };
00478 
00479 
00480 void showPlayerPanel( bool open )
00481 {
00482    static PlayerColorPanel* pcp = NULL;
00483    if ( open && !pcp ) 
00484       pcp = new PlayerColorPanel();
00485 
00486 
00487    if ( !pcp )
00488       return;
00489 
00490    if( open )
00491       pcp->Show();
00492    else
00493       pcp->Hide();
00494 }
00495 
00496 
00497 // � ExecAction
00498 
00499 
00501 void execaction( int code)
00502 {
00503    switch(code) {
00504     case act_toggleresourcemode :  {
00505          if ( mainScreenWidget )
00506             mainScreenWidget->toggleMapLayer( "resources");
00507          displaymap();
00508        }
00509        break;
00510     case act_asc_resource :   {
00511                                   actmap->_resourcemode = false;
00512                                   displaymessage ( "ASC Resource mode enabled", 3 );
00513                                 }
00514        break;
00515     case act_bi_resource :   {
00516                                   actmap->_resourcemode = true;
00517                                   displaymessage ( "Battle Isle Resource mode enabled", 3 );
00518                                }
00519        break;
00520     case act_changeplayers : playerchange();
00521        break;
00522        /*
00523     case act_polymode :   {
00524           getpolygon(&pfpoly);
00525           if (pfpoly != NULL ) {
00526              tfill = false;
00527              polyfieldmode = true;
00528 
00529              tchangepoly cp;
00530 
00531              cp.poly = pfpoly;
00532              cp.setpolytemps(1);
00533              cursor.gotoxy(1,1);
00534 
00535              displaymap();
00536              pdbaroff();
00537           }
00538        }
00539        break;
00540        */
00541     case act_viewmap :  
00542              {
00543              while (mouseparams.taste != 0)
00544                 releasetimeslice();
00545              // showmap ();
00546              displaymap();
00547              }
00548        break;
00549     case act_changeunitdir : {
00550                       tfield* pf2 = getactfield();
00551                       if ( pf2 && pf2->vehicle  ) {
00552                          pf2->vehicle->direction++;
00553                          if (pf2->vehicle->direction >= sidenum )
00554                             pf2->vehicle->direction = 0;
00555                          
00556                          mapsaved = false;
00557                          displaymap();
00558                       } 
00559                    }
00560        break;
00561     case act_changeresources :   changeresource();
00562        break;
00563     case act_createresources : {
00564                            tputresourcesdlg prd;
00565                            prd.init();
00566                            prd.run();
00567                            prd.done();
00568                            if ( mainScreenWidget )
00569                               mainScreenWidget->activateMapLayer( "resources", true);
00570                         
00571                            repaintMap();
00572 
00573                          }
00574        break;
00575        /*
00576     case act_fillmode :   if ( polyfieldmode == false ) {   
00577                  if (tfill == true) tfill = false;
00578                  else tfill = true; 
00579                  fillx1 = cursor.posx + actmap->xpos;
00580                  filly1 = cursor.posy + actmap->ypos; 
00581                  pdbaroff(); 
00582               } 
00583        break;
00584        */
00585     case act_mapgenerator : mapgenerator();
00586        break;
00587     case act_setactivefieldvals : if ( getactfield() ) 
00588                                       selection.pickup( getactfield() ); 
00589        break;
00590     case act_deletething : {
00591                          tfield* pf2 = getactfield();
00592                          mapsaved = false;
00593                          if (pf2 != NULL) {
00594                             if ( !removeCurrentItem() ) {
00595                               if (pf2->vehicle != NULL)
00596                                  delete pf2->vehicle;
00597                               else
00598                                  if (pf2->building != NULL)
00599                                     delete pf2->building;
00600                                  else
00601                                     if ( !pf2->mines.empty() )
00602                                        pf2->removemine( -1 );
00603                                     else 
00604                                        pf2->removeobject( NULL );
00605                             }
00606                                   
00607 
00608                             mapsaved = false;
00609                             mapChanged( actmap );
00610                          }
00611                       }
00612         break;
00613     case act_deleteunit : {
00614                          tfield* pf2 = getactfield();
00615                          if (pf2 != NULL)
00616                             if (pf2->vehicle != NULL) {
00617                                delete pf2->vehicle;
00618                                mapsaved = false;
00619                                mapChanged( actmap );
00620                             }
00621                          }
00622         break;
00623      case act_deletebuilding : {
00624                          tfield* pf2 = getactfield();
00625                          if (pf2 != NULL)
00626                             if (pf2->building != NULL) {
00627                                delete pf2->building;
00628                                mapsaved = false;
00629                                mapChanged( actmap );
00630                             }
00631                       }
00632         break;
00633      case act_deleteobject :
00634      case act_deletetopmostobject : {
00635                          tfield* pf2 = getactfield();
00636                          if ( pf2 ) {
00637                             mapsaved = false;
00638                             pf2->removeobject( NULL );
00639                             mapChanged( actmap );
00640                          }
00641                       }
00642         break;
00643      case act_deleteallobjects : {
00644                          tfield* pf2 = getactfield();
00645                          if ( pf2 ) {
00646                             mapsaved = false;
00647                             pf2->objects.clear( );
00648                             calculateallobjects();
00649                             mapChanged( actmap );
00650                          }
00651                       }
00652         break;
00653      case act_deletemine : {
00654                          tfield* pf2 = getactfield();
00655                          if (pf2 != NULL) {
00656                             mapsaved = false;
00657                             pf2->removemine( -1 );
00658                             mapChanged( actmap );
00659                          }
00660                       }
00661         break;
00662     case act_changeminestrength : changeminestrength();
00663        break;
00664     case act_changeunitvals :   {
00665                  tfield* pf2 = getactfield();
00666                  if ( pf2  ) {
00667                     if ( pf2->vehicle ) {
00668                        changeunitvalues(pf2->vehicle);
00669                        displaymap();
00670                     }
00671                     else if ( pf2->building ) {
00672                        changebuildingvalues(*pf2->building);
00673                     } /* endif */
00674                  } /* endif */
00675               } 
00676               break;
00677               
00678     case act_mirrorcursorx :   {
00679                      MapDisplayPG* md = getMainScreenWidget()->getMapDisplay();
00680                      md->cursor.goTo( MapCoordinate(actmap->xsize - md->cursor.pos().x, md->cursor.pos().y ) );
00681                  }
00682 
00683        break;
00684     case act_mirrorcursory :   {
00685                      MapDisplayPG* md = getMainScreenWidget()->getMapDisplay();
00686                      md->cursor.goTo( MapCoordinate(md->cursor.pos().x, actmap->ysize - md->cursor.pos().y ) );
00687                  }
00688        break;
00689        
00690 //    case act_placemine : placemine();
00691 //       break;
00692     case act_placething : placeCurrentItem();
00693        break;
00694        /*
00695     case act_endpolyfieldmode : {
00696           if (polyfieldmode) {
00697              polyfieldmode = false;
00698              tchangepoly cp;
00699 
00700              cp.poly = pfpoly;
00701              cp.setpolytemps(0);
00702 
00703              displaymap();
00704              pdbaroff();
00705              ch = 255;
00706           }
00707        }
00708        break;
00709        */
00710     case act_about :
00711     case act_aboutbox : {
00712        
00713        ASCString s = "#fontsize=22#Advanced Strategic Command\nMap Editor#fontsize=14#\n";
00714        s += getVersionAndCompilation();
00715 
00716        // s += "\n#fontsize=18#Credits#fontsize=14#\n";
00717 
00718        s += readtextmessage( 1020 );
00719                      
00720        ViewFormattedText vft( "About", s, PG_Rect(-1,-1,450,550));
00721        vft.Show();
00722        vft.RunModal();
00723        
00724        /*
00725          help(1020);
00726          tviewanytext vat;
00727          ASCString msg = kgetstartupmessage();
00728          vat.init ( "about", msg.c_str() );
00729          vat.run();
00730          vat.done();
00731        */
00732       }
00733       break;
00734    case act_smoothcoasts : {
00735             ForestCalculation::smooth ( 6, actmap, NULL );
00736             displaymap();
00737       }
00738       break;
00739    case act_resizemap : resizemap();
00740       break;
00741    case act_movebuilding: movebuilding();
00742       break;
00743       case act_setactweatherglobal: setweatherall ( selection.getWeather() );
00744                                  displaymap();
00745       break;
00746    case act_terraininfo: viewterraininfo( actmap, actmap->getCursor(), true);
00747       break;
00748    case act_setunitfilter: selectunitsetfilter();
00749                            filtersChangedSignal(); 
00750       break;
00751    // case act_setzoom : choosezoomlevel();
00752    //    break;
00753    case act_unitsettransformation: unitsettransformation();
00754       break;
00755    case act_unitSetInformation: viewUnitSetinfo();
00756       break;
00757    case act_primaryAction: if ( mapSwitcher.getDefaultAction() == MapSwitcher::select ) {
00758                               execaction ( act_setactivefieldvals );
00759                               execaction(act_switchmaps);
00760                            } else 
00761                              execaction( act_placething );
00762                              
00763                            break;
00764                            
00765    case act_switchmaps: mapSwitcher.toggle();
00766                         displaymap();
00767                         updateFieldInfo();
00768       break;
00769    case act_editArchivalInformation: editArchivalInformation();
00770       break;
00771    case act_displayResourceComparison : resourceComparison();
00772       break;
00773       /*
00774    case act_specifyunitproduction: unitProductionLimitation();
00775       break;
00776       */
00777    case act_pasteFromClipboard: if ( getactfield() && !getactfield()->getContainer() ) {
00778                                    ClipBoard::Instance().place( actmap->getCursor() );
00779                                    mapsaved = false;
00780                                    displaymap();
00781                                 }
00782       break;
00783    case act_copyToClipboard: if ( getactfield() ) {
00784                                  if ( getactfield()->vehicle ) {
00785                                     ClipBoard::Instance().clear();
00786                                     ClipBoard::Instance().addUnit( getactfield()->vehicle );
00787                                  } else
00788                                     if ( getactfield()->building ) {
00789                                        ClipBoard::Instance().clear();
00790                                        ClipBoard::Instance().addBuilding( getactfield()->building );
00791                                     }
00792                              }
00793       break;
00794    case act_cutToClipboard: if ( getactfield() ) {
00795                               if ( getactfield()->vehicle ) {
00796                                  ClipBoard::Instance().clear();
00797                                  ClipBoard::Instance().addUnit( getactfield()->vehicle );
00798                                  execaction ( act_deleteunit );
00799                                  mapsaved = false;
00800                               } else
00801                                  if ( getactfield()->building ) {
00802                                     ClipBoard::Instance().clear();
00803                                     ClipBoard::Instance().addBuilding( getactfield()->building );
00804                                     execaction ( act_deletebuilding );
00805                                     mapsaved = false;
00806                                  }
00807                             }
00808       break;
00809    case act_saveClipboard:  saveClipboard();
00810       break;
00811 
00812    case act_readClipBoard:  readClipboard();
00813       break;
00814    case act_setTurnNumber:  actmap->time.set ( getid("Turn",actmap->time.turn(),0,maxint), 0 );
00815       break;
00816    case act_showPipeNet:    mainScreenWidget->getMapDisplay()->toggleMapLayer("pipes");
00817       repaintMap();
00818       break;
00819    case act_editResearch:  editResearch();
00820       break;
00821    case act_editResearchPoints:  editResearchPoints();
00822       break;
00823    case act_generateTechTree: generateTechTree();
00824       break;
00825    case act_editTechAdapter: editTechAdapter();
00826       break;
00827    case act_playerStrengthSummary: pbpplayerstatistics( actmap );
00828       break;
00829 
00830     }
00831 }
00832 
00834 void execaction_pg(int code) 
00835 {
00836    switch(code) {
00837 #ifdef WEATHERGENERATOR
00838       case act_setactnewweather: weatherConfigurationDialog();
00839          break;
00840 #endif
00841     case act_selbodentyp : if ( mapSwitcher.getDefaultAction() == MapSwitcher::select ) 
00842                               execaction ( act_setactivefieldvals );
00843                            execaction( act_switchmaps);
00844        break;
00845     case act_selbodentypAll : mainScreenWidget->selectTerrainList();
00846        break;
00847     case act_selunit : mainScreenWidget->selectVehicle();
00848        break;
00849     case act_selbuilding : mainScreenWidget->selectBuilding(); 
00850        break;
00851     case act_selobject : mainScreenWidget->selectObject();
00852        break;
00853     case act_selobjectAll: mainScreenWidget->selectTerrainList();
00854        /* if ( mapSwitcher.getDefaultAction() == MapSwitcher::select ) 
00855                               execaction ( act_setactivefieldvals );
00856                            execaction( act_switchmaps);
00857                            */
00858        break;                    
00859     case act_selmine : mainScreenWidget->selectMine();
00860        break;
00861     case act_unitinfo :  unitInfoDialog();
00862        break;
00863     case act_setmapparameters: setmapparameters( actmap );
00864        break;
00865     case act_setupalliances :  setupalliances( actmap, true );
00866        break;
00867     case act_setupplayers :  setupPlayers( actmap, true );
00868        break;
00869     case act_loadmap :   {
00870                             if (mapsaved == false )
00871                                if (choice_dlg("Map not saved ! Save now ?","~y~es","~n~o") == 1) 
00872                                   k_savemap(false);
00873 
00874                             GameMap* oldmap = actmap;
00875                             actmap = NULL;
00876                             try {
00877                                 k_loadmap();
00878                             }
00879                             catch ( ... ) {
00880                                 displaymessage ( "error loading file",1 );
00881                             }
00882                             if ( !actmap ) {
00883                                 actmap = oldmap;
00884                                 oldmap = NULL;
00885                             } else {
00886                                delete oldmap;
00887                                oldmap = NULL;
00888                             }
00889                             displaymap();
00890                           } 
00891        break;
00892     case act_savemap :  k_savemap(false);
00893        break;
00894     case act_savemapas :  k_savemap(true);
00895        break;
00896     case act_maptopcx : {
00897        bool view = choice_dlg("Include view ?","~n~o", "~y~es") == 2;
00898        if ( view )
00899           computeview( actmap );
00900        writemaptopcx ( actmap, view );
00901                         }
00902        break;
00903     case act_end : {
00904           if ( mapSwitcher.getDefaultAction() == MapSwitcher::select ) 
00905              execaction(act_switchmaps);
00906           else
00907              if (choice_dlg("Do you really want to quit ?","~y~es","~n~o") == 1) {
00908                 getPGApplication().Quit();
00909              }
00910        }
00911        break;
00912        case act_changecargo :
00913           if ( getactfield() && getactfield()->getContainer() )
00914              cargoEditor( getactfield()->getContainer() );
00915        
00916        break;
00917        case act_createresources2 : resourcePlacementDialog();
00918          displaymap();
00919        break;
00920        case act_changeproduction :   if ( getactfield() && getactfield()->getContainer() ) {
00921                                        if ( getactfield()->getContainer()->baseType->hasFunction( ContainerBaseType::InternalVehicleProduction  ))
00922                                           editProduction( getactfield()->getContainer() );
00923                                        else
00924                                           warning("this unit/building has no production capabilities");
00925                                      }
00926        break;
00927        case act_selectgraphicset: selectgraphicset();
00928                               // showallchoices();
00929        break;
00930        case act_transformMap: transformMap();
00931        break;
00932       case act_increase_zoom:
00933          if ( mainScreenWidget && mainScreenWidget->getMapDisplay() ) {
00934             mainScreenWidget->getMapDisplay()->changeZoom( 10 );
00935             viewChanged();
00936             repaintMap();
00937          }
00938          break;
00939       case act_decrease_zoom:
00940          if ( mainScreenWidget && mainScreenWidget->getMapDisplay() ) {
00941             mainScreenWidget->getMapDisplay()->changeZoom( -10 );
00942             viewChanged();
00943             repaintMap();
00944          }
00945          break;
00946       case act_editpreferences:
00947          editGameOptions( false );
00948          break;
00949 
00950       case act_events :   eventEditor();
00951          break;
00952       case act_resetPlayerData: adminGame( actmap );
00953          break;
00954       case act_changemapvals :   editMap(actmap);
00955          break;
00956       case act_newmap :   newmap();
00957          break;
00958       case act_clearresources: {
00959          for ( int y = 0; y < actmap->ysize; ++y)
00960             for ( int x = 0; x < actmap->xsize; ++x ) {
00961                actmap->getField(x,y)->fuel = 0;
00962                actmap->getField(x,y)->material = 0;
00963             }
00964             repaintMap();
00965       }
00966       case act_dumpBuilding: 
00967          if ( getactfield() && getactfield()->building ) {
00968             ASCString filename = selectFile( "*.dump", false );
00969             if ( !filename.empty () ) {
00970                tn_file_buf_stream stream ( filename, tnstream::writing );
00971                PropertyWritingContainer pc ( "BuildingDump", stream );
00972                actmap->getbuildingtype_byid(getactfield()->building->typ->id)->runTextIO( pc );
00973             }
00974          } else
00975             errorMessage("no building selected");
00976          break;
00977       case act_dumpVehicle: 
00978          if ( getactfield() && getactfield()->vehicle ) {
00979             ASCString filename = selectFile( "*.dump", false );
00980             if ( !filename.empty () ) {
00981                tn_file_buf_stream stream ( filename, tnstream::writing );
00982                PropertyWritingContainer pc ( "VehicleDump", stream );
00983                actmap->getvehicletype_byid(getactfield()->vehicle->typ->id)->runTextIO( pc );
00984             }
00985          } else
00986             errorMessage("no building selected");
00987          break;
00988       case act_dumpObject: 
00989          if ( getactfield() && !getactfield()->objects.empty() ) {
00990             ASCString filename = selectFile( "*.dump", false );
00991             if ( !filename.empty () ) {
00992                tn_file_buf_stream stream ( filename, tnstream::writing );
00993                PropertyWritingContainer pc ( "ObjectDump", stream );
00994                actmap->getobjecttype_byid( getactfield()->objects.front().typ->id)->runTextIO( pc );
00995             }
00996          } else
00997             errorMessage("no building selected");
00998          break;
00999     case act_help : help(1000);
01000        break;
01001     case act_pbpstatistics: pbpplayerstatistics( actmap );
01002        break;
01003     case act_exchangeGraphics: exchangeGraphics();
01004        break;
01005     case act_openControlPanel: showPlayerPanel(true);
01006        break;
01007     case act_releaseControlPanel: showPlayerPanel(false);
01008        break;
01009     case act_dumpAllVehicleDefinitions: {
01010                                           StatusMessageWindowHolder smw = MessagingHub::Instance().infoMessageWindow( "dumping all units" );
01011                                           for ( int i = 0; i < vehicleTypeRepository.getNum(); ++i ) {
01012                                              Vehicletype* veh = vehicleTypeRepository.getObject_byPos( i );
01013                                              tn_file_buf_stream stream ( "Vehicle" + ASCString::toString( i ) + ".dump", tnstream::writing );
01014                                              PropertyWritingContainer pc ( "VehicleDump", stream );
01015                                              veh->runTextIO( pc );
01016                                           }
01017                                         };
01018        break;
01019     case act_dumpAllBuildings: {
01020                                           StatusMessageWindowHolder smw = MessagingHub::Instance().infoMessageWindow( "dumping all buildings" );
01021                                           for ( int i = 0; i < buildingTypeRepository.getNum(); ++i ) {
01022                                              BuildingType* bld = buildingTypeRepository.getObject_byPos( i );
01023                                              tn_file_buf_stream stream ( "Building" + ASCString::toString( i ) + ".dump", tnstream::writing );
01024                                              PropertyWritingContainer pc ( "BuildingDump", stream );
01025                                              bld->runTextIO( pc );
01026                                           }
01027                                         };
01028        break;
01029 
01030       case act_clearSelection: selection.clear();
01031       break;
01032       case act_locateItemByID: locateItemByID();
01033          break;
01034       case act_mirrorMap: mirrorMap();
01035          break;
01036       case act_copyArea: copyArea();
01037          break;
01038       case act_pasteArea: pasteArea();
01039          break;
01040       case asc_nullPointerCrash: {
01041             char* p = NULL;
01042             *p = 1;
01043          }
01044          break;
01045       case asc_testFunction: testDebugFunction(); 
01046          break;
01047       case act_import_bi_map : 
01048          if (mapsaved == false )
01049             if (choice_dlg("Map not saved ! Save now ?","~y~es","~n~o") == 1) 
01050                k_savemap(false);
01051          importBI3Map( actmap );
01052          displaymap();
01053          break;
01054       case act_insert_bi_map : 
01055          importBI3Map( actmap, true );
01056          displaymap();
01057          break;
01058    };
01059 }
01060 
01061 void         execaction_ev(int code)
01062 {
01063    execaction_pg(code);
01064    execaction(code);
01065 }

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