Browse Source

Start making actual item/world types

main
Noëlle 9 months ago
parent
commit
25137c702c
No known key found for this signature in database
3 changed files with 121 additions and 29 deletions
  1. 35
    0
      destinations.py
  2. 44
    0
      items.py
  3. 42
    29
      swjg.py

+ 35
- 0
destinations.py View File

@@ -0,0 +1,35 @@
from enum import Enum
from typing import NamedTuple


class DestinationType(Enum):
STATION = 1
TEMPERATE_WORLD = 2
DESERT_WORLD = 3
FROZEN_WORLD = 4
JUNGLE_WORLD = 5
OCEAN_WORLD = 6
ASTEROID = 7


class Destination(NamedTuple):
name: str
system: str | None
sector: str | None
type: DestinationType


DESTINATIONS = [
Destination(
name="Alderaan",
system=None,
sector="Core Worlds",
type=DestinationType.TEMPERATE_WORLD,
),
Destination(
name="Tattooine",
system=None,
sector="Outer Rim",
type=DestinationType.DESERT_WORLD,
),
]

+ 44
- 0
items.py View File

@@ -0,0 +1,44 @@
from typing import NamedTuple


class ItemType(NamedTuple):
name: str
potential_tons: tuple
potential_values: tuple
potential_times: tuple | None = None
chance_for_time: int | None = None
must_be_smuggled: bool = False


ITEMS = [
ItemType(
name="gravel",
potential_tons=(1, 8),
potential_values=(5, 40),
),
ItemType(
name="computer chips",
potential_tons=(1, 3),
potential_values=(10, 120),
potential_times=(7, 31),
chance_for_time=50,
),
ItemType(
name="spice",
potential_tons=(1, 10),
potential_values=(12, 120),
potential_times=(7, 31),
chance_for_time=75,
must_be_smuggled=True,
),
ItemType(
name="live ysalamiri",
potential_tons=(1, 2),
potential_values=(5, 10),
potential_times=(7, 14),
chance_for_time=100,
),
ItemType(
name="empty shipping containers", potential_values=(1, 2), potential_tons=(2, 5)
),
]

+ 42
- 29
swjg.py View File

@@ -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()

Loading…
Cancel
Save