Exemple #1
0
    private static Ship GenerateMotherBase()
    {
        Ship motherBase = new Ship(1000f)
        {
            EntityName = "MotherBase"
        };

        DMagnet magnet = new DMagnet()
        {
            EntityName = "magnet"
        };
        DRanger ranger = new DRanger()
        {
            EntityName = "ranger", detectionRange = 5f
        };
        DTradeComputer trader = new DTradeComputer()
        {
            EntityName = "trader"
        };


        motherBase.IntegratedDevice.IntegrateDevice(ranger);
        motherBase.IntegratedDevice.IntegrateDevice(magnet);
        motherBase.IntegratedDevice.IntegrateDevice(trader);


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

        rootDecision.AddCondition(ranger.GetCheck("IsAnyTarget"));

        return(motherBase);
    }
Exemple #2
0
        public BSBranch CreateBranch()
        {
            BSBranch node = new BSBranch()
            {
                m_scheme = this
            };

            m_nodes.Add(node);
            return(node);
        }
Exemple #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);
    }