internal void ReceiveCommandForShip(MessageShipCommand msg) { ShipController sc = _shipCs[msg.ShipId]; // check the ship *could* execute this command switch (msg.Command.CommandType) { case ShipCommandEnum.SetXY: ShipSetXY(msg, sc); break; case ShipCommandEnum.Undock: ShipUndock(msg, sc); break; case ShipCommandEnum.Dock: ShipDock(msg, sc); break; case ShipCommandEnum.SetDestination: ShipSetDestination(msg, sc); break; case ShipCommandEnum.SetAutopilot: ShipSetAutopilot(msg, sc); break; default: throw new Exception("Unknown Ship Command"); } }
internal bool checkValidSetDestinationCommand(MessageShipCommand msg) { if (msg.Command.CommandType == ShipCommandEnum.SetDestination) { return(true); } return(false); }
internal bool checkValidDockCommand(MessageShipCommand msg) { if (msg.Command.CommandType == ShipCommandEnum.Dock && _model.DockedPlanet == null && _model.ShipState != ShipStateEnum.Docked) { return(true); } return(false); }
internal bool checkValidSetXYCommand(MessageShipCommand msg) { if (msg.Command.CommandType == ShipCommandEnum.SetXY) { return(true); } //TODO Check within speed of ship return(false); }
internal bool checkValidSetAutopilotCommand(MessageShipCommand msg) { if (msg.Command.CommandType == ShipCommandEnum.SetAutopilot) { return(true); } // TODO check we have a destination and are in space return(false); }
private static bool ShipSetAutopilot(MessageShipCommand msg, ShipController sc) { bool success = false; if (sc.checkValidSetAutopilotCommand(msg)) { MessageShipSetAutopilot msd = (MessageShipSetAutopilot)msg.Command; sc.SetAutopilot(msd.Active); success = true; } return(success); }
private static bool ShipSetDestination(MessageShipCommand msg, ShipController sc) { bool success = false; if (sc.checkValidSetDestinationCommand(msg)) { MessageShipSetDestination msd = (MessageShipSetDestination)msg.Command; sc.SetDestination(msd.DestinationScId); success = true; } return(success); }
private static bool ShipSetXY(MessageShipCommand msg, ShipController sc) { bool success = false; if (sc.checkValidSetXYCommand(msg)) { MessageShipSetXY msd = (MessageShipSetXY)msg.Command; sc.SetXY(msd.X, msd.Y); success = true; } return(success); }
private bool ShipUndock(MessageShipCommand msg, ShipController sc) { bool success = false; if (sc.checkValidUndockCommand(msg)) { _planetCs[sc.DockedPlanet.PlanetId].UndockShip(msg.ShipId); sc.Undock(); success = true; } return(success); }
private bool ShipDock(MessageShipCommand msg, ShipController sc) { bool success = false; if (sc.checkValidDockCommand(msg)) { Ship s = _model.Ships.Where(x => x.ShipId == msg.ShipId).First(); Planet p = _model.Planets.Where(x => x.StarChartId == ((MessageShipDocking)msg.Command).DockingTargetId).FirstOrDefault(); _planetCs[p.PlanetId].DockShip(s); sc.Dock(p); success = true; } return(success); }
private void receiveCommandForShip(MessageShipCommand msg) { _solarSystemC.ReceiveCommandForShip(msg); }