00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "campaignactionrecorder.h"
00022
00023 #include "dialogs/fileselector.h"
00024
00025
00026
00027 void CampaignActionLogger::endTurn( Player& player )
00028 {
00029 gamemap->actions.breakUndo();
00030 commands.push_back( "-- Ending turn " + ASCString::toString( player.getParentMap()->time.turn() ) + "\n" );
00031 commands.push_back( "asc.endTurn()\n" );
00032 }
00033
00034 void CampaignActionLogger::mapWon( Player& player )
00035 {
00036 ASCString filename = selectFile( "*.lua", false );
00037 if ( !filename.empty() ) {
00038 tn_file_buf_stream stream ( filename, tnstream::writing );
00039 for ( CommandList::const_iterator i = commands.begin(); i != commands.end(); ++i )
00040 stream.writeString( *i, false );
00041 }
00042 }
00043
00044
00045 void CampaignActionLogger::commitCommand( GameMap* map, Command& command )
00046 {
00047 if ( map == gamemap && map->getCurrentPlayer().isHuman() ) {
00048 writer.printComment( command.getDescription() );
00049 writer.printCommand( command.getCommandString() );
00050 }
00051 }
00052
00053 CampaignActionLogger::CampaignActionLogger ( GameMap* map ) : gamemap ( map ), commands(), writer( commands )
00054 {
00055 gamemap->sigPlayerUserInteractionEnds.connect( SigC::slot( *this, &CampaignActionLogger::endTurn ));
00056 gamemap->sigMapWon.connect( SigC::slot( *this, &CampaignActionLogger::mapWon ));
00057 gamemap->actions.commitCommand.connect( SigC::slot( *this, &CampaignActionLogger::commitCommand ));
00058 }
00059
00060
00061 void CampaignActionLogger::readData ( tnstream& stream )
00062 {
00063 stream.readInt();
00064 int count = stream.readInt();
00065 for ( int i = 0; i <count; ++i ) {
00066 ASCString s;
00067 stream.readTextString( s, true );
00068 commands.push_back( s );
00069 }
00070 int check = stream.readInt();
00071 if ( check != 0xbac0 )
00072 throw ASCmsgException("marker not matched when loading CampaignActionLogger");
00073
00074 }
00075
00076 void CampaignActionLogger::writeData ( tnstream& stream )
00077 {
00078 stream.writeInt(1);
00079 stream.writeInt( commands.size() );
00080 for ( CommandList::const_iterator i = commands.begin(); i != commands.end(); ++i ) {
00081 stream.writeString( *i );
00082 }
00083 stream.writeInt( 0xbac0 );
00084 };
00085