diff options
author | Colin Noga <Tempus@Spectrum-Song.local> | 2011-08-14 13:38:04 -0500 |
---|---|---|
committer | Colin Noga <Tempus@Spectrum-Song.local> | 2011-08-14 13:38:04 -0500 |
commit | 74a7d023469eb0a5a2dc713c74709b11e1815b8a (patch) | |
tree | 017199545fe6110e2e700907ea393a6654865cb8 /src | |
parent | ead037af2d2665e94ed8d804a1e220c47ba54db9 (diff) | |
parent | 4d482b80241de4512b68bc160dfc29b7e521134d (diff) | |
download | kamek-74a7d023469eb0a5a2dc713c74709b11e1815b8a.tar.gz kamek-74a7d023469eb0a5a2dc713c74709b11e1815b8a.zip |
Merge branch 'level-select' of treeki:newergit/Kamek into level-select
Diffstat (limited to 'src')
-rw-r--r-- | src/poweruphax.S | 38 | ||||
-rw-r--r-- | src/randtiles.cpp | 215 | ||||
-rw-r--r-- | src/randtiles.h | 63 |
3 files changed, 221 insertions, 95 deletions
diff --git a/src/poweruphax.S b/src/poweruphax.S index 9274b78..e028eb9 100644 --- a/src/poweruphax.S +++ b/src/poweruphax.S @@ -16,6 +16,7 @@ .extern continuePlumberSetPowerupTexture .extern doneSettingThePowerupTexture .extern doneSettingThePowerupTexture2 +.extern returnFromPowerupSoundChange #ifndef __MWERKS__ .set r0,0; .set r1,1; .set r2,2; .set r3,3; .set r4,4 @@ -391,16 +392,30 @@ _not19: .global FixPowerupSound FixPowerupSound: - # WARNING! This is a bad, bad, bad hack. - # I was too lazy to add anything to the linker script, so... - - # We branch at 80141334, so our LR is 80141338 - # We need to jump to 80141384 - mflr r3 - addi r3, r3, 0x4C - mtlr r3 + #lis r3, DBString@h + #ori r3, r3, DBString@l + #lwz r4, 0x1090(r29) + #crclr 4*cr1+eq + #bl OSReport + + lwz r5, 0x14DC(r29) # Original powerup + lwz r0, 0x1090(r29) # New powerup + # if NEW is 1 (big) and OLD is not 0 or 3, then play 273 (powerdown) + cmpwi r0, 1 + bne dontConsiderPowerdown + + cmpwi r5, 0 + beq dontConsiderPowerdown + cmpwi r5, 3 + beq dontConsiderPowerdown + # If the player is here, he was downgraded from a higher powerup to Big Mario + # So play the powerdown sound + mr r3, r29 + li r4, 273 + li r5, 0 + b returnFromPowerupSoundChange - lwz r0, 0x1090(r29) +dontConsiderPowerdown: lis r3, PowerupSounds@h ori r3, r3, PowerupSounds@l slwi r4, r0, 2 @@ -408,7 +423,7 @@ FixPowerupSound: mr r3, r29 li r5, 0 - blr + b returnFromPowerupSoundChange .global WeirdAnimLoadHack @@ -719,6 +734,9 @@ I_hammerModelName: PowerupTexDebugStr: .string "Plumber::SetPowerupTexture() called on class %p with texnum %d lr=%p\n" +DBString: + .string "PW:%d\n" + #.global BrosModelFilename #BrosModelFilename: # .string "g3d/bros.brres" diff --git a/src/randtiles.cpp b/src/randtiles.cpp index 0bc2ede..1508200 100644 --- a/src/randtiles.cpp +++ b/src/randtiles.cpp @@ -1,22 +1,193 @@ -#include "randtiles.h" - -u32 djb2(u8 *str) { - u32 hash = 5381; - int c; - - while (c = *str++) - hash = ((hash << 5) + hash) + c; - - return hash; -} - -RandTiles_Section *RandTiles_Search(void *file, u32 nameHash) { - for (int i = 0; i < RandTiles_GetSectionCount(file); i++) { - RandTiles_Section *sect = RandTiles_GetSection(file, i); - - if (sect->nameHash == nameHash) - return sect; - } - - return 0; -} +#include <game.h>
+
+class RandomTileData {
+public:
+ enum Type {
+ CHECK_NONE = 0,
+ CHECK_HORZ = 1,
+ CHECK_VERT = 2,
+ CHECK_BOTH = 3
+ };
+
+ enum Special {
+ SP_NONE = 0,
+ SP_VDOUBLE_TOP = 1,
+ SP_VDOUBLE_BOTTOM = 2
+ };
+
+ class NameList {
+ public:
+ u32 count;
+ u32 offsets[1]; // variable size
+
+ const char *getName(int index) {
+ return ((char*)this) + offsets[index];
+ }
+
+ bool contains(const char *name) {
+ for (int i = 0; i < count; i++) {
+ if (strcmp(name, getName(i)) == 0)
+ return true;
+ }
+
+ return false;
+ }
+ };
+
+ class Entry {
+ public:
+ u8 lowerBound, upperBound;
+ u8 count, type;
+ u32 tileNumOffset;
+
+ u8 *getTileNums() {
+ return ((u8*)this) + tileNumOffset;
+ }
+ };
+
+ class Section {
+ public:
+ u32 nameListOffset;
+ u32 entryCount;
+ Entry entries[1]; // variable size
+
+ NameList *getNameList() {
+ return (NameList*)(((u32)this) + nameListOffset);
+ }
+ };
+
+ u32 magic;
+ u32 sectionCount;
+ u32 offsets[1]; // variable size
+
+ Section *getSection(int id) {
+ return (Section*)(((char*)this) + offsets[id]);
+ }
+
+ Section *getSection(const char *name);
+
+ static RandomTileData *instance;
+};
+
+class RTilemapClass : public TilemapClass {
+public:
+ // NEWER ADDITIONS
+ RandomTileData::Section *sections[4];
+};
+
+RandomTileData::Section *RandomTileData::getSection(const char *name) {
+ for (int i = 0; i < sectionCount; i++) {
+ RandomTileData::Section *sect = getSection(i);
+
+ if (sect->getNameList()->contains(name))
+ return sect;
+ }
+
+ return 0;
+}
+
+
+// Real tile handling code
+
+RandomTileData *RandomTileData::instance = 0;
+
+dDvdLoader_c RandTileLoader;
+
+extern "C" bool RandTileLoadHook() {
+ OSReport("Trying to load...");
+ void *buf = RandTileLoader.load("/NewerRes/RandTiles.bin");
+ if (buf == 0) {
+ OSReport("Failed.\n");
+ return false;
+ } else {
+ OSReport("Successfully loaded RandTiles.bin [%p].\n", buf);
+ RandomTileData::instance = (RandomTileData*)buf;
+ return true;
+ }
+}
+
+
+extern "C" void IdentifyTilesets(RTilemapClass *self) {
+ self->_C0C = 0xFFFFFFFF;
+
+ for (int i = 0; i < 4; i++) {
+ const char *tilesetName = BGDatClass::instance->getTilesetName(self->areaID, i);
+
+ self->sections[i] = RandomTileData::instance->getSection(tilesetName);
+ OSReport("[%d] Chose %p for %s\n", i, self->sections[i], tilesetName);
+ }
+}
+
+extern "C" void TryAndRandomise(RTilemapClass *self, BGRender *bgr) {
+ int fullTile = bgr->tileToPlace & 0x3FF;
+ int tile = fullTile & 0xFF;
+ int tileset = fullTile >> 8;
+
+ RandomTileData::Section *rtSect = self->sections[tileset];
+ if (rtSect == 0)
+ return;
+
+ for (int i = 0; i < rtSect->entryCount; i++) {
+ RandomTileData::Entry *entry = &rtSect->entries[i];
+
+ if (tile >= entry->lowerBound && tile <= entry->upperBound) {
+ // Found it!!
+ // Try to make one until we meet the conditions
+ u8 type = entry->type & 3;
+ u8 special = entry->type >> 2;
+
+ u8 *tileNums = entry->getTileNums();
+ u16 chosen = 0xFF;
+
+ // If it's the top special, then ignore this tile, we'll place that one
+ // once we choose the bottom one
+ if (special == RandomTileData::SP_VDOUBLE_TOP)
+ break;
+
+ u16 *top = 0, *left = 0, *right = 0, *bottom = 0;
+ if (type == RandomTileData::CHECK_HORZ || type == RandomTileData::CHECK_BOTH) {
+ left = self->getPointerToTile((bgr->curX - 1) * 16, bgr->curY * 16);
+ right = self->getPointerToTile((bgr->curX + 1) * 16, bgr->curY * 16);
+ }
+
+ if (type == RandomTileData::CHECK_VERT || type == RandomTileData::CHECK_BOTH) {
+ top = self->getPointerToTile(bgr->curX * 16, (bgr->curY - 1) * 16);
+ bottom = self->getPointerToTile(bgr->curX * 16, (bgr->curY + 1) * 16);
+ }
+
+ int attempts = 0;
+ while (true) {
+ // is there even a point to using that special random function?
+ chosen = (tileset << 8) | tileNums[MakeRandomNumberForTiles(entry->count)];
+
+ // avoid infinite loops
+ attempts++;
+ if (attempts > 5)
+ break;
+
+ if (top != 0 && *top == chosen)
+ continue;
+ if (bottom != 0 && *bottom == chosen)
+ continue;
+ if (left != 0 && *left == chosen)
+ continue;
+ if (right != 0 && *right == chosen)
+ continue;
+ break;
+ }
+
+ bgr->tileToPlace = chosen;
+
+ if (special == RandomTileData::SP_VDOUBLE_BOTTOM) {
+ if (top == 0)
+ top = self->getPointerToTile(bgr->curX * 16, (bgr->curY - 1) * 16);
+
+ *top = (chosen - 0x10);
+ }
+
+ return;
+ }
+ }
+}
+
+
diff --git a/src/randtiles.h b/src/randtiles.h deleted file mode 100644 index 14355da..0000000 --- a/src/randtiles.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef __NEWER_RANDTILES_H -#define __NEWER_RANDTILES_H - -#include <common.h> -#include "fileload.h" - -#define RAND_CHECK_HORZ -#define RAND_CHECK_VERT -#define RAND_CHECK_BOTH - -struct RandTiles_Header { - u32 magic; - u32 sectionCount; -}; - -struct RandTiles_Section { - u32 nameHash; - u32 entryCount; -}; - -struct RandTiles_Entry { - u16 startTile; - u16 endTile; - u8 count; - u8 type; - u16 reserved; - u32 dataOffset; -}; - -inline u32 RandTiles_GetSectionCount(void *file) { - return ((RandTiles_Header*)file)->sectionCount; -} - -inline u32 *RandTiles_GetOffsets(void *file) { - return (u32*)(((RandTiles_Header*)file)+1); -} - -inline RandTiles_Section *RandTiles_GetSection(void *file, int id) { - u32 offs = RandTiles_GetOffsets(file)[id]; - return (RandTiles_Section*)(((char*)file)+offs); -}; - -inline RandTiles_Entry *RandTiles_GetTiles(void *file, RandTiles_Section *section) { - return (RandTiles_Entry*)(section+1); -} - -inline RandTiles_Entry *RandTiles_GetTiles(void *file, int sectionID) { - return (RandTiles_Entry*)(RandTiles_GetSection(file, sectionID)+1); -} - -inline char *RandTiles_GetName(void *file, RandTiles_Section *section) { - return ((char*)file)+section->nameOffset; -} - -inline u16 *RandTiles_GetData(void *file, RandTiles_Entry *entry) { - return (u16*)(((char*)file)+entry->dataOffset); -} - -u32 djb2(u8 *str); -RandTiles_Section *RandTiles_Search(void *file, u32 nameHash); - - -#endif |