/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.bindedobjects.gamecontent;
import transientlibs.objects.creatures.Person;
import transientlibs.objects.general.Node;
import transientlibs.tex.ReqList;
import transientlibs.tex.StringAnalyst;
import java.util.ArrayList;
import transientlibs.slick2d.util.Log;
import transientlibs.bindedobjects.core.Binding;
/**
*
* @author kibertoad
*/
public class PersonalName {
public String LName;
public static int currentGender = 0;
public static int currentNation = -1;
public static ArrayList<ArrayList<PersonalName>> femaleNames = new ArrayList<ArrayList<PersonalName>>();
public static ArrayList<ArrayList<PersonalName>> maleNames = new ArrayList<ArrayList<PersonalName>>();
public static ArrayList<PersonalName> globalMaleNames = new ArrayList<PersonalName>();
public static ArrayList<PersonalName> globalFemaleNames = new ArrayList<PersonalName>();
// public static Name lastName;
public PersonalName (String setString) {
LName = setString;
}
public static void loadNames (){
if (StringAnalyst.isFileExist("names.dat")) {
StringAnalyst reader = new StringAnalyst();
for (int x = 0 ; x<Nation.nations.size(); x++) {
femaleNames.add(new ArrayList<PersonalName>());
maleNames.add(new ArrayList<PersonalName>());
}
reader.openFile("names.dat");
currentNation = 0;
currentGender = Person.femaleGender;
while (!reader.eof) {
reader.readRow();
analyzeStringForNames (reader);
}
reader.closeFile();
}
}
public static void analyzeStringForNames (StringAnalyst analyst) {
analyzeStringForNames ("-NO-", analyst);
}
public static ArrayList<PersonalName> returnNameList (int forGender){
if (forGender == Person.femaleGender) {
return globalFemaleNames;
} else {
return globalMaleNames;
}
}
public static ArrayList<PersonalName> returnNameList (int forGender, int forNation){
if (forGender == Person.femaleGender)
{
//Log.info("Nation: "+forNation+", size "+femaleNames.get(forNation).size());
return femaleNames.get(forNation);}
else {return maleNames.get(forNation);}
}
public static void analyzeStringForNames (String getString, StringAnalyst analyst) {
if (!"-NO-".equals(getString)) {analyst.fullStr = getString;}
analyst.checkForAliases();
analyst.getNextString();
String nowStr = analyst.lastStr;
boolean withResult = false;
if (nowStr.equals("female")) {
currentGender = Person.femaleGender;
withResult = true;
}
if (nowStr.equals("male")) {
currentGender = Person.maleGender;
withResult = true;
}
if (nowStr.equals("nation")) {
currentNation = analyst.readBinding(Binding.nationBinding);
withResult = true;
}
if (nowStr.equals("name")) {
//if (currentGender == Person.femaleGender) {
//femaleNames.get(currentNation).add (new PersonalName (analyst.restOfRow()));
//Log.info ("Added new female name");} else
//{maleNames.get(currentNation).add (new PersonalName (analyst.restOfRow()));}
if (currentNation != -1){
returnNameList (currentGender, currentNation).add (new PersonalName (analyst.restOfRow()));
} else {
returnNameList (currentGender).add (new PersonalName (analyst.restOfRow()));
}
withResult = true;
}
if ((withResult == false) && (nowStr.length()>2) && (!nowStr.startsWith("//"))) {
Log.error("Unknown string: "+nowStr); }
}
}