1 package hughai; 2 3 import java.util.*; 4 import java.io.*; 5 6 import com.springrts.ai.*; 7 import com.springrts.ai.oo.*; 8 import com.springrts.ai.oo.clb.*; 9 10 import hughai.ui.MainUI; 11 import hughai.utils.*; 12 import hughai.utils.TimeHelper.TimeSpan; 13 import hughai.loader.*; 14 import hughai.loader.utils.*; 15 import hughai.test.*; 16 17 // Original intentions: Stores options from start script, pumps some into config 18 // 19 // Right, we could just have things get properties by strings, but that 20 // sounds... error-prone... so we could have a list of valid strings, 21 // or get them by reading one of the lua options files, or 22 // have a class and pump available options into that class/object 23 // but what if those values weren't specified in the incoming options? 24 // give them appropriate defaults? read from config? set them to null? 25 // let's make them classes for now, and have them default to null 26 // and: we'll need some higher level options abstraction to choose 27 // between the config values and the startscript values 28 // hmmm: we could make anything that is valid in the xml config file 29 // be a valid startscript option :-O 30 // then it is fairly easy to make a higher-level abstraction 31 // in the gui, we could just grey those out or something, signal 32 // somehow that they are being overridden 33 public class OptionsFromStartScript { 34 // public class Options { 35 // Integer difficultyLevel = null; 36 // Boolean debugOn = null; 37 // } 38 39 PlayerObjects playerObjects; 40 41 final HashMap<String,String> optionValues = new HashMap<String,String>(); 42 final HashMap<String,String> info = new HashMap<String,String>(); 43 getOptionKeys()44 public Collection<String> getOptionKeys() { 45 return optionValues.keySet(); 46 } 47 48 // returns null if option doesn't exist getOption( String optionName )49 public String getOption( String optionName ) { 50 return optionValues.get( optionName.toLowerCase() ); 51 } 52 53 // returns defaultValue if option doesn't exist getOption( String optionName, String defaultValue )54 public String getOption( String optionName, String defaultValue ) { 55 if( optionValues.containsKey( optionName.toLowerCase() ) ) { 56 return optionValues.get( optionName.toLowerCase() ); 57 } 58 return defaultValue; 59 } 60 OptionsFromStartScript( PlayerObjects playerObjects )61 public OptionsFromStartScript( PlayerObjects playerObjects ) { 62 this.playerObjects = playerObjects; 63 64 init(); 65 } 66 debug( Object message )67 void debug( Object message ) { 68 playerObjects.getLogFile().WriteLine( "" + this.getClass().getSimpleName() + ": " + message ); 69 } 70 init()71 void init() { 72 Info inf = playerObjects.getAicallback().getSkirmishAI().getInfo(); 73 int numInfo = inf.getSize(); 74 for (int i=0; i < numInfo; i++) { 75 String key = inf.getKey(i); 76 String value = inf.getValue(i); 77 debug( "infovalue: " + key + " = " + value ); 78 info.put(key, value); 79 } 80 81 OptionValues opVals = playerObjects.getAicallback().getSkirmishAI().getOptionValues(); 82 int numOpVals = opVals.getSize(); 83 for (int i=0; i < numOpVals; i++) { 84 String key = opVals.getKey(i); 85 String value = opVals.getValue(i); 86 debug( "optionvalue: " + key + " = " + value ); 87 optionValues.put(key, value); 88 } 89 } 90 } 91 92