aboutsummaryrefslogtreecommitdiff
path: root/wagons.lua
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2016-06-02 14:42:01 +0200
committerorwell96 <mono96.mml@gmail.com>2016-06-02 14:42:01 +0200
commite449704a92c8c1931fb687e58f095bea27db3ddc (patch)
tree4e8eec18b018cb47a30ca24a4338520d82b284c2 /wagons.lua
parenta7bd6e96afa02e4bddfbd105e31616900be2edfb (diff)
downloadadvtrains-e449704a92c8c1931fb687e58f095bea27db3ddc.tar.gz
advtrains-e449704a92c8c1931fb687e58f095bea27db3ddc.tar.bz2
advtrains-e449704a92c8c1931fb687e58f095bea27db3ddc.zip
use real pos-in-train calculation also for trainlen calculation, fix bugs and add damage by trains
Diffstat (limited to 'wagons.lua')
-rw-r--r--wagons.lua33
1 files changed, 20 insertions, 13 deletions
diff --git a/wagons.lua b/wagons.lua
index 54d41fb..31a07b2 100644
--- a/wagons.lua
+++ b/wagons.lua
@@ -134,6 +134,7 @@ function wagon:on_punch(puncher, time_from_last_punch, tool_capabilities, direct
end
function wagon:on_step(dtime)
+ local t=os.clock()
local pos = self.object:getpos()
if not self.initialized_pre then
print("[advtrains] wagon stepping while not yet initialized_pre, returning")
@@ -210,19 +211,7 @@ function wagon:on_step(dtime)
return
end
- local pos_in_train_left=self.pos_in_train+0
- local index=gp.index
- if pos_in_train_left>(index-math.floor(index))*(gp.path_dist[math.floor(index)] or 1) then
- pos_in_train_left=pos_in_train_left - (index-math.floor(index))*(gp.path_dist[math.floor(index)] or 1)
- index=math.floor(index)
- while pos_in_train_left>(gp.path_dist[index-1] or 1) do
- pos_in_train_left=pos_in_train_left - (gp.path_dist[index-1] or 1)
- index=index-1
- end
- index=index-(pos_in_train_left/(gp.path_dist[index-1] or 1))
- else
- index=index-(pos_in_train_left*(gp.path_dist[math.floor(index-1)] or 1))
- end
+ local index=advtrains.get_real_path_index(self:train(), self.pos_in_train)
--print("trainindex "..gp.index.." wagonindex "..index)
--position recalculation
@@ -283,6 +272,24 @@ function wagon:on_step(dtime)
self.old_velocity_vector=velocityvec
self.old_yaw=yaw
+ printbm("wagon step", t)
+end
+
+function advtrains.get_real_path_index(train, pit)
+ local pos_in_train_left=pit
+ local index=train.index
+ if pos_in_train_left>(index-math.floor(index))*(train.path_dist[math.floor(index)] or 1) then
+ pos_in_train_left=pos_in_train_left - (index-math.floor(index))*(train.path_dist[math.floor(index)] or 1)
+ index=math.floor(index)
+ while pos_in_train_left>(train.path_dist[index-1] or 1) do
+ pos_in_train_left=pos_in_train_left - (train.path_dist[index-1] or 1)
+ index=index-1
+ end
+ index=index-(pos_in_train_left/(train.path_dist[index-1] or 1))
+ else
+ index=index-(pos_in_train_left*(train.path_dist[math.floor(index-1)] or 1))
+ end
+ return index
end