Ejemplo n.º 1
0
    /// <summary>
    /// Parsing recipe formula.
    /// It has format:
    /// (([\w]{1,20}([*][\d]{0,3}){0,1})([|]([\w]{1,20}[*][\d]{0,3})){0,};){1,}
    /// itemName*count | itemName; itemName
    /// </summary>
    /// <param name="dependencyStr">recipe</param>
    /// <returns> parced recipe </returns>
    public static DependencyCount[] ParseDependencyCounts(string dependencyStr)
    {
        string[]          dependency      = dependencyStr.Split(';');
        DependencyCount[] dependencyCount = new DependencyCount[dependency.Length];

        for (int i = 0; i < dependency.Length; i++)
        {
            string[] conditions = dependency[i].Split('|');
            for (int condI = 0; condI < conditions.Length; condI++)
            {
                string   str   = conditions[condI];
                float    count = 1;
                string[] cnt   = str.Split('*');

                if (cnt.Length > 1)
                {
                    try
                    {
                        count = FloatParse(cnt[1]);
                        str   = cnt[0];
                    }
                    catch (Exception ex)
                    {
                        Debug.Log("Object float parsing error:" + dependency[i] + " " + ex.Message);
                        return(null);
                    }
                }

                try
                {
                    while (str.Length > 1 && str[0] == ' ')
                    {
                        str = str.Substring(1);
                    }
                }catch (Exception ex)
                {
                    Debug.Log("Object splitting substrings error:" + dependency[i] + " " + ex.Message);
                    return(null);
                }

                foreach (AbstractObject dependMat in m_sEverything)
                {
                    if (dependMat.m_name == str)
                    {
                        if (dependencyCount[i] == null)
                        {
                            dependencyCount[i] = new DependencyCount();
                        }

                        dependencyCount[i].m_dependency.Add(dependMat);
                        dependencyCount[i].m_value.Add(count);
                        break;
                    }
                }
            }
        }

        return(dependencyCount);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Open item at startup.
    /// Here: getting buildings for living and happy tools for furver using
    /// Could be called only in Start/Load game
    /// </summary>
    public override void OpenItem()
    {
        for (int i = 0; i < 30; i++)
        {
            m_starved.Enqueue(-m_people.PeopleNumber);
        }

        m_isItIterable = false;
        m_tools        = new List <ItemsEffect>();

        m_dependencyCount    = new DependencyCount[1];
        m_dependencyCount[0] = new DependencyCount();
        m_dependencyCount[0].m_dependency = new List <AbstractObject>();
        foreach (var food in Productions.GetProductions("food"))
        {
            m_dependencyCount[0].m_dependency.Add(food as GameMaterial);
        }

        foreach (var building in Productions.GetTools("living"))
        {
            m_livingPlaces.Add(new ItemsEffect(building));
        }

        m_livingPlaces.Sort((ItemsEffect pair1, ItemsEffect pair2) =>
        {
            Buildings bld1 = pair1.m_toolLink as Buildings;
            Buildings bld2 = pair2.m_toolLink as Buildings;
            return((int)(bld1.m_happyEffect.m_value - bld2.m_happyEffect.m_value));
        });
        Productions.AddProduction(this, "happy");

        m_people = Camera.main.GetComponent <People>();
        while (m_people.GetWorker())
        {
            ((GameMaterial)(m_dependencyCount[0].m_dependency[0])).m_workers++;
        }
    }