Compare commits

...

5 Commits

Author SHA1 Message Date
mbb 875eb90acb Improve textures and models of industrial train and add new more powerful industrial engine 2017-12-12 22:28:57 +01:00
orwell96 e9c51dfab4
Make sure an old_velocity is always passed
Fixes crash on placing a new subway wagon
2017-12-06 21:27:04 +01:00
orwell96 dc67ff7226 Implement sound api and some sounds
- Level crossing bell
- Horns
- Subway train driving and door sounds
...to be continued...
2017-12-06 13:23:55 +01:00
orwell96 be8aca9fb8 Remove zip file and makefile
These are not needed anyway
2017-11-29 17:23:47 +01:00
orwell96 83df46d786 Change name of update_animation function
I will use this for sounds, and so it needs to be changed to a more general name
2017-11-29 17:20:46 +01:00
29 changed files with 127 additions and 23 deletions

View File

@ -1,4 +0,0 @@
tarball: clean
which zip && zip -r advtrains.zip . -x "assets*" -x "*.zip" -x "*.git*"
clean:
rm -f advtrains.zip

Binary file not shown.

View File

@ -57,10 +57,14 @@ advtrains.register_wagon(name, prototype, description, inventory_image)
open={ open={
[-1]={frames={x=0, y=20}, time=1}, -- open left doors [-1]={frames={x=0, y=20}, time=1}, -- open left doors
[1]={frames={x=40, y=60}, time=1} -- open right doors [1]={frames={x=40, y=60}, time=1} -- open right doors
sound = <simpleSoundSpec>
^- The sound file of the doors opening. If none is specified, nothing is played.
}, },
close={ close={
[-1]={frames={x=20, y=40}, time=1}, -- close left doors [-1]={frames={x=20, y=40}, time=1}, -- close left doors
[1]={frames={x=60, y=80}, time=1} -- close right doors [1]={frames={x=60, y=80}, time=1} -- close right doors
sound = <simpleSoundSpec>
^- The sound file of the doors closing. If none is specified, nothing is played.
} }
}, },
door_entry={ 1.5, -1.5 } door_entry={ 1.5, -1.5 }
@ -77,6 +81,8 @@ advtrains.register_wagon(name, prototype, description, inventory_image)
extent_v = 2, extent_v = 2,
^- Determines the collision box extent in y direction. Defaults to 2 (=3). ^- Determines the collision box extent in y direction. Defaults to 2 (=3).
^- The actual bounding box size is extent_v+1, so 0 means 1, 1 means 2, 2 means 3 a.s.o. ^- The actual bounding box size is extent_v+1, so 0 means 1, 1 means 2, 2 means 3 a.s.o.
horn_sound = <simpleSoundSpec>,
^- The sound file of the horn. If none is specified, this wagon can't sound a horn. The specified sound file will be looped.
drops = {"default:steelblock 3"} drops = {"default:steelblock 3"}
^- List of itemstrings what to drop when the wagon is destroyed ^- List of itemstrings what to drop when the wagon is destroyed
@ -99,8 +105,9 @@ advtrains.register_wagon(name, prototype, description, inventory_image)
^- optional: Execute custom code on every step ^- optional: Execute custom code on every step
custom_on_activate = function(self, dtime_s) end custom_on_activate = function(self, dtime_s) end
^- optional: Execute custom code on activate. Staticdata does not need to be saved and restored since all properties written in 'self' are preserved over unloads. ^- optional: Execute custom code on activate. Staticdata does not need to be saved and restored since all properties written in 'self' are preserved over unloads.
update_animation = function(self, velocity) end custom_on_velocity_change = function(self, velocity, old_velocity) end
^- optional: Function that is called whenever the train's velocity changes or every 2 seconds. Used to call 'self.object:update_animation()' if needed. ^- optional: Function that is called whenever the train's velocity changes or every 2 seconds. Used to call 'self.object:update_animation()' if needed.
^- for compatibility reasons the name 'update_animation' for this function is still supported.
} }
@ -164,4 +171,4 @@ minetest.register_node(nodename, {
on_train_leave=function(pos, train_id) end on_train_leave=function(pos, train_id) end
^- called when a train leaves the rail ^- called when a train leaves the rail
} }
}) })

View File

@ -262,7 +262,7 @@ ndb.restore_all = function()
end end
else else
ndb.clear(pos) ndb.clear(pos)
atwarn("Found ghost node (former",ndbnode.name,") @",pos,"deleting") atwarn("Found ghost node (former",ndbnode and ndbnode.name,") @",pos,"deleting")
end end
end end
end end

View File

@ -225,3 +225,19 @@ minetest.register_node("advtrains:across_on", {
end end
end, end,
}) })
minetest.register_abm(
{
label = "Sound for Level Crossing",
nodenames = {"advtrains:across_on"},
interval = 3,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
minetest.sound_play("advtrains_crossing_bell", {
pos = pos,
gain = 1.0, -- default
max_hear_distance = 16, -- default, uses an euclidean metric
})
end,
}
)

Binary file not shown.

View File

@ -270,6 +270,18 @@ function wagon:on_step(dtime)
if has_driverstand then if has_driverstand then
--regular driver stand controls --regular driver stand controls
advtrains.on_control_change(pc, self:train(), self.wagon_flipped) advtrains.on_control_change(pc, self:train(), self.wagon_flipped)
--sound horn when required
if self.horn_sound and pc.aux1 and not pc.sneak and not self.horn_handle then
self.horn_handle = minetest.sound_play(self.horn_sound, {
object = self.object,
gain = 1.0, -- default
max_hear_distance = 128, -- default, uses an euclidean metric
loop = true,
})
elseif not pc.aux1 and self.horn_handle then
minetest.sound_stop(self.horn_handle)
self.horn_handle = nil
end
else else
-- If on a passenger seat and doors are open, get off when W or D pressed. -- If on a passenger seat and doors are open, get off when W or D pressed.
local pass = self.seatp[seatno] and minetest.get_player_by_name(self.seatp[seatno]) local pass = self.seatp[seatno] and minetest.get_player_by_name(self.seatp[seatno])
@ -322,10 +334,12 @@ function wagon:on_step(dtime)
-- if changed from 0 to +-1, play open anim. if changed from +-1 to 0, play close. -- 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 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 if self.door_state == 0 then
if self.doors.open.sound then minetest.sound_play(self.doors.open.sound, {object = self.object}) end
at=self.doors.open[dstate] at=self.doors.open[dstate]
self.object:set_animation(at.frames, at.speed or 15, at.blend or 0, false) self.object:set_animation(at.frames, at.speed or 15, at.blend or 0, false)
self.door_state = dstate self.door_state = dstate
else else
if self.doors.close.sound then minetest.sound_play(self.doors.close.sound, {object = self.object}) end
at=self.doors.close[self.door_state or 1]--in case it has not been set yet 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.object:set_animation(at.frames, at.speed or 15, at.blend or 0, false)
self.door_state = 0 self.door_state = 0
@ -502,12 +516,16 @@ function wagon:on_step(dtime)
self.object:setyaw(yaw) self.object:setyaw(yaw)
self.updatepct_timer=2 self.updatepct_timer=2
if self.update_animation then if self.update_animation then
self:update_animation(gp.velocity) self:update_animation(gp.velocity, self.old_velocity)
end
if self.custom_on_velocity_change then
self:custom_on_velocity_change(gp.velocity, self.old_velocity or 0)
end end
end end
self.old_velocity_vector=velocityvec self.old_velocity_vector=velocityvec
self.old_velocity = gp.velocity
self.old_acceleration_vector=accelerationvec self.old_acceleration_vector=accelerationvec
self.old_yaw=yaw self.old_yaw=yaw
atprintbm("wagon step", t) atprintbm("wagon step", t)

View File

@ -13,22 +13,23 @@ advtrains.register_wagon("engine_industrial", {
max_speed=20, max_speed=20,
seats = { seats = {
{ {
name=S("Driver Stand (left)"), name=S("Driver Stand (right)"),
attach_offset={x=-5, y=10, z=-10}, attach_offset={x=5, y=7, z=-8},
view_offset={x=0, y=10, z=0}, view_offset={x=5.2, y=-4, z=0},
driving_ctrl_access=true, driving_ctrl_access=true,
group = "dstand", group = "dstand",
}, },
{ {
name=S("Driver Stand (right)"), name=S("Driver Stand (left)"),
attach_offset={x=5, y=10, z=-10}, attach_offset={x=5, y=7, z=-8},
view_offset={x=0, y=10, z=0}, view_offset={x=-5.2, y=-4, z=0},
driving_ctrl_access=true, driving_ctrl_access=true,
group = "dstand", group = "dstand",
}, },
}, },
seat_groups = { seat_groups = {
dstand={ dstand={
name = "Driver Stand", name = "Driver Stand",
access_to = {}, access_to = {},
}, },
@ -39,7 +40,45 @@ advtrains.register_wagon("engine_industrial", {
is_locomotive=true, is_locomotive=true,
collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0}, collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
drops={"default:steelblock 4"}, drops={"default:steelblock 4"},
horn_sound = "advtrains_industrial_horn",
}, S("Industrial Train Engine"), "advtrains_engine_industrial_inv.png") }, S("Industrial Train Engine"), "advtrains_engine_industrial_inv.png")
--big--
advtrains.register_wagon("engine_industrial_big", {
mesh="advtrains_engine_industrial_big.b3d",
textures = {"advtrains_engine_industrial_big.png"},
drives_on={default=true},
max_speed=30,
seats = {
{
name=S("Driver Stand (right)"),
attach_offset={x=5, y=7, z=20},
view_offset={x=5.2, y=-4, z=11},
driving_ctrl_access=true,
group = "dstand",
},
{
name=S("Driver Stand (left)"),
attach_offset={x=5, y=7, z=-8},
view_offset={x=-5.2, y=-4, z=0},
driving_ctrl_access=true,
group = "dstand",
},
},
seat_groups = {
dstand={
name = "Driver Stand",
access_to = {},
},
},
assign_to_seat_group = {"dstand"},
visual_size = {x=1, y=1},
wagon_span=4,
is_locomotive=true,
collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
drops={"default:steelblock 4"},
horn_sound = "advtrains_industrial_horn",
}, S("Big Industrial Train Engine"), "advtrains_engine_industrial_inv.png")
advtrains.register_wagon("wagon_tank", { advtrains.register_wagon("wagon_tank", {
mesh="advtrains_wagon_tank.b3d", mesh="advtrains_wagon_tank.b3d",
textures = {"advtrains_wagon_tank.png"}, textures = {"advtrains_wagon_tank.png"},

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -72,6 +72,7 @@ advtrains.register_wagon("engine_japan", {
is_locomotive=true, is_locomotive=true,
collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0}, collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
drops={"default:steelblock 4"}, drops={"default:steelblock 4"},
horn_sound = "advtrains_japan_horn",
}, S("Japanese Train Engine"), "advtrains_engine_japan_inv.png") }, S("Japanese Train Engine"), "advtrains_engine_japan_inv.png")
advtrains.register_wagon("wagon_japan", { advtrains.register_wagon("wagon_japan", {

Binary file not shown.

View File

@ -37,7 +37,7 @@ advtrains.register_wagon("newlocomotive", {
visual_size = {x=1, y=1}, visual_size = {x=1, y=1},
wagon_span=2.3, wagon_span=2.3,
collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0}, collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
update_animation=function(self, velocity) custom_on_velocity_change=function(self, velocity)
if self.old_anim_velocity~=advtrains.abs_ceil(velocity) then if self.old_anim_velocity~=advtrains.abs_ceil(velocity) then
self.object:set_animation({x=1,y=80}, advtrains.abs_ceil(velocity)*15, 0, true) self.object:set_animation({x=1,y=80}, advtrains.abs_ceil(velocity)*15, 0, true)
self.old_anim_velocity=advtrains.abs_ceil(velocity) self.old_anim_velocity=advtrains.abs_ceil(velocity)
@ -71,6 +71,7 @@ advtrains.register_wagon("newlocomotive", {
}) })
end, end,
drops={"default:steelblock 4"}, drops={"default:steelblock 4"},
horn_sound = "advtrains_steam_whistle",
}, S("Steam Engine"), "advtrains_engine_steam_inv.png") }, S("Steam Engine"), "advtrains_engine_steam_inv.png")
advtrains.register_wagon("detailed_steam_engine", { advtrains.register_wagon("detailed_steam_engine", {
@ -105,7 +106,7 @@ advtrains.register_wagon("detailed_steam_engine", {
visual_size = {x=1, y=1}, visual_size = {x=1, y=1},
wagon_span=2.05, wagon_span=2.05,
collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0}, collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
update_animation=function(self, velocity) custom_on_velocity_change=function(self, velocity)
if self.old_anim_velocity~=advtrains.abs_ceil(velocity) then if self.old_anim_velocity~=advtrains.abs_ceil(velocity) then
self.object:set_animation({x=1,y=80}, advtrains.abs_ceil(velocity)*15, 0, true) self.object:set_animation({x=1,y=80}, advtrains.abs_ceil(velocity)*15, 0, true)
self.old_anim_velocity=advtrains.abs_ceil(velocity) self.old_anim_velocity=advtrains.abs_ceil(velocity)
@ -139,6 +140,7 @@ advtrains.register_wagon("detailed_steam_engine", {
}) })
end, end,
drops={"default:steelblock 4"}, drops={"default:steelblock 4"},
horn_sound = "advtrains_steam_whistle",
}, S("Detailed Steam Engine"), "advtrains_detailed_engine_steam_inv.png") }, S("Detailed Steam Engine"), "advtrains_detailed_engine_steam_inv.png")
advtrains.register_wagon("wagon_default", { advtrains.register_wagon("wagon_default", {

View File

@ -59,11 +59,13 @@ advtrains.register_wagon("subway_wagon", {
doors={ doors={
open={ open={
[-1]={frames={x=0, y=20}, time=1}, [-1]={frames={x=0, y=20}, time=1},
[1]={frames={x=40, y=60}, time=1} [1]={frames={x=40, y=60}, time=1},
sound = "advtrains_subway_dopen",
}, },
close={ close={
[-1]={frames={x=20, y=40}, time=1}, [-1]={frames={x=20, y=40}, time=1},
[1]={frames={x=60, y=80}, time=1} [1]={frames={x=60, y=80}, time=1},
sound = "advtrains_subway_dclose",
} }
}, },
door_entry={-1, 1}, door_entry={-1, 1},
@ -73,10 +75,26 @@ advtrains.register_wagon("subway_wagon", {
collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0}, collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
is_locomotive=true, is_locomotive=true,
drops={"default:steelblock 4"}, drops={"default:steelblock 4"},
--custom_on_activate = function(self, dtime_s) horn_sound = "advtrains_subway_horn",
-- atprint("subway custom_on_activate") custom_on_velocity_change = function(self, velocity, old_velocity)
-- self.object:set_animation({x=1,y=80}, 15, 0, true) if old_velocity == 0 and velocity > 0 then
--end, minetest.sound_play("advtrains_subway_depart", {object = self.object})
end
if velocity < 2 and (old_velocity >= 2 or old_velocity == velocity) and not self.sound_arrive_handle then
self.sound_arrive_handle = minetest.sound_play("advtrains_subway_arrive", {object = self.object})
elseif (velocity > old_velocity) and self.sound_arrive_handle then
minetest.sound_stop(self.sound_arrive_handle)
self.sound_arrive_handle = nil
end
if velocity > 0 and not self.sound_loop_handle then
self.sound_loop_handle = minetest.sound_play({name="advtrains_subway_loop", gain=0.3}, {object = self.object, loop=true})
elseif velocity==0 then
if self.sound_loop_handle then
minetest.sound_stop(self.sound_loop_handle)
self.sound_loop_handle = nil
end
end
end,
}, S("Subway Passenger Wagon"), "advtrains_subway_wagon_inv.png") }, S("Subway Passenger Wagon"), "advtrains_subway_wagon_inv.png")
--wagons --wagons

View File

@ -24,6 +24,13 @@ Inventory images : mbb
Small code contributions : NaruTrey Small code contributions : NaruTrey
Major code contributions : gpcf Major code contributions : gpcf
Mod Description : hajo Mod Description : hajo
Sounds:
advtrains_crossing_bell : Codesound
advtrains_japan_horn : Codesound
advtrains_steam_whistle : googol
advtrains_subway_horn : https://freesound.org/people/Mullumbimby/sounds/385283/
advtrains_subway_* : Gabriel (gpcf, gbl08ma)
If I forgot someone please punish me for that. If I forgot someone please punish me for that.
You can see this mod in action on Linuxworks Next Generation server. You can see this mod in action on Linuxworks Next Generation server.