/** Returns if there is any word in the trie that equals to the given word after modifying exactly one character */
 bool search(string word) {
     return isMagical(root,word);
 }
Exemple #2
0
void Trap::disarm() {
  //Abort if trap is hidden
  if(isHidden()) {
    eng.log->addMsg(msgDisarmNoTrap);
    Renderer::drawMapAndInterface();
    return;
  }

  //Spider webs are automatically destroyed if wielding machete
  bool isAutoSucceed = false;
  if(getTrapType() == trap_spiderWeb) {
    Item* item = eng.player->getInv().getItemInSlot(SlotId::wielded);
    if(item != NULL) {
      isAutoSucceed = item->getData().id == ItemId::machete;
    }
  }

  const bool IS_OCCULTIST   = PlayerBon::getBg() == Bg::occultist;

  if(isMagical() && IS_OCCULTIST == false) {
    eng.log->addMsg("I do not know how to dispel magic traps.");
    return;
  }

  vector<PropId> props;
  eng.player->getPropHandler().getAllActivePropIds(props);

  const bool IS_BLESSED =
    find(props.begin(), props.end(), propBlessed) != props.end();
  const bool IS_CURSED =
    find(props.begin(), props.end(), propCursed)  != props.end();

  int       disarmNumerator     = 5;
  const int DISARM_DENOMINATOR  = 10;

  if(IS_BLESSED)  disarmNumerator += 3;
  if(IS_CURSED)   disarmNumerator -= 3;

  constrInRange(1, disarmNumerator, DISARM_DENOMINATOR - 1);

  const bool IS_DISARMED =
    Rnd::fraction(disarmNumerator, DISARM_DENOMINATOR) || isAutoSucceed;
  if(IS_DISARMED) {
    eng.log->addMsg(specificTrap_->getDisarmMsg());
  } else {
    eng.log->addMsg(specificTrap_->getDisarmFailMsg());

    Renderer::drawMapAndInterface();
    const int TRIGGER_ONE_IN_N = IS_BLESSED ? 9 : IS_CURSED ? 2 : 4;
    if(Rnd::oneIn(TRIGGER_ONE_IN_N)) {
      if(getTrapType() == trap_spiderWeb) {
        eng.player->pos = pos_;
      }
      triggerTrap(*eng.player);
    }
  }
  eng.gameTime->actorDidAct();

  if(IS_DISARMED) {
    eng.featureFactory->spawnFeatureAt(feature_stoneFloor, pos_);
  }
}