]> icculus.org git repositories - btb/d2x.git/blob - main/editor/macro.c
Move old logs to ChangeLog-old
[btb/d2x.git] / main / editor / macro.c
1 /* $Id: macro.c,v 1.3 2004-12-19 14:52:48 btb Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * Routines for recording/playing/saving macros
18  *
19  */
20
21
22 #ifdef RCS
23 static char rcsid[] = "$Id: macro.c,v 1.3 2004-12-19 14:52:48 btb Exp $";
24 #endif
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <math.h>
30 #include <string.h>
31
32 #include "inferno.h"
33 #include "segment.h"
34 #include "editor.h"
35
36 #include "gr.h"
37 #include "ui.h"
38 #include "key.h"
39 #include "fix.h"
40 #include "mono.h"
41 #include "3d.h"
42 #include "mouse.h"
43 #include "bm.h"
44 #include "error.h"
45 #include "medlisp.h"
46 #include "cflib.h"
47
48 #include "kdefs.h"
49
50 #include "u_mem.h"
51
52 #define MAX_NUM_EVENTS 10000
53
54 UI_EVENT * RecordBuffer;
55
56 int MacroNumEvents = 0;
57 int MacroStatus = 0;
58
59 static char filename[128] = "*.MIN";
60
61 int MacroRecordAll()
62 {
63         if ( MacroStatus== UI_STATUS_NORMAL )
64         {
65                 if (RecordBuffer) free( RecordBuffer );
66                 MALLOC( RecordBuffer, UI_EVENT, MAX_NUM_EVENTS );
67                 ui_record_events( MAX_NUM_EVENTS, RecordBuffer, UI_RECORD_MOUSE | UI_RECORD_KEYS );
68                 MacroStatus = UI_STATUS_RECORDING;
69         }
70         return 1;
71 }
72
73 int MacroRecordKeys()
74 {
75         if ( MacroStatus== UI_STATUS_NORMAL )
76         {
77                 if (RecordBuffer) free( RecordBuffer );
78                 MALLOC( RecordBuffer, UI_EVENT, MAX_NUM_EVENTS );
79                 ui_record_events( MAX_NUM_EVENTS, RecordBuffer, UI_RECORD_KEYS );
80                 MacroStatus = UI_STATUS_RECORDING;
81         }
82         return 1;
83 }
84
85 int MacroPlayNormal()
86 {
87         if (MacroStatus== UI_STATUS_NORMAL && MacroNumEvents > 0 && RecordBuffer )
88         {
89                 ui_set_playback_speed( 1 );
90                 ui_play_events_realtime(MacroNumEvents, RecordBuffer);
91                 MacroStatus = UI_STATUS_PLAYING;
92         }
93         return 1;
94 }
95
96 int MacroPlayFast()
97 {
98         if (MacroStatus== UI_STATUS_NORMAL && MacroNumEvents > 0 && RecordBuffer )
99         {
100                 ui_mouse_hide();
101                 ui_play_events_fast(MacroNumEvents, RecordBuffer);
102                 MacroStatus = UI_STATUS_FASTPLAY;
103         }
104         return 1;
105 }
106
107 int MacroSave()
108 {
109
110         if (MacroNumEvents < 1 )
111         {
112                 MessageBox( -2, -2, 1, "No macro has been defined to save!", "Oops" );
113                 return 1;
114         }
115
116         if (ui_get_filename( filename, "*.MAC", "SAVE MACRO" ))   {
117                 RecordBuffer[0].type = 7;
118                 RecordBuffer[0].frame = 0;
119                 RecordBuffer[0].data = MacroNumEvents;
120                 WriteFile(  filename, RecordBuffer, sizeof(UI_EVENT)*MacroNumEvents );
121         }
122         return 1;
123 }
124
125 int MacroLoad()
126 {
127         int length;
128
129         if (ui_get_filename( filename, "*.MAC", "LOAD MACRO" ))   {
130                 if (RecordBuffer) free( RecordBuffer );
131                 RecordBuffer = (UI_EVENT *)ReadFile( filename, &length );
132                 MacroNumEvents = RecordBuffer[0].data;
133         }
134         return 1;
135 }
136
137 void macro_free_buffer()
138 {
139         if ( RecordBuffer ) 
140                 free(RecordBuffer);
141 }
142
143 int MacroMenu()
144 {
145         int x;
146         char * MenuItems[] = { "Play fast",
147                                            "Play normal",
148                                            "Record all",
149                                            "Record keys",
150                                            "Save macro",
151                                            "Load macro" };
152
153         x = MenuX( -1, -1, 6, MenuItems );
154
155         switch( x )
156         {
157         case 1:
158                 MacroPlayFast();
159                 break;
160         case 2:
161                 MacroPlayNormal();
162                 break;
163         case 3:
164                 MacroRecordAll();
165                 break;
166         case 4:
167                 MacroRecordKeys();
168                 break;
169         case 5:     // Save
170                 MacroSave();
171                 break;
172         case 6:     // Load
173                 MacroLoad();
174                 break;
175         }
176         return 1;
177 }
178