109 lines
4.2 KiB
GDScript
109 lines
4.2 KiB
GDScript
extends Node
|
|
## NameGenerator - Generates unique names for guest players and bots.
|
|
## Guest names: Capitalized adjective+noun combos (e.g. "SwiftFox")
|
|
## Bot names: Simple first names only, no numbers (e.g. "Jack")
|
|
|
|
# -----------------------------------------------------------------------
|
|
# Guest name pools — adjective + noun combos
|
|
# -----------------------------------------------------------------------
|
|
const ADJECTIVES: Array[String] = [
|
|
"Swift", "Silent", "Bold", "Iron", "Dark", "Wild", "Frost", "Storm",
|
|
"Keen", "Jade", "Blaze", "Rift", "Neon", "Onyx", "Azure", "Grim",
|
|
"Sage", "Nova", "Apex", "Luna", "Solar", "Lunar", "Tech", "Vero",
|
|
"Echo", "Zeal", "Volt", "Brisk", "Dusk", "Dawn", "Sable", "Civic",
|
|
"Pixel", "Brave", "Sharp", "Amber", "Vivid", "Rapid", "Sleek", "Null",
|
|
"Prime", "Zero", "Hyper", "Turbo", "Sigma", "Omega", "Alpha", "Delta",
|
|
"Hex", "Red", "Blue", "Gold", "Aqua", "Teal", "Lime", "Ruby"
|
|
]
|
|
|
|
const NOUNS: Array[String] = [
|
|
"Fox", "Wolf", "Hawk", "Bear", "Lynx", "Crow", "Dirk", "Rook",
|
|
"Fang", "Bolt", "Node", "Byte", "Flux", "Spark", "Drift", "Tide",
|
|
"Claw", "Wing", "Shade", "Arrow", "Spike", "Globe", "Beam", "Core",
|
|
"Path", "Edge", "Root", "Link", "Code", "Beam", "Grid", "Chip",
|
|
"Dust", "Blade", "Stone", "Coin", "Rock", "Peak", "Wick", "Ray",
|
|
"Kite", "Mist", "Gale", "Reef", "Veil", "Gate", "Ash", "Dune"
|
|
]
|
|
|
|
# -----------------------------------------------------------------------
|
|
# Bot name pools — simple first names, lowercase-first style (Title Case)
|
|
# No numbers. These are distinct from guest names.
|
|
# -----------------------------------------------------------------------
|
|
const BOT_NAMES: Array[String] = [
|
|
"Jack", "Max", "Sam", "Alex", "Leo", "Mia", "Zoe", "Kai",
|
|
"Ray", "Jay", "Kim", "Rex", "Ace", "Finn", "Ada", "Eli",
|
|
"Nia", "Ben", "Tao", "Vex", "Rue", "Dax", "Ora", "Pip",
|
|
"Cal", "Bex", "Jax", "Ren", "Ash", "Sky", "Nova", "Cruz",
|
|
"Remi", "Theo", "Cora", "Axel", "Nora", "Ivan", "Luna", "Dani",
|
|
"Luca", "Roxy", "Seth", "Tara", "Kale", "Vera", "Omar", "Jade"
|
|
]
|
|
|
|
# Track in-use names to prevent duplicates per session
|
|
var _used_guest_names: Array[String] = []
|
|
var _used_bot_names: Array[String] = []
|
|
|
|
func _ready() -> void:
|
|
randomize()
|
|
|
|
# -----------------------------------------------------------------------
|
|
# Guest name generation
|
|
# -----------------------------------------------------------------------
|
|
|
|
func generate_guest_name() -> String:
|
|
"""Generate a unique guest name like 'SwiftFox'. Falls back if pool exhausted."""
|
|
var attempts := 0
|
|
var max_attempts := 100
|
|
|
|
while attempts < max_attempts:
|
|
var adj := ADJECTIVES[randi() % ADJECTIVES.size()]
|
|
var noun := NOUNS[randi() % NOUNS.size()]
|
|
var name_candidate := adj + noun
|
|
|
|
if name_candidate not in _used_guest_names:
|
|
_used_guest_names.append(name_candidate)
|
|
return name_candidate
|
|
attempts += 1
|
|
|
|
# Fallback: numbered guest if pool exhausted
|
|
var fallback := "Guest%d" % (_used_guest_names.size() + 1)
|
|
_used_guest_names.append(fallback)
|
|
return fallback
|
|
|
|
func release_guest_name(name: String) -> void:
|
|
"""Call when a guest disconnects to free up their name for reuse."""
|
|
_used_guest_names.erase(name)
|
|
|
|
# -----------------------------------------------------------------------
|
|
# Bot name generation
|
|
# -----------------------------------------------------------------------
|
|
|
|
func generate_bot_name() -> String:
|
|
"""Generate a unique bot name like 'Jack'. Falls back with suffix if pool exhausted."""
|
|
# Build shuffled list of bot names not yet in use
|
|
var available: Array[String] = []
|
|
for n in BOT_NAMES:
|
|
if n not in _used_bot_names:
|
|
available.append(n)
|
|
|
|
if available.size() > 0:
|
|
available.shuffle()
|
|
var chosen := available[0]
|
|
_used_bot_names.append(chosen)
|
|
return chosen
|
|
|
|
# Pool exhausted — pick a random base name with a letter suffix
|
|
var base := BOT_NAMES[randi() % BOT_NAMES.size()]
|
|
var suffix_chars := "abcdefghijklmnopqrstuvwxyz"
|
|
var candidate := base + suffix_chars[randi() % suffix_chars.length()]
|
|
_used_bot_names.append(candidate)
|
|
return candidate
|
|
|
|
func release_bot_name(name: String) -> void:
|
|
"""Call when a bot slot is removed to free up its name."""
|
|
_used_bot_names.erase(name)
|
|
|
|
func reset_all() -> void:
|
|
"""Reset both pools — useful on returning to main menu."""
|
|
_used_guest_names.clear()
|
|
_used_bot_names.clear()
|