Esempio n. 1
0
def EUDLoopTrigger(player):
    player = c.EncodePlayer(player)

    tbegin = tt.TrigTriggerBegin(player)
    if cs.EUDIfNot()(tbegin == 0):
        tend = tt.TrigTriggerEnd(player)
        for ptr, epd in EUDLoopList(tbegin, tend):
            yield ptr, epd
    cs.EUDEndIf()
Esempio n. 2
0
def f_getcurpl():
    """Get current player value.

    eudplib internally caches the current player value, so this function uses
    that value if the value is valid. Otherwise, update the current player
    cache and return it.
    """
    cpcond = c.curpl.cpcacheMatchCond()
    cpcache = c.curpl.GetCPCache()
    if cs.EUDIfNot()(cpcond):
        _f_updatecpcache()
    cs.EUDEndIf()

    return cpcache
Esempio n. 3
0
def QueueGameCommand(data, size):
    """Queue game command to packet queue.

    Starcraft periodically boradcasts game packets to other player. Game
    packets are stored to queue, and this function add data to that queue, so
    that SC can boradcast it.

    :param data: Data to put in queue
    :param size: Size of data

    .. note::
        If packet queue is full, this function fails. This behavior is silent
        without any warning or error, since this behavior shouldn't happen in
        common situations. So **Don't use this function too much in a frame.**

    """
    prov_maxbuffer = f_dwread_epd(ut.EPD(0x57F0D8))
    cmdqlen = f_dwread_epd(ut.EPD(0x654AA0))
    if cs.EUDIfNot()(cmdqlen + size + 1 >= prov_maxbuffer):
        f_memcpy(0x654880 + cmdqlen, data, size)
        c.SetVariables(ut.EPD(0x654AA0), cmdqlen + size)
    cs.EUDEndIf()
Esempio n. 4
0
def EUDBinaryMin(cond, minv=0, maxv=0xFFFFFFFF):
    """ Find minimum x satisfying cond(x) using binary search

    :param cond: Test condition
    :param minv: Minimum value in domain
    :param maxv: Maximum value in domain

    Cond should be binary classifier, meaning that for some N
        for all x < N, cond(x) is false.
        for all x >= N, cond(x) is true
    Then EUDBinaryMin will find such N

    .. note:: If none of the value satisfies condition, then this
        function will return maxv.
    """
    x = c.EUDVariable()
    x << maxv

    if isinstance(minv, int) and isinstance(maxv, int):
        r = maxv - minv
        if r == 0:
            return minv

    else:
        r = None

    for i in range(31, -1, -1):
        if r and 2**i > r:
            continue

        if cs.EUDIf()([x >= 2**i]):
            cs.DoActions(x.SubtractNumber(2**i))
            if cs.EUDIfNot()([x >= minv, cond(x)]):
                cs.DoActions(x.AddNumber(2**i))
            cs.EUDEndIf()
        cs.EUDEndIf()

    return x
Esempio n. 5
0
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