public void ApplyUndo()
        {
            if (this.m_undoList.Count < 1)
            {
                return;
            }
            InGameTerrainTool.UndoStroke undoStroke = this.m_undoList[this.m_undoList.Count - 1];
            this.m_undoList.RemoveAt(this.m_undoList.Count - 1);
            ushort[] undoBuffer    = Singleton <TerrainManager> .instance.UndoBuffer;
            ushort[] backupHeights = Singleton <TerrainManager> .instance.BackupHeights;
            ushort[] rawHeights    = Singleton <TerrainManager> .instance.RawHeights;
            int      num           = Singleton <TerrainManager> .instance.UndoBuffer.Length;
            int      num2          = Singleton <TerrainManager> .instance.RawHeights.Length;
            int      num3          = undoStroke.pointer;

            for (int i = undoStroke.zmin; i <= undoStroke.zmax; i++)
            {
                for (int j = undoStroke.xmin; j <= undoStroke.xmax; j++)
                {
                    int num4 = i * 1081 + j;
                    rawHeights[num4]    = undoBuffer[num3];
                    backupHeights[num4] = undoBuffer[num3];
                    num3++;
                    num3 %= num;
                }
            }
            this.m_undoBufferFreePointer = undoStroke.pointer;
            for (int k = 0; k < num2; k++)
            {
                backupHeights[k] = rawHeights[k];
            }
            int num5 = 128;

            undoStroke.xmin = Math.Max(0, undoStroke.xmin - 2);
            undoStroke.xmax = Math.Min(1080, undoStroke.xmax + 2);
            undoStroke.zmin = Math.Max(0, undoStroke.zmin - 2);
            undoStroke.zmax = Math.Min(1080, undoStroke.zmax + 2);
            for (int l = undoStroke.zmin; l <= undoStroke.zmax; l += num5 + 1)
            {
                for (int m = undoStroke.xmin; m <= undoStroke.xmax; m += num5 + 1)
                {
                    TerrainModify.UpdateArea(m, l, m + num5, l + num5, true, false, false);
                }
            }
            this.m_strokeXmin = 1080;
            this.m_strokeXmax = 0;
            this.m_strokeZmin = 1080;
            this.m_strokeZmax = 0;
            int cost = undoStroke.total_cost * m_costMultiplier;

            Singleton <EconomyManager> .instance.FetchResource(EconomyManager.Resource.Construction, -cost, ItemClass.Service.None,
                                                               ItemClass.SubService.None,
                                                               ItemClass.Level.None);
        }
Beispiel #2
0
        private void EndStroke()
        {
            int num  = Singleton <TerrainManager> .instance.UndoBuffer.Length;
            int num2 = Math.Max(0, 1 + this.m_strokeXmax - this.m_strokeXmin) * Math.Max(0, 1 + this.m_strokeZmax - this.m_strokeZmin);

            if (num2 < 1)
            {
                return;
            }
            int num3 = 0;

            while (this.GetFreeUndoSpace() < num2 && num3 < 10000)
            {
                this.m_undoList.RemoveAt(0);
                num3++;
            }
            if (num3 >= 10000)
            {
                Debug.Log("InGameTerrainTool:EndStroke: unexpectedly terminated freeing loop, might be a bug.");
                return;
            }
            InGameTerrainTool.UndoStroke item = default(InGameTerrainTool.UndoStroke);
            item.xmin       = this.m_strokeXmin;
            item.xmax       = this.m_strokeXmax;
            item.zmin       = this.m_strokeZmin;
            item.zmax       = this.m_strokeZmax;
            item.total_cost = (int)m_totalCost;
            item.pointer    = this.m_undoBufferFreePointer;
            this.m_undoList.Add(item);
            ushort[] undoBuffer    = Singleton <TerrainManager> .instance.UndoBuffer;
            ushort[] backupHeights = Singleton <TerrainManager> .instance.BackupHeights;
            ushort[] rawHeights    = Singleton <TerrainManager> .instance.RawHeights;
            for (int i = this.m_strokeZmin; i <= this.m_strokeZmax; i++)
            {
                for (int j = this.m_strokeXmin; j <= this.m_strokeXmax; j++)
                {
                    int num4 = i * 1081 + j;
                    undoBuffer[this.m_undoBufferFreePointer++] = backupHeights[num4];
                    backupHeights[num4]           = rawHeights[num4];
                    this.m_undoBufferFreePointer %= num;
                }
            }
            this.m_strokeXmin = 1080;
            this.m_strokeXmax = 0;
            this.m_strokeZmin = 1080;
            this.m_strokeZmax = 0;
            this.m_totalCost  = 0;
        }