diff options
| author | Franklin Wei <git@fwei.tk> | 2016-02-20 20:37:06 -0500 |
|---|---|---|
| committer | Franklin Wei <git@fwei.tk> | 2016-02-28 16:30:21 -0500 |
| commit | 2c687e77cd9ae3fd01010d7b36c8d0082bb76315 (patch) | |
| tree | b8cd58cea075a3c94cb2f1417e6eaea27865b827 /worlds | |
| parent | 02de31c48c021742c6245b711790f6d853866c36 (diff) | |
| download | netcosm-2c687e77cd9ae3fd01010d7b36c8d0082bb76315.zip netcosm-2c687e77cd9ae3fd01010d7b36c8d0082bb76315.tar.gz netcosm-2c687e77cd9ae3fd01010d7b36c8d0082bb76315.tar.bz2 netcosm-2c687e77cd9ae3fd01010d7b36c8d0082bb76315.tar.xz | |
implements aliases and other assorted features/enhancements
Diffstat (limited to 'worlds')
| -rw-r--r-- | worlds/test.c | 69 |
1 files changed, 64 insertions, 5 deletions
diff --git a/worlds/test.c b/worlds/test.c index eab1b4c..cdcaba9 100644 --- a/worlds/test.c +++ b/worlds/test.c @@ -10,8 +10,7 @@ static void deadend_init(room_id id) new->list = true; room_obj_add(id, new); new = obj_copy(new); - if(!room_obj_add(id, new)) - error("failed to add obj"); + room_obj_add(id, new); } static void ew_road_init(room_id id) @@ -28,6 +27,39 @@ static void fork_init(room_id id) struct verb_t *new = verb_new("dig"); new->name = strdup("dig"); room_verb_add(id, new); + + room_get(id)->userdata = calloc(1, sizeof(bool)); + /* flag for whether the user has already dug */ + bool *b = room_get(id)->userdata; + *b = false; +} + +static void fork_ser(room_id id, int fd) +{ + bool *b = room_get(id)->userdata; + write_bool(fd, *b); +} + +static void fork_deser(room_id id, int fd) +{ + bool *b = calloc(1, sizeof(bool)); + *b = read_bool(fd); + room_get(id)->userdata = b; +} + +static void fork_destroy(room_id id) +{ + free(room_get(id)->userdata); +} + +static void senw_init(room_id id) +{ + struct object_t *new = obj_new("/generic"); + new->name = strdup("some food"); + new->userdata = strdup("It looks like some kind of meat. Smells pretty bad."); + new->default_article = false; + room_obj_add(id, new); + room_obj_add_alias(id, new, strdup("food")); } const struct roomdata_t netcosm_world[] = { @@ -39,6 +71,9 @@ const struct roomdata_t netcosm_world[] = { deadend_init, NULL, NULL, + NULL, + NULL, + NULL, }, { @@ -49,23 +84,45 @@ const struct roomdata_t netcosm_world[] = { ew_road_init, NULL, NULL, + NULL, + NULL, + NULL, }, { "fork", "Fork", "You are at a fork of two passages, one to the northeast, and one to the southeast. The ground here seems very soft. You can also go back west.", - { NONE_N, NONE_NE, NONE_E, NONE_SE, NONE_S, NONE_SW, "ew_road", NONE_NW, NONE_UP, NONE_DN, NONE_IN, NONE_OT }, + { NONE_N, "nesw_road", NONE_E, "senw_road", NONE_S, NONE_SW, "ew_road", NONE_NW, NONE_UP, NONE_DN, NONE_IN, NONE_OT }, fork_init, NULL, NULL, + fork_ser, + fork_deser, + fork_destroy, }, { "senw_road", "SE/NW road", "You are on a southeast/northwest road.", - { NONE_N, NONE_NE, NONE_E, NONE_SE, NONE_S, NONE_SW, NONE_W, NONE_NW, NONE_UP, NONE_DN, NONE_IN, NONE_OT }, + { NONE_N, NONE_NE, NONE_E, NONE_SE, NONE_S, NONE_SW, NONE_W, "fork", NONE_UP, NONE_DN, NONE_IN, NONE_OT }, + senw_init, + NULL, + NULL, + NULL, + NULL, + NULL, + }, + + { + "nesw_road", + "NE/SW road", + "You are on a northeast/southwest road.", + { NONE_N, NONE_NE, NONE_E, NONE_SE, NONE_S, "fork", NONE_W, NONE_NW, NONE_UP, NONE_DN, NONE_IN, NONE_OT }, + NULL, + NULL, + NULL, NULL, NULL, NULL, @@ -151,8 +208,10 @@ static void dig_exec(struct verb_t *verb, char *args, user_t *user) if(!strcmp(room_get(user->room)->data.name, "Fork")) { - if(!room_obj_get(user->room, "cpu")) + bool *b = room_get(user->room)->userdata; + if(!*b) { + *b = true; struct object_t *new = obj_new("/generic"); new->name = strdup("CPU card"); new->userdata = strdup("The CPU board has a VAX chip on it. It seems to have 2 Megabytes of RAM onboard."); |