remove unneeded route entries
[rofl0r-openDOW.git] / enemytag.c
blobbb99c76db4664e1c9b68b2e1bcaddf443fa41073
1 #include "enemy.h"
2 #include "gameobj.h"
3 #include "video.h"
4 #include <unistd.h>
5 static struct enemy_spawn tag_enemy;
6 static int tag_enemy_current_route;
7 static int tag_enemy_current_shot;
8 static int tag_enemy_id;
9 static int tag_enemy_spawnline;
10 static int tag_enemy_y;
11 static int tag_enemy_upscrolled;
13 static void scrollup() {
14 tag_enemy_upscrolled += 10;
15 objs[player_ids[0]].pos.y -= 10*SCALE;
18 #define STRING_ENTRY(x) [x] = #x
19 static const char* enemy_weapon_string_lut[] = {
20 STRING_ENTRY(EW_GUN),
21 STRING_ENTRY(EW_GRENADE),
23 static const char* enemy_shape_string_lut[] = {
24 STRING_ENTRY(ES_SOLDIER1_DOWN),
25 STRING_ENTRY(ES_SOLDIER1_LEFT),
26 STRING_ENTRY(ES_SOLDIER1_RIGHT),
27 STRING_ENTRY(ES_SOLDIER2_DOWN),
28 STRING_ENTRY(ES_SOLDIER2_LEFT),
29 STRING_ENTRY(ES_SOLDIER2_RIGHT),
30 STRING_ENTRY(ES_GUNTURRET_MOVABLE_MAN),
31 STRING_ENTRY(ES_GUNTURRET_MOVABLE_MACHINE),
32 STRING_ENTRY(ES_JEEP),
33 STRING_ENTRY(ES_TANK_SMALL),
34 STRING_ENTRY(ES_TANK_BIG),
35 STRING_ENTRY(ES_TRANSPORTER),
36 STRING_ENTRY(ES_BUNKER_1),
37 STRING_ENTRY(ES_BUNKER_2),
38 STRING_ENTRY(ES_BUNKER_3),
39 STRING_ENTRY(ES_BUNKER_4),
40 STRING_ENTRY(ES_BUNKER_5),
41 STRING_ENTRY(ES_MINE_FLAT),
42 STRING_ENTRY(ES_MINE_CROSS),
43 STRING_ENTRY(ES_FLAMETURRET),
44 STRING_ENTRY(ES_GUNTURRET_FIXED_SOUTH),
45 STRING_ENTRY(ES_GUNTURRET_FIXED_NORTH),
46 STRING_ENTRY(ES_BOSS),
47 STRING_ENTRY(ES_MAX),
49 static const char* dir16_string_lut[] = {
50 STRING_ENTRY(DIR16_N),
51 STRING_ENTRY(DIR16_NNW),
52 STRING_ENTRY(DIR16_NW),
53 STRING_ENTRY(DIR16_WNW),
54 STRING_ENTRY(DIR16_W),
55 STRING_ENTRY(DIR16_WSW),
56 STRING_ENTRY(DIR16_SW),
57 STRING_ENTRY(DIR16_SSW),
58 STRING_ENTRY(DIR16_S),
59 STRING_ENTRY(DIR16_SSO),
60 STRING_ENTRY(DIR16_SO),
61 STRING_ENTRY(DIR16_OSO),
62 STRING_ENTRY(DIR16_O),
63 STRING_ENTRY(DIR16_ONO),
64 STRING_ENTRY(DIR16_NO),
65 STRING_ENTRY(DIR16_NNO),
66 STRING_ENTRY(DIR16_MAX),
68 static void dump_enemy() {
70 .scroll_line = 1,
71 .weapon = EW_GUN,
72 .x = 100,
73 .y = 100,
74 .route = {
75 [3] = {
76 .shape = ES_JEEP,
77 .dir = DIR16_WNW,
78 .start_step = 0,
79 .vel = 2,
81 [4] = {
82 .shape = ES_SOLDIER1_RIGHT,
83 .dir = DIR16_NNW,
84 .start_step = 128,
85 .vel = 2,
90 #define tprintf(tabs, args...) do { int __tabs; for(__tabs = 0; __tabs < tabs; __tabs++) printf("\t"); printf(args); } while(0)
91 printf("XXX screen %d\n", map_spawn_screen_index);
92 tprintf(2, ".scroll_line = %d,\n", tag_enemy_spawnline);
93 tprintf(2, ".weapon = %s,\n", enemy_weapon_string_lut[tag_enemy.weapon]);
94 tprintf(2, ".x = %d,\n", tag_enemy.x);
95 tprintf(2, ".y = %d,\n", tag_enemy_y);
96 tprintf(2, ".route = {\n");
97 int i;
98 for(i = 0; i < ENEMY_MAX_ROUTE; i++) {
99 tprintf(3, "[%d] = {\n", i);
100 tprintf(4, ".shape = %s,\n", enemy_shape_string_lut[tag_enemy.route[i].shape]);
101 tprintf(4, ".dir = %s,\n", dir16_string_lut[tag_enemy.route[i].dir]);
102 tprintf(4, ".start_step = %d,\n", tag_enemy.route[i].start_step);
103 tprintf(4, ".vel = %d,\n", tag_enemy.route[i].vel);
104 tprintf(3, "},\n");
106 tprintf(2, "},\n");
107 tprintf(2, ".shots = {\n");
108 for(i = 0; i < ENEMY_MAX_SHOT; i++)
109 tprintf(3, "[%d] = %d,\n", i, tag_enemy.shots[i]);
110 tprintf(2, "},\n");
113 static void reset_tag_enemy() {
114 memset(&tag_enemy, 0, sizeof(tag_enemy));
115 tag_enemy.route[0].shape = ES_SOLDIER1_DOWN;
118 static void update_tag_enemy(int doremove) {
119 if(doremove) remove_enemy(tag_enemy_id);
120 tag_enemy.y = tag_enemy_y + tag_enemy_upscrolled;
121 tag_enemy_id = init_enemy(&tag_enemy);
124 static void dup_route() {
125 int i;
126 for(i = tag_enemy_current_route + 1; i < ENEMY_MAX_ROUTE; i++)
127 tag_enemy.route[i] = tag_enemy.route[tag_enemy_current_route];
130 static void toggle_shape(int shapedir) {
131 int s = tag_enemy.route[tag_enemy_current_route].shape;
132 s += shapedir;
133 if(s < ES_FIRST) s = ES_MAX - 1;
134 else if(s >= ES_MAX) s = ES_FIRST;
135 int i;
136 for(i = tag_enemy_current_route; i < ENEMY_MAX_ROUTE; i++)
137 tag_enemy.route[i].shape = s;
140 static void toggle_vel(int veldir) {
141 int v = tag_enemy.route[tag_enemy_current_route].vel;
142 v+=veldir;
143 if(v<0) v = 0;
144 else if(v > 255) v = 255;
145 int i;
146 for(i = tag_enemy_current_route; i < ENEMY_MAX_ROUTE; i++)
147 tag_enemy.route[i].vel = v;
148 update_tag_enemy(1);
151 static void toggle_route(int dir) {
152 int newroute = tag_enemy_current_route + dir;
153 if(newroute >= ENEMY_MAX_ROUTE) newroute = 0;
154 else if(newroute < 0) newroute = ENEMY_MAX_ROUTE -1;
155 tag_enemy_current_route = newroute;
158 static void toggle_shot(int dir) {
159 int newshot = tag_enemy_current_shot + dir;
160 if(newshot >= ENEMY_MAX_SHOT) newshot = 0;
161 else if(newshot < 0) newshot = ENEMY_MAX_SHOT -1;
162 tag_enemy_current_shot = newshot;
165 static void toggle_gun(void) {
166 if(tag_enemy.weapon == EW_GRENADE) tag_enemy.weapon = EW_GUN;
167 else tag_enemy.weapon = EW_GRENADE;
170 static void insert_steps(void) {
171 tag_enemy.route[tag_enemy_current_route].start_step = objs[tag_enemy_id].objspecific.enemy.curr_step;
172 dup_route();
175 static void insert_shot(void) {
176 tag_enemy.shots[tag_enemy_current_shot] = objs[tag_enemy_id].objspecific.enemy.curr_step;
179 static int paused;
180 static void tag_update_caption(void) {
181 char buf [128];
182 snprintf(buf, 128, "%s tag mode: x %d, y %d, route: %d, vel: %d, step: %d, shot: %d",
183 paused ? "XXXX PAUSED XXXX" : "",
184 (int) tag_enemy.x, (int) tag_enemy.y,
185 (int) tag_enemy_current_route,
186 (int) tag_enemy.route[tag_enemy_current_route].vel,
187 (int) objs[tag_enemy_id].objspecific.enemy.curr_step,
188 (int) tag_enemy_current_shot
190 SDL_WM_SetCaption(buf, 0);
193 static void print_dirbuf(char* dirbuf) {
194 char buf [128];
195 snprintf(buf, 128, "enter dir16: %s", dirbuf);
196 SDL_WM_SetCaption(buf, 0);
199 static void do_pause() {
200 static int save_vel[ENEMY_MAX_ROUTE];
201 int i;
202 if(!paused) {
203 for(i = 0; i < ENEMY_MAX_ROUTE; i++) save_vel[i] = tag_enemy.route[i].vel;
204 for(i = 0; i < ENEMY_MAX_ROUTE; i++) tag_enemy.route[i].vel = 0;
205 } else {
206 for(i = 0; i < ENEMY_MAX_ROUTE; i++) tag_enemy.route[i].vel = save_vel[i];
208 paused = !paused;
211 static void enter_direction() {
212 char dirbuf[4] = {0};
213 char* p = dirbuf;
214 while(1) {
215 SDL_Event sdl_event;
216 while (SDL_PollEvent(&sdl_event)) {
217 if(sdl_event.type == SDL_KEYUP) switch(sdl_event.key.keysym.sym) {
218 #define check(dir) if(p+dir < dirbuf || p+dir>=dirbuf+4) break;
219 case SDLK_w: check(1); *p++ = 'w'; break;
220 case SDLK_s: check(1); *p++ = 's'; break;
221 case SDLK_o: check(1); *p++ = 'o'; break;
222 case SDLK_n: check(1); *p++ = 'n'; break;
223 case SDLK_BACKSPACE: check(-1); *--p = 0; break;
224 #undef check
225 case SDLK_RETURN: goto end_loop;
226 default: ;
228 print_dirbuf(dirbuf);
230 print_dirbuf(dirbuf);
231 SDL_Delay(5);
233 end_loop:;
234 enum direction16 dir;
235 if(0);
236 else if (!strcmp(dirbuf,"o")) dir= DIR16_O;
237 else if (!strcmp(dirbuf,"ono")) dir= DIR16_ONO;
238 else if (!strcmp(dirbuf,"no")) dir= DIR16_NO;
239 else if (!strcmp(dirbuf,"nno")) dir= DIR16_NNO;
240 else if (!strcmp(dirbuf,"n")) dir= DIR16_N;
241 else if (!strcmp(dirbuf,"nnw")) dir= DIR16_NNW;
242 else if (!strcmp(dirbuf,"nw")) dir= DIR16_NW;
243 else if (!strcmp(dirbuf,"wnw")) dir= DIR16_WNW;
244 else if (!strcmp(dirbuf,"w")) dir= DIR16_W;
245 else if (!strcmp(dirbuf,"wsw")) dir= DIR16_WSW;
246 else if (!strcmp(dirbuf,"sw")) dir= DIR16_SW;
247 else if (!strcmp(dirbuf,"ssw")) dir= DIR16_SSW;
248 else if (!strcmp(dirbuf,"s")) dir= DIR16_S;
249 else if (!strcmp(dirbuf,"sso")) dir= DIR16_SSO;
250 else if (!strcmp(dirbuf,"so")) dir= DIR16_SO;
251 else if (!strcmp(dirbuf,"oso")) dir= DIR16_OSO;
252 else dir = DIR16_INVALID;
253 if(dir != DIR16_INVALID) tag_enemy.route[tag_enemy_current_route].dir = dir;
254 dup_route();
255 update_tag_enemy(1);
258 static void enemy_tag_loop() {
259 update_caption = tag_update_caption;
260 tag_enemy_current_route = 0;
261 tag_enemy_current_shot = 0;
262 tag_enemy_spawnline = map_spawn_line;
263 tag_enemy_y = 0;
264 tag_enemy_upscrolled = 0;
265 reset_tag_enemy();
266 tag_enemy_id = init_enemy(&tag_enemy);
268 SDL_Event sdl_event;
269 while(1) {
270 if(!obj_slot_used[tag_enemy_id]) update_tag_enemy(0);
271 //tag_enemy_id = init_enemy(&tag_enemy);
272 unsigned need_redraw = 1;
273 while (SDL_PollEvent(&sdl_event)) {
274 need_redraw = 0;
275 int dir = -1;
276 switch (sdl_event.type) {
277 case SDL_KEYUP:
278 switch(sdl_event.key.keysym.sym) {
279 case SDLK_e: dump_enemy(); return;
280 case SDLK_g: toggle_gun(); break;
281 case SDLK_d: enter_direction(); break;
282 case SDLK_i: insert_steps(); break;
283 case SDLK_s: insert_shot(); break;
284 case SDLK_p: do_pause(); break;
285 case SDLK_c: clear_screen(); video_update(); need_redraw = 1; break;
286 case SDLK_SPACE: update_tag_enemy(1); break;
287 case SDLK_PAGEUP: scrollup(); break;
288 case SDLK_KP_PLUS:
289 dir = 1;
290 case SDLK_KP_MINUS:
291 if((sdl_event.key.keysym.mod & KMOD_RSHIFT) ||
292 (sdl_event.key.keysym.mod & KMOD_LSHIFT))
293 toggle_shape(dir);
294 else
295 if((sdl_event.key.keysym.mod & KMOD_RALT) ||
296 (sdl_event.key.keysym.mod & KMOD_LALT))
297 toggle_route(dir);
298 else
299 if((sdl_event.key.keysym.mod & KMOD_RCTRL) ||
300 (sdl_event.key.keysym.mod & KMOD_LCTRL))
301 toggle_shot(dir);
302 else
303 toggle_vel(dir);
304 break;
305 default: break;
307 case SDL_KEYDOWN:
308 switch(sdl_event.key.keysym.sym) {
309 case SDLK_RIGHT: dir = 1;
310 case SDLK_LEFT:
311 if((sdl_event.key.keysym.mod & KMOD_RSHIFT) ||
312 (sdl_event.key.keysym.mod & KMOD_LSHIFT)) dir *= 4;
313 tag_enemy.x += dir;
314 update_tag_enemy(1);
315 break;
316 case SDLK_DOWN:
317 dir = 1;
318 case SDLK_UP:
319 if((sdl_event.key.keysym.mod & KMOD_RSHIFT) ||
320 (sdl_event.key.keysym.mod & KMOD_LSHIFT)) dir *= 4;
321 tag_enemy_y += dir;
322 update_tag_enemy(1);
323 break;
324 default: ;
326 break;
327 default: ;
330 game_tick(need_redraw);