Example #1
0
    private string GeneratePreventSplitResultMessage()
    {
        float charismaFactor = _clan.CurrentLeader.Charisma / 10f;
        float wisdomFactor   = _clan.CurrentLeader.Wisdom / 15f;

        float attributesFactor = Mathf.Max(charismaFactor, wisdomFactor);

        attributesFactor = Mathf.Clamp(attributesFactor, 0.5f, 2f);

        float minPreferencePercentChange = BaseMinPreferencePercentChange / attributesFactor;
        float maxPreferencePercentChange = BaseMaxPreferencePercentChange / attributesFactor;

        float prefValue = _clan.GetPreferenceValue(CulturalPreference.AuthorityPreferenceId);

        float minPrefChange = MathUtility.DecreaseByPercent(prefValue, minPreferencePercentChange);
        float maxPrefChange = MathUtility.DecreaseByPercent(prefValue, maxPreferencePercentChange);

        string authorityPreferenceChangeStr = "\t• Clan " + _clan.Name.BoldText + ": authority preference (" + prefValue.ToString("0.00")
                                              + ") decreases to: " + minPrefChange.ToString("0.00") + " - " + maxPrefChange.ToString("0.00");

        minPreferencePercentChange = BaseMinPreferencePercentChange * attributesFactor;
        maxPreferencePercentChange = BaseMaxPreferencePercentChange * attributesFactor;

        prefValue = _clan.GetPreferenceValue(CulturalPreference.CohesionPreferenceId);

        minPrefChange = MathUtility.IncreaseByPercent(prefValue, minPreferencePercentChange);
        maxPrefChange = MathUtility.IncreaseByPercent(prefValue, maxPreferencePercentChange);

        string cohesionPreferenceChangeStr = "\t• Clan " + _clan.Name.BoldText + ": cohesion preference (" + prefValue.ToString("0.00")
                                             + ") increases to: " + minPrefChange.ToString("0.00") + " - " + maxPrefChange.ToString("0.00");

        return(authorityPreferenceChangeStr + "\n" + cohesionPreferenceChangeStr);
    }
Example #2
0
    public static void CalculateMinMaxInfluence(Clan clan, out float minInfluence, out float maxInfluence)
    {
        float charismaFactor  = clan.CurrentLeader.Charisma / 10f;
        float cultureModifier = 1 + (charismaFactor * clan.GetPreferenceValue(CulturalPreference.CohesionPreferenceId));

        minInfluence = clan.Influence * SplitClanMinInfluence / cultureModifier;
        maxInfluence = clan.Influence * SplitClanMaxInfluence / cultureModifier;
    }
    public float CalculateChanceOfSplittingForSplitClan()
    {
        float administrativeLoad = _dominantClan.CalculateAdministrativeLoad();

        if (float.IsPositiveInfinity(administrativeLoad))
        {
            return(1);
        }

        float cohesionPreferenceValue = _splitClan.GetPreferenceValue(CulturalPreference.CohesionPreferenceId);

        if (cohesionPreferenceValue <= 0)
        {
            return(1);
        }

        float cohesionPrefFactor = 2 * cohesionPreferenceValue;

        cohesionPrefFactor = Mathf.Pow(cohesionPrefFactor, 4);

        float authorityPreferenceValue = _splitClan.GetPreferenceValue(CulturalPreference.AuthorityPreferenceId);

        if (authorityPreferenceValue <= 0)
        {
            return(1);
        }

        float authorityPrefFactor = 2 * authorityPreferenceValue;

        authorityPrefFactor = Mathf.Pow(authorityPrefFactor, 4);

        float relationshipFactor = 2 * _splitClan.GetRelationshipValue(_dominantClan);

        relationshipFactor = Mathf.Pow(relationshipFactor, 4);

        float diffLimitsAdministrativeLoad = SplitClanMaxAdministrativeLoad - SplitClanMinAdministrativeLoad;

        float modMinAdministrativeLoad = SplitClanMinAdministrativeLoad * cohesionPrefFactor * relationshipFactor;
        float modMaxAdministrativeLoad = modMinAdministrativeLoad +
                                         (diffLimitsAdministrativeLoad * _dominantClan.CurrentLeader.Wisdom * _dominantClan.CurrentLeader.Charisma * authorityPrefFactor * MaxAdministrativeLoadChanceFactor);

        float chance = (administrativeLoad - modMinAdministrativeLoad) / (modMaxAdministrativeLoad - modMinAdministrativeLoad);

        return(Mathf.Clamp01(chance));
    }
    public static long CalculateTriggerDate(Clan clan)
    {
        float randomFactor = clan.GetNextLocalRandomFloat(RngOffsets.TRIBE_SPLITTING_EVENT_CALCULATE_TRIGGER_DATE + unchecked ((int)clan.Id));

        randomFactor = Mathf.Pow(randomFactor, 2);

        Clan dominantClan = clan.Polity.DominantFaction as Clan;

        float administrativeLoad = dominantClan.CalculateAdministrativeLoad();

        float loadFactor = 1;

        if (!float.IsPositiveInfinity(administrativeLoad))
        {
            float modAdminLoad           = Mathf.Max(0, administrativeLoad - SplitClanMinAdministrativeLoad);
            float modHalfFactorAdminLoad = SplitClanMaxAdministrativeLoad - SplitClanMinAdministrativeLoad;

            loadFactor = modHalfFactorAdminLoad / (modAdminLoad + modHalfFactorAdminLoad);
        }

        float cohesionPreferenceValue = clan.GetPreferenceValue(CulturalPreference.CohesionPreferenceId);

        float cohesionPrefFactor = 2 * cohesionPreferenceValue;

        cohesionPrefFactor = Mathf.Pow(cohesionPrefFactor, 4);

        float dateSpan = (1 - randomFactor) * DateSpanFactorConstant * loadFactor * cohesionPrefFactor;

        long triggerDateSpan = (long)dateSpan + CellGroup.GenerationSpan;

        if (triggerDateSpan < 0)
        {
            Debug.LogWarning("updateSpan less than 0: " + triggerDateSpan);

            triggerDateSpan = CellGroup.MaxUpdateSpan;
        }

        long triggerDate = clan.World.CurrentDate + triggerDateSpan;

        if (triggerDate > World.MaxSupportedDate)
        {
            // nextDate is invalid, generate report
            Debug.LogWarning(
                "CalculateTriggerDate - triggerDate (" + triggerDate +
                ") greater than MaxSupportedDate (" + World.MaxSupportedDate +
                "). dateSpan: " + dateSpan + ", randomFactor: " + randomFactor);

            triggerDate = int.MinValue;
        }

        return(triggerDate);
    }
    public float CalculateChanceOfSplitting()
    {
        float administrativeLoad = _clan.CalculateAdministrativeLoad();

        if (float.IsPositiveInfinity(administrativeLoad))
        {
            return(1);
        }

        float cohesionPreferenceValue = _clan.GetPreferenceValue(CulturalPreference.CohesionPreferenceId);

        if (cohesionPreferenceValue <= 0)
        {
            return(1);
        }

        float cohesionPrefFactor = 2 * cohesionPreferenceValue;

        cohesionPrefFactor = Mathf.Pow(cohesionPrefFactor, 4);

        float authorityPreferenceValue = _clan.GetPreferenceValue(CulturalPreference.AuthorityPreferenceId);

        if (authorityPreferenceValue <= 0)
        {
            return(1);
        }

        float authorityPrefFactor = 2 * authorityPreferenceValue;

        authorityPrefFactor = Mathf.Pow(authorityPrefFactor, 4);

        float modMinAdministrativeLoad = MinAdministrativeLoad * cohesionPrefFactor;
        float modMaxAdministrativeLoad = modMinAdministrativeLoad + (AdministrativeLoadSpan * _clan.CurrentLeader.Wisdom * _clan.CurrentLeader.Charisma * authorityPrefFactor * MaxAdministrativeLoadChanceFactor);

        float chance = (administrativeLoad - modMinAdministrativeLoad) / (modMaxAdministrativeLoad - modMinAdministrativeLoad);

        return(Mathf.Clamp01(chance));
    }
    private string GeneratePreventSplitResultEffectsString_AuthorityPreference()
    {
        float charismaFactor = _splitClan.CurrentLeader.Charisma / 10f;
        float wisdomFactor   = _splitClan.CurrentLeader.Wisdom / 15f;

        float attributesFactor = Mathf.Max(charismaFactor, wisdomFactor);

        attributesFactor = Mathf.Clamp(attributesFactor, 0.5f, 2f);

        float minPercentChange = BaseMinPreferencePercentChange / attributesFactor;
        float maxPercentChange = BaseMaxPreferencePercentChange / attributesFactor;

        float originalValue = _splitClan.GetPreferenceValue(CulturalPreference.AuthorityPreferenceId);

        float minValChange = MathUtility.DecreaseByPercent(originalValue, minPercentChange);
        float maxValChange = MathUtility.DecreaseByPercent(originalValue, maxPercentChange);

        return("Clan " + _splitClan.Name.BoldText + ": authority preference (" + originalValue.ToString("0.00") + ") decreases to: " +
               minValChange.ToString("0.00") + " - " + maxValChange.ToString("0.00"));
    }
    public static long CalculateTriggerDate(Clan clan)
    {
        float randomFactor = clan.GetNextLocalRandomFloat(RngOffsets.CLAN_DEMANDS_INFLUENCE_EVENT_CALCULATE_TRIGGER_DATE + unchecked ((int)clan.Id));

        randomFactor = Mathf.Pow(randomFactor, 2);

        float administrativeLoad = clan.CalculateAdministrativeLoad();

        float loadFactor = 1;

        if (!float.IsPositiveInfinity(administrativeLoad))
        {
            float modAdminLoad = Mathf.Max(0, administrativeLoad - DemandClanMinAdministrativeLoad);

            loadFactor = 1 - DemandClanAdministrativeLoadSpan / (modAdminLoad + DemandClanAdministrativeLoadSpan);
        }

        float authorityPreferenceValue = clan.GetPreferenceValue(CulturalPreference.AuthorityPreferenceId);

        float authorityPrefFactor = 2 * (1 - authorityPreferenceValue);

        authorityPrefFactor = Mathf.Pow(authorityPrefFactor, 4);

        float dateSpan = (1 - randomFactor) * DateSpanFactorConstant * loadFactor * authorityPrefFactor;

        long triggerDateSpan = (long)dateSpan + CellGroup.GenerationSpan;

        if (triggerDateSpan < 0)
        {
            Debug.LogWarning("updateSpan less than 0: " + triggerDateSpan);

            triggerDateSpan = CellGroup.MaxUpdateSpan;
        }

        long triggerDate = clan.World.CurrentDate + triggerDateSpan;

        //#if DEBUG
        //        if ((Manager.RegisterDebugEvent != null) && (Manager.TracingData.Priority <= 0))
        //        {
        //            SaveLoadTest.DebugMessage debugMessage = new SaveLoadTest.DebugMessage(
        //                "ClanDemandsInfluenceDecisionEvent:CalculateTriggerDate - clan.Id:" + clan.Id,
        //                "triggerDate: " + triggerDate +
        //                ", triggerDateSpan: " + triggerDateSpan +
        //                ", dateSpan: " + dateSpan +
        //                ", randomFactor: " + randomFactor +
        //                ", loadFactor: " + loadFactor +
        //                ", authorityPrefFactor: " + authorityPrefFactor +
        //                ", clan.LastUpdateDate: " + clan.LastUpdateDate +
        //                ", clan.World.CurrentDate: " + clan.World.CurrentDate +
        //                "");

        //            Manager.RegisterDebugEvent("DebugMessage", debugMessage);
        //        }
        //#endif

        if (triggerDate > World.MaxSupportedDate)
        {
            // nextDate is invalid, generate report
            Debug.LogWarning(
                "CalculateTriggerDate - triggerDate (" + triggerDate +
                ") greater than MaxSupportedDate (" + World.MaxSupportedDate +
                "). dateSpan: " + dateSpan + ", randomFactor: " + randomFactor);

            triggerDate = int.MinValue;
        }

        return(triggerDate);
    }
    public float CalculateChanceOfMakingDemand()
    {
        float administrativeLoad = _demandClan.CalculateAdministrativeLoad();

        if (float.IsPositiveInfinity(administrativeLoad))
        {
            return(0);
        }

        float authorityPreferenceValue = _demandClan.GetPreferenceValue(CulturalPreference.AuthorityPreferenceId);

        if (authorityPreferenceValue <= 0)
        {
            return(0);
        }

        float authorityPrefFactor = 2 * authorityPreferenceValue;

        authorityPrefFactor = Mathf.Pow(authorityPrefFactor, 4);

        float relationshipValue = _demandClan.GetRelationshipValue(_dominantClan);

        if (relationshipValue >= 1)
        {
            return(0);
        }

        float relationshipFactor = 2 * (1 - relationshipValue);

        relationshipFactor = Mathf.Pow(relationshipFactor, 4);

        float influenceDeltaValue = _dominantClan.Influence - _demandClan.Influence;

        if (influenceDeltaValue <= 0)
        {
            return(0);
        }

        if (influenceDeltaValue >= 1)
        {
            return(1);
        }

        float influenceFactor = 2 * influenceDeltaValue;

        influenceFactor = Mathf.Pow(influenceFactor, 4);

        float factors = authorityPrefFactor * relationshipFactor * influenceFactor * DecisionChanceFactor;

        float modMinAdministrativeLoad = DemandClanMinAdministrativeLoad * factors;
        float modMaxAdministrativeLoad = DemandClanMaxAdministrativeLoad * factors;

        float chance = 1 - (administrativeLoad - modMinAdministrativeLoad) / (modMaxAdministrativeLoad - modMinAdministrativeLoad);

        //#if DEBUG
        //        if ((Manager.RegisterDebugEvent != null) && (Manager.TracingData.Priority <= 0))
        //        {
        //            if ((Manager.TracingData.FactionId == _dominantClan.Id) ||
        //                (Manager.TracingData.FactionId == _demandClan.Id))
        //            {
        //                SaveLoadTest.DebugMessage debugMessage = new SaveLoadTest.DebugMessage(
        //                    "ClanDemandsInfluenceDecisionEvent:CalculateChanceOfMakingDemand - DemandClanId:" + _demandClan.Id + ", DominantClan: " + _dominantClan.Id,
        //                    "TriggerDate: " + TriggerDate +
        //                    ", administrativeLoad: " + administrativeLoad +
        //                    ", authorityPreferenceValue: " + authorityPreferenceValue +
        //                    ", relationshipValue: " + relationshipValue +
        //                    ", influenceDeltaValue: " + influenceDeltaValue +
        //                    "");

        //                Manager.RegisterDebugEvent("DebugMessage", debugMessage);
        //            }
        //        }
        //#endif

        return(Mathf.Clamp01(chance));
    }