Пример #1
0
    // 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);
    }
Пример #2
0
    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);
    }
Пример #3
0
    private static Ship GeneratePatrolShip()
    {
        Ship ship = new Ship(0.3f)
        {
            EntityName = "patrolship"
        };

        GameObject[] markers = new GameObject[]
        {
            new GameObject("Marker1", typeof(TransformMarker)),
            new GameObject("Marker2", typeof(TransformMarker)),
            new GameObject("Marker3", typeof(TransformMarker)),
            new GameObject("Marker4", typeof(TransformMarker)),
        };

        markers[0].transform.position = Vector3.right * 15f;
        markers[1].transform.position = Vector3.left * 15f;
        markers[2].transform.position = Vector3.forward * 15f;
        markers[3].transform.position = Vector3.back * 15f;


        DEngine engine = new DEngine()
        {
            EntityName = "engine", m_lookDirection = Vector3.forward, m_space = Space.Self
        };
        DSteerModule steerer = new DSteerModule()
        {
            EntityName = "steerer"
        };
        DPatrolModule patrol = new DPatrolModule()
        {
            EntityName     = "patrol",
            m_patrolPoints = new Vector3[] {
                markers[0].transform.position,
                markers[1].transform.position,
                markers[2].transform.position,
                markers[3].transform.position
            }
        };

        DLauncher launcher = new DLauncher()
        {
            EntityName = "launcher", m_projectileName = "Missile"
        };
        DRanger enemydetector = new DRanger()
        {
            EntityName = "enemydetector", detectionRange = 5f
        };
        DMagnet        magnet = new DMagnet();
        DTradeComputer trader = new DTradeComputer();



        ship.IntegratedDevice.IntegrateDevice(trader);
        ship.IntegratedDevice.IntegrateDevice(engine);
        ship.IntegratedDevice.IntegrateDevice(steerer);
        ship.IntegratedDevice.IntegrateDevice(patrol);
        ship.IntegratedDevice.IntegrateDevice(enemydetector);
        ship.IntegratedDevice.IntegrateDevice(launcher);
        ship.IntegratedDevice.IntegrateDevice(magnet);



        BSBranch rootDecision = ship.IntegratedDevice.Blueprint.CreateBranch();

        BSSequence patrolSequence     = ship.IntegratedDevice.Blueprint.CreateSequence();
        BSAction   disableEngine      = ship.IntegratedDevice.Blueprint.CreateAction("DeactivateDevice", engine);
        BSAction   steerTowardsTarget = ship.IntegratedDevice.Blueprint.CreateAction("SteerTowards", steerer, patrol.GetQuery("CurrentTarget"));
        BSAction   enableEngine       = ship.IntegratedDevice.Blueprint.CreateAction("ActivateDevice", engine);
        BSAction   waitUntilReach     = ship.IntegratedDevice.Blueprint.CreateAction("ReachTarget", patrol, patrol.GetQuery("CurrentTarget"));
        BSAction   nextPoint          = ship.IntegratedDevice.Blueprint.CreateAction("SetNextPoint", patrol);


        BSBranch miningDecision = ship.IntegratedDevice.Blueprint.CreateBranch();

        miningDecision.AddCondition(magnet.GetCheck("IsStorageble"),
                                    enemydetector.GetQuery("CurrentTargetContainer"));



        BSSequence shootingSequence           = ship.IntegratedDevice.Blueprint.CreateSequence();
        BSAction   steerTowardsShootingTarget =
            ship.IntegratedDevice.Blueprint.CreateAction("SteerTowards", steerer,
                                                         enemydetector.GetQuery("CurrentTargetPosition"));
        BSAction shootTarget = ship.IntegratedDevice.Blueprint.CreateAction("Fire", launcher);

        BSSequence collectingSequence = ship.IntegratedDevice.Blueprint.CreateSequence();
        BSAction   attractAsteroid    = ship.IntegratedDevice.Blueprint.CreateAction("Attract", magnet,
                                                                                     enemydetector.GetQuery("CurrentTargetContainer"));
        BSAction storageAsteroid = ship.IntegratedDevice.Blueprint.CreateAction("Load", magnet,
                                                                                enemydetector.GetQuery("CurrentTargetContainer"));


        DeviceQuery tradeInfo = () =>
        {
            return(ship.m_cargo.ComposeTradeOffer("Asteroid"));
        };

        DeviceQuery stationPosition = () =>
        {
            return(new PositionArgs()
            {
                position = WorldManager.RequestContainerData("MotherBase").View.transform.position
            });
        };

        Device stationTrader = WorldManager.RequestContainerData("MotherBase").IntegratedDevice.GetInternalDevice("trader");


        BSSequence goingHomeSequence  = ship.IntegratedDevice.Blueprint.CreateSequence();
        BSAction   steerTowardsHome   = ship.IntegratedDevice.Blueprint.CreateAction("SteerTowards", steerer, stationPosition);
        BSAction   waitUntilReachHome = ship.IntegratedDevice.Blueprint.CreateAction("ReachTarget", patrol, stationPosition);
        BSAction   sellResouces       = ship.IntegratedDevice.Blueprint.CreateAction("LoadItemsFrom", stationTrader, tradeInfo);


        // interupt current commands stack
//		enemydetector.AddEvent("OnRangerEntered", ship.IntegratedDevice.Blueprint.InterruptExecution);


        ship.IntegratedDevice.Blueprint.m_entryPoint.AddChild(rootDecision);

        rootDecision.AddCondition(enemydetector.GetCheck("IsAnyTarget"));
        rootDecision.AddCondition(ship.IntegratedDevice.GetCheck("IsCargoFull"));


        rootDecision.AddChild(miningDecision);
        rootDecision.AddChild(goingHomeSequence);
        rootDecision.AddChild(patrolSequence);


        miningDecision.AddChild(collectingSequence);
        miningDecision.AddChild(shootingSequence);


        collectingSequence.AddChild(storageAsteroid);
        collectingSequence.AddChild(attractAsteroid);
        collectingSequence.AddChild(disableEngine);


        shootingSequence.AddChild(shootTarget);
        shootingSequence.AddChild(steerTowardsShootingTarget);
        shootingSequence.AddChild(disableEngine);

        patrolSequence.AddChild(nextPoint);
        patrolSequence.AddChild(waitUntilReach);
        patrolSequence.AddChild(enableEngine);
        patrolSequence.AddChild(steerTowardsTarget);
        patrolSequence.AddChild(disableEngine);


        goingHomeSequence.AddChild(sellResouces);
        goingHomeSequence.AddChild(waitUntilReachHome);
        goingHomeSequence.AddChild(enableEngine);
        goingHomeSequence.AddChild(steerTowardsHome);
        goingHomeSequence.AddChild(disableEngine);

        ContainerView shipView = WorldManager.SpawnContainer(ship, Vector3.zero, Quaternion.identity, 2);

        return(ship);
    }