Advanced Strategic Command
command.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 "command.h"
23 #include "../util/messaginghub.h"
24 #include "../basestrm.h"
25 
27  : GameAction( gamemap ), state ( Planned )
28 {
29 }
30 
31 void Command::readData ( tnstream& stream )
32 {
33  stream.readInt();
34  state = (State)stream.readInt();
35 }
36 
37 
38 void Command::writeData ( tnstream& stream ) const
39 {
40  stream.writeInt(1);
41  stream.writeInt( (int) state );
42 }
43 
44 void Command::setState( State state )
45 {
46  this->state = state;
47 }
48 
49 
51 {
53  if ( !res.successful() )
54  return res;
55  else
56  return go ( context );
57 }
58 
59 
61 {
62  return ActionResult(0);
63 }
64 
66 {
67  if ( getState() == Finished || getState() == Run )
68  setState( SetUp );
69 
71 
72  Context c ( context, this );
73 
74  return go(c);
75 }
76 
77 vector<MapCoordinate> Command::getCoordinates() const
78 {
79  return vector<MapCoordinate>();
80 }
81 
83 {
84  return ActionResult(0);
85 }
86 
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
the command is totally done
Definition: command.h:120
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
State getState() const
Definition: command.h:125
The interface for all kinds of IO stream.
Command(GameMap *gamemap)
Definition: command.cpp:26
virtual ActionResult runAction(const Context &context)
Definition: command.cpp:50
virtual void readData(tnstream &stream)
Definition: command.cpp:31
virtual ActionResult checkExecutionPrecondition() const
Definition: command.cpp:82
virtual ActionResult undoAction(const Context &context)
Definition: command.cpp:60
void setState(State state)
Definition: command.cpp:44
virtual void writeData(tnstream &stream) const
Definition: command.cpp:38
bool successful() const
ActionResult redo(const Context &context)
Definition: command.cpp:65
virtual ActionResult go(const Context &context)=0
the command is completed this turn, but there is still something to do next turn
Definition: command.h:119
void deleteChildren()
Definition: action.cpp:159
A GameAction is an modification of something on a map.
Definition: action.h:45
virtual vector< MapCoordinate > getCoordinates() const
this is for informational purposes, so the player can see where a Command has taken place when review...
Definition: command.cpp:77
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182