Lycanphoenix

MechEngine Beta (0.30.92)

May 29th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 35.31 KB | None | 0 0
  1. print("MechEngine Beta, 0.30.92");
  2. print("Build Date: 2018-05-29. Designed using Python 3.6.4 Stackless Shell");
  3. import math, os, sys, time, datetime, threading, builtins
  4. def gettime():
  5.     now = datetime.datetime.now()
  6.     return print("Current Time and Date, Local:", now.strftime("%A, %Y-%m-%d, %H:%M:%S %z"))
  7. gettime()
  8. print();
  9.  
  10. #Development Goals:
  11.      #Add options to restart program and/or export log upon completion.
  12.      #Add engine descriptions to help the user make an informed decision.
  13.     #Add example mechs to choose from
  14.  
  15. def fib(n):    # write Fibonacci series up to n
  16.      """Print a Fibonacci series up to n."""
  17.      a, b = 0, 1
  18.      while a <= n:
  19.          print(a, end=" ");
  20.          a, b = b, a + b
  21.      print();
  22.  
  23. def mem_fib(n, _cache={}):
  24.     '''efficiently memoized recursive function, returns a Fibonacci number with n iterations.'''
  25.     if n in _cache:
  26.         return _cache[n]
  27.     elif n > 1:
  28.         return _cache.setdefault(n, mem_fib(n-1) + mem_fib(n-2))
  29.     return n
  30.  
  31. def printfib(n):
  32.     for i in range(n):
  33.         print(i, mem_fib(i))
  34.  
  35. def RoundUp5(x):
  36.   return math.ceil(x / 5.0) * 5 #Round up to nearest multiple of 5
  37.  
  38. def RoundUpHalf(x):
  39.   return math.ceil(x*2.0)/2.0
  40.  
  41. def RoundUpQuarter(x):
  42.   return math.ceil(x*4.0)/4.0
  43.  
  44. def RoundUpFractional(x):
  45.   return math.ceil(x*1000.0)/1000.0
  46.  
  47. def RoundDown5(x):
  48.   return math.floor(x / 5.0) * 5
  49.  
  50. def RoundDownHalf(x):
  51.   return math.floor(x*2.0)/2.0
  52.  
  53. def RoundDownQuarter(x):
  54.   return math.floor(x*4.0)/4.0
  55.  
  56. def RoundDownFractional(x):
  57.   return math.floor(x*1000.0)/1000.0
  58.  
  59. def roundNearest(f):
  60.     return round(f + .00000000000001);
  61.  
  62. #Deprecated
  63. def roundHalfUp(f): #deprecated!
  64.     return RoundUpHalf(f) #round(f + 0.00000000000001)
  65.  
  66. def roundEngine(x, base=5): #deprecated!
  67.     return int(base * RoundUpHalf(float(x)/base));
  68.  
  69. def roundTonnage(x, base=5): #deprecated!
  70.     return int(base * RoundUpHalf(float(x)/base));
  71. #End Deprecation
  72.  
  73. #HYN-DRN-5813 Core Input Dictionary:
  74. def clamp(min_value, max_value, x):
  75.   """Returns x, limited to the range min_val to max_val."""
  76.   return max(min(x, max_value), min_value)
  77.  
  78. def RepresentsInt(s):
  79.     try:
  80.         int(s)
  81.         return True
  82.     except ValueError:
  83.         return False
  84.  
  85. def ask(question, min_val, max_val):
  86.   x = ''
  87.   while not RepresentsInt(x) or int(x) < min_val or int(x) > max_val:
  88.     if x != '':
  89.           print ("This is not a number. Please enter a valid input.")
  90.     x = input(question + " (min %d, max %d)"%(min_val, max_val) + ": ")
  91.   return clamp(min_val, max_val, int(x))
  92.  
  93. MechType = ("Biped")
  94. #def PromptMechType()
  95. #NewMechType = PromptMechType()
  96. #MechType = NewMechType
  97. CurrentMechType = MechType
  98.  
  99. Inputs = {"BattleMech’s Tonnage": {"min":2, "max":200, "value": None},
  100.           "desired Walk MP" : {"min":1, "max":30 , "value": None},
  101. #          "desired number of additional Heat Sinks": {"min:":0, "max":100, "value": None},
  102.           }
  103.  
  104. def load_inputs(inputs_dict):
  105.   """Iterate over the given inputs dictionary, asking the user for each
  106.   and setting their values"""
  107.   for name in inputs_dict:
  108.     #name takes each key in the dictionary, which in this case is names of inputs
  109.     inputs_dict[name]["value"] = ask("Please provide your %s"%name,
  110.                                      inputs_dict[name]["min"],
  111.                                      inputs_dict[name]["max"])
  112.  
  113. #"Load inputs"
  114. print ("Hint: One ground hex = 30 meters, one turn = 10 seconds.")
  115. load_inputs(Inputs)
  116.  
  117. SuspFact = 0 #SuspFact = (input("Suspension Factor: "))
  118.  
  119. MechTonnage = (Inputs["BattleMech’s Tonnage"]["value"])
  120.  
  121. if MechTonnage < 10:
  122.     MechClass = ("ProtoMech")
  123.     MechName = ("ProtoMech")
  124. elif 9 < MechTonnage:
  125.     if MechTonnage < 20: MechClass = ("Ultralight")
  126.     elif 19 < MechTonnage < 36: MechClass = ("Light")
  127.     elif 35 < MechTonnage < 56: MechClass = ("Medium")
  128.     elif 55 < MechTonnage < 76: MechClass = ("Heavy")
  129.     elif 75 < MechTonnage < 101: MechClass = ("Assault")
  130.     elif 100 < MechTonnage: MechClass = ("SuperHeavy")
  131.     MechName = (MechClass + " BattleMech")
  132. else:
  133.     MechName = ("Unit")
  134.  
  135. NewMechName = input("Name your BattleMech: ");
  136. if NewMechName != '': MechName = NewMechName
  137. print()
  138.  
  139. CruisingSpeed = math.ceil(Inputs["desired Walk MP"]["value"]);
  140. def kph(s):
  141.     return (math.ceil(s*108))/10
  142. def metersec(s):
  143.     return (math.ceil(s*30))/10
  144. def mph(s):
  145.     return (math.ceil(s*671))/100
  146. #UserHeatSinks = (#(Inputs["desired number of additional Heat Sinks"]["value"]);
  147.  
  148. print ("Press ENTER to confirm Unit Statistics:")
  149. print ("Unit Name:", MechName)
  150. print ("Unit Type:", MechType)
  151. print ("Tonnage:", MechTonnage, "Metric Tons.")
  152. print ("Weightclass:", MechClass)
  153. print ("Cruising Speed:", CruisingSpeed, "Hexes per Turn.")
  154. input()
  155.  
  156. fib(MechTonnage)
  157. print();
  158.  
  159. #"Do calculations"
  160. FlankingSpeed = math.ceil(CruisingSpeed * 1.5)
  161. if MechTonnage > 15:
  162.     rating = max(10, RoundUp5((Inputs["BattleMech’s Tonnage"]["value"] * Inputs["desired Walk MP"]["value"]) - SuspFact));
  163. else:
  164.     rating = max(2, (Inputs["BattleMech’s Tonnage"]["value"] * Inputs["desired Walk MP"]["value"]) - SuspFact);
  165.  
  166. if rating >500:
  167.     print ("WARNING! This engine rating of", rating, "is outside normal parameters, and the weight has been extrapolated through a polynomial function.",
  168.             "Consent among all participating players must be reached before it can be used in an actual game.");
  169.  
  170. TableTuple = False
  171.  
  172. if TableTuple is True:
  173.     #"Master Engine Table:" (Tuple)
  174.     FusionEngineTable = {#See TechManual and Tactical Operations for more details
  175.       (5,10,15,20,25): 0.5, (30,35,40,45): 1.0, (50,55,60): 1.5, (65,70,75): 2.0, (80,85): 2.5, (90,95,100): 3.0,#Standard Gyro: 1 Ton.
  176.       (105,110): 3.5, (115,120,125): 4.0, (130,135): 4.5, (140,145): 5.0, (150,155): 5.5, (160,165,170): 6.0, (175,180): 7.0, (185,190): 7.5, (195,): 8.0, (200,205): 8.5,#Standard Gyro: 2 Tons.
  177.       (210,): 9.0, (215,): 9.5, (220,225): 10.0, (230,): 10.5, (235,): 11.0, (240,): 11.5, (245,): 12.0, (250,): 12.5, (255,): 13.0, (260,): 13.5, (265,): 14.0, (270,): 14.5, (275,): 15.5, (280,): 16.0, (285,): 16.5, (290,): 17.5, (295,): 18.0, (300,): 19.0,#Standard Gyro: 3 Tons.
  178.       (305,): 19.5, (310,): 20.5, (315,): 21.5, (320,): 22.5, (325,): 23.5, (330,): 24.5, (335,): 25.5, (340,): 27.0, (345,): 28.5, (350,): 29.5, (355,): 31.5, (360,): 33.0, (365,): 34.5, (370,): 36.5, (375,): 38.5, (380,): 41.0, (385,): 43.5, (390,): 46.0, (395,): 49.0, (400,): 52.5,#Standard Gyro: 4 Tons.
  179.       (405,): 56.5, (410,): 61.0, (415,): 66.5, (420,): 72.5, (425,): 79.5, (430,): 87.5, (435,): 97.0, (440,): 107.5, (445,): 119.5, (450,): 133.5, (455,): 150.0, (460,): 168.5, (465,): 190.0, (470,): 214.5, (475,): 243.0, (480,): 275.5, (485,): 313.0, (490,): 356.0, (495,): 405.5, (500,): 462.5#Standard Gyro: 5 Tons. XL Gyro: N/A.
  180.       }
  181.  
  182. else:
  183.     #"Master Engine Table:" (Backup)
  184.     FusionEngineTable = {#See TechManual and Tactical Operations for more details
  185.       5: 0.5, 10: 0.5, 15: 0.5, 20: 0.5, 25: 0.5, 30: 1.0, 35: 1.0, 40: 1.0, 45: 1.0, 50: 1.5, 55: 1.5, 60: 1.5, 65: 2.0, 70: 2.0, 75: 2.0, 80: 2.5, 85: 2.5, 90: 3.0, 95: 3.0, 100: 3.0,#Standard Gyro: 1 Ton. Compact Gyro: 1.5 Tons. XL Gyro: 0.5 Tons. Heavy-Duty Gyro: 2 Tons.
  186.       105: 3.5, 110: 3.5, 115: 4.0, 120: 4.0, 125: 4.0, 130: 4.5, 135: 4.5, 140: 5.0, 145: 5.0, 150: 5.5, 155: 5.5, 160: 6.0, 165: 6.0, 170: 6.0, 175: 7.0, 180: 7.0, 185: 7.5, 190: 7.5, 195: 8.0, 200: 8.5,#Standard Gyro: 2 Tons. Compact Gyro: 3 Tons. XL Gyro: 1 Ton. Heavy-Duty/SuperHeavy Gyro: 4 Tons.
  187.       205: 8.5, 210: 9.0, 215: 9.5, 220: 10.0, 225: 10.0, 230: 10.5, 235: 11.0, 240: 11.5, 245: 12.0, 250: 12.5, 255: 13.0, 260: 13.5, 265: 14.0, 270: 14.5, 275: 15.5, 280: 16.0, 285: 16.5, 290: 17.5, 295: 18.0, 300: 19.0,#Standard Gyro: 3 Tons. Compact Gyro: 4.5 Tons. XL Gyro: 1.5 Tons. Heavy-Duty/SuperHeavy Gyro: 6 Tons.
  188.       305: 19.5, 310: 20.5, 315: 21.5, 320: 22.5, 325: 23.5, 330: 24.5, 335: 25.5, 340: 27.0, 345: 28.5, 350: 29.5, 355: 31.5, 360: 33.0, 365: 34.5, 370: 36.5, 375: 38.5, 380: 41.0, 385: 43.5, 390: 46.0, 395: 49.0, 400: 52.5,#Standard Gyro: 4 Tons. Compact Gyro: 6 Tons. XL Gyro: 2 Tons. Heavy-Duty/SuperHeavy Gyro: 8 Tons.
  189.       405: 56.5, 410: 61.0, 415: 66.5, 420: 72.5, 425: 79.5, 430: 87.5, 435: 97.0, 440: 107.5, 445: 119.5, 450: 133.5, 455: 150.0, 460: 168.5, 465: 190.0, 470: 214.5, 475: 243.0, 480: 275.5, 485: 313.0, 490: 356.0, 495: 405.5, 500: 462.5#Standard Gyro: 5 Tons. Compact Gyro: 7.5 Tons. XL Gyro: N/A. Heavy-Duty/SuperHeavy Gyro: 10 Tons.
  190.       }
  191.  
  192.     #ProtoMechEngineTable = {#ProtoMechs, for engine ratings below 40, multiply the engine rating by 0.025 to find the mass. Afterwards, they use Standard Fusion Engine weights.
  193.     #    1: .025, 2: .050, 3: .075, 4: .100, 5: .125, 6: .150, 7: .175, 8: .200, 9: .225, 10: .250,
  194.     #    11: .275, 12: .300, 13: .325, 14: .350, 15: .375, 16: .400, 17: .425, 18: .450, 19: .475, 20: .500,
  195.     #    21: .525, 22: .550, 23: .575, 24: .600, 25: .625, 26: .650, 27: .675, 28: .700, 29: .725, 30: .750,
  196.     #    31: .775, 32: .800, 33: .825, 34: .850, 35: .875, 36: .900, 37: .925, 38: .950, 39: .975, 40: 1.0,}
  197.  
  198. def PromptEngineType():
  199.     """Ask the user for their desired engine type, then return it."""
  200.     #engine list:
  201.     if MechTonnage < 16 and rating < 401:
  202.         el = [#Basic Engine Types:
  203.               "Standard Fusion Engine", "Light Fusion Engine", "XL Fusion Engine",
  204.               #Advanced Engine Types:
  205.               "XXL Fusion Engine", "Compact Fusion Engine",
  206.               #Non-Fusion Engines:
  207.               "Internal Combustion Engine (ICE)", "Fuel Cell", "Fission Engine",
  208.               #Primitive Engines:
  209.               "Primitive Fusion Engine", "Primitive Internal Combustion Engine (ICE)", "Primitive Fuel Cell", "Primitive Fission Engine",
  210.               #Special Engine Types:
  211.               "Lithium-Fusion Engine", "ProtoMech Engine",
  212.               ]
  213.     elif MechTonnage < 16 and rating > 400:
  214.         el = ["Standard Fusion Engine", "Light Fusion Engine", "XL Fusion Engine", "XXL Fusion Engine", "Internal Combustion Engine (ICE)", "Fuel Cell", "Fission Engine", "Primitive Fusion Engine", "Primitive Internal Combustion Engine (ICE)", "Primitive Fuel Cell", "Primitive Fission Engine", "Lithium-Fusion Engine", "ProtoMech Engine"]
  215.     elif 15 < MechTonnage < 101 and rating < 401:
  216.         el = ["Standard Fusion Engine", "Light Fusion Engine", "XL Fusion Engine","XXL Fusion Engine", "Compact Fusion Engine","Internal Combustion Engine (ICE)", "Fuel Cell", "Fission Engine","Primitive Fusion Engine", "Primitive Internal Combustion Engine (ICE)", "Primitive Fuel Cell", "Primitive Fission Engine", "Lithium-Fusion Engine"]
  217.     elif 15 < MechTonnage < 101 and rating > 400:
  218.         el = ["Standard Fusion Engine", "Light Fusion Engine", "XL Fusion Engine", "XXL Fusion Engine", "Internal Combustion Engine (ICE)", "Fuel Cell", "Fission Engine", "Primitive Fusion Engine", "Primitive Internal Combustion Engine (ICE)", "Primitive Fuel Cell", "Primitive Fission Engine", "Lithium-Fusion Engine"]
  219.     elif MechTonnage > 100 and rating < 401:
  220.         el = ["Standard Fusion Engine", "Light Fusion Engine", "XL Fusion Engine", "XXL Fusion Engine", "Compact Fusion Engine", "Fission Engine", "Lithium-Fusion Engine"]
  221.     elif MechTonnage > 100 and rating > 400:
  222.         el = ["Standard Fusion Engine", "Light Fusion Engine", "XL Fusion Engine", "XXL Fusion Engine", "Fission Engine", "Lithium-Fusion Engine"]
  223.  
  224.     if rating < 401:
  225.         print("Engine types:");
  226.         for i in range(0, len(el)):
  227.             print("  (%d) %s"%(i, el[i]));
  228.         num = ask("Please select your desired Engine type", 0, len(el)-1);
  229.         print();
  230.         return el[num]
  231.     else:
  232.         print("Large Engine types:");
  233.         for i in range(0, len(el)):
  234.             print("  (%d) %s"%(i, el[i]));
  235.         num = ask("Please select your desired Large Engine type", 0, len(el)-1);
  236.         print();
  237.         return el[num]
  238.  
  239. if MechTonnage < 10:
  240.     EngineType = ("ProtoMech Engine")
  241. else:
  242.     EngineType = PromptEngineType()
  243.  
  244. if EngineType in {"ProtoMech Engine"}:
  245.     rating = (MechTonnage * FlankingSpeed) - SuspFact
  246.     if rating < 41:
  247.         rating = RoundUp5(rating)
  248.     if MechClass in {"Ultralight"}:
  249.         MechClass = ("UltraHeavy ProtoMech")
  250. else:
  251.     rating = RoundUp5((MechTonnage * CruisingSpeed) - SuspFact)
  252.  
  253. if EngineType in {"Lithium-Fusion Engine"}:
  254.     if CruisingSpeed < 2:
  255.         CruisingSpeed = 2
  256.         FlankingSpeed = math.ceil(CruisingSpeed * 1.5)
  257.     elif CruisingSpeed > 1:
  258.         CruisingSpeed = (Inputs["desired Walk MP"]["value"])
  259.         FlankingSpeed = math.ceil(CruisingSpeed * 1.5)
  260.  
  261. def FusionWeight(rating):
  262.     if EngineType in ["ProtoMech Engine"]:
  263.         if rating < 41:
  264.             weight = rating * (25.0/1000.0)
  265.             #print (weight)
  266.             return rating * (25.0/1000.0) #ProtoMechEngineTable[rating]
  267.         else:
  268.             return FusionEngineTable[RoundUp5(rating)]
  269. #            for key in FusionEngineTable:
  270. #                    if rating in key:
  271. #                        weight = FusionEngineTable[key]
  272. #                        #print (weight)
  273. #                        return FusionEngineTable[key]
  274.     elif rating < 501:
  275.         return FusionEngineTable[RoundUp5(rating)]
  276. #        for key in FusionEngineTable:
  277. #                if rating in key:
  278. #                    weight = FusionEngineTable[key]
  279. #                    #print (weight)
  280. #                    return FusionEngineTable[key]
  281.     elif rating > 500: #Uses polynomial curves and floating-point math to extrapolate mass for engine ratings beyond 500. Experimental feature, not recommended for everyday use.
  282.         x = RoundUp5(rating)
  283.         coeff = [7.05283012941420e-23, -1.58264921514316e-19,  1.58814453473840e-16,
  284.                  -9.19203426420176e-14,  3.32942410135420e-11, -7.72438823285226e-09,
  285.                  1.13925338769604e-06, -0.000102985669746005,  0.00538423547801741,
  286.                  -0.112116210954985, 1.24919663674987]
  287.         icoeff = zip(range(0, len(coeff)), reversed(coeff))
  288.         weight = 0.0
  289.         for p,c in icoeff:
  290.             weight += c * (x**p)
  291.         weight = RoundUpFractional(weight*1000.0)/1000.0
  292.         #print (weight)
  293.         return weight
  294.         print ("WARNING! This Engine Rating is outside normal Rating parameters, and its weight has been extrapolated. Player discretion is advised.");
  295.         print();
  296.  
  297. #def FusionWeightPoly(rating): #Uses polynomial curves and floating-point math to extrapolate mass for engine ratings beyond 500. Experimental feature, not recommended for everyday use.
  298. #  x = RoundUp5(rating)
  299. #  coeff = [7.05283012941420e-23, -1.58264921514316e-19,  1.58814453473840e-16,
  300. #          -9.19203426420176e-14,  3.32942410135420e-11, -7.72438823285226e-09,
  301. #           1.13925338769604e-06, -0.000102985669746005,  0.00538423547801741,
  302. #          -0.112116210954985, 1.24919663674987]
  303. #  icoeff = zip(range(0, len(coeff)), reversed(coeff))
  304. #  weight = 0.0
  305. #  for p,c in icoeff:
  306. #    weight += c * (x**p)
  307. #  weight = roundNearest(weight * 2.0)/2.0
  308. #  return weight
  309. #
  310. #for k in FusionEngineTable:
  311. #  t = FusionWeight(k)
  312. #  p = FusionWeightPoly(k)
  313. #  d = t - p
  314. #  if d > .01:
  315. #    print(k, t, p, d)
  316.  
  317. def EngineWeight(engine_type, rating):
  318.    #Using a dictionary to match engine name to a formula
  319.    weight = FusionWeight(rating * 1.0)
  320.    #print (weight)
  321.    primitive = FusionWeight(rating * 1.2)
  322.    lithium = FusionWeight(max(MechTonnage, rating - MechTonnage))
  323.    if rating < 41:
  324.       proto = rating * (25.0/1000.0) #ProtoMechEngineTable[rating]
  325.       lithium_proto = max(MechTonnage, rating - MechTonnage) * (25.0/1000.0)
  326.    else:
  327.       proto = weight * 1.0
  328.       lithium_proto = lithium * 1.0
  329.  
  330.    #print (weight)
  331.    ed = {"Standard Fusion Engine" : max(0.5, weight * 1.0),
  332.          "Light Fusion Engine"    : max(0.5, RoundUpHalf(weight * .75)),
  333.          "XL Fusion Engine"       : max(0.5, RoundUpHalf(weight * .50)),
  334.          "XXL Fusion Engine"      : max(0.5, RoundUpHalf(weight / 3.0)),
  335.          "Compact Fusion Engine"  : max(1.0, RoundUpHalf(weight * 1.5)),
  336.          "Internal Combustion Engine (ICE)"  : max(1.0, RoundUpHalf(weight * 2.0)), #No Heat Sinks at all. Can't use energy weapons or Jump Jets. Don't forget fuel!
  337.          "Fuel Cell"  : max(1.0, RoundUpHalf((weight * 2.0) * 0.5)), #Only 1 Heat Sink. Can't use energy weapons or Jump Jets. Don't forget fuel!
  338.          "Fission Engine"  : max(5.0, RoundUpHalf(weight * float(7.0/4.0))), #Only 5 Heat Sinks. Illegal in the Inner Sphere, and expensive.
  339.          "Lithium-Fusion Engine"  : max(0.5, RoundUpHalf(lithium)), #Non-Canon. 10 Heat Sinks. Increases a mech's Walking Speed by 1.
  340.          "Primitive Fusion Engine"  : max(0.5, RoundUpHalf(primitive)), #Multiplies engine rating by 1.2, but does not increase performance.
  341.          "Primitive Internal Combustion Engine (ICE)"  : max(1.0, RoundUpHalf(primitive * 2.0)), #Multiplies engine rating by 1.2, but does not increase performance.
  342.          "Primitive Fuel Cell"  : max(1.0, RoundUpHalf(primitive * 1.2)), #Multiplies engine rating by 1.2, but does not increase performance.
  343.          "Primitive Fission Engine"  : max(5.0, RoundUpHalf(primitive * (7.0/4.0))), #Multiplies engine rating by 1.2, but does not increase performance.
  344.          "ProtoMech Engine" : RoundUpFractional((proto * 1000.0)/1000.0),
  345.          "ProtoMech XL Lithium-Fusion Engine" : RoundUpFractional(max(0.013, lithium_proto/2)),
  346.          "No Engine" : 0,
  347.          }
  348.    return ed[engine_type]
  349.  
  350. if EngineType in {"Lithium-Fusion Engine"}:
  351.     LithiumBatteryRating = max(MechTonnage, rating - MechTonnage)
  352. elif EngineType in {"Primitive Fusion Engine", "Primitive Internal Combustion Engine (ICE)", "Primitive Fuel Cell," "Primitive Fission Engine"}:
  353.     LithiumBatteryRating = RoundUp5(rating * 1.2)
  354. else:
  355.     LithiumBatteryRating = rating
  356.  
  357. #Cockpits
  358. def PromptCockpitType():
  359.     """Ask the user for their desired cockpit type, then return it."""
  360.     #cockpit list:
  361.     if LithiumBatteryRating < 401:
  362.             cl = ["Standard", "Small", "Armored", "Torso", "Interface", "Drone Operating System"]
  363.     elif LithiumBatteryRating > 400:
  364.           cl = ["Standard", "Small", "Armored", "Interface", "Drone Operating System"]
  365.     print("Cockpit types:");
  366.     for i in range(0, len(cl)):
  367.         print("  (%d) %s"%(i, cl[i]));
  368.     num = ask("Please select your desired Cockpit type", 0, len(cl)-1);
  369.     print();
  370.     return cl[num]
  371.  
  372. def CockpitWeight(cockpit_type):
  373.    #Using a dictionary to match cockpit name to a formula
  374.    cd = {
  375.         "ProtoMech": 0.5,
  376.         "UltraHeavy ProtoMech": 0.75,
  377.         "Drone Operating System": max(1.0, RoundUpHalf((MechTonnage/10.0) + 0.5)),
  378.         "Small": 2.0,
  379.         ("Standard", "AutoMech", "Industrial", "Armored Small"): 3.0,
  380.         ("Armored", "Torso", "Tripod", "Interface", "SuperHeavy"): 4.0,
  381.         ("Primitive", "Primitive Industrial", "SuperHeavy Tripod"): 5.0
  382.         }
  383. #   return ed[cockpit_type]
  384.    for key in cd:
  385.         if cockpit_type in key:
  386.              return cd[key]
  387.  
  388. #Skeletons
  389. def PromptInternalType():
  390.    """Ask the user for their desired internal structure type, then return it."""
  391.    #internal structure list:
  392.    if MechTonnage < 101:
  393.         if EngineType in {"Primitive Fusion Engine", "Primitive Internal Combustion Engine (ICE)", "Primitive Fuel Cell", "Primitive Fission Engine"}:
  394.             il = ["Primitive Standard", "Primitive Industrial"]
  395.         else:
  396.             il = ["Standard", "Endo Steel", "Composite", "Hybrid", "Reinforced", "Industrial"]
  397.    elif MechTonnage > 100:
  398.         il = ["SuperHeavy Standard", "SuperHeavy Hybrid", "SuperHeavy Endo Steel", "SuperHeavy Reinforced", "SuperHeavy Industrial"] #You have balls if you pick that last one.
  399.    print("Internal Structure types:");
  400.    for i in range(0, len(il)):
  401.        print("  (%d) %s"%(i, il[i]))
  402.    num = ask("Please select your desired Internal Structure type", 0, len(il)-1);
  403.    print();
  404.    return il[num]
  405.  
  406. def InternalWeight(internal_type):
  407.     #Using a dictionary to match internal structure name to a formula
  408.     isd = {
  409.          ("Standard", "Primitive Standard", "SuperHeavy Endo Steel", "ProtoMech"): RoundUpHalf(MechTonnage/10.0),
  410.          ("Endo Steel", "Composite"): RoundUpHalf(MechTonnage/20.0),
  411.          "Hybrid": RoundUpHalf(MechTonnage*7.5/100.0),
  412.          ("Reinforced", "Industrial", "Primitive Industrial", "SuperHeavy Standard") : RoundUpHalf(MechTonnage/5.0),
  413.          "SuperHeavy Hybrid": RoundUpHalf(MechTonnage*15.0/100.0),
  414.          ("SuperHeavy Industrial", "SuperHeavy Reinforced"): RoundUpHalf(MechTonnage/2.5),
  415.          }
  416. #   return ed[internal_type] #Trying to select keys from individual items out of a tuple, but the program is instead reading the entire tuple as a key.
  417.     for key in isd:
  418.        if internal_type in key:
  419.            return isd[key]
  420.  
  421. if MechTonnage > 100:
  422.      InternalType = PromptInternalType()
  423.      CockpitType = ("SuperHeavy")
  424.      if MechType in ["Tripod"]:
  425.           MechType = ("SuperHeavy Tripod")
  426.      else:
  427.           Mechtype = ("SuperHeavy" + CurrentMechType)
  428. elif EngineType in ["ProtoMech Engine"]:
  429.      InternalType = ("ProtoMech")
  430.      MechType = ("ProtoMech")
  431.      if MechTonnage < 10:
  432.           CockpitType = ("ProtoMech")
  433.      elif MechTonnage > 9:
  434.           CockpitType = ("UltraHeavy ProtoMech")
  435. else:
  436.      MechType = CurrentMechType
  437.      InternalType = PromptInternalType()
  438.      if EngineType in {"Primitive Fusion Engine", "Primitive Internal Combustion Engine (ICE)", "Primitive Fuel Cell", "Primitive Fission Engine"}:
  439.          CockpitType = ("Primitive")
  440.      else:
  441.          CockpitType = PromptCockpitType()
  442.  
  443. #Gyros
  444. def PromptGyroType():
  445.     """Ask the user for their desired gyro type, then return it."""
  446.     #gyro list:
  447.     if LithiumBatteryRating < 401 or EngineType in ["Compact Fusion Engine"]:
  448.           gl = ["Standard", "XL (Extra-Light)", "Compact", "Heavy-Duty",]
  449.     elif EngineType in {"Lithium-Fusion Engine"} and rating < 501:
  450.           gl = ["Standard", "XL (Extra-Light)", "Compact", "Heavy-Duty",]
  451.     elif LithiumBatteryRating > 400 or CockpitType in ["Torso"]:
  452.           if EngineType not in ["Compact Fusion Engine"]:
  453.               gl = ["Standard", "Compact", "Heavy-Duty",]
  454.     print("Gyro types:")
  455.     for i in range(0, len(gl)):
  456.         print("  (%d) %s"%(i, gl[i]))
  457.     num = ask("Please select your desired Gyro type", 0, len(gl)-1)
  458.     print();
  459.     return gl[num]
  460.  
  461. if EngineType in ["Lithium-Fusion Engine"]:
  462.     FinalRating = LithiumBatteryRating
  463. elif EngineType in ["Primitive Fusion Engine", "Primitive Internal Combustion Engine (ICE)", "Primitive Fuel Cell", "Primitive Fission Engine"]:
  464.     FinalRating = MechTonnage * CruisingSpeed * 1.2
  465. elif EngineType in ["ProtoMech Engine"]:
  466.     FinalRating = MechTonnage * FlankingSpeed
  467. else:
  468.     FinalRating = MechTonnage * CruisingSpeed
  469.  
  470. GyroRating = math.ceil(FinalRating / 100)
  471.  
  472. if MechTonnage > 100:
  473.     GyroType = ("SuperHeavy")
  474. elif EngineType in ["Primitive Fusion Engine", "Primitive Internal Combustion Engine (ICE)", "Primitive Fuel Cell", "Primitive Fission Engine"]:
  475.     if MechTonnage < 101:
  476.          GyroType = ("Primitive")
  477.     elif MechTonnage > 100:
  478.          GyroType = ("SuperHeavy Primitive")
  479. elif CockpitType in ["ProtoMech", "UltraHeavy ProtoMech", "Interface"]:
  480.     GyroType = ("None")
  481. else:
  482.     GyroType = PromptGyroType()
  483.  
  484. def GyroWeight(gyro_type):
  485.    #Using a dictionary to match gyro name to a formula
  486.    gmass = GyroRating
  487.    gd = {
  488.         ("Standard", "Primitive") : max(1.0, gmass*1.0),
  489.         "XL (Extra-Light)" : max(1.0, RoundUpHalf(gmass/2.0)),
  490.         "Compact" : max(1.5, RoundUpHalf(gmass*1.5)),
  491.         ("Heavy-Duty", "SuperHeavy", "Primitive SuperHeavy") : max(2.0, math.ceil(gmass * 2.0)),
  492.         "None": (gmass*0.0),
  493.         "Armored" : (gmass + 2.0),
  494.         "Armored Compact" :  1.0 + RoundUpHalf(gmass*1.5),
  495.         "Armored XL" : 3.0 + RoundUpHalf(gmass/2.0),
  496.         "Armored Heavy-Duty" : 2.0 + (gmass*2.0),
  497.         }
  498. #   return ed[gyro_type]
  499.    for key in gd:
  500.         if gyro_type in key:
  501.              return gd[key]
  502.  
  503. #Heat Sinks
  504. def PromptHeatSinkType():
  505.     """Ask the user for their desired heat sink type, then return it."""
  506.     #heat sink list:
  507.     hsl = ["Single", "Double (Inner Sphere)", "Double (Clan)", "Laser", "Compact"]
  508.     print("Heat Sink types:");
  509.     for i in range(0, len(hsl)):
  510.         print("  (%d) %s"%(i, hsl[i]));
  511.     num = ask("Please select your desired Heat Sink type", 0, len(hsl)-1);
  512.     print();
  513.     return hsl[num]
  514.  
  515. if EngineType in {"Fission Engine", "Primitive Fission Engine"}:
  516.     FreeHeatSinks = 5
  517.     HeatSinkType = PromptHeatSinkType()
  518. elif EngineType in {"Fuel Cell", "Primitive Fuel Cell"}:
  519.     FreeHeatSinks = 1
  520.     HeatSinkType = PromptHeatSinkType()
  521. elif EngineType in {"Internal Combustion Engine (ICE)", "Primitive Internal Combustion Engine (ICE)"}:
  522.     FreeHeatSinks = 0
  523.     HeatSinkType = PromptHeatSinkType()
  524. elif EngineType in {"ProtoMech Engine"}:
  525.     FreeHeatSinks = 0
  526.     HeatSinkType = ("ProtoMech")
  527. else:
  528.     FreeHeatSinks = 10
  529.     HeatSinkType = PromptHeatSinkType()
  530.  
  531. if EngineType in ["ProtoMech Engine"]:
  532.      UserHeatSinks = ask("Please provide your desired quantity of ProtoMech Heat Sinks", 0, MechTonnage*4)
  533.      
  534. elif HeatSinkType in ["Compact"]:
  535.      print ("You currently have", int(FreeHeatSinks), HeatSinkType, "Heat Sinks.")
  536.      UserHeatSinks = ask("If you wish to install additional Heat Sinks, enter the quantity you wish to add", 0, math.floor(MechTonnage*2/3))
  537. else:
  538.      print ("You currently have", int(FreeHeatSinks), HeatSinkType, "Heat Sinks.")
  539.      UserHeatSinks = ask("If you wish to install additional Heat Sinks, enter the quantity you wish to add", 0, MechTonnage)
  540.      
  541. TotalHeatSinks = UserHeatSinks + FreeHeatSinks
  542.  
  543. if UserHeatSinks > 0:
  544.      print("You now have", TotalHeatSinks, "total", HeatSinkType, "HeatSinks.")
  545.  
  546. if EngineType in {"ProtoMech Engine"}:
  547.         HeatSinkWeight = RoundUpFractional(UserHeatSinks/4.0)
  548.         IntegralHeatSinks = int(TotalHeatSinks)
  549.         HeatSinkSlots = 0
  550. elif HeatSinkType in {"Compact"}:
  551.         HeatSinkWeight = RoundUpHalf(UserHeatSinks * 1.5)
  552.         IntegralHeatSinks = int(min(TotalHeatSinks, math.floor(LithiumBatteryRating/12.5)))
  553. else:
  554.         HeatSinkWeight = UserHeatSinks * 1.0
  555.         IntegralHeatSinks = int(min(TotalHeatSinks, math.floor(LithiumBatteryRating/25.0)))
  556.  
  557. PodHeatSinks = TotalHeatSinks - IntegralHeatSinks
  558.  
  559. if MechTonnage < 101:
  560.      if HeatSinkType in ["Single", "Liquid Metal"]:
  561.          HeatSinkSlots = PodHeatSinks
  562.      elif HeatSinkType in ["Double (Inner Sphere)", "Double (ProtoType)"]:
  563.          HeatSinkSlots = PodHeatSinks * 3
  564.      elif HeatSinkType in ["Double (Clan)", "Double (Star Empire)", "Laser"]:
  565.          HeatSinkSlots = PodHeatSinks * 2
  566.      elif HeatSinkType in ["Compact"]:
  567.          HeatSinkSlots = math.ceil(PodHeatSinks/2)
  568.      elif HeatSinkType in ["ProtoMech"]:
  569.          HeatSinkSlots = 0
  570.  
  571. elif MechTonnage > 100:
  572.      if HeatSinkType in ["Single"]:
  573.          HeatSinkSlots = math.ceil(PodHeatSinks/2)
  574.      elif HeatSinkType in ["Double (Inner Sphere)"]:
  575.          HeatSinkSlots = math.ceil(PodHeatSinks * 1.5)
  576.      elif HeatSinkType in ["Double (Clan)", "Laser"]:
  577.          HeatSinkSlots = PodHeatSinks
  578.      elif HeatSinkType in ["Compact"]:
  579.          HeatSinkSlots = math.ceil(PodHeatSinks/4)
  580.  
  581. #Podspace
  582. skeleton = InternalWeight(InternalType)
  583. tripod = RoundUpHalf(skeleton * 1.1)
  584. cockpit = CockpitWeight(CockpitType)
  585. gyro = GyroWeight(GyroType)
  586. EngineTonnage = EngineWeight(EngineType, rating)
  587.  
  588. if MechType in ["Combat Vehicle", "Support Vehicle"]:
  589.      if EngineType in ["Internal Combustion Engine (ICE)", "Fuel Cell", "Primitive Internal Combustion Engine (ICE)", "Primitive Fuel Cell"]:
  590.           VehicleEngine = EngineTonnage
  591.      else:
  592.           if MechType in ["Combat Vehicle"]:
  593.                VehicleEngine = RoundUpHalf(EngineTonnage * 1.5)
  594.           elif MechType in ["Support Vehicle"]:
  595.                VehicleEngine = RoundUpFractional(EngineTonnage * 1.5)
  596. else:
  597.      VehicleEngine = EngineTonnage
  598.  
  599. print()
  600.  
  601. #DEBUG READOUT - UNCOMMENT IF CRASHES OCCUR
  602. print ("DEBUG READOUT - RECOMMENT IF CRASHES NO LONGER OCCUR")
  603. print ("MechTonnage =", MechTonnage)
  604. print ("EngineTonnage =", EngineTonnage)
  605. print ("VehicleEngine =", VehicleEngine)
  606. print ("FinalRating =", FinalRating)
  607. print ("skeleton =", skeleton)
  608. print ("tripod =", tripod)
  609. print ("gyro =", gyro)
  610. print ("cockpit =", cockpit)
  611. print ("HeatSinkWeight =", HeatSinkWeight)
  612. print ("Press ENTER to confirm, or Ctrl+C to abort.")
  613. input()
  614. #^^^^^^^^^^^^^
  615.        
  616. if MechType in ["Tripod", "SuperHeavy Tripod"]:
  617.      podspace = RoundDownHalf(MechTonnage - EngineTonnage - tripod - gyro - cockpit - HeatSinkWeight)
  618. elif EngineType in ["ProtoMech Engine", "ProtoMech XL Lithium-Fusion Engine"] or MechType in ["ProtoMech", "Quad ProtoMech", "Glider ProtoMech"]:
  619.      podspace = RoundDownFractional(MechTonnage - EngineTonnage - skeleton - gyro - cockpit - HeatSinkWeight)
  620. elif MechType in ["Combat Vehicle"]:
  621.      podspace = RoundDownHalf(MechTonnage - VehicleEngine - skeleton - gyro - cockpit - HeatSinkWeight)
  622. elif MechType in ["Support Vehicle"]:
  623.      podspace = RoundDownFractional(MechTonnage - VehicleEngine - skeleton - gyro - cockpit - HeatSinkWeight)
  624. else:
  625.      podspace = RoundDownHalf(MechTonnage - EngineTonnage - skeleton - gyro - cockpit - HeatSinkWeight)
  626.  
  627. if VehicleEngine > MechTonnage:
  628.     print ("WARNING! Your engine is heavier than the mech!");
  629.     print ("WARNING! Your mech has negative podspace, and is Overweight!");
  630.     input()
  631. elif podspace < 0.0:
  632.     print ("WARNING! Your mech has negative podspace, and is Overweight!");
  633.     input()
  634. else:
  635.     print("ALL SYSTEMS NOMINAL.")
  636.     input()
  637.  
  638. #Finalize
  639. if MechName in {"BattleMech", "Ultralight BattleMech", "Light BattleMech", "Medium BattleMech", "Heavy BattleMech", "Assault BattleMech", "SuperHeavy BattleMech"}:
  640.      if InternalType in {"Industrial"}:
  641.          if MechClass in {"Ultralight", "Light", "Medium", "Heavy", "Assault", "SuperHeavy"}:
  642.               MechName = (MechClass + " IndustrialMech")
  643.      if InternalType in {"Primitive Standard"}:
  644.          if MechClass in {"Ultralight", "Light", "Medium", "Heavy", "Assault", "SuperHeavy"}:
  645.               MechName = ("Primitive " + MechClass + " BattleMech")
  646.      if InternalType in {"Primitive Industrial"}:
  647.          if MechClass in {"Ultralight", "Light", "Medium", "Heavy", "Assault", "SuperHeavy"}:
  648.               MechName = ("Primitive " + MechClass + " IndustrialMech")
  649.      elif MechClass in {"ProtoMech", "UltraHeavy ProtoMech"}:
  650.           MechName = MechClass
  651.           MechType = ("ProtoMech")
  652.      elif CockpitType in {"AutoMech"}:
  653.           MechName = (MechClass + "AutoMech")
  654.           MechType = ("AutoMech")
  655.  
  656. #Technical Readout
  657. fib(FinalRating)
  658. print()
  659. print ("Your", MechName, "has a Cruising MP of", CruisingSpeed, "hexes per turn, and a Flanking MP of", FlankingSpeed, "hexes per turn.");
  660.  
  661. print ("This speed is provided by a", FinalRating,'rated', EngineType, "weighing", EngineTonnage, "metric tons.");
  662.  
  663. if EngineType in ["ProtoMech Engine", "ProtoMech XL Lithium-Fusion Engine"]:
  664.      print("You have", TotalHeatSinks, HeatSinkType, "Heat Sinks weighing", HeatSinkWeight, "metric tons.")
  665.  
  666. else:
  667.      print("You have", TotalHeatSinks, HeatSinkType, "Heat Sinks weighing", HeatSinkWeight, "metric tons, of which", IntegralHeatSinks, "of them are Integral,")
  668.      print ("and out of those", TotalHeatSinks, HeatSinkType, "Heat Sinks,",FreeHeatSinks, "of them come with the engine.")
  669.      if PodHeatSinks > 0:
  670.           print ("The remaining", HeatSinkType, "Heat Sinks occupy", HeatSinkSlots, "Critical Spaces in total.")    
  671.  
  672. print()
  673.  
  674. if MechType in ["Tripod"]:
  675.      print ("The Mech's weight is supported by a", InternalType, "Internal Structure with a mass of", tripod, "metric tons.");
  676.  
  677. elif MechType in ["AutoMech"]:
  678.      print ("The AutoMech’s weight is supported by a", InternalType, "Internal Structure with a mass of", skeleton, "metric tons.");
  679.      
  680. elif MechType in ["ProtoMech"]:
  681.      print ("The ProtoMech’s weight is supported by a", InternalType, "Internal Structure with a mass of", skeleton*1000, "kilograms.");
  682.  
  683. else:
  684.      print ("The Mech’s weight is supported by a", InternalType, "Internal Structure with a mass of", skeleton, "metric tons.");
  685.  
  686. if GyroType in ["None"] and MechTonnage > 9:
  687.      print("The pilot is cocooned in an", CockpitType, "Cockpit, which weighs", cockpit, "metric tons.");
  688.  
  689. elif GyroType in ["None"] and MechTonnage <10:
  690.      print("The pilot is cocooned in a", CockpitType, "Cockpit, which weighs", cockpit, "metric tons.");
  691.  
  692. elif CockpitType in ["Drone Operating System", "AutoMech"]:
  693.      if GyroType in ["XL (Extra-Light)"]:
  694.           print ("and keeping the", MechName, "upright is an", GyroType, "Gyro weighing", gyro, "metric tons.")
  695.      else:
  696.           print ("and keeping the", MechName, "upright is a", GyroType, "Gyro weighing", gyro, "metric tons.")
  697.      
  698.      if CockpitType in ["Drone Operating System"]:
  699.           print ("The brains of this machine consist of a", CockpitType, "weighing", cockpit, "metric tons.")
  700.      
  701.      elif CockpitType in ["AutoMech"]:
  702.           print ("The brains of this machine consist of an", CockpitType, "weighing", cockpit, "metric tons.")
  703.  
  704. elif GyroType in ["SuperHeavy"]:
  705.      print ("and the only thing stopping your", MechName, "from toppling over is a monstrous", GyroType, "Gyro weighing", gyro, "metric tons.");
  706.      print ("The pilots are 'efficiently' huddled together in a", CockpitType, "Cockpit, weighing a massive", cockpit, "metric tons.");
  707.  
  708. elif GyroType in ["XL (Extra-Light)"]:
  709.      print ("and keeping the", MechName, "upright is an", GyroType, "Gyro weighing", gyro, "metric tons.");
  710.      print ("The pilot sits ’comfortably’ in a", CockpitType, "Cockpit, which weighs", cockpit, "metric tons.");
  711.  
  712. else:
  713.      print ("and keeping the", MechName, "upright is a", GyroType, "Gyro weighing", gyro, "metric tons.");
  714.      print ("The pilot sits 'comfortably' in a", CockpitType, "Cockpit, which weighs", cockpit, "metric tons.");
  715.  
  716. print()
  717. print ("The", MechName, "has an average walking speed of", kph(CruisingSpeed), "km/h, and a maximum running speed of", kph(FlankingSpeed), "km/h.");
  718.  
  719. if podspace > 0.0:
  720.    print ("The", MechName, "has", podspace, "tons of Pod Space available to mount weapons, armor and equipment.");
  721.    print();
  722.    fib(podspace)
  723.    print();
  724. else:
  725.    print ("Oh, stravag! It would seem that your engineers left your", MechName, "with only", podspace, "tons of Pod Space,")
  726.    print ("and now thanks to them, it cannot mount any weapons, armor or equipment!");
  727.    print();
  728.    print("+++ MELON. MELON. MELON. Out-of-Cheese Error. +++")
  729.    print("Redo from Start.")
  730.    input()
  731.  
  732. ## Closing sequence.
  733. print ("Please visit http://www.sarna.net for more information on these terms and components.");
  734. print ("If you have any questions or feedback about the software, such as feature requests or bug reports,");
  735. print ("if you need technical support, or would simply like to contribute to development, then please visit:");
  736. print ("https://tinyurl.com/Sarna-Forums-MechEngine");
  737. print();
  738. gettime()
  739. input("Shutdown Sequence: Initiated.") #Change this line to a menu option once Restart has been implemented.
  740. print ("Shutting Down.")
  741.  
  742. ## End of Line.
  743.  
  744. #Contribution Links:
  745. #     https://pastebin.com/FyZMY15V
  746. #     https://docs.google.com/document/d/1A6Y79pelpzdRg00DHcZNO3tyrdvthFSaU4tihSvGkE8/edit?usp=sharing
Add Comment
Please, Sign In to add comment