public static ExecutableNode GetNode(Fleet fleet, NodalEditor.SaveStruct data, int nodeID) { if (!data.nodes.ContainsKey(nodeID)) { throw new System.Exception("NodeID n'existe pas lors de l'instaciation d'une executionNode"); } NodeInfos n = data.nodes[nodeID]; switch (n.type) { case "Start": return(new StartNode(fleet, data, nodeID, SimulatedWideDataManager.Container)); case "End": return(new EndNode(fleet, data, nodeID, SimulatedWideDataManager.Container)); case "Explore": return(new ExploreNode(fleet, data, nodeID, SimulatedWideDataManager.Container)); case "If": return(new IfNode(fleet, data, nodeID, SimulatedWideDataManager.Container)); case "Move To": return(new MoveToNode(fleet, data, nodeID, SimulatedWideDataManager.Container)); case "NotNull": return(new NotNull(fleet, data, nodeID, SimulatedWideDataManager.Container)); case "Loop": return(new LoopNode(fleet, data, nodeID, SimulatedWideDataManager.Container)); } throw new System.Exception(n.type + " : Unkown type of executionNode"); }
public ExecutableNode(Fleet f, NodalEditor.SaveStruct nodes, int nodeIndex, SimulatedWideDataManager.SerializeContainer datas) { _nodes = nodes; _data = datas; _myID = nodeIndex; _fleet = f; }
private int UpdateStop(Fleet f, NodeInfos n, NodalEditor.SaveStruct data) { _container._fleets.Remove(f.ID); foreach (int shipID in f.ShipIDs) { Ship s = _container._ships[shipID]; _currentUpdate.Add(s); s.Fleet = 0; } AddLog(f, "End of flight plan"); return(0); }
private int UpdateNode(Fleet f, NodeInfos n, NodalEditor.SaveStruct data) { switch (n.type) { case "Start": return(UpdateStart(f, n, data)); case "End": return(UpdateStop(f, n, data)); case "Explore": return(UpdateExplore(f, n, data)); case "Move To": return(UpdateMoveTo(f, n, data)); } throw new System.Exception("Node type unexpected " + n.type); }
private int UpdateFlee(Fleet f) { if (f.FleetParams == null) { f.FleetParams = new ParamHolder(); } NodalEditor.SaveStruct s = Newtonsoft.Json.JsonConvert.DeserializeObject <NodalEditor.SaveStruct>(f.Data); if (s.nodes.ContainsKey(f.CurrentNode)) { return(UpdateNode(f, s.nodes[f.CurrentNode], s)); } throw new System.Exception("pas de node active???"); }
private int UpdateStart(Fleet f, NodeInfos n, NodalEditor.SaveStruct data) { AddLog(f, "Starting flight plan"); foreach (LinkInfo l in data.links) { if (l.FromID == n.id && l.FromParam == "StartOutput") { f.CurrentNode = l.ToID; break; } } return(0); }
private int UpdateFlee(Fleet f) { if (f.FleetParams == null) { f.FleetParams = new ParamHolder(); } NodalEditor.SaveStruct s = Newtonsoft.Json.JsonConvert.DeserializeObject <NodalEditor.SaveStruct>(f.Data); if (s.nodes.ContainsKey(f.CurrentNode)) { ExecutableNode node = ExecutableNodeFactory.GetNode(f, s, f.CurrentNode); int result = node.Update(_currentUpdate); f.Data = Newtonsoft.Json.JsonConvert.SerializeObject(s); return(result); } throw new System.Exception("pas de node active???"); }
public EndNode(Fleet f, NodalEditor.SaveStruct nodes, int nodeIndex, SimulatedWideDataManager.SerializeContainer data) : base(f, nodes, nodeIndex, data) { }
private int UpdateMoveTo(Fleet f, NodeInfos n, NodalEditor.SaveStruct data) { //preparation des parametres if (_container._currentFrame >= f.TaskStartFrame) { int doneFrameInNode = _container._currentFrame - f.TaskStartFrame; int timeToUndock = 100; int timeToMove = timeToUndock + 500; int timeToDock = timeToMove + 100; int timeToFuel = timeToDock + 50; string lastDoneStep = f.FleetParams.GetString("lastState", "none"); switch (lastDoneStep) { case "none": { //undocking //analyse des parametres en input if (doneFrameInNode >= 0) { int hangarID = 1; foreach (LinkInfo l in data.links) { if (l.ToID == n.id && l.ToParam == "Station") { NodeInfos hangarSelectorNode = data.nodes[l.FromID]; hangarID = hangarSelectorNode.nodeParams.GetInt("HangarID"); } } f.FleetParams.Set("targetHangar", hangarID); //undocking f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "Undocking"; _currentUpdate.Add(ship); }); f.FleetParams.Set("lastState", "undock"); return(f.TaskStartFrame + timeToUndock); } else { return(f.TaskStartFrame); } } case "undock": { if (doneFrameInNode >= timeToUndock) { //undock result + moving AddLog(f, "Undocked from station"); Hangar hangar = _container._hangars[f.LastHangar]; _currentUpdate.Add(hangar); f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "Moving to station"; ship.Hangar = -1; _currentUpdate.Add(ship); hangar.Ships.Remove(ship.ID); }); f.FleetParams.Set("lastState", "moving"); return(f.TaskStartFrame + timeToMove); } else { return(f.TaskStartFrame + timeToUndock); } } case "moving": { if (doneFrameInNode >= timeToMove) { AddLog(f, "Moved to target station"); f.FleetParams.Set("lastState", "dock"); return(f.TaskStartFrame + timeToDock); } else { return(f.TaskStartFrame + timeToMove); } } case "dock": { if (doneFrameInNode >= timeToDock) { //docking result int hangarID = f.FleetParams.GetInt("targetHangar"); Hangar hangar = _container._hangars[hangarID]; _currentUpdate.Add(hangar); f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "Docking"; ship.Hangar = hangarID; hangar.Ships.Add(ship.ID); _currentUpdate.Add(ship); }); AddLog(f, "Docked in station"); //start fueling f.FleetParams.Set("lastState", "fuel"); return(f.TaskStartFrame + timeToFuel); } else { return(f.TaskStartFrame + timeToDock); } } case "fuel": { if (doneFrameInNode >= timeToFuel) { AddLog(f, "Fueled for Y ICU"); //fueling is done f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "Idle in station"; }); foreach (LinkInfo l in data.links) { if (l.FromID == n.id && l.FromParam == "MoveOutput") { f.CurrentNode = l.ToID; break; } } f.FleetParams.Set("lastState", "none"); f.TaskStartFrame = f.TaskStartFrame + timeToFuel; return(f.TaskStartFrame); } return(f.TaskStartFrame + timeToFuel); } } } return(f.TaskStartFrame); }
private int UpdateExplore(Fleet f, NodeInfos n, NodalEditor.SaveStruct data) { //preparation des parametres int doneFrameInNode = _container._currentFrame - f.TaskStartFrame; if (_container._currentFrame >= f.TaskStartFrame) { int timeToUndock = 100; int timeToMoveZone = timeToUndock + 200; int timeToExplore = timeToMoveZone + 500; int timeToMoveBack = timeToExplore + 200; int timeToDock = timeToMoveBack + 100; int timeToFuel = timeToDock + 200; string lastDoneStep = f.FleetParams.GetString("lastState", "none"); switch (lastDoneStep) { case "none": { //undocking f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "Undocking"; _currentUpdate.Add(ship); }); f.FleetParams.Set("lastState", "undock"); return(f.TaskStartFrame + timeToUndock); } case "undock": { //moving to site if (doneFrameInNode >= timeToUndock) { f.FleetParams.Set("fromHangar", f.LastHangar); f.FleetParams.Set("fromStation", f.LastStation); Hangar hangar = _container._hangars[f.LastHangar]; _currentUpdate.Add(hangar); f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "moving to site"; ship.Hangar = -1; _currentUpdate.Add(ship); hangar.Ships.Remove(sID); }); AddLog(f, "undocked from station"); //prepare next step f.FleetParams.Set("lastState", "moveOut"); return(f.TaskStartFrame + timeToMoveZone); } else { return(f.TaskStartFrame + timeToUndock); } } case "moveOut": { //Exploring if (doneFrameInNode >= timeToMoveZone) { f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "Exploring"; }); AddLog(f, "Moved to explore site"); f.FleetParams.Set("lastState", "explore"); return(f.TaskStartFrame + timeToExplore); } else { return(f.TaskStartFrame + timeToMoveZone); } } case "explore": { //moving back to station if (doneFrameInNode >= timeToExplore) { f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "Moving back to station"; }); AddLog(f, "Done with exploration"); f.FleetParams.Set("lastState", "moveIn"); return(f.TaskStartFrame + timeToMoveBack); } else { return(f.TaskStartFrame + timeToExplore); } } case "moveIn": { //Docking if (doneFrameInNode >= timeToMoveBack) { f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "Docking"; }); AddLog(f, "Returned to station"); f.FleetParams.Set("lastState", "docking"); return(f.TaskStartFrame + timeToDock); } else { return(f.TaskStartFrame + timeToMoveBack); } } case "docking": { //Fueling if (doneFrameInNode >= timeToDock) { f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "Fueling"; }); AddLog(f, "Docked to station"); f.FleetParams.Set("lastState", "fueling"); return(f.TaskStartFrame + timeToFuel); } else { return(f.TaskStartFrame + timeToDock); } } case "fueling": { //next step if (doneFrameInNode >= timeToFuel) { int hangarID = f.FleetParams.GetInt("fromHangar"); Hangar hangar = _container._hangars[hangarID]; _currentUpdate.Add(hangar); f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Hangar = hangarID; _currentUpdate.Add(ship); hangar.Ships.Add(sID); }); AddLog(f, "undocked from station"); //prepare fueling AddLog(f, "Fueled for X ICU"); f.FleetParams.Set("lastState", "nextStep"); return(f.TaskStartFrame + timeToFuel); } else { return(f.TaskStartFrame + timeToFuel); } } case "nextStep": { //all done, next node if (doneFrameInNode >= timeToFuel) { f.ShipIDs.ForEach((sID) => { Ship ship = _container._ships[sID]; ship.Status = "Idle in station"; }); foreach (LinkInfo l in data.links) { if (l.FromID == n.id && l.FromParam == "ExploreOutput") { f.CurrentNode = l.ToID; break; } } f.FleetParams.Set("lastState", "none"); f.TaskStartFrame = f.TaskStartFrame + timeToFuel; return(f.TaskStartFrame + timeToFuel); } else { return(f.TaskStartFrame + timeToFuel); } }; } } return(f.TaskStartFrame); }