Exemplo n.º 1
0
        /// <summary>
        /// Copies from original list to a new list based on treeindex values, based upon the flag sent.
        /// ie copies entries with 0 to 262144 only or that have 262144 to 'limit', or just all.
        /// </summary>
        /// <param name="orgBurningList">The orginal source list</param>
        /// <param name="bCopyFlag">0= CopyAllEntries; 1= 0 to 262144; 2= 262144 to 'limit'</param>
        /// <returns>a new FastList of treemanager.burningtrees, returns an empty list on none or error.</returns>
        public static FastList <TreeManager.BurningTree> CopyBurningTreesList(ref FastList <TreeManager.BurningTree> orgBurningList, byte bCopyFlag)
        {
            FastList <TreeManager.BurningTree> newlist = new FastList <TreeManager.BurningTree>();

            newlist.Clear();
            try
            {
                if (orgBurningList != null)
                {
                    int orgcount = orgBurningList.m_size;
                    newlist.EnsureCapacity(orgcount);
                    TreeManager.BurningTree tmpTree = new TreeManager.BurningTree();

                    int tmpcounter = 0;
                    int MinValue   = 0;
                    int MaxValue   = 0;
                    if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                    {
                        Logger.dbgLog("CopyFlag = " + bCopyFlag.ToString());
                    }
                    switch (bCopyFlag)
                    {
                    //0-262144 mainserialze()
                    case 1:
                        MinValue = 0;
                        MaxValue = Mod.DEFAULT_TREE_COUNT;
                        break;

                    //262144 to activelimit  customserialze( not packed)
                    case 2:
                        MinValue = Mod.DEFAULT_TREE_COUNT;
                        MaxValue = LimitTreeManager.Helper.TreeLimit;
                        break;

                    //262144 to lastsavecount.count customseralize(packed)???
                    case 3:
                        MinValue = Mod.DEFAULT_TREE_COUNT;
                        MaxValue = LoadingExtension.LastSaveList.Count;
                        break;

                    //just copy all of them.
                    default:
                        MinValue = 0;
                        MaxValue = LimitTreeManager.Helper.TreeLimit;
                        break;
                    }
                    if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                    {
                        Logger.dbgLog(string.Concat("copying from: ", MinValue.ToString(), " to ", MaxValue.ToString()));
                    }

                    if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                    {
                        m_PerfMonitor.Reset(); m_PerfMonitor.Start();
                    }

                    foreach (TreeManager.BurningTree orgTree in orgBurningList)
                    {
                        if (orgTree.m_treeIndex > 0 && (orgTree.m_treeIndex >= MinValue & orgTree.m_treeIndex < MaxValue))
                        {
                            //copy tree
                            tmpTree.m_treeIndex     = orgTree.m_treeIndex;
                            tmpTree.m_fireDamage    = orgTree.m_fireDamage;
                            tmpTree.m_fireIntensity = orgTree.m_fireIntensity;
                            newlist.Add(tmpTree);
                            tmpcounter++;
                        }
                    }
                    newlist.Trim();
                    if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                    {
                        m_PerfMonitor.Stop(); Logger.dbgLog(string.Concat("Copy time took (ticks):", m_PerfMonitor.ElapsedTicks.ToString()));
                    }
                    if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled() && OptionsWrapper <Configuration> .Options.DebugLoggingLevel > 1)
                    {
                        Logger.dbgLog(string.Concat("orgCount(m_size):", orgcount.ToString(), " copycount:", tmpcounter.ToString()) + " new_msize:" + newlist.m_size.ToString());
                    }
                }
                else
                {
                    Logger.dbgLog("orgBurningList is Null!");
                    return(newlist);
                }
            }
            catch (Exception ex)
            { Logger.dbgLog(ex.ToString()); }

            return(newlist);
        }
Exemplo n.º 2
0
        public static bool BurnTree(TreeManager tm, uint treeIndex, InstanceManager.Group group, int fireIntensity)
        {
            unsafe
            {
                //TreeManager tm = Singleton<TreeManager>.instance; see above {this} is passed in bydefault by .net as secret first param.
                TreeManager.BurningTree burningTree = new TreeManager.BurningTree();
                //if (Mod.DEBUG_LOG_ON && Mod.DEBUG_LOG_LEVEL > 1)
                //{ Logger.dbgLog("request to burn tree: " + treeIndex.ToString() ); }
                if (treeIndex == 0 || (tm.m_trees.m_buffer[treeIndex].m_flags & 64) != 0)
                {
                    return(false);
                }
                if (!Singleton <LoadingManager> .instance.SupportsExpansion(Expansion.NaturalDisasters))
                {
                    return(false);
                }
                TreeFireControl_Loader.FireStats.totalburncalls++;
                //our additions
                if (Mod.DEBUG_LOG_ON && Mod.DEBUG_LOG_LEVEL > 2)
                {
                    Logger.dbgLog(string.Format("ratetree:{0} ratedistree:{1} fireIntensity:{2}", Mod.config.TreeFireSpreadRate.ToString(), Mod.config.TreeFireDisasterSpreadRate.ToString(), fireIntensity.ToString()));
                }


                if (group != null)
                {
                    ushort disaster = group.m_ownerInstance.Disaster;
                    if (disaster != 0)
                    {
                        if (Mod.DEBUG_LOG_ON && Mod.DEBUG_LOG_LEVEL > 2)
                        {
                            Logger.dbgLog("burn req is connected to disaster");
                        }
                        TreeFireControl_Loader.FireStats.totalburncallsdisaster++;
                        if (TreeFireControl.TFCTreeManager.Utils.ShouldWeBurnit(ref group, Mod.config.TreeFireDisasterSpreadRate))
                        {
                            //do nothing == burn tree. and count it toward disaster.
                            Singleton <DisasterManager> .instance.m_disasters.m_buffer[disaster].m_treeFireCount = Singleton <DisasterManager> .instance.m_disasters.m_buffer[disaster].m_treeFireCount + 1;
                            //end org
                        }
                        else
                        {
                            //retruned false - block the burn call.
                            TreeFireControl_Loader.FireStats.totalburncallsblockeddisaster++;
                            return(false);
                        }
                    }
                    else //Was not null but not a valid disaster id. handle like normal.
                    {
                        if (Mod.DEBUG_LOG_ON && Mod.DEBUG_LOG_LEVEL > 2)
                        {
                            Logger.dbgLog("burn req is *not* connected to disaster.");
                        }
                        TreeFireControl_Loader.FireStats.totalburncallsnormal++;
                        if (!TreeFireControl.TFCTreeManager.Utils.ShouldWeBurnit(ref group, Mod.config.TreeFireSpreadRate))
                        {
                            TreeFireControl_Loader.FireStats.totalburncallsblockednormal++;
                            return(false); //no burning. //else let it continue and burn the tree
                        }
                    }
                }
                else //not tied to disasters.
                {
                    if (Mod.DEBUG_LOG_ON && Mod.DEBUG_LOG_LEVEL > 2)
                    {
                        Logger.dbgLog("burn req is *not* connected to disaster. group null");
                    }
                    TreeFireControl_Loader.FireStats.totalburncallsnormal++;
                    if (!TreeFireControl.TFCTreeManager.Utils.ShouldWeBurnit(ref group, Mod.config.TreeFireSpreadRate))
                    {
                        TreeFireControl_Loader.FireStats.totalburncallsblockednormal++;
                        return(false); //no burning. //else let it continue
                    }
                    //burnlog;
                }

                //cont org
                burningTree.m_treeIndex     = treeIndex;
                burningTree.m_fireIntensity = (byte)fireIntensity;
                burningTree.m_fireDamage    = 4;
                InstanceID instanceID = new InstanceID()
                {
                    Tree = treeIndex
                };
                Singleton <InstanceManager> .instance.SetGroup(instanceID, group);

                tm.m_trees.m_buffer[treeIndex].m_flags = (ushort)(tm.m_trees.m_buffer[treeIndex].m_flags | 192);
                tm.m_burningTrees.Add(burningTree);
                return(true);
            }
        }