Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R7/RPlatform.txt
1319 views
1
//-----------------Sonic CD R Platform Script-----------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Aliases
6
#alias Object.Value0 : Object.Angle
7
#alias Object.Value1 : Object.PlatformX
8
#alias Object.Value2 : Object.PlatformY
9
#alias Object.Value3 : Object.ChangeX
10
#alias Object.Value4 : Object.ChangeY
11
#alias Object.Value5 : Object.SwingAngle
12
#alias Object.Value6 : Object.ChainsNo
13
14
// States
15
#alias 0 : RPLATFORM_FULL_CW_SLOWAPEX
16
#alias 1 : RPLATFORM_FULL_CW
17
#alias 2 : RPLATFORM_FULL_CCW
18
#alias 3 : RPLATFORM_TOP180
19
#alias 4 : RPLATFORM_RIGHT180
20
#alias 5 : RPLATFORM_BOTTOM180
21
22
// Collision
23
#alias 1 : PLAYER_COL_FLOOR
24
#alias 2 : PLAYER_COL_LWALL
25
#alias 3 : PLAYER_COL_RWALL
26
#alias 4 : PLAYER_COL_ROOF
27
28
// Property Values
29
#alias 19 : HALF_CW_BOTTOM
30
#alias 35 : HALF_CW_TOP
31
#alias 54 : FULL_CW_SLOW
32
#alias 67 : HALF_CW_RIGHT
33
#alias 99 : FULL_CW
34
#alias 115: FULL_CCW
35
36
// Gravity
37
#alias 0 : GRAVITY_GROUND
38
39
40
sub ObjectMain
41
// Each state directly corresponds to a subtype of the platform
42
switch Object.State
43
case RPLATFORM_FULL_CW_SLOWAPEX
44
Object.SwingAngle++
45
Object.SwingAngle &= 511
46
Sin(Object.Angle, Object.SwingAngle)
47
Object.Angle /= 3
48
Object.Angle += 640
49
break
50
51
case RPLATFORM_FULL_CW
52
Object.SwingAngle++
53
Object.SwingAngle &= 511
54
TempValue0 = Object.SwingAngle
55
TempValue0 >>= 1
56
Cos(TempValue1, TempValue0)
57
TempValue1 >>= 1
58
Object.Angle = 640
59
Object.Angle -= TempValue1
60
break
61
62
case RPLATFORM_FULL_CCW
63
Object.SwingAngle++
64
Object.SwingAngle &= 511
65
TempValue0 = Object.SwingAngle
66
TempValue0 >>= 1
67
Cos(Object.Angle, TempValue0)
68
Object.Angle >>= 1
69
Object.Angle += 640
70
break
71
72
case RPLATFORM_TOP180
73
Object.SwingAngle++
74
Object.SwingAngle &= 511
75
Sin(Object.Angle, Object.SwingAngle)
76
Object.Angle >>= 2
77
Object.Angle += 896
78
break
79
80
case RPLATFORM_RIGHT180
81
Object.SwingAngle++
82
Object.SwingAngle &= 511
83
Sin(Object.Angle, Object.SwingAngle)
84
Object.Angle >>= 2
85
Object.Angle += 512
86
break
87
88
case RPLATFORM_BOTTOM180
89
Object.SwingAngle++
90
Object.SwingAngle &= 511
91
Sin(Object.Angle, Object.SwingAngle)
92
Object.Angle >>= 2
93
Object.Angle += 640
94
break
95
96
end switch
97
98
TempValue1 = Object.ChainsNo
99
TempValue1++
100
TempValue1 <<= 4
101
102
Cos(Object.ChangeX, Object.Angle)
103
Object.ChangeX *= TempValue1
104
Object.ChangeX <<= 7
105
Object.ChangeX += Object.XPos
106
Object.ChangeX &= 0xFFFF0000 // Truncate the value
107
Object.ChangeX -= Object.PlatformX
108
109
Sin(Object.ChangeY, Object.Angle)
110
Object.ChangeY *= TempValue1
111
Object.ChangeY <<= 7
112
Object.ChangeY += Object.YPos
113
Object.ChangeY &= 0xFFFF0000 // Truncate the value
114
Object.ChangeY -= Object.PlatformY
115
116
end sub
117
118
119
sub ObjectPlayerInteraction
120
// First backup the object's position
121
TempValue0 = Object.XPos
122
TempValue1 = Object.YPos
123
124
TempValue2 = Player.YPos
125
Object.XPos = Object.PlatformX
126
Object.YPos = Object.PlatformY
127
128
if Player.State == Player_State_Hurt
129
PlayerObjectCollision(C_BOX, -32, -8, 32, 8)
130
else
131
PlayerObjectCollision(C_BOX, -24, -8, 24, 8)
132
end if
133
134
switch CheckResult
135
case PLAYER_COL_FLOOR
136
// The player's on top of the platform, just move them with it for now
137
Player.XPos += Object.ChangeX
138
Player.YPos += Object.ChangeY
139
break
140
141
case PLAYER_COL_LWALL
142
case PLAYER_COL_RWALL
143
CallFunction(Player_Hit)
144
145
// [Fallthrough to below, for more collision checks]
146
147
case PLAYER_COL_ROOF
148
PlayerObjectCollision(C_TOUCH, -16, -8, 16, 9)
149
150
if CheckResult == true
151
if Player.State != Player_State_Hurt
152
TempValue3 = Player.XVelocity
153
if TempValue3 < 0
154
FlipSign(TempValue3)
155
end if
156
157
if TempValue3 < 0x60000
158
if Player.Gravity == GRAVITY_GROUND
159
CallFunction(Player_Kill)
160
end if
161
else
162
if Player.Gravity == GRAVITY_GROUND
163
CallFunction(Player_Hit)
164
end if
165
end if
166
else
167
Player.YPos = TempValue2
168
end if
169
else
170
Player.YPos = TempValue2
171
172
if Player.Gravity == GRAVITY_GROUND
173
CallFunction(Player_Hit)
174
end if
175
end if
176
break
177
178
end switch
179
180
// Now we can restore the Object back to its normal position
181
Object.XPos = TempValue0
182
Object.YPos = TempValue1
183
184
end sub
185
186
187
sub ObjectDraw
188
// Draw the platform post frame
189
DrawSprite(0)
190
191
// Draw all the chains
192
TempValue0 = 0
193
TempValue1 = 16
194
while TempValue0 < Object.ChainsNo
195
Cos(TempValue2, Object.Angle)
196
TempValue2 *= TempValue1
197
TempValue2 <<= 7
198
TempValue2 += Object.XPos
199
200
Sin(TempValue3, Object.Angle)
201
TempValue3 *= TempValue1
202
TempValue3 <<= 7
203
TempValue3 += Object.YPos
204
205
DrawSpriteXY(1, TempValue2, TempValue3)
206
207
TempValue0++
208
TempValue1 += 16
209
loop
210
211
// Draw the main platform sprite
212
213
// Find the X component
214
Cos(Object.PlatformX, Object.Angle)
215
Object.PlatformX *= TempValue1
216
Object.PlatformX <<= 7
217
Object.PlatformX += Object.XPos
218
Object.PlatformX &= 0xFFFF0000 // Truncate the value
219
220
// And then find the Y
221
Sin(Object.PlatformY, Object.Angle)
222
Object.PlatformY *= TempValue1
223
Object.PlatformY <<= 7
224
Object.PlatformY += Object.YPos
225
Object.PlatformY &= 0xFFFF0000 // Truncate the value
226
227
DrawSpriteXY(2, Object.PlatformX, Object.PlatformY)
228
229
end sub
230
231
232
sub ObjectStartup
233
234
LoadSpriteSheet("R7/Objects.gif")
235
236
// Pivot Ball Frame
237
SpriteFrame(-8, -8, 16, 16, 34, 1)
238
239
// Chain Frame
240
SpriteFrame(-8, -8, 16, 16, 51, 1)
241
242
// Platform Frame
243
SpriteFrame(-32, -8, 64, 16, 68, 1)
244
245
ArrayPos0 = 32
246
while ArrayPos0 < 1056
247
if Object[ArrayPos0].Type == TypeName[R Platform]
248
if Object[ArrayPos0].PropertyValue == HALF_CW_BOTTOM
249
Object[ArrayPos0].State = RPLATFORM_BOTTOM180
250
Object[ArrayPos0].ChainsNo = 2
251
end if
252
253
if Object[ArrayPos0].PropertyValue == HALF_CW_TOP
254
Object[ArrayPos0].State = RPLATFORM_TOP180
255
Object[ArrayPos0].ChainsNo = 2
256
end if
257
258
if Object[ArrayPos0].PropertyValue == FULL_CW_SLOW
259
Object[ArrayPos0].State = RPLATFORM_FULL_CW_SLOWAPEX
260
Object[ArrayPos0].ChainsNo = 5
261
end if
262
263
if Object[ArrayPos0].PropertyValue == HALF_CW_RIGHT
264
Object[ArrayPos0].State = RPLATFORM_RIGHT180
265
Object[ArrayPos0].ChainsNo = 2
266
end if
267
268
if Object[ArrayPos0].PropertyValue == FULL_CW
269
Object[ArrayPos0].State = RPLATFORM_FULL_CW
270
Object[ArrayPos0].ChainsNo = 2
271
end if
272
273
if Object[ArrayPos0].PropertyValue == FULL_CCW
274
Object[ArrayPos0].State = RPLATFORM_FULL_CCW
275
Object[ArrayPos0].ChainsNo = 2
276
end if
277
end if
278
279
ArrayPos0++
280
loop
281
282
end sub
283
284
285
// ========================
286
// Editor Subs
287
// ========================
288
289
// the property value format seems to be
290
// lowest three bits - chain length
291
// above - multiplier idk
292
// but thanks to the way the object's set up, it doesn't truly work like that
293
// it is worth noting though, that while rsdk uses this rigid and kinda fake system, cd 93 seems to *actually* follow the format so that's interesting
294
295
sub RSDKEdit
296
if Editor.ReturnVariable == true
297
switch Editor.VariableID
298
case EDIT_VAR_PROPVAL // Property Value
299
CheckResult = Object.PropertyValue
300
break
301
case 0 // Type
302
CheckResult = Object.PropertyValue
303
break
304
end switch
305
else
306
switch Editor.VariableID
307
case EDIT_VAR_PROPVAL // Property Value
308
Object.PropertyValue = Editor.VariableValue
309
break
310
case 0 // Type
311
Object.PropertyValue = Editor.VariableValue
312
break
313
end switch
314
end if
315
end sub
316
317
// TODO: probably best to rearrange the temps used here, at the moment it's quite the mess...
318
319
sub RSDKDraw
320
321
TempValue4 = 0 // chainsNo
322
TempValue1 = 0 // behaviour
323
324
switch Object.PropertyValue
325
case 19
326
default
327
TempValue4 = 2
328
TempValue1 = 5
329
break
330
case 35
331
TempValue4 = 2
332
TempValue1 = 3
333
break
334
case 54
335
TempValue4 = 5
336
TempValue1 = 0
337
break
338
case 67
339
TempValue4 = 2
340
TempValue1 = 4
341
break
342
case 99
343
TempValue4 = 2
344
TempValue1 = 1
345
break
346
case 115
347
TempValue4 = 2
348
TempValue1 = 2
349
break
350
end switch
351
352
switch TempValue1
353
case 0
354
case 1
355
case 2
356
case 5
357
Object.Angle = 640; break
358
case 3
359
Object.Angle = 896; break
360
case 4
361
Object.Angle = 512; break
362
end switch
363
364
DrawSprite(0)
365
366
TempValue0 = 0
367
TempValue1 = 16
368
while TempValue0 < TempValue4
369
Cos(TempValue2, Object.Angle)
370
TempValue2 *= TempValue1
371
TempValue2 <<= 7
372
TempValue2 += Object.XPos
373
374
Sin(TempValue3, Object.Angle)
375
TempValue3 *= TempValue1
376
TempValue3 <<= 7
377
TempValue3 += Object.YPos
378
379
DrawSpriteXY(1, TempValue2, TempValue3)
380
381
TempValue0++
382
TempValue1 += 16
383
loop
384
385
Cos(TempValue0, Object.Angle)
386
TempValue0 *= TempValue1
387
TempValue0 <<= 7
388
TempValue0 += Object.XPos
389
TempValue0 &= 0xFFFF0000 // Truncate the value
390
391
Sin(TempValue2, Object.Angle)
392
TempValue2 *= TempValue1
393
TempValue2 <<= 7
394
TempValue2 += Object.YPos
395
TempValue2 &= 0xFFFF0000 // Truncate the value
396
397
DrawSpriteXY(2, TempValue0, TempValue2)
398
end sub
399
400
401
sub RSDKLoad
402
LoadSpriteSheet("R7/Objects.gif")
403
SpriteFrame(-8, -8, 16, 16, 34, 1) // Pivot Ball
404
SpriteFrame(-8, -8, 16, 16, 51, 1) // Chain
405
SpriteFrame(-32, -8, 64, 16, 68, 1) // Platform
406
407
// TODO: actual names lol
408
AddEditorVariable("Type")
409
SetActiveVariable("Type")
410
AddEnumVariable("why do", 19)
411
AddEnumVariable("the values", 35)
412
AddEnumVariable("jump around", 54)
413
AddEnumVariable("its so", 67)
414
AddEnumVariable("wierd", 99)
415
AddEnumVariable("ratio", 115)
416
end sub
417
418