Advanced Strategic Command
containeraction.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Advanced Strategic Command; http://www.asc-hq.de
3  Copyright (C) 1994-2010 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 "containeraction.h"
23 
24 #include "../vehicle.h"
25 #include "../gamemap.h"
26 
28  : GameAction( container->getMap() )
29 {
30  this->containerID = container->getIdentification();
31 }
32 
34  : GameAction( map )
35 {
36  this->containerID = -1;
37 }
38 
39 
40 
42 {
43  ContainerBase* veh = getMap()->getContainer( containerID );
44  if ( !veh && !dontThrow )
45  throw ActionResult(21001, "ID is " + ASCString::toString(containerID) );
46  else
47  return veh;
48 }
49 
50 const ContainerBase* ContainerAction::getContainer( bool dontThrow ) const
51 {
52  const ContainerBase* veh = getMap()->getContainer( containerID );
53  if ( !veh && !dontThrow )
54  throw ActionResult(21001, "ID is " + ASCString::toString(containerID) );
55  else
56  return veh;
57 }
58 
60 {
61  int version = stream.readInt();
62  if ( version != 1 )
63  throw tinvalidversion ( "containerID", 1, version );
64 
65  containerID = stream.readInt();
66 };
67 
68 
69 void ContainerAction::writeData ( tnstream& stream ) const
70 {
71  stream.writeInt( 1 );
72  stream.writeInt( containerID );
73 };
74 
75 void ContainerAction::setID( int id )
76 {
77  containerID = id;
78 }
79 
void writeData(tnstream &stream) const
virtual void writeInt(int i)
Writes a 32 bit signed Integer. In the stream little-endian byte order is used and a translation is p...
Definition: basestrm.cpp:363
virtual int readInt(void)
Reads a 32 bit signed Integer. In the stream little-endian byte order is used and a translation is pe...
Definition: basestrm.cpp:284
ContainerBase * getContainer(int nwid)
Definition: gamemap.cpp:1231
void setID(int id)
should usually not be called, the ID should only be set through the constructor
virtual int getIdentification() const =0
GameMap * getMap()
Definition: action.h:92
The interface for all kinds of IO stream.
static ASCString toString(int i)
converts the parameter to a String
Definition: ascstring.cpp:193
ContainerAction(ContainerBase *container)
ContainerBase * getContainer(bool dontThrow=false)
The parent class of Vehicle and Building; The name Container originates from Battle Isle...
Definition: containerbase.h:40
A GameAction is an modification of something on a map.
Definition: action.h:45
void readData(tnstream &stream)
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182