File: state.h

package info (click to toggle)
crawl 2%3A0.34.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 100,188 kB
  • sloc: cpp: 363,709; ansic: 27,765; javascript: 9,516; python: 8,463; perl: 3,293; java: 3,132; xml: 2,380; makefile: 1,835; sh: 611; objc: 250; cs: 15; sed: 9; lisp: 3
file content (302 lines) | stat: -rw-r--r-- 8,661 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/**
 * @file
 * @brief Game state.
**/

#pragma once

#include <vector>

#include "activity-interrupt-type.h"
#include "command-type.h"
#include "disable-type.h"
#include "end.h"
#include "game-exit-type.h"
#include "game-type.h"
#include "player.h"

class monster;
class mon_acting;
class targeter;
struct activity_interrupt_data;

struct god_act_state
{
public:

    god_act_state();
    void reset();

    god_type which_god;
    bool     retribution;
    int      depth;
};

// Track various aspects of Crawl game state.
struct game_state
{
    vector<string> command_line_arguments;

    bool game_crashed;      // The game crashed and is now in the process of
                            // dumping crash info.
    bool crash_debug_scans_safe; // should the crash handler run various debug
                                 // scans?

    bool mouse_enabled;     // True if mouse input is currently relevant.

    bool waiting_for_command; // True when the game is waiting for a command.
    bool waiting_for_ui;     // True when waiting for input from the ui overlay
    bool terminal_resized;   // True if the term was resized and we need to
                             // take action to handle it.
    time_t last_winch;       // Time of last resize, for crash dumps.

    uint64_t seed;

    bool io_inited;         // Is curses or the equivalent initialised?
    bool need_save;         // Set to true when game can be saved, false when the game ends.
    bool save_after_turn;
    bool game_started;      // Set to true when a game has started.
    bool saving_game;       // Set to true while in save_game.
    bool updating_scores;   // Set to true while updating hiscores.
    bool parsing_rc;
#ifndef USE_TILE_LOCAL
    bool smallterm;         // The terminal has been resized under the min view
                            // size, and errors need to be displayed
#endif
    const char* no_gdb;     // reason for not running gdb

    int  seen_hups;         // Set to true if SIGHUP received.

    bool map_stat_gen;      // Set if we're generating stats on maps.
    bool map_stat_dump_disconnect; // Set if we dump disconnected maps and exit
                                   // under mapstat.
    bool obj_stat_gen;      // Set if we're generating object stats.

    string force_map;       // Set if we're forcing a specific map to generate.

    game_type type;
    game_type last_type;
    game_ended_condition last_game_exit;
    bool marked_as_won;
    bool arena_suspended;   // Set if the arena has been temporarily
                            // suspended.
    bool generating_level;

    bool dump_maps;         // Dump map Lua to stderr on fresh parse.
    bool test;              // Set if we want to run self-tests and exit.
    bool test_list;         // Show available tests and exit.
    bool script;            // Set if we want to run a Lua script and exit.
    bool build_db;          // Set if we want to rebuild the db and exit.
    bool use_des_cache;
    vector<string> tests_selected; // Tests to be run.
    vector<string> script_args;    // Arguments to scripts.

    bool throttle;

    bool bypassed_startup_menu;

    /** The maximum total memory that the user-script Lua interpreter is
     * allowed to allocate, in megabytes. This limit is enforced to prevent
     * badly-written or malicious user scripts from consuming too much memory.
     */
    uint64_t clua_max_memory_mb;

    bool show_more_prompt;  // Set to false to disable --more-- prompts.

    bool skip_autofight_check; // XXX EVIL HACK

    string sprint_map;      // Sprint map set on command line, if any.

    string map;             // Map selected in the newgame menu

    void (*terminal_resize_handler)();
    void (*terminal_resize_check)();

    bool            doing_prev_cmd_again;
    command_type    prev_cmd;
    deque<int>      prev_cmd_keys;

    command_type    repeat_cmd;
    bool            cmd_repeat_start;
    command_type    prev_repeat_cmd;
    int             prev_cmd_repeat_goal;
    bool            cmd_repeat_started_unsafe;
    int             lua_calls_no_turn;
    bool            lua_script_killed;
    bool            lua_ready_throttled;
    bool            stat_gain_prompt;

    bool            simulating_xp_gain; // is the skill menu in xp potion mode?

    bool level_annotation_shown;
    bool viewport_monster_hp;
    bool viewport_weapons;

    bool tiles_disabled; // ignored unless USE_TILE_LOCAL is defined
    bool title_screen; // ignored unless USE_TILE_LOCAL is defined

    bool invisible_targeting;

    // Area beyond which view should be darkened,  0 = disabled.
    targeter *darken_range;

    // Monsters to highlight on the screen, 0 = disabled.
    vector<monster *> *flash_monsters;

    // monsters which saw the player retreating.
    set<monster*> potential_pursuers;

    // Any changes to macros that need to be changed?
    bool unsaved_macros;

    FixedBitVector<NUM_DISABLEMENTS> disables;

    // Version of the last character save.
    int minor_version;

    // Git version of the character save. This will be empty unless the
    // character has been loaded from a previous save.
    std::string save_rcs_version;

    string default_startup_name;

    // Should flushing a nonempty key buffer error or crash? Used for tests.
    bool nonempty_buffer_flush_errors;

    string last_builder_error;
    bool last_builder_error_fatal;

protected:
    void reset_cmd_repeat();
    void reset_cmd_again();

    god_act_state         god_act;
    vector<god_act_state> god_act_stack;

    monster*          mon_act;
    vector<monster* > mon_act_stack;

public:
    game_state();

    void reset_game();

    void add_startup_error(const string &error);

    bool is_replaying_keys() const;

    bool is_repeating_cmd() const;

    void cancel_cmd_repeat(string reason = "", bool force=false);
    void cancel_cmd_again(string reason = "", bool force=false);
    void cancel_cmd_all(string reason = "");

    void cant_cmd_repeat(string reason = "");
    void cant_cmd_again(string reason = "");
    void cant_cmd_any(string reason = "");

    void zero_turns_taken();

    void check_term_size() const
    {
        if (terminal_resize_check)
            (*terminal_resize_check)();
    }

    bool     is_god_acting() const;
    bool     is_god_retribution() const;
    god_type which_god_acting() const;
    void     inc_god_acting(bool is_retribution = false);
    void     inc_god_acting(god_type which_god, bool is_retribution = false);
    void     dec_god_acting();
    void     dec_god_acting(god_type which_god);
    void     clear_god_acting();

    vector<god_act_state> other_gods_acting() const;

    bool      is_mon_acting() const;
    monster* which_mon_acting() const;
    void      inc_mon_acting(monster* mon);
    void      dec_mon_acting(monster* mon);
    void      clear_mon_acting();
    void      mon_gone(monster* mon);

    void dump();
    bool player_is_dead() const;

    bool game_is_valid_type() const;
    bool game_is_normal() const;
    bool game_is_tutorial() const;
    bool game_is_arena() const;
    bool game_is_sprint() const;
    bool game_is_hints() const;
    bool game_is_hints_tutorial() const;
    bool game_is_descent() const;

    bool game_has_random_floors() const;
    bool game_saves_prefs() const;

    bool seed_is_known() const;

    // Save subdirectory used for games such as Sprint.
    string game_type_name() const;
    string game_savedir_path() const;
    string game_type_qualifier() const;

    static string game_type_name_for(game_type gt);

    inline void mark_last_game_won()
    {
        marked_as_won = true;
    }

    friend class mon_acting;
};

#ifdef DEBUG_GLOBALS
#define crawl_state (*real_crawl_state)
#endif
extern game_state crawl_state;

class god_acting
{
public:
    god_acting(bool is_retribution = false)
        : god(you.religion)
    {
        crawl_state.inc_god_acting(god, is_retribution);
    }
    god_acting(god_type who, bool is_retribution = false)
        : god(who)
    {
        crawl_state.inc_god_acting(god, is_retribution);
    }
    ~god_acting()
    {
        crawl_state.dec_god_acting(god);
    }
private:
    god_type god;
};

class mon_acting
{
public:
    mon_acting(monster* _mon) : mon(_mon)
    {
        crawl_state.inc_mon_acting(_mon);
    }

    ~mon_acting()
    {
        // Monster might have died in the meantime.
        if (mon == crawl_state.mon_act)
            crawl_state.dec_mon_acting(mon);
    }

private:
    monster* mon;
};

bool interrupt_cmd_repeat(activity_interrupt ai,
                          const activity_interrupt_data &at);