Пример #1
0
 def testCodeCheckFails(self):
     code = TradeCodes("Wa")
     self.assertFalse(code.check_world_codes(self.star1))
     self.assertFalse(code.check_world_codes(self.star2))
Пример #2
0
    def parse_line_into_star(line, sector, pop_code, ru_calc):
        star = Star()
        star.sector = sector
        star.logger.debug(line)
        if Star.starline.match(line):
            data = Star.starline.match(line).groups()
        elif '{Anomaly}' in line:
            star.logger.info(
                "Found anomaly, skipping processing: {}".format(line))
            return None
        else:
            star.logger.error(u"Unmatched line: {}".format(line))
            return None

        star.logger.debug(data)

        star.position = data[0].strip()
        star.set_location(sector.dx, sector.dy)
        star.name = data[1].strip()

        star.uwp = data[2].strip()
        star.port = star.uwp[0]
        star.size = star.uwp[1]
        star.atmo = star.uwp[2]
        star.hydro = star.uwp[3]
        star.pop = star.uwp[4]
        star.gov = star.uwp[5]
        star.law = star.uwp[6]
        star.tl = star._ehex_to_int(star.uwp[8])
        try:
            star.popCode = star._ehex_to_int(star.pop)
        except ValueError:
            star.popCode = 12

        star.tradeCode = TradeCodes(data[3].strip())
        star.ownedBy = star.tradeCode.owned_by(star)

        star.economics = data[6].strip(
        ) if data[6] and data[6].strip() != u'-' else None
        star.social = data[7].strip(
        ) if data[7] and data[7].strip() != u'-' else None

        star.nobles = Nobles()
        star.nobles.count(data[11])

        star.baseCode = data[12].strip()
        star.zone = data[13].strip()
        star.ggCount = int(data[14][2], 16) if data[14][2] not in 'X?' else 0
        star.popM = int(data[14][0]) if data[14][0] not in 'X?' else 0
        star.belts = int(data[14][1], 16) if data[14][1] not in 'X?' else 0

        star.worlds = int(data[15]) if data[15].strip().isdigit() else 0

        star.alg = data[16].strip()
        star.alg_base = star.alg

        star.stars = data[17].strip()
        star.extract_routes()
        star.split_stellar_data()

        star.uwpCodes = {
            'Starport': star.port,
            'Size': star.size,
            'Atmosphere': star.atmo,
            'Hydrographics': star.hydro,
            'Population': star.pop,
            'Government': star.gov,
            'Law Level': star.law,
            'Tech Level': star.uwp[8],
            'Pop Code': str(star.popM)
        }

        star.tradeCode.check_world_codes(star)

        if (data[5]):
            imp = int(data[5][1:-1].strip())
            star.calculate_importance()
            if imp != star.importance:
                star.logger.error(
                    u'{}-{} Calculated importance {} does not match generated importance {}'
                    .format(star, star.baseCode, star.importance, imp))
        else:
            star.calculate_importance()

        star.check_ex()
        star.check_cx()

        star.calculate_wtn()
        star.calculate_mspr()
        star.calculate_gwp(pop_code)

        star.calculate_TCS()
        star.calculate_army()
        star.calculate_ru(ru_calc)

        star.tradeIn = 0
        star.tradeOver = 0
        star.tradeCount = 0
        star.passIn = 0
        star.passOver = 0
        star.starportSize = 0
        star.starportBudget = 0
        star.starportPop = 0

        star.eti_cargo_volume = 0
        star.eti_pass_volume = 0
        star.eti_cargo = 0
        star.eti_passenger = 0
        star.eti_worlds = 0
        star.calculate_eti()

        star._hash = None
        star.trade_id = None  # Used by the Speculative Trade
        return star
Пример #3
0
 def testCodeCheck(self):
     code = TradeCodes("Fl")
     self.assertTrue(code.check_world_codes(self.star1))
Пример #4
0
 def testCodeCheck2(self):
     code = TradeCodes("Po Lo")
     self.assertTrue(code.check_world_codes(self.star2))
     self.assertTrue(code.poor)
     self.assertTrue(code.low)
Пример #5
0
 def testWorldSophontsMultiple(self):
     code = TradeCodes("Ag Wiki4 Huma2")
     self.assertFalse(code.homeworld)
     self.assertTrue(code.sophonts == ['Wiki4', 'Huma2'])
     self.assertTrue(code.codeset == ['Ag'])
Пример #6
0
 def testSophontCombined(self):
     code = TradeCodes("Ri (Wiki) Huma4 Alph2 (Deneb)2")
     self.assertTrue(len(code.homeworld) > 0)
     self.assertTrue(code.sophonts == ['Huma4', 'Alph2', 'WikiW', 'Dene2'], msg=code.sophonts)
     self.assertTrue(code.homeworld == ['Wiki', 'Deneb'], msg=code.homeworld)
     self.assertTrue(code.codeset == ['Ri'], code.codeset)
Пример #7
0
 def testSophontsPartial(self):
     code = TradeCodes(u"(Wiki)4")
     self.assertTrue(code.homeworld == [u'Wiki'], code.homeworld)
     self.assertTrue(code.sophonts == [u'Wiki4'])
Пример #8
0
 def testWorldSophont(self):
     code = TradeCodes("Ag Huma4")
     self.assertFalse(code.homeworld)
     self.assertTrue(code.sophonts == ['Huma4'])
     self.assertTrue(code.codeset == ['Ag'])
Пример #9
0
 def testSophonts(self):
     code = TradeCodes(u"(Wiki)")
     self.assertTrue(code.homeworld == [u'Wiki'], code.homeworld)
     self.assertTrue(code.sophonts == [u'WikiW'], code.sophonts)
Пример #10
0
 def testOwned(self):
     code = TradeCodes(u"Ag O:1011")
     self.assertTrue(code.owned == [u'O:1011'], code.owned)
     self.assertTrue(code.owners('Deneb') == [u'O:Dene-1011'])
     self.assertTrue(code.colonies('Deneb') == [])
Пример #11
0
 def testColony(self):
     code = TradeCodes(u"Ph C:0404")
     self.assertTrue(code.owned == [u'C:0404'], code.owned)
     self.assertTrue(code.colonies("Spinward Marches") == [u'C:Spin-0404'], code.colonies("Spinward Marches"))
     self.assertTrue(code.owners('Spinward Marches') == [])
Пример #12
0
 def testOrdering(self):
     code = TradeCodes("Wa Ag Ni")
     self.assertTrue(code.pcode == 'Wa')
     self.assertTrue(str(code) == u'Ag Ni Wa')
     self.assertTrue(code.agricultural)
     self.assertTrue(code.nonindustrial)
Пример #13
0
 def testLo(self):
     code = TradeCodes("Lo")
     self.assertTrue(code.pcode is None)
     self.assertTrue(str(code) == u'Lo')
     self.assertTrue(code.low)
     self.assertFalse(code.high)