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

Function autokey

src/lock.c:288–344  ·  view source on GitHub ↗

pick a tool for autounlock */

Source from the content-addressed store, hash-verified

286
287/* pick a tool for autounlock */
288struct obj *
289autokey(boolean opening) /* True: key, pick, or card; False: key or pick */
290{
291 struct obj *o, *key, *pick, *card, *akey, *apick, *acard;
292
293 /* mundane item or regular artifact or own role's quest artifact */
294 key = pick = card = (struct obj *) 0;
295 /* other role's quest artifact (Rogue's Key or Tourist's Credit Card) */
296 akey = apick = acard = (struct obj *) 0;
297 for (o = gi.invent; o; o = o->nobj) {
298 if (any_quest_artifact(o) && !is_quest_artifact(o)) {
299 switch (o->otyp) {
300 case SKELETON_KEY:
301 if (!akey)
302 akey = o;
303 break;
304 case LOCK_PICK:
305 if (!apick)
306 apick = o;
307 break;
308 case CREDIT_CARD:
309 if (!acard)
310 acard = o;
311 break;
312 default:
313 break;
314 }
315 } else {
316 switch (o->otyp) {
317 case SKELETON_KEY:
318 if (!key || is_magic_key(&gy.youmonst, o))
319 key = o;
320 break;
321 case LOCK_PICK:
322 if (!pick)
323 pick = o;
324 break;
325 case CREDIT_CARD:
326 if (!card)
327 card = o;
328 break;
329 default:
330 break;
331 }
332 }
333 }
334 if (!opening)
335 card = acard = 0;
336 /* only resort to other role's quest artifact if no other choice */
337 if (!key && !pick && !card)
338 key = akey;
339 if (!pick && !card)
340 pick = apick;
341 if (!card)
342 card = acard;
343 return key ? key : pick ? pick : card ? card : 0;
344}
345

Callers 2

doopen_indirFunction · 0.85
do_loot_contFunction · 0.85

Calls 2

is_quest_artifactFunction · 0.85
is_magic_keyFunction · 0.85

Tested by

no test coverage detected