/// <summary> /// Executes behavior with given context /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public override BehaviorReturnCode Behave(IBehaviorContext context) { UnitBehaviorContext unitContext = context as UnitBehaviorContext; if (unitContext == null) { returnCode = BehaviorReturnCode.Failure; return(returnCode); } ColonyShip unit = unitContext.Unit as ColonyShip; if (unit == null || !unit.IsOnOrbit) { returnCode = BehaviorReturnCode.Failure; return(returnCode); } Planet planet = unitContext.EnvironmentTarget as Planet; if (planet == null) { returnCode = BehaviorReturnCode.Failure; return(returnCode); } ColonizeTask task = new ColonizeTask(unit, planet); returnCode = BehaviorReturnCode.Success; return(returnCode); }
void HandleShipSelectionChanged(ShipNames newShipName) { if (gameCore.ColonyShips.TryGetValue(newShipName, out ColonyShip chosenShip)) { FocusShip = chosenShip; } }
private void InstantiateColonyShip() { Empire empire = localSystem.GetEmpire(); ColonyShip ship = Instantiate(empire.GetColonyShipPrefab(), empire.transform.Find("ColonyShips").transform).GetComponent <ColonyShip>(); ship.GetComponent <MovementController>().SetLocation(localSystem); empire.AddColonyShip(ship); }
// Called when the node enters the scene tree for the first time. public override void _Ready() { parentShip = GetNode <ColonyShip>("../"); TurretControls = new TurretControls(this); cooldowns = new float[tubeCount]; TurretControls.OnTubeTriggered += HandleTubeTriggered; }
private void HandleFocusShipWarped(ColonyShip ship, string oldSolarSystem, string newSolarSystem) { gameCore.MainCamera.GetParent()?.RemoveChild(gameCore.MainCamera); var destinationViewportContainer = gameCore.SolarSystemViewportContainersByName[newSolarSystem]; destinationViewportContainer.GetChild(0).AddChild(gameCore.MainCamera); gameCore.MoveChild(destinationViewportContainer, gameCore.GetChildCount() - 1); }
public void SetFocusShip(ColonyShip ship) { for (int i = 0; i < optionButton.GetItemCount(); i++) { if (optionButton.GetItemText(i).CompareTo(ship.ShipName.ToString()) == 0) { optionButton.Select(i); } } }
void RefreshText(ColonyShip focusShip) { missionAccomplishedLabel.Text = focusShip.MissionResult; shipName.Text = focusShip.Name; timeTakenData.Text = focusShip.TimeElapsed.ToString("0.000"); damageTakenData.Text = focusShip.TotalDamage.ToString(); collisionsNumber.Text = focusShip.TotalCollisionCount.ToString(); torpedoesFired.Text = focusShip.TorpedoesFired.ToString(); scanEnergyUsed.Text = focusShip.TotalScanEnergy.ToString(); jumpCost.Text = focusShip.TotalJumpCost.ToString(); }
void HandleFocusShipIsLandedChanged(ColonyShip focusShip, bool hasLanded) { if (hasLanded) { RefreshText(focusShip); Visible = true; } else { Visible = false; } }
private void HandleFocusShipChanged(ColonyShip oldFocus, ColonyShip newFocus) { //Unsubscibe if (oldFocus != null) { oldFocus.IsLandedChanged -= HandleFocusShipIsLandedChanged; } //Subscribe if (newFocus != null) { newFocus.IsLandedChanged += HandleFocusShipIsLandedChanged; RefreshText(newFocus); } }
public void SetFocusShip(ColonyShip ship) { if (ship == null) { GD.PrintErr("Cannot SetFocusShip(null)"); return; } this.focusShip = ship; tube0ProgressBar.MaxValue = focusShip.Turret.CooldownDuration; tube1ProgressBar.MaxValue = focusShip.Turret.CooldownDuration; tube2ProgressBar.MaxValue = focusShip.Turret.CooldownDuration; tube3ProgressBar.MaxValue = focusShip.Turret.CooldownDuration; }
public void BuildColonyShip() { ColonyShip ship = new ColonyShip(ColonyShip.GetColonyShipName()); ShipList.Add(ship); GameObject shipObject = Instantiate(colShipPrefab); Vector3 BuildLocation = um.currentlySelectedGO.transform.position; BuildLocation.y += 1; shipObject.transform.position = BuildLocation; shipObject.transform.SetParent(this.transform); ShipToObjectMap.Add(ship, shipObject); }
public void SetFocusShip(ColonyShip ship) { //Unsubscribe from old if (focusShip != null) { focusShip.PropulsionController.IsProcessingChanged -= HandlePropulsionControllerProcessingChanged; focusShip.ThrusterControls.OnUFODriveEnabledChanged -= HandleUFODriveEnabledChanged; //focusShip.OnPropulsionModeChanged -= HandleShipPropulsionModeChanged; focusShip = null; } //Subscribe to new focusShip = ship; focusShip.PropulsionController.IsProcessingChanged += HandlePropulsionControllerProcessingChanged; focusShip.ThrusterControls.OnUFODriveEnabledChanged += HandleUFODriveEnabledChanged; HandlePropulsionControllerProcessingChanged(focusShip.PropulsionController, focusShip.PropulsionController.IsProcessing); HandleUFODriveCheckBoxChanged(focusShip.ThrusterControls.IsUFODriveEnabled); //focusShip.OnPropulsionModeChanged += HandleShipPropulsionModeChanged; //HandleShipPropulsionModeChanged(focusShip, focusShip.PropulsionMode); }
void HandleFocusShipChanged(ColonyShip oldFocusShip, ColonyShip newFocusShip) { //Unsubscribe if (oldFocusShip != null) { oldFocusShip.OnShipWarped -= HandleFocusShipWarped; } MainCamera mainCamera = gameCore.MainCamera; mainCamera.GetParent().RemoveChild(mainCamera); mainCamera.SetFocus(newFocusShip); //var startingViewportContainer = gameCore.SolarSystemViewportContainersByName[gameCore.GalaxyMap.StartingNode.Name]; var targetViewportContainer = newFocusShip.FindParent("*ViewportContainer*"); targetViewportContainer.GetChild(0).AddChild(mainCamera); sensorsSubsystemInformationPanel.SetFocusShip(focusShip); propulsionSubsystemInformationPanel.SetFocusShip(focusShip); defenceSubsystemInformationPanel.SetFocusShip(focusShip); shipSelectPanel.SetFocusShip(focusShip); //Update viewport containers var currentViewportContainer = gameCore.SolarSystemViewportContainersByName[focusShip.CurrentSolarSystemName]; gameCore.MoveChild(currentViewportContainer, gameCore.GetChildCount() - 1); //Subscribe focusShip.OnShipWarped += HandleFocusShipWarped; // Shows/Hides mission accomplished screen if (newFocusShip != null) { gameCore.MissionAccomplishedUI.SetFocusShip(focusShip); gameCore.MissionAccomplishedUI.Visible = newFocusShip.IsLanded; } }
public bool Select(Player player) { if (hasShip && owner == player.netId) { if (player.isBuyingBoosterUpgrade) { if (player.Purchase(PurchaseManager.UpgradeBooster)) { NetworkServer.FindLocalObject(associatedShip).GetComponent <Ship>().Boosters++; } } else if (player.isBuyingBlasterUpgrade && hasLocalPlayerFleetVessel) { if (player.Purchase(PurchaseManager.UpgradeBlaster)) { NetworkServer.FindLocalObject(associatedShip).GetComponent <FleetVessel>().Blasters++; } } else if (player.isBuyingTractorBeamUpgrade && hasLocalPlayerFleetVessel) { if (player.Purchase(PurchaseManager.UpgradeTractorBeam)) { NetworkServer.FindLocalObject(associatedShip).GetComponent <FleetVessel>().TractorBeams++; } } else { if (NetworkServer.FindLocalObject(associatedShip).GetComponent <Ship>().IsDisabled) { return(false); } //clicking on my ship space, select it selected = !selected; GameManager.singleton.selectedCell = selected ? this : null; if (selected) { foreach (GameCell cell in NetworkServer.FindLocalObject(associatedShip).GetComponent <Ship>().nearbyCells) { if (cell.state == GameCellState.Empty || cell.state == GameCellState.ShipBuildArea || (cell.state == GameCellState.TempusSpace && player.reputation >= GameManager.singleton.tempusReputation)) { cell.SetCell(player, GameCellState.MovementArea); } } } else { foreach (GameCell cell in NetworkServer.FindLocalObject(associatedShip).GetComponent <Ship>().nearbyCells) { if (cell.state == GameCellState.MovementArea) { cell.Revert(); } } } } } else if (state == GameCellState.ShipBuildArea && owner == player.netId) { if (player.isBuyingFleetVessel && player.Purchase(PurchaseManager.FleetVessel)) { GameObject objShip = (GameObject)Instantiate(prefabFleetVessel, transform.position, Quaternion.identity); NetworkServer.Spawn(objShip); FleetVessel ship = objShip.GetComponent <FleetVessel>(); ship.Color = player.color; ship.ownerId = player.netId; ship.associatedCell = this.netId; player.fleetVessels.Add(ship); SetCell(player, GameCellState.Empty, true, ship.netId); return(true); } else if (player.isBuyingColonyShip && player.Purchase(PurchaseManager.ColonyShip)) { GameObject objShip = (GameObject)Instantiate(prefabColonyShip, transform.position, Quaternion.identity); NetworkServer.Spawn(objShip); ColonyShip ship = objShip.GetComponent <ColonyShip>(); ship.Color = player.color; ship.ownerId = player.netId; ship.associatedCell = this.netId; SetCell(player, GameCellState.Empty, true, ship.netId); return(true); } } else if (state == GameCellState.MovementArea && owner == player.netId) { foreach (GameCell cell in NetworkServer.FindLocalObject(GameManager.singleton.selectedCell.associatedShip).GetComponent <Ship>().nearbyCells) { if (cell.state == GameCellState.MovementArea) { cell.Revert(); } } //move the ship SetCell(player, true, GameManager.singleton.selectedCell.associatedShip); GameManager.singleton.selectedCell.SetCell(false, NetworkInstanceId.Invalid); GameManager.singleton.selectedCell = null; NetworkServer.FindLocalObject(associatedShip).GetComponent <Ship>().MoveTo(this.netId); return(true); } else if (state == GameCellState.Depot && owner == player.netId) { if (player.isBuyingStarport && player.Purchase(PurchaseManager.Starport)) { SetCell(player, GameCellState.Starport); NetworkServer.Destroy(NetworkServer.FindLocalObject(associatedStation)); GameObject obj = (GameObject)Instantiate(prefabStarport, transform.position, Quaternion.identity); Starport starport = obj.GetComponent <Starport>(); starport.color = player.color; starport.owner = player; NetworkServer.Spawn(obj); associatedStation = starport.netId; //player.depots.Add(depot); return(true); } } else if (state == GameCellState.DepotBuildArea && owner == player.netId) { if (player.isBuyingDepot && player.Purchase(PurchaseManager.Depot)) { SetCell(player, GameCellState.Depot); GameObject objDepot = (GameObject)Instantiate(prefabDepot, transform.position, Quaternion.identity); Depot depot = objDepot.GetComponent <Depot>(); depot.color = player.color; depot.owner = player; NetworkServer.Spawn(objDepot); associatedStation = depot.netId; //player.depots.Add(depot); return(true); } } return(false); }
void HandleColonyShipSpawned(ColonyShip newColonyShip) { optionButton.AddItem(newColonyShip.ShipName.ToString()); }
public void SetFocusShip(ColonyShip ship) { this.focusShip = ship; }
public static void Update(UnityModManager.ModEntry modData, float tDelta) { // Set up manager here, where it's guaranteed to be initialized. if (_Manager is null) { _Manager = GameManager.getInstance(); } // Get intro and try to cast it as an IntroCinematic. If that fails, exit. if (Intro is null) { Intro = CameraManager.getInstance().getCinematic() as IntroCinemetic; if (Intro is null) { return; } // Reflection to get ship. Ship = Intro .GetType() .GetField("mColonyShip", instanceFlags) .GetValue(Intro) as ColonyShip; } // Check if ship is done. Also run if ship is null. if (Ship?.isDone() ?? true) { Intro = null; return; } var state = _Manager.getGameState() as GameStateGame; var gameInterface = state .GetType() .GetField("mGameGui", instanceFlags) .GetValue(state) as GameGui; // Disable Menu if (gameInterface.getWindow() is GuiGameMenu) { gameInterface.setWindow(null); } if (Input.GetKeyUp(KeyCode.Escape)) { // I removed a null check for Intro here since we only get here if the cutscene isn't null // and that only happens during the intro cutscene. PhysicsUtil.findFloor( Ship.getPosition(), out Vector3 shipLandingPosition, _LayerMask); shipLandingPosition.y += CameraManager.DefaultHeight; // Snap the camera to the ground and make it look at the landing spot Transform cameraTransform = CameraManager.getInstance().getTransform(); Vector3 localBackupVector = Ship.getDirection().flatDirection() * BackupDistance; cameraTransform.position = shipLandingPosition + localBackupVector; cameraTransform.LookAt(shipLandingPosition); // Set vertical angle Vector3 euler = cameraTransform.eulerAngles; euler.x = VerticalAngle; cameraTransform.rotation = Quaternion.Euler(euler); // Remove black bars Intro .GetType() .GetField("mBlackBars", instanceFlags) .SetValue(Intro, 0f); CameraManager.getInstance().setCinematic(null); Intro = null; } }
void LoadGalaxy(PackedScene galaxyScene) { GalaxyMap = galaxyScene.Instance() as GalaxyMap; hudRoot.AddChild(GalaxyMap); GalaxyMap.Visible = false; //Randomize galaxy map edge weights? if (simulationMode == SimulationMode.Gamma && galaxySeed != 0) { GalaxyMap.RandomizeEdgeWeights(galaxySeed); } foreach (GalaxyMapNode mapNode in GalaxyMap.Nodes) { var newSolarSystem = LoadSolarSystemIntoViewportContainer(mapNode.Name); } var startingViewportContainer = SolarSystemViewportContainersByName[GalaxyMap.StartingNode.Name]; MoveChild(startingViewportContainer, GetChildCount() - 1); //Spawn colony ships ColonyShip firstColonyShip = null; for (int i = 0; i < colonyShipScenes.Count; i++) { var newColonyShip = colonyShipScenes[i].Instance() as ColonyShip; //newColonyShip.LandingSequenceTriggered += HandleColonyShipLandingSequenceTriggered; ColonyShips.Add(newColonyShip.ShipName, newColonyShip); //Move colony ship back to origin if (newColonyShip != null) { if (newColonyShip.GetParent() != null) { newColonyShip.GetParent().RemoveChild(newColonyShip); } SolarSystemViewportContainersByName[GalaxyMap.StartingNode.Name].GetChild(0).AddChild(newColonyShip); //gameObjectsRoot.AddChild(newColonyShip); newColonyShip.CurrentSolarSystemName = GalaxyMap.StartingNode.Name; newColonyShip.GlobalPosition = Vector2.Left * 100f + Vector2.Up * 100f * i; } OnColonyShipSpawned?.Invoke(newColonyShip); if (firstColonyShip == null) { firstColonyShip = newColonyShip; } } //Set camera/info panel focus ColonyShip focusShip = null; foreach (var pair in ColonyShips) { if (pair.Key == startFocusedOnShip) { focusShip = pair.Value; } } if (focusShip == null) { GD.PrintErr("No focus ship designed in GameCore inspector panel. Choosing Nostromo by default."); focusShip = ColonyShips[ShipNames.Nostromo]; } else { shipInfoPanels.FocusShip = focusShip; } }
public void AddColonyShip(ColonyShip ship) { ship.SetEmpire(this); colonyShips.Add(ship); UpdateVisibleObject(ship.gameObject, true); }
public MapManager(int width, int height, int a_lenSide, int xOffset, int yOffset, GraphicsDevice device) { this.gridVerts = new List <VertexPositionColor>(); this.ships = new List <BaseShip>(); this.ownedHexes = new List <HexCell>(); this.resourceVerts = new List <VertexPositionColor>(); this.width = width; this.height = height; this.xOffset = xOffset; this.yOffset = yOffset; this.lenSide = a_lenSide; hexes = new HexCell[height, width]; resources = new ResourceObject[height, width]; basicAI = new BasicAI(); effect = new BasicEffect(device, null); effect.VertexColorEnabled = true; float h = Global.Instance.CalculateH(lenSide); float r = Global.Instance.CalculateR(lenSide); float hexWidth = 0; float hexHeight = 0; hexWidth = r + r; hexHeight = lenSide + h; this.pixelWidth = (width * hexWidth) + r; this.pixelHeight = (height * hexHeight) + h; bool inTopRow = false; bool inBottomRow = false; bool inLeftColumn = false; bool inRightColumn = false; bool isTopLeft = false; bool isTopRight = false; bool isBottomLeft = false; bool isBottomRight = false; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { #region Position Booleans if (i == 0) { inTopRow = true; } else { inTopRow = false; } if (i == height - 1) { inBottomRow = true; } else { inBottomRow = false; } if (j == 0) { inLeftColumn = true; } else { inLeftColumn = false; } if (j == width - 1) { inRightColumn = true; } else { inRightColumn = false; } if (inTopRow && inLeftColumn) { isTopLeft = true; } else { isTopLeft = false; } if (inTopRow && inRightColumn) { isTopRight = true; } else { isTopRight = false; } if (inBottomRow && inLeftColumn) { isBottomLeft = true; } else { isBottomLeft = false; } if (inBottomRow && inRightColumn) { isBottomRight = true; } else { isBottomRight = false; } #endregion // Calculate hex positions. if (isTopLeft) { // First hex. hexes[0, 0] = new HexCell(new Vector3(0 + r + xOffset, 0 + yOffset, 0), lenSide, new Vector2(0, 0)); } else { if (inLeftColumn) { // Calculate from hex above and stagger the rows. if (i % 2 == 0) { hexes[i, j] = new HexCell(hexes[i - 1, j].vertices[(int)HexVertice.BottomLeft].Position, lenSide, new Vector2(j, i)); } else { hexes[i, j] = new HexCell(hexes[i - 1, j].vertices[(int)HexVertice.BottomRight].Position, lenSide, new Vector2(j, i)); } } else { // Calculate from hex to the left. float x = hexes[i, j - 1].vertices[(int)HexVertice.TopRight].Position.X; float y = hexes[i, j - 1].vertices[(int)HexVertice.TopRight].Position.Y; x += r; y -= h; hexes[i, j] = new HexCell(new Vector3(x, y, 0), lenSide, new Vector2(j, i)); } } } } selectionHex = new HexCell(hexes[0, 0].GetPos() + new Vector3(0, (int)(lenSide * 0.2), 0), (int)(lenSide * 0.8), new Vector2(0, 0)); hoverHex = new HexCell(hexes[0, 0].GetPos() + new Vector3(0, (int)(lenSide * 0.01), 0), (int)(lenSide * 0.99), new Vector2(0, 0)); // Combine each hex vertex list into grid vertex list. for (int i = 0; i < hexes.GetLength(0); i++) { for (int j = 0; j < hexes.GetLength(1); j++) { gridVerts.AddRange(hexes[i, j].vertices.ToArray()); } } // Load layer 1 (resources). // Assign resources to each hex location. for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { resources[i, j] = new ResourceObject((int)Global.PlayerOwners.None, hexes[i, j], (int)Global.Instance.rand.Next(0, 4)); } } // Create some visually linear distributions of black holes to act as 'walls' for A*. int blackholeStreaks = (int)Global.Instance.rand.Next(7, 14); for (int i = 0; i < blackholeStreaks; i++) { Vector2 streakCoords = new Vector2(Global.Instance.rand.Next(1, Global.Instance.HexGridSizeX - 2), Global.Instance.rand.Next(1, Global.Instance.HexGridSizeY - 2)); int streakLength = (int)Global.Instance.rand.Next(9, 15); int streakDirection = 0; for (int j = 0; j < streakLength; j++) { resources[(int)streakCoords.Y, (int)streakCoords.X].resourceType = 9; hexes[(int)streakCoords.Y, (int)streakCoords.X].toggleHasShip(true); streakDirection = Global.Instance.rand.Next(0, 6); bool oddRow = streakCoords.Y % 2 > 0 ? true : false; Vector2 nextCoords = streakCoords; if (oddRow) { switch (streakDirection) { case 0: // TopRight exit nextCoords.X += 1.0f; nextCoords.Y += 1.0f; break; case 1: // Right exit nextCoords.X += 1.0f; break; case 2: // BottomRight exit nextCoords.X += 1.0f; nextCoords.Y -= 1.0f; break; case 3: // BottomLeft exit nextCoords.Y -= 1.0f; break; case 4: // Left exit nextCoords.X -= 1.0f; break; case 5: // TopLeft exit nextCoords.Y += 1.0f; break; } } else if (!oddRow) { switch (streakDirection) { case 0: // TopRight exit nextCoords.Y += 1.0f; break; case 1: // Right exit nextCoords.X += 1.0f; break; case 2: // BottomRight exit nextCoords.Y -= 1.0f; break; case 3: // BottomLeft exit nextCoords.Y -= 1.0f; nextCoords.X -= 1.0f; break; case 4: // Left exit nextCoords.X -= 1.0f; break; case 5: // TopLeft exit nextCoords.Y += 1.0f; nextCoords.X -= 1.0f; break; } } // Skip if it's a border tile. if ((nextCoords.X < 1 || nextCoords.X > Global.Instance.HexGridSizeX - 2) || (nextCoords.Y < 1 || nextCoords.Y > Global.Instance.HexGridSizeY - 2)) { // streakCoords remain the same. } else { streakCoords = nextCoords; } // This location becomes a black hole. (hasShip has an unfortunate name.) resources[(int)streakCoords.Y, (int)streakCoords.X].resourceType = 9; hexes[(int)streakCoords.Y, (int)streakCoords.X].toggleHasShip(true); } } // Load layer 2 (ships) // Player starts off with one colony ship. ColonyShip playerBeginningShip = new ColonyShip((int)Global.PlayerOwners.User, hexes[0, 0]); ships.Add(playerBeginningShip); hexes[0, 0].toggleHasShip(true); ships[0].selected = true; // Computer starts off with a scout. ScoutShip computerBeginningShip = new ScoutShip((int)Global.PlayerOwners.Computer1, hexes[height - 1, width - 1]); ships.Add(computerBeginningShip); basicAI.AddAI(ships[1]); hexes[height - 1, width - 1].toggleHasShip(true); }
public void RemoveColonyShip(ColonyShip colonyShip) { colonyShips.Remove(colonyShip); UpdateVisibleObject(colonyShip.gameObject, false); }
public bool TryTeleportShip(ColonyShip ship, out string newSolarSystemName, out float jumpCost) { if (destinationSolarSystemName == null) { newSolarSystemName = currentSolarSystemName; jumpCost = 0f; return(false); } float edgeCost = -1f; foreach (var edgeData in gameCore.GalaxyMap.GalaxyMapData.edgeData) { if (edgeData.nodeA.systemName == currentSolarSystemName) { if (edgeData.nodeB.systemName == destinationSolarSystemName) { edgeCost = edgeData.edgeCost; break; } } else if (edgeData.nodeB.systemName == currentSolarSystemName) { if (edgeData.nodeA.systemName == destinationSolarSystemName) { edgeCost = edgeData.edgeCost; break; } } } if (edgeCost == -1f) { newSolarSystemName = currentSolarSystemName; jumpCost = 0f; return(false); } //Record the ship's position offset relative to this outbound gate Vector2 positionOffset = ship.GlobalPosition - this.GlobalPosition; //Add ship to new solar system ship.GetParent()?.RemoveChild(ship); var destinationSolarSystem = gameCore.SolarSystemViewportContainersByName[destinationSolarSystemName].GetChild(0).GetChild(0); destinationSolarSystem.AddChild(ship); //Find the incoming warpgate and position the ship relative to it Node targetNode = destinationSolarSystem.FindNode("WarpGate to " + currentSolarSystemName, true); WarpGate incomingWarpGate = targetNode as WarpGate; ship.GlobalPosition = incomingWarpGate.GlobalPosition + positionOffset; ship.CurrentSolarSystemName = incomingWarpGate.currentSolarSystemName; newSolarSystemName = incomingWarpGate.currentSolarSystemName; jumpCost = edgeCost; return(true); }