home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / macro.c < prev    next >
Text File  |  1998-06-08  |  4KB  |  212 lines

  1. /*
  2.  * $Source: f:/miner/source/main/editor/rcs/macro.c $
  3.  * $Revision: 2.0 $
  4.  * $Author: john $
  5.  * $Date: 1995/02/27 11:35:09 $
  6.  * 
  7.  * Routines for recording/playing/saving macros
  8.  * 
  9.  * $Log: macro.c $
  10.  * Revision 2.0  1995/02/27  11:35:09  john
  11.  * Version 2.0! No anonymous unions, Watcom 10.0, with no need
  12.  * for bitmaps.tbl.
  13.  * 
  14.  * Revision 1.12  1993/11/15  14:46:37  john
  15.  * Changed Menu to MenuX
  16.  * 
  17.  * Revision 1.11  1993/11/05  17:32:44  john
  18.  * added funcs
  19.  * .,
  20.  * 
  21.  * Revision 1.10  1993/10/28  16:23:20  john
  22.  * *** empty log message ***
  23.  * 
  24.  * Revision 1.9  1993/10/28  13:03:12  john
  25.  * ..
  26.  * 
  27.  * Revision 1.8  1993/10/25  16:02:35  john
  28.  * *** empty log message ***
  29.  * 
  30.  * Revision 1.7  1993/10/22  13:35:29  john
  31.  * *** empty log message ***
  32.  * 
  33.  * Revision 1.6  1993/10/21  17:10:09  john
  34.  * Fixed bug w/ load macro.
  35.  * 
  36.  * Revision 1.5  1993/10/19  12:58:47  john
  37.  * *** empty log message ***
  38.  * 
  39.  * Revision 1.4  1993/10/19  12:55:02  john
  40.  * *** empty log message ***
  41.  * 
  42.  * Revision 1.3  1993/10/19  12:49:49  john
  43.  * made EventBuffer dynamic, use ReadFile, WriteFile
  44.  * 
  45.  * Revision 1.2  1993/10/15  17:42:20  john
  46.  * *** empty log message ***
  47.  * 
  48.  * Revision 1.1  1993/10/15  17:28:06  john
  49.  * Initial revision
  50.  * 
  51.  * 
  52.  */
  53.  
  54.  
  55. #pragma off (unreferenced)
  56. static char rcsid[] = "$Id: macro.c 2.0 1995/02/27 11:35:09 john Exp $";
  57. #pragma on (unreferenced)
  58.  
  59. #include <stdio.h>
  60. #include <stdlib.h>
  61. #include <stdarg.h>
  62. #include <math.h>
  63. #include <string.h>
  64.  
  65. #include "inferno.h"
  66. #include "segment.h"
  67. #include "editor.h"
  68.  
  69. #include "gr.h"
  70. #include "ui.h"
  71. #include "key.h"
  72. #include "fix.h"
  73. #include "mono.h"
  74. #include "3d.h"
  75. #include "mouse.h"
  76. #include "bm.h"
  77. #include "error.h"
  78. #include "medlisp.h"
  79. #include "cflib.h"
  80.  
  81. #include "kdefs.h"
  82.  
  83. #include "mem.h"
  84.  
  85. #define MAX_NUM_EVENTS 10000
  86.  
  87. UI_EVENT * RecordBuffer;
  88.  
  89. int MacroNumEvents = 0;
  90. int MacroStatus = 0;
  91.  
  92. static char filename[128] = "*.MIN";
  93.  
  94. int MacroRecordAll()
  95. {
  96.     if ( MacroStatus== UI_STATUS_NORMAL )
  97.     {
  98.         if (RecordBuffer) free( RecordBuffer );
  99.         MALLOC( RecordBuffer, UI_EVENT, MAX_NUM_EVENTS );
  100.         ui_record_events( MAX_NUM_EVENTS, RecordBuffer, UI_RECORD_MOUSE | UI_RECORD_KEYS );
  101.         MacroStatus = UI_STATUS_RECORDING;
  102.     }
  103.     return 1;
  104. }
  105.  
  106. int MacroRecordKeys()
  107. {
  108.     if ( MacroStatus== UI_STATUS_NORMAL )
  109.     {
  110.         if (RecordBuffer) free( RecordBuffer );
  111.         MALLOC( RecordBuffer, UI_EVENT, MAX_NUM_EVENTS );
  112.         ui_record_events( MAX_NUM_EVENTS, RecordBuffer, UI_RECORD_KEYS );
  113.         MacroStatus = UI_STATUS_RECORDING;
  114.     }
  115.     return 1;
  116. }
  117.  
  118. int MacroPlayNormal()
  119. {
  120.     if (MacroStatus== UI_STATUS_NORMAL && MacroNumEvents > 0 && RecordBuffer )
  121.     {
  122.         ui_set_playback_speed( 1 );
  123.         ui_play_events_realtime(MacroNumEvents, RecordBuffer);
  124.         MacroStatus = UI_STATUS_PLAYING;
  125.     }
  126.     return 1;
  127. }
  128.  
  129. int MacroPlayFast()
  130. {
  131.     if (MacroStatus== UI_STATUS_NORMAL && MacroNumEvents > 0 && RecordBuffer )
  132.     {
  133.         ui_mouse_hide();
  134.         ui_play_events_fast(MacroNumEvents, RecordBuffer);
  135.         MacroStatus = UI_STATUS_FASTPLAY;
  136.     }
  137.     return 1;
  138. }
  139.  
  140. int MacroSave()
  141. {
  142.  
  143.     if (MacroNumEvents < 1 )
  144.     {
  145.         MessageBox( -2, -2, 1, "No macro has been defined to save!", "Oops" );
  146.         return 1;
  147.     }
  148.  
  149.     if (ui_get_filename( filename, "*.MAC", "SAVE MACRO" ))   {
  150.         RecordBuffer[0].type = 7;
  151.         RecordBuffer[0].frame = 0;
  152.         RecordBuffer[0].data = MacroNumEvents;
  153.         WriteFile(  filename, RecordBuffer, sizeof(UI_EVENT)*MacroNumEvents );
  154.     }
  155.     return 1;
  156. }
  157.  
  158. int MacroLoad()
  159. {
  160.     int length;
  161.  
  162.     if (ui_get_filename( filename, "*.MAC", "LOAD MACRO" ))   {
  163.         if (RecordBuffer) free( RecordBuffer );
  164.         RecordBuffer = (UI_EVENT *)ReadFile( filename, &length );
  165.         MacroNumEvents = RecordBuffer[0].data;
  166.     }
  167.     return 1;
  168. }
  169.  
  170. void macro_free_buffer()
  171. {
  172.     if ( RecordBuffer ) 
  173.         free(RecordBuffer);
  174. }
  175.  
  176. int MacroMenu()
  177. {
  178.     int x;
  179.     char * MenuItems[] = { "Play fast",
  180.                        "Play normal",
  181.                        "Record all",
  182.                        "Record keys",
  183.                        "Save macro",
  184.                        "Load macro" };
  185.  
  186.     x = MenuX( -1, -1, 6, MenuItems );
  187.  
  188.     switch( x )
  189.     {
  190.     case 1:
  191.         MacroPlayFast();
  192.         break;
  193.     case 2:
  194.         MacroPlayNormal();
  195.         break;
  196.     case 3:
  197.         MacroRecordAll();
  198.         break;
  199.     case 4:
  200.         MacroRecordKeys();
  201.         break;
  202.     case 5:     // Save
  203.         MacroSave();
  204.         break;
  205.     case 6:     // Load
  206.         MacroLoad();
  207.         break;
  208.     }
  209.     return 1;
  210. }
  211.  
  212.