Beispiel #1
0
 def dump(self, bp):
     nbp = BlockPar(sort=False)
     nbp.add("Begin", str(self.begin))
     nbp.add("End", str(self.end))
     nbp.add("Relations", str(self.relations))
     nbp.add("WarWeight", str(self.war_weight))
     bp.add(str(self.name), nbp)
Beispiel #2
0
    def __init__(self):
        self.viewpos = Point(0, 0)
        self.name = ""
        self.filename = ""

        self.textfilenames = BlockPar(sort=False)
        self.textfilenames["rus"] = ""
        self.translations = BlockPar(sort=False)
        self.translations_id = BlockPar(sort=False)

        self.graphpoints = []
        self.graphlinks = []
        self.graphrects = []
Beispiel #3
0
    def restore_blockpar(self, root: str) -> BlockPar:
        bp = BlockPar()

        keys = self.get(root, '0')
        values = self.get(root, '1')
        for i in range(len(keys.entries)):
            bp.add(keys.get_widestr(i), values.get_widestr(i))

        keys = self.get(root, '2')
        values = self.get(root, '3')
        for i in range(len(keys.entries)):
            bp.add(keys.get_widestr(i),
                   self.restore_blockpar(values.get_widestr(i)))

        return bp
Beispiel #4
0
 def dump(self, bp):
     nbp = BlockPar(sort=False)
     nbp.add("Star", str(self.star))
     nbp.add("Type", str(self.type))
     if self.type is not pt_.FREE:
         nbp.add("Object", str(self.object))
     if self.type is pt_.FREE:
         nbp.add("Angle", str(self.angle))
     if self.type in (pt_.FREE, pt_.TO_STAR, pt_.FROM_SHIP):
         nbp.add("Distance", str(self.distance))
     if self.type is not pt_.IN_PLANET:
         nbp.add("Radius", str(self.radius))
     if self.type in (pt_.TO_STAR, pt_.FROM_SHIP):
         nbp.add("Angle", str(self.angle))
     bp.add(str(self.name), nbp)
Beispiel #5
0
 def dump(self, bp):
     nbp = BlockPar(sort=False)
     nbp.add("Count", str(self.count))
     nbp.add("Owner", str(self.owner))
     nbp.add("Type", str(self.type))
     nbp.add("IsPlayer", str(self.is_player))
     nbp.add("Speed", str(self.speed))
     nbp.add("Weapon", str(self.weapon))
     nbp.add("CargoHook", str(self.cargohook))
     nbp.add("EmptySpace", str(self.emptyspace))
     if self._script.version < 7:
         nbp.add("Rating", str(self.rating))
     st = BlockPar(sort=False)
     st.add("Trader", str(self.status.trader))
     st.add("Warrior", str(self.status.warrior))
     st.add("Pirate", str(self.status.pirate))
     nbp.add("Status", st)
     if self._script.version < 7:
         nbp.add("Score", str(self.score))
     nbp.add("Strength", str(self.strength))
     nbp.add("Ruins", str(self.ruins))
     bp.add(str(self.name), nbp)
Beispiel #6
0
 def dump(self, bp):
     nbp = BlockPar(sort=False)
     nbp.add("Race", str(self.race))
     nbp.add("Owner", str(self.owner))
     nbp.add("Economy", str(self.economy))
     nbp.add("Government", str(self.government))
     nbp.add("Range", str(self.range))
     nbp.add("Dialog", str(self.dialog))
     bp.add(str(self.name), nbp)
Beispiel #7
0
 def dump(self, bp):
     nbp =BlockPar(sort=False)
     nbp.add("EndStar", str(self._script.stars[self.end_star].name) + \
                        ' (' + str(self.end_star) + ')')
     if self._script.version < 7:
         nbp.add("Angle", str(self.angle))
     nbp.add("Distance", str(self.distance))
     if self._script.version < 7:
         nbp.add("Relation", str(self.relation))
         nbp.add("Deviation", str(self.deviation))
     nbp.add("IsHole", str(self.is_hole))
     bp.add(str(self.name), nbp)
Beispiel #8
0
    def dump(self, bp):
        nbp = BlockPar(sort=False)
        nbp.add("Constellation", str(self.constellation))
        if self._script.version < 7:
            nbp.add("IsSubspace", str(self.is_subspace))
        nbp.add("NoKling", str(self.no_kling))
        nbp.add("NoComeKling", str(self.no_come_kling))

        nnbp = BlockPar(sort=False)
        for sl in self.starlinks:
            sl.dump(nnbp)
        nbp.add("StarLinks", nnbp)

        nnbp = BlockPar(sort=False)
        for p in self.planets:
            p.dump(nnbp)
        nbp.add("Planets", nnbp)

        nnbp = BlockPar(sort=False)
        for s in self.ships:
            s.dump(nnbp)
        nbp.add("Ships", nnbp)

        bp.add(str(self.name), nbp)
Beispiel #9
0
 def dump(self, bp):
     nbp = BlockPar(sort=False)
     nbp.add("Type", str(self.type))
     nbp.add("Value", str(self.value))
     bp.add(str(self.name), nbp)
Beispiel #10
0
    def dump(self, f):
        """
        :type f: io.TextIO
        """
        bp = BlockPar(sort=False)

        bp.add("Version", str(self.version))

        nbp = BlockPar(sort=False)
        for e in self.globalvars:
            e.dump(nbp)
        bp.add("GlobalVars", nbp)

        bp.add("GlobalCode", self.globalcode)

        nbp = BlockPar(sort=False)
        for e in self.localvars:
            e.dump(nbp)
        bp.add("LocalVars", nbp)

        bp.add("Constellations", str(self.constellations))

        nbp = BlockPar(sort=False)
        for e in self.stars:
            e.dump(nbp)
        bp.add("Stars", nbp)

        nbp = BlockPar(sort=False)
        for e in self.places:
            e.dump(nbp)
        bp.add("Places", nbp)

        nbp = BlockPar(sort=False)
        for e in self.items:
            e.dump(nbp)
        bp.add("Items", nbp)

        nbp = BlockPar(sort=False)
        for e in self.groups:
            e.dump(nbp)
        bp.add("Groups", nbp)

        nbp = BlockPar(sort=False)
        for e in self.grouplinks:
            e.dump(nbp)
        bp.add("GroupLinks", nbp)

        bp.add("InitCode", self.initcode)

        bp.add("TurnCode", self.turncode)

        bp.add("DialogBegin", self.dialogbegincode)

        nbp = BlockPar(sort=False)
        for i, e in enumerate(self.states):
            e.dump(nbp)
        bp.add("States", nbp)

        nbp = BlockPar(sort=False)
        for e in self.dialogs:
            e.dump(nbp)
        bp.add("Dialogs", nbp)

        nbp = BlockPar(sort=False)
        for e in self.dialog_msgs:
            e.dump(nbp)
        bp.add("DialogMsgs", nbp)

        nbp = BlockPar(sort=False)
        for e in self.dialog_answers:
            e.dump(nbp)
        bp.add("DialogAnswers", nbp)

        bp.save_txt(f)
        del bp
Beispiel #11
0
 def dump(self, bp):
     nbp = BlockPar(sort=False)
     nbp.add("Command", str(self.command))
     nbp.add("Answer", str(self.answer))
     nbp.add("Code", self.code)
     bp.add(str(self.name), nbp)
Beispiel #12
0
 def dump(self, bp):
     nbp = BlockPar(sort=False)
     nbp.add("Name", str(self.command))
     nbp.add("Code", self.code)
     bp[str(self.name)] = nbp
Beispiel #13
0
 def dump(self, bp):
     nbp = BlockPar(sort=False)
     nbp.add("Code", self.code)
     bp.add(str(self.name), nbp)
Beispiel #14
0
 def dump(self, bp):
     nbp = BlockPar(sort=False)
     nbp.add("Type", str(self.type))
     if self.type not in (mt_.NONE, mt_.FREE):
         nbp.add("Object", str(self.object))
     attack = BlockPar(sort=False)
     for i, a in enumerate(self.attack):
         attack.add(str(i), str(a))
     nbp.add("Attack", attack)
     nbp.add("TakeItem", str(self.take_item))
     nbp.add("TakeAll", str(self.take_all))
     nbp.add("OutMsg", str(self.out_msg))
     nbp.add("InMsg", str(self.in_msg))
     nbp.add("Ether", str(self.ether))
     nbp.add("Code", self.code)
     bp.add(str(self.name), nbp)
Beispiel #15
0
 def dump(self, bp):
     nbp = BlockPar(sort=False)
     nbp.add("Place", str(self.place))
     nbp.add("Class", str(self.kind))
     nbp.add("Type", str(self.type))
     nbp.add("Size", str(self.size))
     nbp.add("Level", str(self.level))
     nbp.add("Radius", str(self.radius))
     nbp.add("Owner", str(self.owner))
     nbp.add("Useless", str(self.useless))
     bp.add(str(self.name), nbp)
Beispiel #16
0
    def restore(self, f):
        """
        :type f: io.TextIO
        """
        root = BlockPar(sort=False)
        root.load_txt(f)

        self.version = int(root.get_par("Version"))

        for block in root.get_block("GlobalVars"):
            e = Var(self, block.name)
            e.restore(block.content)
            self.globalvars.append(e)

        self.globalcode = root.get_par("GlobalCode")

        for block in root.get_block("LocalVars"):
            e = Var(self, block.name)
            e.restore(block.content)
            self.localvars.append(e)

        self.constellations = int(root.get_par("Constellations"))

        for block in root.get_block("Stars"):
            e = Star(self, block.name)
            e.restore(block.content)
            self.stars.append(e)

        for block in root.get_block("Places"):
            e = Place(self, block.name)
            e.restore(block.content)
            self.places.append(e)

        for block in root.get_block("Items"):
            e = Item(self, block.name)
            e.restore(block.content)
            self.items.append(e)

        for block in root.get_block("Groups"):
            e = Group(self, block.name)
            e.restore(block.content)
            self.groups.append(e)

        for block in root.get_block("GroupLinks"):
            e = GroupLink(self, block.name)
            e.restore(block.content)
            self.grouplinks.append(e)

        self.initcode = root.get_par("InitCode")
        self.turncode = root.get_par("TurnCode")
        self.dialogbegincode = root.get_par("DialogBegin")

        for block in root.get_block("States"):
            e = State(self, block.name)
            e.restore(block.content)
            self.states.append(e)

        for block in root.get_block("Dialogs"):
            e = Dialog(self, block.name)
            e.restore(block.content)
            self.dialogs.append(e)

        for block in root.get_block("DialogMsgs"):
            e = DialogMsg(self, block.name)
            e.restore(block.content)
            self.dialog_msgs.append(e)

        for block in root.get_block("DialogAnswers"):
            e = DialogAnswer(self, block.name)
            e.restore(block.content)
            self.dialog_answers.append(e)
Beispiel #17
0
 def dump(self, bp):
     nbp = BlockPar(sort=False)
     nbp.add("Planet", str(self.planet))
     nbp.add("State", str(self.state) + \
                      '(' + str(self._script.states[self.state].name) + ')')
     nbp.add("Owner", str(self.owner))
     nbp.add("Type", str(self.type))
     nbp.add("Count", str(self.count))
     nbp.add("Speed", str(self.speed))
     nbp.add("Weapon", str(self.weapon))
     nbp.add("CargoHook", str(self.cargohook))
     nbp.add("EmptySpace", str(self.emptyspace))
     if self._script.version < 7:
         nbp.add("Friendship", str(self.friendship))
     nbp.add("AddPlayer", str(self.add_player))
     if self._script.version < 7:
         nbp.add("Rating", str(self.rating))
         nbp.add("Score", str(self.score))
     st = BlockPar(sort=False)
     st.add("Trader", str(self.status.trader))
     st.add("Warrior", str(self.status.warrior))
     st.add("Pirate", str(self.status.pirate))
     nbp.add("Status", st)
     nbp.add("SearchDist", str(self.search_distance))
     nbp.add("Dialog", str(self.dialog))
     nbp.add("Strength", str(self.strength))
     nbp.add("Ruins", str(self.ruins))
     bp.add(str(self.name), nbp)
Beispiel #18
0
class SourceScript:
    version = 6

    def __init__(self):
        self.viewpos = Point(0, 0)
        self.name = ""
        self.filename = ""

        self.textfilenames = BlockPar(sort=False)
        self.textfilenames["rus"] = ""
        self.translations = BlockPar(sort=False)
        self.translations_id = BlockPar(sort=False)

        self.graphpoints = []
        self.graphlinks = []
        self.graphrects = []

    def add(self, clsname, pos=None):
        if not pos:
            pos = random_point()
        gp = classnames[clsname](self, pos)
        self.graphpoints.append(gp)
        return gp

    def link(self, begin, end):
        if isinstance(begin, Star) and isinstance(end, Star):
            gl = StarLink(self, begin, end)
        elif isinstance(begin, Group) and isinstance(end, Group):
            gl = GroupLink(self, begin, end)
        elif isinstance(begin, State) and isinstance(end, State):
            gl = StateLink(self, begin, end)
        else:
            gl = GraphLink(self, begin, end)
        self.graphlinks.append(gl)
        # end.pos = near_point(begin.pos)
        return gl

    def find(self, name):
        if name == "": return None
        for gp in self.graphpoints:
            if gp.text == name:
                return gp
        return None

    def index(self, gp):
        if isinstance(gp, str):
            gp = self.find(gp)
        if not gp:
            return -1
        return self.graphpoints.index(gp)

    def find_link_begin(self, gp, clsname):
        cls = classnames[clsname]
        for gl in self.graphlinks:
            # noinspection PyTypeHints
            if (gl.begin is gp) and isinstance(gl.end, cls):
                return gl

    def save(self, f):
        s = Stream.from_io(f)

        s.add(b'\x55\x44\x33\x22')
        s.add_uint(self.version)
        s.add_int(self.viewpos.x)
        s.add_int(self.viewpos.y)
        s.add_widestr(self.name)
        s.add_widestr(self.filename)
        self.textfilenames.save(s)
        self.translations.save(s)
        self.translations_id.save(s)
        s.add_uint(len(self.graphpoints))
        for gp in self.graphpoints:
            gp.save(s)
        s.add_uint(len(self.graphlinks))
        for gl in self.graphlinks:
            gl.save(s)
        s.add_uint(len(self.graphrects))
        for gr in self.graphrects:
            gr.dump(s)