Ejemplo n.º 1
0
    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);
    }
Ejemplo n.º 2
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);
    }