package th; import java.lang.Math; class SpanningRegion extends Region { public static String name = "Open Pipe"; public static String description = "The tunnel dead-ends with a large open" + " steam pipe leading away\ninto darkness."; public static String color = Ifc.BRIGHT_BLUE; private static Class SpanningTunnel = Utl.gclass("SpanningTunnel"); public SpanningRegion (Node start, int region) { super(start, region); } public void generate (Node origin, int region, int direction) { origin.name = name; origin.description = description; origin.color = color; origin.unique = false; Node destination = (Node)Utl.rn(g.deadends); g.deadends.remove((Object)destination); destination = new Region_Bridge(destination); int xdist = origin.x - destination.x; int ydist = origin.y - destination.y; int phase = 0; int curdir = direction; int direc1 = -1; int direc2 = -1; if (ydist <= 0) direc1 = 1; else direc1 = 0; if (xdist <= 0) direc2 = 3; else direc2 = 2; //if (direction == direc1) { //phase = 1; curdir = direc1; //} //else if (direction == direc2) { //phase = direc2; direc2 = direc1; //direc1 = curdir = phase; phase = 1; //} xdist = Math.abs(xdist); ydist = Math.abs(ydist); if (xdist == ydist) xdist = ydist = (xdist / 3) + 1; else if (xdist < ydist) { int ratio = (ydist / (xdist + 1)) + 1; xdist = (xdist / 3) + 1; ydist = xdist * ratio; } else if (ydist < xdist) { int ratio = (xdist / (ydist + 1)) + 1; ydist = (Math.abs(ydist) / 3) + 1; xdist = ydist * ratio; } Node oldnode = origin; Node newnode = null; while (xdist + ydist > 0) { newnode = (Node)Utl.newInstance(SpanningTunnel); newnode.region = region; Map.makelink(newnode, oldnode, curdir); if (curdir > 1) --xdist; else --ydist; if (phase == 0) { if (curdir > 1) curdir = direc1; else curdir = direc2; phase = 1; } else if (phase == 1) { if (Utl.rn() && xdist > 0) curdir = direc2; else if (ydist > 0) curdir = direc1; else curdir = direc2; } oldnode = newnode; } if ((curdir == 0 && destination.south != null) || (curdir == 1 && destination.north != null)) curdir = Math.max(direc1, direc2); else if ((curdir == 2 && destination.east != null) || (curdir == 3 && destination.west != null)) curdir = Math.min(direc1, direc2); Map.makelink(destination, newnode, curdir); destination.name = name; destination.description = description; destination.color = color; destination.unique = false; } } class SpanningTunnel extends Node { public SpanningTunnel() { super(); color = Ifc.BLUE; description = "The pipe stretches on in front of and behind you."; name = "Steam Tunnel"; tunnel = true; if (Utl.rn()) add(Utl.rn(Species.span_spawn).make()); } }