From 8ad6a04bb5addbcb33a3bbd65a9435069092b69b Mon Sep 17 00:00:00 2001 From: Treeki Date: Thu, 29 Mar 2012 04:14:45 +0200 Subject: magic platform hax requested by antnee --- src/magicplatform.cpp | 100 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) (limited to 'src/magicplatform.cpp') diff --git a/src/magicplatform.cpp b/src/magicplatform.cpp index 924d849..e9fa940 100644 --- a/src/magicplatform.cpp +++ b/src/magicplatform.cpp @@ -12,6 +12,10 @@ class daEnMagicPlatform_c : public dEn_c { // Settings u8 rectID, moveSpeed, moveDirection, moveLength; + u8 moveDelay, currentMoveDelay; + + bool doesMoveInfinitely; + float moveMin, moveMax, moveDelta, moveBaseDelta; float *moveTarget; @@ -41,12 +45,87 @@ daEnMagicPlatform_c *daEnMagicPlatform_c::build() { return c; } +extern "C" void HurtMarioBecauseOfBeingSquashed(void *mario, dStageActor_c *squasher, int type); + +static void PhysCB1(daEnMagicPlatform_c *one, dStageActor_c *two) { + if (two->stageActorType != 1) + return; + + // if left/right + if (one->moveDirection <= 1) + return; + + if (one->pos_delta.y > 0.0f) + HurtMarioBecauseOfBeingSquashed(two, one, 1); + else + HurtMarioBecauseOfBeingSquashed(two, one, 9); +} + +static void PhysCB2(daEnMagicPlatform_c *one, dStageActor_c *two) { + if (two->stageActorType != 1) + return; + + // if left/right + if (one->moveDirection <= 1) + return; + + if (one->pos_delta.y < 0.0f) + HurtMarioBecauseOfBeingSquashed(two, one, 2); + else + HurtMarioBecauseOfBeingSquashed(two, one, 10); +} + +static void PhysCB3(daEnMagicPlatform_c *one, dStageActor_c *two, bool unkMaybeNotBool) { + if (two->stageActorType != 1) + return; + + // if left/right + if (one->moveDirection <= 1) + return; + + if (unkMaybeNotBool) { + if (one->pos_delta.x > 0.0f) + HurtMarioBecauseOfBeingSquashed(two, one, 6); + else + HurtMarioBecauseOfBeingSquashed(two, one, 12); + } else { + if (one->pos_delta.x < 0.0f) + HurtMarioBecauseOfBeingSquashed(two, one, 5); + else + HurtMarioBecauseOfBeingSquashed(two, one, 11); + } +} + +static bool PhysCB4(daEnMagicPlatform_c *one, dStageActor_c *two) { + return (one->pos_delta.y > 0.0f); +} + +static bool PhysCB5(daEnMagicPlatform_c *one, dStageActor_c *two) { + return (one->pos_delta.y < 0.0f); +} + +static bool PhysCB6(daEnMagicPlatform_c *one, dStageActor_c *two, bool unkMaybeNotBool) { + if (unkMaybeNotBool) { + if (one->pos_delta.x > 0.0f) + return true; + } else { + if (one->pos_delta.x < 0.0f) + return true; + } + return false; +} + int daEnMagicPlatform_c::onCreate() { rectID = settings & 0xFF; + moveSpeed = (settings & 0xF00) >> 8; moveDirection = (settings & 0x3000) >> 12; moveLength = ((settings & 0xF0000) >> 16) + 1; + moveDelay = ((settings & 0xF00000) >> 20) * 6; + + doesMoveInfinitely = (settings & 0x10000000); + setupMovement(); findSourceArea(); @@ -56,7 +135,11 @@ int daEnMagicPlatform_c::onCreate() { float fHeight = height * 16.0f; physics.setup(this, 0.0f, 0.0f, fWidth, -fHeight, - 0, 0, 0/*&PhysCB1, &PhysCB2, &PhysCB3*/, 1, 0, 0); + &PhysCB1, &PhysCB2, &PhysCB3, 1, 0, 0); + + physics.callback1 = &PhysCB4; + physics.callback2 = &PhysCB5; + physics.callback3 = &PhysCB6; physics.addToList(); @@ -77,6 +160,9 @@ int daEnMagicPlatform_c::onExecute() { updateTilePositions(); physics.update(); + if (doesMoveInfinitely) + checkZoneBoundaries(0); + return 1; } @@ -119,6 +205,8 @@ void daEnMagicPlatform_c::setupMovement() { } else { isMoving = false; } + + currentMoveDelay = 0; } void daEnMagicPlatform_c::handleMovement() { @@ -145,12 +233,21 @@ void daEnMagicPlatform_c::handleMovement() { if (!isMoving) return; + if (currentMoveDelay > 0) { + currentMoveDelay--; + return; + } + // Do it bool goesForward = (moveDelta > 0.0f); bool reachedEnd = false; *moveTarget += moveDelta; + // if we're set to move infinitely, never stop + if (doesMoveInfinitely) + return; + if (goesForward) { if (*moveTarget >= moveMax) { *moveTarget = moveMax; @@ -175,6 +272,7 @@ void daEnMagicPlatform_c::handleMovement() { } else { // Otherwise, reverse moveDelta = -moveDelta; + currentMoveDelay = moveDelay; } } } -- cgit v1.2.3