Skip to content
This repository has been archived by the owner on Feb 20, 2022. It is now read-only.

Commit

Permalink
v1.5.1. Added governor options GUI (stock Swing version with bad look…
Browse files Browse the repository at this point in the history
… & feel)
  • Loading branch information
coder111111 committed Apr 17, 2020
1 parent 7063560 commit 64bc170
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 49 deletions.
39 changes: 14 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,49 +24,38 @@ amount of micromanagement needed drastically.

To run the mod:

* Download my distribution of ROTP-1.5.jar (large file) and run that instead of
* Download my distribution of ROTP-1.5.1.jar (large file) and run that instead of
original game.

or

* Download only the ROTP-1.5-governor.jar
* Download only the ROTP-1.5.1-governor.jar
* Place it in same directory that contains original Remnants.jar version Beta 1.4
* Run ROTP-1.5-governor.jar
* Run ROTP-1.5.1-governor.jar

To enable governor, use 'q' key on keyboard, or else click "Allocate Spending"
text in the planetary spending screen. Since version 1.5 Governor is on by default.
text in the planetary spending screen. Since version 1.5.1 Governor is on by default.

---

Additional features.

* This mod will transport population from planets that are full to planets that
* Since version 1.5 governor will be on by default on new colonies.

* Governor will transport population from planets that are full to planets that
are underpopulated. Population from planets with maximum population will be
transported. Only population that will grow back in 1 turn will be transported
(usually 1-2 pop). When choosing destination, target population and distance will
be taken into account. If you want to turn this off, add "-Dautotransport=false"
to Java command line like this:

java -Dautotransport=false -Xmx2560m -jar ROTP-1.5.jar arg1
or
java -Dautotransport=false -Xmx2560m -jar ROTP-1.5-governor.jar
be taken into account.

* This mod will build stargates on all planets when technology is available. If you
want to turn this off, add "-Dautogate=false" to Java command line.
* Governor will build stargates on Rich and Ultra Rich planets when technology is
available.

java -Dautogate=false -Xmx2560m -jar ROTP-1.5.jar arg1
or
java -Dautogate=false -Xmx2560m -jar ROTP-1.5-governor.jar

* Since version 1.5 governor will be on by default on new colonies. If you want to
turn this off, add "-Ddefaultgovernor=false" to Java command line.

java -Ddefaultgovernor=false -Xmx2560m -jar ROTP-1.5.jar arg1
or
java -Ddefaultgovernor=false -Xmx2560m -jar ROTP-1.5-governor.jar
GUI has now been added to control behaviour of the governor. Please click "Options"
next to "Allocate Spending" to go to governor options. Old system properties based
options are supported for now but will be dropped in future releases.

* You can add multiple "-Dxxx=yyy" options on command line. I will implement GUI at
some point to toggle these options...
Governor options should be saved in your save game file.

---

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.rayfowler</groupId>
<artifactId>ROTP</artifactId>
<version>1.5</version>
<version>1.5.1</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
5 changes: 5 additions & 0 deletions src/assembly/governor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<include>**/EmpireColonySpendingPane*.class</include>
<include>**/EmpireSystemPanel*.class</include>
<include>**/PlanetsUI*.class</include>
<include>**/GameSession*.class</include>
<include>**/GovernorOptions*.class</include>
<include>**/GovernorOptionsPanel*.class</include>
<include>**/Galaxy*.class</include>
<include>**/en/labels.txt</include>
</includes>
<outputDirectory>/</outputDirectory>
</fileSet>
Expand Down
2 changes: 1 addition & 1 deletion src/rotp/RotpGovernor.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* to get more memory it uses the right jar file name.
*/
public class RotpGovernor {
static String governorVersion = "1.5";
static String governorVersion = "1.5.1";
static String expectedROTPVersion = "Beta 1.5";

public static void main(String[] args) {
Expand Down
1 change: 1 addition & 0 deletions src/rotp/lang/en/labels.txt
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ MAIN_COLONY_INDUSTRY | Ind
MAIN_COLONY_ECOLOGY | Eco
MAIN_COLONY_TECHNOLOGY | Tech
MAIN_COLONY_ALLOCATE_SPENDING | Allocate Spending
GOVERNOR_OPTIONS | Options
MAIN_COLONY_SPENDING_NONE | None
MAIN_COLONY_SPENDING_RESERVE | Reserve
MAIN_COLONY_SPENDING_CONVERT | Convert
Expand Down
60 changes: 39 additions & 21 deletions src/rotp/model/colony/Colony.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import rotp.model.galaxy.ShipFleet;
import rotp.model.galaxy.StarSystem;
import rotp.model.galaxy.Transport;
import rotp.model.game.GameSession;
import rotp.model.game.GovernorOptions;
import rotp.model.incidents.ColonyCapturedIncident;
import rotp.model.incidents.ColonyInvadedIncident;
import rotp.model.planet.Planet;
Expand Down Expand Up @@ -1069,7 +1071,7 @@ public void destroy() {
}
}

private boolean governor = !"false".equalsIgnoreCase(System.getProperty("defaultgovernor", "true"));
private boolean governor = GameSession.instance().getGovernorOptions().isGovernorOnByDefault();

public boolean isGovernor() {
return governor;
Expand Down Expand Up @@ -1123,7 +1125,7 @@ public void governIfNeeded() {
*
*/
public void govern() {
if (!"false".equalsIgnoreCase(System.getProperty("autotransport"))) {
if (session().getGovernorOptions().isAutotransport()) {
autotransport();
}
// unlock all sliders
Expand Down Expand Up @@ -1153,25 +1155,9 @@ public void govern() {
if (!defense().isCompleted()) {
moveSlider(Colony.DEFENSE, null, "Reserve");
}

// Build gate if tech is available. Also add a system property to turn it off.
if (!"false".equalsIgnoreCase(System.getProperty("autogate"))) {
if (this.shipyard().canBuildStargate()) {
Design first = this.shipyard().design();
Design current = this.shipyard().design();
while (!this.empire.shipLab().stargateDesign().equals(current)) {
this.shipyard().goToNextDesign();
current = this.shipyard().design();
if (current.equals(first)) {
System.out.println("unable to cycle to Shargate design");
break;
}
}
if (this.empire.shipLab().stargateDesign().equals(current)) {
locked(Colony.SHIP, false);
moveSlider(Colony.SHIP, null, "Reserve");
}
}
}
buildStargate();

// if all sliders are set to 0, increase research.
boolean noSpending = true;
Expand Down Expand Up @@ -1278,8 +1264,40 @@ private void autotransport() {
scheduleTransportsToSystem(targets.get(0), toTransport);
governor = true;
}
public int incomingTransportsNextTurn() {
private int incomingTransportsNextTurn() {
return galaxy().friendlyPopApproachingSystemNextTurn(starSystem());
}

private void buildStargate() {
if (!this.shipyard().canBuildStargate()) {
return;
}
if (session().getGovernorOptions().getGates() == GovernorOptions.GatesGovernor.None) {
return;
}
if (session().getGovernorOptions().getGates() == GovernorOptions.GatesGovernor.Rich) {
if (!planet().isResourceRich() && !planet.isResourceUltraRich()) {
return;
}
}
// don't build gate if planet production is below 300
// Not sure about this one, now that maintenance is taken from global pool
// if (production() < 300) {
// return;
// }
Design first = this.shipyard().design();
Design current = this.shipyard().design();
while (!this.empire.shipLab().stargateDesign().equals(current)) {
this.shipyard().goToNextDesign();
current = this.shipyard().design();
if (current.equals(first)) {
System.out.println("unable to cycle to Shargate design");
break;
}
}
if (this.empire.shipLab().stargateDesign().equals(current)) {
locked(Colony.SHIP, false);
moveSlider(Colony.SHIP, null, "Reserve");
}
}
}
10 changes: 10 additions & 0 deletions src/rotp/model/game/GameSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -791,4 +791,14 @@ static ThreadFactory minThreadFactory() {
return t;
};
}

private GovernorOptions governorOptions = new GovernorOptions();

public GovernorOptions getGovernorOptions() {
// can happen on deserialized stock save game
if (governorOptions == null) {
governorOptions = new GovernorOptions();
}
return governorOptions;
}
}
45 changes: 45 additions & 0 deletions src/rotp/model/game/GovernorOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package rotp.model.game;

import java.io.Serializable;

/**
* Governor options.
*/
public class GovernorOptions implements Serializable {
public enum GatesGovernor {
None,
Rich,
All
}
// keep backwards compatibility with system properties
private boolean governorOnByDefault = !"false".equalsIgnoreCase(System.getProperty("defaultgovernor", "true"));;
private boolean autotransport = !"false".equalsIgnoreCase(System.getProperty("autotransport", "true"));
private GatesGovernor gates = "false".equalsIgnoreCase(System.getProperty("autogate", "true")) ? GatesGovernor.None : GatesGovernor.Rich;

public GovernorOptions() {
}

public boolean isGovernorOnByDefault() {
return governorOnByDefault;
}

public boolean isAutotransport() {
return autotransport;
}

public GatesGovernor getGates() {
return gates;
}

public void setGovernorOnByDefault(boolean governorOnByDefault) {
this.governorOnByDefault = governorOnByDefault;
}

public void setAutotransport(boolean autotransport) {
this.autotransport = autotransport;
}

public void setGates(GatesGovernor gates) {
this.gates = gates;
}
}
33 changes: 32 additions & 1 deletion src/rotp/ui/main/EmpireColonySpendingPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import rotp.ui.BasePanel;
import rotp.ui.SystemViewer;

import javax.swing.*;

public class EmpireColonySpendingPane extends BasePanel {
private static final long serialVersionUID = 1L;
static final Color sliderHighlightColor = new Color(255,255,255);
Expand Down Expand Up @@ -183,6 +185,9 @@ public void paintComponent(Graphics g0) {
String titleText = text("MAIN_COLONY_ALLOCATE_SPENDING");
int titleY = getHeight() - s6;
drawShadowedString(g, titleText, 2, s5, titleY, color, textC);

String governorOptionsText = text("GOVERNOR_OPTIONS");
drawShadowedString(g, governorOptionsText, 2, w-s60, titleY, MainUI.shadeBorderC(), textC);
return;
}
String text = text(Colony.categoryName(category));
Expand Down Expand Up @@ -362,7 +367,11 @@ else if (rightArrow.contains(x,y))
increment(true);
else {
if (this.category < 0) {
toggleGovernor();
if (x < EmpireColonySpendingPane.this.getWidth() - s60) {
toggleGovernor();
} else {
governorOptions();
}
}
float pct = pctBoxSelected(x,y);
if (pct >= 0) {
Expand Down Expand Up @@ -425,6 +434,28 @@ public float pctBoxSelected(int x, int y) {
return num/den;
}
}

JFrame governorOptionsFrame = null;
private void governorOptions() {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (governorOptionsFrame == null) {
governorOptionsFrame = new JFrame("GovernorOptions");
governorOptionsFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

//Create and set up the content pane.
GovernorOptionsPanel newContentPane = new GovernorOptionsPanel(governorOptionsFrame);
newContentPane.getPanel().setOpaque(true); //content panes must be opaque
governorOptionsFrame.setContentPane(newContentPane.getPanel());
}
//Display the window.
governorOptionsFrame.pack();
governorOptionsFrame.setVisible(true);

}
});
}

private void toggleGovernor() {
if (parent.systemViewToDisplay() != null && parent.systemViewToDisplay().colony() != null) {
Colony colony = parent.systemViewToDisplay().colony();
Expand Down
Loading

0 comments on commit 64bc170

Please sign in to comment.