import com.swath.*; import com.swath.cmd.*; /** * Zero Turn Map script for SWATH. Provides the ability to map an arbitrary * range of sectors, so the task of mapping can be divided among teammates. * Duplicates the Fold and Var algorithms from SWATH's built-in mapper, and * adds Dist Map, which is of dubious value... * * @author Mongoose <kjkrum@yahoo.com> * @version 20030324 */ public class ZTM extends UserDefinedScript { private static final String title = "ZTM"; private static final String error = "Script Error"; private static final int MODE_FOLD = 0; private static final int MODE_VAR = 1; private static final int MODE_DIST_MAP = 2; private Parameter startSectorP; private Parameter endSectorP; private Parameter baseSectorP; private Parameter modeP; /* static so they keep their value between runs */ private static int startSector; private static int endSector; private static int baseSector; private static int mode; public String getName() { return title; } public boolean initScript() throws Exception { /* check prompt */ int prompt = Swath.main.prompt(); if(!(prompt == Swath.COMMAND_PROMPT || prompt == Swath.COMPUTER_PROMPT || prompt == Swath.CITADEL_PROMPT)) { MessageBox.exec("You must be at the Command,\nComputer, or Citadel prompt.", error, MessageBox.ICON_ERROR, MessageBox.TYPE_OK); return false; } startSectorP = new Parameter("Start sector:"); startSectorP.setType(Parameter.INTEGER); if(startSector == 0) startSectorP.setInteger(1); else startSectorP.setInteger(startSector); endSectorP = new Parameter("End sector:"); endSectorP.setType(Parameter.INTEGER); if(endSector == 0) endSectorP.setInteger(Swath.main.sectors()); else endSectorP.setInteger(endSector); baseSectorP = new Parameter("Base sector (dist maps only):"); baseSectorP.setType(Parameter.INTEGER); if(baseSector == 0) baseSectorP.setInteger(Swath.main.stardock()); else baseSectorP.setInteger(baseSector); modeP = new Parameter("Map Type:"); modeP.setType(Parameter.CHOICE); modeP.addChoice(MODE_FOLD, "Fold (1->2, 2->1, ...)"); modeP.addChoice(MODE_VAR, "Var (1->5000, 2->4999, ...)"); modeP.addChoice(MODE_DIST_MAP, "Dist Map (base->all)"); modeP.setCurrentChoice(mode); registerParam(startSectorP); registerParam(endSectorP); registerParam(baseSectorP); registerParam(modeP); return true; } /* end initScript() */ public boolean runScript() throws Exception { startSector = startSectorP.getInteger(); endSector = endSectorP.getInteger(); baseSector = baseSectorP.getInteger(); mode = modeP.getCurrentChoice(); /* validate parameters */ int sectors = Swath.main.sectors(); if((startSector > sectors) || (startSector < 1) || (endSector > sectors) || (endSector < 1) || (startSector == endSector)) { MessageBox.exec("Invalid sector range.", error, MessageBox.ICON_ERROR, MessageBox.TYPE_OK); return false; } if(startSector > endSector) { /* swap values */ int tmp = startSector; startSector = endSector; endSector = tmp; } /* get to the computer prompt */ if(Swath.main.prompt() != Swath.COMPUTER_PROMPT) EnterComputer.exec(); /* do stuff */ switch(mode) { case MODE_FOLD: /* 1->2, 2->1, 3->4, etc. */ while(startSector < endSector) { PlotCourse.exec(startSector, startSector + 1); PlotCourse.exec(startSector + 1, startSector); startSector += 2; } break; case MODE_VAR: /* 1->5000, 2->4999, etc. */ while(startSector < endSector) { PlotCourse.exec(startSector, sectors - startSector + 1); ++startSector; } break; case MODE_DIST_MAP: /* optimized base sector->all sectors */ if(baseSector < 1 || baseSector > sectors) { MessageBox.exec("Invalid base sector for Dist Map.", error, MessageBox.ICON_ERROR, MessageBox.TYPE_OK); return false; } boolean[] mapped = new boolean[Swath.main.sectors()]; while(startSector <= endSector) { /* avoids plotting paths to sectors that were listed on a path to a more distant sector */ if(!mapped[startSector]) { int[] path = PlotCourse.exec(baseSector, startSector); for(int i = 0; i < path.length; ++i) mapped[path[i]] = true; } ++startSector; } break; } /* end switch */ /* reset to defaults after completion */ startSector = 1; endSector = sectors; return true; } /* end runScript() */ } /* end class ZTM */