Vendily

dex map fix

Jan 8th, 2019
193
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def pbFindEncounter(encounter,species)
  2.   return false if !encounter
  3.   for i in 0...encounter.length
  4.     next if !encounter[i]
  5.     for j in 0...encounter[i].length
  6.       return true if encounter[i][j][0]==species
  7.     end
  8.   end
  9.   return false
  10. end
  11.  
  12.  
  13.  
  14. ################################################################################
  15. # Shows the "Nest" page of the Pokédex entry screen.
  16. ################################################################################
  17. class PokemonNestMapScene
  18.   CursorAnimateDelay = 12.0
  19.   CursorMoveSpeed = 4.0
  20.  
  21.   def pbStartScene(species,regionmap=-1)
  22.     @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
  23.     @viewport.z=99999
  24.     @mapvp=Viewport.new(16,32,480,320)
  25.     @mapvp.z=100000
  26.     @viewport2=Viewport.new(0,0,Graphics.width,Graphics.height)
  27.     @viewport2.z=100001
  28.     @sprites={}
  29.     @window=SpriteHash.new
  30.     pbRgssOpen("Data/townmap.dat","rb"){|f|
  31.        @mapdata=Marshal.load(f)
  32.     }
  33.     mappos=!$game_map ? nil : pbGetMetadata($game_map.map_id,MetadataMapPosition)
  34.     region=regionmap
  35.     if region<0                                    # Use player's current region
  36.       region=mappos ? mappos[0] : 0                           # Region 0 default
  37.     end
  38.     @sprites["background"]=IconSprite.new(0,0,@viewport)
  39.     @sprites["background"].setBitmap(_INTL("Graphics/Pictures/pokedexNest"))
  40.     @window["map"]=Sprite.new(@mapvp)
  41.     @window["map"].bmp("Graphics/Pictures/#{@mapdata[region][1]}")
  42.     for hidden in REGIONMAPEXTRAS
  43.       if hidden[0]==region && hidden[1]>0 && $game_switches[hidden[1]]
  44.         if !@sprites["map2"]
  45.           @window["map2"]=BitmapSprite.new(480,320,@mapvp)
  46.           @window["map2"].x=@sprites["map"].x; @window["map2"].y=@window["map"].y
  47.         end
  48.         pbDrawImagePositions(@sprites["map2"].bitmap,[
  49.            ["Graphics/Pictures/#{hidden[4]}",
  50.               hidden[2]*PokemonRegionMapScene::SQUAREWIDTH,
  51.               hidden[3]*PokemonRegionMapScene::SQUAREHEIGHT,0,0,-1,-1]
  52.         ])
  53.       end
  54.     end
  55.     @sprites["arrowLeft"] = Sprite.new(@viewport2)
  56.     @sprites["arrowLeft"].bmp("Graphics/Pictures/mapArrowRight")
  57.     @sprites["arrowLeft"].mirror = true
  58.     @sprites["arrowLeft"].center_origins
  59.     @sprites["arrowLeft"].xyz = 12, Graphics.height / 2
  60.     @sprites["arrowRight"] = Sprite.new(@viewport2)
  61.     @sprites["arrowRight"].bmp("Graphics/Pictures/mapArrowRight")
  62.     @sprites["arrowRight"].center_origins
  63.     @sprites["arrowRight"].xyz = Graphics.width - 12, Graphics.height / 2
  64.     @sprites["arrowUp"] = Sprite.new(@viewport2)
  65.     @sprites["arrowUp"].bmp("Graphics/Pictures/mapArrowDown")
  66.     @sprites["arrowUp"].angle = 180
  67.     @sprites["arrowUp"].center_origins
  68.     @sprites["arrowUp"].xyz = Graphics.width / 2, 24
  69.     @sprites["arrowDown"] = Sprite.new(@viewport2)
  70.     @sprites["arrowDown"].bmp("Graphics/Pictures/mapArrowDown")
  71.     @sprites["arrowDown"].center_origins
  72.     @sprites["arrowDown"].xyz = Graphics.width / 2, Graphics.height - 24
  73.     @dirs = []
  74.     @mdirs = []
  75.     @i = 0
  76.    
  77.     @point=BitmapWrapper.new(PokemonRegionMapScene::SQUAREWIDTH+4,
  78.                              PokemonRegionMapScene::SQUAREHEIGHT+4)
  79.     @point.fill_rect(0,0,
  80.                      PokemonRegionMapScene::SQUAREWIDTH+4,
  81.                      PokemonRegionMapScene::SQUAREHEIGHT+4,Color.new(255,0,0))
  82.     @point2=BitmapWrapper.new(PokemonRegionMapScene::SQUAREWIDTH+4,
  83.                               PokemonRegionMapScene::SQUAREHEIGHT+4)
  84.     @point2.fill_rect(4,0,
  85.                       PokemonRegionMapScene::SQUAREWIDTH,
  86.                       PokemonRegionMapScene::SQUAREHEIGHT+4,Color.new(255,0,0))
  87.     @point3=BitmapWrapper.new(PokemonRegionMapScene::SQUAREWIDTH+4,
  88.                               PokemonRegionMapScene::SQUAREHEIGHT+4)
  89.     @point3.fill_rect(0,4,
  90.                       PokemonRegionMapScene::SQUAREWIDTH+4,
  91.                       PokemonRegionMapScene::SQUAREHEIGHT,Color.new(255,0,0))
  92.     @point4=BitmapWrapper.new(PokemonRegionMapScene::SQUAREWIDTH+4,
  93.                               PokemonRegionMapScene::SQUAREHEIGHT+4)
  94.     @point4.fill_rect(4,4,
  95.                       PokemonRegionMapScene::SQUAREWIDTH,
  96.                       PokemonRegionMapScene::SQUAREHEIGHT,Color.new(255,0,0))
  97.     encdata=load_data("Data/encounters.dat")
  98.     points=[]
  99.     mapwidth=1+PokemonRegionMapScene::RIGHT-PokemonRegionMapScene::LEFT
  100.     j=-1
  101.     for i in 0...RoamingSpecies.length
  102.       s=getID(PBSpecies,RoamingSpecies[i][0])
  103.       if s==species
  104.         j=i
  105.         break
  106.       end
  107.     end
  108.     for enc in encdata.keys
  109.       enctypes=encdata[enc][1]
  110.       if pbFindEncounter(enctypes,species) || (j>-1 && enc==$PokemonGlobal.roamPosition[j])
  111.         mappos=pbGetMetadata(enc,MetadataMapPosition)
  112.         if mappos && mappos[0]==region
  113.           showpoint=true
  114.           for loc in @mapdata[region][2]
  115.             showpoint=false if loc[0]==mappos[1] && loc[1]==mappos[2] &&
  116.                                loc[7] && !$game_switches[loc[7]]
  117.           end
  118.           if showpoint
  119.             mapsize=pbGetMetadata(enc,MetadataMapSize)
  120.             if mapsize && mapsize[0] && mapsize[0]>0
  121.               sqwidth=mapsize[0]
  122.               sqheight=(mapsize[1].length*1.0/mapsize[0]).ceil
  123.               for i in 0...sqwidth
  124.                 for j in 0...sqheight
  125.                   if mapsize[1][i+j*sqwidth,1].to_i>0
  126.                     points[mappos[1]+i+(mappos[2]+j)*mapwidth]=true
  127.                   end
  128.                 end
  129.               end
  130.             else
  131.               points[mappos[1]+mappos[2]*mapwidth]=true
  132.             end
  133.           end
  134.         end
  135.       end
  136.     end
  137.     i=0
  138.     for j in 0...points.length
  139.       if points[j]
  140.         s=SpriteWrapper.new(@mapvp)
  141.         s.x=(j%mapwidth)*PokemonRegionMapScene::SQUAREWIDTH-2
  142.         s.x+=(Graphics.width-@window["map"].bitmap.width)/2
  143.         s.y=(j/mapwidth)*PokemonRegionMapScene::SQUAREHEIGHT-2
  144.         s.y+=(Graphics.height-@window["map"].bitmap.height)/2
  145.         if j>=1 && points[j-1]
  146.           if j>=mapwidth && points[j-mapwidth]
  147.             s.bitmap=@point4
  148.           else
  149.             s.bitmap=@point2
  150.           end
  151.         else
  152.           if j>=mapwidth && points[j-mapwidth]
  153.             s.bitmap=@point3
  154.           else
  155.             s.bitmap=@point
  156.           end
  157.         end
  158.         @window["point#{i}"]=s
  159.         i+=1
  160.       end
  161.     end
  162.     @numpoints=i
  163.     @sprites["mapbottom"]=MapBottomSprite.new(@viewport2)
  164.     @sprites["mapbottom"].maplocation=pbGetMessage(MessageTypes::RegionNames,region)
  165.     @sprites["mapbottom"].mapdetails=_INTL("{1}'s nest",PBSpecies.getName(species))
  166.     if points.length==0
  167.       @sprites["mapbottom"].nonests=true
  168.     end
  169.     return true
  170.   end
  171.  
  172.   def pbUpdate
  173.     @numpoints.times {|i|
  174.        @window["point#{i}"].opacity=[64,96,128,160,128,96][(Graphics.frame_count/4)%6]
  175.     }
  176.     @sprites["arrowLeft"].visible = @mapscroll && @window.x < 0
  177.     @sprites["arrowRight"].visible = @mapscroll && @window.x > -1 * (@window["map"].bmp.width - 480)
  178.     @sprites["arrowUp"].visible = @mapscroll && @window.y < 0
  179.     @sprites["arrowDown"].visible = @mapscroll && @window.y > -1 * (@window["map"].bmp.height - 320)
  180.    
  181.     @i += 1
  182.     if @i % 2 == 0
  183.       case @i % 32
  184.       when 0...8
  185.         @sprites["arrowLeft"].x -= 1
  186.         @sprites["arrowRight"].x += 1
  187.         @sprites["arrowUp"].y -= 1
  188.         @sprites["arrowDown"].y += 1
  189.       when 8...24
  190.         @sprites["arrowLeft"].x += 1
  191.         @sprites["arrowRight"].x -= 1
  192.         @sprites["arrowUp"].y += 1
  193.         @sprites["arrowDown"].y -= 1
  194.       when 24...32
  195.         @sprites["arrowLeft"].x -= 1
  196.         @sprites["arrowRight"].x += 1
  197.         @sprites["arrowUp"].y -= 1
  198.         @sprites["arrowDown"].y += 1
  199.       end
  200.     end
  201.    
  202.     # Map movement
  203.     if @mdirs.include?(6)
  204.       @hor_count ||= 0
  205.       @hor_count += 1
  206.       @window.x = @mx - (PokemonRegionMapScene::SQUAREWIDTH / CursorMoveSpeed.to_f) * @hor_count
  207.       if @hor_count == CursorMoveSpeed
  208.         @mdirs.delete(6)
  209.         @hor_count = nil
  210.         @mx = nil
  211.       end
  212.     end
  213.     if @mdirs.include?(4)
  214.       @hor_count ||= 0
  215.       @hor_count += 1
  216.       @window.x = @mx + (PokemonRegionMapScene::SQUAREWIDTH / CursorMoveSpeed.to_f) * @hor_count
  217.       if @hor_count == CursorMoveSpeed
  218.         @mdirs.delete(4)
  219.         @hor_count = nil
  220.         @mx = nil
  221.       end
  222.     end
  223.     if @mdirs.include?(8)
  224.       @ver_count ||= 0
  225.       @ver_count += 1
  226.       @window.y = @my + (PokemonRegionMapScene::SQUAREHEIGHT / CursorMoveSpeed.to_f) * @ver_count
  227.       if @ver_count == CursorMoveSpeed
  228.         @mdirs.delete(8)
  229.         @ver_count = nil
  230.         @my = nil
  231.       end
  232.     end
  233.     if @mdirs.include?(2)
  234.       @ver_count ||= 0
  235.       @ver_count += 1
  236.       @window.y = @my - (PokemonRegionMapScene::SQUAREHEIGHT / CursorMoveSpeed.to_f) * @ver_count
  237.       if @ver_count == CursorMoveSpeed
  238.         @mdirs.delete(2)
  239.         @ver_count = nil
  240.         @my = nil
  241.       end
  242.     end
  243.   end
  244.  
  245.   def pbMapScene(listlimits)
  246.     Graphics.transition
  247.     ret=0
  248.     loop do
  249.       Graphics.update
  250.       Input.update
  251.       pbUpdate
  252.       if @mapscroll
  253.         if Input.press?(Input::RIGHT) && ![4,6].any? { |e| @mdirs.include?(e) }
  254.           if @window.x > -1 * (@window["map"].bmp.width - 480)
  255.             $PokemonGlobal.regionMapSel[0] += 1
  256.             @mx = @window.x
  257.             @mdirs << 6
  258.           end
  259.         end
  260.         if Input.press?(Input::LEFT) && ![4,6].any? { |e| @mdirs.include?(e) }
  261.           if @window.x < 0
  262.             $PokemonGlobal.regionMapSel[0] -= 1
  263.             @mx = @window.x
  264.             @mdirs << 4
  265.           end
  266.         end
  267.         if Input.press?(Input::DOWN) && ![2,8].any? { |e| @mdirs.include?(e) }
  268.           if @window.y > -1 * (@window["map"].bmp.height - 320)
  269.             $PokemonGlobal.regionMapSel[1] += 1
  270.             @my = @window.y
  271.             @mdirs << 2
  272.           end
  273.         end
  274.         if Input.press?(Input::UP) && ![2,8].any? { |e| @mdirs.include?(e) }
  275.           if @window.y < 0
  276.             $PokemonGlobal.regionMapSel[1] -= 1
  277.             @my = @window.y
  278.             @mdirs << 8
  279.           end
  280.         end
  281.       else
  282.         if Input.trigger?(Input::LEFT)
  283.           ret=4
  284.           break
  285.         elsif Input.trigger?(Input::RIGHT)
  286.           ret=6
  287.           break
  288.         elsif Input.trigger?(Input::UP) && listlimits&1==0 # If not at top of list
  289.           ret=8
  290.           break
  291.         elsif Input.trigger?(Input::DOWN) && listlimits&2==0 # If not at end of list
  292.           ret=2
  293.           break
  294.         end
  295.       end
  296.       if Input.trigger?(Input::C)
  297.         @mapscroll^=true
  298.       elsif Input.trigger?(Input::B)
  299.         ret=1
  300.         pbPlayCancelSE()
  301.         pbFadeOutAndHide(@sprites)
  302.         #@window.hide # Looks kind of dumb.
  303.         break
  304.       end
  305.     end
  306.     return ret
  307.   end
  308.  
  309.   def pbEndScene
  310.     pbDisposeSpriteHash(@sprites)
  311.     @window.dispose
  312.     @point.dispose
  313.     @viewport.dispose
  314.     @mapvp.dispose
  315.     @viewport2.dispose
  316.   end
  317. end
  318.  
  319.  
  320.  
  321. class PokemonNestMap
  322.   def initialize(scene)
  323.     @scene=scene
  324.   end
  325.  
  326.   def pbStartScreen(species,region,listlimits)
  327.     @scene.pbStartScene(species,region)
  328.     ret=@scene.pbMapScene(listlimits)
  329.     @scene.pbEndScene
  330.     return ret
  331.   end
  332. end
  333.  
  334.  
  335.  
  336. ################################################################################
  337. # Shows the "Form" page of the Pokédex entry screen.
  338. ################################################################################
  339. class PokedexFormScene
  340.   def pbStartScene(species)
  341.     @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
  342.     @viewport.z=99999
  343.     @species=species
  344.     @gender=$Trainer.formlastseen[species][0]
  345.     @form=$Trainer.formlastseen[species][1]
  346.     @available=pbGetAvailable # [name, gender, form]
  347.     @sprites={}
  348.     @sprites["background"]=IconSprite.new(0,0,@viewport)
  349.     @sprites["background"].setBitmap(_INTL("Graphics/Pictures/pokedexForm"))
  350.     @sprites["info"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
  351.     pbSetSystemFont(@sprites["info"].bitmap)
  352.     @sprites["front"]=PokemonSprite.new(@viewport)
  353.     @sprites["back"]=PokemonSprite.new(@viewport)
  354.     @sprites["icon"]=PokemonSpeciesIconSprite.new(@species,@viewport)
  355.     @sprites["icon"].pbSetParams(@species,@gender,@form)
  356.     @sprites["icon"].x=52
  357.     @sprites["icon"].y=290
  358.     pbRefresh
  359.     return true
  360.   end
  361.  
  362.   def pbUpdate
  363.     pbUpdateSpriteHash(@sprites)
  364.   end
  365.  
  366.   def pbRefresh
  367.     @sprites["info"].bitmap.clear
  368.     name=""
  369.     for i in @available
  370.       if i[1]==@gender && i[2]==@form
  371.         name=i[0]; break
  372.       end
  373.     end
  374.     text=[
  375.        [sprintf("%s",PBSpecies.getName(@species)),
  376.           (Graphics.width+72)/2,Graphics.height-86,2,
  377.           Color.new(88,88,80),Color.new(168,184,184)],
  378.        [sprintf("%s",name),
  379.           (Graphics.width+72)/2,Graphics.height-54,2,
  380.           Color.new(88,88,80),Color.new(168,184,184)],
  381.     ]
  382.     pbDrawTextPositions(@sprites["info"].bitmap,text)
  383.     @sprites["front"].setSpeciesBitmap(@species,(@gender==1),@form,false,false,false)
  384.     pbPositionPokemonSprite(@sprites["front"],74,96)
  385.     @sprites["back"].setSpeciesBitmap(@species,(@gender==1),@form,false,false,true)
  386.     metrics=load_data("Data/metrics.dat")
  387.     backMetric=metrics[0][@species]
  388.     pbPositionPokemonSprite(@sprites["back"],310,98+16+backMetric*2)
  389.     @sprites["icon"].pbSetParams(@species,@gender,@form)
  390.   end
  391.  
  392.   def pbGetAvailable
  393.     available=[] # [name, gender, form]
  394.     dexdata=pbOpenDexData
  395.     pbDexDataOffset(dexdata,@species,18)
  396.     genderbyte=dexdata.fgetb
  397.     dexdata.close
  398.     formnames=pbGetMessage(MessageTypes::FormNames,@species)
  399.     if !formnames || formnames==""
  400.       formnames=[""]
  401.     else
  402.       formnames=strsplit(formnames,/,/)
  403.     end
  404.     @gender=0 if genderbyte==0 || genderbyte==255 # Always male or genderless
  405.     @gender=1 if genderbyte==254 # Always female
  406.     if formnames && formnames[0]!=""
  407.       for j in 0...2
  408.         if $Trainer.formseen[@species][j][0] || ALWAYSSHOWALLFORMS # That gender/form has been seen
  409.           if pbResolveBitmap(sprintf("Graphics/Battlers/%sf",getConstantName(PBSpecies,@species))) ||
  410.              pbResolveBitmap(sprintf("Graphics/Battlers/%03df",@species))
  411.             available.push([_INTL("{1} Male",formnames[0]),j,0]) if j==0
  412.             available.push([_INTL("{1} Female",formnames[0]),j,0]) if j==1
  413.           else
  414.             gendertopush=(genderbyte==254) ? 1 : 0
  415.             available.push([formnames[0],gendertopush,0])
  416.             break
  417.           end
  418.         end
  419.       end
  420.     else
  421.       if $Trainer.formseen[@species][0][0] || ALWAYSSHOWALLFORMS # Male/form 0 has been seen
  422.         if genderbyte!=254 && genderbyte!=255 # Not always female & not genderless
  423.           available.push([_INTL("Male"),0,0])
  424.         end
  425.       end
  426.       if $Trainer.formseen[@species][1][0] || ALWAYSSHOWALLFORMS # Female/form 0 has been seen
  427.         if genderbyte!=0 && genderbyte!=255 # Not always male & not genderless
  428.           available.push([_INTL("Female"),1,0])
  429.         end
  430.       end
  431.       if $Trainer.formseen[@species][0][0] || ALWAYSSHOWALLFORMS # Genderless/form 0 has been seen
  432.         if genderbyte==255 # Genderless
  433.           if formnames && formnames.length>1
  434.             available.push([_INTL("One Form"),0,0])
  435.           else
  436.             available.push([_INTL("Genderless"),0,0])
  437.           end
  438.         end
  439.       end
  440.     end
  441.     for i in 1...formnames.length
  442.       for j in 0...2
  443.         if $Trainer.formseen[@species][j][i] || ALWAYSSHOWALLFORMS # That gender/form has been seen
  444.           if pbResolveBitmap(sprintf("Graphics/Battlers/%sf_%d",getConstantName(PBSpecies,@species),i)) ||
  445.              pbResolveBitmap(sprintf("Graphics/Battlers/%03df_%d",@species,i))
  446.             available.push([_INTL("{1} Male",formnames[i]),j,i]) if j==0
  447.             available.push([_INTL("{1} Female",formnames[i]),j,i]) if j==1
  448.           else
  449.             gendertopush=(genderbyte==254) ? 1 : 0
  450.             available.push([formnames[i],gendertopush,i])
  451.             break
  452.           end
  453.         end
  454.       end
  455.     end
  456.     return available
  457.   end
  458.  
  459.   def pbGetCommands
  460.     commands=[]
  461.     for i in @available
  462.       commands.push(i[0])
  463.     end
  464.     return commands
  465.   end
  466.  
  467.   def pbChooseForm
  468.     oldgender=@gender
  469.     oldform=@form
  470.     commands=pbGetCommands
  471.     using(cmdwindow=Window_CommandPokemon.new(commands)) {
  472.        cmdwindow.height=128 if cmdwindow.height>128
  473.        cmdwindow.z=@viewport.z+1
  474.        pbBottomRight(cmdwindow)
  475.        for i in 0...@available.length
  476.          if @available[i][1]==@gender && @available[i][2]==@form
  477.            cmdwindow.index=i
  478.            break
  479.          end
  480.        end
  481.        loop do
  482.          oldindex=cmdwindow.index
  483.          Graphics.update
  484.          Input.update
  485.          cmdwindow.update
  486.          pbUpdate
  487.          if cmdwindow.index!=oldindex
  488.            @gender=@available[cmdwindow.index][1]
  489.            @form=@available[cmdwindow.index][2]
  490.            pbRefresh
  491.          end
  492.          if Input.trigger?(Input::B)
  493.            pbPlayCancelSE()
  494.            @gender=oldgender
  495.            @form=oldform
  496.            pbRefresh
  497.            break
  498.          end
  499.          if Input.trigger?(Input::C)
  500.            pbPlayDecisionSE()
  501.            break
  502.          end
  503.        end
  504.     }
  505.   end
  506.  
  507.   def pbControls(listlimits)
  508.     Graphics.transition
  509.     ret=0
  510.     loop do
  511.       Graphics.update
  512.       Input.update
  513.       pbUpdate
  514.       if Input.trigger?(Input::C)
  515.         pbChooseForm
  516.       elsif Input.trigger?(Input::LEFT)
  517.         ret=4
  518.         break
  519.       elsif Input.trigger?(Input::UP) && listlimits&1==0 # If not at top of list
  520.         ret=8
  521.         break
  522.       elsif Input.trigger?(Input::DOWN) && listlimits&2==0 # If not at end of list
  523.         ret=2
  524.         break
  525.       elsif Input.trigger?(Input::B)
  526.         ret=1
  527.         pbPlayCancelSE()
  528.         pbFadeOutAndHide(@sprites) { pbUpdate }
  529.         break
  530.       end
  531.     end
  532.     $Trainer.formlastseen[@species][0]=@gender
  533.     $Trainer.formlastseen[@species][1]=@form
  534.     return ret
  535.   end
  536.  
  537.   def pbEndScene
  538.     pbDisposeSpriteHash(@sprites)
  539.     @viewport.dispose
  540.   end
  541. end
  542.  
  543.  
  544.  
  545. class PokedexForm
  546.   def initialize(scene)
  547.     @scene=scene
  548.   end
  549.  
  550.   def pbStartScreen(species,listlimits)
  551.     @scene.pbStartScene(species)
  552.     ret=@scene.pbControls(listlimits)
  553.     @scene.pbEndScene
  554.     return ret
  555.   end
  556. end
RAW Paste Data