Advertisement
blucalm

Ra Gardening 3813

Mar 9th, 2013
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 114.36 KB | None | 0 0
  1. #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  2. # ** Garden System
  3. #    Author: Eshra
  4. #    Beta Release Date: 3 Nov. 2012
  5. #    Full Version Release: 4 Dec. 2012
  6. #    Compatibility: RPG Maker VX Ace
  7. #    Dependencies:
  8. #       1. Tsuki_CustomDataManager
  9. #       2. Ra Custom DM add-on v0.1
  10. #       3. Ra Highlights v0.1
  11. #       4. Ra Event Spawn v0.1
  12. #
  13. #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  14. #
  15. #    About:
  16. #
  17. #    This script provides support for using events to represent plants while
  18. #    in Scene_Map. It creates functionality for somewhat complicated plant
  19. #    growth cycles, plant fertillization, and plant watering systems.
  20. #
  21. #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  22. #
  23. #------------------------------------------------------------------------------
  24. # * How to Use
  25. #------------------------------------------------------------------------------
  26. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  27. # Setting up a plant:
  28. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  29. #
  30. # Plants are represented by items (or skills) in the database. To mark an item
  31. # as a plant you need to give it a growth rate and a maximum stage.
  32. #
  33. # You can give the plant a growth rate with this note tag:
  34. # <seed rate VALUE>
  35. #
  36. # You can give the plant a maximum stage with this note tag:
  37. # <seed stages VALUE>
  38. #
  39. #  - 'VALUE' should be replaced with an integer in the above two note tags -
  40. #
  41. # These are the only two notetags that are required to make a plant. There are
  42. # many more notetags though that can be used if you want to specify more
  43. # specific behavior for the plant.
  44. #
  45. # Don't forget to give the item a name, this is important!
  46. # After you have done this, you must now create an associated event for the plant.
  47. #
  48. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  49. # Plant-events:
  50. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  51. # When plants are placed on the map, their associated event is loaded based on
  52. # an event from another designated map in your project. The default script
  53. # expects all of these events to be on one map. (The map is used like a proxy
  54. # its sole purpose should be to store the event data for the plants in your
  55. # project).
  56. #
  57. # The ID of the map that these events are stored in is specified by
  58. #
  59. # GardenRa::SeedMap
  60. #
  61. # Change the value of this constant to the id number of the map which you will
  62. # be using to store your plant events.
  63. #
  64. # How to create a plant-event:
  65. # The next step after after creating the plant-item and plant-events-map is
  66. # creating the plant-event, i.e. the event (or events) that will be associated
  67. # with the plant. This is what allows the plant to be seen on the map.
  68. #
  69. # Plants are associated with events based on the name of the associated item
  70. # and the name of the associated event.
  71. # Events can be associated with plants by giving them the name of the plant
  72. # followed by a space, folled by an integer.
  73. #
  74. # For example:
  75. # We want to make a plant called 'Strawberry'.
  76. #
  77. # To do this, we have to make an item named 'Strawberry' and give it the
  78. # two essential notetags specified above. Make sure the item has no targets and
  79. # can only be used from the main menu (using the checkboxes in the database).
  80. #
  81. # After we've done this we must go to create an event to be associated with
  82. # the plant.
  83. #
  84. # So we go to the designated map in our project and e decide to name the event
  85. # 'Stawberry 1'.
  86. # By doing this, we've let the script know that the event with the name
  87. # 'Strawberry 1' is the first event that will be used to display the stages of
  88. # the item name 'Strawberry'.
  89. #
  90. # Let's say we've specified the strawberry to have 7 stages in the note tag box:
  91. #
  92. # <seed stages 7>
  93. #
  94. # By default each plant-event can be used to represent 5 growth stages.
  95. # But what is a stage?
  96. # A stage is represented by a page of an event. In the default script, once a
  97. # plant-event is placed on the map, its self switches will be iterated through
  98. # from 'A' to 'D'. The next self-switch is turned on each time the plant
  99. # advances a stage in that order (First A, then B, then C, then D).
  100. #
  101. # This means that we can represent 5 stages of growth for our strawberry with
  102. # one event (The first stage has no selfswitches on, the second stage has self-
  103. # switch 'A' on, the third stage has self-switch 'B' on, etc.)
  104. #
  105. # Create the event in your designated plant-events-map and make 4 additional
  106. # pages for it so that it has five pages total. Use a different picture for
  107. # each stage so that when the event's self-switches are flipped on it will appear
  108. # that it is growing.
  109. #
  110. # But there is a problem! We specified that we wanted our plant to have 7 stages
  111. # not 5. How do we handle the extra two stages?
  112. # Just make another event and associate it with the 'Strawberry' item.
  113. #
  114. # The next event we make we name as 'Strawberry 2'.
  115. # For this event, it's not necessary to create 5 pages for it. We only need two
  116. # total pages on this event. One for when it has no self-switches on and one for
  117. # when self-switch 'A' is on.
  118. # This event will represent stages 6 and 7 in the overall growth of our plant.
  119. # The script an handle any number of events created this way for any given plant.
  120. #
  121. # If we wanted to make a plant with 100 growth stages, we would just have to make
  122. # 20 different events, set up the 5 pages on each of those events, and name them
  123. # sequentially so that the script knows which plant-event to choose when it is
  124. # changing events.
  125. #
  126. # We are now done creating our plant. To place the plant on the map all you have
  127. # to do is use it from your inventory just like you would any other item.
  128. #
  129. # If it is not clear how to create plants based on the above instructions I
  130. # apologize, I have made a video and have a demo as well which might be easier
  131. # to understand.
  132. #
  133. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  134. # Specifying looping plants:
  135. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  136. #
  137. # Use these notetags:
  138. # <seed loop true>
  139. # <Seed loop stage VALUE>
  140. #
  141. # - Replace 'VALUE' in the above notetags with an integer -
  142. #
  143. # To specify a plant that will loop back to a previous stage after it has grown
  144. # to it's last stage.
  145. # 'VALUE' is the stage number that it will loop back to.
  146. #
  147. # This might be useful if you have a plant that should cycle through stages
  148. # repetetively, like a tree changing through the seasons.
  149. #
  150. # Seeds can be limited to certain terrain tags with this notetag:
  151. # <Seed terrain VALUE,VALUE,...>
  152. #
  153. # - replace 'VALUE' with an integer. each value must be separated by a comma the
  154. # elipses are there to denote the pattern continues, don't actually put elispses
  155. # in the notetag -
  156. # For example, to specify a seed can only be planted on terrain tags 0, 7, 4,
  157. # and 5, you would use this notetag:
  158. #
  159. # <seed terrain 5,7,0,4>
  160. #
  161. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  162. # Fertillizer:
  163. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  164. #
  165. # Plants can be fertilliezed by items which are fertillizers. To make a fertillizer
  166. # use this notetag:
  167. #
  168. # <Seed fertillizer FLOAT>
  169. #
  170. # - Replace FLOAT with a floating point number between 0 and 1, for example 0.32 -
  171. # The value you use in this parameter represents the concentration of the fertillizer
  172. # As the concentration of the fertillizer increases the growth rate of the plant
  173. # will also increase. Additionally, the yield of a plant will increase based on
  174. # the amount of fertillizer that has been applied to it.
  175. #
  176. # Fertillizer is used by using the associated item from the player's inventory.
  177. # After you see the fertillizer on the ground, you can plant a seed at that
  178. # location to apply the fertillizer to the seed. The fertillizer can also be
  179. # applied after the seed has started growing, as long as the seed is not
  180. # at its last stage of growth.
  181. #
  182. # Limiting the amount of fertillizer that can be applied to a plant:
  183. #
  184. # If you want to limit the amount of fertillizer that a plant can applied to a
  185. # plant use this notetag:
  186. #
  187. # <seed max fertillizer FLOAT>
  188. #
  189. # - Replace 'FLOAT' with a floating point number between 0 and 1 -
  190. #
  191. # Plants can also be given a 'Fertillizer effect ratio'
  192. # The lower this ratio is, the less of an effect fertillization will have on that
  193. # plant.
  194. # To set this value use this notetag:
  195. #
  196. # <seed fertile rate FLOAT>
  197. #
  198. # - Replace 'FLOAT' with a floating point number between 0 and 1 -
  199. #
  200. # You can limit fertillizer to only being planted in certain areas with this
  201. # notetag:
  202. # <fertillizer terrain VALUE,VALUE,VALUE...>
  203. # - replace 'VALUE' with an integer. each value must be separated by a comma the
  204. # elipses are there to denote the pattern continues, don't actually put elispses
  205. # in the notetag-
  206. #
  207. # For example, to specify a fertillizer can only be placed on terrain tags 0 and
  208. # 2 use this notetag:
  209. #
  210. # <fertillizer terrain 0,2>
  211. #
  212. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  213. # Watering Plants:
  214. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  215. #
  216. # Plants can be watered any number of times during each of their growth stages.
  217. # They can be set to die if they aren't watered enough or if they are watered
  218. # too much.
  219. # Plants can also be given an optimal water amount. The optimal water amount is
  220. # the amount of times the plant should be watered during each stage of growth
  221. # in order to maximize the harvest for that plant.
  222. #
  223. # Set minimum water amounts with this notetag:
  224. # <seed min water VALUE>
  225. #
  226. # Set maximum water amount with this notetag:
  227. # <seed max water VALUE>
  228. #
  229. # Set optimal water amount with this notetag:
  230. # <seed optimal water VALUE>
  231. #
  232. # - Replace 'VALUE' in the above notetags with an integer -
  233. #
  234. # Making a water container:
  235. # Water containers are items that can be used to water plants. Once the party
  236. # has a water container in their inventory, just walk up to a plant that isn't
  237. # fully grown and press the interact key to water it
  238. # You can denote items as water containers with this notetag:
  239. #
  240. # <water container VALUE>
  241. # VALUE is the how much water the container can hold.
  242. #
  243. # - Replace 'VALUE' in the above notetag with an integer-
  244. #
  245. # Water containers can be refilled using this script call from an event:
  246. #
  247. # garden_fill_containers
  248. #
  249. # You can also pass in an optional integer value to that method to modify all of
  250. # the water containers in the parties inventory by that amount.
  251. #
  252. # Harvesting and clearing plants
  253. #
  254. # Use this notetag:
  255. # <Seed harvest VALUE>
  256. #
  257. # To set the base harvest amount for a plant. The base harvest amount will be
  258. # achieved at harvest time if the plant was watered optimally at each stage.
  259. # The base harvest amount can be exceeded if the plant was fertillized.
  260. #
  261. # Use this notetag:
  262. # <seed harvest VALUE - VALUE>
  263. #
  264. # To specify a range to use has the base harvest instead of a specific value.
  265. # When harvesting a value in between the specified range will be used as the base
  266. #
  267. # **Note: Do not specifiy both a base value and a range for the same item or
  268. # skill, use one or the other **
  269. #
  270. # - Replace 'VALUE' in the above notetags with an integer -
  271.  
  272. # Use this notetag:
  273. # <clears crops VALUE>
  274. #
  275. # to mark an item or skill as being able to clear crops. Once an item is marked
  276. # with this notetag, you can use it to remove plants. if an integer value
  277. # is specified, the range of effect of the item will be increased.
  278. # For example:
  279. # <clears crops 1> means that the item will clear all of the crops adjacent to
  280. # the player.
  281. # <clears crops 2> will clear all of the plants at a distance of 2 from the player
  282. # <clears crops> without a value specified means the item can only be used to
  283. # clear crops directly in front of the player.
  284. #
  285. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  286. # Setting up the map:
  287. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  288. #
  289. # If you want your fertillizer to erode over time, you need to use these
  290. # notetags when setting up your map:
  291. #
  292. # <Erosion rate VALUE>
  293. # <Erosion value FLOAT>
  294. #
  295. # The erosion rate is specified in frames and is how quickly the fertilizer will
  296. # erode. The erosion value is how much fertillizer concentration will be
  297. # decremented by after each tic. A tic being equal to the specified erosion rate.
  298. #
  299. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  300. # Additonal settings
  301. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  302. #
  303. # If you are using the same events for multiple skills or items and don't want
  304. # all of those skills or items to have the same name, use this notetag:
  305. #
  306. # <seed name NAME>
  307. # - replace 'NAME' with the name of the event -
  308. #
  309. # To explicitly associate the item with the event of that name.
  310. #
  311. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  312. # Author Notes:
  313. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  314. #
  315. # By default, the Shift key can be held down when placing fertillizer or planting
  316. # a seed to put it infront of the player instead of at the same location the
  317. # player is standing.
  318. #
  319. # Fertillizer is applied at the time the plant is planted or the fertillizer is
  320. # placed. If the fertillizer concentration at that location changes after this
  321. # it is not reapplied.
  322. #
  323. # Internal common events are created to use the clearing items, the seeds, and
  324. # the fertillizer. If one of these items is associated with another common event
  325. # the internal common event will run first, then the event you have specified will
  326. # run.
  327. #
  328. # To do list:
  329. # There is currently no animation or fading shown when fertillizer is removed
  330. # from the map. Fix this.
  331. # There is currently no animation for watering plants.
  332. # Add a feature to change the precedence of internal common events vs. real
  333. # events.
  334. #
  335. #------------------------------------------------------------------------------
  336. # Thanks & Acknowledgments:
  337. #------------------------------------------------------------------------------
  338. #
  339. # Tsukihime - Custom DM
  340. # Celianna - Sprites
  341. #
  342. #------------------------------------------------------------------------------
  343. #
  344. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  345. # Original Release Date: 4 Dec. 2012
  346. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  347. #
  348. # Update Log
  349. # 8 Mar. 2013 - Updated Script to version 0.2 for compatibility with the water
  350. #               start add-on.
  351. # 8 Mar. 2013 - Minor changes in code style added a few @ symbols. No changes in
  352. #               functionality of base script.
  353. # 8 Dec. 2012 - BaseHarvest amount can now be specified with a constant.
  354. #               A range can now be specified instead of a base harvest amount.
  355. #               Use this notetag:
  356. #
  357. #                 <seed harvest VALUE - VALUE>
  358. #                 * replace "VALUE" with an integer value
  359. #
  360. #               to specify a range to use when generating the base value for
  361. #               harvesting.
  362. #
  363. # 7 Dec. 2012 - Fixed crashes when trying to equip items.
  364. # 5 Dec. 2012 - Fixed improper alias for move_straight inside Game_Characters
  365. #
  366. # 3 Nov. 2012 - Added support to clear crops. More options to harvest, fixed
  367. #               fertillization rates, added popups to show how much was
  368. #               harvested.
  369. #
  370. # 2 Nov. 2012 - First Version Finished
  371. #
  372. # 27 Oct. 2012 - Started work.
  373. #
  374. #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  375. # Terms of Use
  376. #-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  377. # Free to use as you please. Please respect the header though so the dates can
  378. # be preserved.
  379. #------------------------------------------------------------------------------
  380.  
  381. $imported ||= {}
  382. raise "Couldn't find: Tsuki_CustomDataManager" if !$imported["Tsuki_CustomDataManager"]
  383. raise "Couldn't find: Ra Event Spawn v0.1" if ($imported["Ra Event Spawn"] ||=-1) < 0.1
  384. raise "Couldn't find: Ra Highlights v0.1" if ($imported["Ra Highlights"] ||=-1) < 0.1
  385. raise "Couldn't find: Ra Custom DM add-on" if ($imported["Ra Custom DM add-on"] ||=-1) < 0.1
  386. $imported["Ra Gardening"] = 0.2
  387. #==============================================================================
  388. # ** RPG::BaseItem
  389. #==============================================================================
  390. class RPG::BaseItem
  391.   attr_accessor :clears_crops # this item can be used to clear crops
  392.   def clears_crops?; false; end
  393.   def is_garden_seed?; false; end
  394.   def is_fertillizer?; false; end
  395. end
  396. #==============================================================================
  397. # ** RPG::UsableItem
  398. #==============================================================================
  399. class RPG::UsableItem < RPG::BaseItem
  400.   attr_accessor :seed_loop   # boolean
  401.   attr_accessor :seed_stages # int
  402.   attr_accessor :seed_rate   # int
  403.   attr_accessor :seed_events # array
  404.   attr_accessor :seed_name
  405.   attr_accessor :loop_stage  # int
  406.   attr_accessor :seed_terrain # hash
  407.   attr_accessor :fertillizer_rate  # float (rate of the fertillizer)
  408.   attr_accessor :fertile_effect    # float (modifer, property of seeds)
  409.   attr_accessor :fertillizer_terrain # hash
  410.   attr_accessor :seed_optimal_water   # optimal times to water this seed per stage
  411.   attr_accessor :seed_max_water       # plant will die if watered more than this many times per stage
  412.   attr_accessor :seed_base_harvest  # maximum output from seed when calculating harvest
  413.   attr_accessor :seed_max_fertillizer # dies after this much fertilizer is applied
  414.   attr_accessor :water_amount_uses    # amount of times item can be used for water before needing to be refilled
  415.   attr_accessor :water_available_uses # amount of available water
  416.   attr_accessor :seed_water_min    # min times seed should be watered per stage
  417.   attr_accessor :seed_base_harvest_min # min harvest specified instead of base amount
  418.   attr_accessor :seed_base_harvest_max # max of harvest range if specified instead of base amount
  419.  
  420.   def garden_item_default_values
  421.     @seed_loop = false
  422.     @seed_stages = 0
  423.     @seed_rate = 0
  424.     @seed_events = []
  425.     @seed_name = nil
  426.     @loop_stage = 0
  427.     @seed_terrain = nil
  428.     @fertillizer_rate = 0.0
  429.     @fertile_effect = 0.0
  430.     fertillizer_terrain = nil
  431.     @seed_optimal_water = 0
  432.     @seed_max_water = 1<<31
  433.     @seed_base_harvest = GardenRa::BaseHarvest
  434.     @seed_max_fertillizer = 0.8
  435.     @water_amount_uses = -1
  436.     @water_available_uses = 0
  437.     @seed_water_min = 0
  438.     @clears_crops = false
  439.     @seed_base_harvest_min = @seed_base_harvest
  440.     @seed_base_harvest_max = @seed_base_harvest
  441.   end
  442.   #----------------------------------------------------------------------------
  443.   # * Item is a representation of a seed?
  444.   #----------------------------------------------------------------------------
  445.   def is_garden_seed?
  446.     @seed_rate > 0
  447.   end
  448.   #----------------------------------------------------------------------------
  449.   # * Item is a representation of Fertillizer?
  450.   #----------------------------------------------------------------------------
  451.   def is_fertillizer?
  452.     @fertillizer_rate > 0
  453.   end
  454.   #----------------------------------------------------------------------------
  455.   # * Item is a representation of a watering container?
  456.   #----------------------------------------------------------------------------
  457.   def is_waterer?
  458.     @water_amount_uses > -1
  459.   end
  460.   #----------------------------------------------------------------------------
  461.   # * Item clears the crop infront of the player when it's used
  462.   #----------------------------------------------------------------------------
  463.   def clears_crops?
  464.     @clears_crops
  465.   end
  466.   #----------------------------------------------------------------------------
  467.   # * Terrains which this seed/fertillizer can be placed on
  468.   #----------------------------------------------------------------------------
  469.   def garden_terrains(tag)
  470.     if is_garden_seed?
  471.       return true if @seed_terrain.nil?
  472.       return @seed_terrain[tag]
  473.     else
  474.       return true if @fertillizer_terrain.nil?
  475.       return @fertillizer_terrain[tag]
  476.     end
  477.   end
  478.   #----------------------------------------------------------------------------
  479.   # * The seed/fertillizer can be placed anywhere?
  480.   #----------------------------------------------------------------------------
  481.   def garden_ok_anywhere?
  482.     @fertillizer_terrain.nil? && @seed_terrain.nil?
  483.   end
  484.   #----------------------------------------------------------------------------
  485.   # * Set the Terrain Tags for a Seed
  486.   #----------------------------------------------------------------------------
  487.   def set_seed_terrains(tags)
  488.     split_tags_era(tags, @seed_terrain={})
  489.   end
  490.   #----------------------------------------------------------------------------
  491.   # * Set the Terrain Tags for Fertillizer
  492.   #----------------------------------------------------------------------------
  493.   def set_fertillizer_terrains(tags)
  494.     split_tags_era(tags, @fertillizer_terrain={})
  495.   end
  496.   #----------------------------------------------------------------------------
  497.   # * Split Tags - Helper method to reduce repetitive code when loading in
  498.   #     terrain tag data
  499.   #----------------------------------------------------------------------------
  500.   def split_tags_era(tags, v)
  501.     tags.split(",").each{ |tag|
  502.       v[tag.strip.to_i] = true
  503.     }
  504.   end
  505.   #----------------------------------------------------------------------------
  506.   # * Update Waterer Description - modify the description of water containers
  507.   #     to show the currently available water and the maximum amount of water.
  508.   #----------------------------------------------------------------------------
  509.   def update_waterer_description(orig = false)
  510.     @org_desc_gd = @description if orig
  511.    
  512.     lines = @org_desc_gd.split(/[\r\n]+/)
  513.     lpos = lines.length-1
  514.  
  515.     carrying =  "Current Water: #{@water_available_uses}"
  516.     capacity =  "Max: #{@water_amount_uses}"
  517.    
  518.     return @description = @org_desc_gd+carrying<<" "<<capacity if lpos < 0
  519.    
  520.     last = lines[lpos]
  521.    
  522.     last = "#{last} #{carrying} #{capacity}\n"
  523.     lines[lpos] = last
  524.     accum = ""
  525.     lines.each{ |line|
  526.       accum<<line<<"\r\n"
  527.     }
  528.     @description = accum
  529.   end
  530.   #----------------------------------------------------------------------------
  531.   # * Modify the water available in a watering container
  532.   #----------------------------------------------------------------------------
  533.   def mod_waterer_available_uses(mod)
  534.     @water_available_uses += mod
  535.     if @water_available_uses < 0
  536.       @water_available_uses = 0
  537.     elsif @water_available_uses > @water_amount_uses
  538.       @water_available_uses = @water_amount_uses
  539.     end
  540.     update_waterer_description
  541.   end # mod_waterer_available_uses
  542. end # RPG::UsableItem
  543.  
  544. #==============================================================================
  545. # ** RPG::MapInfo
  546. #==============================================================================
  547. class RPG::MapInfo
  548.   attr_accessor :erosion_rate
  549.   attr_accessor :erosion_value
  550. end # RPG::MapInfo
  551.  
  552. #==============================================================================
  553. # ** GardenRa
  554. #     Module containing script settings as well as the helper method plant_seed
  555. #     which will plant a seed on the map.
  556. #==============================================================================
  557. module GardenRa
  558.   # The default map to pull events from
  559.   SeedMap = 2              
  560.  
  561.   # Default growth rate
  562.   DefGrowRate = 70          
  563.  
  564.   # Default stages per event
  565.   StagesPerEvent = 5      
  566.  
  567.   # Will show the fertillized locations when map loaded
  568.   ShowFertillizer = true    
  569.  
  570.   # Ignore the next 'n' commands when turning if TurnFirst
  571.   TurnDelay = 4            
  572.  
  573.   # Plant seeds even if theres an event at the position
  574.   PlantOntop = false
  575.  
  576.   # Symbol for key which allows planting/fertillizing infront of the player
  577.   Front = :A
  578.  
  579.   # False if you want to hide the text popups that show up when harvesting
  580.   ShowTextPopups = true
  581.  
  582.   # True if you want to use an image from a file for fertillizer
  583.   UseSheetData = true
  584.  
  585.   # Default amount the will be harvested from plants with no base amount specified
  586.   BaseHarvest = 7
  587.  
  588.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  589.   # Specify the Graphic you want to use as fertillizer here. The graphic should
  590.   # be stored inside Graphics/Characters.
  591.   #
  592.   # FertName is the name of the file with the Fertillizer graphic in it.
  593.   #
  594.   # Index is the index of the set of images you want to use from the file you
  595.   # specified (for example, in the default spritesheets 8 sets of images are
  596.   # specified per file). The index sould range from 0 - 7
  597.   #
  598.   # FertRow is the row you want to use as the animation for the fertillizer.
  599.   #
  600.   # FertFreq is how quickly the animation should iterate.
  601.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  602.  
  603.   # Name of the file with the fertillizer image, the file should be stored in
  604.   #   Graphics/Characters
  605.   FertName = '$Fertillizer'
  606.  
  607.   # The index of the set of images you want to use from the file specified above
  608.   #   can be 0 - 7 in the default engine
  609.   FertIndex = 0
  610.  
  611.   # The row of the set of images to use based on the specifed file.
  612.   #   with the default engine this value should range from 0 - 3
  613.   FertRow = 0
  614.  
  615.   # How quickly the graphic for the fertillizer should change.
  616.   FertFreq = 24
  617.  
  618.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  619.   # SS is a hash representing the self switches in the game, add addtional keys
  620.   # if you're using additional self switches for your game. I.e. if you were
  621.   # using a self switch 'E' in your project you would change the hash to look
  622.   # like:
  623.   #   SS = { 0 => false, 1 => 'A', 2 => 'B', 3 => 'C', 4 => 'D', 5 => 'E' }
  624.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  625.   SS = { 0 => false, 1 => 'A', 2 => 'B', 3 => 'C', 4 => 'D' }
  626.  
  627.   # The internal common event for using fertillizer
  628.   CE_Place_Fertillizer = Proc.new{ |id, is_item|
  629.     front = Input.press?(GardenRa::Front)
  630.  
  631.     xy = $game_temp.garden_seed_temp_xy_helper(id, front)
  632.     rate = $data_items[id].fertillizer_rate
  633.     $game_map.add_fertillizer(rate, [[xy[0],xy[1]]])
  634.   }
  635.  
  636.   # The internal common event for using a seed
  637.   CE_Plant_Seeds = Proc.new{ |id, is_item|
  638.     item = is_item ? $data_items[id] : $data_skills[id]
  639.     front = Input.press?(GardenRa::Front)
  640.     xy = $game_temp.garden_seed_temp_xy_helper(id, front)
  641.     GardenRa.plant_seed(item, $game_system.add_plant, true, {:x=>xy[0],:y=>xy[1]})
  642.   }
  643.  
  644.   Harvest_Crop = Proc.new{ |item_id, intp, destroy|
  645.     h=intp.harvest_garden_plant(destroy)
  646.     item = $data_items[item_id]
  647.     $game_party.gain_item(item, as_int = h.to_i)
  648.    
  649.     return unless (scene = SceneManager.scene).is_a?(Scene_Map) && GardenRa::ShowTextPopups
  650.     spm = scene.instance_eval('@spriteset')
  651.    
  652.     plms= as_int < 0 ? "" : "+"
  653.     spm.add_spgt_to_spm("#{plms}#{as_int} #{item.name}") # Add a spiggot to a spim!
  654.   }
  655.  
  656.   Clear_Crop = Proc.new{
  657.     map = $game_map
  658.     seeds_to_clear = $game_temp.temp_seed_clear
  659.     seeds_to_clear.each{ |ev|
  660.    
  661.       plant_id = ev.plant.plant_id #~*
  662.       $game_system.destroy_plant(ev.plant.plant_id)
  663.     }
  664.     $game_temp.temp_seed_clear = [] # reset temp data after access
  665.   }
  666.  
  667.   #----------------------------------------------------------------------------
  668.   # ** Regular Expressions
  669.   #     Be sure to maintain the parenthesis if you're goint to modify specific
  670.   #     words in the regular expressions (unless you're making the changes
  671.   #     intentionally making of course).
  672.   #----------------------------------------------------------------------------
  673.   module RE
  674.    
  675.     # number stages of growth
  676.     Stages = /<Seed stages (\d+)>/i
  677.    
  678.     # do stages loop?
  679.     Loop = /<Seed loop (true|false|t|f)>/i
  680.    
  681.     # growth rate, larger means slower
  682.     Rate = /<Seed rate (\d+)>/i    
  683.    
  684.     # Can specify the name of the seed per item
  685.     SeedName = /<Seed name (.+)>/i  
  686.    
  687.     # The stage to be looped back to
  688.     LoopStage = /<Seed loop stage (\d+)>/i
  689.    
  690.     # The terrain tags a seed can be planted on
  691.     SeedTerrain = /<\s*Seed\s*terrain\s*(\d+\s*(?:,\s*\d+\s*)*)\s*>/i
  692.    
  693.     # Use to set an item as a fertillizer and give it a fertillizer concentration
  694.     Fertillizer = /<\s*Seed\s*Fertillizer\s*((?:\d+|)\.(?:\d+))\s*>/i
  695.    
  696.     # The effect that fertillizer has on this specific seed. The lower the value
  697.     #   provided, the more resistant the seed is to being fertillized.
  698.     FertileEffect = /<\s*Seed\s*Fertile\s*rate\s*((?:\d+|)\.(?:\d+))\s*>/i
  699.    
  700.     # Terrain where fertillizer can be placed
  701.     FertTerrain = /<\s*Seed\s*Fertillizer\s*terrain\s*(\d+\s*(?:,\s*\d+\s*)*)\s*>/i
  702.    
  703.     # The maximum concentration of fertillizer a plant can grow in.
  704.     MaxFertillizer = /<\s*Seed\s*max\s*fertillizer\s*((?:\d+|)\.(?:\d+))\s*>/i
  705.    
  706.     # The optimal amount of times that a plant should be watered during each
  707.     #   growth stage
  708.     OptimalWaterPerStage = /<\s*Seed\s*optimal\s*water\s*(\d+)\s*>/i
  709.    
  710.     # The plant will die if it is watered more than this many times on one stage
  711.     OverWatered = /<\s*Seed\s*max\s*water\s*(\d+)\s*>/i
  712.    
  713.     # Maximum base output from this plant, this value can be exceeded if the
  714.     #   plant is fertillized.
  715.     MaxHarvest = /<\s*Seed\s*harvest\s*(\d+)\s*>/i
  716.    
  717.     # Harvest range can be specified instead of a base harvest amount
  718.     HarvestRange = /<\s*Seed\s*harvest\s*(\d+)\s*-\s*(\d+)\s*>/i
  719.    
  720.     # The maximum amount of water a container can hold
  721.     SeedWatering = /<\s*water\s*container\s*(\d+)\s*>/i #
  722.    
  723.     # The minimum amount of times a seed must be watered per growth stage
  724.     SeedWateringMin = /<\s*Seed\s*min\s*water\s*(\d+)\s*>/i # minimum times a seedmust be watered per growth stage
  725.    
  726.     # How much the fertillizer will be reduced on this map when it is eroding
  727.     FertillizerErodeAmt = /<\s*Erosion\s*Value\s*((?:\d+|)\.(?:\d+))>/i
  728.    
  729.     # How quickly the map will erode, specified in frames
  730.     FertillizerErodeRate = /<\s*Erosion\s*Rate\s*(\d+)>/i
  731.    
  732.     # Item can be used to clear crops out of the way
  733.     ClearCrops = /<\s*clears\s*crops\s*(\d+|)\s*>/i
  734.   end # RE
  735.  
  736.   #----------------------------------------------------------------------------
  737.   # * Plant Seed
  738.   #   param: args[0] is the item (the seed) that is being planted
  739.   #   param: args[1] is the id of the plant
  740.   #   param: args[2] is true if the seed is being planted for the first time
  741.   #   param: args[3] is an options hash to be given to the EventEng script
  742.   #   param: args[4] is the position in item.seed_events which will be accessed to
  743.   #          get the event's id for the new seed.
  744.   #   param: args[5] is a numeric representation of what stage the plants growth
  745.   #          is on.
  746.   #----------------------------------------------------------------------------
  747.   def self.plant_seed(*args)
  748.    
  749.     item = args[0]
  750.     plant_id = args[1] # the unique plant id this event is associated with
  751.     planting = args[2]
  752.     opts = (t = args[3]) ? t : {} # optional
  753.     pos = (t = args[4]) ? t : 0   # optional
  754.     stage = (t = args[5]) ? t : 1 # optional
  755.    
  756.     options = {
  757.       :map_id => GardenRa::SeedMap,
  758.       :x => $game_player.x,
  759.       :y => $game_player.y,
  760.       :persist => false,
  761.       :dir => 2,
  762.       :SS => {} # hash of self switches can be passed ({:A => true...})
  763.     }.merge(opts)
  764.    
  765.     t = $game_system.plant_info(plant_id)
  766.    
  767.     t[:item] = item
  768.     t[:pos] = pos
  769.     t[:cur_stage] = stage
  770.    
  771.     t[:max_fertile] ||= item.seed_max_fertillizer
  772.     t[:grow_frames] ||= item.seed_rate  
  773.     t[:loop] ||= item.seed_loop
  774.     t[:loop_stage] ||= item.loop_stage
  775.     t[:fertile_effect] ||= item.fertile_effect
  776.    
  777.     e_id = item.seed_events[t[:pos]]
  778.     event = EventSpawn.spawn_event(options[:map_id], e_id, options[:x],
  779.               options[:y], options[:persist], options[:dir], options[:SS])
  780.     event.start_plant(plant_id, planting) unless event.nil?# Only time a garden object is created
  781.   end # plant_seed
  782.   #----------------------------------------------------------------------------
  783.   # Self switch which corresponds to param: stage
  784.   #----------------------------------------------------------------------------
  785.   def self.stage_to_ss(stage)
  786.     SS[(stage-1) % GardenRa::StagesPerEvent]
  787.   end # stage_to_ss
  788.  
  789. end # GardenRa
  790.  
  791. #==============================================================================
  792. # ** DataManager
  793. #     Loads item data for fertillizers and seeds
  794. #==============================================================================
  795. module DataManager
  796.   #----------------------------------------------------------------------------
  797.   # * Alias - load_database
  798.   #----------------------------------------------------------------------------
  799.   class <<self
  800.     alias load_garden_seed_pl_ntags load_database
  801.   end
  802.   #----------------------------------------------------------------------------
  803.   # * Load Database
  804.   #----------------------------------------------------------------------------
  805.   def self.load_database
  806.     load_garden_seed_pl_ntags
  807.     load_tags_garden_seed_itm
  808.   end
  809.   #----------------------------------------------------------------------------
  810.   # * Load Tags
  811.   #----------------------------------------------------------------------------
  812.   def self.load_tags_garden_seed_itm
  813.     iter = [$data_items, $data_skills]
  814.     @tmp_map = load_data(sprintf("Data/Map%03d.rvdata2", GardenRa::SeedMap))
  815.     hv_err_msg = "A harvest base amount and harvest range was specified for"
  816.     iter.each do |set|
  817.       set.each_with_index do |item, i|
  818.         next unless item
  819.        
  820.         item.garden_item_default_values
  821.        
  822.         item.note.split(/[\r\n]+/).each do |line|
  823.           case line
  824.           when GardenRa::RE::Stages
  825.             item.seed_stages = $1.to_i
  826.           when GardenRa::RE::Loop
  827.             item.seed_loop = $1.eql?("true") || $1.eql?("t")
  828.           when GardenRa::RE::Rate
  829.             item.seed_rate = $1.to_i
  830.           when GardenRa::RE::SeedName
  831.             item.seed_name = $1
  832.           when GardenRa::RE::LoopStage
  833.             item.loop_stage = $1.to_i
  834.           when GardenRa::RE::SeedTerrain
  835.             item.set_seed_terrains($1)
  836.           when GardenRa::RE::Fertillizer
  837.             item.fertillizer_rate = $1.to_f
  838.           when GardenRa::RE::FertileEffect
  839.             item.fertile_effect = $1.to_f
  840.           when GardenRa::RE::FertTerrain
  841.             item.set_fertillizer_terrains($1)
  842.           when GardenRa::RE::OptimalWaterPerStage
  843.             item.seed_optimal_water = $1.to_i
  844.           when GardenRa::RE::OverWatered
  845.             item.seed_max_water = $1.to_i
  846.           when GardenRa::RE::MaxHarvest
  847.             if item.seed_base_harvest_min != item.seed_base_harvest_max
  848.               dt = " #{item.is_a?(RPG::Skill) ? "skill" : "item"} #{item.id}"
  849.               raise hv_err_msg << dt
  850.             end
  851.             item.seed_base_harvest = $1.to_i
  852.           when GardenRa::RE::HarvestRange
  853.             if item.seed_base_harvest != GardenRa::BaseHarvest
  854.               dt = " #{item.is_a?(RPG::Skill) ? "skill" : "item"} #{item.id}"
  855.               raise hv_err_msg << dt
  856.             end
  857.             item.seed_base_harvest_min = $1.to_i
  858.             item.seed_base_harvest_max = $2.to_i
  859.           when GardenRa::RE::MaxFertillizer
  860.             item.seed_max_fertillizer = $1.to_f
  861.           when GardenRa::RE::SeedWatering
  862.             item.water_available_uses = item.water_amount_uses = $1.to_i
  863.             item.update_waterer_description(true)
  864.             item.is_unique_rpgbi = true
  865.           when GardenRa::RE::SeedWateringMin
  866.             item.seed_water_min = $1.to_i
  867.           when GardenRa::RE::ClearCrops
  868.             item.clears_crops = $1.to_i
  869.           end
  870.         end
  871.        
  872.         load_seed_events(i,item.instance_of?(RPG::Item))
  873.        
  874.       end # set.each_with_index
  875.     end # iter.each
  876.   end # load_tags_garden_seed_itm
  877.   #----------------------------------------------------------------------------
  878.   # * Load seed events - store the event data
  879.   #----------------------------------------------------------------------------
  880.   def self.load_seed_events(i, is_item)
  881.     item = is_item ? $data_items[i] : $data_skills[i]
  882.     temp_hash = {}
  883.     item.seed_events = []
  884.     events = @tmp_map.events
  885.     name = !(s = item.seed_name).nil? ? s : item.name
  886.     events.values.each do |ev|
  887.       next unless ev
  888.       case ev.name
  889.       when  /^#{name} (\d+)\s*$/i
  890.         temp_hash[$1.to_i] = ev.id    # temporarily store the events in a hash
  891.       end
  892.     end
  893.    
  894.     keys = temp_hash.keys.sort!                          # order the events
  895.     keys.each{ |k| item.seed_events.push(temp_hash[k]) } # store events in order
  896.   end # load_seed_events
  897.  
  898. end # DataManager
  899.  
  900. #==============================================================================
  901. # ** Garden_Object
  902. #     The representation of a plant.
  903. #==============================================================================
  904. class Garden_Object
  905.   attr_reader :low
  906.   attr_reader :plant_id
  907.   attr_reader :fertillized
  908.   #----------------------------------------------------------------------------
  909.   # * Initialize
  910.   #----------------------------------------------------------------------------
  911.   def initialize(plant_id, ev_id, planting = false)
  912.     @low = true
  913.     @ev_id = ev_id
  914.     @plant_id = plant_id
  915.     @p_info = $game_system.plant_info(@plant_id)
  916.    
  917.     load_grow_data
  918.     apply_fertillizer if planting
  919.     store_init_data
  920.     store_xy
  921.   end
  922.   #----------------------------------------------------------------------------
  923.   # * Apply Fertillizer
  924.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  925.   #   The Fertillizer's effect is calculated by multplying the fertile_effect of
  926.   #   the seed with the fertilizer_rate of the of its location on the map and
  927.   #   then applying that value to @grow_frames.
  928.   #   Example:
  929.   #     A spot on the map with a fertillizer concentration of .5 applied  to a
  930.   #     seed which grows every 50 frames with a "fertile_effect" of .9 would
  931.   #     end up with a grow_rate of 0.9*0.5*50 = 22.5.
  932.   #----------------------------------------------------------------------------
  933.   def apply_fertillizer
  934.     f_data = $game_system.fertillizer_data
  935.     ev = $game_map.events[@ev_id]
  936.     x,y = ev.x, ev.y
  937.     f_rate = f_data[[x,y]]
  938.    
  939.     return if !f_rate
  940.    
  941.     f_effect = @p_info[:item].fertile_effect
  942.     f_effect = !f_effect.nil? ? f_effect : (@p_info[:item].fertile_effect = 1)
  943.     f_rate = !f_rate.nil? ? f_rate + (f_rate * f_effect) : 1
  944.    
  945.     update_fertile_input(f_rate)
  946.     new_gf = [@grow_frames * (1-f_rate),1].max.to_i
  947.    
  948.     @p_info[:grow_frames] = @grow_frames = new_gf
  949.   end
  950.   #----------------------------------------------------------------------------
  951.   # * Update Fertillizer Input
  952.   #----------------------------------------------------------------------------
  953.   def update_fertile_input(rate)
  954.     @p_info[:fertile_input] = rate
  955.   end
  956.   #----------------------------------------------------------------------------
  957.   # * Store position
  958.   #----------------------------------------------------------------------------
  959.   def store_xy
  960.     event = $game_map.events[@ev_id]
  961.     @p_info[:x], @p_info[:y] = event.x, event.y
  962.   end
  963.   #----------------------------------------------------------------------------
  964.   # * Plant id should be added to the game system before making a garden object
  965.   #----------------------------------------------------------------------------
  966.   def load_grow_data
  967.     update_grow_frame((t = @p_info[:base_frame]) ? t : $game_system.garden_timer)
  968.     @grow_frames = (t = @p_info[:grow_frames]) ? t : GardenRa::DefGrowRate
  969.     @simple = (t = @p_info[:simple]) ? t : true      # literal
  970.     @loop = (t = @p_info[:loop]) ? t : false         # literal
  971.     @loop_stage = (t = @p_info[:loop_stage]) ? t : 1 #literal
  972.   end
  973.   #----------------------------------------------------------------------------
  974.   # * Update Grow Frame
  975.   #----------------------------------------------------------------------------
  976.   def update_grow_frame(frame = @base_frame)
  977.     @p_info[:base_frame] = @base_frame = frame
  978.   end
  979.   #----------------------------------------------------------------------------
  980.   # * Store Init Data
  981.   #----------------------------------------------------------------------------
  982.   def store_init_data
  983.     @p_info[:grow_frames] = @grow_frames
  984.     @p_info[:simple] = @simple
  985.     @p_info[:loop] = @loop
  986.     @p_info[:loop_stage] = @loop_stage
  987.     @p_info[:event_id] = @ev_id
  988.   end
  989.   #----------------------------------------------------------------------------
  990.   # * Loop Stage
  991.   #----------------------------------------------------------------------------
  992.   def loop_stage
  993.     @p_info[:loop_stage]
  994.   end
  995.   #----------------------------------------------------------------------------
  996.   # * Last Stage
  997.   #----------------------------------------------------------------------------
  998.   def last_stage
  999.     @p_info[:item].seed_stages
  1000.   end
  1001.   #----------------------------------------------------------------------------
  1002.   # * Update
  1003.   #----------------------------------------------------------------------------
  1004.   def update
  1005.     check_should_die
  1006.     return if @p_info[:dead]
  1007.     return if (needs_to_loop = stage == item.seed_stages) && !@loop
  1008.     return if !@loop && stage == last_stage
  1009.     if need_jump?
  1010.       jump_ahead
  1011.     else
  1012.       update_grow(needs_to_loop)
  1013.     end
  1014.   end
  1015.   #----------------------------------------------------------------------------
  1016.   # * Modify the times the plant has been watered
  1017.   #----------------------------------------------------------------------------
  1018.   def mod_times_watered(st,fn,reset=true,mod=0)
  1019.     $game_system.mod_times_watered(@plant_id, loop_stage, last_stage, reset, mod)
  1020.   end
  1021.   #----------------------------------------------------------------------------
  1022.   # * Does the plant need to 'jump' to the correct stage after not having been
  1023.   #     updated for awhile. (Not on scene map or the map is being reloaded
  1024.   #     after the player was transferred to it for the first time in some time)
  1025.   #----------------------------------------------------------------------------
  1026.   def need_jump?
  1027.     ($game_system.garden_timer - @p_info[:base_frame]) > @grow_frames
  1028.   end
  1029.   #----------------------------------------------------------------------------
  1030.   # * Update grow
  1031.   #----------------------------------------------------------------------------
  1032.   def update_grow(should_loop = false)
  1033.     if (gt = $game_system.garden_timer) - @p_info[:base_frame] == @grow_frames
  1034.      
  1035.       mod_times_watered(loop_stage, last_stage) if should_loop
  1036.       update_grow_frame(gt)
  1037.      
  1038.      
  1039.       if should_loop && @loop
  1040.         old_stage = @p_info[:cur_stage]
  1041.         st_per = GardenRa::StagesPerEvent
  1042.         old_pos = pos
  1043.         update_stage(@p_info[:loop_stage])
  1044.         nxt_ev
  1045.        
  1046.       else
  1047.         on_grow
  1048.       end
  1049.       $game_map.refresh
  1050.     end
  1051.   end
  1052.   #----------------------------------------------------------------------------
  1053.   # * Are Any Selfswitches On? - Currently only used for debugging,
  1054.   #     can be removed
  1055.   #----------------------------------------------------------------------------
  1056.   def any_ss_on?
  1057.     EventSpawn::Constants::SS.each{|l|
  1058.       return true if $game_self_switches[[$game_map.map_id, @ev_id, l]]
  1059.     }
  1060.     return false
  1061.   end
  1062.   #----------------------------------------------------------------------------
  1063.   # * Update Stage
  1064.   #----------------------------------------------------------------------------
  1065.   def update_stage(new_stage)
  1066.     @p_info[:cur_stage] = new_stage
  1067.     @p_info[:pos] = (@p_info[:cur_stage] - 1)/GardenRa::StagesPerEvent
  1068.   end
  1069.   #----------------------------------------------------------------------------
  1070.   # * On Last Stage
  1071.   #----------------------------------------------------------------------------
  1072.   def on_last_stage
  1073.     stage == last_stage
  1074.   end
  1075.   #----------------------------------------------------------------------------
  1076.   # * Stage
  1077.   #----------------------------------------------------------------------------
  1078.   def stage
  1079.     @p_info[:cur_stage]
  1080.   end
  1081.   #----------------------------------------------------------------------------
  1082.   # * Pos
  1083.   #----------------------------------------------------------------------------
  1084.   def pos
  1085.     @p_info[:pos]
  1086.   end
  1087.   #----------------------------------------------------------------------------
  1088.   # * Times Watered
  1089.   #----------------------------------------------------------------------------
  1090.   def times_watered(st = stage)
  1091.     (@p_info[:watered_vals]||={})[st]||=0
  1092.   end
  1093.   #----------------------------------------------------------------------------
  1094.   # * Max Water
  1095.   #----------------------------------------------------------------------------
  1096.   def max_water
  1097.     item.seed_max_water
  1098.   end
  1099.   #----------------------------------------------------------------------------
  1100.   # * On plant grow by default all plants are 'simple' but feel free to write
  1101.   #     more complicated growth patterns for plants.
  1102.   #----------------------------------------------------------------------------
  1103.   def on_grow
  1104.     grow_simple if @simple
  1105.   end
  1106.   #----------------------------------------------------------------------------
  1107.   # * Kill the plant
  1108.   #----------------------------------------------------------------------------
  1109.   def kill_plant(should_kill=true)
  1110.     @p_info[:dead] = true
  1111.   end
  1112.   #----------------------------------------------------------------------------
  1113.   # * Minimum number of times the plant should be watered per stage
  1114.   #----------------------------------------------------------------------------
  1115.   def min_water
  1116.     item.seed_water_min
  1117.   end
  1118.   #----------------------------------------------------------------------------
  1119.   # * Should the plant advance to the next stage?
  1120.   #----------------------------------------------------------------------------
  1121.   def is_at_stage_tic
  1122.     $game_system.garden_timer - @p_info[:base_frame] == @grow_frames
  1123.   end
  1124.   #----------------------------------------------------------------------------
  1125.   # * Check if the plant should still be alive
  1126.   #----------------------------------------------------------------------------
  1127.   def check_should_die(about_to_jump = false)
  1128.    
  1129.     # can't dry up once on the last stage
  1130.     dried_up = (is_at_stage_tic || about_to_jump) && !(min = min_water).nil? &&
  1131.       times_watered < min && !on_last_stage
  1132.     roots_molded = !(max = max_water).nil? && times_watered > max
  1133.    
  1134.     if dried_up || roots_molded
  1135.       return kill_plant
  1136.     end
  1137.     # if fertillizer is too concentrated or if watered too many times, @p_info[:dead] = true
  1138.     return unless (cur=@p_info[:fertile_input]) && (max = @p_info[:max_fertile])
  1139.     if cur > max
  1140.       return kill_plant
  1141.     end
  1142.   end
  1143.   #----------------------------------------------------------------------------
  1144.   # * Dead?
  1145.   #----------------------------------------------------------------------------
  1146.   def dead?
  1147.     @p_info[:dead]
  1148.   end
  1149.   #----------------------------------------------------------------------------
  1150.   # * Harvest
  1151.   #     Returns an integer value calculated from the amount of times the plant
  1152.   #     was watered at each stage, the optimal amount of times for it to be
  1153.   #     watered, and the amount of fertillizer that was applied to it.
  1154.   #----------------------------------------------------------------------------
  1155.   def harvest
  1156.     return 0 if dead?
  1157.    
  1158.     min=min_harvest_range
  1159.     max=max_harvest_range
  1160.    
  1161.     base_output = min == max && min == GardenRa::BaseHarvest ? base_harvest : rand(max-min) + min + 1
  1162.    
  1163.     fertillizer = fertillizer_concentration
  1164.     offset_output = base_output * fertillizer + base_output
  1165.     offset = 1-((t=number_stages_not_watered_optimally.to_f)/last_stage)
  1166.     total_harvest = offset_output * offset
  1167.    
  1168.     print "harvest: \n"
  1169.     print "   base_output = #{base_output}\n"
  1170.     print "   number_stages_not_watered_optimally = #{t}\n"
  1171.     print "   fertillizer = #{fertillizer}\n"
  1172.     print "   offset_output = #{offset_output}\n"
  1173.     print "   offset = #{offset}\n"
  1174.     print "   total harvest = #{total_harvest}\n"
  1175.    
  1176.     return total_harvest.to_i
  1177.   end
  1178.   #----------------------------------------------------------------------------
  1179.   # * Fertillizer concentration
  1180.   #----------------------------------------------------------------------------
  1181.   def fertillizer_concentration
  1182.     @p_info[:fertile_input] ||= 0
  1183.   end
  1184.   #----------------------------------------------------------------------------
  1185.   # * Not including the last stage
  1186.   #----------------------------------------------------------------------------
  1187.   def number_stages_not_watered_optimally
  1188.     count = 0
  1189.     optimal_water_per_st = optimal_water
  1190.     (1...last_stage).each{ |st|
  1191.       count += 1 if times_watered(st) != optimal_water_per_st
  1192.     }
  1193.     count
  1194.   end
  1195.   #----------------------------------------------------------------------------
  1196.   # * Optimal times the plant should be watered on each stage
  1197.   #----------------------------------------------------------------------------
  1198.   def optimal_water
  1199.     item.seed_optimal_water
  1200.   end
  1201.   #----------------------------------------------------------------------------
  1202.   # * Base harvest amount
  1203.   #----------------------------------------------------------------------------
  1204.   def base_harvest
  1205.     item.seed_base_harvest
  1206.   end
  1207.   #----------------------------------------------------------------------------
  1208.   # * Minimum of harvest range
  1209.   #----------------------------------------------------------------------------
  1210.   def min_harvest_range
  1211.     item.seed_base_harvest_min
  1212.   end
  1213.   #----------------------------------------------------------------------------
  1214.   # * Maximum of harvest range
  1215.   #----------------------------------------------------------------------------
  1216.   def max_harvest_range
  1217.     item.seed_base_harvest_max
  1218.   end
  1219.   #----------------------------------------------------------------------------
  1220.   #   The default garden plant will grow by turning its selfswitches on
  1221.   #   sequentially from A to D and then turning them all off and repeating.
  1222.   #----------------------------------------------------------------------------
  1223.   def grow_simple
  1224.     stage = (@p_info[:cur_stage] += 1)
  1225.     map_id = $game_map.map_id
  1226.     ch = GardenRa.stage_to_ss(stage)
  1227.     if !ch
  1228.       handle_last_page
  1229.     else
  1230.       turn_on_ss(ch)
  1231.     end
  1232.    
  1233.     e = $game_map.events[@ev_id]
  1234.     e.refresh unless e.nil? # nil when queuing a new event for the plant
  1235.   end
  1236.   #----------------------------------------------------------------------------
  1237.   # * The item associated with this plant
  1238.   #----------------------------------------------------------------------------
  1239.   def item
  1240.     @p_info[:item]
  1241.   end
  1242.   #----------------------------------------------------------------------------
  1243.   # * The last stage that the current event has stored for this plant. I.e.
  1244.   #     the next event for this plants growth cycle will need to be placed on
  1245.   #     the map.
  1246.   #----------------------------------------------------------------------------
  1247.   def handle_last_page
  1248.     nxt_ev if item.seed_events[@p_info[:pos]+1]
  1249.   end # handle_last_page
  1250.   #----------------------------------------------------------------------------
  1251.   # * Replace the plants event, removes the current event associated with the
  1252.   #     plant and queues a new one to be placed on the map.
  1253.   #----------------------------------------------------------------------------
  1254.   def replace_plant_event(opts={})
  1255.     map = $game_map
  1256.     p_info = $game_system.plant_info(@plant_id)
  1257.    
  1258.     event = map.events[@ev_id]
  1259.     options = { :x => event.x, :y => event.y, :persist => false }.merge(opts)
  1260.    
  1261.     map.destroy_event_any(@ev_id)
  1262.     map.add_seed_to_plant(p_info[:item], @plant_id, false, options, p_info[:pos],
  1263.       p_info[:cur_stage])
  1264.   end
  1265.   #----------------------------------------------------------------------------
  1266.   # * Jump to the proper stage when reloading the plant on the map.
  1267.   #----------------------------------------------------------------------------
  1268.   def jump_ahead
  1269.    
  1270.     dead = check_should_die(true) # param just tells method the plant wants to jump
  1271.     return if dead
  1272.    
  1273.     map, sys = $game_map, $game_system
  1274.     st_per = GardenRa::StagesPerEvent
  1275.     jump = ((gt = sys.garden_timer) - @p_info[:base_frame]) / @grow_frames # stages to skip
  1276.     update_grow_frame(@p_info[:base_frame]+jump*@grow_frames)#((gt-@grow_frames) + ((gt - @base_frame) % @grow_frames))
  1277.     old_stage = @p_info[:cur_stage]
  1278.    
  1279.     # calculate roll over if @loop
  1280.     loop_back = @loop && (n_st = jump + old_stage) > @p_info[:item].seed_stages
  1281.     mod_times_watered(loop_stage, last_stage) if loop_back
  1282.     new_stage = false
  1283.    
  1284.     excess = 0
  1285.     if loop_back
  1286.       # loop in between:
  1287.       loop_btw = @p_info[:item].seed_stages - (@p_info[:loop_stage]-1)
  1288.       excess = n_st - @p_info[:item].seed_stages
  1289.       new_stage = (@p_info[:loop_stage]-1) + (excess % loop_btw)
  1290.     end
  1291.    
  1292.     # store updated plant data
  1293.     old_pos = (pos-1)/st_per
  1294.     update_stage(new_stage ? new_stage : [old_stage + jump, item.seed_stages].min)
  1295.     nxt_ev
  1296.   end
  1297.   #----------------------------------------------------------------------------
  1298.   # * Queue up a new plant('seed to be planted') when the current plant has
  1299.   #     moved through all of the stages for its the current event
  1300.   #----------------------------------------------------------------------------
  1301.   def nxt_ev
  1302.     @p_info[:pos] = (@p_info[:cur_stage]-1)/GardenRa::StagesPerEvent
  1303.     ch = GardenRa.stage_to_ss(@p_info[:cur_stage])
  1304.     opts = !ch ? {} : {:SS => {ch.to_sym => true}}
  1305.     replace_plant_event(opts)
  1306.   end
  1307.   #----------------------------------------------------------------------------
  1308.   # * Turn on Selfswich
  1309.   #----------------------------------------------------------------------------
  1310.   def turn_on_ss(ch, is_on = true)
  1311.     $game_self_switches[[$game_map.map_id, @ev_id, ch]] = is_on unless !ch
  1312.   end
  1313.   #----------------------------------------------------------------------------
  1314.   # * Reset Selfswitches
  1315.   #----------------------------------------------------------------------------
  1316.   def reset_ss
  1317.     EventSpawn::Constants::SS.each{|l| turn_on_ss(l,false)}
  1318.   end
  1319.   #----------------------------------------------------------------------------
  1320.   # *
  1321.   #----------------------------------------------------------------------------
  1322.   #def destroy_self
  1323.   #  $game_system.destroy_plant(@plant_id)
  1324.   #  map.destroy_event_any(@ev_id)
  1325.   #end
  1326.   #----------------------------------------------------------------------------
  1327.   # * Print what memory looks like
  1328.   #----------------------------------------------------------------------------
  1329.   def debug
  1330.     print "\n"
  1331.     print "debug data:"
  1332.     print "     plant_id = #{@plant_id} event_id = #{@ev_id}\n"
  1333.     print "     @p_info = #{@p_info}\n"
  1334.     print "     garden timer = #{$game_system.garden_timer}\n"
  1335.     print "     current stage = #{@p_info[:cur_stage]}\n"
  1336.     print "     pos = #{pos}\n"
  1337.     print "     self switches A = #{$game_self_switches[[$game_map.map_id, @ev_id, "A"]]}\n"
  1338.     print "     self switches B = #{$game_self_switches[[$game_map.map_id, @ev_id, "B"]]}\n"
  1339.     print "     self switches C = #{$game_self_switches[[$game_map.map_id, @ev_id, "C"]]}\n"
  1340.     print "     self switches D = #{$game_self_switches[[$game_map.map_id, @ev_id, "D"]]}\n"
  1341.   end
  1342.  
  1343. end # Garden_Object
  1344.  
  1345. #==============================================================================
  1346. # ** Game_System
  1347. #==============================================================================
  1348. class Game_System
  1349.  
  1350.   attr_accessor :garden_timer
  1351.   attr_accessor :garden_plants # map_id => event_id => :sym => value
  1352.  
  1353.   Epsilon_GS_Era = 0.00001 # Fertillizer removed if concentration is < this value
  1354.   #----------------------------------------------------------------------------
  1355.   # * Alias - Initialize
  1356.   #----------------------------------------------------------------------------
  1357.   alias init_g_plt_hash_get_data_on_reload initialize
  1358.   def initialize
  1359.     @garden_timer, @plant_ids = 0, 0
  1360.     @garden_plants, @garden_fertillizer = {},{} # maps ids to base frames
  1361.    
  1362.     init_g_plt_hash_get_data_on_reload
  1363.   end
  1364.   #----------------------------------------------------------------------------
  1365.   # * Alias - on_after_load
  1366.   #----------------------------------------------------------------------------
  1367.   alias on_after_ld_add_evs_garden_to_m on_after_load
  1368.   def on_after_load
  1369.     on_after_ld_add_evs_garden_to_m
  1370.     $game_map.place_all_plants
  1371.   end
  1372.   #----------------------------------------------------------------------------
  1373.   # * Update Garden Timer
  1374.   #----------------------------------------------------------------------------
  1375.   def update_garden(erode = true)
  1376.     @garden_timer += 1 unless @garden_timer.nil?
  1377.     update_erosion if erode
  1378.   end
  1379.   #----------------------------------------------------------------------------
  1380.   # * Erode the fertillizer away from all of the maps in the game.
  1381.   #----------------------------------------------------------------------------
  1382.   def update_erosion
  1383.     @garden_fertillizer.keys.each{ |map_id| # ids for each map with fertillizer
  1384.      
  1385.       minfo = $data_mapinfos[map_id]
  1386.       map_erode_rate = minfo.erosion_rate
  1387.       map_erode_val = minfo.erosion_value
  1388.       valid = !map_erode_rate.nil? && !map_erode_val.nil?
  1389.      
  1390.       next unless valid && @garden_timer % map_erode_rate == 0
  1391.      
  1392.       fert_xys = @garden_fertillizer[map_id]
  1393.       fert_xys.keys.each{ |xy| # fertillizer values for each xy
  1394.         next unless !fert_xys[xy].nil?
  1395.         fert_xys[xy] = [fert_xys[xy]-map_erode_val,0.0].max
  1396.        
  1397.         if fert_xys[xy] < Epsilon_GS_Era
  1398.           fert_xys.delete(xy)
  1399.           remove_saved_highlight(xy[0],xy[1],map_id)
  1400.           $game_map.setup_map_highlights_era(map_id)
  1401.           update_erosion_helper_del_hl(map_id)
  1402.         end
  1403.        
  1404.       }
  1405.     }
  1406.   end
  1407.   #----------------------------------------------------------------------------
  1408.   # * Update the highlights if current map is $game_map
  1409.   #----------------------------------------------------------------------------
  1410.   def update_erosion_helper_del_hl(map_id)
  1411.     return unless $game_map.map_id == map_id
  1412.     return unless (scene = SceneManager.scene).is_a?(Scene_Map)
  1413.     spm = scene.instance_eval('@spriteset')
  1414.     spm.refresh_highlights unless spm.nil?
  1415.   end
  1416.   #----------------------------------------------------------------------------
  1417.   # * Plant Info
  1418.   #     @garden_plants[map_id][:fertillized] is a hash mapping x,y values to
  1419.   #     booleans. True if that location is fertillized.
  1420.   #----------------------------------------------------------------------------
  1421.   def plant_info(plant_id = nil)
  1422.     map_id = $game_map.map_id
  1423.     !plant_id.nil? ? (return @garden_plants[map_id][plant_id]) : (return @garden_plants[map_id])
  1424.   end
  1425.   #----------------------------------------------------------------------------
  1426.   # * Removes a plants information from the game_system
  1427.   #----------------------------------------------------------------------------
  1428.   def destroy_plant(plant_id, map_id = nil)
  1429.     map = $game_map
  1430.     map_id = map_id.nil? ? map.map_id : map_id
  1431.    
  1432.     gpm = @garden_plants[map_id]
  1433.     ev_id = gpm[plant_id][:event_id]
  1434.    
  1435.     map.destroy_event_any(ev_id) if map_id == map.map_id
  1436.     gpm.delete(plant_id)
  1437.   end
  1438.   #----------------------------------------------------------------------------
  1439.   # * Get the Fertillizer Data For the Current Map
  1440.   #----------------------------------------------------------------------------
  1441.   def fertillizer_data
  1442.     map_id = $game_map.map_id
  1443.     return @garden_fertillizer[map_id]||={}
  1444.   end
  1445.   #----------------------------------------------------------------------------
  1446.   # * Next Plant Id
  1447.   #----------------------------------------------------------------------------
  1448.   def next_plant_id
  1449.     @plant_ids + 1
  1450.   end
  1451.   #----------------------------------------------------------------------------
  1452.   # * Add Plant
  1453.   #----------------------------------------------------------------------------
  1454.   def add_plant(map_id=nil)
  1455.     map_id = map_id.nil? && $game_map.nil? ? map_id : $game_map.map_id
  1456.     return if map_id.nil?
  1457.     @garden_plants[map_id][@plant_ids+=1] = {}
  1458.     return @plant_ids
  1459.   end
  1460.   #----------------------------------------------------------------------------
  1461.   # * Plant Added
  1462.   #----------------------------------------------------------------------------
  1463.   def plant_added?(id)
  1464.     @plant_ids + 1 > id
  1465.   end
  1466.   #----------------------------------------------------------------------------
  1467.   # * Water the Plant with id = param: plant_id
  1468.   #----------------------------------------------------------------------------
  1469.   def water_plant_era(plant_id, times=1)
  1470.     p_info = plant_info(plant_id)
  1471.     stage = p_info[:cur_stage]
  1472.     p_info[:watered_vals] ||= {}
  1473.     p_info[:watered_vals][stage] ||= 0
  1474.     p_info[:watered_vals][stage] += times
  1475.   end
  1476.   #----------------------------------------------------------------------------
  1477.   # * Modify the amount of times a plant has been watered
  1478.   #     param: first, the stage to start modifying at
  1479.   #     param: last, the last stage in the range to modify
  1480.   #----------------------------------------------------------------------------
  1481.   def mod_times_watered(plant_id, first, last, reset = true, mod=0)
  1482.     p_info = plant_info(plant_id)
  1483.     w_vals = p_info[:watered_vals] ||= {}
  1484.     (first..last).each{ |stage|
  1485.       w_vals[stage] = reset ? 0 : (w_vals[stage] ? [w_vals[stage]+mod,0].min : 0)
  1486.     }
  1487.   end # mod_times_watered
  1488. end # Game_System
  1489.  
  1490. #==============================================================================
  1491. # ** Game_Map
  1492. #     Load plant and fertillizer data for the current map when setting up.
  1493. #     Allow plants to be queue
  1494. #==============================================================================
  1495. class Game_Map
  1496.   #----------------------------------------------------------------------------
  1497.   # * Alias - setup
  1498.   #----------------------------------------------------------------------------
  1499.   alias set_up_garden_ch_for_old_hash setup
  1500.   def setup(map_id)
  1501.     $game_system.garden_plants[map_id] ||= {}
  1502.    
  1503.     @era_seeds_to_plant = []
  1504.     # redraw spriteset for scene map
  1505.    
  1506.     set_up_garden_ch_for_old_hash(map_id)
  1507.    
  1508.     setup_erosion_vals
  1509.   end
  1510.   #----------------------------------------------------------------------------
  1511.   # * Alias - update
  1512.   #----------------------------------------------------------------------------
  1513.   alias upd_pl_seeds_af_update_hash_new_item update
  1514.   def update(*args)
  1515.     upd_pl_seeds_af_update_hash_new_item(*args)
  1516.     plant_seeds_after_update
  1517.    
  1518.     place_all_plants if @want_to_place_plants
  1519.   end
  1520.   #----------------------------------------------------------------------------
  1521.   # * Alias - setup_events
  1522.   #----------------------------------------------------------------------------
  1523.   alias setup_evs_add_plant_evs_for_map setup_events
  1524.   def setup_events
  1525.     setup_evs_add_plant_evs_for_map
  1526.    
  1527.     # make plant events from data inside Game_System
  1528.     place_all_plants
  1529.   end
  1530.  
  1531.   #----------------------------------------------------------------------------
  1532.   # * Place all plants back on the map when reloading
  1533.   #----------------------------------------------------------------------------
  1534.   def place_all_plants
  1535.    
  1536.     return !(@want_to_place_plants = true) if !SceneManager.scene.is_a?(Scene_Map)
  1537.     plant_data = $game_system.plant_info
  1538.     plant_data.keys.each{ |plant_id|
  1539.       p_info = plant_data[plant_id]
  1540.       x, y = p_info[:x], p_info[:y]
  1541.      
  1542.       ch = GardenRa.stage_to_ss(cur_stage = p_info[:cur_stage])
  1543.       ss = !ch ? {} : {ch.to_sym => true}
  1544.      
  1545.       GardenRa.plant_seed(p_info[:item], plant_id, false, {:x=>x, :y=>y, :SS=>ss}, p_info[:pos],
  1546.         cur_stage)
  1547.     }
  1548.     refresh
  1549.     @want_to_place_plants = false
  1550.   end
  1551.   #----------------------------------------------------------------------------
  1552.   # * Plant the queued seeds
  1553.   #----------------------------------------------------------------------------
  1554.   def plant_seeds_after_update
  1555.     @era_seeds_to_plant.each{ |args| GardenRa.plant_seed(*args) }
  1556.     @era_seeds_to_plant = []
  1557.   end
  1558.   #----------------------------------------------------------------------------
  1559.   # * Add Seed to Plant - Queue up planting a seed
  1560.   #----------------------------------------------------------------------------
  1561.   def add_seed_to_plant(*args)
  1562.     @era_seeds_to_plant.push(args) # Order is not checked but shouldn't be modified
  1563.   end
  1564.   #----------------------------------------------------------------------------
  1565.   # * Setup Erosion Values
  1566.   #----------------------------------------------------------------------------
  1567.   def setup_erosion_vals
  1568.     dmap = $data_mapinfos[@map_id]
  1569.     if dmap.erosion_rate.nil? || dmap.erosion_value.nil?
  1570.       @map.note.split(/[\r\n+]/).each{ |line|
  1571.         case line
  1572.         when GardenRa::RE::FertillizerErodeAmt
  1573.           dmap.erosion_value = $1.to_f
  1574.         when GardenRa::RE::FertillizerErodeRate
  1575.           dmap.erosion_rate = $1.to_i
  1576.         end
  1577.       }
  1578.     end
  1579.   end
  1580.   #----------------------------------------------------------------------------
  1581.   # * Seed Location Ok?
  1582.   #----------------------------------------------------------------------------
  1583.   def seed_location_ok?(x,y)
  1584.     if !GardenRa::PlantOntop # Don't plant ontop of non erased events
  1585.       events_xy(x,y).each{ |ev| return false if ev && !ev.instance_eval('@erase')}
  1586.     end
  1587.     return true
  1588.   end
  1589.   #----------------------------------------------------------------------------
  1590.   # * Add Fertillizer
  1591.   #----------------------------------------------------------------------------
  1592.   def add_fertillizer(rate, range)
  1593.     map_info = $game_system.fertillizer_data
  1594.    
  1595.     range.each{ |xy|
  1596.       x,y = xy[0], xy[1]
  1597.       t = map_info[xy]
  1598.       map_info[xy] = t ? t + (t * rate) : rate
  1599.      
  1600.       events_xy(x,y).each{ |ev| ev.apply_fertillizer} #update plants w/ fertillizer
  1601.      
  1602.       if GardenRa::UseSheetData
  1603.         sh = Sheet_Data.new(GardenRa::FertName,GardenRa::FertIndex,GardenRa::FertRow)
  1604.       end
  1605.      
  1606.       spm = SceneManager.scene.instance_eval("@spriteset")
  1607.       spm.add_highlight(:x => x, :y => y, :sh => sh, :retain => true, :opacity => 255) if GardenRa::ShowFertillizer
  1608.     }
  1609.   end # add_fertillizer
  1610.  
  1611. end # Game_Map
  1612.  
  1613. #==============================================================================
  1614. # ** Game_Event
  1615. #     Associates an event with a plant.
  1616. #==============================================================================
  1617.  
  1618. class Spriteset_Map
  1619.   attr_accessor :map_id
  1620. end
  1621.  
  1622. class Game_Event
  1623.  
  1624.   attr_accessor :plant
  1625.   attr_accessor :opacity
  1626.   #----------------------------------------------------------------------------
  1627.   # * Alias - Initialize
  1628.   #----------------------------------------------------------------------------
  1629.   alias initialize_gard_ev__grow initialize
  1630.   def initialize(*args)
  1631.     initialize_gard_ev__grow(*args)
  1632.     #create_garden_obj
  1633.   end
  1634.  
  1635.   # show plant under player? (for use when planting)
  1636.   def low; @plant ? @plant.low : false; end
  1637.   #----------------------------------------------------------------------------
  1638.   # * Alias - Screen Z
  1639.   #----------------------------------------------------------------------------
  1640.   alias garden_plant_screen_z_ed screen_z
  1641.   def screen_z
  1642.     return garden_plant_screen_z_ed if @plant.nil?
  1643.     ls = @plant.stage == @plant.last_stage
  1644.     if !ls && (p=$game_player).real_x.to_i == @x && p.real_y.to_i == @y
  1645.       return garden_plant_screen_z_ed - 1 #show under player when planting
  1646.     else
  1647.       return garden_plant_screen_z_ed
  1648.     end
  1649.   end
  1650.   #----------------------------------------------------------------------------
  1651.   # * Alias - Update
  1652.   #----------------------------------------------------------------------------
  1653.   alias update_ch_garden_obj_ud update
  1654.   def update
  1655.     update_ch_garden_obj_ud
  1656.     @plant.update unless @plant.nil?
  1657.   end
  1658.   #----------------------------------------------------------------------------
  1659.   # * Start Plant
  1660.   #----------------------------------------------------------------------------
  1661.   def start_plant(plant_id, planting = false)
  1662.     @plant = Garden_Object.new(plant_id, @id, planting)
  1663.   end
  1664.   #----------------------------------------------------------------------------
  1665.   # * Plant Dead?
  1666.   #----------------------------------------------------------------------------
  1667.   def garden_plant_dead?
  1668.     return !@plant.nil? && @plant.dead?
  1669.   end
  1670.  
  1671.   #--------------------------------------------------------------------------
  1672.   # * Alias move_straight - update the location of the plant in game_system
  1673.   #--------------------------------------------------------------------------
  1674.   alias mve_strght_mod_edit_upd_str_gard_upd move_straight
  1675.   def move_straight(dir, turn_ok = true)
  1676.     mve_strght_mod_edit_upd_str_gard_upd(dir)
  1677.     update_garden_plant_xy if @plant
  1678.   end
  1679.  
  1680.   #--------------------------------------------------------------------------
  1681.   # * Alias move_diagonal- update the location of the plant in game_system
  1682.   #--------------------------------------------------------------------------
  1683.   alias mv_diag_gard_upd_pl_posit_upd move_diagonal
  1684.   def move_diagonal(horz, vert)
  1685.     mv_diag_gard_upd_pl_posit_upd(horz, vert)
  1686.     update_garden_plant_xy if @plant.plant_id
  1687.   end
  1688.   #----------------------------------------------------------------------------
  1689.   # * Update plant position if the event moves
  1690.   #----------------------------------------------------------------------------
  1691.   def update_garden_plant_xy
  1692.     p_info = $game_system.plant_info(@plant.plant_id)
  1693.     p_info[:x], p_info[:y] = @x, @y
  1694.   end
  1695.   #----------------------------------------------------------------------------
  1696.   # * Apply Fertillizer
  1697.   #----------------------------------------------------------------------------
  1698.   def apply_fertillizer
  1699.     return unless @plant
  1700.     return if @plant.dead? || @plant.stage == @plant.last_stage # on last stage or dead
  1701.     @plant.apply_fertillizer # applier fertillizer from current location to growth rate
  1702.   end # apply_fertillizer
  1703.  
  1704. end # Game_Event
  1705.  
  1706. #==============================================================================
  1707. # ** Scene_Base
  1708. #     * Update the garden timer when inside any scene.
  1709. #==============================================================================
  1710. class Scene_Base
  1711.   #----------------------------------------------------------------------------
  1712.   # * Alias - update
  1713.   #----------------------------------------------------------------------------
  1714.   alias upd_timer_for_farm_evs update
  1715.   def update
  1716.     upd_timer_for_farm_evs
  1717.     update_garden_timer
  1718.   end
  1719.   #----------------------------------------------------------------------------
  1720.   # * Update Garden Timer
  1721.   #----------------------------------------------------------------------------
  1722.   def update_garden_timer
  1723.     $game_system.update_garden
  1724.   end
  1725.  
  1726. end # Scene_Base
  1727.  
  1728. #==============================================================================
  1729. # ** Scene_Map
  1730. #      Add gui for selecting a watering container.
  1731. #==============================================================================
  1732. class Scene_Map < Scene_Base
  1733.   #----------------------------------------------------------------------------
  1734.   # * Start
  1735.   #----------------------------------------------------------------------------
  1736.   alias st_add_cd_draw_sp_highl_era start
  1737.   def start
  1738.     st_add_cd_draw_sp_highl_era
  1739.   end
  1740.   #----------------------------------------------------------------------------
  1741.   # * Create Waterer Options Window
  1742.   #----------------------------------------------------------------------------
  1743.   def create_window_waterer_opts
  1744.     @waterer_opts_window = Window_ShowOptsEra.new(300,200,82,79)
  1745.     @waterer_opts_window.viewport = @viewport
  1746.     @waterer_opts_window.set_handler(:ok, method(:process_choice_era))
  1747.     @waterer_opts_window.set_handler(:cancel, method(:on_ch_cancel_era))
  1748.     @waterer_opts_window.hide
  1749.   end
  1750.   #----------------------------------------------------------------------------
  1751.   # * Create Water Question Window
  1752.   #----------------------------------------------------------------------------
  1753.   def create_window_water_question
  1754.     x,y = Graphics.width * 0.2, Graphics.height * 0.7
  1755.     w,h = 300, 55
  1756.     @waterer_question_window = Window_WatererText.new(x,y,w,h)
  1757.     @waterer_question_window.viewport = @viewport
  1758.     @waterer_question_window.hide
  1759.   end
  1760.   #----------------------------------------------------------------------------
  1761.   # * Create Water Container Selection Window
  1762.   #----------------------------------------------------------------------------
  1763.   def create_waterer_window
  1764.     @waterer_window = Window_SelectWaterer.new(0,100,230,210)
  1765.     @waterer_window.viewport = @viewport
  1766.     @waterer_window.set_handler(:ok, method(:on_waterer_ok))
  1767.     @waterer_window.set_handler(:cancel, method(:on_waterer_cancel))
  1768.     @waterer_window.hide
  1769.   end
  1770.   #----------------------------------------------------------------------------
  1771.   # * Create Water Container Data Window
  1772.   #----------------------------------------------------------------------------
  1773.   def create_waterer_data_window
  1774.     x,y = Graphics.width * 0.2, Graphics.height * 0.7
  1775.     w,h = 380, 55
  1776.     @waterer_data_window = Window_WatererData.new(0,Graphics.height-45,w,47)
  1777.     @waterer_data_window.give_item_window(@waterer_window)
  1778.     @waterer_data_window.hide
  1779.     @waterer_data_window.deactivate
  1780.   end
  1781.   #----------------------------------------------------------------------------
  1782.   # * Create Water Number Window
  1783.   #----------------------------------------------------------------------------
  1784.   def create_waterer_amount_window
  1785.     @waterer_number_window = Window_WaterAmt.new(300,200,100,65)
  1786.     @waterer_number_window.viewport = @viewport
  1787.     @waterer_number_window.hide
  1788.     @waterer_number_window.set_handler(:ok, method(:waterer_number_ok))
  1789.     @waterer_number_window.set_handler(:cancel, method(:waterer_number_cancel))
  1790.   end
  1791.   #----------------------------------------------------------------------------
  1792.   # * Create Water Number Text Window
  1793.   #----------------------------------------------------------------------------
  1794.   def create_waterer_amount_help_window
  1795.     x,y = Graphics.width * 0.2, Graphics.height * 0.7
  1796.     w,h = 300, 55
  1797.     @waterer_amount_text_window = Window_WatererText.new(x,y,w,h)
  1798.     @waterer_amount_text_window.viewport = @viewport
  1799.     @waterer_amount_text_window.hide
  1800.   end
  1801.   #----------------------------------------------------------------------------
  1802.   # * Create Select Name Text Window
  1803.   #----------------------------------------------------------------------------
  1804.   def create_select_name_waterer_window
  1805.     w = @waterer_window.width
  1806.     @waterer_selection_name = Window_WatererText.new(0,50,w,47)
  1807.     @waterer_selection_name.viewport = @viewport
  1808.     @waterer_selection_name.hide
  1809.   end
  1810.   #----------------------------------------------------------------------------
  1811.   # * Reorient Watering Windows
  1812.   #----------------------------------------------------------------------------
  1813.   def waterer_reorient_windows_era
  1814.     @waterer_window.y = @waterer_selection_name.y + @waterer_selection_name.height
  1815.     @waterer_data_window.width = @waterer_window.width
  1816.     @waterer_data_window.height = @waterer_selection_name.height
  1817.    
  1818.     @waterer_question_window.x = Graphics.width - @waterer_question_window.width
  1819.     @waterer_question_window.y = @waterer_opts_window.y + @waterer_opts_window.height
  1820.     @waterer_opts_window.x = Graphics.width - @waterer_opts_window.width
  1821.    
  1822.     @waterer_number_window.x = Graphics.width - @waterer_number_window.width
  1823.     @waterer_amount_text_window.x = @waterer_question_window.x
  1824.     @waterer_amount_text_window.y = @waterer_number_window.y + @waterer_number_window.height
  1825.   end
  1826.   #----------------------------------------------------------------------------
  1827.   # * Process Choice
  1828.   #----------------------------------------------------------------------------
  1829.   def process_choice_era
  1830.     if @waterer_opts_window.index == 0
  1831.       want_to_water_era
  1832.     else
  1833.       on_ch_cancel_era
  1834.     end
  1835.   end
  1836.   #----------------------------------------------------------------------------
  1837.   # * On Number Selection 'OK'
  1838.   #----------------------------------------------------------------------------
  1839.   def waterer_number_ok
  1840.     @waterer_item_era.mod_waterer_available_uses(-(n=@waterer_number_window.number))
  1841.     $game_system.water_plant_era(@target_plant_id_era,n)
  1842.     hide_waterers_number
  1843.     $game_player.freeze_era(false)
  1844.   end
  1845.   #----------------------------------------------------------------------------
  1846.   # * Number Selection 'CANCEL'
  1847.   #----------------------------------------------------------------------------
  1848.   def waterer_number_cancel
  1849.     hide_waterers_number
  1850.     $game_player.freeze_era(false)
  1851.   end
  1852.   #----------------------------------------------------------------------------
  1853.   # * Water Container Selection 'CANCEL'
  1854.   #----------------------------------------------------------------------------
  1855.   def waterer_number_cancel
  1856.     hide_waterers_number
  1857.     $game_player.freeze_era(false)
  1858.   end
  1859.   #----------------------------------------------------------------------------
  1860.   # * Hide Water Number Windows
  1861.   #----------------------------------------------------------------------------
  1862.   def hide_waterers_number
  1863.     @waterer_number_window.hide
  1864.     @waterer_amount_text_window.hide
  1865.   end
  1866.   #----------------------------------------------------------------------------
  1867.   # * Water Container Selection 'OK'
  1868.   #----------------------------------------------------------------------------
  1869.   def on_waterer_ok
  1870.     @waterer_item_era = @waterer_window.item
  1871.     @waterer_number_window.give_waterer(@waterer_item_era)
  1872.    
  1873.     uses = @waterer_item_era.water_available_uses
  1874.     @waterer_window.deactivate
  1875.     hide_secondary_waterer_windows
  1876.      
  1877.     @waterer_number_window.show
  1878.     @waterer_number_window.activate
  1879.      
  1880.      
  1881.     @waterer_amount_text_window.give_text("How many times do you want to water it?")
  1882.     @waterer_amount_text_window.show
  1883.   end
  1884.   #----------------------------------------------------------------------------
  1885.   # * Water Selection 'CANCEL'
  1886.   #----------------------------------------------------------------------------
  1887.   def on_waterer_cancel
  1888.     hide_secondary_waterer_windows
  1889.     $game_player.freeze_era(false)
  1890.   end
  1891.   #----------------------------------------------------------------------------
  1892.   # * Yes-No Selection 'CANCEL'
  1893.   #----------------------------------------------------------------------------
  1894.   def on_ch_cancel_era
  1895.     @waterer_opts_window.hide
  1896.     @waterer_question_window.hide
  1897.     @waterer_opts_window.deactivate
  1898.     $game_player.freeze_era(false)
  1899.   end
  1900.   #----------------------------------------------------------------------------
  1901.   # * Hide Specific Watering Windows
  1902.   #----------------------------------------------------------------------------
  1903.   def hide_secondary_waterer_windows
  1904.     @waterer_selection_name.hide
  1905.     @waterer_data_window.hide
  1906.     @waterer_window.hide
  1907.   end
  1908.   #----------------------------------------------------------------------------
  1909.   # * Water the Plant with param: plant_id
  1910.   #----------------------------------------------------------------------------
  1911.   def water_plant(plant_id)
  1912.     $game_player.freeze_era(true)
  1913.    
  1914.     @target_plant_id_era = plant_id
  1915.    
  1916.     create_waterer_window
  1917.     create_waterer_data_window
  1918.     create_window_water_question
  1919.     create_window_waterer_opts
  1920.     create_waterer_amount_window
  1921.     create_waterer_amount_help_window
  1922.     create_select_name_waterer_window
  1923.     waterer_reorient_windows_era
  1924.    
  1925.     @waterer_question_window.show
  1926.     @waterer_opts_window.show
  1927.     @waterer_opts_window.select(0)
  1928.     @waterer_opts_window.activate
  1929.   end
  1930.   #----------------------------------------------------------------------------
  1931.   # * Decided to water the plant
  1932.   #----------------------------------------------------------------------------
  1933.   def want_to_water_era
  1934.     @waterer_question_window.hide
  1935.     @waterer_opts_window.hide
  1936.     @waterer_opts_window.deactivate
  1937.    
  1938.     @waterer_selection_name.show
  1939.     @waterer_selection_name.give_text("Choose a Watering Container")
  1940.    
  1941.     @waterer_window.select(0)
  1942.     @waterer_window.show
  1943.     @waterer_window.activate#@w = Window_MenuCommand.new#Window_SelectWaterer.new(0,0,300,200)
  1944.     @waterer_window.refresh
  1945.     @waterer_data_window.show
  1946.   end
  1947.   #----------------------------------------------------------------------------
  1948.   # * Dispose Windows
  1949.   #----------------------------------------------------------------------------
  1950.   def disp_wins_era(clean = true)
  1951.     $game_player.freeze_era(false)
  1952.     @waterer_window.dispose unless @waterer_window.nil?
  1953.     @waterer_opts_window.dispose unless @waterer_opts_window.nil?
  1954.     @waterer_data_window.dispose unless @waterer_data_window.nil?
  1955.     @waterer_question_window.dispose unless @waterer_question_window.nil?
  1956.     @waterer_number_window.dispose unless @waterer_number_window.nil?
  1957.     @waterer_amount_text_window.dispose unless @waterer_amount_text_window.nil?
  1958.     @waterer_selection_name.dispose unless @waterer_selection_name.nil?
  1959.     clean_wins_era if clean
  1960.   end
  1961.   #----------------------------------------------------------------------------
  1962.   # * Set windows to nil, called after disposing just to be safe
  1963.   #----------------------------------------------------------------------------
  1964.   def clean_wins_era
  1965.     @waterer_window = nil
  1966.     @waterer_opts_window = nil
  1967.     @waterer_data_window = nil
  1968.     @waterer_question_window = nil
  1969.     @waterer_number_window = nil
  1970.     @waterer_amount_text_window = nil
  1971.     @waterer_selection_name = nil
  1972.   end
  1973.   #----------------------------------------------------------------------------
  1974.   # * Update
  1975.   #----------------------------------------------------------------------------
  1976.   alias update_need_to_pl_seed_era update
  1977.   def update
  1978.     update_need_to_pl_seed_era
  1979.     disp_wins_era if scene_changing?
  1980.   end # update
  1981.  
  1982. end # Scene_Map
  1983.  
  1984. #==============================================================================
  1985. # ** Sprite_Character
  1986. #==============================================================================
  1987. class Sprite_Character < Sprite_Base
  1988.   #----------------------------------------------------------------------------
  1989.   # * Alias - Update
  1990.   #----------------------------------------------------------------------------
  1991.   alias update_pr_tone_garden_debug update
  1992.   def update
  1993.     update_pr_tone_garden_debug
  1994.     color_dead_garden_plant if garden_plant_dead_era?
  1995.   end
  1996.   #----------------------------------------------------------------------------
  1997.   # * Check if the Associated Plant Event is Dead
  1998.   #----------------------------------------------------------------------------
  1999.   def garden_plant_dead_era?
  2000.     return unless (c=@character).is_a?(Game_Event)
  2001.     c.garden_plant_dead?
  2002.   end
  2003.   #----------------------------------------------------------------------------
  2004.   # * Get the Color of a Dead Plant
  2005.   #----------------------------------------------------------------------------
  2006.   def color_dead_garden_plant
  2007.     tone.gray = 205
  2008.     tone.blue = -160
  2009.     tone.red = -160
  2010.     tone.green = -130
  2011.   end # color_dead_garden_plant
  2012. end # Sprite_Character
  2013.  
  2014. #==============================================================================
  2015. # ** Game_Player
  2016. #==============================================================================
  2017. class Game_Player < Game_Character
  2018.   #----------------------------------------------------------------------------
  2019.   # * Initialize
  2020.   #----------------------------------------------------------------------------
  2021.   alias init_add_t_del_var_for_more_nat_w initialize
  2022.   def initialize
  2023.     init_add_t_del_var_for_more_nat_w
  2024.     @turn_delay_era = 0
  2025.   end
  2026.   #----------------------------------------------------------------------------
  2027.   # * Alias, Check Event Triger There
  2028.   #----------------------------------------------------------------------------
  2029.   alias chk_ev_trigs_chk_to_water_first check_event_trigger_there
  2030.   def check_event_trigger_there(triggers)
  2031.     try_to_water_plants
  2032.     chk_ev_trigs_chk_to_water_first(triggers)
  2033.   end
  2034.   #----------------------------------------------------------------------------
  2035.   # * Alias - move_straight
  2036.   #----------------------------------------------------------------------------
  2037.   alias mov_straight_don_move_when_frozen move_straight
  2038.   def move_straight(*args)
  2039.     return if @frozen_era
  2040.     mov_straight_don_move_when_frozen(*args)
  2041.   end
  2042.   #----------------------------------------------------------------------------
  2043.   # * Try to Water Plants - ask player if they want to water a plant when
  2044.   #     checking for event triggers if the event is a plant.
  2045.   #----------------------------------------------------------------------------
  2046.   def try_to_water_plants
  2047.     return unless party_has_waterer_era?
  2048.     map = $game_map
  2049.     rx = map.round_x_with_direction(@x,@direction)
  2050.     ry = map.round_y_with_direction(@y,@direction)
  2051.    
  2052.     $game_map.events_xy(rx,ry).each{ |ev|
  2053.       next unless ev
  2054.       plant = ev.plant
  2055.       if plant && !ev.garden_plant_dead? && (plant.stage != plant.last_stage)
  2056.         SceneManager.scene.water_plant(ev.plant.plant_id)
  2057.       end
  2058.     }
  2059.   end
  2060.   #----------------------------------------------------------------------------
  2061.   # * Check if the party has a watering container
  2062.   #----------------------------------------------------------------------------
  2063.   def party_has_waterer_era?(full = false)
  2064.     items = $game_party.items
  2065.     items.each{|item|
  2066.       next unless is_waterer = item.is_waterer?
  2067.       curr, max = item.water_available_uses, item.water_amount_uses
  2068.      
  2069.       valid = full ? curr < max : curr > 0
  2070.       return true if is_waterer && valid
  2071.     }
  2072.     return false
  2073.   end
  2074.   #----------------------------------------------------------------------------
  2075.   # * Freeze the player when displying water container selection windows
  2076.   #----------------------------------------------------------------------------
  2077.   def freeze_era(stop = true)
  2078.     @frozen_era = stop
  2079.   end # freeze_era
  2080.  
  2081. end # Game_Player
  2082.  
  2083. #==============================================================================
  2084. # ** Game_BattlerBase
  2085. #     Add code to handle internal common events. The arguments are
  2086. #     being converted to strings when they're passed
  2087. #==============================================================================
  2088. class Game_BattlerBase
  2089.   #----------------------------------------------------------------------------
  2090.   # * Alias usable? - add checks looking for seeds, fertillizer, or clearer
  2091.   #----------------------------------------------------------------------------
  2092.   alias usa_elbasu_ube_garden_seed usable?
  2093.   def usable?(item)
  2094.     return can_clear_crop(item) if !item.nil? && item.clears_crops?
  2095.     return garden_area_valid?(item) if !item.nil? && item.is_garden_seed?
  2096.     return garden_area_valid?(item) if !item.nil? && item.is_fertillizer?
  2097.     usa_elbasu_ube_garden_seed(item)
  2098.   end
  2099.   #----------------------------------------------------------------------------
  2100.   # * Garden Area Valid - Check if a seed can be planted or if fertillizer can
  2101.   #     be placed based on the players current position.
  2102.   #----------------------------------------------------------------------------
  2103.   def garden_area_valid?(item)
  2104.     xy = []
  2105.    
  2106.     map, player = $game_map, $game_player
  2107.     px, py, d = player.x, player.y, player.direction
  2108.     sx,sy = map.round_x_with_direction(px, d), map.round_y_with_direction(py, d)
  2109.    
  2110.     is_fertillizer = item.is_fertillizer?
  2111.     f_ok = map.seed_location_ok?(sx,sy) || is_fertillizer
  2112.     c_ok = map.seed_location_ok?(px,py) || is_fertillizer
  2113.    
  2114.     front_ok = item.garden_terrains(map.terrain_tag(sx, sy)) && f_ok
  2115.     cent_ok = item.garden_terrains(map.terrain_tag(px, py)) && c_ok
  2116.     anywhere_ok = item.garden_ok_anywhere?
  2117.    
  2118.     id = item.id
  2119.     $game_temp.temp_seed_data[id] = {}
  2120.    
  2121.     hash = $game_temp.temp_seed_data[id]
  2122.     hash[:sx], hash[:sy] = sx, sy if front_ok
  2123.     hash[:px], hash[:py] = px, py if cent_ok || anywhere_ok
  2124.    
  2125.     front_ok || cent_ok || anywhere_ok
  2126.   end # garden_area_valid?
  2127.  
  2128.   #----------------------------------------------------------------------------
  2129.   # * Check if there are any crop close enough to be cleared.
  2130.   #----------------------------------------------------------------------------
  2131.   def can_clear_crop(item)
  2132.     map, player, gtemp = $game_map, $game_player, $game_temp
  2133.     dir = player.direction
  2134.    
  2135.    
  2136.     front_x = map.round_x_with_direction(player.x, dir)
  2137.     front_y = map.round_y_with_direction(player.y, dir)
  2138.     front_evs = map.events_xy(front_x, front_y) # getting events, may want to get
  2139.                                         # plant ids and delete the plants current
  2140.                                         # event if it turns out the plant can grow
  2141.                                         # a stage while trying to harvest.
  2142.    
  2143.     gtemp.temp_seed_clear = [] # erase previously stored events
  2144.    
  2145.     if (amt = item.clears_crops) <= 0
  2146.       pushed = false
  2147.       front_evs.each{ |ev|
  2148.         if !ev.plant.nil?
  2149.           gtemp.temp_seed_clear.push(ev)
  2150.           pushed = true
  2151.         end
  2152.       }
  2153.     # only check the front position unless a distance is specified
  2154.     else
  2155.       # calculate additional locations
  2156.       pushed = store_adjsdiag_temp_clearer(amt) || pushed
  2157.     end
  2158.    
  2159.     return pushed
  2160.   end
  2161.   #----------------------------------------------------------------------------
  2162.   # * Store plants at a distance of dist from game_player for removal.
  2163.   #----------------------------------------------------------------------------
  2164.   def store_adjsdiag_temp_clearer(dist)
  2165.     map, player, gtemp = $game_map, $game_player, $game_temp
  2166.     x, y = player.x, player.y
  2167.     need_check = []
  2168.     (0...dist).each{ |d|
  2169.       need_check = p_at_dist_plants_clear(need_check, d, x, y)
  2170.     }
  2171.     pushed = false
  2172.    
  2173.     # get all events within range that are plants
  2174.     need_check.each do |xy|
  2175.       evs = map.events_xy(xy[0], xy[1])
  2176.       evs.each{ |ev|
  2177.         next unless ev
  2178.         if !ev.plant.nil?
  2179.           gtemp.temp_seed_clear.push(ev)
  2180.           pushed = true
  2181.         end
  2182.       }
  2183.     end # need_check.each
  2184.     return pushed
  2185.   end # store_adjsdiag_temp_clearer
  2186.   #----------------------------------------------------------------------------
  2187.   # * Points in a circle at distsance: dist from x,y
  2188.   #----------------------------------------------------------------------------
  2189.   def p_at_dist_plants_clear(points, dist, x, y, opts = {})
  2190.     max = dist+1
  2191.     (0..dist).each{ |i|
  2192.       points.push([ x+i, y-(max-i)])
  2193.       points.push([x-i, y+(max-i)])
  2194.       points.push([x+(max-i), y+i])
  2195.       points.push([x-(max-i), y-i])
  2196.     }
  2197.     points
  2198.   end
  2199. end # Game_BattlerBase
  2200.  
  2201. #==============================================================================
  2202. # ** Game_Battler - Add support for when using items that are fertillizers or
  2203. #     seeds.
  2204. #==============================================================================
  2205. class Game_Battler < Game_BattlerBase
  2206.   #----------------------------------------------------------------------------
  2207.   # * Alias use_item - set up appropriate internal common events when
  2208.   #    fertillizer or seeds are used.
  2209.   #----------------------------------------------------------------------------
  2210.   alias usitm_use_ce_seed_mod_meti use_item
  2211.   def use_item(item)
  2212.     # Seed
  2213.     if item.is_garden_seed?
  2214.       strsym = "GardenRa::CE_Plant_Seeds"
  2215.       $game_temp.reserve_internal_ce(strsym.to_sym, item.id, item.is_a?(RPG::Item))
  2216.     end
  2217.    
  2218.     # Fertillizer
  2219.     if item.is_fertillizer?
  2220.       strsym = "GardenRa::CE_Place_Fertillizer"
  2221.       $game_temp.reserve_internal_ce(strsym.to_sym, item.id, item.is_a?(RPG::Item))
  2222.     end
  2223.    
  2224.     # Clearer
  2225.     if item.clears_crops?
  2226.       strsym = "GardenRa::Clear_Crop"
  2227.       $game_temp.reserve_internal_ce(strsym.to_sym)
  2228.     end
  2229.     usitm_use_ce_seed_mod_meti(item)
  2230.   end # use_item
  2231. end # Game_Battler
  2232.  
  2233. #==============================================================================
  2234. # ** Game_Temp
  2235. #     Functionality is added to support internal common events.
  2236. #==============================================================================
  2237. class Game_Temp
  2238.   attr_accessor :temp_seed_data
  2239.   attr_accessor :temp_seed_clear
  2240.   #----------------------------------------------------------------------------
  2241.   # * Alias initialize - added a helper hash
  2242.   #----------------------------------------------------------------------------
  2243.   alias init_gt_tini_gme_temp_tia initialize
  2244.   def initialize
  2245.     init_gt_tini_gme_temp_tia
  2246.     @temp_seed_data = {} # data stored when trying to plant a seed to prevent
  2247.                          # calculating the seeds placement location twice (once
  2248.                          # when checking if plantable and again when planting)
  2249.     @temp_seed_clear = [] # data stored when trying to clear a plant to prevent
  2250.                           # recalculation of the same information.
  2251.   end
  2252.   #----------------------------------------------------------------------------
  2253.   # * Alias - Clear Common Event, clear internal common events as well
  2254.   #----------------------------------------------------------------------------
  2255.   alias cce_cle_com_even_inter clear_common_event
  2256.   def clear_common_event
  2257.    
  2258.     # Only clear out the internal common event if one is found. This will allow
  2259.     # the real common event that was reserved to be used next time.
  2260.     if @internal_ce_sym
  2261.       @internal_ce_sym = false
  2262.       return @last_internal_ce = nil
  2263.     end
  2264.    
  2265.     cce_cle_com_even_inter
  2266.    
  2267.   end
  2268.   #----------------------------------------------------------------------------
  2269.   # * Alias - Common Event Reserved, reserve internal common events
  2270.   #----------------------------------------------------------------------------
  2271.   alias cer_comm_eve_reser_comresv common_event_reserved?
  2272.   def common_event_reserved?
  2273.     cer_comm_eve_reser_comresv || @internal_ce_sym
  2274.   end
  2275.   #----------------------------------------------------------------------------
  2276.   # * Alias method - Reserved Common Event, add functionality to return
  2277.   #     internal common events if one has been reserved.
  2278.   #----------------------------------------------------------------------------
  2279.   alias rescomev_rce_res_com_ev reserved_common_event
  2280.   def reserved_common_event
  2281.     if @internal_ce_sym # play the internal common event first, then the real one.
  2282.       return make_internal_ce
  2283.     else
  2284.       return rescomev_rce_res_com_ev
  2285.     end
  2286.   end
  2287.   #----------------------------------------------------------------------------
  2288.   # * Reserve Internal Common Event
  2289.   #----------------------------------------------------------------------------
  2290.   def reserve_internal_ce(sym, *args)
  2291.     @internal_ce_sym = sym
  2292.     @internal_ce_args = args
  2293.   end
  2294.   #----------------------------------------------------------------------------
  2295.   # * Make Internal Common Event
  2296.   #----------------------------------------------------------------------------
  2297.   def make_internal_ce
  2298.     return @last_internal_ce unless @last_internal_ce.nil?
  2299.     ce = RPG::CommonEvent.new
  2300.     ce.list = []
  2301.     ce.give_script(@internal_ce_sym.to_s, @internal_ce_args)
  2302.     ce.list.push(RPG::EventCommand.new)
  2303.     @last_internal_ce = ce
  2304.   end
  2305.   #----------------------------------------------------------------------------
  2306.   # * Garden Seed Placement-Position-Checking Helper
  2307.   #    Helper method to reduce repetitive similar code in the internal common
  2308.   #    events. Returns the xy position that the fertillizer or seed should be
  2309.   #    placed at.
  2310.   #----------------------------------------------------------------------------
  2311.   def garden_seed_temp_xy_helper(id, front)
  2312.     seed_data = @temp_seed_data.delete(id)
  2313.    
  2314.     sx, sy = seed_data[:sx], seed_data[:sy]
  2315.     px, py = seed_data[:px], seed_data[:py]
  2316.     fx, fy = nil, nil
  2317.    
  2318.     if front # want to plant in front of player
  2319.       if sx.nil? && sy.nil? # wanted to plant in front but couldn't
  2320.         fx,fy = px, py # so place at players x,y instead
  2321.       else
  2322.         fx,fy = sx, sy # plant in front
  2323.       end
  2324.     else # want to plant at player's location
  2325.       if px.nil? && py.nil? # wanted to plant at player's location but was blocked
  2326.         fx, fy = sx, sy
  2327.       else
  2328.         fx, fy = px, py
  2329.       end
  2330.     end # if front
  2331.    
  2332.     [fx, fy]
  2333.   end # garden_seed_temp_xy_helper
  2334.  
  2335. end # Game_Temp
  2336.  
  2337. #==============================================================================
  2338. # ** RPG::CommonEvent
  2339. #==============================================================================
  2340. class RPG::CommonEvent
  2341.   #----------------------------------------------------------------------------
  2342.   # * Give Script - Only pass in one line for now
  2343.   #----------------------------------------------------------------------------
  2344.   def give_script(proc_name, args)
  2345.     accum = ""
  2346.     args.each{ |v| accum.eql?("") ? accum<<"#{v}" : accum<<",#{v}" }
  2347.     proc_name<<".call("<<accum<<")"
  2348.     @list.push(RPG::EventCommand.new(355,0,[proc_name]))
  2349.   end # give_script
  2350.  
  2351. end # RPG::CommonEvent
  2352.  
  2353. #==============================================================================
  2354. # ** Window_SelectWaterer
  2355. #     A window shown in Scene_Map when selecting a water container to use when
  2356. #     watering a plant.
  2357. #==============================================================================
  2358. class Window_SelectWaterer < Window_ItemList
  2359.   #--------------------------------------------------------------------------
  2360.   # * Get Digit Count
  2361.   #--------------------------------------------------------------------------
  2362.   def col_max
  2363.     return 1
  2364.   end
  2365.   #--------------------------------------------------------------------------
  2366.   # * Include in Item List?
  2367.   #--------------------------------------------------------------------------
  2368.   def include?(item)
  2369.     item.is_a?(RPG::Item) && item.is_waterer? && item.water_available_uses > 0
  2370.   end
  2371.   #----------------------------------------------------------------------------
  2372.   # * Update
  2373.   #----------------------------------------------------------------------------
  2374.   def update
  2375.     super
  2376.     self.opacity += 25
  2377.   end
  2378.   #----------------------------------------------------------------------------
  2379.   # * Show
  2380.   #----------------------------------------------------------------------------
  2381.   def show
  2382.     super
  2383.     self.opacity = 0
  2384.   end # show
  2385.  
  2386. end # Window_SelectWaterer
  2387.  
  2388. #==============================================================================
  2389. # ** Window_WatererData
  2390. #     Displays how much water is left in the currently selected container when
  2391. #     choosing one to use to water a plant.
  2392. #==============================================================================
  2393. class Window_WatererData < Window_Base
  2394.   #----------------------------------------------------------------------------
  2395.   # * Initialize
  2396.   #----------------------------------------------------------------------------
  2397.   def initialize(*args)
  2398.     super(*args)
  2399.     self.opacity = 0
  2400.     self.windowskin = Bitmap.new(Graphics.width,300)
  2401.   end
  2402.   #----------------------------------------------------------------------------
  2403.   # * Give Item Window
  2404.   #----------------------------------------------------------------------------
  2405.   def give_item_window(w)
  2406.     @item_window = w
  2407.     @old = nil
  2408.   end
  2409.   #----------------------------------------------------------------------------
  2410.   # * Update
  2411.   #----------------------------------------------------------------------------
  2412.   def update
  2413.     super
  2414.    
  2415.     self.opacity += 25
  2416.     refresh if @old != item
  2417.   end
  2418.   #----------------------------------------------------------------------------
  2419.   # * Help Text
  2420.   #----------------------------------------------------------------------------
  2421.   def help_text
  2422.     return unless item
  2423.     e_str = "#{item.water_available_uses}/#{item.water_amount_uses}"
  2424.     "#{item.name}: #{e_str}"
  2425.   end
  2426.   #----------------------------------------------------------------------------
  2427.   # * Item
  2428.   #----------------------------------------------------------------------------
  2429.   def item
  2430.     return unless @item_window
  2431.     @item_window.item
  2432.   end
  2433.   #----------------------------------------------------------------------------
  2434.   # * Show
  2435.   #----------------------------------------------------------------------------
  2436.   def show
  2437.     super
  2438.     self.opacity = 0
  2439.   end
  2440.   #----------------------------------------------------------------------------
  2441.   # * Refresh
  2442.   #----------------------------------------------------------------------------
  2443.   def refresh
  2444.     @old = item
  2445.     contents.clear
  2446.     contents.font.size = 22
  2447.     draw_background(Rect.new(0,0,width,height))
  2448.     draw_text(0,0,width,line_height,help_text)
  2449.   end
  2450.   #----------------------------------------------------------------------------
  2451.   # * Draw Background
  2452.   #----------------------------------------------------------------------------
  2453.   def draw_background(rect)
  2454.     temp_rect = rect.clone
  2455.     temp_rect.width /= 2
  2456.     contents.gradient_fill_rect(temp_rect, back_color2, back_color1)
  2457.     temp_rect.x = temp_rect.width
  2458.     contents.gradient_fill_rect(temp_rect, back_color1, back_color2)
  2459.   end
  2460.   #--------------------------------------------------------------------------
  2461.   # * Get Background Color 1
  2462.   #--------------------------------------------------------------------------
  2463.   def back_color1
  2464.     Color.new(0, 0, 0, 192)
  2465.   end
  2466.   #--------------------------------------------------------------------------
  2467.   # * Get Background Color 2
  2468.   #--------------------------------------------------------------------------
  2469.   def back_color2
  2470.     Color.new(0, 0, 0, 0)
  2471.   end # back_color2
  2472.  
  2473. end # Window_WatererData
  2474.  
  2475. #==============================================================================
  2476. # ** Window_ShowOptsEra
  2477. #     Window displayed when the player is selecting whether or not they want
  2478. #     to water a plant.
  2479. #==============================================================================
  2480. class Window_ShowOptsEra < Window_Selectable
  2481.   #----------------------------------------------------------------------------
  2482.   # * Initialize
  2483.   #----------------------------------------------------------------------------
  2484.   def initialize(*args)
  2485.     super(*args)
  2486.     draw_text(7,0,70,line_height, "Yes")
  2487.     draw_text(7,25,70,line_height, "No")
  2488.   end
  2489.   #----------------------------------------------------------------------------
  2490.   # * Item Max
  2491.   #----------------------------------------------------------------------------
  2492.   def item_max
  2493.     return 2
  2494.   end
  2495.   def update
  2496.     super
  2497.     self.opacity += 25
  2498.   end
  2499.   #----------------------------------------------------------------------------
  2500.   # * Show
  2501.   #----------------------------------------------------------------------------
  2502.   def show
  2503.     super
  2504.     self.opacity = 0
  2505.   end
  2506.   #----------------------------------------------------------------------------
  2507.   # * Draw Item
  2508.   #----------------------------------------------------------------------------
  2509.   def draw_item(index)
  2510.     case index
  2511.     when 0
  2512.       return "Yes"
  2513.     when 1
  2514.       return "No"
  2515.     end
  2516.   end # draw_item
  2517.  
  2518. end # Window_ShowOptsEra
  2519.  
  2520. #==============================================================================
  2521. # ** Window_WatererText
  2522. #     Used to show windowed during Scene_Map
  2523. #==============================================================================
  2524. class Window_WatererText < Window_Base
  2525.   #----------------------------------------------------------------------------
  2526.   # * Initialize
  2527.   #----------------------------------------------------------------------------
  2528.   def initialize(*args)
  2529.     super(*args)
  2530.     self.opacity = 0
  2531.     refresh
  2532.   end
  2533.   #----------------------------------------------------------------------------
  2534.   # * Give Text
  2535.   #----------------------------------------------------------------------------
  2536.   def give_text(text)
  2537.     @text = text
  2538.     refresh
  2539.   end
  2540.   #----------------------------------------------------------------------------
  2541.   # * Update
  2542.   #----------------------------------------------------------------------------
  2543.   def update
  2544.     super
  2545.     self.opacity += 25
  2546.   end
  2547.   #----------------------------------------------------------------------------
  2548.   # * Help text - default text shown if none is given to this window.
  2549.   #----------------------------------------------------------------------------
  2550.   def help_text
  2551.     @text ? @text : "Would you like to water it?"
  2552.   end
  2553.   #----------------------------------------------------------------------------
  2554.   # * Show
  2555.   #----------------------------------------------------------------------------
  2556.   def show
  2557.     super
  2558.     self.opacity = 0
  2559.   end
  2560.   #----------------------------------------------------------------------------
  2561.   # * Refresh
  2562.   #----------------------------------------------------------------------------
  2563.   def refresh
  2564.     contents.clear
  2565.     draw_text(0,0,width,line_height+10,help_text)
  2566.   end # Refresh
  2567.  
  2568. end # Window_WatererText
  2569.  
  2570. #==============================================================================
  2571. # ** Window_WaterAmt
  2572. #     Used to select the number of times the plant should be watered.
  2573. #==============================================================================
  2574. class Window_WaterAmt < Window_Selectable
  2575.   #--------------------------------------------------------------------------
  2576.   # * Initialize
  2577.   #--------------------------------------------------------------------------
  2578.   def initialize(*args)
  2579.     super(*args)
  2580.     @number = 1
  2581.     refresh
  2582.   end
  2583.   #--------------------------------------------------------------------------
  2584.   # * Item Max
  2585.   #--------------------------------------------------------------------------
  2586.   def item_max
  2587.     1
  2588.   end
  2589.   #--------------------------------------------------------------------------
  2590.   # * Number
  2591.   #--------------------------------------------------------------------------
  2592.   def number
  2593.     @number
  2594.   end
  2595.   #--------------------------------------------------------------------------
  2596.   # * Give Water Container
  2597.   #--------------------------------------------------------------------------
  2598.   def give_waterer(item)
  2599.     @item = item
  2600.   end
  2601.   #--------------------------------------------------------------------------
  2602.   # * Frame Update
  2603.   #--------------------------------------------------------------------------
  2604.   def update
  2605.     super
  2606.     if active
  2607.       last_number = @number
  2608.       update_number
  2609.       if @number != last_number
  2610.         Sound.play_cursor
  2611.         refresh
  2612.       end
  2613.     end
  2614.   end
  2615.   #--------------------------------------------------------------------------
  2616.   # * Update Quantity
  2617.   #--------------------------------------------------------------------------
  2618.   def update_number
  2619.     change_number(10)   if Input.repeat?(:RIGHT)
  2620.     change_number(-10)  if Input.repeat?(:LEFT)
  2621.     change_number(1)  if Input.repeat?(:UP)
  2622.     change_number(-1) if Input.repeat?(:DOWN)
  2623.   end
  2624.   #--------------------------------------------------------------------------
  2625.   # * Change Number
  2626.   #--------------------------------------------------------------------------
  2627.   def change_number(mod)
  2628.     @number = [@number+mod,0].max
  2629.     if @number > (n=@item.water_available_uses)
  2630.       @number = n
  2631.     end
  2632.   end
  2633.   #--------------------------------------------------------------------------
  2634.   # * Refresh
  2635.   #--------------------------------------------------------------------------
  2636.   def refresh
  2637.     contents.clear
  2638.     draw_number
  2639.   end
  2640.   #--------------------------------------------------------------------------
  2641.   # * Draw Number
  2642.   #--------------------------------------------------------------------------
  2643.   def draw_number
  2644.     change_color(normal_color)
  2645.     draw_text(0, 0, 80, line_height, @number,2)
  2646.     draw_text(0,0, 80, line_height, "x")
  2647.   end
  2648.   #--------------------------------------------------------------------------
  2649.   # * Activate
  2650.   #--------------------------------------------------------------------------
  2651.   def activate
  2652.     super
  2653.     select(0)
  2654.   end # Activate
  2655.  
  2656. end # Window_WaterAmt
  2657.  
  2658. #==============================================================================
  2659. # ** Game_Interpreter
  2660. #==============================================================================
  2661. class Game_Interpreter
  2662.   #----------------------------------------------------------------------------
  2663.   # * Garden Fill Containers
  2664.   #   Pass an integer to modifer the containers by a specified amount,
  2665.   #   otherwise the containers will be completely refilled
  2666.   #----------------------------------------------------------------------------
  2667.   def garden_fill_containers(mod = :max)
  2668.     return false unless $game_player.party_has_waterer_era?(mod == :max || mod > 0)
  2669.     $game_party.items.each do |item|
  2670.       if item.is_waterer?
  2671.         if mod == :max
  2672.           item.mod_waterer_available_uses(item.water_amount_uses)
  2673.         else
  2674.           item.mod_waterer_available_uses(mod)
  2675.         end
  2676.       end # item.is_waterer?
  2677.      
  2678.       scene=SceneManager.scene
  2679.       return unless scene.is_a?(Scene_Map)
  2680.       spm = scene.instance_eval('@spriteset')
  2681.      
  2682.       if mod == :max
  2683.         spm.add_spgt_to_spm("Water containers maxed")
  2684.       else
  2685.         spm.add_spgt_to_spm("Water containers #{mod < 0 ? "-" : "+"}#{mod}")
  2686.       end
  2687.     end # $game_party.items.each
  2688.     return true
  2689.   end # garden_fill_containers
  2690.   #----------------------------------------------------------------------------
  2691.   # * Destroy a garden plant from its event's interpreter.
  2692.   #----------------------------------------------------------------------------
  2693.   def harvest_garden_plant(should_destroy)
  2694.     ev = (map = $game_map).events[@event_id]
  2695.     return unless !ev.plant.nil?
  2696.     harvest = ev.plant.harvest
  2697.    
  2698.     if should_destroy
  2699.       $game_system.destroy_plant(ev.plant.plant_id)
  2700.       @event_id = 0
  2701.     end
  2702.    
  2703.     return harvest
  2704.   end
  2705. end # Game_Interpreter
  2706.  
  2707. #==============================================================================
  2708. # ** Spriteset_Map
  2709. #     Add methods to support adding instances of Sprite_GardenText to the spm
  2710. #==============================================================================
  2711. class Spriteset_Map
  2712.   #----------------------------------------------------------------------------
  2713.   # * Alias - initialize
  2714.   #----------------------------------------------------------------------------
  2715.   alias init_spgt_teserir_pam_spm_ali_era initialize
  2716.   def initialize
  2717.     init_spgt_teserir_pam_spm_ali_era
  2718.     create_spgt_arr
  2719.   end
  2720.   #----------------------------------------------------------------------------
  2721.   # * Alias - Dispose
  2722.   #----------------------------------------------------------------------------
  2723.   alias dis_sprmt_esopsi_disp_b_chars dispose
  2724.   def dispose
  2725.     dis_sprmt_esopsi_disp_b_chars
  2726.     dispose_spgdtext
  2727.   end
  2728.   #----------------------------------------------------------------------------
  2729.   # * Alias - Update
  2730.   #----------------------------------------------------------------------------
  2731.   alias etad_upd_sprm_txtbm_disp_era update
  2732.   def update
  2733.     etad_upd_sprm_txtbm_disp_era
  2734.     update_spgdtext
  2735.   end
  2736.   #----------------------------------------------------------------------------
  2737.   # * Create Sprite Garden Text Array
  2738.   #----------------------------------------------------------------------------
  2739.   def create_spgt_arr
  2740.     @spgt_text_era = []
  2741.   end
  2742.   #----------------------------------------------------------------------------
  2743.   # * Update Sprite Garden Text
  2744.   #----------------------------------------------------------------------------
  2745.   def update_spgdtext
  2746.     return unless @spgt_text_era
  2747.     @spgt_text_era.each{|spgt| spgt.update}
  2748.   end
  2749.   #----------------------------------------------------------------------------
  2750.   # * Dispose Sprite Garden Text
  2751.   #----------------------------------------------------------------------------
  2752.   def dispose_spgdtext
  2753.     @spgt_text_era.each{|spgt| spgt.dispose}
  2754.   end
  2755.   #----------------------------------------------------------------------------
  2756.   # * Add Sprite Garden to Spritesetmap
  2757.   #----------------------------------------------------------------------------
  2758.   def add_spgt_to_spm(text)
  2759.     @spgt_text_era.push(Sprite_GardenText.new(@viewport3).give(text))
  2760.   end
  2761.  
  2762. end # Spriteset_Map
  2763. #==============================================================================
  2764. # ** Sprite_GardenText
  2765. #     Displays bouncing text on the screen.
  2766. #==============================================================================
  2767. class Sprite_GardenText < Sprite_Base
  2768.   #----------------------------------------------------------------------------
  2769.   # * Initialize
  2770.   #----------------------------------------------------------------------------
  2771.   def initialize(*args)
  2772.     super(*args)
  2773.     self
  2774.   end
  2775.   #----------------------------------------------------------------------------
  2776.   # * Give
  2777.   #----------------------------------------------------------------------------
  2778.   def give(text = "!")
  2779.     @bounce_min = 23
  2780.     @bounce_min_count = 0
  2781.     @val = -4
  2782.    
  2783.     self.bitmap = Bitmap.new(200,35)
  2784.     self.bitmap.font.color.set(200,220,100)
  2785.     self.bitmap.font.size = 24
  2786.     self.bitmap.draw_text(0,0,200,35,text)
  2787.     self.y = $game_player.x * 32 - $game_map.display_x
  2788.     self.x = $game_player.y * 32 - $game_map.display_y
  2789.     self.ox = bitmap.width/5
  2790.     self.oy = bitmap.height/3
  2791.     self
  2792.   end
  2793.   #----------------------------------------------------------------------------
  2794.   # * Update
  2795.   #----------------------------------------------------------------------------
  2796.   def update
  2797.     return if self.bitmap.disposed?
  2798.     if @bounce_min <= 0
  2799.       self.opacity -= 5.5
  2800.       self.bitmap.dispose if self.opacity < 0
  2801.       return
  2802.     end
  2803.     self.x += 1
  2804.     self.y+=@val
  2805.     self.zoom_x+=0.004
  2806.     self.zoom_y+=0.004
  2807.     @bounce_min_count += 5.5
  2808.     return if @val > 0 && @bounce_min_count/2 < @bounce_min
  2809.     if @bounce_min_count >= @bounce_min || (@val < 0 ? @bounce_min_count >= @bounce_min/2 : false)
  2810.       @val *= -1
  2811.       @bounce_min -= 7 if @val < 0
  2812.       @bounce_min_count = -@bounce_min_count/2
  2813.     end
  2814.    
  2815.   end
  2816.   #----------------------------------------------------------------------------
  2817.   # * Dispose
  2818.   #----------------------------------------------------------------------------
  2819.   def dispose
  2820.     self.bitmap.dispose
  2821.   end # dispose
  2822. end # Sprite_GardenText
  2823.  
  2824. # End of File
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement