diff options
Diffstat (limited to 'advtrains/occupation.lua')
-rw-r--r-- | advtrains/occupation.lua | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/advtrains/occupation.lua b/advtrains/occupation.lua index 6852dfa..26e1f79 100644 --- a/advtrains/occupation.lua +++ b/advtrains/occupation.lua @@ -159,10 +159,8 @@ function o.reverse_lookup(ppos) local r = {} local i = 1 while t[i] do - if t[i]~=train_id then - if not r[t[i]] then r[t[i]] = {} end - table.insert(r[t[i]], t[i+1]) - end + if not r[t[i]] then r[t[i]] = {} end + table.insert(r[t[i]], t[i+1]) i = i + 2 end return r @@ -188,6 +186,7 @@ local OCC_CLOSE_PROXIMITY = 3 -- Gets a mapping of train id's to index of trains that have a path item at this position. Selects at most one index based on a given heuristic, or even none if it does not match the heuristic criterion -- returns (table with train_id->index), position -- "in_train": first index that lies between train index and end index +-- "train_at_node": first index where the train is standing on that node (like in_train but with +-0.5 added to index) -- "first_ahead": smallest index that is > current index -- "before_end"(default): smallest index that is > end index -- "close_proximity": within 3 indices close to the train index and end_index @@ -214,6 +213,9 @@ function o.reverse_lookup_sel(pos, heuristic) if heuristic == "in_train" and idx < otrn.index and idx > otrn.end_index then h_value = idx end + if heuristic == "train_at_node" and idx < (otrn.index+0.5) and idx > (otrn.end_index-0.5) then + h_value = idx + end if heuristic == "close_proximity" and idx < (otrn.index + OCC_CLOSE_PROXIMITY) and idx > (otrn.end_index - OCC_CLOSE_PROXIMITY) then h_value = idx end @@ -228,7 +230,7 @@ end -- returns (table with train_id->index) function o.get_trains_at(ppos) local pos = advtrains.round_vector_floor_y(ppos) - return o.reverse_lookup_sel(pos, "in_train") + return o.reverse_lookup_sel(pos, "train_at_node") end advtrains.occ = o |