|
|
@@ -6,6 +6,9 @@ from typing import NamedTuple |
|
|
|
|
|
|
|
from jinja2 import Environment, PackageLoader, select_autoescape |
|
|
|
|
|
|
|
import items |
|
|
|
from destinations import DESTINATIONS, Destination |
|
|
|
|
|
|
|
# global variables |
|
|
|
|
|
|
|
env = Environment(loader=PackageLoader("swjg"), autoescape=select_autoescape) |
|
|
@@ -25,6 +28,14 @@ def get_identifiers_from_template(template): |
|
|
|
return matches |
|
|
|
|
|
|
|
|
|
|
|
def get_destination_type_from_enum(destination): |
|
|
|
dtype = destination.type |
|
|
|
dtype_name = dtype._name_ |
|
|
|
dtype_name_lower = dtype_name.lower() |
|
|
|
dtype_name_nou = dtype_name_lower.replace("_", " ") |
|
|
|
return dtype_name_nou |
|
|
|
|
|
|
|
|
|
|
|
class DangerLevel(Enum): |
|
|
|
NONE = 1 |
|
|
|
LOW = 2 |
|
|
@@ -42,17 +53,13 @@ class DangerType(Enum): |
|
|
|
ATMOSPHERE = 6 |
|
|
|
|
|
|
|
|
|
|
|
class Destination(NamedTuple): |
|
|
|
world: str |
|
|
|
system: str | None |
|
|
|
sector: str | None |
|
|
|
|
|
|
|
|
|
|
|
# Class definitions |
|
|
|
|
|
|
|
|
|
|
|
class Mission: |
|
|
|
output_destination_template = Template("to $world in the $system system") |
|
|
|
output_destination_template = Template( |
|
|
|
"to $world, a $destination_type in the $system system" |
|
|
|
) |
|
|
|
output_sector_template = Template(", part of the $sector,") |
|
|
|
value_template = Template("for $value credits") |
|
|
|
error_template = Template( |
|
|
@@ -61,14 +68,13 @@ class Mission: |
|
|
|
|
|
|
|
def __init__(self, destination: Destination, value: int, *args, **kwargs): |
|
|
|
# destination: Destination (see above) |
|
|
|
self.world = destination.world if destination.world is not None else None |
|
|
|
self.world = destination.name if destination.name is not None else None |
|
|
|
self.system = ( |
|
|
|
destination.system if destination.system is not None else destination.world |
|
|
|
destination.system if destination.system is not None else destination.name |
|
|
|
) |
|
|
|
self.sector = destination.sector if destination.sector is not None else None |
|
|
|
self.destination_type = get_destination_type_from_enum(destination) |
|
|
|
self.value = value |
|
|
|
# for arg, val in kwargs.items(): |
|
|
|
# setattr(self, arg, val) |
|
|
|
|
|
|
|
def assemble_templates(self) -> list: |
|
|
|
# Override this in children |
|
|
@@ -85,6 +91,7 @@ class Mission: |
|
|
|
"world": self.world, |
|
|
|
"system": self.system, |
|
|
|
"sector": self.sector, |
|
|
|
"destination_type": self.destination_type, |
|
|
|
"value": self.value, |
|
|
|
} |
|
|
|
|
|
|
@@ -92,7 +99,7 @@ class Mission: |
|
|
|
object_vars = vars(self) |
|
|
|
missing = [] |
|
|
|
for key, val in object_vars.items(): |
|
|
|
if val == None: |
|
|
|
if val is None and key != "time": # time is optional |
|
|
|
missing.append(key) |
|
|
|
return missing |
|
|
|
|
|
|
@@ -143,7 +150,7 @@ class CargoMission(Mission): |
|
|
|
output_initial_template = Template("Deliver $tons tons of $item") |
|
|
|
output_time_timeplate = Template("in the next $time days") |
|
|
|
|
|
|
|
def __init__(self, tons: int, item: str, time: int, *args, **kwargs): |
|
|
|
def __init__(self, tons: int, item: str, time: int | None, *args, **kwargs): |
|
|
|
# tons: integer |
|
|
|
# item: string (this will not be pluralized in the text) |
|
|
|
# time: integer (number of days the crew have to complete delivery) |
|
|
@@ -201,21 +208,28 @@ def main(): |
|
|
|
missions = [] |
|
|
|
for _ in range(5): |
|
|
|
current_mission = random.choice(mission_types) |
|
|
|
destination = Destination("Alderaan", None, "Core Worlds") |
|
|
|
number = random.randint(1, 8) |
|
|
|
tons = random.randint(4, 12) |
|
|
|
item = random.choice( |
|
|
|
[ |
|
|
|
"gravel", |
|
|
|
"computer chips", |
|
|
|
"spice", |
|
|
|
"live ysalamiri", |
|
|
|
"empty shipping containers", |
|
|
|
] |
|
|
|
) |
|
|
|
time = random.randint(7, 31) |
|
|
|
value = random.randint(20, 120) * 1000 |
|
|
|
group = None |
|
|
|
destination = random.choice(DESTINATIONS) |
|
|
|
item, time, tons, number, value, group = [None] * 6 |
|
|
|
if current_mission == CargoMission: |
|
|
|
current_item = random.choice(items.ITEMS) |
|
|
|
tons = random.randint( |
|
|
|
current_item.potential_tons[0], current_item.potential_tons[1] |
|
|
|
) |
|
|
|
value = random.randint(*current_item.potential_values) * 1000 |
|
|
|
item = current_item.name |
|
|
|
if current_item.potential_times is not None: |
|
|
|
if current_item.chance_for_time is not None: |
|
|
|
is_there_a_time = random.random() * 100 |
|
|
|
# print(current_item.chance_for_time, is_there_a_time, is_there_a_time < current_item.chance_for_time) |
|
|
|
if is_there_a_time < current_item.chance_for_time: |
|
|
|
time = random.randint( |
|
|
|
current_item.potential_times[0], |
|
|
|
current_item.potential_times[1], |
|
|
|
) |
|
|
|
else: |
|
|
|
number = random.randint(1, 8) |
|
|
|
time = random.randint(7, 31) |
|
|
|
value = random.randint(20, 120) * 1000 |
|
|
|
if current_mission == GroupMission: |
|
|
|
group = random.choice(["family", "performing troupe", "acrobatic troupe"]) |
|
|
|
missions.append( |
|
|
@@ -235,6 +249,5 @@ def main(): |
|
|
|
|
|
|
|
|
|
|
|
# Don't do anything if the module is loaded wholesale into something else |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
main() |