roll.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. };
  23. // Describe the actual result of rolling an arbitrary set of dice with mods
  24. struct dice_roll {
  25. // Collapse this roll into its actual value
  26. operator int() const;
  27. // A vector of component roll results, each on representing a single NdM
  28. // expression.
  29. std::vector<die_roll> sub_rolls;
  30. // A vector of every modifier attached to the system.
  31. std::vector<mod> modifiers;
  32. difficulty_class dc;
  33. };
  34. class roller {
  35. public:
  36. roller();
  37. roller(engine::random && g);
  38. /**
  39. * @param d Some dice roll structure, containing any number of dice sets 'NdM'
  40. * as well as any number of roll modifiers (fixed numbers). Additionally,
  41. * can contain a repetition parameter.
  42. * @return A vector of actualized rolls, where `vector.size() == d.num`.
  43. */
  44. std::vector<dice_roll> operator()(dice const & d);
  45. private:
  46. engine::random gen;
  47. };
  48. /**
  49. * Print out the component elements of an actualized dice roll.
  50. * Use instead `out << int(r)` to print the final summation.
  51. */
  52. std::ostream & operator<<(std::ostream & out, dice_roll const & r);
  53. }