From cf2179dea5baae1e1170a7aaa56214a862b0f3fe Mon Sep 17 00:00:00 2001 From: orwell96 Date: Tue, 26 Nov 2019 16:01:51 +0100 Subject: remove obsolete code/comments --- advtrains/trainlogic.lua | 34 ---------------------------------- 1 file changed, 34 deletions(-) (limited to 'advtrains/trainlogic.lua') diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua index 86f60c1..eac7ddb 100644 --- a/advtrains/trainlogic.lua +++ b/advtrains/trainlogic.lua @@ -703,40 +703,6 @@ advtrains.te_register_on_remove(function(id, train) --atdebug(id,"tnc remove",train.index,train.end_index) end) --- Calculates the indices where the window borders of the occupation windows are. --- TODO adapt this code to new system, probably into a callback (probably only the brake distance code is needed) -local function calc_occwindows(id, train) - local end_index = advtrains.path_get_index_by_offset(train, train.index, -train.trainlen) - train.end_index = end_index - local cpl_b = end_index - COUPLE_ZONE - local safety_b = advtrains.path_get_index_by_offset(train, cpl_b, -SAFETY_ZONE) - local cpl_f = end_index + COUPLE_ZONE - local safety_f = advtrains.path_get_index_by_offset(train, cpl_f, SAFETY_ZONE) - - -- calculate brake distance - local acc_all = t_accel_all[1] - local acc_eng = t_accel_eng[1] - local nwagons = #train.trainparts - local acc = acc_all + (acc_eng*train.locomotives_in_train)/nwagons - local vel = train.velocity - local brakedst = (vel*vel) / (2*acc) - - local brake_i = math.max(advtrains.path_get_index_by_offset(train, train.index, brakedst + BRAKE_SPACE), safety_f) - local aware_i = advtrains.path_get_index_by_offset(train, brake_i, AWARE_ZONE) - - return { - safety_b, - cpl_b, - end_index, - train.index, - cpl_f, - safety_f, - brake_i, - aware_i, - } -end - - --returns new id function advtrains.create_new_train_at(pos, connid, ioff, trainparts) local new_id=advtrains.random_id() -- cgit v1.2.3 From 7082038f758e0616d7b54ed4e5f9a231103ac887 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Tue, 26 Nov 2019 16:43:47 +0100 Subject: Don't spawn couple entities when not loaded --- advtrains/trainlogic.lua | 58 ++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 27 deletions(-) (limited to 'advtrains/trainlogic.lua') diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua index eac7ddb..580a7d4 100644 --- a/advtrains/trainlogic.lua +++ b/advtrains/trainlogic.lua @@ -951,21 +951,23 @@ function advtrains.train_check_couples(train) if not train.cpl_front then -- recheck front couple local front_trains, pos = advtrains.occ.get_occupations(train, atround(train.index) + CPL_CHK_DST) - for tid, idx in pairs(front_trains) do - local other_train = advtrains.trains[tid] - if not advtrains.train_ensure_init(tid, other_train) then - atwarn("Train",tid,"is not initialized! Couldn't check couples!") - return - end - --atdebug(train.id,"front: ",idx,"on",tid,atround(other_train.index),atround(other_train.end_index)) - if other_train.velocity == 0 then - if idx>=other_train.index and idx<=other_train.index + CPL_ZONE then - createcouple(pos, train, true, other_train, true) - break + if minetest.get_node_or_nil(pos) then -- if the position is loaded... + for tid, idx in pairs(front_trains) do + local other_train = advtrains.trains[tid] + if not advtrains.train_ensure_init(tid, other_train) then + atwarn("Train",tid,"is not initialized! Couldn't check couples!") + return end - if idx<=other_train.end_index and idx>=other_train.end_index - CPL_ZONE then - createcouple(pos, train, true, other_train, false) - break + --atdebug(train.id,"front: ",idx,"on",tid,atround(other_train.index),atround(other_train.end_index)) + if other_train.velocity == 0 then + if idx>=other_train.index and idx<=other_train.index + CPL_ZONE then + createcouple(pos, train, true, other_train, true) + break + end + if idx<=other_train.end_index and idx>=other_train.end_index - CPL_ZONE then + createcouple(pos, train, true, other_train, false) + break + end end end end @@ -979,20 +981,22 @@ function advtrains.train_check_couples(train) if not train.cpl_back then -- recheck back couple local back_trains, pos = advtrains.occ.get_occupations(train, atround(train.end_index) - CPL_CHK_DST) - for tid, idx in pairs(back_trains) do - local other_train = advtrains.trains[tid] - if not advtrains.train_ensure_init(tid, other_train) then - atwarn("Train",tid,"is not initialized! Couldn't check couples!") - return - end - if other_train.velocity == 0 then - if idx>=other_train.index and idx<=other_train.index + CPL_ZONE then - createcouple(pos, train, false, other_train, true) - break + if minetest.get_node_or_nil(pos) then -- if the position is loaded... + for tid, idx in pairs(back_trains) do + local other_train = advtrains.trains[tid] + if not advtrains.train_ensure_init(tid, other_train) then + atwarn("Train",tid,"is not initialized! Couldn't check couples!") + return end - if idx<=other_train.end_index and idx>=other_train.end_index - CPL_ZONE then - createcouple(pos, train, false, other_train, false) - break + if other_train.velocity == 0 then + if idx>=other_train.index and idx<=other_train.index + CPL_ZONE then + createcouple(pos, train, false, other_train, true) + break + end + if idx<=other_train.end_index and idx>=other_train.end_index - CPL_ZONE then + createcouple(pos, train, false, other_train, false) + break + end end end end -- cgit v1.2.3