Changed: PokemonEvolution --- Left +++ Right @@ -180,10 +180,4 @@ end -def pecho(*arg) - for i in arg - echo i.inspect+"\r\n" - end -end - class SpriteMetafilePlayer def initialize(metafile,sprite=nil) @@ -396,9 +390,8 @@ metaplayer2.play $game_system.bgm_stop - sefile=sprintf("Audio/SE/%03dCry.wav",@pokemon.species) - Audio.se_play(sefile) + pbPlayCry(@pokemon) Kernel.pbDisplayMessageFancy(@sprites["msgwindow"], _INTL("What?\r\n{1} is evolving!",@pokemon.name),-1,100) - Audio.se_play(pbGetDecisionSE) + pbPlayDecisionSE() oldstate=pbSaveSpriteState(@sprites["rsprite1"]) oldstate2=pbSaveSpriteState(@sprites["rsprite2"]) @@ -420,10 +413,10 @@ if canceled $game_system.bgm_stop - Audio.se_play(pbGetDecisionSE) + pbPlayCancelSE() Kernel.pbDisplayMessageFancy(@sprites["msgwindow"], _INTL("Huh?\r\n{1} stopped evolving!",@pokemon.name)) else sefile=sprintf("Audio/SE/%03dCry.wav",@newspecies) - playtime=[0,getPlayTime(sefile)].max + playtime=getPlayTime(sefile) frames=(playtime*Graphics.frame_rate).ceil $game_system.bgm_stop Changed: Audio --- Left +++ Right @@ -136,5 +136,5 @@ volume=0 if !getPlayMusic() begin - filename = canonicalize(rtpGetPath(name,[".mid",".mp3",".wma",".ogg",".wav",""])) + filename = canonicalize(RTP.getPath(name,[".mid",".mp3",".wma",".ogg",".wav",""])) if AudioState.meActive? AudioState.setWaitingBGM(filename,volume,pitch,position) Changed: PokemonMessages --- Left +++ Right @@ -366,6 +366,4 @@ def pbButtonInputProcessing(variableNumber=0,timeoutFrames=0) msgwindow=Kernel.pbCreateMessageWindow - skinfile=PokemonSkins.getDefaultTextSkin - pbLoadSkin(msgwindow,"Graphics/Windowskins/#{skinfile}") Kernel.pbDisplayMessageFancy(msgwindow,_INTL("PRESS ANY CONTROL KEY"),nil,0) ret=0 @@ -401,4 +399,5 @@ class Game_Interpreter include InterpreterMixin + @@immediateDisplayAfterWait=false def command_105 pbButtonInputProcessing(@list[@index].parameters[0]) @@ -438,4 +437,16 @@ commands=@list[nextIndex].parameters @index=nextIndex + elsif code == 106 && @@immediateDisplayAfterWait + params=@list[nextIndex].parameters + if params[0]<=10 + nextcode=@list[nextIndex+1].code + if nextcode==101||nextcode==102||nextcode==103 + @index=nextIndex + else + break + end + else + break + end elsif code == 103 numInputVar=@list[nextIndex].parameters[0] @@ -449,5 +460,4 @@ end message=_MAPINTL($game_map.map_id,message) - defaultskin=PokemonSkins.getDefaultTextSkin if commands cmdlist=[] @@ -455,10 +465,10 @@ cmdlist.push(_MAPINTL($game_map.map_id,cmd)) end - command=Kernel.pbMessage(message+messageend,cmdlist,commands[1],defaultskin) + command=Kernel.pbMessage(message+messageend,cmdlist,commands[1]) @branch[@list[@index].indent] = command elsif numInputVar - Kernel.pbMessageChooseNumberVarNew(message+messageend,numInputVar,numInputDigitsMax,defaultskin) + Kernel.pbMessageChooseNumberVarNew(message+messageend,numInputVar,numInputDigitsMax) else - Kernel.pbMessage(message+messageend,nil,0,defaultskin) + Kernel.pbMessage(message+messageend) end return true @@ -480,4 +490,5 @@ class Interpreter include InterpreterMixin + @@immediateDisplayAfterWait=false def command_105 pbButtonInputProcessing(@list[@index].parameters[0]) @@ -518,4 +529,16 @@ commands=@list[nextIndex].parameters @index=nextIndex + elsif code == 106 && @@immediateDisplayAfterWait + params=@list[nextIndex].parameters + if params[0]<=10 + nextcode=@list[nextIndex+1].code + if nextcode==101||nextcode==102||nextcode==103 + @index=nextIndex + else + break + end + else + break + end elsif code == 103 numInputVar=@list[nextIndex].parameters[0] @@ -529,5 +552,4 @@ end message=_MAPINTL($game_map.map_id,message) - defaultskin=PokemonSkins.getDefaultTextSkin if commands cmdlist=[] @@ -535,10 +557,10 @@ cmdlist.push(_MAPINTL($game_map.map_id,cmd)) end - command=Kernel.pbMessage(message+messageend,cmdlist,commands[1],defaultskin) + command=Kernel.pbMessage(message+messageend,cmdlist,commands[1]) @branch[@list[@index].indent] = command elsif numInputVar - Kernel.pbMessageChooseNumberVarNew(message+messageend,numInputVar,numInputDigitsMax,defaultskin) + Kernel.pbMessageChooseNumberVarNew(message+messageend,numInputVar,numInputDigitsMax) else - Kernel.pbMessage(message+messageend,nil,0,defaultskin) + Kernel.pbMessage(message+messageend,nil) end return true @@ -800,11 +822,5 @@ def Kernel.pbMessage(message,commands=nil,cmdIfCancel=0,skin=nil) ret=0 - msgwindow=Kernel.pbCreateMessageWindow - if skin - pbLoadSkin(msgwindow,"Graphics/Windowskins/#{skin}") - else - skinfile=PokemonSkins.getDefaultTextSkin - pbLoadSkin(msgwindow,"Graphics/Windowskins/#{skinfile}") - end + msgwindow=Kernel.pbCreateMessageWindow(nil,skin) if commands ret=Kernel.pbDisplayMessageFancy(msgwindow,message,-1,0,commands,cmdIfCancel,true) @@ -819,28 +835,13 @@ def Kernel.pbMessageBrief(message) - msgwindow=Kernel.pbCreateMessageWindow - Audio.se_play(pbGetDecisionSE) - skinfile=PokemonSkins.getDefaultTextSkin - pbLoadSkin(msgwindow,"Graphics/Windowskins/#{skinfile}") - Kernel.pbDisplayMessageFancy(msgwindow,message,-1,0,nil,nil,true) - Kernel.pbDisposeMessageWindow(msgwindow) - Input.update + return Kernel.pbMessage(message+"\\wtnp[0]") end def Kernel.pbMessageSound(message,se) - msgwindow=Kernel.pbCreateMessageWindow - skinfile=PokemonSkins.getDefaultTextSkin - pbLoadSkin(msgwindow,"Graphics/Windowskins/#{skinfile}") - Kernel.pbDisplayMessageFancy(msgwindow,message,-1,0,nil,nil,false) - Audio.se_play(se) if se - Kernel.pbDisplayMessageFancy(msgwindow,message,nil,60) - Kernel.pbDisposeMessageWindow(msgwindow) - Input.update + return Kernel.pbMessage("\\se[]"+message+"\\se[../../#{se}]\\wtnp[30]") end def Kernel.pbMessageChooseNumber(message,defNumber,maxDigits,skin=nil,maxnumber=nil) - msgwindow=Kernel.pbCreateMessageWindow - skin=PokemonSkins.getDefaultTextSkin if !skin - pbLoadSkin(msgwindow,"Graphics/Windowskins/#{skin}") if skin + msgwindow=Kernel.pbCreateMessageWindow(nil,skin) Kernel.pbDisplayMessageFancy(msgwindow,message,-1,0,nil,nil,true) ret=Kernel.pbChooseNumber(msgwindow,defNumber,maxDigits,maxnumber) @@ -851,7 +852,5 @@ def Kernel.pbMessageChooseNumberEx(message,initialNum,minNum,maxNum,cancelNum,skin=nil) - msgwindow=Kernel.pbCreateMessageWindow - skin=PokemonSkins.getDefaultTextSkin if !skin - pbLoadSkin(msgwindow,"Graphics/Windowskins/#{skin}") + msgwindow=Kernel.pbCreateMessageWindow(nil,skin) Kernel.pbDisplayMessageFancy(msgwindow,message,-1,0,nil,nil,true) ret=Kernel.pbChooseNumberEx(msgwindow,initialNum,minNum,maxNum,cancelNum) @@ -862,7 +861,5 @@ def Kernel.pbMessageChooseNumberNew(message,defNumber,maxDigits,skin=nil,maxnumber=nil) - msgwindow=Kernel.pbCreateMessageWindow - skin=PokemonSkins.getDefaultTextSkin if !skin - pbLoadSkin(msgwindow,"Graphics/Windowskins/#{skin}") + msgwindow=Kernel.pbCreateMessageWindow(nil,skin) Kernel.pbDisplayMessageFancy(msgwindow,message,-1,0,nil,nil,true) ret=Kernel.pbChooseNumberNew(msgwindow,defNumber,maxDigits,maxnumber) @@ -873,7 +870,5 @@ def Kernel.pbMessageChooseNumberVar(message,variable,maxDigits,skin=nil) - msgwindow=Kernel.pbCreateMessageWindow - skin=PokemonSkins.getDefaultTextSkin if !skin - pbLoadSkin(msgwindow,"Graphics/Windowskins/#{skin}") + msgwindow=Kernel.pbCreateMessageWindow(nil,skin) Kernel.pbDisplayMessageFancy(msgwindow,message,-1,0,nil,nil,true) ret=Kernel.pbChooseNumber(msgwindow,$game_variables[variable],maxDigits) @@ -885,7 +880,5 @@ def Kernel.pbMessageChooseNumberVarNew(message,variable,maxDigits,skin=nil) - msgwindow=Kernel.pbCreateMessageWindow - skin=PokemonSkins.getDefaultTextSkin if !skin - pbLoadSkin(msgwindow,"Graphics/Windowskins/#{skin}") + msgwindow=Kernel.pbCreateMessageWindow(nil,skin) Kernel.pbDisplayMessageFancy(msgwindow,message,-1,0,nil,nil,true) ret=Kernel.pbChooseNumberNew(msgwindow,$game_variables[variable],maxDigits) @@ -919,5 +912,5 @@ end -def Kernel.pbCreateMessageWindow(viewport=nil) +def Kernel.pbCreateMessageWindow(viewport=nil,skin=nil) msgwindow=Window_AdvancedTextPokemon.new("") if !viewport @@ -932,4 +925,6 @@ $game_temp.message_window_showing=true if $game_temp $game_message.visible=true if $game_message + skin=PokemonSkins.getDefaultTextSkin if !skin + pbLoadSkin(msgwindow,"Graphics/Windowskins/#{skin}") return msgwindow end @@ -981,5 +976,5 @@ g/=256 b/=256 - return (r+g+b)/3<128 + return (r*0.299+g*0.587+b*0.114)<128 elsif windowskin.width==128 && windowskin.height==128 y=4 @@ -997,8 +992,8 @@ g/=256 b/=256 - return (r+g+b)/3<128 + return (r*0.299+g*0.587+b*0.114)<128 else clr=windowskin.get_pixel(windowskin.width/2, windowskin.height/2) - return (clr.red+clr.green+clr.blue)/3<128 + return (clr.red*0.299+clr.green*0.587+clr.blue*0.114)<128 end end @@ -1014,5 +1009,5 @@ @facebitmaptmp=AnimatedBitmap.new(facefile) @facebitmap=Bitmap.new(96,96) - @facebitmap.blt(0,0,@facebitmaptmp,Rect.new( + @facebitmap.blt(0,0,@facebitmaptmp.bitmap,Rect.new( (@faceIndex % 4) * 96, (@faceIndex / 4) * 96, 96, 96 @@ -1073,4 +1068,28 @@ end +def pbDisplayGoldWindow(msgwindow) + moneyString="" + if $Trainer + moneyString=_INTL("${1}",$Trainer.money) + else + if $data_system.respond_to?("words") + moneyString=_INTL("{1} {2}",$game_party.gold,$data_system.words.gold) + else + moneyString=_INTL("{1} {2}",$game_party.gold,Vocab.gold) + end + end + goldwindow=Window_UnformattedTextPokemon.newWithSize( + _INTL("MONEY:\n{1}",moneyString),0,0,32,32,msgwindow.viewport) + goldwindow.resizeToFit(goldwindow.text,Graphics.width) + if msgwindow.y==0 + goldwindow.y=Graphics.height-goldwindow.height + else + goldwindow.y=0 + end + goldwindow.viewport=msgwindow.viewport + goldwindow.z=msgwindow.z + return goldwindow +end + def pbRecord(arg); end @@ -1078,4 +1097,5 @@ msgwindow,message,textspeed=-1, delay=-1,msgCommands=nil,msgCommandsCancel=-1,sound=false) + return if !msgwindow oldtextspeed=pbGetSystemTextSpeed oldletterbyletter=msgwindow.letterbyletter @@ -1099,5 +1119,5 @@ ### Text replacement if $game_actors - text.gsub!(/\\[Nn]\[([0-8])\]/){ + text.gsub!(/\\[Nn]\[([1-8])\]/){ m=$1.to_i next $game_actors[m].name @@ -1165,5 +1185,4 @@ text=textchunks.join("") unformattedText=toUnformattedText(text) - startSE=sound ? pbGetDecisionSE : nil for i in 0...controls.length control=controls[i][0] @@ -1173,5 +1192,5 @@ facewindow=PictureWindow.new("Graphics/Pictures/#{param}") elsif control=="se" && controls[i][2]==0 - startSE="Audio/SE/#{param}" + startSE=param controls[i]=nil elsif control=="ff" @@ -1190,19 +1209,20 @@ end end - Audio.se_play(startSE) if startSE + if startSE!=nil + $game_system.se_play(pbStringToAudioFile(startSE)) if startSE!="" + elsif sound + pbPlayDecisionSE() + end delay=0 if commands ########## Position message window ############## msgwindow.height=32*linecount+msgwindow.borderY msgwindow.y=(Graphics.height)-(msgwindow.height) - facetop=false if $game_temp && $game_temp.in_battle && !$scene.respond_to?("update_basic") msgwindow.y=0 - facetop=true elsif $game_system && $game_system.respond_to?("message_position") case $game_system.message_position when 0 # up msgwindow.y=0 - facetop=true when 1 # middle msgwindow.y=(Graphics.height/2)-(msgwindow.height/2) @@ -1220,5 +1240,5 @@ when 1 # dim msgwindow.opacity=0 - msgback=IconWindow(0,msgwindow.y,msgwindow.viewport) + msgback=IconSprite.new(0,msgwindow.y,msgwindow.viewport) msgback.z=msgwindow.z-1 msgback.setBitmap("Graphics/System/MessageBack") @@ -1257,33 +1277,17 @@ elsif control=="g" # Display gold window goldwindow.dispose if goldwindow - moneyString="" - if $Trainer - moneyString=_INTL("${1}",$Trainer.money) - else - if $data_system.respond_to?("words") - moneyString=_INTL("{1} {2}",$game_party.gold,$data_system.words.gold) - else - moneyString=_INTL("{1} {2}",$game_party.gold,Vocab.gold) - end - end - goldwindow=Window_UnformattedTextPokemon.newWithSize( - _INTL("MONEY:\n{1}",moneyString),0,0,32,32,msgwindow.viewport) - goldwindow.resizeToFit(goldwindow.text,Graphics.width) - if facetop - goldwindow.y=Graphics.height-goldwindow.height - else - goldwindow.y=0 - end - goldwindow.viewport=msgwindow.viewport - goldwindow.z=msgwindow.z + goldwindow=pbDisplayGoldWindow(msgwindow) elsif control=="wu" msgwindow.y=0 msgback.y=msgwindow.y if msgback + pbPositionNearMsgWindow(facewindow,msgwindow,:left) elsif control=="wm" msgwindow.y=(Graphics.height/2)-(msgwindow.height/2) msgback.y=msgwindow.y if msgback + pbPositionNearMsgWindow(facewindow,msgwindow,:left) elsif control=="wd" msgwindow.y=(Graphics.height)-(msgwindow.height) msgback.y=msgwindow.y if msgback + pbPositionNearMsgWindow(facewindow,msgwindow,:left) elsif control=="." waitcount+=Graphics.frame_rate/4 @@ -1306,7 +1310,7 @@ autoresume=true elsif control=="se" # Play SE - $game_system.se_play(pbStringToAudioFile(param)) + $game_system.se_play(pbStringToAudioFile(param)) if param!="" elsif control=="me" # Play ME - $game_system.me_play(pbStringToAudioFile(param)) + $game_system.me_play(pbStringToAudioFile(param)) if param!="" end controls[i]=nil @@ -1333,5 +1337,5 @@ if (Input.trigger?(Input::C) || Input.trigger?(Input::B)) if msgwindow.busy? - Audio.se_play(pbGetDecisionSE) if msgwindow.pausing? + pbPlayDecisionSE() if msgwindow.pausing? msgwindow.resume else Changed: PokemonEntry --- Left +++ Right @@ -20,4 +20,6 @@ F8=28 F9=29 + LeftMouseKey=1 + RightMouseKey=2 # GetAsyncKeyState or GetKeyState will work here @GetKeyState=Win32API.new("user32", "GetAsyncKeyState", "i", "i") @@ -213,4 +215,56 @@ end +# Requires Win32API +module Mouse + gsm = Win32API.new('user32', 'GetSystemMetrics', 'i', 'i') + @GetCursorPos = Win32API.new('user32', 'GetCursorPos', 'p', 'i') + @SetCapture = Win32API.new('user32', 'SetCapture', 'p', 'i') + @ReleaseCapture = Win32API.new('user32', 'ReleaseCapture', '', 'i') + module_function + def getMouseGlobalPos + pos = [0, 0].pack('ll') + if @GetCursorPos.call(pos) != 0 + return pos.unpack('ll') + else + return nil + end + end + def screen_to_client(x, y) + return nil unless x and y + screenToClient = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i') + pos = [x, y].pack('ll') + if screenToClient.call(Win32API.pbFindRgssWindow, pos) != 0 + return pos.unpack('ll') + else + return nil + end + end + def setCapture + @SetCapture.call(Win32API.pbFindRgssWindow) + end + def releaseCapture + @ReleaseCapture.call + end + # Returns the position of the mouse relative to the game window. + def getMousePos(catch_anywhere = false) + resizeFactor=($ResizeFactor) ? $ResizeFactor : 1 + x, y = screen_to_client(*getMouseGlobalPos) + width, height = Win32API.client_size + if catch_anywhere or (x >= 0 and y >= 0 and x < width and y < height) + return (x/resizeFactor).to_i, (y/resizeFactor).to_i + else + return nil + end + end + def del + if @oldcursor == nil + return + else + @SetClassLong.call(Win32API.pbFindRgssWindow,-12, @oldcursor) + @oldcursor = nil + end + end +end + class Window_CharacterEntry < SpriteWindow_Base XSIZE=13 @@ -322,5 +376,5 @@ end if @index!=oldindex - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() # Cursor index was changed refresh end @@ -1053,6 +1107,4 @@ def Kernel.pbMessageFreeText(message,currenttext,passwordbox,maxlength) msgwindow=Kernel.pbCreateMessageWindow - skinfile=PokemonSkins.getDefaultTextSkin - pbLoadSkin(msgwindow,"Graphics/Windowskins/#{skinfile}") Kernel.pbDisplayMessageFancy(msgwindow,message,-1,0) window=Window_TextEntry_Keyboard.new(currenttext,0,0,240,64) @@ -1162,25 +1214,25 @@ if Input.trigger?(Input::C) index=@sprites["entry2"].index - if index==-3 - Audio.se_play(pbGetDecisionSE) + if index==-3 # Confirm text + pbPlayDecisionSE() ret=@sprites["entry"].text break - elsif index==-1 + elsif index==-1 # Insert a space if @sprites["entry"].insert(" ") - Audio.se_play(pbGetDecisionSE) + pbPlayDecisionSE() else - Audio.se_play("Audio/SE/buzzer.wav") + pbPlayBuzzerSE() end - elsif index==-2 - Audio.se_play(pbGetDecisionSE) + elsif index==-2 # Change character set + pbPlayDecisionSE() @symtype+=1 @symtype=0 if @symtype>=@@Characters.length @sprites["entry2"].setCharset(@@Characters[@symtype][0]) @sprites["entry2"].setOtherCharset(@@Characters[@symtype][1]) - else + else # Insert given character if @sprites["entry"].insert(@sprites["entry2"].character) - Audio.se_play(pbGetDecisionSE) + pbPlayDecisionSE() else - Audio.se_play("Audio/SE/buzzer.wav") + pbPlayBuzzerSE() end end @@ -1521,7 +1573,7 @@ end end - if @cursorpos!=oldcursor + if @cursorpos!=oldcursor # Cursor position changed @sprites["cursor"].setCursorPos(@cursorpos) - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() return true else @@ -1539,13 +1591,14 @@ if Input.trigger?(Input::B) @helper.delete - Audio.se_play(pbGetDecisionSE) + pbPlayCancelSE() pbUpdateOverlay elsif Input.trigger?(Input::C) if @cursorpos==BACK1 || @cursorpos==BACK2 + # Backspace @helper.delete - Audio.se_play(pbGetDecisionSE) + pbPlayCancelSE() pbUpdateOverlay elsif @cursorpos==OK - Audio.se_play(pbGetDecisionSE) + pbPlayDecisionSE() # Done if @helper.length>=@minlength ret=@helper.text @@ -1564,5 +1617,5 @@ @helper.insert(chset[charpos]) @sprites["cursor"].twitch - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() if @helper.length>=@maxlength @cursorpos=OK Changed: SpriteWindow --- Left +++ Right @@ -122,5 +122,5 @@ class AnimatedBitmap def initialize(file,hue=0) - #echoln([file,hue]) + raise "filename is nil" if file==nil if file[/^\[(\d+)\]/] @bitmap=PngAnimatedBitmap.new(file,hue) @@ -162,5 +162,139 @@ end +######################### +module MiniRegistry + HKEY_CLASSES_ROOT = 0x80000000 + HKEY_CURRENT_USER = 0x80000001 + HKEY_LOCAL_MACHINE = 0x80000002 + HKEY_USERS = 0x80000003 + FormatMessageA=Win32API.new("kernel32","FormatMessageA","LPLLPLP","L") + RegOpenKeyExA=Win32API.new("advapi32","RegOpenKeyExA","LPLLP","L") + RegCloseKey=Win32API.new("advapi32","RegCloseKey","L","L") + RegQueryValueExA=Win32API.new("advapi32","RegQueryValueExA","LPLPPP","L") + def self.open(hkey,subkey) + key=0.chr*4 + if RegOpenKeyExA.call(hkey, subkey, 0, 0x20019, key)!=0 + return nil + end + key=key.unpack("V")[0] + if block_given? + begin; yield(key) + ensure; check(RegCloseKey.call(key)); end + else + return key + end + end + def self.close(hkey); check(RegCloseKey.call(hkey)) if hkey; end + def self.get(hkey,subkey,name,defaultValue=nil) + self.open(hkey,subkey){|key| + return self.read(key,name) rescue defaultValue + } + return defaultValue + end + def self.read(hkey,name) + hkey=0 if !hkey + type=0.chr*4; size=0.chr*4 + check(RegQueryValueExA.call(hkey,name,0,type,0,size)) + data=" "*size.unpack("V")[0] + check(RegQueryValueExA.call(hkey,name,0,type,data,size)) + type=type.unpack("V")[0] + data=data[0,size.unpack("V")[0]] + case type + when 1; return data.chop # REG_SZ + when 2; return data.gsub(/%([^%]+)%/) { ENV[$1] || $& } # REG_EXPAND_SZ + when 3; return data # REG_BINARY + when 4; return data.unpack("V")[0] # REG_DWORD + when 5; return data.unpack("V")[0] # REG_DWORD_BIG_ENDIAN + when 11; qw=data.unpack("VV"); return (data[1]<<32|data[0]) # REG_QWORD + else; raise "Type #{type} not supported." + end + end + private + def self.check(code) + if code!=0 + msg="\0"*1024 + len = FormatMessageA.call(0x1200, 0, code, 0, msg, 1024, 0) + raise msg[0, len].tr("\r", '').chomp + end + end +end + +module RTP + @rtpPaths=nil + def self.exists?(filename,extensions=[]) + return false if !filename || filename=="" + eachPath {|path| + return true if FileTest.exist?(path+filename) + for ext in extensions + return true if FileTest.exist?(path+filename+ext) + end + } + return false + end + def self.getPath?(filename,extensions=[]) + return filename if !filename || filename=="" + eachPath {|path| + return path+filename if FileTest.exist?(path+filename) + for ext in extensions + file=path+filename+ext + return file if FileTest.exist?(file) + end + } + return filename + end + def self.eachPath + yield ".\\" + if !@rtpPaths + tmp=Sprite.new + isRgss2=tmp.respond_to?("wave_amp") + tmp.dispose + @rtpPaths=[] + if isRgss2 + rtp=getGameIniValue("Game","RTP") + if rtp!="" + rtp=MiniRegistry.get(MiniRegistry::HKEY_LOCAL_MACHINE, + "SOFTWARE\\Enterbrain\\RGSS2\\RTP",rtp,nil) + if rtp && FileTest.directory?(rtp) + @rtpPaths.push(rtp.sub(/[\/\\]$/,"")+"\\") + end + end + else + %w( RTP1 RTP2 RTP3 ).each{|v| + rtp=getGameIniValue("Game",v) + if rtp!="" + rtp=MiniRegistry.get(MiniRegistry::HKEY_LOCAL_MACHINE, + "SOFTWARE\\Enterbrain\\RGSS\\RTP",rtp,nil) + if rtp && FileTest.directory?(rtp) + @rtpPaths.push(rtp.sub(/[\/\\]$/,"")+"\\") + end + end + } + end + end + @rtpPaths.each{|x| yield x } + end + private + def self.getGameIniValue(section,key) + val = "\0"*256 + gps = Win32API.new('kernel32', 'GetPrivateProfileString',%w(p p p p l p), 'l') + gps.call(section, key, "", val, 256, ".\\Game.ini") + val.delete!("\0") + return val + end +end + +module FileTest + Image_ext = ['.bmp', '.png', '.jpg', '.jpeg', '.gif'] + Audio_ext = ['.mp3', '.mid', '.midi', '.ogg', '.wav', '.wma'] + def self.audio_exist?(filename) + return RTP.exists?(filename,Audio_ext) + end + def self.image_exist?(filename) + return RTP.exists?(filename,Image_ext) + end +end + + ########### @@ -410,15 +544,48 @@ $PokemonSystem.textspeed=speed if $PokemonSystem end -def pbGetDecisionSE +def pbPlayDecisionSE() if $data_system && $data_system.respond_to?("decision_se") && $data_system.decision_se && $data_system.decision_se.name!="" - return "Audio/SE/"+$data_system.decision_se.name + Audio.se_play("Audio/SE/"+$data_system.decision_se.name) elsif $data_system && $data_system.respond_to?("sounds") && - $data_system.sounds[1] && $data_system.sounds[1].name!="" - return "Audio/SE/"+$data_system.sounds[1].name - else - return "Audio/SE/Choose.wav" + $data_system.sounds && $data_system.sounds[1] && $data_system.sounds[1].name!="" + Audio.se_play("Audio/SE/"+$data_system.sounds[1].name) + elsif FileTest.audio_exist?("Audio/SE/Choose") + Audio.se_play("Audio/SE/Choose") end end +def pbPlayCursorSE() + if $data_system && $data_system.respond_to?("cursor_se") && + $data_system.decision_se && $data_system.decision_se.name!="" + Audio.se_play("Audio/SE/"+$data_system.decision_se.name) + elsif $data_system && $data_system.respond_to?("sounds") && + $data_system.sounds && $data_system.sounds[0] && $data_system.sounds[0].name!="" + Audio.se_play("Audio/SE/"+$data_system.sounds[0].name) + elsif FileTest.audio_exist?("Audio/SE/Choose") + Audio.se_play("Audio/SE/Choose") + end +end +def pbPlayCancelSE() + if $data_system && $data_system.respond_to?("cancel_se") && + $data_system.decision_se && $data_system.decision_se.name!="" + Audio.se_play("Audio/SE/"+$data_system.decision_se.name) + elsif $data_system && $data_system.respond_to?("sounds") && + $data_system.sounds && $data_system.sounds[2] && $data_system.sounds[2].name!="" + Audio.se_play("Audio/SE/"+$data_system.sounds[2].name) + elsif FileTest.audio_exist?("Audio/SE/Choose") + Audio.se_play("Audio/SE/Choose") + end +end +def pbPlayBuzzerSE() + if $data_system && $data_system.respond_to?("buzzer_se") && + $data_system.decision_se && $data_system.decision_se.name!="" + Audio.se_play("Audio/SE/"+$data_system.decision_se.name) + elsif $data_system && $data_system.respond_to?("sounds") && + $data_system.sounds && $data_system.sounds[3] && $data_system.sounds[3].name!="" + Audio.se_play("Audio/SE/"+$data_system.sounds[3].name) + elsif FileTest.audio_exist?("Audio/SE/buzzer") + Audio.se_play("Audio/SE/buzzer") + end +end ######################### @@ -714,5 +881,6 @@ def pbTryString(x) - return pbHaveString(x) ? x : nil + ret=pbGetFileChar(x) + return (ret!=nil && ret!="") ? x : nil end @@ -725,11 +893,14 @@ return nil if !x noext=x.gsub(/\.(bmp|png|gif|jpg|jpeg)$/,"") - filename=pbTryString(x) - filename=pbTryString("#{noext}.png") if !filename - filename=pbTryString("#{x}.gif") if !filename - filename=pbTryString("#{noext}.gif") if !filename - filename=pbTryString("#{noext}.jpg") if !filename - filename=pbTryString("#{noext}.jpeg") if !filename - filename=pbTryString("#{noext}.bmp") if !filename + filename=nil + RTP.eachPath{|path| + filename=pbTryString(path+x) if !filename + filename=pbTryString(path+"#{noext}.png") if !filename + filename=pbTryString(path+"#{x}.gif") if !filename + filename=pbTryString(path+"#{noext}.gif") if !filename + filename=pbTryString(path+"#{noext}.jpg") if !filename + filename=pbTryString(path+"#{noext}.jpeg") if !filename + filename=pbTryString(path+"#{noext}.bmp") if !filename + } return filename end @@ -991,8 +1162,11 @@ end +# Used to determine whether a data file exists (rather than a +# graphics or audio file). Doesn't check +# RTP, but does check encrypted archives. def pbRgssExists?(filename) filename=canonicalize(filename) if (FileTest.exist?("./Game.rgssad") || FileTest.exist?("./Game.rgss2a")) - return pbGetFileString(filename)!=nil + return pbGetFileChar(filename)!=nil else return FileTest.exist?(filename) @@ -1000,4 +1174,6 @@ end +# Opens an IO, even if the file is in an encrypted +# archive. Doesn't check RTP for the file. def pbRgssOpen(file,mode=nil) file=canonicalize(file) @@ -1016,5 +1192,6 @@ end - +# Gets at least the first byte of a file. Doesn't check +# RTP, but does check encrypted archives. def pbGetFileChar(file) file=canonicalize(file) @@ -1037,4 +1214,6 @@ end +# Gets the contents of a file. Doesn't check +# RTP, but does check encrypted archives. def pbGetFileString(file) file=canonicalize(file) @@ -1137,4 +1316,17 @@ @_windowskin end + # Flags used to preserve compatibility + # with RGSS/RGSS2's version of Window + module CompatBits + CorrectZ=1 + ExpandBack=2 + ShowScrollArrows=4 + StretchSides=8 + end + attr_reader :compat + def compat=(value) + @compat=value + privRefresh(true) + end def initialize(viewport=nil) @sprites={} @@ -1161,5 +1353,5 @@ @_windowskin=nil @rpgvx=false - @compat=true + @compat=CompatBits::ExpandBack|CompatBits::StretchSides @x=0 @y=0 @@ -1206,5 +1398,4 @@ @sidebitmaps.clear @_windowskin=nil - @_contents=nil @disposed=true end @@ -1552,6 +1743,6 @@ @sprites[i].z=@z end - if @compat && @skinformat==0 - # Compatibility Mode + if (@compat & CompatBits::CorrectZ)>0 && @skinformat==0 && !@rpgvx + # Compatibility Mode: Cursor, pause, and contents have higher Z @sprites["cursor"].z=@z+1 @sprites["contents"].z=@z+2 @@ -1649,7 +1840,6 @@ @sprites["contents"].x=@x+trimStartX @sprites["contents"].y=@y+trimStartY - if @compat && @skinformat==0 - # Compatibility mode -=begin + if (@compat & CompatBits::ShowScrollArrows)>0 && @skinformat==0 + # Compatibility mode: Make scroll arrows visible if @skinformat==0 && @_windowskin && !@_windowskin.disposed? && @contents && !@contents.disposed? @@ -1659,5 +1849,4 @@ @sprites["scroll3"].visible = @visible && (@contents.height - @oy) > @height-trimHeight end -=end end if @_windowskin && !@_windowskin.disposed? @@ -1692,6 +1881,6 @@ @sprites["cursor"].x=@x+startX+@cursor_rect.x @sprites["cursor"].y=@y+startY+@cursor_rect.y - if @compat && @skinformat==0 - # Compatibility mode + if (@compat & CompatBits::ExpandBack)>0 && @skinformat==0 + # Compatibility mode: Expand background @sprites["back"].x=@x+2 @sprites["back"].y=@y+2 @@ -1772,6 +1961,6 @@ @sidebitmaps[i].clear if sideRects[i].width>0 && sideRects[i].height>0 - if @compat && @skinformat==0 - # Compatibility mode + if (@compat & CompatBits::StretchSides)>0 && @skinformat==0 + # Compatibility mode: Stretch sides @sidebitmaps[i].stretch_blt(@sprites["side#{i}"].src_rect, @_windowskin,sideRects[i]) @@ -1782,6 +1971,6 @@ end end - if @compat && @skinformat==0 - # Compatibility mode + if (@compat & CompatBits::ExpandBack)>0 && @skinformat==0 + # Compatibility mode: Expand background backwidth=@width-4 backheight=@height-4 @@ -1862,20 +2051,26 @@ def setSkin(skin) # Sets the bitmap's windowskin. Supports animated images. @customskin.dispose if @customskin - @customskin=AnimatedBitmap.new(skin) - __setWindowskin(@customskin.bitmap) + @customskin=nil + if skin && skin!="" + @customskin=AnimatedBitmap.new(skin) + __setWindowskin(@customskin.bitmap) + end end def setSystemFrame @customskin.dispose if @customskin + @customskin=nil __setWindowskin(@sysframe.bitmap) end def update super - if @customskin && @customskin.totalFrames>1 - @customskin.update - __setWindowskin(@customskin.bitmap) - elsif @sysframe && @sysframe.totalFrames>1 - @sysframe.update - __setWindowskin(@sysframe.bitmap) - end + if self.windowskin + if @customskin && @customskin.totalFrames>1 + @customskin.update + __setWindowskin(@customskin.bitmap) + elsif @sysframe && @sysframe.totalFrames>1 + @sysframe.update + __setWindowskin(@sysframe.bitmap) + end + end if @curframe!=pbGetSystemFrame @curframe=pbGetSystemFrame @@ -1967,5 +2162,5 @@ if (@column_max == 1 and Input.trigger?(Input::DOWN)) or @index < @item_max - @column_max - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() @index = (@index + @column_max) % @item_max update_cursor_rect @@ -1975,5 +2170,5 @@ if (@column_max == 1 and Input.trigger?(Input::UP)) or @index >= @column_max - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() @index = (@index - @column_max + @item_max) % @item_max update_cursor_rect @@ -1982,5 +2177,5 @@ if Input.repeat?(Input::RIGHT) if @column_max >= 2 and @index < @item_max - 1 - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() @index += 1 update_cursor_rect @@ -1989,5 +2184,5 @@ if Input.repeat?(Input::LEFT) if @column_max >= 2 and @index > 0 - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() @index -= 1 update_cursor_rect @@ -1996,5 +2191,5 @@ if Input.repeat?(Input::R) if self.top_row + (self.page_row_max - 1) < (self.row_max - 1) - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() @index = [self.index + self.page_item_max, @item_max - 1].min self.top_row += self.page_row_max @@ -2004,5 +2199,5 @@ if Input.repeat?(Input::L) if self.top_row > 0 - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() @index = [self.index - self.page_item_max, 0].max self.top_row -= self.page_row_max @@ -2908,5 +3103,5 @@ digits=@digits_max+(@sign ? 1 : 0) if Input.repeat?(Input::UP) or Input.repeat?(Input::DOWN) - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() if @index==0 && @sign @negative=!@negative @@ -2925,5 +3120,5 @@ elsif Input.repeat?(Input::RIGHT) if digits >= 2 - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() @index = (@index + 1) % digits refresh @@ -2931,5 +3126,5 @@ elsif Input.repeat?(Input::LEFT) if digits >= 2 - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() @index = (@index + digits - 1) % digits refresh Changed: DrawText --- Left +++ Right @@ -143,5 +143,5 @@ color=RgbToColor(param) shadow=nil - isdark=(color.red+color.green+color.blue)/3 < 128 + isdark=(color.red*0.299+color.green*0.587+color.blue*0.114) < 128 if isdark shadow=Color.new(color.red+64,color.green+64,color.blue+64) @@ -154,5 +154,5 @@ def shadowctagFromColor(color) shadow=nil - isdark=(color.red+color.green+color.blue)/3 < 128 + isdark=(color.red*0.299+color.green*0.587+color.blue*0.114) < 128 if isdark shadow=Color.new(color.red+64,color.green+64,color.blue+64) @@ -397,5 +397,5 @@ trialHalf=half+((leftSearchkeys.length - Audio.se_play("Audio/SE/buzzer.wav") + pbPlayBuzzerSE() penalty=0 time=-1 @@ -445,8 +445,8 @@ if keyState>=0 # Either correct or incorrect if keyState==1 # Correct - Audio.se_play(pbGetDecisionSE) + pbPlayDecisionSE() keystates[blitzCurrent]=1 else # Incorrect - Audio.se_play("Audio/SE/buzzer.wav") + pbPlayBuzzerSE() keystates[blitzCurrent]=2 penalty+=30 Changed: PokemonSave --- Left +++ Right @@ -43,5 +43,5 @@ } end - Kernel.pbMessageBrief(_INTL("Saving...\r\nDon't turn off the power.")) + Kernel.pbMessage(_INTL("Saving...\r\nDon't turn off the power.\\wtnp[0]")) if pbSave Kernel.pbMessageSound(_INTL("The game was saved."),"Audio/SE/save.wav") @@ -112,17 +112,21 @@ Kernel.pbMessage(_INTL("There is a different game file that is already saved.")) Kernel.pbMessage(_INTL("If you save now, the other file's adventure, including items and Pokémon, will be entirely lost.")) - confirm=_INTL("Are you sure you want to save now and overwrite the other save file?") + if !Kernel.pbConfirmMessageSerious( + _INTL("Are you sure you want to save now and overwrite the other save file?")) + @scene.pbEndScreen + return false + end else - confirm=_INTL("There is already a saved file. Is it OK to overwrite it?") + if !Kernel.pbConfirmMessage( + _INTL("There is already a saved file. Is it OK to overwrite it?")) + @scene.pbEndScreen + return false + end end - if !Kernel.pbConfirmMessage(confirm) - @scene.pbEndScreen - return false - end end $PokemonTemp.begunNewGame=false - Kernel.pbMessageBrief(_INTL("Saving...\r\nDon't turn off the power.")) + Kernel.pbMessage(_INTL("Saving...\r\nDon't turn off the power.\\wtnp[0]")) if pbSave - Kernel.pbMessageSound(_INTL("{1} saved the game.",$Trainer.name),"Audio/SE/save.wav") + Kernel.pbMessageSound(_INTL("{1} saved the game.\\se[save]",$Trainer.name),"Audio/SE/save.wav") ret=true else Changed: PokemonNetwork --- Left +++ Right @@ -1265,154 +1265,2 @@ ###################################################### -def pbPostData(url, postdata, filename=nil, depth=0) - if url[/^http:\/\/([^\/]+)(.*)$/] - host=$1 - path=$2 - body = postdata.map {|key, value| - keyString=key.to_s - valueString=value.to_s - keyString.gsub!(/[^a-zA-Z0-9_\.\-]/n) {|s| sprintf('%%%02x', s[0]) } - valueString.gsub!(/[^a-zA-Z0-9_\.\-]/n) {|s| sprintf('%%%02x', s[0]) } - next "#{keyString}=#{valueString}" - }.join('&') - request="POST #{path} HTTP/1.1\nUser-Agent: Ruby Agent\nPragma: no-cache\nHost: #{host}\nProxy-Connection: Close\n" - request+="Content-Type: application/x-www-form-urlencoded\n" - request+="Content-Length: #{body.length}\n" - request+="\n" - request+=body - return pbHttpRequest(host, request, filename, depth) - end -end - -def pbDownloadData(url, filename=nil, depth=0) - if depth>10 - raise "Redirection level too deep" - end - if url[/^http:\/\/([^\/]+)(.*)$/] - host=$1 - path=$2 - request="GET #{path} HTTP/1.1\nUser-Agent: Ruby Agent\nPragma: no-cache\nHost: #{host}\nProxy-Connection: Close\n\n" - return pbHttpRequest(host, request, filename, depth) - end -end - -def pbHttpRequest(host, request, filename=nil, depth=0) - if depth>10 - raise "Redirection level too deep" - end - socket=::TCPSocket.new(host, 80) - time=Time.now.to_i - begin - socket.send(request) - result=socket.gets - data="" - # Get the HTTP result - if result[/^HTTP\/1\.[01] (\d+).*/] - errorcode=$1.to_i - if errorcode>=400 && errorcode<500 - raise "HTTP Error #{errorcode}" - end - headers={} - # Get the response headers - while true - result=socket.gets.sub(/\r$/,"") - break if result=="" - if result[/^([^:]+):\s*(.*)/] - headers[$1]=$2 - end - end - length=-1 - chunked=false - if headers["Content-Length"] - length=headers["Content-Length"].to_i - end - if headers["Transfer-Encoding"]=="chunked" - chunked=true - end - if headers["Location"] && errorcode >= 300 && errorcode < 400 - socket.close rescue socket=nil - return pbDownloadData(headers["Location"],filename,depth+1) - end - if chunked==true - # Chunked content - while true - lengthline=socket.gets.sub(/\r$/,"") - length=lengthline.to_i(16) - break if length==0 - while Time.now.to_i-time>=5 || socket.select(10)==0 - time=Time.now.to_i - Graphics.update - end - data+=socket.recv(length) - socket.gets - end - elsif length==-1 - # No content length specified - while true - if socket.select(500)==0 - break - else - while Time.now.to_i-time>=5 || socket.select(10)==0 - time=Time.now.to_i - Graphics.update - end - data+=socket.recv(1) - end - end - else - # Content length specified - while length>0 - chunk=[length,4096].min - while Time.now.to_i-time>=5 || socket.select(10)==0 - time=Time.now.to_i - Graphics.update - end - data+=socket.recv(chunk) - length-=chunk - end - end - end - if filename - File.open(filename,"wb"){|f| - f.write(data) - } - else - return data - end - ensure - socket.close rescue socket=nil - end - return "" -end - -def pbDownloadToString(url) - begin - data=pbDownloadData(url) - return data - rescue - return "" - end -end - -def pbDownloadToFile(url, file) - begin - pbDownloadData(url,file) - rescue - end -end - -def pbPostToString(url, postdata) - begin - data=pbPostData(url, postdata) - return data - rescue - return "" - end -end - -def pbPostToFile(url, postdata, file) - begin - pbPostData(url, postdata,file) - rescue - end -end Changed: PokemonUtilities --- Left +++ Right @@ -1,3 +1,9 @@ +################################## +# +# General purpose utilities +# +################################## + module PBDayNight Shades=[ @@ -22,24 +28,86 @@ Tone.new(0,0,0,0) ] + @hourlyTones=nil + @getGeoInfo=nil + @realLatLong=nil + @gettingRealLatLong=nil + def self.hourlyTones; @hourlyTones; end + def self.hourlyTones=(value); @hourlyTones=value; end + def self.getLatLong + x=nil + b=false + if @getGeoInfo==nil + @getGeoInfo=Win32API.new("kernel32","GetGeoInfoA","llpll","i") rescue false + @getUserGeoID=Win32API.new("kernel32","GetUserGeoID","i","i") rescue false + end + Thread.critical=true; begin + x=@realLatLong + b=@gettingRealLatLong;@gettingRealLatLong=true if !x + ensure; Thread.critical=false; end + if !x + # Use an approximation instead + x=[-42*Math::PI/180, + (Time.now.gmt_offset/3600.0*15)*Math::PI/180] + if @getGeoInfo + geoid=@getUserGeoID.call(16) # get national ID + if geoid>0 + lat="\0"*16 + retval=@getGeoInfo.call(geoid,2,lat,16,0) # get latitude + lat=lat.sub(/\0.*$/,"") + if retval!=0 && lat.length>0 + # replace latitude + x[0]=-lat.to_f*Math::PI/180 + end + lon="\0"*16 + retval=@getGeoInfo.call(geoid,3,lon,16,0) # get longitude + lon=lon.sub(/\0.*$/,"") + if retval!=0 && lon.length>0 + rads=rads.to_f*Math::PI/180 + deg15=0.261799387799149 + if (rads-x[1]).abs<=deg15 && + (rads+Math::PI*2-x[1]).abs<=deg15 + # replace longitude if given longitude is up to 15 + # degrees away from longitude derived from time zone + x[1]=rads + end + end + end + end + # Record approximation + Thread.critical; begin + @realLatLong=x + ensure; Thread.critical=false; end + if !b + # Run a thread that calls the Internet + Thread.new { + Thread.stop + # Geocode the current user via the internet (requires script "Sockets") + data="" + if Kernel.respond_to?("pbDownloadToString") + data=pbDownloadToString("http://api.hostip.info/rough.php?position=true") + end + lat=200;lon=200 + 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 + end + if lat!=200 && lon!=200 + Thread.critical=true; begin + @realLatLong=[lat,lon] + ensure; Thread.critical=false; end + end + }.run + end + end + return x + end end -# Similar to pbFadeOutIn, but pauses the music -# as it fades out. -def pbFadeOutInWithMusic(zViewport) - playingBGS=$game_system.getPlayingBGS - playingBGM=$game_system.getPlayingBGM - $game_system.bgm_pause(1.0) - $game_system.bgs_pause(1.0) - pos=$game_system.bgm_position - pbFadeOutIn(zViewport) { - yield - $game_system.bgm_position=pos - $game_system.bgm_resume(playingBGM) - $game_system.bgs_resume(playingBGS) - } -end - -def getShade(lat,lon,sunPos) # all coordinates in radians +# Internal function +def getShade(currentPos,sunPos) # all coordinates in radians # 0 = full night; 255 = full day + lat=currentPos[0]; lon=currentPos[1] vec=[Math.sin(lon)*Math.cos(lat),Math.sin(lat),Math.cos(lon)*Math.cos(lat)] lat=sunPos[0]; lon=sunPos[1] @@ -55,4 +123,5 @@ end +# Internal function def getSunCoords(time) d=(2440586.5+time.to_i/86400.0)-2447891.5 @@ -82,9 +151,5 @@ ] end - -class PokemonTemp - attr_accessor :hourlyTones -end - +# Internal function def pbShadeToTone(shade) part=shade%16 @@ -99,15 +164,16 @@ def pbGetDayNightShade() + # Returns a value from 0 through 255 + # 0 = full night; 255 = full day sun=getSunCoords(Time.now) - return getShade( - -42*Math::PI/180, - ((Time.now.gmt_offset/3600)*15)*Math::PI/180,sun) + return getShade(PBDayNight.getLatLong(),sun) end def pbSetDayNightTone(toneToSet) - return if !$PokemonTemp + # Calculates the tone for the current frame, used + # for day/night effects now=Time.now - if (!$PokemonTemp.hourlyTones || (Graphics.frame_count%5000)==0) - $PokemonTemp.hourlyTones=[] + if (!PBDayNight.hourlyTones || (Graphics.frame_count%5000)==0) + PBDayNight.hourlyTones=[] day=0 # Get just the day @@ -122,14 +188,12 @@ for i in 0...24 sun=getSunCoords(Time.at(day+i*3600)) - shade=getShade( - -42*Math::PI/180, - ((now.gmt_offset/3600)*15)*Math::PI/180,sun) - $PokemonTemp.hourlyTones[i]=pbShadeToTone(shade) + shade=getShade(PBDayNight.getLatLong(),sun) + PBDayNight.hourlyTones[i]=pbShadeToTone(shade) end end hour=now.hour minute=now.min - tone=$PokemonTemp.hourlyTones[hour] - nexthourtone=$PokemonTemp.hourlyTones[(hour+1)%24] + tone=PBDayNight.hourlyTones[hour] + nexthourtone=PBDayNight.hourlyTones[(hour+1)%24] # Calculate current tint according to current and next hour's tint and # depending on current minute @@ -140,5 +204,90 @@ end +############################# + +#Modified by Wichu, adapted by Peter O. +def getRandomNameEx(type,variable,upper,*formats) +if formats.length==0 + case type + when 0 + formats=%w( 1423 2341 23441 14235 1415 14141 142314 41423 4141 42341 ) + when 1 + formats=%w( 1416 14416 141416 23416 41416 423416 414236 14236 1414236 14146 ) + when 2 + formats=%w( cvcvvc cvvcvc cvcvcv vcvvc cvcv cvvc cvcv cvve bvc bve cve bvvc bvcv bvcvc) + end +end +format=formats[rand(formats.length)] +name="" +format.scan(/./) {|c| + case c + when "c" + set=%w( b c d f g h j k l l m n n p r r s s t t v w x z ) + name+=set[rand(set.length)] + when "v" + set=%w( a a a e e e i i i o o o u u u y ) + name+=set[rand(set.length)] + when "b" # two-letter "blends" + set=%w( br bl ch cl cr dr fr fl gh gl gr ph pl pr sc sh sk sl + sm sn sp st sw th tr tw wh wr ) + name+=set[rand(set.length)] + when "e" # two-letter "blends" at end + set=%w( ck ch dd ff bb gg gh ld ll mm nd nt ng ph pt ps sk sh sp ss st rd + rn rp rm rk ns bs ft ) + name+=set[rand(set.length)] + when "1" + set=%w( b c d f g h j k l m n p q r s t v w x z ) + name+=set[rand(set.length)] + when "2" + set=%w( c f g k l p r s t ) + name+=set[rand(set.length)] + when "3" + set=%w( h k l s t ) + name+=set[rand(set.length)] + when "4" + set=%w( a e i o u ) + name+=set[rand(set.length)] + when "5" + set=%w( e e o o o u u ) + name+=set[rand(set.length)] + when "6" + set=%w( a a a i i i e ) + name+=set[rand(set.length)] + end +} +case upper + when 0 + name=name.upcase + when 1 + name[0,1]=name[0,1].upcase +end +$game_variables[variable]=name if variable +return name +end + +def getRandomName(*formats) + return getRandomNameEx(2,nil,nil,formats) +end + +def pbStringToAudioFile(str) + # Converts a string to an audio file. Possible formats: + # filename volume and pitch 100 + # filename:volume pitch 100 + # filename:volume:pitch + if str[/^(.*)\:\s*(\d+)\s*\:\s*(\d+)\s*$/] + file=$1 + volume=$2.to_i + pitch=$3.to_i + return RPG::AudioFile.new(file,volume,pitch) + elsif str[/^(.*)\:\s*(\d+)\s*$/] + file=$1 + volume=$2.to_i + return RPG::AudioFile.new(file,volume,100) + else + return RPG::AudioFile.new(str,100,100) + end +end + def pbIsWeekday(wdayVariable,*arg) wday=Time.now.wday @@ -161,19 +310,4 @@ end -def printException(e) - s="" - e.backtrace.each do |i| - s=s+"#{i}\r\n" - end - s.gsub!(/Section(\d+)/){$RGSS_SCRIPTS[$1.to_i][1]} - print(s) - if "#{e.class}"=="Reset" || e.is_a?(SystemExit) - raise e - end - if !printRetry("#{e.message}\r\n#{s}") - return - end -end - def isConst?(val,mod,constant) begin @@ -194,4 +328,243 @@ end +module ItemStorageHelper + # Implements methods that act on arrays of items. Each element + # in an item array is itself an array of [itemID, itemCount] + # Determines the quantity of an item from item array, maximum size per slot, and item ID + def self.pbQuantity(items,maxsize,item) + ret=0 + for i in 0...maxsize + itemslot=items[i] + if itemslot && itemslot[0]==item + ret+=itemslot[1] + end + end + return ret + end + # Deletes an item from item array, maximum size per slot, item, and number of items to delete + def self.pbDeleteItem(items,maxsize,item,qty) + raise "Invalid value for qty: #{qty}" if qty<0 + return true if qty==0 + ret=false + for i in 0...maxsize + itemslot=items[i] + if itemslot && itemslot[0]==item + amount=[qty,itemslot[1]].min + itemslot[1]-=amount + qty-=amount + items[i]=nil if itemslot[1]==0 + if qty==0 + ret=true + break + end + end + end + items.compact! + return ret + end + def self.pbCanStore?(items,maxsize,maxPerSlot,item,qty) + raise "Invalid value for qty: #{qty}" if qty<0 + return true if qty==0 + for i in 0...maxsize + itemslot=items[i] + if !itemslot + qty-=[qty,maxPerSlot].min + return true if qty==0 + elsif itemslot[0]==item && itemslot[1]127 - if vol>=16 - volume+=vol - count+=1 - end - i+=distance - end - return 0 if count==0 - return volume/count # from 0 through 127 - end - def time - return @freq==0 ? 0.0 : (@samples.length)*1.0/@freq - end - def play - return if @samples.length==0 - data=[ - 0x46464952,@samples.length+0x2C, - 0x45564157,0x20746d66,0x10, - 0x01,0x01, # PCM,mono - @freq,@freq, - 1,8, # 8-bit - 0x61746164,@samples.length - ].pack("VVVVVvvVVvvVV") - f=openTemp("wav","wb") - if f - path=f.path - f.write(data) - f.write(@samples) - f.close - Audio.se_play(path) - pbDelayedDelete(path) - end - end -end - -# Creates wave data from the given WAV file path -def getWaveData(filename) - time=-1 - if !FileTest.exist?(filename) - return 1 # Not found - end - File.open(filename,"rb"){|file| - file.pos=0 - fdw=file.fgetdw - if fdw==0x46464952 # "RIFF" - filesize=file.fgetdw - wave=file.fgetdw - if wave!=0x45564157 # "WAVE" - return 2 - end - fmt=file.fgetdw - if fmt!=0x20746d66 # "fmt " - return 2 - end - fmtsize=file.fgetdw - format=file.fgetw - if format!=1 - return 3 # unsupported - end - channels=file.fgetw # channels (1 or 2) - if channels!=1 - return 3 # unsupported - end - rate=file.fgetdw # samples per second - bytessec=file.fgetdw # avg bytes per second - if bytessec==0 - return 2 - end - bytessample=file.fgetw # bytes per sample - bitssample=file.fgetw # bits per sample (8, 16, etc.) - if bitssample!=8 && bitssample!=16 - return 3 # unsupported - end - data=file.fgetdw - if data!=0x61746164 # "data" - return 2 - end - datasize=file.fgetdw - data=file.read(datasize) - samples=nil - if bitssample==8 - samples=data.unpack("C*") - start=0 - for i in 0...samples.length - s=samples[i] - if s<0x70 || s>=0x90 - start=i - break - end - end - finish=start - i=samples.length-1 - while i>=start - s=samples[i] - if s<0x70 || s>=0x90 - finish=i+1 - break - end - i-=1 - end - if finish==start - return 4 # Nothing was recorded - end - start=0 - finish=samples.length - wave=WaveData.new(rate,samples[start,finish-start]) - return wave - elsif bitssample==16 - samples=data.unpack("v*") - start=0 - for i in 0...samples.length - s=samples[i] - if s>0x1000 && s<0xF000 - start=i - break - end - end - finish=start - i=samples.length-1 - while i>=start - s=samples[i] - if s<0x1000 && s<0xF000 - finish=i+1 - break - end - i-=1 - end - if finish==start - return 4 # Nothing was recorded - end - start=0 - # Convert to 8-bit samples - for i in start...finish - samples[i]=((samples[i]-0x8000)>>8)&0xFF - end - finish=samples.length - return WaveData.new(rate,samples[start,finish-start]) - end - end - } - return 2 -end - -def getWaveDataUI(filename,deleteFile=false) - error=getWaveData(filename) - if deleteFile - begin - File.delete(filename) - rescue Errno::EINVAL, Errno::EACCES, Errno::ENOENT - end - end - if error==1 - Kernel.pbMessage(_INTL("The recorded data could not be found or saved.")) - elsif error==2 - Kernel.pbMessage(_INTL("The recorded data was in an invalid format.")) - elsif error==3 - Kernel.pbMessage(_INTL("The recorded data's format is not supported.")) - elsif error==4 - Kernel.pbMessage(_INTL("There was no sound in the recording. Please ensure that a microphone is attached to the computer and is ready.")) - else - return error - end - return nil -end - -MciSendString = Win32API.new('winmm','mciSendString','%w(p,p,l,l)','l') -MciErrorString = Win32API.new('winmm','mciGetErrorString','%w(l,p,l)','l') - -# Starts recording. Returns 0 if successful. -def beginRecord - MciSendString.call("open new type waveaudio alias RECORDER buffer 4",0,0,0) - MciSendString.call("set RECORDER channels 1",0,0,0) - retval=MciSendString.call("record RECORDER",0,0,0) - if retval!=0 - MciSendString.call("close RECORDER",0,0,0) - end - return retval -end - -# Starts recording, and displays a message if the -# recording failed to start. Returns true if -# successful, false otherwise -def beginRecordUI - code=beginRecord - case code - when 0; return true - when 256+66 - Kernel.pbMessage(_INTL("All recording devices are in use. Recording is not possible now.")) - return false - when 256+72 - Kernel.pbMessage(_INTL("No supported recording device was found. Recording is not possible.")) - return false - else - buffer="\0"*256 - MciErrorString.call(code,buffer,256) - Kernel.pbMessage(_INTL("Recording failed: {1}",buffer.gsub(/\x00/,""))) - return false - end -end - -# Gets a single sample from the microphone. -# The beginRecord or beginRecordUI function -# must have been called beforehand. -def getRecorderSample - buffer="\0"*256 - ret=0 - MciSendString.call("stop RECORDER",0,0,0) - MciSendString.call("status RECORDER bitspersample",buffer,256,0) - bitspersample=buffer.to_i - MciSendString.call("status RECORDER level",buffer,256,0) - MciSendString.call("record RECORDER",0,0,0) - if bitspersample==8 - ret=buffer.to_i<<8 # max 128 - else - ret=buffer.to_i # max 0x8000 - end - return ret -end - -def stopRecord() - MciSendString.call("stop RECORDER",0,0,0) - MciSendString.call("close RECORDER",0,0,0) -end - -def endRecord(file) - MciSendString.call("stop RECORDER",0,0,0) - if file && file!="" - MciSendString.call("save RECORDER #{file}",0,0,0) - end - MciSendString.call("close RECORDER",0,0,0) -end - class PokemonGlobalMetadata attr_accessor :trainerRecording @@ -1588,88 +1437,2 @@ end - - -=begin -module PBDayNight - # Screen tints for each hour of the day. - HourlyTones=[ - Tone.new(-142.5,-142.5,-22.5,68), - Tone.new(-135.5,-135.5,-24,68), - Tone.new(-127.5,-127.5,-25.5,68), - Tone.new(-127.5,-127.5,-25.5,68), - Tone.new(-119,-96.3,-45.3,45.3), - Tone.new(-51,-73.7,-73.7,22.7), - Tone.new(17,-51,-102,0), - Tone.new(14.2,-42.5,-85,0), - Tone.new(11.3,-34,-68,0), - Tone.new(8.5,-25.5,-51,0), - Tone.new(5.7,-17,-34,0), - Tone.new(2.8,-8.5,-17,0), - Tone.new(0,0,0,0), - Tone.new(0,0,0,0), - Tone.new(0,0,0,0), - Tone.new(0,0,0,0), - Tone.new(-3,-7,-2,0), - Tone.new(-10,-18,-5,0), - Tone.new(-36,-75,-13,0), - Tone.new(-72,-136,-34,3), - Tone.new(-88.5,-133,-31,34), - Tone.new(-108.5,-129,-28,68), - Tone.new(-127.5,-127.5,-25.5,68), - Tone.new(-142.5,-142.5,-22.5,68) - ] - # Adjustments to the clock in summer - SummerAdjustment=[ - 0, 1.25, 2.75, 4, 5, 6, - 7, 8, 9, 9.75, 10.5, 11.25, - 12, 12,75, 13.25, 14, 15, 16, - 17, 18, 19.5, 21, 22.5, 23.5] - # Adjustments to the clock in winter - WinterAdjustment=[ - 0, 0.5, 1, 1.5, 2, 3.5, - 5, 6.5, 7.5, 9, 10, 11, - 12, 14, 16, 18.5, 19.5, 20.75, - 21.5, 22, 22.25, 22.75, 23.25, 23.75] - # Proportion of the summer adjustment to apply for each month - SummerMultiplier=[0.0, 0.1, 0.2, 0.5, 0.7, 0.8, 1.0, 0.95, 0.8, 0.5, 0.2, 0.05] - # Proportion of the winter adjustment to apply for each month - WinterMultiplier= [1.0, 0.9, 0.8, 0.5, 0.3, 0.2, 0.0, 0.05, 0.2, 0.5, 0.8, 0.95] -end -def pbGetDayNightMinutes - now=Time.now # Get the current system time - hour=now.hour - minute=now.min - month=now.mon-1 - nextMonth=(month+1)%12 - nextHour=hour==0 ? 23 : hour-1 - dayPosition=month==1 ? ([28,now.mday].min-1)/28.0 : ([30,now.mday].min-1)/30.0 - summerMult=PBDayNight::SummerMultiplier[month]*1.0; - summerMult+=(PBDayNight::SummerMultiplier[nextMonth]-PBDayNight::SummerMultiplier[month])*dayPosition - winterMult=PBDayNight::WinterMultiplier[month]*1.0; - winterMult+=(PBDayNight::WinterMultiplier[nextMonth]-PBDayNight::WinterMultiplier[month])*dayPosition - realHour=PBDayNight::SummerAdjustment[hour]*summerMult+ - PBDayNight::WinterAdjustment[hour]*winterMult - realNextHour=PBDayNight::SummerAdjustment[nextHour]*summerMult+ - PBDayNight::WinterAdjustment[nextHour]*winterMult - realMinutes=realHour+((realNextHour-realHour)*(minute/60.0)) - realMinutes=((realMinutes*60).to_i)%(60*24) - realMinutes=0 if realMinutes<0 - realMinutes=3599 if realMinutes>3599 - return realMinutes -end - -def pbSetDayNightTone(toneToSet) - # Gets the time of day in minutes that the current time "feels like" - realMinutes=pbGetDayNightMinutes() - hour=realMinutes/60 - minute=realMinutes%60 - tone=PBDayNight::HourlyTones[hour] - nexthourtone=PBDayNight::HourlyTones[(hour+1)%24] - # Calculate current tint according to current and next hour's tint and - # depending on current minute - toneToSet.red = ((nexthourtone.red-tone.red)*minute/60.0)+tone.red - toneToSet.green = ((nexthourtone.green-tone.green)*minute/60.0)+tone.green - toneToSet.blue = ((nexthourtone.blue-tone.blue)*minute/60.0)+tone.blue - toneToSet.gray = ((nexthourtone.gray-tone.gray)*minute/60.0)+tone.gray -end -=end Changed: PokeBattle_Battle --- Left +++ Right @@ -941,5 +941,4 @@ def pbRegisterMove(idxPokemon,idxMove) thispkmn=@battlers[idxPokemon] -# printRetry("pbRegisterMove #{idxPokemon} #{idxMove}") thismove=thispkmn.moves[idxMove] if !pbCanChooseMove?(idxPokemon,idxMove,1) Changed: PokemonItems --- Left +++ Right @@ -19,5 +19,5 @@ window.y=0 window.x=480-window.width - Audio.se_play(pbGetDecisionSE) + pbPlayDecisionSE() loop do Graphics.update @@ -126,4 +126,32 @@ end + +def pbItemRestoreHP(pokemon,restorehp) + newhp=pokemon.hp+restorehp + newhp=pokemon.totalhp if newhp>pokemon.totalhp + hpgain=newhp-pokemon.hp + pokemon.hp=newhp + return hpgain +end + +def pbSpeciesCompatible?(species,move) + ret=false + return false if species<=0 + data=load_data("Data/tm.dat") + return false if !data[move] + return data[move].any? {|item| item==species } +end + +def pbForgetMove(pokemon,moveToLearn) + ret=-1 + pbFadeOutIn(99999){ + scene=PokemonSummaryScene.new + screen=PokemonSummary.new(scene) + ret=screen.pbStartForgetScreen([pokemon],0,moveToLearn) + } + return ret +end + + def pbRaiseEffortValues(pokemon,ev,evgain=10,evlimit=true) if pokemon.ev[ev]>=100 && evlimit @@ -403,5 +431,5 @@ pbUpdateSceneMap end - Kernel.pbMessage(_INTL("Oh! The Itemfinder's shaking wildly!")) + Kernel.pbMessage(_INTL("Oh! The Itemfinder's shaking wildly!\1")) Kernel.pbMessage(_INTL("There's an item buried underfoot!")) else @@ -423,5 +451,5 @@ pbUpdateSceneMap end - Kernel.pbMessage(_INTL("Oh! The Itemfinder's responding!")) + Kernel.pbMessage(_INTL("Oh! The Itemfinder's responding!\1")) Kernel.pbMessage(_INTL("There's an item buried around here!")) end @@ -435,42 +463,4 @@ -def pbItemRestoreHP(pokemon,restorehp) - newhp=pokemon.hp+restorehp - newhp=pokemon.totalhp if newhp>pokemon.totalhp - hpgain=newhp-pokemon.hp - pokemon.hp=newhp - return hpgain -end - -def pbSpeciesCompatibleOld?(species,machine) - ret=false - return false if species<=0 - pbRgssOpen("Data/tmRS.dat","rb"){|f| - f.pos=(species-1)*8 - f.pos+=machine>>3 - ret=(f.fgetb&(1<<(machine&0x07)))!=0 - } - return ret -end - - -def pbSpeciesCompatible?(species,move) - ret=false - return false if species<=0 - data=load_data("Data/tm.dat") - return false if !data[move] - return data[move].any? {|item| item==species } -end - -def pbForgetMove(pokemon,moveToLearn) - ret=-1 - pbFadeOutIn(99999){ - scene=PokemonSummaryScene.new - screen=PokemonSummary.new(scene) - ret=screen.pbStartForgetScreen([pokemon],0,moveToLearn) - } - return ret -end - def pbMachineAnnotations(move) ret=[] @@ -501,15 +491,15 @@ for i in 0..3 if pokemon.moves[i].id==move - Kernel.pbMessage(_INTL("{1} already knows {2}.",pkmnname,movename)) if !ignoreifknown + Kernel.pbMessage(_INTL("{1} already knows\r\n{2}.",pkmnname,movename)) if !ignoreifknown return false end if pokemon.moves[i].id==0 pokemon.moves[i]=PBMove.new(move) - Kernel.pbMessage(_INTL("{1} learned {2}!",pkmnname,movename)) + Kernel.pbMessage(_INTL("{1} learned\r\n{2}!\\se[itemlevel]",pkmnname,movename)) return true end end loop do - Kernel.pbMessage(_INTL("{1} wants to learn {2}.\1",pkmnname,movename)) + Kernel.pbMessage(_INTL("{1} wants to learn\r\n{2}.\1",pkmnname,movename)) Kernel.pbMessage(_INTL("But {1} already knows four moves.\1",pkmnname)) if Kernel.pbConfirmMessage(_INTL("Delete a move to make room for {1}?",movename)) @@ -519,9 +509,9 @@ oldmovename=PBMoves.getName(pokemon.moves[forgetmove].id) pokemon.moves[forgetmove]=PBMove.new(move)#Replaces current/total PP - Kernel.pbMessage(_INTL("1, 2, and... ... ...\1")) - Kernel.pbMessage(_INTL("Poof!\1")) - Kernel.pbMessage(_INTL("{1} forgot {2}.\1",pkmnname,oldmovename)) + Kernel.pbMessage(_INTL("\\se[]1, 2 and...\\wt[20] ...\\wt[20] ...\\wtnp[20]")) + Kernel.pbMessage(_INTL("\\se[]Poof!\\se[balldrop]\1")) + Kernel.pbMessage(_INTL("{1} forgot\r\n{2}.\1",pkmnname,oldmovename)) Kernel.pbMessage(_INTL("And...\1")) - Kernel.pbMessage(_INTL("{1} learned {2}!",pkmnname,movename)) + Kernel.pbMessage(_INTL("\\se[]{1} learned\r\n{2}!\\se[itemlevel]",pkmnname,movename)) return true elsif Kernel.pbConfirmMessage(_INTL("Should {1} stop learning {2}?",pkmnname,movename)) Changed: PokemonScreen --- Left +++ Right @@ -583,5 +583,4 @@ helpwindow=@sprites["helpwindow"] helpwindow.visible=true - Audio.se_play(pbGetDecisionSE) using(cmdwindow=Window_CommandPokemon.new(commands)) { cmdwindow.z=@viewport.z+1 @@ -597,9 +596,10 @@ self.update if Input.trigger?(Input::B) + pbPlayCancelSE() ret=-1 break end if Input.trigger?(Input::C) - Audio.se_play(pbGetDecisionSE) + pbPlayDecisionSE() ret=cmdwindow.index break @@ -777,6 +777,6 @@ @activecmd=pbChangeSelection(key,@activecmd) end - if @activecmd!=oldsel - Audio.se_play(pbGetDecisionSE) + if @activecmd!=oldsel # Changing selection + pbPlayCursorSE() numsprites=(@multiselect) ? 8 : 7 for i in 0...numsprites @@ -788,4 +788,5 @@ end if Input.trigger?(Input::C) + pbPlayDecisionSE() cancelsprite=(@multiselect) ? 7 : 6 return (@activecmd==cancelsprite) ? -1 : @activecmd @@ -806,5 +807,5 @@ @sprites["messagebox"].visible=true @sprites["helpwindow"].visible=false - Audio.se_play(pbGetDecisionSE) + pbPlayDecisionSE() loop do Graphics.update @@ -812,5 +813,5 @@ self.update if @sprites["messagebox"].busy? && Input.trigger?(Input::C) - Audio.se_play(pbGetDecisionSE) if @sprites["messagebox"].pausing? + pbPlayDecisionSE() if @sprites["messagebox"].pausing? @sprites["messagebox"].resume end Changed: PokemonStorage --- Left +++ Right @@ -1498,5 +1498,5 @@ key=Input::UP if Input.repeat?(Input::UP) if key>=0 - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() newselection=pbPartyChangeSelection(key,selection) if newselection==-1 @@ -1683,5 +1683,5 @@ key=Input::UP if Input.repeat?(Input::UP) if key>=0 - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() selection=pbChangeSelection(key,selection) pbSetArrow(@sprites["arrow"],selection) Changed: Sockets --- Left +++ Right @@ -1,14 +1,9 @@ module Win32 - - #-------------------------------------------------------------------------- - # ● Retrieves data from a pointer. - #-------------------------------------------------------------------------- def copymem(len) buf = "\0" * len Win32API.new("kernel32", "RtlMoveMemory", "ppl", "").call(buf, self, len) buf - end - + end end @@ -191,5 +186,5 @@ #-------------------------------------------------------------------------- - # ● Constants + # * Constants #-------------------------------------------------------------------------- AF_UNSPEC = 0 @@ -273,5 +268,4 @@ EAI_PROTOCOL = 13 EAI_MAX = 14 - AI_PASSIVE = 1 AI_CANONNAME = 2 @@ -283,7 +277,6 @@ AI_DEFAULT = 1536 AI_V4MAPPED = 2048 - #-------------------------------------------------------------------------- - # ● Returns the associated IP address for the given hostname. + # * Returns the associated IP address for the given hostname. #-------------------------------------------------------------------------- def self.getaddress(host) @@ -292,5 +285,5 @@ #-------------------------------------------------------------------------- - # ● Returns the associated IP address for the given hostname. + # * Returns the associated IP address for the given hostname. #-------------------------------------------------------------------------- def self.getservice(serv) @@ -306,5 +299,5 @@ #-------------------------------------------------------------------------- - # ● Returns information about the given hostname. + # * Returns information about the given hostname. #-------------------------------------------------------------------------- def self.gethostbyname(name) @@ -315,5 +308,5 @@ #-------------------------------------------------------------------------- - # ● Returns the user's hostname. + # * Returns the user's hostname. #-------------------------------------------------------------------------- def self.gethostname @@ -324,5 +317,5 @@ #-------------------------------------------------------------------------- - # ● Returns information about the given service. + # * Returns information about the given service. #-------------------------------------------------------------------------- def self.getservbyname(name) @@ -345,11 +338,11 @@ return 110 else - Network.testing? != 0 ? (Network.testresult(true)) : (raise "Service not recognized.") - return if Network.testing? == 2 + #Network.testing? != 0 ? (Network.testresult(true)) : (raise "Service not recognized.") + #return if Network.testing? == 2 end end #-------------------------------------------------------------------------- - # ● Creates an INET-sockaddr struct. + # * Creates an INET-sockaddr struct. #-------------------------------------------------------------------------- def self.sockaddr_in(port, host) @@ -357,14 +350,14 @@ [AF_INET, getservice(port)].pack("sn") + gethostbyname(host)[3] + [].pack("x8") rescue - Network.testing? != 0 ? (Network.testresult(true)): (nil) - return if Network.testing? == 2 + #Network.testing? != 0 ? (Network.testresult(true)): (nil) + #return if Network.testing? == 2 rescue Hangup - Network.testing? != 0 ? (Network.testresult(true)): (nil) - return if Network.testing? == 2 + #Network.testing? != 0 ? (Network.testresult(true)): (nil) + #return if Network.testing? == 2 end end #-------------------------------------------------------------------------- - # ● Creates a new socket and connects it to the given host and port. + # * Creates a new socket and connects it to the given host and port. #-------------------------------------------------------------------------- def self.open(*args) @@ -381,5 +374,5 @@ #-------------------------------------------------------------------------- - # ● Creates a new socket. + # * Creates a new socket. #-------------------------------------------------------------------------- def initialize(domain, type, protocol) @@ -389,5 +382,5 @@ #-------------------------------------------------------------------------- - # ● Accepts incoming connections. + # * Accepts incoming connections. #-------------------------------------------------------------------------- def accept(flags = 0) @@ -398,5 +391,5 @@ #-------------------------------------------------------------------------- - # ● Binds a socket to the given sockaddr. + # * Binds a socket to the given sockaddr. #-------------------------------------------------------------------------- def bind(sockaddr) @@ -406,5 +399,5 @@ #-------------------------------------------------------------------------- - # ● Closes a socket. + # * Closes a socket. #-------------------------------------------------------------------------- def close @@ -414,8 +407,8 @@ #-------------------------------------------------------------------------- - # ● Connects a socket to the given sockaddr. + # * Connects a socket to the given sockaddr. #-------------------------------------------------------------------------- def connect(sockaddr) - return if Network.testing? == 2 + #return if Network.testing? == 2 SocketError.check if (ret = Winsock.connect(@fd, sockaddr, sockaddr.size)) == -1 ret @@ -423,5 +416,5 @@ #-------------------------------------------------------------------------- - # ● Listens for incoming connections. + # * Listens for incoming connections. #-------------------------------------------------------------------------- def listen(backlog) @@ -431,13 +424,14 @@ #-------------------------------------------------------------------------- - # ● Checks waiting data's status. + # * Checks waiting data's status. #-------------------------------------------------------------------------- - def select(timeout) - SocketError.check if (ret = Winsock.select(1, [1, @fd].pack("ll"), 0, 0, [timeout, timeout * 1000000].pack("ll"))) == -1 + def select(timeout) # timeout in seconds + SocketError.check if (ret = Winsock.select(1, [1, @fd].pack("ll"), 0, 0, [timeout.to_i, + (timeout * 1000000).to_i].pack("ll"))) == -1 ret end #-------------------------------------------------------------------------- - # ● Checks if data is waiting. + # * Checks if data is waiting. #-------------------------------------------------------------------------- def ready? @@ -446,5 +440,5 @@ #-------------------------------------------------------------------------- - # ● Reads data from socket. + # * Reads data from socket. #-------------------------------------------------------------------------- def read(len) @@ -455,5 +449,5 @@ #-------------------------------------------------------------------------- - # ● Returns received data. + # * Returns received data. #-------------------------------------------------------------------------- def recv(len, flags = 0) @@ -472,5 +466,5 @@ #-------------------------------------------------------------------------- - # ● Sends data to a host. + # * Sends data to a host. #-------------------------------------------------------------------------- def send(data, flags = 0) @@ -497,5 +491,5 @@ end def recvTimeout - if select(1000)==0 + if select(10)==0 raise Hangup.new("Timeout") end @@ -509,6 +503,17 @@ message = "" # Loop Until "end of line" - while (char = recv(1)) != "\n" - message += char + count=0 + while true + #p "Starting gets" + x=select(0.05) + if x==0 + count+=1 + Graphics.update if count%10==0 + raise Errno::ETIMEOUT if count>200 + next + end + ch = recv(1) + break if ch == "\n" + message += ch end # Return recieved data @@ -517,5 +522,5 @@ #-------------------------------------------------------------------------- - # ● Writes data to socket. + # * Writes data to socket. #-------------------------------------------------------------------------- def write(data) @@ -525,8 +530,4 @@ end -#------------------------------------------------------------------------------- -# End SDK Enabled Test -#------------------------------------------------------------------------------- - #=============================================================================== # ** TCPSocket - Creates and manages TCP sockets. @@ -543,5 +544,5 @@ #-------------------------------------------------------------------------- - # ● Creates a new socket and connects it to the given host and port. + # * Creates a new socket and connects it to the given host and port. #-------------------------------------------------------------------------- def self.open(*args) @@ -558,5 +559,5 @@ #-------------------------------------------------------------------------- - # ● Creates a new socket and connects it to the given host and port. + # * Creates a new socket and connects it to the given host and port. #-------------------------------------------------------------------------- def initialize(host, port) @@ -568,5 +569,5 @@ #============================================================================== -# ■ SocketError +# ** SocketError #------------------------------------------------------------------------------ # Default exception class for sockets. @@ -576,10 +577,170 @@ def self.check errno = Winsock.WSAGetLastError - if not Network.testing? == 1 + #if not Network.testing? == 1 raise Errno.const_get(Errno.constants.detect { |c| Errno.const_get(c).new.errno == errno }) + #else + # errno != 0 ? (Network.testresult(true)) : (Network.testresult(false)) + #end + end +end + +############################# +# +# HTTP utility functions +# +############################# + +def pbPostData(url, postdata, filename=nil, depth=0) + if url[/^http:\/\/([^\/]+)(.*)$/] + host=$1 + path=$2 + body = postdata.map {|key, value| + keyString=key.to_s + valueString=value.to_s + keyString.gsub!(/[^a-zA-Z0-9_\.\-]/n) {|s| sprintf('%%%02x', s[0]) } + valueString.gsub!(/[^a-zA-Z0-9_\.\-]/n) {|s| sprintf('%%%02x', s[0]) } + next "#{keyString}=#{valueString}" + }.join('&') + request="POST #{path} HTTP/1.1\nUser-Agent: Ruby Agent\nPragma: no-cache\nHost: #{host}\nProxy-Connection: Close\n" + request+="Content-Type: application/x-www-form-urlencoded\n" + request+="Content-Length: #{body.length}\n" + request+="\n" + request+=body + return pbHttpRequest(host, request, filename, depth) + end + return "" +end + +def pbDownloadData(url, filename=nil, depth=0) + if depth>10 + raise "Redirection level too deep" + end + if url[/^http:\/\/([^\/]+)(.*)$/] + host=$1 + path=$2 + request="GET #{path} HTTP/1.1\nUser-Agent: Ruby Agent\nPragma: no-cache\nHost: #{host}\nProxy-Connection: Close\n\n" + return pbHttpRequest(host, request, filename, depth) + end + return "" +end + +def pbHttpRequest(host, request, filename=nil, depth=0) + if depth>10 + raise "Redirection level too deep" + end + socket=::TCPSocket.new(host, 80) + time=Time.now.to_i + begin + socket.send(request) + result=socket.gets + data="" + # Get the HTTP result + if result[/^HTTP\/1\.[01] (\d+).*/] + errorcode=$1.to_i + if errorcode>=400 && errorcode<500 + raise "HTTP Error #{errorcode}" + end + headers={} + # Get the response headers + while true + result=socket.gets.sub(/\r$/,"") + break if result=="" + if result[/^([^:]+):\s*(.*)/] + headers[$1]=$2 + end + end + length=-1 + chunked=false + if headers["Content-Length"] + length=headers["Content-Length"].to_i + end + if headers["Transfer-Encoding"]=="chunked" + chunked=true + end + if headers["Location"] && errorcode >= 300 && errorcode < 400 + socket.close rescue socket=nil + return pbDownloadData(headers["Location"],filename,depth+1) + end + if chunked==true + # Chunked content + while true + lengthline=socket.gets.sub(/\r$/,"") + length=lengthline.to_i(16) + break if length==0 + while Time.now.to_i-time>=5 || socket.select(10)==0 + time=Time.now.to_i + Graphics.update + end + data+=socket.recv(length) + socket.gets + end + elsif length==-1 + # No content length specified + while true + if socket.select(500)==0 + break + else + while Time.now.to_i-time>=5 || socket.select(10)==0 + time=Time.now.to_i + Graphics.update + end + data+=socket.recv(1) + end + end else - errno != 0 ? (Network.testresult(true)) : (Network.testresult(false)) + # Content length specified + while length>0 + chunk=[length,4096].min + while Time.now.to_i-time>=5 || socket.select(10)==0 + time=Time.now.to_i + Graphics.update + end + data+=socket.recv(chunk) + length-=chunk + end end + end + if filename + File.open(filename,"wb"){|f| + f.write(data) + } + else + return data + end + ensure + socket.close rescue socket=nil end + return "" end +def pbDownloadToString(url) + begin + data=pbDownloadData(url) + return data + rescue + return "" + end +end + +def pbDownloadToFile(url, file) + begin + pbDownloadData(url,file) + rescue + end +end + +def pbPostToString(url, postdata) + begin + data=pbPostData(url, postdata) + return data + rescue + return "" + end +end + +def pbPostToFile(url, postdata, file) + begin + pbPostData(url, postdata,file) + rescue + end +end Changed: PokemonAnimEditor --- Left +++ Right @@ -1,51 +1,3 @@ -module Mouse - gsm = Win32API.new('user32', 'GetSystemMetrics', 'i', 'i') - @GetCursorPos = Win32API.new('user32', 'GetCursorPos', 'p', 'i') - @SetCapture = Win32API.new('user32', 'SetCapture', 'p', 'i') - @ReleaseCapture = Win32API.new('user32', 'ReleaseCapture', '', 'i') - module_function - def getMouseGlobalPos - pos = [0, 0].pack('ll') - if @GetCursorPos.call(pos) != 0 - return pos.unpack('ll') - else - return nil - end - end - def screen_to_client(x, y) - return nil unless x and y - screenToClient = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i') - pos = [x, y].pack('ll') - if screenToClient.call(Win32API.pbFindRgssWindow, pos) != 0 - return pos.unpack('ll') - else - return nil - end - end - def setCapture - @SetCapture.call(Win32API.pbFindRgssWindow) - end - def releaseCapture - @ReleaseCapture.call - end - def getMousePos(catch_anywhere = false) - x, y = screen_to_client(*getMouseGlobalPos) - width, height = Win32API.client_size - if catch_anywhere or (x >= 0 and y >= 0 and x < width and y < height) - return (x/$ResizeFactor).to_i, (y/$ResizeFactor).to_i - else - return nil - end - end - def del - if @oldcursor == nil - return - else - @SetClassLong.call(Win32API.pbFindRgssWindow,-12, @oldcursor) - @oldcursor = nil - end - end -end class Window_Menu < Window_CommandPokemon @@ -182,10 +134,10 @@ self.width-2,self.height-2) rect=toAbsoluteRect(rect) - if Input.triggerex?(0x01) && + if Input.triggerex?(Input::LeftMouseKey) && rect.contains(mousepos[0],mousepos[1]) && !@captured @captured=true self.invalidate end - if Input.releaseex?(0x01) && @captured + if Input.releaseex?(Input::LeftMouseKey) && @captured self.changed=true if rect.contains(mousepos[0],mousepos[1]) @captured=false @@ -462,5 +414,5 @@ end return false if self.disabled - return false if !Input.repeatex?(0x01) + return false if !Input.repeatex?(Input::LeftMouseKey) return false if !mousepos left=toAbsoluteRect(@leftarrow) @@ -847,5 +799,5 @@ mousepos=Mouse::getMousePos @changed=false - return if !Input.repeatex?(0x01) + return if !Input.repeatex?(Input::LeftMouseKey) return if !mousepos return if !self.animbitmap @@ -1258,5 +1210,5 @@ mousepos=Mouse::getMousePos if mousepos && pbSpriteHitTest(self,mousepos[0],mousepos[1],false,true) - if Input.triggerex?(0x01) # Left mouse button + if Input.triggerex?(Input::LeftMouseKey) # Left mouse button selectedcel=-1 maxspr=PBAnimation::MAXSPRITES @@ -1525,5 +1477,5 @@ hit=menuwindow.hittest menuwindow.index=hit if hit>=0 - if Input.triggerex?(0x01) || Input.triggerex?(0x02) # Left or right button + if Input.triggerex?(Input::LeftMouseKey) || Input.triggerex?(Input::RightMouseKey) # Left or right button menuwindow.dispose return hit @@ -2038,5 +1990,5 @@ break end - if Input.triggerex?(0x01) + if Input.triggerex?(Input::LeftMouseKey) for j in 0...4 next if !curve[j].hittest? @@ -2120,5 +2072,5 @@ break end - if Input.triggerex?(0x01) + if Input.triggerex?(Input::LeftMouseKey) break end @@ -2323,8 +2275,5 @@ def pbRgssChdir(dir) - Dir.chdir(dir) { yield } - chdirRTP("RTP1"){ Dir.chdir(dir) { yield } } - chdirRTP("RTP2"){ Dir.chdir(dir) { yield } } - chdirRTP("RTP3"){ Dir.chdir(dir) { yield } } + RTP.eachPath{|path| Dir.chdir(path+dir) { yield } } end @@ -2779,5 +2728,5 @@ pbHelpWindow next - elsif Input.triggerex?(0x02) && sliderwin.hittest?(0) # Right mouse button + elsif Input.triggerex?(Input::RightMouseKey) && sliderwin.hittest?(0) # Right mouse button commands=[ _INTL("Copy Frame"), @@ -2813,5 +2762,5 @@ end next - elsif Input.triggerex?(0x02) # Right mouse button + elsif Input.triggerex?(Input::RightMouseKey) # Right mouse button mousepos=Mouse::getMousePos mousepos=[0,0] if !mousepos Changed: Compiler --- Left +++ Right @@ -750,10 +750,10 @@ record.push(csvEnumFieldOrInt!(thisline,hashenum,"",_INTL("(line {1})",lineno))) record.push(csvInt!(thisline,lineno)) - if !FileTest.exist?(sprintf("Data/Map%03d.rxdata",record[0])) && - !FileTest.exist?(sprintf("Data/Map%03d.rvdata",record[0])) + if !pbRgssExists?(sprintf("Data/Map%03d.rxdata",record[0])) && + !pbRgssExists?(sprintf("Data/Map%03d.rvdata",record[0])) print _INTL("Warning: Map {1}, as mentioned in the map\r\nconnection data, was not found.\r\n{2}",record[0],FileLineData.linereport) end - if !FileTest.exist?(sprintf("Data/Map%03d.rxdata",record[3])) && - !FileTest.exist?(sprintf("Data/Map%03d.rvdata",record[3])) + if !pbRgssExists?(sprintf("Data/Map%03d.rxdata",record[3])) && + !pbRgssExists?(sprintf("Data/Map%03d.rvdata",record[3])) print _INTL("Warning: Map {1}, as mentioned in the map\r\nconnection data, was not found.\r\n{2}",record[3],FileLineData.linereport) end @@ -1333,12 +1333,4 @@ end -def removeConstantName(mod,name) - for c in mod.constants - if name.to_sym==c.to_sym - mod.send(:remove_const,c.to_sym) - end - end -end - def removeConstantValue(mod,value) for c in mod.constants @@ -1358,11 +1350,4 @@ end -def hasConstValue?(mod,value) - for c in mod.constants - return true if mod.const_get(c.to_sym)==value - end - return false -end - def getConstantName(mod,value) for c in mod.constants @@ -3236,4 +3221,5 @@ j+=1 end + text=text.sub(/\\m\s*$/,"") pbPushComment(newList,"Battle: #{text}") if list[j].code==111 && list[j].parameters[0]==12 @@ -3243,13 +3229,15 @@ text=event.pages[1].list[0].parameters[0] j=1;while j=numCards elsif Input.repeat?(Input::UP) - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() choice-=1 choice=numCards-1 if choice<0 elsif Input.trigger?(Input::B) - Audio.se_play(pbGetDecisionSE) + pbPlayCancelSE() choice=-1 end @@ -306,18 +304,17 @@ Input.update pbUpdate - @sprites["helpwindow"].update if Input.repeat?(Input::DOWN) - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() choice+=1 choice=0 if choice>=numCards elsif Input.repeat?(Input::UP) - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() choice-=1 choice=numCards-1 if choice<0 elsif Input.trigger?(Input::C) - Audio.se_play(pbGetDecisionSE) + pbPlayDecisionSE() break elsif Input.trigger?(Input::A) && @battle.open - Audio.se_play(pbGetDecisionSE) + pbPlayDecisionSE() pbViewOpponentCards(numCards) if @battle.open @@ -404,22 +401,21 @@ Input.update pbUpdate - @sprites["helpwindow"].update if Input.repeat?(Input::DOWN) - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() boardY+=1 boardY=0 if boardY>=@battle.height doRefresh=true elsif Input.repeat?(Input::UP) - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() boardY-=1 boardY=@battle.height-1 if boardY<0 doRefresh=true elsif Input.repeat?(Input::LEFT) - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() boardX-=1 boardX=@battle.width-1 if boardX<0 doRefresh=true elsif Input.repeat?(Input::RIGHT) - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() boardX+=1 boardX=0 if boardX>=@battle.width @@ -429,7 +425,7 @@ elsif Input.trigger?(Input::C) if @battle.isOccupied?(boardX,boardY) - Audio.se_play("Audio/SE/buzzer.wav") + pbPlayBuzzerSE() else - Audio.se_play(pbGetDecisionSE) + pbPlayDecisionSE() @sprites["player#{@cardIndexes[cardIndex]}"].z=2 break @@ -463,5 +459,4 @@ Input.update pbUpdate - @sprites["helpwindow"].update command.update if command.index!=index @@ -484,5 +479,5 @@ index=-1 else - Audio.se_play("Audio/SE/buzzer.wav") + pbPlayBuzzerSE() end elsif Input.trigger?(Input::C) @@ -492,7 +487,7 @@ item=cardStorage[command.index] if !item || (@battle.pbQuantity(cardStorage,item[0])==0) - Audio.se_play("Audio/SE/buzzer.wav") + pbPlayBuzzerSE() else - Audio.se_play(pbGetDecisionSE) + pbPlayDecisionSE() sprite=@sprites["player#{chosenCards.length}"] sprite.bitmap.dispose if sprite.bitmap @@ -860,12 +855,14 @@ ret=cmdwindow.number if ret>maximum - Audio.se_play("Audio/SE/buzzer.wav") + pbPlayBuzzerSE() elsif ret100 - raise - end + #$PBDebugExceptions+=1 + #if $PBDebugExceptions>100 + # raise + #end end end Changed: PokemonField --- Left +++ Right @@ -16,4 +16,79 @@ HIDDENMACHINECOMMONEVENT=-1 + +class RectInterpolator + def initialize(oldrect,newrect,frames) + restart(oldrect,newrect,frames) + end + def restart(oldrect,newrect,frames) + @oldrect=oldrect + @newrect=newrect + @frames=[frames,1].max + @curframe=0 + @rect=oldrect.clone + end + def set(rect) + rect.set(@rect.x,@rect.y,@rect.width,@rect.height) + end + def done? + @curframe>@frames + end + def update + return if done? + t=(@curframe*1.0/@frames) + x1=@oldrect.x + x2=@newrect.x + x=x1+t*(x2-x1) + y1=@oldrect.y + y2=@newrect.y + y=y1+t*(y2-y1) + rx1=@oldrect.x+@oldrect.width + rx2=@newrect.x+@newrect.width + rx=rx1+t*(rx2-rx1) + ry1=@oldrect.y+@oldrect.height + ry2=@newrect.y+@newrect.height + ry=ry1+t*(ry2-ry1) + minx=xrx ? x : rx + miny=yry ? y : ry + @rect.set(minx,miny,maxx-minx,maxy-miny) + @curframe+=1 + end +end + +class PointInterpolator + def initialize(oldx,oldy,newx,newy,frames) + restart(oldx,oldy,newx,newy,frames) + end + def restart(oldx,oldy,newx,newy,frames) + @oldx=oldx + @oldy=oldy + @newx=newx + @newy=newy + @frames=frames + @curframe=0 + @x=oldx + @y=oldy + end + def x; @x;end + def y; @y;end + def done? + @curframe>@frames + end + def update + return if done? + t=(@curframe*1.0/@frames) + rx1=@oldx + rx2=@newx + @x=rx1+t*(rx2-rx1) + ry1=@oldy + ry2=@newy + @y=ry1+t*(ry2-ry1) + @curframe+=1 + end +end + + module EncounterModifier @@procs=[] @@ -29,4 +104,5 @@ end + def moveFromSymbol(item) if item.is_a?(Symbol) || item.is_a?(String) @@ -201,4 +277,5 @@ module PokemonSkins + # Overrides "getDefaultTextSkin" in the script PokemonMessages def self.getDefaultTextSkin skin=$PokemonSystem ? $PokemonSystem.textskin : nil @@ -606,5 +683,5 @@ def Kernel.pbPickup(pokemon) - return if pokemon.ability!=PBAbilities::PICKUP || pokemon.egg? + return if !isConst?(pokemon.ability,PBAbilities,:PICKUP) || pokemon.egg? return if pokemon.item!=0 return if rand(10)!=0 @@ -874,17 +951,4 @@ end -class WinSprite < Sprite - def initialize(bitmap) - super() - self.bitmap=bitmap - end - def width - return self.bitmap.width - end - def height - return self.bitmap.height - end -end - class LocationWindow def initialize(name) @@ -1320,6 +1384,4 @@ wave=nil msgwindow=Kernel.pbCreateMessageWindow - skinfile=PokemonSkins.getDefaultTextSkin - pbLoadSkin(msgwindow,"Graphics/Windowskins/#{skinfile}") oldvolume=Kernel.Audio_bgm_get_volume() Kernel.Audio_bgm_set_volume(0) @@ -1569,12 +1631,4 @@ end -def Kernel.pbCheckMove(move) - for i in $Trainer.party - for j in i.moves - return i if j.id==move - end - end - return nil -end def Kernel.pbCut @@ -1582,5 +1636,5 @@ movefinder=Kernel.pbCheckMove(PBMoves::CUT) if $DEBUG || movefinder - Kernel.pbMessage(_INTL("This tree looks like it can be cut down!")) + Kernel.pbMessage(_INTL("This tree looks like it can be cut down!\1")) if Kernel.pbConfirmMessage(_INTL("Would you like to cut it?")) speciesname=!movefinder ? PBSpecies.getName(0) : movefinder.name @@ -1598,77 +1652,4 @@ end -class RectInterpolator - def initialize(oldrect,newrect,frames) - restart(oldrect,newrect,frames) - end - def restart(oldrect,newrect,frames) - @oldrect=oldrect - @newrect=newrect - @frames=[frames,1].max - @curframe=0 - @rect=oldrect.clone - end - def set(rect) - rect.set(@rect.x,@rect.y,@rect.width,@rect.height) - end - def done? - @curframe>@frames - end - def update - return if done? - t=(@curframe*1.0/@frames) - x1=@oldrect.x - x2=@newrect.x - x=x1+t*(x2-x1) - y1=@oldrect.y - y2=@newrect.y - y=y1+t*(y2-y1) - rx1=@oldrect.x+@oldrect.width - rx2=@newrect.x+@newrect.width - rx=rx1+t*(rx2-rx1) - ry1=@oldrect.y+@oldrect.height - ry2=@newrect.y+@newrect.height - ry=ry1+t*(ry2-ry1) - minx=xrx ? x : rx - miny=yry ? y : ry - @rect.set(minx,miny,maxx-minx,maxy-miny) - @curframe+=1 - end -end - -class PointInterpolator - def initialize(oldx,oldy,newx,newy,frames) - restart(oldx,oldy,newx,newy,frames) - end - def restart(oldx,oldy,newx,newy,frames) - @oldx=oldx - @oldy=oldy - @newx=newx - @newy=newy - @frames=frames - @curframe=0 - @x=oldx - @y=oldy - end - def x; @x;end - def y; @y;end - def done? - @curframe>@frames - end - def update - return if done? - t=(@curframe*1.0/@frames) - rx1=@oldx - rx2=@newx - @x=rx1+t*(rx2-rx1) - ry1=@oldy - ry2=@newy - @y=ry1+t*(ry2-ry1) - @curframe+=1 - end -end - def pbHiddenMoveAnimation(pokemon) return false if !pokemon @@ -1720,5 +1701,5 @@ if ptinterp.done? phase=3 - pbPlayCry(pokemon.species) + pbPlayCry(pokemon) frames=0 end Changed: PokemonSummary --- Left +++ Right @@ -557,5 +557,5 @@ @sprites["movesel"].index=selmove newmove=(selmove==4) ? 0 : @pokemon.moves[selmove].id - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() drawSelectedMove(@pokemon,0,newmove) end @@ -569,5 +569,5 @@ @sprites["movesel"].index=selmove newmove=(selmove==4) ? 0 : @pokemon.moves[selmove].id - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() drawSelectedMove(@pokemon,0,newmove) end @@ -663,6 +663,6 @@ @page=2 if @page>2 dorefresh=true - if @page!=oldpage - Audio.se_play(pbGetDecisionSE) + if @page!=oldpage # Move to next page + pbPlayCursorSE() dorefresh=true end @@ -673,6 +673,6 @@ @page=0 if @page<0 @page=2 if @page>2 - if @page!=oldpage - Audio.se_play(pbGetDecisionSE) + if @page!=oldpage # Move to next page + pbPlayCursorSE() dorefresh=true end Changed: PokemonMart --- Left +++ Right @@ -1,4 +1,8 @@ + def pbGetPrice(item) + return $ItemData[item][ITEMPRICE] + end +################### class Window_PokemonMart < SpriteWindow_Selectable @@ -99,9 +103,7 @@ end - def pbGetPrice(item) - return $ItemData[item][ITEMPRICE] - end + class PokemonMartScene @@ -271,5 +273,5 @@ cw.visible=true i=0 - Audio.se_play(pbGetDecisionSE) + pbPlayDecisionSE() loop do Graphics.update @@ -300,5 +302,5 @@ cw.visible=true i=0 - Audio.se_play(pbGetDecisionSE) + pbPlayDecisionSE() loop do Graphics.update @@ -328,5 +330,5 @@ cw.y-=dw.height cw.index=0 - Audio.se_play(pbGetDecisionSE) + pbPlayDecisionSE() loop do cw.visible=!dw.busy? Changed: PokeBattle_ActualScene --- Left +++ Right @@ -1176,5 +1176,5 @@ if Input.trigger?(Input::C) || @abortable if cw.pausing? - Audio.se_play(pbGetDecisionSE) if !@abortable + pbPlayDecisionSE() if !@abortable cw.resume end @@ -1205,9 +1205,9 @@ if Input.trigger?(Input::C) || @abortable if cw.busy? - Audio.se_play(pbGetDecisionSE) if cw.pausing? && !@abortable + pbPlayDecisionSE() if cw.pausing? && !@abortable cw.resume else cw.text="" - Audio.se_play(pbGetDecisionSE) + pbPlayDecisionSE() cw.visible=false if @messagemode return @@ -1239,5 +1239,5 @@ if Input.trigger?(Input::B) if dw.busy? - Audio.se_play(pbGetDecisionSE)if dw.pausing? + pbPlayDecisionSE() if dw.pausing? dw.resume else @@ -1249,5 +1249,5 @@ if Input.trigger?(Input::C) if dw.busy? - Audio.se_play(pbGetDecisionSE)if dw.pausing? + pbPlayDecisionSE() if dw.pausing? dw.resume else @@ -1610,6 +1610,5 @@ # Show shiny animation if !@battle.opponent - pkmnwav=sprintf("Audio/SE/%03dCry",@battle.party2[0].species) - Audio.se_play(pkmnwav,90,100) rescue nil + pbPlayCry(@battle.party2[0]) if @battle.party2[0].isShiny? pbCommonAnimation("Shiny",@battle.battlers[1],nil) @@ -1866,5 +1865,5 @@ if Input.trigger?(Input::C) ret=[0,2,1,3][cw2.index] - Audio.se_play(pbGetDecisionSE) + pbPlayDecisionSE() @lastcmd[index]=ret return ret @@ -1872,5 +1871,5 @@ nextindex=pbNextIndex(cw2.index) if cw2.index!=nextindex - Audio.se_play(pbGetDecisionSE) + pbPlayCursorSE() cw2.index=nextindex end @@ -1935,18 +1934,18 @@ pbInputUpdate pbFrameUpdate(cw) - if Input.trigger?(Input::B) + if Input.trigger?(Input::B) # Cancel fight menu @lastmove[index]=cw.index - Audio.se_play(pbGetDecisionSE) + pbPlayCancelSE() return -1 end - if Input.trigger?(Input::C) + if Input.trigger?(Input::C)# Confirm choice ret=cw.index - Audio.se_play(pbGetDecisionSE) + pbPlayDecisionSE() @lastmove[index]=ret return ret end nextindex=pbNextIndex(cw.index) - if cw.index!=nextindex - Audio.se_play(pbGetDecisionSE) + if cw.index!=nextindex # Move cursor + pbPlayCursorSE() cw.setIndex(nextindex) end @@ -2341,4 +2340,5 @@ return nil end + return nil end @@ -2355,4 +2355,7 @@ end +def pbAnimation(moveid,attacker,opponent,side=true) + +end def pbAnimation(moveid,attacker,opponent,side=true) Changed: PokemonTrading --- Left +++ Right @@ -156,6 +156,5 @@ def pbTrade $game_system.bgm_stop - sefile=sprintf("Audio/SE/%03dCry.wav",@pokemon.species) - Audio.se_play(sefile) + pbPlayCry(@pokemon) speciesname1=PBSpecies.getName(@pokemon.species) speciesname2=PBSpecies.getName(@pokemon2.species) @@ -163,5 +162,5 @@ _INTL("{1}\r\nID: {2} OT: {3}",@pokemon.name, (@pokemon.trainerID&0xFFFF), @pokemon.ot),-1,100) - Audio.se_play(pbGetDecisionSE) + pbPlayDecisionSE() pbScene1 Kernel.pbDisplayMessageFancy(@sprites["msgwindow"], Changed: PokemonLoad --- Left +++ Right @@ -103,4 +103,11 @@ } end + def self.pbResolveFont(name) + RTP.eachPath {|path| + file=path+Source+name + return file if FileTest.exist?(file) + } + return Source+name + end def self.install success = [] @@ -111,11 +118,13 @@ exist=false end + if !Font.exist?(Names[i]) + exist=false + end end return if exist # Check if all source fonts exist - exist=false for i in 0...Names.size - if FileTest.exist?(Source + Filenames[i]) + if RTP.exists?(Source + Filenames[i]) exist=true break @@ -125,5 +134,5 @@ Kernel.pbMessage(_INTL("One or more fonts used in this game do not exist on the system.\1")) Kernel.pbMessage(_INTL("The game can be played, but the look of the game's text will not be optimal.\1")) - Kernel.pbMessage(_INTL("The game will now install the necessary fonts.")) + failed=false for i in 0...Filenames.size f = Filenames[i] @@ -131,14 +140,14 @@ if not FileTest.exist?(Dest + f) # check to ensure font is in specified location... - if FileTest.exist?(Source + f) + if RTP.exists?(Source + f) # copy file to fonts folder succeeded=false begin - copy_file(Source + f, Dest + f) + copy_file(pbResolveFont(f), Dest + f) # add font resource AFR.call(Dest + f) # add entry to win.ini/registry WPS.call('Fonts', Names[i] + ' (TrueType)', f) - succeeded=FileTest.exists?(Dest + f) + succeeded=FileTest.exist?(Dest + f) rescue SystemCallError # failed @@ -148,12 +157,10 @@ success.push(Names[i]) else - Kernel.pbMessage(_INTL("The font \"{1}\" could not be installed.",Names[i])) + failed=true end - else - # Kernel.pbMessage(_INTL("The font \"{1}\" could not be found.",f)) end end end - if success != [] # one or more fonts successfully installed + if success.length>0 # one or more fonts successfully installed SM.call(HWND_BROADCAST,WM_FONTCHANGE,0,0) if Notify @@ -162,5 +169,10 @@ fonts << f << ', ' end - Kernel.pbMessage(_INTL("The fonts were successfully installed.\1",f)) + if failed + Kernel.pbMessage(_INTL("Some of the fonts were successfully installed.\1")) + Kernel.pbMessage(_INTL("To install the other fonts, copy the files in this game's Fonts folder to the Fonts folder in Control Panel.")) + else + Kernel.pbMessage(_INTL("The fonts were successfully installed.\1")) + end if Kernel.pbConfirmMessage(_INTL("Would you like to restart the game and apply the changes?")) a = Thread.new { system('Game') } @@ -168,4 +180,7 @@ end end + else + # No fonts were installed. + Kernel.pbMessage(_INTL("To install the necessary fonts, copy the files in this game's Fonts folder to the Fonts folder in Control Panel.")) end end Changed: BitmapCache --- Left +++ Right @@ -147,12 +147,30 @@ module Cache def self.system(x,hue=0) - BitmapCache.load_bitmap("Graphics/System/",x,hue) + BitmapCache.load_bitmap("Graphics/System/"+x,hue, true) end def self.character(x,hue=0) - BitmapCache.load_bitmap("Graphics/Characters/",x,hue) + BitmapCache.load_bitmap("Graphics/Characters/"+x,hue, true) end def self.picture(x,hue=0) - BitmapCache.load_bitmap("Graphics/Pictures/",x,hue) + BitmapCache.load_bitmap("Graphics/Pictures/"+x,hue, true) end + def self.animation(x,hue=0) + BitmapCache.load_bitmap("Graphics/Animations/"+x,hue, true) + end + def self.battler(x,hue=0) + BitmapCache.load_bitmap("Graphics/Battlers/"+x,hue, true) + end + def self.face(x,hue=0) + BitmapCache.load_bitmap("Graphics/Faces/"+x,hue, true) + end + def self.parallax(x,hue=0) + BitmapCache.load_bitmap("Graphics/Parallaxes/"+x,hue, true) + end + def self.clear + BitmapCache.clear() + end + def self.load_bitmap(dir,name,hue=0) + BitmapCache.load_bitmap(dir+name,hue, true) + end end @@ -204,5 +222,5 @@ end def self.tile(filename, tile_id, hue) - BitmapCache(filename,tile_id,hue) + BitmapCache.tile(filename,tile_id,hue) end def self.clear Changed: Win32API_ --- Left +++ Right @@ -28,11 +28,4 @@ return 0 end - def Win32API.GetPrivateProfileString(section, key) - val = "\0"*256 - gps = Win32API.new('kernel32', 'GetPrivateProfileString',%w(p p p p l p), 'l') - gps.call(section, key, "", val, 256, ".\\Game.ini") - val.delete!("\0") - return val - end def Win32API.SetWindowPos(w, h) hWnd = pbFindRgssWindow