aboutsummaryrefslogtreecommitdiff
path: root/advtrains
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains')
-rw-r--r--advtrains/api_doc.txt6
-rw-r--r--advtrains/nodedb.lua2
-rw-r--r--advtrains/signals.lua16
-rw-r--r--advtrains/sounds/advtrains_crossing_bell.oggbin0 -> 47722 bytes
-rw-r--r--advtrains/wagons.lua14
5 files changed, 37 insertions, 1 deletions
diff --git a/advtrains/api_doc.txt b/advtrains/api_doc.txt
index e86f16b..c944e30 100644
--- a/advtrains/api_doc.txt
+++ b/advtrains/api_doc.txt
@@ -57,10 +57,14 @@ advtrains.register_wagon(name, prototype, description, inventory_image)
open={
[-1]={frames={x=0, y=20}, time=1}, -- open left 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={
[-1]={frames={x=20, y=40}, time=1}, -- close left 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 }
@@ -77,6 +81,8 @@ advtrains.register_wagon(name, prototype, description, inventory_image)
extent_v = 2,
^- 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.
+ 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"}
^- List of itemstrings what to drop when the wagon is destroyed
diff --git a/advtrains/nodedb.lua b/advtrains/nodedb.lua
index 45a51fe..2f014f8 100644
--- a/advtrains/nodedb.lua
+++ b/advtrains/nodedb.lua
@@ -262,7 +262,7 @@ ndb.restore_all = function()
end
else
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
diff --git a/advtrains/signals.lua b/advtrains/signals.lua
index 62b9f03..a42f5e7 100644
--- a/advtrains/signals.lua
+++ b/advtrains/signals.lua
@@ -225,3 +225,19 @@ minetest.register_node("advtrains:across_on", {
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,
+ }
+)
diff --git a/advtrains/sounds/advtrains_crossing_bell.ogg b/advtrains/sounds/advtrains_crossing_bell.ogg
new file mode 100644
index 0000000..74df669
--- /dev/null
+++ b/advtrains/sounds/advtrains_crossing_bell.ogg
Binary files differ
diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua
index 4306b50..b30d3d4 100644
--- a/advtrains/wagons.lua
+++ b/advtrains/wagons.lua
@@ -270,6 +270,18 @@ function wagon:on_step(dtime)
if has_driverstand then
--regular driver stand controls
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
-- 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])
@@ -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 +-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.doors.open.sound then minetest.sound_play(self.doors.open.sound, {object = self.object}) end
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
+ 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
self.object:set_animation(at.frames, at.speed or 15, at.blend or 0, false)
self.door_state = 0