Ejemplo n.º 1
0
    public static void LeaderPreventsSplit(Clan splitClan, Clan dominantClan, Tribe tribe, long eventId)
    {
        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);

        int rngOffset = RngOffsets.TRIBE_SPLITTING_EVENT_TRIBE_LEADER_PREVENTS_MODIFY_ATTRIBUTE;

        // Influence

        float randomFactor           = dominantClan.GetNextLocalRandomFloat(rngOffset++);
        float influencePercentChange = (BaseMaxInfluencePercentChange - BaseMinInfluencePercentChange) * randomFactor + BaseMinInfluencePercentChange;

        influencePercentChange /= attributesFactor;

        Polity.TransferInfluence(dominantClan, splitClan, influencePercentChange);

        // Relationship

        randomFactor = dominantClan.GetNextLocalRandomFloat(rngOffset++);
        float relationshipPercentChange = (BaseMaxRelationshipPercentChange - BaseMinRelationshipPercentChange) * randomFactor + BaseMinRelationshipPercentChange;

        relationshipPercentChange *= attributesFactor;

        float newValue = MathUtility.IncreaseByPercent(dominantClan.GetRelationshipValue(splitClan), relationshipPercentChange);

        Faction.SetRelationship(dominantClan, splitClan, newValue);

        // Updates

        LeaderPreventsSplit_notifySplitClan(splitClan, dominantClan, tribe, eventId);
    }
    public static void LeaderPreventsSplit(Clan splitClan, Clan dominantClan, Tribe tribe)
    {
        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);

        int rngOffset = RngOffsets.TRIBE_SPLITTING_EVENT_SPLITCLAN_LEADER_PREVENTS_MODIFY_ATTRIBUTE;

        // Authority preference

        float randomFactor = splitClan.GetNextLocalRandomFloat(rngOffset++);
        float authorityPreferencePercentChange = (BaseMaxPreferencePercentChange - BaseMinPreferencePercentChange) * randomFactor + BaseMinPreferencePercentChange;

        authorityPreferencePercentChange /= attributesFactor;

        splitClan.DecreasePreferenceValue(CulturalPreference.AuthorityPreferenceId, authorityPreferencePercentChange);

        // Influence

        randomFactor = splitClan.GetNextLocalRandomFloat(rngOffset++);
        float influencePercentChange = (BaseMaxInfluencePercentChange - BaseMinInfluencePercentChange) * randomFactor + BaseMinInfluencePercentChange;

        influencePercentChange /= attributesFactor;

        Polity.TransferInfluence(splitClan, dominantClan, influencePercentChange);

        // Relationship

        randomFactor = splitClan.GetNextLocalRandomFloat(rngOffset++);
        float relationshipPercentChange = (BaseMaxRelationshipPercentChange - BaseMinRelationshipPercentChange) * randomFactor + BaseMinRelationshipPercentChange;

        relationshipPercentChange *= attributesFactor;

        float newValue = MathUtility.IncreaseByPercent(splitClan.GetRelationshipValue(dominantClan), relationshipPercentChange);

        Faction.SetRelationship(splitClan, dominantClan, newValue);

        // Updates

        splitClan.SetToUpdate();
        dominantClan.SetToUpdate();

        tribe.AddEventMessage(new SplitClanPreventTribeSplitEventMessage(splitClan, tribe, splitClan.CurrentLeader, splitClan.World.CurrentDate));
    }
    public float CalculateChanceOfSplittingForTribe()
    {
        float administrativeLoad = _dominantClan.CalculateAdministrativeLoad();

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

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

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

        float cohesionPrefFactor = 2 * cohesionPreferenceValue;

        cohesionPrefFactor = Mathf.Pow(cohesionPrefFactor, 4);

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

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

        float authorityPrefFactor = 2 * authorityPreferenceValue;

        authorityPrefFactor = Mathf.Pow(authorityPrefFactor, 4);

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

        relationshipFactor = Mathf.Pow(relationshipFactor, 4);

        float diffLimitsAdministrativeLoad = TribeMaxAdministrativeLoad - TribeMinAdministrativeLoad;

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

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

        return(Mathf.Clamp01(chance));
    }
    private string GeneratePreventSplitResultEffectsString_Relationship()
    {
        _dominantClan = _tribe.DominantFaction as Clan;

        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 = BaseMinRelationshipPercentChange * attributesFactor;
        float maxPercentChange = BaseMaxRelationshipPercentChange * attributesFactor;

        float originalValue = _splitClan.GetRelationshipValue(_dominantClan);

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

        return("Clan " + _splitClan.Name.BoldText + ": relationship with clan " + _dominantClan.Name.BoldText + " (" + originalValue.ToString("0.00") + ") increases to: " +
               minValChange.ToString("0.00") + " - " + maxValChange.ToString("0.00"));
    }
    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));
    }