Compositions

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

Compositions

#1

Post by Lobby »

Overview
Compositions are a way to combine buildings, roads, road decorations and trees as a building. An important property of compositions is the support of a non square ground size. Therefore it could be used to make up non squared buildings for example :teach

Compositions are used for example for the pre-built train stations :img
sample_composition.png


Definition
Technically compositions are defined as buildings that contain a list of the "things" they are built up with. The user can build it like a regular building, the preview displays the actual contents of the building. However, once the player issues to build the building the actual contents of the building will be built instead.

Basic structure (here for the train station as an example) :json

Code: Select all

[
  {
    "id": "$somerandomid00",
    "type": "decoration",
    "width": 4,
    "height": 2,
    "composition": [
      {"id": "$trainplatform03","x": 0,"y": 0,"frame": 1}, // A platform
      ...
      {"id": "$rails00","x0": 0,"y0": 1,"x1": 3,"y1": 1},  // Rails/road
      ...
      {"id": "$railroof01","x": 1,"y": 1},                 // Road decoration (for the rail)
      ...
    ]
  }
]
To understand how it's built up let's try to make a composition of the following:
draft.png
So basically a road with a crossing on it and a park. The size of the building is 4x2. The basic structure of the building might look like:

Code: Select all

[{
  "id": "$compositionexample00",
  "type": "decoration",
  "width": 4,
  "height": 2,
  "composition": []   -- We will put something in here
}]
Note that we will put the components of the composition into the composition array. Let's begin with the park. Since it's a building (we'll use the park with id $park01 for it) all we have to provide is the id, the position x, y within the composition. Optionally we can specify which frame of the park should be used. If we don't provide a frame the game will pick one randomly (if multiple are available). The code for the park:

Code: Select all

{"id": "$park00", "x": 0, "y": 1, "frame": 0}
The next thing will be the road. We will use $road01 (the country road) and have to provide the starting position x0, y0 and the target position x1, y1. To form a line that is axis aligned these parameters have to obey x0 == x1 or y0 == y1 (or both). With that, the code for the road would be:

Code: Select all

{"id": "$road01", "x0": 0, "y0": 0, "x1": 3, "y1": 0}
Note that y0 == y1, so the condition mentioned above is fulfilled. Roads will connect to neighboring roads automatically if they intersect with them or if the start/end point is near to a connectable road.
Last but not least we want to put a crossing on the road. For that we will use the road decoration of id $roaddeco_crosswalk00. Similar to buildings it's sufficient to provide the id as well as a position x, y:

Code: Select all

{"id": "$roaddeco_crosswalk00", "x": 1, "y": 0}
Done!

Let's insert these objects into the composition array above and we get :json

Code: Select all

[{
  "id": "$compositionexample00",
  "type": "decoration",
  "width": 4,
  "height": 2,
  "composition": [
    {"id": "$park01", "x": 0, "y": 1, "frame": 0},
    {"id": "$road01", "x0": 0, "y0": 0, "x1": 3, "y1": 0},
    {"id": "$roaddeco_crosswalk00", "x": 1, "y": 0}
  ]
}]
Alternatively you may download it as a ready to play plugin (no external files needed):
composition_example.json
(418 Bytes) Downloaded 299 times
which results in :img
result.png
result.png (186.35 KiB) Viewed 14285 times
As you can see it's possible to rotate the composition. If rotation aware buildings are part of the composition they will rotate accordingly.



:66:
image.png
image.png (548.69 KiB) Viewed 13665 times

Code: Select all

[{
  "id": "$compositionexample01",
  "type": "decoration",
  "width": 3,
  "height": 3,
  "composition": [
    {"id": "$road01", "x0": 0, "y0": 0, "x1": 2, "y1": 0,"l0":0,"l1":1},
    {"id": "$road01", "x0": 2, "y0": 0, "x1": 2, "y1": 2,"l0":1,"l1":2},
    {"id": "$road01", "x0": 2, "y0": 2, "x1": 0, "y1": 2,"l0":2,"l1":3},
    {"id": "$road01", "x0": 0, "y0": 1, "x1": 2, "y1": 1,"join":false}
  ]
}]
For road decorations and bus stops you can provide a level attribute (0 by default).

New attributes were added for roads in compositions, namely:
Show
l0, l1
Use these to specify the start and the end level of the road with "l0" being the start, and "l1" the end level.

The default values are 0 which means on ground (also in context of terrain; road levels are always relative to the ground). The behavior is the same as if you would use the road tool to build a road by hand (e.g. start and end point of the road are always flat)
Show
join
By default, the roads in road compositions join to other roads. However, in some cases you may not want that to happen. Now you can prevent that by using:

Code: Select all

"join":false
The road will still align to other roads that it intersects.
You may for example create intersections with these. The composition extractor mentioned below doesn't work for roads that are not on ground.

Since version 1.10.62 you can also include bus stops in your compositions. Lines for bus stops will look like that:

Code: Select all

{"id": "$busstop00", "x":1, "y":0, "level":0}

Tool
To make building up a composition easier there's a tool to convert a selected rectangle from a city to corresponding json code. It's part of the Plugin Creator Tools that you may find in the Plugin Store (you may find it via search function or listed in Categories->Tools).

Once you have installed the tool(s) you can select it from the toolbar. After that mark the area you want to create a json composition code for. The code will be copied into your clipboard then. This may look like:

Code: Select all

{
  "width":4,"height":2,
  "composition":[
    {"y0":0,"x0":0,"y1":0,"x1":3,"id":"$road01"},
    {"level":0,"x":1,"y":0,"id":"$roaddeco_crosswalk00"},
    {"x":0,"y":1,"id":"$park01","frame":0}
  ]
}
Note that it's up to you to add at least an id as well as a building type (e.g. decoration) to it.

Known issues:
-The tool does not always handle road curves correctly.
-Road levels aren't supported, yet.

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: Compositions

#2

Post by Hadestia »

Can you give sample zip for this Lobby?

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

Platform

Re: Compositions

#3

Post by Lobby »

Of course! Added the json file to it :json

User avatar
BetterBear
Inhabitant of a Galaxy Cluster
Reactions:
Posts: 2896
Joined: 18 Apr 2017, 09:03
Location: In a place you don't expect.
Plugins: Showcase Store
Version: Beta

Platform

Re: Compositions

#4

Post by BetterBear »

Thank you!

This will definately make some things come to life, such as one-tap custom intersections. :)

User avatar
Ssss
Metropolitan
Reactions:
Posts: 136
Joined: 24 Feb 2018, 14:51
Location: South korea
Plugins: Showcase Store
Version: Beta
Contact:

Plugin Creator

Platform

Re: Compositions

#5

Post by Ssss »

When i use "Composition" to make 1×3 building, there is an error(game was shutdowned when i place my building). It work before i add two or more frames.

This is my plugin that has some problems.

Code: Select all

[
{
"id":"$Composition_Test1_MSG$",
"type":"decoration",
"width":1,
"height":1,
"buildtime":0,
"needsroad":false,
"author":"MSG",
"drawground":true,
"influencepark":30,
"influencepolice":100,
"influenceculture":2,
"price":0,
"monthlyprice":0,
"frames":[
{
"bmp":"1.png"
},
{
"bmp":"4.png"
}
],
"rotationaware":false
},
{
"id":"$Composition_Test2_MSG$",
"type":"decoration",
"width":1,
"height":1,
"buildtime":0,
"needsroad":false,
"author":"MSG",
"drawground":true,
"influencepark":30,
"influencepolice":100,
"influenceculture":2,
"price":0,
"monthlyprice":0,
"frames":[
{
"bmp":"2.png"
},
{
"bmp":"5.png"
}
],
"rotationaware":false
},
{
"id":"$Composition_Test3_MSG$",
"type":"decoration",
"width":1,
"height":1,
"buildtime":0,
"needsroad":false,
"author":"MSG",
"drawground":true,
"influencepark":30,
"influencepolice":100,
"influenceculture":2,
"price":0,
"monthlyprice":0,
"frames":[
{
"bmp":"3.png"
},
{
"bmp":"6.png"
}
],
"rotationaware":false
},
{
"id":"$Composition_Test_MSG$",
"text":"Test",
"title":"Test",
"type":"park",
"width":3,
"height":1,
"composition":[
{
"id":"$Composition_Test1_MSG$",
"x":0,
"y":0
},
{
"id":"$Composition_Test2_MSG$",
"x":1,
"y":0
},
{
"id":"$Composition_Test3_MSG$",
"x":2,
"y":0
}
],
"rotationaware":false
}
]
P.S. I cannot login & register.I also haven't received any mail. It's not just my problem some of user cannot receive any mail and also accounts are inactive...
-MsgmSgmsG-

MsgmSgmsG said

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

Platform

Re: Compositions

#6

Post by Lobby »

This code works for me, did he ensure that he has the latest version (that is 606)?

User avatar
Ssss
Metropolitan
Reactions:
Posts: 136
Joined: 24 Feb 2018, 14:51
Location: South korea
Plugins: Showcase Store
Version: Beta
Contact:

Plugin Creator

Platform

Re: Compositions

#7

Post by Ssss »

Ssss wrote:
02 May 2019, 15:04
When i use "Composition" to make 1×3 building, there is an error(game was shutdowned when i place my building). It work before i add two or more frames.

This is my plugin that has some problems.

Code: Select all

[
{
"id":"$Composition_Test1_MSG$",
"type":"decoration",
"width":1,
"height":1,
"buildtime":0,
"needsroad":false,
"author":"MSG",
"drawground":true,
"influencepark":30,
"influencepolice":100,
"influenceculture":2,
"price":0,
"monthlyprice":0,
"frames":[
{
"bmp":"1.png"
},
{
"bmp":"4.png"
}
],
"rotationaware":false
},
{
"id":"$Composition_Test2_MSG$",
"type":"decoration",
"width":1,
"height":1,
"buildtime":0,
"needsroad":false,
"author":"MSG",
"drawground":true,
"influencepark":30,
"influencepolice":100,
"influenceculture":2,
"price":0,
"monthlyprice":0,
"frames":[
{
"bmp":"2.png"
},
{
"bmp":"5.png"
}
],
"rotationaware":false
},
{
"id":"$Composition_Test3_MSG$",
"type":"decoration",
"width":1,
"height":1,
"buildtime":0,
"needsroad":false,
"author":"MSG",
"drawground":true,
"influencepark":30,
"influencepolice":100,
"influenceculture":2,
"price":0,
"monthlyprice":0,
"frames":[
{
"bmp":"3.png"
},
{
"bmp":"6.png"
}
],
"rotationaware":false
},
{
"id":"$Composition_Test_MSG$",
"text":"Test",
"title":"Test",
"type":"park",
"width":3,
"height":1,
"composition":[
{
"id":"$Composition_Test1_MSG$",
"x":0,
"y":0
},
{
"id":"$Composition_Test2_MSG$",
"x":1,
"y":0
},
{
"id":"$Composition_Test3_MSG$",
"x":2,
"y":0
}
],
"rotationaware":false
}
]
P.S. I cannot login & register.I also haven't received any mail. It's not just my problem some of user cannot receive any mail and also accounts are inactive...
-MsgmSgmsG-

MsgmSgmsG said
Attachments
Composition_test.zip
(169.96 KiB) Downloaded 228 times

User avatar
Ssss
Metropolitan
Reactions:
Posts: 136
Joined: 24 Feb 2018, 14:51
Location: South korea
Plugins: Showcase Store
Version: Beta
Contact:

Plugin Creator

Platform

Re: Compositions

#8

Post by Ssss »

Lobby wrote:
02 May 2019, 16:01
This code works for me, did he ensure that he has the latest version (that is 606)?
Attachments
Composition_test.zip
(169.96 KiB) Downloaded 221 times

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

Platform

Re: Compositions

#9

Post by Lobby »

The composition building has to be rotation aware since the map can be rotated. Therefor, remove the line

Code: Select all

"rotation aware":false
from your composition building $Composition_Test_MSG and it should work.

User avatar
Mrqwerty
Inhabitant of a Megalopolis
Reactions:
Posts: 579
Joined: 06 Oct 2018, 21:48
Location: Vermont, United States
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Compositions

#10

Post by Mrqwerty »

Can RCI be built in a composition?

User avatar
Mrqwerty
Inhabitant of a Megalopolis
Reactions:
Posts: 579
Joined: 06 Oct 2018, 21:48
Location: Vermont, United States
Plugins: Showcase Store
Version: Beta

Plugin Creator

Platform

Re: Compositions

#11

Post by Mrqwerty »

Ok i guess it can have rci. I tried it. Also the tool is very helpful!

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

Platform

Re: Compositions

#12

Post by Lobby »

:66: Time for some pre-built intersections I guess.

User avatar
XNOTE
Settler
Reactions:
Posts: 3
Joined: 04 Nov 2018, 18:45
Location: Republic of Korea
Plugins: Showcase Store
Version: Beta

Re: Compositions

#13

Post by XNOTE »

Is this only working on 1x1 buildings? (I was trying to make my own composition with 8x8 buildings and it doesn't build any building.

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

Plugin Creator

Platform

Re: Compositions

#14

Post by CommanderABab »

It works for other sizes also, but placement is tricky.

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

Plugin Creator

Platform

Re: Compositions

#15

Post by CommanderABab »

Screenshot_20190704-110549.png
Screenshot_20190704-110749.png
Screenshot_20190704-111119.png
Screenshot_20190704-110613.png
Screenshot_20190704-111135.png
It's mostly industrial, but there are a decoration and a small fire station included. To place requires a large area zoned industrial. Roads will have to be built surrounding the buildings to keep them viable.

User avatar
AngelPandaEarth
Small-town resident
Reactions:
Posts: 32
Joined: 11 Jun 2018, 04:14
Location: United States
Plugins: Showcase Store
Contact:

Plugin Creator

Platform

Re: Compositions

#16

Post by AngelPandaEarth »

Wow, so I can add presets to a future plugin I'm making.

User avatar
Sparkle8538
Small-town resident
Reactions:
Posts: 25
Joined: 26 Jul 2019, 11:35
Plugins: Showcase Store

Re: Compositions

#17

Post by Sparkle8538 »

Screenshot_20190829-170600.png

User avatar
choggoba
Townsman
Reactions:
Posts: 50
Joined: 20 Jul 2018, 08:30
Location: Korea
Plugins: Showcase Store

Platform

Re: Compositions

#18

Post by choggoba »

When inserting a one-way road (64 frames) into a composition tag,
The completed road uses 64 frames.

However, before road construction (preview), only 16 frames are used.

So users can't predict exactly what the road will look like before it's built.
What should I do?
Screenshot_20200717-092951_TheoTown.jpg
Screenshot_20200717-093026_Pixly.jpg

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

Platform

Re: Compositions

#19

Post by Lobby »

I have to admit, I don't see a difference between them in the image.

However, it is correct, the game does not use direction information for the preview of roads in compositions as of right now.



Please send me your plugin including the composition, I will then try to fix that :)

User avatar
AngelPandaEarth
Small-town resident
Reactions:
Posts: 32
Joined: 11 Jun 2018, 04:14
Location: United States
Plugins: Showcase Store
Contact:

Plugin Creator

Platform

Re: Compositions

#20

Post by AngelPandaEarth »

Why can't I place this
Screenshot_20210103-023135_TheoTown.jpg

Post Reply Previous topicNext topic

Return to “Tutorials and Documentation”