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
|
#include <world_api.h>
const char *sword_desc(struct object_t *obj, user_t *user)
{
return "It is very shiny.";
}
static void portal_init(room_id id)
{
debugf("portal room init.\n");
struct object_t *new = obj_new("weapon");
new->name = strdup("sword");
new->list = true;
new->userdata = malloc(sizeof(double));
double p = 3.14159265358979323846L;
memcpy(new->userdata, &p, sizeof(p));
room_obj_add(id, new);
}
const struct roomdata_t netcosm_world[] = {
{
"portal_room",
"Portal Room",
"You stand in the middle of a stone room. In to the east lies a portal to the world. Above it, there is a sign that reads `Alacron, 238 A.B.A.`.",
{ NONE_N, NONE_NE, "world_start", NONE_SE, NONE_S, NONE_SW, NONE_W, NONE_NW, NONE_UP, NONE_DN, "world_start", NONE_OT },
portal_init,
NULL,
NULL,
},
{
"world_start",
"Beride Town Square",
"You are in the Beride town square. All around you there are people hurrying to get along. To the north stands a statue of the late King Ajax IV. There are exits in all four directions.",
{ "beride_square_n_statue", NONE_NE, "beride_square_e", NONE_SE, "beride_square_s", NONE_SW, "beride_square_w", NONE_NW, NONE_UP, NONE_DN, NONE_IN, NONE_OT },
NULL,
NULL,
NULL,
},
{
"beride_square_n_statue",
"King Ajax IV Statue",
"Your path is blocked by an enormous bronze statue. A plaque on the pedestal reads,\n\nKing Ajax IV\n\n182 - 238 A.B.A.\n\nTo the south is the Beride Town Square.",
{ NONE_N, NONE_NE, NONE_E, NONE_SE, "world_start", NONE_SW, NONE_W, NONE_NW, NONE_UP, NONE_DN, NONE_IN, NONE_OT },
NULL,
NULL,
NULL,
},
{
"beride_square_e",
"Bottomless Pit",
"You take a step onto what seems to be solid rock, but your foot unexplicably slips through it, leading you to lose your balance and slip into the bottomless abyss...",
{ NONE_N, NONE_NE, NONE_E, NONE_SE, NONE_S, NONE_SW, NONE_W, NONE_NW, NONE_UP, NONE_DN, NONE_IN, NONE_OT },
NULL,
NULL,
NULL,
},
{
"beride_square_w",
"Bottomless Pit",
"You take a step onto what seems to be solid rock, but your foot unexplicably slips through it, leading you to lose your balance and slip into the bottomless abyss...",
{ NONE_N, NONE_NE, NONE_E, NONE_SE, NONE_S, NONE_SW, NONE_W, NONE_NW, NONE_UP, NONE_DN, NONE_IN, NONE_OT },
NULL,
NULL,
NULL,
},
{
"beride_square_s",
"Bottomless Pit",
"You take a step onto what seems to be solid rock, but your foot unexplicably slips through it, leading you to lose your balance and slip into the bottomless abyss...",
{ NONE_N, NONE_NE, NONE_E, NONE_SE, NONE_S, NONE_SW, NONE_W, NONE_NW, NONE_UP, NONE_DN, NONE_IN, NONE_OT },
NULL,
NULL,
NULL,
},
};
const size_t netcosm_world_sz = ARRAYLEN(netcosm_world);
const char *netcosm_world_name = "Alacron 0.1";
/************ OBJECT DEFINITIONS ************/
const char *shiny(struct object_t *obj, user_t *user)
{
if(user->state == STATE_ADMIN)
{
static char buf[128];
double *d = obj->userdata;
snprintf(buf, sizeof(buf), "It has %f written on it.", *d);
return buf;
}
else
return "It's kinda shiny.";
}
void weap_serialize(int fd, struct object_t *obj)
{
if(obj->userdata)
write(fd, obj->userdata, sizeof(double));
}
void weap_deserialize(int fd, struct object_t *obj)
{
obj->userdata = malloc(sizeof(double));
read(fd, obj->userdata, sizeof(double));
}
void weap_destroy(struct object_t *obj)
{
free(obj->userdata);
obj->userdata = NULL;
}
void *weap_clone(void *userdata)
{
void *ret = malloc(sizeof(double));
memcpy(ret, userdata, sizeof(double));
return ret;
}
const struct obj_class_t netcosm_obj_classes[] = {
{ "weapon",
weap_serialize,
weap_deserialize,
NULL,
NULL,
weap_clone,
weap_destroy,
shiny },
};
const size_t netcosm_obj_classes_sz = ARRAYLEN(netcosm_obj_classes);
|