Introduce the concept of a `game_aux_info' structure. This is
[sgt/puzzles] / nullgame.c
... / ...
CommitLineData
1/*
2 * nullgame.c [FIXME]: Template defining the null game (in which no
3 * moves are permitted and nothing is ever drawn). This file exists
4 * solely as a basis for constructing new game definitions - it
5 * helps to have something which will compile from the word go and
6 * merely doesn't _do_ very much yet.
7 *
8 * Parts labelled FIXME actually want _removing_ (e.g. the dummy
9 * field in each of the required data structures, and this entire
10 * comment itself) when converting this source file into one
11 * describing a real game.
12 */
13
14#include <stdio.h>
15#include <stdlib.h>
16#include <string.h>
17#include <assert.h>
18#include <ctype.h>
19#include <math.h>
20
21#include "puzzles.h"
22
23enum {
24 COL_BACKGROUND,
25 NCOLOURS
26};
27
28struct game_params {
29 int FIXME;
30};
31
32struct game_state {
33 int FIXME;
34};
35
36static game_params *default_params(void)
37{
38 game_params *ret = snew(game_params);
39
40 ret->FIXME = 0;
41
42 return ret;
43}
44
45static int game_fetch_preset(int i, char **name, game_params **params)
46{
47 return FALSE;
48}
49
50static void free_params(game_params *params)
51{
52 sfree(params);
53}
54
55static game_params *dup_params(game_params *params)
56{
57 game_params *ret = snew(game_params);
58 *ret = *params; /* structure copy */
59 return ret;
60}
61
62static game_params *decode_params(char const *string)
63{
64 game_params *ret = snew(game_params);
65
66 ret->FIXME = 0;
67
68 return ret;
69}
70
71static char *encode_params(game_params *params)
72{
73 return dupstr("FIXME");
74}
75
76static config_item *game_configure(game_params *params)
77{
78 return NULL;
79}
80
81static game_params *custom_params(config_item *cfg)
82{
83 return NULL;
84}
85
86static char *validate_params(game_params *params)
87{
88 return NULL;
89}
90
91static char *new_game_seed(game_params *params, random_state *rs,
92 game_aux_info **aux)
93{
94 return dupstr("FIXME");
95}
96
97void game_free_aux_info(game_aux_info *aux)
98{
99 assert(!"Shouldn't happen");
100}
101
102static char *validate_seed(game_params *params, char *seed)
103{
104 return NULL;
105}
106
107static game_state *new_game(game_params *params, char *seed)
108{
109 game_state *state = snew(game_state);
110
111 state->FIXME = 0;
112
113 return state;
114}
115
116static game_state *dup_game(game_state *state)
117{
118 game_state *ret = snew(game_state);
119
120 ret->FIXME = state->FIXME;
121
122 return ret;
123}
124
125static void free_game(game_state *state)
126{
127 sfree(state);
128}
129
130static char *game_text_format(game_state *state)
131{
132 return NULL;
133}
134
135static game_ui *new_ui(game_state *state)
136{
137 return NULL;
138}
139
140static void free_ui(game_ui *ui)
141{
142}
143
144static game_state *make_move(game_state *from, game_ui *ui, int x, int y,
145 int button)
146{
147 return NULL;
148}
149
150/* ----------------------------------------------------------------------
151 * Drawing routines.
152 */
153
154struct game_drawstate {
155 int FIXME;
156};
157
158static void game_size(game_params *params, int *x, int *y)
159{
160 *x = *y = 200; /* FIXME */
161}
162
163static float *game_colours(frontend *fe, game_state *state, int *ncolours)
164{
165 float *ret = snewn(3 * NCOLOURS, float);
166
167 frontend_default_colour(fe, &ret[COL_BACKGROUND * 3]);
168
169 *ncolours = NCOLOURS;
170 return ret;
171}
172
173static game_drawstate *game_new_drawstate(game_state *state)
174{
175 struct game_drawstate *ds = snew(struct game_drawstate);
176
177 ds->FIXME = 0;
178
179 return ds;
180}
181
182static void game_free_drawstate(game_drawstate *ds)
183{
184 sfree(ds);
185}
186
187static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
188 game_state *state, int dir, game_ui *ui,
189 float animtime, float flashtime)
190{
191 /*
192 * The initial contents of the window are not guaranteed and
193 * can vary with front ends. To be on the safe side, all games
194 * should start by drawing a big background-colour rectangle
195 * covering the whole window.
196 */
197 draw_rect(fe, 0, 0, 200, 200, COL_BACKGROUND);
198}
199
200static float game_anim_length(game_state *oldstate, game_state *newstate,
201 int dir)
202{
203 return 0.0F;
204}
205
206static float game_flash_length(game_state *oldstate, game_state *newstate,
207 int dir)
208{
209 return 0.0F;
210}
211
212static int game_wants_statusbar(void)
213{
214 return FALSE;
215}
216
217#ifdef COMBINED
218#define thegame nullgame
219#endif
220
221const struct game thegame = {
222 "Null Game", NULL,
223 default_params,
224 game_fetch_preset,
225 decode_params,
226 encode_params,
227 free_params,
228 dup_params,
229 FALSE, game_configure, custom_params,
230 validate_params,
231 new_game_seed,
232 game_free_aux_info,
233 validate_seed,
234 new_game,
235 dup_game,
236 free_game,
237 FALSE, game_text_format,
238 new_ui,
239 free_ui,
240 make_move,
241 game_size,
242 game_colours,
243 game_new_drawstate,
244 game_free_drawstate,
245 game_redraw,
246 game_anim_length,
247 game_flash_length,
248 game_wants_statusbar,
249};