double EstimateDanger(AWizard my, bool considerWizardBesieded = true) { double res = 0; var nearestTower = OpponentCombats.FirstOrDefault(x => x is ABuilding && x.GetDistanceTo2(my) <= Geom.Sqr(x.CastRange)); foreach (var opp in OpponentCombats) { var dist = opp.GetDistanceTo(my); if (dist > 2 * my.VisionRange) { continue; } if (opp is AWizard) { var wizard = opp as AWizard; var inner = (Game.StaffRange + my.Radius) + 1; // (куда достаёт посохом) + запас var outer = (opp.CastRange + my.Radius + Game.MagicMissileRadius) + 1; // (куда достанет MagicMissile) + запас if (GoAwayCond(my, wizard)) { outer += GoAwaySafeDist - Game.MagicMissileRadius; } var coeff = 45; if (!wizard.IsBesieded || !considerWizardBesieded || (nearestTower != null && !Utility.IsBase(nearestTower) && BuildingsObserver.MyBase.GetDistanceTo2(my) > BuildingsObserver.MyBase.GetDistanceTo2(nearestTower) && BuildingsObserver.MyBase.GetDistanceTo2(wizard) > BuildingsObserver.MyBase.GetDistanceTo2(nearestTower) ) ) { if (dist < inner) { res += (wizard.StaffDamage + wizard.MagicMissileDamage) * 2; } else if (dist < outer) { res += (wizard.MagicMissileDamage + coeff - (dist - inner) / (outer - inner) * coeff) * 2; } } else { var otr = my.VisionRange * 1.3; if (dist < otr) { res -= 10 + 60 - dist / otr * 60; } } } else if (opp is ABuilding) { var building = opp as ABuilding; if (building.IsBase && !Game.IsSkillsEnabled) { var outer = building.CastRange; if (dist <= outer) { res += 90 - dist / outer * 90 + building.Damage; } } else if (building.IsBesieded) { var inner = my.Radius + building.Radius + 2 * Game.DartRadius + 3; // свои фетиши могут стрелять var outer = building.VisionRange * 1.2; if (dist < inner) { res += 20 - dist / inner * 20; } else if (dist < outer) { res -= 2 - dist / outer * 2; } } else { var inner = Game.StaffRange + building.Radius; // откуда можно достать посохом var outer = building.CastRange; // куда достреливает башня double delta = -80; if (dist < inner) { res += building.Damage - delta; } else if (dist <= outer) { res += (dist - inner) / (outer - inner) * delta + building.Damage - delta; } } } else if (opp is AOrc) { var inner = Game.OrcWoodcutterAttackRange + my.Radius + Game.MinionSpeed + 20 /*запас*/; var outer = 800; if (dist < inner) { res += Game.OrcWoodcutterDamage + 15 - dist / inner * 15; } else if (dist < outer && my.MmSkillLevel < 5) { res -= 3 - (dist - inner) / (outer - inner) * 3; } } else if (opp is AFetish) { var inner = opp.CastRange + my.Radius + Game.DartRadius + 10; if (dist < inner) { var fetishTarget = MinionsTargetsSelector.Select(opp); if (fetishTarget == null || Geom.Sqr(dist - 5) < opp.GetDistanceTo2(fetishTarget)) { res += 15 - dist / inner * 15 + Game.DartDirectDamage; } } } } // не прижиматься к своим foreach (var co in MyCombats) { var dist = my.GetDistanceTo(co) - co.Radius - my.Radius; if (my.Id != co.Id && dist < 15) { res += 1 - dist / 15 * 1; } } if (Game.IsSkillsEnabled) { // прижиматься за главную башню var cr = new Point(World.Width - 258, 258); var cornerMaxDist = 800; var distToCorner = my.GetDistanceTo(cr); if (distToCorner < cornerMaxDist) { res -= 10 - (distToCorner / cornerMaxDist) * 10; } } // держаться подальше от места появления минионов var spawnDelta = Game.FactionMinionAppearanceIntervalTicks * 0.33; var spawnRemains = World.TickIndex % Game.FactionMinionAppearanceIntervalTicks; if (spawnRemains < spawnDelta) { foreach (var pt in MagicConst.MinionAppearencePoints) { var dist = pt.GetDistanceTo(my); var inner = 450; if (dist < inner) { res += 14 - dist / inner * 14; } } } // двигаться по пути к бонусу if (NextBonusWaypoint != null) { var dist = my.GetDistanceTo(NextBonusWaypoint); var outer = 100.0; if (dist < outer) { res -= GoToBonusDanger - dist / outer * GoToBonusDanger; } } var nearestRoad = RoadsHelper.Roads.ArgMin(seg => seg.GetDistanceTo(my)); var linePadding = nearestRoad.LaneType == ALaneType.Middle || nearestRoad.LaneType == ALaneType.Middle2 ? 250.0 : 160.0; // не прижиматься к лесу if (MagicConst.TreesFreeCircles.All(x => x.GetDistanceTo(my) > x.Radius)) { var distToLine = nearestRoad.GetDistanceTo(my); var outerPadding = 500; if (distToLine > linePadding && distToLine < outerPadding) { res += (distToLine - linePadding) / (outerPadding - linePadding) * 10; } else if (distToLine >= outerPadding) { res += 10; } } { // прижиматься к центру дорожки var distToLine = RoadsHelper.Roads.Where(seg => seg.LaneType != ALaneType.Middle2).Min(seg => seg.GetDistanceTo(my)); var outerPadding = 500; if (distToLine > linePadding && distToLine < outerPadding) { res -= 1 - (distToLine - linePadding) / (outerPadding - linePadding) * 1; } else if (distToLine <= linePadding) { res -= 1; } } // не прижиматься к стене var distToBorders = Math.Min(Math.Min(my.X, my.Y), Math.Min(Const.MapSize - my.X, Const.MapSize - my.Y)); var bordersPadding = 45; if (distToBorders < bordersPadding) { res += 4 - distToBorders / bordersPadding * 4; } // не перекрывать бонус foreach (var bonus in BonusesObserver.Bonuses) { var inner = bonus.Radius + my.Radius; var dist = my.GetDistanceTo(bonus); if (dist <= inner && !bonus.Exists && bonus.RemainingAppearanceTicks < 100) { res += 30 + 20 - dist / inner * 20; } } // не прижиматься к углам for (var i = 0; i <= 3; i += 3) { var corner = Const.MapCorners[i]; var dist = my.GetDistanceTo(corner); var outer = 500; if (dist < outer) { res += 7 - dist / outer * 7; } } foreach (var tr in BuildingsDangerTriangles) { if (Geom.ContainPoint(tr, my)) { res += new Segment(tr[0], tr[1]).GetDistanceTo(my) / 100 * 10; } } return(res); }