Skip to content

Commit

Permalink
implement solo sniffamizer=pool
Browse files Browse the repository at this point in the history
  • Loading branch information
black-sliver committed Mar 28, 2024
1 parent 9e80d4b commit 7a47596
Show file tree
Hide file tree
Showing 8 changed files with 1,012 additions and 243 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ow-patch
*.res
gen.h
gourds.h
sniff.h

#releases
old
Expand All @@ -25,6 +26,10 @@ rls
release.sh
test-code.sh

#temps
.~lock*
/raw-data

#python cache
__pycache__
*.pyc
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ else
$(PYTHON) gourds2h.py $@ gourds.csv "$(ROM)"
endif
endif
ifneq (,$(wildcard gourds.csv)) # assume we have a pre-built sniff.h if sniff.csv is missing
sniff.h: sniff.csv sniff2h.py util.py
ifeq ($(strip $(ROM)),)
$(PYTHON) sniff2h.py $@ sniff.csv
else
$(PYTHON) sniff2h.py $@ sniff.csv "$(ROM)"
endif
endif

main.res: icon.ico
echo "id ICON $(^)" | $(WIN32WINDRES) -O coff -o $@
Expand Down Expand Up @@ -123,6 +131,9 @@ endif
ifneq (,$(wildcard gourds.csv)) # only if not pre-built
rm -rf gourds.h
endif
ifneq (,$(wildcard sniff.csv)) # only if not pre-built
rm -rf sniff.h
endif

test: $(EXE)
ifeq ($(strip $(ROM)),)
Expand Down
42 changes: 40 additions & 2 deletions data.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ enum check_tree_item_type {
CHECK_GOURD,
CHECK_EXTRA,
CHECK_TRAP,
CHECK_SNIFF,
CHECK_NPC,
CHECK_RULE,
};
Expand Down Expand Up @@ -494,9 +495,11 @@ static const check_tree_item blank_check_tree[] = {
{0, CHECK_RULE,P_BRONZE_AXE_PLUS, 0, 0, REQ1(P_REAL_BRONZE_AXE_PLUS), PVD1(P_BRONZE_AXE_PLUS)},
// Energy core fragments conversion; will be updated in main
{0, CHECK_RULE,P_ENERGY_CORE, 0, 0, REQ1N(-1, P_CORE_FRAGMENT), NOTHING_PROVIDED},
// Gourd checks included from generated gourds.h
#define CHECK_TREE
// Gourd checks included from generated gourds.h
#include "gourds.h"
// Sniff checks included from generated sniff.h
#include "sniff.h"
#undef CHECK_TREE
};

Expand Down Expand Up @@ -532,9 +535,11 @@ static const drop_tree_item drops[] = {
{CHECK_BOSS,DIAMOND_EYE_DROP_IDX, PVD1(P_DE)},
{CHECK_BOSS,DINO_DROP_IDX, PVD1(P_ARMOR)},
{CHECK_BOSS,BAZOOKA_DROP_IDX, PVD1(P_BAZOOKA)},
// Gourd drops with progression included from generated gourds.h
#define DROP_TREE
// Gourd drops with progression included from generated gourds.h
#include "gourds.h"
// Sniff drops with progression included from generated sniff.h
#include "sniff.h"
#undef DROP_TREE
};

Expand Down Expand Up @@ -574,6 +579,7 @@ static inline void drop_progress(const drop_tree_item* drop, int* progress)
static inline const drop_tree_item* get_drop(enum check_tree_item_type type, uint16_t idx)
{
// NOTE: since we only have progression in drops, always iterating over everything is fast
// this could still be sped up using binary search
for (size_t i=0; i<ARRAY_SIZE(drops); i++)
if (drops[i].type == type && drops[i].index == idx) return drops+i;
return NULL;
Expand Down Expand Up @@ -751,6 +757,16 @@ static uint32_t get_drop_setup_target(enum check_tree_item_type type, uint16_t i
uint32_t addr = trap_data[idx].setup;
return (addr & 0x7fff) | ((((addr&0x7fffff)-0x120000) >> 1) & 0xff8000);
}
if (type == CHECK_SNIFF && ((idx >= 0x200 && idx <= 0x215) || idx == 0x1f)) {
// sniff items are encoded using the in-game item IDs, making the above
// statement somewhat false
if (idx == 0x1f) // iron bracer is an odd sniff item, we put it after ingredients
idx = 0x16;
else
idx -= 0x200;
uint32_t addr = 0x30ff00 + 6 * idx;
return (addr & 0x7fff) | ((((addr&0x7fffff)-0x120000) >> 1) & 0xff8000);
}
assert(0);
return 0;
}
Expand All @@ -762,6 +778,23 @@ static uint32_t get_drop_setup_target_from_packed(uint16_t packed)
return get_drop_setup_target(type, idx);
}

static const char* get_item_name(uint16_t item)
{
// order of mushroom and mud peppers are swapped in inventory vs item id
if (item == 0x200 + MUSHROOM)
return ingredient_names[MUD_PEPPER];
if (item == 0x200 + MUD_PEPPER)
return ingredient_names[MUSHROOM];
// other ingredients are in order starting at 0x200
if (item >= 0x200 && item < 0x200 + ARRAY_SIZE(ingredient_names))
return ingredient_names[item - 0x200];
// special sniff spot item
if (item == 0x41f)
return "Iron Bracer";
assert(0);
return "";
}

static const char* get_drop_name(enum check_tree_item_type type, uint16_t idx)
{
if (type == CHECK_NONE) return "Remote";
Expand All @@ -770,6 +803,8 @@ static const char* get_drop_name(enum check_tree_item_type type, uint16_t idx)
if (type == CHECK_BOSS && idx<ARRAY_SIZE(boss_drop_names)) return boss_drop_names[idx];
if (type == CHECK_EXTRA && idx<ARRAY_SIZE(extra_data)) return extra_data[idx].name;
if (type == CHECK_TRAP && idx<ARRAY_SIZE(trap_data)) return trap_data[idx].name;
if (type == CHECK_SNIFF) return get_item_name((idx < 0x100 && idx > 1) ? (0x400 + idx) : idx);
printf("Couldn't get name for %d 0x%03x\n", type, idx);
assert(0);
return "";
}
Expand Down Expand Up @@ -802,6 +837,9 @@ static bool is_real_progression_from_packed(uint16_t packed)
enum check_tree_item_type type = (enum check_tree_item_type)(packed>>10);
uint16_t idx = packed&0x3ff;

if (type == CHECK_SNIFF)
return false; // manual speed up until we have smarter search

for (size_t i=0; i<ARRAY_SIZE(drops); i++) {
const drop_tree_item* drop = drops+i;
if (drop->type == type && drop->index == idx)
Expand Down
Loading

0 comments on commit 7a47596

Please sign in to comment.