Skip to content
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

Add unit option for when hit points damaged changes into #2689

Merged
merged 8 commits into from Dec 15, 2017

Conversation

ron-murhammer
Copy link
Member

@ron-murhammer ron-murhammer commented Dec 15, 2017

Addresses the first part of feature request: https://forums.triplea-game.org/topic/327/unit-option-when-damaged-change-into-different-unit-weakened-battleships

Functional Changes

  • Added new unit option whenHitPointsDamagedChangesInto to allow units to change into a different unit type when damaged during battle

Tested

  • Added the below example XML to TWW and tested running battles where battleships are damaged

Example XML

    <attachment name="unitAttachment" attachTo="germanBattleship" javaClass="games.strategy.triplea.attachments.UnitAttachment" type="unitType">
      <option name="movement" value="2"/>
      <option name="attack" value="7"/>
      <option name="defense" value="8"/>
      <option name="canBombard" value="true"/>
      <option name="isSea" value="true"/>
      <option name="hitPoints" value="2"/>
      <option name="bombard" value="6"/>
      <option name="requiresUnits" value="germanDocks:germanFactory"/>
      <option name="consumesUnits" value="1:germanHull"/>
      <option name="whenHitPointsDamagedChangesInto" value="1:true:germanBattleshipDamaged"/>
    </attachment>
    <attachment name="unitAttachment" attachTo="germanBattleshipDamaged" javaClass="games.strategy.triplea.attachments.UnitAttachment" type="unitType">
      <option name="movement" value="1"/>
      <option name="attack" value="3"/>
      <option name="defense" value="4"/>
      <option name="canBombard" value="true"/>
      <option name="isSea" value="true"/>
      <option name="hitPoints" value="2"/>
      <option name="bombard" value="3"/>
    </attachment>

@codecov-io
Copy link

codecov-io commented Dec 15, 2017

Codecov Report

Merging #2689 into master will increase coverage by <.01%.
The diff coverage is 26.56%.

Impacted file tree graph

@@             Coverage Diff             @@
##             master   #2689      +/-   ##
===========================================
+ Coverage      20.2%   20.2%   +<.01%     
- Complexity     5759    5763       +4     
===========================================
  Files           816     816              
  Lines         73766   73813      +47     
  Branches      12312   12319       +7     
===========================================
+ Hits          14905   14916      +11     
- Misses        56725   56757      +32     
- Partials       2136    2140       +4
Impacted Files Coverage Δ Complexity Δ
...ames/strategy/triplea/delegate/BattleDelegate.java 23.07% <0%> (+0.09%) 53 <0> (ø) ⬇️
.../java/games/strategy/triplea/delegate/Matches.java 43.23% <0%> (-0.05%) 356 <1> (+1)
...mes/strategy/triplea/delegate/MustFightBattle.java 66.66% <41.66%> (-0.75%) 350 <3> (+1)
...s/strategy/triplea/attachments/UnitAttachment.java 42.48% <9.52%> (-0.43%) 325 <1> (+1)
src/main/java/games/strategy/net/nio/Decoder.java 67.3% <0%> (+0.96%) 25% <0%> (+1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f781c8c...9b1e25f. Read the comment docs.

}

public void resetWhenHitPointsDamagedChangesInto() {
m_whenHitPointsDamagedChangesInto = new LinkedHashMap<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method uses LinkedHashMap, but the field initializer uses HashMap. Was that intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

* Can remove null check and this comment for next incompatible release.
*/
public Map<Integer, Tuple<Boolean, UnitType>> getWhenHitPointsDamagedChangesInto() {
if (m_whenHitPointsDamagedChangesInto == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need a similar null check in clearWhenHitPointsDamagedChangesInto() and setWhenHitPointsDamagedChangesInto(String)? Or will those code paths not be hit after deserializing an old save game?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fairly sure those shouldn't be hit.

@ssoloff ssoloff merged commit 428126e into master Dec 15, 2017
@RoiEXLab RoiEXLab deleted the Add_Unit_Option_For_whenHitPointsDamagedChangesInto branch December 15, 2017 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants