diff --git a/eudplib/eudlib/locf/__init__.py b/eudplib/eudlib/locf/__init__.py index 155fe63f..c5e25062 100644 --- a/eudplib/eudlib/locf/__init__.py +++ b/eudplib/eudlib/locf/__init__.py @@ -23,4 +23,5 @@ THE SOFTWARE. """ +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/bringcount.py b/eudplib/eudlib/locf/bringcount.py new file mode 100644 index 00000000..cd0cacb5 --- /dev/null +++ b/eudplib/eudlib/locf/bringcount.py @@ -0,0 +1,76 @@ +#!/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 +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): + if c.IsEUDVariable(player): + 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 + + 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 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()