Пример #1
0
        /// <summary>
        /// Unregister platforms from the DistributionManager.
        /// This changes the graph the distributionmanager knows and is only needed for Producing or Defending platforms.
        /// </summary>
        /// <param name="platforms">The platforms you want to unregister.</param>
        /// <param name="isDef">True if they are defending platforms, false if they are producing platforms</param>
        /// /// <param name="inactivate">True if the platform is not truly removed from the graph but inactivated, false if it is removed from the graph</param>
        public void Unregister(List <PlatformBlank> platforms, bool isDef, bool inactivate)
        {
            var list              = isDef ? mDefPlatforms : mProdPlatforms;
            var job               = isDef ? JobType.Defense : JobType.Production;
            var joblist           = isDef ? mDefense : mProduction;
            var unitstodistribute = new List <GeneralUnit>();

            //REMOVE PLATFORMS, COLLECT THEIR UNITS
            foreach (var platform in platforms)
            {
                //No longer observe platform
                Pair <PlatformBlank, int> pair = list.Find(x => x.GetFirst().Equals(platform));
                list.Remove(pair);

                var units = platform.GetAssignedUnits()[job];
                //In this case just collect every unit on the platform and redistribute it (redistribution later in code).
                if (inactivate)
                {
                    foreach (var unitbool in new List <Pair <GeneralUnit, bool> >(units))
                    {
                        unitstodistribute.Add(unitbool.GetFirst());
                        joblist.Remove(unitbool.GetFirst());
                        //Unassigns itself from its platform
                        unitbool.GetFirst().ChangeJob(JobType.Idle);
                    }
                }
                //In this case look if every assigned unit is on the same graph as the platform and handle it
                else
                {
                    var unitbools = new List <Pair <GeneralUnit, bool> >();
                    unitbools.AddRange(units);
                    foreach (var unitbool in unitbools)
                    {
                        //In this case they are on the platform
                        if (unitbool.GetSecond())
                        {
                            //Remove unit from this joblist to no longer influence this unit.
                            joblist.Remove(unitbool.GetFirst());
                        }
                        else
                        {
                            //It will arrive, so just handle it as if it had already arrived at the platform
                            if (unitbool.GetFirst().Graphid == platform.GetGraphIndex())
                            {
                                joblist.Remove(unitbool.GetFirst());
                            }
                            //It will not arrive, so it has to be redistributed!
                            else
                            {
                                unitstodistribute.Add(unitbool.GetFirst());
                                //Unassigns itself from its platform
                                unitbool.GetFirst().ChangeJob(JobType.Idle);
                            }
                        }
                    }

                    // the first in the pair is the id, the second is the TTL
                    // we tell the manager we killed the platform, but we didnt really kill it.
                    mKilled.Add(new Pair <int, int>(platform.Id, Math.Max(mBuildingResources.Count, mRefiningOrStoringResources.Count)));
                }
            }
            //If there are any units to redistribute do it now
            AssignUnitsFairly(unitstodistribute, isDef);

            //TODO: this is a dirty fix and might cause slider adjustment issues (null propagation added)
            mHandler?.ForceSliderPages();
        }