Skip to content

Commit

Permalink
Added an extra check that will allow the human player to attack AI pl…
Browse files Browse the repository at this point in the history
…ayers with relations above the endHostilitiesThreshold. (#1142)

Added Test AI switching to space and ground war also.
Fixed decade in service/oldest man achievements not counted.
  • Loading branch information
hemoridos authored May 26, 2024
1 parent dc5c5c8 commit 0ccf488
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 51 deletions.
6 changes: 3 additions & 3 deletions src/hu/openig/mechanics/Simulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -805,12 +805,12 @@ static void checkAchievements(World world, boolean dayChange) {
}
}
if (dayChange) {
AchievementProgress ap = p.getOrCreateProgress("achievements.decade");
AchievementProgress ap = p.getOrCreateProgress("achievement.decade");
ap.displayProgress = true;
ap.max = 10;
ap.progress += 1 / 365.2425;

ap = p.getOrCreateProgress("achievements.oldest_man");
ap = p.getOrCreateProgress("achievement.oldest_man");
ap.displayProgress = true;
ap.max = 100;
ap.progress += 1 / 365.2425;
Expand Down Expand Up @@ -954,7 +954,7 @@ static void handleAttack(World world, Fleet fleet) {
}
// cancel attack if relations improved
int endHostilitiesThreshold = Math.max(dr.first.endHostilitiesThreshold, dr.second.endHostilitiesThreshold);
if (dr.value > endHostilitiesThreshold) {
if (dr.value > endHostilitiesThreshold && !(fleet.owner.ai instanceof AIUser)) {
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/hu/openig/model/Building.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class Building implements HasLocation {
public int assignedWorker;
/** The buildup progress up to the top hit point. */
public int buildProgress;
/** The hitpoints of this building. */
/** The currently available hitpoints of this building. */
public int hitpoints;
/** The current upgrade. Can be null for plain buildings. */
public Upgrade currentUpgrade;
Expand Down
53 changes: 27 additions & 26 deletions src/hu/openig/screen/GameKeyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,29 @@ void handleDefaultKeyboard(KeyEvent e) {
e.consume();
}
break;
// FIXME CHEAT
case KeyEvent.VK_J:
if (e.isControlDown()) {
Player p = world().player;

if (p.aiMode == AIMode.NONE) {
p.aiMode = AIMode.TEST;
p.ai = new AITest();
p.ai.init(p);
System.out.println("Switching to TEST AI.");
} else {
p.aiMode = AIMode.NONE;
p.ai = new AIUser();
p.ai.init(p);
System.out.println("Switching to no AI.");
}
e.consume();
}
break;
default:
}
}
if (!commons.worldLoading && world() != null

&& !control().movieVisible() && !commons.battleMode) {
if (e.getKeyChar() == '+' || e.getKeyCode() == KeyEvent.VK_PAGE_UP) {
if (enableForCurrentScreen()) {
Expand Down Expand Up @@ -581,33 +599,16 @@ public void invoke(CustomBalanceSettings value) {
break;
// FIXME CHEAT
case KeyEvent.VK_J:
// TOGGLE test AI on player
if (e.isControlDown()) {
if (e.isShiftDown()) {
Player p = world().player;
for (Player p0 : p.knownPlayers().keySet()) {
if (!p0.noDiplomacy) {
DiplomaticOffer dio = new DiplomaticOffer(CallType.ALLIANCE, ApproachType.HUMBLE);
dio.value(1000);
p.offers.put(p0.id, dio);
}
}
signalMessage(p);
} else {
Player p = world().player;

if (p.aiMode == AIMode.NONE) {
p.aiMode = AIMode.TEST;
p.ai = new AITest();
p.ai.init(p);
System.out.println("Switching to TEST AI.");
} else {
p.aiMode = AIMode.NONE;
p.ai = new AIUser();
p.ai.init(p);
System.out.println("Switching to no AI.");
if (e.isControlDown() && e.isShiftDown()) {
Player p = world().player;
for (Player p0 : p.knownPlayers().keySet()) {
if (!p0.noDiplomacy) {
DiplomaticOffer dio = new DiplomaticOffer(CallType.ALLIANCE, ApproachType.HUMBLE);
dio.value(1000);
p.offers.put(p0.id, dio);
}
}
signalMessage(p);

e.consume();
}
Expand Down
62 changes: 41 additions & 21 deletions src/hu/openig/screen/items/SpacewarScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
import hu.openig.core.Location;
import hu.openig.core.Pair;
import hu.openig.core.SimulationSpeed;
import hu.openig.mechanics.AITest;
import hu.openig.mechanics.AIUser;
import hu.openig.mechanics.BattleSimulator;
import hu.openig.mechanics.FreeFormSpaceWarMovementHandler;
import hu.openig.mechanics.SimpleSpaceWarMovementHandler;
import hu.openig.mechanics.WarMovementHandler;
import hu.openig.model.AIMode;
import hu.openig.model.AISpaceBattleManager;
import hu.openig.model.BattleEfficiencyModel;
import hu.openig.model.BattleGroundProjector;
Expand Down Expand Up @@ -1487,30 +1489,29 @@ void placeStations(Planet nearbyPlanet, boolean alien) {

// add shields
for (Building b : nearbyPlanet.surface.buildings.iterable()) {
double power = Math.abs(b.assignedEnergy * 1.0 / b.getEnergy());
if (power >= 0.5 && b.type.kind.equals("Shield")) {

double eff = power;

BattleGroundShield bge = world().battle.groundShields.get(b.type.id);
if (b.type.kind.equals("Shield")) {
double eff = Math.abs(b.assignedEnergy * 1.0 / b.getEnergy());
if (eff >= 0.5) {
BattleGroundShield bge = world().battle.groundShields.get(b.type.id);

SpacewarStructure st = new SpacewarStructure(b.type);
st.owner = nearbyPlanet.owner;
st.type = StructureType.SHIELD;
st.angles = new BufferedImage[] { alien ? bge.alternative : bge.normal };
st.trimmedHeight = bge.trimmedHeight;
st.trimmedWidth = bge.trimmedWidth;
st.infoImageName = bge.infoImageName;
st.hpMax = world().getHitpoints(b.type, nearbyPlanet.owner, true);
st.hp = (1d * b.hitpoints * st.hpMax / b.type.hitpoints);
st.value = b.type.cost;
st.destruction = bge.destruction;
st.building = b;
st.planet = nearbyPlanet;
SpacewarStructure st = new SpacewarStructure(b.type);
st.owner = nearbyPlanet.owner;
st.type = StructureType.SHIELD;
st.angles = new BufferedImage[] { alien ? bge.alternative : bge.normal };
st.trimmedHeight = bge.trimmedHeight;
st.trimmedWidth = bge.trimmedWidth;
st.infoImageName = bge.infoImageName;
st.hpMax = world().getHitpoints(b.type, nearbyPlanet.owner, true);
st.hp = (1d * b.hitpoints * st.hpMax / b.type.hitpoints);
st.value = b.type.cost;
st.destruction = bge.destruction;
st.building = b;
st.planet = nearbyPlanet;

shieldValue += eff * bge.shields;
shieldValue += eff * bge.shields;

structures.add(st);
structures.add(st);
}
}
}
for (SpacewarStructure sws : shields()) {
Expand Down Expand Up @@ -3714,6 +3715,25 @@ public boolean keyboard(KeyEvent e) {
e.consume();
return true;
}
// FIXME CHEAT
if (e.getKeyCode() == KeyEvent.VK_J) {
Player p = world().player;

if (p.aiMode == AIMode.NONE) {
p.aiMode = AIMode.TEST;
p.ai = new AITest();
p.ai.init(p);
System.out.println("Switching to TEST AI.");
} else {
p.aiMode = AIMode.NONE;
p.ai = new AIUser();
p.ai.init(p);
System.out.println("Switching to no AI.");
}
allPlayerSet.put(player(), p.ai.spaceBattle(this));
e.consume();
return true;
}
}
if (e.getKeyCode() == KeyEvent.VK_V && e.isControlDown() && e.isShiftDown()) {
showDebug = !showDebug;
Expand Down

0 comments on commit 0ccf488

Please sign in to comment.