ScummVM API documentation
dice.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  *
21  * Based on the original sources
22  * Faery Tale II -- The Halls of the Dead
23  * (c) 1993-1996 The Wyrmkeep Entertainment Co.
24  */
25 
26 #ifndef SAGA2_DICE_H
27 #define SAGA2_DICE_H
28 
29 namespace Saga2 {
30 
31 inline int32 RANDOM(int32 minV, int32 maxV) {
32  return (maxV - minV + 1) ? g_vm->_rnd->getRandomNumber(ABS(maxV - minV)) + minV : 0;
33 }
34 
35 inline int32 diceRoll(int dice, int sides, int perDieMod, int base) {
36  int32 rv = base;
37  if (dice)
38  for (int i = 0; i < ABS(dice); i++)
39  rv += (RANDOM(1, sides) + perDieMod * (dice > 0 ? 1 : -1));
40  return rv;
41 }
42 
43 class RandomDice {
44  int8 _dice, _side;
45 public:
46  RandomDice(int8 d, int8 s) {
47  _dice = d;
48  _side = s;
49  }
50  RandomDice() {
51  _dice = 1;
52  _side = 1;
53  }
54 
55  int32 roll(int32 resist = 0) {
56  return diceRoll(_dice, _side, resist, 0);
57  }
58 };
59 
60 } // end of namespace Saga2
61 
62 #endif
Definition: dice.h:43
Definition: actor.h:32
uint32 getRandomNumber(uint maxNum)
Definition: ags.h:109
T ABS(T x)
Definition: util.h:56