/// <summary> /// Returns an array with a heightmap on it /// </summary> /// <param name="lon">longitude</param> /// <param name="lat">latitude</param> /// <returns></returns> public static Texture2D getHeight(GCS target, int zoom) { Texture2D tex; using (WebClient client = new WebClient()) { // Zoom levels (zxy): // http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames // World APIs: // http://a.tile.stamen.com/terrain-background/12/656/1582.png // https://tile.mapzen.com/mapzen/terrain/v1/terrarium/12/656/1582.png?api_key=mapzen-HgL87jY" /// Tile that containts the given Longitude and Latitude. GCS tile = WorldToTilePos(target.lon, target.lat, zoom); tile.lon = (float)Math.Floor(tile.lon); tile.lat = (float)Math.Floor(tile.lat); // TODO change tile.lon and tile.lat for chunk.x and chunk.z //Int3 chunk = mapZenChunk(target.lon, target.lat, zoom); string url = "https://tile.mapzen.com/mapzen/terrain/v1/terrarium/" + zoom.ToString() + "/" + tile.lon.ToString() + "/" + tile.lat.ToString() + ".png?api_key=" + UVariables.mapzenAPIKey; ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback; byte[] pngData = client.DownloadData(url); tex = new Texture2D(256, 256); tex.LoadImage(pngData); tex.Apply(); } return(tex); }
public Diffuse(GCS _unit, int _emptySlot) { unit = _unit; emptySlot = _emptySlot; candidates = new List <CoverSpotCandidate>(); firstRandomPos = new Vector3(-1f, -1f, -1f); }
public TakeCover(GCS _unit, int _emptySlot) { emptySlot = _emptySlot; unit = _unit; previousTarget = new Vector3(-1f, -1f, -1f); candidates = new List <CoverSpotCandidate>(); }
void IContextMenu.GetCommandString(uint idcmd, GCS uflags, uint reserved, IntPtr commandstring, int cchMax) { string tip = ""; switch (uflags) { case GCS.VERB: break; case GCS.HELPTEXTW: switch (idcmd) { case 0: tip = "上传"; break; case 1: tip = "下载"; break; case 2: tip = "查看"; break; default: break; } if (!string.IsNullOrEmpty(tip)) { byte[] data = new byte[cchMax * 2]; Encoding.Unicode.GetBytes(tip, 0, tip.Length, data, 0); Marshal.Copy(data, 0, commandstring, data.Length); } break; } }
public override void Fire(GameObject _shooter) { shooter = _shooter; shooterPos = shooter.transform.position; shooterSheet = shooter.GetComponent <GCS>(); shooterSheet.ClearEnemyList(); if (shooterSheet.enemies.Count == 0) { return; } for (int i = 0; i < shooterSheet.enemies.Count; i++) { shooterSheet.enemies[i].position = shooterSheet.enemies[i].unit.transform.position; } shooterSheet.enemies.Sort((e1, e2) => (shooterPos - e1.position).sqrMagnitude.CompareTo((shooterPos - e2.position).sqrMagnitude)); if (!shooterSheet.enemies[0].shootable) { return; } enemy = shooterSheet.enemies[0].unit; enemyPos = enemy.transform.position; enemySheet = enemy.GetComponent <GCS>(); int hitDieCount = shooterSheet.hitDieCount; int hitDieType = shooterSheet.hitDieType; int hitDie = 0; for (int i = 0; i < hitDieCount; i++) { hitDie += Random.Range(1, hitDieType + 1); } int enemyCoverLevel = EnemyCoverLevel(enemyPos, shooterPos); if (enemyCoverLevel == 1) { hitDie -= hitDieType / 3; } else if (enemyCoverLevel == 2) { hitDie -= hitDieType / 2; } enemySheet.Alert(shooter); AlertEnemiesByGunNoise(shooter, shooterPos); shooterSheet.commandHub.CmdApplyStress(enemy, hitDie); if (hitDie >= enemySheet.armorClass) { shooterSheet.commandHub.CmdHit(enemy); } shooterSheet.commandHub.CmdCreateBullet(enemyPos, shooterPos); }
public void set(GCS p, int _zoom) { USlippyTile a = GCS2Slippy(p, _zoom); x = a.x; y = a.y; zoom = _zoom; }
public Charge(GCS _unit) { children = new List <BTNode>(); unit = _unit; unitsThatCanShootMe = new List <Enemy>(); firstChargePos = new Vector3(-1f, -1f, -1f); stressResolution = "charging"; }
public Enemy(GameObject _unit) { unit = _unit; unitSheet = unit.GetComponent <GCS>(); position = unit.transform.position; shootable = false; canShootMe = false; numberOfAlertTimers = 0; }
public static GCS Slippy2GCS(USlippyTile tile) { GCS p = new GCS(); double n = Math.PI - ((2.0 * Math.PI * tile.y) / Math.Pow(2.0, tile.zoom)); p.lon = (float)((tile.x / Math.Pow(2.0, tile.zoom) * 360.0) - 180.0); p.lat = (float)(180.0 / Math.PI * Math.Atan(Math.Sinh(n))); return(p); }
public static GCS TileToWorldPos(double tile_x, double tile_y, int zoom) { GCS p = new GCS(); double n = Math.PI - ((2.0 * Math.PI * tile_y) / Math.Pow(2.0, zoom)); p.lon = (float)((tile_x / Math.Pow(2.0, zoom) * 360.0) - 180.0); p.lat = (float)(180.0 / Math.PI * Math.Atan(Math.Sinh(n))); return(p); }
/// <summary> /// Top left point position of the tile in the world. /// From: http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#C.23 /// </summary> /// <param name="lon">longitude</param> /// <param name="lat">latitude</param> /// <param name="zoom">zoom [0-18]</param> /// <returns></returns> public static GCS WorldToTilePos(double lon, double lat, int zoom) { GCS p = new GCS(); p.lon = (float)((lon + 180.0) / 360.0 * (1 << zoom)); p.lat = (float)((1.0 - Math.Log(Math.Tan(lat * Math.PI / 180.0) + 1.0 / Math.Cos(lat * Math.PI / 180.0)) / Math.PI) / 2.0 * (1 << zoom)); return(p); }
public TakeCover_Deprecated(GCS _unit, int _emptySlot) { emptySlot = _emptySlot; unit = _unit; possibilities = new List <int>(); for (int i = 0; i < 8; i++) { possibilities.Add(emptySlot); } previousTarget = new Vector3(-1f, -1f, -1f); }
void Start() { unit = GetComponent <GCS>(); moveSpeed = unit.moveSpeed; coroutineRunning = false; pathFinder = new AStar(); map = unit.odin.GetComponent <AStarMap>().map; path = new List <Vector2>(); pathInStack = new Stack <Vector2>(); pathFinder.map = map; speedCooldown = false; StartCoroutine(InfiniteMoveCoroutine()); }
private void gmapBox_MouseUp(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Left) { return; } var moved = System.Drawing.Point.Empty; if (this._drag.End(e.X, e.Y, out moved) == false) { return; } if (moved == System.Drawing.Point.Empty) { if (this._begin.IsEmpty || !this._end.IsEmpty) { this._gmap.RemovePolygon("area"); this._begin = new System.Drawing.Point(e.X, e.Y); this._end = System.Drawing.Point.Empty; var path = new OYOGmapPath(this._gmap.Pixel2Coord(this._begin)); this._gmap.DrawMarker = true; this._gmap.AddPath("begin", path); this._gmap.RequestGmap(); } else { this._gmap.DrawMarker = false; this._gmap.ClearPath(); this._end = new System.Drawing.Point(e.X, e.Y); var left_bot = new System.Drawing.Point(this._begin.X, this._end.Y); var right_top = new System.Drawing.Point(this._end.X, this._begin.Y); var polygon = new OYOGmapPolygon(3, Color.FromArgb(64, Color.Blue), Color.Transparent, this._gmap.Pixel2Coord(this._begin), this._gmap.Pixel2Coord(left_bot), this._gmap.Pixel2Coord(this._end), this._gmap.Pixel2Coord(right_top)); this._gmap.AddPolygon("area", polygon, true); this.Points = this.GetPoints(this._begin, this._end); this.Begin = this._gmap.Pixel2Coord(this._begin); this.End = this._gmap.Pixel2Coord(this._end); } } else { this._gmap.SetPosition(this._drag.BeginPoint.X - moved.X, this._drag.BeginPoint.Y - moved.Y, true); } }
public AutoFlyingDialog(GCS center) { InitializeComponent(); this._gmap.DrawMarker = true; this._gmap.DrawSelfMarker = true; this._gmap.SetPosition(center); this._gmap.AddMarker("init", new OYOGmapMarker(center)); this._gmap.Resize(this.gmapBox.Size); this._gmap.DrawPolygon = true; this._gmap.ReceiveGmap += this.OnReceiveGmap; this._dragStopwatch.Start(); }
private Vector3 GCSImagePos; /// Geographic coordinate system public void genHeight() { GCS target = new GCS(lon, lat); data = HeightLoader.getHeight(target, zoom); //lon, lat m = new Material(Shader.Find("Unlit/Texture")); if (GetComponent <MeshRenderer>() != null) { GetComponent <MeshRenderer>().material = m; } data.Apply(); m.SetTexture("_MainTex", data); TerrainData td = terrain.terrainData; td.alphamapResolution = 257; float[,] heights = new float[td.alphamapWidth, td.alphamapHeight]; for (int i = 0; i < td.alphamapWidth; i++) { for (int j = 0; j < td.alphamapHeight; j++) { Color c = data.GetPixel(i, j); float r = c.r; float g = c.g; float b = c.b; //if (j % 100 == 0) Debug.Log(r + " " + g + " " + b); //heights[i, j] = ((r * 256 + g + b / 256) - 32768) * 0.05f; //if (j % 100 == 0) Debug.Log(heights[i, j]); heights[j, i] = (r * 256 + g + b / 256) / 256; /// bad border (?) if (i == 256) { heights[j, i] = heights[j, 255]; } } /// bad border (?) heights[256, i] = heights[255, i]; } td.SetHeights(0, 0, heights); terrain.ApplyDelayedHeightmapModification(); GCSImagePos = new Vector3(); updatePointPosition(); }
private GCS[] GetPoints(System.Drawing.Point begin, System.Drawing.Point end) { var height = this._end.Y - this._begin.Y; var count = (int)Math.Min((height / 5.0f) + 1, 10); var margin = (height / (float)(count - 1)); var ret = new GCS[count * 2]; for (var i = 0; i < count * 2; i++) { var x = (i % 4 == 0 || (i + 1) % 4 == 0) ? this._begin.X : this._end.X; // 왼쪽 포인트인 경우 begin.x, 오른쪽인 경우 end.x var y = this._begin.Y + (int)(margin * (i / 2)); // 한 라인당 2개의 포인트 ret[i] = this._gmap.Pixel2Coord(x, y); } return(ret); }
public void AlertEnemiesByGunNoise(GameObject shooter, Vector3 noiseOrigin) { GCS shooterSheet = shooter.GetComponent <GCS>(); int layerMask; if (shooter.layer == 8) { layerMask = 1 << 9; } else { layerMask = 1 << 8; } Collider[] alertedUnits = Physics.OverlapSphere(noiseOrigin, shooterSheet.gunNoiseReach, layerMask); for (int i = 0; i < alertedUnits.Length; i++) { alertedUnits[i].gameObject.GetComponent <GCS>().AlertByGunNoise(shooter); } }
/// <summary> /// Uses the OpenStreetMap API to get the desired data in a latitude and longitude bounds. /// </summary> /// <param name="tile">tile x, y and zoom</param> /// <returns>An XML with the OSM data</returns> public static XmlDocument getOSMXML(USlippyTile tile) { XmlDocument xml = new XmlDocument(); using (WebClient client = new WebClient()) { //tile.y USlippyTile copy = new USlippyTile(tile.x, tile.y, tile.zoom); copy.y += 1; GCS gcs = copy.getGCS(); /// North-East USlippyTile's GCS GCS gcsNE = copy.getNorthEastGCS(); // # LefttLon #LowLat #RightLon #HiLat //chunkLimits = [2.13078, 41.48236, 2.13454, 41.48593] string url = OSMApiCall + gcs.lon + "," + gcs.lat + "," + gcsNE.lon + "," + gcsNE.lat; xml.LoadXml(client.DownloadString(url)); } return(xml); }
/// <summary> /// Gets the command string. /// </summary> /// <param name="idcmd">The idcmd.</param> /// <param name="uflags">The uflags.</param> /// <param name="reserved">The reserved.</param> /// <param name="commandstring">The commandstring.</param> /// <param name="cch">The CCH.</param> HResult IContextMenu.GetCommandString(int idcmd, GCS uflags, int reserved, StringBuilder commandstring, int cch) { // Get the item. if (idcmd >= contextMenuStrip.Value.Items.Count) { return(HResult.E_FAIL); } var item = contextMenuStrip.Value.Items[idcmd]; // Based on the flags, choose a string to set. var stringData = string.Empty; switch (uflags) { case GCS.GCS_VERBW: // We need to provide a verb. Use the item name, as the Context Menu Builder will // make sure it is unique. stringData = item.Name; break; case GCS.GCS_HELPTEXTW: // We need to provide the tooltip text. stringData = item.ToolTipText ?? string.Empty; break; } // If we have not been given sufficient space for the string, throw an insufficient buffer exception. if (stringData.Length > cch - 1) { Marshal.ThrowExceptionForHR(WinError.STRSAFE_E_INSUFFICIENT_BUFFER); return(HResult.E_FAIL); } // Append the string data. commandstring.Clear(); commandstring.Append(stringData); // Return success. return(HResult.S_OK); }
/// <summary> /// Updates the composition to a copy of what the Operating System has in its IME input. /// </summary> /// <param name="handle"></param> /// <param name="gcs"></param> /// <returns>Returns True if update was handled, False if not and hence default OS behavior should be fallbacked upon.</returns> public bool UpdateCurrentComposition(IntPtr handle, GCS gcs) { if (((gcs & GCS.GCS_RESULTSTR) == GCS.GCS_RESULTSTR)) { if (this._imeComposition != null) { //this.textView.SelectedText = this.imeComposition.Text; //this.imeComposition = this.GetCurrentComposition(handle); } else { return(false); } } else if (((gcs & GCS.GCS_RESULTSTR) == GCS.GCS_RESULTSTR) == false) { this._imeComposition = this.GetCurrentComposition(handle); } return(true); }
void updatePointPosition() { /// Top left point position of the tile in the world. GCS tile = HeightLoader.WorldToTilePos(lon, lat, zoom); /// Get the decimals in the interval [0 - 1) tile.lon = tile.lon - System.Math.Truncate(tile.lon); tile.lat = tile.lat - System.Math.Truncate(tile.lat); /// Terrain coordinates in Unity starts in bottom left, BUT! /// terrain coordinates in Height map starts in top left GCSImagePos.x = (float)(tile.lon * 256); GCSImagePos.z = 256 - (float)(tile.lat * 256); /// so we need to subtract that /// Coordinates in height map int xx = (int)(tile.lon * 256); int zz = 256 - (int)(tile.lat * 256); /// Update position GCSImagePos.y = GetComponent <Terrain>().terrainData.GetHeight(xx, zz) + GetComponent <Transform>().position.y; }
/// <summary> /// Gets the command string. /// </summary> /// <param name="idcmd">The idcmd.</param> /// <param name="uflags">The uflags.</param> /// <param name="reserved">The reserved.</param> /// <param name="commandstring">The commandstring.</param> /// <param name="cch">The CCH.</param> int IContextMenu.GetCommandString(int idcmd, GCS uflags, int reserved, StringBuilder commandstring, int cch) { // Get the item. if (idcmd >= contextMenuStrip.Value.Items.Count) return WinError.E_FAIL; var item = contextMenuStrip.Value.Items[idcmd]; // Based on the flags, choose a string to set. var stringData = string.Empty; switch (uflags) { case GCS.GCS_VERBW: // We need to provide a verb. Use the item name, as the Context Menu Builder will // make sure it is unique. stringData = item.Name; break; case GCS.GCS_HELPTEXTW: // We need to provide the tooltip text. stringData = item.ToolTipText ?? string.Empty; break; } // If we have not been given sufficient space for the string, throw an insufficient buffer exception. if(stringData.Length > cch - 1) { Marshal.ThrowExceptionForHR(WinError.STRSAFE_E_INSUFFICIENT_BUFFER); return WinError.E_FAIL; } // Append the string data. commandstring.Clear(); commandstring.Append(stringData); // Return success. return WinError.S_OK; }
int IContextMenu3.GetCommandString(int idcmd, GCS uflags, int reserved, StringBuilder commandstring, int cch) { return(((IContextMenu)this).GetCommandString(idcmd, uflags, reserved, commandstring, cch)); }
/// <summary> /// Gets information about a shortcut menu command, including the help string and the language-independent, or canonical, name /// for the command. /// </summary> /// <param name="idCmd">Menu command identifier offset.</param> /// <param name="uType">Flags specifying the information to return.</param> /// <param name="pReserved"> /// Reserved. Applications must specify NULL when calling this method and handlers must ignore this parameter when called. /// </param> /// <param name="pszName">The reference of the buffer to receive the null-terminated string being retrieved.</param> /// <param name="cchMax">Size of the buffer, in characters, to receive the null-terminated string.</param> /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns> void GetCommandString(IntPtr idCmd, GCS uType, IntPtr pReserved, IntPtr pszName, uint cchMax);
public static extern int ImmGetCompositionStringW(HIMC hIMC, GCS dwIndex, byte[] buf, uint dwBufLen);
public static string ImmGetCompositionString(this HIMC hIMC, GCS dwIndex) => BufferReader.ReadString((buf, size) => Imm32.ImmGetCompositionStringW(hIMC, dwIndex, buf, size));
void Start() { unit = transform.parent.gameObject.GetComponent <GCS>(); }
/// <summary> /// Gets information about a shortcut menu command, including the help string and the language-independent, or canonical, name /// for the command. /// </summary> /// <param name="idCmd">Menu command identifier offset.</param> /// <param name="uType">Flags specifying the information to return.</param> /// <param name="pReserved"> /// Reserved. Applications must specify NULL when calling this method and handlers must ignore this parameter when called. /// </param> /// <param name="pszName">The reference of the buffer to receive the null-terminated string being retrieved.</param> /// <param name="cchMax">Size of the buffer, in characters, to receive the null-terminated string.</param> /// <returns>If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns> void GetCommandString([In] IntPtr idCmd, GCS uType, [Optional] IntPtr pReserved, [Out] IntPtr pszName, uint cchMax);
public override void Fire(GameObject _shooter) { shooter = _shooter; shooterSheet = shooter.GetComponent <GCS>(); shooterPos = shooter.transform.position; shooterSheet.ClearEnemyList(); if (shooterSheet.enemies.Count == 0) { return; } for (int i = 0; i < shooterSheet.enemies.Count; i++) { shooterSheet.enemies[i].position = shooterSheet.enemies[i].unit.transform.position; } shooterSheet.enemies.Sort((e1, e2) => (shooterPos - e1.position).sqrMagnitude.CompareTo((shooterPos - e2.position).sqrMagnitude)); shooterSheet.commandHub.ClearSpottersList(); List <GameObject> spotters = shooterSheet.commandHub.spotters; List <GameObject> spottedUnits; int index = -1; bool targetFound = false; for (int i = 0; i < shooterSheet.enemies.Count; i++) { for (int j = 0; j < spotters.Count; j++) { spotters[j].GetComponent <GCS>().ClearSpottedUnitsList(); spottedUnits = spotters[j].GetComponent <GCS>().spottedUnits; for (int k = 0; k < spottedUnits.Count; k++) { if (shooterSheet.enemies[i].unit == spottedUnits[k] && shooterSheet.enemies[i].shootable) { index = i; targetFound = true; break; } } if (targetFound) { break; } } if (targetFound) { break; } } if (index == -1) { return; } enemy = shooterSheet.enemies[index].unit; enemyPos = enemy.transform.position; enemySheet = enemy.GetComponent <GCS>(); int hitDieCount = shooterSheet.hitDieCount; int hitDieType = shooterSheet.hitDieType; int hitDie = 0; for (int i = 0; i < hitDieCount; i++) { hitDie += Random.Range(1, hitDieType + 1); } int enemyCoverLevel = EnemyCoverLevel(enemyPos, shooterPos); if (enemyCoverLevel == 1) { hitDie -= hitDieType / 3; } else if (enemyCoverLevel == 2) { hitDie -= hitDieType / 2; } if (hitDie >= enemySheet.armorClass) { shooterSheet.commandHub.CmdHit(enemy); } enemySheet.Alert(shooter); AlertEnemiesByGunNoise(shooter, shooterPos); }
public MakeUnitInPosition(GCS _unit) { unit = _unit; }
int IContextMenu3.GetCommandString(int idcmd, GCS uflags, int reserved, StringBuilder commandstring, int cch) { return ((IContextMenu)this).GetCommandString(idcmd, uflags, reserved, commandstring, cch); }