aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2017-12-06 13:23:55 +0100
committerorwell96 <orwell@bleipb.de>2017-12-06 13:23:55 +0100
commitdc67ff7226a2836863a0e709a5b81c90c977f288 (patch)
treed1743a0f59fbc2ed4b4ab8359b1a2bf93c621c6a
parentbe8aca9fb8ee406d4728c470a1340be8f418e45f (diff)
downloadadvtrains-dc67ff7226a2836863a0e709a5b81c90c977f288.tar.gz
advtrains-dc67ff7226a2836863a0e709a5b81c90c977f288.tar.bz2
advtrains-dc67ff7226a2836863a0e709a5b81c90c977f288.zip
Implement sound api and some sounds
- Level crossing bell - Horns - Subway train driving and door sounds ...to be continued...
-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
-rw-r--r--advtrains_train_industrial/init.lua1
-rw-r--r--advtrains_train_industrial/sounds/advtrains_industrial_horn.oggbin0 -> 24325 bytes
-rw-r--r--advtrains_train_japan/init.lua1
-rw-r--r--advtrains_train_japan/sounds/advtrains_japan_horn.oggbin0 -> 39307 bytes
-rwxr-xr-xadvtrains_train_steam/init.lua2
-rw-r--r--advtrains_train_steam/sounds/advtrains_steam_whistle.oggbin0 -> 56532 bytes
-rw-r--r--advtrains_train_subway/init.lua30
-rw-r--r--advtrains_train_subway/sounds/advtrains_subway_arrive.oggbin0 -> 22658 bytes
-rw-r--r--advtrains_train_subway/sounds/advtrains_subway_dclose.oggbin0 -> 14298 bytes
-rw-r--r--advtrains_train_subway/sounds/advtrains_subway_depart.oggbin0 -> 39161 bytes
-rw-r--r--advtrains_train_subway/sounds/advtrains_subway_dopen.oggbin0 -> 14307 bytes
-rw-r--r--advtrains_train_subway/sounds/advtrains_subway_horn.oggbin0 -> 14370 bytes
-rw-r--r--advtrains_train_subway/sounds/advtrains_subway_loop.oggbin0 -> 19691 bytes
-rw-r--r--readme.txt7
19 files changed, 72 insertions, 7 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
diff --git a/advtrains_train_industrial/init.lua b/advtrains_train_industrial/init.lua
index ebf8d65..42804f3 100644
--- a/advtrains_train_industrial/init.lua
+++ b/advtrains_train_industrial/init.lua
@@ -39,6 +39,7 @@ advtrains.register_wagon("engine_industrial", {
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("Industrial Train Engine"), "advtrains_engine_industrial_inv.png")
advtrains.register_wagon("wagon_tank", {
mesh="advtrains_wagon_tank.b3d",
diff --git a/advtrains_train_industrial/sounds/advtrains_industrial_horn.ogg b/advtrains_train_industrial/sounds/advtrains_industrial_horn.ogg
new file mode 100644
index 0000000..2bc42c2
--- /dev/null
+++ b/advtrains_train_industrial/sounds/advtrains_industrial_horn.ogg
Binary files differ
diff --git a/advtrains_train_japan/init.lua b/advtrains_train_japan/init.lua
index 8816db3..6cf6c6d 100644
--- a/advtrains_train_japan/init.lua
+++ b/advtrains_train_japan/init.lua
@@ -72,6 +72,7 @@ advtrains.register_wagon("engine_japan", {
is_locomotive=true,
collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
drops={"default:steelblock 4"},
+ horn_sound = "advtrains_japan_horn",
}, S("Japanese Train Engine"), "advtrains_engine_japan_inv.png")
advtrains.register_wagon("wagon_japan", {
diff --git a/advtrains_train_japan/sounds/advtrains_japan_horn.ogg b/advtrains_train_japan/sounds/advtrains_japan_horn.ogg
new file mode 100644
index 0000000..f7ddb14
--- /dev/null
+++ b/advtrains_train_japan/sounds/advtrains_japan_horn.ogg
Binary files differ
diff --git a/advtrains_train_steam/init.lua b/advtrains_train_steam/init.lua
index 37c63a0..b8d9adb 100755
--- a/advtrains_train_steam/init.lua
+++ b/advtrains_train_steam/init.lua
@@ -71,6 +71,7 @@ advtrains.register_wagon("newlocomotive", {
})
end,
drops={"default:steelblock 4"},
+ horn_sound = "advtrains_steam_whistle",
}, S("Steam Engine"), "advtrains_engine_steam_inv.png")
advtrains.register_wagon("detailed_steam_engine", {
@@ -139,6 +140,7 @@ advtrains.register_wagon("detailed_steam_engine", {
})
end,
drops={"default:steelblock 4"},
+ horn_sound = "advtrains_steam_whistle",
}, S("Detailed Steam Engine"), "advtrains_detailed_engine_steam_inv.png")
advtrains.register_wagon("wagon_default", {
diff --git a/advtrains_train_steam/sounds/advtrains_steam_whistle.ogg b/advtrains_train_steam/sounds/advtrains_steam_whistle.ogg
new file mode 100644
index 0000000..42172a2
--- /dev/null
+++ b/advtrains_train_steam/sounds/advtrains_steam_whistle.ogg
Binary files differ
diff --git a/advtrains_train_subway/init.lua b/advtrains_train_subway/init.lua
index e3c73c9..f8e5e3b 100644
--- a/advtrains_train_subway/init.lua
+++ b/advtrains_train_subway/init.lua
@@ -59,11 +59,13 @@ advtrains.register_wagon("subway_wagon", {
doors={
open={
[-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={
[-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},
@@ -73,10 +75,26 @@ advtrains.register_wagon("subway_wagon", {
collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
is_locomotive=true,
drops={"default:steelblock 4"},
- --custom_on_activate = function(self, dtime_s)
- -- atprint("subway custom_on_activate")
- -- self.object:set_animation({x=1,y=80}, 15, 0, true)
- --end,
+ horn_sound = "advtrains_subway_horn",
+ custom_on_velocity_change = function(self, velocity, old_velocity)
+ if old_velocity == 0 and velocity > 0 then
+ 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")
--wagons
diff --git a/advtrains_train_subway/sounds/advtrains_subway_arrive.ogg b/advtrains_train_subway/sounds/advtrains_subway_arrive.ogg
new file mode 100644
index 0000000..71bb90e
--- /dev/null
+++ b/advtrains_train_subway/sounds/advtrains_subway_arrive.ogg
Binary files differ
diff --git a/advtrains_train_subway/sounds/advtrains_subway_dclose.ogg b/advtrains_train_subway/sounds/advtrains_subway_dclose.ogg
new file mode 100644
index 0000000..ffbc6ed
--- /dev/null
+++ b/advtrains_train_subway/sounds/advtrains_subway_dclose.ogg
Binary files differ
diff --git a/advtrains_train_subway/sounds/advtrains_subway_depart.ogg b/advtrains_train_subway/sounds/advtrains_subway_depart.ogg
new file mode 100644
index 0000000..aca8cbc
--- /dev/null
+++ b/advtrains_train_subway/sounds/advtrains_subway_depart.ogg
Binary files differ
diff --git a/advtrains_train_subway/sounds/advtrains_subway_dopen.ogg b/advtrains_train_subway/sounds/advtrains_subway_dopen.ogg
new file mode 100644
index 0000000..f1322df
--- /dev/null
+++ b/advtrains_train_subway/sounds/advtrains_subway_dopen.ogg
Binary files differ
diff --git a/advtrains_train_subway/sounds/advtrains_subway_horn.ogg b/advtrains_train_subway/sounds/advtrains_subway_horn.ogg
new file mode 100644
index 0000000..f4519a3
--- /dev/null
+++ b/advtrains_train_subway/sounds/advtrains_subway_horn.ogg
Binary files differ
diff --git a/advtrains_train_subway/sounds/advtrains_subway_loop.ogg b/advtrains_train_subway/sounds/advtrains_subway_loop.ogg
new file mode 100644
index 0000000..1a7021a
--- /dev/null
+++ b/advtrains_train_subway/sounds/advtrains_subway_loop.ogg
Binary files differ
diff --git a/readme.txt b/readme.txt
index cb9173e..110bdef 100644
--- a/readme.txt
+++ b/readme.txt
@@ -24,6 +24,13 @@ Inventory images : mbb
Small code contributions : NaruTrey
Major code contributions : gpcf
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.
You can see this mod in action on Linuxworks Next Generation server.