예제 #1
0
 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 + ")");
     }
 }
예제 #2
0
 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;
     }
 }
예제 #3
0
 public void initDockingWith(int id) {
     DockingProcedure proc = new DockingProcedure(id);
     proc.setNavHandle(this.navHandle);
     proc.initDocking();
 }