# tribalwars calculation program v0.01 # Copyright 2008 Thomas Hodson tomhodson.net import math def inputter(whose): while True: try: out = int(raw_input(whose + ": ")) break except ValueError: print "Invalid number, try again." return out def distancer(): if myvill == 0: x = inputter("Your x co-ord ") y = inputter("Your y co-ord ") else: x = myvillx y = myvilly ex = inputter("Enemy's x co-ord") ey = inputter("Enemy's y co-ord") distancex = x-ex distancey = y-ey return math.sqrt((distancex**2)+(distancey**2)) def timeformat(intime): if intime < 10: intime = "0"+str(intime) return str(intime) def timefunct(speedf, distancef): stringg = int(distancef*speedf) stringh = int(stringg/60) stringf = int((distancef*speedf-stringg)*60)+1 stringg = stringg-stringh*60 stringf = timeformat(stringh)+":"+timeformat(stringg)+":"+timeformat(stringf) return stringf print "Welcome to the tribalwars calc" print "by tomhodson.net" print "______________________________" myvill = 0 while exit!=1: print # Print out the menu if myvill == 1: print "Your village: "+ str(myvillx) +"|"+ str(myvilly) print "Please select a task:" print "1 Time for Arrival" print "2 Set your co-ordinates" print "3 Clear your co-ordinates" print "4 Minimum Nobles" print "5 Nobles" print "6 Exit" # Get the users choice choice = inputter("> ") # Calculate the area: if choice == 1: distance = distancer() print "Distance :", distance print "Merchant :", timefunct(6,distance) print "Spearmen :", timefunct(18,distance) print "Swordmen :", timefunct(22,distance) print "Axemen :", timefunct(18,distance) print "Archers :", timefunct(18,distance) print "Scouts :", timefunct(9,distance) print "Light Cavalry :", timefunct(10,distance) print "Mounted Archers :", timefunct(10,distance) print "Heavy Cavalry :", timefunct(11,distance) print "Ram :", timefunct(30,distance) print "Catapult :", timefunct(30,distance) print "Noble :", timefunct(35,distance) print "Paladin :", timefunct(10,distance) else: if choice ==2: myvillx = inputter("Your x co-ord") myvilly = inputter("Your y co-ord") myvill = 1 else: if choice ==3: myvill=0 else: if choice ==4: distance=distancer() teg=((distance*2*35)/60/20) #nobles=recovery/damage if int(teg+1)>5: teg=5 dprw= (20*teg) runsw=1 nobletimew=timefunct(35,distance) print "Minimum nobles :", teg print "Damage per run :", dprw print "Runs :", runsw print "Time :", nobletimew else: teh=((distance*2*35)/60/35) dprw= (20*int(teg+1))-((distance*2*35)/60) #damage for one full run=damage*nobles-recovery dprb= 35*int(teh+1)-((distance*2*35)/60) runsw=int(((100-20*teg)/(dprw))+1) #overall/damage for one run= total runs runsb=int(((100-35*teh)/(dprb))+1) nobletimew=timefunct(35,((runsw-1)*distance*2)+distance) nobletimeb=timefunct(35,((runsb-1)*distance*2)+distance) if int(teh+1) == int(teg+1): print "Minimum nobles :", int(teh+1) else: print "Minimum nobles :", int(teh+1), "-", int(teg+1) print "Damage per run :", dprw, "-", dprb print "Runs :",runsb, "-",runsw print "Time :", nobletimeb,"-",nobletimew else: if choice == 5: distance=distancer() teg = inputter("Number of Nobles") if teg*20<100: dprw= 20*teg-((distance*2*35)/60) #damage for one full run=damage*nobles-recovery dprb= 35*teg-((distance*2*35)/60) if dprb>0: runsw=int(((100-20*teg)/(dprw))+2) #overall/damage for one run= total runs runsb=int(((100-35*teg)/(dprb))+2) if runsw>0: nobletimew=timefunct(35,((runsw-1)*distance*2)+distance) else: nobletimew="Inf" runsw="Inf" nobletimeb=timefunct(35,((runsb-1)*distance*2)+distance) print "Damage per run :", dprw, "-", dprb print "Runs :",runsb, "-",runsw print "Time :", nobletimeb,"-",nobletimew else: print "Impossible" else: dprw=100 runsw=1 nobletimew=timefunct(35,distance) print "Damage per run :",dprw print "Runs :",runsw print "Time :", nobletimew else: exit = 1