Ejemplo n.º 1
0
bool BaseAI::startTurn()
{
  static bool initialized = false;
  int count = 0;
  count = getPlayerCount(c);
  players.clear();
  players.resize(count);
  for(int i = 0; i < count; i++)
  {
    players[i] = Player(getPlayer(c, i));
  }

  count = getMappableCount(c);
  mappables.clear();
  mappables.resize(count);
  for(int i = 0; i < count; i++)
  {
    mappables[i] = Mappable(getMappable(c, i));
  }

  count = getTileCount(c);
  tiles.clear();
  tiles.resize(count);
  for(int i = 0; i < count; i++)
  {
    tiles[i] = Tile(getTile(c, i));
  }

  count = getTrapCount(c);
  traps.clear();
  traps.resize(count);
  for(int i = 0; i < count; i++)
  {
    traps[i] = Trap(getTrap(c, i));
  }

  count = getThiefCount(c);
  thiefs.clear();
  thiefs.resize(count);
  for(int i = 0; i < count; i++)
  {
    thiefs[i] = Thief(getThief(c, i));
  }

  count = getThiefTypeCount(c);
  thiefTypes.clear();
  thiefTypes.resize(count);
  for(int i = 0; i < count; i++)
  {
    thiefTypes[i] = ThiefType(getThiefType(c, i));
  }

  count = getTrapTypeCount(c);
  trapTypes.clear();
  trapTypes.resize(count);
  for(int i = 0; i < count; i++)
  {
    trapTypes[i] = TrapType(getTrapType(c, i));
  }

  if(!initialized)
  {
    initialized = true;
    init();
  }
  return run();
}
Ejemplo n.º 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_);
  }
}