From 8d0328b0531a5470b9716e7ac8395f2d6f7e341a Mon Sep 17 00:00:00 2001 From: Treeki Date: Thu, 30 Aug 2012 22:40:32 +0200 Subject: bone piece thing --- NewerProjectKP.yaml | 1 + bonepiece.yaml | 16 ++++++++ src/bonepiece.cpp | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 bonepiece.yaml create mode 100644 src/bonepiece.cpp diff --git a/NewerProjectKP.yaml b/NewerProjectKP.yaml index f099f40..59c03fd 100644 --- a/NewerProjectKP.yaml +++ b/NewerProjectKP.yaml @@ -3,6 +3,7 @@ code_address: 0x808D9000 modules: - processed/prolog.yaml - processed/magicplatform.yaml + - processed/bonepiece.yaml - processed/bugfixes.yaml - processed/koopatlas.yaml - processed/levelnames.yaml diff --git a/bonepiece.yaml b/bonepiece.yaml new file mode 100644 index 0000000..885b461 --- /dev/null +++ b/bonepiece.yaml @@ -0,0 +1,16 @@ +--- +# replaces WM_BOSS_IGGY +source_files: [../src/bonepiece.cpp] +hooks: + - name: BuildBonePiece + type: add_func_pointer + src_addr_pal: 0x80986B48 + target_func: 'daBonePiece_c::build(void)' + + - name: UpdateBonePieceSpriteInfo + type: patch + addr_pal: 0x8030A610 + # -ID- ---- -X Offs- -Y Offs- -RectX1- -RectY1- -RectX2- -RectY2- -1C- -1E- -20- -22- Flag ---- + # Orig 02EB 0000 00000000 00000000 00000000 00000000 00000000 00000000 0000 0000 0000 0000 0000 0000 + data: '0289 0000 00000000 00000000 00000000 00000000 00000100 00000100 0000 0000 0000 0000 0002 0000' + diff --git a/src/bonepiece.cpp b/src/bonepiece.cpp new file mode 100644 index 0000000..57e862e --- /dev/null +++ b/src/bonepiece.cpp @@ -0,0 +1,104 @@ +#include + +class daBonePiece_c : public dStageActor_c { + public: + static daBonePiece_c *build(); + + int onCreate(); + int onExecute(); + int onDraw(); + int onDelete(); + + StandOnTopCollider collider; + + nw4r::g3d::ResFile resFile; + mHeapAllocator_c allocator; + m3d::mdl_c model; +}; + +/*****************************************************************************/ +// Glue Code +daBonePiece_c *daBonePiece_c::build() { + void *buffer = AllocFromGameHeap1(sizeof(daBonePiece_c)); + daBonePiece_c *c = new(buffer) daBonePiece_c; + return c; +} + +int daBonePiece_c::onCreate() { + // load the model + allocator.link(-1, GameHeaps[0], 0, 0x20); + + resFile.data = getResource("lift_torokko", "g3d/t00.brres"); + + static char thing[] = "lift_torokko?"; + thing[0xC] = 'A' + (settings & 3); + + nw4r::g3d::ResMdl resmdl = resFile.GetResMdl(thing); + model.setup(resmdl, &allocator, 0, 1, 0); + SetupTextures_MapObj(&model, 0); + + allocator.unlink(); + + // if rotation is off, do nothing else + if ((settings >> 28) & 1) { + // OK, figure out the rotation + u8 sourceRotation = (settings >> 24) & 0xF; + + // 0 is up. -0x4000 is right, 0x4000 is left ... + s16 rotation; + + // We'll flip it later. + // Thus: 0..7 rotates left (in increments of 0x800), + // 8..15 rotates right (in increments of 0x800 too). + // To specify facing up, well.. just use 0. + + if (sourceRotation < 8) + rotation = (sourceRotation * 0x800) - 0x4000; + else + rotation = (sourceRotation * 0x800) - 0x3800; + + rotation = -rotation; + + rot.z = rotation; + } + + collider.init(this, + /*xOffset=*/0.0f, /*yOffset=*/0.0f, + /*topYOffset=*/0, + /*rightSize=*/16.0f, /*leftSize=*/-16.0f, + /*rotation=*/rot.z, /*_45=*/1 + ); + + collider._47 = 0xA; + collider.flags = 0x80180 | 0xC00; + + collider.addToList(); + + return true; +} + +int daBonePiece_c::onDelete() { + return true; +} + +int daBonePiece_c::onExecute() { + matrix.translation(pos.x, pos.y - 8.0f, pos.z); + matrix.applyRotationYXZ(&rot.x, &rot.y, &rot.z); + + model.setDrawMatrix(matrix); + model.setScale(&scale); + model.calcWorld(false); + + collider.update(); + + return true; +} + +int daBonePiece_c::onDraw() { + model.scheduleForDrawing(); + + return true; +} + + + -- cgit v1.2.3