~ubuntu-branches/ubuntu/hoary/inform/hoary

« back to all changes in this revision

Viewing changes to include/doors.h

  • Committer: Bazaar Package Importer
  • Author(s): Mark Baker
  • Date: 2004-03-29 23:52:44 UTC
  • Revision ID: james.westby@ubuntu.com-20040329235244-fox1z1yv7d6vojoo
Tags: upstream-6.30
ImportĀ upstreamĀ versionĀ 6.30

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -*- Inform -*- !!!!
 
2
!       DOORS           An INFORM 6.10 library creating easy-to-code doors
 
3
!                       By L. Ross Raszewski <rraszews@skipjack.bluecrab.org>
 
4
!
 
5
!  According to "The Inform Designer's Manual, 3rd edition" (reprinted 
 
6
! without permission)
 
7
! To set up a door:
 
8
!
 
9
!   (a) give the object the door attribute;
 
10
!   (b) set its door_to property to the destination;
 
11
!   (c) set its door_dir property to the direction which that would be,
 
12
!       such as n_to;
 
13
!   (d) make the room's map connection in that direction point to the door
 
14
!       itself.
 
15
!
 
16
! Yeah, right.  The majority of doors you'll meet in real life are two-sided
 
17
! and anyone who's tried to code up a two-sided door in Inform knows what 
 
18
! they're in for. You'll need something like a
 
19
!       door_to [; if (location == shrine) return jungle; return shrine;],
 
20
! and a 
 
21
!       door_dir [; if (location == shrine) return u_to; return d_to;],
 
22
! Now, I'll agree this isn't all that bad, but I'm sure you've wished it 
 
23
! was easier.  Many a newbie has died trying to code up something lke this.
 
24
!
 
25
! Not anymore.
 
26
!
 
27
! Observe if you will the Connector class.
 
28
!
 
29
! Suppose you need a door between roomA and roomB, where roomA is to the east 
 
30
! of roomB.
 
31
!
 
32
!
 
33
!  Connector door "door"
 
34
!        with name "door",
 
35
!             e_to roomA,
 
36
!             w_to roomB,
 
37
!             when_open "The door is open",  
 
38
!             when_closed "The door is closed",
 
39
!        has openable;
 
40
!
 
41
! Voila!  This simple syntax is equivalent to the conventional syntax:
 
42
!
 
43
! Object door "door"
 
44
!        with name "door",
 
45
!             door_to [; if (location == roomA) return roomB; return roomA;],
 
46
!             door_dir [; if (location == roomB) return e_to; return w_to;],
 
47
!             when_open "The door is open",  
 
48
!             when_closed "The door is closed",
 
49
!             found_in roomA roomB;
 
50
!        has openable door static;
 
51
!
 
52
! I can hear you now.  "What?  I save three lousy lines?"  Well, yeah, but in
 
53
! a game with a lot of doors, you've saved yourself some syntax. And it 
 
54
! certaintly is more intuitive.
 
55
 
56
! The only catch, for the sake of economy, is that you have to call the 
 
57
! function InitDoors(); in your initialise.
 
58
!
 
59
! Also by the author:
 
60
!               The AltMenuing system
 
61
!       Center          Centers a line of text in either window.
 
62
!       Domenu          Improved menuing with multiple description lines
 
63
!       Altmenu         Object oriented menuing system
 
64
!       Hints           Altmenu hint system
 
65
!       Sound           The Inform Sound System
 
66
!       YesNo           pseudo-rhetorical Yes or no questions
 
67
!       Date            Datekeeping and printing
 
68
!       Footnote        Autonumbering footnotes
 
69
!       Locktest        Default key selection
 
70
!       Newlock         Key-side lock definition
 
71
!       Ordinal         Ordinal number printing
 
72
!       Whatis          "What is a" questions
 
73
!       Senses          Recursive sensory perception
 
74
!       Pmove           Move objects into the tree as the youngest object
 
75
!       Movie           Non-interactive cut-scenes
 
76
!       Manual          inform "instruction manual" system
 
77
!       
 
78
!  Coming soon:
 
79
!       Converse        Hit-word based conversation
 
80
!       MenuTalk        Menu-based Conversation
 
81
!       UniCursr        Unicursor- Text adventures with the contol simplicity
 
82
!                       of omnifunction click graphic games (ie. Type "clock" 
 
83
!                       to examine, take, or manipulate the clock)
 
84
!
 
85
!       Please write me and tell me what you think.
 
86
 
 
87
Class   Connector
 
88
 with   door_dir [;
 
89
                if (location==self.sidea) return self.dira;
 
90
                return self.dirb;
 
91
        ],
 
92
        door_to [;
 
93
                if (location==self.sidea) return self.sideb;
 
94
                return self.sidea;
 
95
        ],
 
96
        sidea 0,
 
97
        dira 0,
 
98
        sideb 0,
 
99
        dirb 0,
 
100
        found_in 0 0,
 
101
  has   door static;
 
102
 
 
103
[ InitDoors o i j;
 
104
        objectloop (j ofclass Connector) { 
 
105
                objectloop (o in compass) {
 
106
                        i = o.door_dir;
 
107
                        if (j provides i) {
 
108
                                j.sidea = j.i;
 
109
                                j.dirb = i;
 
110
                        }
 
111
                }
 
112
 
 
113
                objectloop (o in compass) {
 
114
                        i = o.door_dir;
 
115
                        if ((j provides i) && (j.dirb ~= i)) {
 
116
                                j.sideb = j.i;
 
117
                                j.dira = i;
 
118
                        }
 
119
                }
 
120
 
 
121
                j.&found_in-->0 = j.sidea;
 
122
                j.&found_in-->1 = j.sideb;
 
123
        }
 
124
];