Beispiel #1
0
    public void SaveBiome()
    {
        BiomeController bc = biomeManager.GetBiome(Vector3Int.zero);

        if (bc == null)
        {
            return;
        }

        string path = Path.Combine(Application.dataPath, "Resources/Biomes/" + inputField.text + ".bytes");

        using (
            BinaryWriter writer = new BinaryWriter(File.Open(path, FileMode.Create))
            )
        {
            bc.Save(writer, true);
        }
    }
        public void OnConstructedChanged(bool constructed)
        {
            QuickLogger.Debug($"Constructed - {constructed}");

            if (IsBeingDeleted)
            {
                return;
            }

            if (constructed)
            {
                _seaBase = gameObject?.transform?.parent?.gameObject;

                if (isActiveAndEnabled)
                {
                    if (IsOperational())
                    {
                        if (!IsInitialized)
                        {
                            Initialize();
                        }

                        if (_display != null)
                        {
                            _display.Setup(this);
                            _runStartUpOnEnable = false;
                        }

                        _currentBiome = BiomeManager.GetBiome();
                        RotateToMag();
                        SetCurrentRotation();
                        QuickLogger.Debug($"Turbine Constructed Rotation Set {_rotor.transform.rotation.ToString()} ", true);
                    }
                    else
                    {
                        QuickLogger.Message(DisplayLanguagePatching.NotOperational(), true);
                    }
                }
                else
                {
                    _runStartUpOnEnable = true;
                }
            }
        }
Beispiel #3
0
    public void Generate(Action callback, NoiseData inNoiseData, World.WorldGenData inWorldGenData, ChunkGenerator inChunkGenerator)
    {
        int textureSize = inWorldGenData.chunkSize;

        float[,] heightMap = inNoiseData.heightMap.noise;
        float[,] humidMap  = inNoiseData.humidMap.noise;
        BiomeManager biomeManager = inChunkGenerator.biomeManager;

        // Calculate colormap
        _colorMap = new Color[textureSize * textureSize];
        for (int y = 0; y < textureSize; y++)
        {
            for (int x = 0; x < textureSize; x++)
            {
                _colorMap[y * textureSize + x] = biomeManager.GetBiome(heightMap[x, y], humidMap[x, y]).color;
            }
        }

        lock (inChunkGenerator.textureDataThreadInfoQueue)
            inChunkGenerator.textureDataThreadInfoQueue.Enqueue(callback);
    }
        public override void OnConstructedChanged(bool constructed)
        {
            QuickLogger.Info("In Constructed Changed");

            IsConstructed = constructed;

            if (constructed)
            {
                if (isActiveAndEnabled)
                {
                    if (!IsInitialized)
                    {
                        Initialize();
                    }

                    CurrentBiome = BiomeManager.GetBiome();
                    StartCoroutine(TryGetLoot());
                }
                else
                {
                    _runStartUpOnEnable = true;
                }
            }
        }
        public override void OnConstructedChanged(bool constructed)
        {
            QuickLogger.Info("In Constructed Changed");

            IsConstructed = constructed;

            if (constructed)
            {
                var seaBase = gameObject?.transform?.parent?.gameObject;

                if (seaBase != null)
                {
                    QuickLogger.Debug($"Base Name: {seaBase.name}", true);
                    if (seaBase.name.StartsWith("Base", StringComparison.OrdinalIgnoreCase))
                    {
                        QuickLogger.Debug("Is a base");
                        _invalidPlacement = true;
                    }
                }

                if (isActiveAndEnabled)
                {
                    if (!IsInitialized)
                    {
                        Initialize();
                    }

                    CurrentBiome = BiomeManager.GetBiome();
                    StartCoroutine(TryGetLoot());
                }
                else
                {
                    _runStartUpOnEnable = true;
                }
            }
        }
Beispiel #6
0
        private void PopulateChunk(ChunkColumn chunk)
        {
            var bottom   = new SimplexOctaveGenerator(ServerSettings.Seed.GetHashCode(), 8);
            var overhang = new SimplexOctaveGenerator(ServerSettings.Seed.GetHashCode(), 8);

            overhang.SetScale(1 / OverhangScale);
            bottom.SetScale(1 / Groundscale);


            for (var x = 0; x < 16; x++)
            {
                for (var z = 0; z < 16; z++)
                {
                    float ox = x + chunk.X * 16;
                    float oz = z + chunk.Z * 16;

                    var cBiome = _biomeManager.GetBiome((int)ox, (int)oz);
                    chunk.BiomeId[x * 16 + z] = cBiome.MinecraftBiomeId;

                    var bottomHeight =
                        (int)
                        ((bottom.Noise(ox, oz, BottomsFrequency, BottomsAmplitude) * BottomsMagnitude) + BottomOffset + cBiome.BaseHeight);

                    var maxHeight =
                        (int)
                        ((overhang.Noise(ox, oz, OverhangFrequency, OverhangAmplitude) * OverhangsMagnitude) + bottomHeight +
                         OverhangOffset);
                    maxHeight = Math.Max(1, maxHeight);

                    for (var y = 0; y < maxHeight && y < 256; y++)
                    {
                        if (y == 0)
                        {
                            chunk.SetBlock(x, y, z, BlockFactory.GetBlockById(7));
                            continue;
                        }

                        if (y > bottomHeight)
                        {
                            //part where we do the overhangs
                            if (EnableOverhang)
                            {
                                var density = overhang.Noise(ox, y, oz, OverhangFrequency, OverhangAmplitude);
                                if (density > Threshold)
                                {
                                    chunk.SetBlock(x, y, z, BlockFactory.GetBlockById(1));
                                }
                            }
                        }
                        else
                        {
                            chunk.SetBlock(x, y, z, BlockFactory.GetBlockById(1));
                        }
                    }

                    //Turn the blocks ontop into the correct material
                    for (var y = 0; y < 256; y++)
                    {
                        if (chunk.GetBlock(x, y + 1, z) == 0 && chunk.GetBlock(x, y, z) == 1)
                        {
                            chunk.SetBlock(x, y, z, cBiome.TopBlock);

                            chunk.SetBlock(x, y - 1, z, cBiome.Filling);
                            chunk.SetBlock(x, y - 2, z, cBiome.Filling);
                        }
                    }

                    foreach (var decorator in cBiome.Decorators)
                    {
                        decorator.Decorate(chunk, cBiome, x, z);
                    }
                    new OreDecorator().Decorate(chunk, cBiome, x, z);                     //Ores :)
                    new BedrockDecorator().Decorate(chunk, cBiome, x, z);                 //Random bedrock :)
                }
            }

            new WaterDecorator().Decorate(chunk, new PlainsBiome());             //For now, ALWAYS use the water decorator on all chunks...
            _cavegen.GenerateCave(chunk);
            new LavaDecorator().Decorate(chunk, new PlainsBiome());
        }
        private void OnEnable()
        {
            if (!_runStartUpOnEnable)
            {
                return;
            }

            if (!IsInitialized)
            {
                Initialize();
            }

            if (_display != null)
            {
                _display.Setup(this);
            }

            if (_seaBase != null)
            {
                _currentBiome = BiomeManager.GetBiome();
                RotateToMag();
                SetCurrentRotation();
                QuickLogger.Debug($"World Rotation {AISolutionsData.StartingRotation} ", true);

                QuickLogger.Debug($"Turbine Constructed Rotation Set {_rotor.transform.rotation.ToString()} ", true);
            }

            if (_data == null)
            {
                ReadySaveData();
            }

            if (_data != null)
            {
                QuickLogger.Debug("// ****************************** Load Data *********************************** //");

                if (_prefabID != null)
                {
                    QuickLogger.Info($"Loading JetStream {_prefabID.Id}");

                    PowerManager.SetHasBreakerTripped(_data.HasBreakerTripped);
                    HealthManager.SetHealth(_data.Health);
                    PowerManager.SetCharge(_data.Charge);
                    _currentSpeed = _data.CurrentSpeed;
                    //RotateTurbine(savedData.DegPerSec);
                    _targetRotation = _data.TurbineRot.TargetRotationToQuaternion();
                    QuickLogger.Debug($"Target Rotation Set {_targetRotation}", true);
                    _currentBiome = _data.Biome;
                    HealthManager.SetPassedTime(_data.PassedTime);
                    AISolutionsData.StartingRotation = _targetRotation;
                    PowerManager.SetStoredPower(_data.StoredPower);
                    if (_display != null)
                    {
                        _display.SetCurrentPage();
                    }
                }
                else
                {
                    QuickLogger.Error("PrefabIdentifier is null");
                }
                QuickLogger.Debug("// ****************************** Loaded Data *********************************** //");
            }

            _runStartUpOnEnable = false;
        }
        private void Initialize()
        {
            _buildable = GetComponent <Constructable>() ?? GetComponentInParent <Constructable>();

            if (FindComponents())
            {
                QuickLogger.Debug($"Turbine Components Found", true);

                _prefabID = GetComponentInParent <PrefabIdentifier>();

                var currentBiome = BiomeManager.GetBiome();

                if (!string.IsNullOrEmpty(currentBiome))
                {
                    var data = BiomeManager.GetBiomeData(currentBiome);
                }

                AISolutionsData.Instance.OnRotationChanged += AiSolutionsDataOnOnRotationChanged;

                if (HealthManager == null)
                {
                    HealthManager = gameObject.GetComponent <AIJetStreamT242HealthManager>() ?? GetComponentInParent <AIJetStreamT242HealthManager>();
                }


                HealthManager.Initialize(this);
                HealthManager.SetHealth(100);
                HealthManager.SetDamageModel(_damage);

                if (PowerManager == null)
                {
                    PowerManager          = GetComponentInParent <AIJetStreamT242PowerManager>() ?? GetComponent <AIJetStreamT242PowerManager>();
                    PowerManager.maxPower = 300;
                }



                if (PowerRelay == null)
                {
                    PowerRelay = gameObject.AddComponent <PowerRelay>();

                    PowerRelay.internalPowerSource = PowerManager;
                    PowerRelay.maxOutboundDistance = 15;
                    PowerRelay.dontConnectToRelays = false;


                    PowerFX    yourPowerFX = gameObject.AddComponent <PowerFX>();
                    PowerRelay powerRelay  = CraftData.GetPrefabForTechType(TechType.SolarPanel).GetComponent <PowerRelay>();

                    yourPowerFX.vfxPrefab   = powerRelay.powerFX.vfxPrefab;
                    yourPowerFX.attachPoint = gameObject.transform;
                    PowerRelay.powerFX      = yourPowerFX;

                    Resources.UnloadAsset(powerRelay);
                }

                PowerManager.Initialize(this);

                AnimationManager = gameObject.GetComponentInParent <AIJetStreamT242AnimationManager>();

                BeaconManager = gameObject.GetComponentInParent <BeaconController>();

                if (_display == null)
                {
                    _display = GetComponent <AIJetStreamT242Display>() ?? GetComponentInParent <AIJetStreamT242Display>();
                }

                IsInitialized = true;
                //_currentBiome = BiomeManager.GetBiome();
            }
            else
            {
                IsInitialized = false;
                throw new MissingComponentException("Failed to find all components");
            }

            if (!IsInitialized)
            {
                return;
            }

            PowerManager.OnKillBattery += Unsubscribe;
        }
Beispiel #9
0
        private void Initialize()
        {
            _buildable = GetComponent <Constructable>() ?? GetComponentInParent <Constructable>();

            if (FindComponents())
            {
                QuickLogger.Debug($"Turbine Components Found", true);

                _prefabID = GetComponentInParent <PrefabIdentifier>();

                var currentBiome = BiomeManager.GetBiome();

                if (!string.IsNullOrEmpty(currentBiome))
                {
                    var data = BiomeManager.GetBiomeData(currentBiome);
                }

                AISolutionsData.Instance.OnRotationChanged += AiSolutionsDataOnOnRotationChanged;

                if (HealthManager == null)
                {
                    HealthManager = gameObject.GetComponent <AIJetStreamT242HealthManager>() ?? GetComponentInParent <AIJetStreamT242HealthManager>();
                }


                HealthManager.Initialize(this);
                HealthManager.SetHealth(100);
                HealthManager.SetDamageModel(_damage);

                if (PowerManager == null)
                {
                    PowerManager = GetComponentInParent <AIJetStreamT242PowerManager>() ?? GetComponent <AIJetStreamT242PowerManager>();
                }

                PowerManager.Initialize(this);

                AnimationManager = gameObject.GetComponentInParent <AIJetStreamT242AnimationManager>();

                BeaconManager = gameObject.GetComponentInParent <BeaconController>();

                if (_display == null)
                {
                    _display = GetComponent <AIJetStreamT242Display>() ?? GetComponentInParent <AIJetStreamT242Display>();
                }

                IsInitialized = true;
                //_currentBiome = BiomeManager.GetBiome();
            }
            else
            {
                IsInitialized = false;
                throw new MissingComponentException("Failed to find all components");
            }

            if (!IsInitialized)
            {
                return;
            }

            PowerManager.OnKillBattery += Unsubscribe;
        }