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

Function autopick

src/pickup.c:974–1003  ·  view source on GitHub ↗

* Pick from the given list using flags.pickup_types. Return the number * of items picked (not counts). Create an array that returns pointers * and counts of the items to be picked up. If the number of items * picked is zero, the pickup list is left alone. The caller of this * function must free the pickup list. */

Source from the content-addressed store, hash-verified

972 * function must free the pickup list.
973 */
974staticfn int
975autopick(
976 struct obj *olist, /* the object list */
977 int follow, /* how to follow the object list */
978 menu_item **pick_list) /* list of objects and counts to pick up */
979{
980 menu_item *pi; /* pick item */
981 struct obj *curr;
982 int n;
983 boolean check_costly = TRUE;
984
985 /* first count the number of eligible items */
986 for (n = 0, curr = olist; curr; curr = FOLLOW(curr, follow)) {
987 if (autopick_testobj(curr, check_costly))
988 ++n;
989 check_costly = FALSE; /* only need to check once per autopickup */
990 }
991
992 if (n) {
993 *pick_list = pi = (menu_item *) alloc(sizeof (menu_item) * n);
994 for (n = 0, curr = olist; curr; curr = FOLLOW(curr, follow)) {
995 if (autopick_testobj(curr, FALSE)) {
996 pi[n].item.a_obj = curr;
997 pi[n].count = curr->quan;
998 n++;
999 }
1000 }
1001 }
1002 return n;
1003}
1004
1005/*
1006 * Put up a menu using the given object list. Only those objects on the

Callers 1

pickupFunction · 0.85

Calls 2

autopick_testobjFunction · 0.85
allocFunction · 0.70

Tested by

no test coverage detected