<%@ page contentType="application/xhtml+xml" %> <%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page import="java.awt.Point" %> <%! public String loadFile(String fname) { // String path = "c:\\apache-tomcat-6.0.29\\webapps\\examples\\jsp\\svgs\\"; String path = "/home/inkwe0/public_html/roleplaying_tools/random_village/svgs/"; StringBuilder vill1 = new StringBuilder(); FileReader vill1fr = null; try { vill1fr = new FileReader(path+fname); BufferedReader vill1br = new BufferedReader(vill1fr); String s; while((s = vill1br.readLine())!=null) { vill1.append(s).append("\n"); } } catch(Exception e) { vill1 = new StringBuilder("Exception while reading "+fname); } try { if(vill1fr!=null) vill1fr.close(); } catch (Exception e) {} return vill1.toString(); } %> <%! public String getParamString(String pname, HttpServletRequest request) { String pstr = request.getParameter(pname); if(pstr!=null) { return pstr.trim(); } return ""; } public int getParam(String pstr) { if(pstr!=null) { pstr = pstr.trim(); if(pstr!="") { try { int temp = Integer.parseInt(pstr); if(temp>=0) return temp; } catch(Exception e) {}; } } return -1; } %> <% boolean debug = ("true".equals(request.getParameter("debug"))); String rseed = getParamString("randomseed", request); long randomseed; if(rseed==null||"".equals(rseed)) { randomseed = (long)(Math.random()*1000000000); } else randomseed = getParam(rseed); Random random = new Random(randomseed); int villnum = (int)(random.nextDouble()*2)+1; boolean hasriver = villnum==1&&(random.nextDouble()<.5); boolean hasextraroad1 = villnum==1&&(random.nextDouble()<.8); boolean hasextraroad2 = villnum==2&&(random.nextDouble()<.8); String numhousesstr = getParamString("numhouses", request); int numhouses = getParam(numhousesstr); boolean housenums[] = new boolean[(hasextraroad1||hasextraroad2?64:58)]; if(numhouses<0) { numhouses = 0; for(int i = 0; i < housenums.length; i++) { housenums[i] = (random.nextDouble()>=.65); if(debug) housenums[i] = true; if(housenums[i]) numhouses++; } } else { for(int i = 0; i < numhouses; i++) { boolean set = false; while(!set) { int temp = (int) (random.nextDouble()*housenums.length); if(!housenums[temp]) { housenums[temp] = true; set = true; } } } } Point[] housepts = new Point[housenums.length]; if(villnum==1) { housepts[0] = new Point(300,5);//h housepts[1] = new Point(60,0);//w housepts[2] = new Point(350,40);//e housepts[3] = new Point(130,130);//w housepts[4] = new Point(340,240);//c housepts[5] = new Point(430,220);//c housepts[6] = new Point(360,300);//c housepts[7] = new Point(450,270);//c housepts[8] = new Point(420,400);//c housepts[9] = new Point(510,370);//c housepts[10] = new Point(450,460);//c housepts[11] = new Point(540,430);//c housepts[12] = new Point(460,530);//c housepts[13] = new Point(550,500);//c housepts[14] = new Point(5,785);//h housepts[15] = new Point(20,1170);//h housepts[16] = new Point(5,875);//w housepts[17] = new Point(190,830);//f housepts[18] = new Point(370,820);//c housepts[19] = new Point(400,880);//c housepts[20] = new Point(300,840);//c housepts[21] = new Point(330,900);//c housepts[22] = new Point(970,710);//c housepts[23] = new Point(1070,780);//c housepts[24] = new Point(1050,700);//c housepts[25] = new Point(1130,770);//c housepts[26] = new Point(1150,690);//c housepts[27] = new Point(1200,760);//c housepts[28] = new Point(1300,510);//w housepts[29] = new Point(1400,640);//f housepts[30] = new Point(1500,490);//f housepts[31] = new Point(1500,600);//f housepts[32] = new Point(1620,500);//h housepts[33] = new Point(1640,660);//h housepts[34] = new Point(810,1070);//c housepts[35] = new Point(910,1040);//c housepts[36] = new Point(850,1120);//c housepts[37] = new Point(950,1090);//c housepts[38] = new Point(920,1170);//c housepts[39] = new Point(1020,1160);//c housepts[40] = new Point(950,1230);//c housepts[41] = new Point(1050,1220);//c housepts[42] = new Point(980,1290);//c housepts[43] = new Point(1080,1280);//c housepts[44] = new Point(880,1360);//w housepts[45] = new Point(1160,1320);//e housepts[46] = new Point(990,1500);//w housepts[47] = new Point(1220,1440);//e housepts[48] = new Point(1140,1630);//h housepts[49] = new Point(1280,1600);//h housepts[50] = new Point(1500,1200);//h housepts[51] = new Point(1580,1400);//h housepts[52] = new Point(1380,1240);//h housepts[53] = new Point(1520,1490);//h housepts[54] = new Point(110,280);//w housepts[55] = new Point(580,180);//e housepts[56] = new Point(220,520);//w housepts[57] = new Point(630,420);//e if(housepts.length>58) housepts[58] = new Point(850,200);//w if(housepts.length>58) housepts[59] = new Point(1120,250);//e if(housepts.length>58) housepts[60] = new Point(820,350);//w if(housepts.length>58) housepts[61] = new Point(940,480);//c if(housepts.length>58) housepts[62] = new Point(900,550);//c if(housepts.length>58) housepts[63] = new Point(1030,480);//c } else { housepts[0] = new Point(300,5);//h housepts[1] = new Point(100,500);//w housepts[2] = new Point(950,150);//e housepts[3] = new Point(1340,160);//w housepts[4] = new Point(850,710);//c housepts[5] = new Point(930,680);//c housepts[6] = new Point(430,460);//c housepts[7] = new Point(470,510);//c housepts[8] = new Point(880,770);//c housepts[9] = new Point(920,810);//c housepts[10] = new Point(670,1100);//c housepts[11] = new Point(610,290);//c housepts[12] = new Point(680,260);//c housepts[13] = new Point(610,220);//c housepts[14] = new Point(900,50);//h housepts[15] = new Point(1100,80);//h housepts[16] = new Point(300,620);//w housepts[17] = new Point(580,800);//f housepts[18] = new Point(1590,300);//c housepts[19] = new Point(1580,380);//c housepts[20] = new Point(1580,460);//c housepts[21] = new Point(1480,450);//c housepts[22] = new Point(1560,550);//c housepts[23] = new Point(650,1200);//c housepts[24] = new Point(1240,760);//c housepts[25] = new Point(790,1060);//c housepts[26] = new Point(1420,550);//c housepts[27] = new Point(1490,610);//c housepts[28] = new Point(410,730);//w housepts[29] = new Point(950,860);//f housepts[30] = new Point(1050,820);//f housepts[31] = new Point(1150,780);//f housepts[32] = new Point(10,1000);//h housepts[33] = new Point(30,750);//h housepts[34] = new Point(650,510);//c housepts[35] = new Point(690,550);//c housepts[36] = new Point(730,590);//c housepts[37] = new Point(770,630);//c housepts[38] = new Point(810,670);//c housepts[39] = new Point(740,470);//c housepts[40] = new Point(780,510);//c housepts[41] = new Point(820,550);//c housepts[42] = new Point(860,590);//c housepts[43] = new Point(900,630);//c housepts[44] = new Point(570,920);//w housepts[45] = new Point(1000,350);//e housepts[46] = new Point(220,360);//w housepts[47] = new Point(1090,450);//e housepts[48] = new Point(1140,1630);//h housepts[49] = new Point(1280,1600);//h housepts[50] = new Point(1500,1200);//h housepts[51] = new Point(380,1000);//h housepts[52] = new Point(1380,1240);//h housepts[53] = new Point(230,1090);//h housepts[54] = new Point(1320,300);//w housepts[55] = new Point(630,40);//e housepts[56] = new Point(150,200);//w housepts[57] = new Point(800,1120);//e if(housepts.length>58) housepts[58] = new Point(350,50);//w if(housepts.length>58) housepts[59] = new Point(770,170);//e if(housepts.length>58) housepts[60] = new Point(410,270);//w if(housepts.length>58) housepts[61] = new Point(540,120);//c if(housepts.length>58) housepts[62] = new Point(670,150);//c if(housepts.length>58) housepts[63] = new Point(570,170);//c } String numbarbersstr = getParamString("numbarbers", request); int numbarbers = getParam(numbarbersstr); if(numbarbers<0) { numbarbers = 0; if(debug||random.nextDouble()<(numhouses*.02)) numbarbers++; } String numblacksmithsstr = getParamString("numblacksmiths", request); int numblacksmiths = getParam(numblacksmithsstr); if(numblacksmiths<0) { numblacksmiths = 0; if(debug||random.nextDouble()<(numhouses*.02)) numblacksmiths++; if(debug||random.nextDouble()<(numhouses*.02)) numblacksmiths++; } String nummillsstr = getParamString("nummills", request); int nummills = getParam(nummillsstr); if(nummills<0) { nummills = 0; if(debug||random.nextDouble()<(numhouses*.02)) nummills++; if(debug||random.nextDouble()<(numhouses*.02)) nummills++; } String numinnsstr = getParamString("numinns", request); int numinns = getParam(numinnsstr); if(numinns<0) { numinns = 0; if(debug||random.nextDouble()<(numhouses*.03)) numinns++; } String numtownhallsstr = getParamString("numtownhalls", request); int numtownhalls = getParam(numtownhallsstr); if(numtownhalls<0) { numtownhalls = 0; if(debug||random.nextDouble()<(numhouses*.02)) numtownhalls++; } String numchurchesstr = getParamString("numchurches", request); int numchurches = getParam(numchurchesstr); if(numchurches<0) { numchurches = 0; if(debug||random.nextDouble()<(numhouses*.03)) numchurches++; } String numtavernsstr = getParamString("numtaverns", request); int numtaverns = getParam(numtavernsstr); if(numtaverns<0) { numtaverns = 0; if(debug||random.nextDouble()<(numhouses*.02)) numtaverns++; if(debug||random.nextDouble()<(numhouses*.02)) numtaverns++; } String numwarehousesstr = getParamString("numwarehouses", request); int numwarehouses = getParam(numwarehousesstr); if(numwarehouses<0) { numwarehouses = 0; if(debug||random.nextDouble()<(numhouses*.02)) numwarehouses++; if(debug||random.nextDouble()<(numhouses*.02)) numwarehouses++; } String extrafeature=""; if(hasextraroad1||hasextraroad2) { String[] extrafeatures = {"mine", "monastery", "magic_stones", "tower_round", ""}; extrafeature = extrafeatures[(int)(random.nextDouble()*extrafeatures.length)]; } String largelocs[] = new String[4]; for(int i = 0; i < largelocs.length; i++) largelocs[i] = ""; String medlocs[] = new String[4]; for(int i = 0; i < medlocs.length; i++) medlocs[i] = ""; String smalllocs[] = new String[4]; for(int i = 0; i < smalllocs.length; i++) smalllocs[i] = ""; Point[] llpts = new Point[largelocs.length]; if(villnum==1) llpts[0] = new Point(580,550); else llpts[0] = new Point(630,610); if(villnum==1) llpts[1] = new Point(540,725); else llpts[1] = new Point(610,325); if(villnum==1) llpts[2] = new Point(705,685); else llpts[2] = new Point(965,550); if(villnum==1) llpts[3] = new Point(855,870); else llpts[3] = new Point(820,900); Point[] mlpts = new Point[medlocs.length]; if(villnum==1) mlpts[0] = new Point(660,850); else mlpts[0] = new Point(810,380); if(villnum==1) mlpts[1] = new Point(800,800); else mlpts[1] = new Point(540,550); if(villnum==1) mlpts[2] = new Point(930,780); else mlpts[2] = new Point(965,730); if(villnum==1) mlpts[3] = new Point(520,860); else mlpts[3] = new Point(780,805); Point[] slpts = new Point[smalllocs.length]; if(villnum==1) slpts[0] = new Point(635,655); else slpts[0] = new Point(690,730); if(villnum==1) slpts[1] = new Point(475,655); else slpts[1] = new Point(890,450); if(villnum==1) slpts[2] = new Point(440,775); else slpts[2] = new Point(320,500); if(villnum==1) slpts[3] = new Point(725,950); else slpts[3] = new Point(480,400); Point[] wmpts = new Point[2]; if(villnum==1) wmpts[0] = new Point(20,170); else wmpts[0] = new Point(50,200); if(villnum==1) wmpts[1] = new Point(750,1380); else wmpts[1] = new Point(200,900); Point[] chpts = new Point[2]; if(villnum==1) chpts[0] = new Point(1200,600); else chpts[0] = new Point(720,280); if(villnum==1) chpts[1] = new Point(180,960); else chpts[1] = new Point(1075,665); Point[] grpts = new Point[2]; if(villnum==1) grpts[0] = new Point(1300,700); else grpts[0] = new Point(880,270); if(villnum==1) grpts[1] = new Point(310,960); else grpts[1] = new Point(1200,615); Point extrafeaturept = new Point(950,50); if(villnum==2) extrafeaturept = new Point(410,1350); boolean set = false; if(numblacksmiths>0) { while(!set) { int num = (int)(random.nextDouble()*smalllocs.length); if("".equals(smalllocs[num])) { smalllocs [num]= "blacksmith"; set = true; } } } set = false; if(numblacksmiths>1) { while(!set) { int num = (int)(random.nextDouble()*smalllocs.length); if("".equals(smalllocs[num])) { smalllocs[num] = "blacksmith"; set = true; } } } set = false; if(numinns>0) { while(!set) { int num = (int)(random.nextDouble()*medlocs.length); if("".equals(medlocs[num])) { medlocs[num] = "inn"; set = true; } } } set = false; if(numtownhalls>0) { while(!set) { int num = (int)(random.nextDouble()*largelocs.length); if("".equals(largelocs[num])) { largelocs[num] = "townhall"; set = true; } } } set = false; if(numbarbers>0) { while(!set) { int num = (int)(random.nextDouble()*smalllocs.length); if("".equals(smalllocs[num])) { smalllocs[num] = "barber"; set = true; } } } set = false; if(numtaverns>0) { while(!set) { int num = (int)(random.nextDouble()*largelocs.length); if("".equals(largelocs[num])) { largelocs[num] = "tavern"; set = true; } } } set = false; if(numtaverns>1) { while(!set) { int num = (int)(random.nextDouble()*largelocs.length); if("".equals(largelocs[num])) { largelocs[num] = "tavern"; set = true; } } } set = false; if(numwarehouses>0) { while(!set) { int num = (int)(random.nextDouble()*medlocs.length); if("".equals(medlocs[num])) { medlocs[num] = "warehouse"; set = true; } } } set = false; if(numwarehouses>1) { while(!set) { int num = (int)(random.nextDouble()*medlocs.length); if("".equals(medlocs[num])) { medlocs[num] = "warehouse"; set = true; } } } if(debug) { for(int i = 0; i < largelocs.length; i++) if("".equals(largelocs[i])) largelocs[i] = "tavern"; for(int i = 0; i < medlocs.length; i++) if("".equals(medlocs[i])) medlocs[i] = "warehouse"; for(int i = 0; i < smalllocs.length; i++) if("".equals(smalllocs[i])) smalllocs[i] = "blacksmith"; } String vill1 = loadFile("village"+villnum+".svg"); int breakx = vill1.indexOf("")+7; String vill1a = vill1.substring(0, breakx); String vill1b = vill1.substring(breakx); %> Random Village Map Generator

Random Village Map Generator

Inkwell Ideas' Projects:

Main site w/articles

The Random Village Map Generator creates a "random" village map suitable for fantasy and other role-playing games (RPGs) such as Dungeons and Dragons, Pathfinder, GURPS, HERO and many others.

Because the map is SVG-based, you may resize it (and the whole page) but pressing "control" and "+" or "control" and "-" and the icons will look sharp even when enlarged!
You may save a map by saving the source page and cutting everything but what is between the "svg" tags, inclusive. ("<svg ..." and "</svg>") Save this with a .svg filename and you should be able to open it later in a web browser or edit it in Inkscape or GIMP.

Customize Your Map (Optional)

#Houses/Farms:
#Barbers:
#Blacksmiths:
#Churches:
#Inns:
#Mills:
#Taverns:
#Townhalls:
#Warehouses/General Stores:
Random Seed:
Jot down the random seed to create the same map. (If you set change some values or if the random village generator is updated, the seed will not recreate the same map.)
<%=vill1a%> <%= loadFile("cottageuse.svg") %> <%= loadFile("hunteruse.svg") %> <%= loadFile("farmuse.svg") %> <%= loadFile("farm_w_fields_westuse.svg") %> <%= loadFile("farm_w_fields_eastuse.svg") %> <% if(!"".equals(extrafeature)) { out.println(loadFile(extrafeature+"use.svg")); } %> <% if(hasriver) { out.println(loadFile("bridge_stone1use.svg")); } %> <% if(nummills>0) { out.println(loadFile("windmilluse.svg")); } %> <% if(numbarbers>0) { out.println(loadFile("barberuse.svg")); } %> <% if(numblacksmiths>0) { out.println(loadFile("blacksmithuse.svg")); } %> <% if(numinns>0) { out.println(loadFile("innuse.svg")); } %> <% if(numtaverns>0) { out.println(loadFile("tavernuse.svg")); } %> <% out.println(loadFile("townhalluse.svg")); %> <% if(numwarehouses>0) { out.println(loadFile("warehouseuse.svg")); } %> <% if(numchurches>0) { out.println(loadFile("cathedraluse.svg")); } %> <% if(numchurches>0) { out.println(loadFile("graveyarduse.svg")); } %> <%=vill1b%> <% if(hasextraroad1) { %> <% } %> <% if(hasextraroad2) { %> <% } %> <% if(hasriver) { %> <% } %> <% if(!"".equals(extrafeature)) {%> <% } %> <% if(housenums[0]) { %> <% } %> <% if(housenums[1]) { %> <% } %> <% if(housenums[2]) { %> <% } %> <% if(housenums[3]) { %> <% } %> <% double churchloc = random.nextDouble(); if(debug||(numchurches>0 && churchloc<.5)) { %> <% } %> <% if(housenums[4]) { %> <% } %> <% if(housenums[5]) { %> <% } %> <% if(housenums[6]) { %> <% } %> <% if(housenums[7]) { %> <% } %> <% if(housenums[8]) { %> <% } %> <% if(housenums[9]) { %> <% } %> <% if(housenums[10]) { %> <% } %> <% if(housenums[11]) { %> <% } %> <% if(housenums[12]) { %> <% } %> <% if(housenums[13]) { %> <% } %> <% if(!"".equals(largelocs[0])) { %> <% } %> <% if(!"".equals(smalllocs[0])) { %> <% } %> <% if(!"".equals(smalllocs[1])) { %> <% } %> <% if(!"".equals(smalllocs[2])) { %> <% } %> <% if(!"".equals(largelocs[1])) { %> <% } %> <% if(!"".equals(largelocs[2])) { %> <% } %> <% if(!"".equals(medlocs[0])) { %> <% } %> <% if(!"".equals(medlocs[1])) { %> <% } %> <% if(!"".equals(medlocs[2])) { %> <% } %> <% if(!"".equals(smalllocs[3])) { %> <% } %> <% if(!"".equals(medlocs[3])) { %> <% } %> <% if(!"".equals(largelocs[3])) { %> <% } %> <% if(debug||(numchurches>0 && churchloc>=.5)) { %> <% } %> <% if(housenums[14]) { %> <% } %> <% if(housenums[15]) { %> <% } %> <% if(housenums[16]) { %> <% } %> <% if(housenums[17]) { %> <% } %> <% double millloc = random.nextDouble(); if(debug||(nummills>1 || (nummills>0&&millloc<.5))) { %> <% } %> <% if(debug||(nummills>1 || (nummills>0&&millloc>=.5))) { %> <% } %> <% if(housenums[18]) { %> <% } %> <% if(housenums[19]) { %> <% } %> <% if(housenums[20]) { %> <% } %> <% if(housenums[21]) { %> <% } %> <% if(housenums[22]) { %> <% } %> <% if(housenums[23]) { %> <% } %> <% if(housenums[24]) { %> <% } %> <% if(housenums[25]) { %> <% } %> <% if(housenums[26]) { %> <% } %> <% if(housenums[27]) { %> <% } %> <% if(housenums[28]) { %> <% } %> <% if(housenums[29]) { %> <% } %> <% if(housenums[30]) { %> <% } %> <% if(housenums[31]) { %> <% } %> <% if(housenums[32]) { %> <% } %> <% if(housenums[33]) { %> <% } %> <% if(housenums[34]) { %> <% } %> <% if(housenums[35]) { %> <% } %> <% if(housenums[36]) { %> <% } %> <% if(housenums[37]) { %> <% } %> <% if(housenums[38]) { %> <% } %> <% if(housenums[39]) { %> <% } %> <% if(housenums[40]) { %> <% } %> <% if(housenums[41]) { %> <% } %> <% if(housenums[42]) { %> <% } %> <% if(housenums[43]) { %> <% } %> <% if(housenums[44]) { %> <% } %> <% if(housenums[45]) { %> <% } %> <% if(housenums[46]) { %> <% } %> <% if(housenums[47]) { %> <% } %> <% if(housenums[48]) { %> <% } %> <% if(housenums[49]) { %> <% } %> <% if(housenums[50]) { %> <% } %> <% if(housenums[51]) { %> <% } %> <% if(housenums[52]) { %> <% } %> <% if(housenums[53]) { %> <% } %> <% if(housenums[54]) { %> <% } %> <% if(housenums[55]) { %> <% } %> <% if(housenums[56]) { %> <% } %> <% if(housenums[57]) { %> <% } %> <% if(hasextraroad1) { %> <% if(housenums[58]) { %> <% } %> <% if(housenums[59]) { %> <% } %> <% if(housenums[60]) { %> <% } %> <% if(housenums[61]) { %> <% } %> <% if(housenums[62]) { %> <% } %> <% if(housenums[63]) { %> <% } %> <% } %>

Created by Inkwell Ideas, Inc., but all graphics are released to the public domain. Many map icons were created by nicubunu and were released to the public domain by him. The remaining graphics are heavily derived from his graphics.