public MoveAction(MapUnit unit, int x, int y) { Unit = unit; TargetX = x; TargetY = y; Frac = 0; }
public bool Process(ServerClient client) { if (client.State != ClientState.Playing) { return(false); } Player player = MapLogic.Instance.GetNetPlayer(client); if (player == null) { return(false); // huehue, same as "order error" in a2server.exe, except we just boot them } MapUnit unit = MapLogic.Instance.GetUnitByTag(Tag); if (unit == null) { return(false); // bad desync } if (unit.Player != player) { return(true); // do nothing } MapUnit targetUnit = MapLogic.Instance.GetUnitByTag(TargetTag); if (targetUnit == null) { return(false); } unit.SetState(new AttackState(unit, targetUnit)); return(true); }
public bool Process(ServerClient client) { if (client.State != ClientState.Playing) { return(false); } Player player = MapLogic.Instance.GetNetPlayer(client); if (player == null) { return(false); // huehue, same as "order error" in a2server.exe, except we just boot them } MapUnit unitFrom = MapLogic.Instance.GetUnitByTag(TagFrom); // we can't do anything with units that don't belong to our player. if (unitFrom == null || unitFrom.Player != player) { return(true); } Spell cspell = unitFrom.GetSpell((Spell.Spells)SpellID, (ushort)ItemID); if (cspell == null) { return(true); // spell not found } unitFrom.SetState(new CastState(unitFrom, cspell, TargetX, TargetY)); return(true); }
public AttackAction() { Unit = null; TargetUnit = null; Spell = null; DamageDone = false; }
public override bool Process() { if (NetworkManager.IsClient) { return(false); } if (!(Spell.User is MapUnit)) { return(false); // teleport not usable for structures... can't teleport your house! } if (Timer == 0) { float cscale = (Spell.User.Width + Spell.User.Height) / 2f; Server.SpawnProjectileSimple(AllodsProjectile.Teleport, Spell.User, Spell.User.X + Spell.User.Width / 2f, Spell.User.Y + Spell.User.Height / 2f, 0.2f * cscale, 1f, cscale); Server.SpawnProjectileSimple(AllodsProjectile.Teleport, Spell.User, TargetX + 0.5f, TargetY + 0.5f, 0.2f * cscale, 1f, cscale); } Timer++; if (Timer >= 8) { int utpX = TargetX - Spell.User.Width / 2; int utpY = TargetY - Spell.User.Height / 2; MapUnit unit = Spell.User; if (!unit.Interaction.CheckWalkableForUnit(utpX, utpY, false)) { return(false); } unit.SetPosition(utpX, utpY, true); return(false); } return(true); }
public override bool Process() { if (NetworkManager.IsClient) { return(false); } // find unit to spawn string[] baseUnits = new string[] { "Squirrel", "Turtle", "Foot_Animated" }; int level = Mathf.Max(1, Mathf.Min(4, (Spell.Skill / 4) + 1)); string unitName = baseUnits[UnityEngine.Random.Range(0, 3)] + ((level > 1) ? string.Format(".{0}", level) : ""); MapUnit unit = new MapUnit(unitName); if (unit.Class == null) { Debug.LogFormat("Failed to spawn summoned unit {0}", unitName); return(false); } unit.Player = Spell.User.Player; unit.Tag = MapLogic.Instance.GetFreeUnitTag(); if (!unit.RandomizePosition(Spell.User.X, Spell.User.Y, 2, false)) { // invalid position, don't add unit unit.Dispose(); return(false); } unit.SummonTimeMax = 30; unit.SummonTime = 0; MapLogic.Instance.Objects.Add(unit); return(false); }
public MapUnit Get(MapType type) { List <MapUnit> pool; if (mapPool.TryGetValue(type, out pool)) { MapUnit res = null; if (pool.Count > 0) { res = pool[0]; pool.RemoveAt(0); return(res); } else { res = CreateUnit(type); return(res); } } else { pool = new List <MapUnit>(); mapPool.Add(type, pool); MapUnit res = null; res = CreateUnit(type); return(res); } }
public void Update() { while (addCache.Count > 0) { MapUnit unit = addCache[0]; addCache.RemoveAt(0); switch (unit.unittype) { case UnitType.creature: if (!creatureUnits.ContainsKey(unit.id)) { creatureUnits.Add(unit.id, unit); } break; case UnitType.effect: if (!effectUnits.ContainsKey(unit.id)) { effectUnits.Add(unit.id, unit); } break; } } foreach (var c in creatureUnits) { if (CheckIsMoved(c.Value as CircleMapUnit)) { c.Value.next = c.Value.positon + c.Value.speed; } else { c.Value.next = c.Value.positon; } } foreach (var e in effectUnits) { e.Value.next = e.Value.positon + e.Value.speed; } foreach (var e in effectUnits) { Group sg = e.Value.unit.Group; foreach (var c in creatureUnits) { if (c.Value.unit.Group != sg && IsCollided(e.Value, c.Value)) { EffectUnit effectunit = e.Value.unit as EffectUnit; if (!effectunit.IsContainKey(c.Value.id)) { effectunit.AddUnit(c.Value.id); } } } } //view }
public override GeoPoint MapUnitToGeoPoint(MapUnit mapPoint) { double x = (mapPoint.X - OffsetX) / ScaleX; double y = Math.Min(1, Math.Max(-1, (mapPoint.Y - OffsetY) / ScaleY)); if (IsValidPoint(x, y)) { double z = Math.Sqrt(1 - 0.5 * Math.Pow(x, 2) - 0.5 * Math.Pow(y, 2)); double c = Math.Sqrt(2) * z * x / (2 * Math.Pow(z, 2) - 1); double lon = 2 * Math.Atan(c); double lat = Math.Asin(Math.Min(Math.Max(Math.Sqrt(2) * z * y, -1), 1)); double latInDegree = lat * 180.0 / Math.PI; double lonInDegree = lon * 180.0 / Math.PI; return(new GeoPoint( Math.Min( maxLatitude, Math.Max(minLatitude, RadianToDegree(lat)) ), Math.Min( maxLongitude, Math.Max(minLongitude, RadianToDegree(lon)) ) )); } else { int signX = (x < 0) ? -1 : 1; int signY = (y < 0) ? -1 : 1; return(new GeoPoint(maxLatitude * signY, maxLongitude * signX)); } }
public static async void SaveRoadAllInfo(MapUnit mapUnit, long teamId, bool saveRideRoadInfos = true, bool saveRideTotalInfos = true) { if (mapUnit == null) { Log.Error("SaveRoadAllInfo Failed, mapUnit == null"); return; } if (mapUnit.MapUnitType == MapUnitType.Npc) { return; } var roadInfo = mapUnit.CreateRideRecord(teamId); var roadTotalInfo = mapUnit.CreateRideTotalInfo(); var user = await UserDataHelper.FindOneUser(mapUnit.Uid); BsonDocument log = null; if (saveRideRoadInfos) { SaveRideRoadInfos(roadInfo); } if (saveRideTotalInfos) { SaveRideTotalInfo(user, roadTotalInfo, out log); } SaveUserAndBroadcastTarget(mapUnit, user, log); }
public bool Process(ServerClient client) { if (client.State != ClientState.Playing) { return(false); } Player player = MapLogic.Instance.GetNetPlayer(client); if (player == null) { return(false); } MapUnit unit = MapLogic.Instance.GetUnitByTag(UnitTag); if (unit == null || unit.Player != player) { return(true); } MapStructure structure = MapLogic.Instance.GetStructureByTag(StructureTag); if (structure == null || structure.Class == null || !structure.Class.Usable) { return(false); } unit.SetState(new UseStructureState(unit, structure)); return(true); }
public void InitDefault(MapObject pp) { EnabledCommands = 0; if (pp == null) { return; } if ((pp is IPlayerPawn && ((IPlayerPawn)pp).GetPlayer() == MapLogic.Instance.ConsolePlayer) && (pp.GetObjectType() == MapObjectType.Monster || pp.GetObjectType() == MapObjectType.Human)) { EnabledCommands = (Commands.All & ~Commands.Cast); // enable cast if object has spells or scrolls bool haveSpells = false; MapUnit mu = (MapUnit)pp; for (int i = 0; i < 32; i++) { if (mu.GetSpell((Spell.Spells)i) != null) { haveSpells = true; break; } } if (haveSpells) { EnabledCommands |= Commands.Cast; } CurrentCommandActual = Commands.Move; } }
public void LoadUnit(MapUnit unit) { GameObject NameText = Tools.GetChildNamed(gameObject, "Name Text"); GameObject HealthText = Tools.GetChildNamed(gameObject, "Health Text"); GameObject Portrait = Tools.GetChildNamed(gameObject, "Portrait"); GameObject Shield = Tools.GetChildNamed(gameObject, "Shield"); if (unit == null) { NameText.GetComponent <TextMesh>().text = ""; HealthText.GetComponent <TextMesh>().text = ""; Portrait.GetComponent <SpriteRenderer>().sprite = null; Shield.GetComponent <SpriteRenderer>().sprite = null; } else { NameText.GetComponent <TextMesh>().text = unit.name; HealthText.GetComponent <TextMesh>().text = "HP: " + unit.currentHealth + "/" + unit.maxHealth; Portrait.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("Factions/" + unit.faction + "/Portrait/" + unit.portraitName); if (unit.marred) { Portrait.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("Factions/" + unit.faction + "/Portrait/" + unit.portraitName + " marred"); } if (unit.currentShield == 0) { Shield.GetComponent <SpriteRenderer>().sprite = null; } else { string shieldSpriteName = "Icons/Shields/Shield " + unit.currentShield; Shield.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>(shieldSpriteName); } unit.unitSpace = gameObject; } }
public void SetSpells(MapUnit unit) { uint oldSpellsMask = SpellsMask; if (unit != null && unit.Player == MapLogic.Instance.ConsolePlayer) { Unit = unit; Spells = unit.SpellBook; SpellsMask = 0; for (int i = 0; i < 32; i++) { if (unit.GetSpell((Spell.Spells)i) != null) { SpellsMask |= 1u << i; } } } else { Spells = null; SpellsMask = 0; } if (oldSpellsMask != SpellsMask) { UpdateMesh(); } }
public Statistics() { Actions = new Action(); CharacterActions = new CharacterAction(); Kills = new Kill(); MapUnits = new MapUnit(); }
Rect CalculateBoundingBox(ISupportCoordPoints item) { double maxLat = double.NegativeInfinity; double minLat = double.PositiveInfinity; double maxLon = double.NegativeInfinity; double minLon = double.PositiveInfinity; foreach (GeoPoint point in item.Points) { if (maxLat < point.Latitude) { maxLat = point.Latitude; } if (minLat > point.Latitude) { minLat = point.Latitude; } if (maxLon < point.Longitude) { maxLon = point.Longitude; } if (minLon > point.Longitude) { minLon = point.Longitude; } } MapUnit corner1 = this.projection.GeoPointToMapUnit(new GeoPoint(maxLat, minLon)); MapUnit corner2 = this.projection.GeoPointToMapUnit(new GeoPoint(minLat, maxLon)); return(new Rect(corner1.X, corner1.Y, corner2.X - corner1.X, corner2.Y - corner1.Y)); }
private void UpdatePresentation() { if (selectedCell == null) { infoText.text = ""; moveButton.active = false; ui.infoPanel.Hide(); } else { infoText.text = "Data for cell " + selectedCell.name; selectedUnit = selectedCell.unitPresent; // If there's a unit, give controls for that unit if (selectedUnit != null) { moveButton.active = true; infoText.text += "\nUnit present!"; } else { moveButton.active = false; } ui.infoPanel.Show(); } }
public void MapUnitDown(MapUnit _unit) { if (mapData.dic.ContainsKey(_unit.index)) { downPos = _unit.index; } }
private static MapUnit GetMapUnit(Map map, bool isWebMercator) { MapUnit mapUnit = (isWebMercator ? MapUnit.esriMeters : MapUnit.esriDecimalDegrees); // default value if (map.Layers != null) { // Try to find a dynamic map service with same spatial reference and use units of this service String layerUnits = null; foreach (Layer layer in map.Layers) { if (map.SpatialReference != null && layer.SpatialReference != null && map.SpatialReference.WKID == layer.SpatialReference.WKID) { if (layer is ArcGISDynamicMapServiceLayer) { layerUnits = ((ArcGISDynamicMapServiceLayer)layer).Units; break; } else if (layer is ArcGISTiledMapServiceLayer) { layerUnits = ((ArcGISTiledMapServiceLayer)layer).Units; break; } } } if (!string.IsNullOrEmpty(layerUnits)) { mapUnit = (MapUnit)Enum.Parse(typeof(MapUnit), layerUnits, true); } } return(mapUnit); }
public static void SendCastToUnit(MapUnit unit, Spell.Spells spell, MapUnit target) { Spell cspell = unit.GetSpell(spell); if (cspell == null) { return; } if (cspell.Template.SpellTarget == 2) { SendCastToArea(unit, spell, target.X + target.Width / 2, target.Y + target.Height / 2); return; } if (NetworkManager.IsClient) { ServerCommands.CastToUnit cunitCmd; cunitCmd.TagFrom = unit.Tag; cunitCmd.SpellID = (int)spell; cunitCmd.TagTo = target.Tag; ClientManager.SendCommand(cunitCmd); } else { if (MapLogic.Instance.ConsolePlayer == unit.Player) { unit.SetState(new CastState(unit, cspell, target)); } } }
public SpellProc(Spell spell, int tgX, int tgY, MapUnit tgUnit) { Spell = spell; TargetX = tgX; TargetY = tgY; TargetUnit = tgUnit; }
private const double degreeDist = earthRadius * toRadians; // distance of 1 degree at equator in meters private static double RatioScaleResolution(MapUnit mapUnit, double yCenter, bool isWebMercator) { double ratio; const double inchesPerMeter = (double)MapUnit.esriMeters / (double)MapUnit.esriInches; // = 39.37 if (isWebMercator) { // Transform yCenter from web mercator to decimal degree yCenter = Math.Min(Math.Max(yCenter, -20037508.3427892), 20037508.3427892); MapPoint point = new MapPoint(0, yCenter); MapPoint geographicPoint = (new WebMercator()).ToGeographic(point) as MapPoint; yCenter = (geographicPoint == null ? 0.0 : geographicPoint.Y); ratio = Math.Cos(yCenter * toRadians) * dpi * inchesPerMeter; } else if (mapUnit == MapUnit.esriDecimalDegrees || mapUnit == MapUnit.esriUnknownUnits) { if (Math.Abs(yCenter) > 90) { ratio = 0.0; } else { ratio = Math.Cos(yCenter * toRadians) * degreeDist * dpi * inchesPerMeter; } } else { ratio = dpi * (double)mapUnit / (double)MapUnit.esriInches; } return(ratio); }
public static void SpriteToMapUnits() { string[] s = Selection.assetGUIDs; foreach (string ss in s) { string path = AssetDatabase.GUIDToAssetPath(ss); UnityEngine.Object mapSprite = AssetDatabase.LoadAssetAtPath <Sprite> (path); if (mapSprite.GetType() != typeof(UnityEngine.Sprite)) { continue; } string mapName = ((Sprite)mapSprite).name; UnityEngine.Object[] ass = AssetDatabase.LoadAllAssetsAtPath(path); foreach (UnityEngine.Object uo in ass) { if (uo.GetType() == typeof(Texture2D)) { continue; } Sprite sp = uo as Sprite; string name = sp.name; //string name = mapName+"_"+ uo.GetInstanceID ().ToString(); GameObject newUnit = new GameObject(name); Rigidbody2D newR2 = newUnit.AddComponent <Rigidbody2D> (); BoxCollider2D newB2 = newUnit.AddComponent <BoxCollider2D> (); MapUnit newMu = newUnit.AddComponent <MapUnit> (); newMu.UnitSprite = sp; newMu.preSet(); GameObject newPre = PrefabUtility.CreatePrefab(Settings.Paths.MapUnitPath + "/" + name + ".prefab", newUnit); //AssetDatabase.ImportAsset(("Asset/MapPrefabs/MpaUnits"+name); } } }
public MoveUnit( MapUnit unit, IEnumerable <HexCoords> path) { this.unit = unit; this.path = path; }
public bool Process() { if (!MapLogic.Instance.IsLoaded) { return(false); } MapUnit unit = MapLogic.Instance.GetUnitByTag(Tag); if (unit == null) { Debug.LogFormat("Attempted to set spells for nonexistent unit {0}", Tag); return(true); } // add spells unit.SpellBook.Clear(); for (int i = 0; i < 32; i++) { uint sp = 1u << i; if ((SpellBook & sp) != 0) { Spell cspell = new Spell(i, unit); unit.SpellBook.Add(cspell); } } return(true); }
public bool Process() { if (!MapLogic.Instance.IsLoaded) { return(false); } MapUnit unit = MapLogic.Instance.GetUnitByTag(Tag); if (unit == null) { Debug.LogFormat("Attempted to damage nonexistent unit {0}", Tag); return(true); } // visible = whether to display flying hp unit.Stats.TrySetHealth(unit.Stats.Health - Damage); unit.DoUpdateInfo = true; unit.DoUpdateView = true; if (Visible) { // todo: display flying hp if (unit.GetVisibityInCamera()) { MapView.Instance.SpawnDamageNumbers(unit, Damage, false); } } return(true); }
public bool Process() { if (!MapLogic.Instance.IsLoaded) { return(false); } IPlayerPawn source = null; if (SourceTag > 0) { switch (SourceType) { case MapObjectType.Human: case MapObjectType.Monster: source = MapLogic.Instance.GetUnitByTag(SourceTag); break; case MapObjectType.Structure: source = MapLogic.Instance.GetStructureByTag(SourceTag); break; } } MapUnit target = MapLogic.Instance.GetUnitByTag(TargetTag); if (target == null) { return(false); } Server.SpawnProjectileLightning(source, X, Y, Z, target, Color); return(true); }
public static void LeaveTeam(this RoomTeamComponent self, MapUnit leaveMapUnit) { // 把離開房間的MapUnit設為null for (int i = 0; i < RoomTeamComponent.MEMBER_MAX; i++) { if (self.MemberDatas[i] == null) { continue; } if (!self.MemberDatas[i].LoadingDone) { MapUnit kickMember = self.RoomEntity.GetMapUnitByUid(self.MemberDatas[i].Uid); if (leaveMapUnit?.Uid == kickMember?.Uid) { self.MemberDatas[i] = null; } } } // 判斷是否全部載入完畢 // 讓隊伍進入比賽 if (self.IsAllLoadingDone()) { RoomTeamHelper.LoadingFinish(self); } }
public static void SendCastToArea(MapUnit unit, Spell.Spells spell, int x, int y) { Spell cspell = unit.GetSpell(spell); if (cspell == null) { return; } if (NetworkManager.IsClient) { ServerCommands.CastToArea careaCmd; careaCmd.TagFrom = unit.Tag; careaCmd.SpellID = (int)spell; careaCmd.TargetX = x; careaCmd.TargetY = y; ClientManager.SendCommand(careaCmd); } else { if (MapLogic.Instance.ConsolePlayer == unit.Player) { unit.SetState(new CastState(unit, cspell, x, y)); } } }
public override bool OnAttach(MapUnit unit) { // remove darkness effects List <Darkness> darks = unit.GetSpellEffects <Darkness>(); for (int i = 0; i < darks.Count; i++) { unit.RemoveSpellEffect(darks[i]); } // replace less powerful effects List <Light> lights = unit.GetSpellEffects <Light>(); foreach (Light h in lights) { if (Power > h.Power) { h.Power = Power; unit.UpdateItems(); } h.Timer = 0; return(false); } return(true); }
internal void SetScaleBarMapUnit(MapUnit unit) { _getMapUnitsRetryCount = 0; if (ScaleBar != null) { ScaleBar.MapUnit = unit; // Scalebar updates on extent changed. Force event without altering extent. if (Map.Extent != null) Map.Extent = Map.Extent.Clone(); } ScaleBarExtensions.SetScaleBarMapUnit(Map, unit); }
private static double RatioScaleResolution(MapUnit mapUnit, double yCenter, bool isWebMercator) { double ratio; const double inchesPerMeter = (double)MapUnit.esriMeters / (double)MapUnit.esriInches; // = 39.37 if (isWebMercator) { // Transform yCenter from web mercator to decimal degree yCenter = Math.Min(Math.Max(yCenter, -20037508.3427892), 20037508.3427892); MapPoint point = new MapPoint(0, yCenter); MapPoint geographicPoint = (new WebMercator()).ToGeographic(point) as MapPoint; yCenter = (geographicPoint == null ? 0.0 : geographicPoint.Y); ratio = Math.Cos(yCenter * toRadians) * dpi * inchesPerMeter; } else if (mapUnit == MapUnit.esriDecimalDegrees || mapUnit == MapUnit.esriUnknownUnits) { if (Math.Abs(yCenter) > 90) ratio = 0.0; else ratio = Math.Cos(yCenter * toRadians) * degreeDist * dpi * inchesPerMeter; } else { ratio = dpi * (double)mapUnit / (double)MapUnit.esriInches; } return ratio; }
private double ConvertAreaUnits(double area, MapUnit baseUnits, AreaUnit toUnits) { double mArea = area; if (baseUnits == MapUnit.Feet) { if (toUnits == AreaUnit.Acres) mArea = area * 0.000022956; else if (toUnits == AreaUnit.Sq_Meters) mArea = area * 0.09290304; else if (toUnits == AreaUnit.Sq_Miles) mArea = area * 0.00000003587; else if (toUnits == AreaUnit.Sq_Kilometers) mArea = area * 0.09290304 / 1000000; } else if (baseUnits == MapUnit.Meters) { if (toUnits == AreaUnit.Acres) mArea = area * 0.0002471054; else if (toUnits == AreaUnit.Sq_Miles) mArea = area * 0.0000003861003; else if (toUnits == AreaUnit.Sq_Kilometers) mArea = area * 1.0e-6; else if (toUnits == AreaUnit.Sq_Feet) mArea = area * 10.76391042; } return mArea; }
public double ConvertUnits(double distance, MapUnit fromUnits, MeasureUnit toUnits) { double mDistance = distance; if (fromUnits == MapUnit.Feet) { if (toUnits == MeasureUnit.Miles) { mDistance = distance / 5280; } else if (toUnits == MeasureUnit.Meters) { mDistance = distance * 0.304800609601; } else if (toUnits == MeasureUnit.Kilometers) { mDistance = distance * 0.0003048; } } else { if (toUnits == MeasureUnit.Miles) { mDistance = distance * 0.0006213700922; } else if (toUnits == MeasureUnit.Feet) { mDistance = distance * 3.280839895; } else if (toUnits == MeasureUnit.Kilometers) { mDistance = distance / 1000; } } return mDistance; }
public static void SetScaleBarMapUnit(Map o, MapUnit value) { o.SetValue(ScaleBarMapUnitProperty, value); }
private void FindMapUnits(int row, int column, List<int[]> mapUnits, int currentStepValue, MapUnit unit) { try { for (var offset = -1; offset <= 1; offset += 2) { AddMapUnit(row + offset, column, unit, mapUnits, currentStepValue); AddMapUnit(row, column + offset, unit, mapUnits, currentStepValue); } } catch (Exception ex) { Debug.WriteLine($"{ex.Source}, {ex.Message}"); } }
public string ProcessMeasureRequest(NameValueCollection queryString) { if (m_mapFunctionality == null) GetMeasureResource(); object o = Session["MeasureMapUnits"]; if (o != null) m_mapUnits = (MapUnit)Enum.Parse(typeof(MapUnit), o.ToString()); else if (m_startMapUnits == MapUnit.Resource_Default) m_mapUnits = GetResourceDefaultMapUnit(); else m_mapUnits = m_startMapUnits; string eventArg = queryString["EventArg"].ToLower(); string vectorAction = queryString["VectorAction"].ToLower(); string[] coordPairs, xys; string coordString = queryString["coords"]; if (coordString == null && coordString.Length == 0) coordString = ""; coordPairs = coordString.Split(char.Parse("|")); string mapUnitString = queryString["MapUnits"]; if (mapUnitString != null && mapUnitString.Length > 0) m_mapUnits = (MapUnit)Enum.Parse(typeof(MapUnit), mapUnitString); Session["MeasureMapUnits"] = m_mapUnits; string measureUnitString = queryString["MeasureUnits"]; if (measureUnitString != null && measureUnitString.Length > 0) m_measureUnits = (MeasureUnit)Enum.Parse(typeof(MeasureUnit),measureUnitString); string areaUnitstring = queryString["AreaUnits"]; if (areaUnitstring != null && areaUnitstring.Length > 0) m_areaUnits = (AreaUnit)Enum.Parse(typeof(AreaUnit),areaUnitstring); string response = ""; PointCollection points = new PointCollection(); PointCollection dPoints = new PointCollection(); ArrayList distances = new ArrayList(); double totalDistance = 0; double segmentDistance = 0; double area = 0; double perimeter = 0; double roundFactor = Math.Pow(10, m_numberDecimals); double xD, yD, tempDist, tempDist2, tempArea, x1, x2, y1, y2; TransformationParams transformationParameters = m_map.GetTransformationParams(TransformationDirection.ToMap); if (vectorAction == "addpoint") { if (coordPairs != null && coordPairs.Length > 1) { for (int i = 0; i < coordPairs.Length; i++) { xys = coordPairs[i].Split(char.Parse(":")); points.Add(Point.ToMapPoint(Convert.ToInt32(xys[0]), Convert.ToInt32(xys[1]), transformationParameters)); if (i > 0) { if (m_mapUnits == MapUnit.Degrees) { // use great circle formula tempDist = DegreeToFeetDistance(points[i - 1].X, points[i - 1].Y, points[i].X, points[i].Y); y1 = DegreeToFeetDistance(points[i].X, points[i].Y, points[i].X, 0); x1 = DegreeToFeetDistance(points[i].X, points[i].Y, 0, points[i].Y); dPoints.Add(new Point(x1, y1)); segmentDistance = ConvertUnits(tempDist, MapUnit.Feet, m_measureUnits); } else { // get third side of triangle for distance xD = Math.Abs(points[i].X - points[i - 1].X); yD = Math.Abs(points[i].Y - points[i - 1].Y); tempDist = Math.Sqrt(Math.Pow(xD, 2) + Math.Pow(yD, 2)); segmentDistance = ConvertUnits(tempDist, m_mapUnits, m_measureUnits); } distances.Add(segmentDistance); totalDistance += segmentDistance; segmentDistance = Math.Round(segmentDistance * roundFactor) / roundFactor; totalDistance = Math.Round(totalDistance * roundFactor) / roundFactor; } else { if (m_mapUnits == MapUnit.Degrees) { y1 = DegreeToFeetDistance(points[i].X, points[i].Y, points[i].X, 0); x1 = DegreeToFeetDistance(points[i].X, points[i].Y, 0, points[i].Y); dPoints.Add(new Point(x1, y1)); } } } } if (eventArg == "polygon") { if (points.Count > 2) { if (m_mapUnits == MapUnit.Degrees) { tempDist = DegreeToFeetDistance(points[points.Count - 1].X, points[points.Count - 1].Y, points[0].X, points[0].Y); tempDist2 = ConvertUnits(tempDist, MapUnit.Feet, m_measureUnits); distances.Add(tempDist2); dPoints.Add(dPoints[0]); } else { xD = Math.Abs(points[points.Count - 1].X - points[0].X); yD = Math.Abs(points[points.Count - 1].Y - points[0].Y); tempDist = Math.Sqrt(Math.Pow(xD, 2) + Math.Pow(yD, 2)); tempDist2 = ConvertUnits(tempDist, m_mapUnits, m_measureUnits); distances.Add(tempDist2); } points.Add(points[0]); perimeter = totalDistance + tempDist2; // add area calculation tempArea = 0; MapUnit mUnits = m_mapUnits; for (int j = 0; j < points.Count - 1; j++) { if (m_mapUnits == MapUnit.Degrees) { x1 = Convert.ToDouble(dPoints[j].X); x2 = Convert.ToDouble(dPoints[j + 1].X); y1 = Convert.ToDouble(dPoints[j].Y); y2 = Convert.ToDouble(dPoints[j + 1].Y); mUnits = MapUnit.Feet; } else { x1 = Convert.ToDouble(points[j].X); x2 = Convert.ToDouble(points[j + 1].X); y1 = Convert.ToDouble(points[j].Y); y2 = Convert.ToDouble(points[j + 1].Y); } //tempArea += tempArea + (x1 + x2) * (y1 - y2); double xDiff = x2 - x1; double yDiff = y2 - y1; tempArea += x1 * yDiff - y1 * xDiff; } tempArea = Math.Abs(tempArea) / 2; area = ConvertAreaUnits(tempArea, mUnits, m_areaUnits); perimeter = Math.Round(perimeter * roundFactor) / roundFactor; area = Math.Round(area * roundFactor) / roundFactor; response = String.Format("<table cellspacing='0' ><tr><td>Perimeter: </td><td align='right'>{0}</td><td>{1}</td></tr><tr><td>Area:</td><td align='right'>{2}</td><td>{3}</td></tr></table>", perimeter, WriteMeasureUnitDropdown(), area, WriteAreaUnitDropdown()); } else response = String.Format("<table cellspacing='0' ><tr><td>Perimeter: </td><td align='right'> 0</td><td>{0}</td></tr><tr><td>Area:</td><td align='right'>0 </td><td>{1}</td></tr></table>", WriteMeasureUnitDropdown(), WriteAreaUnitDropdown()); } else response = String.Format("<table cellspacing='0' ><tr><td>Segment: </td><td align='right'>{0} </td><td>{1}</td></tr><tr><td>Total Length:</td><td align='right'>{2} </td><td>{3}</td></tr></table>", segmentDistance, m_measureUnits.ToString(), totalDistance, WriteMeasureUnitDropdown()); } else if (vectorAction == "coordinates") { xys = coordPairs[0].Split(char.Parse(":")); Point coordPoint = Point.ToMapPoint(Convert.ToInt32(xys[0]), Convert.ToInt32(xys[1]), transformationParameters); response = String.Format("<table cellspacing='0' ><tr><td>X Coordinate:</td><td align='right'>{0}</td></tr><tr><td>Y Coordinate:</td><td align='right'>{1}</td></tr></table>", (Math.Round(coordPoint.X * roundFactor) / roundFactor).ToString(), (Math.Round(coordPoint.Y * roundFactor) / roundFactor).ToString()); } else if (vectorAction == "finish") { response = "Shape complete"; } return String.Format("measure:::{0}:::{1}:::{2}", m_id, vectorAction, response); }
private void AddMapUnit(int row, int column, MapUnit unit, List<int[]> mapUnits, int currentStepValue) { try { if (IsReachable(row, column) && IsUnit(row, column, unit)) { var unitLocation = new int[] { row, column }; mapUnits.Add(unitLocation); if (currentStepValue > -1) { investigatedMap[row, column] = currentStepValue + 1; } } } catch (Exception ex) { Debug.WriteLine($"{ex.Source}, {ex.Message}, {ex.StackTrace}"); } }
private bool IsUnit(int row, int column, MapUnit unit) { return investigatedMap[row, column] == (int) unit; }