Advertisement
Elec0

Untitled

Dec 4th, 2012 (edited)
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.  Persistable = 0  'NotPersistable
  5.  DataBindingBehavior = 0  'vbNone
  6.  DataSourceBehavior  = 0  'vbNone
  7.  MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "clsMap"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15.  
  16. ''
  17. ' This class represents a map account. It provides methods
  18. ' to handle data manipulation along with its own saving
  19. ' and loading methods.
  20. '
  21. ' @version 1.0.0
  22. ' @author smchronos
  23. '
  24.  
  25. ''
  26. ' The structure representing the data stored in the Map Class.
  27. '
  28. Private Type MapRec
  29.     name As String * 20
  30.     Revision As Long
  31.     Moral As Byte
  32.     Up As Integer
  33.     Down As Integer
  34.     Left As Integer
  35.     Right As Integer
  36.     Music As Integer
  37.     BootMap As Integer
  38.     BootX As Byte
  39.     BootY As Byte
  40.     Shop As Integer
  41.     Indoors As Byte
  42.     Tile(0 To 15, 0 To 11) As clsTile
  43.     NPC(1 To 14) As Long
  44.     Server As Boolean
  45.     Respawn As Byte
  46.     Weather As Byte
  47. End Type
  48.  
  49. Private mapData As MapRec
  50. Private tilesInitialized As Boolean '// Whether or not the tiles have been initialized
  51.  
  52. ''
  53. ' This subroutine is called when the class instance is initialized.
  54. ' This merely sets all of the data to default values.
  55. ' No parameters are allowed by VB6, unfortunately.
  56. '
  57. Private Sub Class_Initialize()
  58.     reset
  59.     initTiles
  60. End Sub
  61.  
  62. ''
  63. ' This subroutine is called when the class instance is deleted.
  64. ' This merely sets all of the data to empty values as a safety precaution.
  65. ' No parameters are allowed by VB6, unfortunately.
  66. '
  67. Private Sub Class_Terminate()
  68.     reset
  69. End Sub
  70.  
  71. ''
  72. ' This subroutine clears all of the fields in this class's data structure.
  73. '
  74. Public Sub reset()
  75.     Dim x As Byte, y As Byte
  76.     mapData.name = ""
  77.     mapData.Revision = 0
  78.     mapData.Moral = 0
  79.     mapData.Up = 0
  80.     mapData.Down = 0
  81.     mapData.Left = 0
  82.     mapData.Right = 0
  83.     mapData.Music = 0
  84.     mapData.BootMap = 0
  85.     mapData.BootX = 0
  86.     mapData.BootY = 0
  87.     mapData.Shop = 0
  88.     mapData.Indoors = 0
  89.    
  90.     '// Set all tiles to nothing
  91.    For y = 0 To 11
  92.         For x = 0 To 15
  93.             Set mapData.Tile(x, y) = Nothing
  94.         Next x
  95.     Next y
  96.    
  97.     '// Loop through and clear all NPC numbers
  98.    For x = 1 To 14
  99.         mapData.NPC(x) = 0
  100.     Next x
  101.     mapData.Server = 0
  102.     mapData.Respawn = 0
  103.     mapData.Weather = 0
  104.    
  105.     '// Tiles are no longer initialized
  106.    tilesInitialized = False
  107. End Sub
  108.  
  109. ''
  110. ' This subroutine clears the memory associated with this Map.
  111. '
  112. Public Sub wipeMemory()
  113.     zeroMemory mapData, Len(mapData)
  114. End Sub
  115.  
  116. ''
  117. ' This subroutine creates a new instance of each tile in the Map's data.
  118. '
  119. Public Sub initTiles()
  120.     Dim y As Long, x As Long
  121.     '// Create a new instance of each tile
  122.    For y = 0 To 11
  123.         For x = 0 To 15
  124.             Set mapData.Tile(x, y) = New clsTile
  125.         Next x
  126.     Next y
  127.    
  128.     '// Tiles are now initialized
  129.    tilesInitialized = True
  130. End Sub
  131.  
  132. ''
  133. ' This subroutine loads the Map's data from a file.
  134. '
  135. ' @param fileName The string containing the path to the Map file.
  136. '
  137. Public Sub loadMapFromFile(ByVal fileName As String)
  138.     Dim f As Integer
  139.     f = FreeFile '// Grab an open slot to use for file IO
  140.    
  141.     '// Reset the data first to make sure nothing is left over
  142.    reset
  143.    
  144.     '// Open and store the data
  145.    Open fileName For Binary As #f
  146.         loadMapFromOpenFile f
  147.     Close #f
  148. End Sub
  149.  
  150. ''
  151. ' This subroutine saves the Map's data to a file.
  152. '
  153. ' @param fileName The string containing the path to the Map file
  154. '           (creates one if it does not exist).
  155. '
  156. Public Sub saveMapToFile(ByVal fileName As String)
  157.     Dim f As Integer
  158.     f = FreeFile '// Grab an open slot to use for file IO
  159.    
  160.     '// Open the file and write the data from the Map structure object
  161.    Open fileName For Binary As #f
  162.         saveMapToOpenFile f
  163.     Close #f
  164. End Sub
  165.  
  166. ''
  167. ' This subroutine loads the Map's data from an already open file.
  168. '
  169. ' @param fileSlot The integer pointing to the open file.
  170. '
  171. Public Sub loadMapFromOpenFile(ByVal fileSlot As Integer)
  172.     Dim y As Long, x As Long
  173.    
  174.     '// Initialize the tile data if necessary
  175.    If Not tilesInitialized Then initTiles
  176.    
  177.     Get #fileSlot, , mapData.name
  178.     Get #fileSlot, , mapData.Revision
  179.     Get #fileSlot, , mapData.Moral
  180.     Get #fileSlot, , mapData.Up
  181.     Get #fileSlot, , mapData.Down
  182.     Get #fileSlot, , mapData.Left
  183.     Get #fileSlot, , mapData.Right
  184.     Get #fileSlot, , mapData.Music
  185.     Get #fileSlot, , mapData.BootMap
  186.     Get #fileSlot, , mapData.BootX
  187.     Get #fileSlot, , mapData.BootY
  188.     Get #fileSlot, , mapData.Shop
  189.     Get #fileSlot, , mapData.Indoors
  190.     For y = 0 To 11
  191.         For x = 0 To 15
  192.             mapData.Tile(x, y).loadTileFromOpenFile fileSlot
  193.         Next x
  194.     Next y
  195.     Get #fileSlot, , mapData.NPC
  196.     Get #fileSlot, , mapData.Server
  197.     Get #fileSlot, , mapData.Respawn
  198.     Get #fileSlot, , mapData.Weather
  199. End Sub
  200.  
  201. ''
  202. ' This subroutine saves the Map's data to an already open file.
  203. '
  204. ' @param fileSlot The integer pointing to the open file.
  205. '
  206. Public Sub saveMapToOpenFile(ByVal fileSlot As Integer)
  207.     Dim y As Long, x As Long
  208.     Put #fileSlot, , mapData.name
  209.     Put #fileSlot, , mapData.Revision
  210.     Put #fileSlot, , mapData.Moral
  211.     Put #fileSlot, , mapData.Up
  212.     Put #fileSlot, , mapData.Down
  213.     Put #fileSlot, , mapData.Left
  214.     Put #fileSlot, , mapData.Right
  215.     Put #fileSlot, , mapData.Music
  216.     Put #fileSlot, , mapData.BootMap
  217.     Put #fileSlot, , mapData.BootX
  218.     Put #fileSlot, , mapData.BootY
  219.     Put #fileSlot, , mapData.Shop
  220.     Put #fileSlot, , mapData.Indoors
  221.     For y = 0 To 11
  222.         For x = 0 To 15
  223.             mapData.Tile(x, y).saveTileToOpenFile fileSlot
  224.         Next x
  225.     Next y
  226.     Put #fileSlot, , mapData.NPC
  227.     Put #fileSlot, , mapData.Server
  228.     Put #fileSlot, , mapData.Respawn
  229.     Put #fileSlot, , mapData.Weather
  230. End Sub
  231.  
  232. ''
  233. ' Sets the Name of the Map class.
  234. '
  235. ' @param Name The new Name of the Map class
  236. '
  237. Public Sub setName(ByVal name As String)
  238.     mapData.name = name
  239. End Sub
  240.  
  241. ''
  242. ' Returns the Name of the Map class.
  243. '
  244. ' @return The String Name of the Map class
  245. '
  246. Public Function getName() As String
  247.     getName = mapData.name
  248. End Function
  249.  
  250. ''
  251. ' Sets the Revision of the Map class.
  252. '
  253. ' @param Revision The new Revision of the Map class
  254. '
  255. Public Sub setRevision(ByVal Revision As Long)
  256.     mapData.Revision = Revision
  257. End Sub
  258.  
  259. ''
  260. ' Returns the Revision of the Map class.
  261. '
  262. ' @return The Long Revision of the Map class
  263. '
  264. Public Function getRevision() As Long
  265.     getRevision = mapData.Revision
  266. End Function
  267.  
  268. ''
  269. ' Sets the Moral of the Map class.
  270. '
  271. ' @param Moral The new Moral of the Map class
  272. '
  273. Public Sub setMoral(ByVal Moral As Byte)
  274.     mapData.Moral = Moral
  275. End Sub
  276.  
  277. ''
  278. ' Returns the Moral of the Map class.
  279. '
  280. ' @return The Byte Moral of the Map class
  281. '
  282. Public Function getMoral() As Byte
  283.     getMoral = mapData.Moral
  284. End Function
  285.  
  286. ''
  287. ' Sets the Up of the Map class.
  288. '
  289. ' @param Up The new Up of the Map class
  290. '
  291. Public Sub setUp(ByVal Up As Integer)
  292.     mapData.Up = Up
  293. End Sub
  294.  
  295. ''
  296. ' Returns the Up of the Map class.
  297. '
  298. ' @return The Integer Up of the Map class
  299. '
  300. Public Function getUp() As Integer
  301.     getUp = mapData.Up
  302. End Function
  303.  
  304. ''
  305. ' Sets the Down of the Map class.
  306. '
  307. ' @param Down The new Down of the Map class
  308. '
  309. Public Sub setDown(ByVal Down As Integer)
  310.     mapData.Down = Down
  311. End Sub
  312.  
  313. ''
  314. ' Returns the Down of the Map class.
  315. '
  316. ' @return The Integer Down of the Map class
  317. '
  318. Public Function getDown() As Integer
  319.     getDown = mapData.Down
  320. End Function
  321.  
  322. ''
  323. ' Sets the Left of the Map class.
  324. '
  325. ' @param Left The new Left of the Map class
  326. '
  327. Public Sub setLeft(ByVal Left As Integer)
  328.     mapData.Left = Left
  329. End Sub
  330.  
  331. ''
  332. ' Returns the Left of the Map class.
  333. '
  334. ' @return The Integer Left of the Map class
  335. '
  336. Public Function getLeft() As Integer
  337.     getLeft = mapData.Left
  338. End Function
  339.  
  340. ''
  341. ' Sets the Right of the Map class.
  342. '
  343. ' @param Right The new Right of the Map class
  344. '
  345. Public Sub setRight(ByVal Right As Integer)
  346.     mapData.Right = Right
  347. End Sub
  348.  
  349. ''
  350. ' Returns the Right of the Map class.
  351. '
  352. ' @return The Integer Right of the Map class
  353. '
  354. Public Function getRight() As Integer
  355.     getRight = mapData.Right
  356. End Function
  357.  
  358. ''
  359. ' Sets the Music of the Map class.
  360. '
  361. ' @param Music The new Music of the Map class
  362. '
  363. Public Sub setMusic(ByVal Music As Integer)
  364.     mapData.Music = Music
  365. End Sub
  366.  
  367. ''
  368. ' Returns the Music of the Map class.
  369. '
  370. ' @return The Integer Music of the Map class
  371. '
  372. Public Function getMusic() As Integer
  373.     getMusic = mapData.Music
  374. End Function
  375.  
  376. ''
  377. ' Sets the BootMap of the Map class.
  378. '
  379. ' @param BootMap The new BootMap of the Map class
  380. '
  381. Public Sub setBootMap(ByVal BootMap As Integer)
  382.     mapData.BootMap = BootMap
  383. End Sub
  384.  
  385. ''
  386. ' Returns the BootMap of the Map class.
  387. '
  388. ' @return The Integer BootMap of the Map class
  389. '
  390. Public Function getBootMap() As Integer
  391.     getBootMap = mapData.BootMap
  392. End Function
  393.  
  394. ''
  395. ' Sets the BootX of the Map class.
  396. '
  397. ' @param BootX The new BootX of the Map class
  398. '
  399. Public Sub setBootX(ByVal BootX As Byte)
  400.     mapData.BootX = BootX
  401. End Sub
  402.  
  403. ''
  404. ' Returns the BootX of the Map class.
  405. '
  406. ' @return The Byte BootX of the Map class
  407. '
  408. Public Function getBootX() As Byte
  409.     getBootX = mapData.BootX
  410. End Function
  411.  
  412. ''
  413. ' Sets the BootY of the Map class.
  414. '
  415. ' @param BootY The new BootY of the Map class
  416. '
  417. Public Sub setBootY(ByVal BootY As Byte)
  418.     mapData.BootY = BootY
  419. End Sub
  420.  
  421. ''
  422. ' Returns the BootY of the Map class.
  423. '
  424. ' @return The Byte BootY of the Map class
  425. '
  426. Public Function getBootY() As Byte
  427.     getBootY = mapData.BootY
  428. End Function
  429.  
  430. ''
  431. ' Sets the Shop of the Map class.
  432. '
  433. ' @param Shop The new Shop of the Map class
  434. '
  435. Public Sub setShop(ByVal Shop As Integer)
  436.     mapData.Shop = Shop
  437. End Sub
  438.  
  439. ''
  440. ' Returns the Shop of the Map class.
  441. '
  442. ' @return The Integer Shop of the Map class
  443. '
  444. Public Function getShop() As Integer
  445.     getShop = mapData.Shop
  446. End Function
  447.  
  448. ''
  449. ' Sets the Indoors of the Map class.
  450. '
  451. ' @param Indoors The new Indoors of the Map class
  452. '
  453. Public Sub setIndoors(ByVal Indoors As Byte)
  454.     mapData.Indoors = Indoors
  455. End Sub
  456.  
  457. ''
  458. ' Returns the Indoors of the Map class.
  459. '
  460. ' @return The Byte Indoors of the Map class
  461. '
  462. Public Function getIndoors() As Byte
  463.     getIndoors = mapData.Indoors
  464. End Function
  465.  
  466. ''
  467. ' Sets the Tile of the Map class at the given location.
  468. '
  469. ' @param X The x location on the map
  470. ' @param Y The y location on the map
  471. ' @param Tile The new Tile of the Map class
  472. '
  473. Public Sub setTile(ByVal x As Byte, ByVal y As Byte, ByVal Tile As clsTile)
  474.     Set mapData.Tile(x, y) = Tile
  475. End Sub
  476.  
  477. ''
  478. ' Returns the Tile of the Map class at the given location.
  479. '
  480. ' @param X The x location on the map
  481. ' @param Y The y location on the map
  482. '
  483. ' @return The clsTile Tile of the Map class
  484. '
  485. Public Function getTile(ByVal x As Byte, ByVal y As Byte) As clsTile
  486.     Set getTile = mapData.Tile(x, y)
  487. End Function
  488.  
  489. ''
  490. ' Sets the NPC of the Map class with the specified index.
  491. '
  492. ' @param Index The location of the NPC to set
  493. '
  494. ' @param NPC The new NPC of the Map class
  495. '
  496. Public Sub setNPC(ByVal index As Byte, ByVal NPC As Long)
  497.     mapData.NPC(index) = NPC
  498. End Sub
  499.  
  500. ''
  501. ' Returns the NPC of the Map class with the specified index.
  502. '
  503. ' @param Index The location of the NPC to return
  504. '
  505. ' @return The Long NPC of the Map class
  506. '
  507. Public Function getNPC(ByVal index As Byte) As Long
  508.     getNPC = mapData.NPC(index)
  509. End Function
  510.  
  511. ''
  512. ' Sets the Server of the Map class.
  513. '
  514. ' @param Server The new Server of the Map class
  515. '
  516. Public Sub setServer(ByVal Server As Boolean)
  517.     mapData.Server = Server
  518. End Sub
  519.  
  520. ''
  521. ' Returns the Server of the Map class.
  522. '
  523. ' @return The Boolean Server of the Map class
  524. '
  525. Public Function getServer() As Boolean
  526.     getServer = mapData.Server
  527. End Function
  528.  
  529. ''
  530. ' Sets the Respawn of the Map class.
  531. '
  532. ' @param Respawn The new Respawn of the Map class
  533. '
  534. Public Sub setRespawn(ByVal Respawn As Byte)
  535.     mapData.Respawn = Respawn
  536. End Sub
  537.  
  538. ''
  539. ' Returns the Respawn of the Map class.
  540. '
  541. ' @return The Byte Respawn of the Map class
  542. '
  543. Public Function getRespawn() As Byte
  544.     getRespawn = mapData.Respawn
  545. End Function
  546.  
  547. ''
  548. ' Sets the Weather of the Map class.
  549. '
  550. ' @param Weather The new Weather of the Map class
  551. '
  552. Public Sub setWeather(ByVal Weather As Byte)
  553.     mapData.Weather = Weather
  554. End Sub
  555.  
  556. ''
  557. ' Returns the Weather of the Map class.
  558. '
  559. ' @return The Byte Weather of the Map class
  560. '
  561. Public Function getWeather() As Byte
  562.     getWeather = mapData.Weather
  563. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement