Beispiel #1
0
    private void AddNewCitizens()
    {
        if (GameObject.FindGameObjectWithTag("Enemy"))
        {
            return;
        }

        int   allCurrentCitizens = allCitizens.Count + currentEmployedAmount;
        float bedsLeft           = currentBedsAmount - allCurrentCitizens;

        if (bedsLeft <= 0)
        {
            MessageLog.AddNewMessage("Some people tried to join your town but there were no beds available, perhaps we should build more houses");  return;
        }

        //How many citizens are added depends on the happiness of the people
        int citizensToAdd = Mathf.RoundToInt(bedsLeft / 100 * currentHappinessAmount);

        for (int i = 0; i < citizensToAdd; i++)
        {
            SpawnNewCitizen();
        }
        if (currentHappinessAmount >= 100)
        {
            MessageLog.AddNewMessage("Its a new day and " + citizensToAdd.ToString() + " decided to join your town!");
        }
        else
        {
            float citizensLeft = bedsLeft - citizensToAdd;
            MessageLog.AddNewMessage("Its a new day and " + citizensToAdd.ToString() + " decided to join your town but " + citizensLeft.ToString() + " refused");
        }
        citizensText.text = (currentEmployedAmount + allCitizens.Count).ToString();
    }
Beispiel #2
0
    private void CheckHappiness()
    {
        float happinessPerCitizen = 0;

        if (allCitizens.Count > 0)
        {
            happinessPerCitizen = 100 / allCitizens.Count;
        }
        currentHappinessAmount = 0;

        for (int i = 0; i < allCitizens.Count; i++)
        {
            if (allCitizens[i].IsHappy())
            {
                currentHappinessAmount += happinessPerCitizen;
            }
        }

        if (currentHappinessAmount <= 5)
        {
            if (allCitizens.Count > 0)
            {
                int citizensToLeave = Random.Range(3, allCitizens.Count / 100 * 50);
                if (citizensToLeave > allCitizens.Count)
                {
                    citizensToLeave = allCitizens.Count;
                }
                DeleteCitizen(citizensToLeave);
                MessageLog.AddNewMessage("Your people are unhappy! " + citizensToLeave.ToString() + " left your city!");
            }
            else if (currentEmployedAmount > 0)
            {
                int citizensToLeave = Random.Range(3, currentEmployedAmount / 100 * 50);
                if (citizensToLeave > currentEmployedAmount)
                {
                    citizensToLeave = currentEmployedAmount;
                }
                currentEmployedAmount -= citizensToLeave;
                MessageLog.AddNewMessage("Your people are unhappy! " + citizensToLeave.ToString() + " left your city!");
            }

            int allCitizensLeft = allCitizens.Count + currentEmployedAmount;
            if (allCitizensLeft <= 0)
            {
                Time.timeScale = 0;
                ES3.DeleteFile(ES3.Load <string>("CurrentSaveName") + ".es3");
                ES3.DeleteFile(ES3.Load <string>("CurrentSaveName") + ".png");
                loseMenu.SetActive(true);
            }
            citizensText.text = allCitizensLeft.ToString();
        }

        happinessText.text = Mathf.RoundToInt(currentHappinessAmount).ToString() + "%";
    }
Beispiel #3
0
 private void SpawnTroops()
 {
     MessageLog.AddNewMessage("A unit has finished training!");
     if (isMeleeTrainer)
     {
         GameManager.GetManager().SpawnNewMeleeUnit(troopSpawnLocation.position);
     }
     else
     {
         GameManager.GetManager().SpawnNewRangedUnit(troopSpawnLocation.position);
     }
 }
Beispiel #4
0
    private void HandleTaxes()
    {
        if (!taxesEnabled)
        {
            return;
        }

        int allCitizensCount = allCitizens.Count + currentEmployedAmount;
        int goldEarned       = 0;

        for (int i = 0; i < allCitizensCount; i++)
        {
            goldEarned += goldPerCitizen;
        }

        currentGoldAmount += goldEarned;

        if (allUnits.Count > 0)
        {
            int goldSpent = 0;
            for (int i = 0; i < allUnits.Count; i++)
            {
                //Units cost 5 gold per warrior, every unit has 9 warriors
                goldSpent += 45;
            }

            currentGoldAmount -= goldSpent;
            if (currentGoldAmount <= 0)
            {
                currentGoldAmount = 0;
                MessageLog.AddNewMessage("Tax report! You earned " + goldEarned.ToString() + " today and you paid your all troops " + goldSpent.ToString() + "! You dont have any money left, your citizens are unhappy");
            }
            else
            {
                MessageLog.AddNewMessage("Tax report! You earned " + goldEarned.ToString() + " today and you paid your all troops " + goldSpent.ToString() + "!");
            }
        }
        else
        {
            MessageLog.AddNewMessage("Tax report! You earned " + goldEarned.ToString() + " from your citizens");
        }

        goldText.text = currentGoldAmount.ToString();
    }
Beispiel #5
0
    private void SpawnEnemyShips()
    {
        if (GameObject.FindGameObjectWithTag("Enemy"))
        {
            return;
        }

        AudioManager.PlayAudioClipGlobal(attackSound);
        int maxAmount = Mathf.RoundToInt(allCitizens.Count / 100);

        if (maxAmount < 1)
        {
            maxAmount = 1;
        }

        int amountToSpawn = Random.Range(1, maxAmount);

        MessageLog.AddNewMessage("ATTACK! " + amountToSpawn + " enemy ships have been spotted, get ready!");

        List <Transform> randomSpawnPoints = new List <Transform>();

        int childCount = enemyShipInstantiateContent.childCount;

        for (int i = 0; i < childCount; ++i)
        {
            randomSpawnPoints.Add(enemyShipInstantiateContent.GetChild(i));
        }

        for (int i = 0; i < amountToSpawn; i++)
        {
            Transform randomSpawnPoint = randomSpawnPoints[Random.Range(0, randomSpawnPoints.Count)];
            randomSpawnPoints.Remove(randomSpawnPoint);

            GameObject newShip = Instantiate(enemyShips[Random.Range(0, enemyShips.Length)], randomSpawnPoint.position, randomSpawnPoint.rotation);
        }
    }
Beispiel #6
0
    private void NewDay()
    {
        currentDay += 1;

        AddNewCitizens();

        HandleTaxes();

        if (currentDay > 365)
        {
            currentDay   = 1;
            currentYear += 1;
        }

        int allCurrentCitizens = allCitizens.Count + currentEmployedAmount;
        int peopleUnfed        = 0;

        for (int i = 0; i < allCurrentCitizens; i++)
        {
            currentFoodAmount  -= 1;
            currentWaterAmount -= 1;
            if (currentFoodAmount <= 0)
            {
                currentFoodAmount = 0;
                peopleUnfed      += 1;
            }
            else if (currentWaterAmount <= 0)
            {
                peopleUnfed += 1;
            }

            if (currentWaterAmount <= 0)
            {
                currentWaterAmount = 0;
            }
        }

        if (peopleUnfed > 1)
        {
            MessageLog.AddNewMessage(peopleUnfed + " citizens are unhappy because they dont have food or water!");
        }
        else if (peopleUnfed > 0)
        {
            MessageLog.AddNewMessage(peopleUnfed + " citizen is unhappy because they dont have food or water!");
        }

        int unhappyPeople = peopleUnfed;

        if (unhappyPeople > allCitizens.Count)
        {
            unhappyPeople = allCitizens.Count;
        }
        for (int c = 0; c < allCitizens.Count; c++)
        {
            unhappyPeople -= 1;
            if (unhappyPeople > -1)
            {
                if (allCitizens[c])
                {
                    allCitizens[c].ToggleHappy(false);
                }
            }
            else
            {
                if (allCitizens[c])
                {
                    allCitizens[c].ToggleHappy(true);
                }
            }
        }

        foodText.text  = currentFoodAmount.ToString();
        waterText.text = currentWaterAmount.ToString();

        CheckHappiness();

        //We want to give the player a headstart before we start attacking him
        if (currentDay > 10 && allBuildings.Count > 3)
        {
            if (Random.Range(0, 100) <= chanceToSpawnEnemy)
            {
                SpawnEnemyShips();
            }
        }

        if (currentYear > 0)
        {
            timeText.text = "Year: " + currentYear + " - Day: " + currentDay;
        }
        else
        {
            timeText.text = "Day: " + currentDay;
        }
    }
Beispiel #7
0
    private void LoadSaveGame(SaveGame save)
    {
        currentSave            = save;
        currentHappinessAmount = currentSave.AmountHappiness;
        currentFoodAmount      = currentSave.AmountFood;
        currentStoneAmount     = currentSave.AmountStone;
        currentWoodAmount      = currentSave.AmountWood;
        currentWaterAmount     = currentSave.AmountWater;
        currentEmployedAmount  = currentSave.CitizenAmount;
        currentGoldAmount      = currentSave.AmountGold;
        currentYear            = currentSave.Year;
        currentDay             = currentSave.Day;

        Camera.main.transform.position = save.CameraPosition;
        Camera.main.transform.rotation = save.CameraRotation;

        woodText.text  = currentWoodAmount.ToString();
        stoneText.text = currentStoneAmount.ToString();
        foodText.text  = currentFoodAmount.ToString();
        waterText.text = currentWaterAmount.ToString();
        goldText.text  = currentGoldAmount.ToString();

        for (int i = 0; i < currentSave.AllBuildings.Count; i++)
        {
            GameObject newObject = Instantiate(Resources.Load("Buildings/" + currentSave.AllBuildings[i].BuildingName) as GameObject);
            newObject.transform.position = currentSave.AllBuildings[i].BuildingPosition;
            newObject.transform.rotation = currentSave.AllBuildings[i].BuildingRotation;
            allBuildings.Add(newObject);
            newObject.transform.SetParent(buildingParent);
            newObject.GetComponent <ObjectID>().SetID(currentSave.AllBuildings[i].BuildingID);

            if (currentSave.AllBuildings[i].BuildFinished)
            {
                if (newObject.GetComponent <ConstructionBuilding>())
                {
                    if (newObject.GetComponent <ConstructionBuilding>().GetTaxesEnabled())
                    {
                        ToggleTaxesEnabled(true);
                    }
                    Destroy(newObject.GetComponent <ConstructionBuilding>());
                }
                if (newObject.GetComponent <CitizenHouse>())
                {
                    newObject.GetComponent <CitizenHouse>().enabled = true;
                }
                if (newObject.GetComponent <ResourceGenerator>())
                {
                    newObject.GetComponent <ResourceGenerator>().StartGenerator(currentSave.AllBuildings[i].Progress);
                }
                else
                {
                    Destroy(newObject.GetComponent <JobActivator>());
                }
            }
            else
            {
                newObject.GetComponent <ConstructionBuilding>().PlaceBuilding();
                newObject.GetComponent <ConstructionBuilding>().BuildObject(Mathf.RoundToInt(currentSave.AllBuildings[i].Progress));
            }
        }

        for (int i = 0; i < currentSave.AllJobs.Count; i++)
        {
            AddNewJob(GetBuildingByID(currentSave.AllJobs[i]).GetComponent <JobActivator>(), true);
        }

        for (int i = 0; i < currentSave.AllCitizens.Count; i++)
        {
            SpawnNewCitizen(currentSave.AllCitizens[i]);
        }

        for (int i = 0; i < currentSave.AllUnits.Count; i++)
        {
            if (currentSave.AllUnits[i].IsMelee)
            {
                SpawnNewMeleeUnit(Vector3.zero, currentSave.AllUnits[i]);
            }
            else
            {
                SpawnNewRangedUnit(Vector3.zero, currentSave.AllUnits[i]);
            }
        }

        for (int i = 0; i < currentSave.MessageLogMessages.Count; i++)
        {
            MessageLog.AddNewMessage(currentSave.MessageLogMessages[i]);
        }

        //If there are no citizens it means the player started a new game, if this happens lets give him 3 citizens and some food to start off with.
        if (allCitizens.Count < 1)
        {
            for (int i = 0; i < 3; i++)
            {
                SpawnNewCitizen();
            }
        }

        CheckAvailableBeds();
        CheckHappiness();
    }