c7113a46b8f6a443d7006091b46d775505606ba3
[rfk-inform.git] / kitten.inf
1 ! robotfindskitten
2 ! A Zen Simulation
3 ! Release 7 / Serial number 130315 / Inform v6.33
4 !
5 !     [-]       |\_/|        http://www.robotfindskitten.org
6 !     (+)=C     |o o|__      Leonard Richardson (C) 1997, 2000
7 !     | |       --*--__\     David Griffith (C) 2002  (Inform Edition)
8 !     OOO       C_C(____)
9 !
10 !
11 ! This Zen simulation is based on the C version v1600003.248b
12 ! by Leonard Richardson (C) 1997, 2000.
13 ! Written originally for the Nerth Pork robotfindskitten contest.
14 ! Reimplemented in Inform by David Griffith (C) 2002.
15 !
16 ! Lots more information on robotfindskitten is available at
17 ! http://www.robotfindskitten.org.
18 !
19 !
20 ! In this game, you are Robot (#).  Your job is to find Kitten.  This
21 ! task is complicated by the existance of various things which are not
22 ! kitten.  Robot must touch items to determine if they are Kitten or
23 ! not.  Move Robot with the cursor keys, the numeric keypad, or
24 ! using the vi/rogue movement keys. The game ends when robotfindskitten.
25 ! Alternatively, you may end the game by hitting the Esc or Q keys.
26 !
27 ! Developed with Inform 6.21.4 as installed from NetBSD's pkgsrc tree
28 ! and Frotz 2.42.
29 !
30
31 ! Notes:
32 !       1) More than half of the code is taken up by non kitten items
33 !       (NKIs).  When I compiled the code with just five messages and
34 !       no debugging code, the resulting binary was less than 10k bytes.
35 !
36 !       2) If it wasn't already abundantly obvious, this program won't
37 !       compile to Glulx because of copious use of Z-machine assembly
38 !       instructions.
39 !       
40 !       3) Compiling for V5 or higher is required due to "style" calls.
41 !       Is there a reason why someone would want to compile this for V4
42 !       or previous?
43
44 !Switches xv5s;
45
46 Switches "d2~S";
47
48
49 Constant Nonkitten_Default 20;
50
51 ! Maxmimum possible number of non-kitten items on the playfield at once.
52 ! For whatever reason, this cannot be set dynamically.
53 !
54 Constant Nonkitten_Max  589;
55
56 Release 7;
57 Serial "130315";        ! Presumed release date
58
59 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
60
61 Constant Story "robotfindskitten";
62 Constant Headline "^A Zen Simulation^";
63
64 ! NKIs are generated with nki2inf.pl and put into nki.inf
65 Include "nki.inf";
66
67 Constant Anim_Meet      10;     ! Number of spaces from the left where
68                                 !  Robot and Kitten meet during animation.
69
70 Global Height = 0;              ! These are set at runtime.
71 Global Width = 0;
72
73 Global Back_def = 2;            ! Black.
74 Global Fore_def = 9;            ! White.
75
76 Global TopBar = 5;              ! Lines from the top.
77
78 Global player_x = 0;            ! Keeping track of where the player was
79 Global player_y = 0;            !  1 move ago allows us to keep the
80 Global player_x_last = 0;       !  player from walking through obstacles.
81 Global player_y_last = 0;
82
83 Global kitten_x = 0;
84 Global kitten_y = 0;
85 Global kitten_char = 0;
86 Global kitten_color = 0;
87
88 Global last_message = "";       ! Always show the last-encountered message.
89
90 Global nonkitten_count = Nonkitten_Default;
91
92 Array nonkitten_x --> Nonkitten_Max;
93 Array nonkitten_y --> Nonkitten_Max;
94 Array nonkitten_color --> Nonkitten_Max;
95 Array nonkitten_char --> Nonkitten_Max;
96 Array nonkitten_msg --> Nonkitten_Max;
97
98 Global already_msg_count = 0;
99 Global already_count = 0;
100 Array already_x --> Nonkitten_Max + 2;
101 Array already_y --> Nonkitten_Max + 2;
102 Array already_msg --> Nonkitten_Max;
103
104 ! If a key is held down while the found_kitten animation is playing,
105 ! (0-->1) & $03ff gets corrupted.  Seems like it might be a bug
106 ! somewhere in Unix Frotz.
107 !
108 Global Real_Release = 0;
109
110 [ Main key;
111
112         @set_colour Fore_def Back_def;
113
114 !       if (MESSAGE_NUM < Nonkitten_Max) {
115 !               nonkitten_count = MESSAGE_NUM;
116 !       } else {
117 !               nonkitten_count = Nonkitten_Default;
118 !       }
119
120         nonkitten_count = Nonkitten_Default;
121
122         Real_Release = (0-->1)&$03ff;
123
124         Width = $22-->0;
125         Height = $24-->0;
126
127         main_menu();    
128         while (true) {
129                 key = getkey();
130                 switch (key) {
131                 'F':    already_count = 0;
132                         init_nonkittens();
133                         init_kitten();
134                         init_robot();
135                         while (findkitten())
136                                 ;
137                 'D':    set_nonkitten_count();
138                 'I':    print_instructions();
139                 'A':    print_about();
140                 'T':    print_thoughts();
141                 }
142                 if (key == 'Q' || key == $1b)   ! $1b == ESC
143                         break;
144                 main_menu();
145         }
146         quit;
147 ];
148
149
150 [ main_menu psycho;
151
152         ! There's a 1:50 chance that the kitten in the title screen
153         ! will have a "psycho" appearance.
154         !
155         psycho = random(50);
156         if (psycho == 1)
157                 psycho = true;
158         else
159                 psycho = false;
160
161         @erase_window $ffff;
162         @split_window 11;
163         @set_window 1;
164
165         Banner();
166         draw_horiz(TopBar);
167
168         draw_big_robot(3, 7);
169
170         if (psycho)
171                 draw_big_kitten_psycho(14, 7);
172         else
173                 draw_big_kitten(15, 7);
174
175         @set_cursor 7 30;
176         print "http://www.robotfindskitten.org";
177         @set_cursor 8 30;
178         print "Leonard Richardson (C) 1997, 2000";
179         @set_cursor 9 30;
180         print "David Griffith (C) 2002  (Inform Edition)";
181         @set_cursor 10 30;
182         print "    ", MESSAGE_NUM, " different nonkittens!";
183
184         @set_window 0;
185
186         print "  F) Find Kitten^",
187                 "  D) Difficulty  (", nonkitten_count, ")^",
188                 "  I) Instructions^",
189                 "  T) Thoughts^",
190                 "  A) About^",
191                 "  Q) Quit^",
192                 "^> ";
193 ];
194
195
196 ! Copied from module/verblibm.h of the Inform 6.21.3 standard library.
197 !
198 [ Banner i;
199         if (Story ~= 0) {
200                 style bold; 
201                 print (string) Story;
202                 style roman;
203         }
204         if (Headline ~= 0) {
205                 print (string) Headline;
206         }
207         print "Release ", Real_Release, " / Serial number ";
208         for (i=18:i<24:i++) print (char) 0->i;
209         print " / Inform v"; inversion; print "";
210         new_line;
211 ];
212
213
214 Constant INBUFSIZE 80;
215 Array inbuf -> INBUFSIZE;
216
217 [ set_nonkitten_count maxnum val;
218
219         while (true) {
220                 @erase_window $ffff;
221                 @split_window 5;
222                 @set_window 1;
223                 Banner();
224                 draw_horiz(TopBar);
225                 @set_window 0;
226
227                 if (MESSAGE_NUM < Nonkitten_Max) {
228                         maxnum = MESSAGE_NUM;
229                 } else {
230                         maxnum = Nonkitten_Max;
231                 } 
232
233                 print "^Please enter the number of nonkittens you
234                         wish to search through.^(1 to ", maxnum, " only)^^> ";
235
236                 while (true) {
237                         val = get_number(1, maxnum, nonkitten_count);
238                         if (val == -1) {
239                                 break;
240                         } else {
241                                 nonkitten_count = val;
242                                 return;
243                         }
244                 }
245         }
246 ];
247
248
249 [ get_number min max init inbufvar ix cx len val;
250
251         while (true) {
252                 inbuf->0 = (INBUFSIZE-3);
253                 inbuf->1 = 0;
254                 inbufvar = inbuf;
255                 ix = 0;
256                 @aread inbufvar ix;
257                 new_line;
258                 len = inbuf->1;
259                 cx = 0;
260                 while (cx < len && inbuf->(2+cx) == ' ')
261                         cx++;
262                 if (cx < len && inbuf->(2+cx) == '.')
263                         break;
264
265                 ! If user just hits return, use what we have already. 
266                 if (len == 0)
267                         return init;
268                 if (cx == len || inbuf->(2+cx) < '0' || inbuf->(2+cx) > '9') {
269                         print "Please enter a value from ", min, " to ", max,
270                                 ", or Enter by itself to exit.^
271                                 [Press any key to continue.] ";
272                         getkey();
273                         return -1;
274                 }
275                 val = 0;
276                 while (cx < len && inbuf->(2+cx) >= '0' && inbuf->(2+cx) <= '9') {
277                         val = val * 10 + (inbuf->(2+cx) - '0');
278                         cx++;
279                 }
280                 if (val < min || val > max) {
281                         print "Please enter a value from ", min, " to ", max,
282                                 ", or Enter by itself to exit.^
283                                 [Press any key to continue.] ";
284                         getkey();
285                         return -1;
286                 } else break;
287         }
288         return val;
289 ];
290
291
292 [ print_about;
293
294         @erase_window $ffff;
295         @split_window TopBar;
296         @set_window 1;
297         Banner();
298         draw_horiz(TopBar);
299         @set_window 0;
300
301 print "^
302 This Zen simulation is based on the C version v1600003.248b^
303 by Leonard Richardson (C) 1997, 2000.^
304 Written originally for the Nerth Pork robotfindskitten contest.^
305 Reimplemented in Inform by David Griffith (C) 2002.^
306 ^
307 This code is freely redistributable.  Do with it what you will, but
308 don't go about claiming you wrote it.  I, David Griffith, retain
309 copyright on this program except for the NKIs imported from the master
310 (aka POSIX) port.^
311 ^
312 Lots more information on robotfindskitten is available at
313 http://www.robotfindskitten.org.^
314 ^
315 To submit new NKI's, please go to the above URL.^
316 ^
317 ^
318 Release History:^
319 ^
320 Release 1 / Serial number 0211xx to 021214 or so^
321 Initial private release.  Limited distribution for beta testing and
322 debugging purposes.^
323 ^
324 Release 2 / Serial Number 021216^
325 First public release.^
326 ^
327 Release 3 / Serial Number 021221^
328 Bugfix release.^
329 - Movement keys 'J' and 'K' were swapped by mistake.  Fixed.^
330 - Special PalmOS movement key support added.^
331 - More NKIs added (401 total).^
332 ^
333 Release 4 / Serial Number 030131^
334 Light overhaul release.^
335 - Now an official port of robotfindskitten.^
336 - Typos in NKIs fixed.^
337 - Fixed diagonal collision-detection strangeness.^
338 - Added color support.^
339 - Added an easter egg.  Can you find it?^
340 - Removed PalmOS movement key support (superfluous and ugly).^
341 - Removed playfield resizing code (superfluous and ugly).^
342 - It's ~robotfindskitten~, not ~Robot Finds Kitten~.^
343 - Merged in new NKIs from the new POSIX release of robotfindskitten.^
344 - More NKIs added (561 total).^
345 ^
346 Release 5 / Serial Number 030524^
347 Even more NKIs release.^
348 - Idiotic typos fixed.^
349 - More NKIs added (602 total).^
350 ^
351 Release 6 / Serial Number 031116^
352 Challenge release.^
353 - More NKIs added (764 total).^
354 - Increased maximum difficulty to 589.^
355 - Lots more comments in the source code.^
356 - Assorted cleanups in the source code.^
357 ^
358 Release 7 / Serial Number 040523^
359 Grammatically correct release.^
360 - Grammar corrections from the POSIX port added.^
361 - More NKIs added (800 total).^
362 ^
363 ^
364 Known Bugs:^
365 ^
366 1) I still don't know why already_seen_xy() occasionally causes Robot to
367 get placed on top of another object when a game is started.  Fortunately
368 this seems to happen only very rarely and typically only if the
369 difficulty is set to more than 200.  This bug also seems to very
370 occasionally put Kitten underneath an NKI.^
371 ^
372 2) Under earlier versions of Windows Frotz, Robot used to appear as a
373 solid block. This was because of a bug in Windows Frotz which
374 incorrectly makes the cursor opaque. The cursor is now moved off to
375 the upper-right corner so that the game looks okay on terminals that use
376 something other than reverse for the cursor. I still can't figure out
377 how to make Inform hide the cursor completely. At least on xterm and
378 NetBSD's console, @@64set_cursor -1 doesn't work.^
379 ^
380 3) Under Windows Frotz, an annoying [MORE] prompt might appear at the
381 main menu. This is another bug in Windows Frotz which causes the
382 interpreter to follow Windows' suggestion that something less than 24 or
383 25 lines is okay.^
384 ^
385 [Press any key to continue.] "; 
386         getkey();
387 ];
388
389
390 [ print_instructions;
391         @erase_window $ffff;
392         @split_window TopBar;
393         @set_window 1;
394         Banner();
395         draw_horiz(TopBar);
396         @set_window 0;
397 print "^
398 In this game, you are Robot ( ";
399 style reverse; print "#"; style roman;
400 print " ). Your job is to find Kitten. This task is complicated by the
401 existance of various things which are not Kitten. Robot must touch
402 items to determine if they are Kitten or not.  Move Robot with the
403 cursor keys, the numeric keypad (make sure numlock is on), or using the
404 vi/rogue/nethack movement keys. The game ends when robotfindskitten.
405 Alternatively, you may end the game by hitting the Esc or Q keys.^
406 ^
407 [Press any key to continue.] "; 
408         getkey();
409 ];
410
411
412 [ print_thoughts;
413
414         @erase_window $ffff;
415         @split_window TopBar;
416         @set_window 1;
417         Banner();
418         draw_horiz(TopBar);
419         @set_window 0;
420 print "^
421 A Final Thought.^
422 ^
423 Day and night I feverishly worked upon the machine, creating both a soul
424 which could desire its goal, and a body with which it could realize 
425 it. Many who saw my creation called it an abomination, and denied me
426 grant money.  But they could not dissuade me from my impossible 
427 task.  It was a spectre that tormented me always, a ghost I had to give
428 a form and a life, lest it consume me from the inside.  And when at last
429 my task was done, when the grey box on wheels was complete and when it,
430 as well as I, knew what had to be done, I felt deep sympathy for the
431 machine.  For I had not destroyed the phantom, but merely exorcized it
432 into another body.  The robot knew not why this task had to be
433 performed, for I could not imbue it with knowledge I did not myself
434 posess.  And at the same time, I felt a sweeping sense of relief sweep
435 over me, that somehow, the dream that had driven me for my entire life
436 had come one step closer to fruition.^
437 ^
438 ~Gort, Klaatu Verada Nikto~^
439 ^
440 As I vocally activated the robot, I realized that it was following my
441 instructions, but not out of any desire to obey me.  Had I remained
442 silent, it would have performed exactly the same operations.  We were
443 two beings controlled by the same force now.  And yet, seeking vainly to
444 hold some illusion of control over the machine I thought I had created,
445 I gave my final command.^
446 ^
447 ~GO!~  I told the box as it began to roll out of my workshop into the
448 frozen desert beyond. ~FIND KITTEN!~^
449 ^
450 -- The Book of Found Kittens, pages 43-4, author unknown.^
451 ^
452 [Press any key to continue.] "; 
453         getkey();
454 ];
455
456
457 [ draw_big_robot x y; 
458
459         if (x == 0)
460                 x = 1;
461         if (y == 0)
462                 y = 1;
463         @set_cursor y x;
464         @set_colour 6 Back_def;
465         print "[";
466         @set_colour 4 Back_def;
467         print "-";
468         @set_colour 6 Back_def;
469         print "]";
470
471         y = y+1;
472         @set_cursor y x;
473         @set_colour 6 Back_def;
474         print "(";
475         @set_colour 3 Back_def;
476         print "+";
477         @set_colour 6 Back_def;
478         print ")";
479         @set_colour 8 Back_def;
480         print "=C";
481
482         y = y+1;
483         @set_cursor y x;
484         @set_colour 6 Back_def;
485         print "| |";
486
487         y = y+1;
488         @set_cursor y x;
489         @set_colour 8 Back_def;
490         print "OOO";
491
492         @set_colour Fore_def Back_def;
493 ];
494
495
496 [ draw_big_kitten x y;
497
498         if (x == 0)
499                 x = 1;
500         if (y == 0)
501                 y = 1;
502         @set_cursor y x;
503
504         @set_colour 5 Back_def;
505         print "|", (char) 92, "_/|";
506         y++;
507         @set_cursor y x;
508         print "|";
509         @set_colour 4 Back_def;
510         print "o o";
511         @set_colour 5 Back_def;
512         print "|__";
513         y++;
514         @set_cursor y x;
515         @set_colour 9 Back_def;
516         print "--";
517         @set_colour 3 Back_def;
518         print "*";
519         @set_colour 9 Back_def;
520         print "--";
521         @set_colour 5 Back_def;
522         print "__", (char) 92;
523         y++;
524         @set_cursor y x;
525         print "C_C(____)";      
526
527         @set_colour Fore_def Back_def;
528 ];
529
530
531 [ draw_big_kitten_psycho x y;
532
533         if (x == 0)
534                 x = 1;
535         if (y == 0)
536                 y = 1;
537         @set_cursor y x;
538
539         @set_colour 5 Back_def;
540         print " |", (char) 92, "_/|";
541         y++;
542         @set_cursor y x;
543         @set_colour 4 Back_def;
544         print "(|) (|)";
545         @set_colour 5 Back_def;
546         print "_";
547         y++;
548         @set_cursor y x;
549         @set_colour 9 Back_def;
550         print " --";
551         @set_colour 3 Back_def;
552         print "O";
553         @set_colour 9 Back_def;
554         print "--";
555         @set_colour 5 Back_def;
556         print "__", (char) 92;
557         y++;
558         @set_cursor y x;
559         print " 3_3(____)";     
560
561         @set_colour Fore_def Back_def;
562 ];
563
564
565 ! Something gets messed up if I make this local to findkitten()
566 ! When going right or left, then up or down to hit the Kitten, the
567 ! animation gets reversed.
568
569 Global last_right = false;
570
571 [ findkitten key i;
572
573         @erase_window $ffff;
574         @split_window TopBar;
575         @set_window 1;
576         @set_cursor 1 1;
577
578         Banner();
579         print (string) last_message;
580         draw_horiz(TopBar);
581
582         draw_object(kitten_x, kitten_y, kitten_char, kitten_color);
583         draw_nonkittens();
584
585         style reverse;
586         draw_object(player_x, player_y, '#');
587         style roman;
588
589         @set_cursor 1 Width;
590
591         ! Get movement key
592         !
593         key = getkey();
594
595         ! Move Robot
596         !
597         player_x_last = player_x;
598         player_y_last = player_y;
599         switch (key) {
600         'Q', $1b:       rfalse;                 ! exit game ($1b == Esc)
601         '8', 'K', 129:  player_y--;             ! up
602         '2', 'J', 130:  player_y++;             ! down
603         '4', 'H', 131:  player_x--;             ! left
604                         last_right = false;
605         '6', 'L', 132:  player_x++;             ! right
606                         last_right = true;
607
608         '7', 'Y':       player_y--; player_x--; ! up-left
609                         last_right = false;
610         '9', 'U':       player_y--; player_x++; ! up-right
611                         last_right = true;
612         '1', 'B':       player_y++; player_x--; ! down-left
613                         last_right = false;
614         '3', 'N':       player_y++; player_x++; ! down-right
615                         last_right = true;
616         }
617
618         ! Keep Robot from falling off edges of playfield.
619         !
620         if (player_y == TopBar || player_y > Height) {
621                 player_y = player_y_last;
622         }
623         if (player_x < 1 || player_x > Width) {
624                 player_x = player_x_last;
625         }
626
627         ! Detect and handle collisions.
628         !
629         if (player_x == kitten_x && player_y == kitten_y) {
630                 animate_kitten(key, last_right);
631                 getkey();
632                 rfalse;
633         }
634         for (i = 0: i < nonkitten_count: i++) {
635                 if (player_x == nonkitten_x-->i
636                 && player_y == nonkitten_y-->i) {
637                         @set_cursor 1 1;
638                         last_message = lookup_msg(nonkitten_msg-->i);
639                         player_x = player_x_last;
640                         player_y = player_y_last;
641                 }
642         }
643         rtrue;
644 ];
645
646
647 [ animate_kitten key my_last_right i j junk robot_x anim_finished;
648
649         switch (key) {
650         '8', 'J', 129:  player_y++;
651         '2', 'K', 130:  player_y--;
652         '4', 'H', 131:  player_x++;
653         '6', 'L', 132:  player_x--;
654         '7', 'Y':       player_y++; player_x++; 
655         '9', 'U':       player_y++; player_x--;
656         '1', 'B':       player_y--; player_x++;
657         '3', 'N':       player_y--; player_x--;
658         }
659
660         anim_finished = false;
661         for (i = 4: i >= 0: i--) {
662                 @erase_window $ffff;
663                 @split_window TopBar;
664                 @set_window 1;
665                 @set_cursor 1 1;
666
667                 Banner();
668                 draw_horiz(TopBar);
669
670                 if (i > 0) {
671                         if (my_last_right) {
672                                 robot_x = Anim_Meet - i;
673                                 style reverse;
674                                 draw_object(robot_x, TopBar - 1, '#');
675                                 style roman;
676                                 draw_object(Anim_Meet - 1 + i, TopBar - 1, 
677                                         kitten_char, kitten_color);
678                         } else {
679                                 robot_x = Anim_Meet - 1 + i;
680                                 style reverse;
681                                 draw_object(robot_x, TopBar - 1, '#');
682                                 style roman;
683                                 draw_object(Anim_Meet - i, TopBar - 1,
684                                         kitten_char, kitten_color);
685                         }
686                 } else {
687                         j = TopBar - 1;
688                         @set_cursor j 1;
689                         print "You found Kitten!  Way to go, Robot!";
690                         anim_finished = true;
691                 }
692
693                 draw_object(kitten_x, kitten_y, kitten_char, kitten_color);
694
695                 style reverse;
696                 draw_object(player_x, player_y, '#');
697                 style roman;
698                 draw_nonkittens();
699
700                 if (anim_finished == false) {
701                         j = TopBar - 1;
702                         @set_cursor 1 Width;
703                         @aread junk 0 10 pause -> junk;
704                 } else {
705                         style reverse;
706                         draw_object(player_x, player_y, '#');
707                         style roman;
708                         @set_cursor 1 Width;
709                 }
710         }
711 ];
712
713
714 [ already_seen_xy x y i;
715         for (i = 0: i < already_count: i++) {
716                 if (already_x-->already_count == x &&
717                 already_y-->already_count ==y) {
718                         rtrue;
719                 }
720         }
721         already_x-->already_count = x;
722         already_y-->already_count = y;
723         already_count++;
724         rfalse;
725 ];
726
727
728 [ pause;
729         rtrue;
730 ];
731
732
733 [ init_kitten;
734         kitten_x = get_random_x();
735         kitten_y = get_random_y();
736         kitten_color = get_random_color();
737         while (already_seen_xy(kitten_x, kitten_y) == true) {
738                 kitten_x = get_random_x();
739                 kitten_y = get_random_y();
740         }
741         kitten_char = get_random_char();
742 ];
743
744
745 [ init_robot;
746         player_x = get_random_x();
747         player_y = get_random_y();
748         while (already_seen_xy(player_x, player_y) == true) {
749                 player_x = get_random_x();
750                 player_y = get_random_y();
751         }
752 ];      
753
754
755 [ init_nonkittens i;
756         already_msg_count = 0;
757         last_message = "";
758         for (i = 0: i < nonkitten_count: i++) {
759                 nonkitten_x-->i = get_random_x();
760                 nonkitten_y-->i = get_random_y();
761                 nonkitten_color-->i = get_random_color();
762                 while (already_seen_xy(nonkitten_x-->i, 
763                         nonkitten_y-->i) == true) {
764                         nonkitten_x-->i = get_random_x();
765                         nonkitten_y-->i = get_random_y();
766                 }
767                 nonkitten_char-->i = get_random_char();
768                 nonkitten_msg-->i = get_random_msg();
769         }
770 ];
771
772
773 [ draw_nonkittens i;
774         for (i = 0: i < nonkitten_count: i++) {
775                 draw_object(nonkitten_x-->i,
776                                 nonkitten_y-->i,
777                                 nonkitten_char-->i,
778                                 nonkitten_color-->i);
779         }
780 ];
781
782
783 [ draw_object x y character fore back;
784         @set_cursor y x;
785
786         if (fore == "")
787                 fore = Back_def;
788         if (back == "")
789                 back = Back_def;        
790
791         @set_colour fore Back_def;
792         if (character)
793                 print (char) character;
794
795         @set_colour Fore_def Back_def;
796 ];
797
798
799 [ draw_horiz row i;
800         @set_cursor row 1;
801         for (i = 0 : i < Width : i++)
802                 print (char) '-';
803 ];
804
805
806 [ getkey x;
807         @read_char 1 -> x;
808         if (x >= 'a' && x <= 'z')
809                 x = x - ('a' - 'A');
810         return x;
811 ];
812
813
814 [ get_random_char num;
815         num = random(93);
816         num = num + 33;
817         while (num == 35) {             ! avoid choosing '#'
818                 num = random(93);
819                 num = num + 33;
820         }
821         return num;
822 ];
823
824
825 [ get_random_msg num;
826         num = random(MESSAGE_NUM);
827         while (is_duplicate_msg(num) == true) {
828                 num = random(MESSAGE_NUM);
829         }
830         return num;
831 ];
832
833
834 [ get_random_color num;
835         num = random(7) + 2;
836         ! 0 and 1 are default color and current color
837         ! and we want to avoid picking the default color explicitly
838         while (num == $2c-->0) {
839                 num = random(7) + 2;
840         }
841         return num;
842 ];
843
844
845 [ is_duplicate_msg num i;
846         for (i = 0: i < already_msg_count: i++) {
847                 if (already_msg-->i==num) {
848                         rtrue;
849                 }
850         }
851         already_msg-->already_msg_count = num;
852         already_msg_count++;
853         rfalse;
854 ];
855
856
857 [ get_random_x;
858         ! Maybe this will need to do something more in the future.
859         return random(Width);
860 ];
861
862
863 [ get_random_y num;
864         ! Make sure we don't draw in the status bar.
865         while (true) {
866                 num = random(Height);
867                 if (num > TopBar)
868                         return num;
869         }
870 ];
871