Guest User

Yiff algebra (addendum)

a guest
Aug 13th, 2011
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 33.36 KB | None | 0 0
  1. require 'rubygems'
  2. gem 'facets'
  3. require 'facets'
  4. require 'facets/random'
  5. require 'mathn'
  6.  
  7.  
  8. # Common-common-common............................17
  9. # Pattern meowtching.............................175
  10. # Long-named class definitions...................230
  11. # Yiff algebra...................................296
  12. # Library........................................425
  13. # Frozen Synapse interface......................1243
  14. # Kama Sutra....................................1300
  15. # Brool Stories, Inc............................1468
  16.  
  17.  
  18. # ---- Common-common-common ----
  19.  
  20.  
  21. Map = Hash
  22.  
  23.  
  24. class Map
  25.  
  26.   def key_and_value
  27.     self.to_a.only
  28.   end
  29.  
  30. end
  31.  
  32.  
  33. # :call-seq:
  34. #   oalias new_method_id => old_method_id
  35. #
  36. # creates alias which always references overriden method rather than
  37. # original one (Ruby's +alias+ keyword creates method which always
  38. # references not overriden method).
  39. #
  40. # The name is abbreviation for "overridable alias".
  41. #
  42. def oalias(arg)
  43.   begin
  44.     new_method_id, old_method_id = arg.key_and_value
  45.     define_method new_method_id, self.instance_method(old_method_id)
  46.   rescue NoMethodError
  47.     eval <<-RUBY
  48.       def #{new_method_id}(*args, &block)
  49.         #{old_method_id}(*args, &block)
  50.       end
  51.     RUBY
  52.   end
  53. end
  54.  
  55.  
  56. class AssertionFailedError < Exception
  57. end
  58.  
  59. def assert(condition, msg = "Assertion failed")
  60.   raise AssertionFailedError.new(msg) unless condition
  61. end
  62.  
  63.  
  64. # :private-to-module:
  65. $last_mentioned_items = []
  66.  
  67.  
  68. class Array
  69.  
  70.   oalias :add => :<<
  71.  
  72.   oalias :present? => :not_empty?
  73.  
  74.   # "item_1, item_2, ..., item_(n-1) and item_n"
  75.   def to_nat_s
  76.     $last_mentioned_items = self
  77.     self.conjoin(", ", " and ")
  78.   end
  79.  
  80. end
  81.  
  82.  
  83. class Object
  84.  
  85.   def eigen_class
  86.     class << self; self; end
  87.   end
  88.  
  89. end
  90.  
  91.  
  92. class Numeric
  93.  
  94.   def seconds
  95.     self
  96.   end
  97.  
  98.   alias second seconds
  99.   alias sec seconds
  100.   alias s seconds
  101.  
  102.   def minutes
  103.     60 * self
  104.   end
  105.  
  106.   alias minute minutes
  107.   alias min minutes
  108.   alias m minutes
  109.  
  110.   def hours
  111.     60 * minutes
  112.   end
  113.  
  114.   alias hour hours
  115.   alias h hours
  116.  
  117.   def percent
  118.     self / 100
  119.   end
  120.  
  121.   def to_time_s
  122.     secs = self.floor
  123.     h = (secs / 3600).floor
  124.     m = ((secs % 3600) / 60).floor
  125.     s = self - h.hours - m.minutes
  126.     s = s.round_to(0.0001) if not s.is_a?(Integer)
  127.     r = "#{s}s"
  128.     r = "#{m}m " + r if m > 0
  129.     r = "#{h}h " + r if h > 0
  130.     return r
  131.   end
  132.  
  133. end
  134.  
  135.  
  136. # Unique integer.
  137. def unique
  138.   return $next_unique.tap { $next_unique += 1 }
  139. end
  140.  
  141. # :private-to-module:
  142. $next_unique = 0
  143.  
  144.  
  145. Inf = 1.0/0.0
  146.  
  147.  
  148. # returns "s" for +items+ of size 1 and "ve" for +items+ of another size.
  149. # By default +items+ are items which Array#to_nat_s() has been last called for.
  150. def s_or_ve(items = $last_mentioned_items)
  151.   if items.one? then "s"
  152.   else "ve"; end
  153. end
  154.  
  155. # returns "is" for +items+ of size 1 and "are" for +items+ of another size.
  156. # By default +items+ are items which Array#to_nat_s() has been last called for.
  157. def is_or_are(items = $last_mentioned_items)
  158.   if items.one? then "is"
  159.   else "are"; end
  160. end
  161.  
  162.  
  163. def yes; true; end
  164. def no; false; end
  165.  
  166.  
  167. class Module
  168.  
  169.   def to_proc
  170.     lambda { |arg| self.new(arg) }
  171.   end
  172.  
  173. end
  174.  
  175.  
  176. # ---- Pattern meowtching ----
  177.  
  178.  
  179. class Array
  180.  
  181.   def ===(other)
  182.     return false unless other.is_a?(Array) or other.respond_to?(:to_a)
  183.     other = other.to_a
  184.     i_self = 0
  185.     i_other = 0
  186.     loop do
  187.       if self[i_self].is_a? Many1
  188.         assert(i_self == self.size - 1)
  189.         return false unless self[i_self].what === other[i_other]
  190.         i_other += 1
  191.         return true if i_other >= other.size
  192.       else
  193.         return false unless self[i_self] === other[i_other]
  194.         i_self += 1
  195.         i_other += 1
  196.         return true if i_self >= self.size and i_other >= other.size
  197.       end
  198.     end
  199.   end
  200.  
  201. end
  202.  
  203.  
  204. # :private-to-module:
  205. class Many1 < Struct.new(:what)
  206. end
  207.  
  208. # "One or many +obj+-s".
  209. def many1(obj)
  210.   Many1.new(obj)
  211. end
  212.  
  213.  
  214. # An object which is case equal ("===") to anything.
  215. def any; Placeholder.new; end
  216.  
  217. alias _ any
  218.  
  219. # :private-to-module:
  220. class Placeholder
  221.  
  222.   def ===(other)
  223.     true
  224.   end
  225.  
  226.   def to_s; "_"; end
  227.  
  228. end
  229.  
  230.  
  231. # ---- Long-named class definitions ----
  232.  
  233.  
  234. # Example of usage:
  235. #
  236. #   include LongNamedClassDefinitions
  237. #  
  238. #   class Something
  239. #     def m(); puts "Do something"; end
  240. #   end
  241. #  
  242. #   Something "Other",
  243. #      m { puts "Do other thing" }
  244. #
  245. #   Something("Other").m()              #=> Do other thing
  246. #   puts Something("Other").class       #=> Other
  247. #
  248. module LongNamedClassDefinitions
  249.  
  250.   begin
  251.     @@long_named_classes = Map.new  # [parent class name, class name] -> Class
  252.   end
  253.  
  254.   CLASS_NAME = /[A-Z].*/
  255.  
  256.   def method_missing(method_id, *args, &block)
  257.     case [method_id.to_s, args, block]
  258.     when [_, [], Proc]
  259.       MethodDef.new(method_id, block)
  260.     when [CLASS_NAME, [String, many1(MethodDef)], nil]
  261.       parent_class_name = method_id.to_s
  262.       class_name = args[0]
  263.       method_defs = args[1..-1]
  264.       clazz = eval <<-RUBY
  265.         class ::#{internal_class_name = "LongNamedClass#{unique}"} < ::#{parent_class_name}
  266.           def self.to_s
  267.             #{class_name.inspect}
  268.           end
  269.         end
  270.         #{internal_class_name}
  271.       RUBY
  272.       clazz.instance_eval {
  273.         method_defs.each { |method_def|
  274.           define_method method_def.method_id, &method_def.code
  275.         }
  276.       }
  277.       @@long_named_classes[[parent_class_name, class_name]] = clazz
  278.     when [CLASS_NAME, [String], nil]
  279.       parent_class_name = method_id.to_s
  280.       class_name = *args
  281.       clazz = @@long_named_classes[[parent_class_name, class_name]]
  282.       raise %Q{Class #{parent_class_name} "#{class_name}" is not declared} if clazz == nil
  283.       clazz.new
  284.     else
  285.       super(method_id, *args, &block)
  286.     end
  287.   end
  288.  
  289.   private
  290.  
  291.   class MethodDef < Struct.new(:method_id, :code)
  292.   end
  293.  
  294. end
  295.  
  296.  
  297. # ---- Yiff algebra ----
  298.  
  299.  
  300. class Yiff
  301.  
  302.   # :immutable:
  303.   class Detail
  304.    
  305.     # returns DetailsSet.
  306.     def * other
  307.       DetailsSet.new([self]) * other
  308.     end
  309.    
  310.     # :overridable:
  311.     #
  312.     # The same as #exclude_sets but should return a single entry.
  313.     #
  314.     def exclude_set
  315.       unique
  316.     end
  317.    
  318.     # :overridable
  319.     #
  320.     # There can not be two Detail-s with intersecting #exclude_sets
  321.     # in single DetailsSet.
  322.     #
  323.     def exclude_sets
  324.       [exclude_set]
  325.     end
  326.    
  327.     # :overridable:
  328.     #
  329.     # Detail-s with less #priority are located in DetailsSet first.
  330.     #
  331.     def priority
  332.       0
  333.     end
  334.    
  335.     def == other
  336.       self.class == other.class
  337.     end
  338.    
  339.     oalias :eql? => :==
  340.    
  341.     oalias :=== => :==
  342.  
  343.     def hash
  344.       self.class.hash
  345.     end
  346.    
  347.     protected
  348.    
  349.     # forwards all unknown methods to #yiff.
  350.     def method_missing(method_id, *args, &block)
  351.       yiff.__send__(method_id, *args, &block)
  352.     end
  353.    
  354.   end
  355.  
  356.   # :immutable:
  357.   # :not-inheritable:
  358.   class DetailsSet
  359.    
  360.     is Enumerable
  361.    
  362.     def initialize(details)
  363.       assert details.is_a?(Enumerable) and details.all? { |d| d.is_a?(Detail) }
  364.       #
  365.       @details = details
  366.     end
  367.    
  368.     def each(&block)
  369.       details.each(&block)
  370.     end
  371.    
  372.     def * other
  373.       case other
  374.       when Detail
  375.         Set.new(
  376.           (self.details.reject { |detail| (detail.exclude_sets & other.exclude_sets).not_empty? } + [other]).
  377.           per.sort_by.priority
  378.         )
  379.       when Set
  380.         other.details.reduce(self, :*)
  381.       else
  382.         raise ArgumentError, "#{other.inspect} must be #{Set} or #{Detail}"
  383.       end
  384.     end
  385.    
  386.     def / other
  387.       # / Fix for KWrite syntax coloring engine.
  388.       Set.new(self.details -
  389.           if other.is_a? Set then other.details
  390.           else [other]; end
  391.       )
  392.     end
  393.    
  394.     def == other
  395.       self.class == other.class and
  396.       self.details == other.details
  397.     end
  398.    
  399.     oalias :eql? => :==
  400.    
  401.     def === other
  402.       self.class == other.class and
  403.       self.details === other.details
  404.     end
  405.    
  406.     def hash
  407.       details.hash
  408.     end
  409.    
  410.     private
  411.    
  412.     Set = DetailsSet
  413.    
  414.     attr_reader :details
  415.    
  416.     # Workaround for Ruby bug.
  417.     protected :details
  418.    
  419.   end
  420.  
  421.   NO_DETAILS = DetailsSet.new([])
  422.  
  423. end
  424.  
  425.  
  426. # ---- Library ----
  427.  
  428.  
  429. def log(msg)
  430.   puts msg
  431. end
  432.  
  433.  
  434. class Furry
  435.  
  436.   def initialize(name, description = "")
  437.     @name = name
  438.     @description = description
  439.     @reminiscences = []
  440.   end
  441.  
  442.   # :immutable:
  443.   attr_reader :name
  444.  
  445.   # :immutable:
  446.   attr_reader :description
  447.  
  448.   # :immutable:
  449.   attr_reader :reminiscences
  450.  
  451.   def remember(event)
  452.     @reminiscences.add event
  453.   end
  454.  
  455.   def says(msg)
  456.     log %Q{#{self} says: "#{msg}"}
  457.   end
  458.  
  459.   def to_s
  460.     name
  461.   end
  462.  
  463. end
  464.  
  465.  
  466. module Male
  467. end
  468. M = Boy = Male
  469.  
  470.  
  471. module Female
  472. end
  473. F = Girl = Female
  474.  
  475.  
  476. class Module
  477.  
  478.   # returns Array of this Module and +other+.
  479.   #
  480.   # This allows to write things like "M/F", "F/M/F" etc.
  481.   #
  482.   def / other
  483.     # / Fix for KWrite syntax coloring engine.
  484.     return [self, other]
  485.   end
  486.  
  487. end
  488.  
  489. class Array
  490.  
  491.   # See Module#/().
  492.   def / other
  493.     # / Fix for KWrite syntax coloring engine.
  494.     return self + [other]
  495.   end
  496.  
  497. end
  498.  
  499.  
  500. # All subclasses of Furry class.
  501. %Q{
  502.  
  503.   Lion (Lioness)
  504.   Tiger (Tigress)
  505.   Fox (Vixen)
  506.   Wolf (Wolfess)
  507.   Deer
  508.   Horse
  509.   Gator
  510.  
  511. }.strip.newlines.each do |entry|
  512.   species, female_species = *(entry.chomp(")").split("(", 2).every.strip)
  513.   male_species = "Male#{species}"
  514.   female_species ||= "Female#{species}"
  515.   eval <<-RUBY
  516.    
  517.     class #{species} < Furry
  518.      
  519.       def self.to_s
  520.         "#{species.methodize.gsub("_", " ")}"
  521.       end
  522.      
  523.     end
  524.    
  525.     def #{species.methodize}(*args, &block)
  526.       #{species}.new(*args, &block)
  527.     end
  528.    
  529.     class #{male_species} < #{species}
  530.      
  531.       is Male
  532.      
  533.       def self.to_s
  534.         "#{male_species.methodize.gsub("_", " ")}"
  535.       end
  536.      
  537.     end
  538.    
  539.     def #{male_species.methodize}(*args, &block)
  540.       #{male_species}.new(*args, &block)
  541.     end
  542.    
  543.     class #{female_species} < #{species}
  544.      
  545.       is Female
  546.      
  547.       def self.to_s
  548.         "#{female_species.methodize.gsub("_", " ")}"
  549.       end
  550.      
  551.     end
  552.    
  553.     def #{female_species.methodize}(*args, &block)
  554.       #{female_species}.new(*args, &block)
  555.     end
  556.    
  557.   RUBY
  558. end
  559.  
  560.  
  561. class Yiff
  562.  
  563.   def initialize(furries)
  564.     @partners = Partners.new(furries.map &Partner)
  565.     @details = NO_DETAILS
  566.     #
  567.     furries.every.remember(yiff)
  568.   end
  569.  
  570.   # See Yiff::Partners.
  571.   attr_reader :partners
  572.  
  573.   # :call-seq:
  574.   #   partner[furry]
  575.   #   partner(furry)
  576.   #
  577.   # returns Partner from this Yiff which corresponds to +furry+.
  578.   #
  579.   def partner(*args)
  580.     case args
  581.     when []
  582.       partners
  583.     when [Furry]
  584.       furry = *args
  585.       partners[furry]
  586.     else
  587.       raise ArgumentError, args.inspect
  588.     end
  589.   end
  590.  
  591.   oalias :p => :partner
  592.   oalias :[] => :partner
  593.  
  594.   def boys
  595.     partners.select { |partner| partner.is_a? Boy }
  596.   end
  597.  
  598.   def boy
  599.     boys.only
  600.   end
  601.  
  602.   def boy1
  603.     boys[0]
  604.   end
  605.  
  606.   def boy2
  607.     boys[1]
  608.   end
  609.  
  610.   def girls
  611.     partners.select { |partner| partner.is_a? Girl }
  612.   end
  613.  
  614.   def girl
  615.     girls.only
  616.   end
  617.  
  618.   attr_reader :details
  619.  
  620.   # NOTE: Detail#apply!() of the +value+ is called <em>after</em>
  621.   # #details become equal to +value+.
  622.   def details=(value)
  623.     value = value * NO_DETAILS unless value.is_a? DetailsSet
  624.     assert value.is_a? DetailsSet
  625.     #
  626.     old_details = @details
  627.     begin
  628.       @details = value.with_regard_to(yiff)
  629.       @details.apply!
  630.     rescue
  631.       @details = old_details
  632.       raise
  633.     end
  634.   end
  635.  
  636.   # perform this Yiff at most for +duration+ (the method may return earlier,
  637.   # for example, due to some partner having finished).
  638.   #
  639.   # It returns this Yiff.
  640.   #
  641.   def perform_at_most_for(duration)
  642.     # Some workaround...
  643.     details = self.details
  644.     partners = self.partners
  645.     #
  646.     if partners.any? { |partner| partner.finished? } and not details.any? { |detail| detail.continue_if_someone_finished? }
  647.       log %Q{(#{partners.to_nat_s} can not continue yiffing because #{partners.select { |p| p.finished?}.to_nat_s} ha#{s_or_ve} finished)}
  648.       return self
  649.     end
  650.     # Exclude finished partners.
  651.     partners = partners.reject { |p| p.finished? }
  652.     # Limit duration until nearest cum.
  653.     duration = duration.at_most partners.every.time_until_cum_left.min
  654.     # Yiff!
  655.     if duration != 0 then log "#{(details.every.description + ["they are moving"]).to_nat_s} for #{duration.to_time_s}."
  656.     else log "#{details.description}."; end
  657.     details.every.when_yiffing()
  658.     partners.each { |partner| partner.time_until_cum_left -= duration }
  659.     # Cum (if any)!
  660.     partners.each do |partner|
  661.       next unless partner.finished?
  662.       # Cum!
  663.       partner.orgasm!
  664.       details.when_cumming(partner)
  665.       if partner.is_a? Boy then partner.satisfied!; end
  666.     end
  667.     #
  668.     return self
  669.   end
  670.  
  671.   # The same as #perform_for() but with +duration+ set to 0.
  672.   # It may be needed, for example, to apply some one-time Detail-s.
  673.   def perform
  674.     yiff.perform_at_most_for(0)
  675.   end
  676.  
  677.   # "Let's do it one more time!"
  678.   #
  679.   # It calls Partner#needs_more!() on #partners which are
  680.   # Partner#finished?.
  681.   #
  682.   # It returns this Yiff.
  683.   #
  684.   def one_more_time!
  685.     partners.per.select.finished?.every.needs_more!
  686.     return self
  687.   end
  688.  
  689.   oalias :continue! => :one_more_time!
  690.  
  691.   # interrupts this Yiff and returns it.
  692.   def interrupted!
  693.     log "#{partners.per.reject.finished?.to_nat_s} ha#{s_or_ve} stopped yiffing."
  694.     return self
  695.   end
  696.  
  697.   oalias :at_most_for => :perform_at_most_for
  698.  
  699.   oalias :do => :perform
  700.  
  701.   # See source code.
  702.   def reset_details()
  703.     self.details = NO_DETAILS
  704.     return self
  705.   end
  706.  
  707.   # :call-seq:
  708.   #   then { ... }
  709.   #   then()
  710.   #   then(additional_details)
  711.   #
  712.   # In the first form it executes the block and returns this Yiff.
  713.   # In the second form it just returns this Yiff.
  714.   # In the third form... see source code, I'm too lazy.
  715.   #
  716.   def then(additional_details = nil, &block)
  717.     case [additional_details, block]
  718.     when [nil, Proc]
  719.       block.call
  720.       return self
  721.     when [nil, nil]
  722.       return self
  723.     when [_, nil]
  724.       yiff.details *= additional_details
  725.       return yiff
  726.     end
  727.   end
  728.  
  729.   oalias :and => :then
  730.  
  731.   oalias :now => :then
  732.  
  733.   # Nah, see source code.
  734.   def not(excluded_details)
  735.     yiff.details /= excluded_details
  736.     return self
  737.   end
  738.  
  739.   # This Yiff.
  740.   def yiff; self; end
  741.    
  742.   def to_s
  743.     "yiff between #{partners.to_nat_s}"
  744.   end
  745.  
  746.   # NOTE: It is wrapper for Furry.
  747.   # NOTE: It is instantiable (see Partner#new).
  748.   module Partner
  749.    
  750.     def self.new(furry)
  751.       # To be a truly wrapper for Furry an instance of the Partner
  752.       # must be of the same class as the furry instance (or of its
  753.       # subclass). Ensure it.
  754.       partner_class = eval <<-RUBY
  755.         class ::#{furry.class.name}
  756.           class YiffPartner < #{furry.class.name}
  757.             include Yiff::Partner
  758.             # Undefine all methods so they can be forwarded to
  759.             # the furry automatically.
  760.             # Don't forget about the Ruby bug that "__send__" does
  761.             # not call "method_missing".
  762.             #{
  763.             furry.class.instance_methods.
  764.               reject do |furry_method_id|
  765.                 furry_method_id.in? %W{
  766.                   __send__
  767.                   __id__
  768.                   method_missing
  769.                   __class__
  770.                   class
  771.                   respond_to?
  772.                   is_a?
  773.                   kind_of?
  774.                   initialize
  775.                   ==
  776.                 }
  777.               end.
  778.               map do |furry_method_id|
  779.                 <<-RUBY
  780.                   def #{furry_method_id}(*args, &block)
  781.                     method_missing(:#{furry_method_id}, *args, &block)
  782.                   end
  783.                 RUBY
  784.               end.join
  785.             }
  786.           end
  787.           YiffPartner
  788.         end
  789.       RUBY
  790.       #
  791.       partner_class.new(furry)
  792.     end
  793.    
  794.     def initialize(furry)
  795.       @furry = furry
  796.       @time_until_cum = Inf
  797.       @progress_left = 1  # [1; 0]
  798.       @orgasms_count = 0
  799.       @satisfied = false
  800.     end
  801.    
  802.     # :immutable:
  803.     attr_reader :orgasms_count
  804.    
  805.     # Time this Partner needs to cum (as if this Yiff would start
  806.     # from zero, not from current time point; see #time_until_cum_left).
  807.     #
  808.     # See also #time_until_cum_left.
  809.     #
  810.     attr_accessor :time_until_cum
  811.    
  812.     # Time this Partner needs to cum (from current time point).
  813.     def time_until_cum_left
  814.       if self.finished? then Inf
  815.       else time_until_cum * @progress_left; end
  816.     end
  817.    
  818.     def time_until_cum_left=(new_time_until_cum_left)
  819.       @progress_left = new_time_until_cum_left / time_until_cum
  820.     end
  821.    
  822.     def finished?
  823.       @progress_left == 0
  824.     end
  825.    
  826.     def just_started?
  827.       @progress_left == 1
  828.     end
  829.    
  830.     def orgasm!
  831.       log %Q{#{self} has got ORGASM!}
  832.       @orgasms_count += 1
  833.     end
  834.    
  835.     def satisfied?
  836.       @satisfied
  837.     end
  838.    
  839.     def satisfied!
  840.       log %Q{#{self} is SATISFIED.}
  841.       @satisfied = true
  842.     end
  843.    
  844.     # sets #satisfied?() and finished?() to false.
  845.     def needs_more!
  846.       log %Q{#{self} needs more.}
  847.       @satisfied = false
  848.       @progress_left = 1
  849.     end
  850.    
  851.     def ==(other)
  852.       super(other) or @furry == other
  853.     end
  854.    
  855.     # forwards all unknown methods to Furry passed via constructor.
  856.     def method_missing(method_id, *args, &block)
  857.       @furry.__send__(method_id, *args, &block)
  858.     end
  859.    
  860.   end
  861.  
  862.   class Partners
  863.    
  864.     is Enumerable
  865.    
  866.     def initialize(partners_array)
  867.       @partners_array = partners_array
  868.     end
  869.    
  870.     def each(&block)
  871.       @partners_array.each(&block)
  872.     end
  873.    
  874.     # returns Yiff::Partner from this Partners which corresponds to +furry+.
  875.     def [](furry)
  876.       @partners_array.find { |p| p == furry }
  877.     end
  878.    
  879.     def to_nat_s
  880.       @partners_array.to_nat_s
  881.     end
  882.    
  883.     def to_a
  884.       @partners_array
  885.     end
  886.    
  887.   end
  888.  
  889.   class Detail
  890.    
  891.     def initialize(yiff = nil)
  892.       @yiff = yiff
  893.     end
  894.    
  895.     # Yiff this Detail is considered with regard to.
  896.     attr_reader :yiff
  897.        
  898.     # returns this Detail considered with regard to +yiff+.
  899.     def with_regard_to(yiff)
  900.       self.class.new(yiff)
  901.     end
  902.    
  903.     oalias :for => :with_regard_to
  904.    
  905.     # :accessible-only-for: Yiff
  906.     #
  907.     # applies this Detail to #yiff.
  908.     #
  909.     def apply!
  910.       raise %Q{"#{self}" is unavailable in #{yiff}} unless self.available?
  911.       #
  912.       apply()
  913.     end
  914.    
  915.     # :overridable:
  916.     #
  917.     # "Is this Detail available in #yiff()?"
  918.     #
  919.     def available?
  920.       true
  921.     end
  922.    
  923.     # :overridable:
  924.     #
  925.     # "What's going on (in #yiff)?"
  926.     #
  927.     def description
  928.       self.class.to_s
  929.     end
  930.    
  931.     # :overridable:
  932.     # :accessible-only-for: Yiff
  933.     #
  934.     # is executed when Yiff with this Detail is in progress.
  935.     #
  936.     def when_yiffing()
  937.     end
  938.    
  939.     # :overridable:
  940.     # :accessible-only-for: Yiff
  941.     #
  942.     # is executed when +partner+ is cumming.
  943.     #
  944.     def when_cumming(partner)
  945.     end
  946.    
  947.     # :overridable:
  948.     # :accessible-only-for: Yiff
  949.     #
  950.     # Default is false.
  951.     #
  952.     def continue_if_someone_finished?
  953.       false
  954.     end
  955.    
  956.     def to_s
  957.       self.class.to_s
  958.     end
  959.    
  960.     # forwards all unknown methods to #yiff.
  961.     def method_missing(method_id, *args, &block)
  962.       yiff.__send__(method_id, *args, &block)
  963.     end
  964.    
  965.     protected
  966.    
  967.     # Implementation of #apply!().
  968.     abstract :apply
  969.    
  970.   end
  971.  
  972.   class DetailsSet
  973.    
  974.     # See Detail#with_regard_to().
  975.     def with_regard_to(yiff)
  976.       DetailsSet.new(details.every.with_regard_to(yiff))
  977.     end
  978.    
  979.     oalias :for => :with_regard_to
  980.    
  981.     # :accessible-only-for: Yiff
  982.     #
  983.     # See Detail#apply!().
  984.     def apply!
  985.       details.every.apply!
  986.     end
  987.    
  988.     # See Detail#description.
  989.     def description
  990.       details.every.description.to_nat_s
  991.     end
  992.    
  993.     # :accessible-only-for: Yiff
  994.     #
  995.     # See Detail#when_cumming().
  996.     def when_cumming(partner)
  997.       details.every.when_cumming(partner)
  998.     end
  999.    
  1000.     def to_s
  1001.       details.to_nat_s
  1002.     end
  1003.    
  1004.   end
  1005.  
  1006. end
  1007.  
  1008. class Array
  1009.  
  1010.   # creates Yiff on this Array of Furry-es.
  1011.   def yiff
  1012.     Yiff.new(self)
  1013.   end
  1014.  
  1015. end
  1016.  
  1017. YiffDetail = Yiff::Detail
  1018.  
  1019.  
  1020. class Pose < Yiff::Detail
  1021.  
  1022.   def exclude_set
  1023.     :poses
  1024.   end
  1025.  
  1026.   def priority; -1; end
  1027.  
  1028.   def available?
  1029.     available_for() === yiff.partners and available_if()
  1030.   end
  1031.  
  1032.   protected
  1033.  
  1034.   def apply
  1035.     assert times_to_cum.is_a? Map
  1036.     times_to_cum.each do |who, time_until_cum|
  1037.       who = partner[who] unless who.is_a? Yiff::Partner
  1038.       who.time_until_cum = time_until_cum
  1039.     end
  1040.   end
  1041.  
  1042.   # returns Array of genders/species/other of Furry-es participating
  1043.   # in Yiff which this Pose is available for.
  1044.   abstract :available_for
  1045.  
  1046.   # :overridable:
  1047.   #
  1048.   # additional availability condition. By default it is just +true+.
  1049.   #
  1050.   def available_if
  1051.     true
  1052.   end
  1053.  
  1054.   # Map: Furry/Yiff::Partner -> time to cum.
  1055.   abstract :times_to_cum
  1056.  
  1057. end
  1058.  
  1059. class Yiff
  1060.  
  1061.   # Pose this Yiff is being performed in.
  1062.   def pose
  1063.     details.find { |detail| detail.is_a? Pose } or raise("#{yiff} is not being performed in any #{Pose}")
  1064.   end
  1065.  
  1066.   # See source code.
  1067.   def in(additional_details)
  1068.     yiff.then(additional_details)
  1069.   end
  1070.  
  1071. end
  1072.  
  1073.  
  1074. class PoseVariation < Yiff::Detail
  1075.  
  1076.   # :overridable:
  1077.   #
  1078.   # NOTE: This property must be higher than Pose#priority.
  1079.   #
  1080.   def priority; 0; end
  1081.  
  1082.   def available?
  1083.     poses = self.poses
  1084.     poses = [poses] unless poses.is_a? Enumerable
  1085.     except_poses = self.except_poses
  1086.     except_poses = [except_poses] unless except_poses.is_a? Enumerable
  1087.     #
  1088.     poses.per.any? === yiff.pose and not except_poses.per.any? === yiff.pose and
  1089.         available_for() === yiff.partners and
  1090.         available_if()
  1091.   end
  1092.  
  1093.   protected
  1094.  
  1095.   # Pose-s this PoseVariation is available for.
  1096.   abstract :poses
  1097.  
  1098.   # :overridable:
  1099.   #
  1100.   # Pose-s this PoseVariation is <em>not</em> available for.
  1101.   #
  1102.   def except_poses
  1103.     []
  1104.   end
  1105.  
  1106.   # :overridable:
  1107.   #
  1108.   # Genders/species of Furry-es in #yiff which this PoseVariation is
  1109.   # available for.
  1110.   #
  1111.   def available_for
  1112.     any
  1113.   end
  1114.  
  1115.   # :overridable:
  1116.   #
  1117.   # Additional availability conditions. By default it is just +true+.
  1118.   #
  1119.   def available_if
  1120.     true
  1121.   end
  1122.  
  1123.   def apply()
  1124.     when_applied()
  1125.   end
  1126.  
  1127.   # :overridable
  1128.   #  
  1129.   def when_applied
  1130.   end
  1131.  
  1132. end
  1133.  
  1134.  
  1135. class Detail < Yiff::Detail
  1136.  
  1137.   def priority; -0.5; end
  1138.  
  1139.   def available?
  1140.     available_for() === yiff.partners and available_if()
  1141.   end
  1142.  
  1143.   protected
  1144.  
  1145.   def apply()
  1146.     when_applied()
  1147.   end
  1148.  
  1149.   # :overridable:
  1150.   #
  1151.   # See Pose#available_for.
  1152.   #
  1153.   abstract :available_for
  1154.  
  1155.   # :overridable:
  1156.   #
  1157.   # See Pose#available_if.
  1158.   #
  1159.   def available_if
  1160.     true
  1161.   end
  1162.  
  1163.   # :overridable:
  1164.   #
  1165.   def when_applied
  1166.   end
  1167.  
  1168. end
  1169.  
  1170.  
  1171. class Range
  1172.  
  1173.   # forwards all unknown methods to Range#at_rand() of this Range casted to
  1174.   # Range of Float-s (with end included).
  1175.   def method_missing(method_id, *args, &block)
  1176.     begin
  1177.       x = (self.begin.to_f..self.end.to_f).at_rand
  1178.     rescue
  1179.       super(method_id, *args, &block)
  1180.     end
  1181.     return super(method_id, *args, &block) unless x.respond_to? method_id
  1182.     x.__send__(method_id, *args, &block)
  1183.   end
  1184.  
  1185. end
  1186.  
  1187.  
  1188. module StoryTelling
  1189.  
  1190.   def tell(msg)
  1191.     log "#{msg}"
  1192.   end
  1193.  
  1194.   class ::String
  1195.    
  1196.     alias old_brackets []
  1197.    
  1198.     # :call-seq:
  1199.     #   []
  1200.     #
  1201.     # Alias for StoryTelling#tell().
  1202.     #
  1203.     def [](*args)
  1204.       if args.empty? then tell self
  1205.       else super(*args); end
  1206.     end
  1207.    
  1208.   end
  1209.  
  1210.   #
  1211.   # returns +furry+.
  1212.   #
  1213.   # NOTE: It also declares constant named after +furry+ (if possible) which is
  1214.   # equal to the +furry+.
  1215.   #
  1216.   def lets_meet(furry)
  1217.     #
  1218.     if furry.description.blank? then tell "Let's meet #{furry} the #{furry.class}."
  1219.     else tell "Let's meet #{furry} the #{furry.class}, #{furry.description}."; end
  1220.     #
  1221.     begin
  1222.       $tmp = furry
  1223.       eval <<-RUBY
  1224.         class ::Object
  1225.           #{furry.name.gsub(" ", "_")} = $tmp
  1226.         end
  1227.       RUBY
  1228.     rescue SyntaxError
  1229.       # Nah, do nothing.
  1230.     ensure
  1231.       $tmp = nil
  1232.     end
  1233.     #
  1234.     return furry
  1235.   end
  1236.  
  1237.   def story(name)
  1238.     tell "\n---- #{name} ----\n\n"
  1239.   end
  1240.  
  1241. end
  1242.  
  1243.  
  1244. # ---- Frozen Synapse interface ----
  1245.  
  1246.  
  1247. class Yiff
  1248.  
  1249.   # returns Plan over this Yiff.
  1250.   def planning_phase!
  1251.     log "PLANNING PHASE"
  1252.     Plan.new(self)
  1253.   end
  1254.  
  1255.   oalias :plan => :planning_phase!
  1256.  
  1257.   # Nah, see source code.
  1258.   class Plan
  1259.    
  1260.     def initialize(yiff)
  1261.       @yiff = yiff
  1262.       @actions = []
  1263.     end
  1264.    
  1265.     def method_missing(method_id, *args, &block)
  1266.       @actions.add(proc { @yiff.__send__(method_id, *args, &block) })
  1267.       return self
  1268.     end
  1269.    
  1270.     def prime!
  1271.       log "System PRIMED!"
  1272.       @actions.per.each.call()
  1273.       @actions.clear()
  1274.       return @yiff
  1275.     end
  1276.    
  1277.   end
  1278.  
  1279. end
  1280.  
  1281.  
  1282. class Proc
  1283.  
  1284.   # Alias to #call() adapted to Frozen Synapse interface.
  1285.   def prime!
  1286.     log "System PRIMED"
  1287.     self.call()
  1288.   end
  1289.  
  1290. end
  1291.  
  1292.  
  1293. # just returns +block+.
  1294. def planning_phase!(&block)
  1295.   log "PLANNING PHASE"
  1296.   return block
  1297. end
  1298.  
  1299.  
  1300. # ---- Kama Sutra ----
  1301.  
  1302.  
  1303. include LongNamedClassDefinitions
  1304.  
  1305.  
  1306. Pose "Girl on top",
  1307.     description { "#{girl} is lying on #{boy}" },
  1308.     available_for { M/F },
  1309.     times_to_cum {{
  1310.       boy => (7..13).minutes,
  1311.       girl => (15..17).minutes
  1312.     }}
  1313.  
  1314. Pose "Boy on top",
  1315.     description { "#{boy} is lying on #{girl}" },
  1316.     available_for { M/F },
  1317.     times_to_cum {{
  1318.       boy => (7..13).minutes,
  1319.       girl => (20..23).minutes
  1320.     }}
  1321.  
  1322. Pose "Cowgirl",
  1323.     description { "#{boy} is lying on back, #{girl} is riding him" },
  1324.     available_for { M/F },
  1325.     times_to_cum {{
  1326.       boy => (5..10).minutes,
  1327.       girl => (10..13).minutes
  1328.     }}
  1329.  
  1330. Pose "Cunnilingus",
  1331.     description { "#{boy} is licking #{girl} at the bottom" },
  1332.     available_for { M/F },
  1333.     times_to_cum {{
  1334.       girl => (5..10).minutes,
  1335.       boy => 1.hour
  1336.     }}
  1337.  
  1338. PoseVariation "Boy holding her hands",
  1339.     description { "#{boy} and #{girl} are holding hands" },
  1340.     exclude_sets {[ :boy_hands, :girl_hands ]},
  1341.     available_for { M/F },
  1342.     poses { any },
  1343.     except_poses { Pose "Cunnilingus" },
  1344.     when_applied {
  1345.       partners.each { |p| p.time_until_cum *= 110.percent }
  1346.     }
  1347.  
  1348. PoseVariation "Boy holding breasts",
  1349.     description { "#{boy} is squeezing #{girl}'s breasts" },
  1350.     exclude_set { :boy_hands },
  1351.     available_for { M/F },
  1352.     poses { any },
  1353.     except_poses { Pose "Cunnilingus" },
  1354.     when_applied {
  1355.       girl.time_until_cum *= 80.percent
  1356.     }
  1357.  
  1358. PoseVariation "Boy holding waist",
  1359.     description { "#{boy} is holding #{girl}'s waist" },
  1360.     exclude_set { :boy_hands },
  1361.     available_for { M/F },
  1362.     poses { any },
  1363.     when_applied {
  1364.       boy.time_until_cum *= 80.percent
  1365.     }
  1366.  
  1367. PoseVariation "Boy holding hips",
  1368.     description { "#{boy} is holding #{girl}'s hips" },
  1369.     exclude_set { :boy_hands },
  1370.     available_for { M/F },
  1371.     poses { any },
  1372.     when_applied {
  1373.       boy.time_until_cum *= 80.percent
  1374.       girl.time_until_cum *= 80.percent
  1375.     }
  1376.  
  1377. PoseVariation "Boy embraces her",
  1378.     description { "#{boy} is embracing #{girl}" },
  1379.     exclude_set { :boy_hands },
  1380.     available_for { M/F },
  1381.     poses { any },
  1382.     except_poses {[ Pose("Cowgirl"), Pose("Cunnilingus") ]},
  1383.     when_applied {
  1384.       boy.time_until_cum *= 80.percent
  1385.     }
  1386.  
  1387. PoseVariation "They caress each other",
  1388.     description { "#{boy} is caressing #{girl}'s waist, her belly, her breasts, #{girl} is caressing him too" },
  1389.     exclude_sets {[ :boy_hands, :girl_hands ]},
  1390.     available_for { M/F },
  1391.     poses { any },
  1392.     except_poses {[ Pose("Cowgirl"), Pose("Cunnilingus") ]},
  1393.     when_applied {
  1394.       boy.time_until_cum *= 70.percent
  1395.       girl.time_until_cum *= 70.percent
  1396.     }
  1397.  
  1398. PoseVariation "They are kissing",
  1399.     description { "#{boy} is kissing #{girl}" },
  1400.     exclude_sets {[ :boy_lips, :girl_lips ]},
  1401.     available_for { M/F },
  1402.     poses { any },
  1403.     except_poses {[ Pose("Cowgirl"), Pose("Cunnilingus") ]},
  1404.     continue_if_someone_finished? { yes },
  1405.     when_applied {
  1406.       girl.satisfied! if boy.finished?
  1407.     },
  1408.     when_cumming { |partner|
  1409.       if partner == boy then girl.satisfied!; end
  1410.     }
  1411.  
  1412. PoseVariation "Boy kissing breasts",
  1413.     description { "#{boy} is kissing #{girl}'s breasts" },
  1414.     exclude_set { :boy_lips },
  1415.     poses { Pose "Boy on top" },
  1416.     when_applied {
  1417.       boy.time_until_cum *= 80.percent
  1418.       girl.time_until_cum *= 80.percent
  1419.     }
  1420.  
  1421. PoseVariation "Girl leans on his chest",
  1422.     description { "#{girl} is leaning with hands on #{boy}'s chest" },
  1423.     exclude_set { :girl_hands },
  1424.     poses { Pose "Cowgirl" }
  1425.  
  1426. PoseVariation "Girl leans at the front and from behind",
  1427.     description { "#{girl} is keeping one hand on #{boy}'s stomach and other hand on his leg" },
  1428.     exclude_set { :girl_hands },
  1429.     poses { Pose "Cowgirl" }
  1430.  
  1431. PoseVariation "Her hands on his hands",
  1432.     description { "#{girl} is keeping her hands on #{boy}'s hands"},
  1433.     exclude_set { :girl_hands },
  1434.     poses { any },
  1435.     except_poses { Pose "Cunnilingus" }
  1436.  
  1437. PoseVariation "Girl embraces him",
  1438.     description { "#{girl} is embracing #{boy}" },
  1439.     exclude_set { :girl_hands },
  1440.     poses { any },
  1441.     except_poses {[ Pose("Cowgirl"), Pose("Cunnilingus") ]}
  1442.  
  1443. PoseVariation "Girl pushes his shoulders",
  1444.     description { "#{girl} is pushing #{boy}'s shoulders" },
  1445.     exclude_set { :girl_hands },
  1446.     poses { any },
  1447.     except_poses { Pose "Cowgirl" }
  1448.  
  1449. PoseVariation "Girl embraces him with legs",
  1450.     description { "#{girl} is crossing her legs behing the #{boy}'s back" },
  1451.     exclude_set { :girl_legs },
  1452.     poses { Pose "Boy on top" },
  1453.     when_applied {
  1454.       girl.time_until_cum *= 90.percent
  1455.       boy.time_until_cum *= 110.percent
  1456.     }
  1457.  
  1458. Detail "Girl likes how boy cums",
  1459.     description { "#{girl} likes how #{boy} cums" },
  1460.     available_for { M/F },
  1461.     when_cumming { |partner|
  1462.       if partner == boy then girl.time_until_cum_left = 10.percent * girl.time_until_cum; end
  1463.     }
  1464.    
  1465. oalias :v => :PoseVariation
  1466.    
  1467.  
  1468. # ---- Brool Stories, Inc. ----
  1469.  
  1470. include StoryTelling
  1471.  
  1472. story "Intrusion"
  1473.  
  1474. "Welcome to Markov Geist. It's easy to forget that there have been other cities."[]
  1475. lets_meet vixen "Kate_Windlight"
  1476. Kate_Windlight.says "Hi Tactics. Your current task is to intrude Brightling
  1477.  University headquarters and to persuade its key figure, Eva Featherling,
  1478.  to our side."
  1479. Kate_Windlight.says "Minor tacticians will handle the other staff and
  1480.  the security, so you will be able to concentrate on
  1481.  the Featherling directly."
  1482. Kate_Windlight.says "You have 15 turns to convince her."
  1483.  
  1484. "Intruder alert!"[]
  1485. red_units =
  1486.     20.of { |i| lets_meet male_fox "Civilian #{i+1}" } +
  1487.     10.of { |i| lets_meet male_tiger "Guardian #{i+1}" } +
  1488.     [lets_meet lioness "Eva Featherling"]
  1489. blue_units =
  1490.     30.of { |i| lets_meet tigress "Unit #{i+1}" } +
  1491.     [lets_meet male_lion "Unit 31"]
  1492.  
  1493. "TURN 1"[]
  1494. plan = planning_phase! do
  1495.   (blue_units - [Unit_31]).zip(red_units - [Eva_Featherling]).each do |blue_unit, red_unit|
  1496.     [blue_unit, red_unit].reverse.yiff.in(Pose("Cowgirl") * v("Girl leans at the front and from behind")).at_most_for(15.minutes)
  1497.   end
  1498. end
  1499.  
  1500. plan.prime!
  1501. "OUTCOME"[]
  1502. red_units.delete_if do |red_unit|
  1503.   if red_unit.reminiscences.not_empty? and red_unit.reminiscences.last.partner[red_unit].satisfied? then
  1504.     log "#{red_unit} is ON OUR SIDE"
  1505.     true
  1506.   end
  1507. end
  1508.  
  1509. "TURN 2"[]
  1510. plan = [Unit_31, Eva_Featherling].yiff.planning_phase!.
  1511.   # First I'll take control immediately.
  1512.   in(Pose("Boy on top") * v("Boy holding her hands") * v("They are kissing")).at_most_for(1.minute).
  1513.   # Then I'll loosen the grip for a while so she thinks that she still controls the situation...
  1514.   reset_details.in(Pose("Cowgirl") * v("Girl leans on his chest")).at_most_for(2.minutes).
  1515.   # ...but I should not relax.
  1516.   now(v("Boy holding breasts") * v("Her hands on his hands")).at_most_for(2.minutes).
  1517.   # Then I should take control to my hands again...
  1518.   then.reset_details.now.in(Pose("Boy on top") * v("Boy holding waist")).at_most_for(1.minute + 30.seconds).
  1519.   # ...to perform an attacking maneuver!
  1520.   in(Pose("Cunnilingus") * v("Boy holding hips") * v("Girl pushes his shoulders")).at_most_for(10.minutes).
  1521.   # Then I'll gracefully finish the battle.
  1522.   continue!.in(Pose("Boy on top") * v("Girl embraces him") * v("Girl embraces him with legs") * v("Boy holding waist")).at_most_for(5.minutes).
  1523.     then(v "They are kissing").do
  1524.  
  1525. plan.prime!
  1526. "OUTCOME"[]
  1527. red_units.delete_if do |red_unit|
  1528.   if red_unit.reminiscences.not_empty? and red_unit.reminiscences.last.partner[red_unit].satisfied? then
  1529.     log "#{red_unit} is ON OUR SIDE"
  1530.     true
  1531.   end
  1532. end
  1533.  
  1534. if red_units.empty? then
  1535.   "***VICTORY***"[]
  1536.   "2 turns! 100 points! 1st place!"[]
  1537. else
  1538.   "***LOSS***"[]
  1539.   "Better try another time."[]
  1540. end
Add Comment
Please, Sign In to add comment