summaryrefslogtreecommitdiff
path: root/hercules/code/server/evol/consts.py
blob: a1cdf185f39d3a982ee3cafcd6eb06ba2263da02 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf8 -*-
#
# Copyright (C) 2014  Evol Online
# Author: Andrei Karas (4144)

import re

def convertConsts(quests):
    dstFile = "newserverdata/db/const.txt"
    fieldsSplit = re.compile("\t+")
    fields = dict()
    with open(dstFile, "w") as w:
        srcFile = "serverdata/db/const.txt"
        with open(srcFile, "r") as r:
            for line in r:
                if len(line) < 2 or line[0:2] == "//":
                    continue
                line = line.replace(" ", "\t")
                rows = fieldsSplit.split(line)
                sz = len(rows)
                if sz < 2 or sz > 3:
                    continue

                fields[rows[0]] = rows[1][:-1]
                if sz == 2:
                    w.write("{0}\t{1}".format(rows[0], rows[1]))
                else:
                    w.write("{0}\t{1}\t{2}".format(rows[0], rows[1], rows[2]))
        # build in parameters
        w.write("ClientVersion\t10000\t1\n")

        srcFile = "oldserverdata/db/const.txt"
        w.write("// evol constants\n")
        with open(srcFile, "r") as r:
            for line in r:
                if len(line) < 2 or line[0:2] == "//":
                    continue
                line = line.replace(" ", "\t")
                rows = fieldsSplit.split(line)
                if len(rows) != 2:
                    continue

                if rows[0] in quests:
                    rows[1] = str(quests[rows[0]]) + "\n"
                if rows[0] in fields:
                    if fields[rows[0]] != rows[1][:-1]:
                        print("warning: different const values for {0} ({1}, {2})".format(rows[0], rows[1][:-1], fields[rows[0]]))
                else:
                    w.write("{0}\t{1}".format(rows[0], rows[1]))