aboutsummaryrefslogtreecommitdiff
path: root/wagons.lua
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2016-11-24 20:25:07 +0100
committerorwell96 <mono96.mml@gmail.com>2016-11-24 20:25:07 +0100
commit7eb17b323322aaf0c9d57c66079465a8df3bae10 (patch)
tree1d641717ce9e6720572cab052002b5a796e18a4c /wagons.lua
parentcccdad4aeb891e2f4fb2d546bf7bea2d07270d44 (diff)
downloadadvtrains-7eb17b323322aaf0c9d57c66079465a8df3bae10.tar.gz
advtrains-7eb17b323322aaf0c9d57c66079465a8df3bae10.tar.bz2
advtrains-7eb17b323322aaf0c9d57c66079465a8df3bae10.zip
change train controlling system and keybindings
also, fix various small bugs
Diffstat (limited to 'wagons.lua')
-rw-r--r--wagons.lua28
1 files changed, 9 insertions, 19 deletions
diff --git a/wagons.lua b/wagons.lua
index 7a99bca..296bc54 100644
--- a/wagons.lua
+++ b/wagons.lua
@@ -259,24 +259,13 @@ function wagon:on_step(dtime)
local driver=self.seatp[seatno] and minetest.get_player_by_name(self.seatp[seatno])
if driver and driver:get_player_control_bits()~=self.old_player_control_bits then
local pc=driver:get_player_control()
- if pc.sneak then --stop
- self:train().tarvelocity=0
- elseif (not self.wagon_flipped and pc.up) or (self.wagon_flipped and pc.down) then --faster
- self:train().tarvelocity=math.min(self:train().tarvelocity+1, advtrains.all_traintypes[self:train().traintype].max_speed or 10)
- elseif (not self.wagon_flipped and pc.down) or (self.wagon_flipped and pc.up) then --slower
- self:train().tarvelocity=math.max(self:train().tarvelocity-1, -(advtrains.all_traintypes[self:train().traintype].max_speed or 10))
- elseif pc.aux1 then --slower
- if true or math.abs(self:train().velocity)<=3 then--TODO debug
- self:get_off(seatno)
- return
- else
- minetest.chat_send_player(driver:get_player_name(), "Can't get off driving train!")
- end
- end
+
+ advtrains.on_control_change(pc, self:train(), self.wagon_flipped)
+
self.old_player_control_bits=driver:get_player_control_bits()
end
if driver then
- advtrains.set_trainhud(driver:get_player_name(), advtrains.hud_train_format(self:train(), self.wagon_flipped))
+ advtrains.update_driver_hud(driver:get_player_name(), self:train(), self.wagon_flipped)
end
end
end
@@ -310,7 +299,8 @@ function wagon:on_step(dtime)
return
end
if not self.pos_in_train then
- print("["..self.unique_id.."][fatal] no pos_in_train set.")
+ --why ever. but better continue next step...
+ advtrains.update_trainpart_properties(self.train_id)
return
end
@@ -347,7 +337,7 @@ function wagon:on_step(dtime)
end
--FIX: use index of the wagon, not of the train.
- local velocity=gp.velocity/(gp.path_dist[math.floor(index)] or 1)
+ local velocity=(gp.velocity*gp.movedir)/(gp.path_dist[math.floor(index)] or 1)
local acceleration=(gp.last_accel or 0)/(gp.path_dist[math.floor(index)] or 1)
local factor=index-math.floor(index)
local actual_pos={x=first_pos.x-(first_pos.x-second_pos.x)*factor, y=first_pos.y-(first_pos.y-second_pos.y)*factor, z=first_pos.z-(first_pos.z-second_pos.z)*factor,}
@@ -414,7 +404,7 @@ function wagon:get_on(clicker, seatno)
self.seatp={}
end
if not self.seats[seatno] then return end
- if self.seatp[seatno] then
+ if self.seatp[seatno] and self.seatp[seatno]~=clicker:get_player_name() then
self:get_off(seatno)
end
self.seatp[seatno] = clicker:get_player_name()
@@ -441,7 +431,7 @@ function wagon:get_off(seatno)
local pname = self.seatp[seatno]
local clicker = minetest.get_player_by_name(pname)
advtrains.player_to_wagon_mapping[pname]=nil
- advtrains.set_trainhud(pname, "")
+ advtrains.clear_driver_hud(pname)
if clicker then
clicker:set_detach()
clicker:set_eye_offset({x=0,y=0,z=0}, {x=0,y=0,z=0})