Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Sat Aug 18, 2018 4:52 pm

All times are UTC




Post new topic  Reply to topic  [ 15 posts ] 
Author Message
 Post subject: PaulC's NML questions
PostPosted: Sun Jan 28, 2018 3:25 am 
Offline
Director
Director
User avatar

Joined: Mon Jul 31, 2006 12:40 pm
Posts: 610
Location: Lancs, England
Trying to improve my coding skills... I've never done much with vehicles in the past and I could never wrap my head around callbacks in NFO, but now I'm working in NML and it's time to have another go. Have taken my time working through the truck/tram/train tutorials and for the most part it seemed fairly straightforward(ish), so now I'm poking around with my own code and seeing if I can make stuff work the way I want it to.

What I'm struggling with at the moment is sound effects. I want to have a vehicle make a sound every now and then as it runs, kind of like how they do in the Generic Cars grf for example. Tried adding the soundeffect callback with the following switch:

Code:
switch(FEAT_ROADVEHS, SELF, switchSoundEffect, getbits(extra_callback_info1, 0, 8)) {
   SOUND_EVENT_RUNNING: SOUND_CAR_HORN_2;
}

That sort of worked in the sense that it plays the desired sound, except it does so continually. Then I tried combining this with a random switch which I hoped woud at least make the sound intermittant:

Code:
random_switch(FEAT_ROADVEHS, SELF, switch_sounds_random) {
   1: SOUND_CAR_HORN_2;
   5: CB_RESULT_NO_SOUND;
}

But that just results in no running sound. Not entirely sure what I'm meant to be doing and I couldn't find any examples to guide me, so I'd be most grateful for any help steering me in the right direction! Calling it a day for now, will take another stab at this tomorrow.

_________________
My projects: New Town Names | Snow Aware Arctic Buildings | Custom Buildings | Mini GRFs | Bits & Bobs
Contributions: BK Enhanced Tunnel Set | Fix TTD GRF Bugs | INFRA Foundations | OpenGFX | OpenGFX+ Airports
Other stuff: The GRFs That Time Forgot! | Buildings in Glasgow

What's that in my avatar? It's the Brighton & Rottingdean Seashore Electric Railway - bonkers Victorian engineering!


Top
   
PostPosted: Sun Jan 28, 2018 3:31 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Sun Feb 21, 2010 12:15 am
Posts: 1028
Location: Fitzroy North - 96
PaulC wrote:
Code:random_switch(FEAT_ROADVEHS, SELF, switch_sounds_random) { 1: SOUND_CAR_HORN_2; 5: CB_RESULT_NO_SOUND;}But that just results in no running sound. Not entirely sure what I'm meant to be doing and I couldn't find any examples to guide me, so I'd be most grateful for any help steering me in the right direction! Calling it a day for now, will take another stab at this tomorrow.


As I understand it, such a switch would only be called once - maybe when the vehicle is built or maybe even when the game starts, I don't know. There would be nothing in the grf that would ask the switch again for a new random value, nor would it have a means to randomly be changing its value as it goes.

I would have thought there would be an in-built method for occasional sounds much like the electric arc visual effect, but maybe not - in that case you'll need something to occasionally trigger your switch and get a new value I assume.

_________________
Image
Trolleybi! Trucks and Buses -- Docklands -- Unspooled -- MLSS


Top
   
PostPosted: Sun Jan 28, 2018 7:18 am 
Offline
Tycoon
Tycoon

Joined: Sun Dec 16, 2007 10:24 pm
Posts: 1648
Location: Idaho, USA
You can make use of the animation_counter variable to trigger sound effects at set intervals.

For instance:

Code:
switch (FEAT_ROADVEHS, SELF, sirenloop1_switch, animation_counter % 32) {
   0..15:         return sound("sirenloop1.wav");
   16..31:         return CB_RESULT_NO_SOUND;
   CB_FAILED;
}


Combine with a random switch, and you can make things a bit stochastic.

_________________
Eyecandy Road Vehicles | Fake Subways | Supercheese's NewObjects

"Fashions and cultures change, but steam trains shall always be majestic."
-Professor Hershel Layton


Top
   
PostPosted: Wed Jan 31, 2018 9:03 am 
Offline
Director
Director
User avatar

Joined: Mon Jul 31, 2006 12:40 pm
Posts: 610
Location: Lancs, England
Thanks for the replies chaps, unfortunately I still haven't managed to crack it. I've adapted Supercheese's switch to make the vehicle play a sound at regular intervals, and I had no trouble combining it with my other switch. It all seems to come unstuck when I try and throw in a random switch. This is the switch combination I ended up with:

Code:
random_switch(FEAT_ROADVEHS, SELF, switch_random_sound, TRIGGER_VEHICLE_32_CALLBACK) {
   1: SOUND_CAR_HORN_2;
   7: CB_RESULT_NO_SOUND;
}

switch(FEAT_ROADVEHS, SELF, switch_car_horn_2, animation_counter % 64) {
   0..1:      return switch_random_sound;
   2..63:   return CB_RESULT_NO_SOUND;
   CB_FAILED;
}

switch(FEAT_ROADVEHS, SELF, switch_sound_effect, getbits(extra_callback_info1, 0, 8)) {
   SOUND_EVENT_START: SOUND_CAR_HORN;
   SOUND_EVENT_RUNNING: switch_car_horn_2;
}

Which is clearly wrong as the vehicle makes no sound when running. It's a non-essential feature though so I'm tempted to skip it and move on, there's only so long I can spend bashing my head against a wall. :?

_________________
My projects: New Town Names | Snow Aware Arctic Buildings | Custom Buildings | Mini GRFs | Bits & Bobs
Contributions: BK Enhanced Tunnel Set | Fix TTD GRF Bugs | INFRA Foundations | OpenGFX | OpenGFX+ Airports
Other stuff: The GRFs That Time Forgot! | Buildings in Glasgow

What's that in my avatar? It's the Brighton & Rottingdean Seashore Electric Railway - bonkers Victorian engineering!


Top
   
PostPosted: Wed Jan 31, 2018 3:50 pm 
Online
Director
Director
User avatar

Joined: Mon Apr 17, 2017 4:52 pm
Posts: 595
Location: Western Ile-de-France Region
Try playing with parent/self


Top
   
PostPosted: Sat Feb 03, 2018 5:58 pm 
Offline
Director
Director
User avatar

Joined: Mon Jul 31, 2006 12:40 pm
Posts: 610
Location: Lancs, England
Thanks for the tip. I've played around with it a bit more but still can't crack it so I'm going to set it aside for now, hopefully I can come back to it when I have a better idea of what I'm doing. I do appreciate the help though, it's all been very useful! :)

Some more questions:

1) I've coded up the disaster ufos as playable vehicles, which is rather fun! Currently I've done this by reusing the sprites from the base set, but is there any way I can leave out the sprites and just reference sprite numbers instead? Or is that not possible with vehicles?

2) I've set the following properties:

Code:
misc_flags:   bitmask(AIRCRAFT_FLAG_NO_BREAKDOWN_SMOKE);
sound_effect:   SOUND_MAGLEV;

I think I've done this right but neither works: I still get breakdown smoke and the default helicopter sound. I can change the sound by using the callback instead (though the property should work, yes?) but otherwise this has me stumped. Am I missing something?

3) Is it not possible to reference a switch from a spritegroup? I'm guessing not since NML didn't like it but this seems rather limiting.

_________________
My projects: New Town Names | Snow Aware Arctic Buildings | Custom Buildings | Mini GRFs | Bits & Bobs
Contributions: BK Enhanced Tunnel Set | Fix TTD GRF Bugs | INFRA Foundations | OpenGFX | OpenGFX+ Airports
Other stuff: The GRFs That Time Forgot! | Buildings in Glasgow

What's that in my avatar? It's the Brighton & Rottingdean Seashore Electric Railway - bonkers Victorian engineering!


Top
   
PostPosted: Sat Feb 03, 2018 6:55 pm 
Online
Director
Director
User avatar

Joined: Mon Apr 17, 2017 4:52 pm
Posts: 595
Location: Western Ile-de-France Region
1: I don't know.
2: Try doing visual_effect: return 0 in callbacks for the no breakdown smoke.
I'd call sounds through the callbacks.
3: Explain more.


Top
   
PostPosted: Sat Feb 03, 2018 7:32 pm 
Offline
Director
Director
User avatar

Joined: Mon Jul 31, 2006 12:40 pm
Posts: 610
Location: Lancs, England
Gwyd wrote:
2: Try doing visual_effect: return 0 in callbacks for the no breakdown smoke.

Hmm, visual_effect callback is only available for rvs and ships, there doesn't seem to be an equivalent for aircraft...

Quote:
3: Explain more.

I have a switch which I'm using to show an alternative spriteset when the vehicle is broken down:

Code:
switch(FEAT_AIRCRAFT, SELF, switch_small_ufo_bd, vehicle_is_broken) {
   0:   spriteset_small_ufo_mv;
   1:   spriteset_small_ufo_bd;
}

This works fine when I reference it from the graphics block. But then I tried throwing in a third spriteset for when the vehicle is loading which (so far as I can tell) requires a spritegroup, hence:

Code:
spritegroup spritegroup_small_ufo {
   loading:   spriteset_large_ufo_st;
   loaded:   switch_small_ufo_bd;
}

But nml didn't like that, it says:

Code:
@[Knmlc ERROR: "ogfx_ufo.nml", line 68: Expected a sprite set reference

Maybe I'm just going about it wrong?

_________________
My projects: New Town Names | Snow Aware Arctic Buildings | Custom Buildings | Mini GRFs | Bits & Bobs
Contributions: BK Enhanced Tunnel Set | Fix TTD GRF Bugs | INFRA Foundations | OpenGFX | OpenGFX+ Airports
Other stuff: The GRFs That Time Forgot! | Buildings in Glasgow

What's that in my avatar? It's the Brighton & Rottingdean Seashore Electric Railway - bonkers Victorian engineering!


Top
   
PostPosted: Sat Feb 03, 2018 9:19 pm 
Offline
Engineer
Engineer
User avatar

Joined: Thu Sep 14, 2017 11:59 am
Posts: 10
PaulC wrote:
Thanks for the tip. I've played around with it a bit more but still can't crack it so I'm going to set it aside for now, hopefully I can come back to it when I have a better idea of what I'm doing. I do appreciate the help though, it's all been very useful! :)

Some more questions:

1) I've coded up the disaster ufos as playable vehicles, which is rather fun! Currently I've done this by reusing the sprites from the base set, but is there any way I can leave out the sprites and just reference sprite numbers instead? Or is that not possible with vehicles?

2) I've set the following properties:

Code:
misc_flags:   bitmask(AIRCRAFT_FLAG_NO_BREAKDOWN_SMOKE);
sound_effect:   SOUND_MAGLEV;

I think I've done this right but neither works: I still get breakdown smoke and the default helicopter sound. I can change the sound by using the callback instead (though the property should work, yes?) but otherwise this has me stumped. Am I missing something?

3) Is it not possible to reference a switch from a spritegroup? I'm guessing not since NML didn't like it but this seems rather limiting.


Maybe there are different ways to replace the default sound for helicopter-type vehicles which I don't know about but I've managed to do it by setting the sound property to a sound switch in the vehicle's graphics block instead of the property block. Example:

Code:
switch(FEAT_AIRCRAFT, SELF, switch_hot_air_balloon_sound, getbits(extra_callback_info1, 0, 8)) {
    SOUND_EVENT_START: sound("sfx/balloon.wav");
}
...
...
...
item(FEAT_AIRCRAFT, item_fire_nation_balloon) {
   property {
   ...
   }
   graphics {
    default: spriteset_fire_nation_balloon;
      additional_text:   string(STR_ORIGIN, string(STR_ORIGIN_AVATAR), string(STR_INSPIRATION), string(STR_LEEG));
      sound_effect:      switch_hot_air_balloon_sound;
      rotor:             no_rotor; //empty spriteset
}


Afaik it isn't possible to use a switch in a spritegroup. Haven't tried this snippet yet but it might solve your problem:

Code:
switch(FEAT_AIRCRAFT, SELF, switch_small_ufo_bd, vehicle_is_broken) {
   0:   spritegroup_small_ufo;
   1:   spriteset_small_ufo_bd;
}

spritegroup spritegroup_small_ufo {
   loading:   spriteset_small_ufo_st;
   loaded:   spriteset_small_ufo_mv;
}


Top
   
PostPosted: Sun Feb 04, 2018 12:52 am 
Offline
Director
Director
User avatar

Joined: Mon Jul 31, 2006 12:40 pm
Posts: 610
Location: Lancs, England
Kaaskroket wrote:
Afaik it isn't possible to use a switch in a spritegroup. Haven't tried this snippet yet but it might solve your problem:

Worked a treat, thanks for the tip! :)

_________________
My projects: New Town Names | Snow Aware Arctic Buildings | Custom Buildings | Mini GRFs | Bits & Bobs
Contributions: BK Enhanced Tunnel Set | Fix TTD GRF Bugs | INFRA Foundations | OpenGFX | OpenGFX+ Airports
Other stuff: The GRFs That Time Forgot! | Buildings in Glasgow

What's that in my avatar? It's the Brighton & Rottingdean Seashore Electric Railway - bonkers Victorian engineering!


Top
   
PostPosted: Sun Feb 11, 2018 11:16 am 
Offline
Director
Director
User avatar

Joined: Mon Jul 31, 2006 12:40 pm
Posts: 610
Location: Lancs, England
Right, I have another question... :) What's the best way to go about refitting? I have a vehicle which I want to carry goods (by default) but also be refittable to mail, food and alcohol. These are the relevant bits of code I'm using to do that:

Code:
cargotable {
   BEER, // Beer
   FISH, // Fish
   FRUT, // Fruit
   GOOD // Goods
}

   refittable_cargo_classes:   bitmask(CC_EXPRESS, CC_MAIL, CC_REFRIGERATED);
   non_refittable_cargo_classes:   bitmask(CC_BULK, CC_LIQUID, CC_OVERSIZED, CC_PASSENGERS, CC_PIECE_GOODS);
   cargo_allow_refit:      [BEER];
   cargo_disallow_refit:      [FISH, FRUT];
   default_cargo_type:      GOOD;

The above does what I want but I don't know if it looks good, there seem to be a number of different ways to go about doing the same thing. If I'm reading it right, NMLTutorial/Cargotable seems to be suggesting that I include all known cargo labels in my table and specify each one individually with the allow/disallow properties. Is that right? It seems a bit longwinded.

_________________
My projects: New Town Names | Snow Aware Arctic Buildings | Custom Buildings | Mini GRFs | Bits & Bobs
Contributions: BK Enhanced Tunnel Set | Fix TTD GRF Bugs | INFRA Foundations | OpenGFX | OpenGFX+ Airports
Other stuff: The GRFs That Time Forgot! | Buildings in Glasgow

What's that in my avatar? It's the Brighton & Rottingdean Seashore Electric Railway - bonkers Victorian engineering!


Top
   
PostPosted: Sun Feb 11, 2018 4:05 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Sun Feb 21, 2010 12:15 am
Posts: 1028
Location: Fitzroy North - 96
PaulC wrote:
Right, I have another question... :) What's the best way to go about refitting? I have a vehicle which I want to carry goods (by default) but also be refittable to mail, food and alcohol. These are the relevant bits of code I'm using to do that:

Code:
cargotable {
   BEER, // Beer
   FISH, // Fish
   FRUT, // Fruit
   GOOD // Goods
}

   refittable_cargo_classes:   bitmask(CC_EXPRESS, CC_MAIL, CC_REFRIGERATED);
   non_refittable_cargo_classes:   bitmask(CC_BULK, CC_LIQUID, CC_OVERSIZED, CC_PASSENGERS, CC_PIECE_GOODS);
   cargo_allow_refit:      [BEER];
   cargo_disallow_refit:      [FISH, FRUT];
   default_cargo_type:      GOOD;

The above does what I want but I don't know if it looks good, there seem to be a number of different ways to go about doing the same thing. If I'm reading it right, NMLTutorial/Cargotable seems to be suggesting that I include all known cargo labels in my table and specify each one individually with the allow/disallow properties. Is that right? It seems a bit longwinded.



My approach is to specify the classes that I want to allow and disallow, and then only use the specific labels for exceptions, or cases where a cargo might have some confusing classes assigned to it.

_________________
Image
Trolleybi! Trucks and Buses -- Docklands -- Unspooled -- MLSS


Top
   
PostPosted: Tue Feb 13, 2018 11:01 pm 
Offline
Director
Director
User avatar

Joined: Mon Jul 31, 2006 12:40 pm
Posts: 610
Location: Lancs, England
supermop wrote:
My approach is to specify the classes that I want to allow and disallow, and then only use the specific labels for exceptions, or cases where a cargo might have some confusing classes assigned to it.

I guess that's more or less what I'm already doing. I'll probably just stick with it then...

_________________
My projects: New Town Names | Snow Aware Arctic Buildings | Custom Buildings | Mini GRFs | Bits & Bobs
Contributions: BK Enhanced Tunnel Set | Fix TTD GRF Bugs | INFRA Foundations | OpenGFX | OpenGFX+ Airports
Other stuff: The GRFs That Time Forgot! | Buildings in Glasgow

What's that in my avatar? It's the Brighton & Rottingdean Seashore Electric Railway - bonkers Victorian engineering!


Top
   
PostPosted: Fri Apr 13, 2018 4:28 pm 
Offline
Tycoon
Tycoon

Joined: Wed Jan 17, 2007 12:14 am
Posts: 7087
PaulC wrote:
Then I tried combining this with a random switch which I hoped woud at least make the sound intermittant:

Code:
random_switch(FEAT_ROADVEHS, SELF, switch_sounds_random) {
   1: SOUND_CAR_HORN_2;
   5: CB_RESULT_NO_SOUND;
}

But that just results in no running sound.

Just chiming in to explain why this doesn't work:

a random switch is based upon random bits which are stored in the vehicle and initialized at vehicle construction, and then always result in the same choice. this is meant for example for picking a random colour. so what this switch does is you have a 1 in 6 chance that a vehicle makes sound all the time, or 5 in 6 that it does no sound, ever. there are also "triggers" to reinitialize the random bits, but those are a bit tricky to use if your random switch is not in the default graphics chain. (there's a special callback for that). even then, that will result in periods of making sound all the time and making no sound, depending on how often this trigger callaback is called, so the other method with using the motion counter is probably also needed

_________________
You might not exactly be interested in Ferion, but if you are, have fun :)


Top
   
PostPosted: Fri Apr 13, 2018 4:37 pm 
Offline
Tycoon
Tycoon

Joined: Wed Jan 17, 2007 12:14 am
Posts: 7087
PaulC wrote:
Right, I have another question... :) What's the best way to go about refitting? I have a vehicle which I want to carry goods (by default) but also be refittable to mail, food and alcohol. These are the relevant bits of code I'm using to do that:

Code:
   non_refittable_cargo_classes:   bitmask(CC_BULK, CC_LIQUID, CC_OVERSIZED, CC_PASSENGERS, CC_PIECE_GOODS);


you should be a bit careful with explicitly listing classes that are not refittable, because you easily run into cases where a cargo with two classes cannot be transported with any vehicle. most of the times you can get away with leaving this property empty

_________________
You might not exactly be interested in Ferion, but if you are, have fun :)


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 15 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2018 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2018.
Hosted by Zernebok Hosting.