From 9561f35b4bdba72b2bbf8ae931fb2bf71e4bcbb6 Mon Sep 17 00:00:00 2001 From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54> Date: Sun, 28 Aug 2011 16:55:37 +0000 Subject: [PATCH] randname git-svn-id: http://svn.net-core.org/repos/t-engine4@4275 51575b47-30f0-44d4-a5cc-537603b46e54 --- game/engines/default/engine/NameGenerator2.lua | 11 +++++++---- game/modules/tome/class/GameState.lua | 10 ++++++++-- .../tome/data/general/npcs/humanoid_random_boss.lua | 5 +++++ game/modules/tome/data/general/npcs/major-demon.lua | 1 + game/modules/tome/data/general/npcs/minor-demon.lua | 1 + 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/game/engines/default/engine/NameGenerator2.lua b/game/engines/default/engine/NameGenerator2.lua index af29705b8a..11985192b1 100644 --- a/game/engines/default/engine/NameGenerator2.lua +++ b/game/engines/default/engine/NameGenerator2.lua @@ -80,9 +80,10 @@ function _M:generate(no_repeat, min_syl, max_syl) -- and have no possible continuations; or if the word is in the forbidden list. local word = {} local word_str = '' + local used = {} while #word < self.min_syl or self.forbidden[word_str] do -- start word with the first syllable - local syl = self:selectSyllable(self.starts, 0) + local syl = self:selectSyllable(self.starts, 0, used) word = {self.syllables[syl]} local done_end = false @@ -94,7 +95,7 @@ function _M:generate(no_repeat, min_syl, max_syl) end -- select next syllable - syl = self:selectSyllable(self.combinations[syl], eend) + syl = self:selectSyllable(self.combinations[syl], eend, used) if not syl then done_end = true break end -- early end for this word, end syllable was chosen word[#word+1] = self.syllables[syl] @@ -102,7 +103,7 @@ function _M:generate(no_repeat, min_syl, max_syl) if not done_end then -- forcefully add an ending syllable if the loop ended without one - syl = self:selectSyllable(self.ends, 0) + syl = self:selectSyllable(self.ends, 0, used) word[#word+1] = self.syllables[syl] end @@ -115,7 +116,7 @@ function _M:generate(no_repeat, min_syl, max_syl) return word_str:capitalize() end -function _M:selectSyllable(counts, end_count) +function _M:selectSyllable(counts, end_count, used) if not counts or #counts == 0 then return end -- "counts" holds cumulative counts, so take the last element in the list @@ -124,6 +125,8 @@ function _M:selectSyllable(counts, end_count) for _, d in ipairs(counts) do if d.c >= chosen then + if used[d.s] then return self:selectSyllable(counts, end_count, used) end + used[d.s] = true return d.s end end diff --git a/game/modules/tome/class/GameState.lua b/game/modules/tome/class/GameState.lua index 39a1d10acc..9b15167cab 100644 --- a/game/modules/tome/class/GameState.lua +++ b/game/modules/tome/class/GameState.lua @@ -21,7 +21,8 @@ require "engine.class" require "engine.Entity" local Particles = require "engine.Particles" local Map = require "engine.Map" -local NameGenerator = require("engine.NameGenerator") +local NameGenerator = require "engine.NameGenerator" +local NameGenerator2 = require "engine.NameGenerator2" local Donation = require "mod.dialogs.Donation" module(..., package.seeall, class.inherit(engine.Entity)) @@ -1307,7 +1308,12 @@ function _M:createRandomBoss(base, data) ------------------------------------------------------------ -- Basic stuff, name, rank, ... ------------------------------------------------------------ - local ngd = NameGenerator.new(randart_name_rules.default) + local ngd + if base.random_name_def then + ngd = NameGenerator2.new("/data/languages/names/"..base.random_name_def:gsub("#sex#", base.female and "female" or "male")..".txt") + else + ngd = NameGenerator.new(randart_name_rules.default) + end local name = ngd:generate() b.name = name.." the "..b.name b.unique = b.name diff --git a/game/modules/tome/data/general/npcs/humanoid_random_boss.lua b/game/modules/tome/data/general/npcs/humanoid_random_boss.lua index 30f5b6f614..5069906fbb 100644 --- a/game/modules/tome/data/general/npcs/humanoid_random_boss.lua +++ b/game/modules/tome/data/general/npcs/humanoid_random_boss.lua @@ -47,6 +47,7 @@ newEntity{ base = "BASE_NPC_HUMANOID_RANDOM_BOSS", e.moddable_tile = "human_#sex#" e.moddable_tile_base = "base_cornac_01.png" end), + random_name_def = "cornac_#sex#", humanoid_random_boss = 1, resolvers.racial(), } @@ -64,6 +65,7 @@ newEntity{ base = "BASE_NPC_HUMANOID_RANDOM_BOSS", e.moddable_tile_base = "base_thalore_01.png" e.moddable_tile_ornament = {female="braid_01"} end), + random_name_def = "thalore_#sex#", humanoid_random_boss = 1, resolvers.racial(), } @@ -81,6 +83,7 @@ newEntity{ base = "BASE_NPC_HUMANOID_RANDOM_BOSS", e.moddable_tile_base = "base_shalore_01.png" e.moddable_tile_ornament = {female="braid_02"} end), + random_name_def = "shalore_#sex#", humanoid_random_boss = 1, resolvers.racial(), } @@ -96,6 +99,7 @@ newEntity{ base = "BASE_NPC_HUMANOID_RANDOM_BOSS", end e.moddable_tile = "halfling_#sex#" end), + random_name_def = "halfling_#sex#", humanoid_random_boss = 1, resolvers.racial(), } @@ -111,6 +115,7 @@ newEntity{ base = "BASE_NPC_HUMANOID_RANDOM_BOSS", end e.moddable_tile = "dwarf_#sex#" end), + random_name_def = "dwarf_#sex#", humanoid_random_boss = 2, resolvers.racial(), } diff --git a/game/modules/tome/data/general/npcs/major-demon.lua b/game/modules/tome/data/general/npcs/major-demon.lua index 8762daca5d..2f7f19d7cf 100644 --- a/game/modules/tome/data/general/npcs/major-demon.lua +++ b/game/modules/tome/data/general/npcs/major-demon.lua @@ -41,6 +41,7 @@ newEntity{ size_category = 3, no_breath = 1, demon = 1, + random_name_def = "demon", resolvers.inscriptions(1, "rune"), on_die = function(self, who) diff --git a/game/modules/tome/data/general/npcs/minor-demon.lua b/game/modules/tome/data/general/npcs/minor-demon.lua index 9120dfa25e..bfa6e0c447 100644 --- a/game/modules/tome/data/general/npcs/minor-demon.lua +++ b/game/modules/tome/data/general/npcs/minor-demon.lua @@ -41,6 +41,7 @@ newEntity{ size_category = 3, no_breath = 1, demon = 1, + random_name_def = "demon", } newEntity{ base = "BASE_NPC_DEMON", -- GitLab