public static bool ShouldSwap(SimGame game, SimUnit unit) { if (!unit.HasWeapon) { return(true); } if (unit.WeaponType == WeaponType.AssaultRifle) { return(false); } var weaponBoxes = game.game.Weapons; var closest = weaponBoxes.OrderBy(w => new MyPosition(w.Position).Dist(unit.Position)).Cast <LootBox?>().FirstOrDefault(); if (closest == null) { return(false); } var weapon = closest.Value.Item as Item.Weapon; var rect = Rect.FromMovingBullet(closest.Value.Position, closest.Value.Size.X); if (rect.Overlapping(unit.Rect) && unit.WeaponType != weapon.WeaponType) { if (weapon.WeaponType == WeaponType.AssaultRifle) { return(true); } if (weapon.WeaponType == WeaponType.Pistol) { return(true); } //return weapon.WeaponType > game.Me.Weapon.Typ; } return(false); }
public static MyPosition GetRealTarget(SimGame game, SimUnit unit) { //if (game.Game.CurrentTick > 1000) return Attack(game); if (!unit.HasWeapon) { return(GetWeapon(game.game, unit)); } var weaps = game.game.Weapons.Where(w => (w.Item as Item.Weapon).WeaponType == WeaponType.AssaultRifle).ToList(); if (unit.Weapon.Typ != AiCup2019.Model.WeaponType.AssaultRifle && weaps.Any(w => unit.Position.Dist(new MyPosition(w.Position)) < 4)) { return(new MyPosition(weaps.First(w => unit.Position.Dist(new MyPosition(w.Position)) < 4).Position)); } if (unit.NeedsHealing && game.game.HasHealing) { return(GetHealing(game.game, unit)); } //return new MyPosition(game.Enemy.Center.MoveTowards(me.Center, 3).X, game.Height-2); if (unit.Weapon.FireTimer > 0.2 && unit.Position.Dist(unit.TargetEnemy.Position) < 3) { return(Hide(game, unit)); } //LogService.WriteLine("Diff: " + game.ScoreDiff + " Tick: " + game.Game.CurrentTick + " " + game.Width + " " + game.Height); if (unit.Position.Dist(unit.TargetEnemy.Position) < 4 && Math.Abs(unit.Position.Y - unit.TargetEnemy.Position.Y) < 1) { return(Attack(game.game, unit)); } // if (unit.Player.ScoreDiff > 0) return Hide(game, unit); if (unit.Player.ScoreDiff == 0 && game.game.Game.CurrentTick < 300 && unit.TargetEnemy.HasWeapon) { return(Hide(game, unit)); } return(Attack(game.game, unit)); }
public void RemoveUnit(SimUnit unit) { unit.Destroy(); units.Remove(unit); boxListener.OnUnitRemoved(unit); }
private static MyPosition GetWeapon(MyGame game, SimUnit unit) { //if (unit.Allied != null) //{ // return new MyPosition(game.Weapons.Where(w => new MyPosition(w.Position).Dist(unit.Allied) > .OrderBy(p => DistService.GetDist(new MyPosition(p.Position), unit.Position)).First().Position); //} return(new MyPosition(game.Weapons.OrderBy(p => DistService.GetDist(new MyPosition(p.Position), unit.Position)).First().Position)); }
private static MyPosition GetHealing(MyGame game, SimUnit unit) { var target = game.HealthPacks.OrderBy(p => DistService.GetDist(p, unit.Position)).FirstOrDefault(h => DistService.GetDist(h, unit.Position) < DistService.GetDist(h, unit.TargetEnemy.Position)); if (target == null) { target = game.HealthPacks.OrderBy(p => DistService.GetDist(p, unit.Position)).First(); } return(target); }
private static MyPosition Attack(MyGame game, SimUnit unit) { return(unit.TargetEnemy.Position); //var diff = 5; //if (game.Game.CurrentTick > 3000 && unit.Player.ScoreDiff <= 0) diff = 3; //var target = unit.TargetEnemy.Position.MoveTowards(unit.Position, diff); //if (target.X >= game.Width || target.X < 0) diff *= -1; //target = unit.TargetEnemy.Position.MoveTowards(unit.Position, diff); //return new MyPosition(target.X, Math.Min(target.Y, target.X)); }
public void OnUnitAdded(SimUnit unit) { GameObject goUnit = new GameObject(); goUnit.transform.parent = unitsContainer; SimUnitUnity unitUnity = goUnit.AddComponent <SimUnitUnity>(); unitUnity.Init(unit); unitsUnity.Add(unitUnity); }
private bool UnloadResources() { SimUnit targetUnit = lastPoint.GetUnitWithTargetAndCapacity(searchTarget, resources); if (targetUnit != null) { resources.TransferResourcesTo(targetUnit.resources); } return(resources.IsEmpty()); }
public SimAgent AddAgent(SimAgentType agentType, SimPoint position, SimUnit owner, SimResourceBinCollection resources, string searchTarget) { SimAgent agent = new SimAgent(); agent.Init(agentType, nextAgentId++, position, owner, resources, searchTarget); agents.Add(agent); boxListener.OnAgentAdded(agent); return(agent); }
public void OnUnitRemoved(SimUnit unit) { for (int i = 0; i < unitsUnity.Count; i++) { if (unitsUnity[i].unit == unit) { GameObject.Destroy(unitsUnity[i].gameObject); unitsUnity.RemoveAt(i); break; } } }
public void Init(SimAgentType agentType, int id, SimPoint position, SimUnit owner, SimResourceBinCollection resources, string searchTarget) { this.agentType = agentType; this.id = id; this.owner = owner; this.searchTarget = searchTarget; this.resources.AddResources(resources); this.worldPosition = position.worldPosition; this.lastPoint = position; }
public SimUnit AddUnit(SimUnitType unitType, SimPoint position) { SimUnit unit = new SimUnit(); unit.Init(unitType, nextUnitId++, position); units.Add(unit); boxListener.OnUnitAdded(unit); return(unit); }
public static bool ShouldShoot(SimGame game, SimUnit unit) { LogService.WriteLine("FireTimer: " + unit.FireTimer); if (!unit.HasWeapon) { return(false); } // return (CanShootAt(unit.Position, unit.TargetEnemy.Position)); //if (me.Unit.Weapon.Value.Spread > me.Unit.Weapon.Value.Parameters.MinSpread + 0.1 && me.Center.Dist(aimPos) > 5) return false; if (!CanShoot(unit.Position, unit.AimTarget, game, unit, unit.Weapon.Parameters.Bullet.Speed)) { return(false); } return(true); }
public static MyPosition[] GetSpread(SimUnit unit) { var aim = unit.AimTarget; var pos = unit.Position; if (!unit.HasWeapon) { return(new MyPosition[0]); } var angle = Math.Atan2(aim.Y - pos.Y, aim.X - pos.X); var max = angle + unit.Spread; var min = angle - unit.Spread; return(new MyPosition[] { pos.MoveTowards(max, 20), pos.MoveTowards(min, 20) }); }
public void Init(SimUnit unit) { this.unit = unit; gameObject.name = unit.unitType.id + "-" + unit.id; transform.localPosition = unit.position.worldPosition; box = GameObject.CreatePrimitive(PrimitiveType.Cube).transform; box.parent = transform; box.localPosition = Vector3.zero; Material unitMaterial = MaterialsFactory.CreateDiffuseColor(unit.unitType.color); box.renderer.sharedMaterial = unitMaterial; }
public static MyPosition FindWalkTarget(SimGame game, SimUnit unit) { var target = GetRealTarget(game, unit); for (var y = (int)target.Y; y < game.game.Height; y++) { var p = new MyPosition(target.X, y); var d = DistService.GetDist(p, unit.Position); if (d < game.game.Width * game.game.Height * 4) { target = p; break; } } LogService.DrawLine(target, unit.Position, 1, 0, 0); return(target); }
private static UnitAction CreateAction(SimUnit unit, SimGame game) { var selectedAction = unit.GetBestNode(); var aim = unit.AimTarget; var pos = unit.Position; var shoot = unit.Shoot; var enemies = unit.Enemies.OrderBy(e => e.Position.Dist(pos) + e.Health * 0.01).ToList(); var targetPos = enemies.First().Position; UnitAction action = new UnitAction { Velocity = selectedAction.Dx * Const.Properties.UnitMaxHorizontalSpeed, Jump = selectedAction.JumpUp, JumpDown = selectedAction.JumpDown, Aim = new Vec2Double(aim.X - pos.X, aim.Y - pos.Y), Shoot = shoot, Reload = !shoot && unit.HasWeapon && pos.Dist(targetPos) > 5 && unit.HasWeapon && unit.Weapon.Magazine < unit.Weapon.Parameters.MagazineSize * 0.3, SwapWeapon = SwapService.ShouldSwap(game, unit), PlantMine = unit.Position.Dist(unit.TargetEnemy.Position) < 3 }; return(action); }
public static MyPosition GetAimTarget(SimGame game, SimUnit unit) { var pos = unit.Position; var targetPos = unit.TargetEnemy.Position; //if (!unit.HasWeapon) return(targetPos); foreach (var e in unit.Enemies.OrderBy(e => e.Position.Dist(unit.Position))) { if (ShootService.CanHitDirect(unit.Position, e.Position, game, unit)) { targetPos = e.Position; break; } } var dist = pos.Dist(targetPos); var requested = unit.WeaponType == AiCup2019.Model.WeaponType.RocketLauncher ? GetClosestGround(game.game, targetPos) : targetPos; if (dist < 3 || Math.Abs(targetPos.Y - pos.Y) < 0.1) { requested = targetPos; } var angle = Math.Atan2(requested.Y - pos.Y, requested.X - pos.X); var prevAngle = unit.AimAngle; if (Math.Abs(angle - prevAngle) < 0.1 || unit.FireTimer > 0 && Math.Abs(angle - prevAngle) < 0.2) { angle = prevAngle; } var dx = Math.Cos(angle) * dist; var dy = Math.Sin(angle) * dist; var target = new MyPosition(pos.X + dx, pos.Y + dy); //LogService.DrawLine(target, unit.Position, 1, 0, 0); return(target); }
public static MyPosition GetHitPos(MyPosition startPos, MyPosition endPos, SimGame game, double bulletSpeed, SimUnit firering, bool stopOnEnd = true) { var dist = endPos.Dist(startPos); var time = GetShootTime(dist, bulletSpeed) * Const.Properties.TicksPerSecond * 15; var dx = (endPos.X - startPos.X) / time; var dy = (endPos.Y - startPos.Y) / time; var x = startPos.X; var y = startPos.Y; var d = startPos.Dist(endPos); for (var i = 0; i < time * 2; i++) { x += dx; y += dy; if (!game.game.OnBoard(x, y)) { return(new MyPosition(x, y)); } var tile = game.GetTileD(x, y); if (tile == Tile.Wall) { return(new MyPosition(x, y)); } tile = game.GetTileD(x - firering.Weapon.Parameters.Bullet.Size * 0.5, y - firering.Weapon.Parameters.Bullet.Size * 0.5); if (tile == Tile.Wall) { return(new MyPosition(x, y)); } tile = game.GetTileD(x + firering.Weapon.Parameters.Bullet.Size * 0.5, y - firering.Weapon.Parameters.Bullet.Size * 0.5); if (tile == Tile.Wall) { return(new MyPosition(x, y)); } var nextD = Math.Sqrt(MyPosition.Pow(x - endPos.X) + MyPosition.Pow(y - endPos.Y)); if (nextD > d && stopOnEnd || nextD < 0.3) { return(endPos); } d = nextD; foreach (var u in game.Units) { if (u == firering || u.unit.PlayerId != firering.unit.PlayerId) { continue; } var unit = u.unit; if (!(Math.Abs(x - unit.Position.X) > firering.Weapon.Parameters.Bullet.Size / 2 + unit.Size.X / 2 || Math.Abs(y - unit.Position.Y) > firering.Weapon.Parameters.Bullet.Size / 2 + unit.Size.Y / 2)) { return(new MyPosition(x, y)); } } } return(endPos); }
public void OnUnitAdded(SimUnit unit) { }
private static MyPosition Hide(SimGame game, SimUnit unit) { var heights = game.game.GetHideouts(); return(heights.OrderByDescending(p => DistService.GetDist(p, unit.TargetEnemy.Position) - DistService.GetDist(unit.Position, p) * 0.5).FirstOrDefault() ?? unit.TargetEnemy.Position); }
public void OnUnitRemoved(SimUnit unit) { }
public static bool CanShoot(MyPosition startPos, MyPosition endPos, SimGame game, SimUnit unit, double bulletSpeed) { var hitPos = GetHitPos(startPos, endPos, game, bulletSpeed, unit); var spread = AimService.GetSpread(unit); var posses = spread.Select(s => GetHitPos(startPos, s, game, bulletSpeed, unit)).ToArray(); foreach (var p in posses) { LogService.DrawLine(p, unit.Position, 0, 0, 1); } if (unit.WeaponType == WeaponType.RocketLauncher) { if (posses.Any(p => p.Dist(unit.TargetEnemy.Position) > p.Dist(unit.Position) && p.Dist(endPos) > unit.Weapon.Parameters.Explosion.Value.Radius - 1)) { return(false); } if (unit.TargetEnemy.Position.Dist(endPos) - unit.Weapon.Parameters.Explosion.Value.Radius > unit.Position.Dist(endPos)) { return(false); } } return(hitPos.Dist(endPos) < 1); }
public static bool CanHitDirect(MyPosition startPos, MyPosition endPos, SimGame game, SimUnit firering) { var hitPos = GetHitPos(startPos, endPos, game, 5, firering); return(hitPos.Dist(endPos) < 1); }