comparison xrogue/state.c @ 155:1af259ac4ed2

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.
author John "Elwin" Edwards
date Fri, 29 May 2015 17:34:04 -0400
parents 708bb2dea17c
children 9b5f1e6aa35a
comparison
equal deleted inserted replaced
154:4ef27dfe0492 155:1af259ac4ed2
956 { 956 {
957 rs_read_int(inf,&c->x); 957 rs_read_int(inf,&c->x);
958 rs_read_int(inf,&c->y); 958 rs_read_int(inf,&c->y);
959 959
960 return(READSTAT); 960 return(READSTAT);
961 }
962
963 /* Assigns a number to an alchemy jug associated with a fuse, so it can be
964 * found and reassociated when restoring.
965 * 1 - 31: slot in pack
966 * 32+ : on floor
967 * Hopefully monsters do not pick them up.
968 */
969 int number_alchemy_jug(struct object *obj) {
970 struct object *tobj = NULL;
971 struct linked_list *item;
972 int i = 1;
973 for (item = pack; item != NULL; item = next(item), i++) {
974 tobj = OBJPTR(item);
975 if (tobj == obj &&
976 tobj->o_type == MM &&
977 tobj->o_which== MM_JUG)
978 break;
979 }
980 if (item == NULL) {
981 for (item = lvl_obj, i = 32; item != NULL; item = next(item), i++) {
982 tobj = OBJPTR(item);
983 if (tobj == obj &&
984 tobj->o_type == MM &&
985 tobj->o_which== MM_JUG)
986 break;
987 }
988 }
989 if (item == NULL)
990 return 0;
991 return i;
992 }
993
994 /* Takes an alchemy jug number and tracks down the object. */
995 struct object *find_alchemy_jug(int n) {
996 struct object *tobj;
997 struct linked_list *item;
998
999 if (n <= 0) {
1000 return NULL;
1001 }
1002 else if (n < 32) {
1003 item = pack;
1004 n -= 1;
1005 }
1006 else if (n < 1024) {
1007 item = lvl_obj;
1008 n -= 32;
1009 }
1010 else {
1011 /* This is likely a bug, not 1024 actual items on the floor. */
1012 return NULL;
1013 }
1014 while (item != NULL && n > 0) {
1015 item = next(item);
1016 n--;
1017 }
1018 if (item == NULL)
1019 return NULL;
1020 tobj = OBJPTR(item);
1021 if (tobj->o_type != MM || tobj->o_which != MM_JUG)
1022 return NULL;
1023 return tobj;
961 } 1024 }
962 1025
963 rs_write_daemons(FILE *savef, struct delayed_action *d_list,int count) 1026 rs_write_daemons(FILE *savef, struct delayed_action *d_list,int count)
964 { 1027 {
965 int i = 0; 1028 int i = 0;
1043 func = 35; 1106 func = 35;
1044 else if (d_list[i].d_func == nocold) 1107 else if (d_list[i].d_func == nocold)
1045 func = 36; 1108 func = 36;
1046 else if (d_list[i].d_func == nobolt) 1109 else if (d_list[i].d_func == nobolt)
1047 func = 37; 1110 func = 37;
1111 else if (d_list[i].d_func == alchemy)
1112 func = 38;
1048 else if (d_list[i].d_func == NULL) 1113 else if (d_list[i].d_func == NULL)
1049 func = 0; 1114 func = 0;
1050 else 1115 else
1051 func = -1; 1116 func = -1;
1052 1117
1068 else if (d_list[i].d_func == cloak_charge) 1133 else if (d_list[i].d_func == cloak_charge)
1069 { 1134 {
1070 int index; 1135 int index;
1071 index = find_list_ptr(player.t_pack,d_list[i].d_arg.vp); 1136 index = find_list_ptr(player.t_pack,d_list[i].d_arg.vp);
1072 rs_write_int(savef,index); 1137 rs_write_int(savef,index);
1138 }
1139 else if (d_list[i].d_func == alchemy)
1140 {
1141 rs_write_int(savef, number_alchemy_jug((void *) d_list[i].d_arg.vp));
1073 } 1142 }
1074 else 1143 else
1075 rs_write_int(savef, d_list[i].d_arg.i); 1144 rs_write_int(savef, d_list[i].d_arg.i);
1076 1145
1077 rs_write_int(savef, d_list[i].d_time); 1146 rs_write_int(savef, d_list[i].d_time);
1190 case 35: d_list[i].d_func = nofire; 1259 case 35: d_list[i].d_func = nofire;
1191 break; 1260 break;
1192 case 36: d_list[i].d_func = nocold; 1261 case 36: d_list[i].d_func = nocold;
1193 break; 1262 break;
1194 case 37: d_list[i].d_func = nobolt; 1263 case 37: d_list[i].d_func = nobolt;
1264 break;
1265 case 38: d_list[i].d_func = alchemy;
1195 break; 1266 break;
1196 case 0: 1267 case 0:
1197 case -1: 1268 case -1:
1198 default: d_list[i].d_func = NULL; 1269 default: d_list[i].d_func = NULL;
1199 break; 1270 break;
1219 { 1290 {
1220 rs_read_int(inf, &dummy); 1291 rs_read_int(inf, &dummy);
1221 d_list[i].d_arg.vp = get_list_item(player.t_pack,dummy); 1292 d_list[i].d_arg.vp = get_list_item(player.t_pack,dummy);
1222 if (d_list[i].d_arg.vp == NULL) 1293 if (d_list[i].d_arg.vp == NULL)
1223 d_list[i].d_type = 0; 1294 d_list[i].d_type = 0;
1295 }
1296 else if (d_list[i].d_func == alchemy)
1297 {
1298 rs_read_int(inf, &dummy);
1299 d_list[i].d_arg.vp = (void *) find_alchemy_jug(dummy);
1300 if (d_list[i].d_arg.vp == NULL)
1301 d_list[i].d_type = 0;
1224 } 1302 }
1225 else 1303 else
1226 rs_read_int(inf, &d_list[i].d_arg.i); 1304 rs_read_int(inf, &d_list[i].d_arg.i);
1227 1305
1228 rs_read_int(inf, &d_list[i].d_time); 1306 rs_read_int(inf, &d_list[i].d_time);