Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-1-Sonic-2-2013-Script-Decompilation
Path: blob/master/Sonic 1/Scripts/Mission/ReviveEnemy.txt
1483 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Revive Enemy/ReviveEnemy Object
4
// Script Author: Christian Whitehead/Simon Thomley
5
// Unpacked by Rubberduckycooly's script unpacker
6
// ----------------------------------
7
8
// This Object is used in several missions where Badniks are to respawn
9
// It should be paired with one of the Revive[*] Badnik objects as well
10
// Do note, however, that this Object name's itself varies between zones - sometimes it's Revive Enemy while other times it's ReviveEnemy, note the space (or lack thereof) but it doesn't really matter
11
12
// ========================
13
// Aliases
14
// ========================
15
16
// To avoid overlap with an object's normal values, this Object's values start descending
17
private alias object.value47 : object.backupType
18
private alias object.value46 : object.backupState
19
20
private alias object.value45 : object.timeCheckpoint
21
22
// A pair of other backup values for the object, only used by Caterkillers it seems
23
private alias object.value44 : object.backupvalueA
24
private alias object.value43 : object.backupvalueB
25
26
// And then this value starts all the way at the beginning, unlike the others
27
// An object's timer doesn't really need to be preserved between respawns though, so I suppose overlapping here is fine
28
private alias object.value0 : object.target
29
30
// States
31
private alias 0: REVIVE_CHECKENEMY
32
private alias 1: REVIVE_STORETIME
33
private alias 2: REVIVE_IDLE
34
private alias 3: REVIVE_REVIVEENEMY
35
36
37
// ========================
38
// Function Declarations
39
// ========================
40
41
reserve function ReviveEnemy_CheckOutOfRange
42
reserve function ReviveEnemy_GetTotalTime
43
44
45
// ========================
46
// Function Definitions
47
// ========================
48
49
private function ReviveEnemy_CheckOutOfRange
50
// This function is called to see if the current Object is out of range, and safe to be restored
51
// It returns the result in checkResult
52
53
temp1 = object.ixpos
54
temp1 -= screen.xoffset
55
CheckLower(temp1, 0)
56
temp0 = checkResult
57
58
CheckGreater(temp1, screen.xsize)
59
temp0 |= checkResult
60
61
temp1 = object.iypos
62
temp1 -= screen.yoffset
63
CheckLower(temp1, 0)
64
temp0 |= checkResult
65
66
CheckGreater(temp1, screen.ysize)
67
checkResult |= temp0
68
end function
69
70
71
private function ReviveEnemy_GetTotalTime
72
// This function gets the current total time, in seconds
73
// Return value is temp0
74
75
temp0 = stage.minutes
76
temp0 *= 60
77
temp0 += stage.seconds
78
end function
79
80
81
// ========================
82
// Events
83
// ========================
84
85
event ObjectUpdate
86
switch object.state
87
case REVIVE_CHECKENEMY
88
// Focus on the badnik that spawned this object
89
arrayPos0 = object.target
90
91
if object[arrayPos0].type == TypeName[Blank Object] // See if the badnik's been destroyed
92
// If it is, then turn it into a Revive Enemy Object and copy loads of values
93
94
object[arrayPos0].type = TypeName[Revive Enemy]
95
object[arrayPos0].xpos = object.xpos
96
object[arrayPos0].ypos = object.ypos
97
object[arrayPos0].propertyValue = object.propertyValue
98
object[arrayPos0].priority = PRIORITY_ACTIVE
99
object[arrayPos0].state = REVIVE_STORETIME
100
object[arrayPos0].backupType = object.backupType
101
object[arrayPos0].backupState = object.backupState
102
object[arrayPos0].backupvalueB = object.backupvalueB
103
object[arrayPos0].backupvalueA = object.backupvalueA
104
end if
105
106
object.type = TypeName[Blank Object]
107
break
108
109
case REVIVE_STORETIME
110
CallFunction(ReviveEnemy_CheckOutOfRange)
111
if checkResult == true
112
// Store the current time
113
CallFunction(ReviveEnemy_GetTotalTime)
114
object.timeCheckpoint = temp0
115
116
// Onwards!
117
object.state = REVIVE_IDLE
118
object.priority = PRIORITY_BOUNDS
119
end if
120
break
121
122
case REVIVE_IDLE
123
// See if it's been 20 seconds since this Enemy was defeated
124
CallFunction(ReviveEnemy_GetTotalTime)
125
temp0 -= object.timeCheckpoint
126
if temp0 >= 20
127
// If it has, then try to restore
128
129
object.state = REVIVE_REVIVEENEMY
130
end if
131
break
132
133
case REVIVE_REVIVEENEMY
134
// It is worth noting, the Object still has default priority when calling this function
135
136
CallFunction(ReviveEnemy_CheckOutOfRange)
137
if checkResult == true
138
// Now, we can restore this Badnik to what it used to be
139
// We're doing it via object.type rather than ResetObjectEntity because we want to preserve this Object's values
140
141
object.type = object.backupType
142
object.state = object.backupState
143
end if
144
break
145
146
end switch
147
end event
148
149
150
// ========================
151
// Editor Events
152
// ========================
153
154
event RSDKDraw
155
DrawSprite(0)
156
end event
157
158
159
event RSDKLoad
160
LoadSpriteSheet("Global/Display.gif")
161
SpriteFrame(-16, -16, 32, 32, 1, 143)
162
163
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
164
end event
165
166