public void registerFearSource(Transform t, float medium, float near) { FearSource source = new FearSource (); source.near = near; source.medium = medium; source.t = t; fearSources.Add (source); }
//Add fear values that do not radiate (MAGES,ARCHERS) public void addFixedSource(FearSource source, int x, int y) { /* * int powerVert = 1; * int powerHori = 1; */ int printhelp = 0; int r = source.radius; int str = source.strength; //Offset to be change if +- 1 is easier int adjustedX = x - PLACEMENT_OFFSET; int adjustedY = y - PLACEMENT_OFFSET; int jTime = 0; int curNumberOfRows; //FOR FEAR POINTS (TILES THAT ARE SCARY) if (r == 0) { if (checkBounds(y, x)) { tiles [adjustedY, adjustedX] += str; return; } } //OUTER LOOP RUNS 2x range + 1 times for (int i = 1; i != source.radius * 2 + 2; i++) { //(2 + 2 * r - Math.Abs (r - (2 * i - 3 - r) - 1)) Is the formula for those sexy diamonds curNumberOfRows = (2 + 2 * r - Math.Abs(r - (2 * i - r) + 2)); for (int j = 1; j != (curNumberOfRows); j++) { //Locations depend on i int newX = x - (r - Math.Abs(r - i + 1)) + j; int newY = (y + r - i + 1); jTime++; //THE FORM INEED IS x needed -r(r if (checkBounds(newX, newY)) { printhelp++; tiles [newY, newX] += str; } } } Debug.Log("The inner loop ran this many times: " + jTime); Debug.Log(printhelp + "Tiles affected"); //Restart row power }
public void UpdateFlockMemberHeading(FlockMember Member, FlockMember[] Members, float AwarenessRadius) { int AwareOfOthersCount = 0; Vector3 AveragePosition = Vector3.zero; Vector3 AverageHeading = Vector3.zero; Vector3 SeparationDirection = Vector3.zero; Vector3 FearDirection = Vector3.zero; for (int m = 0; m < Members.Length; m++) { FlockMember Other = Members[m]; if (Other == Member) { continue; } float DistanceToOther = Vector3.Distance(Other.MyTransform.position, Member.MyTransform.position); if (DistanceToOther < AwarenessRadius) { AwareOfOthersCount++; AveragePosition += Other.MyTransform.position; AverageHeading += Other.Heading; SeparationDirection += (Member.MyTransform.position - Other.MyTransform.position); } } for (int f = 0; f < FearSources.Count; f++) { FearSource Source = FearSources[f]; float DistanceToSource = Vector3.Distance(Member.MyTransform.position, Source.transform.position); if (DistanceToSource < Source.Radius) { FearDirection += (Member.MyTransform.position - Source.transform.position).normalized * Source.Strength; } } float XDistanceFromCenter = Mathf.Abs(Member.MyTransform.position.x); float YDistanceFromCenter = Mathf.Abs(Member.MyTransform.position.y); float XDirToCenter = -1 * Mathf.Sign(Member.MyTransform.position.x); float YDirToCenter = -1 * Mathf.Sign(Member.MyTransform.position.y); float ReturnToXCenterWeight = Mathf.Clamp(((XDistanceFromCenter / AreaWidth) * 3) - 2, 0, 1); float ReturnToYCenterWeight = Mathf.Clamp(((YDistanceFromCenter / AreaHeight) * 3) - 2, 0, 1); Vector3 AwayFromWall = new Vector3(ReturnToXCenterWeight * XDirToCenter, ReturnToYCenterWeight * YDirToCenter, 0); Vector3 TowardsAveragePosition = Vector3.zero; if (AwareOfOthersCount > 0) { AveragePosition = AveragePosition / AwareOfOthersCount; TowardsAveragePosition = AveragePosition - Member.MyTransform.position; AverageHeading = AverageHeading / AwareOfOthersCount; } SeparationDirection = SeparationDirection.normalized; if (FearSources.Count > 0) { FearDirection = FearDirection / FearSources.Count; } Member.Heading += ((TowardsAveragePosition * CohesionWeight) + (AverageHeading * AlignmentWeight) + (SeparationDirection * SeparationWeight) + (FearDirection * FearWeight) + (AwayFromWall * BoundsWeight)) * .5f; Member.Heading = Member.Heading.normalized; Member.Heading.z = 0; }
public void RemoveFearSource(FearSource ToRemove) { FearSources.Remove(ToRemove); }
public void AddFearSource(FearSource NewFearSource) { FearSources.Add(NewFearSource); }