import java.io.*; class Settlers{ static final double[] UP = {0,1}; static final double[] DOWN = {0,-1}; static final double[] LEFT = {-1,0}; static final double[] RIGHT = {1,0}; static final double[] DOWNRIGHT = {Math.sqrt(2)/2,-Math.sqrt(2)/2}; static final double[] DOWNLEFT = {-0.8,-1}; static final double SQRT3 = Math.sqrt(3); static final double SIN60 = Math.sin(Math.toRadians(60)); static final double COS60 = Math.cos(Math.toRadians(60)); // static final int UNIT = 64; // static final int HEXSIZE = 10 * UNIT; static final int DIMENSION = 4; //number of hexes to a side static int HEXSIZE; static double[] CENTER; static final int[][] ROUNDTILES = { {5, 4}, {2, 1}, {6, 5}, {3, 2}, {8, 5}, {10,3}, {9, 4}, {12,1}, {11,2}, {4, 3}, {8, 5}, {10,3}, {9, 4}, {4, 3}, {5, 4}, {6, 5}, {3, 2}, {11,2} }; //the terrains associated with each index static final String[] TERRAIN_NAMES = {"3:1","Brick","oRe","Sheep","Lumber","wHeat"}; static final String[] TERRAIN_LETTERS = {"","B","R","S","L","H"}; //the number of occurences of each terrain type static final int[] TERRAIN = {1,3,3,4,4,4}; //the number of occurences of each port type static final int[] PORT = {4,1,1,1,1,1}; //[TERRAIN type][circleTile number] static int[][] hexes = new int[19][2]; //[port type] static int[][] ocean = new int[18][2]; static FileWriter fw; public static void main(String[] args){ if(args.length < 1){ System.err.println("usage: java Settlers output_file"); System.exit(0); } String SZ = "1.2"; HEXSIZE = (int)((Double.parseDouble(SZ)*400) /((2*DIMENSION-1)*1.5+.5)); CENTER=centerOfBoard(); fw = initOutputFile(args[0]); assignHexes(); try{ printDefs(); drawHexes(); drawInstructions(); closeOutputFile(fw); } catch(IOException e) { System.err.println("IOException"); System.exit(0); } } static void assignHexes(){ int rand=-1; for(int i=0; i -1 ) rand = (int)Math.floor( hexes.length * Math.random() ); //set that hex to TERRAIN i hexes[rand][0] = i; } } //assign pointers to circleTiles int tmp=0; for(int i=0; i0) hexes[i][1]=tmp++; } //assign ports to ocean hexes rand=-1; for(int i=0; i -1 ) rand = cointoss + 2*(int)Math.floor(0.5*ocean.length*Math.random()); //set that oceanhex to port i ocean[rand][1] = i; } } } static FileWriter initOutputFile(String s) { try{ FileWriter ret = new FileWriter(new File(s)); //ret.write("IN;IW0,0,17280,11160;SP1;"); return ret; } catch(IOException e){ System.exit(0); } return null; } static void closeOutputFile( FileWriter fw ){ try{ fw.write("showpage\n"); fw.close(); } catch(IOException e){ System.exit(0); } } static void drawHexes() throws IOException{ double[] origin = new double[2]; double[] pos = new double[2]; origin[0] = HEXSIZE; origin[1] = (((double)DIMENSION)/2.0) * HEXSIZE*SQRT3; double[] direction = {Math.cos(-Math.PI/6),Math.sin(-Math.PI/6)}; //unit vector pos[0] = origin[0]; pos[1] = origin[1]; //hex labeling int hexPointer = 0; int edgePointer; int edgeSize = DIMENSION; pos[0]=origin[0]; pos[1]=origin[1]; while(edgeSize > 1){ edgeSize--; for(int i=0; i<6; i++){ edgePointer = 0; while(edgePointer < edgeSize){ paint(pos,hexPointer); //move along edge displace(pos,direction,SQRT3*HEXSIZE); edgePointer++; hexPointer++; } //if sixth edge then go back one if(i==5) displace(pos,direction,-SQRT3*HEXSIZE); //turn rotate60(direction); //if sixth edge then go forward one if(i==5) displace(pos,direction,SQRT3*HEXSIZE); } } //now the center one paint(pos, hexPointer); } static double[] centerOfBoard(){ double[] ret = new double[2]; ret[0]= HEXSIZE*( 1.5*DIMENSION - 0.5); ret[1]= SQRT3*HEXSIZE * (DIMENSION - 0.5); return ret; } static double[][] sixCorners(double[] pos){ double[][] ret = new double[6][2]; for (int i=0; i< 6; i++){ ret[i][0]=pos[0]+HEXSIZE*Math.cos((Math.PI*i)/3.0); ret[i][1]=pos[1]+HEXSIZE*Math.sin((Math.PI*i)/3.0); } return ret; } static double distance(double[] p1, double[] p2){ return Math.sqrt(Math.pow(p2[1]-p1[1],2) + Math.pow(p2[0]-p1[0],2)); } static int[] findPorts(double[][] corners){ double d; int[] ret = new int[2]; double[] best = new double[2];// = {0,distance(corners[0],CENTER)}; for(int i=0; i<2; i++){ best[1]=0; for(int j=0; j<6; j++){ d=distance(corners[j],CENTER); //System.out.println("i="+i+",j="+j+"d="+d+"b[0]="+best[0]); if(best[1]==0 || d=0){ int[] hex = dereference(hexPointer); double iconSize = HEXSIZE; // case on port type switch(hex[1]){ case 1: drawBrick(pos,iconSize); break; case 2: drawOre(pos,iconSize); break; case 3: drawSheep(pos,iconSize); break; case 4: drawLumber(pos,iconSize); break; case 5: drawWheat(pos,iconSize); break; default: /* Port */ ///drawCircle(pos,0.7*HEXSIZE); movePen(newD(pos,LEFT,HEXSIZE*.2)); label( TERRAIN_NAMES[dereference(hexPointer)[1]] ); break; } double[][] corners = sixCorners(pos); int[] ports = findPorts( corners ); drawCircle( corners[ports[0]], HEXSIZE/8); drawCircle( corners[ports[1]], HEXSIZE/8); } } // else a resource (non-ocean) tile else if (hexPointer>=ocean.length){ //if not desert, ie if land if(dereference(hexPointer)[1]>-1){ //offset movePen(newD(pos,LEFT,HEXSIZE*.6)); //label terrain double[] iconPos = newD(pos,RIGHT,HEXSIZE/4); int[] hex = dereference(hexPointer); double iconSize = Math.sqrt(ROUNDTILES[hex[1]][1])*HEXSIZE/4; final double[][] resourceColors = { {1,1,1}, {1,0.7,0.7}, {0.8,0.8,0.8}, {0.7,1,0.7}, {0.5,0.9,0.2}, {1,1,0.7} }; drawHex(pos,HEXSIZE,resourceColors[hex[0]]); // label roundtiles movePen(newD(pos,LEFT,HEXSIZE*.6)); label(ROUNDTILES[dereference(hexPointer)[1]][0]); movePen(newD(pos,DOWNLEFT,HEXSIZE*.6)); for(int i=0; i