Path: blob/master/Sonic 2/Scripts/Enemies/Sol.txt
1479 views
// ----------------------------------1// RSDK Project: Sonic 22// Script Description: Sol Object3// Script Author: Christian Whitehead/Simon Thomley4// Unpacked by Rubberduckycooly's script unpacker5// ----------------------------------67// ========================8// Aliases9// ========================1011private alias object.value0 : object.unused // Set to 0, but never used again...12private alias object.value1 : object.activeFireballs // Bitfield, bits 1-4 are either true or false for the state of each of the Sol's 4 fireballs13private alias object.value2 : object.startPos.x14private alias object.value3 : object.fireOrbs // true if the Sol should attack the player (always true)15private alias object.value4 : object.targetPlayer16private alias object.value5 : object.backupTargetPlayer // if we cant target any players, target the last player detected (or P1 if none)17private alias object.value6 : object.targetPlayerDistance18private alias object.value7 : object.fireballFrame19private alias object.value8 : object.fireballFrameTimer2021private alias 0 : SOL_AWAITPLAYER22private alias 1 : SOL_FIREFIREBALLS23private alias 2 : SOL_NOFIREBALLS24private alias 3 : SOL_FIREBALL2526// Player Aliases27private alias object.xpos : player.xpos28private alias object.ypos : player.ypos2930private alias object.value40 : player.hitboxLeft31private alias object.value38 : player.hitboxTop32private alias object.value41 : player.hitboxRight33private alias object.value39 : player.hitboxBottom343536// ========================37// Function Declarations38// ========================3940reserve function Sol_DebugDraw41reserve function Sol_DebugSpawn42reserve function Sol_CheckColFull43reserve function Sol_CheckColFireball44reserve function Sol_CheckOffScreen454647// ========================48// Function Definitions49// ========================5051private function Sol_DebugDraw52DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)53end function545556private function Sol_DebugSpawn57CreateTempObject(TypeName[Sol], 0, object.xpos, object.ypos)58object[tempObjectPos].startPos.x = object[tempObjectPos].xpos59object[tempObjectPos].activeFireballs = 1560object[tempObjectPos].fireOrbs = true61if object[tempObjectPos].propertyValue == 062object[tempObjectPos].direction = FLIP_NONE63object[tempObjectPos].xvel = -0x400064else65object[tempObjectPos].direction = FLIP_X66object[tempObjectPos].xvel = 0x400067end if68end function697071private function Sol_CheckColFull72// Called to check for collision of full entity (namely main Sol along with its fireballs)7374// First check collision with the fireballs75temp0 = 076temp7 = object.angle77temp1 = object.xpos78temp2 = object.ypos79while temp0 < 480GetBit(temp6, object.activeFireballs, temp0)81if temp6 == true82Cos256(object.xpos, temp7)83object.xpos <<= 1284object.xpos += temp18586Sin256(object.ypos, temp7)87object.ypos <<= 1288object.ypos += temp28990foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)91BoxCollisionTest(C_TOUCH, object.entityPos, -4, -4, 4, 4, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)92if checkResult == true93CallFunction(Player_FireHit)94end if95next96end if97temp7 += 0x4098temp7 &= 0xFF99temp0++100loop101102// Then check collision with the Sol itself103object.xpos = temp1104object.ypos = temp2105foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)106BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)107if checkResult == true108CallFunction(Player_BadnikBreak)109end if110next111end function112113114private function Sol_CheckColFireball115// Called to check collision ONLY with the fireball, this is called from the child fireball object, separate from the actual parent object Sol116foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)117BoxCollisionTest(C_TOUCH, object.entityPos, -4, -4, 4, 4, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)118if checkResult == true119CallFunction(Player_FireHit)120end if121next122end function123124125private function Sol_CheckOffScreen126if object.outOfBounds == true127temp0 = object.xpos128object.xpos = object.startPos.x129if object.outOfBounds == true130// Reset the Sol131132object.xpos = object.startPos.x133object.activeFireballs = 15134if object.propertyValue == 0135object.direction = FLIP_NONE136object.xvel = -0x4000137else138object.direction = FLIP_X139object.xvel = 0x4000140end if141object.unused = 0142object.animationTimer = 0143object.priority = PRIORITY_BOUNDS144object.state = SOL_AWAITPLAYER145object.angle = 0146else147object.xpos = temp0148end if149end if150end function151152153// ========================154// Events155// ========================156157event ObjectUpdate158switch object.state159case SOL_AWAITPLAYER160object.priority = PRIORITY_ACTIVE161object.xpos += object.xvel162163if object.direction == FLIP_NONE164object.angle++165else166object.angle--167end if168object.angle &= 0xFF169CallFunction(Sol_CheckColFull)170171if object.fireOrbs == true172// (Attempt to) find a target player in order to throw fireballs at them173object.targetPlayerDistance = 0x7FFFFFFF174object.targetPlayer = 0xFFFF175object.backupTargetPlayer = 0176foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)177temp0 = player[currentPlayer].ypos178temp0 -= object.ypos179Abs(temp0)180if temp0 < object.targetPlayerDistance181object.targetPlayerDistance = temp0182object.backupTargetPlayer = currentPlayer183end if184185if temp0 < 0x400000186if object.targetPlayer != 0xFFFF187arrayPos0 = object.targetPlayer188temp0 = player[currentPlayer].xpos189temp0 -= object.xpos190Abs(temp0)191temp1 = object[arrayPos0].xpos192temp1 -= object.xpos193Abs(temp1)194if temp0 < temp1195object.targetPlayer = currentPlayer196end if197else198object.targetPlayer = currentPlayer199end if200end if201next202203if object.targetPlayer != 0xFFFF204arrayPos0 = object.targetPlayer205temp0 = object.xpos206temp0 -= object[arrayPos0].xpos207Abs(temp0)208if temp0 <= 0x800000209object.state = SOL_FIREFIREBALLS210211// Frame 1 is just a dupe of frame 0, this doesn't matter much212object.frame = 1213end if214else215arrayPos0 = object.backupTargetPlayer216end if217218if object[arrayPos0].xpos < object.xpos219object.direction = FLIP_NONE220object.xvel = -0x4000221else222object.direction = FLIP_X223object.xvel = 0x4000224end if225end if226CallFunction(Sol_CheckOffScreen)227break228229case SOL_FIREFIREBALLS230object.xpos += object.xvel231if object.direction == FLIP_NONE232object.angle++233else234object.angle--235end if236object.angle &= 0xFF237238temp0 = 0239temp7 = object.angle240while temp0 < 4241if temp7 == 64242GetBit(temp6, object.activeFireballs, temp0)243if temp6 == true244Cos256(temp1, temp7)245temp1 <<= 12246temp1 += object.xpos247Sin256(temp2, temp7)248temp2 <<= 12249temp2 += object.ypos250SetBit(object.activeFireballs, temp0, false)251CreateTempObject(TypeName[Sol], 0, temp1, temp2)252object[tempObjectPos].state = SOL_FIREBALL253object[tempObjectPos].fireballFrameTimer = object.fireballFrameTimer254object[tempObjectPos].fireballFrame = object.fireballFrame255if object.direction == FLIP_NONE256object[tempObjectPos].xvel = -0x20000257else258object[tempObjectPos].xvel = 0x20000259end if260end if261end if262temp7 += 64263temp7 &= 255264temp0++265loop266267CallFunction(Sol_CheckColFull)268if object.activeFireballs == false269object.state = SOL_NOFIREBALLS270if object.direction == FLIP_NONE271object.xvel = -0x4000272else273object.xvel = 0x4000274end if275end if276277if object.animationTimer < 16278object.animationTimer++279else280// Frame 2 is just a dupe of frame 0 (just like frame 1) so this doesn't matter much281object.frame = 2282end if283CallFunction(Sol_CheckOffScreen)284break285286case SOL_NOFIREBALLS287object.xpos += object.xvel288CallFunction(Sol_CheckColFull)289CallFunction(Sol_CheckOffScreen)290break291292case SOL_FIREBALL293object.xpos += object.xvel294CallFunction(Sol_CheckColFireball)295if object.outOfBounds == true296object.type = TypeName[Blank Object]297end if298break299300end switch301302object.fireballFrameTimer++303if object.fireballFrameTimer >= 12304object.fireballFrameTimer = 0305end if306307object.fireballFrame = object.fireballFrameTimer308object.fireballFrame /= 6309object.fireballFrame += 3310end event311312313event ObjectDraw314switch object.state315case SOL_AWAITPLAYER316case SOL_FIREFIREBALLS317temp0 = 0318temp7 = object.angle319while temp0 < 4320GetBit(temp6, object.activeFireballs, temp0)321if temp6 == true322Cos256(temp1, temp7)323temp1 <<= 12324temp1 += object.xpos325Sin256(temp2, temp7)326temp2 <<= 12327temp2 += object.ypos328DrawSpriteXY(object.fireballFrame, temp1, temp2)329end if330temp7 += 0x40331temp7 &= 0xFF332temp0++333loop334335DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)336break337338case SOL_NOFIREBALLS339DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)340break341342case SOL_FIREBALL343DrawSprite(object.fireballFrame)344break345346end switch347end event348349350event ObjectStartup351CheckCurrentStageFolder("Zone05")352if checkResult == true353LoadSpriteSheet("HTZ/Objects.gif")354355// Normal Frame356SpriteFrame(-8, -8, 16, 16, 91, 222)357358// Getting Angry Frames (Same as above)359SpriteFrame(-8, -8, 16, 16, 91, 222)360SpriteFrame(-8, -8, 16, 16, 91, 222)361362// Fireball Frames363SpriteFrame(-8, -8, 16, 16, 1, 33)364SpriteFrame(-8, -8, 16, 16, 18, 33)365else366LoadSpriteSheet("MBZ/Objects.gif")367368// This SpriteFrame data is just duplicated from HTZ's sheet, so it appears broken when loaded369370// Normal Frame371SpriteFrame(-8, -8, 16, 16, 91, 222)372373// Getting Angry Frames (Same as above)374SpriteFrame(-8, -8, 16, 16, 91, 222)375SpriteFrame(-8, -8, 16, 16, 91, 222)376377// Fireball Frames378SpriteFrame(-8, -8, 16, 16, 1, 33)379SpriteFrame(-8, -8, 16, 16, 18, 33)380end if381382foreach (TypeName[Sol], arrayPos0, ALL_ENTITIES)383object[arrayPos0].startPos.x = object[arrayPos0].xpos384object[arrayPos0].activeFireballs = 15385object[arrayPos0].fireOrbs = true386if object[arrayPos0].propertyValue == 0387object[arrayPos0].direction = FLIP_NONE388object[arrayPos0].xvel = -0x4000389else390object[arrayPos0].direction = FLIP_X391object[arrayPos0].xvel = 0x4000392end if393next394395SetTableValue(TypeName[Sol], DebugMode_ObjCount, DebugMode_TypesTable)396SetTableValue(Sol_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)397SetTableValue(Sol_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)398DebugMode_ObjCount++399end event400401402// ========================403// Editor Events404// ========================405406event RSDKEdit407if editor.returnVariable == true408switch editor.variableID409case EDIT_VAR_PROPVAL // property value410checkResult = object.propertyValue411break412413case 0 // direction414checkResult = object.propertyValue415break416417end switch418else419switch editor.variableID420case EDIT_VAR_PROPVAL // property value421object.propertyValue = editor.variableValue422break423424case 0 // direction425object.propertyValue = editor.variableValue426break427428end switch429end if430end event431432433event RSDKDraw434GetBit(object.direction, object.propertyValue, 0)435436temp0 = 0437temp3 = 0438while temp0 < 4439Cos256(temp1, temp3)440temp1 <<= 12441temp1 += object.xpos442443Sin256(temp2, temp3)444temp2 <<= 12445temp2 += object.ypos446447DrawSpriteXY(3, temp1, temp2)448temp3 += 0x40449temp3 &= 0xFF450temp0++451loop452453DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)454end event455456457event RSDKLoad458CheckCurrentStageFolder("Zone05")459if checkResult == true460LoadSpriteSheet("HTZ/Objects.gif")461SpriteFrame(-8, -8, 16, 16, 91, 222)462SpriteFrame(-8, -8, 16, 16, 91, 222)463SpriteFrame(-8, -8, 16, 16, 91, 222)464SpriteFrame(-8, -8, 16, 16, 1, 33)465SpriteFrame(-8, -8, 16, 16, 18, 33)466else467LoadSpriteSheet("MBZ/Objects.gif")468469// Still broken stuff here :(470SpriteFrame(-8, -8, 16, 16, 91, 222)471SpriteFrame(-8, -8, 16, 16, 91, 222)472SpriteFrame(-8, -8, 16, 16, 91, 222)473SpriteFrame(-8, -8, 16, 16, 1, 33)474SpriteFrame(-8, -8, 16, 16, 18, 33)475end if476477AddEditorVariable("direction")478SetActiveVariable("direction")479AddEnumVariable("Left", 0)480AddEnumVariable("Right", 1)481end event482483484