Esempio n. 1
0
	public void DeleteConnectedPlanet (PregenPlanet pc)
	{
		pc.vines [this] = null;
		vines [pc] = null;

		pc.connectedPlanets.Remove (this);
		connectedPlanets.Remove (pc);
	}
	public static PregenPlanet GetDirection (PregenPlanet planet, PregenSeedizen seedizen)
	{
		var q = new Queue <PregenPlanet> ();
		var discovered = new HashSet <PregenPlanet> ();
		var pathTo = new Dictionary <PregenPlanet, PregenPlanet> ();

		q.Enqueue (planet);
		discovered.Add (planet);

		while (q.Count > 0) {
			var p = q.Dequeue ();

			if (p == null || p.planetType == null)
				continue;

			//check for victory
			if (PlanetIsDestination (p, seedizen)) {
				//success! construct and return the path
				PregenPlanet curPlanet = p;
				while (curPlanet != null && pathTo.ContainsKey (curPlanet)) {
					var prevPlanet = pathTo [curPlanet];
					if (!pathTo.ContainsKey (prevPlanet))
						return curPlanet;
					curPlanet = prevPlanet;
				}
			}

			var neighbors = new List <PregenPlanet> (p.connectedPlanets);
			var neighbors2 = new List <PregenPlanet> ();
			//randomize neighbors
			while (neighbors.Count > 0) {
				int at = Random.Range (0, neighbors.Count);
				neighbors2.Add (neighbors [at]);
				neighbors.RemoveAt (at);
			}

			foreach (var n in neighbors2) {
				if (discovered.Contains (n))
					continue;

				discovered.Add (n);
				pathTo [n] = p;
				q.Enqueue (n);
			}
		}

		//welp, return a random one
		var options = new List <PregenPlanet> (planet.connectedPlanets);
		foreach (var p in planet.connectedPlanets)
			if (planet.vines [p].dispreferred)
				options.Remove (p);
		if (options.Count == 0) {
			return null;
		}
		return options [Random.Range (0, options.Count)];
	}
	private static bool PlanetIsDestination (PregenPlanet planet, PregenSeedizen seedizen)
	{
		if (seedizen.hasPollen) {
			return planet.hasDemands.NeedsPollen (seedizen);
		} else if (seedizen.hasWater) {
			return planet.hasDemands.NeedsWater (seedizen);
		} else if (seedizen.type == "marsh") {
			return planet.makesWater;
		} else {
			return planet.makesPollen;
		}
	}
Esempio n. 4
0
	public void AddConnectedPlanet (PregenPlanet pc, PregenVine v)
	{
		connectedPlanets.Add (pc);
		if (planetType != "travelPlanet") {
			pc.connectedPlanets.Add (this);
		}
		if (pc.planetType == "travelPlanet" && planetType == "travelPlanet") {
			pc.connectedPlanets.Add (this);
		}

		vines [pc] = v;
		pc.vines [this] = v;
	}
Esempio n. 5
0
	// Use this for initialization
	void Start () {
		var cc = gameObject.GetComponent <CircleCollider2D> ();
		if (cc != null) {
			distance = cc.radius + 2.5f;//this is obviously just a sort of made up formula that has no good thought behind it
		}

		//TESTING
		planet = gameObject.GetComponent <PregenPlanet> ();
		string pt = planet.planetType;
		//var vpc = gameObject.GetComponent <VictoryPregenPlanet> ();

		if (!startWithNoDemands && (pt != null && planet.demands)) {
			if (Random.value < .5f) {

				//needs seedizens

				string d = demandTypes [Random.Range (0, demandTypes.Length)];
				for (int i = 0; i < Random.Range (1, 8); i++) {
					AddDemand (d, true, Random.value < .8f);

					if (Random.Range (0f, 1f) < .2f)
						d = demandTypes [Random.Range (0, demandTypes.Length)];
				}
			} else {

				//needs pollen

				string d = demandTypes [Random.Range (0, demandTypes.Length)];
				for (int i = 0; i < Random.Range (1, 8); i++) {
					AddDemand (d, false, Random.value < .8f);

					if (Random.Range (0f, 1f) < .2f)
						d = demandTypes [Random.Range (0, demandTypes.Length)];
				}
			}
		} else if (pt == "vine" && planet.connectedPlanets.Count == 0) {

			//flowers need a person at first
			AddDemand ("", true, true);
		}
	}
Esempio n. 6
0
	private void OnDemandsAllMet () {
		Debug.Log ("CONGRATULATIONS! You met all the demands of: " + gameObject.name);

		if (planet == null)
			planet = gameObject.GetComponent <PregenPlanet> ();
		var pt = planet.planetType;

		/*if (pt.isVictory) {
			GenericUtilityScript.instance.victoryText.SetActive (true);
			return;
		}*/

		if (pt == "vine") {
			planet.IncrementNumBridges ();
		} else if (pt != "") {
			ResourcesDisplay.instance.Add (Random.Range (1,2), pt);
		}

		if (planet != null && planet.planetType != null && planet.numBridges > 0 && planet.planetType != null && planet.planetType == "vine") {
			Debug.Log ("Doing nothing");
			//do nothing. Flowers wait until they are out of bridges
		} else 
			GainPollenAfterWait (Random.Range (5f, 10f));
	}
	public static void RegisterMouseOnPlanet (PregenPlanet planet)
	{
		currentPlanetByMouse = planet;
	}
	public static void RegisterNoMouseOnPlanet (PregenPlanet planet)
	{
		if (currentPlanetByMouse == planet)
			currentPlanetByMouse = null;
	}
	// Update is called once per frame
	void Update () {
		
		AnimationHandler();

		if (flingWithMouse) {
			//flinging
			if (Time.time > flingTime + flingDur) {
				//CameraPanningScript.EnableControls ();
				flingTime = float.MaxValue;
				StartFlight (Camera.main.ScreenToWorldPoint(Input.mousePosition) - mousePosAtStartOfFling);
			}
			//ending fling
			if (inFling && Input.GetKeyUp (KeyCode.Mouse0)) {
				inFling = false;
				CameraPanningScript.Enable ();
				speed = 2f;
			}
		}

		//walking
		if (inTransit && destinationPlanet != null) {
			Vector3 dir = destinationPlanet.gameObject.transform.position - gameObject.transform.position;
			dir.Normalize ();
			dir = dir * Time.deltaTime * speed;
			gameObject.transform.position += dir;

			//facing
			/*var rot = gameObject.transform.rotation;
			if (dir.x < 0)
				rot.y = 0f;
			else
				rot.y = 180f;
			gameObject.transform.rotation = rot;*/

			//var angle = Mathf.Atan2(currentVine.dir.y, currentVine.dir.x) * Mathf.Rad2Deg;
			//gameObject.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
		}

		if (destinationPlanet != null) {
			if (Vector3.Distance (destinationPlanet.gameObject.transform.position, gameObject.transform.position) < .5f) {
				currentPlanet = destinationPlanet;
				destinationPlanet = null;
			}
		}
		if (currentPlanet != null) {
			if (gameObject.transform.position.x > currentPlanet.gameObject.transform.position.x)
			{
				gameObject.transform.rotation = Quaternion.LookRotation (Vector3.forward, (gameObject.transform.position - currentPlanet.gameObject.transform.position).normalized) * Quaternion.Euler(0,0,90);

				var rot = gameObject.transform.rotation;
				rot.y = 180f;
				gameObject.transform.rotation = rot;
			} else
			{
				gameObject.transform.rotation = Quaternion.LookRotation (Vector3.forward, (currentPlanet.gameObject.transform.position - gameObject.transform.position).normalized) * Quaternion.Euler(0,0,90);

				var rot = gameObject.transform.rotation;
				rot.y = 0f;
				gameObject.transform.rotation = rot;
			}
		}

		//randomly choosing a new destination when it gets to its planet
		if (currentPlanet != null && destinationPlanet == null) {
			GoToRandomNeighbor (currentPlanet);
		}

		//walk around the currentplanet
		if (!flying && currentPlanet != null && destinationPlanet == null) {
			//TODO calculate ideal angle
			gameObject.transform.up = (gameObject.transform.position - currentPlanet.gameObject.transform.position).normalized;
		}

		//try to remain upright
		/*float angleDif = gameObject.transform.rotation.z - idealAngle;
		if (angleDif != 0) {
			angleDif = Mathf.Max (angleDif, angleDif * Time.deltaTime * 3f);
			var rot = gameObject.transform.rotation;
			rot.z -= angleDif;
			//Debug.Log (gameObject.transform.rotation + " " + angleDif + " " + rot);
			gameObject.transform.rotation = rot;
		}*/

		//catch the fallen ones
		/*if (gameObject.transform.position.y < CameraPanningScript.minDepth) {
			AbyssComponent.instance.CaptureSeedizen (this);
		}*/
	}
Esempio n. 10
0
	public void AttachToPlanet (PregenPlanet pc) {
		EndFlight ();
		currentPlanet = pc;
		destinationPlanet = null;
		GoToRandomNeighbor (pc);
	}
Esempio n. 11
0
	public void GoToRandomNeighbor (PregenVine vine) {
		if (vine == null)
			return;
		if (vine.ends.Count < 2) {
			Debug.Log ("Weird vine collision");
			return;
		}
		PregenPlanet dest;
		if (Random.Range (0, 2) == 0)
			dest = vine.ends [0];
		else
			dest = vine.ends [1];
		destinationPlanet = dest;
	}
Esempio n. 12
0
	/// <summary>
	/// It's assumed this will only be called when they're at the planet
	/// </summary>
	public void GoToRandomNeighbor (PregenPlanet planet) {
		if (planet == null)
			return;
		planet.ProcessSeedizen (this);
		//		var oldPlanet = planet;
		/*var options = new List <PregenPlanet> (planet.connectedPlanets);
		foreach (var p in planet.connectedPlanets)
			if (planet.vines [p].dispreferred)
				options.Remove (p);
		if (options.Count == 0) {
			destinationPlanet = null;
			return;
		}
		destinationPlanet = options [Random.Range (0, options.Count)];*/
		destinationPlanet = PregenPathfinding.GetDirection (planet, this);
		if (destinationPlanet == null)
			return;
		var oldVine = currentVine;
		if (destinationPlanet == null)
			return;
		currentVine = destinationPlanet.vines [planet];
		if (oldVine != null)
			oldVine.seedizens.Remove (this);
		if (!currentVine.seedizens.Contains (this))
			currentVine.seedizens.Add (this);
		idealAngle = 0f;
	}
Esempio n. 13
0
	public void StartFlight (Vector3 dir) {
		Debug.Log (dir);
		Vector2 dir2d = dir;

		flying = true;
		inTransit = false;
		if (currentVine != null)
			currentVine.seedizens.Remove (this);
		currentPlanet = null;
		destinationPlanet = null;
		currentVine = null;
		//flightDir = dir;

		//Debug.Log (this);
		//Debug.Log (gameObject);

		var rigid = gameObject.GetComponent <Rigidbody2D> ();
		rigid.gravityScale = 1f;


		rigid.AddForce (dir2d.normalized * Mathf.Sqrt (dir2d.magnitude) * 500f);
	}