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

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