예제 #1
0
	public bool checkForDeath(personSim sim, int currentYear)
	{
		float chance = getChance (currentYear - sim.yearBorn, sim.isMale);

		if (currentYear - sim.yearBorn > doubleAt)
			chance *= 2;

		return roulette(chance);
	}
예제 #2
0
	public void addTracker(personSim sim)
	{
		charTracker tracker = (Instantiate (Resources.Load ("charIcon", typeof(GameObject))) as GameObject).GetComponent<charTracker> ();

		bool needsOffset = false;

		for(int i = chars.Count -1; i >= 0; i--)
		{
			if(sim.yearBorn - chars[i].trackedSim.yearBorn < 10)
			{
				needsOffset = true;
				break;
			}
			if(sim.yearBorn - chars[i].trackedSim.yearBorn > 10 )
			{
				break;
			}
		}

		if(needsOffset)
		{
			List<int> banned = new List<int>();

			tracker.yOffset = chars[chars.Count-1].yOffset + 33;

			for(int i = chars.Count -1; i >= 0; i--)
			{
				if(sim.yearBorn - chars[i].trackedSim.yearBorn >= 10  && !banned.Contains(chars[i].yOffset) && chars[i].yOffset < chars[chars.Count-1].yOffset + 33)
				{
					tracker.yOffset = chars[i].yOffset;
					//Debug.Log(sim.firstName + " found a suitable offset from " + chars[i].trackedSim.firstName);
				}
				else if(!banned.Contains(chars[i].yOffset))
				{
					banned.Add(chars[i].yOffset);
				}
			}

		}

		tracker.transform.parent = transform;
		tracker.transform.localScale = Vector3.one;
		tracker.trackedSim = sim;
		tracker.transform.GetComponentInChildren<UILabel> ().text = sim.firstName;
		chars.Add(tracker);

	}
예제 #3
0
	public personSim(int currentYear, float maleMod = 0, personSim guard1 = null, personSim guard2 = null)
	{
		evManager = GameObject.FindGameObjectWithTag ("eventManager").GetComponent<eventManager> ();
		children = new List<personSim> ();
		yearBorn = currentYear;
		isAlive = true;
		this.guard1 = guard1;
		this.guard2 = guard2;
		
		//assign gender
		if(UnityEngine.Random.value >= 0.5f + -maleMod)
		{
			isMale = true;
		}
		else
		{
			isMale = false;
		}

		if(guard1 != null && guard2 != null && guard1.isMale != guard2.isMale)
		{
			//guardians are biological parents, randomly inherit features!
			if(UnityEngine.Random.value >= 0.5f)		
				this.eyeColour = guard1.eyeColour;
			else
				this.eyeColour = guard2.eyeColour;

			if(UnityEngine.Random.value >= 0.5f)		
				this.hairColour = guard1.hairColour;
			else
				this.hairColour = guard2.hairColour;

			if(UnityEngine.Random.value >= 0.5f)		
				this.hairDescription = guard1.hairDescription;
			else
				this.hairDescription = guard2.hairDescription;

			//I'm old fashioned....
			if(guard1.isMale)
				generateName (guard1.surname);
			else
				generateName (guard2.surname);

		}

		else
		{
			if (guard1 != null && guard2 != null && guard1.isMale == guard2.isMale)
			{
				//child is adopted, take name only
				if(UnityEngine.Random.value >= 0.5f)		
					generateName(guard1.surname);
				else
					generateName(guard2.surname);
			}
			else generateName();//no parents given, randomly gen everything

			maidenName = surname;
			eyeColour = eyeColours[UnityEngine.Random.Range(0, eyeColours.Length)];
			hairColour = hairColours[UnityEngine.Random.Range(0, hairColours.Length)];
			hairDescription = hairModifiers[UnityEngine.Random.Range(0, hairModifiers.Length)] + ", " + hairTypes[UnityEngine.Random.Range(0, hairTypes.Length)];
		}
		

	}
예제 #4
0
	public bool yearlyUpdate(List<personSim> chars, causeOfDeath[] causes, int currentYear)
	{
		if(currentYear <= lastYearRun)
		{
			return false;
		}

		lastYearRun = currentYear;

		if(charManager == null)
		{
			charManager = GameObject.FindGameObjectWithTag("trackerManager").GetComponent<charTrackerManager>();
		}

		int age = getAge(currentYear);
		if(isAlive){

			if(partner != null && partner.isAlive)
			{
				partner.diedThisYear (causes, currentYear);
			}

			//make sure parents get updated!
			if(guard1 != null && guard1.isAlive)
			{
				guard1.yearlyUpdate(chars, causes, currentYear);
			}
			if(guard2 != null && guard2.isAlive)
			{
				guard2.yearlyUpdate(chars, causes, currentYear);
			}

			if(partner != null && partner.isAlive && age >= 20 && age <= 53  && children.Count < 2 && charManager.getNumChars() < 8)
			{
				//chance of gaining child
				if((UnityEngine.Random.value >= 0.95f) || (charManager.getNumChars() < 3 && (UnityEngine.Random.value >= 0.85f)))
				{
					personSim child = new personSim(currentYear, 0, this, partner);
					chars.Add(child);
					children.Add(child);
					partner.children.Add(child);

					if(partner.isMale != isMale)
						evManager.addEvent(getName() + " and " + partner.getName() + " gave birth to " + child.getName() + " in " + currentYear.ToString());
					else
						evManager.addEvent(getName() + " and " + partner.getName() + " adopted " + child.getName() + " in " + currentYear.ToString());

					GameObject.FindGameObjectWithTag("trackerManager").GetComponent<charTrackerManager>().addTracker(child);
				}
			}

			//check if should marry
			if(partner != null && partner.isAlive && isMarried == false && UnityEngine.Random.value >= 0.9f)
			{
				partner.isMarried = true;
				isMarried = true;
				marriedSince = currentYear;
				evManager.addEvent(getName() + " married " + partner.getName() + " in " + currentYear + "!");
				if(partner.isMale)
				{	
					string message = getName() + " is now ";
					surname = partner.surname;
					Debug.Log(message + getName());

					foreach(personSim child in children)
					{
						child.surname = surname;
					}
				}
				else
				{
					partner.surname = surname;
				}
			}

			//check if find a partner
			else if(partner == null && age >= 18 && UnityEngine.Random.value >= 0.88f)
			{
				//create partner with adjusted gender odds
				if(isMale)partner = new personSim( yearBorn + UnityEngine.Random.Range(-5, 5), -0.3f);
				else partner = new personSim(currentYear  + UnityEngine.Random.Range(-5, 5), 0.3f);
				evManager.addEvent(getName() + " started going out with " + partner.getName() + " in " + currentYear);
				coupledSince = currentYear;
			}

			updateThoughts(currentYear);

			return diedThisYear (causes, currentYear);
		}

		return false;
	}
예제 #5
0
	// Update is called once per frame
	void Update () {

		if(Input.GetKeyUp(KeyCode.RightArrow))
		{
			yearsToCompute += 5;
		}


		if(startYear + yearsToCompute > currentYear){

			birthRate = ((float)popData[0]/((float)currentPop/1000));
			causesOfDeath[3].alterChances(1 - advancesVsCancer);
			causesOfDeath[9].alterChances(1 - advancesVsHeartDisease);
			causesOfDeath[12].alterChances(1 - (advancesVsSmoking /2));

			if(startYear == currentYear)
			{
				personSim sim = new personSim(currentYear);
				sims.Add (sim);
				iconTracker.addTracker(sim);

			}

			currentYear++;
			
			yearLabel.text = currentYear.ToString();
			
			updateCurrentPopCount(); 
			updateChart();
			
			popCounter.text = currentPop.ToString("N0", new CultureInfo( "en-US", false ).NumberFormat);
			
			int deathToll = 0;
			
			foreach(causeOfDeath cause in causesOfDeath)
			{
				deathToll += cause.populationToll(popData);
			}
			
			
			//move population forward a year
			for(int i = popData.Length - 1; i >= 0; i--)
			{
				if(i > 0)
					popData[i] = popData[i-1];
				else
				{
					if(birthRate > minBirthRatePerThousand)
						popData[0] = (int)(popData[1] * (1 - birthRateChange));
					else
						popData[0] = popData[1];
				}
					
			}
			
			int count = 0;
			
			while(count < sims.Count)
			{
				sims[count].yearlyUpdate(sims, causesOfDeath, currentYear);					
				count++;
			}
			
			iconTracker.updateTrackers(chart, currentYear);			

		}
	}