Page 1 of 2

Road decoration

Posted: Mon May 14, 2018 16:21
by Lobby
Since 475 there is a new type of object in the game: Road decorations.
Those are basically road alignment aware frames that can be attached on top of any road, similar to animations that are defined directly by a road.

How it may look like :img
Screenshot_20180514-154312.png
This one is simple for the purpose of demonstration. I'm confident that you can come up with something that is way better.

The frame we want to use as decoration :img
frames.png
frames.png (535 Bytes) Viewed 4549 times
The usage is supposed to follow this scheme :teach
frames_usage.png
frames_usage.png (3.94 KiB) Viewed 4549 times
The basic structure of road decorations is to define all the needed frames as animation obejcts which can then be referenced in the road decoration object. So here they may look like :json

Code: Select all

{"id":"$anim_roaddeco_sample00_00","type":"animation","frames":[{"bmp":"frames.png","x":0,"w":32,"handle y":8}]},
{"id":"$anim_roaddeco_sample00_01","type":"animation","frames":[{"bmp":"frames.png","x":32,"w":32,"handle y":8}]},
{"id":"$anim_roaddeco_sample00_02","type":"animation","frames":[{"bmp":"frames.png","x":64,"w":32,"handle y":8}]},
{"id":"$anim_roaddeco_sample00_03","type":"animation","frames":[{"bmp":"frames.png","x":96,"w":32,"handle y":8}]}
⚠Although we're talking about animation objects they aren't animated here because each animation has only one frame.

So now we have 4 animation objects that hold our frames that we want to put on top of roads. The basic road decoration structure looks like :json

Code: Select all

{
  "id":"$roaddeco_sample00",
  "type":"road decoration",
  "title":"Sample deco",
  "text":"I am a road decoration.",
  "price":100,
  ...
}
For drawing frames 1 and 3 should be used in the foreground while frames 0 and 2 should be drawn behind cars. We can say so by using animation and animation fg respectively in the road decoration object :json

Code: Select all

"animation":[
  {"id":"$anim_roaddeco_sample00_00"},
  {"id":"$anim_roaddeco_sample00_02"}
],
"animation fg":[
  {"id":"$anim_roaddeco_sample00_01"},
  {"id":"$anim_roaddeco_sample00_03"}
]
The last part is the most important one: We have to tell the game when to show which animation object. By default, all animations are drawn for every frame (so we don't use frame/alignment awareness yet). Normal roads have 16 frames (as defined here), so we have to tell for each frame manually which of the provided animation obejects to use. That can be done by populating the arrays frame animation indices and frame animation fg indices with 16 sub arrays. Each of these sub arrays contains a list of the corresponding animation objects that should be used (indexed by 0 and 1 as we have only two animations for animation and animation fg) :json

Code: Select all

"frame animation indices":[
  [0,1],[0,1],[1],[1],
  [0],[0],[],[],
  [0,1],[0,1],[1],[1],
  [0],[0],[],[]
],
"frame animation fg indices":[
  [0,1],[0],[0,1],[0],
  [0,1],[0],[0,1],[0],
  [1],[],[1],[],
  [1],[],[1],[]
]
Dependent on your project your can just reuse this code and don't have to worry about the meaning.

Here you can get the whole plugin:
roaddeco_sample.zip
(58.31 KiB) Downloaded 97 times
Road decoration objects also support the basic fun attributes fun, on click fun and random fun.

Since 476: The attribute "speed" can be used to apply a speed multiplier to the underlaying road. Default value is 1.0

:66:
New attributes are
Show
required flag *
You can now use road flags to specify on which roads the decoration should be buildable. The default is

Code: Select all

"required flag normal":true
which means that it can only be built on regular roads.

E.g. use

Code: Select all

"required flag normal":false,
"required flag train":true
to define a decoration that can only be placed on rails.
See this thread for more information about flags.
Show
min dirs
This is basically a filter to limit where the decoration can be built. It states the minimum required amount of connected neighboring roads that's required for the decoration to be built.
For example:

Code: Select all

"min dirs":1
would mean that the decoration cannot be built on roads that aren't connected to any other roads. The default value is 0 meaning that no lower limit is given.
Show
max dirs
Works like min dir but specifies an upper limit of to how many neighboring roads the targeted road has to be connected.
Example:

Code: Select all

"max dirs":2
would mean that the decoration cannot be built on roads with 3 or 4 neighbors. This effectively excludes all kinds of crossings (T crossings have 3 neighbors, X crossings have 4). The default value is 4 meaning that no upper limit is given.
Show
symmetric dirs
This is another filter for road decoration placement. If set to true the road has to be connected to neighboring roads in a symmetric way. This is only the case for not connected roads, a line of road and X crossings.
For example:

Code: Select all

"min dirs":2,
"max dirs":2,
"symmetric dirs":true
only allows the road decoration to be built on a line of road without crossings (using the "min dirs" and "max dirs" attributes to filter out other symmetric cases).
Show
line tool
By default road decorations are built per road tile, now. However, you can enable the line tool by using

Code: Select all

"line tool":true

Re: Road decoration

Posted: Mon May 14, 2018 17:47
by Artem_123
(((:

Re: Road decoration

Posted: Mon May 14, 2018 19:23
by CommanderABab
:)

Re: Road decoration

Posted: Tue May 15, 2018 2:44
by khadafi laidi
Lots of mathematical formulas

Re: Road decoration

Posted: Fri May 25, 2018 16:30
by yusuf8a684
Woah thats beatufull but hard

Re: Road decoration

Posted: Wed May 30, 2018 10:54
by -LeoLeo-
Excuse me, but how do you make animation fg go under vehicles???

Like the crosswalks and the bumps??

Re: Road decoration

Posted: Wed May 30, 2018 20:27
by CommanderABab
-LeoLeo- wrote:
Wed May 30, 2018 10:54
Excuse me, but how do you make animation fg go under vehicles???

Like the crosswalks and the bumps??
You don't use it. :)

You would use

Code: Select all

"animation indices" 
for that.

Re: Road decoration

Posted: Sun Jun 03, 2018 23:59
by danekbel
can i make a road change its flag with the deco?
for example, can i write in deco's json "flag bus:false" and the road on which would be this deco placed would be able to pass buses through itself?

Re: Road decoration

Posted: Mon Jun 04, 2018 15:25
by danekbel

Re: Road decoration

Posted: Wed Jun 06, 2018 8:03
by danekbel
OK, if it's not supported, is there a possibility to add it into a game? @Lobby

Re: Road decoration

Posted: Thu Jun 07, 2018 2:57
by -LeoLeo-
danékbel wrote:
Wed Jun 06, 2018 8:03
OK, if it's not supported, is there a possibility to add it into a game? @Lobby
He's probably busy...(?)

Re: Road decoration

Posted: Thu Jun 07, 2018 3:43
by CommanderABab
Using the fun from the road decoration, you could build a different road that would allow the busses in the same spot.

Re: Road decoration

Posted: Sat Jun 09, 2018 11:24
by Ølsken
Just if you wanted to know the difference between animation & animation fg.
In animation the cars will overlay the frame. Simply think that it will be behind the cars like a background.
On the other hand animation fg is the opposite of animation, it will be in front of the car.
So the frame will overlay the cars.


Correct me if I'm wrong with any of this information. :json

Re: Road decoration

Posted: Sat Jun 09, 2018 19:46
by KINGTUT10101
Would it be possible to spawn vehicles using these decorations?

Re: Road decoration

Posted: Sat Jun 09, 2018 19:49
by yusuf8a684
KINGTUT10101 wrote:
Sat Jun 09, 2018 19:46
Would it be possible to spawn vehicles using these decorations?
I hope.it is possible

Re: Road decoration

Posted: Sun Jun 10, 2018 9:05
by Pounkiller
Mann,these are so complicated.

Re: Road decoration

Posted: Sun Jun 10, 2018 17:32
by CommanderABab
KINGTUT10101 wrote:
Sat Jun 09, 2018 19:46
Would it be possible to spawn vehicles using these decorations?
No, or not yet. You choose. It doesn't really make sense for a road to spawn vehicles.

Re: Road decoration

Posted: Sun Jun 10, 2018 18:29
by KINGTUT10101
There's a lot of things in this game that don't make sense...

Re: Road decoration

Posted: Sun Aug 05, 2018 10:38
by -LeoLeo-
Excuse me, @Lobby.
I know tagging is very annoying, sorry.

The new updates added the "Traffic lights crossing" and they actually stop cars!

I mean.... How did you code that????
Can i have some documentation on that?

Also, the ability to place decorations on a 4-way intersections (crosswalks) and the texture changed completely, is beyond me... Can you also tell me about that?

Re: Road decoration

Posted: Sun Aug 05, 2018 11:31
by Lobby
Maybe the code can help you :json

Code: Select all

  {"id":"$anim_roaddeco_trafficlights00_00","type":"animation","frames":[{"x":0,"y":469,"w":32,"h":16,"handle y":8,"offset y":3072}]},
  {"id":"$anim_roaddeco_trafficlights00_01","type":"animation","frames":[{"x":32,"y":469,"w":32,"h":16,"handle y":8,"offset y":3072}]},
  {"id":"$anim_roaddeco_trafficlights00_02","type":"animation","frames":[{"x":64,"y":469,"w":32,"h":16,"handle y":8,"offset y":3072}]},
  {"id":"$anim_roaddeco_trafficlights00_03","type":"animation","frames":[{"x":92,"y":469,"w":32,"h":16,"handle y":8,"offset y":3072}]},
  {
    "id":"$roaddeco_trafficlights00",
    "type":"road decoration",
    "price":100,
    "animation":[
      {"id":"$anim_roaddeco_trafficlights00_00"},
      {"id":"$anim_roaddeco_trafficlights00_02"}
    ],
    "frame animation indices":[
      [0,1],[0,1],[1],[1],
      [0],[0],[],[],
      [0,1],[0,1],[1],[1],
      [0],[0],[],[]
    ],
    "animation fg":[
      {"id":"$anim_roaddeco_trafficlights00_01"},
      {"id":"$anim_roaddeco_trafficlights00_03"}
    ],
    "frame animation fg indices":[
      [0,1],[0],[0,1],[0],
      [0,1],[0],[0,1],[0],
      [1],[],[1],[],
      [1],[],[1],[]
    ],
    "fun":{
      "condition":"day%10>=8",
      "action":{"type":"build","id":"$roaddeco_trafficlights01"}
    }
  },

  {"id":"$anim_roaddeco_trafficlights01_00","type":"animation","frames":[{"x":0,"y":368,"w":32,"h":16,"handle y":8,"offset y":3072}]},
  {"id":"$anim_roaddeco_trafficlights01_01","type":"animation","frames":[{"x":32,"y":368,"w":32,"h":16,"handle y":8,"offset y":3072}]},
  {"id":"$anim_roaddeco_trafficlights01_02","type":"animation","frames":[{"x":64,"y":368,"w":32,"h":16,"handle y":8,"offset y":3072}]},
  {"id":"$anim_roaddeco_trafficlights01_03","type":"animation","frames":[{"x":92,"y":368,"w":32,"h":16,"handle y":8,"offset y":3072}]},
  {
    "hidden":true,
    "id":"$roaddeco_trafficlights01",
    "type":"road decoration",
    "title id":"draft_roaddeco_trafficlights00_title",
    "text id":"draft_roaddeco_trafficlights00_text",
    "price":100,
    "enter speed":0,
    "animation":[
      {"id":"$anim_roaddeco_trafficlights01_00"},
      {"id":"$anim_roaddeco_trafficlights01_02"}
    ],
    "frame animation indices":[
      [0,1],[0,1],[1],[1],
      [0],[0],[],[],
      [0,1],[0,1],[1],[1],
      [0],[0],[],[]
    ],
    "animation fg":[
      {"id":"$anim_roaddeco_trafficlights01_01"},
      {"id":"$anim_roaddeco_trafficlights01_03"}
    ],
    "frame animation fg indices":[
      [0,1],[0],[0,1],[0],
      [0,1],[0],[0,1],[0],
      [1],[],[1],[],
      [1],[],[1],[]
    ],
    "fun":{
      "condition":"day%10<8",
      "action":{"type":"build","id":"$roaddeco_trafficlights00"}
    }
  }
There are actually two decorations that use different frames. One of them stops incoming cars by using "enter speed":0. They replace themself with the other variant at specific days (namely when the remainder of absolute day divided by 10 is <8 or >=8).