euddraft icon indicating copy to clipboard operation
euddraft copied to clipboard

Add custom member and current race for `TrgPlayer`

Open armoha opened this issue 2 months ago • 1 comments

Copied from SEN discord server (Nov 24, 2024)

GGRush: Hi Dr.zzt, I would greatly appreciate it if you could help me improve this code If you could add new features to TrgPlayer, that would be great latest version:

class MyPlayer(TrgPlayer):
    """
    MyPlayer extends TrgPlayer to include additional player-specific attributes and methods.
    """

    _type = None
    _race = PVariable()
    _race_mul36 = PVariable()  # race * 36, use to read/write supply

    @classmethod
    def initialize(cls):
        for p in EUDLoopRange(8):
            dest = EPD(0x57EEE8) + 9 * p
            cls._type[p] = f_bread_epd(dest, 0)
            race = f_bread_epd(dest, 1)
            cls._race[p] = race
            cls._race_mul36[p] = 36 * race

    @classmethod
    def from_epd(cls, epd):  # from unit
        _player = f_bread_epd(epd + 0x4C//4, 0)  # playerID
        return cls(_player)

    def __init__(self, initval) -> None:
        super().__init__(initval)
        if MyPlayer._type is None:
            MyPlayer._type = PVariable()
            EUDOnStart(lambda: MyPlayer.initialize()) 

    @property
    def type(self):
        return MyPlayer._type[self]

    @type.setter
    def type(self, ptype):
        MyPlayer._type[self] = ptype
        f_bwrite_epd(EPD(0x57EEE8) + 9 * self, 0, ptype)

    @property
    def race(self):
        return MyPlayer._race[self]

    @property
    def used(self):  # control/supply/psi used
        return f_dwread_epd(EPD(0x582174) + self + MyPlayer._race_mul36[self])

    @used.setter
    def used(self, value):
        f_dwwrite_epd(EPD(0x582174) + self + MyPlayer._race_mul36[self], value)

    @property
    def available(self):  # control/supply/psi available
        return f_dwread_epd(EPD(0x582144) + self + MyPlayer._race_mul36[self])

    @available.setter
    def available(self, value):
        f_dwwrite_epd(EPD(0x582144) + self + MyPlayer._race_mul36[self], value)

    def all_unit_counts(self, unit):
        unit = EncodeUnit(unit)
        return f_dwread_epd(EPD(0x582324) + self + 12 * unit)

    def set_all_unit_counts(self, unit, value):
        unit = EncodeUnit(unit)
        f_dwwrite_epd(EPD(0x582324) + self + 12 * unit, value)

    def completed_unit_counts(self, unit):
        unit = EncodeUnit(unit)
        return f_dwread_epd(EPD(0x584DE4) + self + 12 * unit)

    def set_completed_unit_counts(self, unit, value):
        unit = EncodeUnit(unit)
        f_dwwrite_epd(EPD(0x584DE4) + self + 12 * unit, value) 

Armoha: there's a GetPlayerInfo(player) for ptype and race nvm GetPlayerInfo reads from map chk while you need in-game info

GGRush: in my map, the info always change, they are not unchanging Not just getting default information once

armoha avatar Nov 30 '24 06:11 armoha