comparison arogue7/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 b786053d2f37
children 9b5f1e6aa35a
comparison
equal deleted inserted replaced
154:4ef27dfe0492 155:1af259ac4ed2
1379 rs_read_boolean(inf, &ws_know[i]); 1379 rs_read_boolean(inf, &ws_know[i]);
1380 rs_read_new_string(inf, &ws_guess[i]); 1380 rs_read_new_string(inf, &ws_guess[i]);
1381 } 1381 }
1382 1382
1383 return(READSTAT); 1383 return(READSTAT);
1384 }
1385
1386 /* Assigns a number to an alchemy jug associated with a fuse, so it can be
1387 * found and reassociated when restoring.
1388 * 1 - 31: slot in pack
1389 * 32+ : on floor
1390 * Hopefully monsters do not pick them up.
1391 */
1392 int number_alchemy_jug(struct object *obj) {
1393 struct object *tobj = NULL;
1394 struct linked_list *item;
1395 int i = 1;
1396 for (item = pack; item != NULL; item = next(item), i++) {
1397 tobj = OBJPTR(item);
1398 if (tobj == obj &&
1399 tobj->o_type == MM &&
1400 tobj->o_which== MM_JUG)
1401 break;
1402 }
1403 if (item == NULL) {
1404 for (item = lvl_obj, i = 32; item != NULL; item = next(item), i++) {
1405 tobj = OBJPTR(item);
1406 if (tobj == obj &&
1407 tobj->o_type == MM &&
1408 tobj->o_which== MM_JUG)
1409 break;
1410 }
1411 }
1412 if (item == NULL)
1413 return 0;
1414 return i;
1415 }
1416
1417 /* Takes an alchemy jug number and tracks down the object. */
1418 struct object *find_alchemy_jug(int n) {
1419 struct object *tobj;
1420 struct linked_list *item;
1421
1422 if (n <= 0) {
1423 return NULL;
1424 }
1425 else if (n < 32) {
1426 item = pack;
1427 n -= 1;
1428 }
1429 else if (n < 1024) {
1430 item = lvl_obj;
1431 n -= 32;
1432 }
1433 else {
1434 /* This is likely a bug, not 1024 actual items on the floor. */
1435 return NULL;
1436 }
1437 while (item != NULL && n > 0) {
1438 item = next(item);
1439 n--;
1440 }
1441 if (item == NULL)
1442 return NULL;
1443 tobj = OBJPTR(item);
1444 if (tobj->o_type != MM || tobj->o_which != MM_JUG)
1445 return NULL;
1446 return tobj;
1384 } 1447 }
1385 1448
1386 int 1449 int
1387 rs_write_daemons(FILE *savef, struct delayed_action *d_list, int count) 1450 rs_write_daemons(FILE *savef, struct delayed_action *d_list, int count)
1388 { 1451 {
1469 func = 35; 1532 func = 35;
1470 else if (d_list[i].d_func == nocold) 1533 else if (d_list[i].d_func == nocold)
1471 func = 36; 1534 func = 36;
1472 else if (d_list[i].d_func == nobolt) 1535 else if (d_list[i].d_func == nobolt)
1473 func = 37; 1536 func = 37;
1537 else if (d_list[i].d_func == alchemy)
1538 func = 38;
1474 else if (d_list[i].d_func == NULL) 1539 else if (d_list[i].d_func == NULL)
1475 func = 0; 1540 func = 0;
1476 else 1541 else
1477 func = -1; 1542 func = -1;
1478 1543
1495 { 1560 {
1496 int index; 1561 int index;
1497 index = find_list_ptr(player.t_pack, d_list[i].d_.varg); 1562 index = find_list_ptr(player.t_pack, d_list[i].d_.varg);
1498 rs_write_int(savef,index); 1563 rs_write_int(savef,index);
1499 } 1564 }
1565 else if (d_list[i].d_func == alchemy)
1566 {
1567 rs_write_int(savef, number_alchemy_jug(d_list[i].d_.varg));
1568 }
1500 else 1569 else
1501 rs_write_int(savef, d_list[i].d_.arg); 1570 rs_write_int(savef, d_list[i].d_.arg);
1502 1571
1503 rs_write_int(savef, d_list[i].d_time); 1572 rs_write_int(savef, d_list[i].d_time);
1504 } 1573 }
1602 case 35: d_list[i].d_func = nofire; 1671 case 35: d_list[i].d_func = nofire;
1603 break; 1672 break;
1604 case 36: d_list[i].d_func = nocold; 1673 case 36: d_list[i].d_func = nocold;
1605 break; 1674 break;
1606 case 37: d_list[i].d_func = nobolt; 1675 case 37: d_list[i].d_func = nobolt;
1676 break;
1677 case 38: d_list[i].d_func = alchemy;
1607 break; 1678 break;
1608 case 0: 1679 case 0:
1609 case -1: 1680 case -1:
1610 default: d_list[i].d_func = NULL; 1681 default: d_list[i].d_func = NULL;
1611 break; 1682 break;
1630 else if (d_list[i].d_func == cloak_charge) 1701 else if (d_list[i].d_func == cloak_charge)
1631 { 1702 {
1632 rs_read_int(inf, &dummy); 1703 rs_read_int(inf, &dummy);
1633 d_list[i].d_.varg = get_list_item(player.t_pack,dummy); 1704 d_list[i].d_.varg = get_list_item(player.t_pack,dummy);
1634 1705
1706 if (d_list[i].d_.varg == NULL)
1707 d_list[i].d_type = 0;
1708 }
1709 else if (d_list[i].d_func == alchemy)
1710 {
1711 rs_read_int(inf, &dummy);
1712 d_list[i].d_.varg = find_alchemy_jug(dummy);
1635 if (d_list[i].d_.varg == NULL) 1713 if (d_list[i].d_.varg == NULL)
1636 d_list[i].d_type = 0; 1714 d_list[i].d_type = 0;
1637 } 1715 }
1638 else 1716 else
1639 rs_read_int(inf, &d_list[i].d_.arg); 1717 rs_read_int(inf, &d_list[i].d_.arg);