Skip to content

Commit

Permalink
Finished refactoring. Moved FKTargetType.java to FKUnitType.java. Tes…
Browse files Browse the repository at this point in the history
…ts have been updated and everything passes.
  • Loading branch information
ryanrolds committed Jan 7, 2011
1 parent 44c917f commit de270e8
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 131 deletions.
10 changes: 5 additions & 5 deletions src/com/mobilebuttes/fortyk/FKAttacker.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public class FKAttacker extends FKUnit {
private boolean thunderHammer = false; // powerfist - against vehicles w/o initiative it causes crew shaken


public int getStrength(FKTargetType target,FKCombatType type) {
if(sniper && target == FKTargetType.ARMORED && type == FKCombatType.SHOOTING) return 3; // BRB p31.2.9 - Sniper
if(witchBlade && target == FKTargetType.ARMORED && type == FKCombatType.CLOSE_COMBAT) return 9; // BRB p42.2.3 - Witchblades
public int getStrength(FKUnitType target,FKCombatType type) {
if(sniper && target == FKUnitType.ARMORED && type == FKCombatType.SHOOTING) return 3; // BRB p31.2.9 - Sniper
if(witchBlade && target == FKUnitType.ARMORED && type == FKCombatType.CLOSE_COMBAT) return 9; // BRB p42.2.3 - Witchblades
if((powerFist || thunderHammer) && type == FKCombatType.CLOSE_COMBAT) {
return (strength * 2 < 10) ? strength * 2 : 10;
}
Expand Down Expand Up @@ -131,8 +131,8 @@ public boolean isThunderHammer() {
public void setThunderHammer(boolean thunderHammer) {
this.thunderHammer = thunderHammer;
}
public boolean isArmorIgnored(FKTargetType target,FKCombatType type) {
if(isPowerWeapon() && target == FKTargetType.UNARMORED && type == FKCombatType.CLOSE_COMBAT) return true;
public boolean isArmorIgnored(FKUnitType target,FKCombatType type) {
if(isPowerWeapon() && target == FKUnitType.UNARMORED && type == FKCombatType.CLOSE_COMBAT) return true;

return false;
}
Expand Down
48 changes: 25 additions & 23 deletions src/com/mobilebuttes/fortyk/FKMath.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,30 @@ public class FKMath {

public void processScenario(FKScenario s) {
double prob = 1.0;
FKAttacker attacker = s.getAttacker();
FKUnit target = s.getTarget();

if(s.getType() == FKScenarioType.SHOOTING) {
double hitChance = calcToHit(s.getBS(),s.isTWL(),s.isOnHitSuccessRR(),s.isOnHitFailureRR());
if(s.getCombatType() == FKCombatType.SHOOTING) {
double hitChance = calcToHit(attacker.getBS(),attacker.isTWL(),target.isOnHitSuccessRR(),attacker.isOnHitFailureRR());

if(s.getTarget() == FKScenarioTarget.UNARMORED) {
double toWound = calcToWound(s.getStrength(),s.getToughness(),s.isOnWoundSuccessRR(),s.isOnWoundFailureRR(),s.isRending(),s.isSniper());
double saveChance = calcArmorSave(s.getArmor(),s.getAP(),s.isOnSaveSuccessRR(),s.isOnSaveFailureRR(),s.isArmorIgnored());
double coverChance = calcCover(s.getCover());
double invChance = calcInvSave(s.getInv(),s.isOnSaveSuccessRR(),s.isOnSaveFailureRR());
double fnpChance = calcFNP(s.isFNP(),s.getAP(),s.isArmorIgnored());
if(target.getType() == FKUnitType.UNARMORED) {
double toWound = calcToWound(attacker.getStrength(target.getType(),s.getCombatType()),target.getToughness(),target.isOnWoundSuccessRR(),attacker.isOnWoundFailureRR(target.getToughness()),attacker.isRending(),attacker.isSniper());
double saveChance = calcArmorSave(target.getArmor(attacker.isLance()),attacker.getAP(),target.isOnSaveSuccessRR(),attacker.isOnSaveFailureRR(),attacker.isArmorIgnored(target.getType(),s.getCombatType()));
double coverChance = calcCover(target.getCover());
double invChance = calcInvSave(target.getInv(),target.isOnSaveSuccessRR(),attacker.isOnSaveFailureRR());
double fnpChance = calcFNP(target.isFNP(),attacker.getAP(),attacker.isArmorIgnored(target.getType(),s.getCombatType()));

double bestSave = saveChance;
if(bestSave > coverChance) bestSave = coverChance;
if(bestSave > invChance) bestSave = invChance;

prob = hitChance * toWound * bestSave * fnpChance;

if(s.isRending()) prob = prob + (hitChance * ANYONESIDE * ((coverChance < invChance) ? coverChance : invChance));
if(attacker.isRending()) prob = prob + (hitChance * ANYONESIDE * ((coverChance < invChance) ? coverChance : invChance));
} else {
double glanceChance = calcToGlance(s.getStrength(),s.getArmor(),s.isMelta(),s.isOrdnance(),s.isRending(),s.isOnWoundSuccessRR(),s.isOnWoundFailureRR());
double penChance = calcToPen(s.getStrength(),s.getArmor(),s.isMelta(),s.isOrdnance(),s.isRending(),s.isOnWoundSuccessRR(),s.isOnWoundFailureRR());
double coverChance = calcCover(s.getCover());
double glanceChance = calcToGlance(attacker.getStrength(target.getType(),s.getCombatType()),target.getArmor(attacker.isLance()),attacker.isMelta(),attacker.isOrdnance(),attacker.isRending(),target.isOnWoundSuccessRR(),attacker.isOnWoundFailureRR(target.getToughness()));
double penChance = calcToPen(attacker.getStrength(target.getType(),s.getCombatType()),target.getArmor(attacker.isLance()),attacker.isMelta(),attacker.isOrdnance(),attacker.isRending(),target.isOnWoundSuccessRR(),attacker.isOnWoundFailureRR(target.getToughness()));
double coverChance = calcCover(target.getCover());

processVehicleDamage(s,hitChance*glanceChance*coverChance,true);
processVehicleDamage(s,hitChance*penChance*coverChance,false);
Expand All @@ -90,21 +92,21 @@ public void processScenario(FKScenario s) {
s.setNoEffectChance(ONE - prob);
}
} else { // TODO Close Combat
if(s.getTarget() == FKScenarioTarget.UNARMORED) { // TODO bug in rending calculation.
double hitChance = calcToAssaultHit(s.getAWS(),s.getTWS(),s.isOnHitSuccessRR(),s.isOnHitFailureRR());
double toWound = calcToAssaultWound(s.getStrength(),s.getToughness(),s.isOnWoundSuccessRR(),s.isOnWoundFailureRR(),s.isRending(),s.isWitchBlade(),s.getPoisoned());
double saveChance = calcArmorSave(s.getArmor(),s.getAP(),s.isOnSaveSuccessRR(),s.isOnSaveFailureRR(),s.isArmorIgnored());
double coverChance = calcCover(s.getCover());
double invChance = calcInvSave(s.getInv(),s.isOnSaveSuccessRR(),s.isOnSaveFailureRR());
double fnpChance = calcFNP(s.isFNP(),s.getAP(),s.isArmorIgnored());
if(s.getTarget().getType() == FKUnitType.UNARMORED) { // TODO bug in rending calculation.
double hitChance = calcToAssaultHit(attacker.getWS(),target.getWS(),target.isOnHitSuccessRR(),attacker.isOnHitFailureRR());
double toWound = calcToAssaultWound(attacker.getStrength(target.getType(),s.getCombatType()),target.getToughness(),target.isOnWoundSuccessRR(),attacker.isOnWoundFailureRR(target.getToughness()),attacker.isRending(),attacker.isWitchBlade(),attacker.getPoisoned());
double saveChance = calcArmorSave(target.getArmor(attacker.isLance()),attacker.getAP(),target.isOnSaveSuccessRR(),attacker.isOnSaveFailureRR(),attacker.isArmorIgnored(target.getType(),s.getCombatType()));
double coverChance = calcCover(target.getCover());
double invChance = calcInvSave(target.getInv(),target.isOnSaveSuccessRR(),attacker.isOnSaveFailureRR());
double fnpChance = calcFNP(target.isFNP(),attacker.getAP(),attacker.isArmorIgnored(target.getType(),s.getCombatType()));

double bestSave = saveChance;
if(bestSave > coverChance) bestSave = coverChance;
if(bestSave > invChance) bestSave = invChance;

prob = hitChance * toWound * bestSave * fnpChance;

if(s.isRending()) prob += hitChance * ANYONESIDE * invChance;
if(attacker.isRending()) prob += hitChance * ANYONESIDE * invChance;
} else {

}
Expand All @@ -118,10 +120,10 @@ private void processVehicleDamage(FKScenario s,double chance,boolean glancing) {
double sixth = chance / 6.0;

if(glancing) shift -= 2; // Glancing hits are -2 to v.damage
if(s.isOpenTopped()) shift += 2; // Open topped is +2 to v. damage
if(s.getAP() == 1) // AP1 is +1 to v. damage
if(s.getTarget().isOpenTopped()) shift += 2; // Open topped is +2 to v. damage
if(s.getAttacker().getAP() == 1) // AP1 is +1 to v. damage
shift++;
else if(s.getAP() < 1) // AP- is -1 to v. damage
else if(s.getAttacker().getAP() < 1) // AP- is -1 to v. damage
shift--;

switch(shift) { // TODO I want to make this cleaner
Expand Down
12 changes: 6 additions & 6 deletions src/com/mobilebuttes/fortyk/FKUnit.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mobilebuttes.fortyk;

public class FKUnit {
protected FKTargetType type = FKTargetType.UNARMORED;
protected FKUnitType type = FKUnitType.UNARMORED;

// Target vars
protected String name = "Target";
Expand All @@ -24,10 +24,10 @@ public class FKUnit {
protected boolean onSaveSuccessRR = false;
protected boolean onInvSuccessRR = false;

public FKTargetType getType() {
public FKUnitType getType() {
return type;
}
public void setType(FKTargetType type) {
public void setType(FKUnitType type) {
this.type = type;
}
public String getName() {
Expand All @@ -54,7 +54,7 @@ public void setBS(int bs) throws OutOfAcceptableRange {
else
throw new OutOfAcceptableRange("Ballistic skill out of range");
}
public int getStrength(FKTargetType target,FKCombatType type) {
public int getStrength(FKUnitType target,FKCombatType type) {
if(strength < 0) return 0;
return strength;
}
Expand All @@ -67,8 +67,8 @@ public void setToughness(int toughness) throws OutOfAcceptableRange {
else
throw new OutOfAcceptableRange("Toughness out of range");
}
public int getArmor(FKTargetType target,boolean lance) {
if(lance && target == FKTargetType.ARMORED && armor > 12) // BRB p32.2.3 - LANCE
public int getArmor(boolean lance) {
if(lance && getType() == FKUnitType.ARMORED && armor > 12) // BRB p32.2.3 - LANCE
return 12;

if(armor < 0) return 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mobilebuttes.fortyk;

public enum FKTargetType {
public enum FKUnitType {
UNARMORED,
ARMORED
}
Loading

0 comments on commit de270e8

Please sign in to comment.