gamefic 0.2.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gamefic/action.rb +87 -56
  3. data/lib/gamefic/ansi.rb +55 -0
  4. data/lib/gamefic/character.rb +130 -76
  5. data/lib/gamefic/command.rb +19 -0
  6. data/lib/gamefic/core_ext/array.rb +51 -40
  7. data/lib/gamefic/core_ext/string.rb +4 -0
  8. data/lib/gamefic/describable.rb +108 -46
  9. data/lib/gamefic/direction.rb +46 -0
  10. data/lib/gamefic/director/delegate.rb +91 -0
  11. data/lib/gamefic/director/order.rb +10 -0
  12. data/lib/gamefic/director/parser.rb +119 -0
  13. data/lib/gamefic/director.rb +16 -197
  14. data/lib/gamefic/engine/cgi.rb +221 -0
  15. data/lib/gamefic/engine/tty.rb +237 -0
  16. data/lib/gamefic/engine.rb +88 -67
  17. data/lib/gamefic/entity.rb +96 -69
  18. data/lib/gamefic/grammar/conjugator.rb +20 -0
  19. data/lib/gamefic/grammar/gender.rb +11 -0
  20. data/lib/gamefic/grammar/person.rb +10 -0
  21. data/lib/gamefic/grammar/plural.rb +13 -0
  22. data/lib/gamefic/grammar/pronouns.rb +60 -0
  23. data/lib/gamefic/grammar/tense.rb +6 -0
  24. data/lib/gamefic/grammar/verb_set.rb +43 -0
  25. data/lib/gamefic/grammar/verbs.rb +25 -0
  26. data/lib/gamefic/grammar/word_adapter.rb +36 -0
  27. data/lib/gamefic/grammar.rb +13 -0
  28. data/lib/gamefic/html.rb +53 -0
  29. data/lib/gamefic/keywords.rb +51 -33
  30. data/lib/gamefic/node.rb +65 -58
  31. data/lib/gamefic/plot/article_mount.rb +22 -0
  32. data/lib/gamefic/plot/command_mount.rb +88 -0
  33. data/lib/gamefic/plot/entity_mount.rb +45 -0
  34. data/lib/gamefic/plot/query_mount.rb +9 -0
  35. data/lib/gamefic/plot/scene_mount.rb +181 -0
  36. data/lib/gamefic/plot/you_mount.rb +22 -0
  37. data/lib/gamefic/plot.rb +296 -247
  38. data/lib/gamefic/query/ambiguous_children.rb +5 -0
  39. data/lib/gamefic/query/base.rb +265 -0
  40. data/lib/gamefic/query/children.rb +10 -0
  41. data/lib/gamefic/query/expression.rb +47 -0
  42. data/lib/gamefic/query/family.rb +10 -0
  43. data/lib/gamefic/query/many_children.rb +7 -0
  44. data/lib/gamefic/query/matches.rb +11 -0
  45. data/lib/gamefic/query/parent.rb +10 -0
  46. data/lib/gamefic/query/plural_children.rb +14 -0
  47. data/lib/gamefic/query/self.rb +10 -0
  48. data/lib/gamefic/query/siblings.rb +10 -0
  49. data/lib/gamefic/query/text.rb +43 -0
  50. data/lib/gamefic/query.rb +19 -203
  51. data/lib/gamefic/rule.rb +18 -0
  52. data/lib/gamefic/scene/active.rb +25 -0
  53. data/lib/gamefic/scene/concluded.rb +22 -0
  54. data/lib/gamefic/scene/multiplechoice.rb +74 -0
  55. data/lib/gamefic/scene/paused.rb +26 -0
  56. data/lib/gamefic/scene/yesorno.rb +43 -0
  57. data/lib/gamefic/scene.rb +125 -0
  58. data/lib/gamefic/script/base.rb +33 -0
  59. data/lib/gamefic/script/file.rb +14 -0
  60. data/lib/gamefic/script/text.rb +14 -0
  61. data/lib/gamefic/script.rb +9 -0
  62. data/lib/gamefic/serialized.rb +24 -0
  63. data/lib/gamefic/shell.rb +9 -247
  64. data/lib/gamefic/snapshots.rb +134 -0
  65. data/lib/gamefic/source/base.rb +12 -0
  66. data/lib/gamefic/source/file.rb +23 -0
  67. data/lib/gamefic/source/text.rb +16 -0
  68. data/lib/gamefic/source.rb +9 -0
  69. data/lib/gamefic/stage.rb +75 -0
  70. data/lib/gamefic/syntax.rb +106 -124
  71. data/lib/gamefic/tester.rb +20 -0
  72. data/lib/gamefic/version.rb +3 -0
  73. data/lib/gamefic.rb +18 -12
  74. metadata +102 -70
  75. data/lib/gamefic/base.rb +0 -10
  76. data/lib/gamefic/before.rb +0 -12
  77. data/lib/gamefic/import/basics/actions/close.rb +0 -16
  78. data/lib/gamefic/import/basics/actions/commands.rb +0 -3
  79. data/lib/gamefic/import/basics/actions/drop-in.rb +0 -17
  80. data/lib/gamefic/import/basics/actions/drop-on.rb +0 -16
  81. data/lib/gamefic/import/basics/actions/drop.rb +0 -30
  82. data/lib/gamefic/import/basics/actions/enter.rb +0 -16
  83. data/lib/gamefic/import/basics/actions/go.rb +0 -35
  84. data/lib/gamefic/import/basics/actions/inventory.rb +0 -8
  85. data/lib/gamefic/import/basics/actions/leave.rb +0 -29
  86. data/lib/gamefic/import/basics/actions/look-in-at.rb +0 -27
  87. data/lib/gamefic/import/basics/actions/look-under.rb +0 -3
  88. data/lib/gamefic/import/basics/actions/look.rb +0 -71
  89. data/lib/gamefic/import/basics/actions/nil.rb +0 -25
  90. data/lib/gamefic/import/basics/actions/open.rb +0 -23
  91. data/lib/gamefic/import/basics/actions/quit.rb +0 -3
  92. data/lib/gamefic/import/basics/actions/take.rb +0 -107
  93. data/lib/gamefic/import/basics/entities/container.rb +0 -8
  94. data/lib/gamefic/import/basics/entities/entity.rb +0 -11
  95. data/lib/gamefic/import/basics/entities/fixture.rb +0 -5
  96. data/lib/gamefic/import/basics/entities/item.rb +0 -5
  97. data/lib/gamefic/import/basics/entities/portal.rb +0 -40
  98. data/lib/gamefic/import/basics/entities/room.rb +0 -30
  99. data/lib/gamefic/import/basics/entities/scenery.rb +0 -5
  100. data/lib/gamefic/import/basics/entities/supporter.rb +0 -6
  101. data/lib/gamefic/import/basics/entities/thing.rb +0 -16
  102. data/lib/gamefic/import/basics/queries/reachable.rb +0 -38
  103. data/lib/gamefic/import/basics/queries/room.rb +0 -8
  104. data/lib/gamefic/import/basics/queries/visible.rb +0 -32
  105. data/lib/gamefic/import/basics/rules/has-enough-light.rb +0 -14
  106. data/lib/gamefic/import/basics.old/actions/container.rb +0 -112
  107. data/lib/gamefic/import/basics.old/actions/inventory.rb +0 -50
  108. data/lib/gamefic/import/basics.old/actions/look.rb +0 -53
  109. data/lib/gamefic/import/basics.old/actions/meta.rb +0 -6
  110. data/lib/gamefic/import/basics.old/actions/traversal.rb +0 -35
  111. data/lib/gamefic/import/basics.old/actions.rb +0 -1
  112. data/lib/gamefic/import/basics.old/entities/container.rb +0 -3
  113. data/lib/gamefic/import/basics.old/entities/fixture.rb +0 -3
  114. data/lib/gamefic/import/basics.old/entities/item.rb +0 -3
  115. data/lib/gamefic/import/basics.old/entities/portal.rb +0 -43
  116. data/lib/gamefic/import/basics.old/entities/room.rb +0 -27
  117. data/lib/gamefic/import/basics.old/entities/scenery.rb +0 -3
  118. data/lib/gamefic/import/basics.old/entities/supporter.rb +0 -3
  119. data/lib/gamefic/import/basics.old/entities.rb +0 -1
  120. data/lib/gamefic/import/basics.old/room_modes.rb +0 -48
  121. data/lib/gamefic/import/basics.rb +0 -6
  122. data/lib/gamefic/import/room_modes.rb +0 -48
  123. data/lib/gamefic/import/standard.rb +0 -1
  124. data/lib/gamefic/meta.rb +0 -12
  125. data/lib/gamefic/optionset.rb +0 -114
  126. data/lib/gamefic/requirement.rb +0 -14
  127. data/lib/gamefic/story.rb +0 -14
  128. data/lib/gamefic/thing.rb +0 -7
@@ -1,35 +0,0 @@
1
- respond :go, Query::Siblings.new(Portal) do |actor, portal|
2
- actor.parent = portal.destination
3
- actor.tell "You go #{portal.name}."
4
- actor.perform "look"
5
- end
6
-
7
- respond :go, Query::Text.new() do |actor, string|
8
- actor.tell "You don't see any exit \"#{string}\" from here."
9
- end
10
-
11
- respond :go do |actor|
12
- actor.tell "Where do you want to go?"
13
- end
14
-
15
- xlate "north", :go, "north"
16
- xlate "south", :go, "south"
17
- xlate "west", :go, "west"
18
- xlate "east", :go, "east"
19
- xlate "up", :go, "up"
20
- xlate "down", :go, "down"
21
- xlate "northwest", :go, "northwest"
22
- xlate "northeast", :go, "northeast"
23
- xlate "southwest", :go, "southwest"
24
- xlate "southeast", :go, "southeast"
25
-
26
- xlate "n", :go, "north"
27
- xlate "s", :go, "south"
28
- xlate "w", :go, "west"
29
- xlate "e", :go, "east"
30
- xlate "u", :go, "up"
31
- xlate "d", :go, "down"
32
- xlate "nw", :go, "northwest"
33
- xlate "ne", :go, "northeast"
34
- xlate "sw", :go, "southwest"
35
- xlate "se", :go, "southeast"
@@ -1,8 +0,0 @@
1
- respond :inventory do |actor|
2
- if actor.children.length > 0
3
- actor.tell actor.children.join(', ')
4
- else
5
- actor.tell "You aren't carrying anything."
6
- end
7
- end
8
- xlate "i", :inventory
@@ -1,29 +0,0 @@
1
- respond :leave, Query::Parent.new(Supporter) do |actor, supporter|
2
- actor.parent = supporter.parent
3
- actor.tell "You get off #{the supporter}."
4
- end
5
- respond :leave, Query::Parent.new(Container) do |actor, supporter|
6
- actor.parent = supporter.parent
7
- actor.tell "You get out of #{the supporter}."
8
- end
9
- respond :leave, Query::Parent.new(Room) do |actor, room|
10
- portals = room.children.that_are(Portal)
11
- if portals.length == 0
12
- actor.tell "You don't see any obvious exits."
13
- elsif portals.length == 1
14
- actor.perform "go #{portals[0]}"
15
- else
16
- actor.tell "I don't know which way you want to go: #{portals.join_and(', ', ' or ')}."
17
- end
18
- end
19
- respond :leave do |actor|
20
- actor.perform "leave #{actor.parent}"
21
- end
22
- xlate "exit :supporter", :leave, :supporter
23
- xlate "get off :supporter", :leave, :supporter
24
- xlate "get up from :supporter", :leave, :supporter
25
- xlate "get up", :leave
26
- xlate "stand", :leave
27
- xlate "get off", :leave
28
- xlate "get out :container", :leave, :container
29
- xlate "get out of :container", :leave, :container
@@ -1,27 +0,0 @@
1
- respond :look_in_at, Query::Text.new(), Query::Text.new() do |actor, container, thing|
2
- actor.tell "You don't see any '#{container}' here."
3
- end
4
-
5
- respond :look_in_at, Query::Reachable.new(), Query::Text.new() do |actor, container, thing|
6
- actor.tell "You don't see any '#{thing}' in #{the container}."
7
- end
8
-
9
- respond :look_in_at, Query::Reachable.new(), Query::Subquery.new() do |actor, container, thing|
10
- if thing.is?(:supported) or thing.is?(:attached) or ( thing.is?(:contained) and (container.is?(:open) or container.is?(:transparent)) )
11
- actor.perform "look #{thing}"
12
- elsif container.is?(:closed)
13
- actor.tell "#{The container} is closed."
14
- else
15
- passthru
16
- end
17
- end
18
-
19
- xlate "look in :container at :thing", :look_in_at, :container, :thing
20
- xlate "l in :container at :thing", :look_in_at, :container, :thing
21
-
22
- xlate "look :thing in :container", :look_in_at, :container, :thing
23
- xlate "look at :thing in :container", :look_in_at, :container, :thing
24
- xlate "l :thing in :container", :look_in_at, :container, :thing
25
- xlate "examine :thing in :container", :look_in_at, :container, :thing
26
- xlate "exam :thing in :container", :look_in_at, :container, :thing
27
- xlate "x :thing in :container", :look_in_at, :container, :thing
@@ -1,3 +0,0 @@
1
- respond :look_under, Query::Reachable.new() do |actor, thing|
2
- actor.tell "There's nothing to see under #{the thing}."
3
- end
@@ -1,71 +0,0 @@
1
- respond :look, Query::Parent.new(Supporter) do |actor, supporter|
2
- actor.tell supporter.description
3
- actor.tell "You are currently on #{the supporter}."
4
- end
5
-
6
- respond :look, Query::Room.new(Room) do |actor, room|
7
- actor.tell room.name.cap_first
8
- actor.tell room.description
9
- chars = room.children.that_are(Character) - [actor]
10
- if chars.length > 0
11
- actor.tell "Others here: #{chars.join(", ")}"
12
- end
13
- items = room.children.that_are(:itemized) - [actor]
14
- if items.length > 0
15
- actor.tell "You see #{items.join_and}."
16
- end
17
- portals = room.children.that_are(Portal)
18
- if portals.length > 0
19
- if portals.length == 1
20
- actor.tell "There is an exit #{portals[0]}."
21
- else
22
- actor.tell "There are exits #{portals.join_and(', ')}."
23
- end
24
- end
25
- if actor.is? :supported
26
- actor.tell "You are on #{the actor.parent}."
27
- actor.parent.children.that_are(:supported).that_are_not(actor).each { |s|
28
- actor.tell "#{A s} is on #{the actor.parent}."
29
- }
30
- end
31
- end
32
- xlate "look", :look, "around"
33
- xlate "l", :look, "around"
34
-
35
- respond :look, Query::Visible.new() do |actor, thing|
36
- actor.tell thing.description
37
- thing.children.that_are(:attached).that_are(:itemized).each { |item|
38
- actor.tell "#{An item} is attached to #{the thing}."
39
- }
40
- end
41
-
42
- respond :look, Query::Text.new() do |actor, string|
43
- actor.tell "You don't see any \"#{string}\" here."
44
- end
45
-
46
- respond :look, Query::Reachable.new(Container) do |actor, container|
47
- passthru
48
- if container.is? :openable
49
- actor.tell "#{The container} is #{container.is?(:open) ? 'open' : 'closed'}."
50
- end
51
- if container.is? :open
52
- contents = container.children.that_are(:contained)
53
- contents.each { |thing|
54
- actor.tell "You see #{a thing} inside #{the container}."
55
- }
56
- end
57
- end
58
-
59
- respond :look, Query::Siblings.new(Supporter) do |actor, supporter|
60
- passthru
61
- supported = supporter.children.that_are(:supported)
62
- supported.each { |thing|
63
- actor.tell "You see #{a thing} sitting there."
64
- }
65
- end
66
-
67
- xlate "look at :thing", :look, :thing
68
- xlate "l :thing", :look, :thing
69
- xlate "examine :thing", :look, :thing
70
- xlate "x :thing", :look, :thing
71
- xlate "search :thing", :look, :thing
@@ -1,25 +0,0 @@
1
- respond nil, Query::Text.new() do |actor, string|
2
- words = string.split_words
3
- if commandwords.include?(words[0])
4
- if words.length > 1
5
- actor.tell "I recognize '#{words[0]}' as a verb but could not understand the rest of your sentence."
6
- else
7
- actor.tell "I recognize '#{words[0]}' as a verb but could not understand it in this context."
8
- end
9
- else
10
- found = []
11
- commandwords.each { |c|
12
- if c.length > words[0].length and c.start_with?(words[0])
13
- found.push c
14
- end
15
- }
16
- if found.length == 1
17
- words[0] = found[0]
18
- actor.perform words.join(' ')
19
- elsif found.length > 1
20
- actor.tell "I'm not sure if #{words[0]} means #{found.join_and(', ', ' or ')}."
21
- else
22
- actor.tell "I don't know what you mean by '#{string}.'"
23
- end
24
- end
25
- end
@@ -1,23 +0,0 @@
1
- respond :open, Query::Text.new() do |actor, string|
2
- actor.tell "You don't see any \"#{string}\" here."
3
- end
4
-
5
- respond :open, Query::Reachable.new(Entity) do |actor, thing|
6
- actor.tell "You can't open #{the thing}."
7
- end
8
-
9
- respond :open, Query::Reachable.new(Container, :openable) do |actor, container|
10
- # Portable containers need to be picked up before they are opened.
11
- if container.is? :portable
12
- actor.perform "take #{container}"
13
- if container.parent != actor
14
- break
15
- end
16
- end
17
- if container.is? :closed
18
- actor.tell "You open #{the container}."
19
- container.is :open
20
- else
21
- actor.tell "It's already open."
22
- end
23
- end
@@ -1,3 +0,0 @@
1
- meta :quit do |actor|
2
- actor.state = GameOverState.new(actor)
3
- end
@@ -1,107 +0,0 @@
1
- respond :take, Query::Text.new() do |actor, thing|
2
- actor.tell "I don't see anything called '#{thing}' here."
3
- end
4
-
5
- respond :take, Query::Reachable.new(:not_portable) do |actor, thing|
6
- actor.tell "You can't take #{the thing}."
7
- end
8
-
9
- respond :take, Query::Siblings.new(:portable) do |actor, thing|
10
- thing.parent = actor
11
- actor.tell "You take #{the thing}."
12
- end
13
-
14
- respond :take, Query::Siblings.new() do |actor, thing|
15
- actor.tell "You can't carry #{the thing}."
16
- end
17
-
18
- respond :take, Query::Visible.new() do |actor, thing|
19
- if thing.parent == actor.parent
20
- passthru
21
- elsif thing.parent.is?(:closed)
22
- actor.tell "#{The thing} is inside #{the thing.parent}, which is closed."
23
- end
24
- end
25
-
26
- respond :take, Query::Visible.new() do |actor, thing|
27
- if actor.is? :supported
28
- if actor.parent != thing.parent and actor.parent != thing.parent.parent
29
- actor.tell "You can't reach it from #{the actor.parent}."
30
- end
31
- else
32
- passthru
33
- end
34
- end
35
-
36
- respond :take, Query::Reachable.new(:attached) do |actor, thing|
37
- actor.tell "#{The thing} is attached to #{the thing.parent}."
38
- end
39
-
40
- respond :take, Query::Reachable.new(:portable, :contained) do |actor, thing|
41
- if thing.parent != actor.parent
42
- if thing.parent.is?(:open) == false
43
- if thing.parent.is?(:transparent)
44
- actor.tell "#{The thing} is closed."
45
- else
46
- passthru
47
- end
48
- break
49
- end
50
- actor.tell "You take #{the thing} from #{the thing.parent}."
51
- thing.parent = actor
52
- else
53
- passthru
54
- end
55
- end
56
-
57
- respond :take, Query::Reachable.new(:portable, :supported) do |actor, thing|
58
- actor.tell "You take #{the thing} from #{the thing.parent}."
59
- thing.parent = actor
60
- end
61
-
62
- respond :take, Query::Children.new() do |actor, thing|
63
- actor.tell "You're already carrying #{the thing}."
64
- end
65
-
66
- xlate "get :thing", :take, :thing
67
- xlate "pick up :thing", :take, :thing
68
- xlate "pick :thing up", :take, :thing
69
-
70
- # The :take_from actions make it a little easier to disambiguate things. For
71
- # example, if there's a green key in the room and a red key in a box, any of
72
- # the following will understand which key you mean:
73
- # * take green key
74
- # * take red key
75
- # * take key from room
76
- # * take key from box
77
- respond :take_from, Query::Room.new(), Query::Siblings.new() do |actor, container, thing|
78
- actor.perform "take #{thing}"
79
- end
80
- respond :take_from, Query::Reachable.new(Container, :closed), Query::Text.new() do |actor, container, thing|
81
- actor.tell "#{The container} is closed."
82
- end
83
- respond :take_from, Query::Reachable.new(Container, :open), Query::Subquery.new(:contained) do |actor, container, thing|
84
- actor.perform "take #{thing}"
85
- end
86
- respond :take_from, Query::Reachable.new(Container, :open), Query::Subquery.new(:attached) do |actor, container, thing|
87
- actor.tell "#{The thing} is attached to #{the container}."
88
- end
89
- respond :take_from, Query::Reachable.new(Supporter), Query::Subquery.new(:supported) do |actor, container, thing|
90
- actor.perform "take #{thing}"
91
- end
92
- xlate "take :thing from :container", :take_from, :container, :thing
93
- xlate "get :thing from :container", :take_from, :container, :thing
94
- xlate "pick :thing up from :container", :take_from, :container, :thing
95
- xlate "pick up :thing from :container", :take_from, :container, :thing
96
- xlate "take :thing in :container", :take_from, :container, :thing
97
- xlate "get :thing in :container", :take_from, :container, :thing
98
- xlate "pick :thing up in :container", :take_from, :container, :thing
99
- xlate "pick up :thing in :container", :take_from, :container, :thing
100
- xlate "take :thing on :container", :take_from, :container, :thing
101
- xlate "get :thing on :container", :take_from, :container, :thing
102
- xlate "pick :thing up on :container", :take_from, :container, :thing
103
- xlate "pick up :thing on :container", :take_from, :container, :thing
104
- xlate "take :thing inside :container", :take_from, :container, :thing
105
- xlate "get :thing inside :container", :take_from, :container, :thing
106
- xlate "pick :thing up inside :container", :take_from, :container, :thing
107
- xlate "pick up :thing inside :container", :take_from, :container, :thing
@@ -1,8 +0,0 @@
1
- class Container < Thing
2
-
3
- end
4
-
5
- options(Container, :not_enterable, :enterable)
6
- options(Container, :opaque, :transparent)
7
- options(Container, :open, :closed).default = :open
8
- options(Container, :openable, :unopenable).default = :unopenable
@@ -1,11 +0,0 @@
1
- class Entity
2
- def room
3
- p = parent
4
- while !p.kind_of?(Room) and !p.nil?
5
- p = p.parent
6
- end
7
- p
8
- end
9
- end
10
-
11
- options(Entity, :not_portable, :portable)
@@ -1,5 +0,0 @@
1
- class Fixture < Thing
2
-
3
- end
4
-
5
- set_default_for(Fixture, :not_portable)
@@ -1,5 +0,0 @@
1
- class Item < Thing
2
-
3
- end
4
-
5
- set_default_for(Item, :portable)
@@ -1,40 +0,0 @@
1
- class Portal < Entity
2
- attr_accessor :destination
3
- def find_reverse
4
- rev = Portal.reverse(self.name)
5
- if rev != nil
6
- destination.children.that_are(Portal).each { |c|
7
- if c.name == rev
8
- return c
9
- end
10
- }
11
- end
12
- nil
13
- end
14
- def self.reverse(direction)
15
- case direction.downcase
16
- when "north"
17
- "south"
18
- when "south"
19
- "north"
20
- when "west"
21
- "east"
22
- when "east"
23
- "west"
24
- when "northwest"
25
- "southeast"
26
- when "southeast"
27
- "northwest"
28
- when "northeast"
29
- "southwest"
30
- when "southwest"
31
- "northeast"
32
- when "up"
33
- "down"
34
- when "down"
35
- "up"
36
- else
37
- nil
38
- end
39
- end
40
- end
@@ -1,30 +0,0 @@
1
- class Room < Entity
2
- def connect(destination, direction, type = Portal, two_way = true)
3
- portal = type.new self.plot, :name => direction, :parent => self, :destination => destination
4
- portal.proper_named = true
5
- if two_way == true
6
- reverse = Portal.reverse(direction)
7
- if reverse == nil
8
- raise "\"#{direction.cap_first}\" does not have an opposite direction"
9
- end
10
- portal2 = type.new(self.plot, {
11
- :name => reverse,
12
- :parent => destination,
13
- :destination => self
14
- })
15
- portal2.proper_named = true
16
- end
17
- portal
18
- end
19
- def synonyms
20
- super.to_s + " around here room"
21
- end
22
- def tell(message, refresh = false)
23
- children.each { |c|
24
- c.tell message, refresh
25
- }
26
- end
27
- end
28
-
29
- options(Room, :lighted, :dark).default = :lighted
30
- options(Room, :enterable, :not_enterable)
@@ -1,5 +0,0 @@
1
- class Scenery < Thing
2
-
3
- end
4
- set_default_for(Scenery, :not_portable)
5
- set_default_for(Scenery, :not_itemized)
@@ -1,6 +0,0 @@
1
- class Supporter < Thing
2
-
3
- end
4
-
5
- options(Supporter, :not_enterable, :enterable)
6
- set_default_for(Supporter, :not_portable)
@@ -1,16 +0,0 @@
1
- options(Thing, :located, :contained, :supported, :attached).default = :located
2
- options(Thing, :itemized, :not_itemized)
3
- set_default_for(Thing, :portable)
4
-
5
- class Thing
6
- def parent=(entity)
7
- super
8
- if parent.kind_of?(Supporter)
9
- is :supported
10
- elsif parent.kind_of?(Container)
11
- is :contained
12
- else
13
- is :located
14
- end
15
- end
16
- end
@@ -1,38 +0,0 @@
1
- # This query filters for objects that the player might be able to handle or
2
- # manipulate, including the following:
3
- #
4
- # * Siblings (other entities with the same parent)
5
- # * The subject's children
6
- # * Entities on reachable supporters
7
- # * Entities in reachable open containers
8
- # * Entities attached to reachable entities
9
- #
10
- # It excludes anything that may be visible but are not reachable:
11
- # * Entities inside closed transparent containers
12
- # * Entities that share the same room as the subject, but not the same parent.
13
-
14
- class Query::Reachable < Query::Family
15
- def context_from(subject)
16
- array = super
17
- if subject.is?(:supported) or subject.is?(:contained)
18
- array.push subject.parent
19
- end
20
- array.each { |thing|
21
- if thing.kind_of?(Container)
22
- if thing.is? :open
23
- array += thing.children.that_are(:contained)
24
- end
25
- elsif thing.kind_of?(Supporter)
26
- array += thing.children.that_are(:supported)
27
- end
28
- thing.children.that_are(:attached).each { |att|
29
- array.push att
30
- if att.kind_of?(Supporter) or att.is?(:open)
31
- array += att.children.that_are(:contained)
32
- array += att.children.that_are(:supported)
33
- end
34
- }
35
- }
36
- array.uniq
37
- end
38
- end
@@ -1,8 +0,0 @@
1
- # This query resolves to the subject's room, as opposed to the parent. It's
2
- # useful for making sure you target the room instead of a container or a
3
- # supporter.
4
- class Query::Room < Query::Parent
5
- def context_from(subject)
6
- [subject.room]
7
- end
8
- end
@@ -1,32 +0,0 @@
1
- # This query filters for objects that the player can see, regardless of
2
- # whether they are reachable. It includes the following:
3
- #
4
- # * Siblings (other entities with the same parent)
5
- # * The subject's children
6
- # * Children of the subject's room (if room is not parent)
7
- # * Entities on reachable supporters
8
- # * Entities inside reachable open containers
9
- # * Entities inside reachable transparent containers
10
- # * Entities attached to reachable entities
11
-
12
- class Query::Visible < Query::Family
13
- def base_specificity
14
- 40
15
- end
16
- def context_from(subject)
17
- array = super
18
- array += subject.room.children
19
- array.uniq!
20
- array.each { |thing|
21
- if thing.kind_of?(Container)
22
- if thing.is? :open or thing.is? :transparent
23
- array += thing.children.that_are(:contained)
24
- end
25
- elsif thing.kind_of?(Supporter)
26
- array += thing.children.that_are(:supported)
27
- end
28
- array += thing.children.that_are(:attached)
29
- }
30
- array
31
- end
32
- end
@@ -1,14 +0,0 @@
1
- assert :has_enough_light do |actor|
2
- if actor.room.is? :lighted
3
- true
4
- else
5
- actor.tell "It's too dark in here."
6
- false
7
- end
8
- end
9
-
10
- # Allow the go command in dark rooms
11
- before :go, Query::Siblings.new(Portal) do |actor, portal|
12
- pass :has_enough_light
13
- passthru
14
- end