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 "consumeresource.h" 00023 00024 #include "../vehicle.h" 00025 #include "../gamemap.h" 00026 00027 ConsumeResource::ConsumeResource( ContainerBase* container, const Resources& toGet ) 00028 : ContainerAction( container ) 00029 { 00030 this->toGet = toGet; 00031 this->globalStorage = globalStorage; 00032 } 00033 00034 00035 ASCString ConsumeResource::getDescription() const 00036 { 00037 ASCString res = "Consume " + toGet.toString() + " resources "; 00038 const ContainerBase* c = getContainer(); 00039 if ( c ) 00040 res += " of " + c->getName(); 00041 return res; 00042 } 00043 00044 00045 const intn consumeResourceVersion = 1; 00046 00047 void ConsumeResource::readData ( tnstream& stream ) 00048 { 00049 ContainerAction::readData( stream ); 00050 00051 int version = stream.readInt(); 00052 if ( version < 1 || version > consumeResourceVersion) 00053 throw tinvalidversion ( "ConsumeResource", consumeResourceVersion, version ); 00054 00055 toGet.read( stream ); 00056 got.read( stream ); 00057 }; 00058 00059 00060 void ConsumeResource::writeData ( tnstream& stream ) const 00061 { 00062 ContainerAction::writeData( stream ); 00063 stream.writeInt( consumeResourceVersion ); 00064 toGet.write( stream ); 00065 got.write( stream ); 00066 }; 00067 00068 00069 GameActionID ConsumeResource::getID() const 00070 { 00071 return ActionRegistry::ConsumeResource; 00072 } 00073 00074 ActionResult ConsumeResource::runAction( const Context& context ) 00075 { 00076 got = getContainer()->getResource( toGet, false, 1, context.actingPlayer->getPosition() ); 00077 return ActionResult(0); 00078 } 00079 00080 00081 ActionResult ConsumeResource::undoAction( const Context& context ) 00082 { 00083 getContainer()->putResource( got, false, 1, context.actingPlayer->getPosition() ); 00084 return ActionResult(0); 00085 } 00086 00087 ActionResult ConsumeResource::postCheck() 00088 { 00089 return ActionResult(0); 00090 } 00091 00092 00093 namespace { 00094 const bool r1 = registerAction<ConsumeResource> ( ActionRegistry::ConsumeResource ); 00095 }
1.5.1