def EUDEndLoopN(): block = ut.EUDPopBlock('loopnblock')[1] if not block['contpoint'].IsSet(): block['contpoint'] << c.NextTrigger() vardb = block['vardb'] c.RawTrigger(actions=c.SetMemory(vardb, c.Subtract, 1)) EUDJump(block['loopstart']) block['loopend'] << c.NextTrigger()
def EUDEndIf(): lb = ut.EUDPopBlock('ifblock') block = lb[1] # Finalize nei_fw = block['next_elseif'] if nei_fw: nei_fw << c.NextTrigger() block['ifend'] << c.NextTrigger()
def EUDEndPlayerLoop(): block = ut.EUDPopBlock('ploopblock')[1] playerv = block['playerv'] origcp = block['origcp'] if not cs.EUDIsContinuePointSet(): cs.EUDSetContinuePoint() playerv += 1 cs.EUDEndWhile() f_setcurpl(origcp)
def EUDLoopUnit(): ut.EUDCreateBlock('unitloop', 0x628430) ptr, epd = f_cunitepdread_epd(ut.EPD(0x628430)) if cs.EUDWhile()(ptr >= 1): yield ptr, epd cs.EUDSetContinuePoint() c.SetVariables([ptr, epd], f_cunitepdread_epd(epd + 1)) cs.EUDEndWhile() ut.EUDPopBlock('unitloop')
def EUDLoopRange(start, end=None): ut.EUDCreateBlock('looprangeblock', None) if end is None: start, end = 0, start v = c.EUDVariable() v << start if EUDWhile()(v < end): yield v EUDLoopSetContinuePoint() v += 1 EUDEndWhile() ut.EUDPopBlock('looprangeblock')
def EUDLoopPlayerUnit(player): player = c.EncodePlayer(player) first_player_unit = 0x6283F8 ut.EUDCreateBlock('playerunitloop', first_player_unit) ptr, epd = f_cunitepdread_epd(ut.EPD(first_player_unit) + player) if cs.EUDWhile()(ptr >= 1): yield ptr, epd cs.EUDSetContinuePoint() # /*0x06C*/ BW::CUnit* nextPlayerUnit; c.SetVariables([ptr, epd], f_cunitepdread_epd(epd + 0x6C // 4)) cs.EUDEndWhile() ut.EUDPopBlock('playerunitloop')
def EUDLoopSprite(): y_epd = c.EUDVariable() y_epd << ut.EPD(0x629688) ut.EUDCreateBlock('spriteloop', 'sprlo') if cs.EUDWhile()(y_epd < ut.EPD(0x629688) + 256): ptr, epd = f_dwepdread_epd(y_epd) if cs.EUDWhile()(ptr >= 1): yield ptr, epd cs.EUDSetContinuePoint() c.SetVariables([ptr, epd], f_dwepdread_epd(epd + 1)) cs.EUDEndWhile() y_epd += 1 cs.EUDEndWhile() ut.EUDPopBlock('spriteloop')
def EUDLoopList(header_offset, break_offset=None): blockname = 'listloop' ut.EUDCreateBlock(blockname, header_offset) ptr, epd = f_dwepdread_epd(ut.EPD(header_offset)) if break_offset is not None: cs.EUDWhileNot()(ptr == break_offset) else: cs.EUDWhile()([ptr > 0, ptr <= 0x7FFFFFFF]) yield ptr, epd cs.EUDSetContinuePoint() c.SetVariables([ptr, epd], f_dwepdread_epd(epd + 1)) cs.EUDEndWhile() ut.ep_assert( ut.EUDPopBlock(blockname)[1] is header_offset, 'listloop mismatch' )
def EUDEndSwitch(): lb = ut.EUDPopBlock('swblock') block = lb[1] swend = block['swend'] EUDJump(swend) # Exit switch block c.PopTriggerScope() # If default block is not specified, skip it if not block['defaultbr'].IsSet(): block['defaultbr'] << swend # Create key selector casebrlist = block['casebrlist'] defbranch = block['defaultbr'] casekeylist = sorted(block['casebrlist'].keys()) var = block['targetvar'] def KeySelector(keys): # Uses simple binary search ret = c.NextTrigger() if len(keys) == 1: # Only one keys on the list tg.EUDBranch(var == keys[0], casebrlist[keys[0]], defbranch) elif len(keys) >= 2: br1 = c.Forward() br2 = c.Forward() midpos = len(keys) // 2 midval = keys[midpos] EUDJumpIf(var == midval, casebrlist[midval]) tg.EUDBranch(var <= midval, br1, br2) br1 << KeySelector(keys[:midpos]) br2 << KeySelector(keys[midpos + 1:]) else: # len(keys) == 0 return defbranch return ret KeySelector(casekeylist) swend << c.NextTrigger()
def EUDEndExecuteOnce(): lb = ut.EUDPopBlock('executeonceblock') ut.ep_assert(lb[0] == 'executeonceblock', 'Block start/end mismatch') block = lb[1] block['blockend'] << c.NextTrigger()
def EUDEndInfLoop(): block = ut.EUDPopBlock('infloopblock')[1] if not block['contpoint'].IsSet(): block['contpoint'] << block['loopstart'] EUDJump(block['loopstart']) block['loopend'] << c.NextTrigger()
def EUDEndWhile(): block = ut.EUDPopBlock('whileblock')[1] if not block['contpoint'].IsSet(): block['contpoint'] << block['loopstart'] EUDJump(block['loopstart']) block['loopend'] << c.NextTrigger()