Path: blob/master/Sonic 1/Scripts/Mission/ReviveEnemy.txt
1483 views
// ----------------------------------1// RSDK Project: Sonic 12// Script Description: Revive Enemy/ReviveEnemy Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// This Object is used in several missions where Badniks are to respawn8// It should be paired with one of the Revive[*] Badnik objects as well9// 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 matter1011// ========================12// Aliases13// ========================1415// To avoid overlap with an object's normal values, this Object's values start descending16private alias object.value47 : object.backupType17private alias object.value46 : object.backupState1819private alias object.value45 : object.timeCheckpoint2021// A pair of other backup values for the object, only used by Caterkillers it seems22private alias object.value44 : object.backupvalueA23private alias object.value43 : object.backupvalueB2425// And then this value starts all the way at the beginning, unlike the others26// An object's timer doesn't really need to be preserved between respawns though, so I suppose overlapping here is fine27private alias object.value0 : object.target2829// States30private alias 0: REVIVE_CHECKENEMY31private alias 1: REVIVE_STORETIME32private alias 2: REVIVE_IDLE33private alias 3: REVIVE_REVIVEENEMY343536// ========================37// Function Declarations38// ========================3940reserve function ReviveEnemy_CheckOutOfRange41reserve function ReviveEnemy_GetTotalTime424344// ========================45// Function Definitions46// ========================4748private function ReviveEnemy_CheckOutOfRange49// This function is called to see if the current Object is out of range, and safe to be restored50// It returns the result in checkResult5152temp1 = object.ixpos53temp1 -= screen.xoffset54CheckLower(temp1, 0)55temp0 = checkResult5657CheckGreater(temp1, screen.xsize)58temp0 |= checkResult5960temp1 = object.iypos61temp1 -= screen.yoffset62CheckLower(temp1, 0)63temp0 |= checkResult6465CheckGreater(temp1, screen.ysize)66checkResult |= temp067end function686970private function ReviveEnemy_GetTotalTime71// This function gets the current total time, in seconds72// Return value is temp07374temp0 = stage.minutes75temp0 *= 6076temp0 += stage.seconds77end function787980// ========================81// Events82// ========================8384event ObjectUpdate85switch object.state86case REVIVE_CHECKENEMY87// Focus on the badnik that spawned this object88arrayPos0 = object.target8990if object[arrayPos0].type == TypeName[Blank Object] // See if the badnik's been destroyed91// If it is, then turn it into a Revive Enemy Object and copy loads of values9293object[arrayPos0].type = TypeName[Revive Enemy]94object[arrayPos0].xpos = object.xpos95object[arrayPos0].ypos = object.ypos96object[arrayPos0].propertyValue = object.propertyValue97object[arrayPos0].priority = PRIORITY_ACTIVE98object[arrayPos0].state = REVIVE_STORETIME99object[arrayPos0].backupType = object.backupType100object[arrayPos0].backupState = object.backupState101object[arrayPos0].backupvalueB = object.backupvalueB102object[arrayPos0].backupvalueA = object.backupvalueA103end if104105object.type = TypeName[Blank Object]106break107108case REVIVE_STORETIME109CallFunction(ReviveEnemy_CheckOutOfRange)110if checkResult == true111// Store the current time112CallFunction(ReviveEnemy_GetTotalTime)113object.timeCheckpoint = temp0114115// Onwards!116object.state = REVIVE_IDLE117object.priority = PRIORITY_BOUNDS118end if119break120121case REVIVE_IDLE122// See if it's been 20 seconds since this Enemy was defeated123CallFunction(ReviveEnemy_GetTotalTime)124temp0 -= object.timeCheckpoint125if temp0 >= 20126// If it has, then try to restore127128object.state = REVIVE_REVIVEENEMY129end if130break131132case REVIVE_REVIVEENEMY133// It is worth noting, the Object still has default priority when calling this function134135CallFunction(ReviveEnemy_CheckOutOfRange)136if checkResult == true137// Now, we can restore this Badnik to what it used to be138// We're doing it via object.type rather than ResetObjectEntity because we want to preserve this Object's values139140object.type = object.backupType141object.state = object.backupState142end if143break144145end switch146end event147148149// ========================150// Editor Events151// ========================152153event RSDKDraw154DrawSprite(0)155end event156157158event RSDKLoad159LoadSpriteSheet("Global/Display.gif")160SpriteFrame(-16, -16, 32, 32, 1, 143)161162SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")163end event164165166