roll.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. namespace dice {
  12. // Describe the actual result of rolling (+/-)NdM
  13. struct die_roll {
  14. // Collapse this roll into its actual value
  15. operator int() const;
  16. // Is this being added, or subtracted from the total
  17. sign sign;
  18. // Since this roll was composed on NdM, rolled.size() == N. Each element
  19. // of rolled is within the integer range [1, M].
  20. std::vector<int> rolled;
  21. };
  22. // Describe the actual result of rolling an arbitrary set of dice with mods
  23. struct dice_roll {
  24. // Collapse this roll into its actual value
  25. operator int() const;
  26. // A vector of component roll results, each on representing a single NdM
  27. // expression.
  28. std::vector<die_roll> sub_rolls;
  29. // A vector of every modifier attached to the system.
  30. std::vector<mod> modifiers;
  31. };
  32. /**
  33. * @param d Some dice roll structure, containing any number of dice sets 'NdM'
  34. * as well as any number of roll modifiers (fixed numbers). Additionally,
  35. * can contain a repetition parameter.
  36. * @return A vector of actualized rolls, where `vector.size() == d.num`.
  37. */
  38. std::vector<dice_roll> roll(dice const & d);
  39. /**
  40. * Print out the component elements of an actualized dice roll.
  41. * Use instead `out << int(r)` to print the final summation.
  42. */
  43. std::ostream & operator<<(std::ostream & out, dice_roll const & r);
  44. }