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 /src/world.c | |
| 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 'src/world.c')
| -rw-r--r-- | src/world.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/world.c b/src/world.c index 256aff1..1516b4c 100644 --- a/src/world.c +++ b/src/world.c @@ -22,7 +22,6 @@ #include "multimap.h" #include "room.h" #include "world.h" -#include "userdb.h" /* processed world data */ @@ -38,10 +37,11 @@ struct room_t *room_get(room_id id) void world_save(const char *fname) { int fd = open(fname, O_CREAT | O_WRONLY, 0644); + write_uint32(fd, WORLD_MAGIC); + write(fd, &world_sz, sizeof(world_sz)); write_string(fd, world_name); - write_uint64(fd, obj_get_idcounter()); /* write all the global verbs */ void *global_verbs = world_verb_map(); @@ -77,7 +77,7 @@ void world_save(const char *fname) /* now we serialize all the objects in this room */ - size_t n_objects = room_obj_count(i); + size_t n_objects = room_obj_count_noalias(i); write(fd, &n_objects, sizeof(n_objects)); room_id id = i; @@ -87,13 +87,15 @@ void world_save(const char *fname) const struct multimap_list *iter = room_obj_iterate(id, &save, NULL); if(!iter) break; + id = ROOM_NONE; while(iter) { struct object_t *obj = iter->val; if(!obj) break; - id = ROOM_NONE; - obj_write(fd, obj); + const char *name = iter->key; + if(!strcmp(name, obj->name)) + obj_write(fd, obj); iter = iter->next; } } @@ -111,7 +113,14 @@ void world_save(const char *fname) verb_map = NULL; verb_write(fd, verb); } + + /* and now user data... */ + if(world[i].data.hook_serialize) + world[i].data.hook_serialize(i, fd); } + + write_uint64(fd, obj_get_idcounter()); + close(fd); } @@ -147,7 +156,7 @@ bool world_load(const char *fname, const struct roomdata_t *data, size_t data_sz return false; if(read_uint32(fd) != WORLD_MAGIC) - return false; + error("unknown world file format"); if(world) world_free(); @@ -167,7 +176,7 @@ bool world_load(const char *fname, const struct roomdata_t *data, size_t data_sz return false; } - obj_set_idcounter(read_uint64(fd)); + obj_set_idcounter(1); size_t n_global_verbs = read_size(fd); for(unsigned i = 0; i < n_global_verbs; ++i) @@ -208,8 +217,14 @@ bool world_load(const char *fname, const struct roomdata_t *data, size_t data_sz error("duplicate verb '%s' in room '%s'", verb->name, world[i].data.name); } + + /* user data, if any */ + if(world[i].data.hook_deserialize) + world[i].data.hook_deserialize(i, fd); } + obj_set_idcounter(read_uint64(fd)); + close(fd); return true; } |