Changed: Game_Event_ --- Left +++ Right Changed: PBAnimation --- Left +++ Right @@ -215,5 +215,6 @@ sprite.zoom_y=frame[AnimFrame::ZOOMY]/100.0 sprite.src_rect.set( - 0,0,128,128) + 0,0,sprite.bitmap ? sprite.bitmap.width : 128, + sprite.bitmap ? sprite.bitmap.height : 128) end sprite.color.set( Changed: PokemonEvolution --- Left +++ Right @@ -418,7 +418,5 @@ _INTL("Huh?\r\n{1} stopped evolving!",@pokemon.name)) else - sefile=sprintf("Audio/SE/%03dCry.wav",@newspecies) - playtime=getPlayTime(sefile) - frames=(playtime*Graphics.frame_rate).ceil + frames=pbCryFrameLength(@newspecies) pbBGMStop() pbPlayCry(@newspecies) Changed: Game_Player_ --- Left +++ Right @@ -199,12 +199,16 @@ # * Set Map Display Position to Center of Screen #-------------------------------------------------------------------------- - def center(x, y) - center_x = (Graphics.width/2 - 16) * 4 # Center screen x-coordinate * 4 - center_y = (Graphics.height/2 - 16) * 4 # Center screen y-coordinate * 4 - max_x = ($game_map.width - Graphics.width/32.0) * 128 - max_y = ($game_map.height - Graphics.height/32.0) * 128 - $game_map.display_x = [0, [x * 128 - center_x, max_x].min].max - $game_map.display_y = [0, [y * 128 - center_y, max_y].min].max - end +def center(x, y) + # X coordinate in the center of the screen + center_x = (Graphics.width/2 - Game_Map::TILEWIDTH/2) * Game_Map::XSUBPIXEL + # Y coordinate in the center of the screen + center_y = (Graphics.height/2 - Game_Map::TILEHEIGHT/2) * Game_Map::YSUBPIXEL + max_x = (self.map.width - Graphics.width*1.0/Game_Map::TILEWIDTH) * Game_Map.realResX + max_y = (self.map.height - Graphics.height*1.0/Game_Map::TILEHEIGHT) * Game_Map.realResY + dispx=x * Game_Map.realResX - center_x + dispy=y * Game_Map.realResY - center_y + self.map.display_x = dispx + self.map.display_y = dispy +end #-------------------------------------------------------------------------- # * Move to Designated Position @@ -387,6 +391,8 @@ last_real_y = @real_y super - center_x = (Graphics.width/2 - 16) * 4 # Center screen x-coordinate * 4 - center_y = (Graphics.height/2 - 16) * 4 # Center screen y-coordinate * 4 + center_x = (Graphics.width/2 - Game_Map::TILEWIDTH/2) * + Game_Map::XSUBPIXEL # Center screen x-coordinate * 4 + center_y = (Graphics.height/2 - Game_Map::TILEHEIGHT/2) * + Game_Map::YSUBPIXEL # Center screen y-coordinate * 4 # If character moves down and is positioned lower than the center # of the screen Changed: PokemonMessages --- Left +++ Right @@ -850,5 +850,4 @@ end -# TODO: Allow default command def Kernel.pbShowCommandsWithHelp(msgwindow,commands,help,cmdIfCancel=0,defaultCmd=0) msgwin=msgwindow @@ -941,4 +940,21 @@ end +def pbPositionFaceWindow(facewindow,msgwindow) + return if !facewindow + if msgwindow + if facewindow.height<=msgwindow.height + facewindow.y=msgwindow.y + else + facewindow.y=msgwindow.y+msgwindow.height-facewindow.height + end + facewindow.x=Graphics.width-facewindow.width + msgwindow.x=0 + msgwindow.width=Graphics.width-facewindow.width + else + facewindow.height=Graphics.height if facewindow.height>Graphics.height + facewindow.x=0 + facewindow.y=0 + end +end def pbPositionNearMsgWindow(cmdwindow,msgwindow,side) Changed: PokeBattle_BattlePalace --- Left +++ Right @@ -146,4 +146,11 @@ if @battlers[index].effects[PBEffects::PerishSong]==1 shouldswitch=true + elsif !pbCanChooseMove?(index,0,false) && + !pbCanChooseMove?(index,1,false) && + !pbCanChooseMove?(index,2,false) && + !pbCanChooseMove?(index,3,false) && + @battlers[index].turncount && + @battlers[index].turncount>5 + shouldswitch=true else hppercent=@battlers[index].hp*100/@battlers[index].totalhp Changed: PokemonUtilities --- Left +++ Right @@ -102,16 +102,14 @@ data=pbDownloadToString("http://www.maxmind.com/app/locate_my_ip") if data[/Latitude\/Longi[\s\S]+?\">\s*([\-0-9\.]+)\/([\-0-9\.]+)/] - # TODO: determine lat/lon format lat=($1.to_f)*Math::PI/180 - lon=-($2.to_f)*Math::PI/180 + lon=($2.to_f)*Math::PI/180 end if lat==200 || lon==200 data=pbDownloadToString("http://api.hostip.info/rough.php?position=true") - # TODO: determine lat/lon format if data[/Latitude\:\s+(-?\d+(?:\.\d+)?)/] lat=($1.to_f)*Math::PI/180 end if data[/Longitude\:\s+(-?\d+(?:\.\d+)?)/] - lon=-($1.to_f)*Math::PI/180 + lon=($1.to_f)*Math::PI/180 end end @@ -250,5 +248,4 @@ return Tone.new(red,green,blue,gray) end -$__hour=0 def self.getToneInternal() # Calculates the tone for the current frame, used @@ -765,4 +762,29 @@ end +def pbCryFrameLength(pokemon,pitch=nil) + return 0 if !pokemon + pitch=100 if !pitch + pitch=pitch.to_f/100 + return 0 if pitch<=0 + playtime=0.0 + if pokemon.is_a?(Numeric) + pkmnwav=sprintf("Audio/SE/%03dCry",pokemon) + pkmnwav=RTP.getPath(pkmnwav,["",".wav",".mp3",".ogg"]) + playtime=getPlayTime(pkmnwav) + elsif !pokemon.egg? + if pokemon.respond_to?("chatter") && pokemon.chatter + playtime=pokemon.chatter.time + pitch=1.0 + else + pkmnwav=sprintf("Audio/SE/%03dCry",pokemon.species) + pkmnwav=RTP.getPath(pkmnwav,["",".wav",".mp3",".ogg"]) + playtime=getPlayTime(pkmnwav) + end + end + playtime/=pitch # sound is lengthened the lower the pitch + # 4 is added to provide a buffer between sounds + return (playtime*Graphics.frame_rate).ceil+4 +end + def pbPlayCry(pokemon,volume=90,pitch=nil) return if !pokemon @@ -960,4 +982,9 @@ end +# +# Checks whether the player would still have an unfainted +# Pokemon if the Pokemon given by _pokemonIndex_ were +# removed from the party +# def pbCheckAble(pokemonIndex) for i in 0...$Trainer.party.length @@ -1019,6 +1046,6 @@ def pbPositionPokemonSprite(sprite,left,top) if sprite.bitmap && !sprite.bitmap.disposed? - sprite.x=left+(sprite.bitmap.width-128)/2 - sprite.y=top+(sprite.bitmap.height-128)/2 + sprite.x=left+(128-sprite.bitmap.width)/2 + sprite.y=top+(128-sprite.bitmap.height)/2 else sprite.x=left @@ -1130,4 +1157,7 @@ end +# +# Note: Returns an AnimatedBitmap, not a Bitmap +# def pbLoadPokemonBitmapSpecies(pokemon, species, back=false) if pokemon.egg? Changed: PokemonItems --- Left +++ Right @@ -10,4 +10,15 @@ ITEMMACHINE=8 + +def pbIsHiddenMove?(move) + return false if !$ItemData + for i in 0...$ItemData.length + next if !pbIsHiddenMachine?(i) + atk=$ItemData[i][ITEMMACHINE] + return true if move==atk + end + return false +end + def pbIsImportantItem?(item) return $ItemData[item] && ($ItemData[item][ITEMPOCKET]==5 || pbIsHiddenMachine?(item)) Changed: PokemonMap --- Left +++ Right @@ -357,4 +357,5 @@ MetadataDarkMap=10 MetadataSafariMap=11 + MetadataSnapEdges=12 def pbClearData @@ -623,16 +624,47 @@ newmap=getNewMap(x,y) return false if !newmap - return false if !newmap[0].valid?(newmap[1],newmap[2]) - return true if $game_player.through - return false unless ($DEBUG && Input.press?(Input::CTRL)) || - newmap[0].passable?(newmap[1],newmap[2],0,$game_player) - for event in newmap[0].events.values - if event.x == newmap[1] and event.y == newmap[2] + return isPassable?(newmap[0].map_id,newmap[1],newmap[2]) + end + def isPassableStrict?(mapID,x,y,thisEvent=nil) + thisEvent=$game_player if !thisEvent + map=getMapNoAdd(mapID) + return false if !map + return false if !map.valid?(x,y) + return true if thisEvent.through + if thisEvent==$game_player + return false unless ($DEBUG && Input.press?(Input::CTRL)) || + map.passableStrict?(x,y,0,thisEvent) + else + return false unless map.passableStrict?(x,y,0,thisEvent) + end + for event in map.events.values + if event.x == x and event.y == y return false if !event.through && (event.character_name!="") end end - if $game_player.x == newmap[1] and $game_player.y == newmap[2] - return false if !$game_player.through && @character_name != "" + return true + end + def isPassable?(mapID,x,y,thisEvent=nil) + thisEvent=$game_player if !thisEvent + map=getMapNoAdd(mapID) + return false if !map + return false if !map.valid?(x,y) + return true if thisEvent.through + if thisEvent==$game_player + return false unless ($DEBUG && Input.press?(Input::CTRL)) || + map.passable?(x,y,0,thisEvent) + else + return false unless map.passable?(x,y,0,thisEvent) end + for event in map.events.values + if event.x == x and event.y == y + return false if !event.through && (event.character_name!="") + end + end + if thisEvent.is_a?(Game_Player) + if thisEvent.x == x and thisEvent.y == y + return false if !thisEvent.through && thisEvent.character_name != "" + end + end return true end @@ -648,4 +680,14 @@ return map end + def getMapNoAdd(id) + for map in @maps + if map.map_id==id + return map + end + end + map=Game_Map.new + map.setup(id) + return map + end def updateMaps(scene) updateMapsInternal() @@ -680,4 +722,15 @@ end end + def areConnected?(mapID1,mapID2) + return true if mapID1==mapID2 + conns=MapFactoryHelper.getMapConnections + for conn in conns + if (conn[0]==mapID1 && conn[3]==mapID2) || + (conn[0]==mapID2 && conn[3]==mapID1) + return true + end + end + return false + end def getNewMap(playerX,playerY) id=$game_map.map_id @@ -725,5 +778,5 @@ end def getTerrainTag(mapid,x,y) - map=getMap(mapid) + map=getMapNoAdd(mapid) return map.terrain_tag(x,y) end @@ -733,19 +786,18 @@ return getTerrainTag(tile[0],tile[1],tile[2]) end - def getThisAndOtherEventRelativePos(thisEvent,otherEvent) - return [0,0] if !thisEvent || !otherEvent - if thisEvent.map.map_id==otherEvent.map.map_id + def getRelativePos(thisMapID,thisX,thisY,otherMapID,otherX,otherY) + if thisMapID==otherMapID # Both events share the same map - return [otherEvent.x-thisEvent.x,otherEvent.y-thisEvent.y] + return [otherX-thisX,otherY-thisY] end conns=MapFactoryHelper.getMapConnections for conn in conns - if conn[0]==thisEvent.map.map_id && conn[1]==otherEvent.map.map_id - posX=(thisEvent.x+conn[4]-conn[1])+otherEvent.x - posY=(thisEvent.y+conn[5]-conn[2])+otherEvent.y + if conn[0]==thisMapID && conn[1]==otherMapID + posX=(thisX+conn[4]-conn[1])+otherX + posY=(thisY+conn[5]-conn[2])+otherY return [posX,posY] - elsif conn[1]==thisEvent.map.map_id && conn[0]==otherEvent.map.map_id - posX=(thisEvent.x+conn[1]-conn[4])+otherEvent.x - posY=(thisEvent.y+conn[2]-conn[5])+otherEvent.y + elsif conn[1]==thisMapID && conn[0]==otherMapID + posX=(thisX+conn[1]-conn[4])+otherX + posY=(thisY+conn[2]-conn[5])+otherY return [posX,posY] end @@ -753,11 +805,22 @@ return [0,0] end - def getFacingTile(direction=nil,event=nil) - event=$game_player if event==nil - return [0,0,0] if !event - x=event.x - y=event.y - id=event.map.map_id - direction=event.direction if direction==nil + # Gets the distance from this event to another event. + # Example: If this event's coordinates are (2,5) and + # the other event's coordinates are (5,1), returns + # the array (3,-4), because (5-2=3) and (1-5=-4) + def getThisAndOtherEventRelativePos(thisEvent,otherEvent) + return [0,0] if !thisEvent || !otherEvent + return getRelativePos( + thisEvent.map.map_id,thisEvent.x,thisEvent.y, + otherEvent.map.map_id,otherEvent.x,otherEvent.y) + end + def getThisAndOtherPosRelativePos(thisEvent,otherMapID,otherX,otherY) + return [0,0] if !thisEvent + return getRelativePos( + thisEvent.map.map_id,thisEvent.x,thisEvent.y, + otherMapID,otherX,otherY) + end + def getFacingTileFromPos(mapID,x,y,direction=0) + id=mapID case direction when 1; y+=1; x-=1 @@ -772,5 +835,5 @@ return [id,x,y] end - if event.map.valid?(x,y) + if getMapNoAdd(id).valid?(x,y) return [id,x,y] end @@ -794,4 +857,13 @@ end return nil + end + def getFacingTile(direction=nil,event=nil) + event=$game_player if event==nil + return [0,0,0] if !event + x=event.x + y=event.y + id=event.map.map_id + direction=event.direction if direction==nil + return getFacingTileFromPos(id,x,y,direction) end def setMapsInRange Changed: Compiler --- Left +++ Right @@ -48,8 +48,8 @@ errorlogline="\r\n"+errorlogline end + File.open(errorlog,"ab"){|f| f.write(message) } if !e.is_a?(Hangup) print("#{message}\r\nThis exception was logged in #{errorlogline}.\r\nPress Ctrl+C to copy this message to the clipboard.") end - File.open(errorlog,"ab"){|f| f.write(message) } end @@ -691,5 +691,6 @@ "DiveMap"=>[9,"u"], "DarkMap"=>[10,"b"], - "SafariMap"=>[11,"b"] + "SafariMap"=>[11,"b"], + "SnapEdges"=>[12,"b"] } end @@ -1423,7 +1424,8 @@ sectionname=nil sections=[] - f=File.open("PBS/tm.txt","rb") - FileLineData.file="PBS/tm.txt" - f.each_line {|line| + if FileTest.exist?("PBS/tm.txt") + f=File.open("PBS/tm.txt","rb") + FileLineData.file="PBS/tm.txt" + f.each_line {|line| if lineno==1&&line[0]==0xEF&&line[1]==0xBB&&line[2]==0xBF line=line[3,line.length-3] @@ -1454,5 +1456,9 @@ Win32API.SetWindowText(_INTL("Processing line {1}",lineno)) end - } + } + elsif FileTest.exist?("Data/tmRS.dat") + File.open("Data/tmRS.dat","rb"){|f| + } + end save_data(sections,"Data/tm.dat") f.close @@ -2848,4 +2854,5 @@ thisEvent.pages[0].list.any? {|cmd| cmd.code==201 } && mapdata.isPassable?(mapID,thisEvent.x,thisEvent.y+1) && + mapdata.isPassable?(mapID,thisEvent.x,thisEvent.y) && !mapdata.isPassable?(mapID,thisEvent.x-1,thisEvent.y) && !mapdata.isPassable?(mapID,thisEvent.x+1,thisEvent.y) && @@ -3545,5 +3552,4 @@ if trainerid filename=sprintf("trchar%03d",trainerid) - p filetype if FileTest.image_exist?("Graphics/Characters/"+filename) firstpage.graphic.character_name=sprintf(filename) @@ -3765,5 +3771,5 @@ def pbImportNewMaps - return if !$DEBUG + return false if !$DEBUG mapfiles={} # Get IDs of all maps in the Data folder @@ -3807,4 +3813,5 @@ Kernel.pbMessage(_INTL("New maps copied to the Data folder were successfully imported.",id)) end + return imported end @@ -3813,6 +3820,6 @@ latesttexttime=0 mustcompile=false - pbImportNewMaps - mustcompile=true if !(PBSpecies.respond_to?("maxValue") rescue false) + mustcompile|=pbImportNewMaps + mustcompile|=!(PBSpecies.respond_to?("maxValue") rescue false) for i in 0...datafiles.length begin Changed: AudioUtilities --- Left +++ Right @@ -1005,9 +1005,20 @@ def getPlayTime(filename) - return [getPlayTime2(filename),0].max + if FileTest.exist?(filename) + return [getPlayTime2(filename),0].max + elsif FileTest.exist?(filename+".wav") + return [getPlayTime2(filename+".wav"),0].max + elsif FileTest.exist?(filename+".mp3") + return [getPlayTime2(filename+".mp3"),0].max + elsif FileTest.exist?(filename+".ogg") + return [getPlayTime2(filename+".ogg"),0].max + else + return 0 + end end def getPlayTime2(filename) time=-1 + return -1 if !FileTest.exist?(filename) fgetdw=proc{|file| (file.eof? ? 0 : (file.read(4).unpack("V")[0] || 0)) Changed: PokemonEditor --- Left +++ Right @@ -2018,5 +2018,7 @@ _INTL("If true, this map is dark and a circle of light appears around the player.")], ["SafariMap",BooleanProperty, - _INTL("If true, this map is part of the Safari Zone (both indoor and outdoor). Not to be used in the reception desk.")] + _INTL("If true, this map is part of the Safari Zone (both indoor and outdoor). Not to be used in the reception desk.")], + ["SnapEdges",BooleanProperty, + _INTL("If true, when the player goes near this map's edge, the game doesn't center the player as usual.")] ] GLOBALMETADATA=[ Changed: PokemonField --- Left +++ Right @@ -510,4 +510,7 @@ viewport=Viewport.new(0,0,Graphics.width,Graphics.height) viewport.z=99999 +# +# Fade to gray a few times. +# viewport.color=Color.new(17*8,17*8,17*8) 3.times do Changed: PokeBattle_Move --- Left +++ Right @@ -415,5 +415,5 @@ damage=pbModifyDamage(damage,attacker,opponent) # Helping Hand - if attacker.effects[PBEffects::HelpingHand] + if attacker.effects[PBEffects::HelpingHand] && (options&NOREFLECT)==0 damage=(damage*1.5).floor end Changed: PokemonSummary --- Left +++ Right @@ -75,6 +75,5 @@ @sprites["pokemon"].setPokemonBitmap(@pokemon) @sprites["pokemon"].mirror=true - @sprites["pokemon"].x=16 - @sprites["pokemon"].y=64 + pbPositionPokemonSprite(@sprites["pokemon"],16,64) @sprites["movepresel"]=MoveSelectionSprite.new(@viewport) @sprites["movesel"]=MoveSelectionSprite.new(@viewport) @@ -518,14 +517,4 @@ end -def pbIsHiddenMove?(move) - return false if !$ItemData - for i in 0...$ItemData.length - next if !pbIsHiddenMachine?(i) - atk=$ItemData[i][ITEMMACHINE] - return true if move==atk - end - return false -end - def pbChooseMoveToForget(moveToLearn) selmove=0 @@ -772,6 +761,7 @@ @scene.pbStartForgetScene(party,partyindex,moveToLearn) loop do - ret=@scene.pbForgetMove(moveToLearn) - if ret>=0 && moveToLearn!=0 && pbIsHiddenMove?(@pokemon.moves[ret].id) + ret=@scene.pbChooseMoveToForget(moveToLearn) + if ret>=0 && moveToLearn!=0 && + pbIsHiddenMove?(party[partyindex].moves[ret].id) Kernel.pbMessage(_INTL("HM moves can't be forgotten now.")){ pbUpdate } else Changed: Resolution_ --- Left +++ Right @@ -13,8 +13,16 @@ def display_x=(value) @display_x=value + if pbGetMetadata(self.map_id,MetadataSnapEdges) + max_x = (self.width - Graphics.width*1.0/Game_Map::TILEWIDTH) * Game_Map.realResX + @display_x = [0, [@display_x, max_x].min].max + end $MapFactory.setMapsInRange if $MapFactory end def display_y=(value) @display_y=value + if pbGetMetadata(self.map_id,MetadataSnapEdges) + max_y = (self.height - Graphics.height*1.0/Game_Map::TILEHEIGHT) * Game_Map.realResY + @display_y = [0, [@display_y, max_y].min].max + end $MapFactory.setMapsInRange if $MapFactory end @@ -42,14 +50,2 @@ end -class Game_Player < Game_Character -def center(x, y) - center_x = (Graphics.width/2 - Game_Map::TILEWIDTH/2) * Game_Map::XSUBPIXEL # X coordinate in the center of the screen - center_y = (Graphics.height/2 - Game_Map::TILEHEIGHT/2) * Game_Map::YSUBPIXEL # Y coordinate in the center of the screen - max_x = ($game_map.width - Graphics.width*1.0/Game_Map::TILEWIDTH) * Game_Map.realResX - max_y = ($game_map.height - Graphics.height*1.0/Game_Map::TILEHEIGHT) * Game_Map.realResY - dispx=x * Game_Map.realResX - center_x - dispy=y * Game_Map.realResY - center_y - $game_map.display_x = dispx#[0, [dispx, max_x].min].max - $game_map.display_y = dispy#[0, [dispy, max_y].min].max -end -end Changed: PokeBattle_ActualScene --- Left +++ Right @@ -2245,6 +2245,7 @@ def pbFainted(pkmn) # This method is called whenever a Pokémon faints + frames=pbCryFrameLength(pkmn.pokemon) pbPlayCry(pkmn.pokemon) - 30.times do + frames.times do pbGraphicsUpdate pbInputUpdate Changed: DependentEvents --- Left +++ Right @@ -18,4 +18,10 @@ $PokemonTemp.dependentEvents.addEvent($game_map.events[eventID],eventName,commonEvent) end +# +# Gets the Game_Character object associated with a dependent event. +# +def pbGetDependency(eventName) + return $PokemonTemp.dependentEvents.getEventByName(eventName) +end def pbRemoveDependency2(eventName) $PokemonTemp.dependentEvents.removeEventByName(eventName) @@ -40,13 +46,21 @@ def pbTurnTowardEvent(event,otherEvent) - sx = event.x - otherEvent.x - sy = event.y - otherEvent.y + sx=0 + sy=0 + if $MapFactory + relativePos=$MapFactory.getThisAndOtherEventRelativePos(otherEvent,event) + sx = relativePos[0] + sy = relativePos[1] + else + sx = event.x - otherEvent.x + sy = event.y - otherEvent.y + end if sx == 0 and sy == 0 - return + return end if sx.abs > sy.abs - sx > 0 ? event.turn_left : event.turn_right + sx > 0 ? event.turn_left : event.turn_right else - sy > 0 ? event.turn_up : event.turn_down + sy > 0 ? event.turn_up : event.turn_down end end @@ -71,10 +85,6 @@ end -def pbTestPass(follower,x,y,direction) - oldThrough=follower.through - follower.through=false - ret=follower.passableStrict?(x,y,direction) - follower.through=oldThrough - return ret +def pbTestPass(follower,x,y,direction=nil) + return $MapFactory.isPassableStrict?(follower.map.map_id,x,y,follower) end @@ -197,13 +207,13 @@ rpgEvent=RPG::Event.new(eventData[3],eventData[4]) rpgEvent.id=eventData[1] + if eventData[9] + # Must setup common event list here and now + commonEvent=Game_CommonEvent.new(eventData[9]) + rpgEvent.pages[0].list=commonEvent.list + end newEvent=Game_Event.new(eventData[0],rpgEvent, $MapFactory.getMap(eventData[2])) newEvent.character_name=eventData[6] newEvent.character_hue=eventData[7] - # Call common event - if eventData[9] - commonEvent=Game_CommonEvent.new(eventData[9]) - newEvent.pages[0].list=commonEvent.list - end case eventData[5] # direction when 2 # down @@ -248,9 +258,9 @@ def pbFollowEventAcrossMaps(leader,follower,instant=false,leaderIsTrueLeader=true) d=leader.direction - # Get relative position of the follower from the leader - relativePos=$MapFactory.getThisAndOtherEventRelativePos(leader, follower) + areConnected=$MapFactory.areConnected?(leader.map.map_id,follower.map.map_id) # Get the rear facing tile of leader facingDirection=[0,0,8,0,6,0,4,0,2][d] - if !leaderIsTrueLeader + if !leaderIsTrueLeader && areConnected + relativePos=$MapFactory.getThisAndOtherEventRelativePos(leader,follower) if (relativePos[1]==0 && relativePos[0]==2) # 2 spaces to the right of leader facingDirection=6 @@ -263,12 +273,47 @@ end end - mapTile=$MapFactory.getFacingTile(facingDirection,leader) - if !mapTile - # No room behind, just place the event at leader's position - follower.moveto(leader.x,leader.y) - pbTurnTowardEvent(follower,leader) - return + facings=[facingDirection] # Get facing from behind + facings.push([0,0,4,0,8,0,2,0,6][d]) # Get right facing + facings.push([0,0,6,0,2,0,8,0,4][d]) # Get left facing + if !leaderIsTrueLeader + facings.push([0,0,2,0,4,0,6,0,8][d]) # Get forward facing end - if follower.map.map_id==mapTile[0] + mapTile=nil + if areConnected + bestRelativePos=-1 + oldthrough=follower.through + follower.through=false + for i in 0...facings.length + facing=facings[i] + tile=$MapFactory.getFacingTile(facing,leader) + passable=tile && $MapFactory.isPassableStrict?(tile[0],tile[1],tile[2],follower) + if i==0 && !passable && tile && + $MapFactory.getTerrainTag(tile[0],tile[1],tile[2])==PBTerrain::Ledge + # If the tile isn't passable and the tile is a ledge, + # get tile from further behind + tile=$MapFactory.getFacingTileFromPos(tile[0],tile[1],tile[2],facing) + passable=tile && $MapFactory.isPassableStrict?(tile[0],tile[1],tile[2],follower) + end + if passable + relativePos=$MapFactory.getThisAndOtherPosRelativePos( + follower,tile[0],tile[1],tile[2]) + distance=Math.sqrt(relativePos[0]*relativePos[0]+relativePos[1]*relativePos[1]) + if bestRelativePos==-1 || bestRelativePos>distance + bestRelativePos=distance + mapTile=tile + end + if i==0 && distance<=1 # Prefer behind if tile can move up to 1 space + break + end + end + end + follower.through=oldthrough + else + tile=$MapFactory.getFacingTile(facings[0],leader) + passable=tile && $MapFactory.isPassableStrict?( + tile[0],tile[1],tile[2],follower) + mapTile=passable ? mapTile : nil + end + if mapTile && follower.map.map_id==mapTile[0] # Follower is on same map newX=mapTile[1] @@ -278,4 +323,5 @@ posX = newX + deltaX posY = newY + deltaY + follower.move_speed=leader.move_speed # sync movespeed if (follower.x-newX==-1 && follower.y==newY) || (follower.x-newX==1 && follower.y==newY) || @@ -306,15 +352,25 @@ pbTurnTowardEvent(follower,leader) else - # Follower will move to different map - events=$PokemonGlobal.dependentEvents - eventIndex=pbEnsureEvent(follower,mapTile[0]) - if eventIndex>=0 - newFollower=@realEvents[eventIndex] - newEventData=events[eventIndex] - newFollower.moveto(mapTile[1],mapTile[2]) - newEventData[3]=mapTile[1] - newEventData[4]=mapTile[2] - if mapTile[0]==leader.map.map_id - pbTurnTowardEvent(follower,leader) + if !mapTile + # Make current position into leader's position + mapTile=[leader.map.map_id,leader.x,leader.y] + end + if follower.map.map_id==mapTile[0] + # Follower is on same map as leader + follower.moveto(leader.x,leader.y) + pbTurnTowardEvent(follower,leader) + else + # Follower will move to different map + events=$PokemonGlobal.dependentEvents + eventIndex=pbEnsureEvent(follower,mapTile[0]) + if eventIndex>=0 + newFollower=@realEvents[eventIndex] + newEventData=events[eventIndex] + newFollower.moveto(mapTile[1],mapTile[2]) + newEventData[3]=mapTile[1] + newEventData[4]=mapTile[2] + if mapTile[0]==leader.map.map_id + pbTurnTowardEvent(follower,leader) + end end end @@ -384,4 +440,5 @@ for i in 0...events.length event=@realEvents[i] + event.transparent=$game_player.transparent if (event.jumping? || event.moving?) || !($game_player.jumping? || $game_player.moving?) then event.update @@ -403,12 +460,22 @@ if e.x==$game_player.x && e.y==$game_player.y # On same position - if not e.jumping? and (!e.respond_to?("over_trigger") || e.over_trigger?) - $game_temp.common_event_id = d[9] + if not e.jumping? && (!e.respond_to?("over_trigger") || e.over_trigger?) + if e.list.size>1 + # Start event + $game_map.refresh if $game_map.need_refresh + e.lock + pbMapInterpreter.setup(e.list,e.id) + end end elsif facingTile && e.map.map_id==facingTile[0] && e.x==facingTile[1] && e.y==facingTile[2] # On facing tile - if not e.jumping? (!e.respond_to?("over_trigger") || !e.over_trigger?) - $game_temp.common_event_id = d[9] + if not e.jumping? && (!e.respond_to?("over_trigger") || !e.over_trigger?) + if e.list.size>1 + # Start event + $game_map.refresh if $game_map.need_refresh + e.lock + pbMapInterpreter.setup(e.list,e.id) + end end end @@ -431,7 +498,15 @@ end end + def getEventByName(name) + events=$PokemonGlobal.dependentEvents + for i in 0...events.length + if events[i] && events[i][8]==name # Arbitrary name given to dependent event + return @realEvents[i] + end + end + return nil + end def removeEventByName(name) events=$PokemonGlobal.dependentEvents - mapid=$game_map.map_id for i in 0...events.length if events[i] && events[i][8]==name # Arbitrary name given to dependent event