1 /**
2  * FreeDink editor-specific code
3 
4  * Copyright (C) 1997, 1998, 1999, 2002, 2003  Seth A. Robinson
5  * Copyright (C) 2005, 2007, 2008, 2009, 2010, 2011, 2012  Sylvain Beucler
6 
7  * This file is part of GNU FreeDink
8 
9  * GNU FreeDink is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 3 of the
12  * License, or (at your option) any later version.
13 
14  * GNU FreeDink is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18 
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see
21  * <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 
28 #include "progname.h"
29 
30 /* #define WIN32_LEAN_AND_MEAN */
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <time.h>
35 /* for tolower */
36 #include <ctype.h>
37 /* #include <io.h> */
38 /* #include <direct.h> */
39 #include <unistd.h>
40 #ifdef _WIN32
41 /* GetModuleFileName */
42 #include <windows.h>
43 #endif
44 #include <getopt.h>
45 
46 #include "SDL.h"
47 #include "SDL_rotozoom.h"
48 #include "SDL_framerate.h"
49 
50 #include "init.h"
51 #include "dinkvar.h"
52 #include "screen.h"
53 #include "fastfile.h"
54 #include "gfx.h"
55 #include "game_engine.h"
56 #include "screen.h"
57 #include "gfx_sprites.h"
58 #include "gfx_tiles.h"
59 #include "gfx_fonts.h"
60 #include "sfx.h"
61 #include "input.h"
62 #include "io_util.h"
63 #include "paths.h"
64 #include "log.h"
65 
66 //Dinkedit-only vars
67 
68 
69 /*
70  * I count 10 modes in Dinkedit: map(1), screen tiles(3), screen
71  * sprites(6), screen hardness initialization (9, switches to 8
72  * immediately), screen hardness(8), tile hardness(4), sprite
73  * chooser(5), tile chooser(2), sprite hardness editor(7), plus input
74  * dialog(0). */
75 /* TODO: The goal is to split the big keybinding functions into these
76  * modes, and in each mode, call a function instead of inlining the
77  * code. And we may use 'else if', or even a hashmap to do the
78  * bindings.
79 */
80 
81 /* Use constants for readability */
82 #define MODE_MINIMAP 1
83 #define MODE_TILE_PICKER 2
84 #define MODE_SPRITE_PICKER 5
85 
86 #define MODE_SCREEN_TILES 3
87 #define MODE_SCREEN_SPRITES 6
88 #define MODE_SCREEN_HARDNESS 8
89 #define MODE_SCREEN_HARDNESS_INIT 9
90 
91 #define MODE_TILE_HARDNESS 4
92 #define MODE_SPRITE_HARDNESS 7
93 
94 #define MODE_DIALOG 0
95 
96 
97 #define INPUT_MINIMAP_LOAD  30
98 #define INPUT_SCREEN_VISION 32
99 #define INPUT_SCREEN_MIDI   33
100 #define INPUT_SCREEN_TYPE   34
101 
102 enum editor_buttons {
103   EDITOR_ACTION_FIRST  = 0, // min constant for loops, like SDLKey
104   EDITOR_ACTION_NOOP = 0,
105   EDITOR_ACTION_ESCAPE = 1,
106   EDITOR_ACTION_RETURN,
107   EDITOR_ACTION_X,
108   EDITOR_ACTION_Z,
109   EDITOR_ACTION_TAB,
110   EDITOR_ACTION_LAST // max+1 constant for loops
111 };
112 
113 struct map_info buffmap;
114 /*bool*/int buf_mode = /*false*/0;
115 static char buf_path[100];
116 static int buf_map = 0;
117 
118 /* Save x and y coordinates for mode 4, 5 and 6 */
119 static int m4x,m4y,m5x,m5y,m6x,m6y,m5ax,m5ay;
120 /* LPDIRECTDRAWCLIPPER lpClipper; */
121 
122 static int sp_base_walk = -1;
123 static int sp_base_idle = -1;
124 static int sp_base_attack = -1;
125 static int sp_base_hit = -1;
126 static int sp_base_die = -1;
127 static int sp_gold, sp_defense, sp_strength, sp_exp, sp_hitpoints;
128 static int sp_timer = 33;
129 static int sp_que;
130 static int sp_hard = 1;
131 static int sp_sound = 0;
132 static int sp_type = 1;
133 static int sp_is_warp = 0;
134 static int sp_warp_map = 0;
135 static /*bool*/int show_display = /*true*/1;
136 static int sp_picker = 0;
137 static int sp_nohit = 0;
138 static int sp_touch_damage = 0;
139 static int sp_warp_x = 0;
140 static int sp_warp_y = 0;
141 static int sp_parm_seq = 0;
142 static char sp_script[15];
143 
144 static int old_command;
145 static int sp_cycle = 0;
146 static   int cur_screen;
147 static int selx = 1;
148 static int sely = 1;
149 static int last_mode = 0;
150 static int last_modereal = 0;
151 static int hold_warp_map, hold_warp_x,hold_warp_y;
152 static int sp_seq,sp_frame = 0;
153 
154 
155 /* const int NUM_SOUND_EFFECTS = 6; */
156 #define NUM_SOUND_EFFECTS 2
157 
158 typedef enum enum_EFFECT
159 {
160     SOUND_STOP = 0,
161 /*     SOUND_THROW, */
162     SOUND_JUMP,
163 /*     SOUND_STUNNED, */
164 /*     SOUND_BEARSTRIKE, */
165 /*     SOUND_BEARMISS, */
166 } EFFECT;
167 
168 static char *szSoundEffects[NUM_SOUND_EFFECTS] =
169 {
170     "stop.wav",
171 /*     "THROW.WAV", */
172     "jump.wav"
173 /*     "STUNNED.WAV", */
174 /*     "STRIKE02.WAV", */
175 /*     "MISS02.WAV" */
176 };
177 
178 
179 static int x = 640;
180 static int y = 480;
181 
182 static char in_temp[200];
183 static int in_command;
184 static int in_onflag;
185 static int in_max = 10;
186 static int in_huh = 0;
187 static char in_default[200];
188 static int in_master = 0;
189 
190 static int *in_int;
191 static char *in_string;
192 static int in_x, in_y;
193 static /*bool*/int in_enabled;
194 
195 static int sp_mode;
196 static int sp_speed = 0;
197 static int sp_brain = 0;
198 static /*bool*/int sp_screenmatch = 0;
199 static int hard_tile = 0;
200 static int last_sprite_added = 0;
201 static int map_vision = 0;
202 
203 static int m1x,m1y;
204 static int m2x,m2y;
205 static int m3x,m3y;
206 static int cur_tile;
207 
208 /**
209  * Get the screen tile under coords x,y
210  */
xy2screentile(int x,int y)211 int xy2screentile(int x, int y)
212 {
213   return
214     ((y + 1) * 12) / 50
215     + x / 50;
216 }
217 
218 
219 
220 // PROC NAMES
221 
222 /*BOOL*/int initFail(char mess[200] );
223 
224 int getkeystate(int key);
225 int getcharstate(Uint16 character);
226 char key_convert(int key);
227 
228 void draw_map(void);
229 void draw_minimap(void);
230 /* void dderror(HRESULT hErr); */
231 
232 
draw_sprite(SDL_Surface * GFX_lpdest,int h)233 void draw_sprite(SDL_Surface *GFX_lpdest, int h)
234 {
235   rect box_crap,box_real;
236 /*   HRESULT             ddrval; */
237 /*   DDBLTFX     ddbltfx; */
238 /*   ddbltfx.dwSize = sizeof( ddbltfx); */
239 /*   ddbltfx.dwFillColor = 0; */
240 
241   if (get_box(h, &box_crap, &box_real))
242     {
243 /*       while(1) */
244 /* 	{ */
245 /* 	again: */
246 /* 	  ddrval = lpdest->Blt(&box_crap, k[getpic(h)].k, */
247 /* 			       &box_real, DDBLT_KEYSRC, &ddbltfx); */
248 
249 	  // GFX
250 	  {
251 	    SDL_Rect src, dst;
252 	    src.x = box_real.left;
253 	    src.y = box_real.top;
254 	    src.w = box_real.right - box_real.left;
255 	    src.h = box_real.bottom - box_real.top;
256 	    dst.x = box_crap.left;
257 	    dst.y = box_crap.top;
258 	    dst.w = box_crap.right - box_crap.left;
259 	    dst.h = box_crap.bottom - box_crap.top;
260 	    gfx_blit_stretch(GFX_k[getpic(h)].k, &src, GFX_lpdest, &dst);
261 	  }
262 
263 /* 	  if (ddrval != DD_OK) */
264 /* 	    { */
265 /* 	      if (ddrval == DDERR_WASSTILLDRAWING) */
266 /* 		goto again; */
267 
268 /* 	      //dderror(ddrval); */
269 /* 	      dderror(ddrval); */
270 /* 	      if (draw_map_tiny > 0)  */
271 /* 		{ */
272 /* 		  Msg("MainSpriteDraw(): Could not draw sprite %d, pic %d. (Seq %d, Fram %d) (map %d)",h,getpic(h),spr[h].pseq, spr[h].pframe, draw_map_tiny); */
273 /* 		  Msg("Box_crap: %d %d %d %d, Box_real: %d %d %d %d",box_crap.left,box_crap.top, */
274 /* 		      box_crap.right, box_crap.bottom,box_real.left,box_real.top, */
275 /* 		      box_real.right, box_real.bottom); */
276 /* 		} */
277 /* 	      else */
278 /* 		{ */
279 /* 		  Msg("MainSpriteDraw(): Could not draw sprite %d, pic %d. (map %d)",h,getpic(h), cur_map); */
280 /* 		} */
281 /* 	      check_sprite_status(h); */
282 /* 	      break; */
283 /* 	    } */
284 /* 	  break; */
285 /* 	} */
286     }
287 }
288 
289 
290 /**
291  * Draw all screen sprites, ordered by queue.
292  *
293  * Also cf. game's place_sprites_game(...) and
294  * place_sprites_game_background(...).
295  */
place_sprites()296 void place_sprites()
297 {
298   int rank[MAX_SPRITES_EDITOR];
299   screen_rank_map_sprites(rank);
300 
301   int r1 = 0;
302   for (; r1 < MAX_SPRITES_EDITOR && rank[r1] > 0; r1++)
303     {
304       //Msg("Ok, rank[%d] is %d.",oo,rank[oo]);
305       int j = rank[r1];
306 
307       if (pam.sprite[j].active == 1
308 	  && (pam.sprite[j].vision == 0 || pam.sprite[j].vision == map_vision))
309 	{
310 	  //we have instructions to make a sprite
311 
312 	  if (pam.sprite[j].type == 0 || pam.sprite[j].type == 2)
313 	    {
314 	      //make it part of the background (much faster)
315 	      int sprite = add_sprite_dumb(pam.sprite[j].x,pam.sprite[j].y, 0,
316 					   pam.sprite[j].seq,pam.sprite[j].frame,
317 					   pam.sprite[j].size);
318 
319 	      spr[sprite].hard = pam.sprite[j].hard;
320 	      check_sprite_status(sprite);
321 	      spr[sprite].sp_index = j;
322 	      rect_copy(&spr[sprite].alt , &pam.sprite[j].alt);
323 
324 	      if (pam.sprite[j].type == 0)
325 		draw_sprite(GFX_lpDDSTwo, sprite);
326 
327 	      if (spr[sprite].hard == 0)
328 		{
329 		  if (pam.sprite[j].is_warp == 0)
330 		    add_hardness(sprite, 1);
331 		  else add_hardness(sprite, 100 + j);
332 		}
333 
334 	      spr[sprite].active = 0;
335 	    }
336 
337 	  if (pam.sprite[j].type == 1)
338 	    {
339 	      //make it a living sprite
340 
341 	      int sprite = add_sprite_dumb(pam.sprite[j].x,pam.sprite[j].y, 0,
342 					   pam.sprite[j].seq,pam.sprite[j].frame,
343 					   pam.sprite[j].size);
344 
345 	      spr[sprite].que = pam.sprite[j].que;
346 	      check_sprite_status(sprite);
347 	      spr[sprite].hard = pam.sprite[j].hard;
348 
349 	      rect_copy(&spr[sprite].alt , &pam.sprite[j].alt);
350 
351 	      if (spr[sprite].hard == 0)
352 		{
353 		  if (pam.sprite[j].is_warp == 0)
354 		    add_hardness(sprite, 1); else add_hardness(sprite,100+j);
355 		}
356 	    }
357 	}
358     }
359 }
360 
361 
362 
363 /* Draw background from tiles */
draw_map(void)364 void draw_map(void)
365 {
366   fill_screen(0);
367   fill_whole_hard();
368 
369   while (kill_last_sprite());
370 
371   gfx_tiles_draw_screen();
372   place_sprites();
373 }
374 
375 
376 
377 
378 /**
379  * Draw the currently selected tile square (in the bottom-right corner
380  * of the screen)
381  */
draw_current()382 void draw_current()
383 {
384   int srctileset_idx0 = cur_tile / 128;
385   int srctile_square_idx0 = cur_tile % 128;
386 
387   SDL_Rect src;
388   int srctile_square_x = srctile_square_idx0 % GFX_TILES_SCREEN_W;
389   int srctile_square_y = srctile_square_idx0 / GFX_TILES_SCREEN_W;
390   src.x = srctile_square_x * GFX_TILES_SQUARE_SIZE;
391   src.y = srctile_square_y * GFX_TILES_SQUARE_SIZE;
392   src.w = GFX_TILES_SQUARE_SIZE;
393   src.h = GFX_TILES_SQUARE_SIZE;
394 
395   SDL_Rect dst = {590, 430};
396   SDL_BlitSurface(gfx_tiles[srctileset_idx0 + 1], &src, GFX_lpDDSTwo, &dst);
397 }
398 
399 /* Edit a tile hardness - show semi-transparent red/blue/orange
400    squares on pixels with different kinds of hardness */
draw_hard(void)401 void draw_hard( void)
402 {
403  //RECT                rcRect;
404   int x;
405   for (x = 0; x < 50; x++)
406     {
407       int y;
408       for (y = 0; y < 50; y++)
409 	{
410 	  /* red */
411 	  if (hmap.htile[hard_tile].x[x].y[y] == 1)
412 	    {
413 /* 	      lpDDSBack->BltFast(95+(x*9), y*9, k[seq[10].frame[2]].k, */
414 /* 				 &k[seq[10].frame[2]].box, DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT); */
415 	      // GFX
416 	      {
417 		SDL_Rect dst;
418 		dst.x = 95 + x*9;
419 		dst.y = y*9;
420 		SDL_BlitSurface(GFX_k[seq[10].frame[2]].k, NULL, GFX_lpDDSBack, &dst);
421 	      }
422 	    }
423 
424 	  /* blue */
425 	  if (hmap.htile[hard_tile].x[x].y[y] == 2)
426 	    {
427 /* 	      lpDDSBack->BltFast(95+(x*9),y*9, k[seq[10].frame[9]].k, */
428 /* 				 &k[seq[10].frame[9]].box, DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT); */
429 	      // GFX
430 	      {
431 		SDL_Rect dst;
432 		dst.x = 95 + x*9;
433 		dst.y = y*9;
434 		SDL_BlitSurface(GFX_k[seq[10].frame[9]].k, NULL, GFX_lpDDSBack, &dst);
435 	      }
436 	    }
437 
438 	  /* orange */
439 	  if (hmap.htile[hard_tile].x[x].y[y] == 3)
440 	    {
441 /* 	      lpDDSBack->BltFast(95+(x*9),y*9, k[seq[10].frame[10]].k, */
442 /* 				 &k[seq[10].frame[10]].box, DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT); */
443 	      // GFX
444 	      {
445 		SDL_Rect dst;
446 		dst.x = 95 + x*9;
447 		dst.y = y*9;
448 		SDL_BlitSurface(GFX_k[seq[10].frame[10]].k, NULL, GFX_lpDDSBack, &dst);
449 	      }
450 	    }
451 	}
452     }
453 }
454 
455 
456 void
draw_this_map(struct map_info * pmap)457 draw_this_map(struct map_info* pmap)
458 {
459   int x;
460   for (x = 0; x < 768; x++)
461     {
462       /* Blue square - unused screen */
463       if (pmap->loc[x+1] == 0)
464 	{
465 /* 	  lpDDSTwo->BltFast((x) * 20 - ((x / 32) * 640), (x / 32) * 20, k[seq[10].frame[6]].k, */
466 /* 			    &k[seq[10].frame[6]].box, DDBLTFAST_NOCOLORKEY| DDBLTFAST_WAIT ); */
467 	  // GFX
468 	  {
469 	    SDL_Rect dst;
470 	    SDL_Surface *sprite;
471 	    sprite = GFX_k[seq[10].frame[6]].k;
472 	    dst.x = x * 20 - x/32*640;
473 	    dst.y = x/32 * 20;
474 	    gfx_blit_nocolorkey(sprite, NULL, GFX_lpDDSTwo, &dst);
475 	  }
476 	}
477       /* Red square - used screen */
478       if (pmap->loc[x+1] > 0)
479 	{
480 /* 	  lpDDSTwo->BltFast((x) * 20 - ((x / 32) * 640), (x / 32) * 20, k[seq[10].frame[7]].k, */
481 /* 			    &k[seq[10].frame[7]].box, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT); */
482 	  // GFX
483 	  {
484 	    SDL_Rect dst;
485 	    SDL_Surface *sprite = GFX_k[seq[10].frame[7]].k;
486 	    dst.x = x * 20 - x/32*640;
487 	    dst.y = x/32 * 20;
488 	    gfx_blit_nocolorkey(sprite, NULL, GFX_lpDDSTwo, &dst);
489 	  }
490 	}
491 
492       /* M mark - screen has MIDI */
493       if (pmap->music[x+1] != 0)
494 	{
495 /* 	  lpDDSTwo->BltFast((x) * 20 - ((x / 32) * 640), (x / 32) * 20, k[seq[10].frame[12]].k, */
496 /* 			    &k[seq[10].frame[12]].box, DDBLTFAST_SRCCOLORKEY| DDBLTFAST_WAIT ); */
497 	  // GFX
498 	  {
499 	    SDL_Rect dst;
500 	    dst.x = x * 20 - x/32*640;
501 	    dst.y = x/32 * 20;
502 	    SDL_BlitSurface(GFX_k[seq[10].frame[12]].k, NULL, GFX_lpDDSTwo, &dst);
503 	  }
504 	}
505       /* S mark - screen has screentype / is indoor */
506       if (pmap->indoor[x+1] != 0)
507 	{
508 /* 	  lpDDSTwo->BltFast( (x) * 20 - ((x / 32) * 640), (x / 32) * 20, k[seq[10].frame[13]].k, */
509 /*            &k[seq[10].frame[13]].box, DDBLTFAST_SRCCOLORKEY| DDBLTFAST_WAIT ); */
510 	  // GFX
511 	  {
512 	    SDL_Rect dst;
513 	    dst.x = x * 20 - x/32*640;
514 	    dst.y = x/32 * 20;
515 	    SDL_BlitSurface(GFX_k[seq[10].frame[13]].k, NULL, GFX_lpDDSTwo, &dst);
516 	  }
517 	}
518     }
519 }
520 
521 /* Draw all squares in the map picker mode, including the 'M' (midi)
522    and 'S' (screentype) marks */
draw_minimap(void)523 void draw_minimap(void)
524 {
525   /*box_crap.top = spr[h].y + k[spr[h].pic].hardbox.top;
526     box_crap.bottom = spr[h].y + k[spr[h].pic].hardbox.bottom;
527     box_crap.left = spr[h].x + k[spr[h].pic].hardbox.left;
528     box_crap.right = spr[h].x + k[spr[h].pic].hardbox.right;
529   */
530   //lpDDSBack->Blt(NULL ,NULL,NULL, DDBLT_COLORFILL, &ddbltfx);
531   draw_this_map(&map);
532 }
533 
534 
535 
536 
load_map_buf(const int num)537 /*bool*/int load_map_buf(const int num)
538 {
539   char crap[120];
540   /* TODO: Dinkedit historically loads map with a filename relative to
541      the current D-Mod directory. Maybe change that to handle absolute
542      paths and paths relative to the refdir. */
543   sprintf(crap, "%sMAP.DAT", buf_path);
544   load_map_to(crap, num, &pam);
545 
546   return /*true*/1;
547 }
548 
load_info_buff(void)549 void load_info_buff(void)
550 {
551   char crap[120];
552 
553   sprintf(crap, "%sDINK.DAT", buf_path);
554 
555   if (load_info_to(crap, &buffmap) < 0)
556     {
557       log_error("World not found in %s.", buf_path);
558       buf_mode = /*false*/0;
559     }
560   else
561     {
562       log_info("World data loaded.");
563       buf_mode = /*true*/1;
564     }
565 }
566 
567 /* draw_minimap() but on a different map ('L' in map picker mode) */
draw_minimap_buff(void)568 void draw_minimap_buff(void)
569 {
570   load_info_buff();
571 
572   if (!buf_mode)
573     {
574       //failed
575       /* TODO: display error message to the user */
576       draw_minimap();
577       return;
578     }
579 
580   draw_this_map(&buffmap);
581 }
582 
583 
add_new_map(void)584 int add_new_map(void)
585 {
586   FILE *fp;
587   long now;
588 
589   fp = paths_dmodfile_fopen("MAP.DAT", "a+b");
590   if (fp == NULL)
591     {
592       perror("Cannot open MAP.DAT");
593       return -1;
594     }
595   fwrite(&pam,sizeof(struct small_map), 1, fp);
596   now = (ftell(fp) / (sizeof(struct small_map)));
597   fclose(fp);
598 
599   return(now);
600 }
601 
602 
603 
604 
605 /* Read key "is pressed?" status from cache */
606 int
getkeystate(int key)607 getkeystate(int key)
608 {
609   if (sjoy.keystate[key])
610     return 1;
611   else
612     return 0;
613 }
614 
615 /* Read key "is pressed?" status from cache - but with a character
616    code*/
617 int
getcharstate(Uint16 character)618 getcharstate(Uint16 character)
619 {
620   if (sjoy.charstate[character])
621     return 1;
622   else
623     return 0;
624 }
625 
626 /* Set the keyboard state in sjoy */
check_keyboard()627 void check_keyboard()
628 {
629   /* Keys state */
630   /* Check if the key was just pressed, or only maintained pressed */
631   int keystate_size;
632   Uint8 *new_keystate;
633   new_keystate = SDL_GetKeyState(&keystate_size);
634   int x = 0;
635   for (x = 0; x < keystate_size; x++)
636     {
637       /* Put the current keyboard state in cache */
638       /* getkey() then can check sjoy.keystate - that is, from the cache */
639       int last_state = sjoy.keystate[x];
640       sjoy.keystate[x] = new_keystate[x];
641 
642       if (last_state == 0 && sjoy.keystate[x] == 1)
643 	/* We just changed from "released" to "pressed" */
644 	sjoy.keyjustpressed[x] = 1;
645       else
646 	sjoy.keyjustpressed[x] = 0;
647     }
648 
649   /* Layout-independant character state */
650   /* Reset 'just pressed' field */
651   memset(sjoy.charjustpressed, 0, sizeof(sjoy.charjustpressed));
652   sjoy.last_unicode = 0;
653   if (sjoy.last_nokey_unicode != 0)
654     {
655       sjoy.charstate[sjoy.last_nokey_unicode] = 0;
656       sjoy.charjustpressed[sjoy.last_nokey_unicode] = 0;
657       sjoy.last_nokey_unicode = 0;
658     }
659 
660   /* Pick ONE event, so as not to miss keystorkes in text input
661      mode */
662   SDL_Event event;
663   if (SDL_PeepEvents(&event, 1, SDL_GETEVENT,
664 		     SDL_EVENTMASK(SDL_KEYDOWN)|SDL_EVENTMASK(SDL_KEYUP)) > 0)
665     {
666       int key = event.key.keysym.sym;
667       Uint16 unicode = event.key.keysym.unicode;
668       switch (event.type)
669 	{
670 	case SDL_KEYDOWN:
671 	  sjoy.charstate[unicode] = 1;
672 	  sjoy.charjustpressed[unicode] = 1;
673 	  sjoy.last_unicode = unicode;
674 	  if (key != 0)
675 	    sjoy.key2char[key] = unicode;
676 	  else
677 	    /* No possible 'kept pressed' support, so will be marked
678 	       'not pressed' next time */
679 	    sjoy.last_nokey_unicode = unicode;
680 	  break;
681 	case SDL_KEYUP:
682 	  /* No Unicode on KEYUP :/ */
683 	  if (key != 0)
684 	    {
685 	      unicode = sjoy.key2char[key];
686 	      sjoy.charstate[unicode] = 0;
687 	    }
688 	  break;
689 	}
690     }
691 }
692 
693 
check_joystick(void)694 void check_joystick(void)
695 {
696   /* Clean-up */
697   /* Actions */
698   {
699     int a = EDITOR_ACTION_FIRST;
700     for (a = EDITOR_ACTION_FIRST; a < EDITOR_ACTION_LAST; a++)
701       sjoy.joybit[a] = 0;
702   }
703 
704   /* Arrows */
705   sjoy.right = 0;
706   sjoy.left = 0;
707   sjoy.up = 0;
708   sjoy.down = 0;
709 
710   if (joystick)
711     {
712       SDL_JoystickUpdate();
713       Sint16 x_pos = 0, y_pos = 0;
714       /* SDL counts buttons from 0, not from 1 */
715       int i = 0;
716       for (i = 0; i < NB_BUTTONS; i++)
717 	if (SDL_JoystickGetButton(jinfo, i))
718 	  {
719 	    if (i == 1-1)
720 	      sjoy.joybit[EDITOR_ACTION_ESCAPE] = 1;
721 	    else if (i == 2-1)
722 	      sjoy.joybit[EDITOR_ACTION_RETURN] = 1;
723 	    else if (i == 3-1)
724 	      sjoy.joybit[EDITOR_ACTION_X] = 1;
725 	    else if (i == 4-1)
726 	      sjoy.joybit[EDITOR_ACTION_Z] = 1;
727 	    else if (i == 5-1)
728 	      sjoy.joybit[EDITOR_ACTION_TAB] = 1;
729 	  }
730 
731       x_pos = SDL_JoystickGetAxis(jinfo, 0);
732       y_pos = SDL_JoystickGetAxis(jinfo, 1);
733       /* Using thresold=10% (original game) is just enough to get rid
734 	 of the noise. Let's use 30% instead, otherwise Dink will go
735 	 diags too easily. */
736       {
737 	Sint16 threshold = 32767 * 30/100;
738 	if (x_pos < -threshold) sjoy.left  = 1;
739 	if (x_pos > +threshold) sjoy.right = 1;
740 	if (y_pos < -threshold) sjoy.up    = 1;
741 	if (y_pos > +threshold) sjoy.down  = 1;
742       }
743     }
744 
745   /* Refresh keyboard state */
746   check_keyboard();
747 
748   if (getkeystate(SDLK_ESCAPE)) sjoy.joybit[EDITOR_ACTION_ESCAPE] = 1;
749   if (getkeystate(SDLK_RETURN)) sjoy.joybit[EDITOR_ACTION_RETURN] = 1;
750   if (getcharstate('x')) sjoy.joybit[EDITOR_ACTION_X] = 1;
751   if (getcharstate('z')) sjoy.joybit[EDITOR_ACTION_Z] = 1;
752   if (getkeystate(SDLK_TAB)) sjoy.joybit[EDITOR_ACTION_TAB] = 1;
753   if (getkeystate(SDLK_RIGHT)) sjoy.right = 1;
754   if (getkeystate(SDLK_LEFT)) sjoy.left = 1;
755   if (getkeystate(SDLK_DOWN)) sjoy.down = 1;
756   if (getkeystate(SDLK_UP)) sjoy.up = 1;
757 
758   {
759     int a = EDITOR_ACTION_FIRST;
760     for (a = EDITOR_ACTION_FIRST; a < EDITOR_ACTION_LAST; a++)
761       {
762 	sjoy.button[a] = 0;
763 	if (sjoy.joybit[a] && sjoy.joybitold[a] == 0)
764 	  /* Button was just pressed */
765 	  sjoy.button[a] = 1;
766 	sjoy.joybitold[a] = sjoy.joybit[a];
767       }
768   }
769 }
770 
771 /* Human-readable representation of the keycode, used to display which
772    key is currently pressed */
773 /* Note: key constants may be found in winuser.h. The
774    "Keycodes"/keycodes.txt file by Dan Walma also brings some clues
775    about the _OEM keys. */
776 char
key_convert(int key)777 key_convert(int key)
778 {
779   if (SDL_GetModState()&KMOD_SHIFT) key = toupper(key);
780 
781   if (key == 190 /* VK_OEM_PERIOD */) { if (SDL_GetModState()&KMOD_SHIFT) key = '>'; else key = '.'; }
782   if (key == 188 /* VK_OEM_COMMA */)  { if (SDL_GetModState()&KMOD_SHIFT) key = '<'; else key = ','; }
783 
784   if (key == '1') if (SDL_GetModState()&KMOD_SHIFT) key = '!';
785   if (key == '2') if (SDL_GetModState()&KMOD_SHIFT) key = '@';
786   if (key == '3') if (SDL_GetModState()&KMOD_SHIFT) key = '#';
787   if (key == '4') if (SDL_GetModState()&KMOD_SHIFT) key = '$';
788   if (key == '5') if (SDL_GetModState()&KMOD_SHIFT) key = '%';
789   if (key == '6') if (SDL_GetModState()&KMOD_SHIFT) key = '^';
790   if (key == '7') if (SDL_GetModState()&KMOD_SHIFT) key = '&';
791   if (key == '8') if (SDL_GetModState()&KMOD_SHIFT) key = '*';
792   if (key == '9') if (SDL_GetModState()&KMOD_SHIFT) key = '(';
793   if (key == '0') if (SDL_GetModState()&KMOD_SHIFT) key = ')';
794 
795   if (key == 189 /* VK_OEM_MINUS */) { if (SDL_GetModState()&KMOD_SHIFT) key = '_'; else key = '-'; }
796   if (key == 187 /* VK_OEM_PLUS */) { if (SDL_GetModState()&KMOD_SHIFT) key = '+'; else key = '='; }
797   if (key == 186 /* VK_OEM_1 */) { if (SDL_GetModState()&KMOD_SHIFT) key = ':'; else key = ';'; }
798   if (key == 222 /* VK_OEM_7 */) { if (SDL_GetModState()&KMOD_SHIFT) key = '\"'; else key = '\''; }
799   if (key == 191 /* VK_OEM_2 */) { if (SDL_GetModState()&KMOD_SHIFT) key = '?'; else key = '/'; }
800   if (key == 220 /* VK_OEM_5 */) { if (SDL_GetModState()&KMOD_SHIFT) key = '|'; else key = '\\'; }
801 
802   return(key);
803 }
804 
805 
806 /* Displays a tile fullscreen, so we can select some squares */
loadtile(int tileset)807 void loadtile(int tileset)
808 {
809 /*   DDBLTFX     ddbltfx; */
810 /*   ZeroMemory(&ddbltfx, sizeof(ddbltfx)); */
811 
812   //feel tile background with a color
813 
814 /*   ddbltfx.dwFillColor = 0; */
815 /*   ddbltfx.dwSize = sizeof(ddbltfx); */
816 /*   lpDDSTwo->Blt(NULL,NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); */
817   // GFX
818   SDL_FillRect(GFX_lpDDSTwo, NULL, SDL_MapRGB(GFX_lpDDSTwo->format, 0, 0, 0));
819 
820   spr[1].seq = 3; spr[1].seq_orig = 3;
821   //  if (mode == 3)
822   if (mode == MODE_SCREEN_TILES)
823     {
824       m3x = spr[1].x; m3y = spr[1].y;
825       spr[1].x = m2x; spr[1].y = m2y; mode = 2;
826       spr[1].speed = 50;
827     }
828 
829   //  if (mode == 4)
830   if (mode == MODE_TILE_HARDNESS)
831     {
832       spr[1].x = m2x; spr[1].y = m2y; mode = 2;
833       spr[1].speed = 50;
834     }
835 
836 /*   lpDDSTwo->BltFast(0, 0, tiles[tileset], &tilerect[tileset], DDBLTFAST_NOCOLORKEY |DDBLTFAST_WAIT); */
837   // GFX
838   SDL_BlitSurface(gfx_tiles[tileset], NULL, GFX_lpDDSTwo, NULL);
839   cur_screen = tileset;
840 
841   last_mode = tileset;
842 
843   while(kill_last_sprite());
844 }
845 
846 
sp_get(int num)847 int sp_get( int num)
848 {
849 
850 int t = 1;
851  int j;
852 	for (j = 1; j < MAX_SEQUENCES; j++)
853 	{
854      check_frame_status(j, 1);
855 
856 		if (seq[j].frame[1] != 0)
857 	 {
858        if (t == num)
859 	   {
860 
861 
862 		   return(j);
863 
864 	   }
865 		   t++;
866 
867 	 }
868 
869 
870 
871 	}
872 
873 return(0);
874 
875 }
876 
877 /* In sprite picking mode, draw a grid to separate sprites or
878    sequences' 50x50 previews */
draw_sprite_picker_grid(void)879 static void draw_sprite_picker_grid(void)
880 {
881 /*   DDBLTFX ddbltfx; */
882 /*   RECT box_crap; */
883 
884 /*   ZeroMemory(&ddbltfx, sizeof(ddbltfx)); */
885 /*   ddbltfx.dwSize = sizeof(ddbltfx); */
886 
887   /* Draw vertical lines */
888   int x2, x3;
889   for (x2 = 1; x2 <= 12; x2++)
890     {
891 /*       ddbltfx.dwFillColor = 120; */
892 
893 /*       box_crap.top = 0; */
894 /*       box_crap.bottom = 400; */
895 /*       box_crap.left = (x2*50) -1; */
896 /*       box_crap.right = box_crap.left+1; */
897 
898 /*       ddrval = lpDDSTwo->Blt(&box_crap ,NULL, NULL, DDBLT_COLORFILL|DDBLT_WAIT, &ddbltfx); */
899       // GFX
900       {
901 	SDL_Rect dst = {12345, 0, 12345, 400};
902 	dst.x = x2*50 - 1;
903 	dst.w = 1;
904 	SDL_FillRect(GFX_lpDDSTwo, &dst, SDL_MapRGB(GFX_lpDDSTwo->format, 123, 132, 99));
905       }
906     }
907 
908   /* Draw horizontal lines */
909   for (x3 = 1; x3 <= 8; x3++)
910     {
911 /*       ddbltfx.dwFillColor = 120; */
912 
913 /*       box_crap.top = (50 * x3)-1; */
914 /*       box_crap.bottom = box_crap.top +1; */
915 /*       box_crap.left = 0; */
916 /*       box_crap.right = 600; */
917 
918 /*       ddrval = lpDDSTwo->Blt(&box_crap ,NULL, NULL, DDBLT_COLORFILL|DDBLT_WAIT, &ddbltfx); */
919       // GFX
920       {
921 	SDL_Rect dst = {0, 12345, 600, 12345};
922 	dst.y = x3*50 - 1;
923 	dst.h = 1;
924 	SDL_FillRect(GFX_lpDDSTwo, &dst, SDL_MapRGB(GFX_lpDDSTwo->format, 123, 132, 99));
925       }
926     }
927 }
928 
929 /* Main sprite selection screen - display a page of the sequence
930    selector */
draw15(int num)931 void draw15(int num)
932 {
933 /*   int crap; */
934 /*   DDBLTFX ddbltfx; */
935 /*   rect  crapRec, Rect, box_crap; */
936   int frame;
937 /*   int ddrval; */
938   int se;
939 /*   int dd; */
940   int x1;
941   //get_sp_seq(2);
942 
943   while(kill_last_sprite());
944 
945 
946 /*   ZeroMemory(&ddbltfx, sizeof(ddbltfx)); */
947 /*   ddbltfx.dwSize = sizeof( ddbltfx); */
948 /*   ddbltfx.dwFillColor = 0; */
949 /*   crap = lpDDSTwo->Blt(NULL ,NULL,NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); */
950   // GFX
951   SDL_FillRect(GFX_lpDDSTwo, NULL, SDL_MapRGB(GFX_lpDDSTwo->format, 0, 0, 0));
952 
953 /*   ZeroMemory(&ddbltfx, sizeof(ddbltfx)); */
954 /*   ddbltfx.dwSize = sizeof( ddbltfx); */
955 
956   Say("Please wait, loading sprite data into SmartCache system...", 147,160);
957 
958   flip_it();
959 
960   /* Draw sprites */
961   for (x1 = 0; x1 <= 11; x1++)
962     {
963       int y1;
964       for (y1=0; y1 <= 7; y1++)
965 	{
966 	  num++;
967 
968 	  se = sp_get(num);
969 	  check_seq_status(se);
970 
971 	  if (se > 0)
972 	    {
973 	      frame = 1;
974 
975 /* 	      Rect.left = x1 * 50; */
976 /* 	      Rect.top = y1 * 50; */
977 /* 	      Rect.right = Rect.left + 50; */
978 /* 	      Rect.bottom = Rect.top + 50; */
979 
980 /* 	      crapRec = k[seq[se].frame[frame]].box; */
981 
982 /* 	      dd = lpDDSTwo->Blt(&Rect, k[seq[se].frame[frame]].k, */
983 /* 				 &crapRec, DDBLT_KEYSRC | DDBLT_DDFX | DDBLT_WAIT, &ddbltfx); */
984 	      // GFX
985 	      {
986 		SDL_Rect dst;
987 		dst.x = x1 * 50;
988 		dst.y = y1 * 50;
989 		dst.w = 50;
990 		dst.h = 50;
991 		gfx_blit_stretch(GFX_k[seq[se].frame[frame]].k, NULL, GFX_lpDDSTwo, &dst);
992 	      }
993 
994 
995 /* 	      if (dd != DD_OK) Msg("Error with drawing sprite! Seq %d, Spr %d.", se, frame); */
996 	    }
997 	}
998     }
999   draw_sprite_picker_grid();
1000 }
1001 
1002 /* Inner sprite selection screen - display all frames/sprites in a
1003    sequence */
draw96(int def)1004 void draw96(int def)
1005 {
1006 /*   int crap; */
1007 /*   DDBLTFX ddbltfx; */
1008 /*   rect crapRec, Rect, box_crap; */
1009 /*   int ddrval; */
1010   int se;
1011 /*   int dd; */
1012   int x1;
1013 
1014   //get_sp_seq(2);
1015   se = sp_seq;
1016   check_seq_status(se);
1017   int num = 0;
1018   while(kill_last_sprite());
1019 
1020 /*   ZeroMemory(&ddbltfx, sizeof(ddbltfx)); */
1021 /*   ddbltfx.dwSize = sizeof( ddbltfx); */
1022 /*   ddbltfx.dwFillColor = 0; */
1023 /*   crap = lpDDSTwo->Blt(NULL ,NULL,NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); */
1024   // GFX
1025   SDL_FillRect(GFX_lpDDSTwo, NULL, SDL_MapRGB(GFX_lpDDSTwo->format, 0, 0, 0));
1026 
1027 /*   ZeroMemory(&ddbltfx, sizeof(ddbltfx)); */
1028 /*   ddbltfx.dwSize = sizeof( ddbltfx); */
1029 
1030   for (x1=0; x1 <= 11; x1++)
1031     {
1032       int y1;
1033       for (y1=0; y1 <= 7; y1++)
1034 	{
1035 	  num++;
1036 	  if (seq[se].frame[num] == 0)
1037 	    {
1038 	      //all done displaying
1039 	      goto pass;
1040 	    }
1041 	  //se = sp_get(num);
1042 
1043 /* 	  Rect.left = x1 * 50; */
1044 /* 	  Rect.top = y1 * 50; */
1045 /* 	  Rect.right = Rect.left + 50; */
1046 /* 	  Rect.bottom = Rect.top + 50; */
1047 
1048 	  if (def > 0 && num == def)
1049 	    {
1050 	      //set default location to sprite they are holding
1051 	      spr[1].x = x1*50;
1052 	      spr[1].y = y1 *50;
1053 	    }
1054 
1055 /* 	  crapRec = k[seq[se].frame[num]].box; */
1056 
1057 /* 	  dd = lpDDSTwo->Blt(&Rect, k[seq[se].frame[num]].k, */
1058 /* 			     &crapRec, DDBLT_KEYSRC | DDBLT_DDFX | DDBLT_WAIT, &ddbltfx ); */
1059 	  // GFX
1060 	  {
1061 	    SDL_Rect dst;
1062 	    dst.x = x1 * 50;
1063 	    dst.y = y1 * 50;
1064 	    dst.w = 50;
1065 	    dst.h = 50;
1066 	    gfx_blit_stretch(GFX_k[seq[se].frame[num]].k, NULL, GFX_lpDDSTwo, &dst);
1067 	  }
1068 
1069 /* 	  if (dd != DD_OK) Msg("Error with drawing sprite! Seq %d, Spr %d.",se,frame); */
1070 	}
1071     }
1072 
1073  pass:
1074   draw_sprite_picker_grid();
1075 }
1076 
1077 
sp_add(void)1078 void sp_add( void )
1079 {
1080   int j;
1081 	for (j = 1; j < 100; j++)
1082 	{
1083 		if (pam.sprite[j].active == /*false*/0)
1084 		{
1085 
1086 			last_sprite_added = j;
1087 			//Msg("Adding sprite %d, seq %d, frame %d.",j,sp_seq,sp_frame);
1088 			pam.sprite[j].active = /*true*/1;
1089             pam.sprite[j].frame = sp_frame;
1090             pam.sprite[j].seq = sp_seq;
1091 			pam.sprite[j].x = spr[1].x;
1092 			pam.sprite[j].y = spr[1].y;
1093 			pam.sprite[j].size = spr[1].size;
1094 			pam.sprite[j].type = sp_type;
1095 			pam.sprite[j].brain = sp_brain;
1096 			pam.sprite[j].speed = sp_speed;
1097 			pam.sprite[j].base_walk = sp_base_walk;
1098 			pam.sprite[j].base_idle = sp_base_idle;
1099 			pam.sprite[j].base_attack = sp_base_attack;
1100 			pam.sprite[j].base_hit = sp_base_hit;
1101 			pam.sprite[j].timer = sp_timer;
1102 			pam.sprite[j].que = sp_que;
1103 			pam.sprite[j].hard = sp_hard;
1104 			pam.sprite[j].is_warp = sp_is_warp;
1105 			pam.sprite[j].warp_map = sp_warp_map;
1106 			pam.sprite[j].warp_x = sp_warp_x;
1107 			pam.sprite[j].warp_y = sp_warp_y;
1108 			pam.sprite[j].parm_seq = sp_parm_seq;
1109 			strcpy(pam.sprite[j].script, sp_script);
1110 			pam.sprite[j].base_die = sp_base_die;
1111 			pam.sprite[j].gold = sp_gold;
1112 			pam.sprite[j].exp = sp_exp;
1113 			pam.sprite[j].strength = sp_strength;
1114 			pam.sprite[j].defense = sp_defense;
1115 			pam.sprite[j].hitpoints = sp_hitpoints;
1116 			pam.sprite[j].sound = sp_sound;
1117 		    pam.sprite[j].vision = map_vision;
1118 		    pam.sprite[j].nohit = sp_nohit;
1119 			pam.sprite[j].touch_damage = sp_touch_damage;
1120 			rect_copy(&pam.sprite[j].alt , &spr[1].alt);
1121 		    return;
1122 		}
1123 
1124 
1125 
1126 	}
1127 
1128 
1129 }
1130 
1131 
smart_add(void)1132 void smart_add(void)
1133 {
1134 
1135 
1136 
1137 
1138 	sp_add();
1139 
1140 if (sp_screenmatch)
1141 {
1142 
1143 if (spr[1].size == 100)
1144 {
1145 //lets see if the sprite crosses into another screen
1146 //use screenmatch technology
1147 
1148 	if ((spr[1].x - k[getpic(1)].xoffset) + k[getpic(1)].box.right > 620)
1149 	{
1150 	log_debug("need to add it to the right");
1151 
1152 		//need to add it to the right
1153 		if (map.loc[cur_map+1] > 0)
1154 		{
1155         	save_map(map.loc[cur_map]);
1156           log_debug("loading right map");
1157 			load_map(map.loc[cur_map+1]);
1158                int holdx = spr[1].x;
1159                int holdy = spr[1].y;
1160 			   spr[1].x -= 600;
1161 			sp_add();
1162 			save_map(map.loc[cur_map+1]);
1163 			load_map(map.loc[cur_map]);
1164            spr[1].x = holdx;
1165 		   spr[1].y = holdy;
1166 		}
1167 	}
1168 
1169 
1170 	if ((spr[1].x - k[getpic(1)].xoffset) - k[getpic(1)].box.right < 20)
1171 	{
1172 	log_debug("need to add it to the right");
1173 
1174 		//need to add it to the left
1175 		if (map.loc[cur_map-1] > 0)
1176 		{
1177         	save_map(map.loc[cur_map]);
1178           log_debug("loading right map");
1179 			load_map(map.loc[cur_map-1]);
1180                int holdx = spr[1].x;
1181                int holdy = spr[1].y;
1182 			   spr[1].x += 600;
1183 			sp_add();
1184 			save_map(map.loc[cur_map-1]);
1185 			load_map(map.loc[cur_map]);
1186            spr[1].x = holdx;
1187 		   spr[1].y = holdy;
1188 		}
1189 	}
1190 
1191 
1192 	if ((spr[1].y - k[getpic(1)].yoffset) + k[getpic(1)].box.bottom > 400)
1193 	{
1194 	log_debug("need to add it to the bottom");
1195 
1196 		//need to add it to the bottom
1197 		if (map.loc[cur_map+32] > 0)
1198 		{
1199         	save_map(map.loc[cur_map]);
1200           log_debug("loading bottom ");
1201 			load_map(map.loc[cur_map+32]);
1202                int holdx = spr[1].x;
1203                int holdy = spr[1].y;
1204 			   spr[1].y -= 400;
1205 			sp_add();
1206 			save_map(map.loc[cur_map+32]);
1207 			load_map(map.loc[cur_map]);
1208            spr[1].x = holdx;
1209 		   spr[1].y = holdy;
1210 		}
1211 	}
1212 
1213 
1214 	if ((spr[1].y - k[getpic(1)].yoffset) - k[getpic(1)].box.bottom < 0)
1215 	{
1216 	log_debug("need to add it to the top");
1217 
1218 		//need to add it to the left
1219 		if (map.loc[cur_map-32] > 0)
1220 		{
1221         	save_map(map.loc[cur_map]);
1222           log_debug("loading top map");
1223 			load_map(map.loc[cur_map-32]);
1224                int holdx = spr[1].x;
1225                int holdy = spr[1].y;
1226 			   spr[1].y += 400;
1227 			sp_add();
1228 			save_map(map.loc[cur_map-32]);
1229 			load_map(map.loc[cur_map]);
1230            spr[1].x = holdx;
1231 		   spr[1].y = holdy;
1232 		}
1233 	}
1234 
1235 }
1236 
1237 }
1238 
1239 
1240 
1241 
1242 
1243 }
1244 
1245 
1246 
1247 
1248 
blit(int seq1,int frame,SDL_Surface * GFX_lpdest,int tx,int ty)1249 void blit(int seq1, int frame, SDL_Surface *GFX_lpdest, int tx, int ty)
1250 {
1251 /* RECT math; */
1252 
1253 /* 	math = k[seq[seq1].frame[frame]].box; */
1254 /* 	OffsetRect(&math, tx, ty); */
1255 /* 	ddrval = lpdest->Blt(&math, k[seq[seq1].frame[frame]].k, &k[seq[seq1].frame[frame]].box, DDBLT_WAIT, NULL); */
1256 	// GFX
1257 	// No scaling needed here
1258 	{
1259 	  SDL_Rect dst;
1260 	  dst.x = tx;
1261 	  dst.y = ty;
1262 	  SDL_BlitSurface(GFX_k[seq[seq1].frame[frame]].k, NULL, GFX_lpdest, &dst);
1263 	}
1264 }
1265 
1266 
1267 /**
1268  * Display the appropriate input dialog
1269  */
check_in(void)1270 void check_in(void)
1271 {
1272   in_huh = in_master;
1273 
1274   /**
1275    * - Sprite dialogs:
1276    *  1 = size
1277    *  2 = type (background|sprite)
1278    *  3 = brain
1279    *  4 = speed
1280    *  5 = timer (timing)
1281    *  6 = base_walk
1282    *  7 = base_idle
1283    *  8 = que
1284    *  9 = hard (hardness_type - background|sprite)
1285    * 10 = is_warp
1286    * 11 = warp_map
1287    * 12 = warp_x
1288    * 13 = warp_y
1289    * 14 = parm_seq
1290    * 15 = script
1291    * 16 = base_die
1292    * 17 = sound (looping sound)
1293    * 18 = hitpoints
1294    * 19 = nohit
1295    * 20 = touch_damage
1296    * 21 = base_attack
1297    * 22 = defense
1298    *
1299    * - Minimap dialogs:
1300    * 30 = 'L' - load screen from another map
1301    *
1302    * - Screen dialogs:
1303    * (called from minimap or screen mode)
1304    * 31 = 'B' - screen script
1305    * 32 = 'V' - vision
1306    * (called from minimap mod)
1307    * 33 = 'M' - screen midi
1308    * 34 = 'S' - screen type (indoors / outside)
1309    **/
1310 
1311   /* In: */
1312   /* in_master = identifier for the property we need to edit */
1313   /* Out: */
1314   /* in_max = maximum length of input (as text) + 1 */
1315   /* in_command = data type (int|string) */
1316   /* in_int =  pointer to the integer value to update */
1317   /* in_string = pointer to the string to update */
1318   /* in_onflag = trigger the creation of an input window */
1319   /* in_enabled ? */
1320 
1321   if (in_master == 1)
1322     {
1323       in_command = 1; //number
1324       in_int = &spr[1].size;
1325       in_max = 10; //max _length
1326       sprintf(in_default,"%d",spr[1].size); //set default
1327       blit(30,1,GFX_lpDDSBack,250,170);
1328       Say("New Size?",260,175);
1329     }
1330 
1331   if (in_master == 2)
1332     {
1333       in_command = 1; //number
1334       in_int = &sp_type;
1335       in_max = 10; //max _length
1336       sprintf(in_default,"%d",sp_type); //set default
1337       blit(30,1,GFX_lpDDSBack,250,170);
1338       Say("New Type?",260,175);
1339       Say("Type controls the sprite's basic type - 0 means it is ornamental only"
1340 	  "(cannot walk behind or think) 1 - means normal sprite.  (for a tree or person)"
1341 	  ,10,10);
1342     }
1343 
1344   if (in_master == 3)
1345     {
1346       in_command = 1; //number
1347       in_int = &sp_brain;
1348       in_max = 10; //max _length
1349       sprintf(in_default,"%d",sp_brain); //set default
1350       blit(30,1,GFX_lpDDSBack,250,170);
1351       Say("New Brain?",260,175);
1352       Say("Brains are a predefined way for this sprite to behave. 0 = No movement, 1 = Dink,"
1353 	  " 2 = Dumb Sprite Bouncer, 3 = Duck, 4 = Pig, 6 = repeat, 7 = one loop then kill,"
1354 	  " 9 = monster (all diag), 10 = monster(no diag)"
1355 	  ,10,10);
1356     }
1357 
1358   if (in_master == 4)
1359     {
1360       in_command = 1; //number
1361       in_int = &sp_speed;
1362       in_max = 10; //max _length
1363       sprintf(in_default,"%d",sp_speed); //set default
1364       blit(30,1,GFX_lpDDSBack,250,170);
1365       Say("New Speed?",260,175);
1366       Say("Speed rating allows you to adjust how fast a certain sprite moves.  Works with"
1367 	  " most brains."
1368 	  ,10,10);
1369     }
1370 
1371   if (in_master == 5)
1372     {
1373       in_command = 1; //number
1374       in_int = &sp_timer;
1375       in_max = 10; //max _length
1376       sprintf(in_default,"%d",sp_timer); //set default
1377       blit(30,1,GFX_lpDDSBack,250,170);
1378       Say("New Timing?",260,175);
1379       Say("This is the delay the CPU waits before processing the sprite after each cycle.  "
1380 	  "(in thousands of a second - so 33 would mean 30 times a second)"
1381 	  ,10,10);
1382     }
1383 
1384   if (in_master == 6)
1385     {
1386       in_command = 1; //number
1387       in_int = &sp_base_walk;
1388       in_max = 10; //max _length
1389       sprintf(in_default,"%d",sp_base_walk); //set default
1390       blit(30,1,GFX_lpDDSBack,250,170);
1391       Say("New Base Walk?",260,175);
1392       Say("The base for which the CPU adds 1 through 9 to make the sprite move, depending on"
1393 	  " direction.  Must be a multiple of ten. (ie, 20 to look like a duck, 40 to look like a pig)"
1394 	  ,10,10);
1395     }
1396 
1397   if (in_master == 7)
1398     {
1399       in_command = 1; //number
1400       in_int = &sp_base_idle;
1401       in_max = 10; //max _length
1402       sprintf(in_default,"%d",sp_base_idle); //set default
1403       blit(30,1,GFX_lpDDSBack,250,170);
1404       Say("New Base Idle?",260,175);
1405       Say("Some brains can optionally use extra sprites for their \'idle\' pose."
1406 	  ,10,10);
1407     }
1408 
1409   if (in_master == 8)
1410     {
1411       in_command = 1; //number
1412       in_int = &sp_que;
1413       in_max = 10; //max _length
1414       sprintf(in_default,"%d",sp_que); //set default
1415       blit(30,1,GFX_lpDDSBack,250,170);
1416       Say("New Depth Que?",250,175);
1417       Say("From 1 to 20000, 0 for default.  (defaults to y cord)"
1418 	  ,10,10);
1419     }
1420 
1421   if (in_master == 9)
1422     {
1423       in_command = 1; //number
1424       in_int = &sp_hard;
1425       in_max = 10; //max _length
1426       sprintf(in_default,"%d",sp_hard); //set default
1427       blit(30,1,GFX_lpDDSBack,250,170);
1428       Say("New Hardness?",260,175);
1429       Say("Sets how hardness works.  1 means normal, (monsters) 0 means added to background. (walls, trees)"
1430 	  ,10,10);
1431     }
1432 
1433   if (in_master == 10)
1434     {
1435       in_command = 1; //number
1436       in_int = &sp_is_warp;
1437       in_max = 10; //max _length
1438       sprintf(in_default,"%d",sp_is_warp); //set default
1439       blit(30,1,GFX_lpDDSBack,250,170);
1440       Say("New Properties?",260,175);
1441       Say("Sets special properties for the hardblock.  0 = normal (just hard) 1 = warp."
1442 	  ,10,10);
1443     }
1444 
1445   if (in_master == 11)
1446     {
1447       in_command = 1; //number
1448       in_int = &sp_warp_map;
1449       in_max = 10; //max _length
1450       sprintf(in_default,"%d",sp_warp_map); //set default
1451       blit(30,1,GFX_lpDDSBack,250,170);
1452       Say("Warp Map #",260,175);
1453       Say("These parms are valid if the hard block property setting is 1.  (warp)"
1454 	  ,10,10);
1455     }
1456 
1457   if (in_master == 12)
1458     {
1459       in_command = 1; //number
1460       in_int = &sp_warp_x;
1461       in_max = 10; //max _length
1462       sprintf(in_default,"%d",sp_warp_x); //set default
1463       blit(30,1,GFX_lpDDSBack,250,170);
1464       Say("Warp X:",260,175);
1465       Say("The X location to warp to.  (20 to 619)"
1466 	  ,10,10);
1467     }
1468 
1469   if (in_master == 13)
1470     {
1471       in_command = 1; //number
1472       in_int = &sp_warp_y;
1473       in_max = 10; //max _length
1474       sprintf(in_default,"%d",sp_warp_y); //set default
1475       blit(30,1,GFX_lpDDSBack,250,170);
1476       Say("Warp Y:",260,175);
1477       Say("The Y location to warp to.  (0 to 499)"
1478 	  ,10,10);
1479     }
1480 
1481   if (in_master == 14)
1482     {
1483       in_command = 1; //number
1484       in_int = &sp_parm_seq;
1485       in_max = 10; //max _length
1486       sprintf(in_default,"%d",sp_parm_seq); //set default
1487       blit(30,1,GFX_lpDDSBack,250,170);
1488       Say("Sequence:",260,175);
1489       Say("This parm is used by some brains/settings if set.  A sequence is an animation #."
1490 	  ,10,10);
1491     }
1492 
1493   if (in_master == 15)
1494     {
1495       in_command = 2; //string
1496       sprintf(in_default, "%s", sp_script);
1497       in_max = 13;
1498       in_string = sp_script;
1499       blit(30,1,GFX_lpDDSBack,250,170);
1500       Say("Script:",260,175);
1501       Say("Filename of script this sprite uses."
1502 	  ,10,10);
1503     }
1504 
1505     if (in_master == 16)
1506       {
1507 	in_command = 1; //number
1508 	in_int = &sp_base_die;
1509 	in_max = 10; //max _length
1510 	sprintf(in_default,"%d",sp_base_die); //set default
1511 	blit(30,1,GFX_lpDDSBack,250,170);
1512 	Say("Base Death:",260,175);
1513 	Say("If this sprite dies, this will be used."
1514 	    ,10,10);
1515       }
1516 
1517     if (in_master == 17)
1518       {
1519 	in_command = 1; //number
1520 	in_int = &sp_sound;
1521 	in_max = 10; //max _length
1522 	sprintf(in_default,"%d",sp_sound); //set default
1523 	blit(30,1,GFX_lpDDSBack,250,170);
1524 	Say("Sound:",260,175);
1525 	Say("This sprite will play this sound looped until it dies."
1526 	    ,10,10);
1527       }
1528 
1529     if (in_master == 18)
1530       {
1531 	in_command = 1; //number
1532 	in_int = &sp_hitpoints;
1533 	in_max = 10; //max _length
1534 	sprintf(in_default,"%d",sp_hitpoints); //set default
1535 	blit(30,1,GFX_lpDDSBack,250,170);
1536 	Say("Hitpoints:",260,175);
1537 	Say("How strong is this creature?  (0 = not alive/invincible)"
1538 	    ,10,10);
1539       }
1540 
1541     if (in_master == 19)
1542       {
1543 	in_command = 1; //number
1544 	in_int = &sp_nohit;
1545 	in_max = 10; //max _length
1546 	sprintf(in_default,"%d",sp_nohit); //set default
1547 	blit(30,1,GFX_lpDDSBack,250,170);
1548 	Say("Nohit:",260,175);
1549 	Say("Can this be punched? 0 if yes.  Either way it will"
1550 	    "still check for hit() if a script is attached."
1551 	    ,10,10);
1552       }
1553 
1554     if (in_master == 20)
1555       {
1556 	in_command = 1; //number
1557 	in_int = &sp_touch_damage;
1558 	in_max = 10; //max _length
1559 	sprintf(in_default,"%d",sp_touch_damage); //set default
1560 	blit(30,1,GFX_lpDDSBack,250,170);
1561 	Say("Touch Damage:",260,175);
1562 	Say("If not 0, the hardbox of this sprite will cause this"
1563 	    "much damage if touched."
1564 	    ,10,10);
1565       }
1566 
1567     if (in_master == 21)
1568       {
1569 	in_command = 1; //number
1570 	in_int = &sp_base_attack;
1571 	in_max = 10; //max _length
1572 	sprintf(in_default,"%d",sp_base_attack); //set default
1573 	blit(30,1,GFX_lpDDSBack,250,170);
1574 	Say("Base Attack:",260,175);
1575 	Say("If not -1, this monster can attack with this sprite base. (base + dir)"
1576 	    ,10,10);
1577       }
1578 
1579     if (in_master == 22)
1580       {
1581 	in_command = 1; //number
1582 	in_int = &sp_defense;
1583 	in_max = 10; //max _length
1584 	sprintf(in_default,"%d",sp_defense); //set default
1585 	blit(30,1,GFX_lpDDSBack,250,170);
1586 	Say("Defense:",260,175);
1587 	Say("This will be deducted from any attack."
1588 	    ,10,10);
1589       }
1590 
1591     if (in_master == INPUT_MINIMAP_LOAD)
1592       {
1593 	in_command = 2; //string
1594 	sprintf(in_default, "%s",  buf_path);
1595 	in_max = 80;
1596 	in_string = buf_path;
1597 	blit(30,1,GFX_lpDDSBack,250,170);
1598 	Say("Path:",260,175);
1599 	Say("Enter the path with trailing backslash to a dir containing"
1600 	    " another dink.dat and map.dat file to choose a replacement"
1601 	    " for this block. (or enter to choose a replacement from the"
1602 	    " current map)"
1603 	    ,10,10);
1604       }
1605 
1606     if (in_master == 31)
1607       {
1608 	in_command = 2; //string
1609 	sprintf(in_default, "%s",  pam.script);
1610 	in_max = 20;
1611 	in_string = pam.script;
1612 	blit(30,1,GFX_lpDDSBack,250,170);
1613 	Say("Script:",260,175);
1614 	Say("This script will be run before the screen is drawn.  A good place"
1615 	    "to change the vision, ect."
1616 	    ,10,10);
1617       }
1618 
1619     if (in_master == INPUT_SCREEN_VISION)
1620       {
1621 	in_command = 1; //number
1622 	in_int = &map_vision;
1623 	in_max = 10; //max _length
1624 	sprintf(in_default,"%d",map_vision); //set default
1625 	blit(30,1,GFX_lpDDSBack,250,170);
1626 	Say("Vision:",260,175);
1627 	Say("Current vision.  If not 0, any sprites you add will ONLY show up"
1628 	    " in the game if the vision level matches this one."
1629 	    ,10,10);
1630       }
1631 
1632     if (in_master == INPUT_SCREEN_MIDI)
1633       {
1634 	in_command = 1; //number
1635 	in_max = 10; //max _length
1636 	sprintf(in_default,"%d",*in_int); //set default
1637 	blit(30,1,GFX_lpDDSBack,250,170);
1638 	Say("Music # for screen?:",260,175);
1639 	Say("Will play #.MID for this screen if nothing else is playing."
1640 	    ,10,10);
1641       }
1642 
1643     if (in_master == INPUT_SCREEN_TYPE)
1644       {
1645 	in_command = 1; //number
1646 	in_max = 10; //max _length
1647 	sprintf(in_default,"%d",*in_int); //set default
1648 	blit(30,1,GFX_lpDDSBack,250,170);
1649 	Say("Screentype?:",260,175);
1650 	Say("Enter 1 for 'indoors'.  (so it won't show up on the player map)."
1651 	    ,10,10);
1652       }
1653 
1654     old_command = in_master;
1655 
1656     in_master = 0;
1657     in_onflag = /*true*/1;
1658 }
1659 
1660 
1661 //this changes all none 0 blocks in this tile to num
change_tile(int tile,int num)1662 void change_tile(int tile, int num)
1663 {
1664   int x;
1665   for (x = 0; x < 50; x++)
1666     {
1667       int y;
1668       for (y = 0; y < 50; y++)
1669 	if (hmap.htile[tile].x[x].y[y] != 0)
1670 	  hmap.htile[tile].x[x].y[y] = num;
1671     }
1672 }
1673 
1674 
1675 
copy_front_to_two(void)1676 void copy_front_to_two( void)
1677 {
1678 /*   RECT rcRect; */
1679 /*   rcRect.left = 0; */
1680 /*   rcRect.top = 0; */
1681 /*   rcRect.right = x; */
1682 /*   rcRect.bottom = y; */
1683 
1684 /*   lpDDSTwo->BltFast( 0, 0, lpDDSBack, */
1685 /* 		     &rcRect, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT); */
1686   // GFX
1687   SDL_BlitSurface(GFX_lpDDSBack, NULL, GFX_lpDDSTwo, NULL);
1688 }
1689 
1690 
1691 /* Create a 20x20 view of lpDDSTwo for use in the minimap */
shrink_screen_to_these_cords(int x1,int y1)1692 void shrink_screen_to_these_cords(int x1, int y1)
1693 {
1694 /*   RECT crapRec, Rect; */
1695 /*   DDBLTFX ddbltfx; */
1696 /*   ZeroMemory(&ddbltfx, sizeof(ddbltfx)); */
1697 /*   ddbltfx.dwSize = sizeof(ddbltfx); */
1698 
1699 /*   SetRect(&crapRec, playl, 0, playx, 400); */
1700 /*   SetRect(&Rect, x1, y1, x1+20, y1+20); */
1701 
1702 /*   lpDDSBack->Blt(&Rect, lpDDSTwo, */
1703 /* 		 &crapRec, DDBLT_DDFX | DDBLT_WAIT, &ddbltfx); */
1704 
1705   // GFX
1706   /* Generic scaling - except no transparency */
1707   {
1708     SDL_Rect src, dst;
1709     src.x = playl;
1710     src.y = 0;
1711     src.w = playx - playl;
1712     src.h = 400;
1713     dst.x = x1;
1714     dst.y = y1;
1715     dst.w = 20;
1716     dst.h = 20;
1717     gfx_blit_stretch(GFX_lpDDSTwo, &src, GFX_lpDDSBack, &dst);
1718   }
1719 }
1720 
1721 
1722 /****************************************************************************
1723  *
1724  *      UpdateCursorPosition
1725  *
1726  *      Move our private cursor in the requested direction, subject
1727  *      to clipping, scaling, and all that other stuff.
1728  *
1729  *      This does not redraw the cursor.  You need to do that yourself.
1730  *
1731  ****************************************************************************/
UpdateCursorPosition(int dx,int dy)1732 void UpdateCursorPosition(int dx, int dy)
1733 {
1734 
1735     /*
1736      *  Pick up any leftover fuzz from last time.  This is important
1737      *  when scaling down mouse motions.  Otherwise, the user can
1738      *  drag to the right extremely slow for the length of the table
1739      *  and not get anywhere.
1740      */
1741     sp_cycle = 0;
1742     spr[1].x += dx;
1743     spr[1].y += dy;
1744     /* Clip the cursor to our client area */
1745 
1746     /* Try to get the mouse (and the focus) within the window, not
1747        100% safe but good enough */
1748     SDL_WarpMouse(320, 240);
1749     /* Ignore the mouse event generated by SDL_WarpMouse: */
1750     SDL_PumpEvents();
1751     SDL_GetRelativeMouseState(NULL, NULL);
1752     /* Alternatively, we can do this all the time, even when dx and dy
1753        are zero, and the mouse will always return to the
1754        application. We'd need to avoid that when the application is
1755        backgrounded though, otherwise FreeDink will keep warping the
1756        mouse. */
1757 }
1758 
1759 
Scrawl_OnMouseInput(void)1760 void  Scrawl_OnMouseInput(void)
1761 {
1762   SDL_Event event;
1763   int dx, dy;
1764 
1765   mouse1 = /*false*/0;
1766   if (mode != 6) return;
1767 
1768   SDL_PumpEvents();
1769   SDL_GetRelativeMouseState(&dx, &dy);
1770   if (dx != 0 || dy != 0)
1771     UpdateCursorPosition(dx, dy);
1772 
1773   /* Process stacked clicks */
1774   while (SDL_PeepEvents(&event, 1, SDL_GETEVENT,
1775 			SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN)) > 0)
1776     {
1777       SDL_MouseButtonEvent *button_event = (SDL_MouseButtonEvent*)&event;
1778       if (button_event->button == SDL_BUTTON_LEFT)
1779 	mouse1 = /*true*/1;
1780     }
1781   return;
1782 
1783 
1784 /* 	BOOL fDone = 0; */
1785 
1786 /*     while (!fDone) { */
1787 
1788 /* 		DIDEVICEOBJECTDATA od; */
1789 
1790 /*         DWORD dwElements = 1; */
1791 
1792 /*         HRESULT hr = g_pMouse->GetDeviceData( */
1793 /*                              sizeof(DIDEVICEOBJECTDATA), &od, */
1794 /*                              &dwElements, 0); */
1795 
1796 /*         if (hr == DIERR_INPUTLOST) { */
1797 /*             /\* */
1798 /*              *  We had acquisition, but lost it.  Try to reacquire it. */
1799 /*              * */
1800 /*              *  WARNING!  DO NOT ATTEMPT TO REACQUIRE IF YOU GET */
1801 /*              *  DIERR_NOTACQUIRED!  Otherwise, you're extremely likely */
1802 /*              *  to get caught in an infinite loop:  The acquire will fail, */
1803 /*              *  and you'll get another DIERR_NOTACQUIRED so you'll */
1804 /*              *  try to aquire again, and that'll fail, etc. */
1805 /*              *\/ */
1806 /*         //    PostMessage(hwnd, WM_SYNCACQUIRE, 0, 0L); */
1807 /*          //   break; */
1808 
1809 /* 		Msg("Have no aquisition!!"); */
1810 /* 		g_pMouse->Acquire(); */
1811 
1812 /* 		} */
1813 
1814 /*         /\* Unable to read data or no data available *\/ */
1815 /*         if (FAILED(hr) || dwElements == 0) { */
1816 /*            // Msg("No mouse data there."); */
1817 /* 			break; */
1818 /*         } */
1819 
1820         /* Look at the element to see what happened */
1821 
1822 /*
1823         switch (od.dwOfs) {
1824 
1825         // DIMOFS_X: Mouse horizontal motion
1826         case DIMOFS_X: UpdateCursorPosition(od.dwData, 0); break;
1827 
1828 
1829         //DIMOFS_Y: Mouse vertical motion
1830         case DIMOFS_Y: UpdateCursorPosition(0, od.dwData); break;
1831 
1832 case DIDFT_BUTTON: if (od.dwData > 0) mouse1 = true; break;
1833 
1834 
1835 
1836 
1837 
1838         }
1839 */
1840 
1841 /*         if (od.dwOfs == DIMOFS_X) */
1842 /*         { */
1843 /*          // DIMOFS_X: Mouse horizontal motion */
1844 /*          UpdateCursorPosition(od.dwData, 0); */
1845 /*         } */
1846 /*         else if (od.dwOfs == DIMOFS_Y) */
1847 /*         { */
1848 /*          //DIMOFS_Y: Mouse vertical motion */
1849 /*          UpdateCursorPosition(0, od.dwData); */
1850 /*         } */
1851 /*         else if (od.dwOfs == DIDFT_BUTTON) */
1852 /*         { */
1853 /*          if (od.dwData > 0) mouse1 = true; */
1854 /*         } */
1855 
1856 /*     } */
1857 
1858 }
1859 
1860 
1861 /**
1862  * So-called "Movie2000 sprite movie maker" feature. It will dump a
1863  * series of DinkC moves that you specify using the mouse
1864  * (destination) and the numpad (direction). Check
1865  * http://www.dinknetwork.com/file/movie2000_tutorial
1866  */
write_moves(void)1867 void write_moves(void)
1868 {
1869   char crap[100];
1870   char move[100];
1871   char fname[100];
1872 
1873   strcpy(fname, sp_script);
1874   if (strlen(sp_script) <= 2)
1875     strcpy(fname, "CRAP");
1876 
1877 
1878   if (sjoy.keyjustpressed[SDLK_KP8 /* 104 */])
1879     {
1880       EditorSoundPlayEffect( SOUND_JUMP );
1881       sprintf(crap, "story/%s.c",fname);
1882       sprintf(move, "move_stop(&current_sprite, 8, %d, 1)\n", spr[1].y);
1883       add_text(move, crap);
1884     }
1885   if (sjoy.keyjustpressed[SDLK_KP4 /* 100 */])
1886     {
1887       EditorSoundPlayEffect( SOUND_JUMP );
1888       sprintf(crap, "story/%s.c",fname);
1889       sprintf(move, "move_stop(&current_sprite, 4, %d, 1)\n", spr[1].x);
1890       add_text(move, crap);
1891     }
1892   if (sjoy.keyjustpressed[SDLK_KP5 /* 101 */])
1893     {
1894       EditorSoundPlayEffect(SOUND_JUMP);
1895       sprintf(crap, "story/%s.c",fname);
1896       add_text("//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n", crap);
1897     }
1898   if (sjoy.keyjustpressed[SDLK_KP2 /* 98 */])
1899     {
1900       EditorSoundPlayEffect(SOUND_JUMP);
1901       sprintf(crap, "story/%s.c", fname);
1902       sprintf(move, "move_stop(&current_sprite, 2, %d, 1)\n", spr[1].y);
1903       add_text(move, crap);
1904     }
1905   if (sjoy.keyjustpressed[SDLK_KP6 /* 102 */])
1906     {
1907       EditorSoundPlayEffect( SOUND_JUMP );
1908       sprintf(crap, "story/%s.c",fname);
1909       sprintf(move, "move_stop(&current_sprite, 6, %d, 1)\n", spr[1].x);
1910       add_text(move, crap);
1911     }
1912   if (sjoy.keyjustpressed[SDLK_KP7 /* 103 */])
1913     {
1914       EditorSoundPlayEffect( SOUND_JUMP );
1915       sprintf(crap, "story/%s.c",fname);
1916       sprintf(move, "move_stop(&current_sprite, 7, %d, 1)\n", spr[1].x);
1917       add_text(move, crap);
1918     }
1919   if (sjoy.keyjustpressed[SDLK_KP1 /* 97 */])
1920     {
1921       EditorSoundPlayEffect( SOUND_JUMP );
1922       sprintf(crap, "story/%s.c",fname);
1923       sprintf(move, "move_stop(&current_sprite, 1, %d, 1)\n", spr[1].x);
1924       add_text(move, crap);
1925     }
1926   if (sjoy.keyjustpressed[SDLK_KP9 /* 105 */])
1927     {
1928       EditorSoundPlayEffect( SOUND_JUMP );
1929       sprintf(crap, "story/%s.c",fname);
1930       sprintf(move, "move_stop(&current_sprite, 9, %d, 1)\n", spr[1].x);
1931       add_text(move, crap);
1932     }
1933   if (sjoy.keyjustpressed[SDLK_KP3 /* 99 */])
1934     {
1935       EditorSoundPlayEffect( SOUND_JUMP );
1936       sprintf(crap, "story/%s.c",fname);
1937       sprintf(move, "move_stop(&current_sprite, 3, %d, 1)\n", spr[1].x);
1938       add_text(move, crap);
1939     }
1940 }
1941 
1942 
1943 /**
1944  * Draw hardness single tile #'tile', pixel by pixel, in white. Used
1945  * to draw the currently selected hardness tile.
1946  */
draw_hard_tile(int x1,int y1,int tile)1947 void draw_hard_tile(int x1, int y1, int tile)
1948 {
1949   SDL_Rect dst;
1950   dst.w = 1;
1951   dst.h = 1;
1952 
1953   int x = 0;
1954   for (x = 0; x < 50; x++)
1955     {
1956       int y = 0;
1957       for (y = 0; y < 50; y++)
1958 	{
1959 	  if (hmap.htile[tile].x[x].y[y] == 1)
1960 	    {
1961 	      //draw it
1962 	      dst.x = x1 + x
1963 		+ 20/* status bar length */;
1964 	      dst.y = y1 + y;
1965 	      /* TODO: not very efficient */
1966 	      SDL_FillRect(GFX_lpDDSBack, &dst,
1967 			   SDL_MapRGB(GFX_lpDDSBack->format, 255, 255, 255));
1968 	    }
1969 	}
1970     }
1971 }
1972 
1973 
1974 /**
1975  * updateFrame
1976  *
1977  * Decide what needs to be blitted next, wait for flip to complete,
1978  * then flip the buffers.
1979  */
updateFrame(void)1980 void updateFrame(void)
1981 {
1982   //    static DWORD        lastTickCount[4] = {0,0,0,0};
1983   //    static int          currentFrame[3] = {0,0,0};
1984   unsigned long thisTickCount;
1985   //  char buffer[20];
1986   rect                rcRect;
1987   rect  Rect;
1988 /*   rect rcRectSrc; */
1989 /*   rect rcRectDest; */
1990   rect box_crap,box_real;
1991 /*   POINT p; */
1992   char msg[500];
1993   char buff[200];
1994   //	DWORD               delay[4] = {0, 0, 0, 20};
1995 /*   HDC         hdc; */
1996   int in_crap2 = 0;
1997   int                 holdx;
1998   //PALETTEENTRY        pe[256];
1999 /*   HRESULT             ddrval; */
2000   int xx;
2001 /*   DDBLTFX     ddbltfx; */
2002   /*BOOL*/int cool;
2003   /*BOOL*/int bs[MAX_SPRITES_AT_ONCE];
2004 
2005   int rank[MAX_SPRITES_AT_ONCE];
2006   int highest_sprite;
2007 
2008   int jj;
2009 
2010   SDL_framerateDelay(&framerate_manager);
2011 
2012   // Decide which frame will be blitted next
2013   thisTickCount = SDL_GetTicks();
2014   strcpy(buff,"Nothing");
2015   check_joystick();
2016   Scrawl_OnMouseInput();
2017   rcRect.left = 0;
2018   rcRect.top = 0;
2019   rcRect.right = x;
2020   rcRect.bottom = y;
2021 
2022   if (draw_map_tiny != -1)
2023     {
2024 
2025     tiny_again:
2026       if (draw_map_tiny  == 769)
2027 	{
2028 	  draw_map_tiny = -1;
2029 	  while(kill_last_sprite());
2030 	  //all done
2031 	} else
2032 	{
2033 
2034 
2035 	  draw_map_tiny++;
2036 
2037 	  copy_front_to_two();
2038 
2039 
2040 	  if (map.loc[draw_map_tiny] != 0)
2041 	    {
2042 	      //a map exists here
2043 	      load_map(map.loc[draw_map_tiny]);
2044 	      //map loaded, lets display it
2045 	      draw_map();
2046 
2047 	      goto pass_flip;
2048 	    } else goto tiny_again;
2049 
2050 
2051 
2052 	}
2053 
2054     }
2055 
2056 
2057 /*   while( 1 ) */
2058 /*     { */
2059 /*       ddrval = lpDDSBack->BltFast( 0, 0, lpDDSTwo, */
2060 /* 				   &rcRect, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT); */
2061       // GFX
2062       SDL_BlitSurface(GFX_lpDDSTwo, NULL, GFX_lpDDSBack, NULL);
2063 
2064 
2065 /*       if( ddrval == DD_OK ) */
2066 /*         { */
2067 /* 	  break; */
2068 /*         } */
2069 /*       if( ddrval == DDERR_SURFACELOST ) */
2070 /*         { */
2071 /* 	  ddrval = restoreAll(); */
2072 /* 	  if( ddrval != DD_OK ) */
2073 /*             { */
2074 /* 	      return; */
2075 /*             } */
2076 /*         } */
2077 /*       if( ddrval != DDERR_WASSTILLDRAWING ) */
2078 /*         { */
2079 /* 	  return; */
2080 /*         } */
2081 
2082 /*     } */
2083 
2084  pass_flip:
2085 
2086   memset(&bs,0,sizeof(bs));
2087 
2088   int	max_s = 105;
2089 
2090   //max_sprites_at_once;
2091 
2092   /*for (int r2 = 1; r2 < max_sprites_at_once; r2++)
2093     {
2094     if (spr[r2].active) max_s = r2+1;
2095     }
2096   */
2097   int height;
2098 
2099 
2100 
2101   spr[1].que = 20000;
2102   if (mode == MODE_SCREEN_SPRITES) if (   ! ((spr[1].pseq == 10) && (spr[1].pframe == 8)) ) spr[1].que = sp_que;
2103 
2104   if (!in_enabled)
2105     {
2106       int r1;
2107     for (r1 = 1; r1 < max_s+1; r1++)
2108       {
2109 	int h1;
2110 	highest_sprite = 22024; //more than it could ever be
2111 
2112 	rank[r1] = 0;
2113 
2114 	for (h1 = 1; h1 < max_s+1; h1++)
2115 	  {
2116 	    if (spr[h1].active)
2117 	      {
2118 		if (bs[h1] == /*FALSE*/0)
2119 		  {
2120 		    //Msg( "Ok,  %d is %d", h1,(spr[h1].y + k[spr[h1].pic].yoffset) );
2121 		    if (spr[h1].que != 0) height = spr[h1].que; else height = spr[h1].y;
2122 		    if ( height < highest_sprite )
2123 		      {
2124 			highest_sprite = height;
2125 			rank[r1] = h1;
2126 		      }
2127 
2128 		  }
2129 
2130 	      }
2131 
2132 	  }
2133 	if (rank[r1] != 0)
2134 	  bs[rank[r1]] = /*TRUE*/1;
2135       }
2136     }
2137 
2138 
2139 
2140 
2141 
2142   if (!in_enabled)
2143 
2144     for (jj = 1; jj < max_s; jj++)
2145       {
2146 
2147 	int h = rank[jj];
2148 	//Msg("Studying %d.,",h);
2149 
2150 	if (spr[h].active)
2151 	  {
2152 
2153 	    //        Msg("Sprite %d is active.",h);
2154 
2155 	    int greba = 0;
2156 
2157 	    if (spr[h].brain == 1)
2158 	      {
2159 		if ((spr[h].seq == 0) || (mode == MODE_TILE_HARDNESS))
2160 		  {
2161 		    //if (mode == 7)
2162 		    if (mode == MODE_SPRITE_HARDNESS)
2163 		      {
2164 			//editing a sprite, setting hard box and depth dot.
2165 			spr[1].pseq = 1;
2166 			spr[1].pframe = 1;
2167 
2168 			if (sjoy.button[EDITOR_ACTION_ESCAPE])
2169 			  {
2170 			    //they want out
2171 			    //mode = 5;
2172 			    mode = MODE_SPRITE_PICKER;
2173 			    draw96(0);
2174 			    spr[1].x = m5x;
2175 			    spr[1].y = m5y;
2176 			    spr[1].pseq = 10;
2177 			    spr[1].pframe = 5;
2178 			    spr[1].speed = 50;
2179 			    goto sp_edit_end;
2180 
2181 			  }
2182 
2183 			if (sjoy.keyjustpressed[SDLK_TAB /* 9 */])
2184 			  {
2185 
2186 			    //they hit tab, lets toggle what mode they are in
2187 			    if (sp_mode == 0) sp_mode = 1; else if (sp_mode == 1) sp_mode = 2; else if (sp_mode == 2) sp_mode = 0;
2188 
2189 
2190 			  }
2191 			if (sjoy.charjustpressed['s' /* 83 */])
2192 			  {
2193 
2194 			    //they hit tab, lets toggle what mode they are in
2195 			    char death[150];
2196 			    char filename[10];
2197 
2198 			    sprintf(death, "SET_SPRITE_INFO %d %d %d %d %d %d %d %d\n",
2199 				    sp_seq,sp_frame, k[seq[sp_seq].frame[sp_frame]].xoffset,  k[seq[sp_seq].frame[sp_frame]].yoffset,
2200 
2201 				    k[seq[sp_seq].frame[sp_frame]].hardbox.left, k[seq[sp_seq].frame[sp_frame]].hardbox.top,
2202 				    k[seq[sp_seq].frame[sp_frame]].hardbox.right,k[seq[sp_seq].frame[sp_frame]].hardbox.bottom);
2203 
2204 			    strcpy(filename, "dink.ini");
2205 			    add_text(death,filename);
2206 			    EditorSoundPlayEffect( SOUND_JUMP );
2207 			  }
2208 
2209 
2210 			int modif = 1;
2211 			if (SDL_GetModState()&KMOD_SHIFT)
2212 			  modif += 9;
2213 
2214 
2215 			if (sp_mode == 0)
2216 			  {
2217 
2218 			    //ok, we are editing depth dot
2219 
2220 			    if (SDL_GetModState()&KMOD_CTRL)
2221 			      {
2222 				if (sjoy.keyjustpressed[SDLK_RIGHT /* 39 */])
2223 				  {
2224 				    k[seq[sp_seq].frame[sp_frame]].xoffset += modif;
2225 				    EditorSoundPlayEffect( SOUND_STOP );
2226 				  }
2227 
2228 				if (sjoy.keyjustpressed[SDLK_LEFT /* 37 */])
2229 				  {
2230 
2231 				    k[seq[sp_seq].frame[sp_frame]].xoffset -= modif;
2232 				    EditorSoundPlayEffect( SOUND_STOP );
2233 				  }
2234 				if (sjoy.keyjustpressed[SDLK_UP /* 38 */])
2235 				  {
2236 				    k[seq[sp_seq].frame[sp_frame]].yoffset -= modif;
2237 				    EditorSoundPlayEffect( SOUND_STOP );
2238 				  }
2239 
2240 				if (sjoy.keyjustpressed[SDLK_DOWN /* 40 */])
2241 				  {
2242 				    k[seq[sp_seq].frame[sp_frame]].yoffset += modif;
2243 				    EditorSoundPlayEffect( SOUND_STOP );
2244 				  }
2245 
2246 			      } else
2247 
2248 			      {
2249 				if (sjoy.right)
2250 				  {
2251 				    k[seq[sp_seq].frame[sp_frame]].xoffset +=  modif;
2252 				    EditorSoundPlayEffect( SOUND_STOP );
2253 				  }
2254 
2255 				if (sjoy.left)
2256 				  {
2257 				    k[seq[sp_seq].frame[sp_frame]].xoffset -=  modif;
2258 				    EditorSoundPlayEffect( SOUND_STOP );
2259 				  }
2260 				if (sjoy.up)
2261 				  {
2262 				    k[seq[sp_seq].frame[sp_frame]].yoffset -= modif;
2263 				    EditorSoundPlayEffect( SOUND_STOP );
2264 				  }
2265 
2266 				if (sjoy.down)
2267 				  {
2268 				    k[seq[sp_seq].frame[sp_frame]].yoffset += modif;
2269 				    EditorSoundPlayEffect( SOUND_STOP );
2270 				  }
2271 
2272 
2273 			      }
2274 
2275 			  }
2276 
2277 
2278 
2279 			if (sp_mode == 2)
2280 			  {
2281 
2282 			    //ok, we are top left hardness
2283 
2284 			    if (SDL_GetModState()&KMOD_CTRL)
2285 			      {
2286 				if (sjoy.keyjustpressed[SDLK_RIGHT /* 39 */])
2287 				  {
2288 				    k[seq[sp_seq].frame[sp_frame]].hardbox.right += modif;
2289 				    EditorSoundPlayEffect( SOUND_STOP );
2290 				  }
2291 
2292 				if (sjoy.keyjustpressed[SDLK_LEFT /* 37 */])
2293 				  {
2294 
2295 				    k[seq[sp_seq].frame[sp_frame]].hardbox.right -= modif;
2296 				    EditorSoundPlayEffect( SOUND_STOP );
2297 				  }
2298 				if (sjoy.keyjustpressed[SDLK_UP /* 38 */])
2299 				  {
2300 				    k[seq[sp_seq].frame[sp_frame]].hardbox.bottom -= modif;
2301 				    EditorSoundPlayEffect( SOUND_STOP );
2302 				  }
2303 
2304 				if (sjoy.keyjustpressed[SDLK_DOWN /* 40 */])
2305 				  {
2306 				    k[seq[sp_seq].frame[sp_frame]].hardbox.bottom += modif;
2307 				    EditorSoundPlayEffect( SOUND_STOP );
2308 				  }
2309 
2310 			      } else
2311 
2312 			      {
2313 				if (sjoy.right)
2314 				  {
2315 				    k[seq[sp_seq].frame[sp_frame]].hardbox.right +=  modif;
2316 				    EditorSoundPlayEffect( SOUND_STOP );
2317 				  }
2318 
2319 				if (sjoy.left)
2320 				  {
2321 				    k[seq[sp_seq].frame[sp_frame]].hardbox.right -=  modif;
2322 				    EditorSoundPlayEffect( SOUND_STOP );
2323 				  }
2324 				if (sjoy.up)
2325 				  {
2326 				    k[seq[sp_seq].frame[sp_frame]].hardbox.bottom -= modif;
2327 				    EditorSoundPlayEffect( SOUND_STOP );
2328 				  }
2329 
2330 				if (sjoy.down)
2331 				  {
2332 				    k[seq[sp_seq].frame[sp_frame]].hardbox.bottom += modif;
2333 				    EditorSoundPlayEffect( SOUND_STOP );
2334 				  }
2335 
2336 
2337 			      }
2338 
2339 
2340 			    if (k[seq[sp_seq].frame[sp_frame]].hardbox.right <= k[seq[sp_seq].frame[sp_frame]].hardbox.left)
2341 			      k[seq[sp_seq].frame[sp_frame]].hardbox.left = k[seq[sp_seq].frame[sp_frame]].hardbox.right -1;
2342 
2343 
2344 			    if (k[seq[sp_seq].frame[sp_frame]].hardbox.bottom <= k[seq[sp_seq].frame[sp_frame]].hardbox.top)
2345 			      k[seq[sp_seq].frame[sp_frame]].hardbox.top = k[seq[sp_seq].frame[sp_frame]].hardbox.bottom -1;
2346 
2347 
2348 			  }
2349 
2350 
2351 			if (sp_mode == 1)
2352 			  {
2353 
2354 			    //ok, we are top left hardness
2355 
2356 			    if (SDL_GetModState()&KMOD_CTRL)
2357 			      {
2358 				if (sjoy.keyjustpressed[SDLK_RIGHT /* 39 */])
2359 				  {
2360 				    k[seq[sp_seq].frame[sp_frame]].hardbox.left += modif;
2361 				    EditorSoundPlayEffect( SOUND_STOP );
2362 				  }
2363 
2364 				if (sjoy.keyjustpressed[SDLK_LEFT /* 37 */])
2365 				  {
2366 
2367 				    k[seq[sp_seq].frame[sp_frame]].hardbox.left -= modif;
2368 				    EditorSoundPlayEffect( SOUND_STOP );
2369 				  }
2370 				if (sjoy.keyjustpressed[SDLK_UP /* 38 */])
2371 				  {
2372 				    k[seq[sp_seq].frame[sp_frame]].hardbox.top -= modif;
2373 				    EditorSoundPlayEffect( SOUND_STOP );
2374 				  }
2375 
2376 				if (sjoy.keyjustpressed[SDLK_DOWN /* 40 */])
2377 				  {
2378 				    k[seq[sp_seq].frame[sp_frame]].hardbox.top += modif;
2379 				    EditorSoundPlayEffect( SOUND_STOP );
2380 				  }
2381 
2382 			      } else
2383 
2384 			      {
2385 				if (sjoy.right)
2386 				  {
2387 				    k[seq[sp_seq].frame[sp_frame]].hardbox.left +=  modif;
2388 				    EditorSoundPlayEffect( SOUND_STOP );
2389 				  }
2390 
2391 				if (sjoy.left)
2392 				  {
2393 				    k[seq[sp_seq].frame[sp_frame]].hardbox.left -=  modif;
2394 				    EditorSoundPlayEffect( SOUND_STOP );
2395 				  }
2396 				if (sjoy.up)
2397 				  {
2398 				    k[seq[sp_seq].frame[sp_frame]].hardbox.top -= modif;
2399 				    EditorSoundPlayEffect( SOUND_STOP );
2400 				  }
2401 
2402 				if (sjoy.down)
2403 				  {
2404 				    k[seq[sp_seq].frame[sp_frame]].hardbox.top += modif;
2405 				    EditorSoundPlayEffect( SOUND_STOP );
2406 				  }
2407 
2408 
2409 			      }
2410 
2411 
2412 			    if (k[seq[sp_seq].frame[sp_frame]].hardbox.left >= k[seq[sp_seq].frame[sp_frame]].hardbox.right)
2413 			      k[seq[sp_seq].frame[sp_frame]].hardbox.right = k[seq[sp_seq].frame[sp_frame]].hardbox.left +1;
2414 
2415 
2416 			    if (k[seq[sp_seq].frame[sp_frame]].hardbox.top >= k[seq[sp_seq].frame[sp_frame]].hardbox.bottom)
2417 			      k[seq[sp_seq].frame[sp_frame]].hardbox.bottom = k[seq[sp_seq].frame[sp_frame]].hardbox.bottom +1;
2418 
2419 
2420 
2421 
2422 			  }
2423 
2424 
2425 
2426 
2427 			if (k[seq[sp_seq].frame[sp_frame]].hardbox.top > 200 ) k[seq[sp_seq].frame[sp_frame]].hardbox.top = 200;
2428 			if (k[seq[sp_seq].frame[sp_frame]].hardbox.top <-200 ) k[seq[sp_seq].frame[sp_frame]].hardbox.top = -200;
2429 
2430 			if (k[seq[sp_seq].frame[sp_frame]].hardbox.left > 316) k[seq[sp_seq].frame[sp_frame]].hardbox.left = 316;
2431 			if (k[seq[sp_seq].frame[sp_frame]].hardbox.left < -320) k[seq[sp_seq].frame[sp_frame]].hardbox.left = -320;
2432 
2433 
2434 			if (k[seq[sp_seq].frame[sp_frame]].hardbox.bottom > 200) k[seq[sp_seq].frame[sp_frame]].hardbox.bottom = 200;
2435 			if (k[seq[sp_seq].frame[sp_frame]].hardbox.bottom <-200 ) k[seq[sp_seq].frame[sp_frame]].hardbox.bottom = -200;
2436 
2437 			if (k[seq[sp_seq].frame[sp_frame]].hardbox.right > 316) k[seq[sp_seq].frame[sp_frame]].hardbox.right = 316;
2438 			if (k[seq[sp_seq].frame[sp_frame]].hardbox.right < -320) k[seq[sp_seq].frame[sp_frame]].hardbox.right = -320;
2439 
2440 
2441 
2442 			goto b1end;
2443 
2444 		      }
2445 
2446 
2447 		    if (mode == MODE_SCREEN_SPRITES)
2448 		      {
2449 			// place sprite
2450 			if ( (sjoy.charjustpressed['v']) )
2451 			  {
2452 			    in_master = INPUT_SCREEN_VISION; // Set screen vision?
2453 			  }
2454 
2455 			int modif = 0;
2456 			if (SDL_GetModState()&KMOD_SHIFT)
2457 			  modif = 9;
2458 
2459 			if (sjoy.charjustpressed['m'])
2460 			  {
2461 			    if (sp_screenmatch)
2462 			      sp_screenmatch = /*false*/0;
2463 			    else
2464 			      sp_screenmatch = /*true*/1;
2465 			  }
2466 
2467 
2468 			if (SDL_GetModState()&KMOD_ALT) // alt
2469 			  {
2470 			    //alt is held down 87
2471 			    if (sjoy.charjustpressed['w' /* 87 */])
2472 			      {
2473 				//pressed W
2474 				if (((spr[1].pseq == 10) && (spr[1].pframe == 8)))
2475 				  {
2476                                     //a sprite is not chosen
2477 				    hold_warp_map = cur_map;
2478 				    hold_warp_x = spr[1].x;
2479 				    hold_warp_y= spr[1].y;
2480 				    EditorSoundPlayEffect(SOUND_JUMP);
2481 				  }
2482 				else
2483 				  {
2484 				    sp_warp_map = hold_warp_map ;
2485 				    sp_warp_x = hold_warp_x;
2486 				    sp_warp_y = hold_warp_y;
2487 				    EditorSoundPlayEffect(SOUND_JUMP);
2488 				  }
2489 			      }
2490 			  }
2491 
2492 			/**
2493 			 * Edit sprite properties
2494 			 */
2495 			if (!((spr[1].pseq == 10) && (spr[1].pframe == 8)))
2496 			  {
2497 			    //they are wheeling around a sprite
2498 			    if (spr[1].x > 1500) spr[1].x = 1500;
2499 			    if (spr[1].y > 1500) spr[1].y = 1500;
2500 
2501 			    if (spr[1].size > 1500) spr[1].size = 1500;
2502 
2503 			    /* if (GetKeyboard(VK_OEM_4 /\* 219 *\/)) // '[' for US */
2504 			    if (getcharstate('['))
2505 			      spr[1].size -= 1+modif;
2506 			    /* if (GetKeyboard(VK_OEM_6 /\* 221 *\/)) // ']' for US */
2507 			    if (getcharstate(']'))
2508 			      spr[1].size += 1+modif;
2509 
2510 
2511 			    if (SDL_GetModState()&KMOD_SHIFT)
2512 			      {
2513 				//shift is being held down
2514 				if (getkeystate('1') || getkeystate(SDLK_KP1) || getkeystate(SDLK_F1))  in_master = 11;
2515 				if (getkeystate('2') || getkeystate(SDLK_KP2) || getkeystate(SDLK_F2))  in_master = 12;
2516 				if (getkeystate('3') || getkeystate(SDLK_KP3) || getkeystate(SDLK_F3))  in_master = 13;
2517 				if (getkeystate('4') || getkeystate(SDLK_KP4) || getkeystate(SDLK_F4))  in_master = 14;
2518 				if (getkeystate('5') || getkeystate(SDLK_KP5) || getkeystate(SDLK_F5))  in_master = 15;
2519 
2520 				if (getkeystate('6') || getkeystate(SDLK_KP6) || getkeystate(SDLK_F6))  in_master = 16;
2521 				if (getkeystate('7') || getkeystate(SDLK_KP7) || getkeystate(SDLK_F7))  in_master = 17;
2522 				if (getkeystate('8') || getkeystate(SDLK_KP8) || getkeystate(SDLK_F8))  in_master = 18;
2523 				if (getkeystate('9') || getkeystate(SDLK_KP9) || getkeystate(SDLK_F9))  in_master = 19;
2524 
2525 
2526 
2527 			      }
2528 			    else if (SDL_GetModState()&KMOD_ALT)
2529 			      {
2530 				  //alt is being held down
2531 				  if (getkeystate('1') || getkeystate(SDLK_KP1) || getkeystate(SDLK_F1))  in_master = 20;
2532 				  if (getkeystate('2') || getkeystate(SDLK_KP2) || getkeystate(SDLK_F2))  in_master = 21;
2533 				  if (getkeystate('3') || getkeystate(SDLK_KP3) || getkeystate(SDLK_F3))  in_master = 22;
2534 				  /*(getkeystate('4' /\* 52 *\/))  in_master = 14;
2535 				    if (getkeystate(53))  in_master = 15;
2536 
2537 				    if (getkeystate(54))  in_master = 16;
2538 				    if (getkeystate(55))  in_master = 17;
2539 				    if (getkeystate(56))  in_master = 18;
2540 				    if (getkeystate(57))  in_master = 19;
2541 
2542 				  */
2543 			      }
2544 			    else
2545 			      {
2546 				  //shift is not being held down
2547 				  if (getkeystate('1') || getkeystate(SDLK_KP1) || getkeystate(SDLK_F1)) in_master = 1;
2548 				  if (getkeystate('2') || getkeystate(SDLK_KP2) || getkeystate(SDLK_F2)) in_master = 2;
2549 				  if (getkeystate('3') || getkeystate(SDLK_KP3) || getkeystate(SDLK_F3)) in_master = 3;
2550 				  if (getkeystate('4') || getkeystate(SDLK_KP4) || getkeystate(SDLK_F4)) in_master = 4;
2551 				  if (getkeystate('5') || getkeystate(SDLK_KP5) || getkeystate(SDLK_F5)) in_master = 5;
2552 				  if (getkeystate('6') || getkeystate(SDLK_KP6) || getkeystate(SDLK_F6)) in_master = 6;
2553 				  if (getkeystate('7') || getkeystate(SDLK_KP7) || getkeystate(SDLK_F7)) in_master = 7;
2554 				  if (getkeystate('8') || getkeystate(SDLK_KP8) || getkeystate(SDLK_F8)) in_master = 8;
2555 				  if (getkeystate('9') || getkeystate(SDLK_KP9) || getkeystate(SDLK_F9)) in_master = 9;
2556 				  if (getkeystate('0') || getkeystate(SDLK_KP0) || getkeystate(SDLK_F10)) in_master = 10;
2557 			      }
2558 
2559 
2560 			    if (sjoy.charjustpressed['s' /* 83 */])
2561 			      {
2562 				smart_add();
2563 
2564 				draw_map();
2565 			      }
2566 
2567 			    if ( (sjoy.button[EDITOR_ACTION_RETURN]) | (mouse1) )
2568 			      {
2569 				smart_add();
2570 				draw_map();
2571 				spr[1].pseq = 10;
2572 				spr[1].pframe = 8;
2573 				spr[1].size = 100;
2574 				rect_set(&spr[1].alt,0,0,0,0);
2575 
2576 			      }
2577 
2578 			    if (sjoy.keyjustpressed[SDLK_DELETE /* 46 */])
2579 			      {
2580 
2581 				spr[1].pseq = 10;
2582 				spr[1].pframe = 8;
2583 				spr[1].size = 100;
2584 				rect_set(&spr[1].alt,0,0,0,0);
2585 
2586 			      }
2587 
2588 			  }
2589 			else
2590 			  {
2591 			    //no sprite is currently selected
2592 
2593 			    int max_spr = 0;
2594 			    int jj;
2595 
2596 			    write_moves();
2597 
2598 
2599 
2600 			    for (jj=1; jj < 100; jj++)
2601 			      {
2602 				if ( pam.sprite[jj].active) if (pam.sprite[jj].vision == map_vision) max_spr++;
2603 			      }
2604 
2605 
2606 			    if (max_spr > 0)
2607 			      {
2608 
2609 				/* if (sjoy.keyjustpressed[VK_OEM_4 /\* 219 *\/]) // '[' for US */
2610 				if (sjoy.charjustpressed['['])
2611 				  {
2612 				    sp_cycle--;
2613 				    if (sp_cycle < 1)
2614 				      sp_cycle = max_spr;
2615 				  }
2616 
2617 				/* if (sjoy.keyjustpressed[VK_OEM_6 /\* 221 *\/]) // ']' for US */
2618 				if (sjoy.charjustpressed[']'])
2619 				  {
2620 				    sp_cycle++;
2621 				    if (sp_cycle > max_spr)
2622 				      sp_cycle = 1;
2623 				  }
2624 
2625 
2626 
2627 			      }
2628 
2629 
2630 
2631 			    //Msg("Cycle is %d", sp_cycle);
2632 			    int realpic = 0;
2633 
2634 			    if (sp_cycle > 0)
2635 			      {
2636 				//lets draw a frame around the sprite we want
2637 				int dumbpic = 0;
2638 				int jh;
2639 				realpic = 0;
2640 				for (jh = 1; dumbpic != sp_cycle; jh++)
2641 				  {
2642 				    if (pam.sprite[jh].active)  if ( pam.sprite[jh].vision == map_vision)
2643 								  {
2644 								    dumbpic++;
2645 								    realpic = jh;
2646 								  }
2647 				    if (jh == 99) goto fail;
2648 
2649 				  }
2650 
2651 				last_sprite_added = realpic;
2652 
2653 
2654 /* 				ddbltfx.dwSize = sizeof(ddbltfx); */
2655 /* 				ddbltfx.dwFillColor = 235; */
2656 
2657 				int	sprite = add_sprite_dumb(pam.sprite[realpic].x,pam.sprite[realpic].y,0,
2658 								 pam.sprite[realpic].seq, pam.sprite[realpic].frame,
2659 								 pam.sprite[realpic].size);
2660 				rect_copy(&spr[sprite].alt , &pam.sprite[realpic].alt);
2661 				get_box(sprite, &box_crap, &box_real);
2662 
2663 
2664 
2665 
2666 				get_box(sprite, &box_crap, &box_real);
2667 				box_crap.bottom = box_crap.top + 5;
2668 /* 				ddrval = lpDDSBack->Blt(&box_crap ,NULL,NULL, DDBLT_COLORFILL| DDBLT_WAIT, &ddbltfx); */
2669 				// GFX
2670 				{
2671 				  SDL_Rect dst;
2672 				  dst.x = box_crap.left;
2673 				  dst.y = box_crap.top;
2674 				  dst.w = box_crap.right - box_crap.left;
2675 				  dst.h = 5;
2676 				  SDL_FillRect(GFX_lpDDSBack, &dst, SDL_MapRGB(GFX_lpDDSTwo->format, 33, 41, 16));
2677 				}
2678 
2679 				get_box(sprite, &box_crap, &box_real);
2680 				box_crap.right = box_crap.left + 5;
2681 /* 				ddrval = lpDDSBack->Blt(&box_crap ,NULL,NULL, DDBLT_COLORFILL| DDBLT_WAIT, &ddbltfx); */
2682 				// GFX
2683 				{
2684 				  SDL_Rect dst;
2685 				  dst.x = box_crap.left;
2686 				  dst.y = box_crap.top;
2687 				  dst.w = 5;
2688 				  dst.h = box_crap.bottom - box_crap.top;
2689 				  SDL_FillRect(GFX_lpDDSBack, &dst, SDL_MapRGB(GFX_lpDDSTwo->format, 33, 41, 16));
2690 				}
2691 
2692 				get_box(sprite, &box_crap, &box_real);
2693 				box_crap.left = box_crap.right - 5;
2694 /* 				ddrval = lpDDSBack->Blt(&box_crap ,NULL,NULL, DDBLT_COLORFILL| DDBLT_WAIT, &ddbltfx); */
2695 				// GFX
2696 				{
2697 				  SDL_Rect dst;
2698 				  dst.x = box_crap.right - 5;
2699 				  dst.y = box_crap.top;
2700 				  dst.w = 5;
2701 				  dst.h = box_crap.bottom - box_crap.top;
2702 				  SDL_FillRect(GFX_lpDDSBack, &dst, SDL_MapRGB(GFX_lpDDSTwo->format, 33, 41, 16));
2703 				}
2704 
2705 				get_box(sprite, &box_crap, &box_real);
2706 				box_crap.top = box_crap.bottom - 5;
2707 /* 				ddrval = lpDDSBack->Blt(&box_crap ,NULL,NULL, DDBLT_COLORFILL| DDBLT_WAIT, &ddbltfx); */
2708 				// GFX
2709 				{
2710 				  SDL_Rect dst;
2711 				  dst.x = box_crap.left;
2712 				  dst.y = box_crap.bottom - 5;
2713 				  dst.w = box_crap.right - box_crap.left;
2714 				  dst.h = 5;
2715 				  SDL_FillRect(GFX_lpDDSBack, &dst, SDL_MapRGB(GFX_lpDDSTwo->format, 33, 41, 16));
2716 				}
2717 
2718 				//	if (ddrval != DD_OK) dderror(ddrval);
2719 
2720 				spr[sprite].active = /*false*/0;
2721 
2722 			      }
2723 
2724 			  fail:
2725 
2726 
2727 			    if ( (sjoy.button[EDITOR_ACTION_RETURN]) | (mouse1))
2728 			      {
2729 				//pick up a sprite already placed by hitting enter
2730 				int uu;
2731 
2732 				for (uu = 100; uu > 0; uu--)
2733 				  {
2734 				    if ( pam.sprite[uu].active) if ( ( pam.sprite[uu].vision == 0) || (pam.sprite[uu].vision == map_vision))
2735 								  {
2736 
2737 								    int	sprite = add_sprite_dumb(pam.sprite[uu].x,pam.sprite[uu].y,0,
2738 												 pam.sprite[uu].seq, pam.sprite[uu].frame,
2739 												 pam.sprite[uu].size);
2740 								    rect_copy(&spr[sprite].alt , &pam.sprite[uu].alt);
2741 								    get_box(sprite, &box_crap, &box_real);
2742 								    if (realpic > 0) goto spwarp;
2743 								    //Msg("Got sprite %d's info. X%d Y %d.",uu,box_crap.left,box_crap.right);
2744 
2745 								    if (inside_box(spr[1].x,spr[1].y,box_crap))
2746 
2747 								      {
2748 									//this is the sprite they want to edit, lets convert them into it
2749 									//						Msg("FOUND SPRITE!  It's %d, huh.",uu);
2750 
2751 									if ( 4 > 9)
2752 									  {
2753 									  spwarp:
2754 									    log_debug("Ah yeah, using %d!", realpic);
2755 									    uu = realpic;
2756 									  }
2757 
2758 
2759 									spr[1].x = pam.sprite[uu].x;
2760 									spr[1].y = pam.sprite[uu].y;
2761 									spr[1].size = pam.sprite[uu].size;
2762 									sp_type = pam.sprite[uu].type;
2763 									sp_brain = pam.sprite[uu].brain;
2764 									sp_speed = pam.sprite[uu].speed;
2765 									sp_base_walk = pam.sprite[uu].base_walk;
2766 									sp_base_idle = pam.sprite[uu].base_idle;
2767 									sp_base_attack = pam.sprite[uu].base_attack;
2768 									sp_base_hit = pam.sprite[uu].base_hit;
2769 									sp_timer = pam.sprite[uu].timer;
2770 									sp_que = pam.sprite[uu].que;
2771 									sp_seq = pam.sprite[uu].seq;
2772 									sp_hard = pam.sprite[uu].hard;
2773 									rect_copy(&spr[1].alt , &pam.sprite[uu].alt);
2774 									sp_frame = pam.sprite[uu].frame;
2775 									spr[1].pseq = pam.sprite[uu].seq;
2776 									spr[1].pframe = pam.sprite[uu].frame;
2777 
2778 									sp_is_warp = pam.sprite[uu].is_warp;
2779 
2780 									sp_warp_map = pam.sprite[uu].warp_map;
2781 									sp_warp_x = pam.sprite[uu].warp_x;
2782 									sp_warp_y = pam.sprite[uu].warp_y;
2783 									sp_parm_seq = pam.sprite[uu].parm_seq;
2784 									strcpy(sp_script, pam.sprite[uu].script);
2785 
2786 									sp_base_die = pam.sprite[uu].base_die;
2787 									sp_gold = pam.sprite[uu].gold;
2788 									sp_hitpoints = pam.sprite[uu].hitpoints;
2789 
2790 									sp_exp = pam.sprite[uu].exp;
2791 									sp_nohit = pam.sprite[uu].nohit;
2792 									sp_touch_damage = pam.sprite[uu].touch_damage;
2793 									sp_defense = pam.sprite[uu].defense;
2794 									sp_strength = pam.sprite[uu].strength;
2795 									sp_sound = pam.sprite[uu].sound;
2796 
2797 									pam.sprite[uu].active = /*false*/0; //erase sprite
2798 									draw_map();
2799 									spr[sprite].active = /*false*/0;
2800 									break;
2801 								      }
2802 								    spr[sprite].active = /*false*/0;
2803 
2804 								  }
2805 				  }
2806 
2807 
2808 			      }
2809 
2810 
2811 			    if ((SDL_GetModState()&KMOD_ALT) && (getkeystate(SDLK_DELETE /* 46 */)))
2812 			      {
2813 				int ll;
2814 				for (ll = 1; ll < 100; ll++)
2815 				  {
2816 				    pam.sprite[ll].active = /*false*/0;
2817 				  }
2818 				draw_map();
2819 				rect_set(&spr[h].alt,0,0,0,0);
2820 			      }
2821 			  }
2822 
2823 			/** Trim a sprite **/
2824 			if (getcharstate('z') || (getcharstate('x')))
2825 			  {
2826 			    if ((spr[h].alt.right == 0) && (spr[h].alt.left == 0)
2827 				&& (spr[h].alt.top == 0) && (spr[h].alt.bottom == 0))
2828 			      rect_copy(&spr[h].alt, &k[getpic(h)].box);
2829 			  }
2830 
2831                         if (getcharstate('z'))
2832 			  {
2833 
2834 			    if (sjoy.keyjustpressed[SDLK_RIGHT /* 39 */])
2835 			      {
2836 				spr[h].alt.left += spr[h].speed + modif;
2837 				EditorSoundPlayEffect( SOUND_STOP );
2838 			      }
2839 
2840 			    if (sjoy.keyjustpressed[SDLK_LEFT /* 37 */])
2841 			      {
2842 				spr[h].alt.left -= spr[h].speed +modif;
2843 				EditorSoundPlayEffect( SOUND_STOP );
2844 			      }
2845 			    if (sjoy.keyjustpressed[SDLK_DOWN /* 40 */])
2846 			      {
2847 				spr[h].alt.top += spr[h].speed + modif;
2848 				EditorSoundPlayEffect( SOUND_STOP );
2849 			      }
2850 
2851 			    if (sjoy.keyjustpressed[SDLK_UP /* 38 */])
2852 			      {
2853 				spr[h].alt.top -= spr[h].speed + modif;
2854 				EditorSoundPlayEffect( SOUND_STOP );
2855 			      }
2856 
2857 
2858 			    if (spr[h].alt.top < 0) spr[h].alt.top = 0;
2859 			    if (spr[h].alt.left < 0) spr[h].alt.left = 0;
2860 			    goto b1end;
2861 			  }
2862 
2863 
2864 
2865 			if (getcharstate('x'))
2866 			  {
2867 
2868 			    if (sjoy.keyjustpressed[SDLK_RIGHT /* 39 */])
2869 			      {
2870 				spr[h].alt.right += spr[h].speed + modif;
2871 				EditorSoundPlayEffect( SOUND_STOP );
2872 			      }
2873 
2874 			    if (sjoy.keyjustpressed[SDLK_LEFT /* 37 */])
2875 			      {
2876 
2877 				spr[h].alt.right -= spr[h].speed +modif;
2878 				EditorSoundPlayEffect( SOUND_STOP );
2879 			      }
2880 			    if (sjoy.keyjustpressed[SDLK_DOWN /* 40 */])
2881 			      {
2882 				spr[h].alt.bottom += spr[h].speed + modif;
2883 				EditorSoundPlayEffect( SOUND_STOP );
2884 			      }
2885 
2886 			    if (sjoy.keyjustpressed[SDLK_UP /* 38 */])
2887 			      {
2888 				spr[h].alt.bottom -= spr[h].speed + modif;
2889 				EditorSoundPlayEffect( SOUND_STOP );
2890 
2891 				//	Msg("Bottom is %d..",spr[h].alt.bottom);
2892 
2893 			      }
2894 			    if (spr[h].alt.bottom > k[getpic(h)].box.bottom) spr[h].alt.bottom = k[getpic(h)].box.bottom;
2895 			    if (spr[h].alt.right > k[getpic(h)].box.right) spr[h].alt.right = k[getpic(h)].box.right;
2896 
2897 			    goto b1end;
2898 
2899 			  }
2900 
2901 
2902 			if (spr[1].size < 1)
2903 			  spr[1].size = 1;
2904 
2905 			/* Precise positionning: move the sprite just
2906 			   1 pixel left/right/up/down, then don't do
2907 			   move until an arrow key is released and
2908 			   pressed again. */
2909 			if (SDL_GetModState()&KMOD_CTRL)
2910 			  {
2911 			    if (sjoy.keyjustpressed[SDLK_RIGHT /* 39 */])
2912 			      {
2913 
2914 				sp_cycle = 0;
2915 
2916 				spr[h].x += spr[h].speed + modif;
2917 				EditorSoundPlayEffect( SOUND_STOP );
2918 			      }
2919 
2920 			    if (sjoy.keyjustpressed[SDLK_LEFT /* 37 */])
2921 			      {
2922 				spr[h].x -= spr[h].speed +modif;
2923 				EditorSoundPlayEffect( SOUND_STOP );
2924 				sp_cycle = 0;
2925 			      }
2926 			    if (sjoy.keyjustpressed[SDLK_UP /* 38 */])
2927 			      {
2928 				spr[h].y -= spr[h].speed + modif;
2929 				EditorSoundPlayEffect( SOUND_STOP );
2930 				sp_cycle = 0;
2931 			      }
2932 
2933 			    if (sjoy.keyjustpressed[SDLK_DOWN /* 40 */])
2934 			      {
2935 				spr[h].y += spr[h].speed + modif;
2936 				EditorSoundPlayEffect( SOUND_STOP );
2937 				sp_cycle = 0;
2938 			      }
2939 
2940 			  }
2941 			else
2942 			  {
2943 			    if (sjoy.right)
2944 			      {
2945 				spr[h].x += spr[h].speed + modif;
2946 				EditorSoundPlayEffect( SOUND_STOP );
2947 				sp_cycle = 0;
2948 			      }
2949 
2950 			    if (sjoy.left)
2951 			      {
2952 				spr[h].x -= spr[h].speed +modif;
2953 				EditorSoundPlayEffect( SOUND_STOP );
2954 				sp_cycle = 0;
2955 			      }
2956 			    if (sjoy.up)
2957 			      {
2958 				spr[h].y -= spr[h].speed + modif;
2959 				EditorSoundPlayEffect( SOUND_STOP );
2960 				sp_cycle = 0;
2961 			      }
2962 
2963 			    if (sjoy.down)
2964 			      {
2965 				spr[h].y += spr[h].speed + modif;
2966 				EditorSoundPlayEffect( SOUND_STOP );
2967 				sp_cycle = 0;
2968 
2969 			      }
2970 
2971 
2972 			  }
2973 
2974 
2975 
2976 
2977 
2978 			if (  (sjoy.button[EDITOR_ACTION_ESCAPE]) )
2979 			  {
2980 			    //return to edit mode or drop sprite, depending..
2981 			    if (((spr[1].pseq == 10) && (spr[1].pframe == 8))  )
2982 
2983 			      {
2984 
2985 				rect_set(&spr[1].alt,0,0,0,0);
2986 
2987 				spr[1].size = 100;
2988 				mode = MODE_SCREEN_TILES;
2989 				spr[1].x = m4x;
2990 				spr[1].y = m4y;
2991 				spr[1].seq = 3;
2992 				spr[1].speed = 50;
2993 			      } else
2994 			      {
2995 				smart_add();
2996 				draw_map();
2997 				rect_set(&spr[1].alt,0,0,0,0);
2998 
2999 				spr[1].pseq = 10;
3000 				spr[1].pframe = 8;
3001 				spr[1].size = 100;
3002 
3003 			      }
3004 			  }
3005 
3006 
3007 			if (sjoy.charjustpressed['e'])
3008 			  {
3009 			    //they hit E, go to sprite picker
3010 			    rect_set(&spr[1].alt,0,0,0,0);
3011 
3012 			    spr[1].size = 100;
3013 			    //mode = 5;
3014 			    mode = MODE_SPRITE_PICKER;
3015 			    m6x = spr[h].x;
3016 			    m6y = spr[h].y;
3017 			    spr[h].x = m5x;
3018 			    spr[h].y = m5y;
3019 
3020 			    spr[1].seq = 3;
3021 			    spr[1].speed = 50;
3022 			    if (sp_seq == 0) draw15(sp_picker); else draw96(sp_frame);
3023 			    goto sp_edit_end;
3024 
3025 			  }
3026 			if (sjoy.button[EDITOR_ACTION_TAB])
3027 			  {
3028 			    //they hit tab, return to tile edit mode
3029 			    if (    !((spr[1].pseq == 10) && (spr[1].pframe == 8))  )
3030 
3031 			      {
3032 				smart_add();
3033 				rect_set(&spr[1].alt,0,0,0,0);
3034 
3035 				draw_map();
3036 			      }
3037 			    spr[1].size = 100;
3038 			    mode = MODE_SCREEN_TILES;
3039 			    spr[h].x = m4x;
3040 			    spr[h].y = m4y;
3041 
3042 			    spr[1].seq = 3;
3043 			    spr[1].speed = 50;
3044 			    //	if (sp_seq == 0) draw15(); else draw96();
3045 			    goto sp_edit_end;
3046 
3047 			  }
3048 
3049 
3050 			goto b1end;
3051 
3052 		      }
3053 
3054 
3055 		    if ( (mode == MODE_SCREEN_TILES)
3056 			 && (sjoy.button[EDITOR_ACTION_TAB]))
3057 		      {
3058 
3059 			//they chose sprite picker mode
3060 			//while (kill_last_sprite());
3061 
3062 
3063 			mode = MODE_SCREEN_SPRITES;
3064 
3065 			spr[1].pseq = 10;
3066 			spr[1].pframe = 8;
3067 
3068 			spr[1].speed = 1;
3069 			selx = 1;
3070 			sely = 1;
3071 			m4x = spr[h].x;
3072 			m4y = spr[h].y;
3073 			//spr[h].x = m5x;
3074 			//spr[h].y = m5y;
3075 
3076 			//if (sp_seq == 0)
3077 			//	draw15(); else draw96();
3078 
3079 		      } else
3080 
3081 
3082 
3083 
3084 
3085 
3086 		      if (mode == MODE_SPRITE_PICKER)
3087 			{
3088 			  //picking a sprite
3089 			  if (sp_seq != 0)
3090 			    {
3091 			      //they are in select sprite phase 2
3092 
3093 			      if (sjoy.charjustpressed['e'])
3094 				{
3095 				  //they want to 'edit' the sprite
3096 				  mode = MODE_SPRITE_HARDNESS;
3097 				  m5x = spr[h].x;
3098 				  m5y = spr[h].y;
3099 
3100 				  //lets blank the screen
3101 /* 				  ZeroMemory(&ddbltfx, sizeof(ddbltfx)); */
3102 /* 				  ddbltfx.dwSize = sizeof( ddbltfx); */
3103 /* 				  ddbltfx.dwFillColor = 255; */
3104 /* 				  crap = lpDDSTwo->Blt(NULL ,NULL,NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); */
3105 				  // GFX
3106 				  SDL_FillRect(GFX_lpDDSTwo, NULL, SDL_MapRGB(GFX_lpDDSTwo->format, 255, 255, 255));
3107 
3108 				  holdx = (spr[1].x / 50);
3109 				  int holdy = (spr[1].y / 50)+1;
3110 				  holdx = holdx * 8;
3111 				  if (seq[sp_seq].frame[holdx + holdy] == 0) goto sp_fin;
3112 
3113 				  add_sprite_dumb(320,200 , 0,sp_seq,holdx + holdy,100 );
3114 
3115 				  sp_frame = holdx + holdy;
3116 				  spr[1].pseq = 10;
3117 				  spr[1].pframe = 8;
3118 
3119 
3120 				  spr[1].speed = 1;
3121 				  goto sp_edit_end;
3122 
3123 				}
3124 
3125 			      if ((sjoy.button[EDITOR_ACTION_ESCAPE]))
3126 				{
3127 
3128 
3129 				  //returning to main sprite picker mode
3130 				  sp_seq = 0;
3131 
3132 				  draw15(sp_picker);
3133 				  spr[h].x = m5ax;
3134 				  spr[h].y = m5ay;
3135 
3136 				  goto sp_edit_end;
3137 				}
3138 
3139 			      if (sjoy.button[EDITOR_ACTION_TAB])
3140 				{
3141 				  //leave to screen editor
3142 				sp_fin:
3143 				  m5x = spr[h].x;
3144 				  m5y = spr[h].y;
3145 
3146 				  draw_map();
3147 				  spr[h].x = m6x;
3148 				  spr[h].y = m6y;
3149 
3150 				  spr[1].pseq = 10;
3151 				  spr[1].pframe = 8;
3152 
3153 				  spr[h].speed = 1;
3154 				  mode = MODE_SCREEN_SPRITES;
3155 				  goto sp_edit_end;
3156 
3157 				}
3158 
3159 			      if (sjoy.button[EDITOR_ACTION_RETURN])
3160 				{
3161 
3162 				  // go to mode 6, sprite placement
3163 				  m5x = spr[h].x;
3164 				  m5y = spr[h].y;
3165 
3166 
3167 				  holdx = (spr[1].x / 50);
3168 				  int holdy = (spr[1].y / 50)+1;
3169 				  holdx = holdx * 8;
3170 				  if (seq[sp_seq].frame[holdx + holdy] == 0) goto sp_fin;
3171 				  spr[1].pseq = sp_seq;
3172 				  spr[1].pframe = holdx + holdy;
3173 				  sp_frame = holdx + holdy;
3174 				  draw_map();
3175 				  spr[h].x = m6x;
3176 				  spr[h].y = m6y;
3177 				  mode = MODE_SCREEN_SPRITES;
3178 				  spr[h].speed = 1;
3179 				  goto sp_edit_end;
3180 
3181 				}
3182 
3183 
3184 			      goto sp_edit_end;
3185 			    }
3186 
3187 
3188 			  if (sjoy.button[EDITOR_ACTION_TAB] || sjoy.button[EDITOR_ACTION_ESCAPE])
3189 			    {
3190 
3191 			      //exit to main editor
3192 			      /*m5x = spr[h].x;
3193 				m5y = spr[h].y;
3194 				draw_map();
3195 				spr[h].x = m4x;
3196 				spr[h].y = m4y;
3197 				mode = 3;
3198 				goto b1end;
3199 			      */
3200 			      m5x = spr[h].x;
3201 			      m5y = spr[h].y;
3202 
3203 			      draw_map();
3204 			      spr[h].x = m6x;
3205 			      spr[h].y = m6y;
3206 			      spr[h].pseq = 10;
3207 			      spr[h].pframe = 8;
3208 
3209 			      spr[h].speed = 1;
3210 			      mode = MODE_SCREEN_SPRITES;
3211 			      goto b1end;
3212 			      //goto sp_edit_end;
3213 
3214 			    }
3215 
3216 			  /* if (sjoy.keyjustpressed[VK_OEM_4 /\* 219 *\/]) // '[' for US */
3217 			  if (sjoy.charjustpressed['['])
3218 			    {
3219 			      if (sp_picker > 95) sp_picker -= 96; else
3220 				{
3221 				  sp_picker = (4 * 96);
3222 				}
3223 			      draw15(sp_picker);
3224 			    }
3225 			    /* if (sjoy.keyjustpressed[VK_OEM_6 /\* 221 *\/]) // ']' for US */
3226 			  if (sjoy.charjustpressed[']'])
3227 			    {
3228 			      if (sp_picker < 400) sp_picker += 96;
3229 			      draw15(sp_picker);
3230 			    }
3231 
3232 			  if (sjoy.button[EDITOR_ACTION_RETURN])
3233 			    {
3234 
3235 			      //they chose a catagory, switch to phase 2, it will know cuz sp_seq > 0.
3236 			      holdx = (spr[1].x / 50);
3237 			      int holdy = (spr[1].y / 50)+1;
3238 			      holdx = holdx * 8;
3239 			      m5ax = spr[1].x;
3240 			      m5ay = spr[1].y;
3241 			      spr[1].x = 0;
3242 			      spr[1].y = 0;
3243 			      sp_seq = sp_get(sp_picker+ (holdx + holdy));
3244 			      //	Msg("Sp_seq is %d",sp_seq);
3245 			      draw96(0);
3246 
3247 			    }
3248 
3249 
3250 			}
3251 		  sp_edit_end:
3252 
3253 
3254 
3255 
3256 		    if (mode == MODE_SCREEN_TILES) draw_current();
3257 
3258 
3259 		    if (mode == MODE_DIALOG)
3260 		      {
3261 
3262 			spr[h].seq = 2;
3263 			spr[h].seq_orig = 2;
3264 			draw_minimap();
3265 			spr[1].que = 20000;
3266 			mode = MODE_MINIMAP;
3267 			spr[2].active = /*FALSE*/0;
3268 			spr[3].active = /*FALSE*/0;
3269 			spr[4].active = /*FALSE*/0;
3270 		      }
3271 
3272 		    if (mode == MODE_DIALOG) goto b1end;
3273 
3274 
3275 
3276 
3277 		    //mode equals 4, they are in hardness edit mode, so lets do this thang
3278 
3279 		    if (mode == MODE_TILE_HARDNESS)
3280 		      {
3281 			if (spr[h].seq == 0)
3282 			  {
3283 			    if ((SDL_GetModState()&KMOD_SHIFT) && (getkeystate(SDLK_RIGHT)))
3284 			      {
3285 				spr[h].seq = 4;
3286 				spr[h].frame = 1;
3287 				if (selx < 8) selx++;
3288 				goto b1fun;
3289 			      }
3290 
3291 			    if ((SDL_GetModState()&KMOD_SHIFT) && (getkeystate(SDLK_LEFT)))
3292 			      {
3293 				spr[h].seq = 4;
3294 				spr[h].frame = 1;
3295 				if (selx > 1) selx--;
3296 				goto b1fun;
3297 			      }
3298 
3299 			    if ((SDL_GetModState()&KMOD_SHIFT) && (getkeystate(SDLK_UP)))
3300 			      {
3301 				spr[h].seq = 4;
3302 				spr[h].frame = 1;
3303 				if (sely > 1) sely--;
3304 				goto b1fun;
3305 			      }
3306 
3307 			    if ((SDL_GetModState()&KMOD_SHIFT) && (getkeystate(SDLK_DOWN)))
3308 			      {
3309 				spr[h].seq = 4;
3310 				spr[h].frame = 1;
3311 				if (sely <  8) sely++;
3312 				goto b1fun;
3313 			      }
3314 
3315 
3316 			    if (sjoy.right)
3317 			      {
3318 				spr[h].x += 9;
3319 				spr[h].seq = 4;
3320 				spr[h].frame = 1;
3321 				EditorSoundPlayEffect(SOUND_STOP);
3322 			      }
3323 			    if (sjoy.left)
3324 			      {
3325 				spr[h].x -= 9;
3326 				spr[h].seq = 4;
3327 				spr[h].frame = 1;
3328 				EditorSoundPlayEffect( SOUND_STOP );
3329 			      }
3330 			    if (sjoy.up)
3331 			      {
3332 				spr[h].y -= 9;
3333 				spr[h].seq = 4;
3334 				spr[h].frame = 1;
3335 				EditorSoundPlayEffect( SOUND_STOP );
3336 			      }
3337 			    if (sjoy.down)
3338 			      {
3339 				spr[h].y += 9;
3340 				spr[h].seq = 4;
3341 				spr[h].frame = 1;
3342 				EditorSoundPlayEffect( SOUND_STOP );
3343 			      }
3344 			  }
3345 
3346 
3347 		      b1fun:
3348 
3349 			//make sure they didn't go past the boundrys
3350 			if (mode != 1)
3351 			  {
3352 
3353 			    if (spr[h].x + (9 * (selx -1))> 95+441) spr[h].x = (95+441) - (9 * (selx-1));
3354 			    if (spr[h].x < 95) spr[h].x = 95;
3355 			    if (spr[h].y < 0) spr[h].y = 0;
3356 			    if (spr[h].y + (9 * (sely -1))> 441) spr[h].y = 441 - (9 * (sely-1));
3357 			  }
3358 
3359 			//change a piece to hard
3360 			if (getcharstate('z'))
3361 			  {
3362 			    int y;
3363 			    for (y = 0; y < sely; y++)
3364 			      {
3365 				int x;
3366 				for (x = 0; x < selx; x++)
3367 				  {
3368 				    hmap.htile[hard_tile].x[((spr[h].x) + (x*9) - 95) / 9].y[(spr[h].y + (y *9)) / 9] = 1;
3369 
3370 				  }
3371 			      }
3372 			  }
3373 
3374 
3375 			//change a piece to soft
3376 			if (getcharstate('x'))
3377 			  {
3378 			    int y;
3379 			    for (y = 0; y < sely; y++)
3380 			      {
3381 				int x;
3382 				for (x = 0; x < selx; x++)
3383 				  {
3384 				    hmap.htile[hard_tile].x[((spr[h].x) + (x*9) - 95) / 9].y[(spr[h].y + (y *9)) / 9] = 0;
3385 
3386 				  }
3387 			      }
3388 			  }
3389 
3390 
3391 			if ( (getcharstate('a')) && (SDL_GetModState()&KMOD_ALT ) )
3392 			  {
3393 			    //change ALL to 'low hard'
3394 			    change_tile(hard_tile, 2);
3395 			    log_debug("Changing whole tile to 2");
3396 
3397 			    return;
3398 			  }
3399 
3400 			if ( (getcharstate('s')) && (SDL_GetModState()&KMOD_ALT ) )
3401 			  {
3402 			    //change ALL to 'low hard'
3403 			    change_tile(hard_tile, 3);
3404 			    log_debug("Chaning whole tile to 3");
3405 
3406 			    return;
3407 			  }
3408 			if ( (getcharstate('x')) && (SDL_GetModState()&KMOD_ALT ) )
3409 			  {
3410 			    //change ALL to 'low hard'
3411 			    change_tile(hard_tile, 1);
3412 			    log_debug("Changing whole tile to 1");
3413 
3414 			    return;
3415 			  }
3416 
3417 
3418                         if (getcharstate('a'))
3419 			  {
3420 			    int y;
3421 			    for (y = 0; y < sely; y++)
3422 			      {
3423 				int x;
3424 				for (x = 0; x < selx; x++)
3425 				  {
3426 				    hmap.htile[hard_tile].x[((spr[h].x) + (x*9) - 95) / 9].y[(spr[h].y + (y *9)) / 9] = 2;
3427 
3428 				  }
3429 			      }
3430 
3431 			  }
3432                         if (getcharstate('s'))
3433 			  {
3434 			    int y;
3435 			    for (y = 0; y < sely; y++)
3436 			      {
3437 				int x;
3438 				for (x = 0; x < selx; x++)
3439 				  {
3440 				    hmap.htile[hard_tile].x[((spr[h].x) + (x*9) - 95) / 9].y[(spr[h].y + (y *9)) / 9] = 3;
3441 
3442 				  }
3443 			      }
3444 
3445 			  }
3446 
3447 
3448 			//update frame with current hard blocks, slow
3449 
3450 			draw_hard();
3451 
3452 			if (sjoy.button[EDITOR_ACTION_ESCAPE] == 1
3453 			    || sjoy.button[EDITOR_ACTION_RETURN] == 1)
3454 			  {
3455 			    //quit hardness edit
3456 
3457 			    spr[h].seq = 3;
3458 			    spr[h].seq_orig = 3;
3459 
3460 			    if (last_modereal == 8)
3461 			      {
3462 				//return to alt hardness editor
3463 				draw_map();
3464 				last_modereal = 0;
3465 				spr[h].x = m4x;
3466 				spr[h].y = m4y;
3467 
3468 				selx = 1;
3469 				sely = 1;
3470 
3471 				mode = MODE_SCREEN_HARDNESS_INIT;
3472 				return;
3473 				//goto skip_draw;
3474 			      }
3475 
3476 			    if (last_mode > 0)
3477 			      {
3478 				loadtile(last_mode);
3479 				selx = 1;
3480 				sely = 1;
3481 				goto b1end;
3482 			      }
3483 			    fill_whole_hard();
3484 
3485 			    draw_map();
3486 			    spr[h].x = m4x;
3487 			    spr[h].y = m4y;
3488 			    mode = MODE_SCREEN_TILES;
3489 			    selx = 1;
3490 			    sely = 1;
3491 			  }
3492 
3493 			goto b1end;
3494 		      }
3495 
3496 
3497 		    //THEY WANT TO EDIT HARDNESS
3498 
3499 		    if ( (sjoy.charjustpressed['b']) )
3500 		      {
3501 			in_master = 31;
3502 
3503 
3504 		      }
3505 
3506 		    if ( (sjoy.charjustpressed['v']) )
3507 		      {
3508 			in_master = INPUT_SCREEN_VISION;
3509 		      }
3510 
3511 
3512 
3513 		    if (((mode == MODE_SCREEN_TILES) && (sjoy.button[EDITOR_ACTION_RETURN]))
3514 			|| ((mode == MODE_TILE_PICKER) && (getkeystate(SDLK_SPACE))))
3515 
3516 		      {
3517 
3518 			if (mode == MODE_SCREEN_TILES)
3519 			  cur_tile = pam.t[(((spr[1].y+1)*12) / 50)+(spr[1].x / 50)].square_full_idx0;
3520 
3521 			if (mode == MODE_TILE_PICKER)
3522 			  {
3523 			    cur_tile = (((spr[1].y+1)*12) / 50)+(spr[1].x / 50);
3524 			    cur_tile += (cur_screen * 128) - 128;
3525 			  }
3526 
3527 			while(kill_last_sprite());
3528 			draw_current();
3529 
3530 			if (cur_tile > 0)
3531 			  {
3532 			    if (hmap.btile_default[cur_tile] == 0)
3533 			      {
3534 				int j;
3535 				for (j = 1; j < 799; j++)
3536 				  {
3537 				    if (hmap.htile[j].used == /*FALSE*/0)
3538 				      {
3539 					hmap.btile_default[cur_tile] = j;
3540 					hmap.htile[j].used = /*TRUE*/1;
3541 				    	hard_tile = j;
3542 					goto tilesel;
3543 				      }
3544 				  }
3545 			      }
3546 			    else
3547 			      hard_tile = hmap.btile_default[cur_tile];
3548 
3549 			  tilesel:
3550 			    xx = cur_tile % 128;
3551 /* 			    Rect.left = (xx * 50- (xx / 12) * 600); */
3552 /* 			    Rect.top = (xx / 12) * 50; */
3553 /* 			    Rect.right = Rect.left + 50; */
3554 /* 			    Rect.bottom = Rect.top + 50; */
3555 
3556 /* 			    crapRec.top = 0; */
3557 /* 			    crapRec.left = 95; */
3558 /* 			    crapRec.bottom = 450; */
3559 /* 			    crapRec.right = 95+450; */
3560 
3561 /* 			    ZeroMemory(&ddbltfx, sizeof(ddbltfx)); */
3562 /* 			    ddbltfx.dwSize = sizeof( ddbltfx); */
3563 
3564 			    spr[1].seq = 0;
3565 			    spr[1].pseq = 10;
3566 			    spr[1].pframe = 1;
3567 
3568 
3569 
3570 			    // Display the given tile square fullscreen, for hardness editing
3571 /* 			    lpDDSTwo->Blt(&crapRec , tiles[cool+1], */
3572 /* 					  &Rect, DDBLT_DDFX | DDBLT_WAIT,&ddbltfx ); */
3573 			    // GFX
3574 			    /* Generic scaling */
3575 			    /* Not perfectly accurate yet: move a 200% sprite to the
3576 			       border of the screen to it is clipped: it's scaled size
3577 			       will slighly vary. Maybe we need to clip the source zone
3578 			       before scaling it.. */
3579 			    {
3580 			      SDL_Rect src, dst;
3581 			      src.x = (xx % 12) * 50;
3582 			      src.y = (xx / 12) * 50;
3583 			      src.w = 50;
3584 			      src.h = 50;
3585 			      dst.x = 95;
3586 			      dst.y = 0;
3587 			      dst.w = 450;
3588 			      dst.h = 450;
3589 
3590 			      cool = cur_tile / 128;
3591 			      gfx_blit_stretch(gfx_tiles[cool+1], &src, GFX_lpDDSTwo, &dst);
3592 			    }
3593 
3594 			    m4x = spr[h].x;
3595 			    m4y = spr[h].y;
3596 
3597 			    spr[1].x = 95;
3598 			    spr[1].y = 0;
3599 			    selx = 1;
3600 			    sely = 1;
3601 
3602 			    mode = MODE_TILE_HARDNESS;
3603 			  }
3604 		      }
3605 
3606 
3607 		    if ((mode == MODE_TILE_PICKER) || (mode == MODE_SCREEN_TILES))
3608 		      {
3609 			//resizing the box
3610 
3611 			if ((SDL_GetModState()&KMOD_SHIFT) && (getkeystate(SDLK_RIGHT /* 39 */)) )
3612 			  {
3613 			    spr[h].seq = 3;
3614 			    spr[h].seq_orig = 3;
3615 			    if (selx < 8) selx++;
3616 			    goto b1end;
3617 			  }
3618 
3619 			if ((SDL_GetModState()&KMOD_SHIFT) && (getkeystate(SDLK_LEFT /* 37 */)) )
3620 			  {
3621 			    spr[h].seq = 3;
3622 			    spr[h].seq_orig = 3;
3623 			    if (selx > 1) selx--;
3624 			    goto b1end;
3625 
3626 			  }
3627 
3628 			if ((SDL_GetModState()&KMOD_SHIFT) && (getkeystate(SDLK_UP /* 38 */)) )
3629 			  {
3630 			    spr[h].seq = 3;
3631 			    spr[h].seq_orig = 3;
3632 			    if (sely > 1) sely--;
3633 			    goto b1end;
3634 			  }
3635 
3636 			if ((SDL_GetModState()&KMOD_SHIFT) && (getkeystate(SDLK_DOWN /* 40 */)) )
3637 			  {
3638 			    spr[h].seq = 3;
3639 			    spr[h].seq_orig = 3;
3640 			    if (sely <  8) sely++;
3641 			    goto b1end;
3642 			  }
3643 
3644 		      }
3645 
3646 
3647 		    if (getkeystate(SDLK_RIGHT))
3648 		      {
3649 			spr[h].x += spr[h].speed;
3650 			spr[h].seq = spr[h].seq_orig;
3651 			EditorSoundPlayEffect( SOUND_STOP );
3652 		      }
3653 
3654 
3655 		    if ((getcharstate('s')) && (mode == MODE_SCREEN_TILES))
3656 		      {
3657 			int y;
3658 			spr[h].seq = 3;
3659 			spr[h].seq_orig = 3;
3660 			//EditorSoundPlayEffect( SOUND_JUMP );
3661 
3662 
3663 			pam.t[(((spr[1].y+1)*12) / 50)+(spr[1].x / 50)].square_full_idx0 = cur_tile;
3664 
3665 			for (y = 0; y < sely; y++)
3666 			  {
3667 			    int x;
3668 			    for (x = 0; x < selx; x++)
3669 			      {
3670 				holdx = (((spr[1].y+1)*12) / 50)+(spr[1].x / 50);
3671 				holdx += (y * 12);
3672 				holdx += x;
3673 				pam.t[holdx].square_full_idx0 = (cur_tile + (y * 12) + x);
3674 
3675 			      }
3676 			  }
3677 
3678 			draw_map();
3679 		      }
3680 
3681 
3682 
3683 		    if ((getcharstate('c')) && (mode == MODE_SCREEN_TILES))
3684 		      {
3685 			spr[h].seq = 3;
3686 			spr[h].seq_orig = 3;
3687 			//SoundPlayEffect( SOUND_JUMP );
3688 			cur_tile = pam.t[(((spr[1].y+1)*12) / 50)+(spr[1].x / 50)].square_full_idx0;
3689 			draw_map();
3690 		      }
3691 
3692 		    /* Tile selection */
3693 		    if (mode == MODE_SCREEN_TILES || mode == MODE_TILE_PICKER)
3694 		      {
3695 			int unit = 0, tile_no = 0;
3696 			if (getkeystate('1') || getkeystate(SDLK_KP1) || getkeystate(SDLK_F1)) unit = 1;
3697 			if (getkeystate('2') || getkeystate(SDLK_KP2) || getkeystate(SDLK_F2)) unit = 2;
3698 			if (getkeystate('3') || getkeystate(SDLK_KP3) || getkeystate(SDLK_F3)) unit = 3;
3699 			if (getkeystate('4') || getkeystate(SDLK_KP4) || getkeystate(SDLK_F4)) unit = 4;
3700 			if (getkeystate('5') || getkeystate(SDLK_KP5) || getkeystate(SDLK_F5)) unit = 5;
3701 			if (getkeystate('6') || getkeystate(SDLK_KP6) || getkeystate(SDLK_F6)) unit = 6;
3702 			if (getkeystate('7') || getkeystate(SDLK_KP7) || getkeystate(SDLK_F7)) unit = 7;
3703 			if (getkeystate('8') || getkeystate(SDLK_KP8) || getkeystate(SDLK_F8)) unit = 8;
3704 			if (getkeystate('9') || getkeystate(SDLK_KP9) || getkeystate(SDLK_F9)) unit = 9;
3705 			if (getkeystate('0') || getkeystate(SDLK_KP0) || getkeystate(SDLK_F10)) unit = 10;
3706 
3707 			tile_no = unit;
3708 			if (SDL_GetModState()&KMOD_SHIFT)
3709 			  tile_no = 10 + unit;
3710 			if (SDL_GetModState()&KMOD_CTRL)
3711 			  tile_no = 20 + unit;
3712 			if (SDL_GetModState()&KMOD_ALT)
3713 			  tile_no = 30 + unit;
3714 
3715 			if (unit > 0) /* make sure one key was pressed */
3716 			  loadtile(tile_no);
3717 
3718 			/* Exception: tile #41 = Alt+` */
3719 			if (SDL_GetModState()&KMOD_ALT
3720 			    && getkeystate(SDLK_BACKQUOTE))
3721 			  loadtile(41);
3722 			/* alternatives for non-US keyboards */
3723 			if (getkeystate(SDLK_F11) || getkeystate(SDLK_KP_PERIOD))
3724 			  loadtile(41);
3725 		      }
3726 
3727 		    //if ( (GetKeyboard(48)) && ( (mode == 3) | (mode ==2)) ) loadtile(11);
3728 
3729 
3730 		    if ((sjoy.button[EDITOR_ACTION_RETURN]) && (mode == MODE_TILE_PICKER))
3731 		      {
3732 			// cut to map editer from tile selection
3733 			spr[h].seq = 3;
3734 			spr[h].seq_orig = 3;
3735 			cur_tile = (((spr[1].y+1)*12) / 50)+(spr[1].x / 50);
3736 			cur_tile += (cur_screen * 128) - 128;
3737 			//SoundPlayEffect( SOUND_JUMP );
3738 			m2x = spr[h].x;
3739 			m2y = spr[h].y;
3740 			spr[h].x = m3x;
3741 			spr[h].y = m3y;
3742 
3743 			mode = MODE_SCREEN_TILES;
3744 			spr[h].speed = 50;
3745 			draw_map();
3746 			last_mode = 0;
3747 		      }
3748 
3749 
3750 
3751 		    if (sjoy.button[EDITOR_ACTION_ESCAPE] && (mode == MODE_TILE_PICKER))
3752 		      {
3753 			// cut to map editer from tile selection
3754 			spr[h].seq = 3;
3755 			spr[h].seq_orig = 3;
3756 			//cur_tile = (((spr[1].y+1)*12) / 50)+(spr[1].x / 50);
3757 			//SoundPlayEffect( SOUND_JUMP );
3758 			m2x = spr[h].x;
3759 			m2y = spr[h].y;
3760 			spr[h].x = m3x;
3761 			spr[h].y = m3y;
3762 
3763 			mode = MODE_SCREEN_TILES;
3764 			draw_map();
3765 			last_mode = 0;
3766 			goto b1end;
3767 		      }
3768 
3769 
3770 		    if ( (sjoy.keyjustpressed[SDLK_SPACE])  && (mode == MODE_MINIMAP))
3771 		      {
3772 			//make_map_tiny();
3773 			draw_map_tiny = 0;
3774 
3775 		      }
3776 
3777 		    if ( (sjoy.charjustpressed['l'])  && (mode == MODE_MINIMAP))
3778 		      {
3779 
3780 			//if (map.loc[(((spr[1].y+1)*32) / 20)+(spr[1].x / 20)] != 0)
3781 			//{
3782 			buf_map = (((spr[1].y+1)*32) / 20)+(spr[1].x / 20);
3783 			in_master = INPUT_MINIMAP_LOAD;
3784 			//}
3785 
3786 		      }
3787 
3788 
3789 		    if ( (sjoy.keyjustpressed[SDLK_ESCAPE /* 27 */]) && (mode == MODE_MINIMAP))
3790 		      {
3791 			load_info();
3792 			draw_minimap();
3793 			buf_mode = /*false*/0;
3794 
3795 		      }
3796 
3797 
3798 		    if ( (sjoy.charjustpressed['m']) && (mode == MODE_MINIMAP))
3799 		      {
3800 			//set music # for this block
3801 			in_int = &map.music[(((spr[1].y+1)*32) / 20)+(spr[1].x / 20)];
3802 			in_master = INPUT_SCREEN_MIDI;
3803 		      }
3804 
3805 		    if ( (sjoy.charjustpressed['s']) && (mode == MODE_MINIMAP))
3806 		      {
3807 			//set music # for this block
3808 			in_int = &map.indoor[(((spr[1].y+1)*32) / 20)+(spr[1].x / 20)];
3809 			in_master = INPUT_SCREEN_TYPE;
3810 		      }
3811 
3812 		    if ( (sjoy.charjustpressed['q']) && (mode == MODE_MINIMAP))
3813 		      {
3814 			save_hard();
3815 			log_info("Info saved.");
3816 			SDL_Event ev;
3817 			ev.type = SDL_QUIT;
3818 			SDL_PushEvent(&ev);
3819 			return;
3820 		      }
3821 
3822 		    if ( (sjoy.button[EDITOR_ACTION_RETURN]) && (mode == MODE_MINIMAP))
3823 		      {
3824 
3825 			if (buf_mode)
3826 			  {
3827 			    //lets replace this screen
3828 
3829 			    buf_mode = /*false*/0;
3830 
3831 
3832 			    if (!load_map_buf(buffmap.loc[(((spr[1].y+1)*32) / 20)+(spr[1].x / 20)]))
3833 			      {
3834 				draw_minimap();
3835 				sjoy.button[EDITOR_ACTION_RETURN] = /*false*/0;
3836 				return;
3837 			      }
3838 
3839 
3840 			    load_info();
3841 
3842 			    if (map.loc[(((spr[1].y+1)*32) / 20)+(spr[1].x / 20)] == 0)
3843 			      {
3844 
3845 				(
3846 				 map.loc[(((spr[1].y+1)*32) / 20)+(spr[1].x / 20)]) = add_new_map();
3847 				//wrongo, let's add the map
3848 
3849 				//draw_minimap();
3850 
3851 
3852 			      }
3853 
3854 			    map.indoor[buf_map] = buffmap.indoor[(((spr[1].y+1)*32) / 20)+(spr[1].x / 20)];
3855 			    map.music[buf_map] = buffmap.music[(((spr[1].y+1)*32) / 20)+(spr[1].x / 20)];
3856 
3857 			    save_map(map.loc[buf_map]);
3858 
3859 			    save_info();
3860 			    draw_minimap();
3861 			    return;
3862 			  }
3863 
3864 			load_info();
3865 
3866 			cur_map=  (((spr[1].y+1)*32) / 20)+(spr[1].x / 20);
3867 			if (map.loc[cur_map] == 0)
3868 			  {
3869 			    //new map screen
3870 
3871 			    map.loc[cur_map] = add_new_map();
3872 			    save_info();
3873 
3874 
3875 			  } else load_map(map.loc[cur_map]);
3876 
3877 			spr[h].seq = 3;
3878 			spr[h].seq_orig = 3;
3879 			k[seq[3].frame[1]].xoffset = -playl;
3880 			//SoundPlayEffect( SOUND_JUMP );
3881 
3882 			log_debug("Y is %d X is %d", spr[h].y, spr[h].x);
3883 
3884 			m1x = spr[h].x;
3885 			m1y = spr[h].y;
3886 			spr[h].x = m3x;
3887 			spr[h].y = m3y;
3888 
3889 
3890 			mode = MODE_SCREEN_TILES;
3891 
3892 			spr[h].speed = 50;
3893 			draw_map();
3894 		      }
3895 
3896 
3897 
3898 		    /* TODO: where is it in the editor, and what are
3899 		       the keys in the original dinkedit? */
3900 		    if ( (mode == MODE_SCREEN_TILES) && (getkeystate(189 /* VK_OEM_MINUS */)) )
3901 		      {
3902 			spr[h].seq = 3;
3903 			spr[h].seq_orig = 3;
3904 			cur_tile--;
3905 			if (cur_tile < 0) cur_tile = 0;
3906 		      }
3907 		    if ( (mode == MODE_SCREEN_TILES) && (getkeystate(187 /* VK_OEM_PLUS */)) )
3908 		      {
3909 			spr[h].seq = 3;
3910 			spr[h].seq_orig = 3;
3911 
3912 			cur_tile++;
3913 			//if (cur_tile > 127) cur_tile = 127;
3914 		      }
3915 
3916 
3917 		    if ((mode == MODE_SCREEN_TILES) && (sjoy.charjustpressed['h']))
3918 		      {
3919 			//start althard mode
3920 
3921 			mode = MODE_SCREEN_HARDNESS_INIT;
3922 			goto skip_draw;
3923 		      }
3924 
3925 		    if (mode == MODE_SCREEN_HARDNESS)
3926 		      {
3927 			//mode for it
3928 			if (sjoy.keyjustpressed[SDLK_ESCAPE])
3929 			  {
3930 			    //exit mode 8
3931 			    mode = MODE_SCREEN_TILES;
3932 			    spr[h].seq = 3;
3933 			    spr[h].seq_orig = 3;
3934 			    draw_map();
3935 			    goto b1end;
3936 			  }
3937 
3938 			/* if (sjoy.keyjustpressed[/\* VK_OEM_4 *\/ 219]) // '[' for US */
3939 			if (sjoy.charjustpressed['['])
3940 			  {
3941 			    hard_tile--;
3942 			    if (hard_tile < 0) hard_tile = 799;
3943 			  }
3944 			/* if (sjoy.keyjustpressed[/\* VK_OEM_6 *\/ 221]) // ']' for US */
3945 			if (sjoy.charjustpressed[']'])
3946 			  {
3947 			    hard_tile++;
3948 			    if (hard_tile > 799) hard_tile = 0;
3949 			  }
3950 
3951 			if (sjoy.charjustpressed['c'])
3952 			  {
3953 			    //copy tile hardness from current block
3954 			    hard_tile = realhard(xy2screentile(spr[1].x, spr[1].y));
3955 			  }
3956 
3957 			if (sjoy.charjustpressed['s'])
3958 			  {
3959 			    //stamp tile hardness to selected
3960 			    pam.t[(((spr[1].y+1)*12) / 50)+(spr[1].x / 50)].althard = hard_tile;
3961 			    draw_map();
3962 			    mode = MODE_SCREEN_HARDNESS_INIT;
3963 
3964 			    return;
3965 			  }
3966 
3967 			if (sjoy.keyjustpressed[SDLK_DELETE])
3968 			  {
3969 			    //stamp tile hardness to selected
3970 			    pam.t[(((spr[1].y+1)*12) / 50)+(spr[1].x / 50)].althard = 0;
3971 			    draw_map();
3972 			    mode = MODE_SCREEN_HARDNESS_INIT;
3973 
3974 			    return;
3975 			  }
3976 
3977 			/* Display the hard tile in the clipboard */
3978 			char crapa[20];
3979 			sprintf(crapa, "Copy: %d",hard_tile);
3980 			SaySmall(crapa, 580,400, 255,255,255);
3981 
3982 			draw_hard_tile(spr[1].x,spr[1].y, hard_tile);
3983 
3984 			if (sjoy.keyjustpressed[SDLK_RETURN])
3985 			  {
3986 			    //they want to edit this alt hardness, let's do it
3987 			    cur_tile = pam.t[xy2screentile(spr[1].x, spr[1].y)].square_full_idx0;
3988 
3989 			    xx = cur_tile - (cool * 128);
3990 			    Rect.left = spr[1].x+20;
3991 			    Rect.top = spr[1].y;
3992 			    Rect.right = Rect.left + 50;
3993 			    Rect.bottom = Rect.top + 50;
3994 
3995 /*			    crapRec.top = 0; */
3996 /*			    crapRec.left = 95; */
3997 /*			    crapRec.bottom = 450; */
3998 /*			    crapRec.right = 95+450; */
3999 
4000 /* 			    ZeroMemory(&ddbltfx, sizeof(ddbltfx)); */
4001 /* 			    ddbltfx.dwSize = sizeof( ddbltfx); */
4002 			    spr[1].seq = 0;
4003 			    spr[1].pseq = 10;
4004 			    spr[1].pframe = 1;
4005 
4006 
4007 /* 			    lpDDSTwo->Blt(&crapRec , lpDDSBack, */
4008 /* 					  &Rect, DDBLT_DDFX | DDBLT_WAIT,&ddbltfx ); */
4009 			    // GFX
4010 			    /* In this particular case, we're scaling
4011 			       the whole screen backbuffer by 900%
4012 			       just to scale a single 50x50 square of
4013 			       it... */
4014 			    {
4015 			      SDL_Rect src, dst;
4016 			      src.x = spr[1].x+20;
4017 			      src.y = spr[1].y;
4018 			      src.w = 50;
4019 			      src.h = 50;
4020 			      dst.x = 95;
4021 			      dst.y = 0;
4022 			      dst.w = 450;
4023 			      dst.h = 450;
4024 			      gfx_blit_stretch(GFX_lpDDSBack, &src, GFX_lpDDSTwo, &dst);
4025 			    }
4026 
4027 			    m4x = spr[h].x;
4028 			    m4y = spr[h].y;
4029 
4030 			    spr[1].x = 95;
4031 			    spr[1].y = 0;
4032 			    selx = 1;
4033 			    sely = 1;
4034 
4035 			    mode = MODE_TILE_HARDNESS;
4036 
4037 			    hmap.htile[hard_tile].used = /*true*/1;
4038 			    last_modereal = 8;
4039 			  }
4040 		      }
4041 
4042 		    if ((mode == MODE_SCREEN_TILES)
4043 			&& (SDL_GetModState()&KMOD_ALT)
4044 			&& sjoy.charjustpressed['x'])
4045 		      {
4046 			spr[h].seq = 2;
4047 			spr[h].seq_orig = 2;
4048 			m3x = spr[h].x;
4049 			m3y = spr[h].y;
4050 			spr[h].x = m1x;
4051 			spr[h].y = m1y;
4052 			mode = MODE_MINIMAP;
4053 			spr[h].speed = 20;
4054 			load_info();
4055 			draw_minimap();
4056 			while (kill_last_sprite());
4057 			return;
4058 		      }
4059 
4060 		    if ((mode == MODE_SCREEN_TILES) && (sjoy.button[EDITOR_ACTION_ESCAPE]))
4061 		      {
4062 			// jump to map selector selector from map mode
4063 			save_map(map.loc[cur_map]);
4064 			spr[h].seq = 2;
4065 			spr[h].seq_orig = 2;
4066 			//SoundPlayEffect( SOUND_JUMP );
4067 			m3x = spr[h].x;
4068 			m3y = spr[h].y;
4069 			//Msg("m1y is %d, math is %d",m1y, (20 * (m1y / 20)) < m1y);
4070 			spr[h].x = m1x;
4071 			spr[h].y = m1y;
4072 			mode = 1;
4073 			spr[h].speed = 20;
4074 			load_info();
4075 			draw_minimap();
4076 			while (kill_last_sprite());
4077 			return;
4078 		      }
4079 
4080 
4081 		    if (getkeystate(SDLK_LEFT))
4082 		      {
4083 			spr[h].x -= spr[h].speed;
4084 			spr[h].seq = spr[h].seq_orig;
4085 			EditorSoundPlayEffect(SOUND_STOP);
4086 		      }
4087 
4088 		    if (getkeystate(SDLK_DOWN))
4089 		      {
4090 			spr[h].y += spr[h].speed;
4091 			spr[h].seq = spr[h].seq_orig;
4092 			EditorSoundPlayEffect(SOUND_STOP);
4093 		      }
4094 
4095 		    if (getkeystate(SDLK_UP))
4096 		      {
4097 			spr[h].y -= spr[h].speed;
4098 			spr[h].seq = spr[h].seq_orig;
4099 			EditorSoundPlayEffect(SOUND_STOP);
4100 		      }
4101 
4102 		    if (spr[h].speed < 1)
4103 		      spr[h].speed = 1;
4104 		    if (spr[h].y > (y - k[getpic(h)].box.bottom))
4105 		      spr[h].y = y - k[getpic(h)].box.bottom;
4106 		    if (spr[h].x > (x - k[getpic(h)].box.right))
4107 		      spr[h].x = x - k[getpic(h)].box.right;
4108 		    if (spr[h].x < 0)
4109 		      spr[h].x = 0;
4110 		    if (spr[h].y < 0)
4111 		      spr[h].y = 0;
4112 
4113 		    // end human brain (1)
4114 
4115 
4116 		    if ((mode == MODE_TILE_PICKER) || (mode == MODE_SCREEN_TILES)
4117 			|| (mode == MODE_SPRITE_PICKER) || (mode == MODE_SCREEN_HARDNESS))
4118 		      {
4119 			if ((selx * 50 + spr[1].x) > 600)
4120 			  {
4121 			    spr[1].x = 600 - (selx * 50);
4122 			  }
4123 		      }
4124 
4125 		    if ((mode == MODE_TILE_PICKER))
4126 		      {
4127 			if ((sely * 50 + spr[1].y) > 450)
4128 			  {
4129 			    spr[1].y = 450 - (sely * 50);
4130 			  }
4131 		      }
4132 		    if ((mode == MODE_SCREEN_TILES) || (mode == MODE_SPRITE_PICKER)
4133 			|| (mode == MODE_SCREEN_HARDNESS))
4134 		      {
4135 			if ((sely * 50 + spr[1].y) > 400)
4136 			  {
4137 			    spr[1].y = 400 - (sely * 50);
4138 			  }
4139 		      }
4140 
4141 		  b1end:;
4142 		  } //end if seq is 0
4143 	      } //real end of human brain
4144 
4145 
4146 	    if (spr[h].brain == 2)
4147 	      {
4148 		if (spr[h].y > (y-k[getpic(h)].box.bottom))
4149 		  {
4150 		    spr[h].my -= (spr[h].my * 2);
4151 		    // SoundPlayEffect( SOUND_JUMP );
4152 		  }
4153 
4154 		if (spr[h].x > (x-k[getpic(h)].box.right))
4155 		  {
4156 		    spr[h].mx -= (spr[h].mx * 2);
4157 		    //SoundPlayEffect( SOUND_JUMP );
4158 		  }
4159 
4160 		if (spr[h].y < 0)
4161 		  {
4162 		    spr[h].my -= (spr[h].my * 2);
4163 		    //SoundPlayEffect( SOUND_JUMP );
4164 		  }
4165 
4166 
4167 		if (spr[h].x < 0)
4168 		  {
4169 		    spr[h].mx -= (spr[h].mx * 2);
4170 		    //SoundPlayEffect( SOUND_JUMP );
4171 		  }
4172 
4173 
4174 		spr[h].x += spr[h].mx;
4175 		spr[h].y += spr[h].my;
4176 
4177 
4178 	      }
4179 	    // end robot(2)
4180 
4181 
4182 
4183 	    if (spr[h].seq > 0)
4184 	      {
4185 		if (spr[h].frame < 1)
4186 		  {
4187 		    // new anim
4188 		    spr[h].pseq = spr[h].seq;
4189 		    spr[h].pframe = 1;
4190 
4191 		    spr[h].frame = 1;
4192 		    spr[h].delay = (thisTickCount + seq[spr[h].seq].delay[1]);
4193 		  } else
4194 		  {
4195 		    // not new anim
4196 
4197 		    //is it time?
4198 
4199 		    if (thisTickCount > spr[h].delay)
4200 		      {
4201 
4202 
4203 			spr[h].frame++;
4204 			spr[h].delay = (thisTickCount + seq[spr[h].seq].delay[spr[h].frame]);
4205 
4206 			spr[h].pseq = spr[h].seq;
4207 			spr[h].pframe = spr[h].frame;
4208 
4209 			if (seq[spr[h].seq].frame[spr[h].frame] == -1)
4210 			  {
4211 			    spr[h].frame = 1;
4212 			    spr[h].pseq = spr[h].seq;
4213 			    spr[h].pframe = spr[h].frame;
4214 			    spr[h].delay = (thisTickCount + seq[spr[h].seq].delay[spr[h].frame]);
4215 
4216 			  }
4217 
4218 			if (seq[spr[h].seq].frame[spr[h].frame] == 0)
4219 			  {
4220 			    spr[h].pseq = spr[h].seq;
4221 			    spr[h].pframe = spr[h].frame-1;
4222 
4223 			    spr[h].frame = 0;
4224 			    spr[h].seq = 0;
4225 
4226 
4227 			  }
4228 
4229 
4230 		      }
4231 
4232 		  }
4233 	      }
4234 
4235 
4236 	    if (mode == MODE_SCREEN_TILES)
4237 	      {
4238 		//need offset to look right
4239 		k[seq[3].frame[1]].xoffset = -20;
4240 		greba = 20;
4241 	      }
4242 	    if (mode == MODE_TILE_PICKER)
4243 	      {
4244 		//pick a tile, needs no offset
4245 		k[seq[3].frame[1]].xoffset = 0;
4246 		greba = 0;
4247 	      }
4248 
4249 	    //		if (  !(( h == 1) & (mode == 9)) )
4250 	    if (!((h == 1) && (mode == MODE_SCREEN_HARDNESS_INIT)))
4251 	      {
4252 		if (draw_map_tiny == -1)
4253 		  draw_sprite(GFX_lpDDSBack, h);
4254 		else
4255 		  draw_sprite(GFX_lpDDSTwo, h);
4256 	      }
4257 
4258 	    //Msg("Drew %d.",h);
4259 
4260 	  skip_draw:
4261 	    if (spr[h].brain == 1)
4262 	      {
4263 		if (mode == MODE_SCREEN_TILES || mode == MODE_TILE_PICKER)
4264 		  {
4265 		    /* Draw the tile squares selector, an expandable
4266 		       array of white non-filled squares */
4267 		    int y;
4268 		    for (y = 0; y < sely; y++)
4269 		      {
4270 			int x;
4271 			for (x = 0; x < selx; x++)
4272 			  {
4273 /* 			    ddrval = lpDDSBack->BltFast( (spr[h].x+(50 *x))+greba,spr[h].y+(50 * y), k[getpic(h)].k, */
4274 /* 							 &k[getpic(h)].box  , DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT ); */
4275 			    // GFX
4276 			    {
4277 			      SDL_Rect dst;
4278 			      dst.x = spr[h].x + 50*x + greba;
4279 			      dst.y = spr[h].y + 50*y;
4280 			      SDL_BlitSurface(GFX_k[getpic(h)].k, NULL, GFX_lpDDSBack, &dst);
4281 			    }
4282 			  }
4283 		      }
4284 		  }
4285 
4286 
4287 		if ((mode == MODE_TILE_HARDNESS))
4288 		  {
4289 		    /* Display the current "pencil"/square to draw hardness with */
4290 		    int yy;
4291 		    for (yy = 0; yy < sely; yy++)
4292 		      {
4293 			int xx;
4294 			for (xx = 0; xx < selx; xx++)
4295 			  {
4296 /* 			    ddrval = lpDDSBack->BltFast( spr[h].x+(9 * xx),spr[h].y+(9 * yy), k[getpic(h)].k, */
4297 /* 							 &k[getpic(h)].box  , DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT ); */
4298 			    // GFX
4299 			    {
4300 			      SDL_Rect dst;
4301 			      dst.x = spr[h].x + 9*xx;
4302 			      dst.y = spr[h].y + 9*yy;
4303 			      SDL_BlitSurface(GFX_k[getpic(h)].k, NULL, GFX_lpDDSBack, &dst);
4304 			    }
4305 			  }
4306 		      }
4307 		  }
4308 	      }
4309 	  }
4310       }
4311 
4312 
4313   if (mode == MODE_SCREEN_HARDNESS_INIT)
4314     {
4315       mode = MODE_SCREEN_HARDNESS;
4316 
4317       fill_whole_hard();
4318       while(kill_last_sprite());
4319       place_sprites();
4320 
4321       /*	draw_map();
4322 
4323 
4324 		rcRect.top = 0;
4325 		rcRect.right = x;
4326 		rcRect.bottom = y;
4327 		ddrval = lpDDSBack->BltFast( 0, 0, lpDDSTwo,
4328 		&rcRect, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
4329       */
4330       drawallhard();
4331 
4332       rcRect.left = 0;
4333       rcRect.right = 640;
4334       rcRect.top = 0;
4335       rcRect.bottom = 400;
4336 /*       ddrval = lpDDSTwo->BltFast( 0, 0, lpDDSBack, */
4337 /* 				  &rcRect, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT); */
4338 /*       if (ddrval != DD_OK) dderror(ddrval); */
4339       // GFX
4340       SDL_BlitSurface(GFX_lpDDSBack, NULL, GFX_lpDDSTwo, NULL);
4341 
4342       while(kill_last_sprite());
4343     }
4344 
4345 
4346   //sprintf(msg, "k[1] top is %d",k[1].box.top);
4347 
4348   //prepare to display misc messages for debug purposes
4349 
4350 /*   if (lpDDSBack->GetDC(&hdc) == DD_OK) */
4351 /*     { */
4352 /*       SetBkMode(hdc, TRANSPARENT);  */
4353 
4354 /*       //   SetBkMode(hdc, OPAQUE); */
4355 /*       SetBkColor(hdc, 1); */
4356 /*       SetTextColor(hdc,RGB(200,200,200)); */
4357       FONTS_SetTextColor(200, 200, 200);
4358 
4359       //	TextOut(hdc,0,0, msg,lstrlen(msg));
4360       //	   if (mode == 0) strcpy(msg,"");
4361       if (mode == MODE_DIALOG)
4362 	strcpy(msg,"");
4363 
4364       if (mode == MODE_MINIMAP)
4365 	{
4366 	  if (20 * (spr[1].y / 20) != spr[1].y)
4367 	    {
4368 	      spr[1].y += 10;
4369 	    }
4370 	  sprintf(msg,
4371 		  "Map # %d - Press ENTER to edit, SPACE to detail map. (%d)  (Q) to quit and save. L to replace a "
4372 		  "screen from another map file.  Z to toggle this help text. S to modify screentype. M to modify midi.",
4373 		  mode,
4374 		  (((spr[1].y+1)*32) / 20)+(spr[1].x / 20));
4375 /* 		  map.loc[(((spr[1].y+1)*32) / 20)+(spr[1].x / 20) ]); */
4376 	}
4377       if (mode == MODE_SCREEN_TILES)
4378 	{
4379 	  //((x-1) - (x / 12))*50, (x / 12) * 50,
4380 	  sprintf(msg,
4381 		  "Map # %d, (C)opy or (S)tamp tile. ESC to exit to map picker. ENTER to edit hardness. TAB for sprite edit mode. 1-10 for tilescreens. (hold alt, crtl or shift for more) SPACE to show hardness of screen. (I)nfo on sprites."
4382 		  " V to change vision, B to change maps base .C file.",
4383 		  mode);
4384 /* 		  cur_map, */
4385 /* 		  cur_tile, */
4386 /* 		  pam.t[crap].num); */
4387 	}
4388       if (mode == MODE_TILE_PICKER)
4389 	sprintf(msg,
4390 		"Map # %d - Current tile # %d - ENTER to choose, SPACE to edit hardness.",
4391 		mode,
4392 		cur_map);
4393 /* 		(((spr[1].y+1)*12) / 50)+(spr[1].x / 50)); */
4394       if (mode == MODE_TILE_HARDNESS)
4395 	{
4396 	  sprintf(msg, "X:%d Y:%d: Density index %d  Z to harden, X to soften, A for low-hard, S for ???.\n"
4397 		  "Alt+X/A/S to fill hardness. Shift+direction for larger brush. ENTER or ESC to exit.",
4398 		  (spr[1].x / 9) -9,(spr[1].y / 9) +1, hard_tile);
4399 	}
4400 
4401       if (mode == MODE_SPRITE_PICKER)
4402 	{
4403 
4404 	  if (sp_seq == 0)
4405 	    {
4406 	      sprintf(msg, "Choose sequence and press ENTER.  ] for next page, [ for previous. ESC or TAB to exit. (now on page %d)",
4407 		      1+(sp_picker / 96));
4408 	    } else
4409 	    {
4410 	      sprintf(msg, "Choose a sprite from sequence %d.  Enter to place sprite, TAB to exit or ESC to return to previous screen."
4411 		      " E to edit depth dot and hardbox",
4412 		      sp_seq);
4413 
4414 	    }
4415 	}
4416 
4417       if (mode == MODE_SCREEN_SPRITES)
4418 	{
4419 
4420 	  char crap7[80];
4421 	  if (sp_screenmatch) strcpy(crap7, "ScreenMatch is ON."); else strcpy(crap7, "ScreenMatch is OFF");
4422 
4423 	  sprintf(msg, "Press ENTER to pickup/putdown sprite. Space to show hardness.  E to edit/pick new sprite. SHIFT to move fast. (S)tamp sprite. ] &"
4424 		  "[ to scale (now at %d). DEL to erase sprite.  Press 1 through 9 to change sprite attributes. (hold alt or shift for more)  Last sprite touched: %d  %s (M to toggle)"
4425 		  "Hold Z or X + arrow keys to trim a sprite. V to change Vision mode. X: %d Y: %d",
4426 		  spr[1].size,last_sprite_added,crap7, spr[1].x, spr[1].y);
4427 
4428 	  //lets draw the depth dot
4429 
4430 
4431 
4432 
4433 	}
4434 
4435 
4436       if (mode == MODE_SPRITE_HARDNESS)
4437 	{
4438 
4439 
4440 	  if (sp_mode == 0)
4441 	    {
4442 	      sprintf(msg, "Editing depth dot for Seq %d, frame %d.  SHIFT to move fast. Control to move one"
4443 		      " pixel.  TAB for next edit option. ESC to return to sprite picker. S to save to dink.ini.",
4444 		      sp_seq,sp_frame);
4445 
4446 	    }
4447 
4448 	  if ( (sp_mode == 1) )
4449 
4450 	    {
4451 	      sprintf(msg, "Editing hardbox up left cordinate for Seq %d, frame %d.  SHIFT to move fast. Control to move one"
4452 		      " pixel.  TAB for next edit option. ESC to return to sprite picker. S to save to dink.ini. X: %d Y: %d",
4453 		      sp_seq,sp_frame, k[seq[sp_seq].frame[sp_frame]].hardbox.left,
4454 		      k[seq[sp_seq].frame[sp_frame]].hardbox.top);
4455 
4456 	    }
4457 
4458 	  if ( (sp_mode == 2) )
4459 
4460 	    {
4461 	      sprintf(msg, "Editing hardbox down right cordinate for Seq %d, frame %d.  SHIFT to move fast. Control to move one"
4462 		      " pixel.  TAB for next edit option. ESC to return to sprite picker. S to save to dink.ini. X: %d Y: %d",
4463 		      sp_seq,sp_frame, k[seq[sp_seq].frame[sp_frame]].hardbox.right,
4464 		      k[seq[sp_seq].frame[sp_frame]].hardbox.bottom);
4465 
4466 	    }
4467 
4468 
4469 
4470 
4471 
4472 
4473 	}
4474 
4475 
4476       if (mode == MODE_SCREEN_HARDNESS)
4477 	{
4478 	  int screentile = xy2screentile(spr[1].x, spr[1].y);
4479 	  int sourcetile = pam.t[screentile].square_full_idx0;
4480 	  int defaulthardness = hmap.btile_default[sourcetile];
4481 	  int curhardness = realhard(screentile);
4482 	  char str[100];
4483 	  if (defaulthardness == curhardness)
4484 	    sprintf(str, "Current %03d (default %03d tile %03d)", curhardness, defaulthardness, sourcetile);
4485 	  else
4486 	    sprintf(str, "Current %03d (default %03d tile %03d) (alternate)", curhardness, defaulthardness, sourcetile);
4487 
4488 	  sprintf(msg, "Alternative Tile Hardness Selector: Press S to stamp this tiles hardness."
4489 		  "  DEL to remove alternate hardness."
4490 		  "  C to copy from current block."
4491 		  "  [ & ] to cycle."
4492 		  "  ESCAPE to exit.\n"
4493 		  "%s", str);
4494 	}
4495 
4496       {
4497 	int x;
4498 	for (x = 0; x < 256; x++)
4499 	  {
4500 	    if (getkeystate(x))
4501 	      {
4502 		sprintf(msg + strlen(msg), " (Key %i)", x);
4503 	      }
4504 	  }
4505       }
4506       rcRect.left = 0;
4507       rcRect.top = 400;
4508       if (mode == MODE_TILE_HARDNESS) rcRect.top = 450;
4509       rcRect.right = 590;
4510       rcRect.bottom = 480;
4511       if (show_display)
4512 	{
4513 	  /* Display help message at the bottom of the screen */
4514 /* 	  DrawText(hdc,msg,lstrlen(msg),&rcRect,DT_WORDBREAK); */
4515 	  // FONTS
4516 	  print_text_wrap(msg, &rcRect, 0, 0, FONT_SYSTEM);
4517 	}
4518 
4519 /*       lpDDSBack->ReleaseDC(hdc); */
4520 
4521 /*     } /\* GetDC(&hdc) *\/ */
4522 
4523 
4524   if ((mode == MODE_MINIMAP))
4525     {
4526       if (sjoy.charjustpressed['z'])
4527 	{
4528 	  if (show_display) show_display = /*false*/0;
4529 	  else show_display = /*true*/1;
4530 	}
4531     }
4532 
4533 
4534   if ( (mode == MODE_SCREEN_SPRITES) | (mode == MODE_SCREEN_TILES) )
4535     {
4536       /* Show sprites info */
4537       if (getcharstate('i'))
4538 	{
4539 	  int j;
4540 	  for (j = 1; j < 100; j++)
4541 	    {
4542 	      if (pam.sprite[j].active == /*true*/1)
4543 		{
4544 
4545 /* 		  ddbltfx.dwSize = sizeof(ddbltfx); */
4546 /* 		  ddbltfx.dwFillColor = 230; */
4547 
4548 		  //info on the sprites  sprite info
4549 /* 		  int temp = s_index[pam.sprite[j].seq].s + pam.sprite[j].frame; */
4550 
4551 
4552 		  int sprite2 = add_sprite_dumb(pam.sprite[j].x,pam.sprite[j].y,0,
4553 						pam.sprite[j].seq,pam.sprite[j].frame,
4554 						pam.sprite[j].size);
4555 		  rect_copy(&spr[sprite2].alt , &pam.sprite[j].alt);
4556 
4557 		  get_box(sprite2, &box_crap, &box_real);
4558 
4559 		  spr[sprite2].active = /*false*/0;
4560 
4561 		  //box_crap.top = box_crpam.sprite[j].y - 25;
4562 		  box_crap.bottom = box_crap.top + 50;
4563 		  box_crap.left = box_crap.left + ( (box_crap.right - box_crap.left) / 2);
4564 		  box_crap.right = box_crap.left+ 50;
4565 
4566 /* 		  ddrval = lpDDSBack->Blt(&box_crap ,k[seq[10].frame[5]].k,&k[seq[10].frame[5]].box, DDBLT_WAIT, &ddbltfx); */
4567 		  //       	if (ddrval != DD_OK) dderror(ddrval);
4568 		  // GFX
4569 		  {
4570 		    SDL_Rect dst;
4571 		    SDL_Surface *sprite = GFX_k[seq[10].frame[5]].k;
4572 		    dst.x = box_crap.left;
4573 		    dst.y = box_crap.top;
4574 		    /* Simplified blit, no scaling, the sprite is already 50x50 */
4575 		    /* We need to avoid transparency though */
4576 		    Uint32 colorkey = sprite->format->colorkey;
4577 		    SDL_SetColorKey(sprite, 0, 0); /* Temporarily disable transparent color */
4578 		    SDL_BlitSurface(sprite, NULL, GFX_lpDDSBack, &dst);
4579 		    SDL_SetColorKey(sprite, SDL_SRCCOLORKEY, colorkey);
4580 		  }
4581 
4582 		  char crap5[200];
4583 
4584                   char crap6[20];
4585 
4586 		  strcpy(crap6,"");
4587 		  if (pam.sprite[j].hard == 0) strcpy(crap6,"HARD");
4588 
4589 		  sprintf(crap5, "B: %d %s",pam.sprite[j].brain,crap6);
4590 
4591 		  if (pam.sprite[j].type == 0)
4592 		    {
4593 
4594 		      SaySmall(crap5,box_crap.left+3,box_crap.top+3,255,255,255);
4595 		    }
4596 
4597 		  if (pam.sprite[j].type > 0)
4598 		    {
4599 		      SaySmall(crap5,box_crap.left+3,box_crap.top+3,255,0,0);
4600 		    }
4601 		  if (strlen(pam.sprite[j].script) > 1)
4602 		    SaySmall(pam.sprite[j].script,box_crap.left+3,box_crap.top+35,255,0,0);
4603 
4604 		  sprintf(crap6,"%d",j);
4605 
4606 		  SaySmall(crap6,box_crap.left+20,box_crap.top-15,0,255,0);
4607 
4608 
4609 		}
4610 	    }
4611 	}
4612 
4613     }
4614   if (mode == MODE_SPRITE_HARDNESS)
4615     {
4616 /*       ddbltfx.dwSize = sizeof(ddbltfx); */
4617 /*       ddbltfx.dwFillColor = 230; */
4618 
4619       if (sp_mode == 0)
4620 	{
4621 	  //draw depth dot for sprite attribute edit
4622 
4623 /* 	  box_crap.top = spr[2].y; */
4624 /* 	  box_crap.bottom = spr[2].y+1; */
4625 /* 	  box_crap.left = spr[2].x - 20; */
4626 /* 	  box_crap.right = spr[2].x + 20; */
4627 
4628 
4629 /* 	  ddrval = lpDDSBack->Blt(&box_crap ,NULL,NULL, DDBLT_COLORFILL| DDBLT_WAIT, &ddbltfx); */
4630 /* 	  if (ddrval != DD_OK) dderror(ddrval); */
4631 	  // GFX
4632 	  {
4633 	    SDL_Rect dst;
4634 	    dst.x = spr[2].x - 20;
4635 	    dst.y = spr[2].y;
4636 	    dst.w = 40;
4637 	    dst.h = 1;
4638 	    SDL_FillRect(GFX_lpDDSBack, &dst, SDL_MapRGB(GFX_lpDDSTwo->format, 41, 0, 49));
4639 	  }
4640 
4641 /* 	  box_crap.top = spr[2].y-20; */
4642 /* 	  box_crap.bottom = spr[2].y+20; */
4643 /* 	  box_crap.left = spr[2].x; */
4644 /* 	  box_crap.right = spr[2].x +1; */
4645 
4646 
4647 /* 	  ddrval = lpDDSBack->Blt(&box_crap ,NULL,NULL, DDBLT_COLORFILL| DDBLT_WAIT, &ddbltfx); */
4648 /* 	  if (ddrval != DD_OK) dderror(ddrval); */
4649 	  // GFX
4650 	  {
4651 	    SDL_Rect dst;
4652 	    dst.x = spr[2].x;
4653 	    dst.y = spr[2].y - 20;
4654 	    dst.w = 1;
4655 	    dst.h = 40;
4656 	    SDL_FillRect(GFX_lpDDSBack, &dst, SDL_MapRGB(GFX_lpDDSTwo->format, 41, 0, 49));
4657 	  }
4658 	}
4659 
4660       if  ((sp_mode == 1) | (sp_mode == 2) )
4661 	{
4662 	  //draw hardbox dot for sprite attribute edit
4663 
4664 /* 	  box_crap = k[seq[sp_seq].frame[sp_frame]].hardbox; */
4665 
4666 /* 	  OffsetRect(&box_crap,320,200); */
4667 
4668 
4669 /* 	  ddrval = lpDDSBack->Blt(&box_crap ,NULL,NULL, DDBLT_COLORFILL| DDBLT_WAIT, &ddbltfx); */
4670 /* 	  if (ddrval != DD_OK) Msg("Error with drawing hard block... you know why."); */
4671 	  // GFX
4672 	  {
4673 	    SDL_Rect dst;
4674 	    dst.x = k[seq[sp_seq].frame[sp_frame]].hardbox.left + 320;
4675 	    dst.y = k[seq[sp_seq].frame[sp_frame]].hardbox.top + 200;
4676 	    dst.w = k[seq[sp_seq].frame[sp_frame]].hardbox.right - k[seq[sp_seq].frame[sp_frame]].hardbox.left;
4677 	    dst.h = k[seq[sp_seq].frame[sp_frame]].hardbox.bottom - k[seq[sp_seq].frame[sp_frame]].hardbox.top;
4678 	    SDL_FillRect(GFX_lpDDSBack, &dst, SDL_MapRGB(GFX_lpDDSTwo->format, 41, 0, 49));
4679 	  }
4680 	}
4681     }
4682 
4683 
4684   if (in_enabled)
4685     {
4686       //text window is open, lets act accordingly
4687       //check_joystick();
4688       if (getkeystate(SDLK_RETURN) || getkeystate(SDLK_KP_ENTER))
4689 	{
4690 	  //exit text mode
4691 
4692 	  if (in_command == 2)
4693 	    {
4694 	      if (in_string != NULL)
4695 		strcpy(in_string, in_temp);
4696 	      else
4697 		log_error("Error, in_char pointer not set, can't issue a value.");
4698 	    }
4699 
4700 	  if (in_command == 1)
4701 	    {
4702 	      if (in_int != NULL)
4703 		{
4704 		  char *stop;
4705 		  int in_crap = strtol(in_temp, &stop,10);
4706 
4707 		  in_crap2 = in_crap;
4708 
4709 		  if ((old_command == INPUT_SCREEN_MIDI) || (old_command == INPUT_SCREEN_TYPE))
4710 		    load_info();
4711 
4712 		  *in_int = in_crap2;
4713 
4714 		  if ((old_command == INPUT_SCREEN_MIDI) || (old_command == INPUT_SCREEN_TYPE))
4715 		    save_info();
4716 		}
4717 	      else
4718 		{
4719 		  log_error("in_int pointer not set, can't issue a value.");
4720 		}
4721 	    }
4722 
4723 	  in_command = 0;
4724 
4725 	  if (in_huh == 3)
4726 	    {
4727 	      if (in_crap2 == 3)
4728 		{
4729 		  //default duck settings
4730 		  sp_speed = 1;
4731 		  sp_base_walk = 20;
4732 		  sp_base_idle = -1;
4733 		  sp_base_hit = -1;
4734 		  sp_base_attack = -1;
4735 		  sp_timer = 33;
4736 		  sp_type = 1;
4737 		  sp_que = 0;
4738 		  sp_hard = 1;
4739 		}
4740 
4741 	      if (in_crap2 == 4)
4742 		{
4743 		  //default pig settings
4744 		  sp_speed = 1;
4745 		  sp_base_walk = 40;
4746 		  sp_base_idle = -1;
4747 		  sp_base_hit = -1;
4748 		  sp_base_attack = -1;
4749 		  sp_timer = 66;
4750 		  sp_type = 1;
4751 		  sp_que = 0;
4752 		  sp_hard = 1;
4753 		}
4754 
4755 	      if (in_crap2 == 9)
4756 		{
4757 		  //default diag settings
4758 		  sp_speed = 1;
4759 		  sp_base_walk =  (sp_seq / 10) * 10;
4760 		  sp_base_idle = -1;
4761 		  sp_base_hit = -1;
4762 		  sp_base_attack = -1;
4763 		  sp_timer = 66;
4764 		  sp_type = 1;
4765 		  strcpy(sp_script, "");
4766 		  sp_que = 0;
4767 		  sp_hard = 1;
4768 		}
4769 
4770 	      if (in_crap2 == 10)
4771 		{
4772 		  //default diag settings
4773 		  sp_speed = 1;
4774 		  sp_base_walk =  (sp_seq / 10) * 10;
4775 		  sp_base_idle = -1;
4776 		  sp_base_hit = -1;
4777 		  sp_base_attack = -1;
4778 		  sp_timer = 66;
4779 		  sp_type = 1;
4780 		  strcpy(sp_script, "");
4781 		  sp_que = 0;
4782 		  sp_hard = 1;
4783 		}
4784 	    }
4785 
4786 	  in_enabled = 0;
4787 	}
4788       else if (sjoy.keyjustpressed[SDLK_ESCAPE])
4789 	{
4790 	  in_enabled = 0;
4791 	}
4792       else if (sjoy.keyjustpressed[SDLK_BACKSPACE])
4793 	//	if (getkey(8)) //this is a much faster backspace than the above
4794 	{
4795 	  if (strlen(in_temp) > 0)
4796 	    in_temp[strlen(in_temp)-1] = 0;
4797 
4798 	}
4799       else if (strlen(in_temp) < in_max)
4800 	{
4801 	  if (isprint(sjoy.last_unicode))
4802 	    sprintf(in_temp + strlen(in_temp), "%c", sjoy.last_unicode);
4803 	}
4804 
4805       if (in_enabled)
4806 	{
4807 	  Say(in_temp,260,200);
4808 	}
4809       else
4810 	{
4811 	  /* Redraw last mode */
4812 	  if (mode == MODE_MINIMAP)
4813 	    {
4814 	      if (old_command == INPUT_MINIMAP_LOAD)
4815 		draw_minimap_buff();
4816 	      else
4817 		draw_minimap();
4818 	    }
4819 	  else
4820 	    {
4821 	      draw_map();
4822 	    }
4823 	}
4824     }
4825 
4826 
4827   if (in_master != 0) check_in();
4828 
4829 
4830   //open a text window?
4831 
4832   if (in_onflag)
4833     {
4834       //start it up
4835 
4836       //copy screen to Two
4837 /*       SetRect(&rcRect, 0, 0, 640, 480); */
4838 /*       ddrval = lpDDSTwo->Blt( &rcRect, lpDDSBack, &rcRect, DDBLT_WAIT, NULL); */
4839 /*       if (ddrval != DD_OK) dderror(ddrval); */
4840       // GFX
4841       // TODO: use copy_front_to_two()
4842       SDL_BlitSurface(GFX_lpDDSBack, NULL, GFX_lpDDSTwo, NULL);
4843 
4844 
4845       strcpy(in_temp,in_default);
4846       in_x = 270;
4847       in_y = 190;
4848       in_onflag = /*false*/0;
4849       in_enabled = /*true*/1;
4850 
4851 
4852 
4853     }
4854 
4855 
4856 
4857   //MAIN PAGE FLIP DONE HERE
4858 
4859 
4860   if (getkeystate(SDLK_SPACE) && (mode != 1))
4861     {
4862       drawallhard();
4863 
4864     }
4865 
4866 
4867 
4868 
4869   if (draw_map_tiny != -1)
4870     {
4871 
4872       int huh = 0;
4873       //if (draw_map_tiny > 32) huh = 1;
4874       shrink_screen_to_these_cords(  (draw_map_tiny-1) * 20 - ((((draw_map_tiny-1) / 32) * 640) )   ,   ((((draw_map_tiny-1) / 32)- huh) * 20));
4875       //Msg("Just flipped # %d", draw_map_tiny);
4876 
4877     }
4878 
4879 
4880 
4881 /*   if (!windowed) */
4882 /*     { */
4883 
4884 /*       while( 1 ) */
4885 /* 	{ */
4886 /* 	  ddrval = lpDDSPrimary->Flip(NULL,DDFLIP_WAIT ); */
4887 /* 	  if( ddrval == DD_OK ) */
4888 /* 	    { */
4889 /* 	      break; */
4890 /* 	    } */
4891 /* 	  if( ddrval == DDERR_SURFACELOST ) */
4892 /* 	    { */
4893 /* 	      ddrval = restoreAll(); */
4894 /* 	      if( ddrval != DD_OK ) */
4895 /* 		{ */
4896 /* 		  break; */
4897 /* 		} */
4898 /* 	    } */
4899 /* 	  if( ddrval != DDERR_WASSTILLDRAWING ) */
4900 /* 	    { */
4901 
4902 /* 	      dderror(ddrval); */
4903 /* 	    } */
4904 /* 	}  */
4905 
4906 /*       if (draw_map_tiny != -1)  */
4907 /* 	{ */
4908 	  //extra flip
4909 
4910 /* 	  ddrval = lpDDSPrimary->Flip(NULL,DDFLIP_WAIT ); */
4911 /* 	} */
4912 
4913 
4914 /*     } else */
4915 /*     { */
4916       flip_it();
4917       /*
4918       //windowed mode, no flipping
4919       p.x = 0; p.y = 0;
4920       ClientToScreen(hWndMain, &p);
4921       GetClientRect(hWndMain, &rcRectDest);
4922 
4923       //rcRectDest.top += winoffset;
4924       rcRectDest.bottom = 480;
4925       rcRectDest.right = 640;
4926 
4927       OffsetRect(&rcRectDest, p.x, p.y);
4928       SetRect(&rcRectSrc, 0, 0, 640, 480);
4929 
4930 
4931 
4932 
4933       ddbltfx.dwSize = sizeof(ddbltfx);
4934 
4935       ddbltfx.dwDDFX = DDBLTFX_NOTEARING;
4936       ddrval = lpDDSPrimary->Blt( &rcRectDest, lpDDSBack, &rcRectSrc, DDBLT_DDFX | DDBLT_WAIT, &ddbltfx);
4937       */
4938 /*     } */
4939 } /* updateFrame */
4940 
4941 
load_editor_sounds()4942 int load_editor_sounds()
4943 {
4944   int i;
4945 
4946   if (InitSound() < 0)
4947     return -1;
4948 
4949   /*
4950    * Load all sounds
4951    */
4952   for(i = 0; i < NUM_SOUND_EFFECTS; i++)
4953     {
4954       char *filename = szSoundEffects[i];
4955       log_info("Loading sound %s [%d]", filename, i);
4956 
4957       /* Try from resources */
4958       SDL_RWops* rwops;
4959       rwops = find_resource_as_rwops(filename);
4960       if (rwops != NULL)
4961 	CreateBufferFromWaveFile_RW(rwops, 1, i);
4962       else
4963 	log_error("Cannot load sound effect %s, from resources or from %s",
4964 		  filename, paths_getpkgdatadir());
4965     }
4966   return 1;
4967 }
4968 
4969 
4970 /*
4971  * doInit - do work required for every instance of the application:
4972  *                create the window, initialize data
4973  */
doInit(int argc,char * argv[])4974 static int doInit(int argc, char *argv[])
4975 {
4976   dinkedit = 1;
4977 
4978   /* New initialization */
4979   if (init(argc, argv, "tiles/esplash.bmp") < 0)
4980     return -1;
4981 
4982   /* Difference with the game: attempt to get a Unicode key state
4983      (to handle '[' and ']' in a layout-independant way, namely) */
4984   SDL_EventState(SDL_KEYUP, SDL_ENABLE);
4985 
4986 
4987   /** SETUP **/
4988   /* Manually setup basic sequences */
4989   {
4990     int i = 1;
4991     for (; i <= 4; i++)
4992       {
4993 	spr[i].active = 0;
4994 	spr[i].x = 10;
4995 	spr[i].y = 10;
4996 	spr[i].my = (rand() % 3)+1;
4997 	spr[i].mx = (rand() % 3)+1;
4998 	spr[i].seq = 1;
4999 	spr[i].speed = (rand() % 40)+1;
5000 	spr[i].brain = 2;
5001 	spr[i].pseq = 10;
5002 	spr[i].pframe = 3;
5003 	spr[i].size = 100;
5004       }
5005   }
5006 
5007   spr[1].active = /*TRUE*/1;
5008   spr[1].x = 0;
5009   spr[1].y = 0;
5010   spr[1].speed = 20;
5011   spr[1].brain = 1;
5012   rect_set(&spr[1].alt,0,0,0,0);
5013   spr[1].pseq = 10;
5014   spr[1].pframe = 3;
5015   spr[1].seq = 0;
5016   spr[1].seq = 2;
5017 
5018   //sprite sequence setup
5019   seq[1].frame[1] = seq[10].frame[1];
5020   seq[1].frame[2] = seq[10].frame[2];
5021   seq[1].frame[3] = seq[10].frame[3];
5022   // FIX: end of sequence is 0, not -1. This made the editor crash.
5023   // seq[1].frame[4] = -1;
5024   seq[1].frame[4] = 0;
5025 
5026   seq[1].delay[1] = 50;
5027   seq[1].delay[2] = 50;
5028   seq[1].delay[3] = 50;
5029   seq[1].delay[4] = 50;
5030 
5031   seq[2].frame[1] = seq[10].frame[4];
5032   seq[2].frame[2] = seq[10].frame[4];
5033   seq[2].frame[3] = seq[10].frame[4];
5034   seq[2].frame[4] = 0;
5035 
5036   seq[2].delay[1] = 10;
5037   seq[2].delay[2] = 10;
5038   seq[2].delay[3] = 10;
5039   seq[2].delay[4] = 10;
5040 
5041   seq[3].frame[1] = seq[10].frame[5];
5042   seq[3].frame[2] = seq[10].frame[5];
5043   seq[3].frame[3] = seq[10].frame[5];
5044   seq[3].frame[4] = 0;
5045 
5046   seq[3].delay[1] = 5;
5047   seq[3].delay[2] = 5;
5048   seq[3].delay[3] = 5;
5049   seq[3].delay[4] = 5;
5050 
5051   seq[4].frame[1] = seq[10].frame[1];
5052   seq[4].frame[2] = seq[10].frame[1];
5053   seq[4].frame[3] = 0;
5054   seq[4].frame[4] = 0;
5055 
5056   seq[4].delay[1] = 2;
5057   seq[4].delay[2] = 2;
5058   seq[4].delay[3] = 2;
5059   seq[4].delay[4] = 2;
5060 
5061   if (sound_on)
5062     load_editor_sounds();
5063 
5064   mode = MODE_DIALOG;
5065   cur_tile = 1;
5066   load_info();
5067 
5068   playl = 20;
5069   playx = 620;
5070   playy = 480;
5071   sp_seq = 0;
5072 
5073   return 0;
5074 }
5075 
5076 
main(int argc,char * argv[])5077 int main(int argc, char *argv[])
5078 {
5079   /* Initialize/setup */
5080   int init_ret = doInit(argc, argv);
5081 
5082   if (init_ret == 0)
5083     {
5084       /* Main loop */
5085       while(1)
5086 	{
5087 	  SDL_Event event;
5088 	  SDL_PumpEvents();
5089 
5090 	  /* Check if we need to quit */
5091 	  if (SDL_PeepEvents(&event, 1, SDL_GETEVENT,
5092 			     SDL_EVENTMASK(SDL_QUIT)) > 0)
5093 	    break;
5094 
5095 	  /* Fullscreen <-> window */
5096 	  if ((SDL_GetModState()&KMOD_ALT) && GetKeyboard(SDLK_RETURN))
5097 	    {
5098 	      /* Note: as of 2008-08-07, only works under X11 */
5099 	      int success = SDL_WM_ToggleFullScreen(GFX_lpDDSBack);
5100 	      if (!success)
5101 		/* Try using a more portable way: */
5102 		gfx_toggle_fullscreen();
5103 	    }
5104 
5105 	  updateFrame();
5106 
5107 	  /* Clean-up finished sounds: normally this is done by
5108 	     SDL_mixer but since we're using effects tricks to
5109 	     stream&resample sounds, we need to do this manually. */
5110 	  sfx_cleanup_finished_channels();
5111 	}
5112     }
5113 
5114   /* Uninitialize/clean-up */
5115   finiObjects();
5116 
5117   if (init_ret < 0)
5118     return EXIT_FAILURE;
5119   else
5120     return EXIT_SUCCESS;
5121 }
5122