Exemplo n.º 1
0
def getUnmodifiedBilateralTradeNumber(source, dest):
    """
    It is unmodified with respect to the path between the worlds.
    :param source:
    :param dest:
    :return:
    """
    if 'wtn' not in source:
        source['wtn'] = getWorldTradeNumber(uwp.strToUwp(source['uwpString']))
    if 'wtn' not in dest:
        dest['wtn'] = getWorldTradeNumber(uwp.strToUwp(dest['uwpString']))
    return source['wtn'] + dest['wtn'] + getWorldTradeCodeModifier(
        source, dest)
Exemplo n.º 2
0
def drawSystemDemographics(draw, origin, system, hexSize, colour):
    coords = hexutils.getCenter(origin, hexSize)
    s = uwp.strToUwp(system['uwpString'])
    circleTable = {
        '0': {
            'base': 0,
            'max': 0
        },
        '1': {
            'base': 0.015125,
            'max': 0.03125
        },
        '2': {
            'base': 0.03125,
            'max': 0.0625
        },
        '3': {
            'base': 0.0625,
            'max': 0.125
        },
        '4': {
            'base': 0.125,
            'max': 0.25
        },
        '5': {
            'base': 0.25,
            'max': 0.5
        },
        '6': {
            'base': 0.5,
            'max': 1
        },
        '7': {
            'base': 1,
            'max': 2
        },
        '8': {
            'base': 2,
            'max': 4
        },
        '9': {
            'base': 4,
            'max': 8
        },
        'A': {
            'base': 8,
            'max': 16
        },
    }
    base = int(hexSize * circleTable[s['Population']]['base'])
    if system['p'] in ['1', '2', '3', '4', '5', '6', '7', '8', '9']:
        max = int(hexSize * circleTable[s['Population']]['max'])
        range = max - base
        mod = int(int(system['p']) * range / 10)
    else:
        mod = 0
    radius = int((base + mod) / 2)
    box = [(coords[0] - radius, coords[1] - radius),
           (coords[0] + radius, coords[1] + radius)]
    draw.ellipse(box, fill=colour, outline='#ffffff', width=int(radius / 10))
Exemplo n.º 3
0
def autocompleteSystem(system, update):
    # All about names
    if not system['hex']:
        raise ValueError
    if not system['name']:
        system['name'] = generateNameFromHex(system['hex'])

    # All about UWP
    if not system['uwpString']:
        s = uwp.generate()
        system['uwpString'] = uwp.uwpToStr(s)
    else:
        s = uwp.strToUwp(system['uwpString'])

    if not system['base'] or update:
        system['base'] = generateBase(s)
    if not system['trade'] or update:
        system['trade'] = trade.generate(s)
    if not system['zone'] or update:
        system['zone'] = generateZone(s)
    if not system['p'] or update:
        system['p'] = generatePopulationMultiplier(s)
    if not system['b'] or update:
        system['b'] = generateBelts(s)
    if not system['g'] or update:
        system['g'] = generateGasGiants(s)
    if not system['allegiance'] or update:
        system['allegiance'] = 'Na'
    if not system['stellar'] or update:
        system['stellar'] = stellar.generate(s)
    return system
Exemplo n.º 4
0
def drawSystem(draw, origin, system, hexSize, scheme):
    s = uwp.strToUwp(system['uwpString'])
    drawDot(draw, origin, s, hexSize, scheme)
    drawName(draw, origin, system['name'], s['Population'], hexSize, scheme)
    drawStarport(draw, origin, s['Starport'], hexSize, scheme)
    drawUwp(draw, origin, system['uwpString'], hexSize, scheme)
    drawGasGiant(draw, origin, system['g'], hexSize, scheme)
    drawBase(draw, origin, system['base'], hexSize, scheme)
Exemplo n.º 5
0
def getTradeRoute(source, dest, systems, map, jumprange=2):
    source['wtn'] = trade.getWorldTradeNumber(uwp.strToUwp(
        source['uwpString']))
    dest['wtn'] = trade.getWorldTradeNumber(uwp.strToUwp(dest['uwpString']))
    ubtn = trade.getUnmodifiedBilateralTradeNumber(source, dest)

    if ubtn < BTN_CUTOFF:
        return None

    path = getBestPath(source, dest, systems, map, jumprange)
    if path:
        btn = ubtn + evaluatePath(path)
    else:
        return None

    jr = min(source['wtn'], dest['wtn'])
    if btn > (jr + 5):
        btn = jr + 5

    return {'btn': btn, 'path': path}
Exemplo n.º 6
0
def drawWorldTradeNumber(input, output, hexSize=256, scheme=DRAFT_SCHEME):
    systems = sector.readSystemsFromFile(input)
    politicalPalette = political.constructPalette(systems)
    economics = []
    for system in systems:
        if system['type'] == 'system':
            wtn = trade.getWorldTradeNumber(uwp.strToUwp(system['uwpString']))
            economics.append({'wtn': wtn, 'system': system})
    economics.sort(key=lambda i: i['wtn'], reverse=True)
    draw, img = hexgrid.getSectorCanvas(hexSize)
    for entry in economics:
        system = entry['system']
        x, y = sector.getCoords(system)
        # x,y coords start from 1
        origin = hexutils.getPosition(x - 1, y - 1, hexSize)
        drawSystemEconomics(draw, origin, entry['wtn'], hexSize,
                            politicalPalette[entry['system']['allegiance']])
    img.save(output)
Exemplo n.º 7
0
def drawDemographics(input, output, hexSize=256, scheme=DRAFT_SCHEME):
    systems = sector.readSystemsFromFile(input)
    politicalPalette = political.constructPalette(systems)
    demographics = []
    for system in systems:
        if system['type'] == 'system':
            s = uwp.strToUwp(system['uwpString'])
            demographic = (int(s['Population'], 16), int(system['p']))
            demographics.append({
                'demographics': demographic,
                'system': system
            })
    demographics.sort(key=lambda i: i['demographics'][0], reverse=True)
    draw, img = hexgrid.getSectorCanvas(hexSize)
    for entry in demographics:
        system = entry['system']
        x, y = sector.getCoords(system)
        # x,y coords start from 1
        origin = hexutils.getPosition(x - 1, y - 1, hexSize)
        drawSystemDemographics(draw, origin, system, hexSize,
                               politicalPalette[entry['system']['allegiance']])
    img.save(output)