static void open_exit(dbref player, dbref loc, char *direction, char *linkto, int key) { dbref exit; char *tpr_buff, *tprp_buff; if (!Good_obj(loc)) return; if (!direction || !*direction) { notify_quiet(player, "Open where?"); return; } else if (!controls(player, loc) && !could_doit(player, loc, A_LOPEN, 0, 0)) { notify_quiet(player, "Permission denied."); return; } exit = create_obj(player, TYPE_EXIT, direction, 0); if (exit == NOTHING) return; /* Initialize everything and link it in. */ s_Exits(exit, loc); s_Next(exit, Exits(loc)); s_Exits(loc, exit); /* and we're done */ if ( !(key & SIDEEFFECT ) ) notify_quiet(player, "Opened."); /* See if we should do a link */ if (!linkto || !*linkto) return; loc = parse_linkable_room(player, linkto); if (loc != NOTHING) { /* Make sure the player passes the link lock */ if ((loc != HOME) && !could_doit(player, loc, A_LLINK, 1, 0)) { notify_quiet(player, "You can't link to there."); return; } /* Link it if the player can pay for it */ if (!payfor(player, mudconf.linkcost)) { tprp_buff = tpr_buff = alloc_lbuf("open_exit"); notify_quiet(player, safe_tprintf(tpr_buff, &tprp_buff, "You don't have enough %s to link.", mudconf.many_coins)); free_lbuf(tpr_buff); } else { s_Location(exit, loc); if ( !(key & SIDEEFFECT ) ) notify_quiet(player, "Linked."); } } }
static void link_exit(dbref player, dbref exit, dbref dest, int key) { int cost, quot; /* Make sure we can link there */ if ((dest != HOME) && ((!controls(player, dest) && !Link_ok(dest)) || !could_doit(player, dest, A_LLINK, 1, 0))) { notify_quiet(player, "Permission denied."); return; } /* Exit must be unlinked or controlled by you */ if ((Location(exit) != NOTHING) && !controls(player, exit)) { notify_quiet(player, "Permission denied."); return; } /* If exit is unlinked and mudconf 'paranoid_exit_linking' is enabled * Do not allow the exit to be linked if you do not control it */ if ( (mudconf.paranoid_exit_linking == 1) && !controls(player,exit) ) { notify_quiet(player, "Permission denied."); return; } /* handle costs */ cost = mudconf.linkcost; quot = 0; if (Owner(exit) != Owner(player)) { cost += mudconf.opencost; quot += mudconf.exit_quota; } if (!canpayfees(player, player, cost, quot, TYPE_EXIT)) return; /* Pay the owner for his loss */ /* Ok, if paranoid_exit_linking is enabled the linker does NOT own exit */ if (!(mudconf.paranoid_exit_linking)) { if (Owner(exit) != Owner(player)) { giveto(Owner(exit), mudconf.opencost, NOTHING); add_quota(Owner(exit), quot, TYPE_EXIT); s_Owner(exit, Owner(player)); s_Flags(exit, (Flags(exit) & ~(INHERIT | WIZARD)) | HALT); } } /* link has been validated and paid for, do it and tell the player */ s_Location(exit, dest); if (!(Quiet(player) || (key & SIDEEFFECT)) ) notify_quiet(player, "Linked."); }
void do_parent(dbref player, dbref cause, int key, char *tname, char *pname) { dbref thing, parent, curr; int lev; /* get victim */ init_match(player, tname, NOTYPE); match_everything(0); thing = noisy_match_result(); if (thing == NOTHING) return; /* Make sure we can do it */ if ( NoMod(thing) && !WizMod(player) ) { notify_quiet(player, "Permission denied."); return; } if (!Controls(player, thing) && !could_doit(player,thing,A_LTWINK, 0, 0)) { notify_quiet(player, "Permission denied."); return; } if ( Backstage(player) && NoBackstage(thing) ) { notify_quiet(player, "Permission denied."); return; } /* Find out what the new parent is */ if (*pname) { init_match(player, pname, Typeof(thing)); match_everything(0); parent = noisy_match_result(); if (parent == NOTHING) return; /* Make sure we have rights to set parent */ if (!Parentable(player, parent)) { notify_quiet(player, "Permission denied."); return; } /* Verify no recursive reference */ ITER_PARENTS(parent, curr, lev) { if (curr == thing) { notify_quiet(player, "You can't have yourself as a parent!"); return; } } } else {
bool can_doit(int descr, dbref player, dbref thing, const char *default_fail_msg) { dbref loc; if ((loc = getloc(player)) == NOTHING) return 0; if (OkObj(thing)) { dbref dest = Typeof(thing) == TYPE_EXIT ? (DBFETCH(thing)->sp.exit.ndest ? DBFETCH(thing)->sp.exit.dest[0] : NOTHING) : NOTHING; if (((FLAG2(player) & F2IMMOBILE) && !(FLAG2(thing) & F2IMMOBILE)) && (!OkObj(dest) || Typeof(dest) != TYPE_PROGRAM) ) { envpropqueue(descr, player, OkObj(player) ? getloc(player) : -1, thing, thing, NOTHING, "@immobile", "Immobile", 1, 1); return 0; } } if (!TMage(OWNER(player)) && Typeof(player) == TYPE_THING && (FLAGS(thing) & ZOMBIE)) { notify(player, "Sorry, but zombies can't do that."); return 0; } if (!could_doit(descr, player, thing)) { /* can't do it */ if (GETFAIL(thing)) { exec_or_notify(descr, player, thing, GETFAIL(thing), "(@Fail)"); } else if (default_fail_msg) { notify(player, default_fail_msg); } if (GETOFAIL(thing) && !Dark(player)) { parse_omessage(descr, player, loc, thing, GETOFAIL(thing), PNAME(player), "(@Ofail)"); } return 0; } else { /* can do it */ /* I moved these to the 'trigger()' function. -Akari */ /* if (GETSUCC(thing)) { exec_or_notify(descr, player, thing, GETSUCC(thing), "(@Succ)"); } if (GETOSUCC(thing) && !Dark(player)) { parse_omessage(descr, player, loc, thing, GETOSUCC(thing), NAME(player), "(@Osucc)"); } */ return 1; } }
// Call this function to see if a given object can // pass a type of lock on a target object. HS_BOOL8 CHSInterface::PassesLock(int obj, int target, HS_LOCKTYPE locktype) { int retval = 0; #ifdef PENNMUSH switch (locktype) { case LOCK_ZONE: retval = eval_lock(obj, target, Zone_Lock); break; case LOCK_USE: retval = eval_lock(obj, target, Use_Lock); break; case LOCK_NORMAL: default: retval = eval_lock(obj, target, Basic_Lock); break; } #endif #if defined(TM3) || defined(MUX) switch (locktype) { case LOCK_ZONE: retval = could_doit(obj, target, A_LCONTROL); break; case LOCK_USE: retval = could_doit(obj, target, A_LUSE); break; default: retval = could_doit(obj, target, A_LOCK); break; } #endif return retval ? true : false; }
const char * mfn_locked(MFUNARGS) { dbref who = mesg_dbref_local(player, what, perms, argv[0]); dbref obj = mesg_dbref_local(player, what, perms, argv[1]); if (who == AMBIGUOUS || who == UNKNOWN || who == NOTHING || who == HOME) ABORT_MPI("LOCKED","Match failed. (1)"); if (who == PERMDENIED) ABORT_MPI("LOCKED","Permission denied. (1)"); if (obj == AMBIGUOUS || obj == UNKNOWN || obj == NOTHING || obj == HOME) ABORT_MPI("LOCKED","Match failed. (2)"); if (obj == PERMDENIED) ABORT_MPI("LOCKED","Permission denied. (2)"); sprintf(buf, "%d", !could_doit(who, obj)); return buf; }
int can_doit(int descr, dbref player, dbref thing, const char *default_fail_msg) { dbref loc; if ((loc = getloc(player)) == NOTHING) return 0; if (!Wizard(OWNER(player)) && Typeof(player) == TYPE_THING && (FLAGS(thing) & ZOMBIE)) { notify(player, "Sorry, but zombies can't do that."); return 0; } if (!could_doit(descr, player, thing)) { /* can't do it */ if (GETFAIL(thing)) { exec_or_notify_prop(descr, player, thing, MESGPROP_FAIL, "(@Fail)"); } else if (default_fail_msg) { notify(player, default_fail_msg); } if (GETOFAIL(thing) && !Dark(player)) { parse_oprop(descr, player, loc, thing, MESGPROP_OFAIL, NAME(player), "(@Ofail)"); } return 0; } else { /* can do it */ if (GETSUCC(thing)) { exec_or_notify_prop(descr, player, thing, MESGPROP_SUCC, "(@Succ)"); } if (GETOSUCC(thing) && !Dark(player)) { parse_oprop(descr, player, loc, thing, MESGPROP_OSUCC, NAME(player), "(@Osucc)"); } return 1; } }
void do_zone(dbref player, dbref cause, int key, char *tname, char *pname) { dbref thing, zonemaster; switch( key ) { case ZONE_ADD: /* or default */ if( *tname && !*pname ) { init_match(player, tname, NOTYPE); match_everything(0); thing = noisy_match_result(); if( thing == NOTHING ) return; if( !Examinable(player, thing) ) { notify_quiet(player, "You can't do that."); return; } viewzonelist(player, thing); return; } if( !*tname || !*pname ) { notify_quiet(player, "This switch expects two arguments."); return; } init_match(player, tname, NOTYPE); match_everything(0); thing = noisy_match_result(); if( thing == NOTHING ) return; /* Make sure we can do it */ if ( (NoMod(thing) && !WizMod(player)) || (Backstage(player) && NoBackstage(thing)) ) { notify_quiet(player, "Permission denied."); return; } if (!Controls(player, thing)) { notify_quiet(player, "Permission denied."); return; } if( ZoneMaster(thing) ) { notify_quiet(player, "You can't zone a Zone Master."); return; } /* Find out what the new zone is */ init_match(player, pname, NOTYPE); match_everything(0); zonemaster = noisy_match_result(); if (zonemaster == NOTHING) return; if( !ZoneMaster(zonemaster) ) { notify_quiet(player, "That's not a Zone Master."); return; } if(!Controls(player, zonemaster) && !could_doit(player, zonemaster, A_LZONETO, 0, 0) && !could_doit(player, zonemaster, A_LZONEWIZ, 0, 0)) { notify_quiet(player, "Permission denied."); return; } if( zlist_inlist(thing, zonemaster) ) { notify_quiet(player, "Object is already in that zone."); return; } zlist_add(thing, zonemaster); zlist_add(zonemaster, thing); notify_quiet(player, "Zone Master added to object."); break; case ZONE_DELETE: if( !*tname || !*pname ) { notify_quiet(player, "This switch expects two arguments."); return; } /* Find out what the zone is */ init_match(player, pname, NOTYPE); match_everything(0); zonemaster = noisy_match_result(); if (zonemaster == NOTHING) return; init_match(player, tname, NOTYPE); match_everything(0); thing = noisy_match_result(); if( thing == NOTHING ) return; if(!zlist_inlist(thing, zonemaster)) { notify_quiet(player, "That is not one of this object's Zone Masters."); return; } /* only need to control zmo or be zonewiz to delete or control object */ if(!Controls(player, thing) && !Controls(player, zonemaster) && !could_doit(player, zonemaster, A_LZONEWIZ, 0, 0) ) { notify_quiet(player, "Permission denied."); return; } if ( (NoMod(thing) && !WizMod(player)) || (Backstage(player) && NoBackstage(thing)) ) { notify_quiet(player, "Permission denied."); return; } zlist_del(thing, zonemaster); zlist_del(zonemaster, thing); notify_quiet(player, "Deleted."); break; case ZONE_PURGE: if( !*tname || *pname) { notify_quiet(player, "This switch expects one argument."); return; } /* Find out what the zone is */ init_match(player, tname, NOTYPE); match_everything(0); thing = noisy_match_result(); if (thing == NOTHING) return; if( ZoneMaster(thing) ) { if(!Controls(player, thing) && !could_doit(player, thing, A_LZONEWIZ, 0, 0)) { notify_quiet(player, "Permission denied."); return; } if ( (NoMod(thing) && !WizMod(player)) || (Backstage(player) && NoBackstage(thing)) ) { notify_quiet(player, "Permission denied."); return; } zlist_destroy(thing); notify_quiet(player, "All objects removed from zone."); } else { if(!Controls(player, thing)) { notify_quiet(player, "Permission denied."); return; } if ( (NoMod(thing) && !WizMod(player)) || (Backstage(player) && NoBackstage(thing)) ) { notify_quiet(player, "Permission denied."); return; } zlist_destroy(thing); notify_quiet(player, "Object removed from all zones."); } break; default: notify_quiet(player, "Unknown switch!"); break; } return; }
void do_link(dbref player, dbref cause, int key, char *what, char *where) { dbref thing, room; char *buff; int nomtest; if ( (key & SIDEEFFECT) && !SideFX(player) ) { notify(player, "#-1 FUNCTION DISABLED"); return; } /* Find the thing to link */ init_match(player, what, TYPE_EXIT); match_everything(0); thing = noisy_match_result(); if (thing == NOTHING) return; nomtest = ((NoMod(thing) && !WizMod(player)) || (DePriv(player,Owner(thing),DP_MODIFY,POWER7,NOTHING) && (Owner(thing) != Owner(player))) || (Backstage(player) && NoBackstage(thing) && !Immortal(player))); /* Allow unlink if where is not specified */ if (!where || !*where) { if (!nomtest) do_unlink(player, cause, key, what); else notify(player,"Permission denied."); return; } switch (Typeof(thing)) { case TYPE_EXIT: /* Set destination */ room = parse_linkable_room(player, where); if (room != NOTHING) { if (!nomtest) link_exit(player, thing, room, key); else notify(player,"Permission denied."); } break; case TYPE_PLAYER: case TYPE_THING: /* Set home */ if (!Controls(player, thing) || nomtest) { notify_quiet(player, "Permission denied."); break; } init_match(player, where, NOTYPE); match_everything(MAT_NO_EXITS); room = noisy_match_result(); if (!Good_obj(room)) break; if (!Has_contents(room)) { notify_quiet(player, "Can't link to an exit."); break; } if (!can_set_home(player, thing, room) || !could_doit(player, room, A_LLINK, 1, 0)) { notify_quiet(player, "Permission denied."); } else if (room == HOME) { notify_quiet(player, "Can't set home to home."); } else { s_Home(thing, room); if (!(Quiet(player) || (key & SIDEEFFECT)) ) notify_quiet(player, "Home set."); } break; case TYPE_ROOM: /* Set dropto */ if (!Controls(player, thing) || nomtest) { notify_quiet(player, "Permission denied."); break; } room = parse_linkable_room(player, where); if (!Good_obj(room) && (room != HOME)) { notify_quiet(player, "Permission denied."); break; } if ((room != HOME) && !isRoom(room)) { notify_quiet(player, "That is not a room!"); } else if ((room != HOME) && ((!controls(player, room) && !Link_ok(room)) || !could_doit(player, room, A_LLINK, 1, 0))) { notify_quiet(player, "Permission denied."); } else { s_Dropto(thing, room); if (!Quiet(player)) notify_quiet(player, "Dropto set."); } break; default: STARTLOG(LOG_BUGS, "BUG", "OTYPE") buff = alloc_mbuf("do_link.LOG.badtype"); sprintf(buff, "Strange object type: object #%d = %d", thing, Typeof(thing)); log_text(buff); free_mbuf(buff); ENDLOG } }
void promote_match(dbref what, int confidence) { /* * Check for type and locks, if requested */ if (md.pref_type != NOTYPE) { if (Good_obj(what) && (Typeof(what) == md.pref_type)) { confidence |= CON_TYPE; } } if (md.check_keys) { MSTATE save_md; save_match_state(&save_md); if (Good_obj(what) && could_doit(md.player, what, A_LOCK)) { confidence |= CON_LOCK; } restore_match_state(&save_md); } /* * If nothing matched, take it */ if (md.count == 0) { md.match = what; md.confidence = confidence; md.count = 1; return; } /* * If confidence is lower, ignore */ if (confidence < md.confidence) { return; } /* * If confidence is higher, replace */ if (confidence > md.confidence) { md.match = what; md.confidence = confidence; md.count = 1; return; } /* * Equal confidence, pick randomly */ md.count++; if (Randomize(md.count) == 0) { md.match = what; } return; }
static void give_money (dbref giver, dbref recipient, int key, int amount) { dbref aowner; int cost, pcost, rcost, aflags, dpamount; char *str; /* do amount consistency check */ if (amount < 0 && ((!Builder(giver) && !HasPriv(giver,recipient,POWER_STEAL,POWER3,NOTHING)) || DePriv(giver,recipient,DP_STEAL,POWER6,NOTHING))) { notify(giver, unsafe_tprintf("You look through your pockets. Nope, no negative %s.", mudconf.many_coins)); return; } if (!amount) { notify(giver, unsafe_tprintf("You must specify a positive number of %s.", mudconf.many_coins)); return; } dpamount = 0; if (amount < 0) dpamount = DePriv(giver,NOTHING,DP_NOSTEAL,POWER7,POWER_LEVEL_NA); else dpamount = DePriv(giver,NOTHING,DP_NOGOLD,POWER7,POWER_LEVEL_NA); if (dpamount) { if (DPShift(giver)) dpamount--; dpamount = mudconf.money_limit[dpamount]; } else dpamount = -1; if (!Admin(Owner(giver))) { if ((Typeof(recipient) == TYPE_PLAYER) && (Pennies(recipient) + amount > mudconf.paylimit)) { notify(giver, unsafe_tprintf("That player doesn't need that many %s!", mudconf.many_coins)); return; } if ((Typeof(recipient) != TYPE_PLAYER) && (!could_doit(giver, recipient, A_LUSE,1))) { notify(giver, unsafe_tprintf("%s won't take your money.", Name(recipient))); return; } } str = atr_get(Owner(giver), A_PAYLIM, &aowner, &aflags); pcost = atoi(str); free_lbuf(str); if (!Immortal(Owner(giver)) && pcost) { if ((Typeof(recipient) == TYPE_PLAYER) && (amount > 0) && (Pennies(recipient) + amount > pcost)) { notify(giver, unsafe_tprintf("That player doesn't need that many %s!", mudconf.many_coins)); return; } else if (Pennies(recipient) + amount < (-pcost)) { notify(giver,"That player doesn't need that much debt!"); return; } } str = atr_get(Owner(recipient), A_RECEIVELIM, &aowner, &aflags); rcost = atoi(str); free_lbuf(str); if (!Immortal(Owner(giver)) && rcost) { if ((Typeof(recipient) == TYPE_PLAYER) && (amount > 0) && (Pennies(recipient) + amount > rcost)) { notify(giver, unsafe_tprintf("That player doesn't need that many %s!", mudconf.many_coins)); return; } else if (Pennies(recipient) + amount < (-rcost)) { notify(giver,"That player doesn't need that much debt!"); return; } } if (!Immortal(Owner(giver))) { if (dpamount >= 0) { if (amount > 0) { if ((Typeof(recipient) == TYPE_PLAYER) && (Pennies(recipient) + amount > dpamount)) { notify(giver, unsafe_tprintf("That player doesn't need that many %s!", mudconf.many_coins)); return; } else if (amount > dpamount) { notify(giver, "Permission denied."); return; } } else { if ((Typeof(recipient) == TYPE_PLAYER) && (Pennies(recipient) + amount < (-dpamount))) { notify(giver, unsafe_tprintf("That player doesn't need that many %s!", mudconf.many_coins)); return; } else if (amount < (-dpamount)) { notify(giver, "Permission denied."); return; } } } } /* try to do the give */ if (!payfor_give(giver, amount)) { notify(giver, unsafe_tprintf("You don't have that many %s to give!", mudconf.many_coins)); return; } /* Find out cost if an object */ if (Typeof(recipient) == TYPE_THING) { str = atr_pget(recipient, A_COST, &aowner, &aflags); cost = atoi(str); free_lbuf(str); /* Can't afford it? */ if (amount < cost) { notify(giver, "Feeling poor today?"); giveto(giver, amount, NOTHING); return; } /* Negative cost */ if (cost < 0) { return; } } else { cost = amount; } if (!(key & GIVE_QUIET)) { if (amount == 1) { notify(giver, unsafe_tprintf("You give a %s to %s.", mudconf.one_coin, Name(recipient))); notify_with_cause(recipient, giver, unsafe_tprintf("%s gives you a %s.", Name(giver), mudconf.one_coin)); } else { notify(giver, unsafe_tprintf("You give %d %s to %s.", amount, mudconf.many_coins, Name(recipient))); notify_with_cause(recipient, giver, unsafe_tprintf("%s gives you %d %s.", Name(giver), amount, mudconf.many_coins)); } } else { if (amount == 1) { notify(giver, unsafe_tprintf("You give a %s to %s. (quiet)", mudconf.one_coin, Name(recipient))); } else { notify(giver, unsafe_tprintf("You give %d %s to %s. (quiet)", amount, mudconf.many_coins, Name(recipient))); } } /* Report change given */ if((amount - cost) == 1) { notify(giver, unsafe_tprintf("You get 1 %s in change.", mudconf.one_coin)); giveto(giver, 1, NOTHING); } else if (amount != cost) { notify(giver, unsafe_tprintf("You get %d %s in change.", (amount - cost), mudconf.many_coins)); giveto(giver, (amount - cost), NOTHING); } if (pcost && (Pennies(Owner(recipient)) + cost > pcost)) { pcost = pcost - Pennies(Owner(recipient)); if (pcost < 0) pcost = 0; } else pcost = cost; if (!giveto(recipient, pcost, giver)) giveto(giver, cost, NOTHING); /* Transfer the money and run PAY attributes */ /* Rooms should not kick off the PAY attribute */ if ( !isRoom(giver) ) did_it(giver, recipient, A_PAY, NULL, A_OPAY, NULL, A_APAY, (char **)NULL, 0); return; }
static void give_thing (dbref giver, dbref recipient, int key, char *what) { dbref thing, loc; char *str, *sp; init_match(giver, what, TYPE_THING); match_possession(); match_me(); thing = match_result(); switch (thing) { case NOTHING: notify(giver, "You don't have that!"); return; case AMBIGUOUS: notify(giver, "I don't know which you mean!"); return; } if (thing == giver) { notify(giver, "You can't give yourself away!"); return; } if (((Typeof(thing) != TYPE_THING) && (Typeof(thing) != TYPE_PLAYER)) || !(Enter_ok(recipient) || controls(giver, recipient))) { notify(giver, "Permission denied."); return; } if ((Flags3(thing) & NOMOVE) && !Wizard(giver)) { notify(giver, "Permission denied."); return; } if (!could_doit(giver, thing, A_LGIVE,1)) { sp = str = alloc_lbuf("do_give.gfail"); safe_str((char *)"You can't give ", str, &sp); safe_str(Name(thing), str, &sp); safe_str((char *)" away.", str, &sp); *sp = '\0'; did_it(giver, thing, A_GFAIL, str, A_OGFAIL, NULL, A_AGFAIL, (char **)NULL, 0); free_lbuf(str); return; } if (!could_doit(thing, recipient, A_LRECEIVE,1)) { sp = str = alloc_lbuf("do_give.rfail"); safe_str(Name(recipient), str, &sp); safe_str((char *)" doesn't want ", str, &sp); safe_str(Name(thing), str, &sp); safe_chr('.', str, &sp); *sp = '\0'; did_it(giver, recipient, A_RFAIL, str, A_ORFAIL, NULL, A_ARFAIL, (char **)NULL, 0); free_lbuf(str); return; } loc = Location(giver); if ( !Good_obj(loc) || loc == NOTHING || loc == AMBIGUOUS || Recover(loc) || Going(loc) ) loc = giver; if (!could_doit(giver, loc, A_LGIVETO, 1)) { sp = str = alloc_lbuf("do_giveto.rfail"); safe_str((char *)"You can not give ", str, &sp); safe_str(Name(thing), str, &sp); safe_str((char *)" away at this location.", str, &sp); *sp = '\0'; notify(giver, str); free_lbuf(str); return; } move_via_generic(thing, recipient, giver, 0); divest_object(thing); if (!(key & GIVE_QUIET)) { str = alloc_lbuf("do_give.thing.ok"); strcpy(str, Name(giver)); notify_with_cause(recipient, giver, unsafe_tprintf("%s gave you %s.", str, Name(thing))); notify(giver, "Given."); notify_with_cause(thing, giver, unsafe_tprintf("%s gave you to %s.", str, Name(recipient))); free_lbuf(str); } else { notify(giver, "Given. (quiet)"); } did_it(giver, thing, A_DROP, NULL, A_ODROP, NULL, A_ADROP, (char **)NULL, 0); did_it(recipient, thing, A_SUCC, NULL, A_OSUCC, NULL, A_ASUCC, (char **)NULL, 0); }
static void promote_match(dbref what, int confidence) { #ifdef REALITY_LVLS // Check is the object is visible. // if ( Good_obj(what) && (confidence & CON_LOCAL) && !IsReal(md.player, what) && what != Location(md.player)) { return; } #endif // REALITY_LVLS // Check for type and locks, if requested. // if (md.pref_type != NOTYPE) { if ( Good_obj(what) && Typeof(what) == md.pref_type) { confidence |= CON_TYPE; } } if (md.check_keys) { MSTATE save_md; save_match_state(&save_md); if ( Good_obj(what) && could_doit(md.player, what, A_LOCK)) { confidence |= CON_LOCK; } restore_match_state(&save_md); } // If nothing matched, take it. // if (md.count == 0) { md.match = what; md.confidence = confidence; md.count = 1; return; } // If confidence is lower, ignore. // if (confidence < md.confidence) { return; } // If confidence is higher, replace. // if (confidence > md.confidence) { md.match = what; md.confidence = confidence; md.count = 1; return; } // Equal confidence, pick randomly. // md.count++; if (RandomINT32(1,md.count) == 1) { md.match = what; } return; }