Skip to content

Context sensitive content

rumangerst edited this page Oct 6, 2017 · 17 revisions

CSL Music Mod extends the functionality of the Cities: Skylines radio with the "context-sensitive content" feature. You can use it to further enhance your stations and react to different conditions in your map. For example you could use it to play different songs at night or include weather-warnings when it's raining.

This feature currently supports following environmental conditions:

  • Time
  • Weather
  • Mood/Happiness of your Cims
  • Disasters

Contexts are set up by the contexts-setting, a list that contain entries that describe which music collections are used when the conditions apply. The mod begins with the first item, check if the conditions apply and if they do, the mod will restrict the content to the one set in the entry. Otherwise it will try the next in the list.

An example:

{
    "name" : "SimCity Extra",
    "collections" : ["SimCity Day", "SimCity Night"],
    "filters" : {
        "day" : { "type" : "time", "from" : 6, "to" : 20 },
        "night" : { "type" : "time", "from" : 20, "to" : 6 }
    },
    "contexts" : [
        { "conditions" : [ [ "day" ] ], "collections" : ["SimCity Day"]},
        { "conditions" : [ [ "night" ] ], "collections" : ["SimCity Night"]}
    ]
}

This file defines the station "SimCity Extra" that loads music from two collections (folders) "SimCity Day" and "SimCity Night". First, two filters are defined (day and night) that will be used in the the part that describes which conditions should be checked by the contexts. The context list contains two entries. Both of them use time type filters to check if the context applies. The time filters check if the current time is between from and to. The mod will begin with the first one, checks if all conditions (here only 1, but you can have more) do apply (e.g. when it's 12'o clock) and then forces all content be be taken only from "SimCity Day". If it's night, the first one does not apply and "SimCity Night" will be played.

You can have multiple conditions per entry: For example "If it's night and it's raining, then play content from xyz"

Condition logics

The conditions settings allows you to define conditions that must apply to force the list of collections defined in collections. You can (like in the example) insert single conditions (e.g. time from 6 to 20).

But if you want to do more complex logic, (e.g "Either it's raining or it's night-time and foggy"), the conditions setting supports all of your settings. You might have noticed that the conditions setting is not one list, but a "list of a list". Here's the explanation, why:

Let's have 3 conditions: "It's raining" (let's call it raining), "It's night-time" (let's call it night) and "It's foggy" (let's call it foggy). How would you set up "Either it's raining or it's night-time and foggy" with the condition logics?

Solution: conditions : [ ["raining"], ["night", "foggy"] ]

This works, because the mod will read it as "raining or (night and foggy)". The conditions in the sub-lists are always linked with an AND. Then the mod takes the result of those and links them with an OR.

If it helps, you can read [ ["raining"], ["night", "foggy"] ] as [ ["raining"] or ["night" and "foggy"] ]. With this you can create long chains like [ ["raining", "night"], [ "fire", "day", "sunny"], ["stormy"] ] ([ ["raining" and "night"] or [ "fire" and "day" and "sunny"] or ["stormy"] ]).

Theoretical background: As all condition types allow you to create the inverse of it (You can make A to "not A"), this should be very related to an disjunctive normal form

Collections and songs

The example shows how to apply context conditions to specific collections. With version 1.1.9.0 or higher CSL Music Mod also supports restriction to specific songs in the collections like "Play only songs with the name x, y and z from collections A and B". By default all songs of a collection is played. The same happens if the list of songs is empty.

The name of a song is the filename without the extensions.

Example You have 2 collections "day" and "night" with following songs:

  • day/happy.ogg
  • day/sunny.ogg
  • day/rainy.ogg
  • night/moon.ogg
  • night/rainy.ogg

If it rains, you want only the "rainy" song to play.

{
    "name" : "Some Station",
    "collections" : ["day", "night"],
    "filters" : {
        "day" : { "type" : "time", "from" : 6, "to" : 20 },
        "night" : { "type" : "time", "from" : 20, "to" : 6 },
        "rain" : { "type" : "weather", "rain" : [2, 10] }
    },
    "contexts" : [
        { "conditions" : [ [ "day", "rain" ] ], "collections" : ["day"], "songs" : [ "rainy" ]},
        { "conditions" : [ [ "day" ] ], "collections" : ["day"]},
        { "conditions" : [ [ "night", "rain" ] ], "collections" : ["night"], "songs" : [ "rainy" ]},
        { "conditions" : [ [ "night" ] ], "collections" : ["night"]}
    ]
}

If you would use both "day" and "night" collections and set "songs" : [ "rainy" ], both day/rainy.ogg and night/rainy.ogg will be playing.

Condition reference

Conditions always have following basic scheme: { "type" : "Insert condition type here" }. Other settings are also set in this entry.

Time condition (time)

This condition checks if the current time is within an interval. The condition type is time.

Setting Function Example
from The begin of the interval. Values range from 0-24. "from" : 20
to The end of the interval. Values range from 0-24. "to" : 5
not If true, the return value of this condition is negated. If left out, it defaults to false "not" : true

If from and to are the same, the condition always applies.

Mood condition (mood)

This condition checks if the happiness of your cims is within a range. The condition type is mood.

Setting Function Example
from The begin of the interval. Values range from 0-100. "from" : 20
to The end of the interval. Values range from 0-100. "to" : 60
not If true, the return value of this condition is negated. If left out, it defaults to false "not" : true

Weather condition (weather)

This condition tracks all supported weather conditions in the game. It tracks the temperature (°C) and the strength of the weather conditions in 1-10. The condition type is weather.

Setting Function Example
temperature The temperature interval in °C. "temperature" : [-10,5]
rain The strength of rain weather 0-10 (0 = none, 10 = max) "rain" : [0,1]
cloudy The strength of cloudy weather 0-10 (0 = none, 10 = max) "cloudy" : [5,10]
foggy The strength of foggy weather 0-10 (0 = none, 10 = max) "foggy" : [0,10]
rainbow The strength (?) of rainbows 0-10 (0 = none, 10 = max) "rainbow" : [5,8]
northernlights The strength (?) of northern lights 0-10 (0 = none, 10 = max) "northernlights" : [1,10]
not If true, the return value of this condition is negated. If left out, it defaults to false "not" : true

If you leave settings out, they default to "always apply".

Disaster condition (disaster)

This condition checks if the count of disasters is within a range. The condition type is disaster.

Setting Function Example
from Minimum number of disasters currently happening. Values range from 0-255. "from" : 20
to Maximum number of disasters currently happening. Values range from 0-255. "to" : 60
of List of disaster types that should be counted. If the list is empty, all disasters are counted. "of" : [ "Generic Flood", "Structure Fire" ]
not If true, the return value of this condition is negated. If left out, it defaults to false "not" : true

of can contain following values:

  • Structure Fire
  • Structure Collapse
  • Generic Flood
  • Meteor Strike
  • Tsunami
  • Forest Fire
  • Earthquake
  • Tornado
  • Thunderstorm
  • Sinkhole
  • Chirpynado

Natural Disasters DLC is needed for all disasters except Structure Fire, Structure Collapse and Generic Flood

Clone this wiki locally