예제 #1
0
 override public void LevelUp(bool returnToUI)
 {
     if (!GameMaster.realMaster.weNeedNoResources)
     {
         ResourceContainer[] cost = GetUpgradeCost();
         if (!colony.storage.CheckBuildPossibilityAndCollectIfPossible(cost))
         {
             GameLogUI.NotEnoughResourcesAnnounce();
             return;
         }
     }
     if (level > 3)
     {
         SetBlockers();
     }
     level++;
     nextStageConditionMet = CheckUpgradeCondition();
     SetModel();
     buildingObserver.CheckUpgradeAvailability();
     Quest.ResetHousingQuest();
     GameLogUI.MakeAnnouncement(Localization.LevelReachedString(level));
     if (GameMaster.soundEnabled)
     {
         GameMaster.audiomaster.Notify(NotificationSound.HQ_Upgraded);
     }
     GameMaster.realMaster.eventTracker?.BuildingUpgraded(this);
 }
예제 #2
0
파일: Dock.cs 프로젝트: Hengle/VoxelGame
    public float BuyResource(ResourceType rt, float volume)
    {
        if (availableVolume <= 0f)
        {
            return(0f);
        }
        if (volume > availableVolume)
        {
            volume = availableVolume;
        }
        var   colony = GameMaster.realMaster.colonyController;
        float p = ResourceType.prices[rt.ID], money = 0f;

        if (p != 0)
        {
            money  = colony.GetEnergyCrystals(volume * ResourceType.prices[rt.ID]);
            volume = money / ResourceType.prices[rt.ID];
            if (volume == 0)
            {
                return(0f);
            }
            else
            {
                GameLogUI.MakeAnnouncement(Localization.GetBuyMsg(rt, volume, money));
            }
        }
        colony.storage.AddResource(rt, volume);
        colony.gears_coefficient -= gearsDamage * volume;
        availableVolume          -= volume;
        return(volume);
    }
예제 #3
0
 public void SubmitButton() // for save option only
 {
     if (terrainsLoading)
     {// ПЕРЕЗАПИСЬ СОХРАНЕНИЯ ТЕРРЕЙНА
         if (deleteSubmit)
         {
             File.Delete(GetTerrainsPath() + '/' + saveNames[lastSelectedIndex] + '.' + TERRAIN_FNAME_EXTENSION);
             Transform t = saveNamesContainer.GetChild(lastSelectedIndex + 1);
             t.GetComponent <Image>().color            = Color.white;
             t.GetChild(0).GetComponent <Text>().color = Color.white;
             lastSelectedIndex = -1;
             RefreshSavesList();
         }
         else
         {
             if (lastSelectedIndex != -1)
             {
                 GameMaster.realMaster.SaveTerrain(saveNames[lastSelectedIndex]);
             }
         }
     }
     else
     {   // ПЕРЕЗАПИСЬ СОХРАНЕНИЯ ИГРЫ
         if (deleteSubmit)
         {
             File.Delete(terrainsLoading ?
                         GetTerrainsPath() + '/' + saveNames[lastSelectedIndex] + '.' + TERRAIN_FNAME_EXTENSION
                 :
                         GetSavesPath() + '/' + saveNames[lastSelectedIndex] + '.' + SAVE_FNAME_EXTENSION);
             Transform t = saveNamesContainer.GetChild(lastSelectedIndex + 1);
             t.GetComponent <Image>().color            = Color.white;
             t.GetChild(0).GetComponent <Text>().color = Color.white;
             lastSelectedIndex = -1;
             RefreshSavesList();
         }
         else
         {
             if (lastSelectedIndex != -1)
             {
                 string s = saveNames[lastSelectedIndex];
                 if (GameMaster.realMaster.SaveGame(s))
                 {
                     GameLogUI.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.GameSaved));
                 }
                 else
                 {
                     GameLogUI.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.SavingFailed));
                     if (GameMaster.soundEnabled)
                     {
                         GameMaster.audiomaster.Notify(NotificationSound.SystemError);
                     }
                 }
             }
         }
     }
     submitWindow.SetActive(false);
 }
예제 #4
0
    public void Dismiss() // экспедиция вернулась домой и распускается
    {
        //зависимость : Disappear()
        if (stage == ExpeditionStage.Disappeared | stage == ExpeditionStage.Dismissed)
        {
            return;
        }
        else
        {
            GameLogUI.MakeAnnouncement(Localization.GetCrewAction(LocalizedCrewAction.Returned, crew));
            if (crew != null)
            {
                crew.CountMission(missionCompleted);
                crew.SetCurrentExpedition(null);
                crew = null;
            }
            QuantumTransmitter.StopTransmission(transmissionID);
            Hangar.ReturnShuttle(shuttleID);
            if (destination != null)
            {
                destination.DeassignExpedition(this);
            }
            if (suppliesCount > 0)
            {
                GameMaster.realMaster.colonyController.storage.AddResource(ResourceType.Supplies, suppliesCount);
            }
            if (expeditionsList.Contains(this))
            {
                expeditionsList.Remove(this);
            }
            if (crystalsCollected > 0)
            {
                GameMaster.realMaster.colonyController.AddEnergyCrystals(crystalsCollected);
                crystalsCollected = 0;
            }
            stage = ExpeditionStage.Dismissed;
            if (missionCompleted)
            {
                expeditionsSucceed++;
                Knowledge.GetCurrent()?.ExpeditionsCheck(expeditionsSucceed);
            }

            expeditionsList.Remove(this);

            if (subscribedToUpdate & !GameMaster.sceneClearing)
            {
                GameMaster.realMaster.labourUpdateEvent -= this.LabourUpdate;
                subscribedToUpdate = false;
            }
            changesMarkerValue++;
        }
    }
예제 #5
0
 public void LaunchButton()
 {
     if (showingExpedition == null)
     {
         if (selectedCrew != null && selectedCrew.atHome)
         {
             var storage = colony.storage;
             var res     = storage.standartResources;
             if (suppliesSlider.value <= res[ResourceType.SUPPLIES_ID] &&
                 crystalsSlider.value <= colony.energyCrystalsCount &&
                 res[ResourceType.FUEL_ID] >= FUEL_BASE_COST)
             {
                 int shID = Hangar.GetFreeShuttleID();
                 if (shID != Hangar.NO_SHUTTLE_VALUE)
                 {
                     var t = QuantumTransmitter.GetFreeTransmitter();
                     if (t != null)
                     {
                         if (storage.TryGetResources(ResourceType.Fuel, FUEL_BASE_COST))
                         {
                             var e = new Expedition(selectedDestination, selectedCrew, shID, t, storage.GetResources(ResourceType.Supplies, suppliesSlider.value), colony.GetEnergyCrystals(crystalsSlider.value));
                             if (workOnMainCanvas)
                             {
                                 showingExpedition = e;
                             }
                             else
                             {
                                 showingExpedition = null;
                                 selectedCrew      = null;
                                 GameMaster.realMaster.globalMap.observer.GetComponent <GlobalMapUI>().PreparePointDescription();
                                 gameObject.SetActive(false);
                             }
                         }
                         else
                         {
                             GameLogUI.MakeAnnouncement(Localization.GetExpeditionErrorText(ExpeditionComposingErrors.NotEnoughFuel));
                         }
                         RedrawWindow();
                     }
                 }
             }
         }
     }
     else
     {
         showingExpedition.EndMission();
     }
 }
예제 #6
0
 override public void LabourUpdate()
 {
     if (!isActive | !isEnergySupplied)
     {
         return;
     }
     if (workersCount > 0)
     {
         if (finding)
         {
             workSpeed = (FIND_SPEED * 0.8f * colony.workspeed + 0.2f * Random.value) * GameMaster.LABOUR_TICK / workflowToProcess;
             workflow += workSpeed;
             if (workflow >= workflowToProcess)
             {
                 int memCount = (int)((workersCount / (float)maxWorkers) * Crew.MAX_MEMBER_COUNT);
                 if (workersCount < memCount)
                 {
                     memCount = workersCount;
                 }
                 if (memCount > 0)
                 {
                     Crew c = Crew.CreateNewCrew(colony, memCount);
                     workersCount -= memCount;
                     workflow      = 0;
                     finding       = false;
                     GameLogUI.MakeAnnouncement(Localization.GetCrewAction(LocalizedCrewAction.Ready, c));
                     hireCost = hireCost * (1 + GameConstants.HIRE_COST_INCREASE);
                     hireCost = ((int)(hireCost * 100)) / 100f;
                     if (showOnGUI)
                     {
                         rcenterObserver.SelectCrew(c);
                     }
                 }
             }
         }
     }
     else
     {
         if (workflow > 0)
         {
             workflow -= backupSpeed * GameMaster.LABOUR_TICK;
             if (workflow < 0)
             {
                 workflow = 0;
             }
         }
     }
 }
예제 #7
0
 override protected void LabourResult()
 {
     shuttleID = nextShuttleID++;
     status    = HangarStatus.ShuttleInside;
     if (workersCount > 0)
     {
         FreeWorkers();
     }
     workflow = 0f;
     listChangesMarkerValue++;
     if (showOnGUI)
     {
         hangarObserver.PrepareHangarWindow();
     }
     GameLogUI.MakeAnnouncement(Localization.GetPhrase(LocalizedPhrase.ShuttleConstructed));
 }
예제 #8
0
    public void MakeQuestCompleted()
    {
        GameLogUI.MakeAnnouncement(Localization.AnnounceQuestCompleted(name));
        uint x = (uint)Mathf.Pow(2, subIndex);

        if ((questsCompletenessMask[(int)type] & x) == 0)
        {
            questsCompletenessMask[(int)type] += x;
        }
        if (type == QuestType.Endgame & subIndex != 2)
        {
            QuestUI.current.SetNewQuest((int)QuestSection.Endgame);
        }
        else
        {
            QuestUI.current.ResetQuestCell(this);
        }
        GameMaster.realMaster.colonyController.AddEnergyCrystals(reward);
    }
예제 #9
0
    /// ===============================
    public Expedition(PointOfInterest i_destination, Crew c, int i_shuttleID, QuantumTransmitter transmitter, float i_supplies, float i_crystals)
    {
        // СДЕЛАТЬ: проверка компонентов и вывод ошибок
        ID    = nextID++;
        stage = ExpeditionStage.WayIn;

        destination = i_destination; destination.AssignExpedition(this);
        crew        = c; c.SetCurrentExpedition(this);

        if (Hangar.OccupyShuttle(i_shuttleID))
        {
            shuttleID = i_shuttleID;
        }
        else
        {
            GameLogUI.MakeAnnouncement(Localization.GetExpeditionErrorText(ExpeditionComposingErrors.ShuttleUnavailable));
            Dismiss();
        }

        if (transmitter != null)
        {
            transmissionID = transmitter.StartTransmission();
            hasConnection  = true;
        }
        else
        {
            transmissionID = QuantumTransmitter.NO_TRANSMISSION_VALUE;
            hasConnection  = false;
        }
        suppliesCount     = (byte)i_supplies;
        crystalsCollected = (ushort)i_crystals;

        //#creating map marker
        GlobalMap gmap = GameMaster.realMaster.globalMap;

        mapMarker = new FlyingExpedition(this, gmap.cityPoint, destination, FLY_SPEED);
        gmap.AddPoint(mapMarker, true);
        //

        expeditionsList.Add(this);
        listChangesMarker++;
    }
예제 #10
0
파일: Dock.cs 프로젝트: Hengle/VoxelGame
    public void SellResource(ResourceType rt, float volume)
    {
        if (availableVolume <= 0f)
        {
            return;
        }
        var colony = GameMaster.realMaster.colonyController;

        if (volume > availableVolume)
        {
            volume = availableVolume;
        }
        float vol   = colony.storage.GetResources(rt, volume);
        float money = vol * ResourceType.prices[rt.ID] * GameMaster.sellPriceCoefficient;

        colony.AddEnergyCrystals(money);
        colony.gears_coefficient -= gearsDamage * vol;
        availableVolume          -= vol;
        GameLogUI.MakeAnnouncement(Localization.GetSellMsg(rt, vol, money));
    }
예제 #11
0
파일: Dock.cs 프로젝트: Hengle/VoxelGame
    public void ShipLoading(Ship s)
    {
        if (loadingShip == null)
        {
            loadingTimer = LOADING_TIME;
            loadingShip  = s;
            if (announceNewShips)
            {
                GameLogUI.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.ShipArrived));
            }
            return;
        }
        availableVolume = workersCount * WORK_PER_WORKER;
        DockSystem.GetCurrent().HandleShip(this, s, colony);
        loadingShip     = null;
        maintainingShip = false;
        s.Undock();

        shipArrivingTimer = GameConstants.GetShipArrivingTimer();
    }
예제 #12
0
파일: Storage.cs 프로젝트: Hengle/VoxelGame
    private void Overloading()
    {
        if (announcementTimer <= 0)
        {
            GameLogUI.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.StorageOverloaded));
            if (GameMaster.soundEnabled)
            {
                GameMaster.audiomaster.Notify(NotificationSound.StorageOverload);
            }
            announcementTimer = 10f;
        }
        else
        {
            // storage dumping
            var      chunk = GameMaster.realMaster.mainChunk;
            ChunkPos cpos;
            bool     secondTry = false;
            if (warehouses.Count > 0)
            {
                cpos = warehouses[Random.Range(0, warehouses.Count)].GetBlockPosition();
            }
            else
            {
                cpos = GameMaster.realMaster.colonyController.hq.GetBlockPosition();
            }
            var sblock = chunk.GetNearestUnoccupiedSurface(cpos);
SECOND_TRY:
            if (sblock != null)
            {
                int   maxIndex = 0, sid = 0;
                float maxValue   = 0;
                var   bmaterials = ResourceType.blockMaterials;
                for (int j = 0; j < bmaterials.Length; j++)
                {
                    sid = bmaterials[j].ID;
                    if (standartResources[sid] > maxValue)
                    {
                        maxValue = standartResources[sid];
                        maxIndex = sid;
                    }
                }
                int dumpingVal = 1000;
                if (dumpingVal > maxValue)
                {
                    dumpingVal = (int)maxValue;
                }

                dumpingVal -= sblock.FORCED_GetExtension().ScatterResources(SurfaceRect.full, ResourceType.GetResourceTypeById(maxIndex), dumpingVal);

                if (dumpingVal != 0)
                {
                    standartResources[maxIndex] -= dumpingVal;
                    totalVolume -= dumpingVal;
                }
                else
                {
                    if (!secondTry)
                    {
                        secondTry = true;
                        sblock    = chunk.GetRandomSurface(Block.UP_FACE_INDEX);
                        goto SECOND_TRY;
                    }
                }
            }
        }
    }
예제 #13
0
    private void Update()
    {
        if (!prepared)
        {
            return;
        }

        float t = Time.deltaTime * GameMaster.gameSpeed;
        float f = 0, a;

        float[] thisCycleRotations = new float[RINGS_COUNT];
        for (int i = 0; i < RINGS_COUNT; i++)
        {
            a = rotationSpeed[i] * t;
            thisCycleRotations[i] = a;
            f  = ringsRotation[i];
            f -= thisCycleRotations[i];
            if (f > 360)
            {
                f = f % 360f;
            }
            else
            {
                if (f < 0)
                {
                    f = 360f - Mathf.Abs(f % 360f);
                }
            }
            ringsRotation[i] = f;
        }

        float ascensionChange = 0;
        float prevX = cityPoint.angle, prevY = cityPoint.height;

        if (mapPoints.Count > 0)
        {
            if (GameMaster.realMaster.colonyController != null)
            {
                //float s = GameMaster.realMaster.stability;
                //if (s > 1f) s = 1f;
                //if (cpoint.height != s)
                //{
                //    cpoint.height = 1f - s;
                //    cpoint.ringIndex = DefineRing(s);
                //}
            }
            int i = 0;
            while (i < mapPoints.Count)
            {
                MapPoint mp = mapPoints[i];
                mp.angle += thisCycleRotations[mp.ringIndex];
                if (mp.type == MapMarkerType.FlyingExpedition)
                {
                    FlyingExpedition fe = (mp as FlyingExpedition);
                    MapPoint         d  = fe.destination;
                    if (d != null)
                    {
                        if (mp.height != d.height)
                        {
                            mp.height = Mathf.MoveTowards(mp.height, d.height, fe.speed * t * 0.01f);
                        }
                        else
                        {
                            if (mp.angle != d.angle)
                            {
                                mp.angle = Mathf.MoveTowardsAngle(mp.angle, d.angle, fe.speed * t);
                            }
                            else
                            {
                                mapPoints.RemoveAt(i);
                                fe.expedition.DropMapMarker();
                                pointsExploringEvent?.Invoke(d);
                                if (fe.expedition.stage == Expedition.ExpeditionStage.WayIn)
                                {
                                    fe.expedition.StartMission();
                                }
                                else
                                {
                                    fe.expedition.Dismiss();
                                }
                                actionsHash++;
                                continue;
                            }
                        }
                    }
                    else
                    {
                        GameLogUI.MakeAnnouncement(Localization.GetCrewAction(LocalizedCrewAction.CannotReachDestination, fe.expedition.crew));
                        fe.expedition.EndMission();
                    }
                }
                i++;
            }
        }
        //
        cityLookVector   = Quaternion.AngleAxis(cityPoint.angle, Vector3.up) * Vector3.forward;
        cityFlyDirection = new Vector3(cityPoint.angle - prevX + rotationSpeed[cityPoint.ringIndex], ascensionChange, cityPoint.height - prevY);
    }
예제 #14
0
    public void SetNewQuest(int i)
    {
        if (questAccessMap[i] == false)
        {
            activeQuests[i] = Quest.NoQuest;
            return;
        }
        // поиск подходящих среди отложенных
        Quest q = Quest.NoQuest;

        switch ((QuestSection)i)
        {
        case QuestSection.Zero: q = Quest.GetProgressQuest(); break;

        case QuestSection.Endgame:
            break;
            uint mask = Quest.questsCompletenessMask[(int)QuestType.Endgame];
            if (mask == 0)
            {
                q = new Quest(QuestType.Endgame, 0);
            }
            else
            {
                if (mask == 3)
                {
                    q = new Quest(QuestType.Endgame, 2);
                }
                else
                {
                    if (mask == 1)
                    {
                        q = new Quest(QuestType.Endgame, 1);
                    }
                }
            }
            break;

        default:
            q = Knowledge.GetCurrent().GetHelpingQuest();
            break;
        }

        if (q == Quest.NoQuest)
        {
            StartCoroutine(WaitForNewQuest(i));
            return;
        }
        else
        {
            activeQuests[i] = q;
            if (openedQuest == -1)
            {
                newQuestMarker.enabled = true;
            }
        }

        if (openedQuest == -1 & GetComponent <Image>().enabled)
        {
            PrepareBasicQuestWindow();
        }
        GameLogUI.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.NewQuestAvailable));
        if (GameMaster.soundEnabled)
        {
            GameMaster.audiomaster.Notify(NotificationSound.newQuestAvailable);
        }
    }
예제 #15
0
    void Start()
    {
        if (gameStarted)
        {
            return;
        }

        if (gameMode != GameMode.Editor)
        {
            difficulty = gameStartSettings.difficulty;
            SetDefaultValues();
            //byte chunksize = gss.chunkSize;
            byte chunksize;
            chunksize = gameStartSettings.chunkSize;
            if (testMode && savenameToLoad != string.Empty)
            {
                gameStartSettings = new GameStartSettings(ChunkGenerationMode.GameLoading);
                savename          = savenameToLoad;
            }
            if (gameStartSettings.generationMode != ChunkGenerationMode.GameLoading)
            {
                if (gameStartSettings.generationMode != ChunkGenerationMode.DontGenerate)
                {
                    if (gameStartSettings.generationMode != ChunkGenerationMode.TerrainLoading)
                    {
                        Constructor.ConstructChunk(chunksize, gameStartSettings.generationMode);
                        // Constructor.ConstructBlock(chunksize);
                        if (gameStartSettings.generationMode == ChunkGenerationMode.Peak)
                        {
                            environmentMaster.PrepareIslandBasis(ChunkGenerationMode.Peak);
                        }
                    }
                    else
                    {
                        LoadTerrain(SaveSystemUI.GetTerrainsPath() + '/' + savename + '.' + SaveSystemUI.TERRAIN_FNAME_EXTENSION);
                    }
                }
                FollowingCamera.main.ResetTouchRightBorder();
                FollowingCamera.main.CameraRotationBlock(false);
                warProximity   = 0.01f;
                layerCutHeight = Chunk.chunkSize; prevCutHeight = layerCutHeight;
                switch (startGameWith)
                {
                case GameStart.Zeppelin:
                    Instantiate(Resources.Load <GameObject>("Prefs/Zeppelin"));
                    if (needTutorial)
                    {
                        GameLogUI.EnableDecisionWindow(null, Localization.GetTutorialHint(LocalizedTutorialHint.Landing));
                    }
                    else
                    {
                        GameLogUI.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.SetLandingPoint));
                    }
                    break;

                case GameStart.Headquarters:
                    var   sblocks = mainChunk.surfaces;
                    Plane sb      = sblocks[Random.Range(0, sblocks.Length)];
                    int   xpos    = sb.pos.x;
                    int   zpos    = sb.pos.z;

                    Structure s;
                    if (testMode)
                    {
                        s = HeadQuarters.GetHQ(6);
                        weNeedNoResources = true;
                    }
                    else
                    {
                        weNeedNoResources = false;
                        s = HeadQuarters.GetHQ(1);
                    }

                    Plane b = mainChunk.GetHighestSurfacePlane(xpos, zpos);
                    s.SetBasement(b, PixelPosByte.zero);


                    sb = mainChunk.GetHighestSurfacePlane(xpos - 1, zpos + 1);
                    if (sb == null)
                    {
                        sb = mainChunk.GetHighestSurfacePlane(xpos, zpos + 1);
                        if (sb == null)
                        {
                            sb = mainChunk.GetHighestSurfacePlane(xpos + 1, zpos + 1);
                            if (sb == null)
                            {
                                sb = mainChunk.GetHighestSurfacePlane(xpos - 1, zpos);
                                if (sb == null)
                                {
                                    sb = mainChunk.GetHighestSurfacePlane(xpos + 1, zpos);
                                    if (sb == null)
                                    {
                                        sb = mainChunk.GetHighestSurfacePlane(xpos - 1, zpos - 1);
                                        if (sb == null)
                                        {
                                            sb = mainChunk.GetHighestSurfacePlane(xpos, zpos - 1);
                                            if (sb == null)
                                            {
                                                sb = mainChunk.GetHighestSurfacePlane(xpos + 1, zpos - 1);
                                                if (sb == null)
                                                {
                                                    print("bad generation, do something!");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    StorageHouse firstStorage = Structure.GetStructureByID(Structure.STORAGE_0_ID) as StorageHouse;
                    firstStorage.SetBasement(sb, PixelPosByte.zero);
                    SetStartResources();
                    break;
                }
                FollowingCamera.main.WeNeedUpdate();
            }
            else
            {
                LoadGame(SaveSystemUI.GetSavesPath() + '/' + savename + ".sav");
            }
        }
        else
        {
            gameObject.AddComponent <PoolMaster>().Load();
            mainChunk = new GameObject("chunk").AddComponent <Chunk>();
            int size = Chunk.chunkSize;
            int[,,] blocksArray = new int[size, size, size];
            size /= 2;
            blocksArray[size, size, size] = ResourceType.STONE_ID;
            mainChunk.CreateNewChunk(blocksArray);
        }

        { // set look point
            FollowingCamera.camBasisTransform.position = sceneCenter;
        }
        gameStarted = true;
    }
예제 #16
0
    public void HandleShip(Dock d, Ship s, ColonyController colony)
    {
        int   peopleBefore = immigrationPlan;
        float efficientcy  = (float)d.workersCount / (float)d.maxWorkers;
        float tradeVolume  = s.volume * (0.05f + 0.95f * efficientcy);

        switch (s.type)
        {
        case ShipType.Passenger:
        {
            float vol = s.volume * (Random.value * 0.5f * colony.happiness_coefficient + 0.5f);
            if (immigrationPlan > 0)
            {
                if (vol > immigrationPlan)
                {
                    colony.AddCitizens(immigrationPlan);
                    immigrationPlan = 0;
                    vol            -= immigrationPlan;
                }
                else
                {
                    int x = (int)vol;
                    colony.AddCitizens(x); immigrationPlan -= x;
                    vol = 0;
                }
            }
            if (vol > 0)
            {
                vol *= colony.happiness_coefficient;
                if (vol > 1f)
                {
                    Hotel.DistributeLodgers((int)vol);
                }
            }

            if (isForSale[ResourceType.FOOD_ID] != null)
            {
                if (isForSale[ResourceType.FOOD_ID] == true)
                {
                    d.SellResource(ResourceType.Food, s.volume * 0.1f);
                }
                else
                {
                    d.BuyResource(ResourceType.Food, s.volume * 0.1f);
                }
            }
            break;
        }

        case ShipType.Cargo:
        {
            float      buyPrioritiesPool = 0, sellPrioritiesPool = 0;
            List <int> buyPositions = new List <int>(), sellPositions = new List <int>();
            var        storage = colony.storage.standartResources;
            float[]    demands = ResourceType.demand;
            for (int i = 0; i < ResourceType.TYPES_COUNT; i++)
            {
                if (isForSale[i] == null)
                {
                    continue;
                }
                if (isForSale[i] == true)         // продаваемый островом ресурс
                {
                    if (storage[i] > minValueForTrading[i])
                    {
                        sellPositions.Add(i);
                        sellPrioritiesPool += demands[i];
                    }
                }
                else         // покупаемый островом ресурс
                {
                    if (storage[i] <= minValueForTrading[i])
                    {
                        buyPositions.Add(i);
                        buyPrioritiesPool += demands[i];
                    }
                }
            }

            if (buyPositions.Count > 0)
            {
                float boughtVolume = 0;
                foreach (int id in buyPositions)
                {
                    float v = demands[id] / buyPrioritiesPool * tradeVolume;
                    if (storage[id] + v > minValueForTrading[id])
                    {
                        v = minValueForTrading[id] - storage[id];
                    }
                    if (v != 0)
                    {
                        boughtVolume += d.BuyResource(ResourceType.GetResourceTypeById(id), v);
                    }
                }
                tradeVolume += boughtVolume;
            }

            if (sellPositions.Count > 0)
            {
                foreach (int id in sellPositions)
                {
                    double v = demands[id] / buyPrioritiesPool * tradeVolume;
                    if (storage[id] - v < minValueForTrading[id])
                    {
                        v = storage[id] - minValueForTrading[id];
                    }
                    float v2 = (float)(demands[id] / sellPrioritiesPool * tradeVolume);
                    if (v2 != 0)
                    {
                        d.SellResource(ResourceType.GetResourceTypeById(id), v2);
                    }
                }
            }
            break;
        }

        case ShipType.Military:
        {
            if (GameMaster.realMaster.warProximity < 0.5f && Random.value < 0.1f && immigrationPlan > 0)
            {
                int veterans = (int)(s.volume * 0.02f);
                if (veterans > immigrationPlan)
                {
                    veterans = immigrationPlan;
                }
                colony.AddCitizens(veterans);
            }
            if (isForSale[ResourceType.FUEL_ID] == true)
            {
                float tv = (float)(tradeVolume * 0.5f * (Random.value * 0.5f + 0.5f));
                if (tv != 0)
                {
                    d.SellResource(ResourceType.Fuel, tv);
                }
            }
            ;
            if (GameMaster.realMaster.warProximity > 0.5f)
            {
                if (isForSale[ResourceType.METAL_S_ID] == true)
                {
                    d.SellResource(ResourceType.metal_S, s.volume * 0.1f);
                }
                if (isForSale[ResourceType.METAL_K_ID] == true)
                {
                    d.SellResource(ResourceType.metal_K, s.volume * 0.05f);
                }
                if (isForSale[ResourceType.METAL_M_ID] == true)
                {
                    d.SellResource(ResourceType.metal_M, s.volume * 0.1f);
                }
            }
            break;
        }

        case ShipType.Private:
            if (isForSale[ResourceType.FUEL_ID] == true)
            {
                d.SellResource(ResourceType.Fuel, (float)(tradeVolume * 0.8f));
            }
            if (isForSale[ResourceType.FOOD_ID] == true)
            {
                d.SellResource(ResourceType.Fuel, (float)(tradeVolume * 0.15f));
            }
            break;
        }

        int newPeople = peopleBefore - immigrationPlan;

        if (newPeople != 0)
        {
            if (newPeople > 0)
            {
                GameLogUI.MakeAnnouncement(Localization.GetPhrase(LocalizedPhrase.ColonistsArrived) + " (" + newPeople.ToString() + ')');
                immigrantsArrived += (uint)newPeople;
                Knowledge.GetCurrent()?.ImmigrantsCheck(immigrantsArrived);
            }
            else
            {
                emigrantsGone += (uint)(newPeople * (-1));
            }
        }
    }
예제 #17
0
 public void SaveLoadButton()
 {
     if (lastSelectedIndex == -1)
     {
         return;
     }
     if (saveMode)
     {
         submitWindow.SetActive(true);
         submitQuestionText.text = Localization.GetWord(LocalizedWord.Rewrite) + '?';
         submitButtonText.text   = Localization.GetWord(LocalizedWord.Yes);
         rejectButtonText.text   = Localization.GetWord(LocalizedWord.Cancel);
         deleteSubmit            = false;
     }
     else
     {
         if (terrainsLoading)
         {// ЗАГРУЗКА  УРОВНЕЙ  ДЛЯ  РЕДАКТОРА
             string fullPath = GetTerrainsPath() + '/' + saveNames[lastSelectedIndex] + '.' + TERRAIN_FNAME_EXTENSION;
             if (ingame)
             {
                 if (GameMaster.realMaster.LoadTerrain(fullPath))
                 {
                     gameObject.SetActive(false);
                 }
             }
             else
             {
                 // теоретический сценарий, не должен использоваться
                 if (File.Exists(fullPath))
                 {
                     GameMaster.SetSavename(saveNames[lastSelectedIndex]);
                     GameStartSettings gss = new GameStartSettings(ChunkGenerationMode.TerrainLoading);
                     GameMaster.gameStartSettings = gss;
                     GameMaster.ChangeScene(GameMaster.EDITOR_SCENE_INDEX);
                 }
                 else
                 {
                     saveNames[lastSelectedIndex] = "File not exist";
                 }
             }
         }
         else
         {// ЗАГРУЗКА  УРОВНЕЙ  ДЛЯ  ИГРЫ
             string fullPath = GetSavesPath() + '/' + saveNames[lastSelectedIndex] + '.' + SAVE_FNAME_EXTENSION;
             if (ingame)
             {
                 if (GameMaster.realMaster.LoadGame(fullPath))
                 {
                     gameObject.SetActive(false);
                     GameLogUI.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.GameLoaded));
                 }
             }
             else
             {
                 if (File.Exists(fullPath))
                 {
                     GameMaster.SetSavename(saveNames[lastSelectedIndex]);
                     GameStartSettings gss = new GameStartSettings(ChunkGenerationMode.GameLoading);
                     GameMaster.gameStartSettings = gss;
                     GameMaster.ChangeScene(GameMaster.PLAY_SCENE_INDEX);
                 }
                 else
                 {
                     saveNames[lastSelectedIndex] = "File not exist";
                 }
             }
         }
     }
 }