-
-
Notifications
You must be signed in to change notification settings - Fork 595
Add cell position adjacency bonus calculations EXCEPT for GetPlayerDataSource() #6855
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
base: master
Are you sure you want to change the base?
Changes from all commits
082442a
1f4f8cb
2b2d049
076e399
3d3fd0c
4ede406
5eea89a
9413a31
4e19465
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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using Components; | ||
| using Godot; | ||
|
|
||
|
|
@@ -141,4 +142,58 @@ public static float CalculateRotationSpeed(IReadOnlyList<HexWithData<CellTemplat | |
|
|
||
| return colonyRotation / cells.Count; | ||
| } | ||
|
|
||
| public static float GetAdjacencySpecializationBonusFromIndexAndPlan(CellTemplate? cellInBodyPlan, | ||
| IReadOnlyList<HexWithData<CellTemplate>> bodyPlan) | ||
| { | ||
| var bonus = 0.0f; | ||
|
|
||
| foreach (var cell in bodyPlan) | ||
| { | ||
| if (cellInBodyPlan!.CellType == cell.Data!.CellType | ||
|
Member
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. Why did you make the parameter nullable if you just use null suppression on it? This is the incorrect way to use null suppression; it should only be overridden when you are sure it is safe to do. We have null suppression enabled so that the compiler can help us notice potential bugs in code and need to write the proper handling code (or modify the parameter definitions so that our caller has to get valid data for us). |
||
| && cell.Position.DistanceTo(cellInBodyPlan.Position) == 1) | ||
| { | ||
| bonus += Constants.CELL_ADJACENCY_SPECIALIZATION_BONUS; | ||
| } | ||
| } | ||
|
|
||
| return 1 + bonus; | ||
| } | ||
|
|
||
| public static float GetAdjacencySpecializationBonusFromIndexAndPlan(int cellIndexInBodyPlan, | ||
| IReadOnlyIndividualLayout<IReadOnlyCellTemplate> bodyPlan) | ||
| { | ||
| var bonus = 0.0f; | ||
| var plan = bodyPlan.ToList(); | ||
|
Member
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. Temporary memory should be avoided. So the looping needs to be done in a different way here. |
||
| var cellInBodyPlan = plan[cellIndexInBodyPlan]; | ||
|
|
||
| foreach (var cell in bodyPlan) | ||
| { | ||
| if (cellInBodyPlan.Data!.CellType == cell.Data!.CellType | ||
| && cell.Position.DistanceTo(cellInBodyPlan.Position) == 1) | ||
| { | ||
| bonus += Constants.CELL_ADJACENCY_SPECIALIZATION_BONUS; | ||
| } | ||
| } | ||
|
|
||
| return 1 + bonus; | ||
| } | ||
|
|
||
| public static float GetAdjacencySpecializationBonusFromIndexAndPlan(int cellIndexInBodyPlan, | ||
| IndividualHexLayout<CellTemplate> bodyPlan) | ||
| { | ||
| var bonus = 0.0f; | ||
| var cellInBodyPlan = bodyPlan[cellIndexInBodyPlan]; | ||
|
|
||
| foreach (var cell in bodyPlan) | ||
| { | ||
| if (cellInBodyPlan.Data!.CellType == cell.Data!.CellType | ||
| && cell.Position.DistanceTo(cellInBodyPlan.Position) == 1) | ||
| { | ||
| bonus += Constants.CELL_ADJACENCY_SPECIALIZATION_BONUS; | ||
| } | ||
| } | ||
|
Comment on lines
+186
to
+195
Member
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. This still looks very similar to me... Like I think the code could be like: So that way there's less code repetition. |
||
|
|
||
| return 1 + bonus; | ||
| } | ||
| } | ||
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.
Overall I think this is pretty good for the backend part of this feature, though the changes in this file are kind of looking very similar, so I think some of the methods here could be simplified so that they just look up some data and then call an overload. Would that be possible?
Also one slight naming thing is that you should clarify if the body plan is the gameplay or editor body plan (as your code only works for the editor body plan variant and will fail for the gameplay body plan).
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'm not exactly sure what you mean by this, and I don't really see any way to simply these methods. CMIIW though, of course.
This seems a bit too important to just hide in parentheses.
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 mean it looks like the index method could just get the cell type from the index and then call the variant that takes in a cell template directly? I did not try to do that rewrite so I might be missing some small detail but to me that seems like a plausible code refactor.
I assumed you were aware of that... You'll want to check the differences between
ModifiableGameplayCellsandModifiableEditorCellsas I think that yeah your algorithm works for one but does not work for the other, so it should be clarified with variable naming and maybe even putting an XML comment with a warning about that that the algorithm only works for one cell layout variant.