Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Wed Sep 26, 2018 5:49 am

All times are UTC




Post new topic  Reply to topic  [ 19 posts ] 
Author Message
PostPosted: Mon May 22, 2017 9:31 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Mon May 25, 2015 9:09 am
Posts: 316
Location: The Netherlands
Hello,
I am currently working on a set of freight locomotives and wagons.
I already have several passenger cars, where I have set which cars can have extra passenger carriages attached. For this I use the following code:

[+] Spoiler
Code:
switch (FEAT_TRAINS, PARENT, CAN_ATTACH, vehicle_type_id) {
   ITEM_HSST03         :string(STR_CANNOT_CONNECT);
   ITEM_HSST04         :string(STR_CANNOT_CONNECT);
   ITEM_HSST05         :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   ITEM_HSST100L      :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   ITEM_HSST100S      :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   ITEM_LINIMO         :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   
   ITEM_M01         :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   ITEM_M80         :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   ITEM_M70         :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   ITEM_E01         :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;

   ITEM_TRANSRAPID05   :string(STR_CANNOT_CONNECT);
   ITEM_TRANSRAPID06   :string(STR_CANNOT_CONNECT);
   ITEM_TRANSRAPID07   :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   ITEM_TRANSRAPID08   :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   ITEM_TRANSRAPID09   :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;

   ITEM_DMV92         :string(STR_CANNOT_CONNECT);
   ITEM_HML03         :string(STR_CANNOT_CONNECT);
   ITEM_UTM01         :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   ITEM_UTM02         :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   ITEM_ECOBEE         :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;

   ITEM_MLX0101      :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   ITEM_MLX01901      :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   ITEM_L0            :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   
   ITEM_CFC01         :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   ITEM_CMS02         :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   ITEM_CMS03A         :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   ITEM_WINDCHASER      :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   ITEM_ZHUIFENGZHE   :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   ITEM_LINGLONGHAO   :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   
   ITEM_TP01         :string(STR_CANNOT_CONNECT);
   ITEM_TP05         :string(STR_CANNOT_CONNECT);
   
   ITEM_SUMA550      :string(STR_CANNOT_CONNECT);
   ITEM_BIRMAG         :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   ITEM_COBRA         :CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES;
   string(STR_CANNOT_CONNECT);
}
switch(FEAT_TRAINS, PARENT, switch_CAN_ATTACH, grfid) {
   str2number("EN\01\01"): return CAN_ATTACH;
   string(STR_CANNOT_CONNECT);
}


The passenger wagon has the name: "ITEM_PASS"
and an example freight wagon has the name "ITEM_ECCO_WAG"

I would like to know how I would have to change this code so I can separately say which wagons I can attach to which trains.
I tried to look into how the 2CC set handled this, but I didn't understand where their code was going.

_________________
No pics no clicks. Seriously.
ImageImageImageImageImageImage


Top
   
PostPosted: Tue May 23, 2017 6:06 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Sat Aug 16, 2008 10:26 pm
Posts: 3828
Skype: neko-master
Location: Oshawa, Ontario, CANADA
I would kind of like to know how that works as I've had to disable the "can attach" wagon feature in my 2cc code for NARS ADD-ON Set 2cc

_________________
Image Proud Canadian Image
Nekomasters Projects! (Downloads available on BaNaNaS!) \(>^w^<)/
# NARS ADD-ON SET 2CC | 2cc Rapid Transit For Me! (2ccRTFM) | 2cc Wagons In NML (2ccWIN)
# NML Category System (Organize your GRFS!) <- TT-Forums Exclusive Download!


Top
   
PostPosted: Tue May 23, 2017 3:10 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Mon May 25, 2015 9:09 am
Posts: 316
Location: The Netherlands
NekoMaster wrote:
I would kind of like to know how that works as I've had to disable the "can attach" wagon feature in my 2cc code for NARS ADD-ON Set 2cc

That's odd.

I really just do:
Code:
   graphics {
      default: SPRITEGROUP_LINIMO; // Use this group
      purchase: SPRITESET_PURCH_LINIMO; // Use this set for the menu
      can_attach_wagon: switch_CAN_ATTACH;
   }


But with this it's whether I can attach any wagon, or nothing at all.

_________________
No pics no clicks. Seriously.
ImageImageImageImageImageImage


Top
   
PostPosted: Tue May 23, 2017 7:05 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Wed Nov 07, 2007 10:44 pm
Posts: 9036
Location: Sol d
Erato wrote:
NekoMaster wrote:
I would kind of like to know how that works as I've had to disable the "can attach" wagon feature in my 2cc code for NARS ADD-ON Set 2cc

That's odd.

I really just do:
Code:
   graphics {
      default: SPRITEGROUP_LINIMO; // Use this group
      purchase: SPRITESET_PURCH_LINIMO; // Use this set for the menu
      can_attach_wagon: switch_CAN_ATTACH;
   }


But with this it's whether I can attach any wagon, or nothing at all.


Of course. But the important part happens in switch_CAN_ATTACH which you didn't show ;) And there you can also decide which wagon can be attached

Code:
switch (FEAT_TRAINS, SELF, switch_CAN_ATTACH, vehicle_type_id) {
   one_allowed_wagon_id: CB_RESULT_ATTACH_ALLOW;
   another_allowed_wagon_id: CB_RESULT_ATTACH_ALLOW;
   return CB_RESULT_ATTACH_DISALLOW
}


However I'd like to encourage you to not be strict with that, but resort to hints for the player in the purchase menu - but let them decide whether it's a fitting combination given the actual circumstances (e.g. a special scenario in an alternate history or whatever):
Code:
   graphics {
      default: SPRITEGROUP_LINIMO; // Use this group
      purchase: SPRITESET_PURCH_LINIMO; // Use this set for the menu
      can_attach_wagon: CB_RESULT_ATTACH_ALLOW;
      additional_text string(STR_ONLY_SUITABLE_FOR_ENGINES_OF_TYPE_XYZ);
   }

_________________
Image
OpenTTD: manual | online content | translations | Wanted contributions and patches
#openttdcoop: blog | wiki | public server | DevZone | NewGRF web translator
DevZone - home of the free NewGRFs: OpenSFX | OpenMSX | OpenGFX | Swedish Rails | OpenGFX+ Trains|RV|Industries|Airports|Landscape | NML


Top
   
PostPosted: Mon May 29, 2017 8:01 pm 
Offline
Tycoon
Tycoon

Joined: Tue Feb 22, 2011 6:34 pm
Posts: 2648
Erato wrote:
I tried to look into how the 2CC set handled this, but I didn't understand where their code was going.

What did you not understand in that code? It basically uses the ID of the new vehicle to determine which can_attach-switch should be called, and then uses the ID of the vehicle in front to determine if the new vehicle can be attached.

_________________
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML


Top
   
PostPosted: Mon May 29, 2017 9:44 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Mon May 25, 2015 9:09 am
Posts: 316
Location: The Netherlands
Transportman wrote:
Erato wrote:
I tried to look into how the 2CC set handled this, but I didn't understand where their code was going.

What did you not understand in that code? It basically uses the ID of the new vehicle to determine which can_attach-switch should be called, and then uses the ID of the vehicle in front to determine if the new vehicle can be attached.

Code:
switch(FEAT_TRAINS, PARENT, switch_can_attach_unit_rail, [STORE_TEMP(position_in_consist_from_end, 0x10F), var[0x61, 0, 0x0000FFFF, 0xC6]])

I really don't know what this switch does and how it works. With all the HEX and all.

_________________
No pics no clicks. Seriously.
ImageImageImageImageImageImage


Top
   
PostPosted: Sun Jun 25, 2017 9:34 am 
Offline
Transport Coordinator
Transport Coordinator

Joined: Thu Oct 07, 2004 12:51 pm
Posts: 290
For you to understand that expression, let's start out with the "var[...]" statement.
It's not documented anywhere, so it's understandable that you don't know it. But if one checks the source for NMLC one can see how it's supposed to work.
Code:
var[num, <shift>, <mask>, <param>]
num - The variable to access. This is feature specific so accessing for example variable 0xB4 on a train would return the current speed.
shift - An optional parameter that performs a bitwise shift on the result. Example: 123 << 4 = 1,968 or in binary: 0111 1011 << 4 = 0111 1011 0000, in other words. It shifts bits left or right. I would assume positive numbers are left shift (<<) and negative numbers are right shift (>>)
mask - An optional parameter that masks the result. For example: 123 & 0xF = 11 or in binary: 0111 1011 & 0000 1111 = 1011. That is, if both bits are 1 in the result and the mask then they are kept.
param - An optional parameter that is sent to the "60+x" variable in question. In this case, since we are working on var 0x61 which is "query variable of n'th vehicle in chain" we are trying to get the value of variable C6 (Vehicle type ID) on the n'th vehicle in the chain.

Or in other words, get variable from n'th vehicle in chain that is "Vehicle type ID" applying no bit shifting and applying logical AND 0x0000FFFF to the result. Or in other words, clamping the result between 0 and 65535.

So, we are trying to base our decision in the switch on the vehicle ID of the wagon that exists before this wagon is attached to the chain.
We only allow adding "unit_rail" wagons to DMU, EMU, unit_rail and SMU's before it.

Now you wonder, how does 0x61 (query var of n'th vehicle in chain) know what the n'th vehicle in the chain is? I mean, there's only a parameter for what variable (0xC6, vehicle id) to get from that n'th vehicle.
Well, when using var 0x61, you have to make use of a temporary variable that refers to the actual offset in the chain. That's what the previous STORE_TEMP(x, 0x10F) does. It stores a value in a SPECIAL register used for this very purpose.
In this case, the value is the "position_in_consist_from_end" variable.

But i fail to see the logic behind this one though... Wouldn't it simply suffice to store 0 (zero) in that temporary register? Or is it actually counting from the engine down because the vehicle being evaluated is a wagon? So many question marks.
Either way, surely there's a reason for that. And if you search for it, you end up on page 43 of the NML language thread: viewtopic.php?t=48891&start=840

And there you have it. Even the comments on the code you pasted tells you the same story. Albeit a bit briefer...
Code:
//Check vehicle ID of the vehicle in front of the unit wagon being attached
//The offset for var 61 is determined by position_in_consist_from_end, which results in the last wagon before the vehicle being attached

If you don't understand some code, but it still works beautifully, then what's the harm in re-using it?


Top
   
PostPosted: Tue Jun 27, 2017 12:52 am 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Mon May 25, 2015 9:09 am
Posts: 316
Location: The Netherlands
Cadde wrote:
For you to understand that expression, let's start out with the "var[...]" statement.
It's not documented anywhere, so it's understandable that you don't know it. But if one checks the source for NMLC one can see how it's supposed to work.
Code:
var[num, <shift>, <mask>, <param>]
num - The variable to access. This is feature specific so accessing for example variable 0xB4 on a train would return the current speed.
shift - An optional parameter that performs a bitwise shift on the result. Example: 123 << 4 = 1,968 or in binary: 0111 1011 << 4 = 0111 1011 0000, in other words. It shifts bits left or right. I would assume positive numbers are left shift (<<) and negative numbers are right shift (>>)
mask - An optional parameter that masks the result. For example: 123 & 0xF = 11 or in binary: 0111 1011 & 0000 1111 = 1011. That is, if both bits are 1 in the result and the mask then they are kept.
param - An optional parameter that is sent to the "60+x" variable in question. In this case, since we are working on var 0x61 which is "query variable of n'th vehicle in chain" we are trying to get the value of variable C6 (Vehicle type ID) on the n'th vehicle in the chain.

Or in other words, get variable from n'th vehicle in chain that is "Vehicle type ID" applying no bit shifting and applying logical AND 0x0000FFFF to the result. Or in other words, clamping the result between 0 and 65535.

So, we are trying to base our decision in the switch on the vehicle ID of the wagon that exists before this wagon is attached to the chain.
We only allow adding "unit_rail" wagons to DMU, EMU, unit_rail and SMU's before it.

Now you wonder, how does 0x61 (query var of n'th vehicle in chain) know what the n'th vehicle in the chain is? I mean, there's only a parameter for what variable (0xC6, vehicle id) to get from that n'th vehicle.
Well, when using var 0x61, you have to make use of a temporary variable that refers to the actual offset in the chain. That's what the previous STORE_TEMP(x, 0x10F) does. It stores a value in a SPECIAL register used for this very purpose.
In this case, the value is the "position_in_consist_from_end" variable.

But i fail to see the logic behind this one though... Wouldn't it simply suffice to store 0 (zero) in that temporary register? Or is it actually counting from the engine down because the vehicle being evaluated is a wagon? So many question marks.
Either way, surely there's a reason for that. And if you search for it, you end up on page 43 of the NML language thread: viewtopic.php?t=48891&start=840

And there you have it. Even the comments on the code you pasted tells you the same story. Albeit a bit briefer...
Code:
//Check vehicle ID of the vehicle in front of the unit wagon being attached
//The offset for var 61 is determined by position_in_consist_from_end, which results in the last wagon before the vehicle being attached

If you don't understand some code, but it still works beautifully, then what's the harm in re-using it?


I see. So I tried using it.
Image
Code:
//ITS
switch(FEAT_TRAINS, PARENT, switch_can_attach_its, [STORE_TEMP(position_in_consist_from_end, 0x10F), var[0x61, 0, 0x0000FFFF, 0xC6]]) {
   ITEM_RANGE_ITS: CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES; //Allow
   ITEM_RANGE_ITS_WAG: CB_RESULT_ATTACH_DISALLOW; //Allow self
   CB_RESULT_ATTACH_DISALLOW;
}

The switch being line 12. If I remove the comma. I get an error message for an unknown "var" on line 12.

What happened?

_________________
No pics no clicks. Seriously.
ImageImageImageImageImageImage


Top
   
PostPosted: Tue Jun 27, 2017 2:56 am 
Offline
Transport Coordinator
Transport Coordinator

Joined: Thu Oct 07, 2004 12:51 pm
Posts: 290
You most likely have a problem on a line further up. The "serializer" can travel quite a bit before it finds an unexpected character and only then will it complain.
If you aren't already, use notepad++ and import the NML syntax highlighting from here: http://dev.openttdcoop.org/documents/24
Then check to make sure you have all the required opening and closing brackets "(){}" etc prior in your file.

If you don't believe me, make a dummy GRF with just that switch statement in it besides the required GRF block.

EDIT: Oh and make sure you are on the latest NMLC version.

Code:
C:\Users\Cadde>nmlc --version
0.4.4
Library versions encountered:
PLY: 3.4
PIL: 1.1.7


Top
   
PostPosted: Tue Jun 27, 2017 10:46 am 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Sun Sep 09, 2007 5:03 am
Posts: 4668
Location: home
Quote:
The switch being line 12. If I remove the comma. I get an error message for an unknown "var" on line 12.
"Unexpected token ','" means the parser expected something else than a comma.
Removing symbols that look ok on first sight is likely not the solution. (But I don't know that "var" thing, so my "ok" doesn't mean much.)

A common trick here is to split the line into several lines, where each line then contains a single comma.That is change the line to
Code:
switch(FEAT_TRAINS,
 PARENT,
  switch_can_attach_its,
   [STORE_TEMP(position_in_consist_from_end,
    0x10F),
     var[0x61,
      0,
       0x0000FFFF,
        0xC6]]) {
Then run the program again, and the error message will point at a different line (most likely). Since there is only one comma at that line, you get precisely which comma is not recognized.

Before that comma, something is not right, most likely some bracket or a wrong number of arguments, as Cadde already said.

_________________
Being a OpenTTD developer does not mean I know what I am doing.
Also, other OpenTTD developers may have different opinions.


Top
   
PostPosted: Tue Jun 27, 2017 11:58 am 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Mon May 25, 2015 9:09 am
Posts: 316
Location: The Netherlands
Cadde wrote:
You most likely have a problem on a line further up. The "serializer" can travel quite a bit before it finds an unexpected character and only then will it complain.
If you aren't already, use notepad++ and import the NML syntax highlighting from here: http://dev.openttdcoop.org/documents/24
Then check to make sure you have all the required opening and closing brackets "(){}" etc prior in your file.

If you don't believe me, make a dummy GRF with just that switch statement in it besides the required GRF block.

EDIT: Oh and make sure you are on the latest NMLC version.

Code:
C:\Users\Cadde>nmlc --version
0.4.4
Library versions encountered:
PLY: 3.4
PIL: 1.1.7

All my brackets are properly opened and closed.
As for the version:
Code:
nmlc --version
unknown
Library versions encountered:
PLY: 3.10
PIL: 1.1.7


Alberth wrote:
Quote:
The switch being line 12. If I remove the comma. I get an error message for an unknown "var" on line 12.
"Unexpected token ','" means the parser expected something else than a comma.
Removing symbols that look ok on first sight is likely not the solution. (But I don't know that "var" thing, so my "ok" doesn't mean much.)

A common trick here is to split the line into several lines, where each line then contains a single comma.That is change the line to
Code:
switch(FEAT_TRAINS,
 PARENT,
  switch_can_attach_its,
   [STORE_TEMP(position_in_consist_from_end,
    0x10F),
     var[0x61,
      0,
       0x0000FFFF,
        0xC6]]) {
Then run the program again, and the error message will point at a different line (most likely). Since there is only one comma at that line, you get precisely which comma is not recognized.

Before that comma, something is not right, most likely some bracket or a wrong number of arguments, as Cadde already said.


That, interestingly enough, results in an error on the latter of these lines:
Code:
                        0xC6]]) {
   ITEM_RANGE_ITS: CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES; //Allow

It's the same error, even though there is no comma on that line, before that line and on the next line.
In a way, this error is still on the same line.

_________________
No pics no clicks. Seriously.
ImageImageImageImageImageImage


Top
   
PostPosted: Tue Jun 27, 2017 6:03 pm 
Offline
Engineer
Engineer

Joined: Wed May 24, 2017 12:51 pm
Posts: 27
Location: East Texas
Erato wrote:
That, interestingly enough, results in an error on the latter of these lines:
Code:
                        0xC6]]) {
   ITEM_RANGE_ITS: CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES; //Allow

It's the same error, even though there is no comma on that line, before that line and on the next line.
In a way, this error is still on the same line.


Double check that your substitutions are getting expanded properly. I copied your code into a trivial nml and it compiled without error but, of course, I had to replace ITEM_RANGE_ITS* with constants.

In case it matters, I used the NotRoadTypes branch of nmlc.
Code:
$ nmlc --version
v6347:96b8395ca393 from 2017-05-18
Library versions encountered:
PIL: 1.1.7
PLY: 3.10

_________________
Unless otherwise stated, all my code is GPL v2.


Top
   
PostPosted: Tue Jun 27, 2017 6:41 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Mon May 25, 2015 9:09 am
Posts: 316
Location: The Netherlands
rowdog wrote:
Erato wrote:
That, interestingly enough, results in an error on the latter of these lines:
Code:
                        0xC6]]) {
   ITEM_RANGE_ITS: CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES; //Allow

It's the same error, even though there is no comma on that line, before that line and on the next line.
In a way, this error is still on the same line.


Double check that your substitutions are getting expanded properly. I copied your code into a trivial nml and it compiled without error but, of course, I had to replace ITEM_RANGE_ITS* with constants.

In case it matters, I used the NotRoadTypes branch of nmlc.
Code:
$ nmlc --version
v6347:96b8395ca393 from 2017-05-18
Library versions encountered:
PIL: 1.1.7
PLY: 3.10

It makes sense that the code should work. For the range, I did this, which should work:
Code:
#define ITEM_RANGE_ITS   \
   ITEM_ITS_PERSONEN,   \
   ITEM_ITS_MATERIAL,   \
   ITEM_ITS_MASSENGUT,   \

_________________
No pics no clicks. Seriously.
ImageImageImageImageImageImage


Top
   
PostPosted: Tue Jun 27, 2017 10:10 pm 
Offline
Transport Coordinator
Transport Coordinator

Joined: Thu Oct 07, 2004 12:51 pm
Posts: 290
Well, your NMLC version reports as "unknown" and that to me sounds like you have some experimental NMLC to begin with.


Top
   
PostPosted: Tue Jun 27, 2017 10:30 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Mon May 25, 2015 9:09 am
Posts: 316
Location: The Netherlands
Cadde wrote:
Well, your NMLC version reports as "unknown" and that to me sounds like you have some experimental NMLC to begin with.

I'm pretty certain that wouldn't be the case.
I tried it again in cmd and got this instead:
Code:
v6201:45b1e0507a8d from 2016-12-23
Library versions encountered:
PLY: 3.4
PIL: 1.1.7

_________________
No pics no clicks. Seriously.
ImageImageImageImageImageImage


Top
   
PostPosted: Wed Jun 28, 2017 5:58 am 
Offline
Transport Coordinator
Transport Coordinator

Joined: Thu Oct 07, 2004 12:51 pm
Posts: 290
Right, still looks experimental to me. ;)
But now that i am a bit more awake, the #defines you have there... I don't normally use #defines, but that surely looks like it's gonna resolve to this:
Code:
//ITS
switch(FEAT_TRAINS, PARENT, switch_can_attach_its, [STORE_TEMP(position_in_consist_from_end, 0x10F), var[0x61, 0, 0x0000FFFF, 0xC6]]) {
   ITEM_ITS_PERSONEN,   
   ITEM_ITS_MATERIAL,   
   ITEM_ITS_MASSENGUT,: CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES; //Allow
   ITEM_RANGE_ITS_WAG: CB_RESULT_ATTACH_DISALLOW; //Allow self
   CB_RESULT_ATTACH_DISALLOW;
}

So, as you can see, not correct NML switch syntax unless the revision you are using allows that? If it does then show me that documentation please. ;)
But if it were me, assuming your id's are in sequential order... Let's for instance say that this were true:
Code:
#define ITEM_ITS_PERSONEN 0x01
#define ITEM_ITS_MATERIAL 0x02   
#define ITEM_ITS_MASSENGUT 0x03

Then you could do this:
Code:
#define ITEM_RANGE_ITS 0x01..0x03
#define ITEM_ITS_PERSONEN 0x01
#define ITEM_ITS_MATERIAL 0x02   
#define ITEM_ITS_MASSENGUT 0x03

#define ITEM_RANGE_ITS_WAG ...
...
//ITS
switch(FEAT_TRAINS, PARENT, switch_can_attach_its, [STORE_TEMP(position_in_consist_from_end, 0x10F), var[0x61, 0, 0x0000FFFF, 0xC6]]) {
   ITEM_RANGE_ITS: CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES; //Allow
   ITEM_RANGE_ITS_WAG: CB_RESULT_ATTACH_DISALLOW; //Allow self
   CB_RESULT_ATTACH_DISALLOW;
}


Top
   
PostPosted: Wed Jun 28, 2017 12:02 pm 
Offline
OpenTTD Developer
OpenTTD Developer

Joined: Sun Sep 09, 2007 5:03 am
Posts: 4668
Location: home
@rowdog: Good catch, I didn't consider #define macros.

Cadde wrote:
Right, still looks experimental to me. ;)
But now that i am a bit more awake, the #defines you have there... I don't normally use #defines, but that surely looks like it's gonna resolve to this:
Code:
//ITS
switch(FEAT_TRAINS, PARENT, switch_can_attach_its, [STORE_TEMP(position_in_consist_from_end, 0x10F), var[0x61, 0, 0x0000FFFF, 0xC6]]) {
   ITEM_ITS_PERSONEN,   
   ITEM_ITS_MATERIAL,   
   ITEM_ITS_MASSENGUT,: CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES; //Allow
   ITEM_RANGE_ITS_WAG: CB_RESULT_ATTACH_DISALLOW; //Allow self
   CB_RESULT_ATTACH_DISALLOW;
}

So, as you can see, not correct NML switch syntax unless the revision you are using allows that?/code]
Indeed, this is wrong. There is no NML version that allows trailing commas.

@Erato:To be fully correct, you also have to remove the \ at the end of the last line. (Now it also merges the line below it, that is, your #define is one line longer than you think it is.)

_________________
Being a OpenTTD developer does not mean I know what I am doing.
Also, other OpenTTD developers may have different opinions.


Top
   
PostPosted: Thu Jun 29, 2017 3:57 pm 
Offline
Tycoon
Tycoon

Joined: Tue Feb 22, 2011 6:34 pm
Posts: 2648
Cadde wrote:
Right, still looks experimental to me. ;)
But now that i am a bit more awake, the #defines you have there... I don't normally use #defines, but that surely looks like it's gonna resolve to this:
Code:
//ITS
switch(FEAT_TRAINS, PARENT, switch_can_attach_its, [STORE_TEMP(position_in_consist_from_end, 0x10F), var[0x61, 0, 0x0000FFFF, 0xC6]]) {
   ITEM_ITS_PERSONEN,   
   ITEM_ITS_MATERIAL,   
   ITEM_ITS_MASSENGUT,: CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES; //Allow
   ITEM_RANGE_ITS_WAG: CB_RESULT_ATTACH_DISALLOW; //Allow self
   CB_RESULT_ATTACH_DISALLOW;
}

So, as you can see, not correct NML switch syntax unless the revision you are using allows that? If it does then show me that documentation please. ;)
But if it were me, assuming your id's are in sequential order... Let's for instance say that this were true:
Code:
#define ITEM_ITS_PERSONEN 0x01
#define ITEM_ITS_MATERIAL 0x02   
#define ITEM_ITS_MASSENGUT 0x03

Then you could do this:
Code:
#define ITEM_RANGE_ITS 0x01..0x03
#define ITEM_ITS_PERSONEN 0x01
#define ITEM_ITS_MATERIAL 0x02   
#define ITEM_ITS_MASSENGUT 0x03

#define ITEM_RANGE_ITS_WAG ...
...
//ITS
switch(FEAT_TRAINS, PARENT, switch_can_attach_its, [STORE_TEMP(position_in_consist_from_end, 0x10F), var[0x61, 0, 0x0000FFFF, 0xC6]]) {
   ITEM_RANGE_ITS: CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES; //Allow
   ITEM_RANGE_ITS_WAG: CB_RESULT_ATTACH_DISALLOW; //Allow self
   CB_RESULT_ATTACH_DISALLOW;
}

That is the reason I switched vehicle ID's in the 2cc TrainsInNML, to create ranges of vehicle IDs that are of the same type, so I could use those ranges in this type of switches.

_________________
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML


Top
   
PostPosted: Sat Jul 01, 2017 11:48 pm 
Offline
Transport Coordinator
Transport Coordinator
User avatar

Joined: Mon May 25, 2015 9:09 am
Posts: 316
Location: The Netherlands
Cadde wrote:
Right, still looks experimental to me. ;)
But now that i am a bit more awake, the #defines you have there... I don't normally use #defines, but that surely looks like it's gonna resolve to this:
Code:
//ITS
switch(FEAT_TRAINS, PARENT, switch_can_attach_its, [STORE_TEMP(position_in_consist_from_end, 0x10F), var[0x61, 0, 0x0000FFFF, 0xC6]]) {
   ITEM_ITS_PERSONEN,   
   ITEM_ITS_MATERIAL,   
   ITEM_ITS_MASSENGUT,: CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES; //Allow
   ITEM_RANGE_ITS_WAG: CB_RESULT_ATTACH_DISALLOW; //Allow self
   CB_RESULT_ATTACH_DISALLOW;
}

So, as you can see, not correct NML switch syntax unless the revision you are using allows that? If it does then show me that documentation please. ;)
But if it were me, assuming your id's are in sequential order... Let's for instance say that this were true:
Code:
#define ITEM_ITS_PERSONEN 0x01
#define ITEM_ITS_MATERIAL 0x02   
#define ITEM_ITS_MASSENGUT 0x03

Then you could do this:
Code:
#define ITEM_RANGE_ITS 0x01..0x03
#define ITEM_ITS_PERSONEN 0x01
#define ITEM_ITS_MATERIAL 0x02   
#define ITEM_ITS_MASSENGUT 0x03

#define ITEM_RANGE_ITS_WAG ...
...
//ITS
switch(FEAT_TRAINS, PARENT, switch_can_attach_its, [STORE_TEMP(position_in_consist_from_end, 0x10F), var[0x61, 0, 0x0000FFFF, 0xC6]]) {
   ITEM_RANGE_ITS: CB_RESULT_ATTACH_ALLOW_IF_RAILTYPES; //Allow
   ITEM_RANGE_ITS_WAG: CB_RESULT_ATTACH_DISALLOW; //Allow self
   CB_RESULT_ATTACH_DISALLOW;
}

Ah. I understand.

Also. This worked :D thanks.

_________________
No pics no clicks. Seriously.
ImageImageImageImageImageImage


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 19 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.