| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- //
- // 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 {
- // 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<int> rolled;
- int sides;
- };
- // 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;
- // 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);
- }
|