private GameObject ScanForTargetToAttackImproved(List <GameObject> potentialTargets, GameObject owner, AIController aiController) { Faction ownerFaction = owner.GetComponent <Faction>(); if (ownerFaction == null) { Debug.LogError(owner.name + " doesn't have a faction.", owner); return(null); } float perceptionDistance = aiController.PerceptionDistance; if (aiController.InCombat) { perceptionDistance *= 2; // was += 6f; } var targets = new List <GameObject>(potentialTargets.Count); var targetDistances = new List <float>(potentialTargets.Count); var targetStaminas = new List <float>(potentialTargets.Count); var targetIsEngageds = new List <bool>(potentialTargets.Count); var maxStamina = float.MinValue; for (int i = 0; i < potentialTargets.Count; i++) { GameObject potentialTarget = potentialTargets[i]; if (ownerFaction.IsHostile(potentialTarget)) { Health targetHealth = potentialTarget.GetComponent <Health>(); if (!(targetHealth == null) && targetHealth.Targetable) { AIController targetAI = potentialTarget.GetComponent <AIController>(); if (!(targetAI == null)) { CharacterStats targetStats = potentialTarget.GetComponent <CharacterStats>(); if (!(targetStats == null)) { float targetDistance = GameUtilities.V3Distance2D(owner.transform.position, potentialTarget.transform.position); bool isValid = false; if (targetStats.NoiseLevelRadius > targetDistance) { isValid = true; GameState.InStealthMode = false; } else if (targetDistance <= perceptionDistance && GameUtilities.LineofSight(owner.transform.position, targetAI.transform.position, 1f, false)) { isValid = true; } if (isValid) { targets.Add(potentialTarget); targetDistances.Add(targetDistance); targetStaminas.Add(targetHealth.CurrentStamina); targetIsEngageds.Add(aiController.HasEngaged(potentialTarget)); maxStamina = Math.Max(targetHealth.CurrentStamina, maxStamina); } } } } } } if (GameState.InStealthMode) { return(null); } const float DISTANCE_WEIGHT = 1f; const float STAMINA_WEIGHT = 1f; const float FICKLENESS_WEIGHT = 0.5f; const float ENGAGED_WEIGHT = -10f; // must be more than the other weights combined const float CURRENT_TARGET_WEIGHT = 2f; var bestWeight = float.MaxValue; GameObject result = null; for (int i = 0; i < targets.Count; ++i) { var distanceValue = (targetDistances[i] / perceptionDistance) * DISTANCE_WEIGHT; var staminaValue = (targetStaminas[i] / maxStamina) * STAMINA_WEIGHT; // targets with less stamina are more attractive var isCurrentTarget = ((Mod_AI_PreTargetScanner)(object)this).DeprioritizeCurrentTarget && (targets[i] == aiController.CurrentTarget); var currentTargetValue = isCurrentTarget ? CURRENT_TARGET_WEIGHT : 0; var engagedValue = (targetIsEngageds[i] ? 1 : 0) * ENGAGED_WEIGHT; var fickleValue = Random.Range(0f, 1f) * FICKLENESS_WEIGHT; // a little randomness is useful var value = distanceValue + staminaValue + currentTargetValue + engagedValue + fickleValue; if (value < bestWeight) { bestWeight = value; result = targets[i]; } } return(result); }
public void UpdateVerticesRevised() { //IEDebug.Log("In UpdateVertices()"); if (this.m_revealList.Count <= 0 || this.m_fogVertices == null || (this.m_fogAlphasStaging == null || this.m_fogDesiredAlphas == null)) { return; } for (int index = 0; index < this.m_prevUpdateList.Count; ++index) { this.m_fogUpdateState[this.m_prevUpdateList[index]] = false; } float mDeltaTime = this.m_deltaTime / 0.5f; if (this.m_disableFogFading || (double)mDeltaTime > 1.0) { mDeltaTime = 1f; } this.m_updateList.Clear(); this.m_underRevealerList.Clear(); this.m_candidates.Clear(); int num2 = 19; int num3 = num2 * 2 + 1; int num4 = num3 * num3; this.m_groundPlane.normal = Vector3.up; this.m_groundPlane.distance = 0.0f; for (int index1 = 0; index1 < this.m_revealList.Count; ++index1) { FogOfWar.Revealer revealer1 = this.m_revealList[index1]; if (!revealer1.RequiresRefresh) { if (revealer1.HasTrigger) { if ((double)revealer1.TriggerBoxSize.sqrMagnitude > 0) { float triggerPos = revealer1.TriggerPos.x - revealer1.TriggerBoxSize.x * 0.5f; float triggerPos1 = revealer1.TriggerPos.x + revealer1.TriggerBoxSize.x * 0.5f; float triggerPos2 = revealer1.TriggerPos.z - revealer1.TriggerBoxSize.z * 0.5f; float triggerPos3 = revealer1.TriggerPos.z + revealer1.TriggerBoxSize.z * 0.5f; bool flag = false; for (int index2 = 0; index2 < this.m_revealList.Count; ++index2) { FogOfWar.Revealer revealer2 = this.m_revealList[index2]; if (revealer2.TriggersBoxColliders && (double)revealer2.WorldPos.x > (double)triggerPos && ((double)revealer2.WorldPos.x < (double)triggerPos1 && (double)revealer2.WorldPos.z > (double)triggerPos2) && (double)revealer2.WorldPos.z < (double)triggerPos3) { flag = true; break; } } if (!flag) { continue; } } else if (this.PointVisible(revealer1.TriggerPos)) { int x = 0; int y = 0; this.WorldToFogOfWar(revealer1.TriggerPos, out x, out y); if (!this.m_fogLOSRevealed[x * this.m_fogVertsPerRow + y]) { continue; } } else { continue; } } int x1 = 0; int y1 = 0; this.WorldToFogOfWar(revealer1.WorldPos, out x1, out y1); int losDistance1 = (int)(((double)revealer1.LOSDistance + 3.0) * 1.0 / (double)this.m_fogTileWidth) + 1; int losDistance2 = (int)(((double)revealer1.LOSDistance + 3.0) * 1.0 / (double)this.m_fogTileHeight) + 1; int num11 = x1 - losDistance1; int num12 = y1 - losDistance2; int mFogVertsPerColumn = x1 + losDistance1; int mFogVertsPerRow2 = y1 + losDistance2; FogOfWar.RevealerCandidate revealerCandidate = new FogOfWar.RevealerCandidate(); revealerCandidate.Revealer = revealer1; revealerCandidate.UseBacksideVerts = false; revealerCandidate.OriginX = x1; revealerCandidate.OriginY = y1; revealerCandidate.OriginIndex = x1 * this.m_fogVertsPerRow + y1; if (this.m_los == null || revealerCandidate.OriginIndex >= 0 && revealerCandidate.OriginIndex < this.m_los.Vertices.Length) { this.m_candidates.Add(revealerCandidate); Ray theRay1 = new Ray(revealer1.WorldPos, -this.CameraPlane.normal); revealer1.CameraPos = FogOfWar.GetCameraPlaneRayIntersectionPosition(this.CameraPlane, theRay1) + this.CameraPlane.normal * 0.5f; Ray theRay2 = new Ray(revealer1.WorldPos - this.m_cameraForward * 500f, this.m_cameraForward); revealerCandidate.WorldPos = this.m_levelInfo.GetGroundPlaneRayIntersectionPosition(this.m_groundPlane, theRay2); if (this.m_los != null && this.m_los.BacksideVertices.ContainsKey(revealerCandidate.OriginIndex)) { int index2 = -1; for (int index3 = 0; index3 < this.m_doorLookupGuid.Length; ++index3) { if (this.m_doorLookupGuid[index3] == this.m_los.BacksideVertices[revealerCandidate.OriginIndex].DoorID) { index2 = index3; break; } } if (index2 >= 0 && this.m_doorLookupValidation[index2]) { Vector2 rhs = GameUtilities.V3Subtract2D(revealer1.WorldPos, this.m_doorLookupPos[index2]); rhs.Normalize(); if ((double)Vector2.Dot(this.m_doorLookupForward[index2], rhs) < 0.0) { revealerCandidate.UseBacksideVerts = true; } } } if (num11 < 0) { num11 = 0; } if (num12 < 0) { num12 = 0; } if (mFogVertsPerColumn >= this.m_fogVertsPerColumn) { mFogVertsPerColumn = this.m_fogVertsPerColumn - 1; } if (mFogVertsPerRow2 >= this.m_fogVertsPerRow) { mFogVertsPerRow2 = this.m_fogVertsPerRow - 1; } for (int index2 = num11; index2 <= mFogVertsPerColumn; ++index2) { for (int index3 = num12; index3 <= mFogVertsPerRow2; ++index3) { int mFogVertsPerRow3 = index2 * this.m_fogVertsPerRow + index3; if (!this.m_fogUpdateState[mFogVertsPerRow3]) { this.m_updateList.Add(mFogVertsPerRow3); this.m_underRevealerList.Add(mFogVertsPerRow3); this.m_fogUpdateState[mFogVertsPerRow3] = true; this.m_fogDesiredAlphas[mFogVertsPerRow3] = this.m_fogAlphasStaging[mFogVertsPerRow3].y; } } } } } } this.m_fadeOutList.Clear(); for (int index1 = 0; index1 < this.m_prevUpdateList.Count; ++index1) { int index2 = this.m_prevUpdateList[index1]; if (!this.m_fogUpdateState[index2]) { this.m_updateList.Add(index2); this.m_fadeOutList.Add(index2); this.m_fogDesiredAlphas[index2] = this.m_fogAlphasStaging[index2].y; } } for (int index = 0; index < this.m_prevUpdateList.Count; ++index) { this.m_fogLOSRevealed[this.m_prevUpdateList[index]] = false; } this.m_prevUpdateList.Clear(); this.m_prevUpdateList.AddRange((IEnumerable <int>) this.m_underRevealerList); for (int index1 = 0; index1 < this.m_updateList.Count; ++index1) { int index2 = this.m_updateList[index1]; float mFogDesiredAlpha = this.m_fogDesiredAlphas[index2]; float mFogAlphasStaging = this.m_fogAlphasStaging[index2].y; float single = mFogAlphasStaging; float single1 = mFogAlphasStaging; for (int index3 = 0; index3 < this.m_candidates.Count; ++index3) { FogOfWar.RevealerCandidate revealerCandidate = this.m_candidates[index3]; float minAlpha = 0.0f; if (this.m_los != null && (!revealerCandidate.Revealer.HasTrigger || revealerCandidate.Revealer.RespectLOS)) { FogOfWarLOS.VertexData[] vertexDataArray = this.m_los.Vertices[revealerCandidate.OriginIndex]; if (revealerCandidate.UseBacksideVerts) { vertexDataArray = this.m_los.BacksideVertices[revealerCandidate.OriginIndex].VertexData; } if (vertexDataArray != null) { int mFogVertsPerRow = index2 / this.m_fogVertsPerRow; int mFogVertsPerRow1 = index2 % this.m_fogVertsPerRow; int originX = mFogVertsPerRow - revealerCandidate.OriginX + num2; int originY = mFogVertsPerRow1 - revealerCandidate.OriginY + num2; int index4 = originX * num3 + originY; if (index4 >= 0 && index4 < num4) { if (vertexDataArray[index4] == null) { minAlpha = 0.0f; } else { minAlpha = vertexDataArray[index4].MinAlpha; if (vertexDataArray[index4].DoorIndices != null) { for (int index5 = 0; index5 < vertexDataArray[index4].DoorIndices.Length; ++index5) { byte num13 = vertexDataArray[index4].DoorIndices[index5]; if (this.m_doorLookupValidation[(int)num13] && this.m_doorLookup[(int)num13].CurrentState != OCL.State.Open && this.m_doorLookup[(int)num13].CurrentState != OCL.State.SealedOpen) { minAlpha = this.m_fogAlphasStaging[index2].y; break; } } } } if ((double)minAlpha > (double)this.m_fogAlphasStaging[index2].y) { minAlpha = this.m_fogAlphasStaging[index2].y; } } else { continue; } } } // #ZEN(Changed) controls the alpha value of explored fog float exploredFogAlpha = 0.0f; //Mathf.Max(0.7f, minAlpha); float lOSDistance3 = revealerCandidate.Revealer.LOSDistance + 3f; float lOSDistance4 = revealerCandidate.Revealer.LOSDistance - 3f; float single2 = GameUtilities.V3Distance2D(this.m_worldVertices[index2], revealerCandidate.WorldPos); if ((double)single2 > (double)lOSDistance3) // if single2 > lOSDistance3 { mFogDesiredAlpha = this.m_fogAlphasStaging[index2].y; } else if ((double)single2 > (double)revealerCandidate.Revealer.LOSDistance) { float lOSDistance = (float)((1.0 - ((double)lOSDistance3 - (double)single2) / 3.0) * 0.300000011920929 + 0.7f); if ((double)lOSDistance < (double)minAlpha) { lOSDistance = minAlpha; } if ((double)lOSDistance < (double)this.m_fogAlphasStaging[index2].y) { mFogAlphasStaging = (double)lOSDistance <= (double)exploredFogAlpha ? exploredFogAlpha : lOSDistance; } if ((double)lOSDistance < (double)this.m_fogDesiredAlphas[index2]) { mFogDesiredAlpha = lOSDistance; } } else if ((double)single2 < (double)lOSDistance4 - 1.0) { mFogDesiredAlpha = minAlpha; mFogAlphasStaging = exploredFogAlpha; } else { float lOSDistance = (float)((1.0 - ((double)revealerCandidate.Revealer.LOSDistance - (double)single2) / 3.0) * 0.699999988079071); if ((double)lOSDistance < (double)minAlpha) { lOSDistance = minAlpha; } if ((double)lOSDistance < (double)this.m_fogAlphasStaging[index2].y) { mFogAlphasStaging = (double)lOSDistance <= (double)exploredFogAlpha ? exploredFogAlpha : lOSDistance; } if ((double)lOSDistance < (double)this.m_fogDesiredAlphas[index2]) { mFogDesiredAlpha = lOSDistance; } } if (!revealerCandidate.Revealer.HasTrigger && (double)mFogDesiredAlpha < 0.699999988079071) { this.m_fogLOSRevealed[index2] = true; } if (revealerCandidate.Revealer.RevealOnly && (double)mFogDesiredAlpha < 0.699999988079071) { mFogDesiredAlpha = 0.0f; } if ((double)mFogDesiredAlpha < (double)single) { single = mFogDesiredAlpha; } if ((double)mFogAlphasStaging < (double)single1) { single1 = mFogAlphasStaging; } } if ((double)single > (double)single1) { single = single1; } this.m_fogDesiredAlphas[index2] = single; this.m_fogAlphasStaging[index2].y = single1; if (!this.Disabled && (double)this.m_fogAlphasStaging[index2].y < 0.699999988079071) { this.m_fogAlphasStaging[index2].y = 0.0f; } float mFogDesiredAlphas1 = this.m_fogDesiredAlphas[index2] - this.m_fogAlphasStaging[index2].x; if ((double)Mathf.Abs(mFogDesiredAlphas1) <= (double)mDeltaTime) { this.m_fogAlphasStaging[index2].x = this.m_fogDesiredAlphas[index2]; } else { if ((double)mFogDesiredAlphas1 > 0.0) { this.m_fogAlphasStaging[index2].x += mDeltaTime; } else { this.m_fogAlphasStaging[index2].x -= mDeltaTime; } this.m_fogUpdateState[index2] = true; } } for (int index1 = 0; index1 < this.m_fadeOutList.Count; ++index1) { int index2 = this.m_fadeOutList[index1]; if ((double)this.m_fogAlphasStaging[index2].x < 0.699999988079071) { this.m_prevUpdateList.Add(index2); } } }
protected GameObject ScanForTargetToAttackNew(List <GameObject> potentialTargets, GameObject owner, AIController aiController) { if (IEModOptions.ImprovedAI) // added this if statement { return(ScanForTargetToAttackImproved(potentialTargets, owner, aiController)); } float num = 3.40282347E+38f; GameObject result = null; Faction component = owner.GetComponent <Faction>(); if (component == null) { Debug.LogError(owner.name + " doesn't have a faction.", owner); return(null); } float num2 = aiController.PerceptionDistance; if (aiController.InCombat) { num2 += 6f; } for (int i = 0; i < potentialTargets.Count; i++) { GameObject gameObject = potentialTargets[i]; if (component.IsHostile(gameObject)) { Health component2 = gameObject.GetComponent <Health>(); if (!(component2 == null) && component2.Targetable) { AIController component3 = gameObject.GetComponent <AIController>(); if (!(component3 == null)) { CharacterStats component4 = gameObject.GetComponent <CharacterStats>(); if (!(component4 == null)) { float num3 = GameUtilities.V3Distance2D(owner.transform.position, gameObject.transform.position); float num4 = num2; if (component4.NoiseLevelRadius > num3) { result = gameObject; GameState.InStealthMode = false; } if (num3 <= num4) { if (GameUtilities.LineofSight(owner.transform.position, component3.transform.position, 1f, false)) { float num5 = 0f; num5 += num3 / num4 * 2f; num5 += component2.CurrentStamina / component2.MaxStamina * 0.5f; num5 += ((!aiController.HasEngaged(gameObject)) ? 0f : -3f); if (num5 < num && !GameState.InStealthMode) { num = num5; result = gameObject; } } } } } } } } return(result); }