Generators

As I’m currently busy working on the Rivtech facility, I thought I’d put out this idea for further reference.

As I was thinking on the power generation problem(i.e that power only generates from vehicles and bionics), I thought about using the quality system to make power generation work without a ton of items.

You would define a quality like this:
{
“type” : “tool_quality”,
“id” : “POWER_GEN”,
“name” : “power generation”
}
and then add it to your generators-when they are consuming charge they have the power generation quality and when they are out of their respective fuel, they turn off, unable to be used in recipes(the off item not having the power generation quality).

So basically like current “must have nearby fire” condition? Susceptible to the regular 'lit wood on fire for 0.1 second, remove 2x4, craft anything requiring fire" bug, except with something like 1 unit of gasoline or 1 battery.
And to all the timer bugs.

Would be more in line with the rest of power consumption if it just consumed charges, charges being gasoline.
Maybe some sort of ‘consumption quality’ which passes the amount specified to the item with that quality to determine if it can consume so and so, modified by some factor, charges and if yes, makes recipe available?

Yeah, this seems slightly problematic.

Although the way to go is probably to fix the fire issue and then adapt the new system to what OP posted, as the general idea is pretty decent.

So basically like current “must have nearby fire” condition? Susceptible to the regular 'lit wood on fire for 0.1 second, remove 2x4, craft anything requiring fire" bug, except with something like 1 unit of gasoline or 1 battery.
And to all the timer bugs.

Would be more in line with the rest of power consumption if it just consumed charges, charges being gasoline.
Maybe some sort of ‘consumption quality’ which passes the amount specified to the item with that quality to determine if it can consume so and so, modified by some factor, charges and if yes, makes recipe available?[/quote]
Unlike a fire, the generator wouldn’t keep going after that, it would turn off(i think), but the best solution would to not have it turn on at if there are no charges and turn it off if you remove the fuel.

Yes, but you still can put in minimal amount of fuel possible and craft in the split second generator is working, if it will run like charcoal kiln instead of like hotplate.

By the way, I have a question that is somehow related to generators. Are there any plans of adding wiring and electricity to power up your base through generators?

AFAIK yes, as i asked the same a while back.

i would very much like to do that if i can, when i’m able, and if noone else does it until then!

I’ve got them on my short list of items to be used in new facilities (places of interest), but I’m not much at coding, so it’s unlikely that I’ll have them working anytime soon.

Formal pre-built generators are officially Discouraged as there’s no good reaction to making a lot of noise.

(IOW: you can have your generator if you leave Wandering Spawns on. But wander-spawns is kinda unreliable and we’d like something better before defaulting it on.)

Wiring systems would be a significant amount of work. They’ve come up before. :-/

What if they’re a DF-mechanics-style, ‘quantum wiring’ systems? Choose generator, choose power consumer, they get ‘connected’. Should be relatively less work than actual wirelaying.

tbh i would prefer wirelaying (and tubelaying for bringing river water in, or connecting liquid/gas tanks to appliances) mechanics, since they would be much more modular (and realistic) than quantum ones.

The current system tries to work around the lack of either, mostly with vehicle construction, since laid frames imply wiring+tubing.

[quote=“jcd, post:11, topic:7390”]tbh i would prefer wirelaying (and tubelaying for bringing river water in, or connecting liquid/gas tanks to appliances) mechanics, since they would be much more modular (and realistic) than quantum ones.

The current system tries to work around the lack of either, mostly with vehicle construction, since laid frames imply wiring+tubing.[/quote]

Living up to your avatar. Feel free to write up such a system and PR it.

[quote=“KA101, post:12, topic:7390”][quote=“jcd, post:11, topic:7390”]tbh i would prefer wirelaying (and tubelaying for bringing river water in, or connecting liquid/gas tanks to appliances) mechanics, since they would be much more modular (and realistic) than quantum ones.

The current system tries to work around the lack of either, mostly with vehicle construction, since laid frames imply wiring+tubing.[/quote]

Living up to your avatar. Feel free to write up such a system and PR it.[/quote]

i do want to… i have even given thought on how to do it. but i have lots of ends to close first, and still learning C++
so it will be later.

on how i was thinking to do it (in case i won’t, but it becomes useful to someone, or for better coders than me to point out why it cannot be done :c ):

  1. Create 2 flags for tiles (WIRING, TUBING). These will imply that the player has laid out wiring/tubing there.
    The flag will be given to terrain tiles when someone “constructs” the wiring/tubing there.

  2. Have a function that will find all connected tiles with wiring/tubing and will also check if/what on it is a battery with charges/water/clean water tank.

  3. Create a power outlet construction, and make water faucets buildable. Also make sinks and maybe some other appliances (computers, etc) workable if powered.

  4. When activating an item with charges, the code will also check if its on a tile with powered power outlet, and if so, it will ask if it should drain from its charges or from the power outlet. (i expect a rewriting of lots of things to do that)
    When it has no charges (e.g. a construction) if powered, it will drain the battery…

  5. Yes, i know. Hard to do… but it does not seem impossible…

2 seems likely to get Expensive in terms of processor use if your base gets to any significant size, and would have reality-bubble issues. (As I leave my wired & plumbed base, the infrastructure increasingly stops working, and likewise powers back up as I return. It could theoretically be asked to run outside the bubble, but that adds even more processor use.)

Rewrites in 4 would be time-consuming, but aren’t the dealbreaker that 2 is likely to be.

Not going to say I’m better, just that I’ve thought about this problem a lot and know the codebase :wink:

[quote=“jcd, post:13, topic:7390”]1. Create 2 flags for tiles (WIRING, TUBING). These will imply that the player has laid out wiring/tubing there.
The flag will be given to terrain tiles when someone “constructs” the wiring/tubing there.[/quote]
Terrain doesn’t have mutable flags, but that’s not a dealbreaker because you can just lay down an invisible field.

This is the big problem because it interacts badly with the reality bubble. The question is how big is your network of wiring going to be, and particularly how far you’re going to allow generators and power consumers to be from each other. If it’s house sized, no problem, but if it’s the size of a city block you run into problems.

  1. The work to decide connectivity becomes nontrivial.
  2. It becomes very hard to ensure that all the map data you need to make this decision is loaded when you need it.
    The trivial case of #2 is when you’re standing next to a light, which has a wire running several blocks to a generator. The map tile the generator is on isn’t even loaded in memory. we can force it to be, but that complicates the hell out of map storage handling, and means arbitrary chunks of map will get stuck in memory. This isn’t totally intractable, but it’s a hefty chunk of work to resolve.

This bit wouldn’t be too hard, although I don’t know where you’re getting your running water from for plumbing, build a water tower of your own?

or just duplicate terrain tiles to have versions with&without wiring. (if fields are cpu expensive or don’t mix well with what will follow)

This is the big problem because it interacts badly with the reality bubble. The question is how big is your network of wiring going to be, and particularly how far you’re going to allow generators and power consumers to be from each other. If it’s house sized, no problem, but if it’s the size of a city block you run into problems.

  1. The work to decide connectivity becomes nontrivial.
  2. It becomes very hard to ensure that all the map data you need to make this decision is loaded when you need it.
    The trivial case of #2 is when you’re standing next to a light, which has a wire running several blocks to a generator. The map tile the generator is on isn’t even loaded in memory. we can force it to be, but that complicates the hell out of map storage handling, and means arbitrary chunks of map will get stuck in memory. This isn’t totally intractable, but it’s a hefty chunk of work to resolve.[/quote]
  3. Since we care only about connected tiles, the algorithm to search for these will look only into adjacent tiles for connections, until it finds none and stops on that end. This should make it cheaper to run than scanning each and every tile for each and every grid.

Also, since the tiles with wiring are semi-permanent (until the player changes them), they don’t change that much, so they do not need to be recalculated constantly.
Instead, they could be loaded only when the reality bubble is loaded, or when the player adds/removes one.
At this point all the connected tiles could be tracked once and have their coordinates stored somewhere. As long as at least one of them is inside the reality bubble, the game won’t recalculate them again. At most, it will need to verify that the coordinates match.

  1. Of course we will calculate the power drained only when we need to.
    But we do not need to load all the connected tiles to do the power calculations. Just the power/water source tile. (the end tile will be always loaded - that’s where the player is).

So, these grids could be objects and their attributes could include the coordinates of their wiring, source tile, power available (and the related power items) and their power outlets, making calculations cheaper.

I guess, this way, even if someone wires a whole town, the cpu&mem load will be aking to loading twice the data at map load
After this though, grid objects will just take up memory, with mimimal cpu overhead.

I certainly do not know the codebase well enough to judge if this makes it possible… what do you think?

This bit wouldn’t be too hard, although I don’t know where you’re getting your running water from for plumbing, build a water tower of your own?[/quote]
i was thinking it would be cheaper for the calculations to have end-points to the line, and only be able to get power through these (of course, a line could have multiple end-points)
As for running water, sure… connect it to the river for water, or maybe to a 55 gallon drum for clean water. If we wanted to also take into account physics (pump or z-levels to create pressure for liquids) this could be done easier than the rest i guess…

PS. I can forsee problems with draining the batteries and these not charging due to the solars being outside the bubble, but well, either load them (also store power generation appliances as an attribute of a grid), or let them be as they work now, to be fixed when the reality bubble behaviour of solars gets fixed.

Wiring tile by tile would be expensive in processor usage. My thoughts would be to have power outlet “nodes”, that with the right amount of wire, you can connect to the main power source, that would then check if the power source is operating and drain power accordingly.

The ‘reality bubble’ issue could be solved by the real-life fact that wires can only transmit power a certain distance before power losses/heat become too great. This is why power is transmitted at high voltages, because the higher the voltage, the less the power loss is. In fact, the whole transmitting power over great distances is inefficient as a whole in terms of manpower needed to maintain the power infrastructure, and would be far beyond the scope of a single survivor.

Therefore different gauge wires would have different ‘transmission’ distances. A small wire might only have a 6 tile transmission distance while a larger one would have a better transmission distance.

With a large (for houses) cable of 10mm2, and say 5kW of power transferred at 230V, you could power a ~100m line with around 4-5% drop in voltage (quick google search reference: Voltage drop calculator (DC & AC) )
So, sure, there is a limit and it is not much bigger than the reality bubble. (AFAIK reality is 60 tiles to every direction)
Maybe we could let the player transfer unlimited power, but just limit the max length to 40-50 tiles?
Meaning that when a player is close to an appliance, the power source will be inside the bubble too!

Besides that, i don’t see why tile by tile wiring will be expensive in cpu, since we do not need to recalculate every turn every tile.
Normally we need to constantly calculate only the source and drain. The wiring gets recalculated only if we add a source to a point or a power outlet, and only once for each change.

PS. If we go with the standard 12V of a car battery, the losses will be around 4% in a length of only 5 meters… even a desperate survivor would not extend such a line over 10-15 meters, as the voltage would start getting at less than 10V, insufficient to power electronic appliances rated for 12V.
(unless we are talking about low power drains, where in that case the cables length can be way bigger)

I’ve talked with creators of technological mods for other games and one solution they used for technology outside of loaded chunks (yes, this was a minecraft mod) was to create a system that could keep things that needed timers up without loading the whole chunk. Not sure if that is viable for this or not. Will leave that to actual coders.

I would argue that connectivity between tiles can be handled separately from the active objects.

You could have wiring/piping started by something similar to the quantum wires in DF - you indicate where you want it to start, and then it lets you know which other nodes are in range as the endpoint . The pathing is done on installation, with resource costs determined by distance. At the moment of install, two things happen - you create (or add on to an existing) ‘network’ using a data structure outside the reality bubble, and you generate the wire/piping path in the reality bubble by the fields method mentioned. The network data structure would just need to be a list (not even a tree) of all nodes, with each entry containing something pointing to the actual corresponding in-game object, what network the node belongs to, what nodes are directly connected to it, and what the node is actively doing. The fields would only need to know two things, and both of those passively - what kind of network it represents and what network it belongs to.

Then any time a tile with a field in it has Something Substantial happen (i.e., something that could/does break a connection), you eliminate that field and then run a fill from an arbitrary node in that network, checking the connection along the entire route. If there are any nodes that can’t be reached by that check, run a fill from each of those in sequence (still using existing connection fields) and create/re-connect them into their own networks as necessary. There could be a construction command to rip out wires or pipes (and maybe a tool or two to let you find wires/pipes through in-game means?) to get resources back. The network data structure’s simplicity could also lend itself to letting your networks run while you aren’t there. Instead of directly modifying the data for a running generator connected to a storage battery (since I assume that’s pretty thoroughly offloaded when outside the bubble), the network could just take a snapshot during the offload of any given node and store deltas to be applied when those nodes are back within the bubble. And since these networks would ONLY exist as the player creates them, you shouldn’t run into issues unless players are doing stupid player tricks with ridiculously sized networks.

So a straightforward example - I want to connect a bicycle generator to a storage battery. I set up the generator, then I set up the storage battery. I then go to one of them and say I want to connect the two. It checks the distance, says it will cost so much copper wire and I say OK. It then routes the power, building the connection directly between them, adding them both to Network 0. I then want to connect a floodlight to the storage battery, but they’re too far away, so I craft and then set up a repeater at a midpoint. I then wire the midpoint in, and then the floodlight, and now Network 0 has four nodes. I decide to go scavenging and accidentally leave the floodlight on - when the node objects are offloaded, it snapshots that the battery has X power and it knows the floodlight is on and that floodlights consume Y power/minute. While I’m out and about, it acknowledges that the amount of power consumed == X, so it knows that the floodlight should be off and the battery should be at zero power. When I get back home, and it loads the floodlight and battery into memory, it applies those deltas to the objects and I get very upset at myself. Later, I accidentally throw a grenade into my wood stove, and the repeater is destroyed in the chaos. The game then recalculates the network, and moves the floodlight into Network 1 pending home repairs.

To handle an edge situation like damage to a network that is partially within the reality bubble, the reconnection logic only needs to make one assumption - that the only things that can change are those within the reality bubble. So when Something Substantial happens somewhere in the reality bubble that causes a network connection recalc, every node within the relevant network should be flagged for a recalc individually. The logic would then randomly select for the fill test only a node that is within the reality bubble. When doing the fill, it assumes that if a connection is on the border of reality heading outside the bubble, then everything beyond that point is intact (and can be handled using the nodes’ connection info stored in the network data structure). If every node within reality is handled and the flagged out of reality ones haven’t been addressed yet, then they would default into being their own network. And since everything is specific to a network, if a player had 20 networks but damage only happens to network 14, it would only be network 14 that needs to be calculated.

IANA coder, but I imagine that the above could handle a lot of the weird edge cases while also allowing for player constructions to continue to operate off-grid. It certainly has a hefty smell, but I don’t think it’s quite as hefty as fiddling around with stored map data.