Advanced Strategic Command
actioncontainer.h
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 #ifndef actionContainerH
23 #define actionContainerH
24 
25 #include <list>
26 #include <map>
27 #include <sigc++/sigc++.h>
28 #include "loki/Functor.h"
29 #include "loki/Typelist.h"
30 
31 #include "command.h"
32 #include "commandwriter.h"
33 
35 
36  GameMap* map;
37 
38  public:
39  typedef vector<Command*> Actions;
40  private:
41  Actions actions;
42 
43  Actions::iterator currentPos;
44 
45  typedef std::map<const Command*,bool> CommandState;
46  CommandState commandState_request;
47  CommandState commandState_map;
48 
49  void initCommandState( CommandState& commandState );
50 
51  public:
52  ActionContainer( GameMap* gamemap );
53  void add( Command* action );
54 
56  bool isActive_map( const Command* action ) const ;
57 
59  bool isActive_req( const Command* action );
60 
61  void setActive( const Command* action, bool active );
62 
63  const Actions& getActions() const { return actions; };
64 
66  ActionResult undo( const Context& context );
67 
69  ActionResult redo( const Context& context );
70 
72  ActionResult rerun( const Context& context );
73 
75  void breakUndo();
76 
77  void read ( tnstream& stream );
78  void write ( tnstream& stream );
79 
80  void getCommands( AbstractCommandWriter& writer );
81 
82  void getActionDescriptions( vector<ASCString>& list );
83 
85  static sigc::signal<void,GameMap*,const Command&> postActionExecution;
86 
89  static sigc::signal<void,GameMap*,Command&> commitCommand;
90 
91  static sigc::signal<void,GameMap*> actionListChanged;
92 
94 };
95 
96 
97 
98 #endif
99 
vector< Command * > Actions
bool isActive_map(const Command *action) const
returns if the command is active in the current map's state
void add(Command *action)
The interface for all kinds of IO stream.
A Command is an action that the player initiates.
Definition: command.h:114
void setActive(const Command *action, bool active)
static sigc::signal< void, GameMap *, const Command & > postActionExecution
signales an executed Command. The command can still be undone after postActionExecution ...
const Actions & getActions() const
ActionResult undo(const Context &context)
does a single undo step
bool isActive_req(const Command *action)
returns if the command is active in the queued command list
static sigc::signal< void, GameMap * > actionListChanged
void getActionDescriptions(vector< ASCString > &list)
void breakUndo()
to be called when some modification to the map is taking place that is not recorded by undo ...
ActionResult redo(const Context &context)
does a single redo step
void read(tnstream &stream)
static sigc::signal< void, GameMap *, Command & > commitCommand
The command, which has already been executed, is finally commited and will not be undone any more Thi...
ActionContainer(GameMap *gamemap)
void getCommands(AbstractCommandWriter &writer)
ActionResult rerun(const Context &context)
reruns the necessary commands to propage take the changes done by setActive to the map ...
void write(tnstream &stream)
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182