public void mouseClicked(MouseEvent e) { int x; int y; e.consume(); if (mouseEventsEnabled) { x = Math.round(e.getX() / scale); y = Math.round(e.getY() / scale); // allow for the canvas margin y -= margin; // System.out.println("Mouse Click: (" + x + ", " + y + ")"); if (e.getClickCount() < 2) { if (nativeSelectItem(x, y)) { parentFTAFrame.updateFrame(); } } else { if (nativeSelectItem(x, y)) { parentFTAFrame.updateFrame(); } editSelected(); parentFTAFrame.updateFrame(); } if (focusEventsEnabled) { // tell the main Canvas to point to this coordinate parentFTAFrame.setCanvasFocus(x, y); } } }
/** Returns angle in degrees from specified origin to specified destination. */ public static int getAngle(Point origin, Point destination) // origin != destination { double distance = getDistance(origin, destination); int add = 0; int x = destination.getx() - origin.getx(); int y = origin.gety() - destination.gety(); // Java flips things around double angleRad = Math.asin(Math.abs(y) / distance); double angleDeg = Math.toDegrees(angleRad); if ((x >= 0) && (y >= 0)) // Quadrant 1 { angleDeg = angleDeg; } if ((x < 0) && (y > 0)) // Quadrant 2 { angleDeg = 180 - angleDeg; } if ((x <= 0) && (y <= 0)) // Quadrant 3 { angleDeg = 180 + angleDeg; } if ((x > 0) && (y < 0)) // Quadrant 4 { angleDeg = 360 - angleDeg; } float angleFloat = Math.round(angleDeg); int angleInt = Math.round(angleFloat); return (angleInt); }
@Override public void onChangeSliderValue(GuiSlider slider) { if (slider.id == 5) { colourR = (int) Math.round( slider.sliderValue * (slider.maxValue - slider.minValue) + slider.minValue); stand.colourR = colourR; } else if (slider.id == 6) { colourG = (int) Math.round( slider.sliderValue * (slider.maxValue - slider.minValue) + slider.minValue); stand.colourG = colourG; } else if (slider.id == 7) { colourB = (int) Math.round( slider.sliderValue * (slider.maxValue - slider.minValue) + slider.minValue); stand.colourB = colourB; } else if (slider.id == 15) { alpha = (int) Math.round( slider.sliderValue * (slider.maxValue - slider.minValue) + slider.minValue); stand.alpha = alpha; } }
/** * Draws an open star with a specified number of points.<br> * The center of this star is specified by centerX,centerY and its size is specified by radius * <br> * (As in the radius of the circle the star would fit inside). <br> * Precondition: points >= 2 <br> * Example: <br> * Expo.drawStar(g,300,200,100,8); <br> * Draws an open star with 8 points and a radius of 100 pixels whose center is located at the * coordinate (300,200). */ public static void drawStar(Graphics g, int centerX, int centerY, int radius, int points) { int halfRadius = getHalfRadius(radius, points); int p = points; points *= 2; int xCoord[] = new int[points]; int yCoord[] = new int[points]; int currentRadius; for (int k = 0; k < points; k++) { if (k % 2 == 0) currentRadius = radius; else currentRadius = halfRadius; xCoord[k] = (int) Math.round(Math.cos(twoPI * k / points - halfPI) * currentRadius) + centerX; yCoord[k] = (int) Math.round(Math.sin(twoPI * k / points - halfPI) * currentRadius) + centerY; } int x = (p - 5) / 2 + 1; if (p >= 5 && p <= 51) switch (p % 4) { case 1: yCoord[x] = yCoord[x + 1] = yCoord[points - x - 1] = yCoord[points - x]; break; case 2: yCoord[x] = yCoord[x + 1] = yCoord[points - x - 1] = yCoord[points - x]; yCoord[x + 3] = yCoord[x + 4] = yCoord[points - x - 4] = yCoord[points - x - 3]; break; case 3: yCoord[x + 2] = yCoord[x + 3] = yCoord[points - x - 3] = yCoord[points - x - 2]; } g.drawPolygon(xCoord, yCoord, points); }
@BeforeClass public void setUp() { nonOverlappingExomeIntervals = new ArrayList<>(100); final Random rdn = new Random(13); // some "random" but fixed seed to make sure errors are deterministic. for (int i = 0; i < ExomeToolsTestUtils.REFERENCE_DICTIONARY.size(); i++) { int current = 0; final SAMSequenceRecord sequence = ExomeToolsTestUtils.REFERENCE_DICTIONARY.getSequence(i); while (current < sequence.getSequenceLength()) { int start = current + Math.max( minimumExonIntergapSize, (int) Math.round( rdn.nextGaussian() * sdExonIntergapSize + averageExonIntergapSize)); if (start >= sequence.getSequenceLength()) { break; } int size = Math.max( minimumExonSize, (int) Math.round(rdn.nextGaussian() * sdExonSize + averageExonSize)); int stop = start + size - 1; if (stop >= sequence.getSequenceLength()) { break; } nonOverlappingExomeIntervals.add( ExomeToolsTestUtils.createInterval(sequence.getSequenceName(), start, stop)); current = stop + 1; } } Collections.sort(nonOverlappingExomeIntervals, IntervalUtils.LEXICOGRAPHICAL_ORDER_COMPARATOR); exonDB = new HashedListTargetCollection<>(nonOverlappingExomeIntervals); }
private void estimateDistribution(int[] bowl, int bowlId, int round, int bowlSize) { // Initially, create a uniform distribution for (int i = 0; i < NUM_FRUITS; i++) { originalDistribution[i] = Math.round(n_fruits / NUM_FRUITS); // Assign uniform probability if (bowls_seen[0] == 0 || bowls_seen[1] == 0) { java.util.Arrays.fill(fruit_probs, 1.0 / NUM_FRUITS); } } // Update fruit history as bowls come by fruitHistory = history(bowl, bowlId, round); bowls_seen[round]++; if (bowls_seen[0] > 0 || bowls_seen[1] > 0) { // Update Probabilities double prob_sum = 0.0; for (int i = 0; i < NUM_FRUITS; i++) { fruit_probs[i] += (fruitHistory[round * n_players + bowlId][i] * 1.0 / bowlSize); prob_sum += fruit_probs[i]; } } // generate a platter based on estimated probabilties of each fruit for (int i = 0; i < NUM_FRUITS; i++) { currentDistribution[i] = (int) Math.round(n_fruits * fruit_probs[i]); } for (int i = 0; i < NUM_FRUITS; i++) { originalDistribution[i] -= currentDistribution[i]; } }
public void calc() { System.out.println("Please Input tow primes:"); Scanner sc = new Scanner(System.in); int p = sc.nextInt(); int q = sc.nextInt(); int n = p * q; int s = (p - 1) * (q - 1); int e, d; for (e = 2; e < s; ++e) if (gcd(e, s) == 1) break; e = 31; for (d = 2; ; ++d) if (d * e % s == 1) break; System.out.println("p\tq\tn\ts\te\td"); System.out.printf("%d\t%d\t%d\t%d\t%d\t%d\n", p, q, n, s, e, d); System.out.println("Please Input M:"); int m = sc.nextInt(); long c = Math.round(Math.pow(m, e)) % n; long mm = Math.round(Math.pow(c, d)) % n; System.out.printf("After encrypt: %d\n", c); System.out.printf("After decrypt: %d\n", mm); }
/** * Reads image meta data. * * @param oimage * @return */ public static Map<String, String> readImageData(IIOImage oimage) { Map<String, String> dict = new HashMap<String, String>(); IIOMetadata imageMetadata = oimage.getMetadata(); if (imageMetadata != null) { IIOMetadataNode dimNode = (IIOMetadataNode) imageMetadata.getAsTree("javax_imageio_1.0"); NodeList nodes = dimNode.getElementsByTagName("HorizontalPixelSize"); int dpiX; if (nodes.getLength() > 0) { float dpcWidth = Float.parseFloat(nodes.item(0).getAttributes().item(0).getNodeValue()); dpiX = (int) Math.round(25.4f / dpcWidth); } else { dpiX = Toolkit.getDefaultToolkit().getScreenResolution(); } dict.put("dpiX", String.valueOf(dpiX)); nodes = dimNode.getElementsByTagName("VerticalPixelSize"); int dpiY; if (nodes.getLength() > 0) { float dpcHeight = Float.parseFloat(nodes.item(0).getAttributes().item(0).getNodeValue()); dpiY = (int) Math.round(25.4f / dpcHeight); } else { dpiY = Toolkit.getDefaultToolkit().getScreenResolution(); } dict.put("dpiY", String.valueOf(dpiY)); } return dict; }
private void updateTables18() { myDatabase.execSQL("ALTER TABLE BookSeries RENAME TO BookSeries_Obsolete"); myDatabase.execSQL( "CREATE TABLE BookSeries(" + "series_id INTEGER NOT NULL REFERENCES Series(series_id)," + "book_id INTEGER NOT NULL UNIQUE REFERENCES Books(book_id)," + "book_index TEXT)"); final SQLiteStatement insert = myDatabase.compileStatement( "INSERT INTO BookSeries (series_id,book_id,book_index) VALUES (?,?,?)"); final Cursor cursor = myDatabase.rawQuery("SELECT series_id,book_id,book_index FROM BookSeries_Obsolete", null); while (cursor.moveToNext()) { insert.bindLong(1, cursor.getLong(0)); insert.bindLong(2, cursor.getLong(1)); final float index = cursor.getFloat(2); final String stringIndex; if (index == 0.0f) { stringIndex = null; } else { if (Math.abs(index - Math.round(index)) < 0.01) { stringIndex = String.valueOf(Math.round(index)); } else { stringIndex = String.format("%.1f", index); } } final BigDecimal bdIndex = SeriesInfo.createIndex(stringIndex); SQLiteUtil.bindString(insert, 3, bdIndex != null ? bdIndex.toString() : null); insert.executeInsert(); } cursor.close(); myDatabase.execSQL("DROP TABLE BookSeries_Obsolete"); }
public void printLoop(int n, float x[], float y[]) { // Need to swap the y component Polygon P = new Polygon(); for (int i = 0; i < n; i++) P.addPoint(Math.round(x[i]), Math.round(height - y[i])); poly_draw.add(P); poly_draw_color.add(curColor); }
private long computeDuj2a(long f1, double q, double ysqD) { // Compute Duj2; where all classes whose frequency in the sample // exceeds Duj2a_DIVIDER are removed. // If there are none, just return Duj2. // if n = 0 when B is removed, fall back on Duj2. if (n_small == 0) { return computeDuj2(n, dn, f1, q, ysqD); } long f1_small = f_small.get(1); if (f1_small == dn_small) { // Assume all classes except those in B are unique. // Estimate how many rows in the population belong the classes in B long Nbig = 0; for (Long vc : B) { Nbig += vc; } Nbig = Math.round((double) Nbig / q); if (Nbig >= N) { // Very few classes other than those in B. Assume we found all // the classes in our sample. return dn; } // N - Nbig is the number of rows in the population not represented // by classes in B. We assume each of these other rows in a // unique class. return B.size() + (N - Nbig); } // Generate an estimate of the population size when the classes in B // are removed by estimating Nj for each class in B and subtracting // that from N. long N_small = N; for (Long vc : B) { // nj = (q * Nj) / (1 - (1 - q)^Nj) // We know nj and q: solve for Nj numerically long Nj = estimateNj(vc, q); N_small -= Nj; } // Compute q, Duj1 and gamma-squared(D) for the sample containing only // the infrequent classes. double q_small = (double) n_small / (double) N_small; double Duj1_small_ = computeDuj1(n_small, dn_small, f1_small, q_small); long Duj1_small = Math.round(Duj1_small_); double ysqD_small = estimateVarianceFromD(n_small, N_small, f_small, Duj1_small); long D_small = computeDuj2(n_small, dn_small, f1_small, q_small, ysqD_small); return D_small + B.size(); }
public static String formatLocation(Location location) { return String.format( "%s: (%d, %d, %d)", location.getWorld().getName(), Math.round(location.getX()), Math.round(location.getY()), Math.round(location.getZ())); }
/** * Zooms out by making the source rectangle (srcRect) larger and centering it on (x,y). If we * can't make it larger, then make the window smaller. */ public void zoomOut(int x, int y) { if (magnification <= 0.03125) return; double oldMag = magnification; double newMag = getLowerZoomLevel(magnification); double srcRatio = (double) srcRect.width / srcRect.height; double imageRatio = (double) imageWidth / imageHeight; double initialMag = imp.getWindow().getInitialMagnification(); if (Math.abs(srcRatio - imageRatio) > 0.05) { double scale = oldMag / newMag; int newSrcWidth = (int) Math.round(srcRect.width * scale); int newSrcHeight = (int) Math.round(srcRect.height * scale); if (newSrcWidth > imageWidth) newSrcWidth = imageWidth; if (newSrcHeight > imageHeight) newSrcHeight = imageHeight; int newSrcX = srcRect.x - (newSrcWidth - srcRect.width) / 2; int newSrcY = srcRect.y - (newSrcHeight - srcRect.height) / 2; if (newSrcX < 0) newSrcX = 0; if (newSrcY < 0) newSrcY = 0; srcRect = new Rectangle(newSrcX, newSrcY, newSrcWidth, newSrcHeight); // IJ.log(newMag+" "+srcRect+" "+dstWidth+" "+dstHeight); int newDstWidth = (int) (srcRect.width * newMag); int newDstHeight = (int) (srcRect.height * newMag); setMagnification(newMag); setMaxBounds(); // IJ.log(newDstWidth+" "+dstWidth+" "+newDstHeight+" "+dstHeight); if (newDstWidth < dstWidth || newDstHeight < dstHeight) { // IJ.log("pack"); setDrawingSize(newDstWidth, newDstHeight); imp.getWindow().pack(); } else repaint(); return; } if (imageWidth * newMag > dstWidth) { int w = (int) Math.round(dstWidth / newMag); if (w * newMag < dstWidth) w++; int h = (int) Math.round(dstHeight / newMag); if (h * newMag < dstHeight) h++; x = offScreenX(x); y = offScreenY(y); Rectangle r = new Rectangle(x - w / 2, y - h / 2, w, h); if (r.x < 0) r.x = 0; if (r.y < 0) r.y = 0; if (r.x + w > imageWidth) r.x = imageWidth - w; if (r.y + h > imageHeight) r.y = imageHeight - h; srcRect = r; } else { srcRect = new Rectangle(0, 0, imageWidth, imageHeight); setDrawingSize((int) (imageWidth * newMag), (int) (imageHeight * newMag)); // setDrawingSize(dstWidth/2, dstHeight/2); imp.getWindow().pack(); } // IJ.write(newMag + " " + srcRect.x+" "+srcRect.y+" "+srcRect.width+" "+srcRect.height+" // "+dstWidth + " " + dstHeight); setMagnification(newMag); // IJ.write(srcRect.x + " " + srcRect.width + " " + dstWidth); setMaxBounds(); repaint(); }
public double getRad() { if (rad > Math.PI) { // if below return (Math.round((rad - (Math.PI * 2)) * 100.00)) / 100.00; } else { return Math.round(rad * 100.00) / 100.00; } }
/** * The coordinate is the top left corner * * @param xm x position in meters * @param ym y position in meters * @return [0] contains row; [1] contains col */ public int[] getNodePosition(double xm, double ym) { int pxW = floorPlan.getWidth(), pxH = floorPlan.getHeight(), pxX, pxY; double widthRatio = pxW / actualW, heightRatio = pxH / actualH; pxX = (int) Math.round(xm * widthRatio); pxY = (int) Math.round(ym * heightRatio); int pos[] = new int[2]; pos[0] = pxY / unitH; pos[1] = pxX / unitW; return pos; }
@Override public boolean tick(Tickable ticking, int tickID) { if (!(affected instanceof MOB)) return super.tick(ticking, tickID); final MOB mob = (MOB) affected; if (tickID != Tickable.TICKID_MOB) return true; if (!proficiencyCheck(null, 0, false)) return true; if ((!mob.isInCombat()) && (CMLib.flags().isSleeping(mob))) { roundsHibernating++; final double man = ((mob.charStats().getStat(CharStats.STAT_INTELLIGENCE) + mob.charStats().getStat(CharStats.STAT_WISDOM))); mob.curState() .adjMana( (int) Math.round( (man * .1) + ((mob.phyStats().level() + (2.0 * super.getXLEVELLevel(invoker()))) / 2.0)), mob.maxState()); mob.curState().setHunger(oldState.getHunger()); mob.curState().setThirst(oldState.getThirst()); final double move = mob.charStats().getStat(CharStats.STAT_STRENGTH); mob.curState() .adjMovement( (int) Math.round( (move * .1) + ((mob.phyStats().level() + (2.0 * super.getXLEVELLevel(invoker()))) / 2.0)), mob.maxState()); if (!CMLib.flags().isGolem(mob)) { final double hp = mob.charStats().getStat(CharStats.STAT_CONSTITUTION); if (!CMLib.combat() .postHealing( mob, mob, this, CMMsg.MASK_ALWAYS | CMMsg.TYP_CAST_SPELL, (int) Math.round( (hp * .1) + ((mob.phyStats().level() + (2.0 * super.getXLEVELLevel(invoker()))) / 2.0)), null)) unInvoke(); } } else { unInvoke(); return false; } return super.tick(ticking, tickID); }
static int getNext(int[] mas) { int next = 0; int n = mas.length; int rez = 1, d1 = 0, d2 = 0; while (rez == 1) { for (int i = 2; i < n; i++) { d1 = (mas[i] - mas[i - 1]); d2 = (mas[i - 1] - mas[i - 2]); rez *= (d1 == d2) ? rez : 0; } if (rez == 1) { next = mas[n - 1] + d1; break; } rez = 1; for (int i = 2; i < n; i++) { d1 = (int) (1000000 * ((double) mas[i] / (double) mas[i - 1])); d2 = (int) (1000000 * ((double) mas[i - 1] / (double) mas[i - 2])); rez *= (d1 == d2) ? rez : 0; } if (rez == 1) { next = mas[n - 1] * d1 / 1000000; break; } rez = 1; for (int i = 2; i < n; i++) { d1 = (int) Math.round(1000000 * (Math.sqrt(mas[i]) - Math.sqrt(mas[i - 1]))); d2 = (int) Math.round(1000000 * (Math.sqrt(mas[i - 1]) - Math.sqrt(mas[i - 2]))); rez *= (d1 == d2) ? rez : 0; } if (rez == 1) { next = (int) Math.pow(Math.sqrt(mas[n - 1]) + d1 / 1000000, 2); break; } rez = 1; for (int i = 2; i < n; i++) { d1 = (int) Math.round(1000000 * (Math.pow(mas[i], 1 / 3.) - Math.pow(mas[i - 1], 1 / 3.))); d2 = (int) Math.round(1000000 * (Math.pow(mas[i - 1], 1 / 3.) - Math.pow(mas[i - 2], 1 / 3.))); rez *= (d1 == d2) ? rez : 0; } if (rez == 1) { next = (int) Math.pow(Math.round(Math.pow(mas[n - 1], 1 / 3.)) + d1 / 1000000, 3); break; } } return next; }
public Item buildMyThing(MOB mob, Room room) { Area A = room.getArea(); boolean bonusWorthy = (Druid_MyPlants.myPlant(room, mob, 0) == null); Vector V = Druid_MyPlants.myAreaPlantRooms(mob, room.getArea()); int pct = 0; if (A.getAreaIStats()[Area.Stats.VISITABLE_ROOMS.ordinal()] > 10) pct = (int) Math.round( 100.0 * CMath.div( V.size(), A.getAreaIStats()[Area.Stats.VISITABLE_ROOMS.ordinal()])); Item I = buildMyPlant(mob, room); if ((I != null) && ((mob.charStats().getCurrentClass().baseClass().equalsIgnoreCase("Druid")) || (CMSecurity.isASysOp(mob)))) { if (!CMLib.law().isACity(A)) { if (pct > 0) { int newPct = (int) Math.round( 100.0 * CMath.div( V.size(), A.getAreaIStats()[Area.Stats.VISITABLE_ROOMS.ordinal()])); if ((newPct >= 50) && (A.fetchEffect("Chant_DruidicConnection") == null)) { Ability A2 = CMClass.getAbility("Chant_DruidicConnection"); if (A2 != null) A2.invoke(mob, A, true, 0); } } } else if ((bonusWorthy) && (!mob.isMonster())) { long[] num = (long[]) plantBonuses.get(mob.Name() + "/" + room.getArea().Name()); if ((num == null) || (System.currentTimeMillis() - num[1] > (room.getArea().getTimeObj().getDaysInMonth() * room.getArea().getTimeObj().getHoursInDay() * CMProps.getMillisPerMudHour()))) { num = new long[2]; plantBonuses.remove(mob.Name() + "/" + room.getArea().Name()); plantBonuses.put(mob.Name() + "/" + room.getArea().Name(), num); num[1] = System.currentTimeMillis(); } if (V.size() >= num[0]) { num[0]++; if (num[0] < 19) { mob.tell("You have made this city greener."); CMLib.leveler().postExperience(mob, null, null, (int) num[0], false); } } } } return I; }
protected boolean canSpawnStructureAtCoords(int par1, int par2) { if (!ranBiomeCheck) { Random random = new Random(); random.setSeed(worldObj.getSeed()); double d = random.nextDouble() * Math.PI * 2D; for (int k = 0; k < structureCoords.length; k++) { double d1 = (1.25D + random.nextDouble()) * 32D; int l = (int) Math.round(Math.cos(d) * d1); int i1 = (int) Math.round(Math.sin(d) * d1); ArrayList arraylist = new ArrayList(); Collections.addAll(arraylist, allowedBiomeGenBases); ChunkPosition chunkposition = worldObj .getWorldChunkManager() .findBiomePosition((l << 4) + 8, (i1 << 4) + 8, 112, arraylist, random); if (chunkposition != null) { l = chunkposition.x >> 4; i1 = chunkposition.z >> 4; } else { System.out.println( (new StringBuilder()) .append("Placed stronghold in INVALID biome at (") .append(l) .append(", ") .append(i1) .append(")") .toString()); } structureCoords[k] = new ChunkCoordIntPair(l, i1); d += (Math.PI * 2D) / (double) structureCoords.length; } ranBiomeCheck = true; } ChunkCoordIntPair achunkcoordintpair[] = structureCoords; int i = achunkcoordintpair.length; for (int j = 0; j < i; j++) { ChunkCoordIntPair chunkcoordintpair = achunkcoordintpair[j]; if (par1 == chunkcoordintpair.chunkXPos && par2 == chunkcoordintpair.chunkZPosition) { System.out.println((new StringBuilder()).append(par1).append(", ").append(par2).toString()); return true; } } return false; }
public static BufferedImage scaleImage(BufferedImage bi, double scale) { int w1 = (int) (Math.round(scale * bi.getWidth())); int h1 = (int) (Math.round(scale * bi.getHeight())); BufferedImage image = new BufferedImage(w1, h1, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.setPaint(Color.white); g2.fillRect(0, 0, w1, h1); g2.drawImage(bi, 0, 0, w1, h1, null); // this); g2.dispose(); return image; }
public String renderLine(int prefixLength) { long millis = Math.round(this.runtime / 1000000); Formatter formatter = new java.util.Formatter(); Object[] args = new Object[] { Integer.valueOf((int) millis), Integer.valueOf(Math.round(millis / invocations)), Integer.valueOf(invocations), name.substring(prefixLength) }; formatter.format("%1$7d ms %2$5d ms %3$6d %4$s%n", args); return formatter.toString(); }
/** Creates Gaussian derivative kernels. */ private void makeKernels2D() { int xkDim, ykDim; int[] derivOrder = new int[2]; kExtents = new int[2]; derivOrder[0] = 2; derivOrder[1] = 0; xkDim = Math.round(8 * sigmas[0]); if ((xkDim % 2) == 0) { xkDim++; } if (xkDim < 3) { xkDim = 3; } kExtents[0] = xkDim; ykDim = Math.round(8 * sigmas[1]); if ((ykDim % 2) == 0) { ykDim++; } if (ykDim < 3) { ykDim = 3; } kExtents[1] = ykDim; GxxData = new float[xkDim * ykDim]; GenerateGaussian Gxx = new GenerateGaussian(GxxData, kExtents, sigmas, derivOrder); Gxx.calc(false); Gxx.finalize(); Gxx = null; derivOrder[0] = 0; derivOrder[1] = 2; GyyData = new float[xkDim * ykDim]; GenerateGaussian Gyy = new GenerateGaussian(GyyData, kExtents, sigmas, derivOrder); Gyy.calc(false); Gyy.finalize(); Gyy = null; }
protected boolean canSpawnStructureAtCoords(int i, int j) { if (!ranBiomeCheck) { rand.setSeed(worldObj.getWorldSeed()); double d = rand.nextDouble() * 3.1415926535897931D * 2D; for (int l = 0; l < structureCoords.length; l++) { double d1 = (1.25D + rand.nextDouble()) * 32D; int j1 = (int) Math.round(Math.cos(d) * d1); int k1 = (int) Math.round(Math.sin(d) * d1); ArrayList arraylist = new ArrayList(); BiomeGenBase abiomegenbase[] = allowedBiomeGenBases; int l1 = abiomegenbase.length; for (int i2 = 0; i2 < l1; i2++) { BiomeGenBase biomegenbase = abiomegenbase[i2]; arraylist.add(biomegenbase); } ChunkPosition chunkposition = worldObj .getWorldChunkManager() .func_35556_a((j1 << 4) + 8, (k1 << 4) + 8, 112, arraylist, rand); if (chunkposition != null) { j1 = chunkposition.x >> 4; k1 = chunkposition.z >> 4; } else { System.out.println( (new StringBuilder()) .append("Placed stronghold in INVALID biome at (") .append(j1) .append(", ") .append(k1) .append(")") .toString()); } structureCoords[l] = new ChunkCoordIntPair(j1, k1); d += 6.2831853071795862D / (double) structureCoords.length; } ranBiomeCheck = true; } ChunkCoordIntPair achunkcoordintpair[] = structureCoords; int k = achunkcoordintpair.length; for (int i1 = 0; i1 < k; i1++) { ChunkCoordIntPair chunkcoordintpair = achunkcoordintpair[i1]; if (i == chunkcoordintpair.chunkXPos && j == chunkcoordintpair.chunkZPos) { return true; } } return false; }
/** * Конвертация строки типа: 5 Minutes * * @param str * @return */ private static int parseDuration(String str) throws ParseException { int idx = str.indexOf(' '); float num = DF.parse(str.substring(0, idx)).floatValue(); switch (str.substring(idx + 1)) { case "Seconds": return Math.round(num); case "Minutes": return Math.round(num * 60); default: throw new ParseException("Неизвестный формат единиц: " + str, idx + 1); } }
/* move the ball */ public void move(ArrayList movingObjects, int objectCounter) { // EFFECT OF GRAVITY gravityEffect(movingObjects); // MOVE pos_x += Math.round(x_speed); pos_y += Math.round(y_speed); // IS BALL OUT OF BOUNDS? isOut(); // HAS BALL COLLIDED WITH ANYTHING? objectCollision(movingObjects); }
private void loadHint(TTGlyph a_glyph, EContourPoint a_point, int a_index) { double x = a_point.getX(); double y = a_point.getY(); XHint[] hints = a_point.getHint(); for (int i = 0; i < hints.length; i++) { EHint hint = (EHint) hints[i]; double xHint = hint.getX(); double yHint = hint.getY(); if (x == xHint && y == yHint) { continue; } // if double xDelta = xHint - x; double yDelta = yHint - y; int instruction = TTGlyph.DELTAP1; double deltaStep = ((double) Engine.getEm()) / hint.getPpem() / 8; int xShift = (int) Math.round(xDelta / deltaStep); int yShift = (int) Math.round(yDelta / deltaStep); if (xShift == 0 && yShift == 0) { continue; } // if a_glyph.addInstruction(TTGlyph.PUSHB000); a_glyph.addInstruction((int) hint.getPpem()); a_glyph.addInstruction(TTGlyph.SDB); if (xShift != 0) { a_glyph.addInstruction(TTGlyph.SVTCA1); a_glyph.addInstruction(TTGlyph.PUSHB010); a_glyph.addInstruction(TTGlyph.toDeltaArg(0, xShift)); a_glyph.addInstruction(a_index); a_glyph.addInstruction(1); a_glyph.addInstruction(TTGlyph.DELTAP1); } // if if (yShift != 0) { a_glyph.addInstruction(TTGlyph.SVTCA0); a_glyph.addInstruction(TTGlyph.PUSHB010); a_glyph.addInstruction(TTGlyph.toDeltaArg(0, yShift)); a_glyph.addInstruction(a_index); a_glyph.addInstruction(1); a_glyph.addInstruction(TTGlyph.DELTAP1); } // if } // for i }
/** * Currently we will arbitrarily choose the first node that is not a destination i.e. it's a * starting point\ if none such exists we will choose a random node. * * @param entitiesList * @param relationshipsList */ private InternalNode getFirstEntity( List<InternalNode> entitiesList, List<InternalRelationship> relationshipsList) { List<InternalNode> entitiesLeft = new ArrayList<InternalNode>(entitiesList); // go through all the relationships and remove destination nodes for (InternalRelationship rel : relationshipsList) { entitiesLeft.remove(rel.getDestination()); } if (!entitiesLeft.isEmpty()) { // TODO throw in random for fun of it return entitiesLeft.get((int) (Math.round(Math.random() * (entitiesLeft.size() - 1)))); } // if all the nodes were destination nodes then return a random node. return entitiesList.get((int) (Math.round(Math.random() * (entitiesList.size() - 1)))); }
public DVector parseLootPolicyFor(MOB mob) { if (mob == null) return new DVector(3); Vector lootPolicy = (!mob.isMonster()) ? new Vector() : CMParms.parseCommas(CMProps.getVar(CMProps.SYSTEM_ITEMLOOTPOLICY), true); DVector policies = new DVector(3); for (int p = 0; p < lootPolicy.size(); p++) { String s = ((String) lootPolicy.elementAt(p)).toUpperCase().trim(); if (s.length() == 0) continue; Vector compiledMask = null; int maskDex = s.indexOf("MASK="); if (maskDex >= 0) { s = s.substring(0, maskDex).trim(); compiledMask = CMLib.masking() .maskCompile(((String) lootPolicy.elementAt(p)).substring(maskDex + 5).trim()); } else compiledMask = new Vector(); Vector parsed = CMParms.parse(s); int pct = 100; for (int x = 0; x < parsed.size(); x++) if (CMath.isInteger((String) parsed.elementAt(x))) pct = CMath.s_int((String) parsed.elementAt(x)); else if (CMath.isPct((String) parsed.elementAt(x))) pct = (int) Math.round(CMath.s_pct((String) parsed.elementAt(x)) * 100.0); int flags = 0; if (parsed.contains("RUIN")) flags |= CMMiscUtils.LOOTFLAG_RUIN; else if (parsed.contains("LOSS")) flags |= CMMiscUtils.LOOTFLAG_LOSS; if (flags == 0) flags |= CMMiscUtils.LOOTFLAG_LOSS; if (parsed.contains("WORN")) flags |= CMMiscUtils.LOOTFLAG_WORN; else if (parsed.contains("UNWORN")) flags |= CMMiscUtils.LOOTFLAG_UNWORN; policies.addElement(Integer.valueOf(pct), Integer.valueOf(flags), compiledMask); } return policies; }
public Trap makeADeprecatedTrap(Environmental unlockThis) { Trap theTrap = null; int roll = (int) Math.round(Math.random() * 100.0); if (unlockThis instanceof Exit) { if (((Exit) unlockThis).hasADoor()) { if (((Exit) unlockThis).hasALock()) { if (roll < 20) theTrap = (Trap) CMClass.getAbility("Trap_Open"); else if (roll < 80) theTrap = (Trap) CMClass.getAbility("Trap_Unlock"); else theTrap = (Trap) CMClass.getAbility("Trap_Enter"); } else { if (roll < 50) theTrap = (Trap) CMClass.getAbility("Trap_Open"); else theTrap = (Trap) CMClass.getAbility("Trap_Enter"); } } else theTrap = (Trap) CMClass.getAbility("Trap_Enter"); } else if (unlockThis instanceof Container) { if (((Container) unlockThis).hasALid()) { if (((Container) unlockThis).hasALock()) { if (roll < 20) theTrap = (Trap) CMClass.getAbility("Trap_Open"); else if (roll < 80) theTrap = (Trap) CMClass.getAbility("Trap_Unlock"); else theTrap = (Trap) CMClass.getAbility("Trap_Get"); } else { if (roll < 50) theTrap = (Trap) CMClass.getAbility("Trap_Open"); else theTrap = (Trap) CMClass.getAbility("Trap_Get"); } } else theTrap = (Trap) CMClass.getAbility("Trap_Get"); } else if (unlockThis instanceof Item) theTrap = (Trap) CMClass.getAbility("Trap_Get"); return theTrap; }
@Override public void affectCharStats(MOB affected, CharStats affectableStats) { super.affectCharStats(affected, affectableStats); affectableStats.setStat( CharStats.STAT_STRENGTH, (int) Math.round(CMath.div(affectableStats.getStat(CharStats.STAT_STRENGTH), 2.0))); }