Example #1
0
    private Citizen AddCitizen(ResidentialCityBlock home)
    {
        GameObject go      = Instantiate(citizenPrefab, citizenContainer.transform);
        Citizen    citizen = go.GetComponent <Citizen>();

        citizen.SetHome(home);
        citizen.SetPathPlanner(this);

        Coordinate workCoord;

        // If no work buildings exist or 25% chance
        if (occupiedIndustrialBlocks.Count == 0 || Random.Range(0, 100) < 25)
        {
            // Occupy new work building
            int r = Random.Range(0, unoccupiedIndustrialBlocks.Count - 1);
            workCoord = unoccupiedIndustrialBlocks[r];

            unoccupiedIndustrialBlocks.RemoveAt(r);
            occupiedIndustrialBlocks.Add(workCoord);
        }
        else
        {
            // Occupy existing work building
            int r = Random.Range(0, occupiedIndustrialBlocks.Count - 1);
            workCoord = occupiedIndustrialBlocks[r];
        }

        IndustrialCityBlock workBlock = GetBlock(workCoord).GetComponent <IndustrialCityBlock>();

        citizen.SetWork(workBlock);

        return(citizen);
    }
Example #2
0
    private void AddFamily()
    {
        int                  r          = Random.Range(0, unoccupiedResidentialBlocks.Count - 1);
        Coordinate           houseCoord = unoccupiedResidentialBlocks[r];
        ResidentialCityBlock houseBlock = GetBlock(houseCoord).GetComponent <ResidentialCityBlock>();

        unoccupiedResidentialBlocks.Remove(houseCoord);
        occupiedResidentialBlocks.Add(houseCoord);

        int familySize = Random.Range(cityData.familyMin, cityData.familyMax);

        for (int i = 0; i < familySize; i++)
        {
            Citizen familyMember = AddCitizen(houseBlock);
            familyMember.SetSpawn(GenerateSpawnPos());
            houseBlock.AddResident(familyMember);
        }
    }
Example #3
0
 public void SetHome(ResidentialCityBlock home)
 {
     this.home = home;
 }