~ubuntu-branches/ubuntu/maverick/asc/maverick

« back to all changes in this revision

Viewing changes to source/actions/convertcontainer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Moritz Muehlenhoff, Moritz Muehlenhoff, Barry deFreese, Alexander Reichle-Schmehl
  • Date: 2010-01-01 22:11:14 UTC
  • mfrom: (1.1.6 upstream) (2.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100101221114-qfg9ogppdfcte4m7
Tags: 2.4.0.0-1
[ Moritz Muehlenhoff ]
* New upstream release. (2.4.0)
  - Drop obsolete patches
  - Initializes map_edit properly. (Closes: #534171).
* Update to standards version 3.8.3
* Switch to source format 3.0 (quilt) (Closes: #538430)
* Adding myself to uploaders

[ Barry deFreese ]
* New upstream release. (2.2.0)

[ Alexander Reichle-Schmehl ]
* Adopt debian/control to my new name.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
     This file is part of Advanced Strategic Command; http://www.asc-hq.de
 
3
     Copyright (C) 1994-2008  Martin Bickel  and  Marc Schellenberger
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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
 
19
*/
 
20
 
 
21
 
 
22
#include "convertcontainer.h"
 
23
#include "destructcontainer.h"
 
24
#include "action-registry.h"
 
25
 
 
26
#include "../vehicle.h"
 
27
 
 
28
ConvertContainer::ConvertContainer( ContainerBase* container, int newPlayer )
 
29
   : ContainerAction( container ), newOwner(newPlayer), previousOwner(-1)
 
30
{
 
31
}
 
32
      
 
33
ASCString ConvertContainer::getDescription() const
 
34
{
 
35
   ASCString res = "Change owner of " + getContainer()->getName();
 
36
   res += " to " + ASCString::toString(newOwner);
 
37
   return  res;
 
38
}
 
39
      
 
40
      
 
41
void ConvertContainer::readData ( tnstream& stream ) 
 
42
{
 
43
   ContainerAction::readData( stream );
 
44
   int version = stream.readInt();
 
45
   if ( version != 1 )
 
46
      throw tinvalidversion ( "ConvertContainer", 1, version );
 
47
   
 
48
   newOwner = stream.readInt();
 
49
   previousOwner = stream.readInt();
 
50
};
 
51
      
 
52
      
 
53
void ConvertContainer::writeData ( tnstream& stream ) const
 
54
{
 
55
   ContainerAction::writeData( stream );
 
56
   stream.writeInt( 1 );
 
57
   stream.writeInt( newOwner );
 
58
   stream.writeInt( previousOwner );
 
59
};
 
60
 
 
61
 
 
62
GameActionID ConvertContainer::getID() const
 
63
{
 
64
   return ActionRegistry::ConvertContainer;
 
65
}
 
66
 
 
67
 
 
68
ActionResult ConvertContainer::runAction( const Context& context )
 
69
{
 
70
   ContainerBase* c = getContainer();
 
71
   previousOwner = c->getOwner();
 
72
   
 
73
   if ( c->baseType->hasFunction( ContainerBaseType::SelfDestructOnConquer  ) ) {
 
74
      (new DestructContainer(c))->execute(context);
 
75
      return ActionResult(0);
 
76
   }
 
77
 
 
78
   c->registerForNewOwner( newOwner );
 
79
   
 
80
   for ( ContainerBase::Cargo::iterator i = c->cargo.begin(); i != c->cargo.end(); ++i )
 
81
      if ( *i ) 
 
82
         (new ConvertContainer( *i, newOwner ))->execute(context);
 
83
   
 
84
   
 
85
   c->conquered();
 
86
   ContainerBase::anyContainerConquered(c);
 
87
   
 
88
   return ActionResult(0);
 
89
}
 
90
 
 
91
 
 
92
ActionResult ConvertContainer::undoAction( const Context& context )
 
93
{
 
94
   getContainer()->registerForNewOwner( previousOwner );
 
95
   return ActionResult(0);
 
96
}
 
97
 
 
98
ActionResult ConvertContainer::preCheck()
 
99
{
 
100
   if ( getContainer()->getOwner() != previousOwner  )
 
101
      throw ActionResult( 21204, getContainer(), "owner" );
 
102
   
 
103
   return ActionResult(0);
 
104
}
 
105
 
 
106
ActionResult ConvertContainer::postCheck()
 
107
{
 
108
   if ( getContainer()->getOwner() != newOwner  )
 
109
      throw ActionResult( 21204, getContainer(), "owner" );
 
110
   
 
111
   return ActionResult(0);
 
112
}
 
113
 
 
114
 
 
115
namespace {
 
116
   const bool r1 = registerAction<ConvertContainer> ( ActionRegistry::ConvertContainer );
 
117
}