bzr branch
http://gegoxaren.bato24.eu/bzr/vqdr/trunk
|
23
by Gustav Hartvigsson
* Added DiceOperatiorToken |
1 |
/* dice_operator_token.vala
|
2 |
*
|
|
3 |
* Copyright 2021 Gustav Hartvigsson
|
|
4 |
*
|
|
5 |
* This file is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU Lesser General Public License as
|
|
7 |
* published by the Free Software Foundation; either version 3 of the
|
|
8 |
* License, or (at your option) any later version.
|
|
9 |
*
|
|
10 |
* This file is distributed in the hope that it will be useful, but
|
|
11 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13 |
* Lesser General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU Lesser General Public
|
|
16 |
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17 |
*
|
|
18 |
* SPDX-License-Identifier: LGPL-3.0-or-later
|
|
19 |
*/
|
|
20 |
||
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
21 |
using Vee; |
|
23
by Gustav Hartvigsson
* Added DiceOperatiorToken |
22 |
|
23 |
namespace VQDR.Expression { |
|
24 |
public class DiceOperatorToken : OperatorToken, UnaryOperator { |
|
25 |
|
|
|
52.1.3
by Gustav Hartvigsson
int -> int32 |
26 |
public DiceOperatorToken (int32 position) { |
|
23
by Gustav Hartvigsson
* Added DiceOperatiorToken |
27 |
base (position); |
28 |
} |
|
29 |
|
|
30 |
public override bool is_unary {public get;public set; default = false;} |
|
31 |
|
|
32 |
public override void evaluate_self (Context instance) throws GLib.Error { |
|
33 |
Dice dice; |
|
34 |
|
|
|
52.1.3
by Gustav Hartvigsson
int -> int32 |
35 |
int32 l_result; |
|
52.1.1
by Gustav Hartvigsson
Use int64 instead of long. |
36 |
int64 l_max_result; |
37 |
int64 l_min_result; |
|
|
23
by Gustav Hartvigsson
* Added DiceOperatiorToken |
38 |
|
39 |
var r_child = get_left_child (); |
|
40 |
var l_child = get_right_child (); |
|
41 |
|
|
42 |
if (! is_unary) { |
|
43 |
l_child.evaluate (instance); |
|
|
52.1.3
by Gustav Hartvigsson
int -> int32 |
44 |
l_result = (int32) l_child.result_value.number; |
|
23
by Gustav Hartvigsson
* Added DiceOperatiorToken |
45 |
l_max_result = l_child.result_max_value.number; |
46 |
l_min_result = l_child.result_min_value.number; |
|
47 |
} else { |
|
48 |
l_result = 1; |
|
49 |
/* In the original code the values were set to something strange. |
|
50 |
* This was dueto the normalisation of the values. We use FastNumber
|
|
51 |
* to do the grunt work, so we don't need to worry about this.
|
|
52 |
*/ |
|
53 |
l_max_result = 1; |
|
54 |
l_min_result = 1; |
|
55 |
} |
|
56 |
|
|
|
52.1.3
by Gustav Hartvigsson
int -> int32 |
57 |
dice = new Dice (l_result, (int32) r_child.result_value.number); |
|
23
by Gustav Hartvigsson
* Added DiceOperatiorToken |
58 |
result_value = FastNumber (dice.roll ()); |
59 |
|
|
|
57
by Gustav Hartvigsson
Made sure that no text rows exeed 80 columns. |
60 |
/* Max Result: The max of the dice faces multiplied my the max of the |
61 |
* dice numbers.
|
|
|
23
by Gustav Hartvigsson
* Added DiceOperatiorToken |
62 |
*/
|
63 |
// This was very complicated for no reason in the original code... |
|
64 |
result_max_value = FastNumber (l_max_result * |
|
65 |
r_child.result_max_value.number); |
|
|
57
by Gustav Hartvigsson
Made sure that no text rows exeed 80 columns. |
66 |
/* Min Result: The min of the dice faces multiplied my the max of the |
67 |
* dice numbers.
|
|
|
23
by Gustav Hartvigsson
* Added DiceOperatiorToken |
68 |
*/
|
69 |
// This was very complicated for no reason in the original code... |
|
70 |
result_max_value = FastNumber (l_min_result * |
|
71 |
r_child.result_min_value.number); |
|
72 |
|
|
73 |
result_string = "[" + result_value.to_string () + "]"; |
|
74 |
} |
|
75 |
|
|
76 |
} |
|
77 |
}
|