Now when mutating plants have their name mutating as well (if not twitch)
This commit is contained in:
@@ -1,16 +1,19 @@
|
|||||||
class_name Random
|
class_name Random
|
||||||
|
|
||||||
const MIN_WORD_LEN = 4
|
const MIN_WORD_LEN = 3
|
||||||
const MAX_WORD_LEN = 8
|
const MAX_WORD_LEN = 5
|
||||||
|
|
||||||
const VOWEL = ["a", "e", "i", "o", "u", "y"]
|
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 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 ------------------
|
#region ------------------ Plant Name ------------------
|
||||||
|
|
||||||
static func generate_random_word(_random_seed = randi()) -> String:
|
static func generate_random_word(_random_seed = randi()) -> String:
|
||||||
if (
|
if (
|
||||||
GameInfo
|
GameInfo
|
||||||
|
and GameInfo.settings_data
|
||||||
and GameInfo.settings_data.activate_twitch_integration
|
and GameInfo.settings_data.activate_twitch_integration
|
||||||
and len(TwitchConnection.pseudo_gathered)
|
and len(TwitchConnection.pseudo_gathered)
|
||||||
):
|
):
|
||||||
@@ -18,7 +21,7 @@ static func generate_random_word(_random_seed = randi()) -> String:
|
|||||||
|
|
||||||
var word_len = randf_range(4,8)
|
var word_len = randf_range(4,8)
|
||||||
var word = ''
|
var word = ''
|
||||||
var last_letter_is_vowel = false
|
var last_letter_is_vowel = randi() % 2
|
||||||
|
|
||||||
for i in range(word_len):
|
for i in range(word_len):
|
||||||
if last_letter_is_vowel:
|
if last_letter_is_vowel:
|
||||||
@@ -29,6 +32,20 @@ static func generate_random_word(_random_seed = randi()) -> String:
|
|||||||
last_letter_is_vowel = not last_letter_is_vowel
|
last_letter_is_vowel = not last_letter_is_vowel
|
||||||
return word.capitalize()
|
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:
|
static func mutate_word(word: String) -> String:
|
||||||
var rand_int = randi()
|
var rand_int = randi()
|
||||||
|
|
||||||
@@ -39,6 +56,44 @@ static func mutate_word(word : String) -> String:
|
|||||||
|
|
||||||
return replace_character(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):
|
static func shorten_word(word: String):
|
||||||
if randi() % 2 == 0:
|
if randi() % 2 == 0:
|
||||||
@@ -49,21 +104,22 @@ static func shorten_word(word : String):
|
|||||||
static func elongate_word(word: String):
|
static func elongate_word(word: String):
|
||||||
if randi() % 2 == 0:
|
if randi() % 2 == 0:
|
||||||
var letter = CONSONANTS.pick_random() if word.left(1) in VOWEL else VOWEL.pick_random()
|
var letter = CONSONANTS.pick_random() if word.left(1) in VOWEL else VOWEL.pick_random()
|
||||||
return (letter + word).capitalize()
|
return (letter + word).to_lower().capitalize()
|
||||||
else:
|
else:
|
||||||
var letter = CONSONANTS.pick_random() if word.right(1) in VOWEL else VOWEL.pick_random()
|
var letter = CONSONANTS.pick_random() if word.right(1) in VOWEL else VOWEL.pick_random()
|
||||||
return (word + letter).capitalize()
|
return (word + letter).to_lower().capitalize()
|
||||||
|
|
||||||
static func replace_character(word: String):
|
static func replace_character(word: String):
|
||||||
var character_id = randi_range(0, len(word))
|
var character_ind = randi_range(0, len(word) - 1)
|
||||||
var character = word[character_id]
|
var character = word[character_ind].to_lower()
|
||||||
|
|
||||||
|
while character == word[character_ind].to_lower():
|
||||||
if character in VOWEL:
|
if character in VOWEL:
|
||||||
character = VOWEL.pick_random()
|
character = VOWEL.pick_random()
|
||||||
else:
|
else:
|
||||||
character = CONSONANTS.pick_random()
|
character = CONSONANTS.pick_random()
|
||||||
|
|
||||||
word[character_id] = character
|
word[character_ind] = character
|
||||||
return word
|
return word
|
||||||
|
|
||||||
#region ------------------ Region Name ------------------
|
#region ------------------ Region Name ------------------
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
@tool
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
@export_tool_button("Test names", "Callable") var update_action = func(): print_random_names()
|
||||||
|
@export_tool_button("Test small mutate one name", "Callable") var test_small_mutation = func(): print_random_small_mutated_name()
|
||||||
|
@export_tool_button("Test big mutate one name", "Callable") var test_big_mutation = func(): print_random_big_mutated_name()
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
print_random_names()
|
||||||
|
|
||||||
|
func print_random_names(number: int = 10) -> void:
|
||||||
|
print("---------")
|
||||||
|
for i in range(number):
|
||||||
|
print(Random.generate_random_plant_name())
|
||||||
|
|
||||||
|
func print_random_small_mutated_name(n_mutations: int = 5) -> void:
|
||||||
|
print("---------")
|
||||||
|
var base := Random.generate_random_plant_name()
|
||||||
|
print("Base: ", base)
|
||||||
|
for i in range(n_mutations):
|
||||||
|
base = Random.small_mutate_plant_name(base)
|
||||||
|
print(i, ": ", base)
|
||||||
|
|
||||||
|
func print_random_big_mutated_name(n_mutations: int = 5) -> void:
|
||||||
|
print("---------")
|
||||||
|
var base := Random.generate_random_plant_name()
|
||||||
|
print("Base: ", base)
|
||||||
|
for i in range(n_mutations):
|
||||||
|
base = Random.big_mutate_plant_name(base)
|
||||||
|
print(i + 1, ": ", base)
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[gd_scene format=3 uid="uid://bpj8mrx3lq6fu"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://dewkwp1gmlxbf" path="res://common/tools/scripts/test_names.gd" id="1_eh0cj"]
|
||||||
|
|
||||||
|
[node name="TestNames" type="Node2D" unique_id=680026966]
|
||||||
|
script = ExtResource("1_eh0cj")
|
||||||
@@ -21,7 +21,7 @@ var region_data : RegionData
|
|||||||
|
|
||||||
func _init(
|
func _init(
|
||||||
_position: Vector2 = Vector2.ZERO,
|
_position: Vector2 = Vector2.ZERO,
|
||||||
_plant_name: String = Random.generate_random_word(),
|
_plant_name: String = Random.generate_random_plant_name(),
|
||||||
_mutations: Array[PlantMutation] = [],
|
_mutations: Array[PlantMutation] = [],
|
||||||
_day: int = 0,
|
_day: int = 0,
|
||||||
_random_seed = randi()
|
_random_seed = randi()
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func _init(
|
|||||||
random_seed = randi()
|
random_seed = randi()
|
||||||
|
|
||||||
static func generate_from_parent(plant_data : PlantData, nearby_plants : Array[PlantData] = []) -> Seed:
|
static func generate_from_parent(plant_data : PlantData, nearby_plants : Array[PlantData] = []) -> Seed:
|
||||||
var mutations : Array[PlantMutation] = plant_data.mutations
|
var mutations : Array[PlantMutation] = plant_data.mutations.duplicate_deep()
|
||||||
var mutation_probability = (
|
var mutation_probability = (
|
||||||
GameInfo.game_data.current_run.plant_info.get_mutation_probability()
|
GameInfo.game_data.current_run.plant_info.get_mutation_probability()
|
||||||
+ plant_data.get_mutation_probability_boost()
|
+ plant_data.get_mutation_probability_boost()
|
||||||
@@ -28,9 +28,15 @@ static func generate_from_parent(plant_data : PlantData, nearby_plants : Array[P
|
|||||||
for pd in nearby_plants:
|
for pd in nearby_plants:
|
||||||
nearby_mutations.append_array(pd.mutations)
|
nearby_mutations.append_array(pd.mutations)
|
||||||
|
|
||||||
|
var child_name := plant_data.plant_name
|
||||||
|
|
||||||
# Mutate for every time mutation probability exceed 1
|
# Mutate for every time mutation probability exceed 1
|
||||||
while mutation_probability > 1:
|
while mutation_probability > 1:
|
||||||
mutations = mutate_mutations(plant_data.mutations, nearby_mutations)
|
mutations = mutate_mutations(plant_data.mutations, nearby_mutations)
|
||||||
|
if len(mutations) != len(plant_data.mutations):
|
||||||
|
child_name = Random.big_mutate_plant_name(child_name)
|
||||||
|
else:
|
||||||
|
child_name = Random.small_mutate_plant_name(child_name)
|
||||||
mutation_probability -= 1
|
mutation_probability -= 1
|
||||||
|
|
||||||
mutations.sort_custom(
|
mutations.sort_custom(
|
||||||
@@ -41,19 +47,19 @@ static func generate_from_parent(plant_data : PlantData, nearby_plants : Array[P
|
|||||||
plant_data.get_state() == PlantData.State.MATURE
|
plant_data.get_state() == PlantData.State.MATURE
|
||||||
and randf() < GameInfo.game_data.current_run.plant_info.get_mutation_probability()
|
and randf() < GameInfo.game_data.current_run.plant_info.get_mutation_probability()
|
||||||
):
|
):
|
||||||
return Seed.new(
|
mutations = mutate_mutations(mutations, nearby_mutations)
|
||||||
plant_data.plant_name,
|
if len(mutations) != len(plant_data.mutations):
|
||||||
mutate_mutations(mutations, nearby_mutations)
|
child_name = Random.big_mutate_plant_name(child_name)
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
return Seed.new(
|
child_name = Random.small_mutate_plant_name(child_name)
|
||||||
plant_data.plant_name,
|
|
||||||
plant_data.mutations.duplicate_deep()
|
return Seed.new(child_name, mutations)
|
||||||
)
|
else:
|
||||||
|
return Seed.new(child_name, mutations)
|
||||||
|
|
||||||
static func generate_random(rarity := 0) -> Seed:
|
static func generate_random(rarity := 0) -> Seed:
|
||||||
var new_seed = Seed.new(
|
var new_seed = Seed.new(
|
||||||
Random.generate_random_word(),
|
Random.generate_random_plant_name(),
|
||||||
generate_first_mutations(rarity),
|
generate_first_mutations(rarity),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user