Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions MekWarsClient/resources/mekwars/guiClient.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
errors.noOpList.text=No OpList. This usually means that you were unable to connect to the server to fetch a copy. Do you wish to exit?
errors.badConfigDir.text=Unable to set the configuration directory, please check the application can create the directory '{0}'
errors.header.text=Startup Error!
options.exit.text=Exit
options.continue.text=Continue
7 changes: 7 additions & 0 deletions MekWarsClient/src/mekwars/client/GUIClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
Expand Down Expand Up @@ -57,10 +58,12 @@ public class GUIClient {
private GUIClientConfig config;
private CMainFrame mainFrame;
private Locale locale = Locale.US;
private ResourceBundle resourceMap;

public GUIClient(MWClient mwClient, GUIClientConfig config) {
this.mwClient = mwClient;
this.config = config;
this.resourceMap = ResourceBundle.getBundle("mekwars.guiClient", locale);
}

public void init() {
Expand Down Expand Up @@ -98,6 +101,10 @@ public Locale getLocale() {
return locale;
}

public String getResourceString(String string) {
return resourceMap.getString(string);
}

/*
* Rewritten in order to allow ConfigPage to reset the skin on the fly.
*
Expand Down
105 changes: 27 additions & 78 deletions MekWarsClient/src/mekwars/client/MWClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.MessageDigest;
import java.text.MessageFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -1271,24 +1272,38 @@ public void setLastPing(long lastping) {
LastPing = lastping;
}

/*
/**
* Connect the DataFetcher to the server and get all relevent information from it.
*/
public void connectDataFetcher() {
try {
FileSystem.getInstance().setConfigDir(Config);
dataFetcher = new DataFetchClient(Integer.parseInt(Config
.getParam("DATAPORT")), Integer.parseInt(Config
.getParam("SOCKETTIMEOUTDELAY")));
} catch (IOException exception) {
LOGGER.error("Unable to set config directory", exception);
JOptionPane.showMessageDialog(
null,
MessageFormat.format(
guiClient.getResourceString("errors.badConfigDir.text"),
Config
),
guiClient.getResourceString("errors.header.text"),
JOptionPane.ERROR_MESSAGE
);
System.exit(0);
}
dataFetcher = new DataFetchClient(Integer.parseInt(Config
.getParam("DATAPORT")), Integer.parseInt(Config
.getParam("SOCKETTIMEOUTDELAY")));

try {
BufferedReader dis = new BufferedReader(new InputStreamReader(
new FileInputStream(FileSystem.getInstance().getDataLastUpdated().toString()
)));
Date lastTS = new Date(Long.parseLong(dis.readLine()));
dataFetcher.setLastTimestamp(lastTS);
dis.close();
} catch (Exception exception) {
LOGGER.error("Couldn't read timestamp of last datafetch. Will need to fetch all planetchanges since last full update.", exception);
LOGGER.warn("Couldn't read timestamp of last datafetch. Will need to fetch all planetchanges since last full update.", exception);
}
// Start the data fetcher, get ops/map/etc

Expand All @@ -1302,13 +1317,15 @@ public void connectDataFetcher() {
try {
dataFetcher.checkForMostRecentOpList();
} catch (IOException e) {
Object[] options = { "Exit", "Continue" };
Object[] options = {
guiClient.getResourceString("options.exit.text"),
guiClient.getResourceString("options.continue.text"),
};
int selectedValue = JOptionPane
.showOptionDialog(
null,
"No OpList. This usually means that you were unable to "
+ "connect to the server to fetch a copy. Do you wish to exit?",
"Startup " + "error!",
guiClient.getResourceString("errors.header.text"),
guiClient.getResourceString("errors.noOpList.text"),
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE, null, options,
options[0]);
Expand Down Expand Up @@ -2825,7 +2842,6 @@ public int getMinPlanetOwnerShip(Planet p) {
}

public int getTotalRepairCosts(Entity unit) {

int cost = 0;
int systemCrits = 0;
int engineCrits = 0;
Expand Down Expand Up @@ -2918,76 +2934,10 @@ public void setServerOpFlags(StringTokenizer st) {
}

public int getTechLaborCosts(Entity unit, int techType) {
int cost = 0;
int techCost = Integer.parseInt(getServerConfigs(UnitUtils
.techDescription(techType) + "TechRepairCost"));
int totalCrits = 0;
boolean damagedEngine = false;

for (int critLocation = 0; critLocation < unit.locations(); critLocation++) {
// These three location have rear armor so the user might be
// selecting that armor instead of crit.
if ((critLocation == Mech.LOC_CT) || (critLocation == Mech.LOC_LT)
|| (critLocation == Mech.LOC_RT)) {
if (unit.getArmor(critLocation, false) != unit.getOArmor(
critLocation, false)) {
cost += techCost;
}
if (unit.getArmor(critLocation, true) != unit.getOArmor(
critLocation, true)) {
cost += techCost;
}
if (unit.getInternal(critLocation) != unit
.getOInternal(critLocation)) {
cost += techCost;
}
}// end toros armor
else {
if (unit.getArmor(critLocation, false) != unit.getOArmor(
critLocation, false)) {
cost += techCost;
}
if (unit.getInternal(critLocation) != unit
.getOInternal(critLocation)) {
cost += techCost;
}
}// end armor

// check for damage system crits.
for (int critSlot = 0; critSlot < unit
.getNumberOfCriticals(critLocation); critSlot++) {

CriticalSlot cs = unit.getCritical(critLocation, critSlot);

if (cs == null) {
continue;
}

if (cs.isBreached()) {
continue;
}

if (!cs.isDamaged()) {
continue;
}

if (UnitUtils.isEngineCrit(cs)) {
damagedEngine = true;
continue;
}
totalCrits++;

}// end slot for
}// end location for

// check for damaged engines
if (damagedEngine) {
totalCrits = +UnitUtils.getNumberOfEngineCrits(unit);
}

cost += (techCost * totalCrits) + techCost;

return cost;
return UnitUtils.getTechLaborCosts(unit, techCost);
}

public void retrieveOpData(String type, String data) {
Expand Down Expand Up @@ -3092,7 +3042,6 @@ public HashMap<String, Equipment> getBlackMarketEquipmentList() {
}

public void updatePartsBlackMarket(String data, int year) {

StringTokenizer ST = new StringTokenizer(data, "#");
boolean allowTechCrossOver = Boolean.parseBoolean(this
.getServerConfigs("AllowCrossOverTech"));
Expand Down
6 changes: 0 additions & 6 deletions MekWarsClient/src/mekwars/client/campaign/CCampaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ public class CCampaign {
public CCampaign(MWClient client) {
mwclient = client;
Player = new CPlayer(mwclient);
File f = new File(MWClient.CAMPAIGN_PATH);
if (f.exists() && !f.isDirectory()) {f.delete();}
if (!f.exists()) {
try {f.mkdirs();}
catch (Exception e) {LOGGER.error("Exception: ", e);}
}
}

public boolean decodeCommand(String command) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public abstract class GameHost implements GameListener, IGameHost {
public static final int STATUS_FIGHTING = 4;

public static final String CAMPAIGN_PREFIX = "/"; // prefix for campaign commands
public static final String CAMPAIGN_PATH = "data/campaign/";
public static final String COMMAND_DELIMITER = "|"; // delimiter for client commands

public String myUsername = "";// public b/c used in RGTS command to set server status. HACK!
Expand Down
18 changes: 12 additions & 6 deletions MekWarsClient/src/mekwars/client/io/FileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

package mekwars.client.io;

import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import mekwars.common.campaign.clientutils.IClientConfig;
import mekwars.common.io.AbstractFileSystem;
Expand All @@ -30,8 +32,6 @@ public class FileSystem extends AbstractFileSystem {
.getPath(DIRECTORY_NAME_SERVERS);

public static final String FILE_NAME_DATA_LAST_UPDATED = "dataLastUpdated.dat";
private static final Path FILE_DATA_LAST_UPDATED = FileSystems.getDefault()
.getPath(FILE_NAME_DATA_LAST_UPDATED);

private static final Path[] DIRECTORIES = new Path[] {
DIRECTORY_DATA,
Expand All @@ -57,8 +57,11 @@ public Path getDataLastUpdated() {
/**
* Sets the config directory to configDir.
*/
public void setConfigDir(String configDir) {
this.configDir = FileSystems.getDefault().getPath(configDir);
public void setConfigDir(String configDir) throws IOException {
Path configPath = FileSystems.getDefault().getPath(configDir);

this.configDir = configPath;
Files.createDirectories(configPath);
}

/**
Expand All @@ -70,7 +73,7 @@ public void setConfigDir(String configDir) {
* @throws IllegalArgumentException When config does not have the SERVERIP or SERVERPORT config
* values
*/
public void setConfigDir(IClientConfig config) throws Exception {
public void setConfigDir(IClientConfig config) throws IOException {
String serverIp = config.getParam("SERVERIP");
String serverPort = config.getParam("SERVERPORT");

Expand All @@ -82,7 +85,10 @@ public void setConfigDir(IClientConfig config) throws Exception {
}

String configDirName = DIRECTORY_NAME_SERVERS + serverIp + "." + serverPort;
this.configDir = FileSystems.getDefault().getPath(configDirName);
Path configPath = FileSystems.getDefault().getPath(configDirName);

this.configDir = configPath;
Files.createDirectories(configPath);
calculateChecksums();
}

Expand Down
70 changes: 70 additions & 0 deletions MekWarsCommon/src/mekwars/common/util/UnitUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2744,4 +2744,74 @@ public static boolean isInnerSphereOnlyAmmo(EnumSet<Munitions> munitionType) {
);
return innersphereMunitions.containsAll(munitionType);
}

public static int getTechLaborCosts(Entity unit, int techCost) {
int cost = 0;
int totalCrits = 0;
boolean damagedEngine = false;

for (int critLocation = 0; critLocation < unit.locations(); critLocation++) {
// These three location have rear armor so the user might be
// selecting that armor instead of crit.
if ((critLocation == Mech.LOC_CT) || (critLocation == Mech.LOC_LT)
|| (critLocation == Mech.LOC_RT)) {
if (unit.getArmor(critLocation, false) != unit.getOArmor(
critLocation, false)) {
cost += techCost;
}
if (unit.getArmor(critLocation, true) != unit.getOArmor(
critLocation, true)) {
cost += techCost;
}
if (unit.getInternal(critLocation) != unit
.getOInternal(critLocation)) {
cost += techCost;
}
} else {
if (unit.getArmor(critLocation, false) != unit.getOArmor(
critLocation, false)) {
cost += techCost;
}
if (unit.getInternal(critLocation) != unit
.getOInternal(critLocation)) {
cost += techCost;
}
}

// check for damage system crits.
for (int critSlot = 0; critSlot < unit
.getNumberOfCriticals(critLocation); critSlot++) {

CriticalSlot cs = unit.getCritical(critLocation, critSlot);

if (cs == null) {
continue;
}

if (cs.isBreached()) {
continue;
}

if (!cs.isDamaged()) {
continue;
}

if (UnitUtils.isEngineCrit(cs)) {
damagedEngine = true;
continue;
}
totalCrits++;

}// end slot for
}// end location for

// check for damaged engines
if (damagedEngine) {
totalCrits = +UnitUtils.getNumberOfEngineCrits(unit);
}

cost += (techCost * totalCrits) + techCost;

return cost;
}
}