1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-05 01:50:25 +01:00

Cleaning some code

This commit is contained in:
Coethium 2016-07-28 17:28:08 +02:00
parent 5cc518badf
commit 2f7e94dbfd
3 changed files with 320 additions and 307 deletions

View File

@ -1,4 +1,5 @@
dofile(minetest.get_modpath("carts").."/functions.lua")
dofile(minetest.get_modpath("carts").."/rails.lua")
local cart = {
physical = true, -- Set to false to not make carts collide with other entities such as carts or the player.
@ -427,51 +428,7 @@ function cart:on_step(dtime)
a = a*0.5
--minetest.chat_send_all(a)
--[[local t = tonumber(minetest.get_meta(pos):get_string("cart_touring_velocity"))
if not t then t=0 end
t = 0
if t>0 then
local vx=math.abs(self.velocity.x)
local vy=math.abs(self.velocity.y)
local vz=math.abs(self.velocity.z)
-- make v the largest of the 3 velocities
local v=vx
if vy>v then v=vy end
if vz>v then v=vz end
--
local diff=0
local acelordecl=0
if v>t then
diff=v-t
acelordecl=-1
elseif v<t then
diff=t-v
acelordecl=1
end --v>t
--minetest.log("action", " on_step t1 v="..v.." t="..t.." diff="..diff.." a="..a.." acelordecl="..acelordecl)
--adjust for grav
if self.velocity.y<0 then --going downhill so grav will acel by extra 0.13
--if we are decel then add an extra 0.13 to how much we need to decel
--if we are accel then subtract an extra 0.13 from how much we need to acel
diff=diff-(0.13*acelordecl)
elseif self.velocity.y>0 then --going uphill grav will decl by extra 0.10
--if we are decel then subtract 0.1 from how much we need to decel
--if we are acel then add 0.1 to how much we need to acel
diff=diff+(0.1*acelordecl)
end -- self.velocity.y<0
--so now diff is the difference between cart velocity (after this turns grav)
--and our target touring velocity
--minetest.log("action", "*!* on_step t2 grav v="..v.." diff="..diff.." a="..a)
if diff<a then --we dont want to over acel or decel
a=diff
elseif diff>a*4 then
a=a*2 --if big difference, play catchup fast!
elseif diff>a*3 then
a=a*1.5 --if big difference, play catchup fast!
end --diff<a
a=a*acelordecl
end -- if t>0--]]
-- Check if down arrow is being pressed (handbrake).
if self.driver then
local ctrl = self.driver:get_player_control()
@ -643,270 +600,9 @@ minetest.register_craft({
},
})
minetest.register_node(":default:rail", {
description = "Rail",
drawtype = "raillike",
tiles = {"default_rail.png", "default_rail_curved.png", "default_rail_t_junction.png", "default_rail_crossing.png"},
inventory_image = "default_rail.png",
wield_image = "default_rail.png",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {bendy = 2, snappy = 1, dig_immediate = 2, rail = 1, connect_to_raillike = 1},
--[[mesecons = {
effector = {
action_off = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "0.5")
minetest.get_meta(pos):set_string("cart_touring_velocity", cart:get_staticdata().velocity)
end,
action_on = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "0")
end,
},
},--]]
})
minetest.register_node("carts:rail_copper", {
description = "Copper Rail",
drawtype = "raillike",
tiles = {"carts_rail_copper.png", "carts_rail_copper_curved.png", "carts_rail_copper_t_junction.png", "carts_rail_copper_crossing.png"},
inventory_image = "carts_rail_copper.png",
wield_image = "carts_rail_copper.png",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {bendy = 2, snappy = 1, dig_immediate = 2, rail = 1, connect_to_raillike = 1},
})
minetest.register_node("carts:rail_invisible", {
description = "Invisible Rail",
stack_max = 10000,
range = 12,
drawtype = "raillike",
tiles = {"invisible.png", "invisible.png", "invisible.png", "invisible.png"},
inventory_image = "default_rail.png^default_steel_ingot.png",
wield_image = "default_rail.png^default_steel_ingot.png",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
drop = "",
groups = {unbreakable = 1, rail = 1, connect_to_raillike = 1, not_in_creative_inventory = 1},
})
minetest.register_node("carts:rail_power", {
description = "Powered Rail",
drawtype = "raillike",
tiles = {"carts_rail_pwr.png", "carts_rail_curved_pwr.png", "carts_rail_t_junction_pwr.png", "carts_rail_crossing_pwr.png"},
inventory_image = "carts_rail_pwr.png",
wield_image = "carts_rail_pwr.png",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {bendy = 2, snappy = 1, dig_immediate = 2, rail = 1, connect_to_raillike = 1},
after_place_node = function(pos, placer, itemstack)
minetest.get_meta(pos):set_string("cart_acceleration", "1")
minetest.get_meta(pos):set_string("cart_touring_velocity", cart:get_staticdata().velocity)
end,
--[[mesecons = {
effector = {
action_off = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "0.5")
end,
action_on = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "0")
end,
},
},--]]
})
minetest.register_node("carts:rail_power_invisible", {
description = "Invisible Powered Rail",
stack_max = 10000,
range = 12,
drawtype = "raillike",
tiles = {"invisible.png", "invisible.png", "invisible.png", "invisible.png"},
inventory_image = "default_rail.png^default_mese_crystal_fragment.png",
wield_image = "default_rail.png^default_mese_crystal_fragment.png",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
drop = "",
groups = {unbreakable = 1, rail = 1, connect_to_raillike = 1, not_in_creative_inventory = 1},
after_place_node = function(pos, placer, itemstack)
minetest.get_meta(pos):set_string("cart_acceleration", "10")
minetest.get_meta(pos):set_string("cart_touring_velocity", cart:get_staticdata().velocity)
end,
})
minetest.register_node("carts:rail_brake", {
description = "Brake Rail",
drawtype = "raillike",
tiles = {"carts_rail_brk.png", "carts_rail_curved_brk.png", "carts_rail_t_junction_brk.png", "carts_rail_crossing_brk.png"},
inventory_image = "carts_rail_brk.png",
wield_image = "carts_rail_brk.png",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {bendy = 2, snappy = 1, dig_immediate = 2, rail = 1, connect_to_raillike = 1},
after_place_node = function(pos, placer, itemstack)
minetest.get_meta(pos):set_string("cart_acceleration", "-1")
minetest.get_meta(pos):set_string("cart_touring_velocity", cart.TARGET_TOUR_V)
end,
--[[mesecons = {
effector = {
action_off = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "-0.2")
end,
action_on = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "0")
end,
},
},--]]
})
minetest.register_node("carts:rail_brake_invisible", {
description = "Invisible Brake Rail",
stack_max = 10000,
range = 12,
drawtype = "raillike",
tiles = {"invisible.png", "invisible.png", "invisible.png", "invisible.png"},
inventory_image = "default_rail.png^default_coal_lump.png",
wield_image = "default_rail.png^default_coal_lump.png",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
drop = "",
groups = {bendy = 2, snappy = 1, dig_immediate = 2, rail = 1, connect_to_raillike = 1, not_in_creative_inventory = 1},
after_place_node = function(pos, placer, itemstack)
minetest.get_meta(pos):set_string("cart_acceleration", "-10")
minetest.get_meta(pos):set_string("cart_touring_velocity", cart:get_staticdata().velocity)
end,
})
--[[minetest.register_node("carts:rail_tour", {
description = "Touring Rail",
drawtype = "raillike",
tiles = {"carts_rail_tour.png", "carts_rail_curved_tour.png", "carts_rail_t_junction_tour.png", "carts_rail_crossing_tour.png"},
inventory_image = "carts_rail_tour.png",
wield_image = "carts_rail_tour.png",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {bendy = 2, snappy = 1, dig_immediate = 2, rail = 1, connect_to_raillike = 1},
after_place_node = function(pos, placer, itemstack)
if not mesecon then
minetest.get_meta(pos):set_string("cart_acceleration", "0.5")
minetest.get_meta(pos):set_string("cart_touring_velocity", cart.TARGET_TOUR_V)
end
end,
mesecons = {
effector = {
action_on = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "0.5")
end,
action_off = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "0")
end,
},
},
})
--]]
minetest.register_craft({
output = "carts:rail_copper 16",
recipe = {
{"default:copper_ingot", "group:stick", "default:copper_ingot"},
{"default:copper_ingot", "group:stick", "default:copper_ingot"},
{"default:copper_ingot", "group:stick", "default:copper_ingot"},
}
})
minetest.register_craft({
type = "shapeless",
output = "carts:rail_power",
recipe = {"group:rail", "default:mese_crystal_fragment"},
})
minetest.register_craft({
type = "shapeless",
output = "carts:rail_brake",
recipe = {"group:rail", "default:coal_lump"},
})
--[[minetest.register_craft({
type = "shapeless",
output = "carts:rail_tour",
recipe = {"group:rail", "default:clay_lump"},
})--]]
minetest.register_alias("carts:powerrail", "carts:rail_power")
minetest.register_alias("carts:power_rail", "carts:rail_power")
minetest.register_alias("carts:brakerail", "carts:rail_brake")
minetest.register_alias("carts:brake_rail", "carts:rail_power")
--minetest.register_alias("carts:tourrail", "carts:rail_tour")
if minetest.setting_getbool("log_mods") then
minetest.log("action", "Carbone: [carts] loaded.")
end
-- temporary
--[[minetest.register_abm({
nodes = {"group:rail"},
func = function(pos)
local name = minetest.get_node(pos).name
minetest.remove_node(pos)
minetest.place_node(pos,{name = name})
end
})--]]

213
mods/carts/rails.lua Normal file
View File

@ -0,0 +1,213 @@
minetest.register_node(":default:rail", {
description = "Rail",
drawtype = "raillike",
tiles = {"default_rail.png", "default_rail_curved.png", "default_rail_t_junction.png", "default_rail_crossing.png"},
inventory_image = "default_rail.png",
wield_image = "default_rail.png",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {bendy = 2, snappy = 1, dig_immediate = 2, rail = 1, connect_to_raillike = 1},
--[[mesecons = {
effector = {
action_off = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "0.5")
minetest.get_meta(pos):set_string("cart_touring_velocity", cart:get_staticdata().velocity)
end,
action_on = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "0")
end,
},
},--]]
})
minetest.register_node("carts:rail_copper", {
description = "Copper Rail",
drawtype = "raillike",
tiles = {"carts_rail_copper.png", "carts_rail_copper_curved.png", "carts_rail_copper_t_junction.png", "carts_rail_copper_crossing.png"},
inventory_image = "carts_rail_copper.png",
wield_image = "carts_rail_copper.png",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {bendy = 2, snappy = 1, dig_immediate = 2, rail = 1, connect_to_raillike = 1},
})
minetest.register_node("carts:rail_invisible", {
description = "Invisible Rail",
stack_max = 10000,
range = 12,
drawtype = "raillike",
tiles = {"invisible.png", "invisible.png", "invisible.png", "invisible.png"},
inventory_image = "default_rail.png^default_steel_ingot.png",
wield_image = "default_rail.png^default_steel_ingot.png",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
drop = "",
groups = {unbreakable = 1, rail = 1, connect_to_raillike = 1, not_in_creative_inventory = 1},
})
minetest.register_node("carts:rail_power", {
description = "Powered Rail",
drawtype = "raillike",
tiles = {"carts_rail_pwr.png", "carts_rail_curved_pwr.png", "carts_rail_t_junction_pwr.png", "carts_rail_crossing_pwr.png"},
inventory_image = "carts_rail_pwr.png",
wield_image = "carts_rail_pwr.png",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {bendy = 2, snappy = 1, dig_immediate = 2, rail = 1, connect_to_raillike = 1},
after_place_node = function(pos, placer, itemstack)
minetest.get_meta(pos):set_string("cart_acceleration", "1")
minetest.get_meta(pos):set_string("cart_touring_velocity", cart:get_staticdata().velocity)
end,
--[[mesecons = {
effector = {
action_off = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "0.5")
end,
action_on = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "0")
end,
},
},--]]
})
minetest.register_node("carts:rail_power_invisible", {
description = "Invisible Powered Rail",
stack_max = 10000,
range = 12,
drawtype = "raillike",
tiles = {"invisible.png", "invisible.png", "invisible.png", "invisible.png"},
inventory_image = "default_rail.png^default_mese_crystal_fragment.png",
wield_image = "default_rail.png^default_mese_crystal_fragment.png",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
drop = "",
groups = {unbreakable = 1, rail = 1, connect_to_raillike = 1, not_in_creative_inventory = 1},
after_place_node = function(pos, placer, itemstack)
minetest.get_meta(pos):set_string("cart_acceleration", "10")
minetest.get_meta(pos):set_string("cart_touring_velocity", cart:get_staticdata().velocity)
end,
})
minetest.register_node("carts:rail_brake", {
description = "Brake Rail",
drawtype = "raillike",
tiles = {"carts_rail_brk.png", "carts_rail_curved_brk.png", "carts_rail_t_junction_brk.png", "carts_rail_crossing_brk.png"},
inventory_image = "carts_rail_brk.png",
wield_image = "carts_rail_brk.png",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {bendy = 2, snappy = 1, dig_immediate = 2, rail = 1, connect_to_raillike = 1},
after_place_node = function(pos, placer, itemstack)
minetest.get_meta(pos):set_string("cart_acceleration", "-1")
minetest.get_meta(pos):set_string("cart_touring_velocity", cart.TARGET_TOUR_V)
end,
--[[mesecons = {
effector = {
action_off = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "-0.2")
end,
action_on = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "0")
end,
},
},--]]
})
minetest.register_node("carts:rail_brake_invisible", {
description = "Invisible Brake Rail",
stack_max = 10000,
range = 12,
drawtype = "raillike",
tiles = {"invisible.png", "invisible.png", "invisible.png", "invisible.png"},
inventory_image = "default_rail.png^default_coal_lump.png",
wield_image = "default_rail.png^default_coal_lump.png",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
drop = "",
groups = {bendy = 2, snappy = 1, dig_immediate = 2, rail = 1, connect_to_raillike = 1, not_in_creative_inventory = 1},
after_place_node = function(pos, placer, itemstack)
minetest.get_meta(pos):set_string("cart_acceleration", "-10")
minetest.get_meta(pos):set_string("cart_touring_velocity", cart:get_staticdata().velocity)
end,
})
minetest.register_craft({
output = "carts:rail_copper 16",
recipe = {
{"default:copper_ingot", "group:stick", "default:copper_ingot"},
{"default:copper_ingot", "group:stick", "default:copper_ingot"},
{"default:copper_ingot", "group:stick", "default:copper_ingot"},
}
})
minetest.register_craft({
type = "shapeless",
output = "carts:rail_power",
recipe = {"group:rail", "default:mese_crystal_fragment"},
})
minetest.register_craft({
type = "shapeless",
output = "carts:rail_brake",
recipe = {"group:rail", "default:coal_lump"},
})
minetest.register_alias("carts:powerrail", "carts:rail_power")
minetest.register_alias("carts:power_rail", "carts:rail_power")
minetest.register_alias("carts:brakerail", "carts:rail_brake")
minetest.register_alias("carts:brake_rail", "carts:rail_power")

104
mods/carts/trash.lua.old Normal file
View File

@ -0,0 +1,104 @@
--[[local t = tonumber(minetest.get_meta(pos):get_string("cart_touring_velocity"))
if not t then t=0 end
t = 0
if t>0 then
local vx=math.abs(self.velocity.x)
local vy=math.abs(self.velocity.y)
local vz=math.abs(self.velocity.z)
-- make v the largest of the 3 velocities
local v=vx
if vy>v then v=vy end
if vz>v then v=vz end
--
local diff=0
local acelordecl=0
if v>t then
diff=v-t
acelordecl=-1
elseif v<t then
diff=t-v
acelordecl=1
end --v>t
--minetest.log("action", " on_step t1 v="..v.." t="..t.." diff="..diff.." a="..a.." acelordecl="..acelordecl)
--adjust for grav
if self.velocity.y<0 then --going downhill so grav will acel by extra 0.13
--if we are decel then add an extra 0.13 to how much we need to decel
--if we are accel then subtract an extra 0.13 from how much we need to acel
diff=diff-(0.13*acelordecl)
elseif self.velocity.y>0 then --going uphill grav will decl by extra 0.10
--if we are decel then subtract 0.1 from how much we need to decel
--if we are acel then add 0.1 to how much we need to acel
diff=diff+(0.1*acelordecl)
end -- self.velocity.y<0
--so now diff is the difference between cart velocity (after this turns grav)
--and our target touring velocity
--minetest.log("action", "*!* on_step t2 grav v="..v.." diff="..diff.." a="..a)
if diff<a then --we dont want to over acel or decel
a=diff
elseif diff>a*4 then
a=a*2 --if big difference, play catchup fast!
elseif diff>a*3 then
a=a*1.5 --if big difference, play catchup fast!
end --diff<a
a=a*acelordecl
end -- if t>0--]]
--[[minetest.register_node("carts:rail_tour", {
description = "Touring Rail",
drawtype = "raillike",
tiles = {"carts_rail_tour.png", "carts_rail_curved_tour.png", "carts_rail_t_junction_tour.png", "carts_rail_crossing_tour.png"},
inventory_image = "carts_rail_tour.png",
wield_image = "carts_rail_tour.png",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {bendy = 2, snappy = 1, dig_immediate = 2, rail = 1, connect_to_raillike = 1},
after_place_node = function(pos, placer, itemstack)
if not mesecon then
minetest.get_meta(pos):set_string("cart_acceleration", "0.5")
minetest.get_meta(pos):set_string("cart_touring_velocity", cart.TARGET_TOUR_V)
end
end,
mesecons = {
effector = {
action_on = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "0.5")
end,
action_off = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "0")
end,
},
},
})
--]]
--[[minetest.register_craft({
type = "shapeless",
output = "carts:rail_tour",
recipe = {"group:rail", "default:clay_lump"},
})--]]
--minetest.register_alias("carts:tourrail", "carts:rail_tour")
-- temporary
--[[minetest.register_abm({
nodes = {"group:rail"},
func = function(pos)
local name = minetest.get_node(pos).name
minetest.remove_node(pos)
minetest.place_node(pos,{name = name})
end
})--]]