idput.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. /* $Id: idput.cc,v 1.2 1999/01/17 20:35:41 mental Exp $
  2. * MegaZeux
  3. *
  4. * Copyright (C) 1998 MenTaLguY - mentalg@geocities.com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. /* edited for mzx s3 by JZig */
  21. #include <stdlib.h>
  22. #include "const.h"
  23. #include "graphics.h"
  24. #define OMIT_IDCHAR_DECLARATIONS
  25. #include "data.h"
  26. #include "idput.h"
  27. /* Unfortunately, this needs to be C++, since C doesn't consider the below
  28. to be true constants */
  29. unsigned char id_chars[455];
  30. unsigned char const *thin_line = id_chars+128;
  31. unsigned char const *thick_line = thin_line+16;
  32. unsigned char const *ice_anim = thick_line+16;
  33. unsigned char const *lava_anim = ice_anim+4;
  34. unsigned char const *low_ammo = lava_anim+3;
  35. unsigned char const *hi_ammo = low_ammo+1;
  36. unsigned char const *lit_bomb = hi_ammo+1;
  37. unsigned char const *energizer_glow = lit_bomb+7;
  38. unsigned char const *explosion_colors = energizer_glow+8;
  39. unsigned char const *horiz_door = explosion_colors+4;
  40. unsigned char const *vert_door = horiz_door+1;
  41. unsigned char const *cw_anim = vert_door+1;
  42. unsigned char const *ccw_anim = cw_anim+4;
  43. unsigned char const *open_door = ccw_anim+4;
  44. unsigned char const *transport_anims = open_door+32;
  45. unsigned char const *trans_north = transport_anims;
  46. unsigned char const *trans_south = trans_north+4;
  47. unsigned char const *trans_east = trans_south+4;
  48. unsigned char const *trans_west = trans_east+4;
  49. unsigned char const *trans_all = trans_west+4;
  50. unsigned char const *thick_arrow = transport_anims+20;
  51. unsigned char const *thin_arrow = thick_arrow+4;
  52. unsigned char const *horiz_lazer = thin_arrow+4;
  53. unsigned char const *vert_lazer = horiz_lazer+4;
  54. unsigned char const *fire_anim = vert_lazer+4;
  55. unsigned char const *fire_colors = fire_anim+6;
  56. unsigned char const *life_anim = fire_colors+6;
  57. unsigned char const *life_colors = life_anim+4;
  58. unsigned char const *ricochet_panels = life_colors+4;
  59. unsigned char const *mine_anim = ricochet_panels+2;
  60. unsigned char const *shooting_fire_anim = mine_anim+2;
  61. unsigned char const *shooting_fire_colors = shooting_fire_anim+2;
  62. unsigned char const *seeker_anim = shooting_fire_colors+2;
  63. unsigned char const *seeker_colors = seeker_anim+4;
  64. unsigned char const *whirlpool_glow = seeker_colors+4;
  65. unsigned char *bullet_char = (unsigned char *)whirlpool_glow+4;
  66. unsigned char *player_char = bullet_char+12;
  67. unsigned char *player_color = player_char+4;
  68. unsigned char *missile_color = player_color+1;
  69. unsigned char *_bullet_color = missile_color+1;
  70. unsigned char *id_dmg = _bullet_color+3;
  71. unsigned char def_id_chars[455] = {
  72. /* id_chars */
  73. 32,178,219,6,0,255,177,255,233,254,255,254,255,178,177,176, /* 0-15 */
  74. 254,255,0,0,176,24,25,26,27,0,0,160,4,4,3,9, /* 16-31 */
  75. 150,7,176,0,11,0,177,12,10,0,0,162,161,0,0,22, /* 32-47 */
  76. 196,0,7,255,255,255,255,159,0,18,29,0,206,0,0,0, /* 48-63 */
  77. '?',178,0,151,152,153,154,32,0,42,0,0,255,255,0,0, /* 64-79 */
  78. 235,236,5,42,2,234,21,224,127,149,5,227,0,0,172,173, /* 80-95 */
  79. '?',0, /* 96-97 */
  80. '?','?','?','?','?','?','?','?', /* 98-121 */
  81. '?','?','?','?','?','?','?','?',
  82. '?','?','?','?','?','?','?','?',
  83. 0,0,0,226,232,0, /* 122-127 */
  84. /* thin_line */
  85. 249,179,179,179, /* None, N, S, NS */
  86. 196,192,218,195, /* E, NE, SE, NSE */
  87. 196,217,191,180, /* W, NW, SW, NSW */
  88. 196,193,194,197, /* EW, NEW, SEW, NSEW */
  89. /* thick_line */
  90. 249,186,186,186, /* None, N, S, NS */
  91. 205,200,201,204, /* E, NE, SE, NSE */
  92. 205,188,187,185, /* W, NW, SW, NSW */
  93. 205,202,203,206, /* EW, NEW, SEW, NSEW */
  94. /* ice_anim */
  95. 32,252,253,255, /* Ice animation table */
  96. /* lava_anim */
  97. 176,177,178, /* Lava animation table */
  98. /* low_ammo, hi_ammo */
  99. 163, /* < 10 ammunition pic */
  100. 164, /* > 9 ammunition pic */
  101. /* lit_bomb */
  102. 171,170,169,168,167,166,165, /* Lit bomb animation */
  103. /* energizer_glow */
  104. 1,9,3,11,15,11,3,9, /* Energizer Glow */
  105. /* explosion_colors */
  106. 239,206,76,4, /* Explosion color table */
  107. /* horiz_door, vert_door */
  108. 196, /* Horizontal door pic */
  109. 179, /* Vertical door pic */
  110. /* cw_anim, ccw_anim */
  111. 47,196,92,179, /* CW animation table */
  112. 47,179,92,196, /* CCW animation table */
  113. /* open_door */
  114. 47,47, /* Open 1/2 of type 0 */
  115. 92,92, /* Open 1/2 of type 1 */
  116. 92,92, /* Open 1/2 of type 2 */
  117. 47,47, /* Open 1/2 of type 3 */
  118. 179,196,179,196,179,196,179,196, /* Open full of all types */
  119. 179,196,179,196,179,196,179,196, /* Open full of all types */
  120. 47,47, /* Close 1/2 of type 0 */
  121. 92,92, /* Close 1/2 of type 1 */
  122. 92,92, /* Close 1/2 of type 2 */
  123. 47,47, /* Close 1/2 of type 3 */
  124. /* transport_anims */
  125. 45,94,126,94, /* North */
  126. 86,118,95,118, /* South */
  127. 93,41,62,41, /* East */
  128. 91,40,60,40, /* West */
  129. 94,62,118,60, /* All directions */
  130. /* thick_arrow, thin_arrow */
  131. 30,31,16,17, /* Thick arrows (pusher-style) NSEW */
  132. 24,25,26,27, /* Thin arrows (gun-style) NSEW */
  133. /* horiz_lazer, vert_lazer */
  134. 130,196,131,196, /* Horizontal Lazer Anim Table */
  135. 128,179,129,179, /* Vertical Lazer Anim Table */
  136. /* fire_anim, fire_colors */
  137. 177,178,178,178,177,176, /* Fire animation */
  138. 4,6,12,14,12,6, /* Fire colors */
  139. /* life_anim, life_colors */
  140. 155,156,157,158, /* Free life animation */
  141. 15,11,3,11, /* Free life colors */
  142. /* ricochet_panels */
  143. 28,23, /* Ricochet pics */
  144. /* mine_anim */
  145. 143,144, /* Mine animation */
  146. /* shooting_fire_anim, shooting_fire_colors */
  147. 15,42, /* Shooting Fire Anim */
  148. 12,14, /* Shooting Fire Colors */
  149. /* seeker_anim, seeker_colors */
  150. '/','-','\\','|', /* Seeker animation */
  151. 11,14,10,12, /* Seeker colors */
  152. /* whirlpool_glow */
  153. 11,3,9,15, /* Whirlpool colors (this ends at 306 bytes, where ver */
  154. /* 1.02 used to end) */
  155. /* bullet_char */
  156. 145,146,147,148, /* Player */
  157. 145,146,147,148, /* Neutral */
  158. 145,146,147,148, /* Enemy */
  159. /* player_char */
  160. 2,2,2,2, /*N S E W */
  161. /* player_color, missile_color, bullet_color */
  162. 27,
  163. 8,
  164. 15, /* Player */
  165. 15, /* Neutral */
  166. 15, /* Enemy */
  167. /* id_dmg */
  168. 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0-15 */
  169. 0,0,0,0,0,0,0,0,0,0,100,0,0,0,0,0, /* 16-31 */
  170. 0,0,0,0,0,0,5,0,0,0,0,0,0,0,0,0, /* 32-47 */
  171. 0,0,0,0,0,0,0,0,0,0,0,10,0,10,5,5, /* 48-63 */
  172. 0,0,0,0,0,0,0,0,0,0,0,10,10,0,10,10, /* 64-79 */
  173. 10,0,0,10,10,10,10,10,10,10,10,10,0,0,10,10, /* 80-95 */
  174. 0,0, /* 96-97 */
  175. 0,0,0,0,0,0,0,0, /* 98-121 */
  176. 0,0,0,0,0,0,0,0,
  177. 0,0,0,0,0,0,0,0,
  178. 0,0,0,0,0,0 /* 122-127 */
  179. };
  180. unsigned char bullet_color[3] = {15,15,15};
  181. unsigned char get_special_id_char(unsigned char cell_id,
  182. int offset) {
  183. /* this is, unfortunately, GCC-specific */
  184. int array_x, array_y;
  185. array_x = offset % max_bxsiz;
  186. array_y = offset / max_bxsiz;
  187. switch (cell_id) {
  188. case 4: goto id_line;
  189. case 18:
  190. case 19: goto id_web;
  191. case 25: goto id_ice;
  192. case 26: goto id_lava;
  193. case 35: goto id_ammo;
  194. case 37: goto id_litbomb;
  195. case 41: goto id_door;
  196. case 42: goto id_opendoor;
  197. case 45: goto id_cw;
  198. case 46: goto id_ccw;
  199. case 49: goto id_transport;
  200. case 56: goto id_pusher;
  201. case 59: goto id_lazer;
  202. case 61: goto id_bullet;
  203. case 62: goto id_pusher; /* missile */
  204. case 63: goto id_fire;
  205. case 66: goto id_life;
  206. case 72: goto id_ricochet;
  207. case 74: goto id_mine;
  208. case 75: goto id_pusher;
  209. case 78: goto id_shootingfire;
  210. case 79: goto id_seeker;
  211. case 92:
  212. case 93: goto id_bulletgun; /* spinning gun */
  213. case 97: goto id_missilegun;
  214. case 122: goto id_sensor;
  215. case 123: goto id_robot;
  216. case 124: goto id_robot; /* pushable robot */
  217. case 127: goto id_player;
  218. default: goto id_default;
  219. }
  220. id_line:
  221. {
  222. register int bits=0;
  223. unsigned char *ptr;
  224. ptr = level_id+offset;
  225. if ( array_y > 0 ) {
  226. if ( *(ptr-max_bxsiz) == 4 ) bits = 1;
  227. } else {
  228. bits = 1;
  229. }
  230. if ( array_y < board_ysiz - 1) {
  231. if ( *(ptr+max_bxsiz) == 4 ) bits |= 2;
  232. } else {
  233. bits |= 2;
  234. }
  235. if ( array_x > 0 ) {
  236. if ( *(ptr-1) == 4 ) bits |= 8;
  237. } else {
  238. bits |= 8;
  239. }
  240. if ( array_x < board_xsiz - 1) {
  241. if ( *(ptr+1) == 4 ) bits |= 4;
  242. } else {
  243. bits |= 4;
  244. }
  245. return thick_line[bits];
  246. }
  247. id_web:
  248. {
  249. register int bits=0;
  250. unsigned char *ptr;
  251. ptr = level_id+offset;
  252. if ( array_y > 0 ) {
  253. if ( *(ptr-max_bxsiz) != 0 ) bits = 1;
  254. } else {
  255. bits = 1;
  256. }
  257. if ( array_y < board_ysiz - 1) {
  258. if ( *(ptr+max_bxsiz) != 0 ) bits |= 2;
  259. } else {
  260. bits |= 2;
  261. }
  262. if ( array_x > 0 ) {
  263. if ( *(ptr-1) != 0 ) bits |= 8;
  264. } else {
  265. bits |= 8;
  266. }
  267. if ( array_x < board_xsiz - 1) {
  268. if ( *(ptr+1) != 0 ) bits |= 4;
  269. } else {
  270. bits |= 4;
  271. }
  272. if ( cell_id == 18 ) return thin_line[bits];
  273. return thick_line[bits];
  274. }
  275. id_ice: return ice_anim[level_param[offset]];
  276. id_lava: return lava_anim[level_param[offset]];
  277. id_ammo: return ( level_param[offset] < 10 ) ? *low_ammo : *hi_ammo;
  278. id_litbomb: return lit_bomb[level_param[offset]&0x0F];
  279. id_door: return ( level_param[offset] & 1 ) ? *vert_door : *horiz_door;
  280. id_cw: return cw_anim[level_param[offset]];
  281. id_ccw: return ccw_anim[level_param[offset]];
  282. id_opendoor: return open_door[level_param[offset]&0x1F];
  283. id_transport:
  284. switch (level_param[offset]&0x07) {
  285. case 0: return trans_north[(level_param[offset]>>3)&0x03];
  286. case 1: return trans_south[(level_param[offset]>>3)&0x03];
  287. case 2: return trans_east[(level_param[offset]>>3)&0x03];
  288. case 3: return trans_west[(level_param[offset]>>3)&0x03];
  289. default: return trans_all[(level_param[offset]>>3)&0x03];
  290. }
  291. id_pusher: return thick_arrow[level_param[offset]];
  292. id_lazer:
  293. if ( level_param[offset] & 1 ) {
  294. return vert_lazer[(level_param[offset]>>1)&0x03];
  295. } else {
  296. return horiz_lazer[(level_param[offset]>>1)&0x03];
  297. }
  298. id_bullet: return bullet_char[level_param[offset]];
  299. id_fire: return fire_anim[level_param[offset]];
  300. id_life: return life_anim[level_param[offset]];
  301. id_ricochet: return ricochet_panels[level_param[offset]];
  302. id_mine: return mine_anim[level_param[offset]&1];
  303. id_shootingfire: return shooting_fire_anim[level_param[offset]&1];
  304. id_seeker: return seeker_anim[level_param[offset]&0x03];
  305. id_bulletgun: return thin_arrow[(level_param[offset]>>3)&0x03];
  306. id_missilegun: return thick_arrow[(level_param[offset]>>3)&0x03];
  307. id_sensor: return sensors[level_param[offset]].sensor_char;
  308. id_robot: return robots[level_param[offset]].robot_char;
  309. id_player: return player_char[(player_last_dir >> 4)];
  310. id_default:
  311. return id_chars[cell_id];
  312. }
  313. unsigned char get_id_char(int id_offset) {
  314. unsigned char cell_id, cell_char;
  315. cell_id = level_id[id_offset];
  316. cell_char = id_chars[cell_id];
  317. switch (cell_char) {
  318. case 255: return level_param[id_offset];
  319. case 0: return get_special_id_char(cell_id, id_offset);
  320. default: return cell_char;
  321. }
  322. }
  323. unsigned char get_id_color(int id_offset) {
  324. unsigned char cell_id;
  325. unsigned char normal_color;
  326. unsigned char spec_color;
  327. cell_id = level_id[id_offset];
  328. normal_color = level_color[id_offset];
  329. spec_color = 0;
  330. switch (cell_id) {
  331. case 33: /* energizer */
  332. spec_color = energizer_glow[level_param[id_offset]];
  333. break;
  334. case 38: /* explosion */
  335. normal_color = explosion_colors[level_param[id_offset]&0x0F];
  336. goto no_spec;
  337. case 63: /* fire */
  338. spec_color = fire_colors[level_param[id_offset]];
  339. break;
  340. case 66: /* life */
  341. spec_color = life_colors[level_param[id_offset]];
  342. break;
  343. case 67:
  344. case 68:
  345. case 69:
  346. case 70: /* whirlpool */
  347. spec_color = whirlpool_glow[cell_id-67];
  348. break;
  349. case 78: /* shooting fire */
  350. spec_color = shooting_fire_colors[level_param[id_offset]&1];
  351. break;
  352. case 79: /* seeker */
  353. spec_color = seeker_colors[level_param[id_offset]&0x03];
  354. break;
  355. case 126: /* scroll */
  356. spec_color = scroll_color;
  357. break;
  358. case 127: /* player */
  359. normal_color = *player_color;
  360. default:
  361. goto no_spec;
  362. }
  363. if (!( spec_color & 0xF0 ) ) {
  364. normal_color &= 0xF0;
  365. normal_color |= (spec_color & 0x0F);
  366. } else {
  367. normal_color = spec_color;
  368. }
  369. no_spec:
  370. if (!( normal_color & 0xF0 ) ) {
  371. normal_color |= (level_under_color[id_offset] & 0xF0);
  372. }
  373. return normal_color;
  374. }
  375. void _id_put(unsigned char x_pos, unsigned char y_pos, int array_x,
  376. int array_y, int ovr_x, int ovr_y, void *vid_seg)
  377. {
  378. int array_offset, overlay_offset;
  379. unsigned char c, color;
  380. array_offset = array_y * max_bxsiz + array_x;
  381. if ( !( overlay_mode & 128 )
  382. && ( overlay_mode & 3 ) && ((overlay_mode & 3) != 3)){
  383. if ( overlay_mode & 2 ) {
  384. overlay_offset = ovr_y * max_bxsiz + ovr_x;
  385. } else {
  386. overlay_offset = array_offset;
  387. }
  388. c = overlay[overlay_offset];
  389. color = overlay_color[overlay_offset];
  390. if ( c == 32 ) {
  391. c = get_id_char(array_offset);
  392. color = get_id_color(array_offset);
  393. } else {
  394. if ( !( color & 0xF0 ) && !( overlay_mode & 64 ) ) {
  395. color = ( color & 0x0F )
  396. | ( get_id_color(array_offset) & 0xF0 );
  397. }
  398. }
  399. } else {
  400. c = get_id_char(array_offset);
  401. color = get_id_color(array_offset);
  402. }
  403. draw_char(c, color, x_pos, y_pos, (unsigned int)vid_seg);
  404. }
  405. extern "C" void id_put(unsigned char x_pos, unsigned char y_pos, int array_x,
  406. int array_y, int ovr_x, int ovr_y, int vid_seg)
  407. {
  408. _id_put(x_pos, y_pos, array_x, array_y, ovr_x, ovr_y, (void *)vid_seg);
  409. }
  410. extern "C" void draw_edit_window(int array_x, int array_y, int vid_seg){
  411. _draw_edit_window(array_x, array_y, (void *)vid_seg);
  412. }
  413. void _draw_edit_window(int array_x, int array_y, void *vid_seg)
  414. {
  415. int viewport_x_size, viewport_y_size;
  416. int x, y;
  417. int a_x, a_y;
  418. viewport_x_size = 80;
  419. viewport_y_size = 19;
  420. if ( board_xsiz < viewport_x_size ) viewport_x_size = board_xsiz;
  421. if ( board_ysiz < viewport_y_size ) viewport_y_size = board_ysiz;
  422. for ( y = 0, a_y = array_y ; y < viewport_y_size ; y++, a_y++ ) {
  423. for ( x = 0, a_x = array_x ; x < viewport_x_size ; x++, a_x++ ) {
  424. _id_put(x, y, a_x, a_y, a_x, a_y, vid_seg);
  425. }
  426. }
  427. }
  428. extern "C" void draw_game_window(int array_x, int array_y, int vid_seg) {
  429. _draw_game_window(array_x, array_y, (void *)vid_seg);
  430. }
  431. void _draw_game_window(int array_x, int array_y, void *vid_seg)
  432. {
  433. int x_limit, y_limit;
  434. int x, y;
  435. int a_x, a_y;
  436. int o_x, o_y;
  437. x_limit = viewport_xsiz;
  438. y_limit = viewport_ysiz;
  439. for ( y = viewport_y, a_y = array_y, o_y = 0 ;
  440. o_y < y_limit ;
  441. y++, a_y++, o_y++ )
  442. {
  443. for ( x = viewport_x, a_x = array_x, o_x = 0 ;
  444. o_x < x_limit ;
  445. x++, a_x++, o_x++ )
  446. {
  447. _id_put(x, y, a_x, a_y, o_x, o_y, vid_seg);
  448. }
  449. }
  450. }