Not logged inOpenClonk Forum
Up Topic Development / Scenario & Object Development / Energy/Power system
- - By Maikel Date 2009-08-24 12:44 Edited 2009-09-03 18:29
Energy/Power system

Let me first elaborate on the flaws of the current energy system in Clonk:

  • Directionality: Power lines possess the properties of a diode, i.e. only energy can flow from the first connected object to the second connected object. First of all, this makes no sense. Secondly in hard scenarios where power generators are likely to be destroyed once in a while, repairing complex systems will end up in a mess and can take up to one hour of work.

  • Power plant: The least used building in Clonk. Why? Because it can not be incorperated in the current power system. It burns fuels unnecessary, and it will stay this way if we keep the current system.

  • Engine internal: The current power system is partly engine internal, by the use of two functions CheckEnergyNeedChain and EnergyCheck. This is in my opinion not needed.

  • Use of Physicals: Energy of buildings is stored in the Physical "Energy", which is also used for the Clonk's hitpoints. Somewhat strange, and it is just more clear to store this in a local variable.


Now I will propose an alternative system which will not use engine internal functions. It uses two scripts which contain all basic functionalities. One script for power generators and one script for power consumers. There is also the powerline which is only used to determine whether two objects are connected. both scripts should be included into either the power generator or the power consumer. 

The power generator script has the following properties:

  • A local variable iPower, this is the current amount of power stored in the generator.

And some functions to modify iPower:

  • IsPowerGenerator(), returns whether the object is a power generator.

  • GetCapacity(), returns the amount of the power that can be stored in the generator.

  • GetGeneratorPriority(), returns the generator's priority, consumers preferably drain from generators with the highest priority.

  • IsPowerGeneratorFor(object pConsumer, object pNext, object pOldLine), Returns whether the objects is a power genarator connected to pConsumer.

  • GetPower(), returns the current power level of the object.

  • SetPower(int iSetPower), sets the current power level of the object to iSetPower.

  • DoPower(int iDoPower),  adds iDoPower to the current power level of the object.

Power generators can fill their storage with SetPower or DoPower in action calls of their power generating activities.

The power consumer script has the following properties:

  • IsPowerConsumer(), returns whether the object is a power generator.

  • CheckPower(int iPowerCheck, bool fNoSubstract), returns true and substracts iPowerCheck if there is enough energy available in a connected generator, otherwise false. This function will start displaying the energy need symbol when false, and stop doing this when true. This function uses FindPowerGenerator to find a connected generator.

  • Find_PowerGenerator(object pConsumer), function compatible with FindObjects, finds all generators connected to pConsumer.

  • Sort_GeneratorPriority(), function compatible with FindObjects, sorts all generators according to their priority.

Power consumers must use CheckPower to check whether a power consuming activity can be sustained.

The powerline is used to connect objects using the power system, it has three public functions:

  • IsPowerLine(), returns whether the object is a power line.

  • IsConnectedWith(object pObject), returns true if pObject is connected with the powerline, otherwise false.

  • GetConnectedObject(object pObject), returns the object at the other end of the line, where pObject defines this end of the line.


An example:
We have the following scheme: Elevator====Windmill====Powerplant====Sawmill

  • Both the windmill and the power plant will fill up their storages with DoPower() calls in their activities, the powerplant will stop its activity when its storage is full.

  • If one starts operating the elevator, CheckPower calls will find the windmill(if it has enough power in its storage) and will substract power from it.

  • If one starts operating the sawmill, CheckPower calls will find the windmill(if it has enough power in its storage) and will substract power from it.

  • In both cases the windmill will be found, since it has the higher priority, consumer will drain only from this until there is more need than power sustained by the mill. Then the plant will be used as a backup.


Edit: Changed to the system Günther proposed(more or less), which cures some problems addressed in posts by Newton.

This can all be checked out in the attached file Power.c4d. The power producers are working good, the consumers I just reworked to get them working, they must be scripted better in OC.

P.S. Power in the function names is not correct, it should be energy. But this is already used.

I hereby license my work contained in Power.c4s under the ISC license.
Attachment: Power.c4s (371k)
Parent - - By Newton [es] Date 2009-08-24 14:30 Edited 2009-08-24 14:33
Very good concept. What is GetFreeCapacity and GetPowerLevel for, though? Where is the difference between POWR_Storage and POWR_Producer? Is it possible to combine these flags?

If I got a windmill, an elevator and a line which connects the two. How would producing energy and consuming energy work? Do I understand correctly that the windmill would just call DoPower() when it is windy, the elevator would just call CheckPower if it wants to move and the rest would be handled automagically by the lines? How do they work, do they have an interface too?

>P.P.S. Power.c4s is not a contribution to OC, it's just a modification of original content of CR -> No licenses.


Anything you coded by yourself is under your copyright. Anything that is your own work, you can license like you want. If you want the new power system to be part of OC, you need to license it under the ISC license.
Parent - By Günther [de] Date 2009-08-24 14:56
If it's a derivative work, things get more complicated than "you can license like you want". Fortunately, CR content is an exception.
Reply
Parent - - By Maikel Date 2009-08-24 15:33
I updated my post to add an example and some more function descriptions.

The power line does not have an interface, I only planned to let the amount of energy transported per frame be adjustable by a function. But this can be changed, since the power line's script is far from perfect.

The copyrights are hard to define here. Almost any script contains some code from RWD and from me.
I am probably allowed to license the scripts of Include.c4d, PowerLine.c4d and PowerPlant.c4d under the ISC license.
Parent - By Günther [de] Date 2009-08-24 20:18

> Almost any script contains some code from RWD and from me.


We have several Redwolf co-workers who can license parts of the CR scripts for use in OpenClonk, so that's not a problem. You just need to give everyone a license for your parts.
Reply
Parent - By B_E [de] Date 2009-08-24 14:45
Sounds very good, I like it too.
Parent - By Günther [de] Date 2009-08-24 14:54

> P.P.S. Power.c4s is not a contribution to OC, it's just a modification of original content of CR -> No licenses.


If you license your changes usefully, we can license the CR script for use in OpenClonk.
Reply
Parent - - By Newton [es] Date 2009-08-24 16:27 Edited 2009-08-24 16:30
Some more remarks:
I think these functions are pretty useless:

># GetFreeCapacity(), returns the free energy capacity of the object, that is GetCapacity - iPower.
># GetPowerLevel(), returns the current energy level in percentages of its maximum.


one can just write GetCapacity() - GetPower() and 100 * GetPower() / GetCapacity()

I think it is worth a thought to add a function called ConsumerPriority() or something similar that returns the priority of the consumer. If there is not enough power, not everything will not work anymore. Question is, if that is not confusing for the player as only one building keeps saying it has no power.

>From storage to consumer has still to be worked out.


I'd say, the producer fills up the storage as well, but with less priority (only if all consumers are filled up) - so only the surplus. To consumers, storages have the same role as producers.

Additionally, the included base object needs to have the functionality to display the "need energy" symbol if it has no power but needs some (or some other means to notify the player that no energy is there). I suggest the symbol is just placed in an additional layer.
Parent - - By Maikel Date 2009-08-25 13:03
I deleted the useless functions.

I changed the system quite a bit: there is now a function GetPowerNeed() [and dropped GetPowerType()] which specifies an object's need for power. The power lines use this and the objects capacity to determine energy flow. I think it works quite well now.

The need energy symbol is now implemented in CheckPower(),  I used an effect and an additional object. I don't know anything about layers.
Parent - - By Newton [es] Date 2009-08-25 14:28
What does GetPowerNeed() return e.g. for the windmill & elevator? 100? -100?

>I don't know anything about layers.


SetGraphics. Basically, display additional graphics without the need of extra objects. But it is not too important.
Parent - - By Maikel Date 2009-08-25 14:46
PowerNeed is just a constant integer between zero and 100, which is an indication of an object's need for power. If it is zero there is nog energy flow towards this object. For example in a closed network with two objects with both capacity 1000 and one has need 50 the other need 100: the available energy will be divided 2:1 in favour of the one with need 100. I redefined the constants as some sort of standards for the three different types. See the first post.

>SetGraphics. Basically, display additional graphics without the need of extra objects. But it is not too important.


Is it possible with this approach to get the symbol flashing on and off, like it is now?
Parent - By Newton [es] Date 2009-08-28 10:01
Yes
Parent - - By Newton [es] Date 2009-08-28 10:04
So with your system, the coal plant will either have a really big storage and/or check if it's power level goes under a certain limit, only then burns another chunk of coal - yes?
Parent - - By Maikel Date 2009-08-31 09:16
Not really, it burns fuels until its power storage is completely filled. This means that alle buildings connected to it will have a completely filled storage, because power flow will be preferably from producers to consumers. This is not a problem since all power produced by the plant will remain in the system. If only one building in that system is operated and the plant is out of fuel, the operating building will drain power from all storages until they are all empty.
Parent - - By Newton [es] Date 2009-08-31 11:51
What if the power line goes like this:

energy storage ======== windmill ========== evalator

If there is no wind, the windmill is out of energy but the energy storage is full, will the power be transmitted to the evelator?
Parent - - By Maikel Date 2009-08-31 12:36
As long as GetPowerNeed of the windmill will not return 0, there is no problem for the elevator. Bottlenecks can occur if the product of GetCapacity and GetPowerNeed is low compared to other connected objects.
Parent - - By Newton [es] Date 2009-08-31 19:25 Edited 2009-08-31 19:31
...which does not seem realistic nor the desired behaviour :-/
Couldn't there be a global behaviour for all buildings in one connected circuit?  (Power is not transmitted from one building to the other but is distributed amongst all buildings in one circuit). There are also problems with these kind of power distrubution, no?


//==Battery ==== Elevator ====Windmill=\\
||                                     ||
\\=====================================//
Parent - - By Sven2 [de] Date 2009-08-31 20:30
We could just drop powerlines altogether and calc (power producers - power consumers). Maybe add a maximum range.

Though admittedly, creating powerlines is one of the more fun things to do.
Parent - - By Atomclonk [de] Date 2009-08-31 20:37
Or making instances of power connections, ignoring alltogether the wires and using them only to add buildings to such an instance? Like...

Elevator=====Windmill=====Powerplant=====Factory
->
/--------------------------------------------\
|  Elevator          Windmill                |
|    Powerplant             Factory          |
\--------------------------------------------/

The windmill and the powerplant are pushing energy into a "pool" and the consumers are taking the energy from the pool. The pool is defined by the chains of connections to buildings.
Reply
Parent - By Ape [fi] Date 2009-09-01 06:47
The pool makes it easier to calculate the power amounts available / needed etc, but I think the power should be still transmitted with the lines. So when something in the pool needs energy it finds the shortest route from an instance with a lot of energy. Then the power is send through the lines. There could be a limit how much one line can transmit per second.

The idea is based on something like decentralized communication / file-sharing networking. One building could also take energy from multiple different routes simultaneously.
Parent - - By Atomclonk [de] Date 2009-08-28 15:08
@coal plant:
Why don't make a battery building like in SL? It would give some more strategic aspects. Maybe.
Reply
Parent - - By Maikel Date 2009-08-31 09:12
What is SL?
Parent - By Faby [it] Date 2009-08-31 10:51
Space Launch
Parent - - By Günther [de] Date 2009-08-31 21:16
Instead of diving directly into the details or just listing the flaws of the old system, I'll try to list the desired design from a player-point-of-view:
A building which needs power has to be connected directly or indirectly to a power-producing building in order to function, and that power-producing building has to have a source of energy available. Further action and consideration from the player shouldn't be needed, except for restocking and providing enough power-producing buildings. Some limits like line capacity or maximum line length might be fun, but probably not more than the hassle they would cause. Whether there are enough power-producing buildings should be immediately obvious.

I think this might be easiest to simulate by a function which calculates everything in one step. Make a list of all buildings connected to a power line, sort them into connected groups, ask every building how much power it needs, produces or can produce, add the first two up for every group, and if there is more power needed than produced, start the potential producers until there is enough power or all available producers are online. Then tell every consumer how much it gets until everything is used up, sorted by distance to power producers. Maybe create some sparkles if there are leftovers :-)

A more simulation-like scheme with independent actors like in previous Clonk titles and like you describe may seem more appealing at first, but in the end it only hides some parts of the algorithm in the engine, limiting flexibility.
Reply
Parent - - By Maikel Date 2009-09-01 12:10
So I changed the system accordingly(see first post).

>I think this might be easiest to simulate....


I did not implemented it like this. The producers just fill their storages, and the consumers try to find filled storages in group of objects that are connected to them.
Parent - - By Randrian [de] Date 2009-09-03 15:27
well, you have still the problem, that power producers have no priority. So the powerplant sometimes burns coal if there would also by a windmill supplying free energ.
Reply
Parent - By Maikel Date 2009-09-03 18:15
This I indicated in my first post.

But it's solved now. I'll update.
Parent - By Nachtfalter [de] Date 2009-10-02 00:16 Edited 2009-10-02 00:19
Because we use your very interesting system in a ClonkRage Fanpackage, I wrote some german strings for each Objekt. Use it, if you like.

I hereby license the following file(s) under the CC-by license
Attachment: Power_Germanstrings.c4d (20k)
Reply
- - By dylanstrategie [fr] Date 2010-03-15 21:33
Perhaps we will add a strategic/war idea on energy idea.

First idea : Use a object (like a parasite cable) for send the energy to a... other utilisator. A parasited energy system will have a special icon and is simple to destroy the parasite, go buy a wire cutter and... cut. Or surchage, more evil but don't forgot to cut the old cable...

Second idea : Like in EPIC mod, make wire cutter can destroy energy cables, a clonk infiltrate in ennemy fortress can cut off energy cables for make a big mess. Can also be make with a elevator (the elevator will fall down) and a pomp (the liquid will flood where the drain pipe is cutted)

Third idea : Surchage, is a strange idea, but some strategic, u see a windmill, and a cable, with some special stuff, u will use a surchage on the windmill, is make a huge and damaging energy who will cross the cable trought all the stuff on the way, like if the windmill send his energy to a workshop, if player surchage, a lighting-like energy ray will go to the workshop (very very very fast, like a lighning), all the clonks inside will lose random energy, or will die (all the damages random, a lucky clonk can destroy all, a unlucky clonk can kill itself), the production will lose material, or can be destroyed, the bulding will lose energy, take fire (but like the reworked fire system) or explode...

But more, if the bulding have the windmill to urgency system, and he have a liaison to a real energy system, is armadegon, the energy ray will electrocute all clonks on his way, damage buldings and make energy systems explose.

But, surchage the energy system of a opponent will take about 1 min, the surchage will not be succesfull all times and what is the result, the surchage stuff will be used... and the principal stuff is a player who see a guy try to make a surchage will try to cut off the energy bulding used for suchage, or just make a headshot !

Fourth idea : Energy pole, like telegraphic poles but with energy. Can be cutted with a wire (dangerous), with a axe (less dangerous) or a atombomb (don't try...), can relay energy on a huge map to a colony from the first town !

Final idea : Cut in water the cable will make water dangerous around (but in a limited area, no way to think u can make a sea electrified) and make the cable can't be reworked !

Ok, is more for war, but is good ideas no ?
Reply
Parent - - By AlteredARMOR [ua] Date 2010-03-16 10:24 Edited 2010-03-16 15:19
Do you have any peacefull ideas without cutters, headshots, damage, dying and armageddons? Hard to believe that Clonk is nothing more than just pointless clash of frenetic warriors...

Edit: It was just a joke
Reply
Parent - By Zapper [de] Date 2010-03-16 11:31
Clonk should be a game for both, settlers and fighters. And at least the latter _will_ need damage, dying and armageddons.
- By dylanstrategie [fr] Date 2010-03-16 13:34
Or settlement things if u like more.

Use the energys poles

(I copy/paste :D)

Fourth idea : Energy pole, like telegraphic poles but with energy. Can create a strategic/settle use, like u are on a floodable spot, or u have no more place for energy, u will spot a good place (like a air island, a hill top where the wind is more efficient or create near a charbon drill.

The problem today is when u are too far from energy maker ur cable can't relay.

So i think to energy poles.

Pros :

- Help players on very unstable maps.
- Stop the so problemly full rope limit.
- Can create a energy settlement away from the principal place for earn space.

Cons :

- Can create abuses.
- Will be really difficult to create with the telegraphic pole concept.
- Can be expensive in constrution kit in other way.
- Also expensive in ropes.
- A explosive object on and all break...
- Is will be difficult to know where is the rope limit, can make errors !
Reply
Up Topic Development / Scenario & Object Development / Energy/Power system

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill