Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Super Mario 64: ItemData class and tables #4321

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
82 changes: 47 additions & 35 deletions worlds/sm64ex/Items.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,59 @@
from BaseClasses import Item
from typing import Dict, NamedTuple, Optional

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be able to just use dict since 3.8/3.9 was dropped

from BaseClasses import Item, ItemClassification

sm64ex_base_id: int = 3626000


class SM64Item(Item):
game: str = "Super Mario 64"


generic_item_table = {
"Power Star": 3626000,
"Basement Key": 3626178,
"Second Floor Key": 3626179,
"Progressive Key": 3626180,
"Wing Cap": 3626181,
"Metal Cap": 3626182,
"Vanish Cap": 3626183,
"1Up Mushroom": 3626184
class SM64ItemData(NamedTuple):
code: Optional[int] = None
classification: ItemClassification = ItemClassification.filler
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do this now too (and remove the Optional import)

Suggested change
code: Optional[int] = None
code: int | None = None


generic_item_data_table: Dict[str, SM64ItemData] = {
"Power Star": SM64ItemData(sm64ex_base_id + 0, ItemClassification.progression_skip_balancing),
"Basement Key": SM64ItemData(sm64ex_base_id + 178, ItemClassification.progression),
"Second Floor Key": SM64ItemData(sm64ex_base_id + 179, ItemClassification.progression),
"Progressive Key": SM64ItemData(sm64ex_base_id + 180, ItemClassification.progression),
"Wing Cap": SM64ItemData(sm64ex_base_id + 181, ItemClassification.progression),
"Metal Cap": SM64ItemData(sm64ex_base_id + 182, ItemClassification.progression),
"Vanish Cap": SM64ItemData(sm64ex_base_id + 183, ItemClassification.progression),
"1Up Mushroom": SM64ItemData(sm64ex_base_id + 184, ItemClassification.filler),
}

action_item_table = {
"Double Jump": 3626185,
"Triple Jump": 3626186,
"Long Jump": 3626187,
"Backflip": 3626188,
"Side Flip": 3626189,
"Wall Kick": 3626190,
"Dive": 3626191,
"Ground Pound": 3626192,
"Kick": 3626193,
"Climb": 3626194,
"Ledge Grab": 3626195
action_item_data_table: Dict[str, SM64ItemData] = {
"Double Jump": SM64ItemData(sm64ex_base_id + 185, ItemClassification.progression),
"Triple Jump": SM64ItemData(sm64ex_base_id + 186, ItemClassification.progression),
"Long Jump": SM64ItemData(sm64ex_base_id + 187, ItemClassification.progression),
"Backflip": SM64ItemData(sm64ex_base_id + 188, ItemClassification.progression),
"Side Flip": SM64ItemData(sm64ex_base_id + 189, ItemClassification.progression),
"Wall Kick": SM64ItemData(sm64ex_base_id + 190, ItemClassification.progression),
"Dive": SM64ItemData(sm64ex_base_id + 191, ItemClassification.progression),
"Ground Pound": SM64ItemData(sm64ex_base_id + 192, ItemClassification.progression),
"Kick": SM64ItemData(sm64ex_base_id + 193, ItemClassification.progression),
"Climb": SM64ItemData(sm64ex_base_id + 194, ItemClassification.progression),
"Ledge Grab": SM64ItemData(sm64ex_base_id + 195, ItemClassification.progression),
}

cannon_item_data_table: Dict[str, SM64ItemData] = {
"Cannon Unlock BoB": SM64ItemData(sm64ex_base_id + 200, ItemClassification.progression),
"Cannon Unlock WF": SM64ItemData(sm64ex_base_id + 201, ItemClassification.progression),
"Cannon Unlock JRB": SM64ItemData(sm64ex_base_id + 202, ItemClassification.progression),
"Cannon Unlock CCM": SM64ItemData(sm64ex_base_id + 203, ItemClassification.progression),
"Cannon Unlock SSL": SM64ItemData(sm64ex_base_id + 207, ItemClassification.progression),
"Cannon Unlock SL": SM64ItemData(sm64ex_base_id + 209, ItemClassification.progression),
"Cannon Unlock WDW": SM64ItemData(sm64ex_base_id + 210, ItemClassification.progression),
"Cannon Unlock TTM": SM64ItemData(sm64ex_base_id + 211, ItemClassification.progression),
"Cannon Unlock THI": SM64ItemData(sm64ex_base_id + 212, ItemClassification.progression),
"Cannon Unlock RR": SM64ItemData(sm64ex_base_id + 214, ItemClassification.progression),
}

cannon_item_table = {
"Cannon Unlock BoB": 3626200,
"Cannon Unlock WF": 3626201,
"Cannon Unlock JRB": 3626202,
"Cannon Unlock CCM": 3626203,
"Cannon Unlock SSL": 3626207,
"Cannon Unlock SL": 3626209,
"Cannon Unlock WDW": 3626210,
"Cannon Unlock TTM": 3626211,
"Cannon Unlock THI": 3626212,
"Cannon Unlock RR": 3626214
item_data_table = {
**generic_item_data_table,
**action_item_data_table,
**cannon_item_data_table
}

item_table = {**generic_item_table, **action_item_table, **cannon_item_table}
item_table = {name: data.code for name, data in item_data_table.items() if data.code is not None}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well add the EoF newline now

Suggested change
item_table = {name: data.code for name, data in item_data_table.items() if data.code is not None}
item_table = {name: data.code for name, data in item_data_table.items() if data.code is not None}

4 changes: 2 additions & 2 deletions worlds/sm64ex/Options.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typing
from dataclasses import dataclass
from Options import DefaultOnToggle, Range, Toggle, DeathLink, Choice, PerGameCommonOptions, OptionSet, OptionGroup
from .Items import action_item_table
from .Items import action_item_data_table

class EnableCoinStars(DefaultOnToggle):
"""Disable to Ignore 100 Coin Stars. You can still collect them, but they don't do anything.
Expand Down Expand Up @@ -124,7 +124,7 @@ class MoveRandomizerActions(OptionSet):
"""Which actions to randomize when Move Randomizer is enabled"""
display_name = "Randomized Moves"
# HACK: Disable randomization for double jump
valid_keys = [action for action in action_item_table if action != 'Double Jump']
valid_keys = [action for action in action_item_data_table if action != 'Double Jump']
default = valid_keys

sm64_options_groups = [
Expand Down
7 changes: 4 additions & 3 deletions worlds/sm64ex/Rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .Options import SM64Options
from .Regions import connect_regions, SM64Levels, sm64_level_to_paintings, sm64_paintings_to_level,\
sm64_level_to_secrets, sm64_secrets_to_level, sm64_entrances_to_level, sm64_level_to_entrances
from .Items import action_item_table
from .Items import action_item_data_table

def shuffle_dict_keys(world, dictionary: dict) -> dict:
keys = list(dictionary.keys())
Expand Down Expand Up @@ -372,8 +372,9 @@ def parse_token(self, token: str, cannon_name: str) -> Union[str, bool]:
item = self.token_table.get(token, None)
if not item:
raise Exception(f"Invalid token: '{item}'")
if item in action_item_table:
if self.move_rando_bitvec & (1 << (action_item_table[item] - action_item_table['Double Jump'])) == 0:
if item in action_item_data_table:
double_jump_bitvec_offset = action_item_data_table['Double Jump'].code
if self.move_rando_bitvec & (1 << (action_item_data_table[item].code - double_jump_bitvec_offset)) == 0:
# This action item is not randomized.
return True
return item
Expand Down
22 changes: 9 additions & 13 deletions worlds/sm64ex/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typing
import os
import json
from .Items import item_table, action_item_table, cannon_item_table, SM64Item
from .Items import item_data_table, action_item_data_table, cannon_item_data_table, item_table, SM64Item
from .Locations import location_table, SM64Location
from .Options import sm64_options_groups, SM64Options
from .Rules import set_rules
Expand Down Expand Up @@ -54,9 +54,10 @@ def generate_early(self):
max_stars -= 15
self.move_rando_bitvec = 0
if self.options.enable_move_rando:
double_jump_bitvec_offset = action_item_data_table['Double Jump'].code
for action in self.options.move_rando_actions.value:
max_stars -= 1
self.move_rando_bitvec |= (1 << (action_item_table[action] - action_item_table['Double Jump']))
self.move_rando_bitvec |= (1 << (action_item_data_table[action].code - double_jump_bitvec_offset))
if self.options.exclamation_boxes:
max_stars += 29
self.number_of_stars = min(self.options.amount_of_stars, max_stars)
Expand Down Expand Up @@ -89,14 +90,8 @@ def set_rules(self):
'entrance', self.player)

def create_item(self, name: str) -> Item:
item_id = item_table[name]
if name == "1Up Mushroom":
classification = ItemClassification.filler
elif name == "Power Star":
classification = ItemClassification.progression_skip_balancing
else:
classification = ItemClassification.progression
item = SM64Item(name, classification, item_id, self.player)
data = item_data_table[name]
item = SM64Item(name, data.classification, data.code, self.player)

return item

Expand All @@ -116,11 +111,12 @@ def create_items(self):
self.multiworld.itempool += [self.create_item(cap_name) for cap_name in ["Wing Cap", "Metal Cap", "Vanish Cap"]]
# Cannons
if (self.options.buddy_checks):
self.multiworld.itempool += [self.create_item(name) for name, id in cannon_item_table.items()]
self.multiworld.itempool += [self.create_item(cannon_name) for cannon_name in cannon_item_data_table.keys()]
# Moves
double_jump_bitvec_offset = action_item_data_table['Double Jump'].code
self.multiworld.itempool += [self.create_item(action)
for action, itemid in action_item_table.items()
if self.move_rando_bitvec & (1 << itemid - action_item_table['Double Jump'])]
for action, itemdata in action_item_data_table.items()
if self.move_rando_bitvec & (1 << itemdata.code - double_jump_bitvec_offset)]

def generate_basic(self):
if not (self.options.buddy_checks):
Expand Down
Loading