-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctions.bb
289 lines (263 loc) · 7.36 KB
/
Functions.bb
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
;//////////////////////////////////////////////////////////////////////////////
;--------------------------- UNIVERSAL FUNCTIONS ------------------------------
;//////////////////////////////////////////////////////////////////////////////
;PRODUCE VARIANT SOUND
Function ProduceSound(entity,sound,pitch,vol#)
;fluctuate pitch
range1=pitch-(pitch/8)
range2=pitch+(pitch/16)
pitcher=Rnd(range1,range2)
;fluctuate volume
If vol#=0 Then vol#=Rnd(0.4,1.2)
;deliver sound
If sound>0 And (gotim>0 Or screen<>50)
If pitch>0 Then SoundPitch sound,pitcher
SoundVolume sound,vol#
If entity>0 Then EmitSound sound,entity
If entity=0 Then EmitSound sound,cam
;reset
If pitch>0 Then SoundPitch sound,pitch
SoundVolume sound,1
EndIf
End Function
;---------------------------------------------------------------------------
;///////////////////////////// GRAPHICAL ///////////////////////////////////
;---------------------------------------------------------------------------
;OUTLINE
Function Outline(script$,x,y,r1,g1,b1,r2,g2,b2)
;outline
If r1<>r2 Or g1<>g2 Or b1<>b2
Color r1,g1,b1
Text x+2,y+2,script$,1,1
Text x+1,y,script$,1,1
Text x-1,y,script$,1,1
Text x,y+1,script$,1,1
Text x,y-1,script$,1,1
EndIf
;core
Color r2,g2,b2
Text x,y,script$,1,1
End Function
;OUTLINE STRAIGHT
Function OutlineStraight(script$,x,y,r1,g1,b1,r2,g2,b2)
;outline
If r1<>r2 Or g1<>g2 Or b1<>b2
Color r1,g1,b1
Text x+2,y+2,script$,0,1
Text x+1,y,script$,0,1
Text x-1,y,script$,0,1
Text x,y+1,script$,0,1
Text x,y-1,script$,0,1
EndIf
;core
Color r2,g2,b2
Text x,y,script$,0,1
End Function
;PLOT BOLD LINE
Function DrawLine(startX,startY,endX,endY,r,g,b)
;outline
Color 0,0,0
Line startX-1,startY,endX-1,endY
Line startX+1,startY,endX+1,endY
Line startX,startY-1,endX,endY-1
Line startX,startY+1,endX,endY+1
;coloured line
Color r,g,b
Line startX,startY,endX,endY
End Function
;RESOLUTION X FIX
Function rX#(x#)
factor#=800.0/Float(GraphicsWidth())
newX#=x#/factor#
Return newX#
End Function
;RESOLUTION Y FIX
Function rY#(y#)
factor#=600.0/Float(GraphicsHeight())
newY#=y#/factor#
Return newY#
End Function
;---------------------------------------------------------------------------
;//////////////////////////// MATHEMATICAL /////////////////////////////////
;---------------------------------------------------------------------------
;CALCULATE HEIGHT IN FEET & INCHES
Function GetHeight$(value)
feet=value/12
inches=value-(feet*12)
ft$=(feet+5)+"'"
in$=inches+"''"
figure$=ft$+in$
Return figure$
End Function
;CALCULATE 1'000'000 FIGURE
Function GetFigure$(value)
minus=0
If value<0 Then minus=1 : value=value-(value*2)
;get segments
hundreds=0 : thousands=0 : millions=0
millions=value/1000000
If millions<0 Then millions=0
thousands=(value-(millions*1000000))/1000
If thousands<0 Then thousands=0
hundreds=value-((millions*1000000)+(thousands*1000))
If hundreds<0 Then hundreds=0
;piece together
hun$=hundreds
If thousands>0 Then tho$=thousands Else tho$=""
If millions>0 Then mil$=millions Else mil$=""
If (thousands>0 Or millions>0) Then hun$="'"+hundreds
If (thousands>0 Or millions>0) And hundreds<100 Then hun$="'0"+hundreds
If (thousands>0 Or millions>0) And hundreds<10 Then hun$="'00"+hundreds
If millions>0 Then tho$="'"+thousands
If millions>0 And thousands<100 Then tho$="'0"+thousands
If millions>0 And thousands<10 Then tho$="'00"+thousands
;return
If minus=0 Then figure$=mil$+tho$+hun$
If minus=1 Then figure$="-"+mil$+tho$+hun$
Return figure$
End Function
;TRANSLATE NUMBER INTO DIGITS
Function Dig$(value,degree)
digits$=value
If value<degree Then digits$="0"+digits$
If value<degree/10 Then digits$="0"+digits$
If value=0 And degree=10 Then digits$="00"
If value=0 And degree=100 Then digits$="000"
Return digits$
End Function
;GET FIGURE TO NEAREST ???
Function RoundOff(value,degree)
floater#=value/degree
inty=Int(floater#)
returner=inty*degree
Return returner
End Function
;REACHED VALUE?
Function Reached(curr#,dest#,range)
value=0
If curr#>dest#-range And curr#<dest#+range Then value=1
Return value
End Function
;REACHED CO-ORDINATE?
Function ReachedCord(currX#,currZ#,destX#,destZ#,range)
value=0
If currX#>destX#-range And currX#<destX#+range And currZ#>destZ#-range And currZ#<destZ#+range Then value=1
Return value
End Function
;CLEAN GIVEN ANGLE
Function CleanAngle#(angle#)
its=0
Repeat
If angle#<0 Then angle#=angle#+360
If angle#>360 Then angle#=angle#-360
its=its+1
Until (angle#=>0 And angle#=<360) Or its>100
Return angle#
End Function
;FIND BEST ANGLE ROUTE
Function ReachAngle#(sA#,tA#,speed#)
;clean angles
sA#=CleanAngle#(sA#)
tA#=CleanAngle#(tA#)
;get negative route
neg=0 : checkA#=sA#
Repeat
neg=neg+1
checkA#=checkA#-1
If checkA#<0 Then checkA#=360
Until checkA#=>tA#-1 And checkA#=<tA#+1
;get positive route
pos=0 : checkA#=sA#
Repeat
pos=pos+1
checkA#=checkA#+1
If checkA#>360 Then checkA#=0
Until checkA#=>tA#-1 And checkA#=<tA#+1
;return shortest route
If neg<pos Then value#=-speed# Else value#=speed#
Return value#
End Function
;SATISFIED TARGET ANGLE?
Function SatisfiedAngle(sA#,tA#,range)
value=0
;scan clockwise
angler#=sA#
For count=1 To range
If angler#=>tA#-1 And angler#=<tA#+1 Then value=1
angler#=angler#+1
If angler#>360 Then angler#=0
Next
;scan counter-clockwise
angler#=sA#
For count=1 To range
If angler#=>tA#-1 And angler#=<tA#+1 Then value=1
angler#=angler#-1
If angler#<0 Then angler#=360
Next
Return value
End Function
;CALCULATE DIFFERENCE (between any 2 numbers)
Function GetDiff#(source#,dest#)
diff#=dest#-source#
If diff#<0 Then diff#=MakePositive#(diff#)
Return diff#
End Function
;CALCULATE CENTRE (of any 2 numbers)
Function GetCentre#(source#,dest#)
centre#=source#+(GetDiff#(source#,dest#)/2)
Return centre#
End Function
;CALCULATE DISTANCE (between any 2 co-ordinates)
Function GetDistance#(sourceX#,sourceZ#,destX#,destZ#)
diffX#=GetDiff#(sourceX#,destX#)
diffZ#=GetDiff#(sourceZ#,destZ#)
If diffX#>diffZ# Then distance#=diffX# Else distance#=diffZ#
Return distance#
End Function
;CALCULATE HIGHEST VALUE
Function HighestValue#(valueA#,valueB#)
highest#=valueA#
If valueB#>valueA# Then highest#=valueB#
Return highest#
End Function
;CALCULATE LOWEST VALUE
Function LowestValue#(valueA#,valueB#)
lowest#=valueA#
If valueB#<valueA# Then lowest#=valueB#
Return lowest#
End Function
;SMOOTH TRAVELLING SPEEDS
Function GetSmoothSpeeds(x#,tX#,y#,tY#,z#,tZ#,factor)
;calculate differences & identify leader
diffX#=GetDiff#(x#,tX#)
lead#=diffX# : leader=1
diffY#=GetDiff#(y#,tY#)
If diffY#>lead# Then lead#=diffY# : leader=2
diffZ#=GetDiff#(z#,tZ#)
If diffZ#>lead# Then lead#=diffZ# : leader=3
;make anchor speed from leading difference
anchor#=lead#/factor
;calculate respective speeds
If leader=1 Then speedX#=anchor# Else speedX#=anchor#*(diffX#/lead#)
If leader=2 Then speedY#=anchor# Else speedY#=anchor#*(diffY#/lead#)
If leader=3 Then speedZ#=anchor# Else speedZ#=anchor#*(diffZ#/lead#)
End Function
;FORCE MINUS INTO POSITIVE
Function MakePositive#(value#)
If value#<0
positive#=value#-(value#*2)
Else
positive#=value#
EndIf
Return positive#
End Function
;CALCULATE PERCENTAGE OF VALUE
Function PercentOf#(valueA#,percent#)
valueB#=(valueA#/100)*percent#
Return valueB#
End Function
;CALCULATE VALUE AS PERCENT
Function GetPercent#(valueA#,valueB#)
percent#=(valueA#/valueB#)*100
Return percent#
End Function