alternate version of #adjust used by itemactions() for splitting */
| 5005 | |
| 5006 | /* alternate version of #adjust used by itemactions() for splitting */ |
| 5007 | int |
| 5008 | adjust_split(void) |
| 5009 | { |
| 5010 | struct obj *obj; |
| 5011 | cmdcount_nht splitamount = 0L; |
| 5012 | char let, dig = '\0'; |
| 5013 | |
| 5014 | /* invlet should be queued so no getobj prompting is expected */ |
| 5015 | obj = getobj("split", adjust_ok, GETOBJ_NOFLAGS); |
| 5016 | if (!obj || obj->quan < 2L || obj->otyp == GOLD_PIECE) |
| 5017 | return ECMD_FAIL; /* caller has set things up to avoid this */ |
| 5018 | |
| 5019 | if (obj->quan == 2L) { |
| 5020 | splitamount = 1L; |
| 5021 | } else { |
| 5022 | /* get first digit; doesn't wait for <return> */ |
| 5023 | dig = yn_function("Split off how many?", (char *) 0, '\0', TRUE); |
| 5024 | if (!digit(dig)) { |
| 5025 | pline1(Never_mind); |
| 5026 | return ECMD_CANCEL; |
| 5027 | } |
| 5028 | /* got first digit, get more until next non-digit (except for |
| 5029 | backspace/delete which will take away most recent digit and |
| 5030 | keep going; we expect one of ' ', '\n', or '\r') */ |
| 5031 | let = get_count(NULL, dig, 0L, &splitamount, |
| 5032 | /* yn_function() added the first digit to the |
| 5033 | prompt when recording message history; have |
| 5034 | get_count() display "Count: N" when waiting |
| 5035 | for additional digits (ordinarily that won't be |
| 5036 | shown until a second digit is entered) and also |
| 5037 | add "Count: N" to message history if more than |
| 5038 | one digit gets entered or the original N is |
| 5039 | deleted and replaced with different digit */ |
| 5040 | GC_ECHOFIRST | GC_CONDHIST); |
| 5041 | /* \033 is in quitchars[] so we need to check for it separately |
| 5042 | in order to treat it as cancel rather than as accept */ |
| 5043 | if (!let || let == '\033' || !strchr(quitchars, let)) { |
| 5044 | pline1(Never_mind); |
| 5045 | return ECMD_CANCEL; |
| 5046 | } |
| 5047 | } |
| 5048 | if (splitamount < 1L || splitamount >= obj->quan) { |
| 5049 | static const char |
| 5050 | Amount[] = "Amount to split from current stack must be"; |
| 5051 | |
| 5052 | if (splitamount < 1L) |
| 5053 | pline("%s at least 1.", Amount); |
| 5054 | else |
| 5055 | pline("%s less than %ld.", Amount, obj->quan); |
| 5056 | return ECMD_CANCEL; |
| 5057 | } |
| 5058 | |
| 5059 | /* normally a split would take place in getobj() if player supplies |
| 5060 | a count there, so doorganize_core() figures out 'splitamount' |
| 5061 | from the object; it will undo the split if player cancels while |
| 5062 | selecting the destination slot */ |
| 5063 | obj = splitobj(obj, (long) splitamount); |
| 5064 | return doorganize_core(obj); |
nothing calls this directly
no test coverage detected