/// <summary> /// Will order the _eval by weight from two. So when checking for intersection will start with the /// one tht has less wight from _two /// </summary> private bool OrderEvalByWeight() { var canI = CanPrepareLoop("OrderEvalByWeight"); if (!canI) { return(false); } //means tht another llop is running now var i = loopCount; if (loopCount < _eval.Count) { //_eval[i].CalculateWeight(_curr.Position, U2D.FromV3ToV2(_two.Position), _curr.Id); //_eval[i].CalculateWeight(U2D.FromV3ToV2(_curr.Position)); var finOrC = ReturnCorFinal(); _eval[i].CalculateWeight(finOrC, _two.Position, U2D.FromV2ToV3(_curr.Position)); loopCount++; return(true);//will cut Recursive Path intentionally, bz i need to finish this loop } else { _eval = _eval.OrderBy(a => a.CalcWeight).ToList(); ResetLoop(); return(false);//so let Recursive Keeps it course } }
void DebugBlackThrow() { #if UNITY_EDITOR if (!wasThrow) { if (!debugMarkedOnLand) { debugMarkedOnLand = true; //curr pos is yellow Crystal.DebugCrystal.AddGameObjInPosition(U2D.FromV2ToV3(_curr.Position), Root.yellowSphereHelp); //eval are blue //UVisHelp.CreateHelpers(_eval, Root.blueCube); //UVisHelp.CreateText(U2D.FromV2ToV3(_curr.Position), _curr.CalcWeight + ""); for (int i = 0; i < _debugLines.Count; i++) { _debugLines[i].DebugRender(Color.yellow, 100); } } wasThrow = true; //Program.gameScene.GameSpeed = 0; //throw new Exception("Debug to find why is going to blacklist"); } #endif }
/// <summary> /// Will try to reach RectC or Final and will set explorer object that will tell if are /// Buidings in the middle or not /// </summary> /// <returns></returns> private bool ExploreToFin() { var stepFinalPos = ReturnCorFinal(); // //Debug.Log("Exploring"); canIExplore = false; Line line = new Line(U2D.FromV2ToV3(_curr.Position), stepFinalPos, durationOfLines); _debugLines.Add(line); var interCount = IntersectCount(line); if (interCount == 0) { // //Debug.Log("Exploring went good "); _curr = new Crystal(stepFinalPos, H.None, "", setIdAndName: false); loop = true; //canIExplore = true;//needs to be able to keep exploring ResetExplorer(); ResetLoop(); ClearPrevLoop(); return(true); } return(false); }
internal static List <General> CreateHelpers(List <Crystal> _eval, string root) { List <General> res = new List <General>(); for (int i = 0; i < _eval.Count; i++) { res.Add(General.Create(root, U2D.FromV2ToV3(_eval[i].Position))); } return(res); }
void InitSeaM(Vector2 compare) { _seaM.Clear(); for (int i = 0; i < _seaPath.Count; i++) { var v3 = new Vector3(_seaPath[i].x, m.IniTerr.MathCenter.y, _seaPath[i].y); _seaM.Add(new VectorM((v3), U2D.FromV2ToV3(compare))); } _seaM = _seaM.OrderBy(a => a.Distance).ToList(); }
/// <summary> /// Will tell u if is just crossing a brdige this time /// </summary> /// <param name="_curr"></param> /// <param name="crystal"></param> /// <returns></returns> private bool IsGettingIntoBridge(Crystal currP, Crystal eval) { var samePos = UMath.nearEqualByDistance(U2D.FromV2ToV3(eval.Position), _two.Position, 0.1f); if (samePos) { return(true); } return(false); }
/// <summary> /// Bz they needs to be moved a bit away from Buildign /// </summary> /// <returns></returns> private Crystal ReturnCrystalFurtherTo(Crystal crystal, Vector3 closerTo) { float moveBy = 0.1f; var moved = Vector3.MoveTowards(U2D.FromV2ToV3(crystal.Position), Current, moveBy); crystal.Position = U2D.FromV3ToV2(moved); return(crystal); }
/// <summary> /// Will order _mountainM by distance from 'compare' /// </summary> /// <param name="compare"></param> private void InitMountainM(Vector2 compare) { _mountainM.Clear(); for (int i = 0; i < _mountainPath.Count; i++) { var v3 = new Vector3(_mountainPath[i].x, m.IniTerr.MathCenter.y, _mountainPath[i].y); _mountainM.Add(new VectorM((v3), U2D.FromV2ToV3(compare))); } _mountainM = _mountainM.OrderBy(a => a.Distance).ToList(); }
/// <summary> /// Center of the region the camera is on top of now /// </summary> /// <param name="camPos"></param> /// <returns></returns> internal Vector3 CurrentRegionPos(Vector3 camPos) { var v2 = U2D.FromV3ToV2(camPos); var index = ReturnMyRegion(v2); if (index == -1) { return(camPos); } return(U2D.FromV2ToV3(CrystalRegions[index].Region.center)); }
public static void CreateDebugLines(Rect rect, Color color, float duration = 6000f) { Vector3 NW = U2D.FromV2ToV3(new Vector2(rect.xMin, rect.yMin)); Vector3 NE = U2D.FromV2ToV3(new Vector2(rect.xMax, rect.yMin)); Vector3 SE = U2D.FromV2ToV3(new Vector2(rect.xMax, rect.yMax)); Vector3 SW = U2D.FromV2ToV3(new Vector2(rect.xMin, rect.yMax)); Debug.DrawLine(NW, NE, color, duration); Debug.DrawLine(NE, SE, color, duration); Debug.DrawLine(SE, SW, color, duration); Debug.DrawLine(SW, NW, color, duration); }
private void Recursive() { if (prevLoop == "") { //tha adding of a good point to the Route _checkPoints.Add(new CheckPoint(U2D.FromV2ToV3(_curr.Position), _curr.Type1)); if (wasThrow) { var a = 1; } if (CheckIfDone()) { CanIReach2PointAfter(); Ready(); //if (_finDoor) //{ // Crystal.DebugCrystal.ShowNow(); //} return; } CreateCryRect(); DefineHistoCrys(); DefineCrystalsOnMyRect(); } else if (prevLoop == "DefineCrystalsOnMyRect") { ClearPrevLoop(); OrderCyrstalsFromCurr(); } else if (prevLoop == "OrderCyrstalsFromCurr") { ClearPrevLoop(); DefineEvalCrystals(); AddToEvalFromRect();//i place it here so Auto Delta Routing works if (OrderEvalByWeight()) { return; } //so then is called again until I finish the loop } else if (prevLoop == "OrderEvalByWeight") { ClearPrevLoop(); //PushAwayToLastOnEval(); //InsertFinDoor(); TryReachEval(); } }
private List <Crystal> ReturnOrderedAnchors() { List <Crystal> anchorOrdered = new List <Crystal>(); anchorOrdered = ReturnScaledAnchorsFromBuildingOrStillElement(); for (int i = 0; i < anchorOrdered.Count; i++) { anchorOrdered[i].Distance = Mathf.Abs(Vector3.Distance(U2D.FromV2ToV3(anchorOrdered[i].Position), Final)); } anchorOrdered = anchorOrdered.OrderBy(a => a.Distance).ToList(); return(anchorOrdered); }
internal static List <General> CreateTextEnumarate(List <Crystal> _eval, string p, string texto = "", int fontSize = 120) { List <General> res = new List <General>(); for (int i = 0; i < _eval.Count; i++) { General g = General.Create(Root.texto3d, U2D.FromV2ToV3(_eval[i].Position)); TextMesh textObject = g.transform.GetComponent <TextMesh>(); textObject.fontSize = fontSize; textObject.text = texto + "." + i; res.Add(g); } return(res); }
/// <summary> /// Created to Report Ambience Sound. I need to see how many diff crsytals are /// to detect River, Ocean shore and Full Ocean /// </summary> /// <returns></returns> private string DefineWhichAudioIReport() { //106 ocean shore, 84 river , 64 riv if (Index == 106 || Index == 84 || Index == 64) { var a = 1; } if (Index == 51) { var a = 1; } var myCrsytals = ReturnDiffCrystalsNames(); //crystals that are seaType var seaTypes = myCrsytals.Where(a => a.Type1 == H.WaterObstacle).ToList(); var mountTypes = myCrsytals.Where(a => a.Type1 == H.MountainObstacle).ToList(); var linkTypes = myCrsytals.Where(a => a.Type1 == H.LinkRect).ToList(); var uniqueZones = ReturnDiffCrystals(linkTypes, H.LinkRect); if (myCrsytals.Count == 1) { return("InLand"); } else if (mountTypes.Count > 0) { return("Mountain"); } else if (myCrsytals.Count > 1 && uniqueZones.Count == 0) { return("Later");//OceanSHore } else if (myCrsytals.Count > 1 && uniqueZones.Count == 1) { //this ones will find later if have a Full Ocean around if they do that //it is OceanShore. Otherwise is River return("Later"); } else if (myCrsytals.Count > 1 && uniqueZones.Count > 1) { return("River"); } if (!UTerra.IsOnTerrain(U2D.FromV2ToV3(Region.center))) { return("OutOfTerrain"); } return("FullOcean"); }
/// <summary> /// Will show names on game /// </summary> private void DebugShowNames() { for (int i = 0; i < _current.LinkRects.Count; i++) { // //Debug.Log(_current.LinkRects[i].Name); UVisHelp.CreateText(U2D.FromV2ToV3(_current.LinkRects[i].Position), _current.LinkRects[i].Name, 150); } for (int i = 0; i < _landZones.Count; i++) { // //Debug.Log(_current.LinkRects[i].Name); UVisHelp.CreateText(U2D.FromV2ToV3(_landZones[i].CalcPosition()) + new Vector3(0, 15, 0), _landZones[i].LandZoneName, 1400); } }
private Vector2 FindClosestToMe(Vector2 dot, List <Vector3> poly) { List <VectorM> lis = new List <VectorM>(); for (int i = 0; i < poly.Count; i++) { lis.Add(new VectorM(poly[i], U2D.FromV2ToV3(dot))); } lis = lis.OrderBy(a => a.Distance).ToList(); var closest = lis[0].Point; return(U2D.FromV3ToV2(closest)); }
/// <summary> /// Depending on _curr position will return Final or C. /// So when Im explirng to Final takes in account that we are hitting the sea or a mountain /// in some RectC /// </summary> /// <returns></returns> Vector3 ReturnCorFinal() { var curr = U2D.FromV2ToV3(_curr.Position); var two = _two.Position; Vector3 cVect = Vector3.MoveTowards(curr, two, howFarIsRectC);//20 var distToFin = Vector3.Distance(curr, two); //if dist To Final greater that howFarIsRectC, then return C if (distToFin > howFarIsRectC) { return(cVect); } return(two); }
/// <summary> /// Will return the region index where all the Structure points are /// </summary> /// <param name="building"></param> /// <returns></returns> List <int> ReturnRegionsOfPointsInStructure(Building building) { //nt for Trails List <Vector3> points = new List <Vector3>(); if (!building.MyId.Contains("Trail")) { points = PassAnchorsGetPositionForCrystals(building.Anchors); } //for buildings if (!building.MyId.Contains("Bridge") && !building.MyId.Contains("Trail")) { Structure st = (Structure)building; if (st.SpawnPoint != null) { points.Add(st.SpawnPoint.transform.position); } } //for bridges if (building.MyId.Contains("Bridge")) { var entries = GetBridgeEntries((Bridge)building); points.Add(U2D.FromV2ToV3(entries[0].Position)); points.Add(U2D.FromV2ToV3(entries[1].Position)); } //for Ways that are Trails if (building.MyId.Contains("Trail")) { var obstas = _allObstas.Where(a => a.ParentId == building.MyId).ToList(); for (int i = 0; i < obstas.Count; i++) { points.Add(U2D.FromV2ToV3(obstas[i].Position)); _allObstas.Remove(obstas[i]); } } List <int> res = new List <int>(); for (int i = 0; i < points.Count; i++) { res.Add(ReturnMyRegion(U2D.FromV3ToV2(points[i]))); } return(res.Distinct().ToList()); }
internal void CalculateWeight(Vector3 finOrC, Vector3 final, Vector3 curr) { Distance = Mathf.Abs(Vector3.Distance(U2D.FromV2ToV3(_position), final)); var furtherWeight = CheckIfFurtherThanCurr(curr, final); //can't be further than C furtherWeight += CheckIfFurtherThanCurr(curr, finOrC); //we are going to substract then if (Type1.ToString().Contains("Way")) { Distance = Mathf.Abs(Vector3.Distance(U2D.FromV2ToV3(_position), curr)); } _calcWeight = _baseWeight + Distance + furtherWeight; }
bool TryReachBuilding() { loop = true; //UVisHelp.CreateTextEnumarate(_eval, Root.blueCube, counter1+"", 60); for (int i = 0; i < _eval.Count; i++) { Line aLine = new Line(U2D.FromV2ToV3(_curr.Position), U2D.FromV2ToV3(_eval[i].Position), durationOfLines); _debugLines.Add(aLine); var linesIntersected = IntersectCount(aLine); if (linesIntersected == 0 && !IsOnTheRoute(_eval[i].Position)) { ResetExplorer(); _curr = _eval[i]; //UVisHelp.CreateHelpers(U2D.FromV2ToV3(_curr.Position), Root.yellowCube); ResetLoop(); ClearPrevLoop();//so can restart Recursive() return(true); } } #if UNITY_EDITOR //UVisHelp.CreateHelpers(_eval, Root.blueCube); //UVisHelp.CreateHelpers(_curr.Position, Root.yellowCube); //UVisHelp.CreateHelpers(_two.Position, Root.yellowCube); //UVisHelp.CreateText(_ini.transform.position, "ini:" + _ini.MyId, 40); //UVisHelp.CreateText(_fin.transform.position, "fin:" + _fin.MyId, 40); #endif Debug.Log("At least the intersection should be reached. Go and investigate but at least once should " + "pass this if all fail pls investigate" + "\n ini:" + _ini.MyId + " mid:" + _eval[0].ParentId + " end:" + _fin.MyId + " person:" + _person.MyId + " " + "eval ct:" + _eval.Count + " prof:" + _person.ProfessionProp.ProfDescription); BlackList(); //throw new Exception("At least the intersection should be reached. Go and investigate but at least once should " + // "pass this if all fail pls investigate" + // "\n ini:" + _ini.MyId + " mid:" + _eval[0].ParentId + " end:" + _fin.MyId + " person:" + _person.MyId + " " + // "eval ct:" + _eval.Count + " prof:"+_person.ProfessionProp.ProfDescription); return(false); }
void Start() { _animator = gameObject.GetComponent <Animator>(); _hover = GetChildCalled("Hover"); _hover.gameObject.SetActive(false); var poly = U2D.FromRectToPoly(Region); buildingPrev = (BigBoxPrev)CreatePlane.CreatePlan(Root.bigBoxPrev, Root.dashedLinedSquare, container: transform); buildingPrev.UpdatePos(poly, .25f); buildingPrev.transform.position = U2D.FromV2ToV3(Region.center); //MeshController.CrystalManager1.CrystalRegions[Index].StartWithAudioReport(); Name = "Buy region"; HType = H.BuyRegion; transform.position += new Vector3(0, 10000, 0); }
internal List <Vector3> ReturnPointsInLineEvery(float step) { var a1Loc = U2D.FromV2ToV3(A1); var b1Loc = U2D.FromV2ToV3(B1); List <Vector3> res = new List <Vector3>(); distanceLeft = Vector3.Distance(a1Loc, b1Loc); var add = step; for (float i = 0; i < distanceLeft; i += add) { var point = Vector3.MoveTowards(a1Loc, b1Loc, add); res.Add(point); a1Loc = point; } return(res); }
static public ForSaleRegionGO CreateForSaleRegionGO(string root, int index, Rect region, string name = "", Transform container = null, H hType = H.None) { ForSaleRegionGO obj = null; obj = (ForSaleRegionGO)Resources.Load(root, typeof(ForSaleRegionGO)); obj = (ForSaleRegionGO)Instantiate(obj, U2D.FromV2ToV3(region.center), Quaternion.identity); obj.HType = hType; obj.MyId += " " + index; obj.Index = index; obj.Region = region; if (container != null) { obj.transform.SetParent(container); } return(obj); }
/// <summary> /// Will return the region index where all the StillElement points are /// </summary> /// <param name="still"></param> /// <returns></returns> private List <int> ReturnRegionsOfPointsInStructure(StillElement still) { List <Vector3> points = new List <Vector3>(); var obstas = _allObstas.Where(a => a.ParentId == still.MyId).ToList(); for (int i = 0; i < obstas.Count; i++) { points.Add(U2D.FromV2ToV3(obstas[i].Position)); _allObstas.Remove(obstas[i]); } List <int> res = new List <int>(); for (int i = 0; i < points.Count; i++) { res.Add(ReturnMyRegion(U2D.FromV3ToV2(points[i]))); } return(res.Distinct().ToList()); }
/// <summary> /// /// </summary> /// <param name="ini"></param> /// <param name="end"></param> /// <param name="minimuSize">must have one side with a mimunum side like 10f /// this is to allow Mountain Routing to happen</param> /// <param name="grow">The grow of the rect on scale to make sure contain first and last </param> public CryRect(Vector3 ini, Vector3 end, float grow, bool minimuSize = true, float debugDuration = 20f) { _a = U2D.FromV3ToV2(ini); var poly = Registro.FromALotOfVertexToPolyMathCenterY(new List <Vector3>() { ini, end }); poly = UPoly.ScalePoly(poly, grow); _theRect = Registro.FromALotOfVertexToRect(poly); _c = U2D.FromV3ToV2(end); _b = FindB(); _d = FindD(); //so Rect Grows //so way routing works //PushThemAway(); if (minimuSize) { //when calling this is really importat bz this solved the Mountain Routing problem //Dec 26 2015 ApplyMinimumSize(); } var newPoly = new List <Vector3>() { U2D.FromV2ToV3(_a), U2D.FromV2ToV3(_b), U2D.FromV2ToV3(_c), U2D.FromV2ToV3(_d) }; _theRect = Registro.FromALotOfVertexToRect(newPoly); //RectifyCorners(poly); UVisHelp.CreateDebugLines(TheRect, Color.magenta, debugDuration); SetCrystals(); }
private float howFarIsRectC = 40f; //20 . 20 was too small bz will go trhu mountains /// <summary> /// This is the area we gonna be looking at to evaluate crystals /// </summary> private void CreateCryRect() { var curr = U2D.FromV2ToV3(_curr.Position); var two = _two.Position; if (CheckIfNeedGrow()) { maxCounts++; //curr = PushAwayFromCurrRectCenter(curr); //two = PushAwayFromCurrRectCenter(two); //return; } //the C Vector on the Rect Vector3 cVect = Vector3.MoveTowards(curr, two, howFarIsRectC);//20 _currRect = new CryRect(U2D.FromV2ToV3(_curr.Position), cVect, grow, debugDuration: durationOfLines); _oldCurr = _curr; AddToHistoricalRegions(cVect); AddToHistoricalRegions(U2D.FromV2ToV3(_curr.Position)); }
/// <summary> /// Will set the _calcWeight on the Cristal from 'otherPos' /// </summary> /// <param name="otherPos"></param> public void CalculateWeight(Vector2 curr, Vector2 final, string cryId)//loopCount only use for debug purpose { var pilotDistance = CalcPilotDistance(curr, final); //var pilot = Vector2.MoveTowards(curr, final, pilotDistance); var angle = AbsoluteAngleFrom3PointsInDegrees(final, Position, curr); var sine = Math.Abs((float)Math.Sin(ConvertToRadians(angle))); //Debug.Log("Angle: " + angle); var furtherWeight = CheckIfFurtherThanCurr(curr, final); //var posiToFin = Math.Abs( Vector2.Distance(Position, final)); //var currToPosit = Math.Abs(Vector2.Distance(curr, Position)); var posiToFin = Math.Abs(Vector3.Distance(U2D.FromV2ToV3(Position), U2D.FromV2ToV3(final))); var currToPosit = Math.Abs(Vector3.Distance(U2D.FromV2ToV3(curr), U2D.FromV2ToV3(Position))); //Distance = 3 * Vector2.Distance(_position, curr);//pilot Distance = (posiToFin + currToPosit); //pilot _calcWeight = // sine * sineFactor + (Distance) //+ furtherWeight ; var msg = "1st"; if (cryId != null) { msg = cryId.Substring(0, 3); } passes.Add(msg); passes = passes.Distinct().ToList(); //DebugCrystal.AddNewCrystals(passes.Count + ":: " + sine.ToString("F2") + " | " + angle.ToString("F1") + " | " // + Distance.ToString("F1") + " |w: " +_calcWeight.ToString("f1"), Position); }
public int CountLinesIIntersect(Line line, List <int> histoRegions, CryRoute cryRoute) { int res = 0; var crystals = GiveAllCrystalsInTheseRegionsExcludLinkRects(histoRegions); for (int i = 0; i < crystals.Count; i++) { for (int j = 0; j < crystals[i].Lines.Count; j++) { var lineOnCrys = crystals[i].Lines[j]; if (line.IsIntersecting((lineOnCrys))) { // //Debug.Log("Intersected: " + crystals[i].ParentId + " tp: " +crystals[i].Type1); Vector3 intersection = U2D.FromV2ToV3(line.FindIntersection(lineOnCrys)); //add key to explorer on the CryRoute cryRoute.AddKeyToExplorer(crystals[i], intersection); lineOnCrys.DebugRender(Color.black); res++; } } } return(res); }
internal void CalculateWeight(Vector3 vector3) { Distance = Vector3.Distance(U2D.FromV2ToV3(_position), vector3); // _calcWeight = (_baseWeight * weightFactor) + Distance; _calcWeight = _baseWeight + Distance; }
/// <summary> /// The center position of the rect of the region /// </summary> /// <returns></returns> internal Vector3 Position() { return(U2D.FromV2ToV3(Region.center)); }