Exemplo n.º 1
0
 void SetFields(ResourceIndustryDistrictLineRow uic, DistrictResourceData index, bool totals)
 {
     uic.Oil        = totals ? index.Oil : index.GetPrecentage(index.Oil);
     uic.Farming    = totals ? index.Farming : index.GetPrecentage(index.Farming);
     uic.Ore        = totals ? index.Ore : index.GetPrecentage(index.Ore);
     uic.Forest     = totals ? index.Forest : index.GetPrecentage(index.Forest);
     uic.Name       = index.Name;
     uic.Size       = index.Size;
     uic.Type       = index.Type;
     uic.totals     = totals;
     uic.OilDecline = index.OilDecline;
     uic.OreDecline = index.OreDecline;
 }
Exemplo n.º 2
0
        static public void Calculate2()
        {
            List <DistrictResourceData> latestDistrictResourceList = new List <DistrictResourceData>();

            NaturalResourceManager.ResourceCell[] resourcesFromMap = getResource();
            DistrictManager.Cell[] districts = getDistricts();

            for (int i = 0; i < resourcesFromMap.Length; i++)
            {
                int oreFromMap     = resourcesFromMap[i].m_ore;
                int oilFromMap     = resourcesFromMap[i].m_oil;
                int forestFromMap  = resourcesFromMap[i].m_forest;
                int farmingFromMap = resourcesFromMap[i].m_fertility;
                if (oreFromMap + oilFromMap + forestFromMap + farmingFromMap != 0)
                {
                    int districtIndex = GetDistrictIndex(i);
                    if (districtIndex == -1)
                    {
                        // this resource cannot be in a district
                        continue;
                    }
                    DistrictManager.Cell cell = districts[districtIndex];
                    int    districtId         = GetMatchingDistrictId(cell);
                    string districtName       = GetDistrictName(districtId);
                    if (districtName != null)
                    {
                        DistrictResourceData result = latestDistrictResourceList.Find(x => x.Name.Contains(districtName));
                        if (result == null)
                        {
                            // need to add this distric
                            District district     = (District)getDistrictNames().m_buffer.GetValue(districtId);
                            int      districtType = (int)district.m_specializationPolicies;
                            latestDistrictResourceList.Add(new DistrictResourceData()
                            {
                                Name = districtName, Type = districtType
                            });
                            result = latestDistrictResourceList[latestDistrictResourceList.Count - 1];
                        }
                        // add the resources
                        result.Ore     += oreFromMap;
                        result.Oil     += oilFromMap;
                        result.Forest  += forestFromMap;
                        result.Farming += farmingFromMap;

                        result.Size++;
                    }
                }
            }

            for (int i = 0; i < districts.Length; i++)
            {
                DistrictManager.Cell cell = districts[i];
                int    districtId         = GetMatchingDistrictId(cell);
                string districtName       = GetDistrictName(districtId);
                if (districtName != null)
                {
                    DistrictResourceData result = latestDistrictResourceList.Find(x => x.Name.Contains(districtName));
                    if (result == null)
                    {
                        District district     = (District)getDistrictNames().m_buffer.GetValue(districtId);
                        int      districtType = (int)district.m_specializationPolicies;
                        latestDistrictResourceList.Add(new DistrictResourceData()
                        {
                            Name = districtName, Type = districtType
                        });
                        result = latestDistrictResourceList[latestDistrictResourceList.Count - 1];
                    }
                }
            }

            // now check for decline
            foreach (DistrictResourceData d in latestDistrictResourceList)
            {
                var oldData = districtResourceList.Find(f => f.Name == d.Name);
                if (oldData != null)
                {
                    if (oldData.Oil > d.Oil && d.GetPrecentage(d.Oil) < 0.05)
                    {
                        d.OilDecline = true;
                    }
                    if (oldData.Ore > d.Ore && d.GetPrecentage(d.Ore) < 0.05)
                    {
                        d.OreDecline = true;
                    }
                }
            }
            districtResourceList = latestDistrictResourceList;
        }