package prc.utils;
import prc.autodoc.*;
import java.io.File;
import java.io.FileWriter;
import static prc.Main.verbose;
public final class ItempropMaker {
private ItempropMaker() {
}
private static Data_2da itempropdef2da;
private static Data_2da costtable2da;
private static Data_2da paramtable2da;
private static Data_2da[] cost2daarray;
private static Data_2da[] param12daarray;
private static StringBuilder xml;
public static void main(String[] args) throws Exception {
//load the 2das
itempropdef2da = Data_2da.load2da("2das" + File.separator + "itempropdef.2da", true);
costtable2da = Data_2da.load2da("2das" + File.separator + "iprp_costtable.2da", true);
paramtable2da = Data_2da.load2da("2das" + File.separator + "iprp_paramtable.2da", true);
cost2daarray = new Data_2da[costtable2da.getEntryCount()];
param12daarray = new Data_2da[paramtable2da.getEntryCount()];
for (int i = 0; i < cost2daarray.length; i++) {
cost2daarray[i] = Data_2da.load2da("2das" + File.separator + costtable2da.getBiowareEntry("Name", i) + ".2da", true);
}
for (int i = 0; i < param12daarray.length; i++) {
param12daarray[i] = Data_2da.load2da("2das" + File.separator + paramtable2da.getBiowareEntry("TableResRef", i) + ".2da", true);
}
//loop over each row
for (int itempropdef2darow = 85;
itempropdef2darow < itempropdef2da.getEntryCount();
itempropdef2darow++) {
if (itempropdef2da.getBiowareEntryAsInt("Name", itempropdef2darow) != 0) {
int type = itempropdef2darow;
int subtype;
int cost;
int param1;
if (itempropdef2da.getBiowareEntry("SubTypeResRef", type) == "")
subtype = 0;
else
subtype = 1;
if (itempropdef2da.getBiowareEntryAsInt("CostTableResRef", type) == 0)
cost = 0;
else
cost = 1;
if (itempropdef2da.getBiowareEntry("Param1ResRef", type) == "")
param1 = 0;
else
param1 = 1;
//loop over each subtype
if (subtype != 0) {
Data_2da subtype2da = Data_2da.load2da("2das" + File.separator + itempropdef2da.getBiowareEntry("SubTypeResRef", type) + ".2da", true);
for (int subtypeID = 0; subtypeID < subtype2da.getEntryCount(); subtypeID++) {
//loop over the param1s, if applicable
//look if there is a column for it
boolean subtypeparam1columnexists = false;
String[] columnlabels = subtype2da.getLabels();
for (int i = 0; i < columnlabels.length; i++) {
if (columnlabels[i] == "Param1ResRef")
subtypeparam1columnexists = true;
}
if (subtypeparam1columnexists
&& subtype2da.getBiowareEntry("Param1ResRef", subtypeID) == "") {
param1 = 1;
} else {
if (itempropdef2da.getBiowareEntry("Param1ResRef", type) == "")
param1 = 0;
else
param1 = 2;
}
if (param1 != 0) {
int param1tableid = 0;
if (param1 == 2)
param1tableid = itempropdef2da.getBiowareEntryAsInt("Param1ResRef", type);
else if (param1 == 1)
param1tableid = subtype2da.getBiowareEntryAsInt("Param1ResRef", subtypeID);
Data_2da param12da = param12daarray[param1tableid];
for (int param1ID = 0; param1ID < param12da.getEntryCount(); param1ID++) {
if (cost != 0) {
int costtable = itempropdef2da.getBiowareEntryAsInt("CostTableResRef", type);
Data_2da cost2da = cost2daarray[costtable];
//has type, subtype, param1, and cost
write(type, subtypeID, param1tableid, param1ID, costtable, cost2da.getEntryCount());
} else {
//no cost
//has type, subtype, and param1
write(type, subtypeID, param1tableid, param1ID, -1, -1);
}
}
} else {
//no param1
if (cost != 0) {
int costtable = itempropdef2da.getBiowareEntryAsInt("CostTableResRef", type);
Data_2da cost2da = cost2daarray[costtable];
//has type, subtype, and cost
write(type, subtypeID, -1, -1, costtable, cost2da.getEntryCount());
} else {
//no cost
//has type, and subtype
write(type, subtypeID, -1, -1, -1, -1);
}
}
}
} else {
//no subtype
if (param1 != 0) {
int param1tableid = itempropdef2da.getBiowareEntryAsInt("Param1ResRef", type);
Data_2da param12da = param12daarray[param1tableid];
for (int param1ID = 0; param1ID < param12da.getEntryCount(); param1ID++) {
if (cost != 0) {
int costtable = itempropdef2da.getBiowareEntryAsInt("CostTableResRef", type);
Data_2da cost2da = cost2daarray[costtable];
//has type, param1, and cost
write(type, -1, param1tableid, param1ID, costtable, cost2da.getEntryCount());
} else {
//no cost
//has type, and param1
write(type, -1, param1tableid, param1ID, -1, -1);
}
}
} else {
//no param1
if (cost != 0) {
int costtable = itempropdef2da.getBiowareEntryAsInt("CostTableResRef", type);
Data_2da cost2da = cost2daarray[costtable];
//has type, and cost
write(type, -1, -1, -1, costtable, cost2da.getEntryCount());
} else {
//no cost
//has type
write(type, -1, -1, -1, -1, -1);
}
}
}
}
}
}
/*
-
-
-
-
*/
private static void write(int type, int subtype, int param1table, int param1value, int costtable,
int costmax) throws Exception {
xml = new StringBuilder(0xFFFFF);
//assemble the resref/tag
String resref = "prc_ip" + type;
if (subtype != -1)
resref += "_" + subtype;
if (param1value != -1)
resref += "_" + param1value;
//sanity checks
if (param1value == -1)
param1value = 0;
if (param1table == -1)
param1table = 255;
if (subtype == -1)
subtype = 0;
if (costtable == -1)
costtable = 0;
if (costmax == -1)
costmax = 0;
//output stuff
//header things first
xml.append("\n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
//loop over the itemproperties
for (int i = 0; i < costmax; i++) {
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
}
//footer stuff
xml.append(" \n");
//this is set to 99 so it will not appear in the palette :)
xml.append(" \n");
xml.append(" \n");
xml.append(" \n");
xml.append("");
File target = new File("xml_temp" + File.separator + resref + ".uti.xml");
// Clean up old version if necessary
if (target.exists()) {
if (verbose) System.out.println("Deleting previous version of " + target.getName());
target.delete();
}
if (verbose) System.out.println("Writing brand new version of " + target.getName());
target.createNewFile();
// Creater the writer and print
FileWriter writer = new FileWriter(target, true);
writer.write(xml.toString());
// Clean up
writer.flush();
writer.close();
// Force garbage collection
System.gc();
}
}