roll.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // roll.hpp
  3. // dice-roll
  4. //
  5. // Created by Sam Jaffe on 12/1/18.
  6. // Copyright © 2018 Sam Jaffe. All rights reserved.
  7. //
  8. #pragma once
  9. #include <vector>
  10. #include "die.h"
  11. #include "random.h"
  12. namespace dice {
  13. // Describe the actual result of rolling (+/-)NdM
  14. struct die_roll {
  15. // Collapse this roll into its actual value
  16. operator int() const;
  17. // Is this being added, or subtracted from the total
  18. sign sign;
  19. // Since this roll was composed on NdM, rolled.size() == N. Each element
  20. // of rolled is within the integer range [1, M].
  21. std::vector<int> rolled;
  22. int sides;
  23. };
  24. // Describe the actual result of rolling an arbitrary set of dice with mods
  25. struct dice_roll {
  26. // Collapse this roll into its actual value
  27. operator int() const;
  28. // A vector of component roll results, each on representing a single NdM
  29. // expression.
  30. std::vector<die_roll> sub_rolls;
  31. // A vector of every modifier attached to the system.
  32. std::vector<mod> modifiers;
  33. difficulty_class dc;
  34. };
  35. class roller {
  36. public:
  37. roller();
  38. roller(engine::random && g);
  39. /**
  40. * @param d Some dice roll structure, containing any number of dice sets 'NdM'
  41. * as well as any number of roll modifiers (fixed numbers). Additionally,
  42. * can contain a repetition parameter.
  43. * @return A vector of actualized rolls, where `vector.size() == d.num`.
  44. */
  45. std::vector<dice_roll> operator()(dice const & d);
  46. private:
  47. engine::random gen;
  48. };
  49. /**
  50. * Print out the component elements of an actualized dice roll.
  51. * Use instead `out << int(r)` to print the final summation.
  52. */
  53. std::ostream & operator<<(std::ostream & out, dice_roll const & r);
  54. }