]> icculus.org git repositories - btb/d2x.git/blob - main/editor/macro.c
remove unused variable "length"
[btb/d2x.git] / main / editor / macro.c
1 /* $Id: macro.c,v 1.5 2005-01-24 22:09:54 schaffner 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 #ifdef RCS
22 static char rcsid[] = "$Id: macro.c,v 1.5 2005-01-24 22:09:54 schaffner Exp $";
23 #endif
24
25 #ifdef HAVE_CONFIG_H
26 #include "conf.h"
27 #endif
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <stdarg.h>
32 #include <math.h>
33 #include <string.h>
34
35 #include "inferno.h"
36 #include "segment.h"
37 #include "editor.h"
38
39 #include "gr.h"
40 #include "ui.h"
41 #include "key.h"
42 #include "fix.h"
43 #include "mono.h"
44 #include "3d.h"
45 #include "mouse.h"
46 #include "bm.h"
47 #include "error.h"
48 #include "medlisp.h"
49 #include "cflib.h"
50
51 #include "kdefs.h"
52
53 #include "u_mem.h"
54
55 #define MAX_NUM_EVENTS 10000
56
57 UI_EVENT * RecordBuffer;
58
59 int MacroNumEvents = 0;
60 int MacroStatus = 0;
61
62 static char filename[128] = "*.MIN";
63
64 int MacroRecordAll()
65 {
66         if ( MacroStatus== UI_STATUS_NORMAL )
67         {
68                 if (RecordBuffer) free( RecordBuffer );
69                 MALLOC( RecordBuffer, UI_EVENT, MAX_NUM_EVENTS );
70                 ui_record_events( MAX_NUM_EVENTS, RecordBuffer, UI_RECORD_MOUSE | UI_RECORD_KEYS );
71                 MacroStatus = UI_STATUS_RECORDING;
72         }
73         return 1;
74 }
75
76 int MacroRecordKeys()
77 {
78         if ( MacroStatus== UI_STATUS_NORMAL )
79         {
80                 if (RecordBuffer) free( RecordBuffer );
81                 MALLOC( RecordBuffer, UI_EVENT, MAX_NUM_EVENTS );
82                 ui_record_events( MAX_NUM_EVENTS, RecordBuffer, UI_RECORD_KEYS );
83                 MacroStatus = UI_STATUS_RECORDING;
84         }
85         return 1;
86 }
87
88 int MacroPlayNormal()
89 {
90         if (MacroStatus== UI_STATUS_NORMAL && MacroNumEvents > 0 && RecordBuffer )
91         {
92                 ui_set_playback_speed( 1 );
93                 ui_play_events_realtime(MacroNumEvents, RecordBuffer);
94                 MacroStatus = UI_STATUS_PLAYING;
95         }
96         return 1;
97 }
98
99 int MacroPlayFast()
100 {
101         if (MacroStatus== UI_STATUS_NORMAL && MacroNumEvents > 0 && RecordBuffer )
102         {
103                 ui_mouse_hide();
104                 ui_play_events_fast(MacroNumEvents, RecordBuffer);
105                 MacroStatus = UI_STATUS_FASTPLAY;
106         }
107         return 1;
108 }
109
110 int MacroSave()
111 {
112
113         if (MacroNumEvents < 1 )
114         {
115                 MessageBox( -2, -2, 1, "No macro has been defined to save!", "Oops" );
116                 return 1;
117         }
118
119         if (ui_get_filename( filename, "*.MAC", "SAVE MACRO" ))   {
120                 RecordBuffer[0].type = 7;
121                 RecordBuffer[0].frame = 0;
122                 RecordBuffer[0].data = MacroNumEvents;
123                 WriteFile(  filename, RecordBuffer, sizeof(UI_EVENT)*MacroNumEvents );
124         }
125         return 1;
126 }
127
128 int MacroLoad()
129 {
130         if (ui_get_filename( filename, "*.MAC", "LOAD MACRO" ))   {
131                 if (RecordBuffer) free( RecordBuffer );
132                 RecordBuffer = (UI_EVENT *)ReadFile( filename, &length );
133                 MacroNumEvents = RecordBuffer[0].data;
134         }
135         return 1;
136 }
137
138 void macro_free_buffer()
139 {
140         if ( RecordBuffer ) 
141                 free(RecordBuffer);
142 }
143
144 int MacroMenu()
145 {
146         int x;
147         char * MenuItems[] = { "Play fast",
148                                            "Play normal",
149                                            "Record all",
150                                            "Record keys",
151                                            "Save macro",
152                                            "Load macro" };
153
154         x = MenuX( -1, -1, 6, MenuItems );
155
156         switch( x )
157         {
158         case 1:
159                 MacroPlayFast();
160                 break;
161         case 2:
162                 MacroPlayNormal();
163                 break;
164         case 3:
165                 MacroRecordAll();
166                 break;
167         case 4:
168                 MacroRecordKeys();
169                 break;
170         case 5:     // Save
171                 MacroSave();
172                 break;
173         case 6:     // Load
174                 MacroLoad();
175                 break;
176         }
177         return 1;
178 }
179