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
|
||||
|
||||
const MIN_WORD_LEN = 4
|
||||
const MAX_WORD_LEN = 8
|
||||
const MIN_WORD_LEN = 3
|
||||
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 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)
|
||||
):
|
||||
@@ -18,7 +21,7 @@ static func generate_random_word(_random_seed = randi()) -> String:
|
||||
|
||||
var word_len = randf_range(4,8)
|
||||
var word = ''
|
||||
var last_letter_is_vowel = false
|
||||
var last_letter_is_vowel = randi() % 2
|
||||
|
||||
for i in range(word_len):
|
||||
if last_letter_is_vowel:
|
||||
@@ -29,7 +32,21 @@ static func generate_random_word(_random_seed = randi()) -> String:
|
||||
last_letter_is_vowel = not last_letter_is_vowel
|
||||
return word.capitalize()
|
||||
|
||||
static func mutate_word(word : String) -> String:
|
||||
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:
|
||||
@@ -39,31 +56,70 @@ static func mutate_word(word : String) -> String:
|
||||
|
||||
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
|
||||
|
||||
static func shorten_word(word : String):
|
||||
if randi()%2 == 0:
|
||||
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 :
|
||||
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).capitalize()
|
||||
else :
|
||||
var letter = CONSONANTS.pick_random() if word.right(1) in VOWEL else VOWEL.pick_random()
|
||||
return (word + letter).capitalize()
|
||||
|
||||
static func replace_character(word : String):
|
||||
var character_id = randi_range(0, len(word))
|
||||
var character = word[character_id]
|
||||
|
||||
if character in VOWEL:
|
||||
character = VOWEL.pick_random()
|
||||
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:
|
||||
character = CONSONANTS.pick_random()
|
||||
var letter = CONSONANTS.pick_random() if word.right(1) in VOWEL else VOWEL.pick_random()
|
||||
return (word + letter).to_lower().capitalize()
|
||||
|
||||
word[character_id] = character
|
||||
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 ------------------
|
||||
|
||||
@@ -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(
|
||||
_position: Vector2 = Vector2.ZERO,
|
||||
_plant_name: String = Random.generate_random_word(),
|
||||
_plant_name: String = Random.generate_random_plant_name(),
|
||||
_mutations: Array[PlantMutation] = [],
|
||||
_day: int = 0,
|
||||
_random_seed = randi()
|
||||
|
||||
@@ -18,7 +18,7 @@ func _init(
|
||||
random_seed = randi()
|
||||
|
||||
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 = (
|
||||
GameInfo.game_data.current_run.plant_info.get_mutation_probability()
|
||||
+ 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:
|
||||
nearby_mutations.append_array(pd.mutations)
|
||||
|
||||
var child_name := plant_data.plant_name
|
||||
|
||||
# Mutate for every time mutation probability exceed 1
|
||||
while mutation_probability > 1:
|
||||
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
|
||||
|
||||
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
|
||||
and randf() < GameInfo.game_data.current_run.plant_info.get_mutation_probability()
|
||||
):
|
||||
return Seed.new(
|
||||
plant_data.plant_name,
|
||||
mutate_mutations(mutations, nearby_mutations)
|
||||
)
|
||||
else :
|
||||
return Seed.new(
|
||||
plant_data.plant_name,
|
||||
plant_data.mutations.duplicate_deep()
|
||||
)
|
||||
mutations = mutate_mutations(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)
|
||||
|
||||
return Seed.new(child_name, mutations)
|
||||
else:
|
||||
return Seed.new(child_name, mutations)
|
||||
|
||||
static func generate_random(rarity := 0) -> Seed:
|
||||
var new_seed = Seed.new(
|
||||
Random.generate_random_word(),
|
||||
Random.generate_random_plant_name(),
|
||||
generate_first_mutations(rarity),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user