Example #1
0
        internal static void SaveRpgwoMap(string filename)
        {
            object mapElements = null;
            int    f           = FileSystem.FreeFile();

            mSurfaceArray = 0;

            if (modGlobals.FileExists(filename))
            {
                File.Delete(filename);
            }

            FileSystem.FileOpen(f, filename, OpenMode.Binary, OpenAccess.Write, OpenShare.LockWrite, -1);
            FileSystem.FilePut(f, mMapWidth);
            FileSystem.FilePut(f, mMapHeight);
            FileSystem.FilePut(f, mMapVersion);
            FileSystem.FilePut(f, mSurfaceArray);
            FileSystem.FilePut(f, mMapExtra);
            mNumberOfMonsters--;
            mNumberOfItems--;

            mv2NumberOfItems--;
            mv2NumberOfMonsters--;
            //Get Tile Id
            //ReDim mMap(1 To mMapWidth, 1 To mMapHeight)
            //Put #f, , mMap


            int countSurfaceItems = 1;


            tempmMapData = ArraysHelper.InitializeArray <mMapDataType>(countSurfaceItems);
            int MapSizeTotalCount = 0;
            int tempForEndVar     = mMapWidth;

            for (int x = 1; x <= tempForEndVar; x++)
            {
                int tempForEndVar2 = mMapHeight;
                for (int y = 1; y <= tempForEndVar2; y++)
                {
                    if (mMap[x - 1, y - 1] != 0)
                    {
                        tempmMapData[tempmMapData.GetUpperBound(0)].Xpos    = (short)x;
                        tempmMapData[tempmMapData.GetUpperBound(0)].Ypos    = (short)y;
                        tempmMapData[tempmMapData.GetUpperBound(0)].Surface = (short)mMap[x - 1, y - 1];
                        MapSizeTotalCount++;
                        tempmMapData = ArraysHelper.RedimPreserve(tempmMapData, new int[] { tempmMapData.GetUpperBound(0) + 2 });
                    }
                }
            }
            tempmMapData = ArraysHelper.RedimPreserve(tempmMapData, new int[] { tempmMapData.GetUpperBound(0) });

            if (mSurfaceArray == 1)
            {
                FileSystem.FilePut(f, mapElements);
                FileSystem.FilePut(f, tempmMapData);
            }
            else
            {
                FileSystem.FilePut(f, mMap);
            }


            if (v2Map)
            {
                FileSystem.FilePut(f, mv2NumberOfItems);
                // MsgBox mNumberOfItems
                //ReDim mItems(1 To mNumberOfItems)
                if (mv2NumberOfItems > 0)
                {
                    mItems = ArraysHelper.RedimPreserve(mItems, new int[] { modRpgwoMapFormat.mv2NumberOfItems });
                    FileSystem.FilePut(f, mItems);
                }
                //MsgBox Loc(1)
                FileSystem.FilePut(f, mv2NumberOfMonsters);
                //MsgBox mNumberOfMonsters
                //ReDim mMonsters(1 To mNumberOfMonsters)
                if (mv2NumberOfMonsters > 0)
                {
                    mMonsters = ArraysHelper.RedimPreserve(mMonsters, new int[] { modRpgwoMapFormat.mv2NumberOfMonsters });
                    FileSystem.FilePut(f, mMonsters);
                }
            }
            else
            {
                FileSystem.FilePut(f, mNumberOfItems);
                // MsgBox mNumberOfItems
                //ReDim mItems(1 To mNumberOfItems)
                if (mNumberOfItems > 0)
                {
                    mItems = ArraysHelper.RedimPreserve(mItems, new int[] { modRpgwoMapFormat.mNumberOfItems });
                    FileSystem.FilePut(f, mItems);
                }



                FileSystem.FilePut(f, mNumberOfMonsters);

                //MsgBox mNumberOfMonsters
                //ReDim mMonsters(1 To mNumberOfMonsters)
                if (mNumberOfMonsters > 0)
                {
                    mMonsters = ArraysHelper.RedimPreserve(mMonsters, new int[] { modRpgwoMapFormat.mNumberOfMonsters });
                    FileSystem.FilePut(f, mMonsters);
                }
            }
            // MsgBox "notes start:" & Loc(f)
            short k = 5000;

            FileSystem.FilePut(f, k);
            string notes = new string('\0', 5000);

            notes = StringsHelper.GetFixedLengthString(new String(' ', k), 5000);
            FileSystem.FilePut(f, notes);
            //Get Notes
            FileSystem.FileClose(f);
        }
Example #2
0
        private void cmdSelect_Click(Object eventSender, EventArgs eventArgs)
        {
            string Filename = "";

            CommonDialog1Open.Title            = "Select .rsf file";
            CommonDialog1Open.Filter           = "Script Files (*.rsf)|*.rsf";
            CommonDialog1Open.InitialDirectory = Path.GetDirectoryName(Application.ExecutablePath);
            CommonDialog1Open.ShowDialog();
            if (Strings.Len(CommonDialog1Open.FileName) == 0)
            {
                return;
            }
            Filename = CommonDialog1Open.FileName;
            string data = "";

            modRpgwoMapFormat.mNumberOfItems    = 1;
            modRpgwoMapFormat.mNumberOfMonsters = 1;

            modRpgwoMapFormat.mv2NumberOfItems    = 1;
            modRpgwoMapFormat.mv2NumberOfMonsters = 1;

            if (cboVersion.Text == "V1")
            {
                modRpgwoMapFormat.v2Map       = false;
                modRpgwoMapFormat.mMapVersion = StringsHelper.GetFixedLengthString("1.0       RPGWO Edit", 30);
            }
            else
            {
                modRpgwoMapFormat.v2Map       = true;
                modRpgwoMapFormat.mMapVersion = StringsHelper.GetFixedLengthString("2.0       RPGWO Edit", 30);
            }


            FileSystem.FileOpen(1, Filename, OpenMode.Input, OpenAccess.Default, OpenShare.Default, -1);
            string[] DataArray    = null;
            short    Xpos         = 0;
            short    Ypos         = 0;
            short    ImageNumber  = 0;
            int      SpawnSeconds = 0;

            while (!FileSystem.EOF(1))
            {
                data = FileSystem.LineInput(1);
                if (data.StartsWith("/MAPITEMCLEAR "))
                {
                    data      = data.Substring(Math.Max(data.Length - (Strings.Len(data) - 14), 0));
                    DataArray = (string[])modGlobals.Tokenize(ref data);
                    modRpgwoMapFormat.mMapHeight = Convert.ToInt16(Double.Parse(DataArray[0]));
                    modRpgwoMapFormat.mMapWidth  = Convert.ToInt16(Double.Parse(DataArray[0]));
                    modRpgwoMapFormat.mMap       = new short[Convert.ToInt16(Double.Parse(DataArray[0])), Convert.ToInt16(Double.Parse(DataArray[0]))];


                    //  ReDim Map(Right(Data, Len(Data) - 14) + 5, Right(Data, Len(Data) - 14) + 5)
                    //  ReDim ItemMap(Right(Data, Len(Data) - 14) + 5, Right(Data, Len(Data) - 14) + 5)
                    // ReDim MonsterMap(Right(Data, Len(Data) - 14) + 5, Right(Data, Len(Data) - 14) + 5)
                }
                //Load Items
                if (data.StartsWith("/ITEMIXY "))
                {
                    //Now tokenize the remaining data and break into the parts of image# and x and y position

                    data      = data.Substring(Math.Max(data.Length - (Strings.Len(data) - 9), 0));
                    DataArray = (string[])modGlobals.Tokenize(ref data);

                    ImageNumber = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[0])));

                    Xpos = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[1])));
                    Ypos = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[2])));
                    modRpgwoMapFormat.mItems = ArraysHelper.RedimPreserve(modRpgwoMapFormat.mItems, new int[] { modRpgwoMapFormat.mNumberOfItems + 1 });
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].ItemID       = (short)ImageNumber;
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].Xpos         = (short)Xpos;
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].Ypos         = (short)Ypos;
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].a            = true;
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].SpawnTimeout = (float)Math.Floor(Double.Parse(DataArray[3]));
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].Data1        = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[4])));
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].Data2        = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[5])));
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].Data3        = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[6])));
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].Data4        = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[7])));
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].Data5        = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[8])));
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].Reset        = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[9])));
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].Writing      = StringsHelper.GetFixedLengthString(new String(' ', 200), 200);
                    // mItems(mNumberOfItems).Trigger = Int(DataArray(10))

                    modRpgwoMapFormat.mNumberOfItems++;
                    modRpgwoMapFormat.mv2NumberOfItems++;
                }
                //Spawn items
                if (data.StartsWith("/ITEMSPAWNIXY "))
                {
                    data        = data.Substring(Math.Max(data.Length - (Strings.Len(data) - 14), 0));
                    DataArray   = (string[])modGlobals.Tokenize(ref data);
                    ImageNumber = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[0])));

                    Xpos = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[1])));
                    Ypos = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[2])));
                    modRpgwoMapFormat.mItems = ArraysHelper.RedimPreserve(modRpgwoMapFormat.mItems, new int[] { modRpgwoMapFormat.mNumberOfItems + 1 });
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].ItemID       = (short)ImageNumber;
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].Xpos         = (short)Xpos;
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].Ypos         = (short)Ypos;
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].a            = true;
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].SpawnTimeout = (float)Math.Floor(Double.Parse(DataArray[3]));
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].Data1        = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[4])));
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].Data2        = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[5])));
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].Data3        = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[6])));
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].Data4        = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[7])));
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].Data5        = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[8])));
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].Trigger      = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[8])));
                    modRpgwoMapFormat.mItems[modRpgwoMapFormat.mNumberOfItems - 1].Uses         = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[9])));

                    modRpgwoMapFormat.mNumberOfItems++;
                    modRpgwoMapFormat.mv2NumberOfItems++;
                }
                //Text on item
                if (data.StartsWith("/ITEMTEXTIXY "))
                {
                    data      = data.Substring(Math.Max(data.Length - (Strings.Len(data) - 13), 0));
                    DataArray = (string[])modGlobals.Tokenize(ref data);
                    Xpos      = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[0])));
                    Ypos      = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[1])));
                    //'ItemMap(Xpos, Ypos).ItemText = DataArray(2)
                }

                //Surface the ground
                if (data.StartsWith("/SURFACEIXY "))
                {
                    //Now tokenize the remaining data and break into the parts of image# and x and y position

                    data      = data.Substring(Math.Max(data.Length - (Strings.Len(data) - 12), 0));
                    DataArray = (string[])modGlobals.Tokenize(ref data);

                    ImageNumber = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[0])));
                    Xpos        = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[1])));
                    Ypos        = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[2])));

                    modRpgwoMapFormat.mMap[Xpos - 1, Ypos - 1] = ImageNumber;
                }
                //Load Monsters
                if (data.StartsWith("/MONSTERSPAWNADDXY "))
                {
                    data      = data.Substring(Math.Max(data.Length - (Strings.Len(data) - 19), 0));
                    DataArray = (string[])modGlobals.Tokenize(ref data);

                    ImageNumber  = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[2])));
                    Xpos         = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[0])));
                    Ypos         = Convert.ToInt16(Math.Floor(Double.Parse(DataArray[1])));
                    SpawnSeconds = Convert.ToInt32(Math.Floor(Double.Parse(DataArray[3])));
                    modRpgwoMapFormat.mMonsters = ArraysHelper.RedimPreserve(modRpgwoMapFormat.mMonsters, new int[] { modRpgwoMapFormat.mNumberOfMonsters + 1 });
                    modRpgwoMapFormat.mMonsters[modRpgwoMapFormat.mNumberOfMonsters - 1].Xpos      = (short)Xpos;
                    modRpgwoMapFormat.mMonsters[modRpgwoMapFormat.mNumberOfMonsters - 1].Ypos      = (short)Ypos;
                    modRpgwoMapFormat.mMonsters[modRpgwoMapFormat.mNumberOfMonsters - 1].MonsterId = (short)ImageNumber;
                    modRpgwoMapFormat.mMonsters[modRpgwoMapFormat.mNumberOfMonsters - 1].Timeout   = (short)SpawnSeconds;
                    modRpgwoMapFormat.mMonsters[modRpgwoMapFormat.mNumberOfMonsters - 1].a         = true;
                    modRpgwoMapFormat.mNumberOfMonsters++;
                    modRpgwoMapFormat.mv2NumberOfMonsters++;
                    //MonsterMap(Xpos, Ypos).ImageNumber = ImageNumber
                    //MonsterMap(Xpos, Ypos).MonsterArrayID = GetMonsterArrayId(ImageNumber)
                    //MonsterMap(Xpos, Ypos).MonsterId = Monsters(MonsterMap(Xpos, Ypos).MonsterArrayID).MonsterId 'ImageNumber
                    //MonsterMap(Xpos, Ypos).Life = Monsters(MonsterMap(Xpos, Ypos).MonsterArrayID).Life
                    //MonsterMap(Xpos, Ypos).Stamina = Monsters(MonsterMap(Xpos, Ypos).MonsterArrayID).Stamina
                    //MonsterMap(Xpos, Ypos).Mana = Monsters(MonsterMap(Xpos, Ypos).MonsterArrayID).Mana
                    //MonsterMap(Xpos, Ypos).SpawnSeconds = SpawnSeconds
                    //MonsterMap(Xpos, Ypos).OldX = Xpos
                    //MonsterMap(Xpos, Ypos).OldY = Ypos
                    //MonsterMap(Xpos, Ypos).OldMonsterArrayID = MonsterMap(Xpos, Ypos).MonsterArrayID
                    //MonsterMap(Xpos, Ypos).ImageType = Monsters(MonsterMap(Xpos, Ypos).MonsterArrayID).ImageType
                }
            }
            ;
            FileSystem.FileClose(1);

            //save the file
            if (modRpgwoMapFormat.v2Map)
            {
                modRpgwoMapFormat.SaveRpgwoMap(Filename + "v2-3.map");
            }
            else
            {
                modRpgwoMapFormat.SaveRpgwoMap(Filename + "v1.map");
            }
            //End of rsf file

            MessageBox.Show("Done!", AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));
        }