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