pbpeditor.cpp

Go to the documentation of this file.
00001 static ASCString ASCfilename;
00002 
00003 #include "network/simple_file_transfer.h"
00004 
00005 void         k_savemap(char saveas)
00006 {
00007    ASCString filename;
00008 
00009    int nameavail = 0;
00010    if ( !actmap->preferredFileNames.mapname[0].empty() ) {
00011       nameavail = 1;
00012       filename = actmap->preferredFileNames.mapname[0];;
00013    }
00014 
00015    if ( saveas || !nameavail ) {
00016       filename = selectFile(ASCString("*") + tournamentextension, false);
00017    }
00018    if ( !filename.empty() ) {
00019 
00020       FileTransfer ft;
00021       ft.setup( filename );
00022       ft.send ( actmap, -1, -1 );
00023       mapsaved = true;
00024    }
00025 }
00026 
00027 
00028 void         k_loadmap(void)
00029 {
00030    ASCString s1 = selectFile(  ASCString("*") + tournamentextension + ";*.asc", true );
00031    if ( !s1.empty() ) {
00032       StatusMessageWindowHolder smw = MessagingHub::Instance().infoMessageWindow( "loading map " + s1 );
00033       FileTransfer ft;
00034       GameMap* mp = mapLoadingExceptionChecker( s1, MapLoadingFunction( &ft, &FileTransfer::loadPBEMFile ));
00035       if ( !mp )
00036          return;
00037          
00038       if ( mp->getgameparameter(cgp_superVisorCanSaveMap) == 0 ) {
00039          delete mp;
00040          throw ASCmsgException("The function to manipulate a game has not been enabled when it was started");
00041       }
00042       
00043       bool participatingSV = false;
00044       Password pwd;
00045       for ( int i = 0; i < mp->getPlayerCount(); ++i )
00046          if ( mp->getPlayer(i).stat == Player::supervisor ) 
00047             if ( !mp->getPlayer(i).passwordcrc.empty() ) {
00048                pwd = mp->getPlayer(i).passwordcrc;
00049                participatingSV = true;
00050                break;
00051             }
00052      
00053       if ( pwd.empty() ) 
00054          pwd = mp->supervisorpasswordcrc;
00055 
00056       if ( pwd.empty() ) {
00057          delete mp;
00058          
00059          if ( participatingSV ) 
00060             throw ASCmsgException("You can't load this file. While a supervisor was defined in the game, he doesn't use a password");
00061          else
00062             throw ASCmsgException("Sorry, you can't load this file because no supervisor was defined ");
00063       }
00064 
00065       tlockdispspfld ldsf;
00066       if ( !enterpassword ( pwd )) {
00067          delete mp;
00068          throw  NoMapLoaded();
00069       }
00070       ASCfilename = s1;
00071       
00072       delete actmap;
00073       actmap =  mp;
00074       
00075       displaymap();
00076       mapsaved = true;
00077       actmap->preferredFileNames.mapname[0] = s1;
00078    }
00079 }
00080 

Generated on Mon May 21 01:26:36 2012 for Advanced Strategic Command by  doxygen 1.5.1