aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--advtrains.zipbin1484902 -> 1484978 bytes
-rw-r--r--damage.lua4
-rw-r--r--trainlogic.lua15
-rw-r--r--wagons.lua4
4 files changed, 17 insertions, 6 deletions
diff --git a/advtrains.zip b/advtrains.zip
index 4d966b4..06da9f3 100644
--- a/advtrains.zip
+++ b/advtrains.zip
Binary files differ
diff --git a/damage.lua b/damage.lua
index 3fc1d97..b39fe67 100644
--- a/damage.lua
+++ b/damage.lua
@@ -1,7 +1,7 @@
--damage.lua
--a globalstep that damages players overrolled by trains.
-advtrains.player_to_wagon_mapping={}
+advtrains.player_to_train_mapping={}
local tmr=0
minetest.register_globalstep(function(dtime)
@@ -13,7 +13,7 @@ minetest.register_globalstep(function(dtime)
for _, object in pairs(minetest.get_objects_inside_radius(pos, 1)) do
local le=object:get_luaentity()
if le and le.is_wagon and le.initialized and le:train() then
- if (not advtrains.player_to_wagon_mapping[player:get_player_name()] or le.train_id~=advtrains.player_to_wagon_mapping[player:get_player_name()].train_id) and math.abs(le:train().velocity)>2 then
+ if (not advtrains.player_to_train_mapping[player:get_player_name()] or le.train_id~=advtrains.player_to_train_mapping[player:get_player_name()]) and math.abs(le:train().velocity)>2 then
--player:punch(object, 1000, {damage={fleshy=3*math.abs(le:train().velocity)}})
player:set_hp(player:get_hp()-math.abs(le:train().velocity)-3)
end
diff --git a/trainlogic.lua b/trainlogic.lua
index 11849fd..633024d 100644
--- a/trainlogic.lua
+++ b/trainlogic.lua
@@ -487,8 +487,19 @@ function advtrains.pathpredict(id, train)
train.path_dist[-1]=vector.distance(train.last_pos, train.last_pos_prev)
end
+ local pregen_front=2
+ local pregen_back=2
+ if train.velocity>0 then
+ if train.movedir>0 then
+ pregen_front=2+math.ceil(train.velocity*0.15) --assumes server step of 0.1 seconds, +50% tolerance
+ else
+ pregen_back=2+math.ceil(train.velocity*0.15)
+ end
+ end
+
+
local maxn=advtrains.maxN(train.path)
- while (maxn-train.index) < 2 do--pregenerate
+ while (maxn-train.index) < pregen_front do--pregenerate
--print("[advtrains]maxn conway for ",maxn,minetest.pos_to_string(path[maxn]),maxn-1,minetest.pos_to_string(path[maxn-1]))
local conway=advtrains.conway(train.path[maxn], train.path[maxn-1], train.traintype)
if conway then
@@ -505,7 +516,7 @@ function advtrains.pathpredict(id, train)
end
local minn=advtrains.minN(train.path)
- while (train.index-minn) < (train.trainlen or 0) + 2 do --post_generate. has to be at least trainlen. (we let go of the exact calculation here since this would be unuseful here)
+ while (train.index-minn) < (train.trainlen or 0) + pregen_back do --post_generate. has to be at least trainlen. (we let go of the exact calculation here since this would be unuseful here)
--print("[advtrains]minn conway for ",minn,minetest.pos_to_string(path[minn]),minn+1,minetest.pos_to_string(path[minn+1]))
local conway=advtrains.conway(train.path[minn], train.path[minn+1], train.traintype)
if conway then
diff --git a/wagons.lua b/wagons.lua
index 6b3780a..ca31590 100644
--- a/wagons.lua
+++ b/wagons.lua
@@ -416,7 +416,7 @@ function wagon:get_on(clicker, seatno)
self:get_off(seatno)
end
self.seatp[seatno] = clicker:get_player_name()
- advtrains.player_to_wagon_mapping[clicker:get_player_name()]={wagon=self, seatno=seatno}
+ advtrains.player_to_train_mapping[clicker:get_player_name()]=self.train_id
clicker:set_attach(self.object, "", self.seats[seatno].attach_offset, {x=0,y=0,z=0})
clicker:set_eye_offset(self.seats[seatno].view_offset, self.seats[seatno].view_offset)
end
@@ -438,7 +438,7 @@ function wagon:get_off(seatno)
if not self.seatp[seatno] then return end
local pname = self.seatp[seatno]
local clicker = minetest.get_player_by_name(pname)
- advtrains.player_to_wagon_mapping[pname]=nil
+ advtrains.player_to_train_mapping[pname]=nil
advtrains.clear_driver_hud(pname)
if clicker then
clicker:set_detach()