MCPcopy Index your code
hub / github.com/NetHack/NetHack / tipcontainer_checks

Function tipcontainer_checks

src/pickup.c:3953–4055  ·  view source on GitHub ↗

Perform check on box if we can tip it. Returns one of TIPCHECK_foo values. If allowempty if TRUE, return TIPCHECK_OK instead of TIPCHECK_EMPTY. */

Source from the content-addressed store, hash-verified

3951 Returns one of TIPCHECK_foo values.
3952 If allowempty if TRUE, return TIPCHECK_OK instead of TIPCHECK_EMPTY. */
3953staticfn int
3954tipcontainer_checks(
3955 struct obj *box, /* container player wants to tip */
3956 struct obj *targetbox, /* destination (used here for horn of plenty) */
3957 boolean allowempty) /* affects result when box is empty */
3958{
3959 /* undiscovered bag of tricks is acceptable as a container-to-container
3960 destination but it can't receive items; it has to be opened in
3961 preparation so apply it once before even trying to tip source box */
3962 if (targetbox && targetbox->otyp == BAG_OF_TRICKS) {
3963 int seencount = 0;
3964
3965 bagotricks(targetbox, FALSE, &seencount);
3966 return TIPCHECK_CANNOT;
3967 }
3968
3969 /* caveat: this assumes that cknown, lknown, olocked, and otrapped
3970 fields haven't been overloaded to mean something special for the
3971 non-standard "container" horn of plenty */
3972 if (!box->lknown) {
3973 box->lknown = 1;
3974 if (carried(box))
3975 update_inventory(); /* jumping the gun slightly; hope that's ok */
3976 }
3977
3978 if (box->olocked) {
3979 pline("%s is locked.", upstart(thesimpleoname(box)));
3980 return TIPCHECK_LOCKED;
3981
3982 } else if (box->otrapped) {
3983 /* we're not reaching inside but we're still handling it... */
3984 (void) chest_trap(box, HAND, FALSE);
3985 /* even if the trap fails, you've used up this turn */
3986 if (gm.multi >= 0) { /* in case we didn't become paralyzed */
3987 nomul(-1);
3988 gm.multi_reason = "tipping a container";
3989 gn.nomovemsg = "";
3990 }
3991 return TIPCHECK_TRAPPED;
3992
3993 } else if (box->otyp == BAG_OF_TRICKS || box->otyp == HORN_OF_PLENTY) {
3994 int res = TIPCHECK_OK;
3995 boolean bag = (box->otyp == BAG_OF_TRICKS);
3996 int old_spe = box->spe, seen, totseen;
3997 boolean maybeshopgoods = (!carried(box)
3998 && costly_spot(box->ox, box->oy));
3999 coordxy ox = u.ux, oy = u.uy;
4000
4001 if (targetbox
4002 && ((res = tipcontainer_checks(targetbox, NULL, TRUE))
4003 != TIPCHECK_OK))
4004 return res;
4005
4006 if (get_obj_location(box, &ox, &oy, 0))
4007 box->ox = ox, box->oy = oy;
4008
4009 if (maybeshopgoods && !box->no_charge)
4010 addtobill(box, FALSE, FALSE, TRUE);

Callers 1

tipcontainerFunction · 0.85

Calls 15

bagotricksFunction · 0.85
update_inventoryFunction · 0.85
upstartFunction · 0.85
thesimpleonameFunction · 0.85
chest_trapFunction · 0.85
nomulFunction · 0.85
costly_spotFunction · 0.85
get_obj_locationFunction · 0.85
addtobillFunction · 0.85
hornoplentyFunction · 0.85
check_unpaid_usageFunction · 0.85
subfrombillFunction · 0.85

Tested by

no test coverage detected