예제 #1
0
 def test_amber_zone_gov_law(self):
     '''Test gov+law in [20,21] => amber TZ'''
     system = System()
     system.mainworld.government = uwp.Government('A')
     system.mainworld.law_level = uwp.LawLevel('B')
     system.determine_travel_zone()
     self.assertTrue(system.zone == 'A')
예제 #2
0
 def test_red_zone_gov_law(self):
     '''Test gov+law >= 22 => red TZ'''
     system = System()
     system.mainworld.government = uwp.Government('C')
     system.mainworld.law_level = uwp.LawLevel('D')
     system.determine_travel_zone()
     self.assertTrue(system.zone == 'R')
예제 #3
0
 def test_green_zone_gov_law(self):
     '''Test gov+law < 20 => green TZ'''
     system = System()
     system.mainworld.government = uwp.Government('2')
     system.mainworld.law_level = uwp.LawLevel('5')
     system.determine_travel_zone()
     self.assertTrue(system.zone == '')
예제 #4
0
 def test_rez_zone_starport_x_flag(self):
     '''Test starport X => no red TZ (flag=False)'''
     system = System()
     system.mainworld.starport = 'X'
     system.mainworld.government = uwp.Government('2')
     system.mainworld.law_level = uwp.LawLevel('5')
     system.determine_travel_zone(False)
     self.assertFalse(system.zone == 'R')
예제 #5
0
 def test_as_json(self):
     '''Test system as_json() exporter'''
     system = System()
     jdata = system.as_json()
     s_data = json.loads(jdata)
     self.assertTrue(s_data['name'] == system.name)
     self.assertTrue(s_data['hex'] == system.hex)
     self.assertTrue(s_data['bases'] == system.bases)
     self.assertTrue(s_data['allegiance'] == system.allegiance)
     self.assertTrue(s_data['worlds'] == system.num_worlds)
     self.assertTrue(s_data['Ix'] == str(system.importance_x))
     self.assertTrue(s_data['Ex'] == str(system.economic_x))
     self.assertTrue(s_data['Cx'] == str(system.cultural_x))
     self.assertTrue(s_data['pbg'] == str(system.pbg))
예제 #6
0
 def test_json_importer(self):
     '''Test system.json_import() importer'''
     jdata = '{"mainworld": "{\\"trade_codes\\": [\\"Ni\\"], \\"travel_code\\": \\"\\", \\"is_mainworld\\": true, \\"mainworld_type\\":  \\"Planet\\", \\"parent_type\\": null, \\"orbit_around_parent\\": null, \\"uwp\\": \\"E510423-8\\", \\"orbit\\": 7, \\"bases\\": \\"\\"}", "worlds": 5, "allegiance": "Na", "stellar": "{\\"decimal\\": 2, \\"companion\\": \\"{\\\\\\"habitable_zone\\\\\\": 7, \\\\\\"spectral_type\\\\\\": \\\\\\"A\\\\\\", \\\\\\"companion\\\\\\": null, \\\\\\"decimal\\\\\\": 7, \\\\\\"size\\\\\\": \\\\\\"V\\\\\\"}\\", \\"habitable_zone\\": 7, \\"spectral_type\\": \\"A\\", \\"secondaries\\": {}, \\"size\\": \\"V\\"}", "Ix": "{-3}", "name": "", "zone": "", "Cx": "[511C]", "hex": "0000", "pbg": "001", "bases": "", "Ex": "(A31+2)", "nobility": "B"}'
     s_data = json.loads(jdata)
     system = System()
     system.json_import(jdata)
     self.assertTrue(s_data['name'] == system.name)
     self.assertTrue(s_data['hex'] == system.hex)
     self.assertTrue(s_data['bases'] == system.bases)
     self.assertTrue(s_data['allegiance'] == system.allegiance)
     self.assertTrue(s_data['worlds'] == system.num_worlds)
     self.assertTrue(s_data['Ix'] == str(system.importance_x))
     self.assertTrue(s_data['Ex'] == str(system.economic_x))
     self.assertTrue(s_data['Cx'] == str(system.cultural_x))
     self.assertTrue(s_data['pbg'] == str(system.pbg))
 def test_export_import(self):
     '''Test re-import of exported data'''
     for _ in range(SAMPLE_SIZE):
         syst = System()
         # System
         s_data = json.loads(syst.as_json())
         LOGGER.debug('s_data type: %s', type(s_data))
         LOGGER.debug('s_data: %s', s_data)
         self.compare_dict_to_system(s_data, syst)
         # Planet
         p_data = json.loads(syst.mainworld.as_json())
         LOGGER.debug('p_data type: %s', type(p_data))
         LOGGER.debug('p_data: %s', p_data)
         self.compare_dict_to_planet(p_data, syst.mainworld)
         # Star(s)
         st_data = json.loads(syst.stellar.as_json())
         LOGGER.debug('st_data type: %s', type(st_data))
         LOGGER.debug('st_data: %s', st_data)
         self.compare_dict_to_star(st_data, syst.stellar)
예제 #8
0
    def test_system_plugin(self):
        '''Test plugin basic variables set'''
        system = System()
        plugin = SystemPlugin(system)

        self.assertTrue(system == plugin.system)
        self.assertTrue(system.mainworld == plugin.mainworld)
        self.assertTrue(system.stellar == plugin.stellar)
        self.assertTrue(system.importance_x == plugin.importance_x)
        self.assertTrue(system.cultural_x == plugin.cultural_x)
        self.assertTrue(system.economic_x == plugin.economic_x)
예제 #9
0
 def populate_subsectors(self):
     '''Populate subsectors using data from self.hexes'''
     for hex_id in self.hexes.keys():
         subsector_id = self.find_subsector_id(hex_id)
         # system = self.hexes[hex_id]
         jdata = self.hexes[hex_id].as_json()
         ss_hex_id = self.sector_hex_to_subsector_hex(hex_id)
         LOGGER.debug('hex_id = %s, ss_hex_id = %s ss_id = %s', hex_id,
                      ss_hex_id, subsector_id)
         LOGGER.debug('(1) self.hexes.hex = %s', self.hexes[hex_id].hex)
         self.subsectors[subsector_id].hexes[ss_hex_id] = System()
         self.subsectors[subsector_id].hexes[ss_hex_id].json_import(jdata)
         self.subsectors[subsector_id].hexes[ss_hex_id].hex = ss_hex_id
         LOGGER.debug('(2) self.hexes.hex = %s', self.hexes[hex_id].hex)
     LOGGER.setLevel(logging.CRITICAL)
예제 #10
0
 def test_red_zone_starport_x_noflag(self):
     '''Test starport X => red TZ (flag=True)'''
     system = System()
     system.mainworld.starport = 'X'
     system.determine_travel_zone()
     self.assertTrue(system.zone == 'R')
예제 #11
0
    def test_owning_system_sector(self):
        '''Test owning system (sector)'''
        # Sector data - 0105 is the owned world, 0308 should be the owning world
        sector = Sector('Test sector')
        sector.hexes = {}
        s_data = [
            '{"mainworld": "{\\"trade_codes\\": [\\"Ni\\", \\"O:0101\\"],' + \
                '\\"travel_code\\": \\"\\",' + \
                '\\"is_mainworld\\": true,' + \
                '\\"mainworld_type\\":  \\"Planet\\",' + \
                '\\"parent_type\\": null,' + \
                '\\"orbit_around_parent\\": null,' + \
                '\\"uwp\\": \\"E9D8665-7\\",' + \
                '\\"orbit\\": 3,' + \
                '\\"bases\\": \\"\\"}",' + \
                '"worlds": 4,' + \
                '"allegiance": "Na",' + \
                '"stellar": "{\\"decimal\\": 3,' + \
                '\\"companion\\": null,' + \
                '\\"habitable_zone\\": 3,' + \
                '\\"spectral_type\\": \\"G\\",' + \
                '\\"secondaries\\": {},' + \
                '\\"size\\": \\"V\\"}",' + \
                '"Ix": "{-3}",' + \
                '"name": "Name-0105A",' + \
                '"zone": "",' + \
                '"Cx": "[5349]",' + \
                '"hex": "0105",' + \
                '"pbg": "202",' + \
                '"bases": "",' + \
                '"Ex": "(753+1)",' + \
                '"nobility": "B"}',
            '{"mainworld": "{\\"trade_codes\\": [\\"De\\", \\"Hi\\",' + \
                '\\"In\\", \\"Po\\", \\"Tz\\"],' + \
                '\\"travel_code\\": \\"\\",' + \
                '\\"is_mainworld\\": true,' + \
                '\\"mainworld_type\\":  \\"Planet\\",' + \
                '\\"parent_type\\": null,' + \
                '\\"orbit_around_parent\\": null,' + \
                '\\"uwp\\": \\"B140987-A\\",' + \
                '\\"orbit\\": 0,' + \
                '\\"bases\\": \\"\\"}",' + \
                '"worlds": 5,' + \
                '"allegiance": "Na",' + \
                '"stellar": "{\\"decimal\\": 0,' + \
                '\\"companion\\": null,' + \
                '\\"habitable_zone\\": 0,' + \
                '\\"spectral_type\\": \\"M\\",' + \
                '\\"secondaries\\": {},' + \
                '\\"size\\": \\"III\\"}",' + \
                '"Ix": "{+4}",' + \
                '"name": "Name-0308A",' + \
                '"zone": "",' + \
                '"Cx": "[ED17]",' + \
                '"hex": "0308",' + \
                '"pbg": "103",' + \
                '"bases": "",' + \
                '"Ex": "(A8A+1)",' + \
                '"nobility": "BEf"}',
            '{"mainworld": "{\\"trade_codes\\": [\\"Hi\\", \\"In\\"],' + \
                '\\"travel_code\\": \\"\\",' + \
                '\\"is_mainworld\\": true,' + \
                '\\"mainworld_type\\": \\"Planet\\",' + \
                '\\"parent_type\\": null,' + \
                '\\"orbit_around_parent\\": null,' + \
                '\\"uwp\\": \\"A54598A-C\\",' + \
                '\\"orbit\\": 2,' + \
                '\\"bases\\": \\"\\"}",' + \
                '"worlds": 5,' + \
                '"allegiance": "Na",' + \
                '"stellar": "{\\"decimal\\": 0,' + \
                '\\"companion\\": null,' + \
                '\\"habitable_zone\\": 2,' + \
                '\\"spectral_type\\": \\"K\\",' + \
                '\\"secondaries\\": {},' + \
                '\\"size\\": \\"V\\"}",' + \
                '"Ix": "{+4}",' + \
                '"name": "Name-0805A",' + \
                '"zone": "",' + \
                '"Cx": "[5D4C]",' + \
                '"hex": "0805",' + \
                '"pbg": "403",' + \
                '"bases": "N",' + \
                '"Ex": "(98A+3)",' + \
                '"nobility": "BEf"}',
            '{"mainworld": "{\\"trade_codes\\": [\\"Ni\\", \\"Ag\\", \\"Pr\\"],' + \
                '\\"travel_code\\": \\"\\",' + \
                '\\"is_mainworld\\": true,' + \
                '\\"mainworld_type\\":  \\"Planet\\",' + \
                '\\"parent_type\\": null,' + \
                '\\"orbit_around_parent\\": null,' + \
                '\\"uwp\\": \\"B588510-8\\",' + \
                '\\"orbit\\": 3,' + \
                '\\"bases\\": \\"\\"}",' + \
                '"worlds": 9,' + \
                '"allegiance": "Na",' + \
                '"stellar": "{\\"decimal\\": 7,' + \
                '\\"companion\\": null,' + \
                '\\"habitable_zone\\": 3,' + \
                '\\"spectral_type\\": \\"G\\",' + \
                '\\"secondaries\\": {},' + \
                '\\"size\\": \\"V\\"}",' + \
                '"Ix": "{+0}",' + \
                '"name":' + \
                '"Name-0702A",' + \
                '"zone": "",' + \
                '"Cx": "[7567]",' + \
                '"hex": "0702",' + \
                '"pbg": "802",' + \
                '"bases": "",' + \
                '"Ex": "(B41-1)",' + \
                '"nobility": "BcC"}'
        ]
        for dta in s_data:
            system = System()
            system.json_import(dta)
            sector.hexes[system.hex] = system

        self.assertTrue(sector.find_owning_system('0105') == '0308')
        sector.trade_code_owning_system()
        self.assertTrue('O:0308' in sector.hexes['0105'].mainworld.trade_codes)

        for _ in sector.t5_tab():
            print(_)
예제 #12
0
 def process_hex(self, hex_id, ss_id=''):
     '''Add system on probability check'''
     name = 'Name-{}{}'.format(hex_id, ss_id)
     if self.percentile() <= \
             self.system_presence_table.lookup(self.density):
         self.hexes[hex_id] = System(name, hex_id)
예제 #13
0
#! /usr/bin/env python
'''
Mega-system generator
'''

from T5_worldgen.system import System

print('name,port,siz,atm,hyd,pop,gov,law,tl,uwp')
for ctr in range(5000):
    syst = System('System-{0:04d}'.format(ctr))
    print(','.join([
        syst.name,
        str(syst.mainworld.starport),
        str(syst.mainworld.size),
        str(syst.mainworld.atmosphere),
        str(syst.mainworld.hydrographics),
        str(syst.mainworld.population),
        str(syst.mainworld.government),
        str(syst.mainworld.law_level),
        str(syst.mainworld.tech_level),
        syst.mainworld.uwp()
    ]))
예제 #14
0
'''Trade codes unit test module'''
from __future__ import print_function

import unittest
from T5_worldgen.planet import Planet
from T5_worldgen.system import System
import T5_worldgen.upp as uwp
from T5_worldgen.trade_codes import TradeCodes

SYSTEM = System()
# SYSTEM.stellar.habitable_zone = 3


def gen_trade_codes(planet, include_cepheus=True):
    '''Generate planet'''
    SYSTEM.mainworld = planet
    SYSTEM.determine_mw_orbit()
    codes = TradeCodes(planet, SYSTEM)
    trade_codes = codes.generate(include_cepheus)
    print(planet.uwp(), trade_codes)
    return trade_codes


class TestPlanetaryTradeCodes(unittest.TestCase):
    '''Trade codes: planetary unit tests - test for match'''
    def test_as(self):
        '''Test As'''
        planet = Planet()
        planet.size = uwp.Size(0)
        planet.atmosphere = uwp.Atmosphere(0)
        planet.hydrographics = uwp.Hydrographics(0)