Advertisement
biosp4rk

Metroid Fusion - Drops Predictor

Feb 13th, 2016
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.06 KB | None | 0 0
  1. rns = { 256, 512, 512, 0, 768, 256, 512, 512, 512, 0, 512, 0, 0, 768, 256, 0, 768, 256, 768, 768, 0, 512, 768, 0, 768, 256, 0, 768, 256, 256, 256, 512 }
  2. enHealth = { }
  3. display = { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" }
  4. dropsX =  { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  -- 00
  5.             0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,  -- 10
  6.             0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,  -- 20
  7.             0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0,  -- 30
  8.             0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  -- 40
  9.             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0,  -- 50
  10.             1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,  -- 60
  11.             1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,  -- 70
  12.             1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0,  -- 80
  13.             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  -- 90
  14.             0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0,  -- A0
  15.             0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0,  -- B0
  16.             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }    -- C0
  17.  
  18. function DrawArrow(x, y)    -- displays an arrow
  19.     gui.text(7+x, y, "<-")
  20. end
  21.  
  22. function DrawDrop(x, y, label)
  23.     if label == "Y" then
  24.         gui.text(x, y, label, "#F0F000")
  25.     elseif label == "G" then
  26.         gui.text(x, y, label, "#00F000")
  27.     else
  28.         gui.text(x, y, label, "#F00000")
  29.     end
  30. end
  31.  
  32. while true do
  33.     -- get these values every frame
  34.     local cameraX, cameraY = memory.readword(0x3001228), memory.readword(0x300122A)
  35.     local frame1 = memory.readbyte(0x3000BE5)
  36.     local frame2 = memory.readword(0x3000002)
  37.     local fullHealth = (memory.readword(0x3001310) == memory.readword(0x3001312))
  38.     local fullMissiles = (memory.readbyte(0x3001314) == memory.readbyte(0x3001316))
  39.    
  40.     -- display frame counter for convenience
  41.     gui.text(28, 3, 255 - (frame1 + 45) % 256)
  42.    
  43.     -- for each enemy
  44.     for i=0,23 do
  45.         local status = memory.readword(0x3000140 + i*0x38)
  46.         local prop = memory.readbyte(0x3000174 + i*0x38)
  47.         local id = memory.readbyte(0x300015D + i*0x38)
  48.        
  49.         -- if enemy exists and can drop x
  50.         if status > 0 and prop < 0x80 and dropsX[id + 1] == 1 then
  51.             -- get enemy position  
  52.             local enemyX, enemyY = memory.readword(0x3000144 + i*0x38), memory.readword(0x3000142 + i*0x38)
  53.             local posX, posY = bit.rshift(enemyX - cameraX, 2), bit.rshift(enemyY - cameraY, 2)
  54.            
  55.             -- update enemy's past/current health
  56.             local pastHealth = enHealth[i+1]
  57.             local enemyHealth = memory.readword(0x3000154 + i*56)
  58.             enHealth[i+1] = enemyHealth
  59.            
  60.             -- if enemy recently died, show drop
  61.             if pastHealth == 0 then
  62.                 DrawDrop(posX, posY, display[i+1])
  63.                 DrawArrow(posX, posY)          
  64.            
  65.             -- otherwise, determine which x will be dropped
  66.             else
  67.                 local healthX = memory.readword(0x82E4D54+ id*0xE)
  68.                 local missileX = memory.readword(0x82E4D56 + id*0xE)
  69.                 local redX = memory.readword(0x82E4D58 + id*0xE)
  70.            
  71.                 local temp1 = (frame1 + 45) % 256
  72.                 local temp2 = bit.rshift(frame2 + 45, 4)
  73.                 local rn = rns[((i + temp1 + temp2 + enemyX + enemyY) % 32) + 1]
  74.                 local cmpVal = rn + temp1
  75.                 local cmpRed = 1024 - redX
  76.            
  77.                 local dropLabel
  78.                 if cmpVal >= cmpRed then
  79.                     dropLabel = "R"
  80.                 elseif cmpVal >= cmpRed - missileX then
  81.                     if (fullMissiles and not fullHealth) then
  82.                         dropLabel = "Y"
  83.                     else
  84.                         dropLabel = "G"
  85.                     end
  86.                 else
  87.                     if (fullHealth and not fullMissiles) then
  88.                         dropLabel = "G"
  89.                     else
  90.                         dropLabel = "Y"
  91.                     end
  92.                 end
  93.            
  94.                 DrawDrop(posX, posY, dropLabel)
  95.                
  96.                 -- if enemy just died, save drop and draw arrow
  97.                 if enemyHealth == 0 then
  98.                     display[i+1] = dropLabel
  99.                     DrawArrow(posX, posY)
  100.                 end
  101.            
  102.                 -- determine when red x will appear
  103.                 if redX > 0 then
  104.                     local wait = 0
  105.                     while temp1 ~= 0 do
  106.                         rn = rns[((i + temp1 + temp2 + enemyX + enemyY) % 32) + 1]
  107.                         if rn + temp1 >= cmpRed then
  108.                             gui.text(posX, posY + 7, wait)
  109.                             break
  110.                         end
  111.                         wait = wait + 1
  112.                         temp1 = (temp1 + 1) % 256
  113.                         if (temp1 % 16 == 0) then
  114.                             temp2 = temp2 + 1
  115.                         end
  116.                     end
  117.                 end
  118.                
  119.             end
  120.         end
  121.     end
  122.    
  123.     vba.frameadvance()
  124.  
  125. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement