Ejemplo n.º 1
0
        // Use this for initialization
        public void SetupChunk()
        {
            SetupChunkBorder();
            firstCreate = false;
            if (Ground[0] == null)
            {
                firstCreate = true;
                if (ChunkManager.CurrentChunk == null)
                {
                    // var rand = Random.value;
                    //  Debug.Log("Random = " + rand);
                    var seed = Random.Range(int.MinValue, int.MaxValue);
                    // var n = (int) (Util.GetCountAfterPoint(rand) * rand);
                    Random.InitState(seed);
                }

                var mapZeroGround = map.ZeroGround;

                for (int z = 0; z < ChunkManager.MaxGroundsLvls; z++)
                {
                    Ground[z]   = new GameEntity[MapSize][];
                    IndexMas[z] = new int[MapSize][];
                    for (int i = 0; i < MapSize; i++)
                    {
                        Ground[z][i]   = new GameEntity[MapSize];
                        IndexMas[z][i] = new int[MapSize];
                        for (int j = 0; j < MapSize; j++)
                        {
                            if (z == 0 && mapZeroGround.Count != 0)
                            {
                                var nGround = map.ZeroGround[0].Value;
                                foreach (var kv in map.ZeroGround)
                                {
                                    if (!(Random.value <= kv.Key))
                                    {
                                        continue;
                                    }
                                    nGround = kv.Value;
                                    break;
                                }

                                IndexMas[z][i][j] = Loader.GetIndexByName(nGround);
                            }
                            else
                            {
                                IndexMas[z][i][j] = 0;
                            }
                        }
                    }
                }

                //PreSetup Ground
                if (ChunkManager.staticFillMap)
                {
                    for (int z = 1; z < ChunkManager.MaxGroundsLvls - 1; z++)
                    {
                        IndexMas[z] = ChunkUtil.GenerateCellularAutomata(
                            MapSize, MapSize, 1, 90, true, map);
                        //IndexMas[z] = ChunkUtil.SmoothVNCellularAutomata(IndexMas[z], false, 2, map);
                    }
                }

                /*
                 * //PreSetuping indexes
                 * for (int z = 1; z < ChunkManager.MaxGroundsLvls; z++)
                 * {
                 *  _markList.Clear();
                 *  // IndexMas[z] = Randomize(IndexMas[z], rand / z, Interval);
                 *  // IndexMas[z] = AddingStairs(IndexMas[z], map);
                 *  //IndexMas[z] = AddingTreesInMapIndex(IndexMas[z], map);
                 *  if (z == ChunkManager.MaxGroundsLvls - 1) break;
                 *  IndexMas[z + 1] = MarkGroundUpper(IndexMas[z], IndexMas[z + 1]);
                 *  foreach (Vector2Int vec in _markList)
                 *  {
                 *      IndexMas[z + 1][vec.x][vec.y] = -1;
                 *  }
                 * }
                 */
            }


            SetUpTiles(IndexMas);
            if (firstCreate)
            {
                SetupMapAdditionals();

                if (ChunkManager.StaticSpEnemies)
                {
                    SetUpEnemies(map);
                }
            }

/*
 *
 *          var creatures = CreatureGroupManager.GetAllInChunk(ChunkNumber);
 *          foreach (var unit in creatures)
 *          {
 *              var pos = unit.CurrentPos;
 *              IndexMas[pos.z][pos.x][pos.y] = unit.PrefabIndex;
 *              Ground[pos.z][pos.x][pos.y] = unit;
 *              unit.Enable();
 *          }
 *
 *
 *
 *
 *          var chunkGround = SecondaryGroundLvL.GetChunkGround(ChunkNumber).ToArray();
 *
 *
 *          foreach (var KV in chunkGround)
 *          {
 *              var item = KV.Value;
 *              SetupItem(item.OriginalName, item.CurrentPos, item.Owner);
 *              //Destroy prev item must be
 *          }
 *
 *          SetupTeleported();
 *
 *
 *
 *
 *          Coloring.RecolorAll();
 *
 *          ItemGroup.PreInit();
 *
 */
            //PathCalcManager.CalculatePathGroups();
            Debug.LogFormat("Preloaded in: {0} sec", Time.realtimeSinceStartup.ToString("F5"));
        }