Mercurial > hg > early-roguelike
view rogue5/armor.c @ 110:5f51f7d9805f
arogue5: fix some save/restore-related crashes.
The save/restore code took the pointer intended as an argument for the
doctor() daemon and wrote it to the savefile as an int. I don't know
why it took so long to fail horribly. The problem has been avoided by
replacing the value with &player when restoring. That seems to be the
only argument ever actually used.
The code also writes only four bytes for an unsigned long; if
sizeof(long) == 8, it casts to unsigned int first. It failed to do the
cast when reading back, with the result that four bytes were read and
the other half of the number was effectively uninitialized.
It apparently works now, but the save/restore code ought still to be
regarded as decidedly unfortunate.
author | John "Elwin" Edwards |
---|---|
date | Mon, 06 Jan 2014 15:57:17 -0500 |
parents | f502bf60e6e4 |
children |
line wrap: on
line source
/* * This file contains misc functions for dealing with armor * @(#)armor.c 4.14 (Berkeley) 02/05/99 * * Rogue: Exploring the Dungeons of Doom * Copyright (C) 1980-1983, 1985, 1999 Michael Toy, Ken Arnold and Glenn Wichman * All rights reserved. * * See the file LICENSE.TXT for full copyright and licensing information. */ #include <curses.h> #include "rogue.h" /* * wear: * The player wants to wear something, so let him/her put it on. */ void wear(void) { THING *obj; char *sp; if ((obj = get_item("wear", ARMOR)) == NULL) return; if (cur_armor != NULL) { addmsg("you are already wearing some"); if (!terse) addmsg(". You'll have to take it off first"); endmsg(); after = FALSE; return; } if (obj->o_type != ARMOR) { msg("you can't wear that"); return; } waste_time(); obj->o_flags |= ISKNOW; sp = inv_name(obj, TRUE); cur_armor = obj; if (!terse) addmsg("you are now "); msg("wearing %s", sp); } /* * take_off: * Get the armor off of the players back */ void take_off(void) { THING *obj; if ((obj = cur_armor) == NULL) { after = FALSE; if (terse) msg("not wearing armor"); else msg("you aren't wearing any armor"); return; } if (!dropcheck(cur_armor)) return; cur_armor = NULL; if (terse) addmsg("was"); else addmsg("you used to be"); msg(" wearing %c) %s", obj->o_packch, inv_name(obj, TRUE)); } /* * waste_time: * Do nothing but let other things happen */ void waste_time(void) { do_daemons(BEFORE); do_fuses(BEFORE); do_daemons(AFTER); do_fuses(AFTER); }