From 97ef6ee2df41c5053d758bb9dccccc5fd02af6b0 Mon Sep 17 00:00:00 2001 From: "John \"Elwin\" Edwards" Date: Fri, 29 May 2015 17:34:04 -0400 Subject: [PATCH] arogue7, xrogue: fix save/restore of alchemy jugs. state.c now saves the fuse that refills alchemy jugs, using the method of numbering objects previously applied to Advanced Rogue 5. Alchemy jugs that are empty when the game is saved will continue to function after it is restored. Savefile compatibility should not be affected. --- arogue7/state.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ xrogue/state.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) diff --git a/arogue7/state.c b/arogue7/state.c index 80c6a74..4656b89 100644 --- a/arogue7/state.c +++ b/arogue7/state.c @@ -1383,6 +1383,69 @@ rs_read_sticks(int inf) return(READSTAT); } +/* Assigns a number to an alchemy jug associated with a fuse, so it can be + * found and reassociated when restoring. + * 1 - 31: slot in pack + * 32+ : on floor + * Hopefully monsters do not pick them up. + */ +int number_alchemy_jug(struct object *obj) { + struct object *tobj = NULL; + struct linked_list *item; + int i = 1; + for (item = pack; item != NULL; item = next(item), i++) { + tobj = OBJPTR(item); + if (tobj == obj && + tobj->o_type == MM && + tobj->o_which== MM_JUG) + break; + } + if (item == NULL) { + for (item = lvl_obj, i = 32; item != NULL; item = next(item), i++) { + tobj = OBJPTR(item); + if (tobj == obj && + tobj->o_type == MM && + tobj->o_which== MM_JUG) + break; + } + } + if (item == NULL) + return 0; + return i; +} + +/* Takes an alchemy jug number and tracks down the object. */ +struct object *find_alchemy_jug(int n) { + struct object *tobj; + struct linked_list *item; + + if (n <= 0) { + return NULL; + } + else if (n < 32) { + item = pack; + n -= 1; + } + else if (n < 1024) { + item = lvl_obj; + n -= 32; + } + else { + /* This is likely a bug, not 1024 actual items on the floor. */ + return NULL; + } + while (item != NULL && n > 0) { + item = next(item); + n--; + } + if (item == NULL) + return NULL; + tobj = OBJPTR(item); + if (tobj->o_type != MM || tobj->o_which != MM_JUG) + return NULL; + return tobj; +} + int rs_write_daemons(FILE *savef, struct delayed_action *d_list, int count) { @@ -1471,6 +1534,8 @@ rs_write_daemons(FILE *savef, struct delayed_action *d_list, int count) func = 36; else if (d_list[i].d_func == nobolt) func = 37; + else if (d_list[i].d_func == alchemy) + func = 38; else if (d_list[i].d_func == NULL) func = 0; else @@ -1497,6 +1562,10 @@ rs_write_daemons(FILE *savef, struct delayed_action *d_list, int count) index = find_list_ptr(player.t_pack, d_list[i].d_.varg); rs_write_int(savef,index); } + else if (d_list[i].d_func == alchemy) + { + rs_write_int(savef, number_alchemy_jug(d_list[i].d_.varg)); + } else rs_write_int(savef, d_list[i].d_.arg); @@ -1605,6 +1674,8 @@ rs_read_daemons(int inf, struct delayed_action *d_list, int count) break; case 37: d_list[i].d_func = nobolt; break; + case 38: d_list[i].d_func = alchemy; + break; case 0: case -1: default: d_list[i].d_func = NULL; @@ -1635,6 +1706,13 @@ rs_read_daemons(int inf, struct delayed_action *d_list, int count) if (d_list[i].d_.varg == NULL) d_list[i].d_type = 0; } + else if (d_list[i].d_func == alchemy) + { + rs_read_int(inf, &dummy); + d_list[i].d_.varg = find_alchemy_jug(dummy); + if (d_list[i].d_.varg == NULL) + d_list[i].d_type = 0; + } else rs_read_int(inf, &d_list[i].d_.arg); diff --git a/xrogue/state.c b/xrogue/state.c index 3bb7f8c..83a17b1 100644 --- a/xrogue/state.c +++ b/xrogue/state.c @@ -960,6 +960,69 @@ rs_read_coord(int inf, coord *c) return(READSTAT); } +/* Assigns a number to an alchemy jug associated with a fuse, so it can be + * found and reassociated when restoring. + * 1 - 31: slot in pack + * 32+ : on floor + * Hopefully monsters do not pick them up. + */ +int number_alchemy_jug(struct object *obj) { + struct object *tobj = NULL; + struct linked_list *item; + int i = 1; + for (item = pack; item != NULL; item = next(item), i++) { + tobj = OBJPTR(item); + if (tobj == obj && + tobj->o_type == MM && + tobj->o_which== MM_JUG) + break; + } + if (item == NULL) { + for (item = lvl_obj, i = 32; item != NULL; item = next(item), i++) { + tobj = OBJPTR(item); + if (tobj == obj && + tobj->o_type == MM && + tobj->o_which== MM_JUG) + break; + } + } + if (item == NULL) + return 0; + return i; +} + +/* Takes an alchemy jug number and tracks down the object. */ +struct object *find_alchemy_jug(int n) { + struct object *tobj; + struct linked_list *item; + + if (n <= 0) { + return NULL; + } + else if (n < 32) { + item = pack; + n -= 1; + } + else if (n < 1024) { + item = lvl_obj; + n -= 32; + } + else { + /* This is likely a bug, not 1024 actual items on the floor. */ + return NULL; + } + while (item != NULL && n > 0) { + item = next(item); + n--; + } + if (item == NULL) + return NULL; + tobj = OBJPTR(item); + if (tobj->o_type != MM || tobj->o_which != MM_JUG) + return NULL; + return tobj; +} + rs_write_daemons(FILE *savef, struct delayed_action *d_list,int count) { int i = 0; @@ -1045,6 +1108,8 @@ rs_write_daemons(FILE *savef, struct delayed_action *d_list,int count) func = 36; else if (d_list[i].d_func == nobolt) func = 37; + else if (d_list[i].d_func == alchemy) + func = 38; else if (d_list[i].d_func == NULL) func = 0; else @@ -1071,6 +1136,10 @@ rs_write_daemons(FILE *savef, struct delayed_action *d_list,int count) index = find_list_ptr(player.t_pack,d_list[i].d_arg.vp); rs_write_int(savef,index); } + else if (d_list[i].d_func == alchemy) + { + rs_write_int(savef, number_alchemy_jug((void *) d_list[i].d_arg.vp)); + } else rs_write_int(savef, d_list[i].d_arg.i); @@ -1192,6 +1261,8 @@ rs_read_daemons(int inf, struct delayed_action *d_list, int count) case 36: d_list[i].d_func = nocold; break; case 37: d_list[i].d_func = nobolt; + break; + case 38: d_list[i].d_func = alchemy; break; case 0: case -1: @@ -1222,6 +1293,13 @@ rs_read_daemons(int inf, struct delayed_action *d_list, int count) if (d_list[i].d_arg.vp == NULL) d_list[i].d_type = 0; } + else if (d_list[i].d_func == alchemy) + { + rs_read_int(inf, &dummy); + d_list[i].d_arg.vp = (void *) find_alchemy_jug(dummy); + if (d_list[i].d_arg.vp == NULL) + d_list[i].d_type = 0; + } else rs_read_int(inf, &d_list[i].d_arg.i);