Unify the difficulty settings into init.lua
All the scaling factors are now either in the plant table or the crops.settings table. This makes end-user tuning a bit harder, but switching easier and configuring easier as well.
This commit is contained in:
parent
59d53aa5a6
commit
a1be5250b8
20
corn.lua
20
corn.lua
@ -84,8 +84,8 @@ minetest.register_node("crops:corn_base_seed", {
|
||||
minetest.register_abm({
|
||||
nodenames = { "crops:corn_base_seed" },
|
||||
neighbors = { "group:soil" },
|
||||
interval = crops.interval,
|
||||
chance = crops.chance,
|
||||
interval = crops.settings.interval,
|
||||
chance = crops.settings.chance,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
if not crops.can_grow(pos) then
|
||||
return
|
||||
@ -112,8 +112,8 @@ minetest.register_node("crops:corn_base_1", {
|
||||
minetest.register_abm({
|
||||
nodenames = { "crops:corn_base_1" },
|
||||
neighbors = { "group:soil" },
|
||||
interval = crops.interval,
|
||||
chance = crops.chance,
|
||||
interval = crops.settings.interval,
|
||||
chance = crops.settings.chance,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
if not crops.can_grow(pos) then
|
||||
return
|
||||
@ -218,10 +218,10 @@ minetest.register_node("crops:corn_top_1", {
|
||||
minetest.register_abm({
|
||||
nodenames = { "crops:corn_top_1" },
|
||||
neighbors = { "crops:corn_base_2" },
|
||||
interval = crops.interval,
|
||||
chance = crops.chance,
|
||||
interval = crops.settings.interval,
|
||||
chance = crops.settings.chance,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
if minetest.get_node_light(pos, nil) < crops.light then
|
||||
if minetest.get_node_light(pos, nil) < crops.settings.light then
|
||||
return
|
||||
end
|
||||
minetest.swap_node(pos, { name = "crops:corn_top_2" })
|
||||
@ -254,12 +254,12 @@ minetest.register_node("crops:corn_top_2", {
|
||||
minetest.register_abm({
|
||||
nodenames = { "crops:corn_top_2" },
|
||||
neighbors = { "crops:corn_base_2" },
|
||||
interval = crops.interval,
|
||||
chance = crops.chance,
|
||||
interval = crops.settings.interval,
|
||||
chance = crops.settings.chance,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
-- we don't call crops.grow here otherwise there would be 2 abm's hitting
|
||||
-- this stack, and dmg needs to be applied to the bottom part
|
||||
if minetest.get_node_light(pos, nil) < crops.light then
|
||||
if minetest.get_node_light(pos, nil) < crops.settings.light then
|
||||
return
|
||||
end
|
||||
minetest.swap_node(pos, { name = "crops:corn_top_3" })
|
||||
|
56
init.lua
56
init.lua
@ -13,6 +13,27 @@ of the license, or (at your option) any later version.
|
||||
crops = {}
|
||||
crops.plants = {}
|
||||
|
||||
local settings_easy = {
|
||||
chance = 4,
|
||||
interval = 30,
|
||||
light = 8,
|
||||
}
|
||||
local settings_normal = {
|
||||
chance = 8,
|
||||
interval = 30,
|
||||
light = 10,
|
||||
watercan = 25,
|
||||
watercan_max = 90,
|
||||
watercan_uses = 20,
|
||||
max_damage = 50
|
||||
}
|
||||
local settings_hard = {
|
||||
chance = 16,
|
||||
interval = 30,
|
||||
light = 13,
|
||||
}
|
||||
|
||||
|
||||
local worldpath = minetest.get_worldpath()
|
||||
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
||||
|
||||
@ -35,6 +56,21 @@ else
|
||||
dofile(worldpath .. "/crops_settings.txt")
|
||||
end
|
||||
|
||||
if not crops.difficulty then
|
||||
crops.difficulty = "normal"
|
||||
minetest.log("error", "Defaulting to \"normal\" difficulty settings")
|
||||
end
|
||||
if crops.difficulty == "easy" then
|
||||
crops.settings = settings_easy
|
||||
elseif crops.difficulty == "normal" then
|
||||
crops.settings = settings_normal
|
||||
elseif crops.difficulty == "difficult" then
|
||||
crops.settings = settings_difficult
|
||||
else
|
||||
minetest.log("error", "Defaulting to \"normal\" difficulty settings")
|
||||
crops.settings = settings_normal
|
||||
end
|
||||
|
||||
local find_plant = function(node)
|
||||
for i = 1,table.getn(crops.plants) do
|
||||
if crops.plants[i].name == node.name then
|
||||
@ -54,7 +90,7 @@ crops.plant = function(pos, node)
|
||||
end
|
||||
|
||||
crops.can_grow = function(pos)
|
||||
if minetest.get_node_light(pos, nil) < crops.light then
|
||||
if minetest.get_node_light(pos, nil) < crops.settings.light then
|
||||
return false
|
||||
end
|
||||
local node = minetest.get_node(pos)
|
||||
@ -87,8 +123,8 @@ crops.particles = function(pos, flag)
|
||||
if flag == 0 then
|
||||
-- wither (0)
|
||||
p = {
|
||||
amount = 1 * crops.interval,
|
||||
time = crops.interval,
|
||||
amount = 1 * crops.settings.interval,
|
||||
time = crops.settings.interval,
|
||||
minpos = { x = pos.x - 0.4, y = pos.y - 0.4, z = pos.z - 0.4 },
|
||||
maxpos = { x = pos.x + 0.4, y = pos.y + 0.4, z = pos.z + 0.4 },
|
||||
minvel = { x = 0, y = 0.2, z = 0 },
|
||||
@ -106,8 +142,8 @@ crops.particles = function(pos, flag)
|
||||
else
|
||||
-- soak (1)
|
||||
p = {
|
||||
amount = 8 * crops.interval,
|
||||
time = crops.interval,
|
||||
amount = 8 * crops.settings.interval,
|
||||
time = crops.settings.interval,
|
||||
minpos = { x = pos.x - 0.4, y = pos.y - 0.4, z = pos.z - 0.4 },
|
||||
maxpos = { x = pos.x + 0.4, y = pos.y - 0.4, z = pos.z + 0.4 },
|
||||
minvel = { x = -0.04, y = 0, z = -0.04 },
|
||||
@ -162,10 +198,10 @@ minetest.register_tool("crops:watering_can", {
|
||||
if wear == 65534 then
|
||||
return itemstack
|
||||
end
|
||||
water = math.min(water + crops.watercan, crops.watercan_max)
|
||||
water = math.min(water + crops.settings.watercan, crops.settings.watercan_max)
|
||||
meta:set_int("crops_water", water)
|
||||
|
||||
itemstack:set_wear(math.min(65534, wear + (65535 / crops.watercanuses)))
|
||||
itemstack:set_wear(math.min(65534, wear + (65535 / crops.settings.watercan_uses)))
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
@ -234,8 +270,8 @@ end
|
||||
-- water handling code
|
||||
minetest.register_abm({
|
||||
nodenames = nodenames,
|
||||
interval = crops.interval,
|
||||
chance = crops.chance,
|
||||
interval = crops.settings.interval,
|
||||
chance = crops.settings.chance,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local water = meta:get_int("crops_water")
|
||||
@ -287,7 +323,7 @@ minetest.register_abm({
|
||||
crops.particles(pos, 1)
|
||||
return
|
||||
end
|
||||
meta:set_int("crops_damage", math.min(crops.max_damage, damage))
|
||||
meta:set_int("crops_damage", math.min(crops.settings.max_damage, damage))
|
||||
|
||||
-- is it dead?
|
||||
if damage >= 100 then
|
||||
|
10
melon.lua
10
melon.lua
@ -140,8 +140,8 @@ minetest.register_node("crops:melon", {
|
||||
minetest.register_abm({
|
||||
nodenames = { "crops:melon_plant_1", "crops:melon_plant_2", "crops:melon_plant_3","crops:melon_plant_4" },
|
||||
neighbors = { "group:soil" },
|
||||
interval = crops.interval,
|
||||
chance = crops.chance,
|
||||
interval = crops.settings.interval,
|
||||
chance = crops.settings.chance,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
if not crops.can_grow(pos) then
|
||||
return
|
||||
@ -161,8 +161,8 @@ minetest.register_abm({
|
||||
minetest.register_abm({
|
||||
nodenames = { "crops:melon_plant_5" },
|
||||
neighbors = { "group:soil" },
|
||||
interval = crops.interval,
|
||||
chance = crops.chance,
|
||||
interval = crops.settings.interval,
|
||||
chance = crops.settings.chance,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
if not crops.can_grow(pos) then
|
||||
return
|
||||
@ -207,7 +207,7 @@ minetest.register_abm({
|
||||
--
|
||||
minetest.register_abm({
|
||||
nodenames = { "crops:melon_plant_5_attached" },
|
||||
interval = crops.interval,
|
||||
interval = crops.settings.interval,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
for face = 1, 4 do
|
||||
|
@ -245,8 +245,8 @@ end
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = { "crops:beanpole_plant_base_1", "crops:beanpole_plant_base_2", "crops:beanpole_plant_base_3", "crops:beanpole_plant_base_4" },
|
||||
interval = crops.interval,
|
||||
chance = crops.chance,
|
||||
interval = crops.settings.interval,
|
||||
chance = crops.settings.chance,
|
||||
neighbors = { "group:soil" },
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
if not crops.can_grow(pos) then
|
||||
|
@ -112,8 +112,8 @@ minetest.register_node("crops:soil_with_potatoes", {
|
||||
minetest.register_abm({
|
||||
nodenames = { "crops:potato_plant_1", "crops:potato_plant_2", "crops:potato_plant_3" },
|
||||
neighbors = { "group:soil" },
|
||||
interval = crops.interval,
|
||||
chance = crops.chance,
|
||||
interval = crops.settings.interval,
|
||||
chance = crops.settings.chance,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
if not crops.can_grow(pos) then
|
||||
return
|
||||
@ -141,8 +141,8 @@ minetest.register_abm({
|
||||
minetest.register_abm({
|
||||
nodenames = { "crops:potato_plant_4" },
|
||||
neighbors = { "group:soil" },
|
||||
interval = crops.interval,
|
||||
chance = crops.chance,
|
||||
interval = crops.settings.interval,
|
||||
chance = crops.settings.chance,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
if not crops.can_grow(pos) then
|
||||
return
|
||||
|
@ -123,8 +123,8 @@ minetest.register_craft({
|
||||
minetest.register_abm({
|
||||
nodenames = { "crops:tomato_plant_1", "crops:tomato_plant_2", "crops:tomato_plant_3" },
|
||||
neighbors = { "group:soil" },
|
||||
interval = crops.interval,
|
||||
chance = crops.chance,
|
||||
interval = crops.settings.interval,
|
||||
chance = crops.settings.chance,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
if not crops.can_grow(pos) then
|
||||
return
|
||||
@ -143,8 +143,8 @@ minetest.register_abm({
|
||||
minetest.register_abm({
|
||||
nodenames = { "crops:tomato_plant_4" },
|
||||
neighbors = { "group:soil" },
|
||||
interval = crops.interval,
|
||||
chance = crops.chance,
|
||||
interval = crops.settings.interval,
|
||||
chance = crops.settings.chance,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
if not crops.can_grow(pos) then
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user