public void ReevaluateTarget(ShooterComponent shooterComp) { shooterComp.ReevaluateTarget = true; SmartEntity smartEntity = (SmartEntity)shooterComp.Entity; if (smartEntity.TurretShooterComp != null) { SmartEntity target = shooterComp.Target; int targetWeight = -1; if (target != null && !GameUtils.IsEntityDead(target)) { List <ElementPriorityPair <Entity> > turretsInRangeOf = this.spatialIndexController.GetTurretsInRangeOf(target.TransformComp.CenterGridX(), target.TransformComp.CenterGridZ()); int i = 0; int count = turretsInRangeOf.Count; while (i < count) { ElementPriorityPair <Entity> elementPriorityPair = turretsInRangeOf[i]; if (smartEntity == elementPriorityPair.Element) { TroopComponent troopComp = target.TroopComp; targetWeight = this.CalculateWeight(shooterComp, null, troopComp.TroopType.ArmorType, elementPriorityPair.Priority); break; } i++; } } smartEntity.TurretShooterComp.TargetWeight = targetWeight; } }
private SmartEntity GetPrefferedBuilding(ShooterComponent shooterComp, PriorityList <SmartEntity> buildings, ref int maxWeight) { HashSet <string> hashSet = new HashSet <string>(); SmartEntity result = null; int i = 0; int count = buildings.Count; while (i < count) { ElementPriorityPair <SmartEntity> elementPriorityPair = buildings.Get(i); SmartEntity element = elementPriorityPair.Element; HealthComponent healthComp = element.HealthComp; if (healthComp != null && !healthComp.IsDead()) { BuildingComponent buildingComp = element.BuildingComp; if (buildingComp.BuildingType.Type != BuildingType.Blocker && (element.TrapComp == null || element.TrapComp.CurrentState == TrapState.Armed) && hashSet.Add(buildingComp.BuildingType.BuildingID)) { int num = this.CalculateWeight(shooterComp, null, healthComp.ArmorType, elementPriorityPair.Priority); if (num > maxWeight) { maxWeight = num; result = element; } } } i++; } return(result); }
public void InformTurretsAboutTroop(List <ElementPriorityPair <Entity> > turretsInRangeOf, SmartEntity entity, HashSet <ShooterComponent> resetReevaluateTargetSet) { int i = 0; int count = turretsInRangeOf.Count; while (i < count) { ElementPriorityPair <Entity> elementPriorityPair = turretsInRangeOf[i]; SmartEntity smartEntity = (SmartEntity)elementPriorityPair.Element; HealthComponent healthComp = smartEntity.HealthComp; if (healthComp != null && !healthComp.IsDead()) { ShooterComponent shooterComp = smartEntity.ShooterComp; if (shooterComp != null) { TurretShooterComponent turretShooterComp = smartEntity.TurretShooterComp; if (turretShooterComp != null) { this.AddTurretTarget(shooterComp, turretShooterComp, entity, elementPriorityPair.Priority, resetReevaluateTargetSet); } } } i++; } }
public void Add(T element, int priority) { if (element == null) { throw new ArgumentNullException("element", "The element can't be null."); } if (CopyOnWrite) { _list = new LinkedList <ElementPriorityPair <T> >(_list); } LinkedListNode <ElementPriorityPair <T> > linkedListNode = _list.First; ElementPriorityPair <T> value = new ElementPriorityPair <T>(element, priority); while (linkedListNode != null) { if (priority > linkedListNode.Value.Priority) { _list.AddBefore(linkedListNode, value); return; } linkedListNode = linkedListNode.Next; } _list.AddLast(value); }