Cities: Skylines

Cities: Skylines

Not enough ratings
[DISCONTINUED - SEE DESCRIPTION FOR LINK TO A REPLACEMENT] Specialised Industry Fix [BUGFIX for Vanilla]
   
Award
Favorite
Favorited
Unfavorite
Mod
File Size
Posted
Updated
71.680 KB
9 Apr, 2016 @ 1:22pm
12 Sep, 2016 @ 8:45am
3 Change Notes ( view )

Subscribe to download
[DISCONTINUED - SEE DESCRIPTION FOR LINK TO A REPLACEMENT] Specialised Industry Fix [BUGFIX for Vanilla]

Description
Click the link below to go to an updated version of this mod

https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=1553517176

This version of the mod will not work from version 1.6 of Skylines onwards. Use the updated version at the link above instead.

Thanks to Vectorial1024 for updating the mod for newer versions, and to PropaneDragon for allowing me to use his excellent Rush Hour mod as the basis for my initial fix.

THE FOLLOWING IS LEFT HERE FOR CONTEXT AND DOCUMENTATION PURPOSES ONLY!

Industry Fix - Stop Level 1 Specialised Industry from Toggling between Operating and Not Operating


NOTE: This mod is currently broken. You will need to unsubscribe to avoid the error message when starting the game. If you are interested in creating a new mod for the current version of Skylines that fixes this issue, see the Technical Information below.

I'm currently not playing Skylines because I got tired of the endless cycle of DLC invariably breaking half the mods I have installed, which means endless troubleshooting, disabling mods, waiting for updates etc. etc. Seeing as it takes me about 10 minutes to load my save game, it's no fun when it borks after 8 minutes and you need to repeat the process.

I'm sure a lot of you have been in the same boat.

Technical Information
If you are interested in creating your own mod to fix this issue, I'll be more than willing to help you. The fix itself is very easy; this bug is caused by Skylines using integer arithmetic to calculate the output of these industries.

This is the code I have on my hard drive (in the SimulationStepActive method of IndustrialExtractorAI):

if (handleWorkers_result != 0) { int maxResourceToExtract = (maxOfProductionCapactiy500andMaxOutgoingLoadSize - (int)buildingData.m_customBuffer1) / 100; handleWorkers_result = Mathf.Max(0, Mathf.Min(handleWorkers_result, (maxResourceToExtract * 20000 + maxOfProductionCapactiy500andMaxOutgoingLoadSize - 1) / maxOfProductionCapactiy500andMaxOutgoingLoadSize)); //Debug.LogWarning("num8 is" + num8); int extractionRate = (handleWorkers_result * productionCapacity + Singleton<SimulationManager>.instance.m_randomizer.Int32(1000u)) / 1000; //bug! can be zero! if (extractionRate < 1 && aliveWorkers !=0) //v 0.2: added aliveWorkers check { extractionRate = 1; Debug.LogError("Industry Fix: Extraction rate was zero despite having " + aliveWorkers + " workers! This can shut down the building! Setting to " + extractionRate + "instead"); }

If you decompile using ILSpy, the variables will all have different names (num1, num2 etc.). I renamed them in my code as I was deciphering (roughly) what they seemed to be. But the formulas should be easy enough to spot (search for "20000"). I'm assuming "handleWorkers_result" is num8 based on my comment, but no guarantees :)

As you can see, the extractionRate can end up being 0. If this is the case, Skylines will set the building as inactive later on in the code (I think this is Building.Flags.Active). So I simply made sure that the extractionRate is set to 1 (the minimum before the industry shuts down) if it has workers and the extraction rate was 0 (technically <1, but I don't think it can be negative).

The same applies to the LivestockExtractorAI as well. The issue in both was exactly the same IIRC.

It has been a long time since I touched the code and I'm not really a programmer. In order to implement this fix, I had to decompile the source and override the base method using redirection. I have long since forgotten how that all works. There's a certain amount of tail-chasing and copy/pasting necessary, because the method you have overridden can call other methods and you need to handle these calls too. When I last looked at the code I was just lost.

If anyone thinks they can implement a fix for the current version and needs a hand with the implementation of the fix itself - not the whole redirection - then post a comment and I will help you out. I can also give you my source code which has a number of comments and debug trace output stuff that I used when initally debugging the source. You won't be able to use the source code with the latest release of Skylines though. It might help you understand the code better (as said, I renamed a lot of variables), but the redirects will need to be completely reworked and tbh I think you'd be better starting off with a clean slate as the fix is so basic.

I may - no guarantees - fix this myself once CO stop releaseing DLC and the game is finally in a "stable" condition.


Original Mod Info



This mod fixes an issue in the base game where industries that produce natural resources (e.g. farms, forestry) will randomly toggle state form "Operating" to "Not Operating". You probably haven't noticed that you are suffering from this bug, but if you watch small (low worker) specialised industrial buildings, you'll notice some of them randomly flickering on and off despite having workers, power, water etc. Now you can put an end to it!

Thanks go to PropaneDragon for allowing me to gut his Rush Hour code to make this mod.

This mod (like RushHour) uses the excellent C# detours library[github.com] by Sebastian Schöner. Thanks Sebastian!

This mod *should* be compatible with Rush Hour. I have not tried it with any other mods. It may play havoc with other mods that change the AI of industries producing natural resources.
I also have no DLC installed, but the mod should be compatible with DLC - at least there have been no reports of any issues so far.


Also let me know if you notice anything strange, such as these buildings being active when they shouldn't be.
69 Comments
steevm  [author] 1 Nov, 2018 @ 1:54pm 
I've updated the description of this mod to include a link to the replacement. I haven't tried it myself, but I trust it works better than this version... ;)

Thanks @Vectorial1024
Vectorial1024 1 Nov, 2018 @ 7:43am 
Thanks for the permission!
And here it is: https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=1553517176
(Gotta include your screenshots later}
steevm  [author] 1 Nov, 2018 @ 7:04am 
Sure, why not? They're not particularly amazing though :D
Vectorial1024 31 Oct, 2018 @ 6:49am 
While I prepare the page for the updated mod, may I use the screenshots shown in this page up there?
padichat 30 Oct, 2018 @ 12:11pm 
Thanks to both of you ! But I can not believe there's still this buh while they updated industries. Maybe they did not get any bug reports.
steevm  [author] 30 Oct, 2018 @ 11:19am 
Cool, let me know when you have uploaded it I'll add a link to the top of the page here. You never know if there are other players who might come back after a 3 year absence and be looking to update their old mods...
Vectorial1024 30 Oct, 2018 @ 10:56am 
Good news, guys. :steamhappy: :steamhappy:
With the detailed documentation provided above (it is already sufficient to locate and fix the bug!), I am able to update this mod to the latest v1.11 Industries DLC update. The update I made is pretty stable too.
I'll be posting the update in the near future for all to use after I clean up my code and etc.
skylineslee 17 Aug, 2018 @ 7:44pm 
Ah OK I've found the part with the error from the randomizer line. Now I'll just follow the tutorials a bit more to get a quick fix hopefully! Thanks for your very detailed write up. Really got me started with modding haha.
skylineslee 17 Aug, 2018 @ 7:36pm 
I'm looking at SimulationStepActive in the code now. It looks like much has changed in there since your post. Let me try to understand if the bug still exists there. Thanks a lot for all your help!
steevm  [author] 17 Aug, 2018 @ 7:23pm 
I actually just hacked a version of the Rush Hour mod, because there was a very similar bug in rush hour with commercial buildings that was caused by the same issue with the integer arithmetic. So I just did exactly the same thing for the industrial resource buildings as I'd done for the commercial buildings. Which was essentially just do whatever PropaneDragon had done, and he answered a bunch of questions I had. This meant I never had an incentive to actually *understand* how the code worked. I just wanted to fix the bug...