コード例 #1
0
    public void DeleteVoxels()
    {
        List <IntVector3> selections = GetSelectionPos();

        if (selections.Count == 0)
        {
            return;
        }


        List <BSVoxel> new_voxels = new List <BSVoxel>();
        List <BSVoxel> old_voxels = new List <BSVoxel>();

        for (int i = 0; i < selections.Count; i++)
        {
            BSVoxel voxel = dataSource.Read(selections[i].x, selections[i].y, selections[i].z);

            new_voxels.Add(new BSVoxel());
            old_voxels.Add(voxel);
        }

        BSAction      action = new BSAction();
        BSVoxelModify vm     = new BSVoxelModify(selections.ToArray(), old_voxels.ToArray(), new_voxels.ToArray(), dataSource, EBSBrushMode.Subtract);

        action.AddModify(vm);
        vm.Redo();
        BSHistory.AddAction(action);

        ResetDrawing();
    }
コード例 #2
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);
    }
コード例 #3
0
    // 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);
    }
コード例 #4
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);
    }
コード例 #5
0
 void DoHistory()
 {
     if (!m_Action.IsEmpty())
     {
         BSHistory.AddAction(m_Action);
         m_Action = new BSAction();
     }
 }
コード例 #6
0
        public BSAction CreateAction(string functionName, Device device, DeviceQuery query = null)
        {
            BSAction node = new BSAction()
            {
                m_scheme = this
            };

            node.SetAction(device.GetFunction(functionName), query);

            m_nodes.Add(node);
            return(node);
        }
コード例 #7
0
    public static void AddAction(BSAction action)
    {
        ClearNullAction();

        if (m_Undos.Count == s_MaxCount)
        {
            m_Undos.RemoveAt(0);
        }

        m_Undos.Add(action);
        m_Redos.Clear();
    }
コード例 #8
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);
    }
コード例 #9
0
    public void ClearSelection(BSAction action)
    {
        if (action == null)
        {
            m_Selections.Clear();
            m_RecalcBoxes = true;
        }
        else
        {
            Dictionary <IntVector3, byte> old_selection = new Dictionary <IntVector3, byte>(m_Selections);
            m_Selections.Clear();
            Dictionary <IntVector3, byte> new_selection = new Dictionary <IntVector3, byte>(m_Selections);

            BSSelectedBoxModify sm = new BSSelectedBoxModify(old_selection, new_selection, this);
            action.AddModify(sm);

            m_RecalcBoxes = true;
        }
    }
コード例 #10
0
    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);
    }
コード例 #11
0
    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);
    }
コード例 #12
0
    protected override void Do()
    {
        Vector3 min = Min;
//		Vector3 max = Max;

        Vector3 size = Size;

        List <BSVoxel>               new_voxels  = new List <BSVoxel>();
        List <IntVector3>            indexes     = new List <IntVector3>();
        List <BSVoxel>               old_voxels  = new List <BSVoxel>();
        Dictionary <IntVector3, int> refVoxelMap = new Dictionary <IntVector3, int>();

        // x positive direction
        if (m_Rot == 0)
        {
            IntVector3 isize = CorrectSizeXY(size);
            int        xMin  = Mathf.FloorToInt(min.x * BSBlock45Data.s_ScaleInverted);
            int        xMax  = xMin + isize.x;
            int        zMin  = Mathf.FloorToInt(min.z * BSBlock45Data.s_ScaleInverted);
            int        zMax  = zMin + isize.z;
            int        yMin  = Mathf.FloorToInt(min.y * BSBlock45Data.s_ScaleInverted);
            int        yMax  = yMin + isize.y;

            if (xMax < xMin + 1 || yMax < yMin + 1 || zMax <= zMin)
            {
                return;
            }



            for (int z = zMin; z < zMax; z++)
            {
                IntVector3 up = new IntVector3(xMax, yMax, z);
                IntVector3 dn = new IntVector3(xMin, yMin, z);

                ApplyBevel2_10(up, dn, upVSeal, upBSeal, BuildingMan.Blocks, materialType, new_voxels, old_voxels, indexes, refVoxelMap);
            }
        }
        // z positive direction
        else if (m_Rot == 1)
        {
            IntVector3 isize = CorrectSizeZY(size);
            int        xMin  = Mathf.FloorToInt(min.x * BSBlock45Data.s_ScaleInverted);
            int        xMax  = xMin + isize.x;
            int        zMin  = Mathf.FloorToInt(min.z * BSBlock45Data.s_ScaleInverted);
            int        zMax  = zMin + isize.z;
            int        yMin  = Mathf.FloorToInt(min.y * BSBlock45Data.s_ScaleInverted);
            int        yMax  = yMin + isize.y;

            if ((xMax < xMin + 1 || yMax < yMin + 1 || zMax <= zMin))
            {
                return;
            }

            for (int x = xMin; x < xMax; x++)
            {
                IntVector3 up = new IntVector3(x, yMax, zMax);
                IntVector3 dn = new IntVector3(x, yMin, zMin);

                ApplyBevel2_10(up, dn, upVSeal, upBSeal, BuildingMan.Blocks, materialType, new_voxels, old_voxels, indexes, refVoxelMap);
            }
        }
        // x negative direction
        else if (m_Rot == 2)
        {
            IntVector3 isize = CorrectSizeXY(size);
            int        xMin  = Mathf.FloorToInt(min.x * BSBlock45Data.s_ScaleInverted);
            int        xMax  = xMin + isize.x;
            int        zMin  = Mathf.FloorToInt(min.z * BSBlock45Data.s_ScaleInverted);
            int        zMax  = zMin + isize.z;
            int        yMin  = Mathf.FloorToInt(min.y * BSBlock45Data.s_ScaleInverted);
            int        yMax  = yMin + isize.y;


            if ((xMax < xMin + 1 || yMax < yMin + 1 || zMax <= zMin))
            {
                return;
            }


            for (int z = zMin; z < zMax; z++)
            {
                IntVector3 up = new IntVector3(xMin, yMax, z);
                IntVector3 dn = new IntVector3(xMax, yMin, z);

                ApplyBevel2_10(up, dn, upVSeal, upBSeal, BuildingMan.Blocks, materialType, new_voxels, old_voxels, indexes, refVoxelMap);
            }
        }
        // z negative direction
        else if (m_Rot == 3)
        {
            IntVector3 isize = CorrectSizeZY(size);
            int        xMin  = Mathf.FloorToInt(min.x * BSBlock45Data.s_ScaleInverted);
            int        xMax  = xMin + isize.x;
            int        zMin  = Mathf.FloorToInt(min.z * BSBlock45Data.s_ScaleInverted);
            int        zMax  = zMin + isize.z;
            int        yMin  = Mathf.FloorToInt(min.y * BSBlock45Data.s_ScaleInverted);
            int        yMax  = yMin + isize.y;

            if ((xMax < xMin + 1 || yMax < yMin + 1 || zMax <= zMin))
            {
                return;
            }

            for (int x = xMin; x < xMax; x++)
            {
                IntVector3 up = new IntVector3(x, yMax, zMin);
                IntVector3 dn = new IntVector3(x, yMin, zMax);

                ApplyBevel2_10(up, dn, upVSeal, upBSeal, BuildingMan.Blocks, materialType, new_voxels, old_voxels, indexes, refVoxelMap);
            }
        }


        // Extra Extendable
        FindExtraExtendableVoxels(dataSource, new_voxels, old_voxels, indexes, refVoxelMap);

        // Action
        if (indexes.Count != 0)
        {
            BSAction action = new BSAction();

            BSVoxelModify modify = new BSVoxelModify(indexes.ToArray(), old_voxels.ToArray(), new_voxels.ToArray(), dataSource, EBSBrushMode.Add);

            action.AddModify(modify);

            if (action.Do())
            {
                BSHistory.AddAction(action);
            }
        }
    }
コード例 #13
0
ファイル: BSBoxBrush.cs プロジェクト: shrubba/planetexplorers
    protected override void Do()
    {
        if (gizmoTrigger.RayCast)
        {
            return;
        }


        Vector3 min = Min * dataSource.ScaleInverted;
        Vector3 max = Max * dataSource.ScaleInverted;

        int     cnt    = pattern.size;
        Vector3 center = new Vector3((cnt - 1) / 2.0f, 0, (cnt - 1) / 2.0f);

        if (mode == EBSBrushMode.Add)
        {
            List <BSVoxel>               new_voxels  = new List <BSVoxel>();
            List <IntVector3>            indexes     = new List <IntVector3>();
            List <BSVoxel>               old_voxels  = new List <BSVoxel>();
            Dictionary <IntVector3, int> refVoxelMap = new Dictionary <IntVector3, int>();

            for (int x = (int)min.x; x < (int)max.x; x += cnt)
            {
                for (int y = (int)min.y; y < (int)max.y; y += cnt)
                {
                    for (int z = (int)min.z; z < (int)max.z; z += cnt)
                    {
                        for (int ix = 0; ix < cnt; ix++)
                        {
                            for (int iy = 0; iy < cnt; iy++)
                            {
                                for (int iz = 0; iz < cnt; iz++)
                                {
                                    // rote if need
                                    Vector3 offset = Quaternion.Euler(0, 90 * m_Rot, 0) * new Vector3(ix - center.x, iy - center.y, iz - center.z) + center;

                                    IntVector3 inpos = new IntVector3(Mathf.FloorToInt(x) + offset.x,
                                                                      Mathf.FloorToInt(y) + offset.y,
                                                                      Mathf.FloorToInt(z) + offset.z);

                                    // new voxel
                                    BSVoxel voxel = pattern.voxelList[ix, iy, iz];
                                    voxel.materialType = materialType;
                                    voxel.blockType    = BSVoxel.MakeBlockType(voxel.blockType >> 2, ((voxel.blockType & 0X3) + m_Rot) % 4);

                                    //olde voxel
                                    BSVoxel old_voxel = dataSource.SafeRead(inpos.x, inpos.y, inpos.z);

                                    new_voxels.Add(voxel);
                                    old_voxels.Add(old_voxel);
                                    indexes.Add(inpos);
                                    refVoxelMap.Add(inpos, 0);
                                }
                            }
                        }
                    }
                }
            }

            // Extra Extendable
            FindExtraExtendableVoxels(dataSource, new_voxels, old_voxels, indexes, refVoxelMap);

            // new Modify ?
            if (indexes.Count != 0)
            {
                BSAction action = new BSAction();

                BSVoxelModify modify = new BSVoxelModify(indexes.ToArray(), old_voxels.ToArray(), new_voxels.ToArray(), dataSource, mode);

                action.AddModify(modify);

                if (action.Do())
                {
                    BSHistory.AddAction(action);
                }
            }
        }
        else if (mode == EBSBrushMode.Subtract)
        {
            List <BSVoxel>               new_voxels  = new List <BSVoxel>();
            List <IntVector3>            indexes     = new List <IntVector3>();
            List <BSVoxel>               old_voxels  = new List <BSVoxel>();
            Dictionary <IntVector3, int> refVoxelMap = new Dictionary <IntVector3, int>();

            for (int x = (int)min.x; x < (int)max.x; x += cnt)
            {
                for (int y = (int)min.y; y < (int)max.y; y += cnt)
                {
                    for (int z = (int)min.z; z < (int)max.z; z += cnt)
                    {
                        for (int ix = 0; ix < cnt; ix++)
                        {
                            for (int iy = 0; iy < cnt; iy++)
                            {
                                for (int iz = 0; iz < cnt; iz++)
                                {
                                    IntVector3 inpos = new IntVector3(Mathf.FloorToInt(x) + ix,
                                                                      Mathf.FloorToInt(y) + iy,
                                                                      Mathf.FloorToInt(z) + iz);


                                    BSVoxel voxel = dataSource.Read(inpos.x, inpos.y, inpos.z);

                                    new_voxels.Add(new BSVoxel());
                                    indexes.Add(inpos);
                                    old_voxels.Add(voxel);
                                    refVoxelMap[inpos] = 0;

                                    // extendtable
                                    List <IntVector4> ext_posList = null;
                                    List <BSVoxel>    ext_voxels  = null;
                                    if (dataSource.ReadExtendableBlock(new IntVector4(inpos, 0), out ext_posList, out ext_voxels))
                                    {
                                        for (int i = 0; i < ext_voxels.Count; i++)
                                        {
                                            IntVector3 _ipos = new IntVector3(ext_posList[i].x, ext_posList[i].y, ext_posList[i].z);

                                            if (_ipos == inpos)
                                            {
                                                continue;
                                            }

                                            if (!refVoxelMap.ContainsKey(_ipos))
                                            {
                                                BSVoxel v = dataSource.Read(_ipos.x, _ipos.y, _ipos.z);
                                                old_voxels.Add(v);
                                                indexes.Add(_ipos);
                                                new_voxels.Add(new BSVoxel());
                                                refVoxelMap.Add(_ipos, 0);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Extra Extendable
            FindExtraExtendableVoxels(dataSource, new_voxels, old_voxels, indexes, refVoxelMap);

            // Action
            if (indexes.Count != 0)
            {
                BSAction action = new BSAction();

                BSVoxelModify modify = new BSVoxelModify(indexes.ToArray(), old_voxels.ToArray(), new_voxels.ToArray(), dataSource, mode);

                action.AddModify(modify);

                if (action.Do())
                {
                    BSHistory.AddAction(action);
                }
            }
        }
    }
コード例 #14
0
ファイル: BSIsoBrush.cs プロジェクト: shrubba/planetexplorers
    void Update()
    {
        if (GameConfig.IsInVCE)
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.O))
        {
            Gen = true;
        }

        if (Gen)
        {
            if (m_Cursor != null)
            {
                Destroy(m_Cursor.gameObject);
            }
            m_Cursor = BIsoCursor.CreateIsoCursor(GameConfig.GetUserDataPath() + BSSaveIsoBrush.s_IsoPath + File_Name + BSSaveIsoBrush.s_Ext);
            m_Rot    = 0;
            Gen      = false;
        }

        if (m_Cursor == null)
        {
            return;
        }

        if (BSInput.s_Cancel)
        {
            Cancel();
            if (onCancelClick != null)
            {
                onCancelClick();
            }
            return;
        }

        if (m_Cursor != null)
        {
            m_Cursor.gameObject.SetActive(true);
        }

        if (m_Cursor.ISO.m_HeadInfo.Mode == EBSVoxelType.Block)
        {
            if (BSMath.RayCastDrawTarget(BSInput.s_PickRay, BuildingMan.Blocks, out m_Target, BSMath.MC_ISO_VALUE, true, BuildingMan.Datas))
            {
                m_Cursor.gameObject.SetActive(true);

                Vector3 offset = Vector3.zero;
                offset.x = (m_Cursor.ISO.m_HeadInfo.xSize) / 2 * BSBlock45Data.s_Scale;
                offset.z = (m_Cursor.ISO.m_HeadInfo.zSize) / 2 * BSBlock45Data.s_Scale;


                if (Input.GetKeyDown(KeyCode.T))
                {
                    m_Rot = ++m_Rot > 3 ? 0 : m_Rot;
                }


                m_Cursor.SetOriginOffset(-offset);
                m_Cursor.transform.rotation = Quaternion.Euler(0, 90 * m_Rot, 0);

                // Adjust Offset
                FocusAjust();

                m_Cursor.transform.position = m_Target.cursor + m_FocusOffset * BSBlock45Data.s_Scale;

                if (Input.GetMouseButtonDown(0))
                {
                    if (BSInput.s_MouseOnUI)
                    {
                        return;
                    }

                    if (m_Cursor.gizmoTrigger.RayCast)
                    {
                        return;
                    }

                    // For History
                    m_OldVoxel.Clear();
                    m_NewVoxel.Clear();
                    m_Indexes.Clear();
                    m_VoxelMap.Clear();

                    m_Cursor.OutputVoxels(Vector3.zero, OnOutputBlocks);

                    // Extra Extendable
                    FindExtraExtendableVoxels(dataSource, m_NewVoxel, m_OldVoxel, m_Indexes, m_VoxelMap);

                    // For History
                    BSAction      action = new BSAction();
                    BSVoxelModify modify = new BSVoxelModify(m_Indexes.ToArray(), m_OldVoxel.ToArray(), m_NewVoxel.ToArray(), BuildingMan.Blocks, EBSBrushMode.Add);
                    if (!modify.IsNull())
                    {
                        action.AddModify(modify);
                    }

                    if (action.Do())
                    {
                        BSHistory.AddAction(action);
                        if (onBrushDo != null)
                        {
                            onBrushDo();
                        }
                    }
                }
            }
            else
            {
                m_Cursor.gameObject.SetActive(false);
            }
        }
        else if (m_Cursor.ISO.m_HeadInfo.Mode == EBSVoxelType.Block)
        {
            if (BSMath.RayCastDrawTarget(BSInput.s_PickRay, BuildingMan.Voxels, out m_Target, 1, true, BuildingMan.Datas))
            {
                m_Cursor.gameObject.SetActive(false);
                Debug.Log("Draw building Iso dont support the voxel");
                return;
            }
            else
            {
                m_Cursor.gameObject.SetActive(false);
            }
        }
    }
コード例 #15
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);
    }
コード例 #16
0
    protected override void Do()
    {
        int     cnt    = pattern.size;
        Vector3 center = new Vector3((cnt - 1) / 2.0f, 0, (cnt - 1) / 2.0f);

        if (mode == EBSBrushMode.Add)
        {
            List <BSVoxel>    new_voxels = new List <BSVoxel>();
            List <IntVector3> indexes    = new List <IntVector3>();
            List <BSVoxel>    old_voxels = new List <BSVoxel>();


            for (int x = 0; x < cnt; x++)
            {
                for (int y = 0; y < cnt; y++)
                {
                    for (int z = 0; z < cnt; z++)
                    {
                        // rote if need
                        Vector3 offset = Quaternion.Euler(0, 90 * m_Rot, 0) * new Vector3(x - center.x, y - center.y, z - center.z) + center;

                        IntVector3 inpos = new IntVector3(Mathf.FloorToInt(m_Cursor.x * dataSource.ScaleInverted) + offset.x,
                                                          Mathf.FloorToInt(m_Cursor.y * dataSource.ScaleInverted) + offset.y,
                                                          Mathf.FloorToInt(m_Cursor.z * dataSource.ScaleInverted) + offset.z);

                        // new voxel
                        BSVoxel voxel = pattern.voxelList[x, y, z];
                        voxel.materialType = materialType;
                        voxel.blockType    = BSVoxel.MakeBlockType(voxel.blockType >> 2, ((voxel.blockType & 0X3) + m_Rot) % 4);

                        //olde voxel
                        BSVoxel old_voxel = dataSource.SafeRead(inpos.x, inpos.y, inpos.z);

                        new_voxels.Add(voxel);
                        old_voxels.Add(old_voxel);
                        indexes.Add(inpos);
                    }
                }
            }

            // Modify
            if (indexes.Count != 0)
            {
                BSAction action = new BSAction();

                BSVoxelModify modify = new BSVoxelModify(indexes.ToArray(), old_voxels.ToArray(), new_voxels.ToArray(), dataSource, mode);

                action.AddModify(modify);

                if (action.Do())
                {
                    BSHistory.AddAction(action);
                }
            }
        }
        else if (mode == EBSBrushMode.Subtract)
        {
            List <BSVoxel>    new_voxels = new List <BSVoxel>();
            List <IntVector3> indexes    = new List <IntVector3>();
            List <BSVoxel>    old_voxels = new List <BSVoxel>();

            for (int x = 0; x < cnt; x++)
            {
                for (int y = 0; y < cnt; y++)
                {
                    for (int z = 0; z < cnt; z++)
                    {
                        IntVector3 inpos = new IntVector3(Mathf.FloorToInt(m_Cursor.x * dataSource.ScaleInverted) + x,
                                                          Mathf.FloorToInt(m_Cursor.y * dataSource.ScaleInverted) + y,
                                                          Mathf.FloorToInt(m_Cursor.z * dataSource.ScaleInverted) + z);

                        BSVoxel voxel = dataSource.Read(inpos.x, inpos.y, inpos.z);
                        new_voxels.Add(new BSVoxel());
                        indexes.Add(inpos);
                        old_voxels.Add(voxel);
                    }
                }
            }

            // Action
            if (indexes.Count != 0)
            {
                BSAction action = new BSAction();

                BSVoxelModify modify = new BSVoxelModify(indexes.ToArray(), old_voxels.ToArray(), new_voxels.ToArray(), dataSource, mode);

                action.AddModify(modify);

                if (action.Do())
                {
                    BSHistory.AddAction(action);
                }
            }
        }
    }