Advertisement
Guest User

Untitled

a guest
Jun 4th, 2013
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. -- Navmarkup test
  2.  
  3. NavMarkup = {}
  4. NavMarkup.data = {}
  5. NavMarkup.markup = {}
  6.  
  7. NavMarkup.markup.vectorSectors={}
  8. NavMarkup.markup.roidSectors={}
  9. NavMarkup.markup.stormSectors={}
  10.  
  11. function NavMarkup.GenMarkupTable(sysId) --Function to check systemnotes markup and generate markup based on this
  12. local sysnotes_import = LoadSystemNotes(sysId)
  13. local system_table = unspickle(sysnotes_import)
  14. NavMarkup.markup.vectorSectors={}
  15. NavMarkup.markup.roidSectors={} -- Clear the tables
  16. for i,v in pairs(system_table) do
  17. local comparison_string = string.lower(v)
  18. if string.find(comparison_string,"roid") then
  19. table.insert(NavMarkup.markup.roidSectors, i)
  20. end
  21. if string.find(comparison_string,"vector") then
  22. table.insert(NavMarkup.markup.vectorSectors, i)
  23. end
  24. end
  25. end
  26.  
  27.  
  28. NavMarkup.hazardColors = {
  29. "160 255 160", -- Vector
  30. "155 155 155", -- Unmarked Roid sector
  31. "20 20 200", -- Storm
  32. "20 20 200", -- The rest are just legacy stuff for making a hirearchical markup scheme - not sure if i will use it yet
  33. "20 20 200",
  34. "20 20 200",
  35. "20 20 200",
  36. }
  37.  
  38. function NavMarkup:GetMapForSystem (sysId)
  39. local mapName
  40. mapName = string.format("lua/maps/system%02dmap.lua", sysId)
  41. local map = dofile (mapName)
  42.  
  43. return mapName, map
  44. end
  45.  
  46. function NavMarkup:CreateMapUI (sysId)
  47. local navmap = iup.navmap {}
  48. local mapName = NavMarkup:GetMapForSystem (sysId)
  49. navmap:loadmap (2, mapName, sysId-1)
  50.  
  51. return navmap
  52. end
  53.  
  54. NavMarkup.lastLoadedSysId = 0
  55. function NavMarkup:CreateNavmapUI (pdaTab)
  56. local navmap = pdaTab [1][1][1]
  57.  
  58. local oldLoadMap = navmap.loadmap
  59. function navmap:loadmap (type, path, id)
  60. oldLoadMap (self, type, path, id)
  61. NavMarkup.lastLoadedSysId = 0
  62. NavMarkup.GenMarkupTable(id + 1)
  63. if type == 2 then
  64. NavMarkup.lastLoadedSysId = id + 1
  65. NavMarkup:PaintSystemHazards (navmap, id + 1, NavMarkup.markup.roidSectors, NavMarkup.markup.vectorSectors)
  66. end
  67. end
  68.  
  69. end
  70.  
  71.  
  72. function NavMarkup:IsEncounteredVectorSector (s1)
  73. local result = false
  74. for i,v in pairs(NavMarkup.markup.vectorSectors) do
  75. local comparison_string = tostring(v)
  76. if string.find (comparison_string,s1) then
  77. result = true
  78. end
  79. end
  80.  
  81. return result
  82. end
  83.  
  84. -- Check record for hostile bots
  85. function NavMarkup:IsEncounteredRoidSector (s1)
  86. local result = false
  87. for i,v in pairs(NavMarkup.markup.roidSectors) do
  88. local comparison_string = tostring(v)
  89. if string.find (comparison_string,s1) then
  90. result = true
  91. end
  92. end
  93.  
  94. return result
  95. end
  96.  
  97. function NavMarkup:IsRecordedStormSector (s1)
  98. local result = false
  99. for i,v in pairs(NavMarkup.markup.stormSectors) do
  100. local comparison_string = tostring(v)
  101. if string.find (comparison_string,s1) then
  102. result = true
  103. end
  104. end
  105.  
  106. return result
  107. end
  108.  
  109.  
  110. function NavMarkup:PaintSystemHazards (navmap, sysId, storms, bots)
  111.  
  112. -- Paint all the storm sectors
  113. local sectorId, color, colorId
  114. local x, y
  115. for x = 1, 16 do
  116. for y = 1, 16 do
  117. color = 0
  118. sectorId = NavMarkup:BuildSectorId (sysId, x, y)
  119. if NavMarkup:IsEncounteredVectorSector (sectorId) then color = color + 1 end
  120. if NavMarkup:IsEncounteredRoidSector (sectorId) then color = color + 2 end
  121. if NavMarkup:IsRecordedStormSector (sectorId) then color = color + 4 end
  122.  
  123. -- Set the sector color based on hazard
  124. if color > 0 then
  125. colorId = string.format ("COLOR%d", sectorId)
  126. navmap [colorId] = NavMarkup.hazardColors [color]
  127. end
  128. end
  129. end
  130. end
  131.  
  132. function NavMarkup:RecordStorm (s1, inStation) -- Very basic, need to add timestamp functionality
  133. if not NavMarkup:IsRecordedStormSector(s1) then
  134. table.insert (NavMarkup.markup.stormSectors, s1)
  135. end
  136. end
  137.  
  138. function NavMarkup:OnEvent (event, data)
  139. if event == "STORM_STARTED" then
  140. NavMarkup:RecordStorm (GetCurrentSectorid ())
  141. end
  142. end
  143.  
  144. function NavMarkup:BuildLocationId (x, y)
  145. return 16 * (x - 1) + y
  146. end
  147.  
  148. function NavMarkup:BuildSectorId (sysId, x, y)
  149. return 256 * (sysId-1) + NavMarkup:BuildLocationId (x, y)
  150. end
  151.  
  152.  
  153. function NavMarkup:test()
  154. NavMarkup:CreateNavmapUI (StationPDAShipNavigationTab)
  155. NavMarkup:CreateNavmapUI (PDAShipNavigationTab)
  156. NavMarkup:CreateNavmapUI (CapShipPDAShipNavigationTab)
  157. end
  158.  
  159. NavMarkup:test()
  160.  
  161. RegisterEvent (NavMarkup, "STORM_STARTED")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement