public SpatialIndex() { this.nearnessToBuildings = new SmartEntityPriorityList(); this.turretsInRange = new List <EntityElementPriorityPair>(); this.areaTriggerBuildingsInRange = new List <EntityElementPriorityPair>(); this.AlreadyScannedBuildingsToAttack = false; this.AlreadyScannedTurretsInRange = false; this.AlreadyScannedAreaTriggerBuildingsInRange = false; }
private SmartEntity FindBuildingAsTarget(SmartEntity entity, ref int maxWeight) { TransformComponent transformComp = entity.TransformComp; this.buildingsToAttack = this.spatialIndexController.GetBuildingsToAttack(transformComp.CenterGridX(), transformComp.CenterGridZ()); SmartEntity result = null; if (this.buildingsToAttack != null) { ShooterComponent shooterComp = entity.ShooterComp; result = this.GetPrefferedBuilding(shooterComp, this.buildingsToAttack, ref maxWeight); } return(result); }
private SmartEntity GetPrefferedBuilding(ShooterComponent shooterComp, SmartEntityPriorityList buildings, ref int maxWeight) { HashSet <string> hashSet = new HashSet <string>(); SmartEntity result = null; int i = 0; int count = buildings.Count; while (i < count) { SmartEntityElementPriorityPair smartEntityElementPriorityPair = buildings.Get(i); SmartEntity element = smartEntityElementPriorityPair.Element; if (!shooterComp.ShooterVO.NewTargetOnReload || shooterComp.IsPotentialTargetNew(element.ID)) { HealthComponent healthComp = element.HealthComp; if (healthComp != null && !healthComp.IsDead()) { BuildingComponent buildingComp = element.BuildingComp; if (buildingComp.BuildingType.Type != BuildingType.Blocker) { if (element.TrapComp == null || element.TrapComp.CurrentState == TrapState.Armed) { if (hashSet.Add(buildingComp.BuildingType.BuildingID)) { int num = this.CalculateWeight(shooterComp, null, healthComp.ArmorType, smartEntityElementPriorityPair.Priority); if (num > maxWeight) { maxWeight = num; result = element; } } } } } } i++; } return(result); }