Changeset 202
- Timestamp:
- 05/24/05 18:38:42 (3 years ago)
- Files:
-
- 1 modified
-
branches/simplest-thing/acceptance/epic4.rb (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simplest-thing/acceptance/epic4.rb
r190 r202 11 11 # == Legal 12 12 # 13 # Copyright (c) 2000-200 4The FaerieMUD Consortium. Some rights reserved.13 # Copyright (c) 2000-2005 The FaerieMUD Consortium. Some rights reserved. 14 14 # 15 15 # This is free software. You may use, modify, and/or redistribute this software … … 63 63 ### Clock is a Locus instead of an Instrument for purposes of simplification. 64 64 class 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. 65 73 def initialize( args={} ) 66 74 @thread = nil … … 77 85 78 86 attr_accessor :count, :interval 79 87 88 ### Start a new thread, start ticking in it and return the thread. 80 89 def start 81 90 @thread = Thread::new do … … 88 97 end 89 98 99 ### Execute one tick of the clock, sending appropriate events to 100 ### the environment. 90 101 def tick 91 102 @tickCount += 1 … … 96 107 end 97 108 109 110 ### Send an auditory chime event to the surrounding environment. 98 111 def chime 99 112 self.log.debug "Chime!" … … 104 117 105 118 106 ### Punchbagcan 'say' stuff.119 ### The quasi-orc can 'say' stuff. 107 120 class SayVerb < FaerieMUD::Verb 108 121 109 122 # 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 111 124 112 125 def happen( speaker, language, words ) … … 123 136 ### A simulacrum quasi-orc object. 124 137 class QuasiOrc < FaerieMUD::Locus 138 139 ### Create a new simulated orc. He will assume he's on duty. 125 140 def initialize 126 141 @onDuty = true … … 131 146 end 132 147 148 ### Handle stuff heard from the environment. QuasiOrcs only care about chimes that tell 149 ### them they're on duty or off. 133 150 def handleAuditoryEvent( ev ) 134 151 if ev.verb.class.name =~ /chime/i … … 144 161 end 145 162 163 164 ### Respond to hearing a chime -- he is on duty every three hours. 146 165 def respondToChime 147 166 @chimeCount += 1 … … 149 168 end 150 169 170 171 ### After hearing a third chime, either go on duty or come off, and announce it. 151 172 def changeDutyStatus 152 173 @onDuty = !@onDuty … … 163 184 164 185 186 ### A bodiless observer object class -- just reports events observed from its 187 ### environment to $defout. 165 188 class Observer < FaerieMUD::Locus 189 190 ### Handle events that are sensed through auditory perception 166 191 def handleAuditoryEvent( ev ) 167 192 $defout.puts "Observer heard: %s" % describeEvent( ev ) 168 193 end 169 194 195 ### Handle auditory events that contain speech specially. 170 196 def handleSpeechEvent( ev ) 171 197 prelude = "Observer heard: %s" % describeEvent( ev ) … … 173 199 end 174 200 201 ### Handle events sensed through visual perception. 175 202 def handleVisualEvent( ev ) 176 203 $defout.puts "Observer saw: %s" % describeEvent( ev ) 177 204 end 178 205 206 ### Create a sentence to describe an event. 179 207 def describeEvent( ev ) 180 208 sentence = [] … … 198 226 end 199 227 228 ### Create a noun phrase from the given +obj+. 200 229 def objectToNounPhrase( obj ) 201 230 simplename = obj.class.name.sub( /.*::/, '' ).downcase … … 203 232 end 204 233 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. 205 241 def conjugateVerb( verb ) 206 242 if /(\w+)Verb/.match( verb.class.name ) … … 216 252 217 253 if $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 221 259 222 260 # Set up the scene … … 227 265 228 266 # Put the clock and punchbag into the void 229 topArea << punchbag << clock << observer 267 topArea << punchbag 268 topArea << clock 269 topArea << observer 230 270 231 271 # Start the clock ticking 272 clock.interval = 0.1 232 273 clock.start.join 233 274 end
