Guest User

Untitled

a guest
Jul 6th, 2023
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 33.25 KB | None | 0 0
  1. async def revenue_calc(message: discord.Message, nation: dict, radiation: dict, treasures: dict, prices: dict, colors: dict, seasonal_mod: dict, build: str = None, single_city: bool = False, include_spies: bool = False) -> dict:
  2.     max_commerce = 100
  3.     base_com = 0
  4.     hos_dis_red = 2.5
  5.     alu_mod = 1
  6.     mun_mod = 1
  7.     gas_mod = 1
  8.     manu_poll_mod = 1
  9.     farm_poll_mod = 0.5
  10.     subw_poll_red = 45
  11.     rss_upkeep_mod = 1
  12.     ste_mod = 1
  13.     rec_poll = 70
  14.     pol_cri_red = 2.5
  15.     food_land_mod = 500
  16.     uranium_mod = 1
  17.     rss_upkeep = 0
  18.     civil_upkeep = 0
  19.     military_upkeep = 0
  20.     money_income = 0
  21.     power_upkeep = 0
  22.     nationpop = 0
  23.     color_bonus = 0
  24.     policy_bonus = 1
  25.     new_player_bonus = 1
  26.     mil_cost = 1
  27.     total_infra = 0
  28.     starve_net_text = ""
  29.     starve_money_text = ""
  30.     starve_exp_text = ""
  31.     color_text = ""
  32.     new_player_text = ""
  33.     policy_bonus_text = ""
  34.     treasure_text = ""
  35.     footer = ""
  36.    
  37.     if nation['ironw'] == True:
  38.         ste_mod = 1.36
  39.     if nation['bauxitew'] == True:
  40.         alu_mod = 1.36
  41.     if nation['armss'] == True:
  42.         mun_mod = 1.34
  43.     if nation['egr'] == True:
  44.         gas_mod = 2
  45.     if nation['massirr'] == True:
  46.         food_land_mod = 400
  47.     if nation['itc'] == True:
  48.         max_commerce = 115
  49.     if nation['telecom_satellite'] == True:
  50.         max_commerce = 125
  51.         base_com = 2
  52.     if nation['recycling_initiative'] == True:
  53.         rec_poll = 75
  54.     if nation['green_tech'] == True:
  55.         manu_poll_mod = 0.75
  56.         farm_poll_mod = 0.5
  57.         subw_poll_red = 70
  58.         rss_upkeep_mod = 0.9
  59.     if nation['clinical_research_center'] == True:
  60.         hos_dis_red = 3.5
  61.     if nation['specialized_police_training'] == True:
  62.         hos_dis_red = 3.5
  63.     if nation['uap'] == True:
  64.         uranium_mod = 2
  65.  
  66.     coal = 0
  67.     oil = 0
  68.     uranium = 0
  69.     lead = 0
  70.     iron = 0
  71.     bauxite = 0
  72.     gasoline = 0
  73.     munitions = 0
  74.     steel = 0
  75.     aluminum = 0
  76.     food = 0
  77.  
  78.     if build != None:
  79.         try:
  80.             build = json.loads(build)
  81.         except json.JSONDecodeError:
  82.             await message.edit(content="Something is wrong with the build you sent!")
  83.             return
  84.         land = 0
  85.         for city in nation['cities']:
  86.             land += city['land']
  87.         city = {}
  88.         for key, value in build.items():
  89.             city[key[4:]] = int(value)
  90.         city['infrastructure'] = city.pop('a_needed')
  91.         city['land'] = round(land/nation['num_cities'])
  92.         city['powered'] = True
  93.         city['date'] = nation['cities'][math.ceil(nation['num_cities']/2)]['date']
  94.         city['airforcebase'] = city['hangars']
  95.         nation['cities'] = [city]
  96.         #print(city)
  97.  
  98.     for city in nation['cities']:
  99.         total_infra += city['infrastructure']
  100.         base_pop = city['infrastructure'] * 100
  101.         pollution = 0
  102.         unpowered_infra = city['infrastructure']
  103.         for wind_plant in range(city['windpower']): #can add something about wasted slots
  104.             if unpowered_infra > 0:
  105.                 unpowered_infra -= 250
  106.                 power_upkeep += 42
  107.         for nucl_plant in range(city['nuclearpower']):
  108.             power_upkeep += 10500
  109.             for level in range(2):
  110.                 if unpowered_infra > 0:
  111.                     unpowered_infra -= 1000
  112.                     uranium -= 1.2
  113.         for oil_plant in range(city['oilpower']):
  114.             power_upkeep += 1800
  115.             pollution += 6
  116.             for level in range(5):
  117.                 if unpowered_infra > 0:
  118.                     unpowered_infra -= 100
  119.                     oil -= 1.2
  120.         for coal_plant in range(city['coalpower']):
  121.             power_upkeep += 1200  
  122.             pollution += 8
  123.             for level in range(5):
  124.                 if unpowered_infra > 0:
  125.                     unpowered_infra -= 100
  126.                     coal -= 1.2
  127.  
  128.         rss_upkeep += 400 * city['coalmine'] * rss_upkeep_mod
  129.         pollution += 12 * city['coalmine']
  130.         coal += 3 * city['coalmine'] * (1 + ((0.5 * (city['coalmine'] - 1)) / (10 - 1)))
  131.  
  132.         rss_upkeep += 600 * city['oilwell'] * rss_upkeep_mod
  133.         pollution += 12 * city['oilwell']
  134.         oil += 3 * city['oilwell'] * (1 + ((0.5 * (city['oilwell'] - 1)) / (10 - 1)))
  135.  
  136.         rss_upkeep += 5000 * city['uramine'] * rss_upkeep_mod
  137.         pollution += 20 * city['uramine']
  138.         uranium += 3 * city['uramine'] * (1 + ((0.5 * (city['uramine'] - 1)) / (5 - 1))) * uranium_mod
  139.  
  140.         rss_upkeep += 1500 * city['leadmine'] * rss_upkeep_mod
  141.         pollution += 12 * city['leadmine']
  142.         lead += 3 * city['leadmine'] * (1 + ((0.5 * (city['leadmine'] - 1)) / (10 - 1)))
  143.  
  144.         rss_upkeep += 1600 * city['ironmine'] * rss_upkeep_mod
  145.         pollution += 12 * city['ironmine']
  146.         iron += 3 * city['ironmine'] * (1 + ((0.5 * (city['ironmine'] - 1)) / (10 - 1)))
  147.  
  148.         rss_upkeep += 1600 * city['bauxitemine'] * rss_upkeep_mod
  149.         pollution += 12 * city['bauxitemine']
  150.         bauxite += 3 * city['bauxitemine'] * (1 + ((0.5 * (city['bauxitemine'] - 1)) / (10 - 1)))
  151.  
  152.         rss_upkeep += 300 * city['farm'] * rss_upkeep_mod ## seasonal modifiers and radiation
  153.         pollution += 2 * city['farm'] * farm_poll_mod
  154.         food_prod = city['land']/food_land_mod * city['farm'] * (1 + ((0.5 * (city['farm'] - 1)) / (20 - 1))) * seasonal_mod[nation['continent']] * radiation[nation['continent']] * 12
  155.         if food_prod < 0:
  156.             food += 0
  157.         else:
  158.             food += food_prod
  159.        
  160.         commerce = base_com
  161.         if city['powered']:
  162.             rss_upkeep += 4000 * city['gasrefinery'] * rss_upkeep_mod
  163.             pollution += 32 * city['gasrefinery'] * manu_poll_mod
  164.             oil -= 3 * city['gasrefinery'] * (1 + ((0.5 * (city['gasrefinery'] - 1)) / (5 - 1))) * gas_mod
  165.             gasoline += 6 * city['gasrefinery'] * (1 + ((0.5 * (city['gasrefinery'] - 1)) / (5 - 1))) * gas_mod
  166.  
  167.             rss_upkeep += 4000 * city['steelmill'] * rss_upkeep_mod
  168.             pollution += 40 * city['steelmill'] * manu_poll_mod
  169.             iron -= 3 * city['steelmill'] * (1 + ((0.5 * (city['steelmill'] - 1)) / (5 - 1))) * ste_mod
  170.             coal -= 3 * city['steelmill'] * (1 + ((0.5 * (city['steelmill'] - 1)) / (5 - 1))) * ste_mod
  171.             steel += 9 * city['steelmill'] * (1 + ((0.5 * (city['steelmill'] - 1)) / (5 - 1))) * ste_mod
  172.  
  173.             rss_upkeep += 2500 * city['aluminumrefinery'] * rss_upkeep_mod
  174.             pollution += 40 * city['aluminumrefinery'] * manu_poll_mod
  175.             bauxite -= 3 * city['aluminumrefinery'] * (1 + ((0.5 * (city['aluminumrefinery'] - 1)) / (5 - 1))) * alu_mod
  176.             aluminum += 9 * city['aluminumrefinery'] * (1 + ((0.5 * (city['aluminumrefinery'] - 1)) / (5 - 1))) * alu_mod
  177.  
  178.             rss_upkeep += 3500 * city['munitionsfactory'] * rss_upkeep_mod
  179.             pollution += 32 * city['munitionsfactory'] * manu_poll_mod
  180.             lead -= 6 * city['munitionsfactory'] * (1 + ((0.5 * (city['munitionsfactory'] - 1)) / (5 - 1))) * mun_mod
  181.             munitions += 18 * city['munitionsfactory'] * (1 + ((0.5 * (city['munitionsfactory'] - 1)) / (5 - 1))) * mun_mod
  182.                
  183.             civil_upkeep += city['policestation'] * 750
  184.             civil_upkeep += city['hospital'] * 1000
  185.             civil_upkeep += city['recyclingcenter'] * 2500
  186.             civil_upkeep += city['subway'] * 3250
  187.             civil_upkeep += city['supermarket'] * 600
  188.             civil_upkeep += city['bank'] * 1800
  189.             civil_upkeep += city['mall'] * 5400
  190.             civil_upkeep += city['stadium'] * 12150
  191.  
  192.             police_stations = city['policestation']
  193.             hospitals = city['hospital']
  194.  
  195.             pollution += city['policestation']
  196.             pollution += city['hospital'] * 4
  197.             pollution -= city['recyclingcenter'] * rec_poll
  198.             pollution -= city['subway'] * subw_poll_red
  199.             pollution += city['mall'] * 2
  200.             pollution += city['stadium'] * 5
  201.  
  202.             city['real_pollution'] = pollution
  203.             if pollution < 0:
  204.                 pollution = 0
  205.             city['pollution'] = pollution
  206.  
  207.             commerce += city['subway'] * 8
  208.             commerce += city['supermarket'] * 3
  209.             commerce += city['bank'] * 5
  210.             commerce += city['mall'] * 9
  211.             commerce += city['stadium'] * 12
  212.  
  213.             city['real_commerce'] = commerce
  214.             if commerce > max_commerce:
  215.                 commerce = max_commerce
  216.             city['commerce'] = commerce
  217.  
  218.         else:
  219.             police_stations = 0
  220.             hospitals = 0
  221.  
  222.         crime_rate = ((103 - commerce)**2 + (city['infrastructure'] * 100))/(111111) - police_stations * pol_cri_red
  223.         city['real_crime_rate'] = crime_rate
  224.         if crime_rate < 0:
  225.             crime_rate = 0
  226.         city['crime_rate'] = crime_rate
  227.         crime_deaths = ((crime_rate) / 10) * (100 * city['infrastructure']) - 25
  228.         disease_rate = (((((base_pop / city['land'])**2) * 0.01) - 25)/100) + (base_pop/100000) + pollution * 0.05 - hospitals * hos_dis_red
  229.         city['real_disease_rate'] = disease_rate
  230.         if disease_rate > 100:
  231.             disease_rate = 100
  232.         elif disease_rate < 0:
  233.             disease_rate = 0
  234.         city['disease_rate'] = disease_rate
  235.         disease_deaths = base_pop * (disease_rate/100)
  236.         if disease_deaths < 0:
  237.             disease_deaths = 0
  238.         city_age = (datetime.utcnow() - datetime.strptime(city['date'], "%Y-%m-%d")).days
  239.         if city_age == 0:
  240.             city_age = 1
  241.         population = ((base_pop - disease_deaths - crime_deaths) * (1 + math.log(city_age)/15))
  242.         nationpop += population
  243.         money_income += (((commerce / 50) * 0.725) + 0.725) * population
  244.    
  245.     alliance_treasures = 0
  246.     nation_treasure_bonus = 1
  247.     for treasure in treasures:
  248.         if treasure['nation'] == None:
  249.             continue
  250.         if treasure['nation']['id'] == nation['id']:
  251.             nation_treasure_bonus += treasure['bonus'] / 100
  252.         if nation['alliance']:
  253.             if treasure['nation']['alliance_id'] == nation['alliance_id']:
  254.                 alliance_treasures += 1
  255.     if alliance_treasures > 0:
  256.         nation_treasure_bonus += math.sqrt(alliance_treasures * 4) / 100
  257.     if nation_treasure_bonus > 1:
  258.         treasure_text = f"\n\nTreasure Bonus: ${round(money_income * (nation_treasure_bonus - 1)):,}"
  259.    
  260.     if not single_city:
  261.         color_bonus = colors[nation['color']]
  262.         color_text = f"\n\nColor Trade Bloc Bonus: ${round(color_bonus):,}"
  263.     food -= nationpop / 1000
  264.  
  265.     if nation['num_cities'] < 11:
  266.         new_player_bonus = 2.1 - 0.1 * nation['num_cities']
  267.         new_player_text = f"\n\nNew Player Bonus: ${round((new_player_bonus - 1) * money_income):,}"
  268.     if nation['dompolicy'] == "Open Markets":
  269.         policy_bonus = 1.01
  270.         policy_bonus_text = f"\n\nOpen Markets Bonus: ${round(money_income * 0.01):,}"
  271.    
  272.     at_war = False
  273.     if not single_city:
  274.         for war in nation['wars']:
  275.             if war['turnsleft'] > 0:
  276.                 at_war = True
  277.         if include_spies:
  278.             military_upkeep += await spy_calc(nation) * 2400
  279.         if not at_war:
  280.             military_upkeep += nation['soldiers'] * 1.25
  281.             food -= nation['soldiers'] / 750
  282.             military_upkeep += nation['tanks'] * 50
  283.             military_upkeep += nation['aircraft'] * 500
  284.             military_upkeep += nation['ships'] * 3750
  285.             military_upkeep += nation['missiles'] * 21000
  286.             military_upkeep += nation['nukes'] * 31500
  287.         else:
  288.             military_upkeep += nation['soldiers'] * 1.88
  289.             food -= nation['soldiers'] / 500
  290.             military_upkeep += nation['tanks'] * 75
  291.             military_upkeep += nation['aircraft'] * 750
  292.             military_upkeep += nation['ships'] * 5625
  293.             military_upkeep += nation['missiles'] * 35000
  294.             military_upkeep += nation['nukes'] * 52500
  295.     else:
  296.         military_upkeep += int(city['barracks']) * 3000 * 1.25
  297.         military_upkeep += int(city['factory']) * 250 * 50
  298.         military_upkeep += int(city['airforcebase']) * 15 * 500
  299.         military_upkeep += int(city['drydock']) * 5 * 3750
  300.  
  301.     if nation['dompolicy'] == "Imperialism":
  302.         mil_cost = 0.95
  303.         policy_bonus_text = f"\n\nImperialism Bonus: ${round(military_upkeep * 0.05):,}"
  304.     if food < 0:
  305.         starve_exp_text = f"\n\nPossible Starvation Penalty: ${round(money_income * policy_bonus * new_player_bonus * 0.33):,}*"
  306.         starve_money_text = f" (${round(money_income * policy_bonus * new_player_bonus * 0.67 + color_bonus - power_upkeep - rss_upkeep - military_upkeep * mil_cost - civil_upkeep):,}*)"
  307.         starve_net_text = f" (${round(money_income * policy_bonus * new_player_bonus * 0.67 + color_bonus - power_upkeep - rss_upkeep - military_upkeep * mil_cost - civil_upkeep + coal * prices['coal'] + oil * prices['oil'] + uranium * prices['uranium'] + lead * prices['lead'] + iron * prices['iron'] + bauxite * prices['bauxite'] + gasoline * prices['gasoline'] + munitions * prices['munitions'] + steel * prices['steel'] + aluminum * prices['aluminum'] + food * prices['food']):,}*)"
  308.         footer = "* The income if the nation is suffering from a starvation penalty"
  309.    
  310.     max_infra = sorted(nation['cities'], key=lambda k: k['infrastructure'], reverse=True)[0]['infrastructure']
  311.  
  312.     if single_city:
  313.         rev_obj = nation['cities'][0]
  314.     else:
  315.         rev_obj = {}
  316.     rev_obj['monetary_net_num'] = round(money_income * policy_bonus * new_player_bonus * nation_treasure_bonus + color_bonus - power_upkeep - rss_upkeep - military_upkeep * mil_cost - civil_upkeep + coal * prices['coal'] + oil * prices['oil'] + uranium * prices['uranium'] + lead * prices['lead'] + iron * prices['iron'] + bauxite * prices['bauxite'] + gasoline * prices['gasoline'] + munitions * prices['munitions'] + steel * prices['steel'] + aluminum * prices['aluminum'] + food * prices['food'])
  317.     rev_obj['net_cash_num'] = round(money_income * policy_bonus * new_player_bonus * nation_treasure_bonus + color_bonus - power_upkeep - rss_upkeep - military_upkeep * mil_cost - civil_upkeep)
  318.     rev_obj['food'] = food
  319.     if single_city and not build:
  320.         rev_obj['money'] = rev_obj['net_cash_num']
  321.         rev_obj['net income'] = rev_obj['monetary_net_num']
  322.         rev_obj['aluminum'] = aluminum
  323.         rev_obj['bauxite'] = bauxite
  324.         rev_obj['coal'] = coal
  325.         rev_obj['gasoline'] = gasoline
  326.         rev_obj['iron'] = iron
  327.         rev_obj['lead'] = lead
  328.         rev_obj['munitions'] = munitions
  329.         rev_obj['oil'] = oil
  330.         rev_obj['steel'] = steel
  331.         rev_obj['uranium'] = uranium
  332.         rev_obj['disease_rate'] = disease_rate
  333.         rev_obj['crime_rate'] = crime_rate
  334.         rev_obj['commerce'] = commerce
  335.         rev_obj['pollution'] = pollution
  336.         return rev_obj
  337.     else:
  338.         rev_obj['nation'] = nation
  339.     rev_obj['footer'] = footer
  340.     rev_obj['max_infra'] = max_infra
  341.     rev_obj['avg_infra'] = round(total_infra / nation['num_cities'])
  342.     rev_obj['income_txt']=f"National Tax Revenue: ${round(money_income):,}{color_text}{new_player_text}{policy_bonus_text}{treasure_text}"
  343.     rev_obj['expenses_txt']=f"Power Plant Upkeep: ${round(power_upkeep):,}\n\nResource Prod. Upkeep: ${round(rss_upkeep):,}\n\nMilitary Upkeep: ${round(military_upkeep * mil_cost):,}\n\nCity Improvement Upkeep: ${round(civil_upkeep):,}{starve_exp_text}"
  344.     rev_obj['net_rev_txt']=f"Coal: {round(coal):,}\nOil: {round(oil):,}\nUranium: {round(uranium):,}\nLead: {round(lead):,}\nIron: {round(iron):,}\nBauxite: {round(bauxite):,}\nGasoline: {round(gasoline):,}\nMunitions: {round(munitions):,}\nSteel: {round(steel):,}\nAluminum: {round(aluminum):,}\nFood: {round(food):,}\nMoney: ${round(money_income * policy_bonus * new_player_bonus * nation_treasure_bonus + color_bonus - power_upkeep - rss_upkeep - military_upkeep * mil_cost - civil_upkeep):,}{starve_money_text}"
  345.     rev_obj['mon_net_txt']=f"${round(money_income * policy_bonus * new_player_bonus * nation_treasure_bonus + color_bonus - power_upkeep - rss_upkeep - military_upkeep * mil_cost - civil_upkeep + coal * prices['coal'] + oil * prices['oil'] + uranium * prices['uranium'] + lead * prices['lead'] + iron * prices['iron'] + bauxite * prices['bauxite'] + gasoline * prices['gasoline'] + munitions * prices['munitions'] + steel * prices['steel'] + aluminum * prices['aluminum'] + food * prices['food']):,}{starve_net_text}"
  346.     rev_obj['money_txt']=f"${round(money_income * policy_bonus * new_player_bonus * nation_treasure_bonus + color_bonus - power_upkeep - rss_upkeep - military_upkeep * mil_cost - civil_upkeep):,}{starve_money_text}"
  347.     return rev_obj
  348.  
  349. # RIFT VERSION
  350.  
  351.     async def actual_calculate_revenue(
  352.         self,
  353.         prices: Optional[TradePrices],
  354.         cities: List[FullCity],
  355.         fetch_spies: bool = False,
  356.     ) -> RevenueDict:
  357.         from ...funcs import calculate_spies
  358.  
  359.         spies = await calculate_spies(self) if fetch_spies else 0
  360.         prices = prices or cache.prices
  361.         revenues = [i.calculate_income() for i in cities]
  362.         revenue: RevenueDict = {  # type: ignore
  363.             "gross_income": sum(
  364.                 (i["gross_income"] for i in revenues[1:]), revenues[0]["gross_income"]
  365.             ),
  366.             "net_income": sum(
  367.                 (i["net_income"] for i in revenues[1:]), revenues[0]["net_income"]
  368.             ),
  369.             "upkeep": sum((i["upkeep"] for i in revenues[1:]), revenues[0]["upkeep"]),
  370.         }
  371.         color = await Color.fetch(self.color.lower())
  372.         bonus = color.bonus * 12
  373.         if self.cities <= 10:
  374.             revenue["new_player_bonus"] = revenue["gross_income"].money * (
  375.                 1.1 - (0.1 * self.cities)
  376.             )
  377.             revenue["gross_income"].money *= 2.1 - (0.1 * self.cities)
  378.             revenue["net_income"].money = sum(
  379.                 i.calculate_net_money_income(2.1 - (0.1 * self.cities)) for i in cities
  380.             )
  381.         revenue["gross_income"].money += bonus
  382.         revenue["net_income"].money += bonus
  383.         if self.offensive_wars or self.defensive_wars:
  384.             revenue["net_income"].money -= (
  385.                 (1.88 * (self.soldiers / 500))
  386.                 + (75 * self.tanks)
  387.                 + (750 * self.aircraft)
  388.                 + (5625 * self.ships)
  389.                 + (2400 * spies)
  390.                 + (31500 * self.missiles)
  391.                 + (52500 * self.nukes)
  392.             )
  393.             revenue["net_income"].food -= self.soldiers / 500
  394.             revenue["upkeep"].food += self.soldiers / 500
  395.             revenue["upkeep"].money += (
  396.                 (1.88 * (self.soldiers / 500))
  397.                 + (75 * self.tanks)
  398.                 + (750 * self.aircraft)
  399.                 + (5625 * self.ships)
  400.                 + (2400 * spies)
  401.                 + (31500 * self.missiles)
  402.                 + (52500 * self.nukes)
  403.             )
  404.         else:
  405.             revenue["net_income"].money -= (
  406.                 (1.25 * (self.soldiers / 750))
  407.                 + (50 * self.tanks)
  408.                 + (500 * self.aircraft)
  409.                 + (3750 * self.ships)
  410.                 + (2400 * spies)
  411.                 + (21000 * self.missiles)
  412.                 + (35000 * self.nukes)
  413.             )
  414.             revenue["net_income"].food -= self.soldiers / 750
  415.             revenue["upkeep"].money += (
  416.                 (1.25 * (self.soldiers / 750))
  417.                 + (50 * self.tanks)
  418.                 + (500 * self.aircraft)
  419.                 + (3750 * self.ships)
  420.                 + (2400 * spies)
  421.                 + (21000 * self.missiles)
  422.                 + (35000 * self.nukes)
  423.             )
  424.             revenue["upkeep"].food += self.soldiers / 750
  425.         revenue["gross_total"] = Resources(
  426.             **{
  427.                 key: value * getattr(prices, key).lowest_sell.price
  428.                 for key, value in revenue["gross_income"].to_dict().items()
  429.                 if key != "money"
  430.             }
  431.         )
  432.         revenue["net_total"] = Resources(
  433.             **{
  434.                 key: value * getattr(prices, key).lowest_sell.price
  435.                 for key, value in revenue["net_income"].to_dict().items()
  436.                 if key != "money"
  437.             }
  438.         )
  439.         revenue["upkeep_total"] = Resources(
  440.             **{
  441.                 key: value * getattr(prices, key).lowest_sell.price
  442.                 for key, value in revenue["upkeep"].to_dict().items()
  443.                 if key != "money"
  444.             }
  445.         )
  446.         revenue["trade_bonus"] = bonus
  447.         return revenue
  448.  
  449. ## CITY
  450.     @property
  451.     @cachetools.cached(cache=cachetools.TTLCache(1024, 30))  # type: ignore
  452.     def population(self) -> float:
  453.         return (
  454.             ((self.infrastructure * 100) - (self.disease * self.infrastructure))
  455.             - max((self.crime / 10) * (100 * self.infrastructure) - 25, 0)
  456.         ) * (1 + (math.log(self.age) if self.age else 0) / 15)
  457.  
  458.     @property
  459.     @cachetools.cached(cache=cachetools.TTLCache(1024, 30))  # type: ignore
  460.     def disease(self) -> float:
  461.         disease = (
  462.             (((((self.infrastructure * 100 / self.land) ** 2) * 0.01) - 25) / 100)
  463.             + (self.infrastructure * 100 / 100000)
  464.             + (self.pollution * 0.05)
  465.             - (self.hospitals * 2.5)
  466.             - (self.hospitals * self.projects.clinical_research_center)
  467.         )
  468.         if disease < 0:
  469.             return 0
  470.         if disease > 100:
  471.             return 100
  472.         return disease
  473.  
  474.     @property
  475.     @cachetools.cached(cache=cachetools.TTLCache(1024, 30))  # type: ignore
  476.     def crime(self) -> float:
  477.         crime = (
  478.             ((103 - self.commerce) ** 2 + (self.infrastructure * 100)) / (111111)
  479.             - (self.police_stations * 2.5)
  480.             - (self.police_stations * self.projects.specialized_police_training)
  481.         )
  482.         if crime < 0:
  483.             return 0
  484.         if crime > 100:
  485.             return 100
  486.         return crime
  487.  
  488.     @property
  489.     @cachetools.cached(cache=cachetools.TTLCache(1024, 30))  # type: ignore
  490.     def pollution(self) -> float:
  491.         return (
  492.             self.coal_power * 8
  493.             + self.oil_power * 6
  494.             + self.coal_mines * 12
  495.             + self.iron_mines * 12
  496.             + self.bauxite_mines * 12
  497.             + self.oil_wells * 12
  498.             + self.lead_mines * 12
  499.             + self.uranium_mines * 20
  500.             + self.farms * 2 * (1 - int(self.projects.green_tech) * 0.5)
  501.             + self.oil_refineries * 32 * (1 - int(self.projects.green_tech) * 0.25)
  502.             + self.steel_mills * 40 * (1 - int(self.projects.green_tech) * 0.25)
  503.             + self.aluminum_refineries * 40 * (1 - int(self.projects.green_tech) * 0.25)
  504.             + self.munitions_factories * 32 * (1 - int(self.projects.green_tech) * 0.25)
  505.             + self.police_stations
  506.             + self.hospitals * 4
  507.             - self.recycling_centers * 70
  508.             - self.recycling_centers * 5 * self.projects.recycling_initiative
  509.             - self.subways * 45
  510.             - self.subways * 25 * self.projects.green_tech
  511.             + self.shopping_malls * 2
  512.             + self.stadiums * 5
  513.         )
  514.  
  515.     @property
  516.     @cachetools.cached(cache=cachetools.TTLCache(1024, 30))  # type: ignore
  517.     def commerce(self) -> float:
  518.         commerce = (
  519.             self.supermarkets * 3
  520.             + self.banks * 5
  521.             + self.shopping_malls * 9
  522.             + self.stadiums * 12
  523.             + self.subways * 8
  524.             + self.projects.telecom_satellite * 2
  525.         )
  526.         if self.projects.telecom_satellite:
  527.             return commerce
  528.         if self.projects.itc:
  529.             return min(commerce, 115)
  530.         return min(commerce, 100)
  531.  
  532.     def calculate_income(self) -> Dict[str, Resources]:
  533.         """
  534.        Income is per day.
  535.        """
  536.         return {
  537.             "gross_income": Resources(
  538.                 money=self.calculate_money_income(),
  539.                 food=self.calculate_food_income(),
  540.                 coal=self.calculate_coal_income(),
  541.                 oil=self.calculate_oil_income(),
  542.                 uranium=self.calculate_uranium_income(),
  543.                 lead=self.calculate_lead_income(),
  544.                 iron=self.calculate_iron_income(),
  545.                 bauxite=self.calculate_bauxite_income(),
  546.                 gasoline=self.calculate_gasoline_income(),
  547.                 munitions=self.calculate_munitions_income(),
  548.                 steel=self.calculate_steel_income(),
  549.                 aluminum=self.calculate_aluminum_income(),
  550.             ),
  551.             "net_income": Resources(
  552.                 money=self.calculate_net_money_income(),
  553.                 food=self.calculate_net_food_income(),
  554.                 coal=self.calculate_net_coal_income(),
  555.                 oil=self.calculate_net_oil_income(),
  556.                 uranium=self.calculate_net_uranium_income(),
  557.                 lead=self.calculate_net_lead_income(),
  558.                 iron=self.calculate_net_iron_income(),
  559.                 bauxite=self.calculate_net_bauxite_income(),
  560.                 gasoline=self.calculate_net_gasoline_income(),
  561.                 munitions=self.calculate_net_munitions_income(),
  562.                 steel=self.calculate_net_steel_income(),
  563.                 aluminum=self.calculate_net_aluminum_income(),
  564.             ),
  565.             "upkeep": Resources(
  566.                 money=self.calculate_money_upkeep(),
  567.                 food=self.calculate_food_upkeep(),
  568.                 coal=self.calculate_coal_upkeep(),
  569.                 oil=self.calculate_oil_upkeep(),
  570.                 uranium=self.calculate_uranium_upkeep(),
  571.                 lead=self.calculate_lead_upkeep(),
  572.                 iron=self.calculate_iron_upkeep(),
  573.                 bauxite=self.calculate_bauxite_upkeep(),
  574.             ),
  575.         }
  576.  
  577.     def calculate_money_income(self, income_modifier: float = 1) -> float:
  578.         if not self.powered:
  579.             return 0.725 * self.population
  580.         if self.nation.domestic_policy == "Open Markets":
  581.             return (((self.commerce / 50) * 0.725) + 0.725) * self.population * 1.01
  582.         return (
  583.             (((self.commerce / 50) * 0.725) + 0.725) * self.population * income_modifier
  584.         )
  585.  
  586.     def calculate_food_income(self) -> float:
  587.         return (
  588.             (
  589.                 (self.land / (500 - (int(self.projects.massirr) * 100)))
  590.                 * self.farms
  591.                 * (1 + ((0.5 * (self.farms - 1)) / (20 - 1)))
  592.                 * 12
  593.             )
  594.             if self.farms
  595.             else 0
  596.         )
  597.  
  598.     def calculate_coal_income(self) -> float:
  599.         return (
  600.             3 * self.coal_mines * (1 + ((0.5 * (self.coal_mines - 1)) / (10 - 1)))
  601.             if self.coal_mines
  602.             else 0
  603.         )
  604.  
  605.     def calculate_oil_income(self) -> float:
  606.         return (
  607.             3 * self.oil_wells * (1 + ((0.5 * (self.oil_wells - 1)) / (10 - 1)))
  608.             if self.oil_wells
  609.             else 0
  610.         )
  611.  
  612.     def calculate_uranium_income(self) -> float:
  613.         return (
  614.             (
  615.                 3
  616.                 * self.uranium_mines
  617.                 * (1 + ((0.5 * (self.uranium_mines - 1)) / (5 - 1)))
  618.                 * (1 + int(self.projects.uap))
  619.             )
  620.             if self.uranium_mines
  621.             else 0
  622.         )
  623.  
  624.     def calculate_lead_income(self) -> float:
  625.         return (
  626.             3 * self.lead_mines * (1 + ((0.5 * (self.lead_mines - 1)) / (10 - 1)))
  627.             if self.lead_mines
  628.             else 0
  629.         )
  630.  
  631.     def calculate_iron_income(self) -> float:
  632.         return (
  633.             3 * self.iron_mines * (1 + ((0.5 * (self.iron_mines - 1)) / (10 - 1)))
  634.             if self.iron_mines
  635.             else 0
  636.         )
  637.  
  638.     def calculate_bauxite_income(self) -> float:
  639.         return (
  640.             (
  641.                 3
  642.                 * self.bauxite_mines
  643.                 * (1 + ((0.5 * (self.bauxite_mines - 1)) / (10 - 1)))
  644.             )
  645.             if self.bauxite_mines
  646.             else 0
  647.         )
  648.  
  649.     def calculate_gasoline_income(self) -> float:
  650.         if not self.oil_refineries or not self.powered:
  651.             return 0
  652.         return (
  653.             6
  654.             * self.oil_refineries
  655.             * (1 + ((0.5 * (self.oil_refineries - 1)) / (5 - 1)))
  656.             * (1 + (0.36 * int(self.projects.egr)))
  657.         )
  658.  
  659.     def calculate_munitions_income(self) -> float:
  660.         if not self.munitions_factories or not self.powered:
  661.             return 0
  662.         return (
  663.             18
  664.             * self.munitions_factories
  665.             * (1 + ((0.5 * (self.munitions_factories - 1)) / (5 - 1)))
  666.             * (1 + (0.34 * int(self.projects.armss)))
  667.         )
  668.  
  669.     def calculate_steel_income(self) -> float:
  670.         if not self.steel_mills or not self.powered:
  671.             return 0
  672.         return (
  673.             9
  674.             * self.steel_mills
  675.             * (1 + ((0.5 * (self.steel_mills - 1)) / (5 - 1)))
  676.             * (1 + (0.36 * int(self.projects.ironw)))
  677.         )
  678.  
  679.     def calculate_aluminum_income(self) -> float:
  680.         if not self.aluminum_refineries or not self.powered:
  681.             return 0
  682.         return (
  683.             9
  684.             * self.aluminum_refineries
  685.             * (1 + ((0.5 * (self.aluminum_refineries - 1)) / (5 - 1)))
  686.             * (1 + (0.36 * int(self.projects.bauxitew)))
  687.         )
  688.  
  689.     def calculate_money_upkeep(self):
  690.         return (
  691.             (self.coal_power * 1200)
  692.             + (self.oil_power * 1800)
  693.             + (self.nuclear_power * 10500)
  694.             + (self.wind_power * 500)
  695.             + (self.coal_mines * 400)
  696.             + (self.oil_wells * 600)
  697.             + (self.iron_mines * 1600)
  698.             + (self.bauxite_mines * 1600)
  699.             + (self.lead_mines * 1500)
  700.             + (self.uranium_mines * 5000)
  701.             + (self.farms * 300)
  702.         ) + (
  703.             (
  704.                 (self.oil_refineries * 4000)
  705.                 + (self.steel_mills * 4000)
  706.                 + (self.aluminum_refineries * 2500)
  707.                 + (self.munitions_factories * 3500)
  708.                 + (self.police_stations * 750)
  709.                 + (self.hospitals * 1000)
  710.                 + (self.recycling_centers * 2500)
  711.                 + (self.subways * 3250)
  712.                 + (self.supermarkets * 600)
  713.                 + (self.banks * 1800)
  714.                 + (self.shopping_malls * 5400)
  715.                 + (self.stadiums * 12150)
  716.             )
  717.             if self.powered
  718.             else 0
  719.         )
  720.  
  721.     def calculate_food_upkeep(self):
  722.         return self.population / 1000
  723.  
  724.     def calculate_coal_upkeep(self):
  725.         return (self.coal_power * 1.2) + (
  726.             (self.steel_mills * 3)
  727.             * (1 + ((0.5 * (self.steel_mills - 1)) / (5 - 1)))
  728.             * (1 + (0.36 * int(self.projects.ironw)))
  729.         )
  730.  
  731.     def calculate_oil_upkeep(self):
  732.         return (self.oil_power * 1.2) + (
  733.             (self.oil_refineries * 3)
  734.             * (1 + ((0.5 * (self.oil_refineries - 1)) / (5 - 1)))
  735.             * (1 + (0.36 * int(self.projects.egr)))
  736.         )
  737.  
  738.     def calculate_uranium_upkeep(self) -> float:
  739.         amount = self.infrastructure // 1000
  740.         if amount * 1000 < self.infrastructure:
  741.             amount += 1
  742.         amount = min(amount, self.nuclear_power * 2)
  743.         return amount * 1.2
  744.  
  745.     def calculate_lead_upkeep(self) -> float:
  746.         return (
  747.             (self.munitions_factories * 6)
  748.             * (1 + ((0.5 * (self.munitions_factories - 1)) / (5 - 1)))
  749.             * (1 + (0.34 * int(self.projects.armss)))
  750.         )
  751.  
  752.     def calculate_iron_upkeep(self) -> float:
  753.         return (
  754.             (self.steel_mills * 3)
  755.             * (1 + ((0.5 * (self.steel_mills - 1)) / (5 - 1)))
  756.             * (1 + (0.36 * int(self.projects.ironw)))
  757.         )
  758.  
  759.     def calculate_bauxite_upkeep(self) -> float:
  760.         return (
  761.             (self.aluminum_refineries * 3)
  762.             * (1 + ((0.5 * (self.aluminum_refineries - 1)) / (5 - 1)))
  763.             * (1 + (0.36 * int(self.projects.bauxitew)))
  764.         )
  765.  
  766.     def calculate_net_money_income(self, income_modifier: float = 1) -> float:
  767.         return (
  768.             self.calculate_money_income(income_modifier) - self.calculate_money_upkeep()
  769.         )
  770.  
  771.     def calculate_net_food_income(self) -> float:
  772.         return self.calculate_food_income() - self.calculate_food_upkeep()
  773.  
  774.     def calculate_net_coal_income(self) -> float:
  775.         return self.calculate_coal_income() - self.calculate_coal_upkeep()
  776.  
  777.     def calculate_net_oil_income(self) -> float:
  778.         return self.calculate_oil_income() - self.calculate_oil_upkeep()
  779.  
  780.     def calculate_net_uranium_income(self) -> float:
  781.         return self.calculate_uranium_income() - self.calculate_uranium_upkeep()
  782.  
  783.     def calculate_net_lead_income(self) -> float:
  784.         return self.calculate_lead_income() - self.calculate_lead_upkeep()
  785.  
  786.     def calculate_net_iron_income(self) -> float:
  787.         return self.calculate_iron_income() - self.calculate_iron_upkeep()
  788.  
  789.     def calculate_net_bauxite_income(self) -> float:
  790.         return self.calculate_bauxite_income() - self.calculate_bauxite_upkeep()
  791.  
  792.     calculate_net_gasoline_income = calculate_gasoline_income
  793.     calculate_net_munitions_income = calculate_munitions_income
  794.     calculate_net_steel_income = calculate_steel_income
  795.     calculate_net_aluminum_income = calculate_aluminum_income
Add Comment
Please, Sign In to add comment