Redundant cast removal, from mjunix, GHPR#102.

This commit is contained in:
Mike Pope 2022-03-12 19:30:14 +10:30
parent 436b14f9af
commit ea2960addc
3 changed files with 47 additions and 47 deletions

View File

@ -52,7 +52,7 @@ public enum Size {
}
public Size scaled(float f) {
int val = this.ordinal() + (int)Math.round(4 * (f - 1.0f));
int val = this.ordinal() + Math.round(4 * (f - 1.0f));
return (val < 0 || val >= Size.MAX.ordinal()) ? null
: Size.values()[val];
}

View File

@ -1508,7 +1508,7 @@ public class Map extends FreeColGameObject implements Location {
// This is suboptimal. We do not know where to enter from
// Europe, so start with the standard entry location...
} else if ((p = searchMap(unit,
(Tile)offMapUnit.getFullEntryLocation(),
offMapUnit.getFullEntryLocation(),
goalDecider, costDecider, maxTurns, carrier,
null, lb)) == null) {
path = null;

View File

@ -1776,16 +1776,16 @@ public final class InGameController extends Controller {
* Denounce an existing mission.
*
* @param serverPlayer The {@code ServerPlayer} that is denouncing.
* @param unit The {@code Unit} denouncing.
* @param sUnit The {@code ServerUnit} denouncing.
* @param is The {@code IndianSettlement} containing the mission
* to denounce.
* @return A {@code ChangeSet} encapsulating this action.
*/
public ChangeSet denounceMission(ServerPlayer serverPlayer,
ServerUnit unit,
ServerUnit sUnit,
IndianSettlement is) {
ChangeSet cs = new ChangeSet();
unit.csVisit(serverPlayer, is, 0, cs);
sUnit.csVisit(serverPlayer, is, 0, cs);
// Determine result
Unit missionary = is.getMissionary();
@ -1798,12 +1798,12 @@ public final class InGameController extends Controller {
if (missionary.hasAbility(Ability.EXPERT_MISSIONARY)) {
denounce += 0.2;
}
if (unit.hasAbility(Ability.EXPERT_MISSIONARY)) {
if (sUnit.hasAbility(Ability.EXPERT_MISSIONARY)) {
denounce -= 0.2;
}
if (denounce < 0.5) { // Success, remove old mission and establish ours
return establishMission(serverPlayer, unit, is);
return establishMission(serverPlayer, sUnit, is);
}
// Denounce failed
@ -1812,7 +1812,7 @@ public final class InGameController extends Controller {
cs.addMessage(serverPlayer,
new ModelMessage(MessageType.FOREIGN_DIPLOMACY,
"indianSettlement.mission.noDenounce",
serverPlayer, unit)
serverPlayer, sUnit)
.addStringTemplate("%nation%", owner.getNationLabel()));
cs.addMessage(enemy,
new ModelMessage(MessageType.FOREIGN_DIPLOMACY,
@ -1823,9 +1823,9 @@ public final class InGameController extends Controller {
is.getLocationLabelFor(enemy))
.addStringTemplate("%nation%", owner.getNationLabel()));
cs.add(See.perhaps().always(serverPlayer),
(FreeColGameObject)unit.getLocation());
((ServerUnit)unit).csRemove(See.perhaps().always(serverPlayer),
unit.getLocation(), cs);//-vis(serverPlayer)
(FreeColGameObject)sUnit.getLocation());
sUnit.csRemove(See.perhaps().always(serverPlayer),
sUnit.getLocation(), cs);//-vis(serverPlayer)
serverPlayer.invalidateCanSeeTiles();//+vis(serverPlayer)
// Others can see missionary disappear
@ -2315,25 +2315,25 @@ public final class InGameController extends Controller {
* Establish a new mission.
*
* @param serverPlayer The {@code ServerPlayer} that is establishing.
* @param unit The missionary {@code Unit}.
* @param sUnit The missionary {@code ServerUnit}.
* @param is The {@code IndianSettlement} to establish at.
* @return A {@code ChangeSet} encapsulating this action.
*/
public ChangeSet establishMission(ServerPlayer serverPlayer,
ServerUnit unit,
ServerUnit sUnit,
IndianSettlement is) {
ChangeSet cs = new ChangeSet();
unit.csVisit(serverPlayer, is, 0, cs);
sUnit.csVisit(serverPlayer, is, 0, cs);
// Result depends on tension wrt this settlement.
// Establish if at least not angry.
final Tension tension = is.getAlarm(serverPlayer);
Location loc = unit.getLocation();
Location loc = sUnit.getLocation();
switch (tension.getLevel()) {
case HATEFUL: case ANGRY:
cs.add(See.perhaps().always(serverPlayer), (FreeColGameObject)loc);
((ServerUnit)unit).csRemove(See.perhaps().always(serverPlayer),
loc, cs);//-vis(serverPlayer)
sUnit.csRemove(See.perhaps().always(serverPlayer),
loc, cs);//-vis(serverPlayer)
serverPlayer.invalidateCanSeeTiles();//+vis(serverPlayer)
break;
@ -2342,9 +2342,9 @@ public final class InGameController extends Controller {
if (is.hasMissionary()) sis.csKillMissionary(Boolean.FALSE, cs);
// Always show the tile the unit was on
cs.add(See.perhaps().always(serverPlayer), unit.getTile());
cs.add(See.perhaps().always(serverPlayer), sUnit.getTile());
sis.csChangeMissionary(unit, cs);//+vis(serverPlayer)
sis.csChangeMissionary(sUnit, cs);//+vis(serverPlayer)
break;
}
@ -2353,7 +2353,7 @@ public final class InGameController extends Controller {
cs.addMessage(serverPlayer,
new ModelMessage(MessageType.FOREIGN_DIPLOMACY,
"indianSettlement.mission." + tension.getKey(),
serverPlayer, unit)
serverPlayer, sUnit)
.addStringTemplate("%nation%", nation));
// Others can see missionary disappear and settlement acquire
@ -2594,12 +2594,12 @@ public final class InGameController extends Controller {
* Learn a skill at an IndianSettlement.
*
* @param serverPlayer The {@code ServerPlayer} that is learning.
* @param unit The {@code Unit} that is learning.
* @param sUnit The {@code ServerUnit} that is learning.
* @param is The {@code IndianSettlement} to learn from.
* @return A {@code ChangeSet} encapsulating this action.
*/
public ChangeSet learnFromIndianSettlement(ServerPlayer serverPlayer,
ServerUnit unit,
ServerUnit sUnit,
IndianSettlement is) {
// Sanity checks.
final Specification spec = getGame().getSpecification();
@ -2608,33 +2608,33 @@ public final class InGameController extends Controller {
return serverPlayer.clientError("No skill to learn at "
+ is.getName());
}
if (unit.getUnitChange(UnitChangeType.NATIVES, skill) == null) {
return serverPlayer.clientError("Unit " + unit
if (sUnit.getUnitChange(UnitChangeType.NATIVES, skill) == null) {
return serverPlayer.clientError("Unit " + sUnit
+ " can not learn skill " + skill + " at " + is.getName());
}
// Try to learn
ChangeSet cs = new ChangeSet();
unit.setMovesLeft(0);
sUnit.setMovesLeft(0);
// csVisit has already been called in askLearnSkill
Location loc = unit.getLocation();
Location loc = sUnit.getLocation();
switch (is.getAlarm(serverPlayer).getLevel()) {
case HATEFUL: // Killed, might be visible to other players.
cs.add(See.perhaps().always(serverPlayer), (FreeColGameObject)loc);
((ServerUnit)unit).csRemove(See.perhaps().always(serverPlayer),
loc, cs);//-vis(serverPlayer)
sUnit.csRemove(See.perhaps().always(serverPlayer),
loc, cs);//-vis(serverPlayer)
serverPlayer.invalidateCanSeeTiles();//+vis(serverPlayer)
break;
case ANGRY: // Learn nothing, not even a pet update
cs.addPartial(See.only(serverPlayer), unit,
"movesLeft", String.valueOf(unit.getMovesLeft()));
cs.addPartial(See.only(serverPlayer), sUnit,
"movesLeft", String.valueOf(sUnit.getMovesLeft()));
break;
default:
// Teach the unit, and expend the skill if necessary.
// Do a full information update as the unit is in the settlement.
unit.changeType(skill);//-vis(serverPlayer)
sUnit.changeType(skill);//-vis(serverPlayer)
serverPlayer.invalidateCanSeeTiles();//+vis(serverPlayer)
cs.add(See.perhaps(), unit);
cs.add(See.perhaps(), sUnit);
if (!is.isCapital()
&& !(is.hasMissionary(serverPlayer)
&& spec.getBoolean(GameOptions.ENHANCED_MISSIONARIES))) {
@ -3472,12 +3472,12 @@ public final class InGameController extends Controller {
* Speak to the chief at a native settlement.
*
* @param serverPlayer The {@code ServerPlayer} that is scouting.
* @param unit The scout {@code Unit}.
* @param sUnit The scout {@code ServerUnit}.
* @param is The {@code IndianSettlement} to scout.
* @return A {@code ChangeSet} encapsulating this action.
*/
public ChangeSet scoutSpeakToChief(ServerPlayer serverPlayer,
ServerUnit unit, IndianSettlement is) {
ServerUnit sUnit, IndianSettlement is) {
ChangeSet cs = new ChangeSet();
Tile tile = is.getTile();
boolean tileDirty = is.setVisited(serverPlayer);
@ -3486,10 +3486,10 @@ public final class InGameController extends Controller {
// Hateful natives kill the scout right away.
Tension tension = is.getAlarm(serverPlayer);
if (tension.getLevel() == Tension.Level.HATEFUL) {
Location loc = unit.getLocation();
Location loc = sUnit.getLocation();
cs.add(See.perhaps().always(serverPlayer), (FreeColGameObject)loc);
((ServerUnit)unit).csRemove(See.perhaps().always(serverPlayer),
loc, cs);//-vis(serverPlayer)
sUnit.csRemove(See.perhaps().always(serverPlayer),
loc, cs);//-vis(serverPlayer)
serverPlayer.invalidateCanSeeTiles();//+vis(serverPlayer)
result = "die";
} else {
@ -3497,17 +3497,17 @@ public final class InGameController extends Controller {
List<UnitType> scoutTypes = getGame().getSpecification()
.getUnitTypesWithAbility(Ability.EXPERT_SCOUT);
UnitType scoutSkill = first(scoutTypes);
int radius = unit.getLineOfSight();
int radius = sUnit.getLineOfSight();
UnitType skill = is.getLearnableSkill();
int rnd = randomInt(logger, "scouting", random, 10);
if (is.hasAnyScouted()) {
// Do nothing if already spoken to.
result = "nothing";
} else if (scoutSkill != null && unit.getType() != scoutSkill
} else if (scoutSkill != null && sUnit.getType() != scoutSkill
&& ((skill != null && skill.hasAbility(Ability.EXPERT_SCOUT))
|| rnd == 0)) {
// If the scout can be taught to be an expert it will be.
unit.changeType(scoutSkill);//-vis(serverPlayer)
sUnit.changeType(scoutSkill);//-vis(serverPlayer)
serverPlayer.invalidateCanSeeTiles();//+vis(serverPlayer)
result = "expert";
} else {
@ -3519,7 +3519,7 @@ public final class InGameController extends Controller {
radius = Math.max(radius, IndianSettlement.TALES_RADIUS);
result = "tales";
} else {
if (unit.hasAbility(Ability.EXPERT_SCOUT)) {
if (sUnit.hasAbility(Ability.EXPERT_SCOUT)) {
gold = (gold * 11) / 10; // FIXME: magic number
}
serverPlayer.modifyGold(gold);
@ -3532,7 +3532,7 @@ public final class InGameController extends Controller {
}
// Have now spoken to the chief.
unit.csVisit(serverPlayer, is, 1, cs);
sUnit.csVisit(serverPlayer, is, 1, cs);
tileDirty = true;
// Update settlement tile with new information, and any
@ -3544,12 +3544,12 @@ public final class InGameController extends Controller {
// If the unit was promoted, update it completely, otherwise just
// update moves and possibly gold+score.
unit.setMovesLeft(0);
sUnit.setMovesLeft(0);
if ("expert".equals(result)) {
cs.add(See.perhaps(), unit);
cs.add(See.perhaps(), sUnit);
} else {
cs.addPartial(See.only(serverPlayer), unit,
"movesLeft", String.valueOf(unit.getMovesLeft()));
cs.addPartial(See.only(serverPlayer), sUnit,
"movesLeft", String.valueOf(sUnit.getMovesLeft()));
}
}
if (tileDirty) {
@ -3559,7 +3559,7 @@ public final class InGameController extends Controller {
// Always add result.
cs.add(See.only(serverPlayer),
new ScoutSpeakToChiefMessage(unit, is, result));
new ScoutSpeakToChiefMessage(sUnit, is, result));
// Other players may be able to see unit disappearing, or
// learning.