public void handleDockingRequest(string data) { if (Communication.currentNode.type != "mothership") { return; // Motherships handle docking requests } string[] dataSplitted = data.Split('_'); if (dataSplitted.Count() == 2) { int id = int.Parse(dataSplitted[0]); if (Communication.currentNode.id != id) { return; // If not my id } int slaveId = int.Parse(dataSplitted[1]); int nodeIndex = this.getNodeIndexById(slaveId); if (nodeIndex == -1) { Communication.connectedNodes.Add(slaveId); Drone node = new Drone(slaveId); node.initNavigation(this.myGrid); Communication.connectedNodesData.Add(node); nodeIndex = this.getNodeIndexById(slaveId); } AnchoredConnector available = AnchoredConnector.getAvailableAnchoredConnector(); if (available == null) { Display.print("Docking request denied (Connectors full)."); } else { if (Docking.dockingWithDrone(slaveId)) { Display.print("Already accepted, continue on docking."); this.sendDockingAccepted(slaveId); this.sendConnectorData(slaveId); } else { Display.print("Assigning a proper connector."); DockingProcedure dock = new DockingProcedure(slaveId); dock.setNavHandle(Communication.currentNode.navHandle); dock.myConnector = available; dock.initDocking(); Docking.activeDockingProcedures.Add(dock); this.sendDockingAccepted(slaveId); this.sendConnectorData(slaveId); } } } else { Display.print("[ERROR] Docking request invalid. (" + data + ")"); } }
public void handleDockingStep(List <CommunicationDataStructureValue> responseData) { if (Communication.currentNode.type != "mothership") { return; } int id = 0, slaveId = 0, step = 0, connectorId = 0; foreach (CommunicationDataStructureValue data in responseData) { if (data.getName() == "id") { id = int.Parse(data.getValue()); } else if (data.getName() == "slaveId") { slaveId = int.Parse(data.getValue()); } else if (data.getName() == "step") { step = int.Parse(data.getValue()); } else if (data.getName() == "connectorId") { connectorId = int.Parse(data.getValue()); } } if (id == Communication.currentNode.id) { if (slaveId != 0 && !Docking.dockingWithDrone(slaveId)) { this.sendStopDocking("out-of-order", slaveId); } else { DockingProcedure procedure = Docking.getDroneDockingProcedure(slaveId); if (procedure == null || procedure.myConnector.connectorId != connectorId) { this.sendStopDocking("out-of-order", slaveId); } } } }
public void handleDockingAccepted(string data) { if (Communication.currentNode.type == "mothership") { return; // Motherships handle docking requests } string[] dataSplitted = data.Split('_'); if (dataSplitted.Count() == 2) { int id = int.Parse(dataSplitted[0]); if (Communication.currentNode.id != id) { return; // If not my id } int masterId = int.Parse(dataSplitted[1]); int nodeIndex = this.getNodeIndexById(masterId); if (nodeIndex == -1) { Communication.connectedNodes.Add(masterId); Drone node = new Drone(masterId); node.initNavigation(this.myGrid); Communication.connectedNodesData.Add(node); nodeIndex = this.getNodeIndexById(masterId); } if (Docking.dockingWithDrone(masterId)) { DockingProcedure procedure = Docking.getDroneDockingProcedure(masterId); procedure.haltDocking("docking-already-in-progress"); } DockingProcedure dock = new DockingProcedure(masterId); dock.initDocking(); dock.approveDocking(); dock.setNavHandle(Communication.currentNode.navHandle); Docking.activeDockingProcedures.Add(dock); Communication.currentNode.navHandle.activeDockingProcedure = dock; } }