MCPcopy Create free account
hub / github.com/NetHack/NetHack / same_price

Function same_price

src/shk.c:954–981  ·  view source on GitHub ↗

Decide whether two unpaid items are mergeable; caller is responsible for making sure they're unpaid and the same type of object; we check the price quoted by the shopkeeper and also that they both belong to the same shk. */

Source from the content-addressed store, hash-verified

952 quoted by the shopkeeper and also that they both belong to the same shk.
953 */
954boolean
955same_price(struct obj *obj1, struct obj *obj2)
956{
957 struct monst *shkp1, *shkp2;
958 struct bill_x *bp1 = 0, *bp2 = 0;
959 boolean are_mergable = FALSE;
960
961 /* look up the first object by finding shk whose bill it's on */
962 for (shkp1 = next_shkp(fmon, TRUE); shkp1;
963 shkp1 = next_shkp(shkp1->nmon, TRUE))
964 if ((bp1 = onbill(obj1, shkp1, TRUE)) != 0)
965 break;
966 /* second object is probably owned by same shk; if not, look harder */
967 if (shkp1 && (bp2 = onbill(obj2, shkp1, TRUE)) != 0) {
968 shkp2 = shkp1;
969 } else {
970 for (shkp2 = next_shkp(fmon, TRUE); shkp2;
971 shkp2 = next_shkp(shkp2->nmon, TRUE))
972 if ((bp2 = onbill(obj2, shkp2, TRUE)) != 0)
973 break;
974 }
975
976 if (!bp1 || !bp2)
977 impossible("same_price: object wasn't on any bill!");
978 else
979 are_mergable = (shkp1 == shkp2 && bp1->price == bp2->price);
980 return are_mergable;
981}
982
983/*
984 * Figure out how much is owed to a given shopkeeper.

Callers 1

mergableFunction · 0.85

Calls 3

next_shkpFunction · 0.85
onbillFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected