2
* Copyright (C) 2002-2004 by the Widelands Development Team
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
#ifndef __S__CMD_QUEUE_H
21
#define __S__CMD_QUEUE_H
24
#include "filesystem.h"
25
#include "queue_cmd_ids.h"
29
class Editor_Game_Base;
30
class Widelands_Map_Map_Object_Saver;
31
class Widelands_Map_Map_Object_Loader;
33
// Define here all the possible users
34
#define SENDER_MAPOBJECT 0
35
#define SENDER_PLAYER1 1 // those are just place holder, a player can send commands with
36
#define SENDER_PLAYER2 2 // it's player number
37
#define SENDER_PLAYER3 3
38
#define SENDER_PLAYER4 4
39
#define SENDER_PLAYER5 5
40
#define SENDER_PLAYER6 6
41
#define SENDER_PLAYER7 7
42
#define SENDER_PLAYER8 8
43
#define SENDER_CMDQUEUE 100 // The Cmdqueue sends itself some action request
47
FLAGACTION_GEOLOGIST = 0, // call a geologist
50
ENEMYFLAGACTION_ATTACK = 10, // Performs an attack
52
// ---------------------- END OF CMDS ----------------------------------
55
// This is finally the command queue. It is fully widelands specific,
56
// it needs to know nearly all modules.
66
virtual ~BaseCommand ();
68
virtual void execute (Game*)=0;
70
int get_duetime() const { return duetime; }
71
void set_duetime(int t) { duetime=t; }
73
// Write these commands to a file (for savegames)
74
virtual void Write(FileWrite*, Editor_Game_Base*, Widelands_Map_Map_Object_Saver*)=0;
75
virtual void Read(FileRead*, Editor_Game_Base*, Widelands_Map_Map_Object_Loader*)=0;
77
virtual int get_id(void) = 0; // Get this command id
79
// Write commands for BaseCommand. Must be called from upper classes
80
void BaseCmdWrite(FileWrite*, Editor_Game_Base*, Widelands_Map_Map_Object_Saver*);
81
void BaseCmdRead(FileRead*, Editor_Game_Base*, Widelands_Map_Map_Object_Loader*);
86
friend class Game_Cmd_Queue_Data_Packet;
92
bool operator< (const cmditem& c) const
94
if (cmd->get_duetime()==c.cmd->get_duetime())
95
return serial > c.serial;
97
return cmd->get_duetime() > c.cmd->get_duetime();
105
void enqueue (BaseCommand*);
106
int run_queue (int interval, int* game_time_var);
108
void flush(void); // delete all commands in the queue now
112
std::priority_queue<cmditem> m_cmds;
113
unsigned long nextserial;
116
#endif // __S__CMD_QUEUE_H