def f_dbstr_addptr(dst, number): """Print number as string to dst. :param dst: Destination address (Not EPD player) :param number: DWORD to print :returns: dst + strlen(itoa(number)) """ bw1.seekoffset(dst) ch = [0] * 8 # Get digits for i in range(8): number, ch[i] = c.f_div(number, 16) # print digits for i in range(7, -1, -1): if cs.EUDIf()(ch[i] <= 9): bw1.writebyte(ch[i] + b'0'[0]) if cs.EUDElse()(): bw1.writebyte(ch[i] + (b'A'[0] - 10)) cs.EUDEndIf() dst += 1 bw1.writebyte(0) # EOS bw1.flushdword() return dst
def EUDNot(cond): """ !cond :param conds: Condition to negate """ v = c.EUDVariable() if cs.EUDIf()(cond): v << 0 if cs.EUDElse()(): v << 1 cs.EUDEndIf() return v
def EUDOr(cond1, *conds): """ cond1 || cond2 || ... || condn .. warning:: Short circuiting is not supported :param conds: List of conditions """ v = c.EUDVariable() if cs.EUDIf()(cond1): v << 1 for cond in conds: if cs.EUDElseIf()(cond): v << 1 if cs.EUDElse()(): v << 0 cs.EUDEndIf() return v
def f_playerexist(player): """Check if player has not left the game. :returns: 1 if player exists, 0 if not. """ pts = 0x51A280 cs.EUDSwitch(player) for p in range(8): if cs.EUDSwitchCase()(p): if cs.EUDIf()(c.Memory(pts + p * 12 + 8, c.Exactly, ~(pts + p * 12 + 4))): c.EUDReturn(0) if cs.EUDElse()(): c.EUDReturn(1) cs.EUDEndIf() if cs.EUDSwitchDefault()(): c.EUDReturn(0) cs.EUDEndSwitch()
def EUDAnd(cond1, *conds): """ cond1 && cond2 && ... && condn .. note:: This function computes AND value of various conditions. If you don't want to do much computation, you should better use plain list instead of this function. .. warning:: Short circuiting is not supported. :param conds: List of conditions """ v = c.EUDVariable() if cs.EUDIfNot()(cond1): v << 0 for cond in conds: if cs.EUDElseIfNot()(cond): v << 0 if cs.EUDElse()(): v << 1 cs.EUDEndIf() return v
def f_randomize(): global _seed # Store switch 1 sw1 = c.EUDVariable() if cs.EUDIf()(c.Switch("Switch 1", c.Set)): sw1 << c.EncodeSwitchAction(c.Set) if cs.EUDElse()(): sw1 << c.EncodeSwitchAction(c.Clear) cs.EUDEndIf() _seed << 0 dseed = c.EUDVariable() dseed << 1 if cs.EUDLoopN()(32): cs.DoActions(c.SetSwitch("Switch 1", c.Random)) if cs.EUDIf()(c.Switch("Switch 1", c.Set)): _seed += dseed cs.EUDEndIf() dseed += dseed cs.EUDEndLoopN() cs.DoActions(c.SetSwitch("Switch 1", sw1))
def f_lengthdir(length, angle): # sin, cos table clist = [] slist = [] for i in range(91): cosv = math.floor(math.cos(math.pi / 180 * i) * 65536 + 0.5) sinv = math.floor(math.sin(math.pi / 180 * i) * 65536 + 0.5) clist.append(ut.i2b4(cosv)) slist.append(ut.i2b4(sinv)) cdb = c.Db(b''.join(clist)) sdb = c.Db(b''.join(slist)) # MAIN LOGIC if cs.EUDIf()(angle >= 360): angle << c.f_div(angle, 360)[1] cs.EUDEndIf() ldir_x, ldir_y = c.EUDVariable(), c.EUDVariable() # cos, sin * 65536 # sign of cos, sin csign, ssign = c.EUDLightVariable(), c.EUDLightVariable() tableangle = c.EUDVariable() # get cos, sin from table if cs.EUDIf()(angle <= 89): tableangle << angle csign << 1 ssign << 1 if cs.EUDElseIf()(angle <= 179): tableangle << 180 - angle csign << -1 ssign << 1 if cs.EUDElseIf()(angle <= 269): tableangle << angle - 180 csign << -1 ssign << -1 if cs.EUDElse()(): tableangle << 360 - angle csign << 1 ssign << -1 cs.EUDEndIf() tablecos = f_dwread_epd(ut.EPD(cdb) + tableangle) tablesin = f_dwread_epd(ut.EPD(sdb) + tableangle) # calculate lengthdir ldir_x << c.f_div(c.f_mul(tablecos, length), 65536)[0] ldir_y << c.f_div(c.f_mul(tablesin, length), 65536)[0] # restore sign of cos, sin if cs.EUDIf()(csign == -1): ldir_x << 0xFFFFFFFF - ldir_x + 1 cs.EUDEndIf() if cs.EUDIf()(ssign == -1): ldir_y << 0xFFFFFFFF - ldir_y + 1 cs.EUDEndIf() return ldir_x, ldir_y