Spawner: Nearby plotmarkers are now scanned for all mg_villages:plotmarkers.
Places: Usable nodes now include workplaces Small bug fixes. Relationships: Small bugfix with gift item response. Occupations: Add work node descriptions. Experimental "priest" occupation.
This commit is contained in:
parent
0ddb30c0f9
commit
59bb430e62
@ -268,7 +268,57 @@ if minetest.get_modpath("mg_villages") ~= nil then
|
||||
result.building_type = result.building_data.typ
|
||||
end
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
-- Pre-requisite: only run this function on mg_villages:plotmarker that has been adapted
|
||||
-- by using spawner.adapt_mg_villages_plotmarker
|
||||
function npc.places.get_all_workplaces_from_plotmarker(pos)
|
||||
local result = {}
|
||||
local meta = minetest.get_meta(pos)
|
||||
local pos_data = minetest.deserialize(meta:get_string("building_pos_data"))
|
||||
if pos_data then
|
||||
local workplaces = pos_data.workplaces
|
||||
if workplaces then
|
||||
-- Insert all workplaces in this plotmarker
|
||||
for i = 1, #workplaces do
|
||||
table.insert(result,
|
||||
{
|
||||
workplace=workplaces[i],
|
||||
building_type=meta:get_string("building_type"),
|
||||
surrounding_workplace = false,
|
||||
node_pos= {
|
||||
x=workplaces[i].x,
|
||||
y=workplaces[i].y,
|
||||
z=workplaces[i].z
|
||||
}
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Check the other plotmarkers as well
|
||||
local nearby_plotmarkers = minetest.deserialize(meta:get_string("nearby_plotmarkers"))
|
||||
if nearby_plotmarkers then
|
||||
for i = 1, #nearby_plotmarkers do
|
||||
if nearby_plotmarkers[i].workplaces then
|
||||
-- Insert all workplaces in this plotmarker
|
||||
for j = 1, #nearby_plotmarkers[i].workplaces do
|
||||
minetest.log("Nearby plotmarker workplace #"..dump(j)..": "..dump(nearby_plotmarkers[i].workplaces[j]))
|
||||
table.insert(result, {
|
||||
workplace=nearby_plotmarkers[i].workplaces[j],
|
||||
building_type = nearby_plotmarkers[i].building_type,
|
||||
surrounding_workplace = true,
|
||||
node_pos = {
|
||||
x=nearby_plotmarkers[i].workplaces[j].x,
|
||||
y=nearby_plotmarkers[i].workplaces[j].y,
|
||||
z=nearby_plotmarkers[i].workplaces[j].z
|
||||
}
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
-- This function will search for nodes of type plotmarker and,
|
||||
@ -303,8 +353,11 @@ function npc.places.find_plotmarkers(pos, radius, exclude_current_pos)
|
||||
def["building_type"] = data.building_type
|
||||
if data.building_pos_data then
|
||||
def["building_pos_data"] = data.building_pos_data
|
||||
def["workplaces"] = data.building_pos_data.workplaces
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Add building
|
||||
minetest.log("Adding building: "..dump(def))
|
||||
table.insert(result, def)
|
||||
end
|
||||
end
|
||||
@ -320,7 +373,8 @@ function npc.places.scan_area_for_usable_nodes(pos1, pos2)
|
||||
sittable_type = {},
|
||||
furnace_type = {},
|
||||
storage_type = {},
|
||||
openable_type = {}
|
||||
openable_type = {},
|
||||
workplace_type = {}
|
||||
}
|
||||
local start_pos, end_pos = vector.sort(pos1, pos2)
|
||||
|
||||
@ -330,6 +384,18 @@ function npc.places.scan_area_for_usable_nodes(pos1, pos2)
|
||||
result.storage_type = npc.places.get_nodes_by_type(start_pos, end_pos, npc.places.nodes.STORAGE_TYPE)
|
||||
result.openable_type = npc.places.get_nodes_by_type(start_pos, end_pos, npc.places.nodes.OPENABLE_TYPE)
|
||||
|
||||
-- Find workplace nodes: if mg_villages:plotmarker is given a start pos, take it from there.
|
||||
-- If not, search for them.
|
||||
local node = minetest.get_node(pos1)
|
||||
if node.name == "mg_villages:plotmarker" then
|
||||
if npc.places.get_all_workplaces_from_plotmarker then
|
||||
result.workplace_type = npc.places.get_all_workplaces_from_plotmarker(pos1)
|
||||
end
|
||||
else
|
||||
-- Just search for workplace nodes
|
||||
result.workplace_type = npc.places.get_nodes_by_type(start_pos, end_pos, npc.places.nodes.WORKPLACE_TYPE)
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
|
@ -3,6 +3,29 @@
|
||||
-- Register default occupation
|
||||
npc.occupations.register_occupation("default_basic", npc.occupations.basic_def)
|
||||
|
||||
-- Test priest
|
||||
npc.occupations.register_occupation("test_priest", {
|
||||
dialogues = {
|
||||
{
|
||||
text = "How are you today my child?",
|
||||
tags = "male"
|
||||
}
|
||||
},
|
||||
textures = {
|
||||
"npc_male_priest.png"
|
||||
},
|
||||
initial_inventory = {
|
||||
"farming:bread 1"
|
||||
},
|
||||
building_types = {
|
||||
"home"
|
||||
},
|
||||
surrounding_building_types = {
|
||||
"church"
|
||||
},
|
||||
schedule_entries = {}
|
||||
})
|
||||
|
||||
-- Test farmer
|
||||
npc.occupations.register_occupation("test_farmer", {
|
||||
dialogues = {},
|
||||
|
@ -58,6 +58,10 @@
|
||||
-- -- spawns on house, then it has to be because there is a field
|
||||
-- -- nearby. If left empty or nil, surrounding buildings doesn't
|
||||
-- -- matter
|
||||
-- workplace_nodes = {},
|
||||
-- -- An array of string where each string is a node the NPC
|
||||
-- -- works with. These are useful for assigning workplaces and work
|
||||
-- -- work nodes.
|
||||
-- initial_inventory = {},
|
||||
-- -- An array of entries like the following:
|
||||
-- -- {name="", count=1} -- or
|
||||
|
@ -482,7 +482,7 @@ local function show_receive_gift_reaction(self, item_name, modifier, clicker_nam
|
||||
npc.relationships.GIFT_ITEM_LIKED,
|
||||
self.sex,
|
||||
phase)
|
||||
npc.chat(self.npc_name, clicker_name, message_to_send)
|
||||
npc.chat(self.npc_name, clicker_name, message_to_send.responses[1])
|
||||
-- Disliked items reactions
|
||||
elseif modifier < 0 then
|
||||
effect({x = pos.x, y = pos.y + 1, z = pos.z}, 8, "default_item_smoke.png")
|
||||
@ -492,7 +492,7 @@ local function show_receive_gift_reaction(self, item_name, modifier, clicker_nam
|
||||
npc.relationships.GIFT_ITEM_RESPONSE,
|
||||
npc.relationships.GIFT_ITEM_DISLIKED,
|
||||
self.sex)
|
||||
npc.chat(self.npc_name, clicker_name, message_to_send)
|
||||
npc.chat(self.npc_name, clicker_name, message_to_send.responses[1])
|
||||
end
|
||||
|
||||
end
|
||||
|
27
spawner.lua
27
spawner.lua
@ -204,18 +204,21 @@ function npc.spawner.spawn_npc_on_plotmarker(pos)
|
||||
area_info["npc_count"] = meta:get_int("npc_count")
|
||||
area_info["spawned_npc_count"] = meta:get_int("spawned_npc_count")
|
||||
|
||||
-- TODO: Get occupation name
|
||||
area_info["building_type"] = minetest.deserialize(meta:get_string("building_type"))
|
||||
local nearby_plotmarkers = minetest.deserialize(meta:get_string("nearby_plotmarkers"))
|
||||
|
||||
|
||||
local metadata = npc.spawner.spawn_npc(pos, area_info)
|
||||
|
||||
-- Set all metadata back into the node
|
||||
-- Increase NPC spawned count
|
||||
area_info.spawned_npc_count = area_info.spawned_npc_count + 1
|
||||
area_info.spawned_npc_count = metadata.spawned_npc_count + 1
|
||||
-- Store count into node
|
||||
meta:set_int("spawned_npc_count", area_info.spawned_npc_count)
|
||||
-- Store spawned NPC info
|
||||
meta:set_string("npcs", minetest.serialize(area_info.npcs))
|
||||
meta:set_string("npcs", minetest.serialize(metadata.npcs))
|
||||
-- Store NPC stats
|
||||
meta:set_string("npc_stats", minetest.serialize(area_info.npc_stats))
|
||||
meta:set_string("npc_stats", minetest.serialize(metadata.npc_stats))
|
||||
|
||||
-- Check if there are more NPCs to spawn
|
||||
if area_info.spawned_npc_count >= area_info.npc_count then
|
||||
@ -304,7 +307,7 @@ function npc.spawner.spawn_npc(pos, area_info, occupation_name)
|
||||
area_info.npc_stats = npc_stats
|
||||
-- Return
|
||||
npc.log("INFO", "Spawning successful!")
|
||||
return true
|
||||
return area_info
|
||||
else
|
||||
npc.log("ERROR", "Spawning failed!")
|
||||
ent:remove()
|
||||
@ -400,11 +403,18 @@ function npc.spawner.assign_places(self, entrance, node_data, pos)
|
||||
--meta:set_string("node_data", minetest.serialize(node_data))
|
||||
end
|
||||
-- Add all storage-types to places as shared since NPC should be able
|
||||
-- to use other storage nodes as well.
|
||||
-- to use other storaage nodes as well.
|
||||
npc.places.add_shared_accessible_place(self, node_data.storage_type,
|
||||
npc.places.PLACE_TYPE.STORAGE.SHARED)
|
||||
end
|
||||
|
||||
-- Assign workplace nodes
|
||||
if #node_data.workplace_type > 0 then
|
||||
local occupation = npc.occupations.registered_occupations[self.occupation_name]
|
||||
|
||||
|
||||
end
|
||||
|
||||
npc.log("DEBUG", "Places for NPC "..self.npc_name..": "..dump(self.places_map))
|
||||
|
||||
-- Make NPC go into their house
|
||||
@ -564,7 +574,8 @@ if minetest.get_modpath("mg_villages") ~= nil then
|
||||
local all_data = npc.places.get_mg_villages_building_data(pos)
|
||||
local building_data = all_data.building_data
|
||||
local building_type = all_data.building_type
|
||||
local building_pos_data = all_data.building_pos_data
|
||||
local building_pos_data = all_data.building_pos_dataS
|
||||
|
||||
--minetest.log("Found building data: "..dump(building_data))
|
||||
|
||||
-- Check if the building is of the support types
|
||||
@ -601,7 +612,7 @@ if minetest.get_modpath("mg_villages") ~= nil then
|
||||
-- Store nodedata into the spawner's metadata
|
||||
meta:set_string("node_data", minetest.serialize(nodedata))
|
||||
-- Find nearby plotmarkers, excluding current plotmarker
|
||||
local nearby_plotmarkers = npc.places.find_plotmarkers(pos, 20, true)
|
||||
local nearby_plotmarkers = npc.places.find_plotmarkers(pos, 40, true)
|
||||
minetest.log("Found nearby plotmarkers: "..dump(nearby_plotmarkers))
|
||||
meta:set_string("nearby_plotmarkers", minetest.serialize(nearby_plotmarkers))
|
||||
-- Check if building position data is also available (recent mg_villages)
|
||||
|
Loading…
Reference in New Issue
Block a user