Skip to content

Commit 776b5fa

Browse files
AlchavlordlouBerserker66
authored
LTTP/SM/SMZ3: Show correct item icon for cross-game items (#1112)
Co-authored-by: lordlou <[email protected]> Co-authored-by: Fabian Dill <[email protected]>
1 parent 18e0d25 commit 776b5fa

File tree

3 files changed

+58
-25
lines changed

3 files changed

+58
-25
lines changed

worlds/alttp/Rom.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,9 @@ def write_to_rom(self, rom: LocalRom):
762762
0x4D504, 0x4D507, 0x4D55E, 0x4D56A]
763763

764764

765-
def get_nonnative_item_sprite(item: str) -> int:
765+
def get_nonnative_item_sprite(code: int) -> int:
766+
if 84173 >= code >= 84007: # LttP item in SMZ3
767+
return code - 84000
766768
return 0x6B # set all non-native sprites to Power Star as per 13 to 2 vote at
767769
# https://discord.com/channels/731205301247803413/827141303330406408/852102450822905886
768770

@@ -785,7 +787,7 @@ def patch_rom(world: MultiWorld, rom: LocalRom, player: int, enemized: bool):
785787
if location.item.trap:
786788
itemid = 0x5A # Nothing, which disguises
787789
else:
788-
itemid = get_nonnative_item_sprite(location.item.name)
790+
itemid = get_nonnative_item_sprite(location.item.code)
789791
# Keys in their native dungeon should use the orignal item code for keys
790792
elif location.parent_region.dungeon:
791793
if location.parent_region.dungeon.is_dungeon_item(location.item):
@@ -1739,7 +1741,7 @@ def write_custom_shops(rom, world, player):
17391741
replacement_price_data = get_price_data(item['replacement_price'], item['replacement_price_type'])
17401742
slot = 0 if shop.type == ShopType.TakeAny else index
17411743
if item['player'] and world.game[item['player']] != "A Link to the Past": # item not native to ALTTP
1742-
item_code = get_nonnative_item_sprite(item['item'])
1744+
item_code = get_nonnative_item_sprite(world.worlds[item['player']].item_name_to_id[item['item']])
17431745
else:
17441746
item_code = ItemFactory(item['item'], player).code
17451747
if item['item'] == 'Single Arrow' and item['player'] == 0 and world.retro_bow[player]:

worlds/sm/__init__.py

+29-21
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ def create_items(self):
174174
isAdvancement = False
175175

176176
itemClass = ItemManager.Items[item.Type].Class
177-
smitem = SMItem(item.Name,
178-
ItemClassification.progression if isAdvancement else ItemClassification.filler,
177+
smitem = SMItem(item.Name,
178+
ItemClassification.progression if isAdvancement else ItemClassification.filler,
179179
item.Type,
180-
None if itemClass == 'Boss' else self.item_name_to_id[item.Name],
180+
None if itemClass == 'Boss' else self.item_name_to_id[item.Name],
181181
player=self.player)
182-
182+
183183
if itemClass == 'Boss':
184184
self.locked_items[item.Name] = smitem
185185
elif item.Category == 'Nothing':
@@ -192,10 +192,10 @@ def create_items(self):
192192
for (location, item) in self.locked_items.items():
193193
self.multiworld.get_location(location, self.player).place_locked_item(item)
194194
self.multiworld.get_location(location, self.player).address = None
195-
195+
196196
def evalSMBool(self, smbool, maxDiff):
197197
return smbool.bool == True and smbool.difficulty <= maxDiff
198-
198+
199199
def add_entrance_rule(self, entrance, player, func):
200200
add_rule(entrance, lambda state: self.evalSMBool(func(state.smbm[player]), state.smbm[player].maxDiff))
201201

@@ -221,12 +221,12 @@ def set_entrance_rule(entrance, player, func):
221221
add_accessFrom_rule(location, self.player, value.AccessFrom)
222222
if value.PostAvailable is not None:
223223
add_postAvailable_rule(location, self.player, value.PostAvailable)
224-
224+
225225
for accessPoint in Logic.accessPoints:
226226
if not accessPoint.Escape:
227227
for key, value1 in accessPoint.intraTransitions.items():
228228
set_entrance_rule(self.multiworld.get_entrance(accessPoint.Name + "->" + key, self.player), self.player, value1)
229-
229+
230230
def create_region(self, world: MultiWorld, player: int, name: str, locations=None, exits=None):
231231
ret = Region(name, player, world)
232232
if locations:
@@ -238,7 +238,7 @@ def create_region(self, world: MultiWorld, player: int, name: str, locations=Non
238238
for exit in exits:
239239
ret.exits.append(Entrance(player, exit, ret))
240240
return ret
241-
241+
242242
def create_regions(self):
243243
# create locations
244244
for name in locationsDict:
@@ -248,9 +248,9 @@ def create_regions(self):
248248
regions = []
249249
for accessPoint in Logic.accessPoints:
250250
if not accessPoint.Escape:
251-
regions.append(self.create_region( self.multiworld,
252-
self.player,
253-
accessPoint.Name,
251+
regions.append(self.create_region( self.multiworld,
252+
self.player,
253+
accessPoint.Name,
254254
None,
255255
[accessPoint.Name + "->" + key for key in accessPoint.intraTransitions.keys()]))
256256

@@ -261,9 +261,9 @@ def create_regions(self):
261261
# this is required in AP because a location cant have multiple parent regions
262262
locationRegions = []
263263
for locationName, value in locationsDict.items():
264-
locationRegions.append(self.create_region( self.multiworld,
265-
self.player,
266-
locationName,
264+
locationRegions.append(self.create_region( self.multiworld,
265+
self.player,
266+
locationName,
267267
[locationName]))
268268
for key in value.AccessFrom.keys():
269269
currentRegion = self.multiworld.get_region(key, self.player)
@@ -320,7 +320,7 @@ def get_filler_item_name(self) -> str:
320320
return "Super Missile"
321321
else:
322322
return "Nothing"
323-
323+
324324
def pre_fill(self):
325325
if len(self.NothingPool) > 0:
326326
nonChozoLoc = []
@@ -371,8 +371,8 @@ def post_fill(self):
371371
itemLoc.item.type if isinstance(itemLoc.item, SMItem) and itemLoc.item.type in ItemManager.Items else
372372
'ArchipelagoItem']),
373373
copy.copy(locationsDict[itemLoc.name] if itemLoc.game == self.game else
374-
locationsDict[first_local_collected_loc.name]),
375-
itemLoc.item.player,
374+
locationsDict[first_local_collected_loc.name]),
375+
itemLoc.item.player,
376376
True)
377377
for itemLoc in SMWorld.spheres if itemLoc.item.player == self.player
378378
]
@@ -387,7 +387,7 @@ def post_fill(self):
387387
escapeOk = self.variaRando.randoExec.graphBuilder.escapeGraph(self.variaRando.container, self.variaRando.randoExec.areaGraph, self.variaRando.randoExec.randoSettings.maxDiff, escapeTrigger)
388388
if (not escapeOk):
389389
logger.warning(f"Escape Rando forced to 'Off' for player {self.multiworld.get_player_name(self.player)} because could not find a solution for escape")
390-
390+
391391
# if we couldn't find an area layout then the escape graph is not created either
392392
# and getDoorConnections will crash if random escape is activated.
393393
self.variaRando.doors = GraphUtils.getDoorConnections(self.variaRando.randoExec.areaGraph,
@@ -406,7 +406,7 @@ def stage_post_fill(cls, world):
406406

407407
for item in progitempool:
408408
new_state.collect(item, True)
409-
409+
410410
bossesLoc = ['Draygon', 'Kraid', 'Ridley', 'Phantoon', 'Mother Brain']
411411
for player in world.get_game_players("Super Metroid"):
412412
for bossLoc in bossesLoc:
@@ -548,9 +548,17 @@ def APPostPatchRom(self, romPatcher):
548548
vanillaItemTypesCount = 21
549549
for itemLoc in self.multiworld.get_locations():
550550
if itemLoc.player == self.player and "Boss" not in locationsDict[itemLoc.name].Class:
551-
# item to place in this SM world: write full item data to tables
551+
SMZ3NameToSMType = {
552+
"ETank": "ETank", "Missile": "Missile", "Super": "Super", "PowerBomb": "PowerBomb", "Bombs": "Bomb",
553+
"Charge": "Charge", "Ice": "Ice", "HiJump": "HiJump", "SpeedBooster": "SpeedBooster",
554+
"Wave": "Wave", "Spazer": "Spazer", "SpringBall": "SpringBall", "Varia": "Varia", "Plasma": "Plasma",
555+
"Grapple": "Grapple", "Morph": "Morph", "ReserveTank": "Reserve", "Gravity": "Gravity",
556+
"XRay": "XRayScope", "SpaceJump": "SpaceJump", "ScrewAttack": "ScrewAttack"
557+
}
552558
if isinstance(itemLoc.item, SMItem) and itemLoc.item.type in ItemManager.Items:
553559
itemId = ItemManager.Items[itemLoc.item.type].Id
560+
elif itemLoc.item.game == "SMZ3" and itemLoc.item.name in SMZ3NameToSMType.keys():
561+
itemId = ItemManager.Items[SMZ3NameToSMType[itemLoc.item.name]].Id
554562
else:
555563
itemId = ItemManager.Items["ArchipelagoItem"].Id + idx
556564
multiWorldItems.append({"sym": symbols["message_item_names"],

worlds/smz3/TotalSMZ3/Patch.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import random
55
import typing
66
from BaseClasses import Location
7-
from .Item import Item, ItemType
7+
from .Item import Item, ItemType, lookup_id_to_name
88
from .Location import LocationType
99
from .Region import IReward, RewardType, SMRegion, Z3Region
1010
from .Regions.Zelda.EasternPalace import EasternPalace
@@ -351,6 +351,29 @@ def GetZ3ItemId(self, location: Location):
351351
not (item.IsDungeonItem() and location.Region.IsRegionItem(item) and item.World == self.myWorld) else itemDungeon
352352

353353
return value.value
354+
elif (location.APLocation.item.game == "A Link to the Past"):
355+
if location.APLocation.item.code + 84000 in lookup_id_to_name:
356+
ALTTPBottleContentCodeToSMZ3ItemCode = {
357+
ItemType.RedContent.value: ItemType.BottleWithRedPotion.value,
358+
ItemType.GreenContent.value: ItemType.BottleWithGreenPotion.value,
359+
ItemType.BlueContent.value: ItemType.BottleWithBluePotion.value,
360+
ItemType.BeeContent.value: ItemType.BottleWithBee.value,
361+
}
362+
return ALTTPBottleContentCodeToSMZ3ItemCode.get(location.APLocation.item.code, location.APLocation.item.code)
363+
else:
364+
return ItemType.Something.value
365+
elif (location.APLocation.item.game == "Super Metroid"):
366+
SMNameToSMZ3Code = {
367+
"Energy Tank": ItemType.ETank, "Missile": ItemType.Missile, "Super Missile": ItemType.Super,
368+
"Power Bomb": ItemType.PowerBomb, "Bomb": ItemType.Bombs, "Charge Beam": ItemType.Charge,
369+
"Ice Beam": ItemType.Ice, "Hi-Jump Boots": ItemType.HiJump, "Speed Booster": ItemType.SpeedBooster,
370+
"Wave Beam": ItemType.Wave, "Spazer": ItemType.Spazer, "Spring Ball": ItemType.SpringBall,
371+
"Varia Suit": ItemType.Varia, "Plasma Beam": ItemType.Plasma, "Grappling Beam": ItemType.Grapple,
372+
"Morph Ball": ItemType.Morph, "Reserve Tank": ItemType.ReserveTank, "Gravity Suit": ItemType.Gravity,
373+
"X-Ray Scope": ItemType.XRay, "Space Jump": ItemType.SpaceJump, "Screw Attack": ItemType.ScrewAttack,
374+
"Nothing": ItemType.Something, "No Energy": ItemType.Something, "Generic": ItemType.Something
375+
}
376+
return SMNameToSMZ3Code.get(location.APLocation.item.name, ItemType.Something).value
354377
else:
355378
return ItemType.Something.value
356379

0 commit comments

Comments
 (0)