diff options
Diffstat (limited to 'advtrains/advtrains/wagons.lua')
-rw-r--r-- | advtrains/advtrains/wagons.lua | 61 |
1 files changed, 52 insertions, 9 deletions
diff --git a/advtrains/advtrains/wagons.lua b/advtrains/advtrains/wagons.lua index 029d2d1..b46ed81 100644 --- a/advtrains/advtrains/wagons.lua +++ b/advtrains/advtrains/wagons.lua @@ -32,7 +32,7 @@ function wagon:on_rightclick(clicker) --advtrains.dumppath(self:train().path)
--minetest.chat_send_all("at index "..(self:train().index or "nil"))
--advtrains.invert_train(self.train_id)
- minetest.chat_send_all(dump(self:train()))
+ atprint(dump(self))
return
end
local no=self:get_seatno(clicker:get_player_name())
@@ -78,10 +78,6 @@ function wagon:on_activate(sd_uid, dtime_s) return
end
end
-
- if self.custom_on_activate then
- self:custom_on_activate(dtime_s)
- end
end
function wagon:get_staticdata()
@@ -158,6 +154,13 @@ function wagon:init_shared() end
end
end
+ if self.doors then
+ self.door_anim_timer=0
+ self.door_state=0
+ end
+ if self.custom_on_activate then
+ self:custom_on_activate(dtime_s)
+ end
end
function wagon:ensure_init()
if self.initialized then
@@ -295,7 +298,36 @@ function wagon:on_step(dtime) end
local gp=self:train()
-
+
+ --door animation
+ if self.doors then
+ if (self.door_anim_timer or 0)<=0 then
+ local fct=self.wagon_flipped and -1 or 1
+ local dstate = (gp.door_open or 0) * fct
+ if dstate ~= self.door_state then
+ local at
+ --meaning of the train.door_open field:
+ -- -1: left doors (rel. to train orientation)
+ -- 0: closed
+ -- 1: right doors
+ --this code produces the following behavior:
+ -- if changed from 0 to +-1, play open anim. if changed from +-1 to 0, play close.
+ -- if changed from +-1 to -+1, first close and set 0, then it will detect state change again and run open.
+ if self.door_state == 0 then
+ at=self.doors.open[dstate]
+ self.object:set_animation(at.frames, at.speed or 15, at.blend or 0, false)
+ self.door_state = dstate
+ else
+ at=self.doors.close[self.door_state or 1]--in case it has not been set yet
+ self.object:set_animation(at.frames, at.speed or 15, at.blend or 0, false)
+ self.door_state = 0
+ end
+ self.door_anim_timer = at.time
+ end
+ else
+ self.door_anim_timer = (self.door_anim_timer or 0) - dtime
+ end
+ end
--DisCouple
if self.pos_in_trainparts and self.pos_in_trainparts>1 then
if gp.velocity==0 then
@@ -354,9 +386,20 @@ function wagon:on_step(dtime) end
end
if collides then
- gp.recently_collided_with_env=true
- gp.velocity=-0.5*gp.velocity
- gp.tarvelocity=0
+ if self.collision_count and self.collision_count>10 then
+ --enable collision mercy to get trains stuck in walls out of walls
+ --actually do nothing except limiting the velocity to 1
+ gp.velocity=math.min(gp.velocity, 1)
+ gp.tarvelocity=math.min(gp.tarvelocity, 1)
+ else
+ gp.recently_collided_with_env=true
+ gp.velocity=2*gp.velocity
+ gp.movedir=-gp.movedir
+ gp.tarvelocity=0
+ self.collision_count=(self.collision_count or 0)+1
+ end
+ else
+ self.collision_count=nil
end
end
|