public void LocatePlace(MapPlace mapPlace, float xMax, float yMax) {/* * mapPlace.transform.localPosition = new Vector2((Randomizer.RandomBoolean() ? 1 : -1)*Random.Range(0, xMax), * (Randomizer.RandomBoolean() ? 1 : -1)*Random.Range(0, yMax));*/ mapPlace.transform.localPosition = new Vector2(Random.Range(0, xMax), (Randomizer.RandomBoolean() ? 1 : -1) * Random.Range(-yMax, 0)); }
private MapTriangle FindTriangle(MapPlace toLocate, List <MapPlace> locatedPlaces, List <ShipmentEdge> allEdges) { MapTriangle mapTriangle = new MapTriangle(); List <ShipmentEdge> edgesByIdNode = ShipmentsView.instance.Model.GetEdgesByIdNode(toLocate.Id); List <MapPlace> vertices = locatedPlaces.FindAll(e => edgesByIdNode.Exists(f => f.IdNodeA == e.Id || f.IdNodeB == e.Id)); if (vertices.Count < 2) { return(null); } /* * if (vertices.Count > 2) throw new Exception("mmmh many vertexes"); */ ShipmentEdge edge = allEdges.Find( e => (e.IdNodeA == vertices[0].Id && e.IdNodeB == vertices[1].Id) || (e.IdNodeB == vertices[0].Id && e.IdNodeA == vertices[1].Id)); mapTriangle.Nodes = new List <int>(2); mapTriangle.Edges = new List <ShipmentEdge>(3); mapTriangle.Nodes.AddRange(new [] { toLocate.Id, vertices[0].Id, vertices[1].Id }); mapTriangle.Edges.AddRange(new [] { edge, edgesByIdNode.Find(e => e.IdNodeA == vertices[0].Id || e.IdNodeB == vertices[0].Id), edgesByIdNode.Find(e => e.IdNodeA == vertices[1].Id || e.IdNodeB == vertices[1].Id) }); return(mapTriangle); }
private void AddCellLiseners() { List <ShipmentsAnswerCell> cells = GetAnswerCells(); for (int i = 1; i < cells.Count; i++) { var i1 = i; cells[i].Value = -1; cells[i].GetComponent <Button>().onClick.AddListener( () => { MapPlace mapPlace = MapGenerator.Places.Find(e => e.Id == cells[i1].Value); if (cells[i1].Value != 1 && mapPlace != null) { if (mapPlace.Type == ShipmentNodeType.Other && i1 + 2 < cells.Count && i1 % 3 == 1) { cells[i1 + 2].Clear(); } else if (mapPlace.Type == ShipmentNodeType.Other && i1 - 2 > 0 && i1 % 3 == 0) { cells[i1 - 2].Clear(); } } cells[i1].Clear(); ChangeFocusCell(i1); } ); } }
public bool CheckAllDistances(List <ShipmentEdge> allEdges) { List <MapPlace> locatedPlaces = Places.FindAll(e => e.Id != -1); foreach (MapPlace place in locatedPlaces) { if (!CheckMinDistances(place, locatedPlaces, GetMinDistance())) { return(false); } } foreach (ShipmentEdge edge in allEdges) { MapPlace a = locatedPlaces.Find(e => e.Id == edge.IdNodeA); MapPlace b = locatedPlaces.Find(e => e.Id == edge.IdNodeB); float f = Vector2.Distance(a.transform.position, b.transform.position) / Ruler.GetUnityDistances(); if (Math.Abs(f % edge.Length) > 0.1) { return(false); } } foreach (var mapPlace in locatedPlaces) { if (!IsInMapLimits(mapPlace)) { return(false); } } return(true); }
public void Test_MapPlace() { using (var mapPlace = new MapPlace()) { Assert.IsNotNull(mapPlace); Assert.IsNotNull(mapPlace.Points); Assert.IsNotNull(mapPlace.PlaceRefs); } }
private void SetPlayerToFirstPlace() { MapPlace place = MapGenerator.Places.Find(e => e.Type == ShipmentNodeType.Start); Player.transform.position = place.transform.position; Player.GetComponent <Image>().sprite = GetNeutralBoatSprite(); Player.gameObject.SetActive(false); }
private static MapPlace DeserializeMapPlace(BinaryReader Reader) { MapPlace place = new MapPlace(); DeserializeMapVisualObject(Reader, place); place.Passability = Reader.ReadSingle(); return(place); }
private bool EdgeIsIncorrect(MapPlace toLocate, List <MapPlace> locatedPlaces, float xMax, float yMax, float distanceMin, float f) { iterations++; if (iterations > 100) { return(false); } return(f < 1.9 || Math.Abs(f % 1) > 0.08 || f > 9.1 || Math.Abs(toLocate.transform.localPosition.y) >= yMax || Math.Abs(toLocate.transform.localPosition.x) >= xMax || !CheckMinDistances(toLocate, locatedPlaces, distanceMin)); }
public void SafeLocatePlaces(List <ShipmentNode> nodes, List <ShipmentEdge> edges) { iterations = 0; ResetIds(); float edge = Places[0].GetComponent <RectTransform>().sizeDelta.x / 2; float distanceMin = GetMinDistance(); Vector2 mapSize = Map.GetComponent <RectTransform>().sizeDelta / 2; float xMax = (mapSize.x - edge) * 0.95f; float yMax = (mapSize.y - edge) * 0.95f; List <MapPlace> locatedPlaces = new List <MapPlace>(Places.Count); Utils.Shuffle(Places); nodes.Sort((node1, node2) => node1.Type == ShipmentNodeType.Start ? -1 : node2.Type == ShipmentNodeType.Start ? 1 : ShipmentsView.instance.Model.GetEdgesByIdNode(node2.Id).Count - ShipmentsView.instance.Model.GetEdgesByIdNode(node1.Id).Count); SetFirstPlace(nodes[0], xMax, yMax); locatedPlaces.Add(Places[0]); Places[0].gameObject.SetActive(true); int i = 1; for (; i < nodes.Count; i++) { MapPlace mapPlace = Places[i]; mapPlace.gameObject.SetActive(true); ShipmentNode node = nodes[i]; mapPlace.SetData(node.Id, PlacesSprites[node.Id], CrosSprites[node.Type == ShipmentNodeType.Other ? 1 : 0], node.Type); if (iterations >= 100) { iterations = 0; locatedPlaces.Clear(); foreach (ShipmentEdge a in edges) { a.Length = 0; } SafeLocatePlaces(nodes, edges); return; } SafeLocatePlace(mapPlace, locatedPlaces, ShipmentsView.instance.Model.GetEdgesByIdNode(node.Id), xMax, yMax, distanceMin); } // Oculto los places no usados for (int j = Places.Count - 1; j >= i; j--) { Places[j].gameObject.SetActive(false); } foreach (ShipmentEdge shipmentEdge in edges) { if (shipmentEdge.Length == 0) { MapPlace place = Places.Find(e => e.Id == shipmentEdge.IdNodeA); MapPlace mapPlace = Places.Find(e => e.Id == shipmentEdge.IdNodeB); float distance = Vector2.Distance(place.transform.position, mapPlace.transform.position) / Ruler.GetUnityDistances(); shipmentEdge.Length = (int)distance; } } }
public void OnExitTriger(GameObject objTriger) { MapPlace mapPlace = objTriger.GetComponent <MapPlace>(); if (!ReferenceEquals(mapPlace, null)) { mapPlace.OnExitTriger(); } }
public void SelectPlaces() { GDMIndividualRecord ind = null; bool condBirth = false; bool condDeath = false; bool condResidence = false; if (fView.TotalRadio.Checked) { condBirth = fView.BirthCheck.Checked; condDeath = fView.DeathCheck.Checked; condResidence = fView.ResidenceCheck.Checked; } else if (fView.SelectedRadio.Checked && (fView.PersonsCombo.SelectedIndex >= 0)) { ind = (fView.PersonsCombo.GetSelectedTag <GDMIndividualRecord>()); } fView.MapBrowser.ShowLines = (ind != null && fView.LinesVisibleCheck.Checked); fMapPoints.Clear(); int num = fPlaces.Count; for (int i = 0; i < num; i++) { MapPlace place = fPlaces[i]; if (place.Points.Count < 1) { continue; } int num2 = place.PlaceRefs.Count; for (int j = 0; j < num2; j++) { var placeRef = place.PlaceRefs[j]; GDMCustomEvent evt = placeRef.Event; var evtType = evt.GetTagType(); bool checkEventType = (condBirth && evtType == GEDCOMTagType.BIRT) || (condDeath && evtType == GEDCOMTagType.DEAT) || (condResidence && evtType == GEDCOMTagType.RESI); if ((ind != null && (placeRef.Owner == ind)) || checkEventType) { PlacesLoader.AddPoint(fMapPoints, place.Points[0], placeRef); } } } if (ind != null) { // sort points by date fMapPoints.QuickSort(MapPointsCompare); } PlacesLoader.CopyPoints(fView.MapBrowser, fMapPoints, ind != null); }
private bool IsInMapLimits(MapPlace mapPlace) { float edge = Places[0].GetComponent <RectTransform>().sizeDelta.x / 2; Vector2 mapSize = Map.GetComponent <RectTransform>().sizeDelta / 2; float xMax = (mapSize.x - edge) * 0.95f; float yMax = (mapSize.y - edge) * 0.95f; Vector3 localPosition = mapPlace.transform.localPosition; return(Mathf.Abs(localPosition.x) <= xMax && Mathf.Abs(localPosition.y) <= yMax); }
public GameMap MapCreation(UInt16 MapWidth, UInt16 MapHeight, UInt16 LevelsCount, UInt16 WallsCountOnWalledCells, double WalledCellProbability) { GameMap game = null; Map map; Random rand = new Random(); try { MapImage image = new MapImage(MapImageType.Bmp, null); MapPlace place = new MapPlace(image, (float)0.8); MapWall destroyedWall = new MapWall(image, MapDirection.North, 200); MapWall wall = new MapWall(image, MapDirection.North, 200); Dictionary <MapDirection, MapWall> walls = new Dictionary <MapDirection, MapWall>(); if (WallsCountOnWalledCells > 0) { walls.Add(MapDirection.North, wall); } if (WallsCountOnWalledCells > 1) { walls.Add(MapDirection.South, wall); } if (WallsCountOnWalledCells > 2) { walls.Add(MapDirection.West, wall); } if (WallsCountOnWalledCells > 3) { walls.Add(MapDirection.East, wall); } bool isWall = false; int probability = (int)Math.Round(WalledCellProbability * 100.0); map = new Map(LevelsCount, new MapSize(MapWidth, MapHeight)); for (int z = 0; z < map.LevelsCount; z++) { for (int x = 0; x < map.Size.Width; x++) { for (int y = 0; y < map.Size.Height; y++) { isWall = rand.Next(0, 100) < probability; map.Levels[z].Cells[x, y] = new MapCell(place, isWall ? walls : null); } } } game = new GameMap(new MapState(map)); } catch { } return(game); }
private void btnSelectPlaces_Click(object sender, EventArgs e) { GEDCOMIndividualRecord ind = null; bool condBirth = false; bool condDeath = false; bool condResidence = false; if (radTotal.Checked) { condBirth = chkBirth.Checked.GetValueOrDefault(); condDeath = chkDeath.Checked.GetValueOrDefault(); condResidence = chkResidence.Checked.GetValueOrDefault(); } else if (radSelected.Checked && (cmbPersons.SelectedIndex >= 0)) { GKComboItem item = (GKComboItem)cmbPersons.Items[cmbPersons.SelectedIndex]; ind = (item.Tag as GEDCOMIndividualRecord); } fMapBrowser.ShowLines = (ind != null && chkLinesVisible.Checked.GetValueOrDefault()); fMapPoints.Clear(); int num = fPlaces.Count; for (int i = 0; i < num; i++) { MapPlace place = fPlaces[i]; if (place.Points.Count < 1) { continue; } int num2 = place.PlaceRefs.Count; for (int j = 0; j < num2; j++) { GEDCOMCustomEvent evt = place.PlaceRefs[j].Event; if ((ind != null && (evt.Parent == ind)) || (condBirth && evt.Name == "BIRT") || (condDeath && evt.Name == "DEAT") || (condResidence && evt.Name == "RESI")) { PlacesLoader.AddPoint(fMapPoints, place.Points[0], place.PlaceRefs[j]); } } } if (ind != null) { // sort points by date fMapPoints.QuickSort(MapPointsCompare); } PlacesLoader.CopyPoints(fMapBrowser, fMapPoints, ind != null); }
public void SelectPlaces() { GEDCOMIndividualRecord ind = null; bool condBirth = false; bool condDeath = false; bool condResidence = false; if (fView.TotalRadio.Checked) { condBirth = fView.BirthCheck.Checked; condDeath = fView.DeathCheck.Checked; condResidence = fView.ResidenceCheck.Checked; } else if (fView.SelectedRadio.Checked && (fView.PersonsCombo.SelectedIndex >= 0)) { ind = (fView.PersonsCombo.SelectedTag as GEDCOMIndividualRecord); } fView.MapBrowser.ShowLines = (ind != null && fView.LinesVisibleCheck.Checked); fMapPoints.Clear(); int num = fPlaces.Count; for (int i = 0; i < num; i++) { MapPlace place = fPlaces[i]; if (place.Points.Count < 1) { continue; } int num2 = place.PlaceRefs.Count; for (int j = 0; j < num2; j++) { GEDCOMCustomEvent evt = place.PlaceRefs[j].Event; if ((ind != null && (evt.Parent == ind)) || (condBirth && evt.Name == "BIRT") || (condDeath && evt.Name == "DEAT") || (condResidence && evt.Name == "RESI")) { PlacesLoader.AddPoint(fMapPoints, place.Points[0], place.PlaceRefs[j]); } } } if (ind != null) { // sort points by date fMapPoints.QuickSort(MapPointsCompare); } PlacesLoader.CopyPoints(fView.MapBrowser, fMapPoints, ind != null); }
public static void SaveUserCreatedPoint(MapPlace place) { var dataModel = new DesignEntities(); dataModel.MapPlaces.Add(place); dataModel.SaveChanges(); EmailMe.SendMeAEmail(new EmailMe.Email { Body = string.Format("A new map point created, {0} {1}",place.Title,place.Description), EmailAddress = "*****@*****.**", Name = "Jons Site", Subject = "Point created from your site" }); }
private void AddPlace(GEDCOMPlace place, GEDCOMCustomEvent placeEvent) { try { GEDCOMLocationRecord locRec = place.Location.Value as GEDCOMLocationRecord; string placeName = (locRec != null) ? locRec.LocationName : place.StringValue; var node = FindTreeNode(placeName); MapPlace mapPlace; if (node == null) { mapPlace = new MapPlace(); mapPlace.Name = placeName; fPlaces.Add(mapPlace); node = new GKTreeNode(placeName, mapPlace); fBaseRoot.Children.Add(node); if (locRec == null) { AppHost.Instance.RequestGeoCoords(placeName, mapPlace.Points); int num = mapPlace.Points.Count; for (int i = 0; i < num; i++) { GeoPoint pt = mapPlace.Points[i]; string ptTitle = pt.Hint + string.Format(" [{0:0.000000}, {1:0.000000}]", pt.Latitude, pt.Longitude); node.Children.Add(new GKTreeNode(ptTitle, pt)); } } else { GeoPoint pt = new GeoPoint(locRec.Map.Lati, locRec.Map.Long, placeName); mapPlace.Points.Add(pt); string ptTitle = pt.Hint + string.Format(" [{0:0.000000}, {1:0.000000}]", pt.Latitude, pt.Longitude); node.Children.Add(new GKTreeNode(ptTitle, pt)); } } else { mapPlace = (((GKTreeNode)node).Tag as MapPlace); } mapPlace.PlaceRefs.Add(new PlaceRef(placeEvent)); } catch (Exception ex) { Logger.LogWrite("MapsViewerWin.AddPlace(): " + ex.Message); } }
private void LocatePlaceWithTwoRestricitons(MapPlace toLocate, List <MapPlace> prevPlaces, List <MapPlace> locatedPlaces, float xMax, float yMax, float distanceMin) { float x; float y; MapPlace placed1 = prevPlaces[0]; MapPlace placed2 = prevPlaces[1]; int edgeLength1; int edgeLength2; do { edgeLength1 = Random.Range(3, 10); edgeLength2 = Random.Range(3, 10); float d1 = edgeLength1 * Ruler.GetUnityDistances(); float d2 = edgeLength2 * Ruler.GetUnityDistances(); float a = placed1.transform.position.x; float b = placed1.transform.position.y; float c = placed2.transform.position.x; float d = placed2.transform.position.y; // greg is a fun name, it is only an abbreviation of a calculus var f1 = Mathf.Pow(d2, 2); float greg = Mathf.Pow(d1, 2) - f1 - Mathf.Pow(a, 2) - Mathf.Pow(d - b, 2) + Mathf.Pow(c, 2); float bascaraA = 1 + Mathf.Pow(a - c, 2) / (Mathf.Pow(d - b, 2)); float bascaraB = (greg * (a - c) / (Mathf.Pow(d - b, 2))) - 2 * c; float bascaraC = Mathf.Pow(greg, 2) / (4 * Mathf.Pow(d - b, 2)) - f1 + Mathf.Pow(c, 2); if (Randomizer.RandomBoolean()) { x = (-bascaraB + Mathf.Sqrt(Mathf.Pow(bascaraB, 2) - 4 * bascaraA * bascaraC)) / (2 * bascaraA); } else { x = (-bascaraB - Mathf.Sqrt(Mathf.Pow(bascaraB, 2) - 4 * bascaraA * bascaraC)) / (2 * bascaraA); } float f2 = Mathf.Pow((x - c), 2); y = Mathf.Sqrt(f1 - f2) + d; if (!float.IsNaN(x) && !float.IsNaN(y)) { toLocate.transform.position = new Vector2(x, y); } } while (float.IsNaN(x) || float.IsNaN(y) || EdgeIsIncorrect(toLocate, locatedPlaces, xMax, yMax, distanceMin, edgeLength1 > edgeLength2 ? edgeLength1 : edgeLength2)); List <ShipmentEdge> edges = ShipmentsView.instance.Model.GetEdgesByIdNode(toLocate.Id); edges.Find(e => e.IdNodeA == placed1.Id || e.IdNodeB == placed1.Id).Length = edgeLength1; edges.Find(e => e.IdNodeA == placed2.Id || e.IdNodeB == placed2.Id).Length = edgeLength2; }
private void CheckEdgeAnswer(ShipmentEdge realEdge, List <ShipmentEdge> edgeAnswers, int index) { if (index > 0) { Invoke("PlayBoatSond", 0.2f); } else { PlayBoatSond(); } // no hay arista if (realEdge == null) { AnswerEdgeNotExists( MapGenerator.Places.Find(e => e.Id == edgeAnswers[index].IdNodeB).transform.position, 2, edgeAnswers); return; } ; var answerEdge = edgeAnswers[index]; MapPlace destine = MapGenerator.Places.Find(e => e.Id == answerEdge.IdNodeB); int answerValue = answerEdge.Length / (Model.Scale); int rest = answerEdge.Length % Model.Scale; // caso correcto if (answerValue == realEdge.Length && rest == 0) { Player.transform.DOMove(destine.transform.position, GetDuration(realEdge.Length)) .OnComplete(() => { AddGold(); index++; indexToCorrect = index; Invoke("CorrectAnswerContinueCorrection", 1); }); } // se pasó else if (answerValue >= realEdge.Length) { AnswerEdgeTooLong(destine.transform.position, realEdge.Length, edgeAnswers); } // se quedó corto else { AnswerEdgeTooShort(destine.transform.position, realEdge.Length); } }
private void AddPlace(GDMPlace place, GDMCustomEvent placeEvent) { try { GDMLocationRecord locRec = place.Location.Value as GDMLocationRecord; string placeName = (locRec != null) ? locRec.LocationName : place.StringValue; ITVNode node = fView.FindTreeNode(placeName); MapPlace mapPlace; if (node == null) { mapPlace = new MapPlace(); mapPlace.Name = placeName; fPlaces.Add(mapPlace); node = fView.PlacesTree.AddNode(fBaseRoot, placeName, mapPlace); if (locRec == null) { PlacesCache.Instance.GetPlacePoints(placeName, mapPlace.Points); } else { GeoPoint pt = new GeoPoint(locRec.Map.Lati, locRec.Map.Long, placeName); mapPlace.Points.Add(pt); } int num = mapPlace.Points.Count; for (int i = 0; i < num; i++) { GeoPoint pt = mapPlace.Points[i]; string ptTitle = pt.Hint + string.Format(" [{0:0.000000}, {1:0.000000}]", pt.Latitude, pt.Longitude); fView.PlacesTree.AddNode(node, ptTitle, pt); } } else { mapPlace = (node.Tag as MapPlace); } mapPlace.PlaceRefs.Add(new PlaceRef(placeEvent)); } catch (Exception ex) { Logger.LogWrite("MapsViewerWin.AddPlace(): " + ex.Message); } }
void canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (TargetObject == null) { return; } Point p = e.MouseDevice.GetPosition(canvas); MapPoint cellPoint = Renderer.GetMapPointByPoint(p); if (TargetObject.SourceBase is MapPlace) { MapPlace place = TargetObject.SourceBase as MapPlace; TargetMap.Map.SetPlace(place, cellPoint); Renderer.Render(); } }
private void MapPlace_OnLoaded(object sender, RoutedEventArgs e) { //throw new NotImplementedException(); var rmain = ServiceLocator.Current.GetInstance <MainViewModel>(); MapPlace.SetView(new Location(rmain.Latitude, rmain.Longitude), 12); MapPlace.Children.Clear(); foreach (BasePlaceItem item in rmain.NearestItems) { Pushpin pushpin = new Pushpin(); var location = new Location((item.Latitude), (item.Longitude)); MapLayer.SetPosition(pushpin, location); //pushpin.Background = new SolidColorBrush() { Color = new Color() {A=0, B=0, G=0, R=255}}; pushpin.Name = item.Id.ToString(); //pushpin.Tapped += pushpinTapped; MapPlace.Children.Add(pushpin); } ; }
public void TestCellsMatrix() { MapSize size = new MapSize(1000, 1000); MapPlace place = new MapPlace(new MapImage(MapImageType.Bmp, null), 1); MapCell cell = new MapCell(place, null); MapMatrix <MapCell> matrix1 = new MapMatrix <MapCell>(size); MapCell[,] matrix2 = new MapCell[size.Width, size.Height]; for (int x = 0; x < size.Width; x++) { for (int y = 0; y < size.Height; y++) { matrix1[x, y] = cell; matrix2[x, y] = cell; } } DateTime start1 = DateTime.Now; for (int i = 0; i < 1000000; i++) { cell = matrix1[25, 68]; } DateTime finish1 = DateTime.Now; DateTime start2 = DateTime.Now; for (int i = 0; i < 1000000; i++) { cell = matrix2[25, 68]; } DateTime finish2 = DateTime.Now; double result1 = (finish1 - start1).TotalMilliseconds; double result2 = (finish2 - start2).TotalMilliseconds; Assert.IsTrue(result1 < 100); }
private void SafeLocatePlace(MapPlace toLocate, List <MapPlace> locatedPlaces, List <ShipmentEdge> toLocateEdges, float xMax, float yMax, float distanceMin) { List <MapPlace> prevPlaces = ObtainLocatedNodesPrev(locatedPlaces, toLocateEdges); /* * if(prevPlaces.Count > 2) throw new Exception("Mmmhhh tiene muchas restricciones previas. Revisar la generación del grafo."); */ switch (prevPlaces.Count) { case 2: LocatePlaceWithTwoRestricitons(toLocate, prevPlaces, locatedPlaces, xMax, yMax, distanceMin); break; case 1: LocatePlaceWithOneRestriction(toLocate, prevPlaces, locatedPlaces, xMax, yMax, distanceMin); break; default: do { toLocate.transform.localPosition = new Vector2((Randomizer.RandomBoolean() ? 1 : -1) * Random.Range(0, xMax), (Randomizer.RandomBoolean() ? 1 : -1) * Random.Range(0, yMax)); } while (EdgeIsIncorrect(toLocate, locatedPlaces, xMax, yMax, distanceMin, 5)); break; } locatedPlaces.Add(toLocate); /* * * Vector2 otherPosition = located.CrossReference.transform.position; * * float f; * do * { * toLocate.transform.localPosition = new Vector2((Randomizer.RandomBoolean() ? 1 : -1) * Random.Range(0, xMax), (Randomizer.RandomBoolean() ? 1 : -1) * Random.Range(0, yMax)); * var referenceDistance = Vector2.Distance(toLocate.CrossReference.transform.position, otherPosition); * f = referenceDistance / Ruler.GetUnityDistances(); * } while (f < 1.8 || Math.Abs(f % 1) > 0.1); * * ShipmentsView.instance.measuresList.Add((int)f);*/ }
/* * private bool CheckEdgeDistances(MapPlace mapPlace, List<MapPlace> locatedPlaces, List<int> edgeDistances) * { * for (var i = locatedPlaces.Count - 1; i >= 0; i--) * { * MapPlace locatedPlace = locatedPlaces[i]; * /* * float distance = Vector2.Distance(locatedPlace.transform.localPosition, mapPlace.transform.localPosition); #1# * float referenceDistance = Vector2.Distance(locatedPlace.CrossReference.transform.position, mapPlace.CrossReference.transform.position); * float f = referenceDistance / Ruler.GetUnityDistances(); * if (Math.Abs(f - edgeDistances[i]) > 0.1) * { * return false; * } * * } * * return true; * } */ private bool CheckMinDistances(MapPlace mapPlace, List <MapPlace> locatedPlaces, float distanceMin) { iterations++; if (iterations > 100) { return(false); } foreach (MapPlace locatedPlace in locatedPlaces) { if (locatedPlace.Id == mapPlace.Id) { continue; } ; float distance = Vector2.Distance(locatedPlace.transform.localPosition, mapPlace.transform.localPosition); if (distance < distanceMin) { return(false); } } return(true); }
private void Initializing() { bool explo = true; Place place = Place.Null; if (!ReferenceEquals(treasureController, null)) { explo = treasureController.Exploration; place = treasureController.CurrentPlace; } if (explo) { for (int i = 0; i < _treasureGameObjects.Length; i++) { SetActive(_treasureGameObjects[i], false); } } else { for (int i = 0; i < _treasureGameObjects.Length; i++) { MapPlace mapPlace = _treasureGameObjects[i].GetComponent <MapPlace>(); if (!ReferenceEquals(mapPlace, null)) { if (mapPlace.TargetPlace == place) { SetActive(_treasureGameObjects[i], true); } else { SetActive(_treasureGameObjects[i], false); } } } } }
public void TraceEdges(List <ShipmentEdge> edges) { if (lines == null) { lines = new List <VectorLine>(); } foreach (VectorLine line in lines) { line.rectTransform.gameObject.SetActive(false); } foreach (ShipmentEdge shipmentEdge in edges) { MapPlace mapPlace = Places.Find(e => e.Id == shipmentEdge.IdNodeA); MapPlace place = Places.Find(e => e.Id == shipmentEdge.IdNodeB); Vector3 position = mapPlace.CrossReference.gameObject.transform.position; Vector3 vector3 = place.CrossReference.gameObject.transform.position; VectorLine line = new VectorLine("Curve", new List <Vector2> { position, vector3 }, null, 8.0f, LineType.Continuous); line.SetCanvas(FindObjectOfType <Canvas>()); line.material = DottedLineMateriallMaterial[lastMaterial++]; if (lastMaterial == DottedLineMateriallMaterial.Length) { lastMaterial = 0; } line.textureScale = 1f; line.textureScale = 1f; line.Draw(); lines.Add(line); line.rectTransform.transform.SetParent(Ruler.transform.parent); } }
public static void SerializeMapPlace(BinaryWriter Writer, MapPlace Place) { SerializeMapVisualObject(Writer, Place); Writer.Write(Place.Passability); }
public PlaceViewModel(MapPlace place) : base(place) { Source = place; }
public PollutionSource(MapPlace place) : base(place) { }
private static MapPlace DeserializeMapPlace(BinaryReader Reader) { MapPlace place = new MapPlace(); DeserializeMapVisualObject(Reader, place); place.Passability = Reader.ReadSingle(); return place; }
private static MapPlaceState DeserializeMapPlaceState(BinaryReader Reader, MapPlace place) { return new MapPlaceState(place); }
public Processor(MapPlace place) : base(place) { }
private void LocatePlaceWithOneRestriction(MapPlace toLocate, List <MapPlace> prevPlaces, List <MapPlace> locatedPlaces, float xMax, float yMax, float distanceMin) { MapPlace located = prevPlaces[0]; Vector2 otherPosition = located.transform.position; ShipmentEdge edge = ShipmentsView.instance.Model.GetEdgesByIdNode(toLocate.Id).Find(e => e.IdNodeA == located.Id || e.IdNodeB == located.Id); float f; do { toLocate.transform.localPosition = new Vector2((Randomizer.RandomBoolean() ? 1 : -1) * Random.Range(0.1f * xMax, 0.9f * xMax), (Randomizer.RandomBoolean() ? 1 : -1) * Random.Range(0.1f * yMax, 0.9f * yMax)); float a = Ruler.GetUnityDistances(); float distance = edge.Length == 0 ? Random.Range(3, 9) : edge.Length; float x; float y; if (Randomizer.RandomBoolean()) { // x random x = toLocate.transform.position.x; float f1 = distance * a; float f2 = x - otherPosition.x; while (Mathf.Abs(f1) < Mathf.Abs(f2)) { if (edge.Length != 0) { /* * throw new Exception("Edge have to b resized but the node is located"); */ } if (distance < 10) { distance++; } else { toLocate.transform.localPosition = new Vector2((Randomizer.RandomBoolean() ? 1 : -1) * Random.Range(0, x), 0); x = toLocate.transform.position.x; f2 = x - otherPosition.x; } f1 = distance * a; } float sqrt = Mathf.Sqrt(Mathf.Pow(f1, 2) - Mathf.Pow(f2, 2)); y = -sqrt + otherPosition.y; } else { // y random y = toLocate.transform.position.y; float f1 = distance * a; float f2 = y - otherPosition.y; while (Mathf.Abs(f1) < Mathf.Abs(f2)) { if (edge.Length != 0) { /* * throw new Exception("Edge have to b resized but the node is located"); */ } if (distance < 10) { distance++; } else { toLocate.transform.localPosition = new Vector2(0, (Randomizer.RandomBoolean() ? 1 : -1) * Random.Range(0, yMax)); y = toLocate.transform.position.y; f2 = y - otherPosition.y; } f1 = distance * a; } float sqrt = Mathf.Sqrt(Mathf.Pow(f1, 2) - Mathf.Pow(f2, 2)); x = -sqrt + otherPosition.x; } toLocate.transform.position = new Vector2(x, y); var referenceDistance = Vector2.Distance(toLocate.transform.position, otherPosition); f = referenceDistance / a; } while (EdgeIsIncorrect(toLocate, locatedPlaces, xMax, yMax, distanceMin, f)); edge.Length = (int)f; }