@Override public int deleteAll(Class<?> claxx) { acquireReference(); try { SQLiteDatabase db = mHelper.getWritableDatabase(); SQLStatement stmt = SQLBuilder.buildDeleteAllSql(claxx); int num = stmt.execDelete(db); // 删除关系映射 final MapInfo mapTable = SQLBuilder.buildDelAllMappingSql(claxx); if (mapTable != null && !mapTable.isEmpty()) { Transaction.execute( db, new Worker<Boolean>() { @Override public Boolean doTransaction(SQLiteDatabase db) throws Exception { if (mapTable.delOldRelationSQL != null) { for (SQLStatement st : mapTable.delOldRelationSQL) { long rowId = st.execDelete(db); if (Log.isPrint) { Log.i(TAG, "Exec delete mapping success, nums: " + rowId); } } } return true; } }); } return num; } catch (Exception e) { e.printStackTrace(); } finally { releaseReference(); } return SQLStatement.NONE; }
PlayerAction AI_beta() { MapInfo mi = env.getMapInfo(); Point p = env.getPlayerInfo().getLocation(); CharaInfo pi = env.getPlayerInfo(); // if (mi.getNeedingSpellCount(env.getPlayerInfo(), p) == 0) { SpellPos minSpellPos = null; if (pumpkinX) { List<PumpkinInfo> plist = env.getEnemyInfo().getPumpkinInfos(); for (PumpkinInfo pinfo : plist) { Point pp = pinfo.getCenterLocation(); int point; if (pinfo.getType() == PumpkinType.KingPumpkin) point = 50; else point = 20; SpellPos nsp = new SpellPos(pp, -point); minSpellPos = min(minSpellPos, nsp); } // List<Point> plist2 = PumpkinType.MiniPumpkin.getMineLocations(); // debug(plist2.toArray()); // for (Point pp : plist2) { // SpellPos nsp = new SpellPos(pp, -20); // // if (minSpellPos == null) // // minSpellPos = nsp; // // if (minSpellPos.compareTo(nsp) > 0) // // minSpellPos = nsp; // // if (minSpellPos.compareTo(nsp) == 0 && Math.random() < 0.5) // // minSpellPos = nsp; // minSpellPos = min(minSpellPos, nsp); // } } for (int i = 0; i < mi.getWidth(); i++) { for (int j = 0; j < mi.getHeight(); j++) { Point pp = new Point(i, j); if (mi.getNeedingSpellCount(pi, pp) > 0) { SpellPos nsp = new SpellPos(pp, ((i + j + 1) % 2) * 400); minSpellPos = min(minSpellPos, nsp); } if (pampkinMakable(pp)) { SpellPos nsp = new SpellPos(pp, -20); minSpellPos = min(minSpellPos, nsp); } } } if (minSpellPos == null) return PlayerAction.NONE; if (minSpellPos.ds.length == 0) return PlayerAction.SPELL; return minSpellPos.ds[0].toPlayerAction(); // } else { // return PlayerAction.SPELL; // } }
/** Places a unit in the desired area. */ @Override public void updateDOM(MapInfo mapInfo) { // if we are not displayable, we exit, after remove the order (if // it was created) if (!GUIOrderUtils.isDisplayable(power, mapInfo)) { removeFromDOM(mapInfo); return; } // determine if any change has occured. If no change has occured, // we will not change the DOM. // // we have nothing (yet) to check for change; isDependent() == false. // so just return if we have not been drawn. if (group != null) { return; } // there has been a change, if we are at this point. // // if we've not yet been created, we will create; if we've // already been created, we must remove the existing elements // in our group if (group == null) { // create group group = (SVGGElement) mapInfo .getDocument() .createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, SVGConstants.SVG_G_TAG); mapInfo.getPowerSVGGElement(power, LAYER_HIGHEST).appendChild(group); } else { // remove group children GUIOrderUtils.deleteChildren(group); } // now, render the order // (no highlight + shadow required here) // no offset required // SVGElement[] elements = drawOrder(mapInfo); for (int i = 0; i < elements.length; i++) { group.appendChild(elements[i]); } // draw 'failed' marker, if appropriate. if (!mapInfo.getTurnState().isOrderSuccessful(this)) { SVGElement useElement = GUIOrderUtils.createFailedOrderSymbol(mapInfo, failPt.x, failPt.y); group.appendChild(useElement); } } // updateDOM()
@Override public ArrayList<GridCell> unexpandedNodes() { ArrayList<GridCell> open = new ArrayList<GridCell>(); ArrayList<GridCell> closed = new ArrayList<GridCell>(); if (mapinfo != null) { Trace.print("Closed Set has" + mapinfo.closedCount() + " entries"); // Need to make this open/closed query into singleton style - it iterates through every tile // twice, due // to being called at expanded nodes too!! mapinfo.GetSearchSetsAsArrayList(open, closed); } return (open); }
ArrayList<Point> getPPos() { MapInfo mi = env.getMapInfo(); ArrayList<Point> r = new ArrayList<Point>(); for (int i = 1; i < mi.getWidth() - 1; i++) { for (int j = 1; j < mi.getHeight() - 1; j++) { if (isWritable(new Point(i, j)) && isWritable(new Point(i, j - 1)) && isWritable(new Point(i, j + 1)) && isWritable(new Point(i - 1, j)) && isWritable(new Point(i + 1, j))) { r.add(new Point(i, j)); } } } return r; }
@Override public void removeFromDOM(MapInfo mapInfo) { if (group != null) { SVGGElement powerGroup = mapInfo.getPowerSVGGElement(power, LAYER_HIGHEST); GUIOrderUtils.removeChild(powerGroup, group); group = null; } } // removeFromDOM()
private ComputedPlan generatePlan(GridDomain map, GridCell start, GridCell goal) { mapinfo = new MapInfo(map); // initialize open set with start node mapinfo.add(start, 0f, map.hCost(start, goal)); // repeat while states are left in open set while (mapinfo.isOpenEmpty() == false) { GridCell current = mapinfo.closeCheapestOpen(); // timer.getCurrentNanotime(); // timer.getCurrentNanotime(); // timer.getCurrentNanotime(); Trace.print(current); // if goal has been reached, return path if (current == goal) { Trace.print("found goal!"); return mapinfo.computePlan(goal); } // iterate through neighboring nodes for (State neighbor : map.getSuccessors(current)) { // threadMX.getCurrentThreadCpuTime(); // threadMX.getCurrentThreadCpuTime(); // threadMX.getCurrentThreadCpuTime(); // consider node if it can be entered and is not in closed list if (map.isBlocked(neighbor) == false && mapinfo.isClosed((GridCell) neighbor) == false) { // get g cost of neighbor float gCost = mapinfo.getGCost(current) + map.cost(current, neighbor); if (mapinfo.isOpen((GridCell) neighbor) == false) { // node not previously encountered, add it to the open set mapinfo.add((GridCell) neighbor, gCost, map.hCost(neighbor, goal), current); } else if (gCost < mapinfo.getGCost((GridCell) neighbor)) { // more direct route to node found, update it // NOTE: this can never happen with an admissible heuristic! // System.out.println("failing now..." + gCost + " < " + mapinfo.getGCost((GridCell) // neighbor)); // mapInfo.setGCost(neighbor, gCost); // mapInfo.setParent(neighbor, current); } } } } // no goal found return null; }
/** Get byte array of packet data to send to players on map for updating map data */ public byte[] getUpdatePacketData( ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { byte[] result; // CartoCraft - Adds the custom icons to the packet data sent to players if (!this.customIconsSent && this.customIcons.size() > 0) { byte[] ibyte = new byte[this.customIcons.size() * 3 + 1]; ibyte[0] = customIconPacketId; // The first byte of the array indicates the type of data returned. (0 // = map, 1 = players, 2 = scale) int j = 0; for (Iterator iterator = this.customIcons.values().iterator(); iterator.hasNext(); ++j) { MapCoord mapcoord = (MapCoord) iterator.next(); ibyte[j * 3 + 1] = mapcoord.iconSize; ibyte[j * 3 + 2] = mapcoord.centerX; ibyte[j * 3 + 3] = mapcoord.centerZ; } result = ibyte; this.customIconsSent = true; } else { // Vanilla code MapInfo mapinfo = (MapInfo) this.playersHashMap.get(par3EntityPlayer); result = mapinfo == null ? null : mapinfo.getPlayersOnMap(par1ItemStack); } // Debug /* System.out.println("MapData.getUpdatePacketData - " + cpw.mods.fml.common.FMLCommonHandler.instance().getEffectiveSide()); System.out.println(" Icons: " + this.customIcons.size()); if (result != null) { System.out.print(" Result: "); for (int i = 0; i < result.length; i++) { System.out.print("[" + result[i] + "]"); } System.out.println(""); } */ return result; }
/** * @param request _more_ * @param entry _more_ * @param map _more_ * @return _more_ */ @Override public boolean addToMap(Request request, Entry entry, MapInfo map) { try { if (!entry.isFile()) { return true; } // TODO: stream through the shapes EsriShapefile shapefile = new EsriShapefile(entry.getFile().toString()); List features = shapefile.getFeatures(); int totalPoints = 0; int MAX_POINTS = 10000; for (int i = 0; i < features.size(); i++) { if (totalPoints > MAX_POINTS) { break; } EsriShapefile.EsriFeature gf = (EsriShapefile.EsriFeature) features.get(i); java.util.Iterator pi = gf.getGisParts(); while (pi.hasNext()) { if (totalPoints > MAX_POINTS) { break; } GisPart gp = (GisPart) pi.next(); double[] xx = gp.getX(); double[] yy = gp.getY(); List<double[]> points = new ArrayList<double[]>(); for (int ptIdx = 0; ptIdx < xx.length; ptIdx++) { points.add(new double[] {yy[ptIdx], xx[ptIdx]}); } totalPoints += points.size(); if (points.size() > 1) { map.addLines("", points); } else if (points.size() == 1) { map.addMarker("id", points.get(0)[0], points.get(0)[1], null, ""); } } } } catch (Exception exc) { throw new RuntimeException(exc); } return false; }
static TypeInfo of(FieldValueMetaData fieldValueMetaData, Map<String, String> docStrings) { if (fieldValueMetaData instanceof StructMetaData) { return StructInfo.of((StructMetaData) fieldValueMetaData, docStrings); } if (fieldValueMetaData instanceof EnumMetaData) { return EnumInfo.of((EnumMetaData) fieldValueMetaData, docStrings); } if (fieldValueMetaData instanceof ListMetaData) { return ListInfo.of((ListMetaData) fieldValueMetaData, docStrings); } if (fieldValueMetaData instanceof SetMetaData) { return SetInfo.of((SetMetaData) fieldValueMetaData, docStrings); } if (fieldValueMetaData instanceof MapMetaData) { return MapInfo.of((MapMetaData) fieldValueMetaData, docStrings); } return new TypeInfo(ValueType.of(fieldValueMetaData.type), fieldValueMetaData.isBinary()); }
private SVGElement[] drawOrder(MapInfo mapInfo) { MapMetadata mmd = mapInfo.getMapMetadata(); Point2D.Float center = mmd.getUnitPt(src.getProvince(), src.getCoast()); // get 'integer' and float data float radius = mmd.getOrderRadius(MapMetadata.EL_BUILD, mapInfo.getSymbolName(srcUnitType)); // calculate failPt. failPt = new Point2D.Float(center.x + radius, center.y - radius); // A BUILD consists of the Built Unit ontop of a BuildUnit symbol // elements added in drawing order (thus BuildUnit must come first, // otherwise the unit built will be obscured by the BuilUnit symbol). // SVGElement[] elements = new SVGElement[2]; // BuildUnit symbol MapMetadata.SymbolSize symbolSize = mmd.getSymbolSize(DefaultMapRenderer2.SYMBOL_BUILDUNIT); elements[0] = SVGUtils.createUseElement( mapInfo.getDocument(), "#" + DefaultMapRenderer2.SYMBOL_BUILDUNIT, null, // no ID null, // no special style center.x, center.y, symbolSize); // Unit symbol final String symbolName = mapInfo.getSymbolName(srcUnitType); symbolSize = mmd.getSymbolSize(symbolName); elements[1] = SVGUtils.createUseElement( mapInfo.getDocument(), "#" + symbolName, null, // no ID mapInfo.getUnitCSS(power), // unit style center.x, center.y, symbolSize); return elements; } // drawOrder()
boolean isWritable(Point p) { MapInfo mi = env.getMapInfo(); return mi.isMovable(p) && !mi.isLocked(p); }
public CustomIndoorMapLayoutView(Context context) { super(context); // reading map infor from file IndoorMapReader mapReader = new IndoorMapReader(context, "ZurnMap.xml"); mapReader.readFileToString(); mapInfo = mapReader.getrMapInfo(); // processing all objects to be drawn in the room for (int i = 0; i < mapInfo.getNumberOfObjects(); i++) { IndoorMapObject indoorMapObject = mapInfo.getObject(i); if (indoorMapObject.getDescription().equalsIgnoreCase("room 343")) { room343_x = indoorMapObject.getStartPosition().x; room343_y = indoorMapObject.getStartPosition().y; roomSize = indoorMapObject.getWidth(); Log.d("TTT", "test1"); } else if (indoorMapObject.getDescription().equalsIgnoreCase("room 344")) { room344_x = indoorMapObject.getStartPosition().x; room344_y = indoorMapObject.getStartPosition().y; roomSize = indoorMapObject.getWidth(); Log.d("TTT", "test2"); } else if (indoorMapObject.getDescription().equalsIgnoreCase("room 340")) { room340_x = indoorMapObject.getStartPosition().x; room340_y = indoorMapObject.getStartPosition().y; roomSize = indoorMapObject.getWidth(); Log.d("TTT", "test3"); } else if (indoorMapObject.getDescription().equalsIgnoreCase("Hallway1")) { hallway1_x = indoorMapObject.getStartPosition().x; hallway1_y = indoorMapObject.getStartPosition().y; hallway1Width = indoorMapObject.getWidth(); hallway1Height = indoorMapObject.getHeight(); Log.d("TTT", "test4"); } else if (indoorMapObject.getDescription().equalsIgnoreCase("Hallway")) { hallway2_x = indoorMapObject.getStartPosition().x; hallway2_y = indoorMapObject.getStartPosition().y; hallway2Width = indoorMapObject.getWidth(); hallway2Height = indoorMapObject.getHeight(); Log.d("TTT", "test5"); } } // detector = new ScaleGestureDetector(getContext(), new ScaleListener()); // initializing array list of draw objects // listOfDrawObjects = new ArrayList<IndoorMapObject>(); locationIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.dot2); wifiIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.wifiicon); DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); width = metrics.widthPixels; height = metrics.heightPixels; if (width > 1000) { Log.d("CView", "width < 1000"); roomSize = roomSize * 2; hallway1Width = hallway1Width * 2; hallway1Height = hallway1Height * 2; hallway2Width = hallway2Width * 2; hallway2Height = hallway2Height * 2; } initObjectLengths(); setWillNotDraw(false); paint.setColor(Color.LTGRAY); }
/** * Writes the systems byte order to the out stream. In java only high byte first. * * @param out the stream to write to * @param rasterDataNode */ private static void writeMapProjectionInfo(PrintWriter out, RasterDataNode rasterDataNode) { Product product = rasterDataNode.getProduct(); if (product == null) { return; } String mapProjectionName = "Arbitrary"; String mapUnits = "Meters"; double referencePixelX = 0, referencePixelY = 0; double easting = 0, northing = 0; double pixelSizeX = 0, pixelSizeY = 0; String datumName = ""; int utmZone = -1; String utmHemisphere = ""; MapProjection mapProjection = null; if (product.getGeoCoding() instanceof CrsGeoCoding) { final CrsGeoCoding crsGeoCoding = (CrsGeoCoding) product.getGeoCoding(); final CoordinateReferenceSystem crs = crsGeoCoding.getMapCRS(); final ImageGeometry imgGeom = ImageGeometry.createTargetGeometry( product, crs, null, null, null, null, null, null, null, null, null); final String crsName = crs.getName().toString().toUpperCase(); if (crsName.equals("WGS84(DD)")) { mapProjectionName = "Geographic Lat/Lon"; mapUnits = "Degrees"; } else if (crsName.contains("UTM")) { mapProjectionName = "UTM"; String zoneStr = crsName.substring(crsName.indexOf("ZONE") + 5, crsName.length()).trim(); int i = 0; String zoneNumStr = ""; while (Character.isDigit(zoneStr.charAt(i))) { zoneNumStr += zoneStr.charAt(i++); } utmZone = Integer.parseInt(zoneNumStr); GeoPos centrePos = crsGeoCoding.getGeoPos( new PixelPos(product.getSceneRasterWidth() / 2, product.getSceneRasterHeight() / 2), null); utmHemisphere = centrePos.getLat() > 0 ? "North" : "South"; } referencePixelX = imgGeom.getReferencePixelX(); referencePixelY = imgGeom.getReferencePixelY(); easting = imgGeom.getEasting(); northing = imgGeom.getNorthing(); pixelSizeX = imgGeom.getPixelSizeX(); pixelSizeY = imgGeom.getPixelSizeY(); datumName = crsGeoCoding.getDatum().getName(); } else if (product.getGeoCoding() instanceof MapGeoCoding) { final MapGeoCoding mapGeoCoding = (MapGeoCoding) product.getGeoCoding(); final MapInfo info = mapGeoCoding.getMapInfo(); if (info == null) { return; } mapProjection = info.getMapProjection(); if (mapProjection instanceof UTMProjection) { mapProjectionName = "UTM"; final UTMProjection utmProjection = (UTMProjection) mapProjection; utmZone = utmProjection.getZone(); utmHemisphere = utmProjection.isNorth() ? "North" : "South"; } else if (mapProjection.isPreDefined()) { mapProjectionName = mapProjection.getName(); } if ("meter".equals(mapProjection.getMapUnit())) { mapUnits = "Meters"; } else if ("degree".equals(mapProjection.getMapUnit())) { mapUnits = "Degrees"; } else { mapUnits = mapProjection.getMapUnit(); } datumName = mapGeoCoding.getDatum().getName(); } else { return; } out.print(_enviMapInfo); out.print(" = {"); out.print(mapProjectionName); out.print(","); out.print(referencePixelX + 1.0f); out.print(","); out.print(referencePixelY + 1.0f); out.print(","); out.print(easting); out.print(","); out.print(northing); out.print(","); out.print(pixelSizeX); out.print(","); out.print(pixelSizeY); out.print(","); if (utmZone != -1) { out.print(utmZone); out.print(","); out.print(utmHemisphere); out.print(","); } out.print(datumName); out.print(","); out.print("units=" + mapUnits); out.print("}"); out.println(); if (mapProjection != null && !mapProjection.isPreDefined()) { final MapTransform mapTransform = mapProjection.getMapTransform(); final double[] parameterValues = mapTransform.getParameterValues(); final String transformName = mapTransform.getDescriptor().getName(); out.print(_enviProjectionInfo); out.print(" = {"); if (transformName.equals(TransverseMercatorDescriptor.NAME)) { out.print(3); out.print(","); out.print(parameterValues[0]); // semi_major (meters) out.print(","); out.print(parameterValues[1]); // semi_minor (meters) out.print(","); out.print(parameterValues[2]); // latitude_of_origin (degree) out.print(","); out.print(parameterValues[3]); // central_meridian (degree) out.print(","); out.print(parameterValues[5]); // false_easting (meters) out.print(","); out.print(parameterValues[6]); // false_northing (meters) out.print(","); out.print(parameterValues[4]); // scaling_factor (no unit) out.print(","); } else if (transformName.equals(LambertConformalConicDescriptor.NAME)) { out.print(4); out.print(","); out.print(parameterValues[0]); // semi_major (meters) out.print(","); out.print(parameterValues[1]); // semi_minor (meters) out.print(","); out.print(parameterValues[2]); // latitude_of_origin (degree) out.print(","); out.print(parameterValues[3]); // central_meridian (degree) out.print(","); out.print(0.0); // false_easting (meters) out.print(","); out.print(0.0); // false_northing (meters) out.print(","); out.print(parameterValues[4]); // latitude_of_intersection_1 (meters) out.print(","); out.print(parameterValues[5]); // latitude_of_intersection_2 (meters) out.print(","); } out.print(mapProjectionName); out.print(","); out.print("units=" + mapUnits); out.print("}"); out.println(); } }
/** Get byte array of packet data to send to players on map for updating map data */ public byte[] getUpdatePacketData( ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { MapInfo var4 = (MapInfo) this.playersHashMap.get(par3EntityPlayer); return var4 == null ? null : var4.getPlayersOnMap(par1ItemStack); }
private boolean doWork(MapLocation dest, int priority, int stopWhen, int page) throws GameActionException { if (!dest.equals(previousDest)) { initQueue(dest); System.out.print( "Cleanser BFS to " + dest + ", page " + page + ", start round " + Clock.getRoundNum() + "\n"); } previousDest = dest; previousPage = page; previousRoundWorked = Clock.getRoundNum(); int emptyCount = 0; while (emptyCount < NUM_QUEUES && qHeads[currentQ] == qTails[currentQ]) { // Skip over empty queues emptyCount++; currentQ = (currentQ + 1) % NUM_QUEUES; } if (emptyCount == NUM_QUEUES) return true; // Finished while (Clock.getBytecodesLeft() > stopWhen) { // pop a location from the queue int data = locQueues[qHeads[currentQ]]; int locX = data >> 24; int locY = (data >> 16) & 0xff; double delay = (data & 0xffff) / 10; if (++qHeads[currentQ] % MAX_QUEUE_SIZE == 0) qHeads[currentQ] -= MAX_QUEUE_SIZE; for (int i = 8; i-- > 0; ) { int x = cropX(locX + dirsX[i]); int y = cropY(locY + dirsY[i]); boolean isDiagonal = (i <= 3); if (!processed[x][y]) { processed[x][y] = true; TerrainTile t = map.tile(x, y); if (t.isTraversable()) { MapLocation newLoc = new MapLocation(x, y); // push newLoc onto queue - pick queue according to how long the move takes double newDelay; if (isDiagonal) newDelay = diagonalDelay; else newDelay = moveDelay; int newQ = (currentQ + (int) (newDelay + (delay % 1))) % NUM_QUEUES; newDelay += delay; locQueues[qTails[newQ]] = (x << 24) | (y << 16) | (int) (newDelay * 10); if (++qTails[newQ] % MAX_QUEUE_SIZE == 0) qTails[newQ] -= MAX_QUEUE_SIZE; // System.out.print("Adding " + x + ", " + y + " to queue " + newQ + " element " + // qTails[newQ] + "\n"); publishResult(page, newLoc, dest, dirs[i], (int) newDelay); } else if (t == TerrainTile.UNKNOWN) containsUnknowns = true; } } emptyCount = 0; while (emptyCount < NUM_QUEUES && qHeads[currentQ] == qTails[currentQ]) { // Skip over empty queues emptyCount++; currentQ = (currentQ + 1) % NUM_QUEUES; } if (emptyCount == NUM_QUEUES) { // map.dump(); break; } } writePageMetadata(page, previousRoundWorked, dest, priority, (emptyCount == NUM_QUEUES)); return (emptyCount == NUM_QUEUES && containsUnknowns == false); }