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 "renamecontainercommand.h" 00023 00024 #include "../vehicle.h" 00025 #include "../mapfield.h" 00026 #include "../gamemap.h" 00027 #include "../viewcalculation.h" 00028 #include "../spfst.h" 00029 #include "../mapdisplayinterface.h" 00030 #include "action-registry.h" 00031 #include "../itemrepository.h" 00032 #include "../containercontrols.h" 00033 #include "consumeresource.h" 00034 #include "servicecommand.h" 00035 #include "convertcontainer.h" 00036 00037 bool RenameContainerCommand :: avail ( const ContainerBase* container ) 00038 { 00039 if ( !container ) 00040 return false; 00041 00042 return true; 00043 } 00044 00045 00046 RenameContainerCommand :: RenameContainerCommand ( ContainerBase* container ) 00047 : ContainerCommand ( container ) 00048 { 00049 00050 } 00051 00052 00053 00054 void RenameContainerCommand::setName( const ASCString& publicName, const ASCString& privateName ) 00055 { 00056 this->publicName = publicName; 00057 this->privateName = privateName; 00058 setState( SetUp ); 00059 } 00060 00061 00062 ActionResult RenameContainerCommand::go ( const Context& context ) 00063 { 00064 if ( getState() != SetUp ) 00065 return ActionResult(22000); 00066 00067 if ( !avail( getContainer() )) 00068 return ActionResult(22800); 00069 00070 ContainerBase* container = getContainer(); 00071 00072 originalPublicName = container->name; 00073 originalPrivateName = container->privateName; 00074 container->name = publicName; 00075 container->privateName = privateName; 00076 00077 setState( Finished ); 00078 00079 return ActionResult(0); 00080 } 00081 00082 ActionResult RenameContainerCommand::undoAction( const Context& context ) 00083 { 00084 ContainerBase* container = getContainer(); 00085 if ( !container ) 00086 return ActionResult(23600); 00087 00088 container->name = originalPublicName; 00089 container->privateName = originalPrivateName; 00090 00091 return ContainerCommand::undoAction( context ); 00092 } 00093 00094 00095 static const int RenameContainerCommandVersion = 1; 00096 00097 void RenameContainerCommand :: readData ( tnstream& stream ) 00098 { 00099 ContainerCommand::readData( stream ); 00100 int version = stream.readInt(); 00101 if ( version > RenameContainerCommandVersion ) 00102 throw tinvalidversion ( "RenameContainerCommand", RenameContainerCommandVersion, version ); 00103 originalPublicName = stream.readString(); 00104 originalPrivateName = stream.readString(); 00105 publicName = stream.readString(); 00106 privateName = stream.readString(); 00107 } 00108 00109 void RenameContainerCommand :: writeData ( tnstream& stream ) const 00110 { 00111 ContainerCommand::writeData( stream ); 00112 stream.writeInt( RenameContainerCommandVersion ); 00113 stream.writeString( originalPublicName ); 00114 stream.writeString( originalPrivateName ); 00115 stream.writeString( publicName ); 00116 stream.writeString( privateName ); 00117 } 00118 00119 00120 ASCString RenameContainerCommand :: getCommandString() const 00121 { 00122 ASCString c; 00123 c.format("renameContainer ( map, %d, '%s', '%s' )", getContainerID(), publicName.c_str(), privateName.c_str() ); 00124 return c; 00125 00126 } 00127 00128 GameActionID RenameContainerCommand::getID() const 00129 { 00130 return ActionRegistry::RenameContainerCommand; 00131 } 00132 00133 ASCString RenameContainerCommand::getDescription() const 00134 { 00135 ASCString s = "Rename "; 00136 00137 if ( getContainer(true) ) { 00138 s += getContainer()->baseType->getName(); 00139 } else 00140 s += originalPublicName; 00141 00142 s += " to " + publicName; 00143 00144 return s; 00145 } 00146 00147 namespace 00148 { 00149 const bool r1 = registerAction<RenameContainerCommand> ( ActionRegistry::RenameContainerCommand ); 00150 } 00151
1.5.1