From b01333235bb69339ae845f4e0f81414eec28053c Mon Sep 17 00:00:00 2001 From: armoha Date: Mon, 6 Jun 2022 02:16:15 +0900 Subject: [PATCH 1/5] f_bringcount: initial commit --- eudplib/eudlib/locf/__init__.py | 1 + eudplib/eudlib/locf/count.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 eudplib/eudlib/locf/count.py diff --git a/eudplib/eudlib/locf/__init__.py b/eudplib/eudlib/locf/__init__.py index 155fe63f..53bee77d 100644 --- a/eudplib/eudlib/locf/__init__.py +++ b/eudplib/eudlib/locf/__init__.py @@ -23,4 +23,5 @@ THE SOFTWARE. """ +from .count import f_bringcount from .locf import f_setloc, f_addloc, f_dilateloc, f_getlocTL, f_setloc_epd diff --git a/eudplib/eudlib/locf/count.py b/eudplib/eudlib/locf/count.py new file mode 100644 index 00000000..d28190d5 --- /dev/null +++ b/eudplib/eudlib/locf/count.py @@ -0,0 +1,33 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +""" +Copyright (c) 2022 Armoha + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +""" + +from ... import core as c, ctrlstru as cs, utils as ut + + +def f_bringcount(player, unit, location): + player = c.EncodePlayer(player) + unit = c.EncodeUnit(unit) + location = c.EncodeLocation(location) + c.Bring(player, c.AtLeast, 128, unit, location) From b132099eb3d65eb7dcfe76ba2043f425aec32e97 Mon Sep 17 00:00:00 2001 From: armoha Date: Sat, 11 Jun 2022 19:25:10 +0900 Subject: [PATCH 2/5] initial commit --- eudplib/eudlib/locf/__init__.py | 2 +- eudplib/eudlib/locf/{count.py => bringcount.py} | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) rename eudplib/eudlib/locf/{count.py => bringcount.py} (78%) diff --git a/eudplib/eudlib/locf/__init__.py b/eudplib/eudlib/locf/__init__.py index 53bee77d..c5e25062 100644 --- a/eudplib/eudlib/locf/__init__.py +++ b/eudplib/eudlib/locf/__init__.py @@ -23,5 +23,5 @@ THE SOFTWARE. """ -from .count import f_bringcount +from .bringcount import f_bringcount from .locf import f_setloc, f_addloc, f_dilateloc, f_getlocTL, f_setloc_epd diff --git a/eudplib/eudlib/locf/count.py b/eudplib/eudlib/locf/bringcount.py similarity index 78% rename from eudplib/eudlib/locf/count.py rename to eudplib/eudlib/locf/bringcount.py index d28190d5..a3644143 100644 --- a/eudplib/eudlib/locf/count.py +++ b/eudplib/eudlib/locf/bringcount.py @@ -30,4 +30,9 @@ def f_bringcount(player, unit, location): player = c.EncodePlayer(player) unit = c.EncodeUnit(unit) location = c.EncodeLocation(location) - c.Bring(player, c.AtLeast, 128, unit, location) + bring = c.Bring(player, c.AtLeast, 128, unit, location) + set_count = c.SetMemory(bring + 8, c.Subtract, 64) + set_add = c.SetMemoryX(set_count + 24, c.SetTo, 8 << 24, 0xFF << 24) + set_subtract = c.SetMemoryX(set_count + 24, c.SetTo, 9 << 24, 0xFF << 24) + c.RawTrigger(conditions=bring, actions=set_add) + cs.DoActions(set_count, set_subtract) From 807ece3d2f68bbcdb268298add649013a3c68207 Mon Sep 17 00:00:00 2001 From: armoha Date: Mon, 13 Jun 2022 01:06:29 +0900 Subject: [PATCH 3/5] WIP --- eudplib/eudlib/locf/bringcount.py | 32 ++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/eudplib/eudlib/locf/bringcount.py b/eudplib/eudlib/locf/bringcount.py index a3644143..036fc13b 100644 --- a/eudplib/eudlib/locf/bringcount.py +++ b/eudplib/eudlib/locf/bringcount.py @@ -24,15 +24,29 @@ """ from ... import core as c, ctrlstru as cs, utils as ut +from ...core.eudfunc.eudf import _EUDPredefineParam + + +bring = c.Bring(0, c.AtLeast, 0, 0, 0) + + +@_EUDPredefineParam((ut.EPD(bring) + 1, ut.EPD(bring) + 3, ut.EPD(bring))) +@c.EUDTypedFunc([c.TrgPlayer, c.TrgUnit, c.TrgLocation], [None]) +def _bringcount(player, unit, location): + cs.DoActions( + c.SetMemory(bring + 8, c.SetTo, 1024), + c.SetMemoryX(bring + 12, c.SetTo, 3 << 24, 0xFFFF0000), + ) + c.RawTrigger(conditions=[bring, c.Memory(bring + 8, c.AtMost, 1700)]) def f_bringcount(player, unit, location): - player = c.EncodePlayer(player) - unit = c.EncodeUnit(unit) - location = c.EncodeLocation(location) - bring = c.Bring(player, c.AtLeast, 128, unit, location) - set_count = c.SetMemory(bring + 8, c.Subtract, 64) - set_add = c.SetMemoryX(set_count + 24, c.SetTo, 8 << 24, 0xFF << 24) - set_subtract = c.SetMemoryX(set_count + 24, c.SetTo, 9 << 24, 0xFF << 24) - c.RawTrigger(conditions=bring, actions=set_add) - cs.DoActions(set_count, set_subtract) + if not any(IsEUDVariable(v) for v in (player, unit, location)): + cache = c.EUDVariable() + cache_bring = c.Bring(player, c.Exactly, 0, unit, location) + if cs.EUDIfNot()(cache_bring): + _bringcount(player, unit, location, _ret=[cache]) + c.VProc(cache, cache.QueueAssignTo(ut.EPD(cache_bring) + 2)) + cs.EUDEndIf() + return cache + return _bringcount(player, unit, location) From 52c9fdee19e44a32d5570802babe25e2ed21b0c3 Mon Sep 17 00:00:00 2001 From: armoha Date: Sun, 24 Jul 2022 00:56:15 +0000 Subject: [PATCH 4/5] Autoformat Python code with psf/black --- eudplib/eudlib/stringf/fmtprint.py | 13 +++++++++++-- eudplib/eudlib/stringf/pname.py | 8 +++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/eudplib/eudlib/stringf/fmtprint.py b/eudplib/eudlib/stringf/fmtprint.py index 1160c4dd..f4efd99d 100644 --- a/eudplib/eudlib/stringf/fmtprint.py +++ b/eudplib/eudlib/stringf/fmtprint.py @@ -67,12 +67,20 @@ def _eudformat( # handle arg indexing when empty field_names are given. if field_name == "": if auto_arg_index is False: - raise ValueError(_("cannot switch from manual field specification to automatic field numbering")) + raise ValueError( + _( + "cannot switch from manual field specification to automatic field numbering" + ) + ) field_name = str(auto_arg_index) auto_arg_index += 1 elif field_name.isdigit(): if auto_arg_index: - raise ValueError(_("cannot switch from manual field specification to automatic field numbering")) + raise ValueError( + _( + "cannot switch from manual field specification to automatic field numbering" + ) + ) # disable auto arg incrementing, if it gets # used later on, then an exception will be raised auto_arg_index = False @@ -152,6 +160,7 @@ def f_eprintf(format_string, *args): fmtargs = _format_args(format_string, *args) f_eprintln(*fmtargs) + def f_eprintAll(format_string, *args): fmtargs = _format_args(format_string, *args) _eprintAll(*fmtargs) diff --git a/eudplib/eudlib/stringf/pname.py b/eudplib/eudlib/stringf/pname.py index 80c6c6e1..f0f047f6 100644 --- a/eudplib/eudlib/stringf/pname.py +++ b/eudplib/eudlib/stringf/pname.py @@ -125,7 +125,9 @@ def IsPName(player, name): else: ut.ep_assert( p == c.EncodePlayer(c.CurrentPlayer), - _("IsPName player should be Player1 to Player8 or CurrentPlayer, not {}").format(player), + _( + "IsPName player should be Player1 to Player8 or CurrentPlayer, not {}" + ).format(player), ) init, end, params = GetIsPNameCondition(name) @@ -216,8 +218,8 @@ def _optimize(self): cs.DoActions(c.SetMemory(prevTxtPtr + 8, c.SetTo, 0)) for i in range(3, -1, -1): c.RawTrigger( - conditions=c.MemoryX(0x640B58, c.AtLeast, 1, 2 ** i), - actions=c.SetMemory(prevTxtPtr + 8, c.Add, 2 ** i), + conditions=c.MemoryX(0x640B58, c.AtLeast, 1, 2**i), + actions=c.SetMemory(prevTxtPtr + 8, c.Add, 2**i), ) _end << c.NextTrigger() self.optimize_end << c.RawTrigger() From 0b4ced7a0643908d63fd0c2cb9f9b9c9aba96edc Mon Sep 17 00:00:00 2001 From: armoha Date: Sun, 9 Oct 2022 03:57:44 +0900 Subject: [PATCH 5/5] wip --- eudplib/eudlib/locf/bringcount.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/eudplib/eudlib/locf/bringcount.py b/eudplib/eudlib/locf/bringcount.py index 036fc13b..cd0cacb5 100644 --- a/eudplib/eudlib/locf/bringcount.py +++ b/eudplib/eudlib/locf/bringcount.py @@ -37,11 +37,16 @@ def _bringcount(player, unit, location): c.SetMemory(bring + 8, c.SetTo, 1024), c.SetMemoryX(bring + 12, c.SetTo, 3 << 24, 0xFFFF0000), ) - c.RawTrigger(conditions=[bring, c.Memory(bring + 8, c.AtMost, 1700)]) + c.RawTrigger( + conditions=[ + bring, + c.Memory(bring + 8, c.AtMost, 1700) + ] + ) def f_bringcount(player, unit, location): - if not any(IsEUDVariable(v) for v in (player, unit, location)): + if c.IsEUDVariable(player): cache = c.EUDVariable() cache_bring = c.Bring(player, c.Exactly, 0, unit, location) if cs.EUDIfNot()(cache_bring): @@ -49,4 +54,23 @@ def f_bringcount(player, unit, location): c.VProc(cache, cache.QueueAssignTo(ut.EPD(cache_bring) + 2)) cs.EUDEndIf() return cache - return _bringcount(player, unit, location) + + if any(c.IsEUDVariable(v) for v in (player, unit, location)): + return _bringcount(player, unit, location) + + count = c.EUDVariable() + cache_bring = c.Bring(player, c.Exactly, 0, unit, location) + check_cache, reload_check, update_cache, skip = [c.Forward() for _ in range(4)] + + check_cache << c.RawTrigger( + nextptr=update_cache, + conditions=cache_bring, + actions=c.SetNextPtr(check_cache, reload_check) + ) + reload_check << c.RawTrigger( + nextptr=skip, + actions=c.SetNextPtr(check_cache, update_cache) + ) + update_cache << c.NextTrigger() + skip << c.NextTrigger() + return count