campaignactionrecorder.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-2010  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 #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 

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