Changeset 202

Show
Ignore:
Timestamp:
05/24/05 18:38:42 (3 years ago)
Author:
ged
Message:

- Added method docs.
- Sped up interval a bit.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/simplest-thing/acceptance/epic4.rb

    r190 r202  
    1111# == Legal 
    1212#  
    13 # Copyright (c) 2000-2004 The FaerieMUD Consortium. Some rights reserved. 
     13# Copyright (c) 2000-2005 The FaerieMUD Consortium. Some rights reserved. 
    1414#  
    1515# This is free software. You may use, modify, and/or redistribute this software 
     
    6363### Clock is a Locus instead of an Instrument for purposes of simplification. 
    6464class Clock < FaerieMUD::Locus 
     65 
     66    ### Create a new clock object. You can configure the object with the  
     67    ### following attributes: 
     68    ### [:count]::  Specify how many ticks the clock should generate before  
     69    ###             returning on its thread of execution. 
     70    ### [:interval]:: Specify how many floating-point seconds to sleep between 
     71    ###               ticks. An +interval+ of +0+ causes the clock to tick as 
     72    ###               fast as it can. 
    6573    def initialize( args={} ) 
    6674        @thread = nil 
     
    7785 
    7886    attr_accessor :count, :interval 
    79      
     87 
     88    ### Start a new thread, start ticking in it and return the thread.   
    8089    def start 
    8190        @thread = Thread::new do 
     
    8897    end 
    8998 
     99    ### Execute one tick of the clock, sending appropriate events to  
     100    ### the environment. 
    90101    def tick 
    91102        @tickCount += 1 
     
    96107    end 
    97108 
     109 
     110    ### Send an auditory chime event to the surrounding environment. 
    98111    def chime 
    99112        self.log.debug "Chime!" 
     
    104117 
    105118 
    106 ### Punchbag can 'say' stuff. 
     119### The quasi-orc can 'say' stuff. 
    107120class SayVerb < FaerieMUD::Verb 
    108121 
    109122    # The speaker will always be both instigator and origin, so combine them in 
    110     # the overridden method. 
     123    # the overridden method. Ventriloquism doesn't count. =:P 
    111124 
    112125    def happen( speaker, language, words ) 
     
    123136### A simulacrum quasi-orc object. 
    124137class QuasiOrc < FaerieMUD::Locus 
     138 
     139    ### Create a new simulated orc. He will assume he's on duty. 
    125140    def initialize 
    126141        @onDuty = true 
     
    131146    end 
    132147 
     148    ### Handle stuff heard from the environment. QuasiOrcs only care about chimes that tell  
     149    ### them they're on duty or off. 
    133150    def handleAuditoryEvent( ev ) 
    134151        if ev.verb.class.name =~ /chime/i 
     
    144161    end 
    145162 
     163 
     164    ### Respond to hearing a chime -- he is on duty every three hours. 
    146165    def respondToChime 
    147166        @chimeCount += 1 
     
    149168    end 
    150169 
     170 
     171    ### After hearing a third chime, either go on duty or come off, and announce it. 
    151172    def changeDutyStatus 
    152173        @onDuty = !@onDuty 
     
    163184 
    164185 
     186### A bodiless observer object class -- just reports events observed from its  
     187### environment to $defout. 
    165188class Observer < FaerieMUD::Locus 
     189 
     190    ### Handle events that are sensed through auditory perception 
    166191    def handleAuditoryEvent( ev ) 
    167192        $defout.puts "Observer heard: %s" % describeEvent( ev ) 
    168193    end 
    169194 
     195    ### Handle auditory events that contain speech specially. 
    170196    def handleSpeechEvent( ev ) 
    171197        prelude = "Observer heard: %s" % describeEvent( ev ) 
     
    173199    end 
    174200 
     201    ### Handle events sensed through visual perception. 
    175202    def handleVisualEvent( ev ) 
    176203        $defout.puts "Observer saw: %s" % describeEvent( ev ) 
    177204    end 
    178205 
     206    ### Create a sentence to describe an event. 
    179207    def describeEvent( ev ) 
    180208        sentence = [] 
     
    198226    end 
    199227 
     228    ### Create a noun phrase from the given +obj+. 
    200229    def objectToNounPhrase( obj ) 
    201230        simplename = obj.class.name.sub( /.*::/, '' ).downcase 
     
    203232    end 
    204233 
     234 
     235    ### This is a really simplistic version of what should really happen.  
     236    ### Ideally, verbs will be able to respond with the appropriate word form of 
     237    ### themselves. However, the NLG engine should be able to pervert the canonical 
     238    ### form to achieve tainted or ecstatic views, etc. 
     239 
     240    ### Conjugate the given +verb+ (a FaerieMUD::Verb object) and return it. 
    205241    def conjugateVerb( verb ) 
    206242        if /(\w+)Verb/.match( verb.class.name ) 
     
    216252 
    217253if $0 == __FILE__ 
    218     #FaerieMUD::Logger::global.outputters << 
    219     #   FaerieMUD::Logger::Outputter::create( 'file', $stderr, "STDERR" ) 
    220     #FaerieMUD::Logger::global.level = :debug 
     254    if $DEBUG 
     255        FaerieMUD::Logger::global.outputters << 
     256            FaerieMUD::Logger::Outputter::create( 'file', $stderr, "STDERR" ) 
     257        FaerieMUD::Logger::global.level = :debug 
     258    end 
    221259 
    222260    # Set up the scene  
     
    227265 
    228266    # Put the clock and punchbag into the void 
    229     topArea << punchbag << clock << observer 
     267    topArea << punchbag 
     268    topArea << clock 
     269    topArea << observer 
    230270 
    231271    # Start the clock ticking 
     272    clock.interval = 0.1 
    232273    clock.start.join 
    233274end