-
Notifications
You must be signed in to change notification settings - Fork 0
/
restricted_number.dm
201 lines (133 loc) · 3.01 KB
/
restricted_number.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
Restricted
A datum designed to make numerical keeping a lot easier.
It forces the number to stay always between an upper and lower bound.
Original idea: http://www.byond.com/members/BYONDAnime?command=view_post&post=98823
*/
restricted
var
//the initial value of the number
initial
//the minimum value of the number
minimum
//the current value of the number
current
//the maximum value of the number
maximum
New(minimum = 0, current = 100, maximum = 100)
src.minimum = minimum
src.maximum = maximum
src.initial = current
set_current(current)
proc
//is-at functions
at_min()
return current == minimum
at_max()
return current == maximum
//check-if functions
is_max(number)
return number == maximum
is_min(number)
return number == minimum
greater_than_number(num)
return current > num
gtn(num)
return greater_than_number(num)
less_than_number(num)
return current < num
ltn(num)
return less_than_number(num)
//setter functions
set_maximum(number)
maximum=max(minimum, number)
set_current(get_current())
set_minimum(number)
minimum=min(maximum, number)
set_current(get_current())
set_current(number)
number = max(minimum, number)
number = min(maximum, number)
src.current = number
set_min(number)
set_minimum(number)
set_max(number)
set_maximum(number)
set_cur(number)
set_current(number)
set_current_to_max()
set_current(maximum)
set_current_to_min()
set_current(minimum)
//percentage functions
to_percent()
return (current/maximum)*100
to_percent_rounded()
return round((current/maximum)*100)
greater_than_percent(perc)
return current > maximum*(perc/100)
gtp(perc)
return greater_than_percent(perc)
less_than_percent(perc)
return current < maximum*(perc/100)
ltp(perc)
return less_than_percent(perc)
//"pretty print" functions
to_percent_text()
return "[to_percent()]%"
to_percent_rounded_text()
return "[to_percent_rounded()]%"
to_text()
return "[current] / [maximum]"
//getter functions
get_current()
return current
get_maximum()
return maximum
get_minimum()
return minimum
get_initial()
return initial
//various numeric functions
//++
i()
increment()
//--
d()
decrement()
//+=
add(number)
increase(number)
//-=
sub(number)
decrease(number)
//++
increment()
increase(1)
//--
decrement()
decrease(1)
//+=
increase(number)
set_current(current + number)
//-=
decrease(number)
increase(-number)
//get_maximum wrapper
maximum()
return get_maximum()
//get_minimum wrapper
minimum()
return get_minimum()
//get_current wrapper
current()
return get_current()
cur()
return get_current()
//get_initial wrapper
init()
return get_initial()
//I don't really recommend this function, since if max or min changes, it probably won't work right
//but I'm providing it anyway, because it still has it's uses
reset()
set_current(initial)