aboutsummaryrefslogtreecommitdiff
path: root/worlds/test.c
diff options
context:
space:
mode:
authorFranklin Wei <frankhwei536@gmail.com>2016-01-31 19:53:45 -0500
committerFranklin Wei <frankhwei536@gmail.com>2016-01-31 19:53:45 -0500
commit0730fc3924dd4e04efbe51287d1d69850404d05f (patch)
tree495d79d0dc26e39c9065c6ceb7d16b9a3e76561d /worlds/test.c
parent8405274a91e3652ee98a423608a8496ead1edc05 (diff)
downloadnetcosm-0.5.0-rc1.zip
netcosm-0.5.0-rc1.tar.gz
netcosm-0.5.0-rc1.tar.bz2
netcosm-0.5.0-rc1.tar.xz
bump version to 0.5.0-rc10.5.0-rc1
* implements objects using reference counts rather than copying * implements both room-local and global verbs * refactors the world_* functions into a separate module * numerous other changes
Diffstat (limited to 'worlds/test.c')
-rw-r--r--worlds/test.c134
1 files changed, 109 insertions, 25 deletions
diff --git a/worlds/test.c b/worlds/test.c
index 722584c..edd17ff 100644
--- a/worlds/test.c
+++ b/worlds/test.c
@@ -1,9 +1,6 @@
#include <world_api.h>
-const char *sword_desc(struct object_t *obj, user_t *user)
-{
- return "It is very shiny.";
-}
+/************ ROOM DEFINITIONS ************/
static void portal_init(room_id id)
{
@@ -17,6 +14,26 @@ static void portal_init(room_id id)
room_obj_add(id, new);
}
+static bool no_take(struct object_t *obj, user_t *user)
+{
+ (void)obj; (void)user;
+ return false;
+}
+
+static void road_sign_init(room_id id)
+{
+ struct object_t *new = obj_new("sign");
+ new->name = strdup("sign");
+ new->list = true;
+ new->userdata = strdup("The sign reads,\n\nThe Great Road\n==============\nAlagart -- 35km");
+
+ room_obj_add(id, new);
+
+ struct verb_t *verb = verb_new("read");
+ verb->name = strdup("read");
+ room_verb_add(id, verb);
+}
+
const struct roomdata_t netcosm_world[] = {
{
"portal_room",
@@ -31,8 +48,8 @@ const struct roomdata_t netcosm_world[] = {
{
"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 },
+ "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, and to the east is the Great Road. There are exits in all four directions.",
+ { "beride_square_n_statue", NONE_NE, "great_road_1", NONE_SE, "beride_square_s", NONE_SW, "beride_square_w", NONE_NW, NONE_UP, NONE_DN, NONE_IN, NONE_OT },
NULL,
NULL,
NULL,
@@ -49,10 +66,21 @@ const struct roomdata_t netcosm_world[] = {
},
{
- "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 },
+ "great_road_1",
+ "Great Road",
+ "You are at the start of a long, winding east-west road through the plains. Directly to your west is Beride.",
+ { NONE_N, NONE_NE, "great_road_2", NONE_SE, NONE_S, NONE_SW, "world_start", NONE_NW, NONE_UP, NONE_DN, NONE_IN, NONE_OT },
+ road_sign_init,
+ NULL,
+ NULL,
+ },
+
+
+ {
+ "great_road_2",
+ "Great Road",
+ "You are on a long, winding east-west road through the plains. To your west you can make out a town.",
+ { NONE_N, NONE_NE, NONE_E, NONE_SE, NONE_S, NONE_SW, "great_road_1", NONE_NW, NONE_UP, NONE_DN, NONE_IN, NONE_OT },
NULL,
NULL,
NULL,
@@ -97,40 +125,96 @@ const char *shiny(struct object_t *obj, user_t *user)
return "It's kinda shiny.";
}
-void weap_serialize(int fd, struct object_t *obj)
+static 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)
+static 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)
+static void weap_destroy(struct object_t *obj)
{
free(obj->userdata);
obj->userdata = NULL;
}
-void *weap_clone(void *userdata)
+static void sign_write(int fd, struct object_t *obj)
+{
+ write_string(fd, obj->userdata);
+}
+
+static void sign_read(int fd, struct object_t *obj)
+{
+ obj->userdata = read_string(fd);
+}
+
+static void sign_free(struct object_t *obj)
{
- void *ret = malloc(sizeof(double));
- memcpy(ret, userdata, sizeof(double));
- return ret;
+ free(obj->userdata);
+}
+
+static const char *sign_desc(struct object_t *obj, user_t *user)
+{
+ (void) user;
+ return obj->userdata;
}
const struct obj_class_t netcosm_obj_classes[] = {
- { "weapon",
- weap_serialize,
- weap_deserialize,
- NULL,
- NULL,
- weap_clone,
- weap_destroy,
- shiny },
+ {
+ "weapon",
+ weap_serialize,
+ weap_deserialize,
+ NULL,
+ NULL,
+ weap_destroy,
+ shiny
+ },
+
+ {
+ "sign",
+ sign_write, // serialize
+ sign_read, // deserialize
+ no_take, // take
+ NULL, // drop
+ sign_free, // destroy
+ sign_desc
+ },
};
const size_t netcosm_obj_classes_sz = ARRAYLEN(netcosm_obj_classes);
+
+/**************** VERB DEFINITIONS ****************/
+
+static void read_exec(struct verb_t *verb, char *args, user_t *user)
+{
+ (void) verb;
+ char *save;
+ if(!args)
+ {
+ send_msg(user, "Read what?\n");
+ return;
+ }
+ char *what = strtok_r(args, " ", &save);
+ struct object_t *obj = room_obj_get(user->room, what);
+ if(obj)
+ {
+ if(!strcmp(obj->class->class_name, "sign"))
+ send_msg(user, "%s\n", obj->class->hook_desc(obj, user));
+ else
+ send_msg(user, "You can't read that.\n");
+ }
+ else
+ send_msg(user, "I don't know what that is.\n");
+}
+
+const struct verb_class_t netcosm_verb_classes[] = {
+ { "read",
+ read_exec },
+};
+
+const size_t netcosm_verb_classes_sz = ARRAYLEN(netcosm_verb_classes);