-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdialogue.h
441 lines (396 loc) · 11.7 KB
/
dialogue.h
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
#ifndef _DIALOGUE_H
#define _DIALOGUE_H
#include "game-state/condition.h"
#include "cli/util.h"
#define MAX_DIA_LEN 500
#define MAX_QUIP_LEN 250
#define MAX_NODE_ID_LEN 50
/**********************************************
* DIALOGUE STRUCTURE DEFINITIONS *
**********************************************/
/* Tones */
typedef enum {
POSITIVE,
NEUTRAL,
NEGATIVE
} tone_t;
/* Actions */
typedef enum node_action_type
{
GIVE_ITEM,
TAKE_ITEM,
START_QUEST,
START_BATTLE,
MAKE_HOSTILE,
MOVE_ROOM,
PAUSE_MOVEMENT,
RESUME_MOVEMENT
} node_action_type_t;
/* An action flag. This allows designers to integrate actions into their
* dialogue. NOTE: This is a linked list, allowing for multiple actions.
*
* Includes:
* - action: the type of action (see above)
* - action_id: ID associated with the action (e.g. quest ID)
* - next, prev: next and previous list elements
*/
typedef struct node_action {
node_action_type_t action;
char *action_id;
struct node_action *next, *prev;
} node_action_t;
/* Edge availability status: for conditional dialogue options */
typedef enum {
EDGE_DISABLED = -1,
EDGE_UNAVAILABLE,
EDGE_AVAILABLE
} edge_avail_status;
/* Forward Declaration */
typedef struct node node_t;
/* An edge between two nodes. Each edge represents a dialogue option available
* to the player at that node.
*
* Includes:
* - quip: dialogue option text
* - from: source node
* - to: destination node
* - conditions: conditions determining an edge's availability, NULL if none
* Note: conditions come from game-state/condition.h
* - tone: tone of the dialogue at the current edge
*/
typedef struct edge {
char *quip;
node_t *from, *to;
condition_t *conditions;
tone_t tone;
} edge_t;
/* A doubly-linked list containing edges and their "availabilities."
*
* Includes:
* - availablility: -1 = DISABLED, 0 = UNAVAILABLE, 1 = AVAILABLE (see above)
* - edge: the edge
* - next, prev: next and previous list elements
*/
typedef struct edge_list {
edge_avail_status availability;
edge_t *edge;
struct edge_list *next, *prev;
} edge_list_t;
/* A stage in a conversation.
*
* Includes:
* - node_id: the node's "name"
* - npc_dialogue: what the NPC says on arriving at the node
* - num_edges: total number of edges
* - num_available_edges: number of accessible edges
* - edges: possible responses
* - actions: actions associated with the node (item, quest, battle, etc.)
* - tone: tone of the dialogue at the current node
*/
typedef struct node {
char *node_id;
char *npc_dialogue;
int num_edges;
int num_available_edges;
edge_list_t *edges;
node_action_t *actions;
tone_t tone;
} node_t;
/* A doubly-linked list containing nodes.
*
* Includes:
* - node: a node
* - next, prev: next and previous list elements
*/
typedef struct node_list {
node_t *node;
struct node_list *next, *prev;
} node_list_t;
/* A struct representing a conversation.
*
* Includes:
* - num_nodes: the total number of nodes
* - all_nodes: list of all nodes
* - all_edges: list of all edges
* - cur_node: current node (to run the conversation)
*/
typedef struct convo {
int num_nodes;
node_list_t *all_nodes;
edge_list_t *all_edges;
node_t *cur_node;
} convo_t;
/**********************************************
* DIALOGUE BUILDING FUNCTIONS *
**********************************************/
/* Returns the node corresponding to a given ID.
*
* Parameters:
* - n_lst: node list
* - node_id: node ID
*
* Returns:
* - a pointer to the corresponding node, or NULL if it does not exist
*/
node_t *get_node(node_list_t *n_lst, char *node_id);
/* To create a new convo, use: convo_new()
*/
/* Adds a new node to a conversation.
*
* Parameters:
* - c: pointer to a convo
* - node_id: a string (max. 50 chars) representing the node's "name"
* - dialogue: a string (max. 500 chars) representing the NPC's speech at the
* node
* - tone: enum representing NPC's tone at the node
*
* Returns:
* - SUCCESS on success, FAILURE if an error occurs
* - Possible errors: (1) input strings are too long (assertion error);
* (2) a node with the same ID already exists; (3) memory allocation errors;
* - tone: the tone of the dialogue; influences player hostility_level
*/
int add_node(convo_t *c, char *node_id, char *npc_dialogue, tone_t tone);
/* Adds a new edge to a conversation.
*
* Parameters:
* - c: pointer to a convo
* - quip: a string (max. 250 chars) representing the dialogue option text
* - from_id: source node's ID
* - to_id: destination node's ID
* - conditions: conditions determining the edge's availability, NULL if none
* - tone: enum representing player's tone at the edge
*
* Returns:
* - SUCCESS on success, FAILURE if an error occurs
* - Possible errors: (1) quip is too long; (2) nodes matching from_id and
* to_id could not be found; (3) memory allocation errors;
*/
int add_edge(convo_t *c, char *quip, char *from_id, char *to_id,
condition_t *conditions, tone_t tone);
/**********************************************
* ACTION FUNCTIONS *
**********************************************/
/* Create a new action, and append it to the node's action list.
*
* Parameters:
* - n: node
* - action: type of action
* - action_id: ID associated with that action, if any
*
* Returns:
* - SUCCESS if the operation suceeded, FAILURE otherwise
*/
int add_action_to_node(node_t *n, node_action_type_t action, char *action_id);
/* Adds a give item flag to a node.
*
* Parameters:
* - c: pointer to a convo
* - node_id: ID of the target node
* - item_id: ID of the item
*
* Returns:
* - SUCCESS on success, FAILURE if an error occurs
* - Possible errors: (1) node matching node_id could not be found;
*/
int add_give_item(convo_t *c, char *node_id, char *item_id);
/* Adds a take item flag to a node.
*
* Parameters:
* - c: pointer to a convo
* - node_id: ID of the target node
* - item_id: ID of the item
*
* Returns:
* - SUCCESS on success, FAILURE if an error occurs
* - Possible errors: (1) node matching node_id could not be found;
*/
int add_take_item(convo_t *c, char *node_id, char *item_id);
/* Adds a start quest flag to a node.
*
* Parameters:
* - c: pointer to a convo
* - node_id: ID of the target node
* - quest_id: ID of the quest
*
* Returns:
* - SUCCESS on success, FAILURE if an error occurs
* - Possible errors: (1) node matching node_id could not be found;
*/
int add_start_quest(convo_t *c, char *node_id, long quest_id);
/* Adds a start battle flag to a node.
*
* Note for future implementation:
* Call change_npc_hostility() in npc.c
* such that if tone is negative and NPC becomes hostile,
* battle is initiated
*
* Parameters:
* - c: pointer to a convo
* - node_id: ID of the target node
* - battle_id: ID of the battle
*
* Returns:
* - SUCCESS on success, FAILURE if an error occurs
* - Possible errors: (1) node matching node_id could not be found;
*/
int add_start_battle(convo_t *c, char *node_id, char *battle_id);
/**********************************************
* STRUCT (INIT, NEW, FREE) FUNCTIONS *
**********************************************/
/* Initializes an edge.
*
* Parameters:
* - e: an edge; must point to already allocated memory
* - quip: the dialogue option associated with the edge
* - from: source node
* - to: destination node
* - conditions: conditions determining the edge's availability, NULL if none
* Note: There can be multiple conditions (see condition.h)
* - tone: enum representing player's tone at the edge
*
* Returns:
* - SUCCESS on success, FAILURE if an error occurs
*/
int edge_init(edge_t *e, char *quip, node_t *from, node_t *to,
condition_t *conditions, tone_t tone);
/* Allocates a new edge on the heap.
*
* Parameters:
* - quip: the dialogue option associated with the edge
* - from: source node
* - to: destination node
* - conditions: conditions determining the edge's availability, NULL if none
* Note: There can be multiple conditions (see condition.h)
* - tone: enum representing player's tone at the edge
*
* Returns:
* - pointer to the new edge
*/
edge_t *edge_new(char *quip, node_t *from, node_t *to,
condition_t *conditions, tone_t tone);
/* Frees resources associated with an edge.
*
* Parameters:
* - e: the edge to be freed
*
* Returns:
* - SUCCESS if successful, FAILURE if an error occurs
*/
int edge_free(edge_t *e);
/* Initializes a node.
*
* Parameters:
* - n: a node; must point to already allocated memory
* - node_id: the node's "name"
* - npc_dialogue: a string representing the NPC's speech at the node
* - tone: enum representing NPC's tone at the node
*
* Returns:
* - SUCCESS on success, FAILURE if an error occurs
*/
int node_init(node_t *n, char *node_id, char *npc_dialogue, tone_t tone);
/* Allocates a new node on the heap.
*
* Parameters:
* - node_id: the node's "name"
* - npc_dialogue: a string representing the NPC's speech at the node
* - tone: enum representing NPC's tone at the node
*
* Returns:
* - pointer to the new node
*/
node_t *node_new(char *node_id, char *npc_dialogue, tone_t tone);
/* Frees resources associated with a node.
*
* Parameters:
* - n: the node to be freed
*
* Returns:
* - SUCCESS if successful, FAILURE if an error occurs
*/
int node_free(node_t *n);
/* Initializes a convo.
*
* Parameters:
* - c: a convo; must point to already allocated memory
*
* Returns:
* - SUCCESS on success, FAILURE if an error occurs
*/
int convo_init(convo_t *c);
/* Allocates a new convo in the heap.
*
* Returns:
* - pointer to the new convo
*/
convo_t *convo_new();
/* Frees resources associated with a convo.
*
* Parameters:
* - c: the convo to be freed
*
* Returns:
* - SUCCESS if successful, FAILURE if an error occurs
*/
int convo_free(convo_t *c);
/* Frees an edge list (using macros from common/utlist.h).
*
* Note: free_edges allows you to specify if you want to free the edges along
* with each edge list element. This prevents double freeing in certain
* cases.
*
* Parameters:
* - e_lst: the edge list to be freed
* - free_edge: true if edges should also be freed
*
* Returns:
* - SUCCESS if successful, FAILURE if an error occurs
*/
int free_edge_list(edge_list_t *e_lst, bool free_edges);
/* Frees an node list (using macros from common/utlist.h).
*
* Note: free_nodes allows you to specify if you want to free the nodes along
* with each node list element. This prevents double freeing in certain
* cases.
*
* Parameters:
* - n_lst: the node list to be freed
* - free_nodes: true if nodes should also be freed
*
* Returns:
* - SUCCESS if successful, FAILURE if an error occurs
*/
int free_node_list(node_list_t *n_lst, bool free_nodes);
/* Initializes a node action.
*
* Parameters:
* - n_a: a node action; must point to already allocated memory
* - action: type of action
* - action_id: ID associated with that action, if any
*
* Returns:
* - SUCCESS on success, FAILURE if an error occurs
*/
int node_action_init(node_action_t *n_a, node_action_type_t action,
char *action_id);
/* Allocates a new node action on the heap.
*
* Parameters:
* - action: type of action
* - action_id: ID associated with that action, if any
*
* Returns:
* - pointer to the new node action
*/
node_action_t *node_action_new(node_action_type_t action, char *action_id);
/* Frees an action list (using macros from common/utlist.h).
*
* Parameters:
* - action_lst: the action list to be freed
*
* Returns:
* - SUCCESS if successful, FAILURE if an error occurs
*/
int free_node_actions(node_action_t *action_lst);
#endif /* _DIALOGUE_H */