Example #1
0
    /// <summary>
    /// Creates a province starting at the given position.
    /// </summary>
    /// <param name="coords">The starting location of the province.</param>
    /// <param name="faction">The faction to which this province belongs.</param>
    /// <param name="range">The radius of the new province.</param>
    public static void CreateProvinceAt(TileCoordinates coords, Faction faction, string name, int range = 3)
    {
        Province province = worldManager.CreateProvince();

        province.faction = faction;
        province.name    = name.Replace(" ", "\n");

        // add territory within the range
        for (int x = -range; x <= range; x++)
        {
            for (int z = -range; z <= range; z++)
            {
                if (Math.Abs(x + z) > range)
                {
                    continue;
                }

                Tile tile = GetTileAt(new TileCoordinates(x + coords.x, z + coords.z));
                if (tile == null || tile.faction != null)
                {
                    continue;                                         // if the tile doesn't exist or the tile is already owned
                }
                province.AddTile(tile);
            }
        }

        _provinces.Add(province);
        faction.AddProvince(province);
        worldManager.CreateProvinceLabel(coords, name);

        InvalidateProvinceMesh();
    }
Example #2
0
 /// <summary>
 /// Set up provinces
 /// Depends on races and factions being set up
 /// </summary>
 private void SetUpProvinces()
 {
     _provinces = new Dictionary <int, Province>();
     for (int i = 0; i < _data.provinces.Length; i++)
     {
         Race    dwellers = GetRace(_data.provinces[i].raceId);
         Faction owners   = GetFaction(_data.provinces[i].factionId);
         if (dwellers != null && owners != null)
         {
             Province province = new Province(_data.provinces[i], dwellers, owners, _unitTypes);
             _provinces[_data.provinces[i].id] = province;
             owners.AddProvince(province);
         }
     }
 }
Example #3
0
    /// <summary>
    /// Transfer province ownership to a new faction
    /// </summary>
    /// <param name="province">The province in question</param>
    /// <param name="newOwners">The faction which will control the province</param>
    private void ChangeProvinceOwnership(Province province, Faction newOwners)
    {
        FileLogger.Trace("SUMMARY", province.GetName() + "'s ownership changes from " + province.GetOwnersFaction().GetName() + " to " + newOwners.GetName());
        province.GetOwnersFaction().RemoveProvince(province);
        province.ClearTrainingQueue();
        province.SetOwnersFaction(newOwners);
        newOwners.AddProvince(province);

        // NOTE: there may be a better way to prevent Guardians from suddenly taking over all minor human provinces
        if (newOwners.IsPlayable())
        {
            Race            newOwnersRace = newOwners.GetRace();
            List <Province> neighbors     = province.GetNeighbors();
            for (int i = 0; i < neighbors.Count; i++)
            {
                Province neighbor = neighbors[i];
                if (neighbor.GetDwellersRace() == newOwnersRace && neighbor.GetOwnersFaction().IsMinor())
                {
                    ChangeProvinceOwnership(neighbor, newOwners);
                }
            }
        }
    }