def getGovernment(self, empire):
        governmentSet = naive_parser.ParseSaveFile("files/governments.txt")

        empire.ideology = empire.ideology.replace("_neutral", "")
        government = Dotdict({})

        if naive_parser.drill(governmentSet, "governments", empire.ideology):
            government.authority = naive_parser.drill(governmentSet,
                                                      "governments",
                                                      empire.ideology,
                                                      "authority")
            government.ethics = naive_parser.splitstrings(
                naive_parser.drill(governmentSet, "governments",
                                   empire.ideology, "ethics", ""))
            government.civics = naive_parser.splitstrings(
                naive_parser.drill(governmentSet, "governments",
                                   empire.ideology, "civics", ""))

        else:
            print("WARNING: Did not recognise " + empire.longTag() + "'s \"" +
                  empire.ideology +
                  "\" ideology. Falling back to generic democracy.")

            government.authority = "auth_democratic"
            government.ethics = [
                "ethic_egalitarian", "ethic_pacifist", "ethic_xenophobe"
            ]
            government.civics = [
                "civic_parliamentary_system", "civic_environmentalist"
            ]

        return government
Example #2
0
    def __init__(self, savefileName, hoi4path):
        self.hoi4path = hoi4path

        self.converterDir = os.path.dirname(os.path.realpath(__file__))
        self.converterDir = self.converterDir.replace("\\", "/") + "/"
        print("Running from: " + self.converterDir)

        print("Parsing save file...")
        self.savefile = naive_parser.ParseSaveFile(savefileName)
        print("Reading save data...")
        self.parser = naive_parser.Parser(self.savefile, self.hoi4path)
        print("Save file parsed.")
        self.topNations = self.parser.getTopNations()
    def __init__(self):
        BorgSingleton.__init__(self)
        if hasattr(self, 'loaded'): return
        self.loaded = True

        self.configfile = naive_parser.ParseSaveFile("configuration.txt")
        config = naive_parser.drill(self.configfile, "configuration")

        if getattr(sys, 'frozen', False):
            # running in a bundle
            self.converterDir = self.makeSanePath(
                os.path.dirname(sys.executable))
        else:
            # running live
            self.converterDir = self.makeSanePath(
                os.path.dirname(os.path.realpath(__file__)))

        print("Running from: " + self.converterDir)

        self.savefileName = naive_parser.unquote(
            naive_parser.drill(config, "savefile"))
        self.hoi4Path = naive_parser.unquote(
            naive_parser.drill(config, "HoI4directory"))
        self.hoi4ModPath = naive_parser.unquote(
            naive_parser.drill(config, "HoI4ModDirectory"))
        self.stellarisModPath = naive_parser.unquote(
            naive_parser.drill(config, "StellarisModdirectory"))

        self.useDefconResults = naive_parser.unquote(
            naive_parser.drill(config, "useDefconResults"))
        if self.useDefconResults == "y" or self.useDefconResults == "yes":
            self.defconResults = naive_parser.unquote(
                naive_parser.drill(config, "defconResults"))
        else:
            self.defconResults = False

        self.modName = "outputMod"

        self.baseModPath = self.converterDir + self.modName + "_base/"
        self.outputPath = self.converterDir + self.modName + "/"
        self.outputModFile = self.converterDir + self.modName + ".mod"
        if self.stellarisModPath:
            self.stellarisModPath = self.makeSanePath(self.stellarisModPath)
            self.finalPath = self.stellarisModPath + self.modName + "/"
            self.finalModFile = self.stellarisModPath + self.modName + ".mod"
        else:
            self.finalPath = ""
            self.finalModFile = ""

        if not self.isSane():
            sys.exit(0)
Example #4
0
    def __init__(self):
        print("Parsing configuration")
        self.configfile = naive_parser.ParseSaveFile("configuration.txt")

        self.savefile = naive_parser.drill(self.configfile, "configuration",
                                           "savefile")
        self.hoi4path = naive_parser.drill(self.configfile, "configuration",
                                           "HoI4directory")
        self.targetdir = naive_parser.drill(self.configfile, "configuration",
                                            "StellarisModdirectory")

        print("Save file: " + self.savefile)
        print("HoI4 location: " + self.hoi4path)
        print("Stellaris mod path: " + self.targetdir)

        self.savefile = reformatPath(self.savefile, False)
        self.hoi4path = reformatPath(self.hoi4path, True)
        self.targetdir = reformatPath(self.targetdir, True)

        if not self.savefile:
            print("Error: Could not parse save file.")
            sys.exit(1)

        if not self.hoi4path:
            print("Error: Could not parse HoI4 path.")
            sys.exit(1)

        if not self.targetdir:
            print(
                "Warning: Could not parse Stellaris mod path. Mod will only be created in the converter directory."
            )

        for path in [self.savefile, self.hoi4path, self.targetdir]:
            if not os.path.exists(path):
                print("Error: Could not find " + path)
                sys.exit(1)
Example #5
0
def MakeNameList(tag, hoi4path, destFolder):

    namespath = hoi4path + "common/names/01_names.txt"
    if os.path.exists(namespath):
        print("Reading names from modded " + namespath)
        names = naive_parser.ParseSaveFile(namespath)
    else:
        print("Reading names from " + hoi4path + "common/names/00_names.txt")
        names = naive_parser.ParseSaveFile(hoi4path +
                                           "common/names/00_names.txt")

    specialUnitNamePath = hoi4path + "common/units/names/00_" + tag + "_names.txt"
    if os.path.exists(specialUnitNamePath):
        print("Reading unique unit names from " + specialUnitNamePath)
        unitnames = naive_parser.ParseSaveFile(specialUnitNamePath)
    else:
        print("Could not find " + specialUnitNamePath)
        print("Reading unit names from " + hoi4path +
              "common/units/names/00_names.txt")
        unitnames = naive_parser.ParseSaveFile(
            hoi4path + "common/units/names/00_names.txt")

    malenames = stringlist_drill(names, tag, "male", "names")
    femalenames = stringlist_drill(names, tag, "female", "names")
    surnames = stringlist_drill(names, tag, "surnames")

    subs = stringlist_drill(unitnames, tag, "submarine",
                            "unique") + stringlist_drill(
                                unitnames, tag, "submarine", "generic")
    destroyers = stringlist_drill(unitnames, tag, "destroyer",
                                  "unique") + stringlist_drill(
                                      unitnames, tag, "destroyer", "generic")
    light_cruisers = stringlist_drill(
        unitnames, tag, "light_cruiser", "unique") + stringlist_drill(
            unitnames, tag, "light_cruiser", "generic")
    heavy_cruisers = stringlist_drill(
        unitnames, tag, "heavy_cruiser", "unique") + stringlist_drill(
            unitnames, tag, "heavy_cruiser", "generic")
    battle_cruisers = stringlist_drill(
        unitnames, tag, "battle_cruiser", "unique") + stringlist_drill(
            unitnames, tag, "battle_cruiser", "generic")
    battleships = stringlist_drill(unitnames, tag, "battleship",
                                   "unique") + stringlist_drill(
                                       unitnames, tag, "battleship", "generic")
    carriers = stringlist_drill(unitnames, tag, "carrier",
                                "unique") + stringlist_drill(
                                    unitnames, tag, "carrier", "generic")

    planetnames = subs
    ships = destroyers + light_cruisers + heavy_cruisers + battle_cruisers + battleships + carriers

    planetnames = [
        sub for sub in subs if not any(char.isdigit() for char in sub)
    ]

    if len(planetnames) < 10:
        extraplanets = ships[:]
        random.shuffle(extraplanets)
        planetnames += extraplanets

    print(len(planetnames))

    # Leave this in until I work out what accents Stellaris can't take
    ships = [removeAccents(s) for s in ships]
    planetnames = [removeAccents(s) for s in planetnames]
    malenames = [removeAccents(s) for s in malenames]
    femalenames = [removeAccents(s) for s in femalenames]
    surnames = [removeAccents(s) for s in surnames]

    templateData = {}
    templateData["&TAG&"] = tag
    templateData["&SHIPNAMES&"] = ships
    templateData["&PLANETNAMES&"] = planetnames
    templateData["&MALENAMES&"] = malenames
    templateData["&FEMALENAMES&"] = femalenames
    templateData["&SURNAMES&"] = surnames

    TemplateFill(templateData, "files/stellaris_name_list_template.txt",
                 destFolder + tag + "_test.txt")
Example #6
0
def MakeNameList(tag, destFolder):
    hoi4path = Config().getHoi4Path()

    includeGenericUnitNames = True

    namespath = Config().getModdedHoi4File("common/names/01_names.txt")
    if not namespath:
        namespath = Config().getModdedHoi4File("common/names/00_names.txt")
    print("Reading names from " + namespath)
    names = naive_parser.ParseSaveFile(namespath)

    modUnitNamesPath = Config().getModdedHoi4File(
        "common/units/names/01_names.txt")
    if modUnitNamesPath:
        print("Reading unit names from modded " + modUnitNamesPath)
        unitnames = naive_parser.ParseSaveFile(modUnitNamesPath)
        includeGenericUnitNames = False
    else:
        specialUnitNamePath = Config().getModdedHoi4File(
            "common/units/names/00_" + tag + "_names.txt")
        if not specialUnitNamePath:
            specialUnitNamePath = Config().getModdedHoi4File(
                "common/units/names/00_names.txt")
        print("Reading unique unit names from " + specialUnitNamePath)
        unitnames = naive_parser.ParseSaveFile(specialUnitNamePath)

    malenames = stringlist_drill(names, tag, "male", "names")
    femalenames = stringlist_drill(names, tag, "female", "names")
    surnames = stringlist_drill(names, tag, "surnames")

    subs = stringlist_drill(unitnames, tag, "submarine", "unique")
    destroyers = stringlist_drill(unitnames, tag, "destroyer", "unique")
    light_cruisers = stringlist_drill(unitnames, tag, "light_cruiser",
                                      "unique")
    heavy_cruisers = stringlist_drill(unitnames, tag, "heavy_cruiser",
                                      "unique")
    battle_cruisers = stringlist_drill(unitnames, tag, "battle_cruiser",
                                       "unique")
    battleships = stringlist_drill(unitnames, tag, "battleship", "unique")
    carriers = stringlist_drill(unitnames, tag, "carrier", "unique")

    if includeGenericUnitNames:
        subs += stringlist_drill(unitnames, tag, "submarine", "generic")
        destroyers += stringlist_drill(unitnames, tag, "destroyer", "generic")
        light_cruisers += stringlist_drill(unitnames, tag, "light_cruiser",
                                           "generic")
        heavy_cruisers += stringlist_drill(unitnames, tag, "heavy_cruiser",
                                           "generic")
        battle_cruisers += stringlist_drill(unitnames, tag, "battle_cruiser",
                                            "generic")
        battleships += stringlist_drill(unitnames, tag, "battleship",
                                        "generic")
        carriers += stringlist_drill(unitnames, tag, "carrier", "generic")

    planetnames = subs
    ships = destroyers + light_cruisers + heavy_cruisers + battle_cruisers + battleships + carriers

    # Leave this in until I work out what accents Stellaris can't take
    ships = removeAccents(ships)
    planetnames = removeAccents(planetnames)
    malenames = removeAccents(malenames)
    femalenames = removeAccents(femalenames)
    surnames = removeAccents(surnames)

    if len(planetnames) < 20:
        extraplanets = ships[:]
        random.shuffle(extraplanets)
        planetnames += extraplanets

    print(len(planetnames))

    templateData = {}
    templateData["&TAG&"] = tag
    templateData["&SHIPNAMES&"] = ships
    templateData["&PLANETNAMES&"] = planetnames
    templateData["&MALENAMES&"] = malenames
    templateData["&FEMALENAMES&"] = femalenames
    templateData["&SURNAMES&"] = surnames

    TemplateFill(templateData, "files/stellaris_name_list_template.txt",
                 destFolder + tag + "_test.txt")
        print(historyString)
        return historyString

    def getEarthTypeFlag(self):
        if self.nuclearWar == 2:
            return "nuclear_war"
        elif self.earthOwnedBy:
            return "give_planet"
        else:
            return "un_bureaucracy"

    def getEarthOwner(self):
        return self.earthOwnedBy

    def getEarthClass(self):
        return self.earthType

    def getEmpires(self):
        return self.empires


if __name__ == "__main__":
    savefile = naive_parser.ParseSaveFile("postwar_1948_06_16_01.hoi4")

    universe = Universe(savefile,
                        "D:/Steam/steamapps/common/Hearts of Iron IV/")
    universe.Load()

    for empire in universe.getEmpires():
        print(empire)
 def Init(self):
     print("Parsing save file...")
     self.savefile = naive_parser.ParseSaveFile(self.savefileName)
     print("Reading save data...")
     self.parser = naive_parser.Parser(self.savefile)
     print("Save file parsed.")
def getColours():
    hoi4ColourData = naive_parser.ParseSaveFile(
        config.Config().getModdedHoi4File("common/countries/colors.txt"))
    stellarisGreyData = {
        "grey": [0.65, 0.05, 0.35],
        "dark_grey": [0.65, 0.05, 0.22],
        "black": [0.5, 0.3, 0.05]
    }
    stellarisColourData = {
        "grey": [0.65, 0.05, 0.35],
        "dark_grey": [0.65, 0.05, 0.22],
        "black": [0.5, 0.3, 0.05],
        "dark_brown": [0.07, 0.6, 0.23],
        "brown": [0.07, 0.6, 0.4],
        "beige": [0.1, 0.4, 0.6],
        "yellow": [0.11, 0.8, 0.8],
        "light_orange": [0.09, 1.0, 0.8],
        "orange": [0.06, 0.9, 0.7],
        "red_orange": [0.01, 0.75, 0.7],
        "red": [0.0, 0.95, 0.5],
        "burgundy": [0.95, 0.8, 0.35],
        "pink": [0.88, 0.61, 0.5],
        "purple": [0.74, 0.65, 0.61],
        "dark_purple": [0.74, 0.71, 0.37],
        "indigo": [0.71, 0.85, 0.5],
        "dark_blue": [0.64, 0.85, 0.45],
        "blue": [0.64, 0.7, 0.6],
        "light_blue": [0.6, 0.6, 0.7],
        "turquoise": [0.49, 0.6, 0.6],
        "dark_teal": [0.5, 0.6, 0.3],
        "teal": [0.42, 0.6, 0.5],
        "light_green": [0.35, 0.5, 0.60],
        "green": [0.32, 0.6, 0.40],
        "dark_green": [0.33, 0.6, 0.27],
    }

    hsvSet = {}
    nameSet = {}
    for tag in hoi4ColourData:
        colour = naive_parser.drill(hoi4ColourData, tag, "color", "")
        rgb = ("." not in colour)
        colour = [float(x) for x in colour.replace("  ", " ").split(" ")]

        if rgb:
            colour = list(colorsys.rgb_to_hsv(*colour))
            colour[2] = colour[2] / 255

        hsvSet[tag] = colour

        minDist = 9999
        bestColour = "red"

        if colour[1] < 0.2:
            colourData = stellarisGreyData
        else:
            colourData = stellarisColourData

        for stellarisColour in colourData:
            stellarisHsv = colourData[stellarisColour]
            newDist = colourDistance(colour, stellarisHsv)
            if newDist < minDist:
                minDist = newDist
                bestColour = stellarisColour

        nameSet[tag] = bestColour

    return nameSet
def getClimates():

    climateMap = {}
    stateMap = getStates()

    strategicRegionsPath = config.Config().getModdedHoi4File(
        "map/strategicregions/")
    for filename in os.listdir(strategicRegionsPath):
        climateData = naive_parser.ParseSaveFile(strategicRegionsPath +
                                                 filename)
        provinces = naive_parser.drill(climateData, "strategic_region",
                                       "provinces", "").split(" ")
        periodses = naive_parser.drill(climateData, "strategic_region",
                                       "weather")
        if "period" not in periodses:
            continue
        periods = periodses["period"]
        yearTemperatures = []
        yearRain = []
        yearSnow = []
        yearSand = []

        if len(periods) == 0:
            continue

        for period in periods:
            temperatureRange = naive_parser.drill(period, "temperature",
                                                  "").split(" ")
            maxTemp = temperatureRange[1].replace("\"", "")
            minTemp = temperatureRange[0].replace("\"", "")
            temperature = float(maxTemp) - float(minTemp)
            yearTemperatures.append(temperature)

            lightRain = naive_parser.unquote(
                naive_parser.drill(period, "rain_light"))
            heavyRain = naive_parser.unquote(
                naive_parser.drill(period, "rain_heavy"))
            snow = naive_parser.unquote(naive_parser.drill(period, "snow"))
            blizzard = naive_parser.unquote(
                naive_parser.drill(period, "blizzard"))
            sandstorm = naive_parser.unquote(
                naive_parser.drill(period, "sandstorm"))

            yearRain.append(float(lightRain) + float(heavyRain) * 2)
            yearSnow.append(float(snow) + float(blizzard) * 3)
            yearSand.append(float(sandstorm))

        averageTemperature = sum(yearTemperatures) / len(yearTemperatures)
        averageRain = sum(yearRain) / len(yearRain)
        averageSnow = sum(yearSnow) / len(yearSnow)
        averageSand = sum(yearSand) / len(yearSand)

        climate = "pc_arid"
        if averageSand > 0.05:
            climate = "pc_desert"
        elif averageSnow > 0.3:
            climate = "pc_arctic"
        elif averageSnow > 0.1:
            climate = "pc_tundra"
        elif averageTemperature > 10.0:
            climate = "pc_arid"
        elif averageTemperature < 4.7:
            climate = "pc_savannah"
        else:
            climate = "pc_alpine"

        for province in provinces:
            if not province:
                continue
            provinceId = int(province)
            if provinceId in stateMap:
                stateId = stateMap[provinceId]
                climateMap[stateId] = climate

    return climateMap