Make extended commands return defined flags

Instead of returning 0 or 1, we'll now use ECMD_OK or ECMD_TURN.
These have the same meaning as the hardcoded numbers; ECMD_TURN
means the command uses a turn.

In future, could add eg. a flag denoting "user cancelled command"
or "command failed", and should clear eg. the cmdq.

Mostly this was simply replacing return values with the defines
in the extended commands, so hopefully I didn't break anything.
This commit is contained in:
Pasi Kallinen
2021-12-30 18:46:30 +02:00
parent 511ce70309
commit d53cd28d46
46 changed files with 821 additions and 793 deletions

View File

@@ -308,6 +308,7 @@ wield_ok(struct obj *obj)
return GETOBJ_DOWNPLAY;
}
/* the #wield command - wield a weapon */
int
dowield(void)
{
@@ -321,7 +322,7 @@ dowield(void)
if (cantwield(g.youmonst.data)) {
pline("Don't be ridiculous!");
cmdq_clear();
return 0;
return ECMD_OK;
}
/* Prompt for a new weapon */
@@ -329,14 +330,14 @@ dowield(void)
if (!(wep = getobj("wield", wield_ok, GETOBJ_PROMPT | GETOBJ_ALLOWCNT))) {
/* Cancelled */
cmdq_clear();
return 0;
return ECMD_OK;
} else if (wep == uwep) {
already_wielded:
You("are already wielding that!");
if (is_weptool(wep) || is_wet_towel(wep))
g.unweapon = FALSE; /* [see setuwep()] */
cmdq_clear();
return 0;
return ECMD_OK;
} else if (welded(uwep)) {
weldmsg(uwep);
/* previously interrupted armor removal mustn't be resumed */
@@ -345,7 +346,7 @@ dowield(void)
if (wep->o_id && wep->o_id == g.context.objsplit.child_oid)
unsplitobj(wep);
cmdq_clear();
return 0;
return ECMD_OK;
} else if (wep->o_id && wep->o_id == g.context.objsplit.child_oid) {
/* if wep is the result of supplying a count to getobj()
we don't want to split something already wielded; for
@@ -372,7 +373,7 @@ dowield(void)
uquiver->quan, simpleonames(uquiver));
switch (ynq(qbuf)) {
case 'q':
return 0;
return ECMD_OK;
case 'y':
/* leave N-1 quivered, split off 1 to wield */
wep = splitobj(uquiver, 1L);
@@ -394,14 +395,14 @@ dowield(void)
(void) Shk_Your(qbuf, uquiver); /* replace qbuf[] contents */
pline("%s%s %s readied.", qbuf,
simpleonames(uquiver), otense(uquiver, "remain"));
return 0;
return ECMD_OK;
}
/* wielding whole readied stack, so no longer quivered */
setuqwep((struct obj *) 0);
} else if (wep->owornmask & (W_ARMOR | W_ACCESSORY | W_SADDLE)) {
You("cannot wield that!");
cmdq_clear();
return 0;
return ECMD_OK;
}
wielding:
@@ -420,9 +421,10 @@ dowield(void)
setuswapwep(oldwep);
untwoweapon();
return result;
return result ? ECMD_TIME : ECMD_OK;
}
/* the #swap command - swap wielded and secondary weapons */
int
doswapweapon(void)
{
@@ -434,12 +436,12 @@ doswapweapon(void)
if (cantwield(g.youmonst.data)) {
pline("Don't be ridiculous!");
cmdq_clear();
return 0;
return ECMD_OK;
}
if (welded(uwep)) {
weldmsg(uwep);
cmdq_clear();
return 0;
return ECMD_OK;
}
/* Unwield your current secondary weapon */
@@ -465,9 +467,10 @@ doswapweapon(void)
if (u.twoweap && !can_twoweapon())
untwoweapon();
return result;
return result ? ECMD_TIME : ECMD_OK;
}
/* the #quiver command */
int
dowieldquiver(void)
{
@@ -488,7 +491,7 @@ dowieldquiver(void)
if (!newquiver) {
/* Cancelled */
return 0;
return ECMD_OK;
} else if (newquiver == &cg.zeroobj) { /* no object */
/* Explicitly nothing */
if (uquiver) {
@@ -498,7 +501,7 @@ dowieldquiver(void)
} else {
You("already have no ammunition readied!");
}
return 0;
return ECMD_OK;
} else if (newquiver->o_id == g.context.objsplit.child_oid) {
/* if newquiver is the result of supplying a count to getobj()
we don't want to split something already in the quiver;
@@ -510,23 +513,23 @@ dowieldquiver(void)
/* don't allow splitting a stack of coins into quiver */
You("can't ready only part of your gold.");
unsplitobj(newquiver);
return 0;
return ECMD_OK;
}
finish_splitting = TRUE;
} else if (newquiver == uquiver) {
already_quivered:
pline("That ammunition is already readied!");
return 0;
return ECMD_OK;
} else if (newquiver->owornmask & (W_ARMOR | W_ACCESSORY | W_SADDLE)) {
You("cannot ready that!");
return 0;
return ECMD_OK;
} else if (newquiver == uwep) {
int weld_res = !uwep->bknown;
if (welded(uwep)) {
weldmsg(uwep);
reset_remarm(); /* same as dowield() */
return weld_res;
return weld_res ? ECMD_TIME : ECMD_OK;
}
/* offer to split stack if wielding more than 1 */
if (uwep->quan > 1L && inv_cnt(FALSE) < 52 && splittable(uwep)) {
@@ -534,7 +537,7 @@ dowieldquiver(void)
uwep->quan, simpleonames(uwep), uwep->quan - 1L);
switch (ynq(qbuf)) {
case 'q':
return 0;
return ECMD_OK;
case 'y':
/* leave 1 wielded, split rest off and put into quiver */
newquiver = splitobj(uwep, uwep->quan - 1L);
@@ -556,7 +559,7 @@ dowieldquiver(void)
(void) Shk_Your(qbuf, uwep); /* replace qbuf[] contents */
pline("%s%s %s wielded.", qbuf,
simpleonames(uwep), otense(uwep, "remain"));
return 0;
return ECMD_OK;
}
/* quivering main weapon, so no longer wielding it */
setuwep((struct obj *) 0);
@@ -572,7 +575,7 @@ dowieldquiver(void)
uswapwep->quan - 1L);
switch (ynq(qbuf)) {
case 'q':
return 0;
return ECMD_OK;
case 'y':
/* leave 1 alt-wielded, split rest off and put into quiver */
newquiver = splitobj(uswapwep, uswapwep->quan - 1L);
@@ -596,7 +599,7 @@ dowieldquiver(void)
pline("%s%s %s %s.", qbuf,
simpleonames(uswapwep), otense(uswapwep, "remain"),
u.twoweap ? "wielded" : "as secondary weapon");
return 0;
return ECMD_OK;
}
/* quivering alternate weapon, so no more uswapwep */
setuswapwep((struct obj *) 0);
@@ -628,7 +631,7 @@ dowieldquiver(void)
You("%s.", are_no_longer_twoweap);
res = 1;
}
return res;
return res ? ECMD_TIME : ECMD_OK;
}
/* used for #rub and for applying pick-axe, whip, grappling hook or polearm */
@@ -774,6 +777,7 @@ set_twoweap(boolean on_off)
u.twoweap = on_off;
}
/* the #twoweapon command */
int
dotwoweapon(void)
{
@@ -782,7 +786,7 @@ dotwoweapon(void)
You("switch to your primary weapon.");
set_twoweap(FALSE); /* u.twoweap = FALSE */
update_inventory();
return 0;
return ECMD_OK;
}
/* May we use two weapons? */
@@ -791,9 +795,9 @@ dotwoweapon(void)
You("begin two-weapon combat.");
set_twoweap(TRUE); /* u.twoweap = TRUE */
update_inventory();
return (rnd(20) > ACURR(A_DEX));
return (rnd(20) > ACURR(A_DEX)) ? ECMD_TIME : ECMD_OK;
}
return 0;
return ECMD_OK;
}
/*** Functions to empty a given slot ***/