bool ActionSpellSummonBoat(Heroes & hero) { u8 chance = 0; switch(hero.GetLevelSkill(Skill::Secondary::WISDOM)) { case Skill::Level::BASIC: chance = 50; break; case Skill::Level::ADVANCED: chance = 75; break; case Skill::Level::EXPERT: chance = 100; break; default: chance = 30; break; } const s32 center = hero.GetIndex(); // find water s32 dst_water = -1; const MapsIndexes & v = Maps::ScanAroundObject(center, MP2::OBJ_ZERO); for(MapsIndexes::const_iterator it = v.begin(); it != v.end(); ++it) { if(world.GetTiles(*it).isWater()) { dst_water = *it; break; } } const MapsIndexes & boats = Maps::GetObjectPositions(center, MP2::OBJ_BOAT, false); if(boats.empty()) { DEBUG(DBG_GAME, DBG_WARN, "free boat: " << "not found"); } else { const s32 & src = boats.front(); if(Rand::Get(1, 100) <= chance && Maps::isValidAbsIndex(src) && Maps::isValidAbsIndex(dst_water)) { world.GetTiles(src).SetObject(MP2::OBJ_ZERO); world.GetTiles(dst_water).SetObject(MP2::OBJ_BOAT); } else DialogSpellFailed(Spell::SUMMONBOAT); } return true; }
void Heroes::ScholarAction(Heroes & hero1, Heroes & hero2) { if(! hero1.HaveSpellBook() || ! hero2.HaveSpellBook()) { DEBUG(DBG_GAME, DBG_INFO, "spell_book disabled"); return; } else if(! Settings::Get().ExtWorldEyeEagleAsScholar()) { DEBUG(DBG_GAME, DBG_WARN, "EyeEagleAsScholar settings disabled"); return; } const u8 scholar1 = hero1.GetLevelSkill(Skill::Secondary::EAGLEEYE); const u8 scholar2 = hero2.GetLevelSkill(Skill::Secondary::EAGLEEYE); u8 scholar = 0; Heroes* teacher = NULL; Heroes* learner = NULL; if(scholar1 && scholar1 >= scholar2) { teacher = &hero1; learner = &hero2; scholar = scholar1; } else if(scholar2 && scholar2 >= scholar1) { teacher = &hero2; learner = &hero1; scholar = scholar2; } else { DEBUG(DBG_GAME, DBG_WARN, "Eagle Eye skill not found"); return; } // skip bag artifacts SpellStorage teach = teacher->spell_book.SetFilter(SpellBook::ALL); SpellStorage learn = learner->spell_book.SetFilter(SpellBook::ALL); // remove_if for learn spells if(learn.size()) { SpellStorage::iterator res = std::remove_if(learn.begin(), learn.end(), std::bind1st(HeroesHaveSpell(), teacher)); learn.resize(std::distance(learn.begin(), res)); } if(learn.size()) { SpellStorage::iterator res = std::remove_if(learn.begin(), learn.end(), std::not1(std::bind1st(HeroesCanTeachSpell(), teacher))); learn.resize(std::distance(learn.begin(), res)); } // remove_if for teach spells if(teach.size()) { SpellStorage::iterator res = std::remove_if(teach.begin(), teach.end(), std::bind1st(HeroesHaveSpell(), learner)); teach.resize(std::distance(teach.begin(), res)); } if(teach.size()) { SpellStorage::iterator res = std::remove_if(teach.begin(), teach.end(), std::not1(std::bind1st(HeroesCanTeachSpell(), teacher))); teach.resize(std::distance(teach.begin(), res)); } std::string message, spells1, spells2; // learning for(SpellStorage::const_iterator it = learn.begin(); it != learn.end(); ++it) { teacher->AppendSpellToBook(*it); if(spells1.size()) spells1.append(it + 1 == learn.end() ? _(" and ") : ", "); spells1.append((*it).GetName()); } // teacher for(SpellStorage::const_iterator it = teach.begin(); it != teach.end(); ++it) { learner->AppendSpellToBook(*it); if(spells2.size()) spells2.append(it + 1 == teach.end() ? _(" and ") : ", "); spells2.append((*it).GetName()); } if((CONTROL_HUMAN & teacher->GetControl()) || (CONTROL_HUMAN & learner->GetControl())) { if(spells1.size() && spells2.size()) message = _("%{teacher}, whose %{level} %{scholar} knows many magical secrets, learns %{spells1} from %{learner}, and teaches %{spells2} to %{learner}."); else if(spells1.size()) message = _("%{teacher}, whose %{level} %{scholar} knows many magical secrets, learns %{spells1} from %{learner}."); else if(spells2.size()) message = _("%{teacher}, whose %{level} %{scholar} knows many magical secrets, teaches %{spells2} to %{learner}."); if(message.size()) { StringReplace(message, "%{teacher}", teacher->GetName()); StringReplace(message, "%{learner}", learner->GetName()); StringReplace(message, "%{level}", Skill::Level::String(scholar)); StringReplace(message, "%{scholar}", Skill::Secondary::String(Skill::Secondary::EAGLEEYE)); StringReplace(message, "%{spells1}", spells1); StringReplace(message, "%{spells2}", spells2); Dialog::Message(_("Scholar Ability"), message, Font::BIG, Dialog::OK); } } }