public void setPlatform(MiningPlatform m) { miningPlatform = m; if (m != null) { m.setRock(this); } }
public static void SetBuildingPlatform(int FactionNumber, MiningPlatform p) { Factions[FactionNumber].MiningPlatformCounter -= Factions[FactionNumber].MaxMiningPlatformCounter; Factions[FactionNumber].MaxMiningPlatformCounter += 2; if (Factions[FactionNumber].MaxMiningPlatformCounter > 8) { Factions[FactionNumber].MaxMiningPlatformCounter = 8; } Factions[FactionNumber].BuildingPlatform = p; }
private void addMineralRock(MiningPlatform r) { if (r.GetTeam() == WaveManager.ActiveTeam) { Vector2 UpperLeftCorner = (r.getUpperLeftCorner() - Parent2DScene.MinBoundary.get()) / Divisor; Vector2 LowerRightCorner = (r.getLowerRightCorner() - Parent2DScene.MinBoundary.get()) / Divisor; int MinX = (int)UpperLeftCorner.X; int MinY = (int)UpperLeftCorner.Y; int MaxX = (int)LowerRightCorner.X; int MaxY = (int)LowerRightCorner.Y; for (int x = MinX; x < MaxX; x++) { for (int y = MinY; y < MaxY; y++) { CellJobQue.Enqueue(x); CellJobQue.Enqueue(y); CellJobQue.Enqueue(StartingCell); } } } }
public override void Interact(PlayerShip p) { if (miningPlatform == null && FactionManager.CanBuildMiningPlatform(p.FactionNumber)) { Vector3 P3 = new Vector3(Position.X(), 0, Position.Y()); for (int i = 0; i < 40; i++) { LineParticleSystem.AddParticle(P3, P3 + Rand.V3() * 1000, TeamInfo.GetColor(p.GetTeam())); } MiningPlatform m = FactionManager.GetMiningPlatform(p.FactionNumber); ParentLevel.AddObject(m); m.Position.set(Position.get()); setPlatform(m); SoundManager.Play3DSound("PlayerBuildMiningRing", new Vector3(m.Position.X(), Y, m.Position.Y()), 0.25f, 500, 1); if (p.PlacedStartingMineralRock) { FactionManager.AddCells(p.FactionNumber, -FactionManager.GetMiningPlatformCost(p.FactionNumber)); FactionManager.SetBuildingPlatform(p.FactionNumber, m); } else { FactionManager.GetFaction(p.FactionNumber).MiningPlatformCounter = 0; m.HullToughness *= 2; m.SetAsStarting(); p.PlacedStartingMineralRock = true; p.StartingMineralRock = this; } p.LastPlacedPlatform.AddFirst(m); PathFindingManager.AddMineralRock(m); } base.Interact(p); }
public virtual Vector2 GetPlacePosition(int FactionNumber) { float BestScore = -500000; Vector2 BestPosition = Vector2.Zero; float Distance = 1000; float JumpSize = 100; Vector2 MinPos = new Vector2(10000); Vector2 MaxPos = new Vector2(-10000); foreach (MiningPlatform m in GameManager.GetLevel().getCurrentScene().Enumerate(typeof(MiningPlatform))) { if (m.GetTeam() == FactionManager.GetTeam(FactionNumber) && !m.Dead) { MinPos = Vector2.Min(MinPos, m.Position.get() - new Vector2(Distance)); MaxPos = Vector2.Max(MaxPos, m.Position.get() + new Vector2(Distance)); } } Basic2DScene b = (Basic2DScene)GameManager.GetLevel().getCurrentScene(); MinPos = Vector2.Max(MinPos, b.MinBoundary.get()); MaxPos = Vector2.Min(MaxPos, b.MaxBoundary.get()); for (float x = MinPos.X; x < MaxPos.X; x += JumpSize) { for (float y = MinPos.Y; y < MaxPos.Y; y += JumpSize) { if (TestFree(new Vector2(x, y), TurretSize, FactionNumber) && PathFindingManager.GetCellValue(new Vector2(x, y)) != PathFindingManager.DeadCell) { float score = 5000; if (GetTurretFragility() != 0) { if (PathFindingManager.CollisionLine(new Vector2(x, y), 1, 0, 3)) { score += 100 * GetTurretFragility(); } if (PathFindingManager.CollisionLine(new Vector2(x, y), -1, 0, 3)) { score += 100 * GetTurretFragility(); } if (PathFindingManager.CollisionLine(new Vector2(x, y), 0, 1, 3)) { score += 100 * GetTurretFragility(); } if (PathFindingManager.CollisionLine(new Vector2(x, y), 0, -1, 3)) { score += 100 * GetTurretFragility(); } if (PathFindingManager.CollisionLine(new Vector2(x, y), -1, -1, 2)) { score += 100 * GetTurretFragility(); } if (PathFindingManager.CollisionLine(new Vector2(x, y), 1, -1, 2)) { score += 100 * GetTurretFragility(); } if (PathFindingManager.CollisionLine(new Vector2(x, y), -1, 1, 2)) { score += 100 * GetTurretFragility(); } if (PathFindingManager.CollisionLine(new Vector2(x, y), 1, 1, 2)) { score += 100 * GetTurretFragility(); } } foreach (NeutralSpawn spawn in NeutralManager.SpawnList) { if (PathFindingManager.GetCellValue(spawn.Position.get()) > PathFindingManager.StartingCell - 50 && PathFindingManager.GetCellValue(spawn.Position.get()) < PathFindingManager.StartingCell - 20 && PathFindingManager.GetAreaClear(spawn.Position.get())) { if (GetTurretFragility() != 0 && PathFindingManager.CollisionLine(new Vector2(x, y), spawn.Position.get())) { score += 500 * GetTurretFragility(); } if (score > BestScore) { MiningPlatform NearestMiningPlatform = null; float NearestDistance = 10000; foreach (MiningPlatform m2 in GameManager.GetLevel().getCurrentScene().Enumerate(typeof(MiningPlatform))) { if (m2.GetTeam() == FactionManager.GetTeam(FactionNumber) && !m2.Dead) { float d = Vector2.Distance(m2.Position.get(), spawn.Position.get()); if (d < NearestDistance) { NearestDistance = d; NearestMiningPlatform = m2; } } } score -= Logic.DistanceLineSegmentToPoint(spawn.Position.get(), NearestMiningPlatform.Position.get(), new Vector2(x, y)) * GetTurretAgression(); } } } if (score > BestScore) { Basic2DScene Parent2DScene = (Basic2DScene)GameManager.GetLevel().getCurrentScene(); QuadGrid quad = Parent2DScene.quadGrids.First.Value; foreach (Basic2DObject o in quad.Enumerate(new Vector2(x, y), new Vector2(200))) { if (o.GetType().IsSubclassOf(typeof(UnitBuilding))) { UnitBuilding s = (UnitBuilding)o; if (s.GetTeam() == FactionManager.GetTeam(FactionNumber)) { float d = Vector2.Distance(o.Position.get(), new Vector2(x, y)); if (d < 2000) { score -= (2000 - d) * GetBuildingAvoidence(); if (s.GetType().IsSubclassOf(typeof(MiningPlatform))) { score -= (2000 - d) * GetBaseAvoidence(); } else if (s.GetType().IsSubclassOf(typeof(UnitTurret))) { UnitTurret t = (UnitTurret)s; if (t.MyCard != null) { if (t.MyCard.StrongVs.Equals(StrongVs)) { score -= (2000 - d) * GetTurretAvoidence(); } } else { if (StrongVs.Equals("Heavy")) { score -= (2000 - d) * GetTurretAvoidence(); } } } } } } } if (score > BestScore) { BestScore = score; BestPosition = new Vector2(x, y); } } } } } return(BestPosition); }
public static void AddMineralRock(MiningPlatform r) { self.HotPoints.AddLast(new PathfindingHotPoint(r.Position.get(), r.GetTeam())); self.rebuild(); }
public MiningPlatform traceToMiningPlatform(Vector2 Position, int Team) { int AX = (int)((Position.X - Parent2DScene.MinBoundary.X()) / Divisor.X); int AY = (int)((Position.Y - Parent2DScene.MinBoundary.Y()) / Divisor.Y); AX = AX <1 ? 1 : AX> CellsX.get() - 2 ? CellsX.get() - 2 : AX; AY = AY <1 ? 1 : AY> CellsY.get() - 2 ? CellsY.get() - 2 : AY; int MaxValue; int reps = 0; while (CellGrid[AX, AY] != DeadCell && CellGrid[AX, AY] != StartingCell) { MaxValue = Max(CellGrid[AX - 1, AY], CellGrid[AX + 1, AY], CellGrid[AX, AY - 1], CellGrid[AX, AY + 1]); if (MaxValue == CellGrid[AX - 1, AY]) { AX--; } if (MaxValue == CellGrid[AX + 1, AY]) { AX++; } if (MaxValue == CellGrid[AX, AY - 1]) { AY--; } if (MaxValue == CellGrid[AX, AY + 1]) { AY++; } AX = AX <1 ? 1 : AX> CellsX.get() - 2 ? CellsX.get() - 2 : AX; AY = AY <1 ? 1 : AY> CellsY.get() - 2 ? CellsY.get() - 2 : AY; if (reps++ > 1000) { return(null); } } Vector2 ProjectedPosition = TransformToWorld(AX, AY); float BestDistance = 10000; MiningPlatform Result = null; foreach (UnitBasic u in FactionManager.SortedUnits[Team]) { if (u.GetType().IsSubclassOf(typeof(MiningPlatform))) { float d = Vector2.Distance(u.Position.get(), ProjectedPosition); if (d < BestDistance) { BestDistance = d; Result = (MiningPlatform)u; } } } return(Result); }
public void buildAttackGrid() { if (AttackGrid == null) { AttackGrid = new int[CellsX.get(), CellsY.get()]; } AttackJobQue.Clear(); for (int x = 0; x < CellsX.get(); x++) { for (int y = 0; y < CellsY.get(); y++) { AttackGrid[x, y] = NeutralCell; } } MiningPlatform forwardPlatform = PathFindingManager.TraceToMiningPlatform(NeutralManager.GetSpawnPosition(), WaveManager.ActiveTeam); foreach (MiningPlatform r in Parent2DScene.Enumerate(typeof(MiningPlatform))) { if (!r.Dead && r.GetTeam() == WaveManager.ActiveTeam) { Vector2 UpperLeftCorner = (r.getUpperLeftCorner() - Parent2DScene.MinBoundary.get()) / Divisor; Vector2 LowerRightCorner = (r.getLowerRightCorner() - Parent2DScene.MinBoundary.get()) / Divisor; int MinX = (int)UpperLeftCorner.X; int MinY = (int)UpperLeftCorner.Y; int MaxX = (int)LowerRightCorner.X; int MaxY = (int)LowerRightCorner.Y; for (int x = MinX; x < MaxX; x++) { for (int y = MinY; y < MaxY; y++) { AttackJobQue.Enqueue(x); AttackJobQue.Enqueue(y); AttackJobQue.Enqueue(r == forwardPlatform && WaveManager.CurrentWave > 5 ? StartingCell / 2 : StartingCell); } } } } foreach (UnitTurret u in Parent2DScene.Enumerate(typeof(UnitTurret))) { if (!u.Dead && u.GetTeam() == WaveManager.ActiveTeam && ((u.MyCard == null && !NeutralManager.MyPattern.CurrentCard.Type.Equals("Heavy")) || (u.MyCard != null && !u.MyCard.StrongVs.Equals(NeutralManager.MyPattern.CurrentCard.Type)))) { Vector2 UpperLeftCorner = (u.getUpperLeftCorner() - Parent2DScene.MinBoundary.get()) / Divisor; Vector2 LowerRightCorner = (u.getLowerRightCorner() - Parent2DScene.MinBoundary.get()) / Divisor; int MinX = (int)UpperLeftCorner.X; int MinY = (int)UpperLeftCorner.Y; int MaxX = (int)LowerRightCorner.X; int MaxY = (int)LowerRightCorner.Y; for (int x = MinX; x < MaxX; x++) { for (int y = MinY; y < MaxY; y++) { AttackJobQue.Enqueue(x); AttackJobQue.Enqueue(y); AttackJobQue.Enqueue(StartingCell); } } } } }