def calculateAvailablePassengers( tradingCore, passenger ): # Total passengers = start planet population + start planet traffic mod + # end planet traffic mod + # half Effect of player roll startPlanet = get_object_or_404( Planet, location__exact=tradingCore['startPlanet'] ) endPlanet = get_object_or_404( Planet, location__exact=tradingCore['destinationPlanet'] ) effect = int( math.ceil( passenger['passengerRoll'] / 2 ) ) dm = startPlanet.population + __calculateCurrentPlanetDM( startPlanet ) + \ __calculateDestinationPlanetDM( endPlanet ) + \ effect if ( dm < 0 ): dm = 0; if ( dm > 16 ): dm = 16 p = PASSENGER_TRAFFIC_VALUE[dm] low = parseDiceExpr( p['low'] ) middle = parseDiceExpr( p['middle'] ) high = parseDiceExpr( p['high'] ) if ( low < 0 ): low = 0 if ( middle < 0 ): middle = 0; if ( high < 0 ): high = 0; return { 'low': low, 'middle': middle, 'high': high }
def canCarryMail( tradingCore, tradingMail ): tm = calculateFreightTrafficModifer( tradingCore['startPlanet'], tradingCore['destinationPlanet'] ) mailMod = 0 if tm <= -10: mailMod -= 2 elif tm <= -5: mailMod -= 1 elif tm <= 4: mailMod += 0 elif tm <= 9: mailMod += 1 elif tm >= 10: mailMod += 2 else: raise Exception( 'Whoa mail broken - wtf is tm? ', tm ) if tradingMail['armed']: mailMod += 2 mailMod += tradingMail['navalScoutRank'] mailMod += tradingMail['socialStanding'] startPlanet = get_object_or_404( Planet, location__exact=tradingCore['startPlanet'] ) if startPlanet.tech_level <= 5: mailMod -= 4 mailRoll = parseDiceExpr( "2d12+" + str( mailMod ) ) logger.info( "Rolled " + str( mailRoll ) + " for mail." ) return mailRoll >= 12
def determineGoodsAvailable( tradingCore, tradingSpeculative ): startPlanet = get_object_or_404( Planet, location__exact=tradingCore['startPlanet'] ) availableGoods = {} merchantGoods = trade_code_with_goods['common_goods'] for t in startPlanet.generateTradeCode().split( " " ): merchantGoods += trade_code_with_goods[t] extra_goods = parseDiceExpr( "1d6" ) for _ in range( extra_goods ): # no do-while in python? while True: tens = parseDiceExpr( "1d6" ) units = parseDiceExpr( "1d6" ) dice_total = tens * 10 + units # roll again on 66 if dice_total < 66: break; merchantGoods += ( trade_lookup[dice_total], ) for c in merchantGoods: item = trade_goods[c] if c not in availableGoods: availableGoods[c] = { 'display': item.name, 'cost': item.cost, 'availability': parseDiceExpr( item.availability ), 'purchaseDm': tradingSpeculative['broker'] + \ tradingSpeculative['intOrSocial'] + \ __calcGoodsDM( item.purchase, startPlanet ) - \ __calcGoodsDM( item.sale, startPlanet ), 'illegal': item.illegal } else: availableGoods[c]['availability'] += parseDiceExpr( item.availability ) # filter illegal goods return availableGoods