Roads

Learn here how to create and use plugins.

Moderator: Plugin Moderators

User avatar
Lobby
Developer
Reactions:
Posts: 3705
Joined: 26 Oct 2008, 12:34
Plugins: Showcase Store
Version: Beta

Platform

Roads

#1

Post by Lobby »

So let's create a road plugin. I would like to have a blue road similar to the existing country road that looks like this:
Image


To get started we need some frames for the base graphics first: road.png
Image
The orientation follows a specific order. For your own road it's sufficient to use this graphic as template. You have to provide 16 frames here.

As we want to have a bridge we also have to provide graphics for it: bridge.png
image.png
image.png (7.44 KiB) Viewed 24154 times
The ordering is important :!:
The number of frames must be a multiple of frames per bridge type. If you have 12 frames per bridge type (the default) and provide 24 frames for example, your road will have two types of bridges. You can set a higher frames per bridge type value by using

Code: Select all

"frames per bridge":X
with X being 12, 16, 18 or 20 dependent on how many frames you want to provide per bridge. Providing more frames gives you more flexibility on how the bridge will look like. The bridge frames will be used that way:

Code: Select all

At least 12 frames per bridge
16 to provide ramp graphics which will be used for bridges starting from ground
18 to support "mid" pile frames
20 to support top pile frames

Frame usage:
0-3: slopes
4-7: small railings
8-9: piles
10-11: piles on water (only used on lowest part)
12-13: pile frames for mid part (and top if not provided) (if frames >= 18)
14-15: pile frames for top part (if frames >= 20)
last 4 frames: ramp under road for bridge slopes starting at level 0 (if frames >= 16)
Additionally, in case we want to have some traffic lights, we might use this ones: tf.png
Image
If we use traffic lights, we also have to provide more information about phase lengths.

Our json code may now look like

Code: Select all

[
  {
    "id":"$testroad00",
    "type":"road",
    "level":1,
    "speed":2.0,

    "frames":[{"bmp":"road.png","w":32,"h":16,"count":16}],

    "bridge frames":[{"bmp":"bridge.png","w":32,"h":48,"count":12}],
    "frames per bridge":12,

    "traffic lights":[{"bmp":"tf.png","w":32,"h":32,"count":4}],
    "green phase":3000,
    "yellow phase":500,

    "price":50,
    "bridge price":200,
    "monthly price":2
  }
]
Note how I use can reference multiple frames from one image by providing values w, h and count.

The value level determines whether this road overrides other road types. Every road has it's own level and can only override roads which have a lower level. Value speed determines how fast cars will drive on this road. For reference, the slowest road has speed 1.0, the fastest road has speed 5.0 (natively in the game).

If you don't provide any frames for traffic lights your road won't have any. The values green phase and yellow phase indicate phase length in milliseconds (1000ms = 1s).



:66:
For recent versions please note that the road on the ramp needs one additional line of pixels on the top end to cover specific transitions between slopes and none slopes. The ramps in the image above have already been fixed.

Since terrain was added you can now specify your own frames that will be used for road that is placed directly onto slopes:

Code: Select all

"slope frames":[
  {"x":120,"y":311,"w":32,"h":32,"count":4,"offset x":2048,"offset y":1024}
],
For example:
image.png
image.png (2.68 KiB) Viewed 24154 times
By default the game will use the frames provided for flat road and squeeze them onto the slope. Alternatively, if provided, the ramps of the bridge(s) will be used.

See here for how to support pedestrians on your road: viewtopic.php?f=41&t=14155
For diagonal roads see here: viewtopic.php?p=171988#p171988
Last edited by Lobby on 04 Jun 2017, 23:47, edited 1 time in total.

User avatar
Lobby
Developer
Reactions:
Posts: 3705
Joined: 26 Oct 2008, 12:34
Plugins: Showcase Store
Version: Beta

Platform

#2

Post by Lobby »

There are some more values you might optionally provide.

Show
auto join (default=true)
Determines whether neighboring roads should be joined automatically. May be useful for roads with multiple lanes (see value "width" below).
Show
allow bus (default=true)
Determines whether bus stops may be place on this road.
Show
allow transfer (default=true)
Determines whether buildings have a road connection if they are nearby.
Show
allow crossing (default=true)
Determines whether road tool should allow X crossings. We discourage you to use it as it's no fun for the player.
Show
one way (default=false)
If true, cars can only drive into one direction on this road type. You then have to provide 64 instead of 16 frames. First 16 frames will be used for alignment SOUTH_EAST, the next 16 frames for NORTH_EAST, then NORTH_WEST and at least SOUTH_WEST. You may save texture space by providing the first 16 frames multiple times and use one way frames for an alignment specific overlay.
Show
one way frames (default=empty by default)
For one ways only. Here you can provide 4 frames which will then be used as overlay dependent on road alignment. The order is SOUTH_EAST, NORTH_EAST, NORTH_WEST, SOUTH_WEST.
Show
overrunnable (default=true)
For one ways only. If true, cars may overrun others on this one way.
Show
width (default=1)
Number of lanes that should be built at the same time from road tool. In combination with flag one way this can be used to define highways or alleys. For alleys you can define decorations that should be used with decoration buildings.
Show
decoration buildings (empty by default)
Only used if width is odd and greater than 2. An array of ids of 1x1 sized decoration buildings that should be used for decoration purposes. For example the default alley uses "$decoroad00".
Show
connectable (default=true)
If true, this road can connect to neighbor cities.
Show
pile distant (default=2)
In case you use bridges this is the intended distance between piles.
Show
enter speed
A float value multiplied to the speed of incoming cars. Default value is 1.0
Show
exit speed
A float value multiplied to the speed of outgoing cars. Default value is 1.0
Show
parcel speeds
Similar to the speed attribute, but works on a per tile basis and per parcel basis. Because of that you provde an array of float numbers that will be used as multiplier. If an insufficient number of factors was supplied then numbers will be reused. For example by only defining for factors you could control the speeds for the parcels of all tiles simoultaneously. In regard to ordering the first fource entries will be used for the four parcels of the first tile and so on. So the following are common amounts of entries for the array:
  • 4 - To set the speeds for the four parcels to the same values for all tiles of the road
  • 64 - To set the parcel speeds of all parcels of all tiles individually
  • 256 - Only needed in case you want to set the speeds of all parcels and all tiles of a one way road individually per one way direction
The ordering of four parcels is as following:
  • 0 - left
  • 1 - bottom
  • 2 - top
  • 3 - right
Example:

Code: Select all

"parcel speeds":[1,2,2,1]

You can also set flags. For more information about that see this thread.
Last edited by Lobby on 09 Jun 2017, 21:51, edited 2 times in total.

User avatar
Lobby
Developer
Reactions:
Posts: 3705
Joined: 26 Oct 2008, 12:34
Plugins: Showcase Store
Version: Beta

Platform

Re: Roads

#3

Post by Lobby »

In case you need templates for your own roads, here you have our frames for dirty road and country road.
dirt_road[1].png
dirt_road[1].png (7.61 KiB) Viewed 18920 times
country_road[1].png
country_road[1].png (5.98 KiB) Viewed 18920 times
As usual, you're free to use these graphics in your own TheoTown plugins as long as you state it's source (me and theo) in your publications of it.

User avatar
Lobby
Developer
Reactions:
Posts: 3705
Joined: 26 Oct 2008, 12:34
Plugins: Showcase Store
Version: Beta

Platform

Re: Roads

#4

Post by Lobby »

We added as speed that is only use if winter is active:

speed winter (default=speed)
Speed on this road in winter.

User avatar
CommanderABab
AB
Reactions:
Posts: 11086
Joined: 07 Jun 2016, 21:12
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Road Animations

#5

Post by CommanderABab »

See here for downloadhttp://www.theotown.com/forum/viewtopic ... 211#p43211

Code: Select all

{
    "id":"$ab.roadanim1",
    "author":"CommanderABab",
    "type":"animation",
	"width":1,
	"height":1,
	
	"frames":[
    {"bmp":"rainbowbar1.png","w":4,"target w":31,"target h":15,"handle x":0,"handle y":1,"offset x":0,"offset y":0,"count":16},
     {"bmp":"rainbowbar1.png","w":4,"target w":31,"target h":15,"handle x":0,"handle y":1,"offset x":0,"offset y":0,"count":16}
    ],
    "color":{"r":300,"g":300,"b":300,"a":95}
}
For reference only
For reference only
rainbowbar1.png (681 Bytes) Viewed 28181 times

Code: Select all

{  "id":"$ab.roadanim2",
    "author":"CommanderABab",
    "type":"animation",
	"width":1,
	"height":1,
	
	"frames":[
    {"bmp":"drainbowbar1.png","w":4,"target w":31,"target h":15,"handle x":0,"handle y":1,"offset x":0,"offset y":0,"count":16},
     {"bmp":"drainbowbar1.png","w":4,"target w":31,"target h":15,"handle x":0,"handle y":1,"offset x":0,"offset y":0,"count":16}
    ],
    "color":{"r":300,"g":300,"b":300,"a":95}
}
For reference only
For reference only
drainbowbar1.png (724 Bytes) Viewed 28181 times
Since the different color frames are only 4x4, they are enlarged using the target w and target h. I used 31 and 15 to stay within the road tile. The handle y:1 sets the animation so it can be seen.

The color statement determines amount of each color to allow through. "a" alpha of 0 would not show anything. 95 allows most of the projected image through.

Code: Select all

{
    "id":"$ab.test_road4",
    "title":"dirt road rainbow",
    "text":"showing how to use animations on roads",
    "author":"Lobby Divinus",
    "type":"road",
    "level":10,
    "frames":[{"x":512,"y":0,"w":32,"h":16,"count":16}],
    "speed":1.0,
    "animation":[
      {"id":"$animationblinkingredlight3x3","x":15,"y":-1},
      {"id":"$ab.roadanim1"},
      {"id":"$ab.roadanim2"}
    ],
    "frame animation indices":[
      [0,1,2],
      [0,1,2],
      [0,1,2],
      [1,2],

      [0,1,2],
      [1,2],
      [1,2],
      [1,2],

      [0,1,2],
      [1,2],
      [1,2],
      [1,2],

      [1,2],
      [1,2],
      [1,2],
      [0]
    ],
    "price":10,
    "monthly price":1,
    "connectable":false
  }
]

The road is level 10?
That's the way the example came to me! B)

How are the animations shown?
There are indices to each animation defined in the animations statement.
[0] is the first defined, [1] the next, etc.

So on my road:
[0] shows the blinking red light at that road tile. [] would show none of the animations. [1,2] shows the changing rainbow animations. [0,1,2] shows all three. You could have more.

User avatar
Hadestia
Inhabitant of a Megalopolis
Reactions:
Posts: 727
Joined: 17 Jul 2017, 16:16
Location: Philippines
Plugins: Showcase Store
Contact:

Plugin Creator

Platform

Re: Roads

#6

Post by Hadestia »

i have question how about like highway whats the code for it and what are the value of height and width? or for those alley

User avatar
Kulche
Pluche
Reactions:
Posts: 1141
Joined: 07 Jun 2017, 20:28
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Roads

#7

Post by Kulche »

rjroldan1 wrote:
29 Aug 2017, 02:39
i have question how about like highway whats the code for it and what are the value of height and width? or for those alley
Said above.
Width must be greater than 2 to place decos.

User avatar
CommanderABab
AB
Reactions:
Posts: 11086
Joined: 07 Jun 2016, 21:12
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Roads

#8

Post by CommanderABab »

Width must be odd above or equal to 3 for decos.

User avatar
JustAnyone
Developer
Reactions:
Posts: 3474
Joined: 23 Jul 2017, 12:45
Location: Easter Island
Plugins: Showcase Store

Platform

Re: Roads

#9

Post by JustAnyone »

Can I use steal frames attribute for roads? And how?

User avatar
JustAnyone
Developer
Reactions:
Posts: 3474
Joined: 23 Jul 2017, 12:45
Location: Easter Island
Plugins: Showcase Store

Platform

Re: Roads

#10

Post by JustAnyone »

KoalaGuy wrote:
12 Nov 2017, 13:52
JustAnyone wrote:
12 Nov 2017, 13:45
Can I use steal frames attribute for roads? And how?
Yes. Same as in every other building. I think there's a topic for that.

Code: Select all

[
{
"id":"$devroad001",
"type":"road",
"hidden":false,
"override":true,
"level":3,
"speed": 3.5,
"title":"DSA Vehicle Road",
"text":"Dedicated road for all DSA vehicles.",
"frames": [{
		"steal":"$devroad00"
	}],
 "price":50,
 "monthly price":2
 }
]

User avatar
CommanderABab
AB
Reactions:
Posts: 11086
Joined: 07 Jun 2016, 21:12
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Roads

#11

Post by CommanderABab »

Nope.

User avatar
JustAnyone
Developer
Reactions:
Posts: 3474
Joined: 23 Jul 2017, 12:45
Location: Easter Island
Plugins: Showcase Store

Platform

Re: Roads

#12

Post by JustAnyone »

Or there is another option.
@Lobby could I get national road textures?

User avatar
Lobby
Developer
Reactions:
Posts: 3705
Joined: 26 Oct 2008, 12:34
Plugins: Showcase Store
Version: Beta

Platform

Re: Roads

#13

Post by Lobby »

:img
Attachments
national_road.png
national_road.png (3.48 KiB) Viewed 27694 times

User avatar
fico240
Townsman
Reactions:
Posts: 64
Joined: 21 Dec 2017, 03:20
Location: Córdoba, Argentina
Plugins: Showcase Store
Version: Beta

Platform

Re: Roads

#14

Post by fico240 »

I don't know how write a title and description :(
The name of road is: <draft:unidirectionalfreeway:title>

User avatar
CommanderABab
AB
Reactions:
Posts: 11086
Joined: 07 Jun 2016, 21:12
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Roads

#15

Post by CommanderABab »

Code: Select all

  "title":"unidirectional freeway",
  "text":"freeway lanes to be placed in one direction","...

User avatar
fico240
Townsman
Reactions:
Posts: 64
Joined: 21 Dec 2017, 03:20
Location: Córdoba, Argentina
Plugins: Showcase Store
Version: Beta

Platform

Re: Roads

#16

Post by fico240 »

CommanderABab wrote:
24 Dec 2017, 18:46

Code: Select all

  "title":"unidirectional freeway",
  "text":"freeway lanes to be placed in one direction","...
Yes, I know, but when I add it to the json, it does not let me use the plugin

User avatar
CommanderABab
AB
Reactions:
Posts: 11086
Joined: 07 Jun 2016, 21:12
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Roads

#17

Post by CommanderABab »

For example:

Code: Select all

{  
     "active": true,
     "id":"$redyellow00", 
     "type":"road", 
    // "ordinal":10,
     //"category":"$ab.myroads.s00utile",
     //"author": "Commander ABab",
     "level":4,
     "width":2,
     "height":1,
     "frames":[
       {"bmp":"yellowroad.png","w":32,"count":16},
       {"bmp":"yellowroad.png","w":32,"count":16},
       {"bmp":"yellowroad.png","w":32,"count":16},
       {"bmp":"yellowroad.png","w":32,"count":16}    
     ],
     
     "one way frames":[
       {"steal":"$arrows04","frame":0,"count":4}
     ],
     "show arrows":true,
     "bridge frames":[ 
       {"bmp":"Gb1.png"},
       {"bmp":"Gb2.png"},
       {"bmp":"Gb3.png"},
       {"bmp":"Gb4.png"},
       {"bmp":"Gb5.png","handle x":0,"handle y":19},
       {"bmp":"Gb6.png","handle x":0,"handle y":19},
       {"bmp":"Gb7.png","handle x":0,"handle y":19},
       {"bmp":"Gb8.png","handle x":0,"handle y":19},
       {"bmp":"Gb9.png","handle x":0,"handle y":19},
       {"bmp":"Gb10.png","handle x":0,"handle y":19},
       {"bmp":"Gb11.png","handle x":0,"handle y":19},
       {"bmp":"Gb12.png","handle x":0,"handle y":19}
     ],
     "traffic lights":[
       {"bmp":"Gtl3.png"},
       {"bmp":"Gtl4.png"},
       {"bmp":"Gtl1.png"},
       {"bmp":"Gtl2.png"}
     ],
     "bridge height":        -20,
     "bridge price":         100,
     "overrunnable":         false,
     "one way":              true,
     "green phase":          6000,
     "yellow phase":         1000,
     "speed":                25.2,
     "price":                50, 
     "monthly price":        4,
     "auto join":      false,
     "allow bus stop": true,
     "allow crossing": false,
     "allow transfer": true,
     "title":"Yellow Road", 
     "text":"\nFor those from desert areas. :)"
  },
What does your .json look like?

If you have

Code: Select all

     "one way": true,
, then you have to provide 64 frames for the road:

Code: Select all

"frames":[
       {"bmp":"yellowroad.png","w":32,"count":16},
       {"bmp":"yellowroad.png","w":32,"count":16},
       {"bmp":"yellowroad.png","w":32,"count":16},
       {"bmp":"yellowroad.png","w":32,"count":16}    
     ],

User avatar
fico240
Townsman
Reactions:
Posts: 64
Joined: 21 Dec 2017, 03:20
Location: Córdoba, Argentina
Plugins: Showcase Store
Version: Beta

Platform

Re: Roads

#18

Post by fico240 »

CommanderABab wrote:
24 Dec 2017, 19:16
For example:

Code: Select all

{  
     "active": true,
     "id":"$redyellow00", 
     "type":"road", 
    // "ordinal":10,
     //"category":"$ab.myroads.s00utile",
     //"author": "Commander ABab",
     "level":4,
     "width":2,
     "height":1,
     "frames":[
       {"bmp":"yellowroad.png","w":32,"count":16},
       {"bmp":"yellowroad.png","w":32,"count":16},
       {"bmp":"yellowroad.png","w":32,"count":16},
       {"bmp":"yellowroad.png","w":32,"count":16}    
     ],
     
     "one way frames":[
       {"steal":"$arrows04","frame":0,"count":4}
     ],
     "show arrows":true,
     "bridge frames":[ 
       {"bmp":"Gb1.png"},
       {"bmp":"Gb2.png"},
       {"bmp":"Gb3.png"},
       {"bmp":"Gb4.png"},
       {"bmp":"Gb5.png","handle x":0,"handle y":19},
       {"bmp":"Gb6.png","handle x":0,"handle y":19},
       {"bmp":"Gb7.png","handle x":0,"handle y":19},
       {"bmp":"Gb8.png","handle x":0,"handle y":19},
       {"bmp":"Gb9.png","handle x":0,"handle y":19},
       {"bmp":"Gb10.png","handle x":0,"handle y":19},
       {"bmp":"Gb11.png","handle x":0,"handle y":19},
       {"bmp":"Gb12.png","handle x":0,"handle y":19}
     ],
     "traffic lights":[
       {"bmp":"Gtl3.png"},
       {"bmp":"Gtl4.png"},
       {"bmp":"Gtl1.png"},
       {"bmp":"Gtl2.png"}
     ],
     "bridge height":        -20,
     "bridge price":         100,
     "overrunnable":         false,
     "one way":              true,
     "green phase":          6000,
     "yellow phase":         1000,
     "speed":                25.2,
     "price":                50, 
     "monthly price":        4,
     "auto join":      false,
     "allow bus stop": true,
     "allow crossing": false,
     "allow transfer": true,
     "title":"Yellow Road", 
     "text":"\nFor those from desert areas. :)"
  },
What does your .json look like?

If you have

Code: Select all

     "one way": true,
, then you have to provide 64 frames for the road:

Code: Select all

"frames":[
       {"bmp":"yellowroad.png","w":32,"count":16},
       {"bmp":"yellowroad.png","w":32,"count":16},
       {"bmp":"yellowroad.png","w":32,"count":16},
       {"bmp":"yellowroad.png","w":32,"count":16}    
     ],
thanks, @CommanderABab now my route contain title!

User avatar
mdk_813
Inhabitant of a Country
Reactions:
Posts: 857
Joined: 16 Dec 2016, 02:38
Location: Germany
Plugins: Showcase Store

Platform

Re: Roads

#19

Post by mdk_813 »

Hi guys,
I have a question.
Let's say I want to make a oneway-road, but without 64 frames and without an arrow-overlay. Would it be possible to provide just 16 frames and still have it work as a oneway road. Obviously one would have to pay attention to use the proper directions when building it, but still, would it work?

User avatar
mdk_813
Inhabitant of a Country
Reactions:
Posts: 857
Joined: 16 Dec 2016, 02:38
Location: Germany
Plugins: Showcase Store

Platform

Re: Roads

#20

Post by mdk_813 »

Thanks, @KoalaGuy !

Post Reply Previous topicNext topic

Return to “Tutorials and Documentation”