2
This file is part of Advanced Strategic Command; http://www.asc-hq.de
3
Copyright (C) 1994-2008 Martin Bickel and Marc Schellenberger
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; see the file COPYING. If not, write to the
17
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18
Boston, MA 02111-1307 USA
22
#include "convertcontainer.h"
23
#include "destructcontainer.h"
24
#include "action-registry.h"
26
#include "../vehicle.h"
28
ConvertContainer::ConvertContainer( ContainerBase* container, int newPlayer )
29
: ContainerAction( container ), newOwner(newPlayer), previousOwner(-1)
33
ASCString ConvertContainer::getDescription() const
35
ASCString res = "Change owner of " + getContainer()->getName();
36
res += " to " + ASCString::toString(newOwner);
41
void ConvertContainer::readData ( tnstream& stream )
43
ContainerAction::readData( stream );
44
int version = stream.readInt();
46
throw tinvalidversion ( "ConvertContainer", 1, version );
48
newOwner = stream.readInt();
49
previousOwner = stream.readInt();
53
void ConvertContainer::writeData ( tnstream& stream ) const
55
ContainerAction::writeData( stream );
57
stream.writeInt( newOwner );
58
stream.writeInt( previousOwner );
62
GameActionID ConvertContainer::getID() const
64
return ActionRegistry::ConvertContainer;
68
ActionResult ConvertContainer::runAction( const Context& context )
70
ContainerBase* c = getContainer();
71
previousOwner = c->getOwner();
73
if ( c->baseType->hasFunction( ContainerBaseType::SelfDestructOnConquer ) ) {
74
(new DestructContainer(c))->execute(context);
75
return ActionResult(0);
78
c->registerForNewOwner( newOwner );
80
for ( ContainerBase::Cargo::iterator i = c->cargo.begin(); i != c->cargo.end(); ++i )
82
(new ConvertContainer( *i, newOwner ))->execute(context);
86
ContainerBase::anyContainerConquered(c);
88
return ActionResult(0);
92
ActionResult ConvertContainer::undoAction( const Context& context )
94
getContainer()->registerForNewOwner( previousOwner );
95
return ActionResult(0);
98
ActionResult ConvertContainer::preCheck()
100
if ( getContainer()->getOwner() != previousOwner )
101
throw ActionResult( 21204, getContainer(), "owner" );
103
return ActionResult(0);
106
ActionResult ConvertContainer::postCheck()
108
if ( getContainer()->getOwner() != newOwner )
109
throw ActionResult( 21204, getContainer(), "owner" );
111
return ActionResult(0);
116
const bool r1 = registerAction<ConvertContainer> ( ActionRegistry::ConvertContainer );