diff options
Diffstat (limited to 'advtrains/trainlogic.lua')
-rw-r--r-- | advtrains/trainlogic.lua | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua index c49d7e3..14f3f8b 100644 --- a/advtrains/trainlogic.lua +++ b/advtrains/trainlogic.lua @@ -62,10 +62,17 @@ local LZB_ZERO_APPROACH_DIST = 0.1 -- Speed the train temporarily approaches the stop point with local LZB_ZERO_APPROACH_SPEED = 0.2 - +local on_player_overrun = {} tp_player_tmr = 0 +function advtrains.register_on_player_overrun(func) + -- func = function(player, train_id, train_velocity) + -- train_velocity is a vector with direction of the train's move and length of the train's current speed + assert(type(func) == "function") + table.insert(on_player_overrun, func) +end + advtrains.mainloop_trainlogic=function(dtime, stepno) --build a table of all players indexed by pts. used by damage and door system. advtrains.playersbypts={} @@ -783,10 +790,20 @@ function advtrains.train_step_c(id, train, dtime) end --- 8b damage players --- - if is_loaded_area and train.velocity > 3 and (setting_overrun_mode=="drop" or setting_overrun_mode=="normal") then + if is_loaded_area and train.velocity > 3 --[[ and (setting_overrun_mode=="drop" or setting_overrun_mode=="normal") ]] then local testpts = minetest.pos_to_string(testpos) local player=advtrains.playersbypts[testpts] if player and player:get_hp()>0 and advtrains.is_damage_enabled(player:get_player_name()) then + local train_nextpos = advtrains.path_get(train, atround(collindex) + 1) + if train_nextpos == nil or vector.equals(train_nextpos, collpos) then + minetest.log("error", "Player "..player:get_player_name().." was overrun by train "..train.id..", but can't determine the train's direction!") + else + local train_direction = vector.direction(collpos, train_nextpos) + for _, func in ipairs(on_player_overrun) do + func(player, train.id, train_direction, train.velocity) + end + end + --[[ --atdebug("damage found",player:get_player_name()) if setting_overrun_mode=="drop" then --instantly kill player @@ -803,11 +820,14 @@ function advtrains.train_step_c(id, train, dtime) player_inv:set_list("craft", {}) end player:set_hp(0) + ]] end end end end end + --[[ -- TODO: damage to other objects temporarily disabled to save CPU time, + -- enable it again when get_objects_inside_radius() could be implemented efficiently --- 8c damage other objects --- if is_loaded_area then local objs = minetest.get_objects_inside_radius(rcollpos, 2) @@ -821,6 +841,7 @@ function advtrains.train_step_c(id, train, dtime) end end end + ]] end end end |