コード例 #1
0
	private static bool PlanetIsDestination (PlanetComponent planet, SeedizenComponent seedizen) {
		if (seedizen.hasPollen) {
			return planet.hasDemands.NeedsPollenOf (seedizen);
		} else {
			return planet.planetType.makesPollen;
		}
	}
コード例 #2
0
	public void CaptureSeedizen (SeedizenComponent seed) {
		seed.gameObject.transform.position = rescueSpot;

		seed.AttachToPlanet (gameObject.GetComponent <PlanetComponent> ());

		seed.destinationPlanet = homePlanet;
	}
コード例 #3
0
	public static PlanetComponent GetDirection (PlanetComponent planet, SeedizenComponent seedizen) {
		var q = new Queue <PlanetComponent> ();
		var discovered = new HashSet <PlanetComponent> ();
		var pathTo = new Dictionary <PlanetComponent, PlanetComponent> ();

		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
				PlanetComponent curPlanet = p;
				while (curPlanet != null && pathTo.ContainsKey (curPlanet)) {
					var prevPlanet = pathTo [curPlanet];
					if (!pathTo.ContainsKey (prevPlanet))
						return curPlanet;
					curPlanet = prevPlanet;
				}
			}

			var neighbors = new List <PlanetComponent> (p.connectedPlanets);
			var neighbors2 = new List <PlanetComponent> ();
			//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 <PlanetComponent> (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)];
	}
コード例 #4
0
	public bool MeetDemandWithSeedizen (SeedizenComponent sc) {
		string d = sc.type;
		IsDemandBubble found = null;
		foreach (var db in myDemandBubbles) {
			if ((db.isGenericDemand || db.demanded == d) && db.isSeedizenDemand) {
				found = db;
				break;
			}
		}
		
		if (found) {
			myDemandBubbles.Remove (found);
			
			GameObject.Destroy (found.gameObject);
			
			if (myDemandBubbles.Count == 0)
				OnDemandsAllMet ();
			
			return true;
		} else {
			return false;
		}
	}
コード例 #5
0
	public bool NeedsPollenOf (SeedizenComponent sc) {
		string d = sc.type;
		foreach (var db in myDemandBubbles) {
			if (sc.hasPollen && (db.isGenericDemand || db.demanded == d) && !db.isSeedizenDemand) {
				return true;
			}
		}
		return false;
	}
コード例 #6
0
	public void ProcessSeedizen (SeedizenComponent seedizen)
	{
		if (planetType != null && planetType.makesPollen)
		{
			seedizen.TurnOnPollen ();
		}
		
		//Debug.Log ("I collided with: " + p.gameObject.name + " " + col.relativeVelocity.magnitude);
		
		//if (col.relativeVelocity.magnitude < 18f)
		//	AttachToPlanet (p);

		var hd = gameObject.GetComponent <HasDemands> ();
		if (hd.MeetDemandWithSeedizen (seedizen))
		{
			GameObject.Destroy (seedizen.gameObject);
		}

		if (hd.MeetDemandWithPollen (seedizen))
		{
			seedizen.TurnOffPollen ();
		}
	}
コード例 #7
0
	public void AddSeedizen (SeedizenComponent seed) {
		seedizens.Add (seed);
	}