コード例 #1
0
ファイル: non_idea_costs.py プロジェクト: VforVal/pyradox
def ruler_cost(country, date = pyradox.Date('1444.11.11')):
    monarch = None
    heir = None
    for key, value in country.items():
        if isinstance(key, pyradox.Date):
            if key > date: break
            if 'monarch' in value:
                monarch = value['monarch']
                if heir is not None and monarch['name'] == heir['monarch_name']:
                    monarch_birth = heir_birth
                    heir = None
                else:
                    monarch_birth = key
            if 'heir' in value:
                heir = value['heir']
                heir_birth = key
                next_monarch_name = heir['monarch_name']
    
    cost = 0.0
    if monarch is not None:
        
        skill = sum(monarch[x] for x in ('adm', 'dip', 'mil'))
        age = max(15, (date - monarch_birth) / 365)
        print(skill, age)
        cost += 2 * (skill - 6) * 30 / age
    if heir is not None:
        skill = sum(heir[x] for x in ('adm', 'dip', 'mil'))
        age = (date - heir_birth) / 365
        cost += 2 * (skill - 6) * 30 / (age + 15)
    return cost
コード例 #2
0
ファイル: non_idea_costs.py プロジェクト: VforVal/pyradox
def government_cost(country, date = pyradox.Date('1444.11.11')):
    country = country.at_date(date)
    if 'government' not in country: return 0.0
    government = governments[country['government']]
    if 'nation_designer_cost' in government:
        return government['nation_designer_cost']
    else:
        return 0.0
コード例 #3
0
ファイル: non_idea_costs.py プロジェクト: VforVal/pyradox
def technology_cost(country, date = pyradox.Date('1444.11.11')):
    country = country.at_date(date)
    if 'valid_for_nation_designer' in tech_groups[country['technology_group']] and not tech_groups[country['technology_group']]['valid_for_nation_designer']:
        return 0.0
    if 'capital' in country:
        continent = continents[country['capital']]
    else:
        continent = fallback_continents[country['technology_group']]
    modifier = tech_groups[country['technology_group']]['modifier']
    baseline = tech_groups[baseline_tech[continent]]['modifier']
    if modifier < baseline:
        return (baseline - modifier) * 100
    else:
        return (baseline - modifier) * 20
コード例 #4
0
def generate_map(province_function, filename, force_min=None):
    number_map = {
        int(re.match('\d+', filename).group(0)):
        province_function(int(re.match('\d+', filename).group(0)),
                          province.at_date(pyradox.Date('1444.11.11')))
        for filename, province in provinces.items() if province_function(
            int(re.match('\d+', filename).group(0)), province) is not None
    }

    if force_min is None:
        force_min = min(number_map.values())

    effective_numbers = [max(x, force_min) for x in number_map.values()]

    ranks = scipy.stats.rankdata(effective_numbers, method=rank_method)
    min_rank = min(ranks)
    max_rank = max(ranks)
    range_rank = max_rank - min_rank
    colors = {}
    for number, rank in zip(number_map.values(), ranks):
        if number < force_min:
            colors[number] = pyradox.image.colormap_blue_red(0.0)
        else:
            colors[number] = pyradox.image.colormap_blue_red(
                (rank - min_rank) / range_rank)
    color_map = {
        province_id: colors[number]
        for province_id, number in number_map.items()
    }
    text_map = {
        province_id: ('%d' % round(number))
        for province_id, number in number_map.items()
    }

    province_map = pyradox.worldmap.ProvinceMap()
    image = province_map.generate_image(color_map)
    province_map.overlay_text(image,
                              text_map,
                              fontfile="tahoma.ttf",
                              default_font_color=(255, 255, 255),
                              fontsize=9,
                              antialias=False)
    pyradox.image.save_using_palette(image, filename)
コード例 #5
0
import _initpath
import os
import re
import collections

import pyradox


import pyradox

start_date = pyradox.Date('1444.11.11')

counts = pyradox.Tree() # province counts

# parse all files in a directory, producing instances of pyradox.Tree
for filename, data in pyradox.txt.parse_dir(os.path.join(pyradox.get_game_directory('EU4'), 'history', 'provinces')):
    # pyradox.Tree has many dict methods, such as .keys()
    if 'base_tax' not in data.keys(): continue
    
    trade_good = 'unknown'
    for curr_good in data.find_walk('trade_goods'):
        if curr_good != 'unknown':
            trade_good = curr_good
        
    if trade_good not in counts: counts[trade_good] = 1
    else: counts[trade_good] += 1
        
print([(key, counts[key]) for key in counts.keys()])
コード例 #6
0
ファイル: culture_stats.py プロジェクト: VforVal/pyradox
culture_tree = pyradox.txt.parse_file(
    os.path.join(pyradox.get_game_directory('EU4'), 'common', 'cultures',
                 '00_cultures.txt'))

for group_name, group_data in culture_tree.items():
    for culture in group_data:
        culture_groups[culture] = group_name

culture_data = {}
culture_group_data = {}

for filename, data in pyradox.txt.parse_dir(os.path.join(
        pyradox.get_game_directory('EU4'), 'history', 'provinces'),
                                            verbose=False):
    data = data.at_date(pyradox.Date('1444.11.11'))
    if 'culture' not in data:
        if 'base_tax' in data:
            print('No culture defined in %s.' % filename)
        continue
    if 'owner' not in data:
        continue
    culture = data['culture']
    culture_group = culture_groups[culture]

    culture = localized(culture)
    if culture not in culture_data:
        culture_data[culture] = ['', 0, 0, 0, 0]
    culture_data[culture][0] = localized(culture_group)
    culture_group = localized(culture_group)
コード例 #7
0
        r, g, b = color
        y = 0.2126 * r + 0.7152 * g + 0.0722 * b
        if y >= 255 / 2:
            text_color_string = '#000000'
        else:
            text_color_string = '#ffffff'
        result += '<span style="color:%s; background-color:%s">%0.2f </span>' % (text_color_string, bg_color_string, x)
        x += step
    print(result)

for mode in province_contents:

    val_min, val_max, step = province_contents[mode]
    val_range = val_max - val_min

    print_legend(val_min, val_max, step)

    colormap = {}
    for province_id, data in vanilla_provinces.items():
        data = data.at_date(pyradox.Date('1936.1.1'))
        if mode in data.keys():
            colormap[int(province_id)] = pyradox.image.colormap_red_green((data[mode] - val_min) / val_range)
            
    for province_id, data in tfh_provinces.items():
        data = data.at_date(pyradox.Date('1936.1.1'))
        if mode in data.keys():
            colormap[int(province_id)] = pyradox.image.colormap_red_green((data[mode] - val_min) / val_range)

    out = province_map.generate_image(colormap)
    out.save('out/%s_map.png' % mode)
コード例 #8
0
ファイル: core_map.py プロジェクト: SaucyPigeon/pyradox
    return m.group(1)


def compute_color(values):
    if isinstance(values[0], int):
        # rgb
        r = values[0]
        g = values[1]
        b = values[2]
        return (r, g, b)
    else:
        # hsv
        return pyradox.image.HSVtoRGB(values)


date = pyradox.Date('1936.1.1')
scale = 2.0

# state_id -> [tag]
capital_states = {}
country_colors = {}

country_color_file = pyradox.txt.parse_file(
    os.path.join(pyradox.get_game_directory('HoI4'), 'common', 'countries',
                 'colors.txt'))

for filename, country in pyradox.txt.parse_dir(
        os.path.join(pyradox.get_game_directory('HoI4'), 'history',
                     'countries')):
    tag = compute_country_tag(filename)
    if tag in country_color_file:
コード例 #9
0
ファイル: non_idea_costs.py プロジェクト: VforVal/pyradox
government_costs = {}

for tag, country in countries.items():
    if tag in ('NAT', 'PIR', 'REB'): continue
    print(tag)
    government_costs[tag] = [0.0, 0.0, 0.0] # ruler, govt., tech group
    government_costs[tag][0] = ruler_cost(country)
    government_costs[tag][1] = government_cost(country)
    government_costs[tag][2] = technology_cost(country)

provinces = load.province.get_provinces()

territory_costs = {tag : 0.0 for tag in countries.keys()}

for filename, province in provinces.items():
    province = province.at_date(pyradox.Date('1444.11.11'))
    if 'owner' not in province: continue
    territory_costs[province['owner']] += province_cost(province)
    
result = '{|class = "wikitable sortable"\n'
result += '! Country !! Tag !! Territory cost !! Ruler cost !! Government cost !! Technology cost !! Total cost \n'

for tag in sorted(government_costs.keys()):
    if territory_costs[tag] == 0: continue
    result += '|-\n'
    total_cost = sum(government_costs[tag]) + territory_costs[tag]
    result += '| %s || %s || %d || %0.1f || %d || %d || %d \n' % (
        load.country.get_country_name(tag), tag, territory_costs[tag],
        government_costs[tag][0], government_costs[tag][1], government_costs[tag][2],
        total_cost)
コード例 #10
0
                print(print_string)


def check_years(tech_keys, filename, date):
    for tech_key in tech_keys:
        tech = techs[tech_key]
        if (tech['start_year'] or 0) > date.year:
            print('%s : %s : Tech %s is ahead of time with year %s' %
                  (filename, date, tech_key, tech['start_year']))


for filename, country in pyradox.txt.parse_dir(
        os.path.join(pyradox.get_game_directory('HoI4'), 'history',
                     'countries')):
    tech_keys = set(country['set_technology'].keys())
    check_deps(tech_keys, filename, pyradox.Date('1936.1.1'))
    for date, effects in country.items():
        if not isinstance(date, pyradox.Date): continue
        if 'set_technology' not in effects: continue
        tech_keys |= set(effects['set_technology'].keys())
        check_deps(tech_keys, filename, date)

for filename, country in pyradox.txt.parse_dir(
        os.path.join(pyradox.get_game_directory('HoI4'), 'history',
                     'countries')):
    tech_keys = set(country['set_technology'].keys())
    check_years(tech_keys, filename, pyradox.Date('1936.1.1'))
    for date, effects in country.items():
        if not isinstance(date, pyradox.Date): continue
        if 'set_technology' not in effects: continue
        tech_keys |= set(effects['set_technology'].keys())