1 /* vi: set ts=2 shiftwidth=2 expandtab:
2  *
3  * Copyright (C) 2003-2008  Simon Baldwin and Mark J. Tilford
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of version 2 of the GNU General Public License
7  * as published by the Free Software Foundation.
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307
17  * USA
18  */
19 
20 #include <setjmp.h>
21 
22 #include "scare.h"
23 #include "scprotos.h"
24 
25 #ifndef SCARE_GAMESTATE_H
26 #define SCARE_GAMESTATE_H
27 
28 /* Room state structure, tracks rooms visited by the player. */
29 typedef struct sc_roomstate_s
30 {
31   sc_bool visited;
32 } sc_roomstate_t;
33 
34 /*
35  * Object state structure, tracks object movement, position, parent, openness
36  * for openable objects, state for stateful objects, and whether seen or not
37  * by the player.  The enumerations are values assigned to position when the
38  * object is other than just "in a room"; otherwise position contains the
39  * room number + 1.
40  */
41 enum
42 { OBJ_HIDDEN = -1,
43   OBJ_HELD_PLAYER = 0, OBJ_HELD_NPC = -200,
44   OBJ_WORN_PLAYER = -100, OBJ_WORN_NPC = -300,
45   OBJ_PART_PLAYER = -30, OBJ_PART_NPC = -30,
46   OBJ_ON_OBJECT = -20, OBJ_IN_OBJECT = -10
47 };
48 typedef struct sc_objectstate_s
49 {
50   sc_int position;
51   sc_int parent;
52   sc_int openness;
53   sc_int state;
54   sc_bool seen;
55   sc_bool unmoved;
56   sc_bool static_unmoved;
57 } sc_objectstate_t;
58 
59 /* Task state structure, tracks task done, and if task scored. */
60 typedef struct sc_taskstate_s
61 {
62   sc_bool done;
63   sc_bool scored;
64 } sc_taskstate_t;
65 
66 /* Event state structure, holds event state, and timing information. */
67 enum
68 { ES_WAITING = 1,
69   ES_RUNNING = 2, ES_AWAITING = 3, ES_FINISHED = 4, ES_PAUSED = 5
70 };
71 typedef struct sc_eventstate_s
72 {
73   sc_int state;
74   sc_int time;
75 } sc_eventstate_t;
76 
77 /*
78  * NPC state structure, tracks the NPC location and position, any parent
79  * object, whether the NPC seen, and if the NPC walks, the count of walk
80  * steps and a steps array sized to this count.
81  */
82 typedef struct sc_npcstate_s
83 {
84   sc_int location;
85   sc_int position;
86   sc_int parent;
87   sc_int walkstep_count;
88   sc_int *walksteps;
89   sc_bool seen;
90 } sc_npcstate_t;
91 
92 /*
93  * Resource tracking structure, holds the resource name, including any
94  * trailing "##" for looping sounds, its offset into the game file, and its
95  * length.  Two resources are held -- active, and requested.  The game main
96  * loop compares the two, and notifies the interface on a change.
97  */
98 typedef struct sc_resource_s
99 {
100   const sc_char *name;
101   sc_int offset;
102   sc_int length;
103 } sc_resource_t;
104 
105 /*
106  * Overall game state structure.  Arrays are malloc'ed for the appropriate
107  * number of each of the above state structures.
108  */
109 typedef struct sc_game_s
110 {
111   sc_uint magic;
112 
113   /* References to assorted helper subsystems. */
114   sc_var_setref_t vars;
115   sc_prop_setref_t bundle;
116   sc_filterref_t filter;
117   sc_memo_setref_t memento;
118   sc_debuggerref_t debugger;
119 
120   /* Undo information, also used by the debugger. */
121   struct sc_game_s *temporary;
122   struct sc_game_s *undo;
123   sc_bool undo_available;
124 
125   /* Basic game state -- rooms, objects, and so on. */
126   sc_int room_count;
127   sc_roomstate_t *rooms;
128   sc_int object_count;
129   sc_objectstate_t *objects;
130   sc_int task_count;
131   sc_taskstate_t *tasks;
132   sc_int event_count;
133   sc_eventstate_t *events;
134   sc_int npc_count;
135   sc_npcstate_t *npcs;
136   sc_int playerroom;
137   sc_int playerposition;
138   sc_int playerparent;
139   sc_int turns;
140   sc_int score;
141   sc_bool bold_room_names;
142   sc_bool verbose;
143   sc_bool notify_score_change;
144   sc_char *current_room_name;
145   sc_char *status_line;
146   sc_char *title;
147   sc_char *author;
148   sc_char *hint_text;
149 
150   /* Resource management data. */
151   sc_resource_t requested_sound;
152   sc_resource_t requested_graphic;
153   sc_bool stop_sound;
154   sc_bool sound_active;
155 
156   sc_resource_t playing_sound;
157   sc_resource_t displayed_graphic;
158 
159   /* Game running and game completed flags. */
160   sc_bool is_running;
161   sc_bool has_completed;
162 
163   /* Player's setting for waitturns; overrides the game's. */
164   sc_int waitturns;
165 
166   /* Miscellaneous library and main loop conveniences. */
167   sc_int waitcounter;
168   sc_bool has_notified;
169   sc_bool is_admin;
170   sc_bool do_again;
171   sc_int redo_sequence;
172   sc_bool do_restart;
173   sc_bool do_restore;
174   sc_bool *object_references;
175   sc_bool *multiple_references;
176   sc_bool *npc_references;
177   sc_int it_object;
178   sc_int him_npc;
179   sc_int her_npc;
180   sc_int it_npc;
181 
182   /* Longjump buffer for external requests to quit. */
183   jmp_buf quitter;
184 } sc_game_t;
185 
186 #endif
187