Exemplo n.º 1
0
        private bool UnitCollsionCheck(Vector2 pos, int unitid, bool IsBuilding, bool IsDrawRedLine)
        {
            if (mapeditor.UnitPalleteStackAllow)
            {
                return(true);
            }

            byte height = (byte)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Elevation Level", unitid).Data;
            bool IsAir  = false;

            if (height >= 12)
            {
                IsAir = true;
            }

            ushort uleft  = (byte)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Unit Size Left", unitid).Data;
            ushort uup    = (byte)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Unit Size Up", unitid).Data;
            ushort uright = (byte)(Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Unit Size Right", unitid).Data + 1);
            ushort udown  = (byte)(Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Unit Size Down", unitid).Data + 1);

            Vector2 min  = pos - new Vector2(uleft, uup);
            Vector2 max  = pos + new Vector2(uright, udown);
            Rect    rect = new Rect(new Point(min.X, min.Y), new Point(max.X, max.Y));


            //====지형====
            if (!IsAir)
            {
                if (IsBuilding)
                {
                    ushort bwidth  = (byte)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "StarEdit Placement Box Width", unitid).Data;
                    ushort bheight = (byte)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "StarEdit Placement Box Height", unitid).Data;


                    min = pos - new Vector2(bwidth, bheight) / 2;
                    max = pos + new Vector2(bwidth, bheight) / 2;
                }


                Vector2 mapmin = new Vector2((float)Math.Floor(min.X / 32), (float)Math.Floor(min.Y / 32));
                Vector2 mapmax = new Vector2((float)Math.Floor((max.X - 1) / 32), (float)Math.Floor((max.Y - 1) / 32));

                Vector2 minimin = new Vector2((float)Math.Floor(min.X / 8), (float)Math.Floor(min.Y / 8));
                Vector2 minimax = new Vector2((float)Math.Floor((max.X - 1) / 8), (float)Math.Floor((max.Y - 1) / 8));

                Vector2 gab = mapmax - mapmin;

                for (int Y = 0; Y <= gab.Y; Y++)
                {
                    for (int X = 0; X <= gab.X; X++)
                    {
                        int cxti = (int)(mapmin.X + X);
                        int cyti = (int)(mapmin.Y + Y);

                        if (cxti < 0 || cyti < 0)
                        {
                            continue;
                        }
                        if (cxti >= mapeditor.mapdata.WIDTH || cyti >= mapeditor.mapdata.HEIGHT)
                        {
                            continue;
                        }
                        int tileindex = (int)((mapmin.X + X) + (mapmin.Y + Y) * mapeditor.mapdata.WIDTH);


                        ushort MTXM = mapeditor.mapdata.MTXM[tileindex];


                        ushort megaindex = tileSet.GetMegaTileIndex(mapeditor.opt_drawType, mapeditor.mapdata.TILETYPE, MTXM);
                        vf4    vf4       = tileSet.GetVf4(mapeditor.opt_drawType, mapeditor.mapdata.TILETYPE, megaindex);
                        cv5    cv5       = tileSet.GetCV5(mapeditor.opt_drawType, mapeditor.mapdata.TILETYPE, MTXM);

                        if (mapeditor.UnitPalleteBuildingFix & IsBuilding)
                        {
                            //빌딩

                            if (((cv5.Flags & 0x0040) > 0) | ((cv5.Flags & 0x0080) > 0))
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            //일반 판정
                            if (vf4.IsWall)
                            {
                                return(false);
                            }

                            if (X == 0 | X == gab.X | Y == 0 | Y == gab.Y)
                            {
                                //가장자리
                                for (int my = 0; my < 4; my++)
                                {
                                    for (int mx = 0; mx < 4; mx++)
                                    {
                                        Vector2 minitilepos = new Vector2((mapmin.X + X) * 4 + mx, (mapmin.Y + Y) * 4 + my);

                                        if ((minimin.X <= minitilepos.X) & (minitilepos.X <= minimax.X) &
                                            (minimin.Y <= minitilepos.Y) & (minitilepos.Y <= minimax.Y))
                                        {
                                            int index = mx + my * 4;

                                            if ((vf4.flags[index] & 0b1) == 0)
                                            {
                                                return(false);
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                //안쪽
                                if (!vf4.IsGround)
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                }
            }


            //====유닛====
            for (int i = 0; i < mapeditor.mapdata.UNIT.Count; i++)
            {
                CUNIT cUNIT = mapeditor.mapdata.UNIT[i];

                int _unitid = cUNIT.unitID;

                byte _height = (byte)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Elevation Level", _unitid).Data;
                bool _IsAir  = false;
                if (_height >= 12)
                {
                    _IsAir = true;
                }
                if (_IsAir != IsAir)
                {
                    continue;
                }

                ushort _uleft  = (byte)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Unit Size Left", _unitid).Data;
                ushort _uup    = (byte)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Unit Size Up", _unitid).Data;
                ushort _uright = (byte)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Unit Size Right", _unitid).Data;
                ushort _udown  = (byte)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Unit Size Down", _unitid).Data;

                _uleft -= 1;
                _uup   -= 1;


                Vector2 _pos  = new Vector2(cUNIT.X, cUNIT.Y);
                Vector2 _min  = _pos - new Vector2(_uleft, _uup);
                Vector2 _max  = _pos + new Vector2(_uright, _udown);
                Rect    _rect = new Rect(new Point(_min.X, _min.Y), new Point(_max.X, _max.Y));


                if (Rect.Intersect(rect, _rect) != Rect.Empty)
                {
                    //충돌상황
                    if (IsDrawRedLine)
                    {
                        Vector2 mousepos = mapeditor.PosMapToScreen(_pos);

                        double _l = (_uleft + 1) * mapeditor.opt_scalepercent;
                        double _u = (_uup + 1) * mapeditor.opt_scalepercent;
                        double _r = (_uright + 1) * mapeditor.opt_scalepercent;
                        double _d = (_udown + 1) * mapeditor.opt_scalepercent;
                        DrawRect(_spriteBatch, new Vector2(mousepos.X - (float)_l, mousepos.Y - (float)_u), new Vector2(mousepos.X + (float)_r, mousepos.Y + (float)_d), Color.Red, 1);
                    }
                    return(false);
                }
            }


            return(true);
        }
Exemplo n.º 2
0
        public TileSet()
        {
            cv5data       = new Dictionary <TileType, cv5[]>();
            vf4data       = new Dictionary <TileType, vf4[]>();
            DoodadPallets = new Dictionary <TileType, Dictionary <ushort, DoodadPallet> >();
            DoodadGroups  = new Dictionary <TileType, List <DoodadPalletGroup> >();


            foreach (TileType tileType in Enum.GetValues(typeof(TileType)))
            {
                {
                    string fname = AppDomain.CurrentDomain.BaseDirectory + $"Data\\TileSet\\{tileType.ToString()}.cv5";

                    if (Global.Setting.Vals[Global.Setting.Settings.Program_GRPLoad] == "true")
                    {
                        fname = AppDomain.CurrentDomain.BaseDirectory + $"CascData\\TileSet\\{tileType.ToString()}.cv5";
                    }


                    BinaryReader br = new BinaryReader(new MemoryStream(File.ReadAllBytes(fname)));



                    int   cv5count = (int)br.BaseStream.Length / 52;
                    cv5[] _cv5data = new cv5[cv5count];
                    Dictionary <ushort, DoodadPallet> DoodadDic = new Dictionary <ushort, DoodadPallet>();
                    for (int i = 0; i < cv5count; i++)
                    {
                        cv5 _cv5 = new cv5();
                        _cv5.Index                   = br.ReadUInt16();
                        _cv5.Flags                   = br.ReadUInt16();
                        _cv5.Left_OverlayID          = br.ReadUInt16();
                        _cv5.Top                     = br.ReadUInt16();
                        _cv5.Right_DoodadGroupString = br.ReadUInt16();
                        _cv5.Bottom                  = br.ReadUInt16();
                        _cv5.Unknown1_DoodadID       = br.ReadUInt16();
                        _cv5.EdgeUp_Width            = br.ReadUInt16();
                        _cv5.Unknown2_Height         = br.ReadUInt16();
                        _cv5.EdgeDown                = br.ReadUInt16();
                        _cv5.tiles                   = new ushort[16];

                        for (int p = 0; p < 16; p++)
                        {
                            _cv5.tiles[p] = br.ReadUInt16();
                        }



                        if (_cv5.Index == 1)
                        {
                            //두데드
                            ushort dddID     = _cv5.Unknown1_DoodadID;
                            ushort tblString = _cv5.Right_DoodadGroupString;
                            ushort dddWidth  = _cv5.EdgeUp_Width;
                            ushort dddHeight = _cv5.Unknown2_Height;

                            ushort dddOverlayID = _cv5.Left_OverlayID;
                            ushort dddFlags     = _cv5.Flags;


                            ushort dddGroup = (ushort)i;
                            if (!DoodadDic.ContainsKey(dddID))
                            {
                                DoodadPallet doodadPallet = new DoodadPallet();

                                doodadPallet.dddID = dddID;
                                if (tblString != 0)
                                {
                                    doodadPallet.tblString = Global.WindowTool.stat_txt.Strings[tblString - 1].val1;
                                    //doodadPallet.tblString = Global.WindowTool.stat_txt.Strings[tblString + 1].val1;
                                    doodadPallet.dddWidth     = dddWidth;
                                    doodadPallet.dddHeight    = dddHeight;
                                    doodadPallet.dddOverlayID = dddOverlayID;
                                    doodadPallet.dddFlags     = dddFlags;
                                    doodadPallet.dddGroup     = dddGroup;


                                    DoodadDic.Add(dddID, doodadPallet);
                                }
                            }
                        }



                        _cv5data[i] = _cv5;
                    }

                    cv5data.Add(tileType, _cv5data);
                    DoodadPallets.Add(tileType, DoodadDic);

                    br.Close();
                }
                {
                    string fname = AppDomain.CurrentDomain.BaseDirectory + $"Data\\TileSet\\{tileType.ToString()}.vf4";

                    if (Global.Setting.Vals[Global.Setting.Settings.Program_GRPLoad] == "true")
                    {
                        fname = AppDomain.CurrentDomain.BaseDirectory + $"CascData\\TileSet\\{tileType.ToString()}.vf4";
                    }

                    BinaryReader br       = new BinaryReader(new MemoryStream(File.ReadAllBytes(fname)));
                    int          vf4count = (int)br.BaseStream.Length / 32;
                    vf4[]        _vf4data = new vf4[vf4count];

                    for (int i = 0; i < vf4count; i++)
                    {
                        int walkflag = 0;
                        vf4 _vf4     = new vf4();
                        _vf4.flags = new ushort[16];

                        for (int x = 0; x < 16; x++)
                        {
                            ushort flag = br.ReadUInt16();

                            _vf4.flags[x] = flag;
                            if ((flag & 0b1) > 0)
                            {
                                walkflag += 1;
                            }
                        }
                        if (walkflag == 16)
                        {
                            //전체가 뚫린것
                            _vf4.IsGround = true;
                        }
                        if (walkflag == 0)
                        {
                            //전체가 막힌것
                            _vf4.IsWall = true;
                        }

                        _vf4data[i] = _vf4;
                    }



                    vf4data.Add(tileType, _vf4data);
                    br.Close();
                }
                {
                    List <DoodadPalletGroup> doodadPalletGroups = new List <DoodadPalletGroup>();
                    List <DoodadPallet>      doodad             = DoodadPallets[tileType].Values.ToList();
                    for (int i = 0; i < doodad.Count; i++)
                    {
                        string groupname = doodad[i].tblString;

                        DoodadPalletGroup doodadPalletGroup = doodadPalletGroups.Find((x) => x.groupname == groupname);
                        if (doodadPalletGroup == null)
                        {
                            doodadPalletGroup           = new DoodadPalletGroup();
                            doodadPalletGroup.groupname = groupname;
                            doodadPalletGroups.Add(doodadPalletGroup);
                        }


                        doodadPalletGroup.dddids.Add(doodad[i].dddID);
                    }
                    DoodadGroups.Add(tileType, doodadPalletGroups);
                }
            }
        }
Exemplo n.º 3
0
        private void RenderTileOverlay(bool IsDrawGrp)
        {
            bool WalkableOverlay = false;
            bool BulidingOverlay = false;

            if (mapeditor.PalleteLayer == Control.MapEditor.Layer.Unit)
            {
                if (mapeditor.mapDataBinding.UNIT_BRUSHMODE)
                {
                    if (mapeditor.unit_PasteMode)
                    {
                    }
                    else
                    {
                        int  unitid = (ushort)mapeditor.UnitPallete.SelectIndex;
                        byte gflag  = (byte)Global.WindowTool.scdata.datFile.Values(DatFile.DatFiles.units, "Staredit Group Flags", unitid).Data;

                        if ((gflag & 0x10) > 0)
                        {
                            //건물
                            BulidingOverlay = true;
                        }
                        else
                        {
                            WalkableOverlay = true;
                        }
                    }
                }
            }



            float width  = (float)this.ActualWidth;
            float height = (float)this.ActualHeight;



            Vector2 MapMin  = mapeditor.PosMapToScreen(new Vector2(0, 0));
            Vector2 MapMax  = mapeditor.PosMapToScreen(new Vector2(mapeditor.mapdata.WIDTH, mapeditor.mapdata.HEIGHT) * 32);
            Vector2 MapSize = MapMax - MapMin;


            if (!mapeditor.view_Tile)
            {
                return;
            }


            int startxti = (int)(mapeditor.opt_xpos / 32d);
            int startyti = (int)(mapeditor.opt_ypos / 32d);

            float mag = (float)(32 * mapeditor.opt_scalepercent);



            float startx = (float)-((mapeditor.opt_xpos % 32) * mapeditor.opt_scalepercent);
            float starty = (float)-((mapeditor.opt_ypos % 32) * mapeditor.opt_scalepercent);



            int tileindex = 0;

            int cxti = startxti;
            int cyti = startyti;


            _spriteBatch.Begin(blendState: BlendState.NonPremultiplied, samplerState: SamplerState.PointClamp);
            for (float yi = starty; yi < height; yi += mag)
            {
                cxti = startxti;
                for (float xi = startx; xi < width; xi += mag)
                {
                    if (cxti < 0 || cyti < 0)
                    {
                        cxti++;
                        continue;
                    }
                    if (cxti >= mapeditor.mapdata.WIDTH || cyti >= mapeditor.mapdata.HEIGHT)
                    {
                        cxti++;
                        continue;
                    }


                    tileindex = cxti + cyti * mapeditor.mapdata.WIDTH;
                    ushort MTXM = mapeditor.mapdata.TILE[tileindex];
                    if (IsDrawGrp)
                    {
                        ushort megaindex = tileSet.GetMegaTileIndex(mapeditor.opt_drawType, mapeditor.mapdata.TILETYPE, MTXM);

                        if (WalkableOverlay)
                        {
                            vf4 vf4 = tileSet.GetVf4(mapeditor.opt_drawType, mapeditor.mapdata.TILETYPE, megaindex);
                            if (!vf4.IsGround)
                            {
                                if (vf4.IsWall)
                                {
                                    _spriteBatch.Draw(gridtexture, new Vector2(xi, yi), null, new Color(255, 128, 0, 64), 0, Vector2.Zero, (float)mapeditor.opt_scalepercent * 32, SpriteEffects.None, 0);
                                }
                                else
                                {
                                    for (int ym = 0; ym < 4; ym++)
                                    {
                                        for (int xm = 0; xm < 4; xm++)
                                        {
                                            int index = xm + ym * 4;

                                            if ((vf4.flags[index] & 0b1) == 0)
                                            {
                                                float xmp = (float)(xi + xm * 8 * mapeditor.opt_scalepercent);
                                                float ymp = (float)(yi + ym * 8 * mapeditor.opt_scalepercent);

                                                _spriteBatch.Draw(gridtexture, new Vector2(xmp, ymp), null, new Color(255, 128, 0, 64), 0, Vector2.Zero, (float)mapeditor.opt_scalepercent * 8, SpriteEffects.None, 0);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (BulidingOverlay)
                        {
                            cv5 cv5 = tileSet.GetCV5(mapeditor.opt_drawType, mapeditor.mapdata.TILETYPE, MTXM);
                            //_spriteBatch.DrawString(_font, cv5.Flags.ToString("X"), new Vector2(xi, yi), Color.Red);
                            if (((cv5.Flags & 0x0040) > 0) | ((cv5.Flags & 0x0080) > 0))
                            {
                                //빌딩 건설불가능
                                _spriteBatch.Draw(gridtexture, new Vector2(xi, yi), null, new Color(255, 0, 0, 64), 0, Vector2.Zero, (float)mapeditor.opt_scalepercent * 32, SpriteEffects.None, 0);
                            }
                        }
                    }
                    else
                    {
                        _spriteBatch.DrawString(_font, MTXM.ToString(), new Vector2(xi, yi), Color.Red);
                    }
                    cxti++;
                }
                cyti++;
            }
            _spriteBatch.End();
        }