private void Select(int playerIndex, bool multiselect) { long[] units = m_gameState.GetUnits(playerIndex).ToArray(); long selectedIndex = -1; long[] selection = m_unitSelection.GetSelection(playerIndex, playerIndex); if (selection.Length > 0) { selectedIndex = selection[0]; } if (!multiselect) { if (m_mapCursor != m_cameraController.MapCursor) { m_wasSelected.Clear(); } } VoxelData unitData = FindClosestTo(PlayerIndex, selectedIndex, units, false); if (unitData != null) { if (m_wasSelected.Count == 0) { m_unitSelection.Select(playerIndex, playerIndex, new[] { unitData.UnitOrAssetIndex }); } else { m_unitSelection.AddToSelection(playerIndex, playerIndex, new[] { unitData.UnitOrAssetIndex }); } m_wasSelected.Add(unitData.UnitOrAssetIndex); if (m_wasSelected.Count == 1) { IVoxelDataController dc = m_gameState.GetVoxelDataController(playerIndex, unitData.UnitOrAssetIndex); Coordinate coord = dc.Coordinate; coord = coord.ToWeight(m_cameraController.Weight); coord.Altitude += dc.ControlledData.Height; m_cameraController.MapPivot = coord.MapPos; m_cameraController.SetVirtualMousePosition(coord, true, false); m_mapCursor = m_cameraController.MapCursor; } } }
private void Update() { if (m_gameState.IsActionsMenuOpened(LocalPlayerIndex)) { return; } if (m_gameState.IsMenuOpened(LocalPlayerIndex)) { return; } if (m_gameState.IsContextActionInProgress(LocalPlayerIndex)) { return; } if (m_gameState.IsPaused || m_gameState.IsPauseStateChanging) { return; } int playerIndex = PlayerIndex; if (m_mapCursor != m_cameraController.MapCursor) { m_mapCursor = m_cameraController.MapCursor; VoxelData newSelectedTarget = null; VoxelData target = null; int width = m_map.Map.GetMapSizeWith(GameConstants.MinVoxelActorWeight); if (m_mapCursor.Row >= 0 && m_mapCursor.Col >= 0 && m_mapCursor.Row < width && m_mapCursor.Col < width) { MapCell cell = m_map.Map.Get(m_mapCursor.Row, m_mapCursor.Col, m_cameraController.Weight); for (int i = 0; i < m_selectedUnitDescriptors.Length; ++i) { SelectionDescriptor descriptor = m_selectedUnitDescriptors[i]; bool lowestPossible = true; cell.GetDefaultTargetFor(descriptor.Type, descriptor.Weight, playerIndex, lowestPossible, out target, playerIndex); if (target != null) { break; } } } if (target != null && target.VoxelRef != null && target.UnitOrAssetIndex != -1) { //Player could not destroy own units (and should not be able to select them as target) if (!VoxelData.IsControllableUnit(target.Type) || target.Owner != playerIndex) { newSelectedTarget = target; } } if (m_previouslySelected != newSelectedTarget) { if (newSelectedTarget == null) { ClearSelection(); m_selectedTarget = null; m_previouslySelected = null; } else { m_previouslySelected = newSelectedTarget; TryEnableTargetAutoSelectionMode(); if (m_isTargetAutoSelectionMode) { m_selectedTarget = newSelectedTarget; TargetSelectionSelect(playerIndex, target.Owner, m_selectedTarget.UnitOrAssetIndex); } } } } else { if (m_selectedTarget != null) { IVoxelDataController dc = m_gameState.GetVoxelDataController(m_selectedTarget.Owner, m_selectedTarget.UnitOrAssetIndex); if (dc != null && dc.IsAlive) { Coordinate cursorCoord = new Coordinate(m_cameraController.MapCursor, GameConstants.MinVoxelActorWeight, 0).ToWeight(dc.ControlledData.Weight); if (cursorCoord.MapPos != dc.Coordinate.MapPos) { Coordinate coord = dc.Coordinate.ToWeight(GameConstants.MinVoxelActorWeight); m_cameraController.MapPivot = coord.MapPos; m_cameraController.SetVirtualMousePosition(coord, true, false); m_mapCursor = m_cameraController.MapCursor; } } } } if (m_inputManager.GetButtonDown(InputAction.X, LocalPlayerIndex)) { bool hasSelected = m_targetSelection.HasSelected(playerIndex); Select(playerIndex); if (!hasSelected) { m_isTargetAutoSelectionMode = true; } } else if (m_inputManager.GetButtonUp(InputAction.RB, LocalPlayerIndex)) { m_isTargetAutoSelectionMode = false; ClearSelection(); } }
private void Update() { m_playersBot.Update(Time.realtimeSinceStartup); if (m_gameState.IsActionsMenuOpened(LocalPlayerIndex)) { return; } if (m_gameState.IsContextActionInProgress(LocalPlayerIndex)) { return; } if (m_gameState.IsMenuOpened(LocalPlayerIndex)) { return; } if (m_gameState.IsPaused || m_gameState.IsPauseStateChanging) { return; } if (m_inputManager.GetButtonDown(InputAction.A, LocalPlayerIndex) || m_inputManager.GetButtonDown(InputAction.RMB, LocalPlayerIndex)) { m_wasAButtonDown = true; CreateMovementCmd(false, cmd => { if (cmd != null && cmd.Count > 0) { MovementCmd movementCmd = (MovementCmd)cmd[0]; if (!m_inputManager.IsKeyboardAndMouse(LocalPlayerIndex)) { m_cameraController.SetVirtualMousePosition(movementCmd.Coordinates.Last(), true, true); } } }); } else if (m_inputManager.GetButtonUp(InputAction.A, LocalPlayerIndex) || m_inputManager.GetButtonUp(InputAction.RMB, LocalPlayerIndex)) { if (m_wasAButtonDown) { CreateMovementCmd(false, cmd => { if (cmd != null && cmd.Count > 0) { MovementCmd movementCmd = (MovementCmd)cmd[0]; if (!m_inputManager.IsKeyboardAndMouse(LocalPlayerIndex)) { m_cameraController.SetVirtualMousePosition(movementCmd.Coordinates.Last(), true, true); } SubmitToEngine(m_gameState.LocalToPlayerIndex(LocalPlayerIndex), cmd); } }); m_wasAButtonDown = false; } } else if (m_inputManager.GetButtonDown(InputAction.B, LocalPlayerIndex, false, false)) { OnCancel(); } else if (m_inputManager.GetButtonDown(InputAction.Y, LocalPlayerIndex, false, false)) { m_commandsPanel.IsOpen = true; } }