📄 scenarioloader.java
字号:
Coords coords = new Coords(x,y); e.setPosition(coords); e.setDeployed(true); } catch (NoSuchElementException ex) { } return e; } catch (NumberFormatException e) { e.printStackTrace(); throw new Exception("Unparseable entity line: " + s); } catch (NoSuchElementException e) { e.printStackTrace(); throw new Exception("Unparseable entity line: " + s); } catch (EntityLoadingException e) { e.printStackTrace(); throw new Exception("Unparseable entity line: " + s + "\n Unable to load mech: " + e.getMessage()); } } private void parseAdvantages(Entity entity, String adv) { StringTokenizer st = new StringTokenizer(adv); while ( st.hasMoreTokens() ) { String curAdv = st.nextToken(); IOption option = entity.getCrew().getOptions().getOption(curAdv); if ( null == option ) { System.out.println("Ignoring invalid pilot advantage: " + curAdv); } else { System.out.println("Adding pilot advantage '" + curAdv + "' to " + entity.getDisplayName()); option.setValue(true); } } } private void parseAutoEject(Entity entity, String eject) { if (entity instanceof Mech) { Mech mech = (Mech)entity; mech.setAutoEject(Boolean.valueOf(eject).booleanValue()); } } private int findIndex(String[] sa, String s) { for (int x = 0; x < sa.length; x++) { if (sa[x].equalsIgnoreCase(s)) { return x; } } return -1; } private Player[] createPlayers(Properties p) throws Exception { String sFactions = p.getProperty("Factions"); if (sFactions == null) { throw new Exception("Not a valid MMS file. No Factions"); } StringTokenizer st = new StringTokenizer(sFactions, ","); Player[] out = new Player[st.countTokens()]; for (int x = 0; x < out.length; x++) { out[x] = new Player(x, st.nextToken()); // scenario players start out as ghosts to be logged into out[x].setGhost(true); // check for initial placement String s = p.getProperty("Location_" + out[x].getName()); // default to any if (s == null) { s = "Any"; } int nDir = findIndex(IStartingPositions.START_LOCATION_NAMES, s); // if it's not set by now, make it any if (nDir == -1) { nDir = 0; } out[x].setStartingPos(nDir); //Check for team setup int team = Player.TEAM_NONE; try { team = Integer.parseInt(p.getProperty("Team_" + out[x].getName())); } catch ( Exception e ) { team = Player.TEAM_NONE; } out[x].setTeam(team); String minefields = p.getProperty("Minefields_" + out[x].getName()); if (minefields != null) { try { StringTokenizer mfs = new StringTokenizer(minefields, ","); out[x].setNbrMFConventional(Integer.parseInt(mfs.nextToken())); out[x].setNbrMFCommand(Integer.parseInt(mfs.nextToken())); out[x].setNbrMFVibra(Integer.parseInt(mfs.nextToken())); } catch (Exception e) { out[x].setNbrMFConventional(0); out[x].setNbrMFCommand(0); out[x].setNbrMFVibra(0); System.err.println("Something wrong with " + out[x].getName() + "s minefields."); } } } return out; } /** * Load board files and create the megaboard. */ private IBoard createBoard(Properties p) throws Exception { int mapWidth = 16, mapHeight = 17; if (p.getProperty("MapWidth") == null) { System.out.println("No map width specified. Using "+mapWidth); } else { mapWidth = Integer.parseInt(p.getProperty("MapWidth")); } if (p.getProperty("MapHeight") == null) { System.out.println("No map height specified. Using "+mapHeight); } else { mapHeight = Integer.parseInt(p.getProperty("MapHeight")); } int nWidth = 1, nHeight = 1; if (p.getProperty("BoardWidth") == null) { System.out.println("No board width specified. Using "+nWidth); } else { nWidth = Integer.parseInt(p.getProperty("BoardWidth")); } if (p.getProperty("BoardHeight") == null) { System.out.println("No board height specified. Using "+nHeight); } else { nHeight = Integer.parseInt(p.getProperty("BoardHeight")); } System.out.println("Mapsheets are "+mapWidth+ " by " + mapHeight +" hexes."); System.out.println("Constructing " + nWidth + " by " + nHeight + " board."); // load available boards // basically copied from Server.java. Should get moved somewhere neutral Vector vBoards = new Vector(); File boardDir = new File("data/boards"); String[] fileList = boardDir.list(); for (int i = 0; i < fileList.length; i++) { if (fileList[i].endsWith(".board")) { vBoards.addElement(fileList[i].substring(0, fileList[i].lastIndexOf(".board"))); } } IBoard[] ba = new IBoard[nWidth * nHeight]; StringTokenizer st = new StringTokenizer(p.getProperty("Maps"), ","); for (int x = 0; x < nWidth; x++) { for (int y = 0; y < nHeight; y++) { int n = y * nWidth + x; String sBoard = "RANDOM"; if (st.hasMoreTokens()) { sBoard = st.nextToken(); } System.out.println("(" + x + "," + y + ")" + sBoard); boolean isRotated = false; if ( sBoard.startsWith( Board.BOARD_REQUEST_ROTATION ) ) { isRotated = true; sBoard = sBoard.substring ( Board.BOARD_REQUEST_ROTATION.length() ); } String sBoardFile; if (sBoard.equals("RANDOM")) { sBoardFile = (String)(vBoards.elementAt(Compute.randomInt(vBoards.size()))) + ".board"; } else { sBoardFile = sBoard + ".board"; } File fBoard = new File(boardDir, sBoardFile); if (!fBoard.exists()) { throw new Exception("Scenario requires nonexistant board: " + sBoard); } ba[n] = new Board(); ba[n].load(sBoardFile); BoardUtilities.flip(ba[n], isRotated, isRotated ); } } // if only one board just return it. if(ba.length == 1) return ba[0]; // construct the big board return BoardUtilities.combine(mapWidth, mapHeight, nWidth, nHeight, ba); } private Properties loadProperties() throws Exception { Properties props = new Properties(); FileInputStream fis = new FileInputStream(m_scenFile); props.load(fis); fis.close(); // Strip trailing spaces int loop; String key; StringBuffer value; Properties fixed = new Properties(); Enumeration keyIt = props.keys(); while (keyIt.hasMoreElements()) { key = (String) keyIt.nextElement(); value = new StringBuffer( props.getProperty(key) ); for (loop = value.length() - 1; loop >= 0; loop--) { if(!Character.isWhitespace( value.charAt( loop ) )) break; } value.setLength( loop + 1 ); fixed.setProperty( key, value.toString() ); } return fixed; } public static void main(String[] saArgs) throws Exception { ScenarioLoader sl = new ScenarioLoader(new File(saArgs[0])); IGame g = sl.createGame(); if(g != null) System.out.println("Successfully loaded."); } /* * This is used specify the critical hit location */ public class CritHit { public int loc; public int slot; public CritHit(int l,int s) { loc = l; slot = s; } } /* * * This class is used to store the critical hit plan for a entity * it is loaded from the scenario file. It contains a vector * of CritHit. * */ class CritHitPlan { public Entity entity; Vector critHits = new Vector(); public CritHitPlan(Entity e) { entity = e; } public void AddCritHit(String s) { int loc; int slot; //Get the pos of the ":" int ewSpot = s.indexOf(":"); loc = Integer.parseInt(s.substring(0,ewSpot)); slot = Integer.parseInt(s.substring(ewSpot+1)); critHits.addElement(new CritHit(loc,slot-1)); } } /* * This is used to store the ammour to change ammo at a given location */ public class SetAmmoTo { public int loc; public int slot; public int setAmmoTo; public SetAmmoTo(int Location,int Slot,int SetAmmoTo) { loc = Location; slot = Slot; setAmmoTo = SetAmmoTo; } } /* * * This class is used to store the ammo Adjustments * it is loaded from the scenario file. It contains a vector * of SetAmmoTo. * */ class SetAmmoPlan { public Entity entity; Vector ammoSetTo = new Vector(); public SetAmmoPlan(Entity e) { entity = e; } /* * Converts 2:1-34 to Location 2 Slot 1 set Ammo to 34 */ public void AddSetAmmoTo(String s) { int loc = 0; int slot = 0; int setTo = 0; //Get the pos of the ":" int ewSpot = s.indexOf(":"); int amSpot = s.indexOf("-"); loc = Integer.parseInt(s.substring(0,ewSpot)); slot = Integer.parseInt(s.substring(ewSpot+1,amSpot)); setTo = Integer.parseInt(s.substring(amSpot+1)); ammoSetTo.addElement(new SetAmmoTo(loc,slot,setTo)); } } /* * This is used specify the one damage location */ public class SpecDam { public int loc; public int setArmorTo; public boolean rear; public boolean internal; public SpecDam(int Location,int SetArmorTo,boolean RearHit,boolean Internal) { loc = Location; setArmorTo = SetArmorTo; rear = RearHit; internal = Internal; } } /* * * This class is used to store the dammage plan for a entity * it is loaded from the scenario file. It contains a vector * of SpecDam. * */ class DamagePlan { public Entity entity; public int nBlocks; Vector specificDammage = new Vector(); Vector ammoSetTo = new Vector(); public DamagePlan(Entity e, int n) { entity = e; nBlocks = n; } public DamagePlan(Entity e) { entity = e; nBlocks = 0; } /* * Converts N2:1 to Nornam hit to location 2 set armor to 1! */ public void AddSpecificDammage(String s) { int loc = 0; int setTo = 0; boolean rear = false; boolean internal = false; //Get the type of set to make if (s.substring(0,1).equals("R")) rear = true; if (s.substring(0,1).equals("I")) internal = true; //Get the pos of the ":" int ewSpot = s.indexOf(":"); //Get the Location this is the number starting at Character 2 in the string loc = Integer.parseInt(s.substring(1,ewSpot)); setTo = Integer.parseInt(s.substring(ewSpot+1)); specificDammage.addElement(new SpecDam(loc,setTo,rear,internal)); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -