6cd016ec51308cb1c10126f37cb0c9d777ff4731
[rocksndiamonds.git] / src / game_bd / bd_gameplay.h
1 /*
2  * Copyright (c) 2007, 2008, 2009, Czirkos Zoltan <cirix@fw.hu>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #ifndef BD_GAMEPLAY_H
18 #define BD_GAMEPLAY_H
19
20 #include <glib.h>
21
22 #include "bd_cave.h"
23
24
25 #define GAME_INT_INVALID                -100
26
27 /* prepare cave, gfx buffer */
28 #define GAME_INT_LOAD_CAVE              -73
29
30 /* show description/note of cave. */
31 #define GAME_INT_SHOW_STORY             -72
32
33 /* waiting fire button after showing the story. */
34 #define GAME_INT_SHOW_STORY_WAIT        -71
35
36 /* start uncovering */
37 #define GAME_INT_START_UNCOVER          -70
38
39 /* ...70 frames until full uncover... */
40 #define GAME_INT_UNCOVER_ALL            -1
41
42 /* normal running state. */
43 #define GAME_INT_CAVE_RUNNING           0
44
45 /* add points for remaining time */
46 #define GAME_INT_CHECK_BONUS_TIME       1
47
48 /* ...2..99 = wait and do nothing, after adding time */
49 #define GAME_INT_WAIT_BEFORE_COVER      2
50
51 /* start covering */
52 #define GAME_INT_COVER_START            100
53
54 /* ... 8 frames of cover animation */
55 #define GAME_INT_COVER_ALL              108
56
57 typedef enum _gd_gametype
58 {
59   GD_GAMETYPE_NORMAL,
60   GD_GAMETYPE_SNAPSHOT,
61   GD_GAMETYPE_TEST,
62   GD_GAMETYPE_REPLAY,
63   GD_GAMETYPE_CONTINUE_REPLAY,
64 } GdGameType;
65
66 typedef struct _gd_game
67 {
68   GdString player_name;     /* Name of player */
69   int player_score;         /* Score of player */
70   int player_lives;         /* Remaining lives of player */
71
72   GdDirection player_move;
73   boolean player_move_stick;
74   boolean player_fire;
75
76   GdGameType type;
77
78   GdCave *cave;             /* Copy of the cave. This is the iterated, changed (ruined...) one */
79   GdCave *original_cave;    /* original cave from caveset. used to record highscore */
80
81   GdReplay *replay_record;
82   GdReplay *replay_from;
83
84   GList *replays_recorded;
85
86   boolean out_of_window;   /* will be set to true, if player is not visible in the window, and we have to wait for scrolling */
87
88   int cave_num;             /* actual playing cave number */
89   int cave_score;           /* score collected in this cave */
90   int level_num;            /* actual playing level */
91   int bonus_life_flash;     /* different kind of flashing, for bonus life */
92
93   int state_counter;        /* counter used to control the game flow, rendering of caves */
94   int **element_buffer;
95   int **last_element_buffer;
96   int **dir_buffer;
97   int **gfx_buffer;         /* contains the indexes to the cells; created by *start_level, deleted by *stop_game */
98   int itercycle;
99   int itermax;
100   int itermax_last;
101   int animcycle;
102   int milliseconds_game;
103   int milliseconds_anim;
104
105   int replay_no_more_movements;
106   boolean show_story;      /* variable to remember that the story for a particular cave was already shown. */
107 } GdGame;
108
109 typedef enum _gd_game_state
110 {
111   GD_GAME_INVALID_STATE,
112   GD_GAME_SHOW_STORY,
113   GD_GAME_SHOW_STORY_WAIT,
114   GD_GAME_CAVE_LOADED,
115   GD_GAME_NOTHING,
116   GD_GAME_LABELS_CHANGED,
117   GD_GAME_TIMEOUT_NOW,      /* this signals the moment of time out */
118   GD_GAME_NO_MORE_LIVES,
119   GD_GAME_STOP,
120   GD_GAME_GAME_OVER,
121 } GdGameState;
122
123 GdCave *gd_create_snapshot(GdGame *gameplay);
124
125 void gd_game_free(GdGame *gameplay);
126 GdGame *gd_game_new(const int cave, const int level);
127 GdGame *gd_game_new_snapshot(GdCave *snapshot);
128 GdGame *gd_game_new_test(GdCave *cave, int level);
129 GdGame *gd_game_new_replay(GdCave *cave, GdReplay *replay);
130
131 void play_game_func(GdGame *game, int action);
132
133 #endif  // BD_GAMEPLAY_H