252 lines
6.1 KiB
GDScript
252 lines
6.1 KiB
GDScript
class_name Random
|
|
|
|
const MIN_WORD_LEN = 3
|
|
const MAX_WORD_LEN = 5
|
|
|
|
const VOWEL = ["a", "e", "i", "o", "u", "y"]
|
|
const CONSONANTS = ["b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "z"]
|
|
|
|
const END_PLANT_NAME := ["us", "um", "ae", "ia", "is", "as", "am"]
|
|
|
|
#region ------------------ Plant Name ------------------
|
|
|
|
static func generate_random_word(_random_seed = randi()) -> String:
|
|
if (
|
|
GameInfo
|
|
and GameInfo.settings_data
|
|
and GameInfo.settings_data.activate_twitch_integration
|
|
and len(TwitchConnection.pseudo_gathered)
|
|
):
|
|
return TwitchConnection.pseudo_gathered.pick_random()
|
|
|
|
var word_len = randf_range(4,8)
|
|
var word = ''
|
|
var last_letter_is_vowel = randi() % 2
|
|
|
|
for i in range(word_len):
|
|
if last_letter_is_vowel:
|
|
word += CONSONANTS.pick_random()
|
|
else:
|
|
word += VOWEL.pick_random()
|
|
|
|
last_letter_is_vowel = not last_letter_is_vowel
|
|
return word.capitalize()
|
|
|
|
static func generate_random_plant_name(random_seed = randi()) -> String:
|
|
if (
|
|
GameInfo
|
|
and GameInfo.settings_data
|
|
and GameInfo.settings_data.activate_twitch_integration
|
|
and len(TwitchConnection.pseudo_gathered)
|
|
):
|
|
return TwitchConnection.pseudo_gathered.pick_random()
|
|
|
|
var random_word := generate_random_word(random_seed)
|
|
if VOWEL.has(random_word.right(1)):
|
|
random_word += CONSONANTS.pick_random()
|
|
return random_word + END_PLANT_NAME.pick_random()
|
|
|
|
static func mutate_word(word: String) -> String:
|
|
var rand_int = randi()
|
|
|
|
if len(word) > MIN_WORD_LEN and rand_int % 3 == 0:
|
|
return shorten_word(word)
|
|
elif len(word) < MAX_WORD_LEN and rand_int % 3 == 1:
|
|
return elongate_word(word)
|
|
|
|
return replace_character(word)
|
|
|
|
static func small_mutate_plant_name(name: String) -> String:
|
|
if (
|
|
GameInfo
|
|
and GameInfo.settings_data
|
|
and GameInfo.settings_data.activate_twitch_integration
|
|
and len(TwitchConnection.pseudo_gathered)
|
|
):
|
|
return name
|
|
|
|
var mutable_name = name.substr(1, len(name) - 3)
|
|
mutable_name = replace_character(mutable_name)
|
|
name = name.left(1) + mutable_name + name.right(2)
|
|
return name.to_lower().capitalize()
|
|
|
|
static func big_mutate_plant_name(name: String) -> String:
|
|
if (
|
|
GameInfo
|
|
and GameInfo.settings_data
|
|
and GameInfo.settings_data.activate_twitch_integration
|
|
and len(TwitchConnection.pseudo_gathered)
|
|
):
|
|
return name
|
|
|
|
var name_without_end = name.left(-2)
|
|
var rand_int := randi()
|
|
if len(name) > MIN_WORD_LEN and rand_int % 4 == 0:
|
|
name = shorten_word(name_without_end) + name.right(2)
|
|
elif len(name) < MAX_WORD_LEN and rand_int % 4 == 1:
|
|
name = elongate_word(name_without_end) + name.right(2)
|
|
elif rand_int % 4 == 2:
|
|
name = replace_character(name.left(1)) + name.substr(1)
|
|
else:
|
|
var new_end = END_PLANT_NAME.pick_random()
|
|
while name == name_without_end + new_end:
|
|
new_end = END_PLANT_NAME.pick_random()
|
|
name = name_without_end + new_end
|
|
|
|
return name.to_lower().capitalize()
|
|
|
|
static func shorten_word(word: String):
|
|
if randi() % 2 == 0:
|
|
return word.left(len(word) - 1).capitalize()
|
|
else:
|
|
return word.right(len(word) - 1).capitalize()
|
|
|
|
static func elongate_word(word: String):
|
|
if randi() % 2 == 0:
|
|
var letter = CONSONANTS.pick_random() if word.left(1) in VOWEL else VOWEL.pick_random()
|
|
return (letter + word).to_lower().capitalize()
|
|
else:
|
|
var letter = CONSONANTS.pick_random() if word.right(1) in VOWEL else VOWEL.pick_random()
|
|
return (word + letter).to_lower().capitalize()
|
|
|
|
static func replace_character(word: String):
|
|
var character_ind = randi_range(0, len(word) - 1)
|
|
var character = word[character_ind].to_lower()
|
|
|
|
while character == word[character_ind].to_lower():
|
|
if character in VOWEL:
|
|
character = VOWEL.pick_random()
|
|
else:
|
|
character = CONSONANTS.pick_random()
|
|
|
|
word[character_ind] = character
|
|
return word
|
|
|
|
#region ------------------ Region Name ------------------
|
|
|
|
const RANDOM_REGION_NAME_POOL = [
|
|
"Pinouille",
|
|
"Hyugo",
|
|
"Dedana",
|
|
"Snowy",
|
|
"Eros",
|
|
"Snoop",
|
|
"Warmfuzzy",
|
|
"Sheepish",
|
|
"Nebula",
|
|
"Luna",
|
|
"Catapult",
|
|
"Kepler",
|
|
"Fabricius",
|
|
"Sagan",
|
|
"Lovelace",
|
|
"Torvalds",
|
|
"Turing",
|
|
"Asimov",
|
|
"Herbert",
|
|
"Wells",
|
|
"Pesquet",
|
|
"Tereshkova",
|
|
"Poiro",
|
|
"O'Malley",
|
|
"Dream",
|
|
"Cumulus",
|
|
"Pyrka",
|
|
"Pacho",
|
|
"Birdopia",
|
|
"Obsaya",
|
|
"Looping",
|
|
"Jarvis",
|
|
"Orion",
|
|
"Canaillerie",
|
|
"Solanine",
|
|
"Plume",
|
|
"Tonga",
|
|
"Aimee",
|
|
"Alibi",
|
|
"Asdian",
|
|
"Ino",
|
|
"Tigrou",
|
|
"Plulune",
|
|
"Fledu",
|
|
"Jiclot",
|
|
"Greyun",
|
|
"Ebimeron",
|
|
"Fosmule",
|
|
"Nesnar",
|
|
"Broysau",
|
|
"Shiesal",
|
|
"Eblie",
|
|
"Ostraria",
|
|
"Nochuedan",
|
|
"Woshania",
|
|
"Eblor",
|
|
"Ochil",
|
|
"Speles",
|
|
"Oscesh",
|
|
"Estor",
|
|
"Lagronus",
|
|
"Relmania",
|
|
"Bobbeon",
|
|
"Peclite",
|
|
"Eivis",
|
|
"Drugantu",
|
|
"Latunides",
|
|
"Qisos",
|
|
"Bosos",
|
|
"Yesta",
|
|
"Nodeuria",
|
|
"Thosone",
|
|
"Zinuna",
|
|
"Viurus",
|
|
"Natis",
|
|
"Laduphus",
|
|
"Cebbaphus",
|
|
"Pungea",
|
|
"Vebos",
|
|
"Nebos",
|
|
"Dremili",
|
|
"Seganides",
|
|
"Icania",
|
|
"Aboulara",
|
|
"Guzadus",
|
|
"Dulmea",
|
|
"Kueli",
|
|
"Deothe",
|
|
"Gonides",
|
|
"Monvelib",
|
|
"Cimemia",
|
|
"Ricia",
|
|
"Nechov",
|
|
"Huphus",
|
|
"Maliat",
|
|
"Deaphus",
|
|
]
|
|
|
|
const RANDOM_REGION_TYPE_POOL = [
|
|
"REGION_TYPE_VALLEY",
|
|
"REGION_TYPE_HIGHLANDS",
|
|
"REGION_TYPE_HEIGHTS",
|
|
"REGION_TYPE_MOUNTAIN",
|
|
"REGION_TYPE_PEAKS",
|
|
"REGION_TYPE_HILLS",
|
|
"REGION_TYPE_PASS",
|
|
"REGION_TYPE_PLAIN",
|
|
"REGION_TYPE_CANAL",
|
|
"REGION_TYPE_FLATLANDS",
|
|
"REGION_TYPE_LABYRINTH",
|
|
"REGION_TYPE_REGION",
|
|
"REGION_TYPE_BARRIER",
|
|
"REGION_TYPE_CROWN",
|
|
"REGION_TYPE_SUMMIT",
|
|
"REGION_TYPE_PANORAMA",
|
|
"REGION_TYPE_EXPANSE",
|
|
"REGION_TYPE_GROUNDS",
|
|
"REGION_TYPE_PLATEAU",
|
|
"REGION_TYPE_FOOTHILLS",
|
|
"REGION_TYPE_RIDGE",
|
|
"REGION_TYPE_LANDSCAPE",
|
|
]
|
|
|
|
|