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 00022 #include "command.h" 00023 #include "../util/messaginghub.h" 00024 #include "../basestrm.h" 00025 00026 Command::Command( GameMap* gamemap ) 00027 : GameAction( gamemap ), state ( Planned ) 00028 { 00029 } 00030 00031 void Command::readData ( tnstream& stream ) 00032 { 00033 stream.readInt(); 00034 state = (State)stream.readInt(); 00035 } 00036 00037 00038 void Command::writeData ( tnstream& stream ) const 00039 { 00040 stream.writeInt(1); 00041 stream.writeInt( (int) state ); 00042 } 00043 00044 void Command::setState( State state ) 00045 { 00046 this->state = state; 00047 } 00048 00049 00050 ActionResult Command::runAction( const Context& context ) 00051 { 00052 ActionResult res = checkExecutionPrecondition(); 00053 if ( !res.successful() ) 00054 return res; 00055 else 00056 return go ( context ); 00057 } 00058 00059 00060 ActionResult Command::undoAction( const Context& context ) 00061 { 00062 return ActionResult(0); 00063 } 00064 00065 ActionResult Command::redo( const Context& context ) 00066 { 00067 if ( getState() == Finished || getState() == Run ) 00068 setState( SetUp ); 00069 00070 deleteChildren(); 00071 00072 Context c ( context, this ); 00073 00074 return go(c); 00075 } 00076 00077 vector<MapCoordinate> Command::getCoordinates() const 00078 { 00079 return vector<MapCoordinate>(); 00080 } 00081 00082 ActionResult Command::checkExecutionPrecondition() const 00083 { 00084 return ActionResult(0); 00085 } 00086
1.5.1