1. Factorio
  2. News

Factorio News

Friday Facts #312 - Fluid mixing saga Landfill terrain

Read this post on our website.

Fluid mixing saga

Hello Factorians,

Today I would like to talk to you about my favourite subject - fluid mixing and its prevention. It is a new mechanic introduced in 0.17 that seemed quite simple at first, but has been giving me nightmares ever since.

A while ago I took on the task of updating the fluid system (FFF-260). The way it works in 0.16 is that the fluid boxes (the thing that holds the fluid and is contained in entities like pipes or refineries) had no organisation whatsoever except their connections. They would sit there and do nothing and then once per update send fluid somewhere. It had it's issues especially with symmetry, and when you happened to put some fluid where it did not belong, you could end up requiring major demolition works.

My task was to develop a better algorithm to move the fluids, and a very very optional side task I had in mind was to do something about the fluids getting to wrong places and mixing. We started by organizing the fluid boxes into systems (connected FBs make a system) managed by a special fluid manager, and optimizing the heck out of it (FFF-271).

Soon after, I started working on the new algorithm and anti fluid-mixing. Until then nobody really considered preventing the fluid mixing seriously as it did not seem possible. But when I thought about it, it did not seem that hard. The idea is to simply not allow any action that would lead to fluids getting where they are not supposed to go. When you build a steam pipeline, you should not need nor want it to touch another fluid.

In principle, it would only require a few quite realistic mechanisms:
  • A connected block of fluid boxes would either be fluid-free, or it would be locked to one fluid.
  • Two such blocks can connect only if they are compatible - either one has no fluid lock, or they have the same fluid.
  • An assembler can only set a recipe if it is compatible with the fluid locks on its fluid boxes.
  • Have a migration from old saves that can contain mixing.
By creating the fluid systems right before, number 1 was almost finished and we only needed to assign the lock. It would be set either by a fluid, or by a 'filter', which is a fluidbox that is set to use a fluid - such as a water pump using water, or assembler having some inputs/outputs given by a recipe.

After a while I had both the fluid algorithm and the mixing done (FFF-274). The mixing was not that easy (like 5x more complicated) but it worked pretty well. As for the fluid algorithm, V453000 and Twinsen found some issues with waves on a macro scale, and because it was right before releasing the 0.17 experimental, we decided to hold it off on it for the time being (we have a new version now that seems okay, but has to wait for 0.17 becoming stable first). The mixing made it through though and seemed quite finished.

It turned out that the work on it was at most one tenth complete.



Some difficulties appeared already before the initial release, but that was only a hint of what would come later. One by one, then ten by ten, bugs started coming. The problem is that as often as not, they were not just little issues with simple fixes. Instead, over and over, they turned the current solution on its head and the code had to be completely rewritten in order to account for the new case. As of now, almost exactly half a year and many rewrites later, it is still not fully bug free.

The number one issue was with Assembling machines. It turned out that their code was pretty messy and does not simply allow the checks I needed, so it had to be refactored. The next problem was that the check was not only required when setting a recipe on an existing assembler - as I naively thought - but in about one million different situations I would not dream existed. Building a fixed recipe assembler. Reviving an assembler. Rotating. Blueprint of an assembler. Blueprint with a recipe and a rotation placed over a ghost with a non-default rotation during a full moon. Teleport. Script building. Copy-paste settings. Any combination of these.

Pretty much every case would go through different paths in the code and behave entirely differently. Fixing one would break another and so tons of tests had to be written. When these cases finally worked, it turned out that doing these operations when they fail (e.g. can’t rotate because it would cause mixing) brings another wave of issues. And then mods come and the complexity multiplies. All this, although in a more simple form, had to be done for all other entities that can use fluid too, such as inserters (mods...).

Another number one issue are underground connections. When playing, you would not think twice about them but on a closer look they are all but simple. They have this (cough) uncomfortable feature (want to shoot myself) that you can build another underground pipe between them (or take it out) and a complex reconnection logic jumps in. It means that based on building order, connections are established and reestablished differently. This is a big thing when building a blueprint with many pipes, or loading a save game.

But the largest issue is one tiny corner case with huge implications. Have two underground pipes that have different fluids, but are split by a third, and it gets removed. Until now mixing was theoretically completely avoidable, but here it was and there was nothing to stop it.



As a result, a new concept is introduced - a blocked connection. An underground connection that would normally connect but can’t. Establishing it is the easier part. But when does it get fixed? An entity miles away gets rotated, that splits a fluid system, disconnecting the blocked connection from a fluid filter on the other side, and the connection should unblock. But even something as simple as a rotation contains fluid fixes and re-establishing of fluid boxes and if it fails, it still fixes the blocked connection in the process and it can’t be undone... You get the picture. And we are still talking about underground pipes, while anything can have underground connections, including said assemblers, which the previous code did not consider at all. The complexity just goes deeper and deeper, and Rseding is probably right that we should have never gone this way at all.

So the bug fixing has been basically running in circles - clearing one batch of bugs, thinking that those were the last ones and the ordeal is finally over, only to find another batch (ideally from some bizzare modder idea) a few days later. Many times I wished that mods never existed. Nor multiplayer, or any players at all for that matter. About two months ago all seemed really fine, with basically no reports and just a few crashes in the automated crash reports.

At that moment another nightmare materialized in the form of a talented volunteer bug tester named boskid, who took on a personal crusade to break the fluids to dust (I actually imagine him sitting in his dark room with evil laughter, dreaming about making my next day worse than the previous). In all seriousness, he has done a great deal of work with his bug testing, creating bizzare modded cases and testing scripts, and deserves a big thanks. He is actually coming to our offices next week, so follow the news for reports of developers falling out of windows.


An example of a nice configuration he found (and I can’t fix).

The whole time we were taking the offensive approach to mixing - crash the game when it happens - so that we know about bugs to fix them. Recently we have decided to put a stop to it and have the mixing automatically fix itself once it is detected, eyeing the end of this episode. Right now I have 3 mixing bugs on the list and I am sure those are the last, and mixing will be done (lying to myself is a way to cope with it) and the new fluid algorithm can come soon after :).


(And of course, boskid found a way to use the automatic mixing fixing as an evil PVP tactic.)

Landfill terrain

This week Ernestas came physically to the Wube office to spend some time with us (he is normally working remotely), so we are taking the chance to finish things that we had in the drawer that needed closer communication. One of those things is a specific terrain for landfill. As you know we were using grass for it. Not anymore.



In Factorio we have a clash of two worlds:
  • The natural and organic planet. Off-grid with multiple terrain types, trees and doodads.
  • The world of the factory, which is mathematical, regular, modular, and totally attached to the grid.
This new terrain represents a boundary in between those two worlds. The grid on its surface tries to express the artificiality of it, like mechanically pressed with some sort of industrial stamp. The imperfections of the grid and its irregularities are holding this man made terrain into the realm of the natural environment.

For now the sound of the landfill action is not solved, 'soon' we’ll take care of it.

As always, let us know what you think on our forum.

Friday Facts #311 - New remnants 3

Read this post on our website.

Hello,
Another week has elapsed, which brings us another week deeper into the declining weather of autumn.

Even more Remnants

In FFF-288 we proposed that we are considering multiple approaches to remnants, and in FFF-293, we described that we are choosing the balanced solution which does not obstruct the movement of a player if an entity is destroyed. We have recently finished quite a few which we would like to show you.



Compared to some of the early versions of remnants, you can now really recognize which entity got destroyed.

General

If you have been following the progress of remnants in 0.17 experimental versions, you have probably noticed that a lot of them have been changed quite drastically. In general we are trying to hit the balance between having the remnant look destroyed enough, yet still very well recognizable which entity it was.

This is especially difficult for tall entities as the player has to be able to walk over their remnant, the extreme case being train stop for which we are also implementing a special solution...

Train stop

Train stops are recognizable because of the top coloured part, and the tall scaffold that holds it. Giving the station a colour mask was trivial graphically, but our dear posila needed to add a bit of code to support remnants to have colour masks. Keeping the tall tower is a bigger problem as if the tower is a part of the remnant sprite, the player would be able to just walk over it, and trains would always show on top of it as well. We chose to split the train stop remnant into two layers so the illusion of height is kept.



Remnants with colour masks

We also used the colour masks for basically everything the player has the ability to change the primary colours of. It includes the Locomotive, Turrets, Car and the Tank. Once the entity dies, the colour of the given entity stays with the remnant.

Walls

We have updated the wall sprites as well, as we wanted to make the walls more like broken walls instead of random rubble, to break their line less. The walls are by far the most destroyed entities besides turrets so they can look repetitive quickly. To improve this, wall remnants have several sprite variations.

Compared to 0.16, whenever any entity gets destroyed, the player can tell which entity it was. We believe this makes rebuilding your factory much more fun, and seeing your things get eaten less frustrating. On top of that, we plan to utilize the remnants to a large degree in the campaign for 1.0 for half-destroyed factories to be found and explored.

We will be adding more remnants and improving some further to make this effect even greater than it is currently in 0.17.

Community spotlight - Industrial revolution

In the past month I had the opportunity to balance test an overhaul mod called Industrial Revolution. Now, after around 1,000 hours of development, Deadlock has finally released the mod to the public today. In the around 65 hours I have spent playing the mod, I fell in love with it and I want to present it to you here.

Click to see full resolution
My current base, machines from all ages forming one big factory.

The mod gives more depth and length to the vanilla experience by changing the progression throughout the entire game. You work through ages of technology, always chasing the milestone of the next material. Just like in vanilla, you start out with the stone age and classic burner machinery. Automation is key, even in the stone age; the mod adds new intermediate products to all crafting steps. To allow automation at this stage, the mod provides burner assembling machines and labs.



However, instead of getting to power as soon as possible, the next goal is bronze, an alloy made from the two starting resources, tin and copper. After improving the factory with bronze machines and automating logistics science packs, the iron age is not far away. With it come steam power, oil processing and trains, allowing rapid expansion of the factory. The steel age unlocks better ore refining techniques and powerful machinery, paving the way to the rocket. Beyond the ages, the mod introduces new types of turrets, each with their advantages and disadvantages. On top of all these gameplay differences, the mod boasts incredible graphics and good sounds.



When I started testing the mod, I was expecting a long-ish casual playthrough with some different recipes. What I got instead was an addiction and a huge appreciation for the concepts the mod adds and changes: Different challenges, more logistic puzzles and completely new recipes refreshing the whole experience. The extended burner phase in the mod introduced an unconventional problem to me: Fueling burner inserters and assemblers. Combined with my spaghetti approach and limited space due to the enemies lurking in the desert around me, fueling inserters became a challenge that I spent hours on.

My proudest creation is an electric motor assembler, it needs four inputs, all supplied by burner inserters that need to be fueled by other inserters. The assembler stands to this day:



Another great change by the mod is how it deals with ore processing. Ore processing allows the player to improve how many ingots can be produced from ore, up to producing twice as many ingots. This happens in steps, every age introduces a new technology to refine ore. So, getting more iron means building an extra ore processing step and simply connecting it between the last processing step and smelting. Each refining setup has its own challenges such as multiple outputs or needing a catalyst, so it becomes an interesting puzzle to get more ingots. The new ore processing flows well with the rest of the game; often times I found that I needed an ore refining byproduct and more ore refining at the same time. This is a big improvement compared to the vanilla way of getting more plates: Mine yet another ore patch and smelt it in the same old boring way.

Click to see full resolution
Gold being mined, crushed and purified to increase its yield before smelting it, all in the same area.

Of course, adding more intermediates also means that you run the risk of only ever needing a product for one other recipe. The mod manages to avoid this pitfall, I find myself routing belts and pipes through half the factory because an item is needed in multiple different places. Another possible problem is the long burner phase, it could delay automatic construction. This is prevented by the addition of very early personal construction robots. The clockwork punkbots can be used with an automatically refuelling burner generator that fits into heavy armor, all available in the bronze age.

Vanilla’s boring defenses become more varied with the new turret types. The first turret you unlock is a bronze scattergun turret, it works similarly to a shotgun. These turrets are great at taking out groups and still make up a large part of my defenses. However, their range is lower than that of medium spitters, therefore minigun turrets and laser turrets guard my more commonly attacked areas.



All in all, the mod overhauls vanilla to provide fresh challenges, is well balanced and on top of that nice to look at. I hope you will have as much fun playing the mod as I did, so try it out now that it is released (Mod portal page).

As always, let us know what you think on our

Version 0.17.68 released

Changes


  • Pressing ESC while catching up to a multiplayer game will open the menu with most options disabled. more
Bugfixes


  • Fixed migration bug that doubles up to one sample worth of statistics when a save is loaded from before 0.17.44.
  • Fixed production statistics not calculating the totals correctly. more
  • Fixed that on_built_entity wouldn't be fired for built blueprint entities. more
  • Fixed a crash when right clicking with the map editor tile area tool. more
  • Fluid mixing does not crash the game anymore and is fixed the same way as on migration.
  • Fixed some Lua tables would be incorrectly interpreted as Lua arrays. more
Modding


  • Changed pipe_covers to be drawn with secondary sprite draw order 64 resp. -64 to prevent "z-fighting" issues. more

You can get experimental releases by selecting the '0.17.x' beta branch under Factorio's properties in Steam.

Version 0.17.67 released

Graphics


  • New chemical plant graphics.
  • Heat pipes (also in reactors and heat exchangers) glow with high temperatures.
Changes


  • Pressing ESC while catching up to a multiplayer game will disconnect instead of opening the menu. more
  • An entity can't be teleported into a position where pipe connections would overlap. more
  • The camera will zoom to center instead of zooming to cursor in God controller, Ghost controller and Spectator controller.
Features


  • Added an area tool to the map editor tile editor.
  • Added highlighting of the source entities when selecting areas to clone in the map editor.
  • Added a setting in the map editor to hide entity health bars.
  • Added a setting in the map editor surface editor to generate new chunks using lab tiles.
  • Added support to manipulate items on the stored character while in the map editor.
  • Added infinity settings for automatically controlling items in the map editor.
  • Changed the infinity chest so it can also spawn hidden items.
Gui


  • Rearranged key-bindings in Control Settings to different categories. Improved and added more descriptions of key-bindings.
Bugfixes


  • Fixed cloning ghost entities with rotation didn't work correctly. more
  • Fixed that the lab GUI wouldn't update when the technology being researched changed. more
  • Fixed loader front patch and back patch were not sorted correctly when drawing. more
  • Fixed wire connection distance sometimes being inconsistent. more
  • Fixed a rotation of modded pump with regard to blocked pipe connections. more
  • Prevented a crash resulting from teleporting a pipe to a fluid system with blocked connection. more
  • Fixed that the filter GUI tooltip would flicker when changing tabs. more
  • Fixed fluid mixing from creating an underground pipe by script into a blocked fluid system. more
  • Fixed fluid mixing from copy/pasting an infinite pipe next to a different fluid. more
  • Prevented playing Jesus and changing water into other fluids. more
  • Fixed assembler ghost fluid filters disappearing through loading. more
  • Cliffs sections which are fully marked as indestructible can't be exploded. more
  • Fixed interaction of underground pipes with modded length. more
  • Fixed fluid mixing caused by fluid producing furnace. more
  • Fixed that opening the technology GUI in the same tick as the entity tooltip being shown didn't work correctly. more
  • Prevented rotation of a modded assembler with a blocked pipe connection that results in fluid mixing. more
  • Fixed train condition button indentation not being properly updated under special circumstances. more
  • Fixed that train schedule waypoint was considered to be passed when train departed the related rail rather when it entered it. more

  • Fixed that storage tank entities ignored pipe_picture property in their fluid box definition. more
  • Fixed improper action selection for UI actions for key bindings differentiated by modifiers only. more
  • Fixed a crash related to a modded assembler and fluid mixing. more
  • Applied the cannon shadow to the artillery wagon, fixing some unintended highlights. more
  • Fixed crash when removing electric pole. more
  • Fixed event handler could try to register events twice in some cases. more
  • Fixed blueprinted locomotives would preview as snapped to train stop. more
  • Fixed items spilling on the ground when using fast entity transfer while robots are trying to insert into the player. more
  • Fixed hand reserving a non-empty slot in some situations when player inventory auto-sorting is disabled.
  • Fixed custom lua slider sometimes initializing with the marker in the wrong position. more
  • Fixed "list-box" and "drop-down" custom GUI elements would not update selected index when changing its items programmatically. more
  • Fixed that the map editor 'instant blueprint building' would fail to place trains correctly.
  • Rail signal that is to be reserved by circuit network doesn't allow train to go through even when the block is already occupied by the given train. more
  • Rail signal will change from reserved by circuit network state to closed state when train is manually placed into the block it guards. more
  • Fixed train stop name in map not being positioned properly. more
Modding


  • Changed default value of LoaderPrototype::structure_render_layer from "lower-object" to "transport-belt-circuit-connector", in order to be consistent with other on-belt structure sprites.
  • Different wall types will connect visually by default. If this behavior is not desired for a wall prototype, set it unique "visual_merge_group". more
  • Added optional random_variation_on_create to all simple entity prototypes.
  • Pump was changed to not expand its bounding box when connected to pipe. Collision box for vanilla pump was adjusted to reflect this change.
Scripting


  • Added additional filtering to LuaGameScript::get_filtered_..._prototypes() functions.
  • Added optional "tags" to entities in blueprints and entity ghosts.
  • Added optional "tags" to script_raised_revive, on_built_entity and on_robot_built_entity events when reviving ghosts.
  • Added LuaEntity::tags read/write for entity ghosts.
  • Added LuaItemStack::get_blueprint_entity_count(), get_blueprint_entity_tags(), set_blueprint_entity_tags(), get_blueprint_entity_tag(), and set_blueprint_entity_tag().
  • Added on_force_friends_changed and on_force_cease_fire_changed events.
  • Added "area" to on_chunk_charted and on_sector_scanned events.
  • Added "position" to on_chunk_generated event.
  • Added area to the LuaChunkIterator operator() return value.
  • Added LuaPlayer::toggle_map_editor().
  • The script_destroyed_entity event is raised for map editor instant deconstruction.
  • Added LuaEntity::tick_of_last_attack and LuaEntity::tick_of_last_damage write.

You can get experimental releases by selecting the '0.17.x' beta branch under Factorio's properties in Steam.

Friday Facts #310 - Glowing Heat pipes

Read this post on our website.

A few bugs left...

WoW classic has been released, which means several of our top men have taken time off to spend hours raiding and having fun in Azeroth.

This isn't great timing, as a few new bugs related to train signals appeared. We want to get these bugs solved before we do another release (another stable candidate). As it turns out, the only person with the skillset to fix these specific train signal bugs is also deep into levelling his Priest...

We are still making the rest of the preparations for the stable release. We have started writing up the stable annoucement blog post, and have produced a 0.17 postcard image. Other than the few more critical rail bugs, there doesn't look like there is much else to block the stable release, on the forum we are down to 27 bugs.

Since there are so few bugs left to deal with, some of the team has starting working on 'post-stable' features. Wheybags is working on the new campaign, Oxyd is diving into some detailed pathfinder improvements, and Rseding has started work on some particle optimizations. We will delve deeper into these topics and more in future FFFs, as we always love to do.

Glowing Heat pipes

Heat pipes were released with 0.15, since then, we (the GFX department) contracted a debt with this feature. The original plan was to be able to visualize the amount of heat by using a glow on the pipes. Due to the tight schedule of the 0.15 release we decided to postpone the feature.
Finally Ernestas took care of it, and we can proudly present it integrated in the game.



As you can see, the pipes emit light due to the red hot metal. The fact that they are connected to the reactor and the heat exchanger, made us make some extra patches. It would look wrong if the heat pipes were glowing, but the pipes on the reactor were not. The final result apart from beautiful is also very readable for the player, which is the main point of the entire design.



The glow intensity is proportional to the heat. Now the visualisation should be crystal clear. The new graphics are already merged into master, so will be included with the next experimental release.

As always, let us know what you think on our forum.