-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrooms_npc.h
96 lines (85 loc) · 2.29 KB
/
rooms_npc.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
#ifndef _ROOMS_NPC_H
#define _ROOMS_NPC_H
#include "npc/npc.h"
/*
* Struct for adding and handling npcs in rooms
*
* Components:
* room_id: The name of the room
* npc_list: Hash table storing the npcs in the room
* num_of_npcs: Number of npcs in the room
*/
typedef struct npcs_in_room {
UT_hash_handle hh;
char* room_id;
npc_hash_t *npc_list;
int num_of_npcs;
} npcs_in_room_t;
/* To make the struct hashable */
typedef struct npcs_in_room npcs_in_room_hash_t;
/*
* Initializes the struct that holds the npcs inside a certain room
*
* Parameters:
* npcs_in_room: the npcs in a certain room; must point to already
* allocated memory
* room: the room that the npc will start in
*
* Returns:
* SUCCESS on success, FAILURE if an error occurs.
*/
int npcs_in_room_init(npcs_in_room_t *npcs_in_room, char *room_id);
/*
* Allocates a new npcs_in_room struct in the heap
*
* Parameters:
* room_id: The unique id of the room
*
* Returns:
* Pointer to allocated npcs_in_room struct
*/
npcs_in_room_t *npcs_in_room_new(char* room_id);
/*
* Frees resources associated with an npcs_in_room struct
* Deletes npc_list hashtable, but does not free npcs in hash table
*
* Parameters:
* npcs_in_room: The npcs_in_room struct to be freed
*
* Returns:
* SUCCESS on success, FAILURE if an error occurs.
*/
int npcs_in_room_free(npcs_in_room_t *npcs_in_room);
/*
* Returns the number of npcs in a room
*
* Parameters:
* npcs_in_room: The struct holding the npcs in the room
*
* Returns:
* The number of NPCs in the room as an int
*/
int npcs_in_room_get_number(npcs_in_room_t *npcs_in_room);
/* Adds an npc to the given npcs_in_room
*
* Parameters:
* npcs_in_room_t: Pointer to the npcs_in_room struct
* npc_t: Pointer to an NPC
*
* Returns:
* SUCCESS on success, FAILURE if an error occurs or if NPC is already in the
* respective room.
*/
int add_npc_to_room(npcs_in_room_t *npcs_in_room, npc_t *npc);
/* Removes an npc in a given npcs_in_room
*
* Parameters:
* npcs_in_room_t: Pointer to the npcs_in_room struct
* npc_t: Pointer to an NPC
*
* Returns:
* SUCCESS on success, FAILURE if an error occurs or if NPC is not
* in the room
*/
int delete_npc_from_room(npcs_in_room_t *npcs_in_room, npc_t *npc);
#endif /* _ROOMS_NPC_H */