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