public void AddArmyFromBorderBattle(VisualArmy armyPrefab, Army army) { Armies.Add(army); SupportOnly = Armies.All(x => x.Type == ArmyType.Support); if (!Territories.Contains(army.TargetTerritory)) { Territories.Add(army.TargetTerritory); } if (!Players.Contains(army.SourcePlayer)) { Players.Add(army.SourcePlayer); } if (!Players.Contains(army.TargetPlayer)) { Players.Add(army.TargetPlayer); } // Visual List <Vector2> walkPath = new List <Vector2>(); if (army.IsWaterArmy) { WaterConnection wc = army.SourceTerritory.Region.GetWaterConnectionTo(army.TargetTerritory.Region); System.Tuple <Vector2, float> center = new System.Tuple <Vector2, float>(wc.Center, wc.FromRegion == army.SourceTerritory.Region ? wc.Angle - 90 : wc.Angle + 90); Vector2 borderCenter = center.Item1; float targetAngle = center.Item2 + 180; float approachDistance = wc.Length / 2f; float xTarget = Mathf.Sin(Mathf.Deg2Rad * targetAngle) * approachDistance; float yTarget = Mathf.Cos(Mathf.Deg2Rad * targetAngle) * approachDistance; Vector2 coastPos = borderCenter + new Vector2(xTarget, yTarget); walkPath.Add(borderCenter); walkPath.Add(coastPos); } else { System.Tuple <Vector2, float> center = army.SourceTerritory.Region.GetBorderCenterPositionTo(army.TargetTerritory.Region); Vector2 borderCenter = center.Item1; walkPath.Add(borderCenter); } Vector2 targetPos = army.TargetTerritory.Region.CenterPoi; walkPath.Add(targetPos); VisualArmy visualArmy = GameObject.Instantiate(armyPrefab); visualArmy.Init(army, walkPath, ParriskGame.ArmyApproachTime); }
/// <summary> /// Adds a territory to the Planet /// x and y are bound to between 0 and column(x)/Rows(y) /// If location is taken, it returns false. /// </summary> /// <param name="x"/> /// <param name="y"/> /// <param name="terr">The territory to add.</param> /// <param name="context">The context of the planet.</param> public bool AddTerritoryToLocation(int x, int y, Territory terr, EconSimContext context) { // if the location is already taken, return false. if (Territories.Any(t => t.X == x && t.Y == y && t.Z == HexZ(x, y))) { return(false); } // it's not taken, so add it. terr.PlanetId = Id; Territories.Add(terr); context.Territories.AddOrUpdate(terr); context.SaveChanges(); return(true); }
/// <summary> /// Generates the territory tiles for the planet. /// </summary> public void GeneratePlanetSphere() { // set rows and columns these need to be 0 no matter what. Rows = 0; Columns = 0; Shape = PlanetTopography.Sphere; // Hexes are 250km^2 (30km in radius) // For earth size planet that is 20,402,578 var hexCount = Math.Floor(SurfaceArea / 250); if (hexCount <= 1) // only one hex, just make north pole. { // Create North Pole var NP = TerrGen(null, null, null, "North Pole"); // update it's extent in acres. NP.Extent = SurfaceArea * 250; // Add to territories. Territories.Add(NP); // set NP NorthPole = NP; } else if (hexCount <= 8) // the smallest grid is 2x3 { // Do north var NP = TerrGen(null, null, null, "North Pole"); NP.Extent = Math.Floor(SurfaceArea) / 2 * 250; Territories.Add(NP); NorthPole = NP; // Do south var SP = TerrGen(null, null, null, "South Pole"); SP.Extent = Math.Floor(SurfaceArea) / 2 * 250; Territories.Add(SP); SouthPole = SP; } else // enough for the smallest grid. { // get the height and width of our map. var height = Math.Sqrt((double)SurfaceArea / 2); Rows = (int)Math.Floor(height); Columns = (int)Math.Floor(2 * height); // We do not add any territories unless needed. } }
public void AddTerritory(Territory t) { Territories.Add(t); }