public CoverPoint ToCoverPoint(CoverPointVolume volume) { this.Volume = volume; if (this.IsDynamic) { CoverPoint coverPoint = new CoverPoint(this.Volume, this.Score); coverPoint.IsDynamic = true; coverPoint.SourceTransform = ((Component)this).get_transform(); coverPoint.NormalCoverType = this.NormalCoverType; Transform transform = ((Component)this).get_transform(); coverPoint.Position = transform != null?transform.get_position() : Vector3.get_zero(); return(coverPoint); } Vector3 vector3 = Quaternion.op_Multiply(((Component)this).get_transform().get_rotation(), this.Normal); Vector3 normalized = ((Vector3) ref vector3).get_normalized(); return(new CoverPoint(this.Volume, this.Score) { IsDynamic = false, Position = ((Component)this).get_transform().get_position(), Normal = normalized, NormalCoverType = this.NormalCoverType }); }
public CoverPoint ToCoverPoint(CoverPointVolume volume) { Vector3 vector3; this.Volume = volume; if (!this.IsDynamic) { Vector3 normal = (base.transform.rotation * this.Normal).normalized; return(new CoverPoint(this.Volume, this.Score) { IsDynamic = false, Position = base.transform.position, Normal = normal, NormalCoverType = this.NormalCoverType }); } CoverPoint coverPoint = new CoverPoint(this.Volume, this.Score) { IsDynamic = true, SourceTransform = base.transform, NormalCoverType = this.NormalCoverType }; Transform transforms = base.transform; if (transforms != null) { vector3 = transforms.position; } else { vector3 = Vector3.zero; } coverPoint.Position = vector3; return(coverPoint); }
public override void DoExecute(BaseContext c) { Vector3 best = base.GetBest(c, c.sampledPositions); if (best.sqrMagnitude == 0f) { return; } NPCHumanContext nPCHumanContext = c as NPCHumanContext; if (nPCHumanContext != null && nPCHumanContext.CurrentCoverVolume != null) { int num = 0; while (num < nPCHumanContext.sampledCoverPoints.Count) { CoverPoint item = nPCHumanContext.sampledCoverPoints[num]; CoverPoint.CoverType coverType = nPCHumanContext.sampledCoverPointTypes[num]; if (Vector3Ex.Distance2D(item.Position, best) >= 1f) { num++; } else { nPCHumanContext.CoverSet.Update(item, item, item); break; } } } c.AIAgent.UpdateDestination(best); c.lastSampledPosition = best; }
private CoverPoint CalculateCoverPoint(NavMeshHit info) { RaycastHit raycastHit; CoverPointVolume.CoverType coverType = this.ProvidesCoverInDir(new Ray(info.position, -info.normal), this.CoverPointRayLength, out raycastHit); if (coverType == CoverPointVolume.CoverType.None) { return(null); } CoverPoint coverPoint = new CoverPoint(this, this.DefaultCoverPointScore) { Position = info.position, Normal = -info.normal }; if (coverType == CoverPointVolume.CoverType.Full) { coverPoint.NormalCoverType = CoverPoint.CoverType.Full; } else if (coverType == CoverPointVolume.CoverType.Partial) { coverPoint.NormalCoverType = CoverPoint.CoverType.Partial; } return(coverPoint); }
internal static CoverPoint GetClosestCover( NPCHumanContext c, Vector3 point, float MaxDistance, ProximityToCover.CoverType _coverType, out float bestDistance) { bestDistance = MaxDistance; CoverPoint coverPoint = (CoverPoint)null; for (int index = 0; index < c.sampledCoverPoints.Count; ++index) { CoverPoint sampledCoverPoint = c.sampledCoverPoints[index]; CoverPoint.CoverType sampledCoverPointType = c.sampledCoverPointTypes[index]; if ((_coverType != ProximityToCover.CoverType.Full || sampledCoverPointType == CoverPoint.CoverType.Full) && (_coverType != ProximityToCover.CoverType.Partial || sampledCoverPointType == CoverPoint.CoverType.Partial)) { float num = Vector3.Distance(sampledCoverPoint.Position, point); if ((double)num < (double)bestDistance) { bestDistance = num; coverPoint = sampledCoverPoint; } } } return(coverPoint); }
public override void DoExecute(BaseContext c) { Vector3 best = this.GetBest((IAIContext)c, (IList <Vector3>)c.sampledPositions); if ((double)((Vector3) ref best).get_sqrMagnitude() == 0.0) { return; } NPCHumanContext npcHumanContext = c as NPCHumanContext; if (npcHumanContext != null && Object.op_Inequality((Object)npcHumanContext.CurrentCoverVolume, (Object)null)) { for (int index = 0; index < npcHumanContext.sampledCoverPoints.Count; ++index) { CoverPoint sampledCoverPoint = npcHumanContext.sampledCoverPoints[index]; int sampledCoverPointType = (int)npcHumanContext.sampledCoverPointTypes[index]; if ((double)Vector3Ex.Distance2D(sampledCoverPoint.Position, best) < 1.0) { npcHumanContext.CoverSet.Update(sampledCoverPoint, sampledCoverPoint, sampledCoverPoint); break; } } } c.AIAgent.UpdateDestination(best); c.lastSampledPosition = best; }
public static bool ProvidesCoverFromDirection(CoverPoint cp, Vector3 directionTowardCover, float arcThreshold) { if (Vector3.Dot(cp.Normal, directionTowardCover) < arcThreshold) { return(true); } return(false); }
private IEnumerator StartCooldown(float cooldown) { CoverPoint coverPoint = null; coverPoint.IsCompromised = true; yield return(CoroutineEx.waitForSeconds(cooldown)); coverPoint.IsCompromised = false; }
public void Refresh(IAIAgent self, Vector3 dangerPoint, List <CoverPoint> sampledCoverPoints) { this.Self = self; this.DangerPoint = dangerPoint; this.SampledCoverPoints = sampledCoverPoints; this.BestRetreatValue = 0f; this.BestFlankValue = 0f; this.BestAdvanceValue = 0f; this.BestRetreatCP = null; this.BestFlankCP = null; this.BestAdvanceCP = null; this.HideoutValue = 0f; this.HideoutCP = null; }
public override float GetScore(BaseContext ctx) { NPCHumanContext c = ctx as NPCHumanContext; if (c != null) { float bestDistance; CoverPoint closestCover = ProximityToCover.GetClosestCover(c, c.Position, this.MaxDistance, this._coverType, out bestDistance); if (closestCover != null) { return(this.Response.Evaluate(bestDistance / this.MaxDistance) * closestCover.Score); } } return(0.0f); }
public override float GetScore(BaseContext ctx, Vector3 option) { float single; NPCHumanContext nPCHumanContext = ctx as NPCHumanContext; if (nPCHumanContext != null) { CoverPoint closestCover = ProximityToCover.GetClosestCover(nPCHumanContext, option, this.MaxDistance, this._coverType, out single); if (closestCover != null) { return(this.Response.Evaluate(single / this.MaxDistance) * closestCover.Score); } } return(0f); }
internal static CoverPoint GetClosestCover(NPCHumanContext c, Vector3 point, float MaxDistance, ProximityToCover.CoverType _coverType, out float bestDistance) { bestDistance = MaxDistance; CoverPoint coverPoint = null; for (int i = 0; i < c.sampledCoverPoints.Count; i++) { CoverPoint item = c.sampledCoverPoints[i]; CoverPoint.CoverType coverType = c.sampledCoverPointTypes[i]; if ((_coverType != ProximityToCover.CoverType.Full || coverType == CoverPoint.CoverType.Full) && (_coverType != ProximityToCover.CoverType.Partial || coverType == CoverPoint.CoverType.Partial)) { float single = Vector3.Distance(item.Position, point); if (single < bestDistance) { bestDistance = single; coverPoint = item; } } } return(coverPoint); }
public void GenerateCoverPoints(Transform coverPointGroup) { double realtimeSinceStartup = (double)Time.get_realtimeSinceStartup(); this.ClearCoverPoints(); if (Object.op_Equality((Object)this.ManualCoverPointGroup, (Object)null)) { this.ManualCoverPointGroup = coverPointGroup; } if (Object.op_Equality((Object)this.ManualCoverPointGroup, (Object)null)) { this.ManualCoverPointGroup = ((Component)this).get_transform(); } if (this.ManualCoverPointGroup.get_childCount() > 0) { foreach (ManualCoverPoint componentsInChild in (ManualCoverPoint[])((Component)this.ManualCoverPointGroup).GetComponentsInChildren <ManualCoverPoint>()) { this.CoverPoints.Add(componentsInChild.ToCoverPoint(this)); } } if (this._coverPointBlockers.Count == 0 && Object.op_Inequality((Object)this.BlockerGroup, (Object)null)) { CoverPointBlockerVolume[] componentsInChildren = (CoverPointBlockerVolume[])((Component)this.BlockerGroup).GetComponentsInChildren <CoverPointBlockerVolume>(); if (componentsInChildren != null && componentsInChildren.Length != 0) { this._coverPointBlockers.AddRange((IEnumerable <CoverPointBlockerVolume>)componentsInChildren); } } NavMeshHit navMeshHit; if (this.CoverPoints.Count != 0 || !NavMesh.SamplePosition(((Component)this).get_transform().get_position(), ref navMeshHit, (float)((Component)this).get_transform().get_localScale().y *CoverPointVolume.cover_point_sample_step_height, -1)) { return; } Vector3 position = ((Component)this).get_transform().get_position(); Vector3 vector3_1 = Vector3.op_Multiply(((Component)this).get_transform().get_lossyScale(), 0.5f); for (float num1 = (float)(position.x - vector3_1.x + 1.0); (double)num1 < position.x + vector3_1.x - 1.0; num1 += CoverPointVolume.cover_point_sample_step_size) { for (float num2 = (float)(position.z - vector3_1.z + 1.0); (double)num2 < position.z + vector3_1.z - 1.0; num2 += CoverPointVolume.cover_point_sample_step_size) { for (float num3 = (float)(position.y - vector3_1.y); (double)num3 < position.y + vector3_1.y; num3 += CoverPointVolume.cover_point_sample_step_height) { NavMeshHit info; if (NavMesh.FindClosestEdge(new Vector3(num1, num3, num2), ref info, ((NavMeshHit) ref navMeshHit).get_mask())) { ((NavMeshHit) ref info).set_position(new Vector3((float)((NavMeshHit) ref info).get_position().x, (float)(((NavMeshHit) ref info).get_position().y + 0.5), (float)((NavMeshHit) ref info).get_position().z)); bool flag = true; foreach (CoverPoint coverPoint in this.CoverPoints) { Vector3 vector3_2 = Vector3.op_Subtraction(coverPoint.Position, ((NavMeshHit) ref info).get_position()); if ((double)((Vector3) ref vector3_2).get_sqrMagnitude() < (double)CoverPointVolume.cover_point_sample_step_size * (double)CoverPointVolume.cover_point_sample_step_size) { flag = false; break; } } if (flag) { CoverPoint coverPoint = this.CalculateCoverPoint(info); if (coverPoint != null) { this.CoverPoints.Add(coverPoint); } } } } } } }
public void GenerateCoverPoints(Transform coverPointGroup) { NavMeshHit navMeshHit; NavMeshHit vector3; float single = Time.realtimeSinceStartup; this.ClearCoverPoints(); if (this.ManualCoverPointGroup == null) { this.ManualCoverPointGroup = coverPointGroup; } if (this.ManualCoverPointGroup == null) { this.ManualCoverPointGroup = base.transform; } if (this.ManualCoverPointGroup.childCount > 0) { ManualCoverPoint[] componentsInChildren = this.ManualCoverPointGroup.GetComponentsInChildren <ManualCoverPoint>(); for (int i = 0; i < (int)componentsInChildren.Length; i++) { CoverPoint coverPoint = componentsInChildren[i].ToCoverPoint(this); this.CoverPoints.Add(coverPoint); } } if (this._coverPointBlockers.Count == 0 && this.BlockerGroup != null) { CoverPointBlockerVolume[] coverPointBlockerVolumeArray = this.BlockerGroup.GetComponentsInChildren <CoverPointBlockerVolume>(); if (coverPointBlockerVolumeArray != null && coverPointBlockerVolumeArray.Length != 0) { this._coverPointBlockers.AddRange(coverPointBlockerVolumeArray); } } if (this.CoverPoints.Count == 0 && NavMesh.SamplePosition(base.transform.position, out navMeshHit, base.transform.localScale.y * CoverPointVolume.cover_point_sample_step_height, -1)) { Vector3 vector31 = base.transform.position; Vector3 vector32 = base.transform.lossyScale * 0.5f; for (float j = vector31.x - vector32.x + 1f; j < vector31.x + vector32.x - 1f; j += CoverPointVolume.cover_point_sample_step_size) { for (float k = vector31.z - vector32.z + 1f; k < vector31.z + vector32.z - 1f; k += CoverPointVolume.cover_point_sample_step_size) { for (float l = vector31.y - vector32.y; l < vector31.y + vector32.y; l += CoverPointVolume.cover_point_sample_step_height) { if (NavMesh.FindClosestEdge(new Vector3(j, l, k), out vector3, navMeshHit.mask)) { vector3.position = new Vector3(vector3.position.x, vector3.position.y + 0.5f, vector3.position.z); bool flag = true; foreach (CoverPoint coverPoint1 in this.CoverPoints) { if ((coverPoint1.Position - vector3.position).sqrMagnitude >= CoverPointVolume.cover_point_sample_step_size * CoverPointVolume.cover_point_sample_step_size) { continue; } flag = false; goto Label0; } Label0: if (flag) { CoverPoint coverPoint2 = this.CalculateCoverPoint(vector3); if (coverPoint2 != null) { this.CoverPoints.Add(coverPoint2); } } } } } } } }