News:

Simutrans Wiki Manual
The official on-line manual for Simutrans. Read and contribute.

shorthand dats for vehicles, ways, etc.

Started by Leartin, April 30, 2017, 08:20:49 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Leartin

The short writing form for graphic references in dats is one of my favorite additions to the game since I started creating stuff. (For those who have no idea what I am talking about --> http://forum.simutrans.com/index.php?topic=15133.msg149373#msg149373)

However, it currently only works with numbers, which forbids use for vehicles or ways. I'd like to be able to use this:
emptyimage[s,w,e,n,ne,sw,nw,se]=.horse_hearse.<$0/4>.<$0%4>
The idea is that the listed elements in square brackets would be indexed depending on their position, so s=0, w=1 and so on, such that they can be used to point to a position on the graphics sheet. Usually the positions of graphics on the sheet is always the same, so with this, one would only need to copy that one line for a new vehicle and replace the name of the graphic once, rather than 8 times.

An_dz

Here's my patch for it, I ask for someone with experience to review and see if I have missed something or if it's too crappy.

And here's makeobj for you to test. It has some debug log so if you get a problem you can send me the log report and I may have an idea of what's the problem.

Notice that you can't add the - (hyphen) image as that's considered the range symbol when using numbers. All others should be accepted.

Dwachs

Parsley, sage, rosemary, and maggikraut.

prissi

An empty image "-" is really needed for some objects like waz bridges and some vehicles. Moreover, using instead an empty image (only background) will not work correctly. But if this is only a problem for ranged images, then that should be fine.

An_dz

Quote from: Dwachs on May 05, 2017, 06:05:42 AM
if it works then submit :)
That's the problem, I don't know if it really does :), I just tested with a simple citycar. That's why I also uploaded makeobj.

Quote from: prissi on May 05, 2017, 02:31:45 PM
An empty image "-" is really needed for some objects like waz bridges and some vehicles. Moreover, using instead an empty image (only background) will not work correctly. But if this is only a problem for ranged images, then that should be fine.
The only thing is that you can't add the empty image using the shorthand mode, so you need to write it outside of the shorthand.

These won't work:
emptyimage[n,-]=.horse_hearse.<$0/4>.<$0%4>
emptyimage[n--]=.horse_hearse.<$0/4>.<$0%4>


emptyimage[n-s]=.horse_hearse.<$0/4>.<$0%4> works as emptyimage[n,s]=.horse_hearse.<$0/4>.<$0%4>

prissi

Ok, I though you mean the image named "-" which is needed for some bridges and ways.

An_dz


Leartin

So I did a few vehicles with that and it always worked. But today, I tried to do a way, and discovered two bugs, which both can be shown in one line:
Image[NSEW,NSEW1,NSEW2][0-1]=testtrack.4.<$0+$1*4>,0,48
creates this Debug-information upon paking:

   = Debug =
   0: nsew
   1: nsew1 | 10
   2: nsew2 | 16
   image[nsew][0]testtrack.4.0,0,48
   image[nsew1nsew2][0]testtrack.4.1,0,48
   image[nsew2][0]testtrack.4.2,0,48
   image[][1]testtrack.4.4,0,48
   image[][1]testtrack.4.5,0,48
   image[][1]testtrack.4.6,0,48
   = Debug End =


So the two issues are:
1) for some strange reason, it would randomly put two strings in one output, even though the string seperation seems to have worked. This does not happen with 3-way-intersection, so it cannot be the numbers who are responsible for this. Perhaps it's the number of characters per string, since 5 chars should be the longest there is.

2) If there is a second variable, the strings are only put in once, not for each iteration of the second variable. So you can't define snow-images and normal images in one line.

I attached the full dat and a resized graphic due to forum restrictions, but should work as a pak96.

An_dz


An_dz

Fixed in r8246

Bug #2 was because I was using the number of lines generated, so in this case it was going up to index 5, but there are only three elements, so it can only go up to index 2. A more careful read of the code made me realise that the code already has something dealing with this but I was not using it.

Bug #1 took me a while to find out but then I noticed that I was leaving only up to 5 chars in the array holding the string and you must always keep an extra char for the end string char (\0). Basically the string had no end so it would load the next, or something like that.

I also added some comments in the code for others because the code had none and it was really hard to understand it the first time and even this time I had to spend some time to understand it fully again.

Here's the new makeobj.