-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The Lightning-Factor #543
The Lightning-Factor #543
Conversation
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
@@ -203,6 +204,20 @@ private void OnElectrifiedInteractUsing(EntityUid uid, ElectrifiedComponent elec | |||
TryDoElectrifiedAct(uid, args.User, siemens, electrified); | |||
} | |||
|
|||
/* | |||
im pretty sure this was removed in a cherry-pick, but id like to keep it around for future overvoltage stuff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im pretty sure this was removed in a cherry-pick, but id like to keep it around for future overvoltage stuff | |
I'm pretty sure this was removed in a cherry-pick, but I'd like to keep it around for future overvoltage stuff |
// A logarithm allows a curve of damage that grows quickly, but slows down dramatically past a value. This keeps the damage to a reasonable range. | ||
const float DamageShift = 1.67f; // Shifts the curve for an overall higher or lower damage baseline | ||
const float CeilingCoefficent = 1.35f; // Adjusts the approach to maximum damage, higher = Higher top damage | ||
const float LogGrowth = 0.00001f; // Adjusts the growth speed of the curve |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be arguments on the function
@@ -13,60 +13,31 @@ namespace Content.Server.Lightning.Components; | |||
public sealed partial class LightningTargetComponent : Component | |||
{ | |||
/// <summary> | |||
/// The probability that this target will not be ignored by a lightning strike. This is necessary for Tesla's balance. | |||
/// The probability weighting of being stuck by lightning, compared against other nearby lightning targets. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// The probability weighting of being stuck by lightning, compared against other nearby lightning targets. | |
/// The probability weighting of being struck by lightning, compared against other nearby lightning targets. |
/// For the love of god, do not make this number negative. | ||
/// </summary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// For the love of god, do not make this number negative. | |
/// </summary> | |
/// </summary> | |
/// <remarks>For the love of god, do not make this number negative.</remarks> |
[Dependency] private readonly TransformSystem _transform = default!; | ||
[Dependency] private readonly IEntityManager _entMan = default!; | ||
|
||
// a priority queue is required to iterate through Arcs of various depth |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// a priority queue is required to iterate through Arcs of various depth | |
// A priority queue is required to iterate through Arcs of various depth |
_lightning.ShootRandomLightnings(anomaly, range, anomaly.Comp.MaxBoltCount * 3, 100000f, | ||
maxArcs: 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_lightning.ShootRandomLightnings(anomaly, range, anomaly.Comp.MaxBoltCount * 3, 100000f, | |
maxArcs: 3 | |
_lightning.ShootRandomLightnings(anomaly, range, anomaly.Comp.MaxBoltCount * 3, 100000f, maxArcs: 3 |
@@ -287,7 +287,12 @@ private void OnMeleeThrowOnHitAttempt(Entity<SharedGlimmerReactiveComponent> ent | |||
args.Cancelled = true; | |||
args.Handled = true; | |||
|
|||
_lightning.ShootRandomLightnings(ent, 10, 2, "SuperchargedLightning", 2, false); | |||
_lightning.ShootRandomLightnings(ent, 10f, 2, 50000f, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_lightning.ShootRandomLightnings(ent, 10f, 2, 50000f, | |
_lightning.ShootRandomLightnings( | |
ent, | |
10f, | |
2, | |
50000f, |
@@ -9,42 +9,62 @@ namespace Content.Server.Tesla.Components; | |||
[RegisterComponent, Access(typeof(LightningArcShooterSystem)), AutoGenerateComponentPause] | |||
public sealed partial class LightningArcShooterComponent : Component | |||
{ | |||
/// <summary> | |||
/// The total number of arcs that an energy ball can create from any one shot | |||
/// Increasing this value can lead to increasingly unpredictable ranges |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Increasing this value can lead to increasingly unpredictable ranges | |
/// Increasing this value can lead to increasingly unpredictable ranges | |
/// </summary> |
/// Fires a lightning bolt from one entity to another | ||
/// Only done serverside | ||
/// </summary> | ||
public virtual void ShootLightning(EntityUid user, EntityUid target, float totalCharge, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public virtual void ShootLightning(EntityUid user, EntityUid target, float totalCharge, | |
public virtual void ShootLightning( | |
EntityUid user, | |
EntityUid target, | |
float totalCharge, |
/// Looks for objects with a LightningTarget component in the radius, and fire lightning at (weighted) random targets | ||
/// Only done serverside | ||
/// </summary> | ||
public virtual void ShootRandomLightnings(EntityUid user, float lightningRadius, int lightningCount, float lightningChargePer, EntityCoordinates? queryPosition = null, bool lightningStacking = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public virtual void ShootRandomLightnings(EntityUid user, float lightningRadius, int lightningCount, float lightningChargePer, EntityCoordinates? queryPosition = null, bool lightningStacking = true, | |
public virtual void ShootRandomLightnings( | |
EntityUid user, | |
float lightningRadius, | |
int lightningCount, | |
float lightningChargePer, | |
EntityCoordinates? queryPosition = null, | |
bool lightningStacking = true, |
Any updates on this PR? |
Closing this PR: Derelict |
Description
So, the lightning system in the current back-end is actually a little bit smelly. Different levels of charge are determined by prototypes, and lightning targeting is hard fixated on ground rods. You can technically generate infinite power with a fork, a microwave, and a tesla coil, as tesla coils generate flat amounts of charge.
Another problem, is VM's obligation to emulate lightning effects rather than use a (eventually) cleaner lightning system due to a mixed-bag combination of the above described. I'm hoping that lightning changes could be used in the future to make any of the following possible:
This PR aims to improve the lightning system by first grounding it in reality. Lightning has an established charge that is absorbed by entities as it bounces, as well as implementing lightning forking behaviours. To accomplish this, lightning now pre-calculates a path before executing any effects (otherwise you would encounter anomalies like charge simply vanishing). Lightning has been made more unpredictable by swapping targeting priorities for probability weightings. If you have live sparks near machinery, you are probably doing something wrong.
This PR isn't done yet, I have yet to adjust the effects based on charge although the concept is implemented. Everything should eventually be overrideable with code, and even ignore the discharge system altogether.
TODO
Must-have
Nice
The future
Technical Details
Code changes from most complex to least complex
C.S/.../LightningSystem.cs
is the big fish here, and is hardly recognisable from its original incarnation:LightningSystem
functions now use a 'charge' variable which can be used to calculate factors like damage.LightningContext
struct is used byLightningSystem
which encapsulates the data of any given lightning bolt.LightningContext
contains a list of everyLightningArc
that pertains to it, and iterates through them to execute lightning effects like creating a beam from one entity to another and dealing damage.LightningContext
s are stored in a dictionary with a unique index, which functions like an array that effectively can expand infinitely.LightningSystem
has been reworked to support forking arcs, which requires each lightning step to be depth wise. Previously recursive behaviour wouldn't work as the lightning would continuously fork until it ran out of arcs, creating a chain.LightningArc
s are a new type which are fed into a priority queue system and dequeued based on lowest arc depth. When the priority queue is empty, it immediately triggers lightning effects and cleans theLightningContext
dictionary.LightningTarget
which reduces effect on subsequent targets.LightningSystem
functions use a weighted probability dictionary rather than a sorted list. This makes lightning behaviour much more random, but still permits control over the general likelihood of one thing being targeted over another. This was done to make lightning more spectacular.ShootLightning
andShootRandomLightning
have been updated to support parsing of functions rather than values. This is extremely useful for dynamic/random behaviours.HitByLightningEvent
was renamed toLightningEffectEvent
, and addedLightningStageEvent
. Some of the file diffs will mention this name change.C.S/.../LightningTargetSystem.cs
is adjacent and responsible for creating targets for lightning to arc toward.LightningArcResistance
has been extended intoLightningArcReduction
,LightningChargeReduction
,LightningChargeMultiplier
to encompass new lightning interactions.ElectrocutionSystem
to conditionally deal damage and apply the paralysed status effect, rather than relying on prototype physics collisions.Explosive
component to conditionally trigger it when struck by lightning.C.S/.../LightningTargetComponent.cs
has changes which reflect the above system changes. Additionally, all redundany explosive-related-vars have been culled as they should be used inExplosive
.C.S/.../ElectrocutionSystem.cs
had some questionable logic fixed where some functions would return false depending on input parameters. Essentially, the effect of damage and stunning is independent. This allows machines to take damage from electrocute (finally putting electronic shock vulnerability to use!)int
were replaced withFixedPoint2
.C.Sh/.../ElectrocutionSystem.cs
had anint
changed to aDamageSpecifier
.Beyond the core logic, users of the LightningSystem were also changed to various degrees:
C.S/.../LightningArcShooterSystem.cs
has been updated to use the new function parsing functionality thatLightningSystem
provides. Instead of shooting a random number of lightning bolts with a flat number of arcs, the system tallies a random number of bolts and a random number of arcs to fire. With extremely good(?) luck, you could roll 4 bolts each with only 1 arc. With quantum bad(?) luck, you could roll a singular bolt that extends a 16 arc long chain from tesla containment all the way to the Engineering substation, which proceeds to cut emitter power which then looses the tesla.C.S/.../LightningArcShooterComponent.cs
has variable changes that reflect the system changes.C.S/.../TeslaCoilSystem.cs
now uses discharge fromLightningSystem
rather than generating a flat amount of charge whenever hit by lightning. Also renamedHitByLightningEvent
.C.S/.../TeslaCoilComponent.cs
has ditto.C.S/.../ElectricalAnomalySystem.cs
hadShootRandomLightning
updated.C.S/.../MicrowaveSystem.cs
hadShootRandomLightning
updated.C.S/.../GlimmerReactiveSystem.cs
hadShootRandomLightning
updated.C.S/.../LightningSparkingSystem.cs
hadHitByLightningEvent
renamed.For unique prototype changes
Resources/Prototypes/Entities/Effects/lightning.yml
had every instance ofElectrified
removed, sinceLightningSystem
usesElectrocutionSystem
instead.Resources/Prototypes/Entities/Structures/Power/Generation/Tesla/energyball.yml
was updated to accomodate new changes toLightningArcShooter
, and also fixed a bug whereshader: unshaded
was not put in the correct location.Resources/Prototypes/Entities/Structures/Power/Generation/Tesla/coil.yml
Tesla coils get a target weighting of200
, and now have theShockAbsorber
damage modifier that zeroes incoming shock damage. Grounding rods get a target weighting of400
and also haveShockAbsorber
.Every other prototype change from hereon is simply configuring either
Explosive
orLightningTarget
components.Resources/Prototypes/Entities/Mobs/base.yml
Mobs get a weighting of10
.Resources/Prototypes/Entities/Structures/Doors/Airlocks/base_structureairlocks.yml
Airlocks get a weighting of10
.Resources/Prototypes/Entities/Structures/Lighting/base_lighting.yml
Lights get a weight of2
.Resources/Prototypes/Entities/Structures/Machines/Computers/base_structurecomputers.yml
Computers get a small explosion, and get a weight of10
.Resources/Prototypes/Entities/Structures/Machines/base_structuremachines.yml
Machines get a small explosion, and get a weight of20
.Resources/Prototypes/Entities/Structures/Power/apc.yml
APCs have a moderate explosion, and get a weight of25
.Resources/Prototypes/Entities/Structures/Power/smes.yml
SMESes have a moderate explosion, and get a weight of75
.Resources/Prototypes/Entities/Structures/Power/substation.yml
Both substations maintain their large explosion, and get a weight of50
.Media
Changelog
🆑