public void Submit(int playerIndex, Cmd command) { if (command.Code == CmdCode.Composite) { CompositeCmd composite = (CompositeCmd)command; for (int i = 0; i < composite.Commands.Length; ++i) { long unitId = composite.Commands[i].UnitIndex; m_pathFinders[playerIndex].Terminate(unitId); } } else { // if(command.Code != ) m_pathFinders[playerIndex].Terminate(command.UnitIndex); } m_matchServer.Submit(m_gSettings.ClientId, playerIndex, command, (error, returnedCommand) => { if (m_matchServer.HasError(error)) { Error(error); m_matchServer.Disconnect(); return; } }); }
public void Submit(Cmd command) { if (m_isPlayerLeftRoom) { return; //it means that player has left the room; } if (command.Code == CmdCode.Composite) { CompositeCmd composite = (CompositeCmd)command; if (composite.Commands != null) { for (int i = 0; i < composite.Commands.Length; ++i) { SubmitForUnit(composite.Commands[i]); } } } else { SubmitForUnit(command); } if (command.Code == CmdCode.LeaveRoom) { //Changes player color to neutral?? m_isPlayerLeftRoom = true; } }
private void SubmitToEngine(int playerIndex, List <Cmd> commandsToSubmit) { if (commandsToSubmit.Count == 1) { ITaskEngine taskEngine = m_engine.GetClientTaskEngine(playerIndex); taskEngine.TerminateAll(); m_engine.Submit(playerIndex, commandsToSubmit[0]); //Render hit; } else if (commandsToSubmit.Count > 1) { CompositeCmd cmd = new CompositeCmd { Commands = commandsToSubmit.ToArray() }; ITaskEngine taskEngine = m_engine.GetClientTaskEngine(playerIndex); taskEngine.TerminateAll(); m_engine.Submit(playerIndex, cmd); } else { Debug.LogWarning("No commands to submit"); } }
public CompositeCmd(CompositeCmd cmd) : base(cmd) { if (cmd.Commands != null) { Commands = new Cmd[cmd.Commands.Length]; for (int i = 0; i < Commands.Length; ++i) { if (cmd.Commands[i] != null) { Commands[i] = cmd.Commands[i].Clone(); } } } }
protected override void OnExecuteCommand(Cmd cmd) { if (cmd.Code == CmdCode.Composite) { CompositeCmd compositeCmd = (CompositeCmd)cmd; for (int i = 0; i < compositeCmd.Commands.Length; ++i) { ExecuteCommand(compositeCmd.Commands[i]); } } else { ExecuteCommand(cmd); } }
protected override void OnExecuteCommand(Cmd cmd) { if (m_createdVoxels.Count != 0) { m_createdVoxels.Clear(); } if (cmd.Code == CmdCode.Composite) { CompositeCmd compositeCmd = (CompositeCmd)cmd; for (int i = 0; i < compositeCmd.Commands.Length; ++i) { ExecuteCommand(compositeCmd.Commands[i]); } } else { ExecuteCommand(cmd); } }
protected override void OnExecuteCommand(Cmd cmd) { if (m_eatenOrDestroyedVoxels.Count != 0) { m_eatenOrDestroyedVoxels.Clear(); } CollapseEatExpandClear(m_currentTick - 1); //clear previous side effect commands if remaining if (cmd.Code == CmdCode.Composite) { CompositeCmd compositeCmd = (CompositeCmd)cmd; for (int i = 0; i < compositeCmd.Commands.Length; ++i) { ExecuteCommand(compositeCmd.Commands[i]); } } else { ExecuteCommand(cmd); } }
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); } } }
public bool Tick(long tick, out CommandsArray commands) { m_isPlayerInRoom = !m_isPlayerLeftRoom; bool isChanged = false; if (m_units.Length != m_commandBuffer.Commands.Length) { m_commandBuffer = new CommandsArray(new Cmd[m_idToUnit.Count]); } bool unitsChanged = false; for (int i = 0; i < m_units.Length; ++i) { IMatchUnitController unitController = m_units[i]; Cmd cmd; unitController.Tick(tick, out cmd); IList <VoxelDataCellPair> createdVoxels = unitController.CreatedVoxels; if (createdVoxels.Count != 0) { CreateAssets(createdVoxels); for (int j = 0; j < m_otherPlayerControllers.Length; ++j) { m_otherPlayerControllers[j].CreateAssets(createdVoxels); } } IList <VoxelData> eatenOrDestroyed = unitController.EatenOrDestroyedVoxels; if (eatenOrDestroyed.Count != 0) { RemoveAssets(eatenOrDestroyed); for (int j = 0; j < m_otherPlayerControllers.Length; ++j) { m_otherPlayerControllers[j].RemoveAssets(eatenOrDestroyed); } } m_commandBuffer.Commands[i] = cmd; if (cmd != null) { isChanged = true; if (cmd.Code == CmdCode.Composite) { CompositeCmd composite = (CompositeCmd)cmd; for (int c = 0; c < composite.Commands.Length; ++c) { unitsChanged = PostprocessCmd(unitsChanged, unitController, composite.Commands[c]); } } else { unitsChanged = PostprocessCmd(unitsChanged, unitController, cmd); } } if (!unitController.IsAlive) { unitsChanged = RemoveUnitController(unitsChanged, unitController); } } if (unitsChanged) { m_units = m_idToUnit.Values.ToArray(); } commands = m_commandBuffer; return(isChanged); }
public void Tick(long tick, out Cmd cmd) { if (m_createdVoxels.Count != 0) { m_createdVoxels.Clear(); } if (m_eatenOrDestroyedVoxels.Count != 0) { m_eatenOrDestroyedVoxels.Clear(); } if (!m_dataController.IsAlive) { if (State != VoxelDataState.Idle) { RaiseCmdFailed(null, CmdResultCode.Fail_NoUnit); } else { GoToIdleState(); } cmd = null; return; } if (m_ticksBeforeNextCommand == 0) { cmd = OnTick(tick); if (State != m_prevState) { if (cmd != null) { cmd = new CompositeCmd { UnitIndex = cmd.UnitIndex, Duration = cmd.Duration, Commands = new[] { cmd, new ChangeParamsCmd(CmdCode.StateChanged) { UnitIndex = cmd.UnitIndex, Duration = cmd.Duration, IntParams = new[] { (int)m_prevState, (int)State } } } }; } else { cmd = new ChangeParamsCmd(CmdCode.StateChanged) { UnitIndex = Id, IntParams = new[] { (int)m_prevState, (int)State } }; } CmdResultCode noFail = m_dataController.SetVoxelDataState(State); if (noFail != CmdResultCode.Success) { throw new InvalidOperationException(""); } m_prevState = State; } return; } else { m_ticksBeforeNextCommand--; } cmd = null; return; }