Rewrite weild() to do all prompts to remove stuff in the way before actually removing anything.

This commit is contained in:
Rob Pearce 2016-07-07 12:30:04 +10:00
parent d5254e25aa
commit 6610dfed88
2 changed files with 36 additions and 22 deletions

2
io.c
View File

@ -8214,7 +8214,7 @@ char *makedesc_race(enum RACE rid, char *retbuf, int showextra, int forplayersel
break;
case F_NOTAKECRITS: if (lorelev >= PR_NOVICE) sprintf(buf, "Immune to critical hits."); break;
case F_NOPRAY: if (lorelev >= PR_BEGINNER) sprintf(buf, "Cannot worship gods."); break;
case F_NORESTHEAL: if (lorelev >= PR_NOVICE) sprintf(buf, "Cannot restore gain HP by resting."); break;
case F_NORESTHEAL: if (lorelev >= PR_NOVICE) sprintf(buf, "Cannot restore HP by resting."); break;
case F_NOSMELL: if ((lorelev >= PR_NOVICE) ) sprintf(buf, "No sense of smell."); break;
case F_NOCTURNAL: if ((lorelev >= PR_BEGINNER) && !forplayersel) sprintf(buf, "Sleeps during the day."); break;
case F_NOSPELLS: if (lorelev >= PR_NOVICE) sprintf(buf, "Cannot use magic."); break;

56
lf.c
View File

@ -28018,10 +28018,15 @@ int wear(lifeform_t *lf, object_t *o) {
int weild(lifeform_t *lf, object_t *o) {
char buf[BUFLEN];
flag_t *f;
object_t *oo;
int twohanded = B_FALSE;
object_t *oo,*unweildob[MAXBODYPARTS],*takeoffob[MAXBODYPARTS];
int twohanded = B_FALSE,i,nunweild = 0,ntakeoff = 0;
enum BODYPART weildloc,otherloc;
for (i = 0; i < MAXBODYPARTS; i++) {
unweildob[i] = NULL;
takeoffob[i] = NULL;
}
// this might impact your AR
if (isplayer(lf)) {
statdirty = B_TRUE;
@ -28190,23 +28195,20 @@ int weild(lifeform_t *lf, object_t *o) {
return B_TRUE;
}
} else {
// just unweild it
if (unweild(lf, oo)) {
// if we can't unweild old weapon, stop
return B_TRUE;
}
// don't unweild it yet, because we might still need
// to ask if the player wants to unweild something in their
// other hand. If they say NO, then we shouldn't unweild the
// primary weapon either.
unweildob[nunweild++] = oo;
}
}
// new weapon is two handed? check other hand too.
if (twohanded) {
f = hasflagval(oo->flags, F_EQUIPPED, otherloc, -1, -1, NULL);
if (f) {
if (isweapon(oo)) {
// just unweild it
if (unweild(lf, oo)) {
// if we can't unweild old weapon, stop
return B_TRUE;
}
unweildob[nunweild++] = oo;
} else { // armour
char buf2[BUFLEN];
char inwayname[BUFLEN];
@ -28226,15 +28228,9 @@ int weild(lifeform_t *lf, object_t *o) {
}
if (ch == 'y') {
if (isarmour(oo)) {
if (takeoff(lf, oo)) {
// if we can't remove it, stop.
return B_TRUE;
}
takeoffob[ntakeoff++] = oo;
} else {
if (unweild(lf, oo)) {
// if we can't remove it, stop.
return B_TRUE;
}
unweildob[nunweild++] = oo;
}
} else {
return B_TRUE;
@ -28244,6 +28240,23 @@ int weild(lifeform_t *lf, object_t *o) {
}
}
// now unweild stuff if required.
if (nunweild) {
for (i = 0; i < nunweild; i++) {
if (unweild(lf, unweildob[i])) {
// if we can't unweild old weapon, stop
return B_TRUE;
}
}
}
if (ntakeoff) {
for (i = 0; i < ntakeoff; i++) {
if (takeoff(lf, takeoffob[i])) {
// if we can't remove it, stop.
return B_TRUE;
}
}
}
// if we asked to just unweild our weapon, exit now
// with no error.
@ -28259,12 +28272,13 @@ int weild(lifeform_t *lf, object_t *o) {
return B_FALSE;
}
// touching the new weapon caused us to drop it or similar.
if (touch(lf, o)) {
taketime(lf, getactspeed(lf));
return B_TRUE;
}
// now weild this
// now weild the new weapon.
addflag(o->flags, F_EQUIPPED, weildloc, -1, -1, NULL);
if (istwohandedfor(o, lf)) {
addflag(o->flags, F_EQUIPPED, otherloc, -1, -1, NULL);