Cities: Skylines

Cities: Skylines

Sem avaliações suficientes
(pre-alpha) Traffic Counting Mod
Por RichAntDav
Guide to how to set up and use a super early user unfriendly version of my traffic counting mod.
   
Premiar
Adic. a Favoritos
Nos Favoritos
Desfavoritar
Introduction
Want to get the game to count cars passing a point instead of doing it manually? This mod can help.

However, this mod is currently in a very early state, so it is a bit tricky to install and use. I have not set it up as a proper mod, it just consists of a single source code file that needs to be installed manually (instructions below). Also, it has no UI and the only output the mod makes it to the debug console (details below).

Further Development
Unfortunately I can't continue to develop this mod because I don't have access to any good free c# development tools. To write the mod I was using the community version of visual Studio to write the mod, according to microsoft the community edition is "A fully-featured, extensible, free IDE for creating modern applications for Android, iOS, Windows, as well as web applications and cloud services." Well, that's a lie because after using the IDE for 30 days it started saying "Your evaluation period has ended. Please sign in to unlock the product". Sorry folks, I wrote this mod for fun and I'm not getting paid for this, so I can't justify shelling out money to microsoft to continue.

However, if someone else wants to take the code, improve it, and turn it into a proper mod, that's fine by me, I've open-sourced the code so it's free for anyone to use, copy, modify and/or improve. Some credit and a link to my Youtube channel and Steam workshop page would be nice, but it's not mandatory. If you give me a shout I can also help out with the code I wrote, or with possible enhancements.

Current Usage:
This mod has been used to create the following Guides in the Steam workshop



Setup
As I said, the mod is quite user unfriendly, and its not released as a proper mod, so you have been warned...

Step 1: get the code
So the first thing to do is get a copy of the code, this should be straightforward as the source code consists of just a single text c# file

The code is currently located here:
https://gitlab.com/richantdav/cs-traffic-counting-mod/-/tree/master
you could clone the repo or whatever, but the only file you need is "MyFirstMod.cs"

Step 2: Install the mod
The game searches for mod source folders in the directory C:\Users\<YourName>\AppData\Local\Colossal Order\Cities_Skylines\Addons\Mods.

In this directory, create a new directory named "FirstMod". Inside of that new directory, create another new directory named "Source". That's where you put the "MyFirstMod.cs" file



Other Requirements:
Required mods:
  • ModTools - Debugging toolkit for modders, version 3.3.0 (it should also work for similarly numbered versions). Hit F7 to bring up the debug window

Useful mods:
  • Pause on Load

Create some new Road Types
The way the mod works is that it first looks for all of the road segments that have a very specific name. Those names are:
"HighwayCountOut", "HighwayCountIn", "Highway4CountOut" and "Highway4CountIn"
So, you will need to create 1, 2, 3, or 4 new rroad types and give them those names.


Note, the names have to be an exact match.

To create some new road types with these names you'll need to use the Asset Editor and create a new Road type, for my purposes I created some new road types based on the normal 3 and 4 lane highways. As you can see from the setup screenshots I modified the roads slightly to make them easily distinguishable from the normal version of the roads. I, particular I just increased the "Half Width" property of each new road type to 18 for the "In" roads and "23" for the out roads. This is why the custom roads have a blue stripe beside them. The mod should work fine on any type of road, it doesn't have to be highways or one-way roads.

The way the traffic detector works is that every N frames (in the code this is called "COUNT_FRAME_INTERVAL" and is set to 10) it scans the custom road segments and sees what vehicles are in the segment and makes a list, the next time it scans (10 frames later by default), it makes a new list and sees how many of the vehicles were in the first list and not the new one, these are the vehicles it counts as having left the watched segment. Every minute (this value is also adjustable if you edit the code, it's in a variable called "DIVISOR" for some reason) it reports the tally of the vehicles that left the segment. It does this for every segment, i.e. every minute there is a report on how many vehicles left each of the watched segments. For my purposes I wanted to know how many vehicles entered and how many left a particular intersection, so I created two different groups of road segments, an "in" group and an "out" group. So, in addition to reporting on the individual segments, there is also a report of the sum of all the "in" segments and a sum of all the "out" segments.


Usage
How it looks:
With the mod installed and the game restarted, open up the debug window (hit F7, assuming ModTools is installed) and you should eventually see some debug messages (one per minute) reporting on the special road segments that you added to the map:

How it works
The way the traffic detector works is that every N frames (in the code this is called "COUNT_FRAME_INTERVAL" and is set to 10 by default) it scans for all the instances of the custom road segments ("HighwayCountIn" and "HighwayCountOut") and sees what vehicles are in every segment and makes a list, the next time it scans (10 frames later), it makes a new list and sees how many of the vehicles were in the first list and not the new one, these are the vehicles it counts as having left the watched segment. Every minute (this time period is also adjustable if you edit the code, it's in a variable called "DIVISOR" for some reason) it reports the tally of the vehicles that left the segment. It does this for every segment, i.e. every minute there is a report on how many vehicles left each of the watched segments. For my purposes I wanted to know how many vehicles entered and how many left a particular intersection, so I created two different groups of road segments, an "in" group and an "out" group. So, in addition to reporting on the individual segments, there is also a report of the sum of all the "in" segments and a sum of all the "out" segments.

Debug Output
The following is an example of the debug output:
[Log] MyFirstMod.MyBehaviour.Update(): TICK:
Seg <OUT> {0,2800} = 6
SEQ <IN> {1,9981} = 2
Seg <OUT> {2,16498} = 50
SEQ <IN> {3,19693} = 70
IN TOTAL = 72, OUT TOTAL = 56

So, in this debug text we have 4 road segments, two "in" one and two "out".
  • The first "out" segment is numbered "0", it has a segment_id of "2800" (every road segment has a unique id), and we can see that 6 vehicles left that segment in the last minute
  • The first "in" segment is numbered "1", it has a segment_id of "9981", and we can see that 2 vehicles left that segment in the last minute
  • The second "out" segment is numbered "2", it has a segment_id of "16498", and we can see that 50 vehicles left that segment in the last minute
  • The second "in" segment is numbered "3", it has a segment_id of "19693", and we can see that 70 vehicles left that segment in the last minute
  • the total for all the vehicles that left all of the "in" segments is 2 + 70 = 72 vehicles
  • the total for all the vehicles that left all of the "out" segments is 6 + 50 = 56 vehicles

Things to keep in mind
  • Bicycles are not counted
  • All output is sent to the debug-output. I think this is, or can be, sent to a file, if so, it should be straightforward to parse the text to pull out the raw traffic data, which would be handy if you plan to watch many road segments
  • The game can be adversely affected by what the CPU is doing. You will notice a significant difference in you data when you have CPU-intensive background tasks running and when you don't

Initialization
The mod has no UI so it begins running as soon as a new game is loaded, because of this I use the "pause-on-load" mod which loads games in a paused state. Then, the mod will report zero totals for all segments as long as the game remains paused. To set up a counting/simulation run, clear the debug window, and as soon as you see a see a new debug output reporting the latest minutes totals, unpause the game so it will get a full minutes worth of data for the first minute, so if you are slow unpausing the game you are in danger of getting less than a minutes worth of data. This is an untidy/hacky but (just about) usable way of getting around not having a "start recording data" button.