00001 /* 00002 This file is part of Advanced Strategic Command; http://www.asc-hq.org 00003 Copyright (C) 1994-2010 Martin Bickel 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 "abstracttaskcontainer.h" 00022 #include "../basestrm.h" 00023 00024 00025 AbstractTaskContainer::AbstractTaskContainer() : newTasks(NULL), lastPlayer(-1) 00026 { 00027 for ( int i = 0; i < GameMap::maxTotalPlayers; ++i ) 00028 playerTasks[i] = NULL; 00029 } 00030 00031 AbstractTaskContainer::~AbstractTaskContainer() 00032 { 00033 for ( int i = 0; i < GameMap::maxTotalPlayers; ++i ) { 00034 delete playerTasks[i]; 00035 playerTasks[i] = NULL; 00036 } 00037 00038 delete newTasks; 00039 newTasks = NULL; 00040 } 00041 00042 void AbstractTaskContainer::writeStorage( tnstream& stream ) const 00043 { 00044 stream.writeInt( taskMagic ); 00045 for ( int i = 0; i < GameMap::maxTotalPlayers; ++i ) { 00046 if ( playerTasks[i] ) { 00047 stream.writeInt( 1 ); 00048 playerTasks[i]->writetostream( &stream ); 00049 } else 00050 stream.writeInt( 0 ); 00051 } 00052 stream.writeInt( taskMagic ); 00053 if ( newTasks ) { 00054 stream.writeInt( 1 ); 00055 newTasks->writetostream( &stream ); 00056 } else 00057 stream.writeInt( 0 ); 00058 00059 stream.writeInt( lastPlayer ); 00060 stream.writeInt( taskMagic ); 00061 00062 } 00063 00064 00065 void AbstractTaskContainer::readStorage( tnstream& stream ) 00066 { 00067 int magic = stream.readInt(); 00068 if ( magic != taskMagic ) 00069 throw new tinvalidversion( stream.getLocation(), taskMagic, magic ); 00070 00071 for ( int i = 0; i < GameMap::maxTotalPlayers; ++i ) { 00072 00073 delete playerTasks[i]; 00074 playerTasks[i] = NULL; 00075 00076 int data = stream.readInt(); 00077 if ( data ) { 00078 playerTasks[i] = new MemoryStreamStorage(); 00079 playerTasks[i]->readfromstream( &stream ); 00080 } 00081 } 00082 00083 magic = stream.readInt(); 00084 if ( magic != taskMagic ) 00085 throw new tinvalidversion( stream.getLocation(), taskMagic, magic ); 00086 00087 delete newTasks; 00088 newTasks = NULL; 00089 00090 if ( stream.readInt() ) { 00091 newTasks = new MemoryStreamStorage(); 00092 newTasks->readfromstream( &stream ); 00093 } 00094 00095 lastPlayer = stream.readInt(); 00096 00097 magic = stream.readInt(); 00098 if ( magic != taskMagic ) 00099 throw new tinvalidversion( stream.getLocation(), taskMagic, magic ); 00100 00101 }
1.5.1