public void Merge(CulturalSkill skill, float percentage)
    {
        // _newvalue should have been set correctly either by the constructor or by the Update function
        float value = _newValue * (1f - percentage) + skill.Value * percentage;

        //		#if DEBUG
        //		if ((Manager.RegisterDebugEvent != null) && (Manager.TracingData.Priority <= 0)) {
        //			if (Group.Id == Manager.TracingData.GroupId) {
        //
        //				string groupId = "Id:" + Group.Id + "|Long:" + Group.Longitude + "|Lat:" + Group.Latitude;
        //
        //				SaveLoadTest.DebugMessage debugMessage = new SaveLoadTest.DebugMessage(
        //					"Merge - Group:" + groupId,
        //					"CurrentDate: " + Group.World.CurrentDate +
        //					", Name: " + Name +
        //					", Value: " + Value +
        //					", source Value: " + skill.Value +
        //					", percentage: " + percentage +
        //					", new value: " + value +
        //					"");
        //
        //				Manager.RegisterDebugEvent ("DebugMessage", debugMessage);
        //			}
        //		}
        //		#endif

        _newValue = value;
    }
    public BiomeSurvivalSkill(CellGroup group, CulturalSkill baseSkill, float initialValue) : base(group, baseSkill.Id, baseSkill.Name, baseSkill.RngOffset, initialValue)
    {
        BiomeId = GetBiomeId(baseSkill.Id);

        Group.AddBiomeSurvivalSkill(this);

        CalculateNeighborhoodBiomePresence();
    }
Exemplo n.º 3
0
    protected void RemoveSkill(CulturalSkill skill)
    {
        if (!_skills.ContainsKey(skill.Id))
        {
            return;
        }

        _skills.Remove(skill.Id);
    }
    protected void AddPolityProminenceEffectInternal(CulturalSkill politySkill, PolityProminence polityProminence, long timeSpan, float timeEffectFactor)
    {
        float targetValue      = politySkill.Value;
        float prominenceEffect = polityProminence.Value;

        TerrainCell groupCell = Group.Cell;

        float randomEffect = groupCell.GetNextLocalRandomFloat(RngOffsets.SKILL_POLITY_PROMINENCE + RngOffset + unchecked ((int)polityProminence.PolityId));

        float timeEffect = timeSpan / (timeSpan + timeEffectFactor);

        // _newvalue should have been set correctly either by the constructor or by the Update function
        float change = (targetValue - _newValue) * prominenceEffect * timeEffect * randomEffect;

//#if DEBUG
//        if (Manager.RegisterDebugEvent != null)
//        {
//            if (Manager.TracingData.Priority <= 0)
//            {
//                if (Group.Id == Manager.TracingData.GroupId)
//                {
//                    string groupId = "Id:" + Group.Id + "|Long:" + Group.Longitude + "|Lat:" + Group.Latitude;

//                    SaveLoadTest.DebugMessage debugMessage = new SaveLoadTest.DebugMessage(
//                        "PolityCulturalProminenceInternal - Group:" + groupId,
//                        "CurrentDate: " + Group.World.CurrentDate +
//                        ", Name: " + Name +
//                        ", timeSpan: " + timeSpan +
//                        ", timeEffectFactor: " + timeEffectFactor +
//                        ", randomEffect: " + randomEffect +
//                        ", polity Id: " + polityProminence.PolityId +
//                        ", polityProminence.Value: " + prominenceEffect +
//                        ", politySkill.Value: " + targetValue +
//                        ", Value: " + Value +
//                        ", change: " + change +
//                        "", Group.World.CurrentDate);

//                    Manager.RegisterDebugEvent("DebugMessage", debugMessage);
//                }
//            }
//            else if (Manager.TracingData.Priority <= 1)
//            {
//                string groupId = "Id:" + Group.Id + "|Long:" + Group.Longitude + "|Lat:" + Group.Latitude;

//                SaveLoadTest.DebugMessage debugMessage = new SaveLoadTest.DebugMessage(
//                    "PolityCulturalProminenceInternal - Group:" + groupId,
//                    "CurrentDate: " + Group.World.CurrentDate +
//                    "", Group.World.CurrentDate);

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

        _newValue = _newValue + change;
    }
Exemplo n.º 5
0
    protected void AddSkill(CulturalSkill skill)
    {
        if (_skills.ContainsKey(skill.Id))
        {
            return;
        }

        World.AddExistingCulturalSkillInfo(skill);

        _skills.Add(skill.Id, skill);
    }
    public void AddSkillToLose(string skillId)
    {
        CulturalSkill skill = null;

        if (!_skills.TryGetValue(skillId, out skill))
        {
            Debug.LogWarning("CellCulture: Trying to remove skill that is not present: " + skillId);

            return;
        }

        _skillsToLose.Add(skill as CellCulturalSkill);
    }
    public static CellCulturalSkill CreateCellInstance(CellGroup group, CulturalSkill baseSkill, float initialValue)
    {
        if (BiomeSurvivalSkill.IsBiomeSurvivalSkill(baseSkill))
        {
            return(new BiomeSurvivalSkill(group, baseSkill, initialValue));
        }

        if (SeafaringSkill.IsSeafaringSkill(baseSkill))
        {
            return(new SeafaringSkill(group, baseSkill, initialValue));
        }

        throw new System.Exception("Unhandled CulturalSkill type: " + baseSkill.Id);
    }
Exemplo n.º 8
0
    public bool TryGetSkillValue(string id, out float value)
    {
        value = 0;

        CulturalSkill skill = GetSkill(id);

        if (skill != null)
        {
            value = skill.Value;

            return(true);
        }

        return(false);
    }
    private void UpdateSkills(CellCulture coreCulture, float timeFactor)
    {
        //Profiler.BeginSample("Culture - Update Skills");

        foreach (CulturalSkill s in coreCulture.GetSkills())
        {
            //Profiler.BeginSample("GetSkill");

            CulturalSkill skill = GetSkill(s.Id);

            //Profiler.EndSample();

            if (skill == null)
            {
                //Profiler.BeginSample("new CulturalSkill");

                skill = new CulturalSkill(s);
                AddSkill(skill);

                skill.Value = s.Value * timeFactor;

                //Profiler.EndSample();
            }
            else
            {
                //Profiler.BeginSample("update skill.Value");

                skill.Value = (skill.Value * (1f - timeFactor)) + (s.Value * timeFactor);

                //Profiler.EndSample();
            }
        }

        foreach (CulturalSkill s in _skills.Values)
        {
            //Profiler.BeginSample("coreCulture.Skills.ContainsKey");

            if (coreCulture.GetSkill(s.Id) == null)
            {
                s.Value = s.Value * (1f - timeFactor);
            }

            //Profiler.EndSample();
        }

        //Profiler.EndSample();
    }
Exemplo n.º 10
0
 public static bool IsSeafaringSkill(CulturalSkill skill)
 {
     return(IsSeafaringSkill(skill.Id));
 }
Exemplo n.º 11
0
 public SeafaringSkill(CellGroup group, CulturalSkill baseSkill, float initialValue) : base(group, baseSkill.Id, baseSkill.Name, baseSkill.RngOffset, initialValue)
 {
     CalculateNeighborhoodWaterPresence();
 }
 public override void AddPolityProminenceEffect(CulturalSkill politySkill, PolityProminence polityProminence, long timeSpan)
 {
     AddPolityProminenceEffectInternal(politySkill, polityProminence, timeSpan, TimeEffectConstant);
 }
Exemplo n.º 13
0
 public CulturalSkill(CulturalSkill baseSkill) : base(baseSkill)
 {
     Value = baseSkill.Value;
 }
 public BiomeSurvivalSkill(CellGroup group, CulturalSkill baseSkill) : this(group, baseSkill, baseSkill.Value)
 {
 }
 public static bool IsBiomeSurvivalSkill(CulturalSkill skill)
 {
     return(IsBiomeSurvivalSkill(skill.Id));
 }
 public static CellCulturalSkill CreateCellInstance(CellGroup group, CulturalSkill baseSkill)
 {
     return(CreateCellInstance(group, baseSkill, baseSkill.Value));
 }
Exemplo n.º 17
0
    private void AddFactionCulture(Faction faction)
    {
        float influence = faction.Influence;

        //Profiler.BeginSample("foreach CulturalPreference");

        foreach (CulturalPreference p in faction.Culture.GetPreferences())
        {
            //Profiler.BeginSample("GetPreference");

            CulturalPreference preference = GetPreference(p.Id);

            //Profiler.EndSample();

            if (preference == null)
            {
                //Profiler.BeginSample("AddPreference");

                preference        = new CulturalPreference(p);
                preference.Value *= influence;

                AddPreference(preference);

                //Profiler.EndSample();
            }
            else
            {
                //Profiler.BeginSample("update preference value");

                preference.Value += p.Value * influence;

                //Profiler.EndSample();
            }
        }

        //Profiler.EndSample();

        //Profiler.BeginSample("foreach CulturalActivity");

        foreach (CulturalActivity a in faction.Culture.GetActivities())
        {
            //Profiler.BeginSample("GetActivity");

            CulturalActivity activity = GetActivity(a.Id);

            //Profiler.EndSample();

            if (activity == null)
            {
                //Profiler.BeginSample("AddActivity");

                activity               = new CulturalActivity(a);
                activity.Value        *= influence;
                activity.Contribution *= influence;

                AddActivity(activity);

                //Profiler.EndSample();
            }
            else
            {
                //Profiler.BeginSample("update activity value");

                activity.Value        += a.Value * influence;
                activity.Contribution += a.Contribution * influence;

                //Profiler.EndSample();
            }
        }

        //Profiler.EndSample();

        //Profiler.BeginSample("foreach CulturalSkill");

        foreach (CulturalSkill s in faction.Culture.GetSkills())
        {
            //Profiler.BeginSample("GetSkill");

            CulturalSkill skill = GetSkill(s.Id);

            //Profiler.EndSample();

            if (skill == null)
            {
                //Profiler.BeginSample("AddSkill");

                skill        = new CulturalSkill(s);
                skill.Value *= influence;

                AddSkill(skill);

                //Profiler.EndSample();
            }
            else
            {
                //Profiler.BeginSample("update skill value");

                skill.Value += s.Value * influence;

                //Profiler.EndSample();
            }
        }

        //Profiler.EndSample();

        //Profiler.BeginSample("foreach CulturalKnowledge");

        foreach (CulturalKnowledge k in faction.Culture.GetKnowledges())
        {
            //Profiler.BeginSample("GetKnowledge");

            PolityCulturalKnowledge knowledge = GetKnowledge(k.Id) as PolityCulturalKnowledge;

            //Profiler.EndSample();

            if (knowledge == null)
            {
                //Profiler.BeginSample("AddKnowledge");

                knowledge           = new PolityCulturalKnowledge(k);
                knowledge.AccValue += k.Value * influence;

                AddKnowledge(knowledge);

                //Profiler.EndSample();
            }
            else
            {
                //Profiler.BeginSample("update knowledge value");

                knowledge.AccValue += k.Value * influence;

                //Profiler.EndSample();
            }
        }

        //Profiler.EndSample();

        //Profiler.BeginSample("foreach CulturalDiscovery");

        foreach (Discovery d in faction.Culture.Discoveries.Values)
        {
            AddDiscovery(d);
        }

        //Profiler.EndSample();
    }
 public abstract void AddPolityProminenceEffect(CulturalSkill politySkill, PolityProminence polityProminence, long timeSpan);