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

Function loot_classify

src/invent.c:148–305  ·  view source on GitHub ↗

sortloot() classification; called at most once [per sort] for each object; also called by '\' command if discoveries use sortloot order */

Source from the content-addressed store, hash-verified

146/* sortloot() classification; called at most once [per sort] for each object;
147 also called by '\' command if discoveries use sortloot order */
148void
149loot_classify(Loot *sort_item, struct obj *obj)
150{
151 /* we may eventually make this a settable option to always use
152 with sortloot instead of only when the 'sortpack' option isn't
153 set; it is similar to sortpack's inv_order but items most
154 likely to be picked up are moved to the front */
155 static char def_srt_order[MAXOCLASSES] = {
156 COIN_CLASS, AMULET_CLASS, RING_CLASS, WAND_CLASS, POTION_CLASS,
157 SCROLL_CLASS, SPBOOK_CLASS, GEM_CLASS, FOOD_CLASS, TOOL_CLASS,
158 WEAPON_CLASS, ARMOR_CLASS, ROCK_CLASS, BALL_CLASS, CHAIN_CLASS, 0,
159 };
160 static char armcat[8];
161 const char *classorder;
162 const char *p;
163 int k, otyp = obj->otyp, oclass = obj->oclass;
164 boolean seen, discovered = objects[otyp].oc_name_known ? TRUE : FALSE;
165
166 /*
167 * For the value types assigned by this classification, sortloot()
168 * will put lower valued ones before higher valued ones.
169 */
170 if (!Blind)
171 observe_object(obj); /* xname(obj) does this; we want it sooner */
172 seen = obj->dknown ? TRUE : FALSE,
173 /* class order */
174 classorder = flags.sortpack ? flags.inv_order : def_srt_order;
175 p = strchr(classorder, oclass);
176 if (p)
177 k = 1 + (int) (p - classorder);
178 else
179 k = 1 + (int) strlen(classorder) + (oclass != VENOM_CLASS);
180 sort_item->orderclass = k;
181 /* subclass designation; only a few classes have subclasses
182 and the non-armor ones we use are fairly arbitrary */
183 switch (oclass) {
184 case ARMOR_CLASS:
185 if (!armcat[7]) {
186 /* one-time init; we use a different order than the subclass
187 values defined by objclass.h */
188 armcat[ARM_HELM] = 1; /* [2] */
189 armcat[ARM_GLOVES] = 2; /* [3] */
190 armcat[ARM_BOOTS] = 3; /* [4] */
191 armcat[ARM_SHIELD] = 4; /* [1] */
192 armcat[ARM_CLOAK] = 5; /* [5] */
193 armcat[ARM_SHIRT] = 6; /* [6] */
194 armcat[ARM_SUIT] = 7; /* [0] */
195 armcat[7] = 8; /* sanity protection */
196 }
197 k = objects[otyp].oc_armcat;
198 /* oc_armcat overloads oc_subtyp which is an 'schar' so guard
199 against somebody assigning something unexpected to it */
200 if (k < 0 || k >= 7)
201 k = 7;
202 k = armcat[k];
203 break;
204 case WEAPON_CLASS:
205 /* for weapons, group by ammo (arrows, bolts), launcher (bows),

Callers 2

sortloot_descrFunction · 0.85
sortloot_cmpFunction · 0.85

Calls 1

observe_objectFunction · 0.85

Tested by

no test coverage detected