mirror of
https://gitlab.com/xCrystal/pokecrystal-board.git
synced 2024-11-16 11:27:33 -08:00
better code for MapScriptHeader
This commit is contained in:
parent
746317f90e
commit
49add12c45
@ -5356,7 +5356,7 @@ class SecondMapHeader:
|
|||||||
#TODO: process blockdata ?
|
#TODO: process blockdata ?
|
||||||
#bank appears first
|
#bank appears first
|
||||||
###self.blockdata_address = PointerLabelBeforeBank(address+3)
|
###self.blockdata_address = PointerLabelBeforeBank(address+3)
|
||||||
self.blockdata = MapBlockData(address+3, map_group=self.map_group, map_id=self.map_id, debug=self.debug)
|
self.blockdata = MapBlockData(address+3, map_group=self.map_group, map_id=self.map_id, debug=self.debug, width=self.width, height=self.height)
|
||||||
#bank appears first
|
#bank appears first
|
||||||
#TODO: process MapScriptHeader
|
#TODO: process MapScriptHeader
|
||||||
###self.script_address = PointerLabelBeforeBank(address+6)
|
###self.script_address = PointerLabelBeforeBank(address+6)
|
||||||
@ -5539,11 +5539,7 @@ def parse_map_event_header_at(address, map_group=None, map_id=None, debug=True,
|
|||||||
"""parse crystal map event header byte structure thing"""
|
"""parse crystal map event header byte structure thing"""
|
||||||
return MapEventHeader(address, map_group=map_group, map_id=map_id, debug=debug, bank=bank)
|
return MapEventHeader(address, map_group=map_group, map_id=map_id, debug=debug, bank=bank)
|
||||||
|
|
||||||
class MapScriptHeader(Command):
|
class MapScriptHeader:
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
def parse(self):
|
|
||||||
def to_asm(self):
|
|
||||||
def parse_map_script_header_at(address, map_group=None, map_id=None, debug=True):
|
|
||||||
"""parses a script header
|
"""parses a script header
|
||||||
|
|
||||||
This structure allows the game to have e.g. one-time only events on a map
|
This structure allows the game to have e.g. one-time only events on a map
|
||||||
@ -5553,7 +5549,7 @@ def parse_map_script_header_at(address, map_group=None, map_id=None, debug=True)
|
|||||||
This header a combination of a trigger script section and a callback script
|
This header a combination of a trigger script section and a callback script
|
||||||
section. I don't know if these 'trigger scripts' are the same as the others
|
section. I don't know if these 'trigger scripts' are the same as the others
|
||||||
referenced in the map event header, so this might need to be renamed very
|
referenced in the map event header, so this might need to be renamed very
|
||||||
soon.
|
soon. The scripts in MapEventHeader are called XYTrigger.
|
||||||
|
|
||||||
trigger scripts:
|
trigger scripts:
|
||||||
[[Number1 of pointers] Number1 * [2byte pointer to script][00][00]]
|
[[Number1 of pointers] Number1 * [2byte pointer to script][00][00]]
|
||||||
@ -5595,59 +5591,57 @@ def parse_map_script_header_at(address, map_group=None, map_id=None, debug=True)
|
|||||||
after battle:
|
after battle:
|
||||||
01, 04
|
01, 04
|
||||||
"""
|
"""
|
||||||
print "starting to parse the map's script header.."
|
base_label = "MapScriptHeader_"
|
||||||
#[[Number1 of pointers] Number1 * [2byte pointer to script][00][00]]
|
def __init__(self, address, map_group=None, map_id=None, debug=True, bank=None, label=None):
|
||||||
ptr_line_size = 4 #[2byte pointer to script][00][00]
|
self.address = address
|
||||||
trigger_ptr_cnt = ord(rom[address])
|
self.map_group = map_group
|
||||||
trigger_pointers = grouper(rom_interval(address+1, trigger_ptr_cnt * ptr_line_size, strings=False), count=ptr_line_size)
|
self.map_id = map_id
|
||||||
triggers = {}
|
self.debug = debug
|
||||||
for index, trigger_pointer in enumerate(trigger_pointers):
|
self.bank = bank
|
||||||
print "parsing a trigger header..."
|
if label:
|
||||||
byte1 = trigger_pointer[0]
|
self.label = label
|
||||||
byte2 = trigger_pointer[1]
|
else:
|
||||||
ptr = byte1 + (byte2 << 8)
|
self.label = self.base_label + hex(address)
|
||||||
trigger_address = calculate_pointer(ptr, calculate_bank(address))
|
self.parse()
|
||||||
trigger_script = parse_script_engine_script_at(trigger_address, map_group=map_group, map_id=map_id)
|
script_parse_table[address : self.last_address] = self
|
||||||
triggers[index] = {
|
def parse(self):
|
||||||
"script": trigger_script,
|
address = self.address
|
||||||
"address": trigger_address,
|
map_group = self.map_group
|
||||||
"pointer": {"1": byte1, "2": byte2},
|
map_id = self.map_id
|
||||||
}
|
debug = self.debug
|
||||||
|
#[[Number1 of pointers] Number1 * [2byte pointer to script][00][00]]
|
||||||
#bump ahead in the byte stream
|
self.trigger_count = ord(rom[address])
|
||||||
address += trigger_ptr_cnt * ptr_line_size + 1
|
self.triggers = []
|
||||||
|
ptr_line_size = 4
|
||||||
#[[Number2 of pointers] Number2 * [hook number][2byte pointer to script]]
|
groups = grouper(rom_interval(address+1, self.trigger_count * ptr_line_size, strings=False), count=ptr_line_size)
|
||||||
callback_ptr_line_size = 3
|
current_address = address
|
||||||
callback_ptr_cnt = ord(rom[address])
|
for (index, trigger_bytes) in enumerate(groups):
|
||||||
callback_ptrs = grouper(rom_interval(address+1, callback_ptr_cnt * callback_ptr_line_size, strings=False), count=callback_ptr_line_size)
|
print "parsing a trigger header..."
|
||||||
callback_pointers = {}
|
script = ScriptPointerLabelParam(current_address, map_group=map_group, map_id=map_id, debug=debug)
|
||||||
callbacks = {}
|
self.triggers.append(script)
|
||||||
for index, callback_line in enumerate(callback_ptrs):
|
current_address += ptr_line_size
|
||||||
print "parsing a callback header..."
|
current_address = address + (self.trigger_count * ptr_line_size) + 1
|
||||||
hook_byte = callback_line[0] #1, 2, 3, 4, 5
|
#[[Number2 of pointers] Number2 * [hook number][2byte pointer to script]]
|
||||||
callback_byte1 = callback_line[1]
|
callback_ptr_line_size = 3
|
||||||
callback_byte2 = callback_line[2]
|
self.callback_count = DecimalParam(current_address)
|
||||||
callback_ptr = callback_byte1 + (callback_byte2 << 8)
|
self.callbacks = []
|
||||||
callback_address = calculate_pointer(callback_ptr, calculate_bank(address))
|
for index in range(callback_count):
|
||||||
callback_script = parse_script_engine_script_at(callback_address)
|
hook_byte = HexByte(current_address)
|
||||||
callback_pointers[len(callback_pointers.keys())] = [hook_byte, callback_ptr]
|
callback = ScriptPointerLabelParam(current_address+1, map_group=map_group, map_id=map_id, debug=debug)
|
||||||
callbacks[index] = {
|
callbacks.append({"hook": hook_byte, "callback": callback})
|
||||||
"script": callback_script,
|
return True
|
||||||
"address": callback_address,
|
def to_asm(self):
|
||||||
"pointer": {"1": callback_byte1, "2": callback_byte2},
|
output = ""
|
||||||
}
|
output += "; trigger count\n"
|
||||||
|
output += "db %d\n\n"%self.trigger_count
|
||||||
#XXX do these triggers/callbacks call asm or script engine scripts?
|
output += "; triggers\n"
|
||||||
return {
|
output += "dw " + "\n".join([p.to_asm() for p in self.triggers]) + "\n\n"
|
||||||
#"trigger_ptr_cnt": trigger_ptr_cnt,
|
output += "; callbacks\n"
|
||||||
"trigger_pointers": trigger_pointers,
|
#not so sure about this next one
|
||||||
#"callback_ptr_cnt": callback_ptr_cnt,
|
output += "\n".join(["dbw "+str(p["hook"])+", "+p["callback"].to_asm() for p in self.callbacks])
|
||||||
#"callback_ptr_scripts": callback_ptrs,
|
return output
|
||||||
"callback_pointers": callback_pointers,
|
def parse_map_script_header_at(address, map_group=None, map_id=None, debug=True):
|
||||||
"trigger_scripts": triggers,
|
return MapScriptHeader(address, map_group=map_group, map_id=map_id, debug=debug)
|
||||||
"callback_scripts": callbacks,
|
|
||||||
}
|
|
||||||
|
|
||||||
def old_parse_trainer_header_at(address, map_group=None, map_id=None, debug=True):
|
def old_parse_trainer_header_at(address, map_group=None, map_id=None, debug=True):
|
||||||
bank = calculate_bank(address)
|
bank = calculate_bank(address)
|
||||||
|
Loading…
Reference in New Issue
Block a user