-
Notifications
You must be signed in to change notification settings - Fork 0
/
object.h
86 lines (77 loc) · 2.25 KB
/
object.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
/*
* ISC License
*
* Copyright (c) 2021, Tommi Leino <namhas@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef OBJECT_H
#define OBJECT_H
#include <stddef.h>
#include <stdio.h>
struct player;
struct room;
typedef enum objtype {
OBJ_TYPE_PLAYER=0,
OBJ_TYPE_ROOM,
OBJ_TYPE_ITEM,
MAX_OBJ_TYPE
} ObjType;
#define IS_PLAYER(_x) ((_x)->type == OBJ_TYPE_PLAYER)
#define IS_ROOM(_x) ((_x)->type == OBJ_TYPE_ROOM)
#define IS_ITEM(_x) ((_x)->type == OBJ_TYPE_ITEM)
#define OPARENT(_x) (_x)->parent
#define OBJ(_x) (_x)->object
#define PPARENT(_x) OBJ(_x)->parent
#define PLAYER(_x) (_x)->v.player
#define ROOM(_x) (_x)->v.room
#define ENV(_x) OBJ(_x)->parent
#define THIS(_x) this_player(_x)
struct object {
ObjType type;
struct object *parent;
struct object *first_child;
struct object *next;
struct object *next_all;
struct object *next_hash;
char *key;
char *title;
union {
struct player *player;
struct room *room;
} v;
};
void set_title(
struct object *,
const char *);
const char *title(
struct object *);
size_t max_object_id(ObjType);
void object_save_all(
FILE *,
const char *);
struct object *object_find(
const char *);
struct object *object_create(
const char *);
void object_free(
struct object *);
void object_reparent(
struct object *,
struct object *);
struct object *object_next_child(
struct object *,
struct object *);
struct object *object_next(
struct object *);
#endif