-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroom.h
143 lines (124 loc) · 4.08 KB
/
room.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
#ifndef ROOM_H
#define ROOM_H
#include <stddef.h>
///////////////////////////////////////////////////////////////////////////////
/// ///
/// TYPES ///
/// ///
///////////////////////////////////////////////////////////////////////////////
// The names of all of the rooms on the board
enum RoomName {
NHALL = 0,
TOMB,
GUARDEDWAY,
GALLERY,
ALLEY,
BONEPIT,
ENTRANCE,
VENT,
DUNGEON,
DINING,
LIBRARY,
CRYPT,
PASSAGE,
CHAPEL,
NEST,
BATHROOM,
CANAL,
STAIRCASE,
CELLAR,
SHALL,
BALLROOM,
RESOURCE_REQUEST,
NUM_ROOMS
};
// Room type. Prefer to pass this around over room names so that we can use the
// structure of the map
typedef struct {
enum RoomName room;
struct RoomBuffer *adjacent;
} Room;
// Buffer of rooms
struct RoomBuffer {
Room **rooms; // array of rooms
size_t length; // number of rooms in the buffer.
};
#define EMPTY_BUFFER (struct RoomBuffer){ .rooms = NULL, .length = 0 }
#define MAX_ADJ 4 // the maximum number of rooms that can be adjacent to any
// given room
///////////////////////////////////////////////////////////////////////////////
/// ///
/// FUNCTION PROTOTYPES ///
/// ///
///////////////////////////////////////////////////////////////////////////////
/** @brief Add the room to the buffer, even if it is already present
*
* @param[in,out] buf : the buffer to which to add the room
* @param[in] room : the room to be added
*/
void add_with_duplicate(struct RoomBuffer *buf, Room *room);
/**
* @brief Add the room to the room buffer if it is not there already.
*
* @param buff the buffer to which to add the room.
* @room room the room to be added
*
* @note Assume that buff has enough memory allocated for an extra room.
*/
void add_no_duplicate(struct RoomBuffer *buff, Room *room);
/**
* @brief Append those rooms from src to the buffer dst that are not already
* present
*
* @note assume that dst has enough memory allocated to fit EVERY element of src
*
* @param[in,out] dst : the destination.
* @param[in] src : the buffer with entries to copy over
*/
void concat_no_duplicate(struct RoomBuffer *dst, const struct RoomBuffer src);
/**
* @brief Remove a room from the room buffer (if it is present).
*
* @param[in,out] buf : the buffer from which to remove the room
* @param[in] room : the room to remove
*/
void remove_if_present(struct RoomBuffer *buf, const Room *room);
/**
* @brief Give the index of the supplied room inside the room buffer
*
* @note This function has NO side effects
*
* @return the index of the room in the buffer if present. Otherwise, return -1
*/
int contains_room(const struct RoomBuffer buff, const Room *room);
/**
* @brief Replace dst with the same rooms and length as src.
*
* @note undefined behaviour if dst and src have overlapping memory
*
* @param[out] dst : the destination to copy into
* @param[in] src : the buffer to copy from
*/
void room_buffer_copy(struct RoomBuffer *dst, const struct RoomBuffer src);
/**
* @brief Remove any duplicates from a room buffer
*
* @param[in,out] buf : the buffer from which to remove duplicates
*/
void remove_duplicate_rooms(struct RoomBuffer *buf);
/**
* @brief Create a new room buffer that is a copy of buff.
*
* @param buff the buffer of which to create a copy
* @param arr the array to use as the underlying memory for the new buffer
*
* @return a new room buffer with the same length as and containing the same
* rooms as buff.
*
* @note The returned memory is entirely separate from that of buff (provided
* arr is entirely separate)
*/
struct RoomBuffer room_buffer_from(
const struct RoomBuffer buff,
Room **arr);
#endif // ROOM_H