| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- //
- // roll.hpp
- // dice-roll
- //
- // Created by Sam Jaffe on 12/1/18.
- // Copyright © 2018 Sam Jaffe. All rights reserved.
- //
- #pragma once
- #include <vector>
- #include "die.h"
- #include "random.h"
- namespace dice {
- enum class outcome {
- PASS,
- FAIL,
- };
- struct die_outcome {
- friend auto operator<=>(die_outcome const &, die_outcome const &) = default;
- bool dropped{false};
- int roll;
- int sides;
- };
- // Describe the actual result of rolling (+/-)NdM
- struct die_roll {
- // Collapse this roll into its actual value
- operator int() const;
- // Is this being added, or subtracted from the total
- sign sign;
- // Since this roll was composed on NdM, rolled.size() == N. Each element
- // of rolled is within the integer range [1, M].
- std::vector<die_outcome> rolled;
- };
- // Describe the actual result of rolling an arbitrary set of dice with mods
- struct dice_roll {
- // Collapse this roll into its actual value
- operator int() const;
- std::variant<int, outcome> result() const;
- // A vector of component roll results, each on representing a single NdM
- // expression.
- std::vector<die_roll> sub_rolls;
- // A vector of every modifier attached to the system.
- std::vector<mod> modifiers;
- difficulty_class dc;
- };
- class roller {
- public:
- roller();
- roller(engine::random && g);
- /**
- * @param d Some dice roll structure, containing any number of dice sets 'NdM'
- * as well as any number of roll modifiers (fixed numbers). Additionally,
- * can contain a repetition parameter.
- * @return A vector of actualized rolls, where `vector.size() == d.num`.
- */
- std::vector<dice_roll> operator()(dice const & d);
- private:
- engine::random gen;
- };
- /**
- * Print out the component elements of an actualized dice roll.
- * Use instead `out << int(r)` to print the final summation.
- */
- std::ostream & operator<<(std::ostream & out, dice_roll const & r);
- }
|