Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #-------------------------------------------------------------------------------
  2. # * [ACE] Khas Core Library
  3. #-------------------------------------------------------------------------------
  4. # * By Nilo K. (Khas)
  5. # * Version: 1.03
  6. # * Released on: 12.07.2016
  7. #
  8. # * Social Media
  9. # Blog: arcthunder.blogspot.com
  10. # Facebook: facebook.com/khasarc
  11. # Twitter: twitter.com/arcthunder
  12. # Youtube: youtube.com/c/khasarc
  13. #
  14. # * Khas Scripts @ RPG Maker Web forums (official support!)
  15. # forums.rpgmakerweb.com/index.php?/forum/132-khas-scripts
  16. #
  17. #-------------------------------------------------------------------------------
  18. # * Terms of Use
  19. #-------------------------------------------------------------------------------
  20. # When using KHAS CORE LIBRARY (the script), you agree with the following terms:
  21. # 1. If you purchased a license to one of my scripts, credit is not required.
  22. #    Otherwise, you must give credit to Khas (if you want, a link to my blog is
  23. #    always appreciated);
  24. # 2. You can use the script for free in both non-commercial and commercial
  25. #    projects;
  26. # 4. You can edit the script for using in your own project. However, you are
  27. #    not allowed to share/distribute any modified version;
  28. # 5. If you want to share a Khas script, don’t post the direct download link,
  29. #    redirect the user to my blog instead;
  30. # 6. The script can not be ported to any RPG Maker version than VX Ace.
  31. #
  32. #-------------------------------------------------------------------------------
  33. # * Log
  34. #-------------------------------------------------------------------------------
  35. # KCL 1.03 (12.07.2016)
  36. # Improved Khas notetag system (support for negative numbers)
  37. # Included scene map spriteset access
  38. #
  39. # KCL 1.02 (09.27.2015)
  40. # Fixed some issues with regions that are not used by this script.
  41. #
  42. # KCL 1.01 (08.23.2015)
  43. # Added Min_Region_Height constant. This makes possible to choose a custom
  44. # range of Regions to use as height marks.
  45. #
  46. # KCL 1.00 (03.14.2015)
  47. # First release!
  48. #
  49. #-------------------------------------------------------------------------------
  50. # * Updates
  51. #-------------------------------------------------------------------------------
  52. # Please check my blog for KCL updates!
  53. #
  54. #-------------------------------------------------------------------------------
  55. # * Requirements
  56. #-------------------------------------------------------------------------------
  57. # Place this script before any Khas script.
  58. #
  59. #-------------------------------------------------------------------------------
  60. # * Khas Core (configuration)
  61. #-------------------------------------------------------------------------------
  62.  
  63. module Khas_Core
  64.  
  65.   # MIN REGION HEIGHT
  66.   # Minimum region to consider a height mark.
  67.   # Marking a tile with this value will give it a height of 1.
  68.   # Unmarked tiles or tiles marked with values smaller than this will
  69.   # considered to be of zero height.
  70.   Min_Region_Height = 1
  71.  
  72.   # MAX REGION HEIGHT
  73.   # Maximum region to consider a height mark.
  74.   # Unmarked tiles or tiles marked with values greater than this will
  75.   # considered to be of zero height.
  76.   Max_Region_Height = 16
  77.  
  78.   # LOAD MAP DATA
  79.   # You can add map IDs here if you want their data to be loaded before the
  80.   # game starts. This will prevent any delay when switching to a big map.
  81.   Load_Map_Data = []
  82.  
  83.   # ENABLE BUILDING HEIGHT DATA
  84.   # If you are using scripts and features that need building and height data,
  85.   # please set this to true.
  86.   Enable_BH_Data = true
  87.  
  88. end
  89.  
  90. #-------------------------------------------------------------------------------
  91. # * Khas Variables
  92. #-------------------------------------------------------------------------------
  93.  
  94. $khas = {:core => 1.03}
  95. $khas_graphics = {}
  96. $khas_physics = {}
  97.  
  98. #-------------------------------------------------------------------------------
  99. # * String
  100. #-------------------------------------------------------------------------------
  101.  
  102. class String
  103.  
  104.   def khas_id?
  105.     (self =~ /\A[\w_0-9]+\Z/) == 0
  106.   end
  107.  
  108.   def khas_tag?
  109.     (self =~ /\A\[[\w_0-9]+\]/) == 0
  110.   end
  111.  
  112.   def khas_command?
  113.     (self =~ /\A\[[\w_0-9]+\s-?[\w_0-9]+\]/) == 0
  114.   end
  115.  
  116.   def khas_tag
  117.     self[/\[[\w_0-9]+\]/].sub("\[","").sub("\]","")
  118.   end
  119.  
  120.   def khas_command
  121.     self[/\[[\w_0-9]+\s/].sub("\[","").sub("\s","")
  122.   end
  123.  
  124.   def khas_value
  125.     self[/\s-?[\w_0-9]+\]/].sub("\s","").sub("\]","")
  126.   end
  127.  
  128.   def is_int?
  129.     (self =~ /\A\d+\Z/) == 0
  130.   end
  131.  
  132.   def is_float?
  133.     (self =~ /\A\d+\.\d+\Z/) == 0
  134.   end
  135.  
  136. end
  137.  
  138. #-------------------------------------------------------------------------------
  139. # * Table
  140. #-------------------------------------------------------------------------------
  141.  
  142. class Table
  143.  
  144.   def clear
  145.     for x in 0...xsize
  146.       for y in 0...ysize
  147.         for z in 0...zsize
  148.           self[x,y,z] = 0
  149.         end
  150.       end
  151.     end
  152.   end
  153.  
  154. end
  155.  
  156. #-------------------------------------------------------------------------------
  157. # * RPG Map
  158. #-------------------------------------------------------------------------------
  159.  
  160. class RPG::Map
  161.  
  162.   def valid?(x, y)
  163.     x >= 0 && x < @width && y >= 0 && y < @height
  164.   end
  165.  
  166. end
  167.  
  168. #-------------------------------------------------------------------------------
  169. # * RPG Event Command
  170. #-------------------------------------------------------------------------------
  171.  
  172. class RPG::EventCommand
  173.  
  174.   def comment?
  175.     @code == 108 || @code == 408
  176.   end
  177.  
  178.   def khas_tag?
  179.     @parameters[0].khas_tag?
  180.   end
  181.  
  182.   def khas_command?
  183.     @parameters[0].khas_command?
  184.   end
  185.  
  186.   def khas_tag
  187.     @parameters[0].khas_tag
  188.   end
  189.  
  190.   def khas_command
  191.     @parameters[0].khas_command
  192.   end
  193.  
  194.   def khas_value
  195.     @parameters[0].khas_value
  196.   end
  197.  
  198. end
  199.  
  200. #-------------------------------------------------------------------------------
  201. # * RPG Base Item
  202. #-------------------------------------------------------------------------------
  203.  
  204. class RPG::BaseItem
  205.  
  206.   def khas_note
  207.     tags_commands = []
  208.     @note.each_line do |line|
  209.       tags_commands << line if line.khas_command? || line.khas_tag?
  210.     end
  211.     tags_commands
  212.   end
  213.  
  214. end
  215.  
  216. #-------------------------------------------------------------------------------
  217. # * SceneManager
  218. #-------------------------------------------------------------------------------
  219.  
  220. module SceneManager
  221.  
  222.   def self.spriteset
  223.     @scene.spriteset
  224.   end
  225.  
  226. end
  227.  
  228. #-------------------------------------------------------------------------------
  229. # * Game Map
  230. #-------------------------------------------------------------------------------
  231.  
  232. class Game_Map
  233.  
  234.   include Khas_Core
  235.  
  236.   attr_reader :height_map
  237.   attr_reader :building_map
  238.  
  239.   alias khas_setup setup
  240.   alias khas_setup_events setup_events
  241.  
  242.   def setup(map_id)
  243.     khas_setup(map_id)
  244.     khas_extend_setup
  245.     khas_scan_note
  246.   end
  247.  
  248.   def setup_events
  249.     khas_setup_map
  250.     khas_setup_events
  251.   end
  252.  
  253.   def khas_scan_note
  254.     @map.note.each_line do |line|
  255.       call_khas_tag(line.khas_tag) if line.khas_tag?
  256.       call_khas_command(line.khas_command, line.khas_value) if line.khas_command?
  257.     end
  258.   end
  259.  
  260.   def khas_setup_map
  261.     setup_height_building
  262.   end
  263.  
  264.   def khas_extend_setup
  265.   end
  266.  
  267.   def call_khas_tag(t)
  268.   end
  269.  
  270.   def call_khas_command(c,v)
  271.   end
  272.  
  273.   def setup_height_building
  274.     if Enable_BH_Data
  275.       @height_map = Khas_Core.height_table(@map_id, @map)
  276.       @building_map = Khas_Core.building_table(@map_id, @map)
  277.     end
  278.   end
  279.  
  280.   def local_height(x,y)
  281.     @height_map.lxy(x,y)
  282.   end
  283.  
  284.   def wall?(x,y)
  285.     (@height_map.lxy(x,y) & 0x1) > 0
  286.   end
  287.  
  288.   def floor?(x,y)
  289.     (@height_map.lxy(x,y) & 0x1) == 0
  290.   end
  291.  
  292.   def building?(x,y)
  293.     @building_map.lxy(x,y) > 0
  294.   end
  295.  
  296. end
  297.  
  298. #-------------------------------------------------------------------------------
  299. # * Game Event
  300. #-------------------------------------------------------------------------------
  301.  
  302. class Game_Event < Game_Character
  303.  
  304.   alias khas_setup_page setup_page
  305.  
  306.   def setup_page(new_page)
  307.     khas_setup_page(new_page)
  308.     khas_extend_setup
  309.     khas_scan_comments
  310.   end
  311.  
  312.   def khas_scan_comments
  313.     return if @page.nil? || @list.nil?
  314.     for command in @list
  315.       if command.comment?
  316.         call_khas_tag(command.khas_tag) if command.khas_tag?
  317.         call_khas_command(command.khas_command, command.khas_value) if command.khas_command?
  318.       end
  319.     end
  320.   end
  321.  
  322.   def khas_extend_setup
  323.   end
  324.  
  325.   def call_khas_tag(t)
  326.   end
  327.  
  328.   def call_khas_command(c,v)
  329.   end
  330.  
  331. end
  332.  
  333. #-------------------------------------------------------------------------------
  334. # * Game Interpreter
  335. #-------------------------------------------------------------------------------
  336.  
  337. class Game_Interpreter
  338.  
  339.   def this_event
  340.     $game_map.events[@event_id]
  341.   end
  342.  
  343. end
  344.  
  345. #-------------------------------------------------------------------------------
  346. # * Spriteset Map
  347. #-------------------------------------------------------------------------------
  348.  
  349. class Spriteset_Map
  350.  
  351.   attr_accessor :viewport1
  352.   attr_accessor :viewport2
  353.   attr_accessor :viewport3
  354.  
  355. end
  356.  
  357. #-------------------------------------------------------------------------------
  358. # * Scene Base
  359. #-------------------------------------------------------------------------------
  360.  
  361. class Scene_Base
  362.  
  363.   attr_accessor :spriteset
  364.  
  365. end
  366.  
  367. #-------------------------------------------------------------------------------
  368. # * Table Map
  369. #-------------------------------------------------------------------------------
  370.  
  371. class Table_Map < Table
  372.  
  373.   def initialize(width, height, loop_x, loop_y)
  374.     super(width, height)
  375.     @loop_x = loop_x
  376.     @loop_y = loop_y
  377.   end
  378.  
  379.   def lxy(x,y)
  380.     if @loop_x
  381.       x += xsize if x < 0
  382.       x -= xsize if x >= xsize
  383.     else
  384.       return 0 if x < 0 || x >= xsize
  385.     end
  386.     if @loop_y
  387.       y += ysize if y < 0
  388.       y -= ysize if y >= ysize
  389.     else
  390.       return 0 if y < 0 || y >= ysize
  391.     end
  392.     self[x,y]
  393.   end
  394.  
  395.   def wall?(x,y)
  396.     (lxy(x,y) & 0x1) > 0
  397.   end
  398.  
  399.   def floor?(x,y)
  400.     (lxy(x,y) & 0x1) == 0
  401.   end
  402.  
  403. end
  404.  
  405. #-------------------------------------------------------------------------------
  406. # * Smooth Int
  407. #-------------------------------------------------------------------------------
  408.  
  409. class Smooth_Int
  410.  
  411.   attr_reader :i
  412.  
  413.   def initialize(ii)
  414.     @i = ii
  415.   end
  416.  
  417.   def update
  418.     @timer > 0 ? refresh : set(@target)
  419.   end
  420.  
  421.   def update?
  422.     @timer != nil
  423.   end
  424.  
  425.   def refresh
  426.     @phase -= @dp
  427.     @i = (@base + @delta*(Math.cos(@phase)+1)).to_i
  428.     @timer -= 1
  429.   end
  430.  
  431.   def set(target, time = nil)
  432.     if time.nil?
  433.       @i = target
  434.       @timer = nil
  435.     else
  436.       @phase = Math::PI
  437.       @dp = @phase/time
  438.       @target = target
  439.       @base = @i
  440.       @delta = (@target - @base)/2
  441.       @timer = time - 1
  442.     end
  443.   end
  444.  
  445. end
  446.  
  447. #-------------------------------------------------------------------------------
  448. # * Smooth Float
  449. #-------------------------------------------------------------------------------
  450.  
  451. class Smooth_Float
  452.  
  453.   attr_reader :f
  454.  
  455.   def initialize(ff)
  456.     @f = ff
  457.   end
  458.  
  459.   def update
  460.     @timer > 0 ? refresh : set(@target)
  461.   end
  462.  
  463.   def update?
  464.     @timer != nil
  465.   end
  466.  
  467.   def refresh
  468.     @phase -= @dp
  469.     @f = @base + @delta*(Math.cos(@phase)+1)
  470.     @timer -= 1
  471.   end
  472.  
  473.   def set(target, time = nil)
  474.     if time.nil?
  475.       @f = target
  476.       @timer = nil
  477.     else
  478.       @phase = Math::PI
  479.       @dp = @phase/time
  480.       @target = target
  481.       @base = @f
  482.       @delta = (@target - @base)/2
  483.       @timer = time - 1
  484.     end
  485.   end
  486.  
  487. end
  488.  
  489. #-------------------------------------------------------------------------------
  490. # * Khas Core
  491. #-------------------------------------------------------------------------------
  492.  
  493. module Khas_Core
  494.  
  495.   @@height_cache = {}
  496.   @@building_cache = {}
  497.  
  498.   def self.ntag?(tag)
  499.     tag < Min_Region_Height || tag > Max_Region_Height
  500.   end
  501.  
  502.   def self.gen_height_table(map)
  503.     htable = Table_Map.new(map.width, map.height, map.scroll_type == 2 || map.scroll_type == 3, map.scroll_type == 1 || map.scroll_type == 3)
  504.     for x in 0...map.width
  505.       for y in 0...map.height
  506.         tag = (map.data[x, y, 3] >> 8)
  507.         next if ntag?(tag)
  508.         tag -= (Min_Region_Height - 1)
  509.         htable[x,y] = tag*2
  510.         if map.valid?(x,y+1) && ntag?(map.data[x, y+1, 3] >> 8)
  511.           ty = y + 1
  512.           while map.valid?(x,ty) && ntag?(map.data[x, ty, 3] >> 8) && tag > 0 do
  513.             htable[x,ty] = tag*2 - 1
  514.             ty += 1
  515.             tag -= 1
  516.           end
  517.         end
  518.       end
  519.     end
  520.     htable
  521.   end
  522.  
  523.   def self.gen_building_table(map)
  524.     btable = Table_Map.new(map.width, map.height, map.scroll_type == 2 || map.scroll_type == 3, map.scroll_type == 1 || map.scroll_type == 3)
  525.     for x in 0...map.width
  526.       for y in 0...map.height
  527.         tag = (map.data[x, y, 3] >> 8)
  528.         next if ntag?(tag)
  529.         tag -= (Min_Region_Height - 1)
  530.         btable[x,y+tag] = tag if map.valid?(x,y+tag)
  531.       end
  532.     end
  533.     btable
  534.   end
  535.  
  536.   def self.height_table(map_id, map)
  537.     @@height_cache.include?(map) ? @@height_cache[map_id] : gen_height_table(map)
  538.   end
  539.  
  540.   def self.building_table(map_id, map)
  541.     @@building_cache.include?(map_id) ? @@building_cache[map_id] : gen_building_table(map)
  542.   end
  543.  
  544.   def self.load_bh_data
  545.     for id in Load_Map_Data
  546.       map = load_data(sprintf("Data/Map%03d.rvdata2", id))
  547.       @@height_cache[id] = gen_height_table(map)
  548.       @@building_cache[id] = gen_building_table(map)
  549.     end
  550.   end
  551.  
  552. end
  553.  
  554. Khas_Core.load_bh_data if Khas_Core::Enable_BH_Data
  555.  
  556. #-------------------------------------------------------------------------------
  557. # * End
  558. #-------------------------------------------------------------------------------