Author Topic: shorthand dats for vehicles, ways, etc.  (Read 813 times)

0 Members and 1 Guest are viewing this topic.

Offline Leartin

shorthand dats for vehicles, ways, etc.
« on: April 30, 2017, 08:20:49 PM »
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:
Code: [Select]
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.

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2593
  • Total likes: 289
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: shorthand dats for vehicles, ways, etc.
« Reply #1 on: May 03, 2017, 07:58:05 AM »
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.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4224
  • Total likes: 168
  • Helpful: 148
  • Languages: EN, DE, AT
Re: shorthand dats for vehicles, ways, etc.
« Reply #2 on: May 05, 2017, 06:05:42 AM »
if it works then submit :)
Parsley, sage, rosemary, and maggikraut.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8753
  • Total likes: 305
  • Helpful: 229
  • Languages: De,EN,JP
Re: shorthand dats for vehicles, ways, etc.
« Reply #3 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.

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2593
  • Total likes: 289
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: shorthand dats for vehicles, ways, etc.
« Reply #4 on: May 05, 2017, 03:12:59 PM »
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.

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:
Code: [Select]
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>

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8753
  • Total likes: 305
  • Helpful: 229
  • Languages: De,EN,JP
Re: shorthand dats for vehicles, ways, etc.
« Reply #5 on: May 06, 2017, 01:19:31 PM »
Ok, I though you mean the image named "-" which is needed for some bridges and ways.

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2593
  • Total likes: 289
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: shorthand dats for vehicles, ways, etc.
« Reply #6 on: May 06, 2017, 02:32:03 PM »
Included in r8229

Offline Leartin

BUG in shorthand dats for ways
« Reply #7 on: June 04, 2017, 12:51:40 PM »
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:
Code: [Select]
Image[NSEW,NSEW1,NSEW2][0-1]=testtrack.4.<$0+$1*4>,0,48creates this Debug-information upon paking:
Code: [Select]
   = 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.

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2593
  • Total likes: 289
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: shorthand dats for vehicles, ways, etc.
« Reply #8 on: June 08, 2017, 10:26:23 PM »
Thanks I'll try to look at it today.

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2593
  • Total likes: 289
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: shorthand dats for vehicles, ways, etc.
« Reply #9 on: June 11, 2017, 09:45:30 PM »
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.