private static bool PlanetIsDestination (PlanetComponent planet, SeedizenComponent seedizen) {
		if (seedizen.hasPollen) {
			return planet.hasDemands.NeedsPollenOf (seedizen);
		} else {
			return planet.planetType.makesPollen;
		}
	}
Ejemplo n.º 2
0
        protected override void Initialize()
        {
            MakeRenderTargets();
            GlobalContent.Init(this.Content);

            IsMouseVisible = true;
            camera         = new EditorCamera(this);
            zComponents.Add(camera);
            var earth = new PlanetComponent(this, camera);

            zComponents.Add(earth);
            zComponents.Add(new CityMarker(this, camera, "Pensacola", 30.4668536, -87.3294527));
            zComponents.Add(new CityMarker(this, camera, "Anchorage", 61.2008367, -149.8923965));
#if WINDOWS || LINUX
            zComponents.Add(new ShipComponent(this, camera));
#else
            zComponents.Add(new PinchController(this, camera));
#endif
            zComponents.Add(new FPSCounter(this));
            zComponents.Add(debug = new DebugConsole(this));
            // TODO: just change the ordering to fix this? apparantly setting a render target clears the backbuffer due to Xbox stuff
            GraphicsDevice.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PreserveContents;
#if WINDOWS || LINUX
            if (!Directory.Exists(RECORD_PATH))
            {
                Directory.CreateDirectory(RECORD_PATH);
            }
#endif
            base.Initialize();
        }
Ejemplo n.º 3
0
	public void DeleteConnectedPlanet (PlanetComponent pc)
	{
		pc.vines [this] = null;
		vines [pc] = null;

		pc.connectedPlanets.Remove (this);
		connectedPlanets.Remove (pc);
	}
Ejemplo n.º 4
0
	public void AddConnectedPlanet (PlanetComponent pc, VineComponent v)
	{
		connectedPlanets.Add (pc);
		pc.connectedPlanets.Add (this);

		vines [pc] = v;
		pc.vines [this] = v;
	}
	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)];
	}
Ejemplo n.º 6
0
    public PlanetEntity(GameEntity planetE)
    {
        Planet   = planetE.planet;
        Position = planetE.position;
        Mass     = planetE.mass;
        Health   = planetE.health;

        if (planetE.hasCannon)
        {
            Cannon = planetE.cannon;
        }
        if (planetE.hasCooldownTimer)
        {
            CooldownTimer = planetE.cooldownTimer;
        }
    }
Ejemplo n.º 7
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 <PlanetComponent> ();
		var pt = planet.planetType;
		var vpc = gameObject.GetComponent <VictoryPlanetComponent> ();

		if (!startWithNoDemands && (vpc != null || pt != null && pt.hasDemands)) {
			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.growsFlower && planet.connectedPlanets.Count == 0) {

			//flowers need a person at first
			AddDemand ("", true, true);
		}
	}
Ejemplo n.º 8
0
    public void Setup(SolarModel model)
    {
        _model = model;

        SolarStore.Name     = _model.Name;
        SolarStore.MaxStock = _model.Lifetime;
        SolarStore.Stock    = _model.Lifetime;
        SolarStore.Property = _model.Radius + "";

        planets = new List <PlanetComponent>();
        for (int index = 0; index < _model.Planets.Count; index++)
        {
            GameObject      planet     = Instantiate(PlanetPrefab, PlanetsContainer);
            PlanetComponent planetView = planet.GetComponent <PlanetComponent>();
            planetView.Setup(_model.Planets[index]);
            planets.Add(planetView);
        }

        Observable.Interval(TimeSpan.FromSeconds(1))
        .Where(_ => _model.Lifetime > 0)
        .Subscribe(_ => _model.Lifetime -= 1)
        .AddTo(this);

        _model.rLifetime
        .Where(lifetime => lifetime == 0)
        .Subscribe(_ =>
        {
            Messenger.Dispatch(SolarMessage.SOLAR_DESTROYED, new SolarMessage(0, 0, _model));
            Destroy(gameObject);
        })
        .AddTo(this);

        _model.rLifetime
        .Subscribe(onLifetimeUpdate)
        .AddTo(this);
    }
Ejemplo n.º 9
0
	private void OnDemandsAllMet () {
		Debug.Log ("CONGRATULATIONS! You met all the demands of: " + gameObject.name);
        GetComponent<ParticleSystem>().Emit(Random.Range(10, 20));
        if (planet == null)
			planet = gameObject.GetComponent <PlanetComponent> ();
		var pt = planet.planetType;

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

		if (pt.growsFlower && planet.flower != null) {
			planet.flower.IncrementNumBridges ();
		} else if (pt.produces != "") {
			ResourcesDisplay.instance.Add (Random.Range (1,2), pt.produces);
		}

		if (planet != null && planet.flower != null && planet.flower.numBridges > 0 && planet.planetType != null && planet.planetType.growsFlower) {
			Debug.Log ("Doing nothing");
			//do nothing. Flowers wait until they are out of bridges
		} else 
			GainPollenAfterWait (Random.Range (5f, 10f));
	}
Ejemplo n.º 10
0
	// 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);
		}*/
	}
Ejemplo n.º 11
0
	public void AttachToPlanet (PlanetComponent pc) {
		EndFlight ();
		currentPlanet = pc;
		destinationPlanet = null;
		GoToRandomNeighbor (pc);
	}
Ejemplo n.º 12
0
	public void GoToRandomNeighbor (VineComponent vine) {
		if (vine == null)
			return;
		if (vine.ends.Count < 2) {
			Debug.Log ("Weird vine collision");
			return;
		}
		PlanetComponent dest;
		if (Random.Range (0, 2) == 0)
			dest = vine.ends [0];
		else
			dest = vine.ends [1];
		destinationPlanet = dest;
	}
Ejemplo n.º 13
0
	/// <summary>
	/// It's assumed this will only be called when they're at the planet
	/// </summary>
	public void GoToRandomNeighbor (PlanetComponent planet) {
		if (planet == null)
			return;
		planet.ProcessSeedizen (this);
		//		var oldPlanet = planet;
		/*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) {
			destinationPlanet = null;
			return;
		}
		destinationPlanet = options [Random.Range (0, options.Count)];*/
		destinationPlanet = PathfindingManager.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;
	}
Ejemplo n.º 14
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);
	}
Ejemplo n.º 15
0
    // Update is called once per frame
    void Update()
    {
        Verse.Update();

        if (Input.GetKeyDown(KeyCode.Tab))
        {
            Verse.NextShip();
        }

        if (Input.GetButtonDown("map"))
        {
            switch (viewMode)
            {
            case ViewMode.Ship:
            case ViewMode.TacticalMap:
                SetMode(ViewMode.Map);
                break;

            case ViewMode.Map:
            case ViewMode.SolarMap:
                SetMode(ViewMode.Ship);
                break;
            }
        }
        else if (Input.GetButtonDown("TacticalMap"))
        {
            switch (viewMode)
            {
            case ViewMode.Ship:
            case ViewMode.Map:
            case ViewMode.SolarMap:
                SetMode(ViewMode.TacticalMap);
                break;

            case ViewMode.TacticalMap:
                SetMode(ViewMode.Ship);
                break;
            }
        }
        if (viewMode == ViewMode.Map || viewMode == ViewMode.SolarMap)
        {
            if (Input.GetMouseButtonDown(0))
            {
                Camera  camera = galaxy.GetComponent <GalaxyComponent>().Camera;
                Vector2 ray    = camera.ScreenToWorldPoint(Input.mousePosition);

                RaycastHit2D hitInfo = Physics2D.Raycast(ray, ray, 0.0f);

                if (viewMode == ViewMode.Map && hitInfo.transform != null && hitInfo.transform.GetComponent <SolarSystemComponent>() != null)
                {
                    if (hitInfo.transform.gameObject == oldHitObject && (Time.time - hitTime) < 0.5f)
                    {
                        SolarSystemComponent ssc = hitInfo.transform.GetComponent <SolarSystemComponent>();
                        solarMap = ssc.DisplaySystem();
                        SetMode(ViewMode.SolarMap, ssc.Emitter);

                        Debug.Log(ssc.Emitter.Name);
                    }

                    oldHitObject = hitInfo.transform.gameObject;
                    hitTime      = Time.time;
                    //GUIController.childs["star_menu"].Show();
                }
                else if (viewMode == ViewMode.SolarMap && hitInfo.transform != null && hitInfo.transform.GetComponentInParent <PlanetComponent>() != null)
                {
                    PlanetComponent pc = hitInfo.transform.GetComponentInParent <PlanetComponent>();
                    GUIController.childs["planet_menu"].Show();
                    GUIController.childs["planet_menu"].GameObject.transform.position = camera.WorldToScreenPoint(pc.transform.position);
                    GUIController.childs["planet_menu"].SetParameters(new object[] { pc.Emitter });
                }
                else if (hitInfo.transform == null || hitInfo.transform.GetComponent <WidgetComponent>() == null)
                {
                    if (GUIController.HoverObject == null)
                    {
                        //GUIController.childs["star_menu"].Hide();
                        GUIController.childs["planet_menu"].Hide();
                    }
                }
            }
        }

        Vector3 mousePos = cameraController.mainCamera.ScreenToViewportPoint(Input.mousePosition);

        if (cameraController.tacticalMapCamera.rect.Contains(mousePos))
        {
            //Debug.Log("Mouse is on tacmap.");
            if (Input.GetButtonDown("Fire1"))
            {
                shipController.Ship.AddWaypoint(
                    cameraController.tacticalMapCamera.ScreenToWorldPoint(Input.mousePosition)
                    );
                //Debug.Log(cameraController.tacticalMapCamera.ScreenToWorldPoint(Input.mousePosition));
            }
        }
    }
Ejemplo n.º 16
0
	// Update is called once per frame
	void Update () {
		//mouse
		Vector3 pz = Camera.main.ScreenToWorldPoint(Input.mousePosition);
		pz.z = 0;
		if (useGrid && state == editingState.planets) {
			pz.x = (int)pz.x;
			pz.y = (int)pz.y;
		}
		if (underCursor != null) {
			underCursor.transform.position = pz;
		}

		//right click escapes
		if (Input.GetMouseButton (1)) {
			GameObject.Destroy (currentlyPlacing);
			GameObject.Destroy (underCursor);
			End ();
		}

		switch (state) {
		case editingState.planets:
			if (Input.GetMouseButton (0)) {
				if (currentlyTyped != null) {
					var pd = new PlacementDetails (currentlyTyped, currentlyPlacing.transform.position);
					pd.thePlanetGob = currentlyPlacing;
					record.Add (pd);
				}
				currentlyPlacing = null;
				currentlyTyped = null;
				underCursor = null;
				state = editingState.none;
			}
			break;
		case editingState.vine:
			//TODO stretch
			if (vineEnd1 != null) {
				Vector3 end2 = Vector3.zero;
				if (vineEnd2 != null)
					end2 = vineEnd2.transform.position;
				else 
					end2 = pz;
				FlowerDragManager.PlaceVine (vineEnd1.transform.position, end2, vine);
			}

			if (Input.GetMouseButtonDown (0) && currentPlanetByMouse != null) {
				if (vineEnd1 == null) {
					//Debug.Log ("Vine1");
					vineEnd1 = currentPlanetByMouse;
					
					vine.gameObject.transform.SetAsFirstSibling ();
					//startPos = flo.gameObject.transform.parent.position;
				} else if (currentPlanetByMouse != vineEnd1) {
					//Debug.Log ("Vine2");
					vineEnd2 = currentPlanetByMouse;
					
					//record vine
					PlacementDetails p1 = null;
					PlacementDetails p2 = null;
					foreach (var p in record) {
						if (p.thePlanetGob == currentPlanetByMouse.gameObject)
							p1 = p;
						if (p.thePlanetGob == vineEnd1.gameObject)
							p2 = p;
					}
					if (p1 != null && p2 != null)
						p1.AddVineNeighbor (p2);
					else
						Debug.Log ("Vine recording problem: " + p1 + "-" + p2);

					//straighten out the end
					Vector3 end2 = Camera.main.ScreenToWorldPoint(Input.mousePosition);
					FlowerDragManager.PlaceVine (vineEnd1.transform.position, end2, vine);

					//end
					vineEnd1 = null;
					vineEnd2 = null;
					vine = null;
					state = editingState.none;
					currentlyPlacing = null;
					underCursor = null;
				}
			}
			break;
		case editingState.flower:
			if (Input.GetMouseButtonDown (0) && currentPlanetByMouse != null) {
				//give the planet a flower
				//record flower
				foreach (var p in record) {
					if (p.thePlanetGob == currentPlanetByMouse.gameObject)
						p.hasFlower = true;
				}

				End ();
			}
			break;
		case editingState.demands:
			if (Input.GetMouseButtonDown (0) && currentPlanetByMouse != null && currentDemand != "") {
				//TODO record demand
				//Debug.Log ("Adding demand: "+ currentDemand);
				currentPlanetByMouse.hasDemands.AddDemand (currentDemand, false, false);
			}
			break;
		}
	}
Ejemplo n.º 17
0
	public static void RegisterNoMouseOnPlanet (PlanetComponent planet) {
		if (currentPlanetByMouse == planet)
			currentPlanetByMouse = null;
	}
Ejemplo n.º 18
0
	public static void RegisterMouseOnPlanet (PlanetComponent planet) {
		currentPlanetByMouse = planet;
	}
Ejemplo n.º 19
0
	void End () {
		state = editingState.none;
		currentlyPlacing = null;
		currentlyTyped = null;
		underCursor = null;
		vineEnd1 = null;
		vineEnd2 = null;
		vine = null;
		currentDemand = "";
	}
Ejemplo n.º 20
0
 void Awake()
 {
     planetComponent            = this.GetComponent <PlanetComponent>();
     transmissionRendererPrefab = Resources.Load("TransmissionLineRenderer") as GameObject;
 }