~ubuntu-branches/ubuntu/precise/widelands/precise-backports

« back to all changes in this revision

Viewing changes to src/game.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Quinson
  • Date: 2005-02-14 10:41:12 UTC
  • Revision ID: james.westby@ubuntu.com-20050214104112-6v08iux9fptxpva9
Tags: upstream-build9
Import upstream version build9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2002-2004 by the Widelands Development Team
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 *
 
18
 */
 
19
 
 
20
#ifndef __S__GAME_H
 
21
#define __S__GAME_H
 
22
 
 
23
#include "editor_game_base.h"
 
24
#include "random.h"
 
25
 
 
26
#define WLGF_SUFFIX             ".wgf"
 
27
#define WLGF_MAGIC      "WLgf"
 
28
 
 
29
/** class Game
 
30
 *
 
31
 * This class manages the entire lifetime of a game session, from creating the
 
32
 * game and setting options, selecting maps to the actual playing phase and the
 
33
 * final statistics screen(s).
 
34
 */
 
35
enum {
 
36
        gs_none = 0,    // not connected, nothing
 
37
        gs_menu,                        // in the setup menu(s)
 
38
        gs_paused,              // in-game but paused
 
39
        gs_running              // in-game
 
40
};
 
41
 
 
42
class Player;
 
43
class Interactive_Player;
 
44
class Computer_Player;
 
45
class Map_Loader;
 
46
class BaseCommand;
 
47
class PlayerCommand;
 
48
class NetGame;
 
49
 
 
50
class Game : public Editor_Game_Base {
 
51
        friend class Cmd_Queue; // this class handles the commands
 
52
   friend class Game_Game_Class_Data_Packet;
 
53
   friend class Game_Player_Info_Data_Packet;
 
54
 
 
55
public:
 
56
        Game(void);
 
57
        ~Game(void);
 
58
 
 
59
        // life cycle
 
60
   bool run_splayer_map_direct(const char* mapname, bool scenario);
 
61
        bool run_single_player ();
 
62
        bool run_multi_player (NetGame*);
 
63
   bool run_load_game(bool);
 
64
 
 
65
        void load_map (const char*);
 
66
 
 
67
        void think(void);
 
68
 
 
69
 
 
70
        bool can_start();
 
71
 
 
72
   // Cleanup for load
 
73
   void cleanup_for_load(bool t1, bool t2);
 
74
 
 
75
        // in-game logic
 
76
        inline Cmd_Queue *get_cmdqueue() { return cmdqueue; }
 
77
 
 
78
        // Start using logic_rand() for the actual gamelogic (e.g. critter).
 
79
        // Do NOT use for random events in the UI or other display code.
 
80
        // This will allow us to plug another PRNG in here for game playbacks
 
81
        // and other fancy stuff.
 
82
        inline uint logic_rand() { return rng->rand(); }
 
83
        
 
84
        void logic_rand_seed (uint seed) { rng->seed (seed); }
 
85
 
 
86
        int get_speed() const { return m_speed; }
 
87
        void set_speed(int speed);
 
88
 
 
89
        bool get_allow_cheats();
 
90
        
 
91
        virtual void player_immovable_notification (PlayerImmovable*, losegain_t);
 
92
        virtual void player_field_notification (const FCoords&, losegain_t);
 
93
 
 
94
        void enqueue_command (BaseCommand*);
 
95
 
 
96
        void send_player_command (PlayerCommand*);
 
97
 
 
98
        void send_player_bulldoze (PlayerImmovable*);
 
99
        void send_player_build (int, const Coords&, int);
 
100
        void send_player_build_flag (int, const Coords&);
 
101
        void send_player_build_road (int, Path*);
 
102
        void send_player_flagaction (Flag*, int);
 
103
        void send_player_start_stop_building (Building*);
 
104
        void send_player_enhance_building (Building*, int);
 
105
   void send_player_change_training_options(Building*, int, int);
 
106
   void send_player_drop_soldier(Building*, int);
 
107
        void send_player_change_soldier_capacity(Building*, int);
 
108
        void send_player_enemyflagaction (Flag*, int, int, int, int);
 
109
 
 
110
        // is this base a game
 
111
        inline bool is_game() { return true; }
 
112
 
 
113
   Interactive_Player* get_ipl(void) { return ipl; }
 
114
 
 
115
   // If this has a netgame, return it
 
116
   NetGame* get_netgame( void ) { return m_netgame; }
 
117
 
 
118
private:
 
119
        void init_player_controllers ();
 
120
        bool run (bool = false);
 
121
 
 
122
        Map_Loader*     m_maploader;
 
123
        
 
124
        NetGame*        m_netgame;
 
125
        
 
126
        int             m_state;
 
127
        int             m_speed;                // frametime multiplier
 
128
        
 
129
        RNG*            rng;
 
130
 
 
131
        Interactive_Player*                     ipl;
 
132
        std::vector<Computer_Player*>           cpl;
 
133
        Cmd_Queue*                              cmdqueue;
 
134
 
 
135
        int m_realtime; // the real time (including) pauses in milliseconds
 
136
};
 
137
 
 
138
#endif // __S__GAME_H