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; } } }
public void Execute(Cmd[] commands, long tick, long lagTicks) { HashSet <long> deadUnitsHs = null; List <long> spawnedUnitsList = null; for (int c = 0; c < commands.Length; ++c) { Cmd cmd = commands[c]; if (cmd == null) { continue; } if (cmd.Code == CmdCode.LeaveRoom) { m_isInRoom = false; } else { IMatchUnitControllerCli unitController = m_idToUnit[cmd.UnitIndex]; long duration = cmd.Duration; duration -= lagTicks; duration = Math.Max(0, duration); cmd.Duration = (int)duration; IVoxelDataController dc = unitController.DataController; Coordinate prevCoord = dc.Coordinate; int radius = unitController.DataController.Abilities.VisionRadius; unitController.ExecuteCommand(cmd, tick); if (prevCoord != dc.Coordinate) { HandleCoordinateChange(dc, prevCoord, radius); } IList <VoxelDataCellPair> createdVoxels = unitController.CreatedVoxels; if (createdVoxels.Count != 0) { CreateAssets(createdVoxels); for (int i = 0; i < m_otherPlayerControllers.Length; ++i) { m_otherPlayerControllers[i].CreateAssets(createdVoxels); } } IList <VoxelData> eatenOrDestroyed = unitController.EatenOrDestroyedVoxels; if (eatenOrDestroyed.Count != 0) { RemoveAssets(eatenOrDestroyed); for (int i = 0; i < m_otherPlayerControllers.Length; ++i) { m_otherPlayerControllers[i].RemoveAssets(eatenOrDestroyed); } } if (cmd.Code == CmdCode.Composite) { CompositeCmd compositeCmd = (CompositeCmd)cmd; for (int i = 0; i < compositeCmd.Commands.Length; ++i) { spawnedUnitsList = PostprocessCommand(spawnedUnitsList, compositeCmd.Commands[i], unitController); } } else { spawnedUnitsList = PostprocessCommand(spawnedUnitsList, cmd, unitController); } //if (unitController.DataController.ControlledData.Unit.State == VoxelDataState.Dead) if (!unitController.DataController.IsAlive) { //Voxel voxel = unitController.DataController.ControlledData.VoxelRef; //Debug.Assert(voxel == null);// if (deadUnitsHs == null) { deadUnitsHs = new HashSet <long>(); } if (deadUnitsHs.Contains(cmd.UnitIndex)) { Debug.LogError("Dead unit could not execute commands"); } else { deadUnitsHs.Add(cmd.UnitIndex); } } } } if (deadUnitsHs != null) { long[] deadUnits = deadUnitsHs.ToArray(); for (int i = 0; i < m_gameState.PlayersCount; ++i) { m_selection.Unselect(i, m_playerIndex, deadUnits); m_targetSelection.Unselect(i, m_playerIndex, deadUnits); } for (int i = 0; i < deadUnits.Length; ++i) { long unitId = deadUnits[i]; RemoveUnitController(unitId); } } if (m_isLocalPlayer) { if (spawnedUnitsList != null) { long[] spawnedUnits = spawnedUnitsList.ToArray(); spawnedUnits = spawnedUnits.Where( u => m_gameState.GetVoxelDataController(m_playerIndex, u) != null && VoxelData.IsControllableUnit(m_gameState.GetVoxelDataController(m_playerIndex, u).ControlledData.Type)).ToArray(); m_selection.AddToSelection(m_playerIndex, m_playerIndex, spawnedUnits); } } }