Change naming to static class

This ensures all generators are using the same ID set.
This commit is contained in:
walterroach 2020-12-28 11:22:28 -06:00
parent d7e48662e0
commit 09b7cb3d85

View File

@ -13,12 +13,7 @@ ALPHA_MILITARY = ["Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot",
"Tango", "Uniform", "Victor", "Whisky", "XRay", "Yankee",
"Zulu", "Zero"]
class NameGenerator:
number = 0
infantry_number = 0
ANIMALS = [
ANIMALS = [
"SHARK", "TORTOISE", "BAT", "PANGOLIN", "AARDWOLF",
"MONKEY", "BUFFALO", "DOG", "BOBCAT", "LYNX", "PANTHER", "TIGER",
"LION", "OWL", "BUTTERFLY", "BISON", "DUCK", "COBRA", "MAMBA",
@ -46,20 +41,26 @@ class NameGenerator:
"ANACONDA"
]
def __init__(self):
self.number = 0
self.ANIMALS = NameGenerator.ANIMALS.copy()
class NameGenerator:
number = 0
infantry_number = 0
def reset(self):
self.number = 0
self.ANIMALS = NameGenerator.ANIMALS.copy()
ANIMALS = ANIMALS
def reset_numbers(self):
self.number = 0
self.infantry_number = 0
@classmethod
def reset(cls):
cls.number = 0
cls.infantry_number = 0
cls.ANIMALS = NameGenerator.ANIMALS.copy()
def next_aircraft_name(self, country: Country, parent_base_id: int, flight: Flight):
self.number += 1
@classmethod
def reset_numbers(cls):
cls.number = 0
cls.infantry_number = 0
@classmethod
def next_aircraft_name(cls, country: Country, parent_base_id: int, flight: Flight):
cls.number += 1
try:
if flight.custom_name:
name_str = flight.custom_name
@ -69,38 +70,45 @@ class NameGenerator:
except AttributeError: # Here to maintain save compatibility with 2.3
name_str = "{} {}".format(
flight.package.target.name, flight.flight_type)
return "{}|{}|{}|{}|{}|".format(name_str, country.id, self.number, parent_base_id, db.unit_type_name(flight.unit_type))
return "{}|{}|{}|{}|{}|".format(name_str, country.id, cls.number, parent_base_id, db.unit_type_name(flight.unit_type))
def next_unit_name(self, country: Country, parent_base_id: int, unit_type: UnitType):
self.number += 1
return "unit|{}|{}|{}|{}|".format(country.id, self.number, parent_base_id, db.unit_type_name(unit_type))
@classmethod
def next_unit_name(cls, country: Country, parent_base_id: int, unit_type: UnitType):
cls.number += 1
return "unit|{}|{}|{}|{}|".format(country.id, cls.number, parent_base_id, db.unit_type_name(unit_type))
def next_infantry_name(self, country: Country, parent_base_id: int, unit_type: UnitType):
self.infantry_number += 1
return "infantry|{}|{}|{}|{}|".format(country.id, self.infantry_number, parent_base_id, db.unit_type_name(unit_type))
@classmethod
def next_infantry_name(cls, country: Country, parent_base_id: int, unit_type: UnitType):
cls.infantry_number += 1
return "infantry|{}|{}|{}|{}|".format(country.id, cls.infantry_number, parent_base_id, db.unit_type_name(unit_type))
def next_basedefense_name(self):
@staticmethod
def next_basedefense_name():
return "basedefense_aa|0|0|"
def next_awacs_name(self, country: Country):
self.number += 1
return "awacs|{}|{}|0|".format(country.id, self.number)
@classmethod
def next_awacs_name(cls, country: Country):
cls.number += 1
return "awacs|{}|{}|0|".format(country.id, cls.number)
def next_tanker_name(self, country: Country, unit_type: UnitType):
self.number += 1
return "tanker|{}|{}|0|{}".format(country.id, self.number, db.unit_type_name(unit_type))
@classmethod
def next_tanker_name(cls, country: Country, unit_type: UnitType):
cls.number += 1
return "tanker|{}|{}|0|{}".format(country.id, cls.number, db.unit_type_name(unit_type))
def next_carrier_name(self, country: Country):
self.number += 1
return "carrier|{}|{}|0|".format(country.id, self.number)
@classmethod
def next_carrier_name(cls, country: Country):
cls.number += 1
return "carrier|{}|{}|0|".format(country.id, cls.number)
def random_objective_name(self):
if len(self.ANIMALS) == 0:
@classmethod
def random_objective_name(cls):
if len(cls.ANIMALS) == 0:
return random.choice(ALPHA_MILITARY).upper() + "#" + str(random.randint(0, 100))
else:
animal = random.choice(self.ANIMALS)
self.ANIMALS.remove(animal)
animal = random.choice(cls.ANIMALS)
cls.ANIMALS.remove(animal)
return animal
namegen = NameGenerator()
namegen = NameGenerator