-
Notifications
You must be signed in to change notification settings - Fork 523
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
Cryogenics: restrict cryo pods to cryo meds, restore limited metabolism #1533
Changes from all commits
3cc04e3
d04d7a4
98584f6
8e1b9ba
7e945d3
666fd57
d2ef2a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -606,11 +606,12 @@ public Solution SplitSolutionWithOnly(FixedPoint2 toTake, params string[] includ | |
|
||
return sol; | ||
} | ||
|
||
/// <summary> | ||
/// splits the solution taking the specified amount of reagents proportionally to their quantity. | ||
/// Splits a solution, taking the specified amount of reagents proportionally to their quantity. | ||
/// </summary> | ||
/// <param name="toTake">The total amount of solution to remove and return.</param> | ||
/// <returns>a new solution of equal proportions to the original solution</returns> | ||
/// <returns>A new solution of equal proportions to the original.</returns> | ||
public Solution SplitSolution(FixedPoint2 toTake) | ||
{ | ||
if (toTake <= FixedPoint2.Zero) | ||
|
@@ -674,58 +675,123 @@ public Solution SplitSolution(FixedPoint2 toTake) | |
return newSolution; | ||
} | ||
|
||
// Frontier: cryogenics per-reagent filter function (#1443, #1533) | ||
/// <summary> | ||
/// Frontier | ||
/// splits the solution taking up to the specified amount of each reagent from the solution. | ||
/// If the solution has less of a reagent than the specified amount, it will take all of that reagent. | ||
/// Splits a solution, taking the specified amount of each reagent from the solution. | ||
/// If any reagent in the solution has less volume than specified, it will all be transferred into the new solution. | ||
/// </summary> | ||
/// <param name="toTakePer">How much of each reagent to take</param> | ||
/// <returns>a new solution containing the reagents taken from the original solution</returns> | ||
public Solution SplitSolutionReagentsEvenly(FixedPoint2 toTakePer) | ||
/// <param name="toTakePer">How much of each reagent to take.</param> | ||
/// <returns>A new solution containing the reagents taken from the original solution.</returns> | ||
public Solution SplitSolutionPerReagent(FixedPoint2 toTakePer) | ||
{ | ||
var splitSolution = new Solution(); | ||
|
||
if (toTakePer <= FixedPoint2.Zero) | ||
return splitSolution; | ||
var reagentsCount = Contents.Count; | ||
var reagentsToRemove = new List<ReagentQuantity>(); | ||
for (var i = 0; i < reagentsCount; i++) | ||
return new Solution(); | ||
|
||
var origVol = Volume; | ||
Solution newSolution = new Solution(Contents.Count) { Temperature = Temperature }; | ||
|
||
for (var i = Contents.Count - 1; i >= 0; i--) // iterate backwards because of remove swap. | ||
{ | ||
var currentReagent = Contents[i]; | ||
var (reagent, quantity) = Contents[i]; | ||
|
||
if (currentReagent.Quantity <= FixedPoint2.Zero) | ||
whatston3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// If the reagent has more than enough volume to remove, no need to remove it from the list. | ||
if (quantity > toTakePer) | ||
{ | ||
reagentsToRemove.Add(currentReagent); | ||
continue; | ||
Contents[i] = new ReagentQuantity(reagent, quantity - toTakePer); | ||
newSolution.Contents.Add(new ReagentQuantity(reagent, toTakePer)); | ||
Volume -= toTakePer; | ||
} | ||
else | ||
{ | ||
Contents.RemoveSwap(i); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as I had mentioned in the private messages, it is bad practice to remove from an iterator while iterating threw it. the argument of "but everywhere else does it" falls in line with "if they jump off a bridge would you" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair, but we are also tied with upstream. If you want to move away from the code they have, alright, that's fine, but it must be done with intent. That is not the case here. I would believe that it is easier to maintain a set of solution splitting functions that look and act similarly than four and an odd duck. |
||
//Only add positive quantities to our new solution. | ||
if (quantity > 0) | ||
{ | ||
newSolution.Contents.Add(new ReagentQuantity(reagent, quantity)); | ||
Volume -= quantity; | ||
} | ||
} | ||
} | ||
|
||
// If old solution is empty, invalidate old solution and transfer all volume to new. | ||
if (Volume <= 0) | ||
{ | ||
RemoveAllSolution(); | ||
newSolution.Volume = origVol; | ||
} | ||
else | ||
{ | ||
newSolution.Volume = origVol - Volume; | ||
_heatCapacityDirty = true; | ||
} | ||
newSolution._heatCapacityDirty = true; | ||
|
||
ValidateSolution(); | ||
newSolution.ValidateSolution(); | ||
|
||
return newSolution; | ||
} | ||
|
||
/// <summary> | ||
/// Splits a solution, taking the specified amount of each reagent specified in reagents from the solution. | ||
/// If any reagent in the solution has less volume than specified, it will all be transferred into the new solution. | ||
/// </summary> | ||
/// <param name="toTakePer">How much of each reagent to take.</param> | ||
/// <returns>A new solution containing the reagents taken from the original solution.</returns> | ||
public Solution SplitSolutionPerReagentWithOnly(FixedPoint2 toTakePer, params string[] reagents) | ||
{ | ||
if (toTakePer <= FixedPoint2.Zero) | ||
return new Solution(); | ||
|
||
var origVol = Volume; | ||
Solution newSolution = new Solution(Contents.Count) { Temperature = Temperature }; | ||
|
||
for (var i = Contents.Count - 1; i >= 0; i--) // iterate backwards because of remove swap. | ||
{ | ||
var (reagent, quantity) = Contents[i]; | ||
|
||
// Each reagent to split must be in the set given. | ||
if (!reagents.Contains(reagent.Prototype)) | ||
continue; | ||
|
||
if (currentReagent.Quantity <= toTakePer) | ||
// If the reagent has more than enough volume to remove, no need to remove it from the list. | ||
if (quantity > toTakePer) | ||
{ | ||
splitSolution.AddReagent(currentReagent); | ||
reagentsToRemove.Add(currentReagent); | ||
Contents[i] = new ReagentQuantity(reagent, quantity - toTakePer); | ||
newSolution.Contents.Add(new ReagentQuantity(reagent, toTakePer)); | ||
Volume -= toTakePer; | ||
} | ||
else | ||
{ | ||
splitSolution.AddReagent(currentReagent.Reagent, toTakePer); | ||
RemoveReagent(currentReagent.Reagent, toTakePer); | ||
Contents.RemoveSwap(i); | ||
//Only add positive quantities to our new solution. | ||
if (quantity > 0) | ||
{ | ||
newSolution.Contents.Add(new ReagentQuantity(reagent, quantity)); | ||
Volume -= quantity; | ||
} | ||
} | ||
} | ||
|
||
foreach (var reagent in reagentsToRemove) | ||
// If old solution is empty, invalidate old solution and transfer all volume to new. | ||
if (Volume <= 0) | ||
{ | ||
RemoveReagent(reagent); | ||
} | ||
if (Volume == FixedPoint2.Zero) | ||
whatston3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
RemoveAllSolution(); | ||
|
||
_heatCapacityDirty = true; | ||
splitSolution._heatCapacityDirty = true; | ||
newSolution.Volume = origVol; | ||
} | ||
else | ||
{ | ||
newSolution.Volume = origVol - Volume; | ||
_heatCapacityDirty = true; | ||
} | ||
newSolution._heatCapacityDirty = true; | ||
|
||
ValidateSolution(); | ||
splitSolution.ValidateSolution(); | ||
newSolution.ValidateSolution(); | ||
|
||
return splitSolution; | ||
return newSolution; | ||
} | ||
// End Frontier | ||
|
||
/// <summary> | ||
/// Variant of <see cref="SplitSolution(FixedPoint2)"/> that doesn't return a new solution containing the removed reagents. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
metabolism-group-cryogenic = Cryogenic |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
- id: Food | ||
- id: Drink | ||
- id: Medicine | ||
- id: Cryogenic # Frontier | ||
- id: Poison | ||
- id: Narcotic | ||
- id: Alcohol |
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.
Don't like this: frankly, it should be searchable by MetabolismGroup without LINQ.
Whenever the reagents get loaded from YAML, you could look through the effects, associate them with the metabolism groups they have effects for, and then access that set in some lifecycle call here to build this array.
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.
i would recommend not using a hard coded list. it will make it makes it harder to maintain given somebody might add, re-name, remove, update, something in the future.
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 issue is that (as far as I know) there isn't a good, existing way to look it up. I can tell you what this should be - every reagent that can be metabolized as a Cryogenic drug.
Association's done from the individual reagents, and by the effects they have (can't think of an example of association here that isn't 1:1, but it's possibly 1:N off the top of my head). This isn't being stored at all in the MetabolismGroup, so we can't have a nice look up at runtime.