private static Ship GenerateShip() { Ship ship = new Ship(5f) { EntityName = "ship" }; Device cockpit = GeneratePilotCockpit(); DLauncher launcher = new DLauncher() { EntityName = "launcher", m_projectileName = "Missile" }; DInputModule mouseInput = new DInputModule() { EntityName = "space", m_keyCode = KeyCode.Space }; ship.IntegratedDevice.IntegrateDevice(launcher); ship.IntegratedDevice.IntegrateDevice(cockpit); ship.IntegratedDevice.IntegrateDevice(mouseInput); BSEntry onMouseUp = ship.IntegratedDevice.Blueprint.CreateEntry("space/OnInputReleased", ship.IntegratedDevice); BSAction toFire = ship.IntegratedDevice.Blueprint.CreateAction("launcher/Fire", ship.IntegratedDevice); ship.IntegratedDevice.Blueprint.ConnectElements(onMouseUp, toFire); ContainerView shipView = WorldManager.SpawnContainer(ship, Vector3.zero, Quaternion.identity, 1); return(ship); }
// Heat seeker private static Device GenerateHeatSeeker(float detectionRange) { Device heatSeeker = new Device() { EntityName = "heatseeker" }; DRanger ranger = new DRanger() { EntityName = "ranger", detectionRange = detectionRange }; DSteerModule steerer = new DSteerModule() { EntityName = "steerer" }; heatSeeker.IntegrateDevice(ranger); heatSeeker.IntegrateDevice(steerer); BSSequence onTargetFound = heatSeeker.Blueprint.CreateSequence(); // add target signature BSEntry inRange = heatSeeker.Blueprint.CreateEntry("OnRangerEntered", ranger); // steer towards the target BSAction toSteer = heatSeeker.Blueprint.CreateAction("SteerTowards", steerer, ranger.GetQuery("CurrentTargetPosition")); inRange.AddChild(onTargetFound); onTargetFound.AddChild(toSteer); return(heatSeeker); }
// Can be a mine as it is private static Device GenerateWarhead(float detectionRange) { Device warheadDevice = new Device() { EntityName = "warhead" }; DDetonator detonator = new DDetonator() { EntityName = "detonator" }; DRanger ranger = new DRanger() { EntityName = "ranger", detectionRange = detectionRange }; warheadDevice.IntegrateDevice(detonator); warheadDevice.IntegrateDevice(ranger); BSEntry onClose = warheadDevice.Blueprint.CreateEntry("OnRangerEntered", ranger); BSAction toDetonate = warheadDevice.Blueprint.CreateAction("Detonate", detonator); warheadDevice.Blueprint.ConnectElements(onClose, toDetonate); return(warheadDevice); }
public BSEntry CreateEntry(string eventName, Device device) { BSEntry node = new BSEntry() { m_scheme = this }; device.m_events[eventName] += node.Initialize; m_nodes.Add(node); return(node); }
private static Device GeneratePilotCockpit() { Device input = GenerateInclusiveInputModule(); Device engines = GenerateInclusiveEngineModule(); DSteerModule steerer = new DSteerModule() { EntityName = "steerer" }; Device cockpitDevice = new Device() { EntityName = "cockpit" }; cockpitDevice.IntegrateDevice(input); cockpitDevice.IntegrateDevice(engines); cockpitDevice.IntegrateDevice(steerer); // Steering module BSEntry onMouseWorld = cockpitDevice.Blueprint.CreateEntry("input/mousePos/OnMouseWorldPosition", cockpitDevice); BSAction toSteer = cockpitDevice.Blueprint.CreateAction("steerer/SteerTowards", cockpitDevice); cockpitDevice.Blueprint.ConnectElements(onMouseWorld, toSteer); // Movement module BSEntry onForwardDown = cockpitDevice.Blueprint.CreateEntry("input/w/OnInputHeld", cockpitDevice); BSAction toGoForward = cockpitDevice.Blueprint.CreateAction("engines/forward/MoveForward", cockpitDevice); cockpitDevice.Blueprint.ConnectElements(onForwardDown, toGoForward); BSEntry onBackwardDown = cockpitDevice.Blueprint.CreateEntry("input/s/OnInputHeld", cockpitDevice); BSAction toGoBackward = cockpitDevice.Blueprint.CreateAction("engines/backward/MoveForward", cockpitDevice); cockpitDevice.Blueprint.ConnectElements(onBackwardDown, toGoBackward); BSEntry onLeftDown = cockpitDevice.Blueprint.CreateEntry("input/a/OnInputHeld", cockpitDevice); BSAction toGoleft = cockpitDevice.Blueprint.CreateAction("engines/left/MoveForward", cockpitDevice); cockpitDevice.Blueprint.ConnectElements(onLeftDown, toGoleft); BSEntry onRightDown = cockpitDevice.Blueprint.CreateEntry("input/d/OnInputHeld", cockpitDevice); BSAction toGoRight = cockpitDevice.Blueprint.CreateAction("engines/right/MoveForward", cockpitDevice); cockpitDevice.Blueprint.ConnectElements(onRightDown, toGoRight); return(cockpitDevice); }
private static Ship GenerateMissile() { Ship missile = new Ship(2) { EntityName = "Missile" }; DEngine engine = new DEngine() { EntityName = "engine", m_lookDirection = Vector3.forward, m_space = Space.Self }; Device heatSeeker = GenerateHeatSeeker(3f); Device timeBomb = GenerateTimeBomb(5f); DTimer activeTimer = new DTimer() { EntityName = "activationtimer", m_timerSetUp = 2f }; missile.IntegratedDevice.IntegrateDevice(engine); missile.IntegratedDevice.IntegrateDevice(timeBomb); missile.IntegratedDevice.IntegrateDevice(heatSeeker); missile.IntegratedDevice.IntegrateDevice(activeTimer); timeBomb.GetInternalDevice("warhead/ranger").m_isActive = false; heatSeeker.GetInternalDevice("ranger").m_isActive = false; Job.make(timeBomb.DeactivateDevice(null), true); Job.make(heatSeeker.DeactivateDevice(null), true); BSEntry onTimer = missile.IntegratedDevice.Blueprint.CreateEntry("OnTimerComplete", activeTimer); BSAction toActivateWarhead = missile.IntegratedDevice.Blueprint.CreateAction("ActivateDevice", timeBomb); BSAction toActivateSeeker = missile.IntegratedDevice.Blueprint.CreateAction("ActivateDevice", heatSeeker); missile.IntegratedDevice.Blueprint.ConnectElements(onTimer, toActivateWarhead); missile.IntegratedDevice.Blueprint.ConnectElements(onTimer, toActivateSeeker); return(missile); }
private static Device GenerateTimeBomb(float time) { Device timeBomb = new Device() { EntityName = "timebomb" }; Device warhead = GenerateWarhead(1f); DTimer timer = new DTimer() { EntityName = "timer", m_timerSetUp = time }; timeBomb.IntegrateDevice(warhead); timeBomb.IntegrateDevice(timer); // Generating warhead BSEntry onTimer = timeBomb.Blueprint.CreateEntry("OnTimerComplete", timer); BSAction toDetonate = timeBomb.Blueprint.CreateAction("Detonate", timeBomb.GetInternalDevice("warhead/detonator")); timeBomb.Blueprint.ConnectElements(onTimer, toDetonate); return(timeBomb); }