This time I am trying to create a function to determine how far a destination is, and calculate various things relating to that.
I created a series of lists that contain distances between a current location, and potential destinations. So for example, if the player is at "earth" and wanted to go to mars, they would use the 5th number. (6th item? Still confused about that)
Code: Select all
default travel_distance_rounded = [ #so me ve ea ma ab ju gr tr sa ur ne pl
#"starting location", distance to destination in AU
["sol", 0.00, 0.50, 0.75, 1.00, 1.50, 3.00, 5.00, 6.00, 6.00, 10.00, 19.00, 30.00, 40.00],
["mercury", 0.50, 0.00, 0.25, 0.75, 2.25, 4.25, 5.25, 5.25, 5.50, 9.50, 18.50, 29.50, 39.50],
["venus", 0.75, 0.25, 0.00, 0.25, 0.75, 2.25, 4.25, 5.25, 5.25, 9.25, 18.25, 29.25, 39.25],
["earth", 1.00, 0.50, 0.25, 0.00, 0.50, 2.00, 4.00, 5.00, 5.00, 9.00, 18.00, 29.00, 39.00],
["mars", 1.50, 1.00, 0.75, 0.50, 0.00, 1.50, 3.50, 4.50, 4.50, 8.50, 17.50, 28.50, 38.50],
["asteroid belt", 3.00, 2.50, 2.25, 2.00, 1.50, 0.00, 2.00, 3.00, 3.00, 7.00, 16.00, 27.00, 37.00],
["jupiter", 5.00, 4.50, 4.25, 4.00, 3.50, 2.00, 0.00, 1.00, 1.00, 5.00, 14.00, 25.00, 35.00],
["greeks", 6.00, 5.50, 5.25, 5.00, 4.50, 3.00, 1.00, 0.00, 1.00, 4.00, 13.00, 24.00, 34.00],
["trojans", 6.00, 5.50, 5.25, 5.00, 4.50, 3.00, 1.00, 1.00, 0.00, 4.00, 13.00, 24.00, 34.00],
["saturn", 10.00, 9.50, 9.25, 9.00, 8.50, 7.00, 5.00, 4.00, 4.00, 0.00, 9.00, 20.00, 30.00],
["uranus", 19.00, 18.50, 18.25, 18.00, 17.50, 16.00, 14.00, 13.00, 13.00, 9.00, 0.00, 11.00, 21.00],
["neptune", 30.00, 29.50, 29.25, 29.00, 28.50, 27.00, 25.00, 24.00, 24.00, 20.00, 11.00, 0.00, 10.00],
["pluto", 40.00, 39.50, 39.25, 39.00, 38.50, 37.00, 35.00, 34.00, 34.00, 30.00, 21.00, 10.00, 0.00],
]
Code: Select all
default destination_number = [
["sol", 1],
["mercury", 2],
["venus", 3],
["earth", 4],
["mars", 5],
["asteroid belt", 6],
["jupiter", 7],
["greeks", 8],
["trojans", 9],
["saturn", 10],
["uranus", 11],
["neptune", 12],
["pluto", 13],
]
Code: Select all
init python:
def distance_checker():
global travel_distance_rounded
global destination_number
global player_destination
global player_location
global engine_power
global ship_fuel
AU = 150,000,000
#compare player_location with travel_distance_rounded to find the correct list.
#compare player_destination with destination_number to get the number: dest_number.
dest_number =
#use the dest_number to determine the item number of the list: dist_number
dist_number =
#1 fuel is worth 0.25, so divide dist_number by 0.25 to determine required fuel: req_fuel.
req_fuel = (dist_number / 0.25)
#multiply dist_number and AU to determine distance in kilometers: travel_distance
travel_distance = (dist_number * AU)
#multiply engine_power by dist_number to get travel time: travel_time
travel_time = (engine_power * dist_number)
if ship_fuel >= (req_fuel + 1):
ship_fuel -= req_fuel
jump player_destination
elif ship_fuel == req_fuel:
call fuel_question
else:
narrator("You don't have enough fuel for that destination.", interact=True)
label fuel_question:
"You have exactly enough fuel to reach that destination, but it's recomended that you carry some reserve for emergencies."
menu:
"Do you still wish to procede?"
"Engage!":
jump player_destination
"Reconsider":
return