Example #1
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);
                }
            }
        }
    }