OSDN Git Service

c476ba0c47ea80cc325afcf4b40f546946fbc276
[deeangband/Deeangband-new.git] / Deeangband / Dice.h
1 /*!
2 *  @file Dice.h
3 *  @brief Dice\83N\83\89\83X\82Æ\82»\82Ì\91¼\95t\90\8f\97v\91f\82Ì\92è\8b`
4 *  @date 2014/01/19
5 *  @author Deskull
6 *  2014 Sikabane Works.
7 */
8
9 #pragma once
10
11 #include "Deeangband.h"
12
13 namespace Deeangband
14 {
15
16         /*!
17          * @class Dice
18          * @brief \83Q\81[\83\80\92\86\82Ì\83_\83C\83X\8f\88\97\9d
19          * @details
20          * <H1>\8aT\97v</H1>
21          * <p>Dice\83N\83\89\83X\82Í\83Q\81[\83\80\92\86\82É\91\8dÝ\82·\82é\82 \82ç\82ä\82é\83\89\83\93\83_\83\80\90«\82ð\8e\9d\82Â\83p\83\89\83\81\81[\83^\82Ì\83C\83\93\83X\83^\83\93\83X\82Æ\82È\82è\81A\82»\82Ì\97\90\90\94\8f\88\97\9d\82à\8eÀ\91\95\82³\82ê\82é\81B
22          * \82Ü\82½\90Ã\93I\82È\83N\83\89\83X\8aÖ\90\94\8fã\82Å\82Í\81ABoost(or C++11)\82Å\8eÀ\91\95\82³\82ê\82½\83\81\83\8b\83Z\83\93\83k\83c\83C\83X\83^\97\90\90\94\90\90¬\8aí\82ð\95Û\8e\9d\82µ\81A\92¼\90Ú\90³\8bK\97\90\90\94\82ð\8eó\82¯\8eæ\82é\8b@\94\\82à\8eÀ\91\95\82³\82ê\82é\81B
23          * </p>
24          */
25         class Dice
26         {
27         private:
28
29                 DICE_NUMBER num; //!< \83_\83C\83X\82Ì\90\94
30                 DICE_SIDE side; //!< \83_\83C\83X\82Ì\96Ê\90\94
31
32                 friend class boost::serialization::access;
33
34                 /*!
35                 * @brief \83N\83\89\83X\82Ì\83V\83\8a\83A\83\89\83C\83Y\82ð\90Ý\92è\82·\82é
36                 * @param archive \83A\81[\83J\83C\83u\89»\82·\82é\83N\83\89\83X\82Ì\83A\83h\83\8c\83X
37                 * @param version \83t\83@\83C\83\8b\83o\81[\83W\83\87\83\93
38                 * @return XMLSerialize\83e\83\93\83v\83\8c\81[\83g
39                 */
40                 template<class Archive> void serialize(Archive &archive, const unsigned int version) 
41                 {
42                         if(version >= 0)
43                         {
44                                 archive & boost::serialization::make_nvp("Num", num);
45                                 archive & boost::serialization::make_nvp("Side", side);
46                         }
47                 }
48
49                 template<class Archive> friend void save_construct_data(Archive & archive, const Dice *ptr, const unsigned int version)
50                 {
51                         archive & boost::serialization::make_nvp("num", ptr->GetNum());
52                         archive & boost::serialization::make_nvp("side", ptr->GetSide());
53                 }
54
55                 template<class Archive> friend void load_construct_data(Archive & archive, Dice *ptr, const unsigned int version)
56                 {
57                         DICE_NUMBER n;
58                         DICE_SIDE s;
59                         archive & boost::serialization::make_nvp("num", n);
60                         archive & boost::serialization::make_nvp("side", s);
61                         ::new(ptr) Dice(num, side);
62                 }
63
64         public:
65
66                 static std::mt19937 Dice::mt; //!< \83\81\83\8b\83Z\83\93\83k\83c\83C\83X\83^\82É\82æ\82é\97\90\90\94\90\90¬\83G\83\93\83W\83\93
67
68                 /*!
69                  * @brief \83R\83\93\83X\83g\83\89\83N\83^
70                  */
71                 Dice::Dice(void);
72
73                 /*!
74                  * @brief \83R\83\93\83X\83g\83\89\83N\83^
75                  * @param num \83_\83C\83X\82Ì\90\94
76                  * @param side \83_\83C\83X\82Ì\96Ê
77                  */
78                 Dice::Dice(DICE_NUMBER num, DICE_SIDE side);
79
80                 /*!
81                  * @brief \83f\83X\83g\83\89\83N\83^
82                  */
83                 Dice::~Dice(void);
84
85                 /*!
86                  * @brief \83_\83C\83X\82Ì\90\94\92l\90Ý\92è\82ð\8ds\82¤\81B
87                  * @param num \83_\83C\83X\82Ì\90\94
88                  * @param side \83_\83C\83X\82Ì\96Ê
89                  * @return \82È\82µ
90                  */
91                 void Dice::Set(DICE_NUMBER num, DICE_SIDE side);
92
93                 /*!
94                  * @brief \97\90\90\94\8f\89\8aú\89»\8aÖ\90\94
95                  * @return \82È\82µ
96                  */
97                 static void Dice::Initialize(void);
98
99                 /*!
100                  * @brief \83_\83C\83X\82Ì\90\94\82ð\95Ô\82·
101                  * @return \83_\83C\83X\82Ì\90\94
102                  */
103                 int Dice::GetNum(void);
104
105                 /*!
106                  * @brief \83_\83C\83X\82Ì\96Ê\90\94\82ð\95Ô\82·
107                  * @return \83_\83C\83X\82Ì\96Ê\90\94
108                  */
109                 int Dice::GetSide(void);
110
111                 /*!
112                  * @brief \83_\83C\83X\82ð\90U\82é
113                  * @return \83_\83C\83X\82Ì\91\8d\8cv\92l
114                  */
115                 int Dice::Cast(void);
116
117                 /*!
118                  * @brief \83_\83C\83X\82ð\90U\82é
119                  * @param num \83_\83C\83X\82Ì\90\94
120                  * @param side \83_\83C\83X\82Ì\96Ê\90\94
121                  * @return \83_\83C\83X\82Ì\91\8d\8cv\92l
122                  */
123                 static int Dice::Cast(DICE_NUMBER num, DICE_SIDE side);
124
125                 /*!
126                  * @brief \90³\8bK\97\90\90\94\82ð\90U\82é
127                  * @param ave \95½\8bÏ
128                  * @param dic \95ª\8eU
129                  * @return \97\90\90\94\92l
130                  */
131                 static int Dice::CastNormalRand(int ave, int div);
132
133                 /*!
134                  * @brief \83_\83C\83X\82Ì\8eæ\82è\93¾\82é\8dÅ\91å\92l\82ð\95Ô\82·
135                  * @return \83_\83C\83X\82Ì\8dÅ\91å\92l
136                  */
137                 int Dice::MaxCast(void);
138
139                 /*!
140                  * @brief \83_\83C\83X\82Ì\8eæ\82è\93¾\82é\8dÅ\91å\92l\82ð\95Ô\82·
141                  * @param num \83_\83C\83X\82Ì\90\94
142                  * @param side \83_\83C\83X\82Ì\96Ê\90\94
143                  * @return \83_\83C\83X\82Ì\8dÅ\91å\92l
144                  */
145                 static int Dice::MaxCast(DICE_NUMBER num, DICE_SIDE side);
146
147                 /*!
148                  * @brief 0\82ð\8dÅ\8f¬\92l\82Æ\82µ\82½\97\90\90\94\82ð\95Ô\82·
149                  * @param max \97\90\90\94\82Ì\94Í\88Í(0\81`max-1)
150                  * @return \97\90\90\94\82Ì\92l
151                  */
152                 static int Dice::Rand0(int max);
153
154                 /*!
155                  * @brief 1\82ð\8dÅ\8f¬\92l\82Æ\82µ\82½\97\90\90\94\82ð\95Ô\82·
156                  * @param max \97\90\90\94\82Ì\8dÅ\91å\92l(1\81`max)
157                  * @return \97\90\90\94\82Ì\92l
158                  */
159                 static int Dice::Rand1(int max);
160
161                 /*!
162                  * @brief \83Z\81[\83r\83\93\83O\94»\92è
163                  * @param diff \83Z\81[\83r\83\93\83O\93ï\93x-\83Z\81[\83r\83\93\83O\92l\8d·\95ª
164                  * @return \83Z\81[\83r\83\93\83O\90¬\8c÷\82È\82ç\82Πtrue \82ð\95Ô\82·\81B
165                  */
166                 static bool Dice::Saving(int diff);
167
168         };
169
170 }
171
172 BOOST_CLASS_VERSION(Deeangband::Dice, 10);