Skip to content
Snippets Groups Projects
Commit 9561f35b authored by dg's avatar dg
Browse files

randname

git-svn-id: http://svn.net-core.org/repos/t-engine4@4275 51575b47-30f0-44d4-a5cc-537603b46e54
parent 5ca64f6b
No related branches found
No related tags found
No related merge requests found
...@@ -80,9 +80,10 @@ function _M:generate(no_repeat, min_syl, max_syl) ...@@ -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. -- and have no possible continuations; or if the word is in the forbidden list.
local word = {} local word = {}
local word_str = '' local word_str = ''
local used = {}
while #word < self.min_syl or self.forbidden[word_str] do while #word < self.min_syl or self.forbidden[word_str] do
-- start word with the first syllable -- 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]} word = {self.syllables[syl]}
local done_end = false local done_end = false
...@@ -94,7 +95,7 @@ function _M:generate(no_repeat, min_syl, max_syl) ...@@ -94,7 +95,7 @@ function _M:generate(no_repeat, min_syl, max_syl)
end end
-- select next syllable -- 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 if not syl then done_end = true break end -- early end for this word, end syllable was chosen
word[#word+1] = self.syllables[syl] word[#word+1] = self.syllables[syl]
...@@ -102,7 +103,7 @@ function _M:generate(no_repeat, min_syl, max_syl) ...@@ -102,7 +103,7 @@ function _M:generate(no_repeat, min_syl, max_syl)
if not done_end then if not done_end then
-- forcefully add an ending syllable if the loop ended without one -- 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] word[#word+1] = self.syllables[syl]
end end
...@@ -115,7 +116,7 @@ function _M:generate(no_repeat, min_syl, max_syl) ...@@ -115,7 +116,7 @@ function _M:generate(no_repeat, min_syl, max_syl)
return word_str:capitalize() return word_str:capitalize()
end end
function _M:selectSyllable(counts, end_count) function _M:selectSyllable(counts, end_count, used)
if not counts or #counts == 0 then return end if not counts or #counts == 0 then return end
-- "counts" holds cumulative counts, so take the last element in the list -- "counts" holds cumulative counts, so take the last element in the list
...@@ -124,6 +125,8 @@ function _M:selectSyllable(counts, end_count) ...@@ -124,6 +125,8 @@ function _M:selectSyllable(counts, end_count)
for _, d in ipairs(counts) do for _, d in ipairs(counts) do
if d.c >= chosen then 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 return d.s
end end
end end
......
...@@ -21,7 +21,8 @@ require "engine.class" ...@@ -21,7 +21,8 @@ require "engine.class"
require "engine.Entity" require "engine.Entity"
local Particles = require "engine.Particles" local Particles = require "engine.Particles"
local Map = require "engine.Map" 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" local Donation = require "mod.dialogs.Donation"
module(..., package.seeall, class.inherit(engine.Entity)) module(..., package.seeall, class.inherit(engine.Entity))
...@@ -1307,7 +1308,12 @@ function _M:createRandomBoss(base, data) ...@@ -1307,7 +1308,12 @@ function _M:createRandomBoss(base, data)
------------------------------------------------------------ ------------------------------------------------------------
-- Basic stuff, name, rank, ... -- 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() local name = ngd:generate()
b.name = name.." the "..b.name b.name = name.." the "..b.name
b.unique = b.name b.unique = b.name
......
...@@ -47,6 +47,7 @@ newEntity{ base = "BASE_NPC_HUMANOID_RANDOM_BOSS", ...@@ -47,6 +47,7 @@ newEntity{ base = "BASE_NPC_HUMANOID_RANDOM_BOSS",
e.moddable_tile = "human_#sex#" e.moddable_tile = "human_#sex#"
e.moddable_tile_base = "base_cornac_01.png" e.moddable_tile_base = "base_cornac_01.png"
end), end),
random_name_def = "cornac_#sex#",
humanoid_random_boss = 1, humanoid_random_boss = 1,
resolvers.racial(), resolvers.racial(),
} }
...@@ -64,6 +65,7 @@ newEntity{ base = "BASE_NPC_HUMANOID_RANDOM_BOSS", ...@@ -64,6 +65,7 @@ newEntity{ base = "BASE_NPC_HUMANOID_RANDOM_BOSS",
e.moddable_tile_base = "base_thalore_01.png" e.moddable_tile_base = "base_thalore_01.png"
e.moddable_tile_ornament = {female="braid_01"} e.moddable_tile_ornament = {female="braid_01"}
end), end),
random_name_def = "thalore_#sex#",
humanoid_random_boss = 1, humanoid_random_boss = 1,
resolvers.racial(), resolvers.racial(),
} }
...@@ -81,6 +83,7 @@ newEntity{ base = "BASE_NPC_HUMANOID_RANDOM_BOSS", ...@@ -81,6 +83,7 @@ newEntity{ base = "BASE_NPC_HUMANOID_RANDOM_BOSS",
e.moddable_tile_base = "base_shalore_01.png" e.moddable_tile_base = "base_shalore_01.png"
e.moddable_tile_ornament = {female="braid_02"} e.moddable_tile_ornament = {female="braid_02"}
end), end),
random_name_def = "shalore_#sex#",
humanoid_random_boss = 1, humanoid_random_boss = 1,
resolvers.racial(), resolvers.racial(),
} }
...@@ -96,6 +99,7 @@ newEntity{ base = "BASE_NPC_HUMANOID_RANDOM_BOSS", ...@@ -96,6 +99,7 @@ newEntity{ base = "BASE_NPC_HUMANOID_RANDOM_BOSS",
end end
e.moddable_tile = "halfling_#sex#" e.moddable_tile = "halfling_#sex#"
end), end),
random_name_def = "halfling_#sex#",
humanoid_random_boss = 1, humanoid_random_boss = 1,
resolvers.racial(), resolvers.racial(),
} }
...@@ -111,6 +115,7 @@ newEntity{ base = "BASE_NPC_HUMANOID_RANDOM_BOSS", ...@@ -111,6 +115,7 @@ newEntity{ base = "BASE_NPC_HUMANOID_RANDOM_BOSS",
end end
e.moddable_tile = "dwarf_#sex#" e.moddable_tile = "dwarf_#sex#"
end), end),
random_name_def = "dwarf_#sex#",
humanoid_random_boss = 2, humanoid_random_boss = 2,
resolvers.racial(), resolvers.racial(),
} }
...@@ -41,6 +41,7 @@ newEntity{ ...@@ -41,6 +41,7 @@ newEntity{
size_category = 3, size_category = 3,
no_breath = 1, no_breath = 1,
demon = 1, demon = 1,
random_name_def = "demon",
resolvers.inscriptions(1, "rune"), resolvers.inscriptions(1, "rune"),
on_die = function(self, who) on_die = function(self, who)
......
...@@ -41,6 +41,7 @@ newEntity{ ...@@ -41,6 +41,7 @@ newEntity{
size_category = 3, size_category = 3,
no_breath = 1, no_breath = 1,
demon = 1, demon = 1,
random_name_def = "demon",
} }
newEntity{ base = "BASE_NPC_DEMON", newEntity{ base = "BASE_NPC_DEMON",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment