MCPcopy Create free account
hub / github.com/davemoore22/sorcery / _pit_oops

Method _pit_oops

src/engine/engine.cpp:835–895  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

833 _ctx.controller->set_can_undo(false);
834
835 const auto at{_ctx.game->state->get_player_pos()};
836 if (_ctx.game->state->level->at(at).has_spinner()) {
837
838 auto new_facing{static_cast<Enums::Map::Direction>(
839 _ctx.get_random(Enums::System::Random::ZERO_TO_3))};
840 _ctx.game->state->set_player_facing(new_facing);
841
842 DEBUG_LOG("Player triggered spinner");
843 }
844}
845
846auto Sorcery::Engine::_pit_oops() -> void {
847
848 std::vector<int> deaths{};
849 deaths.clear();
850
851 auto party{_ctx.game->state->get_party_characters()};
852 for (auto &[id, character] : _ctx.game->characters) {
853 if (std::find(party.begin(), party.end(), id) != party.end()) {
854
855 const auto chance{
856 (character.get_cur_attr(Enums::Character::Attribute::AGILITY) -
857 _ctx.game->state->get_depth()) *
858 4};
859 const auto roll(_ctx.get_random(Enums::System::Random::D100));
860 //_ctx.game->state->add_log_dice_roll(
861 // fmt::format("{:>16} - {}", character.get_name(), "Avoid Pit"),
862 // 100, roll, chance);
863 if (roll < chance) {
864
865 // Damage is avoided
866
867 } else {
868
869 // Now in the original Apple 2 version, pit damage is based upon
870 // 3 extra values stored in the square in the TMaze records -
871 // AUX0, AUX1, and AUX2. Thanks to the data extraction by Tommy
872 // Ewers, the relevant values for each pit in the game are 0, 8
873 // and depth respectively. This is a long-winded way of saying
874 // that the pit damage (calculated in APIT and ROCKWATR) is 0 +
875 // (depth * d8), i.e. a d8 for level depth.
876
877 // Inflict damage! (remember depth is negative here and positve
878 // in original wizardry)
879 auto pit_damage{0U};
880 const auto dice{std::abs(_ctx.game->state->get_depth())};
881 for (int i = 1; i <= dice; i++)
882 pit_damage += _ctx.get_random(Enums::System::Random::D8);
883
884 //_ctx.game->state->add_log_message(
885 // fmt::format(
886 // "{} fell into a pit and took {} points of damage!",
887 // character.get_name(), pit_damage),
888 // IMT::GAME);
889
890 if (const auto alive{character.damage(pit_damage)}; !alive) {
891
892 // Oh dear, death from a pit!

Callers

nothing calls this directly

Calls 6

clearMethod · 0.80
get_party_charactersMethod · 0.80
get_cur_attrMethod · 0.80
get_depthMethod · 0.80
get_randomMethod · 0.80
damageMethod · 0.80

Tested by

no test coverage detected