NPCs: Add random female and male names.

Spawner: Start adding metadata to spawner, places to NPCs. (WIP)
This commit is contained in:
Zorman2000 2017-03-27 14:47:31 -04:00
parent b5ef1f8ed8
commit d375762d11
3 changed files with 83 additions and 11 deletions

17
npc.lua
View File

@ -61,6 +61,11 @@ end
-- defined. On a later phase, pre-defining many of the NPC values
-- will be allowed.
local function get_random_name(sex)
local i = math.random(#npc.data.FIRST_NAMES[sex])
return npc.data.FIRST_NAMES[sex][i]
end
local function initialize_inventory()
return {
[1] = "", [2] = "", [3] = "", [4] = "",
@ -136,12 +141,6 @@ function npc.initialize(entity, pos, is_lua_entity)
-- Avoid NPC to be removed by mobs_redo API
ent.remove_ok = false
-- Set name
ent.nametag = "Kio"
-- Set ID
ent.npc_id = tostring(math.random(1000, 9999))..":"..ent.nametag
-- Determine sex based on textures
if (is_female_texture(ent.base_texture)) then
@ -149,6 +148,12 @@ function npc.initialize(entity, pos, is_lua_entity)
else
ent.sex = npc.MALE
end
-- Set name
ent.nametag = get_random_name(ent.sex)
-- Set ID
ent.npc_id = tostring(math.random(1000, 9999))..":"..ent.nametag
-- Initialize all gift data
ent.gift_data = {

View File

@ -322,6 +322,29 @@ npc.data.DIALOGUES.male["phase6"] = {
},
}
-- Names
npc.data.FIRST_NAMES = {
female = {
"Kimy",
"Lili",
"Cora",
"Caroline",
"Gloria",
"Mary",
"Mayra",
"Arlene"
},
male = {
"Jote",
"Luis",
"Charles",
"Joseph",
"Gerald",
"Kiko",
"Michael"
}
}
-- Items
-- Favorite items, disliked items lists
npc.FAVORITE_ITEMS = {

View File

@ -56,10 +56,31 @@ npc.spawner.replace_activated = true
npc.spawner.replacement_interval = 60
npc.spawner.spawn_delay = 10
npc.spawner.spawn_data = {
status = {
"dead" = 0,
"alive" = 1
}
}
---------------------------------------------------------------------------------------
-- Scanning functions
---------------------------------------------------------------------------------------
-- Creates an array of {pos=<node_pos>, owner=''} for managing
-- which NPC owns what
function spawner.get_nodes_by_type(start_pos, end_pos, type)
local result = {}
local nodes = npc.places.find_node_in_area(start_pos, end_pos, type)
for _,node_pos in pairs(nodes) do
local entry = {}
entry["node_pos"] = node_pos
entry["owner"] = ''
table.insert(result, entry)
end
return result
end
-- Scans an area for the supported nodes: beds, benches,
-- furnaces, storage (e.g. chests) and openable (e.g. doors).
-- Returns a table with these classifications
@ -75,16 +96,23 @@ function spawner.scan_area(start_pos, end_pos)
openable_type = {}
}
result.bed_type = npc.places.find_node_in_area(start_pos, end_pos, npc.places.nodes.BED_TYPE)
result.sittable_type = npc.places.find_node_in_area(start_pos, end_pos, npc.places.nodes.SITTABLE_TYPE)
result.furnace_type = npc.places.find_node_in_area(start_pos, end_pos, npc.places.nodes.FURNACE_TYPE)
result.storage_type = npc.places.find_node_in_area(start_pos, end_pos, npc.places.nodes.STORAGE_TYPE)
result.openable_type = npc.places.find_node_in_area(start_pos, end_pos, npc.places.nodes.OPENABLE_TYPE)
result.bed_type = spawner.get_nodes_by_type(start_pos, end_pos, npc.places.nodes.BED_TYPE)
result.sittable_type = spawner.get_nodes_by_type(start_pos, end_pos, npc.places.nodes.SITTABLE_TYPE)
result.furnace_type = spawner.get_nodes_by_type(start_pos, end_pos, npc.places.nodes.FURNACE_TYPE)
result.storage_type = spawner.get_nodes_by_type(start_pos, end_pos, npc.places.nodes.STORAGE_TYPE)
result.openable_type = spawner.get_nodes_by_type(start_pos, end_pos, npc.places.nodes.OPENABLE_TYPE)
--minetest.log("Found nodes inside area: "..dump(result))
return result
end
-- This function will assign places to every NPC that belongs to a specific
-- house/building. It will use the resources of the house and give them
-- until there's no more. Call this function after NPCs are initialized
function spawner.assign_places(pos, self)
end
-- This function is called when the node timer for spawning NPC
-- is expired
function npc.spawner.spawn_npc(pos)
@ -107,6 +135,19 @@ function npc.spawner.spawn_npc(pos)
spawned_npc_count = spawned_npc_count + 1
-- Store count into node
meta:set_int("spawned_npc_count", spawned_npc_count)
-- Store spawned NPC data into node
local npc_table = minetest.deserialize(meta:get_string("npcs"))
-- TODO: Add more information here at some time...
local entry = {
status = npc.spawner.spawn_data.status.alive,
name = ent:get_luaentity().nametag,
id = ent:get_luaentity().npc_id,
born_day = minetest.get_day_count()
}
table.insert(npc_table, entry)
-- Store into metadata
meta:set_string("npcs", minetest.serialize(npc_table))
-- Temp
meta:set_string("infotext", meta:get_string("infotext")..", "..spawned_npc_count)
minetest.log("[advanced_npc] Spawning successful!")
-- Check if there are more NPCs to spawn
@ -220,6 +261,9 @@ function spawner.replace_mg_villages_plotmarker(pos)
local nodedata = spawner.scan_mg_villages_building(pos, building_data)
-- Store nodedata into the spawner's metadata
meta:set_string("node_data", minetest.serialize(nodedata))
-- Initialize NPCs
local npcs = {}
meta:set_string("npcs", minetest.serialize(npcs))
-- Stop searching for building type
break