home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / Epoc / Palmtime / files / FrotzS5_src.ZIP / HOTKEY.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-12  |  4.6 KB  |  244 lines

  1. /*
  2.  * hotkey.c
  3.  *
  4.  * Hot key functions
  5.  *
  6.  */
  7.  
  8. #include "frotz.h"
  9. #include "s5api.h"
  10.  
  11. extern short restore_undo (struct sg *g);
  12.  
  13. extern short read_number (struct sg *g);
  14.  
  15. extern short read_yes_or_no (struct sg *g, const char *);
  16.  
  17. extern void replay_open (struct sg *g);
  18. extern void replay_close (struct sg *g);
  19. extern void record_open (struct sg *g);
  20. extern void record_close (struct sg *g);
  21.  
  22. //extern void seed_random (short);
  23.  
  24. /*
  25.  * hot_key_debugging
  26.  *
  27.  * ...allows user to toggle cheating options on/off.
  28.  *
  29.  */
  30.  
  31. short hot_key_debugging (struct sg *g)
  32. {
  33.  
  34.     print_string (g, "Debugging options\n");
  35.  
  36.     g->option_attribute_assignment = read_yes_or_no (g, "Watch attribute assignment");
  37.     g->option_attribute_testing = read_yes_or_no (g, "Watch attribute testing");
  38.     g->option_object_movement = read_yes_or_no (g, "Watch object movement");
  39.     g->option_object_locating = read_yes_or_no (g, "Watch object locating");
  40.  
  41.     return FALSE;
  42.  
  43. }/* hot_key_debugging */
  44.  
  45. /*
  46.  * hot_key_help
  47.  *
  48.  * ...displays a list of all hot keys.
  49.  *
  50.  */
  51.  
  52. short hot_key_help (struct sg *g) {
  53.  
  54.     print_string (g, "Help\n");
  55.  
  56.     print_string (g,
  57.     "\n"
  58.     "Ctrl-D  debugging options\n"
  59.     "Ctrl-S  help\n"
  60.     "Ctrl-N  new game\n"
  61.     "Ctrl-P  playback on\n"
  62.     "Ctrl-R  recording on/off\n"
  63.     "Ctrl-U  undo one turn\n"
  64.     "Ctrl-X  exit game\n");
  65.  
  66.     return FALSE;
  67.  
  68. }/* hot_key_help */
  69.  
  70. /*
  71.  * hot_key_playback
  72.  *
  73.  * ...allows user to turn playback on.
  74.  *
  75.  */
  76.  
  77. short hot_key_playback (struct sg *g)
  78. {
  79.  
  80.     print_string (g, "Playback on\n");
  81.  
  82.     if (!g->istream_replay)
  83.     replay_open (g);
  84.  
  85.     return FALSE;
  86.  
  87. }/* hot_key_playback */
  88.  
  89. /*
  90.  * hot_key_recording
  91.  *
  92.  * ...allows user to turn recording on/off.
  93.  *
  94.  */
  95.  
  96. short hot_key_recording (struct sg *g)
  97. {
  98.  
  99.     if (g->istream_replay) {
  100.     print_string (g,"Playback off\n");
  101.     replay_close (g);
  102.     } else if (g->ostream_record) {
  103.     print_string (g,"Recording off\n");
  104.     record_close (g);
  105.     } else {
  106.     print_string (g,"Recording on\n");
  107.     record_open (g);
  108.     }
  109.  
  110.     return FALSE;
  111.  
  112. }/* hot_key_recording */
  113.  
  114. /*
  115.  * hot_key_seed
  116.  *
  117.  * ...allows user to seed the random number seed.
  118.  *
  119.  */
  120.  
  121. /*static short hot_key_seed (void)
  122. {
  123.  
  124.     print_string ("Seed random numbers\n");
  125.  
  126.     print_string ("Enter seed value (or return to randomize): ");
  127.     //seed_random (read_number ());
  128.  
  129.     return FALSE;
  130.  
  131. }
  132. */
  133. /* hot_key_seed */
  134.  
  135. /*
  136.  * hot_key_undo
  137.  *
  138.  * ...allows user to undo the previous turn.
  139.  *
  140.  */
  141.  
  142. short hot_key_undo (struct sg *g)
  143. {
  144.  
  145.     print_string (g,"Undo one turn\n");
  146.  
  147.     if (restore_undo (g)) {
  148.  
  149.     if (g->h_version >= V5) {          /* for V5+ games we must */
  150.         store (g, 2);                  /* store 2 (for success) */
  151.         return TRUE;                /* and abort the input   */
  152.     }
  153.  
  154.     if (g->h_version <= V3) {          /* for V3- games we must */
  155.         z_show_status (g);           /* draw the status line  */
  156.         return FALSE;               /* and continue input    */
  157.     }
  158.  
  159.     } else print_string (g, "No more undo information available.\n");
  160.  
  161.     return FALSE;
  162.  
  163. }/* hot_key_undo */
  164.  
  165. /*
  166.  * hot_key_restart
  167.  *
  168.  * ...allows user to start a new game.
  169.  *
  170.  */
  171.  
  172. short hot_key_restart (struct sg *g)
  173. {
  174.  
  175.     print_string (g,"New game\n");
  176.  
  177.     if (read_yes_or_no (g,"Do you wish to restart")) {
  178.  
  179.     z_restart (g);
  180.     return TRUE;
  181.  
  182.     } else return FALSE;
  183.  
  184. }/* hot_key_restart */
  185.  
  186. /*
  187.  * hot_key_quit
  188.  *
  189.  * ...allows user to exit the game.
  190.  *
  191.  */
  192.  
  193. short hot_key_quit (struct sg *g)
  194. {
  195.  
  196.     print_string (g, "Exit game\n");
  197.  
  198.     if (read_yes_or_no (g, "Do you wish to quit")) {
  199.  
  200.     z_quit (g);
  201.     return TRUE;
  202.  
  203.     } else return FALSE;
  204.  
  205. }/* hot_key_quit */
  206.  
  207. /*
  208.  * handle_hot_key
  209.  *
  210.  * Perform the action associated with a so-called hot key. Return
  211.  * true to abort the current input action.
  212.  *
  213.  */
  214.  
  215. short handle_hot_key (struct sg *g, zchar key)
  216. {
  217.  
  218.     if (g->cwin == 0) {
  219.  
  220.     short aborting;
  221.  
  222.     print_string (g, "\nHot key -- ");
  223.  
  224.     switch (key) {
  225.         case ZC_HKEY_RECORD: aborting = hot_key_recording (g); break;
  226.         case ZC_HKEY_PLAYBACK: aborting = hot_key_playback (g); break;
  227.         case ZC_HKEY_UNDO: aborting = hot_key_undo (g); break;
  228.         case ZC_HKEY_RESTART: aborting = hot_key_restart (g); break;
  229.         case ZC_HKEY_QUIT: aborting = hot_key_quit (g); break;
  230.         case ZC_HKEY_DEBUG: aborting = hot_key_debugging (g); break;
  231.         case ZC_HKEY_HELP: aborting = hot_key_help (g); break;
  232.     }
  233.  
  234.     if (aborting)
  235.         return TRUE;
  236.  
  237.     print_string (g,"\nContinue input...\n");
  238.  
  239.     }
  240.  
  241.     return FALSE;
  242.  
  243. }/* handle_hot_key */
  244.