Esempio n. 1
0
    public static Crew CreateNewCrew(ColonyController home, int membersCount)
    {
        if (crewsList.Count >= RecruitingCenter.GetCrewsSlotsCount())
        {
            return(null);
        }
        if (crewsList.Count > MAX_CREWS_COUNT)
        {
            AnnouncementCanvasController.MakeImportantAnnounce(Localization.GetAnnouncementString(GameAnnouncements.CrewsLimitReached));
            GameMaster.LoadingFail();
            return(null);
        }
        Crew c = new GameObject(Localization.NameCrew()).AddComponent <Crew>();

        if (crewsContainer == null)
        {
            crewsContainer = new GameObject("crewsContainer");
        }
        c.transform.parent = crewsContainer.transform;

        c.ID     = nextID; nextID++;
        c.atHome = true;

        //normal parameters
        c.membersCount = (byte)membersCount;
        //attributes
        c.SetAttributes(home);
        //
        crewsList.Add(c);
        listChangesMarkerValue++;
        return(c);
    }
Esempio n. 2
0
 private void SendColonists()
 {
     if (completed)
     {
         return;
     }
     if (anchorBasement.colonistsArrived >= COLONISTS_SEND_LIMIT)
     {
         if (colony.storage.GetResourceCount(COST_RESOURCE_ID) >= COLONISTS_SEND_COST)
         {
             if (hexBuilder.totalHousing > hexBuilder.colonistsCount)
             {
                 anchorBasement.GetColonists(COLONISTS_SEND_LIMIT);
                 colony.storage.GetResources(COST_RESOURCE_ID, COLONISTS_SEND_COST);
                 hexBuilder.AddColonist();
                 colony.RemoveCitizens(COLONISTS_SEND_LIMIT, false);
                 settleWindow.Refresh();
             }
             else
             {
                 AnnouncementCanvasController.MakeImportantAnnounce(localizer.notEnoughLivingSpace);
             }
         }
         else
         {
             AnnouncementCanvasController.MakeImportantAnnounce(localizer.notEnoughSuppliesMsg);
         }
     }
     else
     {
         AnnouncementCanvasController.MakeImportantAnnounce(localizer.notEnoughColonistsMsg);
     }
 }
Esempio n. 3
0
    public void StartEndQuest(byte routeIndex)
    {
        int endIndex = (int)QuestSection.Endgame;

        if (activeQuests[endIndex] == Quest.NoQuest || activeQuests[endIndex] == null)
        {
            questAccessMap[endIndex] = true;
            if ((Knowledge.ResearchRoute)routeIndex == Knowledge.ResearchRoute.Foundation)
            {
                var scn = new FoundationRouteScenario();
                GameMaster.realMaster.BindScenario(scn);
                scn.StartScenario();
            }
            else
            {
                activeQuests[endIndex] = new Quest(QuestType.Endgame, routeIndex);
            }
        }
        else
        {
            AnnouncementCanvasController.MakeImportantAnnounce(Localization.GetAnnouncementString(GameAnnouncements.AlreadyHaveEndquest));
        }
        if (openedQuest == -1 & GetComponent <Image>().enabled)
        {
            PrepareBasicQuestWindow();
        }
    }
Esempio n. 4
0
 public bool StartHiring()
 {
     if (finding)
     {
         return(true);
     }
     else
     {
         if (Crew.crewsList.Count < GetCrewsSlotsCount())
         {
             if (colony.energyCrystalsCount >= hireCost)
             {
                 colony.GetEnergyCrystals(hireCost);
                 finding = true;
                 return(true);
             }
             else
             {
                 AnnouncementCanvasController.NotEnoughMoneyAnnounce();
                 return(false);
             }
         }
         else
         {
             AnnouncementCanvasController.MakeImportantAnnounce(Localization.GetRefusalReason(RefusalReason.NotEnoughSlots));
             if (GameMaster.soundEnabled)
             {
                 GameMaster.audiomaster.Notify(NotificationSound.NotEnoughSlots);
             }
             return(false);
         }
     }
 }
Esempio n. 5
0
 public void AddArtifact(Artifact a, int slotIndex)
 {
     if (a != null && !a.destructed)
     {
         if (!a.researched)
         {
             GameMaster.audiomaster.Notify(NotificationSound.Disagree);
             AnnouncementCanvasController.MakeImportantAnnounce(Localization.GetPhrase(LocalizedPhrase.ArtifactNotResearched));
             return;
         }
         else
         {
             if (affectionPath != Path.TechPath)
             {
                 GameMaster.audiomaster.Notify(NotificationSound.Disagree);
                 AnnouncementCanvasController.MakeImportantAnnounce(Localization.GetPhrase(LocalizedPhrase.AffectionTypeNotMatch));
                 return;
             }
             else
             {
                 if (artifacts == null)
                 {
                     artifacts = new Artifact[4];
                 }
                 else
                 {
                     if (artifacts[slotIndex] != null)
                     {
                         artifacts[slotIndex].ChangeStatus(Artifact.ArtifactStatus.OnConservation);
                     }
                 }
                 artifacts[slotIndex] = a;
                 a.ChangeStatus(Artifact.ArtifactStatus.UsingInMonument);
                 RecalculateAffection();
             }
         }
     }
 }
    public bool LoadGame(string fullname)
    {
        bool   debug_noresource = weNeedNoResources, refreshUI = false;
        Stream fs = File.Open(fullname, FileMode.Open);
        double realHashSum = GetHashSum(fs, true);
        var    data        = new byte[8];

        fs.Read(data, 0, 8);
        double readedHashSum = System.BitConverter.ToDouble(data, 0);
        string errorReason   = "reason not stated";

        if (realHashSum == readedHashSum)
        {
            fs.Position = 0;
            SetPause(true);
            loading = true;


            // НАЧАЛО ЗАГРУЗКИ
            #region gms mainPartLoading
            data = new byte[5];
            fs.Read(data, 0, data.Length);
            int saveSystemVersion = System.BitConverter.ToInt32(data, 0); // может пригодиться в дальнейшем
            gameMode = (GameMode)data[4];
            //
            if (sessionPrepared)
            {
                ClearPreviousSessionData();
                refreshUI = true;
            }
            else
            {
                PrepareSession();
            }
            //start reading
            data = new byte[68];
            fs.Read(data, 0, data.Length);
            gameSpeed                      = System.BitConverter.ToSingle(data, 0);
            lifeGrowCoefficient            = System.BitConverter.ToSingle(data, 4);
            demolitionLossesPercent        = System.BitConverter.ToSingle(data, 8);
            lifepowerLossesPercent         = System.BitConverter.ToSingle(data, 12);
            LUCK_COEFFICIENT               = System.BitConverter.ToSingle(data, 16);
            sellPriceCoefficient           = System.BitConverter.ToSingle(data, 20);
            tradeVesselsTrafficCoefficient = System.BitConverter.ToSingle(data, 24);
            upgradeDiscount                = System.BitConverter.ToSingle(data, 28);
            upgradeCostIncrease            = System.BitConverter.ToSingle(data, 32);
            warProximity                   = System.BitConverter.ToSingle(data, 36);

            difficulty = (Difficulty)data[40];
            int i = 41;
            prevCutHeight = data[i++];
            day           = data[i++];
            month         = data[i++];

            year              = System.BitConverter.ToUInt32(data, i); i += 4;
            timeGone          = System.BitConverter.ToSingle(data, i); i += 4;
            gearsDegradeSpeed = System.BitConverter.ToSingle(data, i); i += 4;
            labourTimer       = System.BitConverter.ToSingle(data, i); i += 4;
            RecruitingCenter.SetHireCost(System.BitConverter.ToSingle(data, i)); i += 4;
            gameID = System.BitConverter.ToInt32(data, i); i += 4;
            #endregion

            DockSystem.LoadDockSystem(fs, saveSystemVersion);
            var b = fs.ReadByte();
            if (b == 1)
            {
                globalMap.Load(fs, saveSystemVersion);
            }
            if (loadingFailed)
            {
                errorReason = "global map error";
                goto FAIL;
            }

            environmentMaster.Load(fs);
            if (loadingFailed)
            {
                errorReason = "environment error";
                goto FAIL;
            }

            Artifact.LoadStaticData(fs); // crews & monuments
            if (loadingFailed)
            {
                errorReason = "artifacts load failure";
                goto FAIL;
            }

            Crew.LoadStaticData(fs);
            if (loadingFailed)
            {
                errorReason = "crews load failure";
                goto FAIL;
            }
            //
            if (colonyController == null)
            {
                PrepareColonyController(false);
            }
            //
            if (mainChunk == null)
            {
                mainChunk = Chunk.InitializeChunk();
            }
            mainChunk.LoadChunkData(fs);
            if (loadingFailed)
            {
                errorReason = "chunk load failure";
                goto FAIL;
            }
            else
            {
                if (blockersRestoreEvent != null)
                {
                    blockersRestoreEvent();
                }
            }

            Settlement.TotalRecalculation(); // Totaru Annihiration no imoto-chan
            if (loadingFailed)
            {
                errorReason = "settlements load failure";
                goto FAIL;
            }

            colonyController.Load(fs); // < --- COLONY CONTROLLER
            if (loadingFailed)
            {
                errorReason = "colony controller load failure";
                goto FAIL;
            }

            if (loadingFailed)
            {
                errorReason = "dock load failure";
                goto FAIL;
            }
            QuestUI.current.Load(fs);
            if (loadingFailed)
            {
                errorReason = "quest load failure";
                goto FAIL;
            }
            Expedition.LoadStaticData(fs);
            Knowledge.Load(fs);
            b = fs.ReadByte();
            if (b == 1)
            {
                executingScenario = Scenario.StaticLoad(fs);
            }
            FollowingCamera.main.Load(fs);
            fs.Close();

            FollowingCamera.main.WeNeedUpdate();
            loading         = false;
            currentSavename = fullname;

            //Debug.Log("recalculation event");
            if (afterloadRecalculationEvent != null)
            {
                afterloadRecalculationEvent();
                afterloadRecalculationEvent = null;
            }
            SetPause(false);
            //Debug.Log("power grid");
            colonyController.FORCED_PowerGridRecalculation();
            //Debug.Log("docks");
            colonyController.SYSTEM_DocksRecalculation();
            //Debug.Log("end");

            if (refreshUI)
            {
                UIController.GetCurrent().GameWasReloaded();
            }

            DEBUG_STOP = true;
            return(true);
        }
        else
        {
            AnnouncementCanvasController.MakeImportantAnnounce(Localization.GetAnnouncementString(GameAnnouncements.LoadingFailed) + " : hashsum incorrect");
            if (soundEnabled)
            {
                audiomaster.Notify(NotificationSound.SystemError);
            }
            SetPause(true);
            fs.Close();
            return(false);
        }
FAIL:
        AnnouncementCanvasController.MakeImportantAnnounce(Localization.GetAnnouncementString(GameAnnouncements.LoadingFailed) + " : data corruption");
        if (soundEnabled)
        {
            audiomaster.Notify(NotificationSound.SystemError);
        }
        Debug.Log(errorReason);
        SetPause(true);
        fs.Close();
        if (debug_noresource)
        {
            weNeedNoResources = true;
        }
        return(false);
    }
    public void PrepareList()
    {
        if (observingMonument == null)
        {
            SelfShutOff();
            return;
        }
        else
        {
            if (selectedSlotIndex == -1)
            {
                listHolder.SetActive(false);
                return;
            }
            if (Artifact.artifactsList.Count == 0)
            {
                AnnouncementCanvasController.MakeImportantAnnounce(Localization.GetPhrase(LocalizedPhrase.NoArtifacts));
                return;
            }
            var arts = new List <Artifact>();
            ids = new List <int>()
            {
                -1
            };
            var  selectedArtifact = observingMonument.artifacts[selectedSlotIndex];
            bool slotWithArtifact = selectedArtifact != null;
            foreach (var a in Artifact.artifactsList)
            {
                if (a.researched)
                {
                    if (a.affectionPath != Path.NoPath
                        &
                        (observingMonument.affectionPath == Path.NoPath | (a.affectionPath == observingMonument.affectionPath))
                        )
                    {
                        if (a.status == Artifact.ArtifactStatus.OnConservation | (slotWithArtifact && selectedArtifact.ID == a.ID))
                        {
                            arts.Add(a);
                            ids.Add(a.ID);
                        }
                    }
                }
            }
            int artsCount = arts.Count;
            if (artsCount > 0)
            {
                // подготовка списка

                int newSelectedItem = -1;

                if (artsCount + 1 > items.Length)
                {
                    // артефакты не помещаются в одну страницу
                    if (!scrollbar.gameObject.activeSelf)
                    {
                        scrollbar.value = 0;
                        scrollbar.gameObject.SetActive(true);
                    }
                    float rsize = items.Length;
                    rsize /= artsCount;
                    if (scrollbar.size != rsize)
                    {
                        scrollbar.size = rsize;
                    }

                    //#preparePositionedList
                    int sindex = GetListStartIndex();
                    int i      = 0;
                    if (sindex == 0)
                    {
                        items[0].transform.GetChild(0).GetComponent <Text>().text = slotWithArtifact ? Localization.GetPhrase(LocalizedPhrase.ClearSlot) : '<' + Localization.GetPhrase(LocalizedPhrase.NoArtifact) + '>';
                        i = 1;
                    }
                    for (; i < items.Length; i++)
                    {
                        items[i].transform.GetChild(0).GetComponent <Text>().text = '"' + arts[i + sindex - 1].name + '"';
                        items[i].SetActive(true);
                    }


                    if (selectedArtifact != null)
                    {
                        for (int j = 0; j < items.Length; j++)
                        {
                            if (ids[j + sindex] == selectedArtifact.ID)
                            {
                                newSelectedItem = j;
                                break;
                            }
                        }
                    }
                    else
                    {
                        if (sindex != 0)
                        {
                            newSelectedItem = -1;
                        }
                        else
                        {
                            newSelectedItem = 0;
                        }
                    }
                    //
                }
                else
                {
                    // артефактов меньше, чем позиций списка
                    items[0].transform.GetChild(0).GetComponent <Text>().text = slotWithArtifact ? Localization.GetPhrase(LocalizedPhrase.ClearSlot) : '<' + Localization.GetPhrase(LocalizedPhrase.NoArtifact) + '>';
                    if (scrollbar.gameObject.activeSelf)
                    {
                        scrollbar.gameObject.SetActive(false);
                    }
                    int i = 0;
                    for (; i < arts.Count; i++)
                    {
                        items[i + 1].transform.GetChild(0).GetComponent <Text>().text = '"' + arts[i].name + '"';
                        items[i + 1].SetActive(true);
                    }
                    i++;
                    if (i < items.Length)
                    {
                        for (; i < items.Length; i++)
                        {
                            items[i].SetActive(false);
                        }
                    }

                    if (selectedArtifact != null)
                    {
                        for (int j = 1; j < items.Length; j++)
                        {
                            if (ids[j] == selectedArtifact.ID)
                            {
                                newSelectedItem = j;
                                break;
                            }
                        }
                    }
                    else
                    {
                        newSelectedItem = 0;
                    }
                }

                if (newSelectedItem != listSelectedItem)
                {
                    if (listSelectedItem != -1)
                    {
                        items[listSelectedItem].GetComponent <Image>().overrideSprite = null;
                    }
                    if (newSelectedItem != -1)
                    {
                        items[newSelectedItem].GetComponent <Image>().overrideSprite = PoolMaster.gui_overridingSprite;
                    }
                    listSelectedItem = newSelectedItem;
                }
                if (!listHolder.activeSelf)
                {
                    listHolder.SetActive(true);
                }
            }
            else
            {
                if (listHolder.activeSelf)
                {
                    if (ids != null)
                    {
                        ids.Clear();
                    }
                    listHolder.SetActive(false);
                }
                AnnouncementCanvasController.MakeImportantAnnounce(Localization.GetPhrase(LocalizedPhrase.NoSuitableArtifacts));
                return;
            }
        }
    }