Esempio n. 1
0
    public static void LeaderPreventsSplit(Clan clan)
    {
        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);

        int rngOffset = RngOffsets.CLAN_SPLITTING_EVENT_LEADER_PREVENTS_MODIFY_ATTRIBUTE;

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

        authorityPreferencePercentChange /= attributesFactor;

        randomFactor = clan.GetNextLocalRandomFloat(rngOffset++);
        float cohesionPreferencePercentChange = (BaseMaxPreferencePercentChange - BaseMinPreferencePercentChange) * randomFactor + BaseMinPreferencePercentChange;

        cohesionPreferencePercentChange *= attributesFactor;

        clan.DecreasePreferenceValue(CulturalPreference.AuthorityPreferenceId, authorityPreferencePercentChange);
        clan.IncreasePreferenceValue(CulturalPreference.CohesionPreferenceId, cohesionPreferencePercentChange);

        clan.SetToUpdate();

        // Should reduce respect for authority and increase cohesion
        clan.Polity.AddEventMessage(new PreventClanSplitEventMessage(clan, clan.CurrentLeader, clan.World.CurrentDate));
    }
Esempio n. 2
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 override void Trigger()
    {
        bool splitClanPreferSplit = _splitClan.GetNextLocalRandomFloat(RngOffsets.TRIBE_SPLITTING_EVENT_SPLITCLAN_PREFER_SPLIT) < _splitClanChanceOfSplitting;

        if (_originalTribe.IsUnderPlayerFocus || _splitClan.IsUnderPlayerGuidance)
        {
            Decision splitClanDecision;

            if (_splitClanChanceOfSplitting >= 1)
            {
                splitClanDecision = new ClanTribeSplitDecision(_originalTribe, _splitClan, _dominantClan, _tribeChanceOfSplitting, Id); // Player that controls split clan can't prevent splitting from happening
            }
            else
            {
                splitClanDecision = new ClanTribeSplitDecision(_originalTribe, _splitClan, _dominantClan, splitClanPreferSplit, _tribeChanceOfSplitting, Id); // Give player options
            }

            if (_splitClan.IsUnderPlayerGuidance)
            {
                World.AddDecisionToResolve(splitClanDecision);
            }
            else
            {
                splitClanDecision.ExecutePreferredOption();
            }
        }
        else if (splitClanPreferSplit)
        {
            ClanTribeSplitDecision.LeaderAllowsSplit(_splitClan, _dominantClan, _originalTribe, _tribeChanceOfSplitting, Id);
        }
        else
        {
            ClanTribeSplitDecision.LeaderPreventsSplit(_splitClan, _dominantClan, _originalTribe);
        }
    }
    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 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);
    }
Esempio n. 6
0
    public static long CalculateTriggerDate(Clan clan)
    {
        float randomFactor = clan.GetNextLocalRandomFloat(RngOffsets.CLAN_CORE_MIGRATION_EVENT_CALCULATE_TRIGGER_DATE);

        randomFactor = Mathf.Pow(randomFactor, 2);

        float dateSpan = (1 - randomFactor) * DateSpanFactorConstant;

        long triggerDate = (long)(clan.World.CurrentDate + dateSpan) + CellGroup.GenerationSpan;

        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 override void Trigger()
    {
//#if DEBUG
//        if ((Id == 160349336613603015L) || (Id == 160349354613603010L))
//        {
//            Debug.LogWarning("Event Id: " + Id + " has been triggered, current date: " + World.CurrentDate + ", loaded world: " + Manager.Debug_IsLoadedWorld);
//        }
//#endif

        bool performDemand = _demandClan.GetNextLocalRandomFloat(RngOffsets.CLAN_DEMANDS_INFLUENCE_EVENT_PERFORM_DEMAND) < _chanceOfMakingDemand;

        Tribe tribe = _demandClan.Polity as Tribe;

        if (tribe.IsUnderPlayerFocus || _demandClan.IsUnderPlayerGuidance)
        {
            Decision demandDecision;

            demandDecision = new ClanDemandsInfluenceDecision(tribe, _demandClan, _dominantClan, performDemand, _chanceOfRejectingDemand, Id);

            if (_demandClan.IsUnderPlayerGuidance)
            {
                World.AddDecisionToResolve(demandDecision);
            }
            else
            {
                demandDecision.ExecutePreferredOption();
            }
        }
        else if (performDemand)
        {
            ClanDemandsInfluenceDecision.LeaderDemandsInfluence(_demandClan, _dominantClan, tribe, _chanceOfRejectingDemand, Id);
        }
        else
        {
            ClanDemandsInfluenceDecision.LeaderAvoidsDemandingInfluence(_demandClan, _dominantClan, tribe);
        }
    }
    public override void Trigger()
    {
        _clan.CoreGroup.SetToUpdate();

        bool preferSplit = _clan.GetNextLocalRandomFloat(RngOffsets.CLAN_SPLITTING_EVENT_PREFER_SPLIT) < _chanceOfSplitting;

        if (_clan.Polity.IsUnderPlayerFocus || _clan.IsUnderPlayerGuidance)
        {
            Decision splitDecision;

            if (_chanceOfSplitting >= 1)
            {
                splitDecision = new ClanSplitDecision(_clan, _newClanCoreGroup, Id); // Player can't prevent splitting from happening
            }
            else
            {
                splitDecision = new ClanSplitDecision(_clan, _newClanCoreGroup, preferSplit, Id); // Give player options
            }

            if (_clan.IsUnderPlayerGuidance)
            {
                World.AddDecisionToResolve(splitDecision);
            }
            else
            {
                splitDecision.ExecutePreferredOption();
            }
        }
        else if (preferSplit)
        {
            ClanSplitDecision.LeaderAllowsSplit(_clan, _newClanCoreGroup, Id);
        }
        else
        {
            ClanSplitDecision.LeaderPreventsSplit(_clan);
        }
    }
    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);
    }