Advertisement
Guest User

Untitled

a guest
Jun 9th, 2014
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 175.58 KB | None | 0 0
  1. /*==========================================================================
  2.  
  3. Dink Smallwood Source Code: Copyright (C) Seth A. Robinson, 1997-2003
  4. www.rtsoft.com
  5.  
  6. This software is provided "as is" without express or implied
  7. warranties. You may freely use, modify and distribute this
  8. source provided that the copyright text below is included in
  9. the resulting source code, for example:
  10. "Portions Copyright (C) Seth A. Robinson, 1997-2003
  11.  
  12. If you use any of this source in a commercial product, you are gently asked
  13. to donate a few bucks to Seth. Check www.codedojo.com for info on how to do that.
  14.  
  15. Donations: If you find this source helpful in some way and use it in a product you are selling, you are
  16. gently asked to donate a couple bucks via codedojo.com. This cash will be used to maintain the site
  17. and hopefully inspire me to get off my duff and release more source.
  18.  
  19.  
  20. Check the license.txt for more info.
  21.  
  22. */
  23.  
  24.  
  25. #define NAME "Dink Smallwood v1.08"
  26. #define TITLE "Dink Smallwood v1.08"
  27. #include <dsound.h>
  28.  
  29. //#define INITGUID
  30. //#define __cplusplus
  31. #include "dinkvar.h"
  32. #include "resource.h"
  33. //#include "speakn.cpp"
  34. const WM_IMDONE = WM_USER+110;
  35.  
  36. int fps_average;
  37.  
  38.  
  39.  
  40. BOOL initFail( HWND hwnd, char mess[200] );
  41. void move(int u, int amount, char kind, char kindy);
  42. void draw_box(RECT box, int color);
  43. void run_through_tag_list_push(int h);
  44. void random_blood(int mx, int my, int h);
  45. int check_if_move_is_legal(int u);
  46. void change_dir_to_diag( int *dir);
  47. int hurt_thing(int h, int damage, int special);
  48.  
  49.  
  50.  
  51. int but_timer = 0;
  52. int water_timer;
  53. bool fire_forward;
  54. int fire_flip;
  55. //const NUM_SOUND_EFFECTS = 10;
  56. int fps_show = 0;
  57.  
  58. //idirectsound
  59. LPDIRECTDRAWCLIPPER lpClipper;
  60.  
  61. BOOL InitSound( HWND );
  62. BOOL DestroySound( void );
  63. BOOL DSDisable( void );
  64. BOOL DSEnable( HWND );
  65.  
  66.  
  67. int drawthistime = true;
  68. int x = 640;
  69. int y = 480;
  70. RECT rc;
  71. int winoffset = 25;
  72. int winoffsetx = 5;
  73.  
  74. int cx;
  75. int cy;
  76. int speed;
  77.  
  78. /*
  79. * restoreAll
  80. *
  81. * restore all lost objects
  82. */
  83.  
  84.  
  85.  
  86. /*
  87. * This function is called if the initialization function fails
  88. */
  89.  
  90.  
  91. void text_draw(int h, HDC hdc)
  92. {
  93.  
  94. char crap[200];
  95. char *cr;
  96. RECT rcRect;
  97. int color = 0;
  98.  
  99. if (spr[h].damage == -1)
  100. {
  101. //redink1 fix for : and '%deee bugs?
  102. strcpy(crap, spr[h].text);
  103. //sprintf(crap, "%s", spr[h].text);
  104. cr = &crap[0];
  105. color = 14;
  106. while( cr[0] == '`')
  107. {
  108. //color code at top
  109. if (cr[1] == '#') color = 13;
  110. if (cr[1] == '1') color = 1;
  111. if (cr[1] == '2') color = 2;
  112. if (cr[1] == '3') color = 3;
  113. if (cr[1] == '5') color = 5;
  114. if (cr[1] == '6') color = 6;
  115. if (cr[1] == '7') color = 7;
  116. if (cr[1] == '8') color = 8;
  117. if (cr[1] == '9') color = 9;
  118. if (cr[1] == '0') color = 10;
  119. if (cr[1] == '$') color = 14;
  120. if (cr[1] == '%') color = 15;
  121. //redink1 support for additional colors
  122. if (cr[1] == '@') color = 12;
  123. if (cr[1] == '!') color = 11;
  124.  
  125. if (cr[1] == '4') color = 4;
  126. cr = &cr[2];
  127. }
  128.  
  129. //Msg("Final is %s.",cr);
  130. if (spr[h].owner == 1000)
  131. {
  132. SetRect(&rcRect,spr[h].x,spr[h].y,spr[h].x+620,spr[h].y+400);
  133. } else
  134. {
  135.  
  136. SetRect(&rcRect,spr[h].x,spr[h].y,spr[h].x+150,spr[h].y+150);
  137.  
  138. if (spr[h].x+150 > 620)
  139. OffsetRect(&rcRect, ((spr[h].x+150)-620) - (((spr[h].x+150)-620) * 2), 0);
  140.  
  141.  
  142.  
  143. }
  144.  
  145. } else
  146. {
  147.  
  148.  
  149. sprintf(crap, "%d", spr[h].damage);
  150. cr = &crap[0];
  151. if (spr[h].brain_parm == 5000)
  152. color = 14;
  153.  
  154.  
  155. if (spr[h].y < 0) spr[h].y = 0;
  156. SetRect(&rcRect,spr[h].x,spr[h].y,spr[h].x+50 ,spr[h].y+50);
  157.  
  158.  
  159. }
  160.  
  161. if (truecolor && (bFadedDown || process_downcycle))
  162. color = 15;
  163.  
  164. SetTextColor(hdc,RGB(8,14,21));
  165. if (spr[h].owner == 1200)
  166. {
  167. //this text has no sprite, and doesn't want to be centered.
  168. DrawText(hdc,cr,strlen(cr),&rcRect,DT_WORDBREAK);
  169.  
  170. OffsetRect(&rcRect,-2,0);
  171. DrawText(hdc,cr,strlen(cr),&rcRect,DT_WORDBREAK);
  172.  
  173. OffsetRect(&rcRect,1,1);
  174. DrawText(hdc,cr,strlen(cr),&rcRect,DT_WORDBREAK);
  175. OffsetRect(&rcRect,0,-2);
  176. DrawText(hdc,cr,strlen(cr),&rcRect,DT_WORDBREAK);
  177.  
  178.  
  179. } else
  180. {
  181.  
  182. DrawText(hdc,cr,strlen(cr),&rcRect,DT_CENTER | DT_WORDBREAK);
  183. OffsetRect(&rcRect,-2,0);
  184. DrawText(hdc,cr,strlen(cr),&rcRect,DT_CENTER | DT_WORDBREAK);
  185.  
  186. OffsetRect(&rcRect,1,1);
  187. DrawText(hdc,cr,strlen(cr),&rcRect,DT_CENTER | DT_WORDBREAK);
  188. OffsetRect(&rcRect,0,-2);
  189. DrawText(hdc,cr,strlen(cr),&rcRect,DT_CENTER | DT_WORDBREAK);
  190.  
  191. }
  192.  
  193. OffsetRect(&rcRect,0,1);
  194.  
  195. //redink1 support for custom colors
  196. if (color >= 1 && color <= 15)
  197. {
  198. SetTextColor(hdc,RGB(font_colors[color].red,font_colors[color].green,font_colors[color].blue));
  199. }
  200. else
  201. {
  202. SetTextColor(hdc,RGB(255,255,255));
  203. }
  204.  
  205. if (spr[h].owner == 1200)
  206.  
  207. DrawText(hdc,cr,strlen(cr),&rcRect,DT_WORDBREAK);
  208. else
  209. DrawText(hdc,cr,strlen(cr),&rcRect,DT_CENTER | DT_WORDBREAK);
  210.  
  211.  
  212. }
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222. HRESULT restoreAll( void )
  223. {
  224.  
  225.  
  226.  
  227. HRESULT ddrval;
  228. char crap[100];
  229. char crap1[10];
  230.  
  231.  
  232.  
  233. ddrval = lpDDSPrimary->Restore();
  234. if( ddrval == DD_OK )
  235. {
  236.  
  237. ddrval = lpDDSTwo->Restore();
  238.  
  239. ddrval = lpDDSTrick->Restore();
  240. ddrval = lpDDSTrick2->Restore();
  241.  
  242.  
  243. /*for (int h=1; h < tile_screens; h++)
  244. {
  245. ddrval = tiles[h]->Restore();
  246.  
  247. if( ddrval == DD_OK )
  248. {
  249. if (h < 10) strcpy(crap1,"0"); else strcpy(crap1, "");
  250. sprintf(crap, "TILES\\TS%s%d.BMP",crap1,h);
  251.  
  252. // sprintf(crap, "TS%d.BMP",h);
  253. DDReLoadBitmap(tiles[h], crap);
  254. Msg("Loading tile %d",h);
  255. }
  256. }
  257. */
  258. Msg("Done with reloading tile set.");
  259. //reload_batch();
  260. Msg("Have all sprites.");
  261.  
  262. //draw_map();
  263. Msg("Drew map.");
  264. if (mode > 2)
  265. {
  266. fill_screen(0);
  267. draw_map_game_background();
  268. if ( *pupdate_status == 1 )
  269. {
  270. draw_status_all();
  271. }
  272. }
  273. }
  274.  
  275. return ddrval;
  276.  
  277.  
  278. } /* restoreAll */
  279.  
  280.  
  281.  
  282. void get_last_sprite(void)
  283. {
  284.  
  285. for (int i = max_sprites_at_once - 1; i > 2; i--)
  286. {
  287.  
  288. if (spr[i].active)
  289. {
  290. last_sprite_created = i;
  291. // Msg("last sprite created is %d.", i);
  292. return;
  293. }
  294. }
  295. }
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309. /*
  310. * DestroySound
  311. *
  312. * Undoes everything that was done in a InitSound call
  313. */
  314. BOOL DestroySound( void )
  315. {
  316. DWORD idxKill;
  317.  
  318. for( idxKill = 0; idxKill < max_sounds; idxKill++ )
  319. {
  320. SoundDestroyEffect( idxKill );
  321. }
  322.  
  323. DSDisable();
  324. return TRUE;
  325.  
  326. } /* DestroySound */
  327.  
  328. /*
  329. * SoundDestroyEffect
  330. *
  331. * Frees up resources associated with a sound effect
  332. */
  333. BOOL SoundDestroyEffect( int sound )
  334. {
  335. if(ssound[sound].sound)
  336. {
  337. ssound[sound].sound->Release();
  338. ssound[sound].sound = NULL;
  339. }
  340. return TRUE;
  341.  
  342. } /* SoundDestryEffect */
  343.  
  344. /*
  345. * SoundLoadEffect
  346. *
  347. * Initializes a sound effect by loading the WAV file from a resource
  348. */
  349. /*BOOL SoundLoadEffect( int sound)
  350. {
  351. if (lpDS && lpSoundEffects[sound] == NULL && *szSoundEffects[sound])
  352. {
  353. //
  354. // use DSLoadSoundBuffer (in ..\misc\dsutil.c) to load
  355. // a sound from a resource.
  356. //
  357. lpSoundEffects[sound] = DSLoadSoundBuffer(lpDS, szSoundEffects[sound]);
  358. if (lpSoundEffects[sound] == NULL) Msg("Damn, got a null one for sound %d.",sound);
  359. }
  360.  
  361. return lpSoundEffects[sound] != NULL;
  362.  
  363. }
  364.  
  365. */
  366. /* SoundLoadEffect */
  367.  
  368.  
  369.  
  370.  
  371. /*
  372. * SoundPlayEffect
  373. *
  374. * Plays the sound effect specified.
  375. * Returns TRUE if succeeded.
  376. */
  377.  
  378.  
  379.  
  380. /*void draw_used( void)
  381. {
  382. for (int x=0; x<768; x++)
  383. {
  384.  
  385. if (map.loc[x+1] == 0)
  386. lpDDSTwo->BltFast( (x) * 20 - ((x / 32) * 640), (x / 32) * 20, k[6].k,
  387. &k[6].box, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
  388.  
  389. if (map.loc[x+1] > 0)
  390. lpDDSTwo->BltFast( (x) * 20 - ((x / 32) * 640), (x / 32) * 20, k[7].k,
  391. &k[7].box, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT );
  392.  
  393. }
  394.  
  395. }
  396. */
  397.  
  398. BOOL keypressed( void )
  399.  
  400. {
  401. for (int x=0; x<256; x++)
  402. {
  403. if (GetKeyboard(x))
  404. {
  405. return(TRUE);
  406. }
  407. }
  408.  
  409. return(FALSE);
  410. }
  411.  
  412. /*
  413. * updateFrame
  414. *
  415. * Decide what needs to be blitted next, wait for flip to complete,
  416. * then flip the buffers.
  417. */
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424. void check_joystick(void)
  425. {
  426.  
  427. HRESULT ddrval;
  428. int total;
  429. //memset(&sjoy,0,sizeof(sjoy));
  430.  
  431. for (int e2=1; e2 <=10; e2++)
  432. {
  433. sjoy.joybit[e2] = FALSE;
  434.  
  435. }
  436. sjoy.right = FALSE;
  437. sjoy.left = FALSE;
  438. sjoy.up = FALSE;
  439. sjoy.down = FALSE;
  440.  
  441. sjoy.rightd = FALSE;
  442. sjoy.leftd = FALSE;
  443. sjoy.upd = FALSE;
  444. sjoy.downd = FALSE;
  445.  
  446. //joystick = false;
  447. if (joystick)
  448. {
  449. memset(&jinfo,0,sizeof(JOYINFOEX));
  450. jinfo.dwSize=sizeof(JOYINFOEX);
  451. jinfo.dwFlags=JOY_RETURNALL;
  452. ddrval = joyGetPosEx(JOYSTICKID1,&jinfo);
  453. if (ddrval == JOYERR_UNPLUGGED) goto pass;
  454.  
  455. total = jinfo.dwButtons;
  456.  
  457. if ((total - 512) >= 0)
  458. {
  459. sjoy.joybit[play.button[10]] = TRUE;
  460. total = total - 512;
  461. }
  462.  
  463. if ((total - 256) >= 0)
  464. {
  465. sjoy.joybit[play.button[9]] = TRUE;
  466. total = total - 256;
  467. }
  468.  
  469. if ((total - 128) >= 0)
  470. {
  471. sjoy.joybit[play.button[8]] = TRUE;
  472. total = total - 128;
  473. }
  474.  
  475. if ((total - 64) >= 0)
  476. {
  477. sjoy.joybit[play.button[7]] = TRUE;
  478. total = total - 64;
  479. }
  480.  
  481. if ((total - 32) >= 0)
  482. {
  483. sjoy.joybit[play.button[6]] = TRUE;
  484. total = total - 32;
  485. }
  486.  
  487. if ((total - 16) >= 0)
  488. {
  489. sjoy.joybit[play.button[5]] = TRUE;
  490. total = total - 16;
  491. }
  492.  
  493. if ((total - 8) >= 0)
  494. {
  495. sjoy.joybit[play.button[4]] = TRUE;
  496. total = total - 8;
  497. }
  498.  
  499. if ((total - 4) >= 0)
  500. {
  501. sjoy.joybit[play.button[3]] = TRUE;
  502. total = total - 4;
  503. }
  504.  
  505. if ((total - 2) >= 0)
  506. {
  507. sjoy.joybit[play.button[2]] = TRUE;
  508. total = total - 2;
  509. }
  510.  
  511. if ((total - 1) >= 0)
  512. {
  513. sjoy.joybit[play.button[1]] = TRUE;
  514. total = total - 1;
  515. }
  516.  
  517.  
  518. if (jinfo.dwXpos > 40000) sjoy.right = TRUE;
  519. if (jinfo.dwXpos < 25000) sjoy.left = TRUE;
  520. if (jinfo.dwYpos > 40000) sjoy.down = TRUE;
  521. if (jinfo.dwYpos < 17000) sjoy.up = TRUE;
  522.  
  523. }
  524.  
  525.  
  526.  
  527. pass:
  528. //redink1 Only accept keyboard input when console is not active.
  529. if ( mConsoleActive == false )
  530. {
  531. if (GetKeyboard(17)) sjoy.joybit[1] = TRUE;
  532. if (GetKeyboard(32)) sjoy.joybit[2] = TRUE;
  533.  
  534. if (GetKeyboard(16)) sjoy.joybit[3] = TRUE;
  535. if (GetKeyboard(13)) sjoy.joybit[4] = TRUE;
  536. if (GetKeyboard(27)) sjoy.joybit[5] = TRUE;
  537. if (GetKeyboard(54)) sjoy.joybit[6] = TRUE;
  538. if (GetKeyboard(77)) sjoy.joybit[6] = TRUE;
  539. if (GetKeyboard(55)) sjoy.joybit[7] = TRUE;
  540. }
  541.  
  542. for (int x5=1; x5 <=10; x5++) sjoy.button[x5] = FALSE;
  543.  
  544.  
  545. for (int x=1; x <=10; x++)
  546.  
  547. {
  548. if (sjoy.joybit[x])
  549. {
  550. if (sjoy.letgo[x] == TRUE)
  551. {
  552. sjoy.button[x] = TRUE;
  553. sjoy.letgo[x] = FALSE;
  554. }
  555.  
  556. }
  557. }
  558.  
  559. //redink1 Only accept keyboard input when console is not active.
  560. if ( mConsoleActive == false )
  561. {
  562. if (GetKeyboard(39)) sjoy.right = TRUE;
  563. if (GetKeyboard(37)) sjoy.left = TRUE;
  564. if (GetKeyboard(40)) sjoy.down = TRUE;
  565. if (GetKeyboard(38)) sjoy.up = TRUE;
  566. }
  567.  
  568. for (int x2=1; x2 <=10; x2++)
  569. {
  570. if (sjoy.joybit[x2]) sjoy.letgo[x2] = FALSE; else sjoy.letgo[x2] = TRUE;
  571.  
  572. }
  573.  
  574. if (sjoy.right) if (sjoy.rightold == TRUE)
  575. {
  576. sjoy.rightd = true;
  577. sjoy.rightold = false;
  578. }
  579.  
  580. if (sjoy.right) sjoy.rightold = false; else sjoy.rightold = true;
  581.  
  582.  
  583. if (sjoy.left) if (sjoy.leftold == TRUE)
  584. {
  585. sjoy.leftd = true;
  586. sjoy.leftold = false;
  587. }
  588.  
  589. if (sjoy.left) sjoy.leftold = false; else sjoy.leftold = true;
  590.  
  591.  
  592. if (sjoy.up) if (sjoy.upold == TRUE)
  593. {
  594. sjoy.upd = true;
  595. sjoy.upold = false;
  596. }
  597.  
  598. if (sjoy.up) sjoy.upold = false; else sjoy.upold = true;
  599.  
  600.  
  601. if (sjoy.down) if (sjoy.downold == TRUE)
  602. {
  603. sjoy.downd = true;
  604. sjoy.downold = false;
  605. }
  606.  
  607. if (sjoy.down) sjoy.downold = false; else sjoy.downold = true;
  608.  
  609.  
  610. if (wait.active)
  611. {
  612.  
  613. //check for dirs
  614.  
  615. if (sjoy.rightd) wait.button = 16;
  616. if (sjoy.leftd) wait.button = 14;
  617. if (sjoy.upd) wait.button = 18;
  618. if (sjoy.downd) wait.button = 12;
  619.  
  620. sjoy.rightd = false;
  621. sjoy.downd = false;
  622. sjoy.upd = false;
  623. sjoy.leftd = false;
  624.  
  625. //check buttons
  626. for (int ll=1; ll <= 10; ll++)
  627. {
  628. if (sjoy.button[ll])
  629. {
  630. //button was pressed
  631. wait.button = ll;
  632.  
  633. }
  634. sjoy.button[ll] = false;
  635.  
  636. }
  637.  
  638. if (wait.button != 0)
  639. {
  640. *presult = wait.button;
  641. wait.active = false;
  642. run_script(wait.script);
  643. }
  644.  
  645.  
  646.  
  647.  
  648.  
  649. }
  650.  
  651.  
  652. }
  653.  
  654.  
  655.  
  656.  
  657. // ********* CHECK TO SEE IF THIS CORD IS ON A HARD SPOT *********
  658. bool not_in_this_base(int seq, int base)
  659. {
  660.  
  661. int realbase = (seq / 10) * 10;
  662.  
  663.  
  664. if (realbase != base)
  665. {
  666.  
  667.  
  668. return(true);
  669. }
  670. else
  671. {
  672. return(false);
  673. }
  674. }
  675.  
  676. bool in_this_base(int seq, int base)
  677. {
  678.  
  679. int realbase = (seq / 10) * 10;
  680. if (realbase == base)
  681. {
  682.  
  683. // Msg("TRUE - Ok, realbase is %d, compared to the base, which is %d.", realbase, base);
  684. return(true);
  685. }
  686. else
  687. {
  688. // Msg("FALSE - Ok, realbase is %d, compared to the base, which is %d.", realbase, base);
  689.  
  690. return(false);
  691. }
  692. }
  693.  
  694.  
  695. void automove (int j)
  696. {
  697.  
  698. char kindx,kindy;
  699. int speedx = 0;
  700. int speedy = 0;
  701.  
  702.  
  703.  
  704.  
  705. if (spr[j].mx != 0)
  706. {
  707. if (spr[j].mx < 0)
  708. kindx = '-'; else kindx = '+';
  709. if (kindx == '-') speedx = (spr[j].mx - (spr[j].mx * 2)); else
  710. speedx = spr[j].mx;
  711. } else kindx = '0';
  712.  
  713. if (spr[j].my != 0)
  714. {
  715. if (spr[j].my < 0)
  716. kindy = '-'; else kindy = '+';
  717. if (kindy == '-') speedy = (spr[j].my - (spr[j].my * 2)); else
  718. speedy = spr[j].my;
  719.  
  720. } else kindy = '0';
  721.  
  722. int speed = speedx;
  723. if (speedy > speedx) speed = speedy;
  724. if (speed > 0)
  725. move(j,speed,kindx,kindy);
  726. //move(j, 1, '+','+');
  727.  
  728. }
  729.  
  730.  
  731. int autoreverse(int j)
  732. {
  733. //Msg("reversing die %d",spr[j].dir);
  734. int r = ((rand() % 2)+1);
  735. if ( (spr[j].dir == 1) || (spr[j].dir == 2) )
  736. {
  737. if (r == 1)
  738. return(8);
  739. if (r == 2)
  740. return(6);
  741.  
  742. }
  743.  
  744. if ( (spr[j].dir == 3) || (spr[j].dir == 6) )
  745. {
  746. if (r == 1)
  747. return(2);
  748. if (r == 2)
  749.  
  750. return(4);
  751.  
  752. }
  753.  
  754. if ( (spr[j].dir == 9) || (spr[j].dir == 8) )
  755. {
  756. if (r == 1)
  757. return(2);
  758. if (r == 2)
  759.  
  760. return(6);
  761.  
  762.  
  763. }
  764.  
  765. if ( (spr[j].dir == 7) || (spr[j].dir == 4) )
  766. {
  767. if (r == 1)
  768. return(8);
  769. if (r == 2)
  770. return(6);
  771.  
  772. }
  773.  
  774. return(0);
  775. }
  776.  
  777.  
  778. int autoreverse_diag(int j)
  779. {
  780. if (spr[j].dir == 0) spr[j].dir = 7;
  781. int r = ((rand() % 2)+1);
  782.  
  783. if ( (spr[j].dir == 1) || (spr[j].dir == 3) )
  784. {
  785.  
  786. if (r == 1)
  787. return(9);
  788. if (r == 2)
  789. return(7);
  790. }
  791.  
  792. if ( (spr[j].dir == 3) || (spr[j].dir == 6) )
  793. {
  794. if (r == 1)
  795. return(7);
  796. if (r == 2)
  797. return(1);
  798.  
  799. }
  800.  
  801. if ( (spr[j].dir == 9) || (spr[j].dir == 8) )
  802. {
  803. if (r == 1)
  804. return(1);
  805. if (r == 2)
  806. return(7);
  807. }
  808.  
  809. if ( (spr[j].dir == 7) || (spr[j].dir == 4) )
  810. {
  811. if (r == 1)
  812. return(3);
  813. if (r == 2)
  814. return(9);
  815.  
  816. }
  817.  
  818. Msg("Auto Reverse Diag was sent a dir %d sprite, base %d walk.",spr[j].dir, spr[j].base_walk);
  819. return(0);
  820. }
  821.  
  822. void draw_damage(int h)
  823. {
  824.  
  825. int crap2 = add_sprite(spr[h].x,spr[h].y,8,0,0);
  826.  
  827. spr[crap2].y -= k[seq[spr[h].pseq].frame[spr[h].pframe]].yoffset;
  828. spr[crap2].x -= k[seq[spr[h].pseq].frame[spr[h].pframe]].xoffset;
  829. spr[crap2].y -= k[seq[spr[h].pseq].frame[spr[h].pframe]].box.bottom / 3;
  830. spr[crap2].x += k[seq[spr[h].pseq].frame[spr[h].pframe]].box.right / 5;
  831.  
  832. spr[crap2].speed = 1;
  833. spr[crap2].hard = 1;
  834. spr[crap2].brain_parm = h;
  835. spr[crap2].my = -1;
  836. spr[crap2].kill = 1000;
  837. spr[crap2].dir = 8;
  838. spr[crap2].damage = spr[h].damage;
  839.  
  840. }
  841.  
  842.  
  843. void add_kill_sprite(int h)
  844. {
  845. if ( (spr[h].dir > 9) || (spr[h].dir < 1) )
  846. {
  847. Msg("Error: Changing sprites dir from %d (!?) to 3.", spr[h].dir);
  848. spr[h].dir = 3;
  849.  
  850. }
  851.  
  852.  
  853. int dir = spr[h].dir;
  854. int base = spr[h].base_die;
  855.  
  856. //Msg("Base die is %d", base);
  857. if (base == -1)
  858. {
  859.  
  860. if (seq[spr[h].base_walk+5].active == true)
  861. {
  862. add_exp(spr[h].exp, h);
  863.  
  864. int crap2 = add_sprite(spr[h].x,spr[h].y,5,spr[h].base_walk +5,1);
  865. spr[crap2].speed = 0;
  866. spr[crap2].seq = spr[h].base_walk + 5;
  867. //redink1 added this so corpses are the same size
  868. spr[crap2].size = spr[h].size;
  869. return;
  870. } else
  871. {
  872. dir = 0;
  873. base = 164;
  874.  
  875. }
  876. }
  877.  
  878.  
  879.  
  880. if (seq[base+dir].active == false)
  881. {
  882.  
  883. if (dir == 1) dir = 9;
  884. else if (dir == 3) dir = 7;
  885. else if (dir == 7) dir = 3;
  886. else if (dir == 9) dir = 1;
  887.  
  888. else if (dir == 4) dir = 6;
  889. else if (dir == 6) dir = 4;
  890. else if (dir == 8) dir = 2;
  891. else if (dir == 2) dir = 8;
  892.  
  893.  
  894. }
  895. if (seq[base+dir].active == false)
  896.  
  897. {
  898. Msg("Can't make a death sprite for dir %d!", base+dir);
  899. }
  900.  
  901.  
  902.  
  903. int crap2 = add_sprite(spr[h].x,spr[h].y,5,base +dir,1);
  904. spr[crap2].speed = 0;
  905. spr[crap2].base_walk = 0;
  906. spr[crap2].seq = base + dir;
  907.  
  908. if (base == 164) spr[crap2].brain = 7;
  909.  
  910. spr[crap2].size = spr[h].size;
  911.  
  912. add_exp(spr[h].exp, h);
  913.  
  914. }
  915.  
  916.  
  917. void done_moving(int h)
  918. {
  919.  
  920. spr[h].move_active = false;
  921.  
  922. spr[h].move_nohard = false;
  923.  
  924. if (spr[h].move_script > 0)
  925. {
  926. // Msg("mover running script %d..", spr[h].move_script);
  927. run_script(spr[h].move_script);
  928. }
  929.  
  930.  
  931.  
  932. }
  933.  
  934. int get_distance_and_dir(int h, int h1, int *dir)
  935. {
  936. if ( smooth_follow )
  937. {
  938. unsigned int x_diff( abs( spr[h].x - spr[h1].x ) );
  939. unsigned int y_diff( abs( spr[h].y - spr[h1].y ) );
  940. if ( spr[h].x < spr[h1].x )
  941. {
  942. if ( spr[h].y < spr[h1].y )
  943. {
  944. // 6, 3, 2
  945. if ( y_diff * 4 < x_diff )
  946. {
  947. *dir = 6;
  948. }
  949. else if ( x_diff * 4 < y_diff )
  950. {
  951. *dir = 2;
  952. }
  953. else
  954. {
  955. *dir = 3;
  956. }
  957. }
  958. else if ( spr[h].y > spr[h1].y )
  959. {
  960. // 4, 9, 8
  961. if ( y_diff * 4 < x_diff )
  962. {
  963. *dir = 6;
  964. }
  965. else if ( x_diff * 4 < y_diff )
  966. {
  967. *dir = 8;
  968. }
  969. else
  970. {
  971. *dir = 9;
  972. }
  973. }
  974. else
  975. {
  976. *dir = 6;
  977. }
  978. }
  979. else if ( spr[h].x > spr[h1].x )
  980. {
  981. if ( spr[h].y < spr[h1].y )
  982. {
  983. // 4, 1, 2
  984. if ( y_diff * 4 < x_diff )
  985. {
  986. *dir = 4;
  987. }
  988. else if ( x_diff * 4 < y_diff )
  989. {
  990. *dir = 2;
  991. }
  992. else
  993. {
  994. *dir = 1;
  995. }
  996. }
  997. else if ( spr[h].y > spr[h1].y )
  998. {
  999. // 4, 7, 8
  1000. if ( y_diff * 4 < x_diff )
  1001. {
  1002. *dir = 4;
  1003. }
  1004. else if ( x_diff * 4 < y_diff )
  1005. {
  1006. *dir = 8;
  1007. }
  1008. else
  1009. {
  1010. *dir = 7;
  1011. }
  1012. }
  1013. else
  1014. {
  1015. *dir = 4;
  1016. }
  1017. }
  1018. else
  1019. {
  1020. if ( spr[h].y < spr[h1].y )
  1021. {
  1022. *dir = 2;
  1023. }
  1024. else if ( spr[h].y > spr[h1].y )
  1025. {
  1026. *dir = 8;
  1027. }
  1028. }
  1029. return max( x_diff, y_diff );
  1030. }
  1031.  
  1032. int distancex = 5000;
  1033. int distancey = 5000;
  1034. int dirx = *dir;
  1035. int diry = *dir;
  1036. if (spr[h].x > spr[h1].x) if ((spr[h].x - spr[h1].x) < distancex)
  1037. {
  1038. distancex = (spr[h].x - spr[h1].x);
  1039. dirx = 4;
  1040. }
  1041.  
  1042. if (spr[h].x <= spr[h1].x) if ((spr[h1].x - spr[h].x) < distancex)
  1043. {
  1044. distancex = (spr[h1].x - spr[h].x);
  1045. dirx = 6;
  1046. }
  1047. if (spr[h].y > spr[h1].y) if ((spr[h].y - spr[h1].y) < distancey)
  1048. {
  1049. distancey = (spr[h].y - spr[h1].y);
  1050. diry = 8;
  1051.  
  1052. }
  1053. if (spr[h].y <= spr[h1].y) if ((spr[h1].y - spr[h].y) < distancey)
  1054. {
  1055. distancey = (spr[h1].y - spr[h].y);
  1056. diry = 2;
  1057. }
  1058. if (distancex > distancey)
  1059. {
  1060.  
  1061. *dir = dirx;
  1062. return(distancex);
  1063. }
  1064. else
  1065. {
  1066. *dir = diry;
  1067. return(distancey);
  1068. }
  1069.  
  1070.  
  1071. }
  1072.  
  1073. void process_follow(int h)
  1074. {
  1075. int hx, hy;
  1076.  
  1077. if (spr[h].follow > 299)
  1078. {
  1079. Msg("ERROR: Sprite %d cannot 'follow' sprite %d??",h,spr[h].follow);
  1080. return;
  1081. }
  1082.  
  1083. if (spr[spr[h].follow].active == false)
  1084. {
  1085. Msg("Killing follow");
  1086. spr[h].follow = 0;
  1087. return;
  1088. }
  1089.  
  1090. hx = spr[spr[h].follow].x;
  1091. hy = spr[spr[h].follow].y;
  1092.  
  1093. int dir;
  1094. int distance = get_distance_and_dir(h, spr[h].follow, &dir);
  1095.  
  1096. if (distance < 40) return;
  1097.  
  1098. changedir(dir,h,spr[h].base_walk);
  1099. automove(h);
  1100.  
  1101.  
  1102. }
  1103.  
  1104.  
  1105. void process_target(int h)
  1106. {
  1107. int hx, hy;
  1108.  
  1109. if (spr[h].target > 299)
  1110. {
  1111. Msg("ERROR: Sprite %d cannot 'target' sprite %d??",h,spr[h].follow);
  1112. return;
  1113. }
  1114.  
  1115. if (spr[spr[h].target].active == false)
  1116. {
  1117. Msg("Killing target");
  1118. spr[h].target = 0;
  1119. return;
  1120. }
  1121.  
  1122. hx = spr[spr[h].target].x;
  1123. hy = spr[spr[h].target].y;
  1124.  
  1125. int dir;
  1126. int distance = get_distance_and_dir(h, spr[h].target, &dir);
  1127.  
  1128. if (distance < spr[h].distance) return;
  1129.  
  1130. changedir(dir,h,spr[h].base_walk);
  1131.  
  1132. automove(h);
  1133.  
  1134.  
  1135. }
  1136.  
  1137.  
  1138. bool check_for_kill_script(int i)
  1139. {
  1140.  
  1141.  
  1142. if (spr[i].script > 0)
  1143. {
  1144. //if ( (spr[i].brain == 0) | (spr[i].brain == 5) | (spr[i].brain == 6) | (spr[i].brain == 7))
  1145.  
  1146. if (locate(spr[i].script, "DIE")) run_script(spr[i].script);
  1147.  
  1148. return(true);
  1149. }
  1150.  
  1151. return(false);
  1152. }
  1153.  
  1154. bool check_for_duck_script(int i)
  1155. {
  1156.  
  1157.  
  1158. if (spr[i].script > 0)
  1159. {
  1160. //if ( (spr[i].brain == 0) | (spr[i].brain == 5) | (spr[i].brain == 6) | (spr[i].brain == 7))
  1161.  
  1162. if (locate(spr[i].script, "DUCKDIE")) run_script(spr[i].script);
  1163.  
  1164. return(true);
  1165. }
  1166.  
  1167. return(false);
  1168. }
  1169.  
  1170.  
  1171.  
  1172. void process_move(int h)
  1173. {
  1174.  
  1175. // Msg("Proccesing sprite %d, dir %d (script is %d)", h, spr[h].dir, spr[h].move_script);
  1176.  
  1177.  
  1178.  
  1179. if ((spr[h].move_dir == 4) | (spr[h].move_dir == 1) | (spr[h].move_dir == 7) )
  1180. {
  1181. if (spr[h].x <= spr[h].move_num)
  1182. {
  1183. //done moving
  1184. done_moving(h);
  1185. return;
  1186. }
  1187. changedir(spr[h].move_dir,h,spr[h].base_walk);
  1188. automove(h);
  1189. }
  1190.  
  1191. if ( (spr[h].move_dir == 6) | (spr[h].move_dir == 9) | (spr[h].move_dir == 3))
  1192. {
  1193. if (spr[h].x >= spr[h].move_num)
  1194. {
  1195. //done moving
  1196. done_moving(h);
  1197. return;
  1198. }
  1199. changedir(spr[h].move_dir,h,spr[h].base_walk);
  1200. automove(h);
  1201. }
  1202.  
  1203.  
  1204. if (spr[h].move_dir == 2)
  1205. {
  1206. if (spr[h].y >= spr[h].move_num)
  1207. {
  1208. //done moving
  1209. done_moving(h);
  1210. return;
  1211. }
  1212. changedir(spr[h].move_dir,h,spr[h].base_walk);
  1213. automove(h);
  1214. }
  1215.  
  1216.  
  1217. if (spr[h].move_dir == 8)
  1218. {
  1219. if (spr[h].y <= spr[h].move_num)
  1220. {
  1221. //done moving
  1222. done_moving(h);
  1223. return;
  1224. }
  1225. changedir(spr[h].move_dir,h,spr[h].base_walk);
  1226. automove(h);
  1227. }
  1228.  
  1229.  
  1230. }
  1231.  
  1232. void duck_brain(int h)
  1233. {
  1234. int hold;
  1235.  
  1236.  
  1237. start:
  1238.  
  1239.  
  1240. if ( (spr[h].damage > 0) && (in_this_base(spr[h].pseq, 110) ) )
  1241. {
  1242.  
  1243. check_for_duck_script(h);
  1244.  
  1245. //hit a dead duck
  1246. int crap2 = add_sprite(spr[h].x,spr[h].y,7,164,1);
  1247. spr[crap2].speed = 0;
  1248. spr[crap2].base_walk = 0;
  1249. spr[crap2].seq = 164;
  1250. draw_damage(h);
  1251. spr[h].damage = 0;
  1252. add_exp(spr[h].exp, h);
  1253.  
  1254. kill_sprite_all(h);
  1255.  
  1256. return;
  1257. }
  1258.  
  1259.  
  1260. if ( (spr[h].damage > 0) && (in_this_base(spr[h].pseq, spr[h].base_walk) ) )
  1261. {
  1262. //SoundPlayEffect( 1,3000, 800 );
  1263. draw_damage(h);
  1264. add_exp(spr[h].exp, h);
  1265. spr[h].damage = 0;
  1266.  
  1267. //lets kill the duck here, ha.
  1268. check_for_kill_script(h);
  1269. spr[h].follow = 0;
  1270. int crap = add_sprite(spr[h].x,spr[h].y,5,1,1);
  1271. spr[crap].speed = 0;
  1272. spr[crap].base_walk = 0;
  1273. spr[crap].size = spr[h].size;
  1274. spr[crap].speed = ((rand() % 3)+1);
  1275.  
  1276.  
  1277. spr[h].base_walk = 110;
  1278. spr[h].speed = 1;
  1279. spr[h].timer = 0;
  1280. spr[h].wait = 0;
  1281. spr[h].frame = 0;
  1282.  
  1283. if (spr[h].dir == 0) spr[h].dir = 1;
  1284. if (spr[h].dir == 4) spr[h].dir = 7;
  1285. if (spr[h].dir == 6) spr[h].dir = 3;
  1286.  
  1287. changedir(spr[h].dir,h,spr[h].base_walk);
  1288. spr[crap].dir = spr[h].dir;
  1289. spr[crap].base_walk = 120;
  1290. changedir(spr[crap].dir,crap,spr[crap].base_walk);
  1291.  
  1292.  
  1293. automove(h);
  1294. return;
  1295. }
  1296.  
  1297.  
  1298. if (spr[h].move_active)
  1299. {
  1300. process_move(h);
  1301. return;
  1302. }
  1303.  
  1304. if (spr[h].freeze)
  1305. {
  1306. return;
  1307. }
  1308.  
  1309.  
  1310. if (spr[h].follow > 0)
  1311. {
  1312. process_follow(h);
  1313. return;
  1314. }
  1315.  
  1316.  
  1317.  
  1318. if (spr[h].base_walk == 110)
  1319. {
  1320. if ( (rand() % 100)+1 == 1)
  1321. random_blood(spr[h].x, spr[h].y-18, h);
  1322. goto walk;
  1323. }
  1324.  
  1325.  
  1326.  
  1327.  
  1328.  
  1329. if (spr[h].seq == 0 )
  1330. {
  1331.  
  1332. if (((rand() % 12)+1) == 1 )
  1333. {
  1334. hold = ((rand() % 9)+1);
  1335.  
  1336. if ((hold != 2) && (hold != 8) && (hold != 5))
  1337. {
  1338.  
  1339. //Msg("random dir change started.. %d", hold);
  1340. changedir(hold,h,spr[h].base_walk);
  1341.  
  1342. }
  1343. else
  1344. {
  1345. int junk = spr[h].size;
  1346.  
  1347. if (junk >= 100)
  1348. junk = 18000 - (junk * 50);
  1349.  
  1350. if (junk < 100)
  1351. junk = 16000 + (junk * 100);
  1352.  
  1353. SoundPlayEffect( 1,junk, 800,h ,0);
  1354. spr[h].mx = 0;
  1355. spr[h].my = 0;
  1356. spr[h].wait = thisTickCount + (rand() % 300)+200;
  1357.  
  1358. }
  1359. return;
  1360. }
  1361.  
  1362. if ((spr[h].mx != 0) || (spr[h].my != 0))
  1363.  
  1364. {
  1365. spr[h].seq = spr[h].seq_orig;
  1366.  
  1367. }
  1368.  
  1369. }
  1370.  
  1371.  
  1372. walk:
  1373. if (spr[h].y > playy)
  1374.  
  1375. {
  1376. changedir(9,h,spr[h].base_walk);
  1377. }
  1378.  
  1379.  
  1380.  
  1381. if (spr[h].x > playx-30)
  1382.  
  1383. {
  1384. changedir(7,h,spr[h].base_walk);
  1385. }
  1386.  
  1387. if (spr[h].y < 10)
  1388. {
  1389. changedir(1,h,spr[h].base_walk);
  1390. }
  1391.  
  1392. if (spr[h].x < 30)
  1393. {
  1394. changedir(3,h,spr[h].base_walk);
  1395. }
  1396.  
  1397. // Msg("Duck dir is %d, seq is %d.", spr[h].dir, spr[h].seq);
  1398. automove(h);
  1399.  
  1400. if (check_if_move_is_legal(h) != 0)
  1401.  
  1402. {
  1403. if (spr[h].dir != 0)
  1404. changedir(autoreverse_diag(h),h,spr[h].base_walk);
  1405. }
  1406.  
  1407. }
  1408. // end duck_brain
  1409.  
  1410. void change_dir_to_diag( int *dir)
  1411. {
  1412.  
  1413. if (*dir == 8) *dir = 7;
  1414. if (*dir == 4) *dir = 1;
  1415. if (*dir == 2) *dir = 3;
  1416. if (*dir == 6) *dir = 9;
  1417.  
  1418. }
  1419.  
  1420.  
  1421.  
  1422. void pill_brain(int h)
  1423. {
  1424. int hold;
  1425.  
  1426. if (spr[h].damage > 0)
  1427. {
  1428. //got hit
  1429. //SoundPlayEffect( 1,3000, 800 );
  1430. if (spr[h].hitpoints > 0)
  1431. {
  1432. draw_damage(h);
  1433. if (spr[h].damage > spr[h].hitpoints) spr[h].damage = spr[h].hitpoints;
  1434. spr[h].hitpoints -= spr[h].damage;
  1435.  
  1436. if (spr[h].hitpoints < 1)
  1437. {
  1438. //they killed it
  1439. check_for_kill_script(h);
  1440.  
  1441. if (spr[h].brain == 9)
  1442. {
  1443. if (spr[h].dir == 0) spr[h].dir = 3;
  1444. change_dir_to_diag(&spr[h].dir);
  1445. add_kill_sprite(h);
  1446. spr[h].active = false;
  1447. }
  1448. return;
  1449.  
  1450. }
  1451. }
  1452. spr[h].damage = 0;
  1453.  
  1454. }
  1455.  
  1456. if (spr[h].move_active)
  1457. {
  1458. process_move(h);
  1459. return;
  1460. }
  1461.  
  1462.  
  1463.  
  1464.  
  1465. if (spr[h].freeze) return;
  1466.  
  1467. if (spr[h].follow > 0)
  1468. {
  1469. process_follow(h);
  1470.  
  1471. }
  1472.  
  1473.  
  1474. if (spr[h].target != 0)
  1475. {
  1476.  
  1477. if (in_this_base(spr[h].seq, spr[h].base_attack))
  1478. {
  1479. //still attacking
  1480. return;
  1481. }
  1482.  
  1483.  
  1484.  
  1485.  
  1486.  
  1487. int dir;
  1488. if (spr[h].distance == 0) spr[h].distance = 5;
  1489. int distance = get_distance_and_dir(h, spr[h].target, &dir);
  1490.  
  1491. if (distance < spr[h].distance) if (spr[h].attack_wait < thisTickCount)
  1492. {
  1493. // Msg("base attack is %d.",spr[h].base_attack);
  1494. if (spr[h].base_attack != -1)
  1495. {
  1496. int attackdir;
  1497. bool old_smooth_follow = smooth_follow;
  1498. smooth_follow = false;
  1499. get_distance_and_dir(h, spr[h].target, &attackdir);
  1500. smooth_follow = old_smooth_follow;
  1501. //Msg("attacking with %d..", spr[h].base_attack+dir);
  1502.  
  1503. spr[h].dir = attackdir;
  1504.  
  1505. spr[h].seq = spr[h].base_attack+spr[h].dir;
  1506. spr[h].frame = 0;
  1507.  
  1508. if (spr[h].script != 0)
  1509. if (locate(spr[h].script, "ATTACK")) run_script(spr[h].script); else
  1510. spr[h].move_wait = thisTickCount + ((rand() % 300)+10);;
  1511. return;
  1512.  
  1513. }
  1514.  
  1515. }
  1516.  
  1517.  
  1518.  
  1519. if (spr[h].move_wait < thisTickCount)
  1520. {
  1521. process_target(h);
  1522. spr[h].move_wait = thisTickCount + 200;
  1523.  
  1524. }
  1525. else
  1526. {
  1527. /* automove(h);
  1528.  
  1529. if (check_if_move_is_legal(h) != 0)
  1530. {
  1531.  
  1532. }
  1533. */
  1534.  
  1535. goto walk_normal;
  1536. }
  1537.  
  1538. return;
  1539. }
  1540.  
  1541.  
  1542.  
  1543. walk_normal:
  1544.  
  1545. if (spr[h].base_walk != -1)
  1546. {
  1547. if ( spr[h].seq == 0) goto recal;
  1548. }
  1549.  
  1550. if (( spr[h].seq == 0) && (spr[h].move_wait < thisTickCount))
  1551. {
  1552. recal:
  1553. if (((rand() % 12)+1) == 1 )
  1554. {
  1555. hold = ((rand() % 9)+1);
  1556. if ( (hold != 4) && (hold != 6) && (hold != 2) && (hold != 8) && (hold != 5))
  1557. {
  1558. changedir(hold,h,spr[h].base_walk);
  1559. spr[h].move_wait = thisTickCount +((rand() % 2000)+200);
  1560.  
  1561. }
  1562.  
  1563. } else
  1564. {
  1565. //keep going the same way
  1566. if (in_this_base(spr[h].seq_orig, spr[h].base_attack)) goto recal;
  1567. spr[h].seq = spr[h].seq_orig;
  1568. if (spr[h].seq_orig == 0) goto recal;
  1569. }
  1570.  
  1571. }
  1572.  
  1573.  
  1574.  
  1575. if (spr[h].y > (playy - 15))
  1576.  
  1577. {
  1578. changedir(9,h,spr[h].base_walk);
  1579. }
  1580.  
  1581. if (spr[h].x > (playx - 15))
  1582.  
  1583. {
  1584. changedir(1,h,spr[h].base_walk);
  1585. }
  1586.  
  1587. if (spr[h].y < 18)
  1588. {
  1589. changedir(1,h,spr[h].base_walk);
  1590. }
  1591.  
  1592. if (spr[h].x < 18)
  1593. {
  1594. changedir(3,h,spr[h].base_walk);
  1595. }
  1596.  
  1597. automove(h);
  1598.  
  1599. if (check_if_move_is_legal(h) != 0)
  1600. {
  1601. spr[h].move_wait = thisTickCount + 400;
  1602. changedir(autoreverse_diag(h),h,spr[h].base_walk);
  1603. }
  1604.  
  1605.  
  1606. // changedir(hold,h,spr[h].base_walk);
  1607.  
  1608.  
  1609. }
  1610.  
  1611. void find_action(int h)
  1612. {
  1613.  
  1614. spr[h].action = (rand() % 2)+1;
  1615.  
  1616.  
  1617. if (spr[h].action == 1)
  1618. {
  1619. //sit and think
  1620. spr[h].move_wait = thisTickCount +((rand() % 3000)+400);
  1621. if (spr[h].base_walk != -1)
  1622. {
  1623. int dir = (rand() % 4)+1;
  1624.  
  1625. spr[h].pframe = 1;
  1626. if (dir == 1) spr[h].pseq = spr[h].base_walk+1;
  1627. if (dir == 2) spr[h].pseq = spr[h].base_walk+3;
  1628. if (dir == 3) spr[h].pseq = spr[h].base_walk+7;
  1629. if (dir == 4) spr[h].pseq = spr[h].base_walk+9;
  1630. }
  1631.  
  1632. return;
  1633. }
  1634.  
  1635. if (spr[h].action == 2)
  1636. {
  1637. //move
  1638. spr[h].move_wait = thisTickCount +((rand() % 3000)+500);
  1639. int dir = (rand() % 4)+1;
  1640. spr[h].pframe = 1;
  1641. if (dir == 1) changedir(1,h,spr[h].base_walk);
  1642. if (dir == 2) changedir(3,h,spr[h].base_walk);
  1643. if (dir == 3) changedir(7,h,spr[h].base_walk);
  1644. if (dir == 4) changedir(9,h,spr[h].base_walk);
  1645. return;
  1646. }
  1647.  
  1648.  
  1649. Msg("Internal error: Brain 16, unknown action.");
  1650. }
  1651.  
  1652.  
  1653. void people_brain(int h)
  1654. {
  1655. int hold;
  1656.  
  1657. if (spr[h].damage > 0)
  1658. {
  1659. //got hit
  1660. //SoundPlayEffect( 1,3000, 800 );
  1661. if (spr[h].hitpoints > 0)
  1662. {
  1663. draw_damage(h);
  1664. if (spr[h].damage > spr[h].hitpoints) spr[h].damage = spr[h].hitpoints;
  1665. spr[h].hitpoints -= spr[h].damage;
  1666.  
  1667. if (spr[h].hitpoints < 1)
  1668. {
  1669. //they killed it
  1670. check_for_kill_script(h);
  1671.  
  1672. if (spr[h].brain == 16)
  1673. {
  1674. if (spr[h].dir == 0) spr[h].dir = 3;
  1675. spr[h].brain = 0;
  1676. change_dir_to_diag(&spr[h].dir);
  1677. add_kill_sprite(h);
  1678. spr[h].active = false;
  1679. }
  1680. return;
  1681.  
  1682. }
  1683. }
  1684. spr[h].damage = 0;
  1685.  
  1686. }
  1687.  
  1688. if (spr[h].move_active)
  1689. {
  1690. process_move(h);
  1691. return;
  1692. }
  1693.  
  1694.  
  1695.  
  1696.  
  1697. if (spr[h].freeze) return;
  1698.  
  1699. if (spr[h].follow > 0)
  1700. {
  1701. process_follow(h);
  1702. return;
  1703. }
  1704.  
  1705.  
  1706. if ((spr[h].move_wait < thisTickCount) && (spr[h].seq == 0))
  1707. {
  1708.  
  1709. spr[h].action = 0;
  1710. }
  1711.  
  1712.  
  1713.  
  1714. if (spr[h].action == 0) find_action(h);
  1715.  
  1716.  
  1717. if (spr[h].action != 2)
  1718. {
  1719. spr[h].seq = 0;
  1720. return;
  1721.  
  1722. }
  1723. if (spr[h].seq_orig != 0)
  1724. if (spr[h].seq == 0) spr[h].seq = spr[h].seq_orig;
  1725.  
  1726.  
  1727. if (spr[h].y > playy)
  1728.  
  1729. {
  1730.  
  1731. if ( ((rand() % 2)+1) == 1)
  1732. changedir(9,h,spr[h].base_walk);
  1733. else changedir(7,h,spr[h].base_walk);
  1734.  
  1735.  
  1736. }
  1737.  
  1738. if (spr[h].x > playx)
  1739.  
  1740. {
  1741. if ( ((rand() % 2)+1) == 1)
  1742. changedir(1,h,spr[h].base_walk);
  1743. else changedir(7,h,spr[h].base_walk);
  1744.  
  1745. }
  1746.  
  1747. if (spr[h].y < 20)
  1748. {
  1749. if ( ((rand() % 2)+1) == 1)
  1750. changedir(1,h,spr[h].base_walk);
  1751. else changedir(3,h,spr[h].base_walk);
  1752. }
  1753.  
  1754. if (spr[h].x < 30)
  1755. {
  1756. if ( ((rand() % 2)+1) == 1)
  1757. changedir(3,h,spr[h].base_walk);
  1758. else changedir(9,h,spr[h].base_walk);
  1759. }
  1760.  
  1761. automove(h);
  1762.  
  1763. if (check_if_move_is_legal(h) != 0)
  1764. {
  1765. if ((rand() % 3) == 2)
  1766. {
  1767. changedir(autoreverse_diag(h),h,spr[h].base_walk);
  1768.  
  1769. } else
  1770. {
  1771. spr[h].move_wait = 0;
  1772. spr[h].pframe = 1;
  1773. spr[h].seq = 0;
  1774. }
  1775. }
  1776.  
  1777.  
  1778. // changedir(hold,h,spr[h].base_walk);
  1779.  
  1780.  
  1781. }
  1782.  
  1783.  
  1784. void no_brain(int h)
  1785. {
  1786. int hold;
  1787.  
  1788. if (spr[h].move_active)
  1789. {
  1790. process_move(h);
  1791. return;
  1792. }
  1793.  
  1794. if (spr[h].freeze) return;
  1795.  
  1796. if (spr[h].follow > 0)
  1797. {
  1798. process_follow(h);
  1799. return;
  1800. }
  1801.  
  1802. }
  1803.  
  1804.  
  1805. void shadow_brain(int h)
  1806. {
  1807. int hold;
  1808.  
  1809. if (spr[spr[h].brain_parm].active == false)
  1810. {
  1811. spr[h].active = false;
  1812. return;
  1813. }
  1814.  
  1815. spr[h].x = spr[spr[h].brain_parm].x;
  1816. spr[h].y = spr[spr[h].brain_parm].y;
  1817. spr[h].size = spr[spr[h].brain_parm].size;
  1818.  
  1819. if (spr[h].seq == 0) if (spr[h].seq_orig != 0) spr[h].seq = spr[h].seq_orig;
  1820.  
  1821. }
  1822.  
  1823.  
  1824.  
  1825. void dragon_brain(int h)
  1826. {
  1827. int hold;
  1828.  
  1829.  
  1830. if (spr[h].damage > 0)
  1831. {
  1832. //got hit
  1833. //SoundPlayEffect( 1,3000, 800 );
  1834. if (spr[h].hitpoints > 0)
  1835. {
  1836. draw_damage(h);
  1837. if (spr[h].damage > spr[h].hitpoints) spr[h].damage = spr[h].hitpoints;
  1838. spr[h].hitpoints -= spr[h].damage;
  1839.  
  1840. if (spr[h].hitpoints < 1)
  1841. {
  1842. //they killed it
  1843.  
  1844. check_for_kill_script(h);
  1845. if (spr[h].brain == 10)
  1846. {
  1847. add_kill_sprite(h);
  1848. spr[h].active = false;
  1849.  
  1850. }
  1851.  
  1852. return;
  1853.  
  1854. }
  1855. }
  1856. spr[h].damage = 0;
  1857. }
  1858.  
  1859.  
  1860. if (spr[h].move_active)
  1861. {
  1862. process_move(h);
  1863. return;
  1864. }
  1865.  
  1866.  
  1867. if (spr[h].freeze) return;
  1868.  
  1869.  
  1870. if (spr[h].follow > 0)
  1871. {
  1872. process_follow(h);
  1873. return;
  1874. }
  1875.  
  1876. if (spr[h].target != 0)
  1877. if (spr[h].attack_wait < thisTickCount)
  1878. {
  1879. if (spr[h].script != 0)
  1880. {
  1881.  
  1882. if (locate(spr[h].script, "ATTACK")) run_script(spr[h].script);
  1883. }
  1884. }
  1885.  
  1886.  
  1887.  
  1888. if (spr[h].seq == 0)
  1889. {
  1890. recal:
  1891. if (((rand() % 12)+1) == 1 )
  1892. {
  1893. hold = ((rand() % 9)+1);
  1894. if ( (hold != 1) && (hold != 3) && (hold != 7) && (hold != 9) && (hold != 5))
  1895. {
  1896. changedir(hold,h,spr[h].base_walk);
  1897.  
  1898. }
  1899.  
  1900. } else
  1901. {
  1902. //keep going the same way
  1903. spr[h].seq = spr[h].seq_orig;
  1904. if (spr[h].seq_orig == 0) goto recal;
  1905. }
  1906.  
  1907. }
  1908.  
  1909.  
  1910. if (spr[h].y > playy)
  1911.  
  1912. {
  1913. changedir(8,h,spr[h].base_walk);
  1914. }
  1915.  
  1916. if (spr[h].x > x)
  1917. {
  1918. changedir(4,h,spr[h].base_walk);
  1919. }
  1920.  
  1921. if (spr[h].y < 0)
  1922. {
  1923. changedir(2,h,spr[h].base_walk);
  1924. }
  1925.  
  1926. if (spr[h].x < 0)
  1927. {
  1928. changedir(6,h,spr[h].base_walk);
  1929. }
  1930.  
  1931. automove(h);
  1932.  
  1933. if (check_if_move_is_legal(h) != 0)
  1934.  
  1935. {
  1936.  
  1937. int mydir = autoreverse(h);
  1938.  
  1939. // Msg("Real dir now is %d, autoresver changed to %d.",spr[h].dir, mydir);
  1940.  
  1941. changedir(mydir,h,spr[h].base_walk);
  1942.  
  1943. Msg("real dir changed to %d",spr[h].dir);
  1944. }
  1945.  
  1946. }
  1947.  
  1948.  
  1949.  
  1950.  
  1951. void pig_brain(int h)
  1952. {
  1953. int hold;
  1954.  
  1955.  
  1956. start:
  1957.  
  1958. if (spr[h].move_active)
  1959. {
  1960. process_move(h);
  1961. return;
  1962. }
  1963.  
  1964. if ( (spr[h].damage > 0) )
  1965. {
  1966. //SoundPlayEffect( 1,3000, 800 );
  1967. draw_damage(h);
  1968. spr[h].hitpoints -= spr[h].damage;
  1969. spr[h].damage = 0;
  1970. if (spr[h].hitpoints < 1)
  1971. {
  1972. add_exp(spr[h].exp, h);
  1973. spr[h].damage = 0;
  1974. //lets kill the duck here, ha.
  1975. check_for_kill_script(h);
  1976. spr[h].speed = 0;
  1977. spr[h].base_walk = -1;
  1978. spr[h].seq = 164;
  1979. spr[h].brain = 7;
  1980. }
  1981.  
  1982. return;
  1983. }
  1984.  
  1985.  
  1986. if (spr[h].freeze) return;
  1987.  
  1988.  
  1989.  
  1990. if (spr[h].seq == 0 )
  1991. {
  1992.  
  1993. if (((rand() % 12)+1) == 1 )
  1994. {
  1995. hold = ((rand() % 9)+1);
  1996.  
  1997. if ( (hold != 4) && (hold != 6) && (hold != 2) && (hold != 8) && (hold != 5))
  1998. {
  1999. changedir(hold,h,spr[h].base_walk);
  2000.  
  2001. }
  2002. else
  2003. {
  2004. int junk = spr[h].size;
  2005.  
  2006. if (junk >= 100)
  2007. junk = 18000 - (junk * 50);
  2008.  
  2009. if (junk < 100)
  2010. junk = 16000 + (junk * 100);
  2011.  
  2012.  
  2013. hold = ((rand() % 4)+1);
  2014.  
  2015. if (!playing(spr[h].last_sound)) spr[h].last_sound = 0;
  2016.  
  2017. if (spr[h].last_sound == 0)
  2018. {
  2019.  
  2020.  
  2021. if (hold == 1)
  2022. spr[h].last_sound = SoundPlayEffect( 2,junk, 800 ,h,0);
  2023. if (hold == 2)
  2024. spr[h].last_sound = SoundPlayEffect( 3,junk, 800,h ,0);
  2025. if (hold == 3)
  2026. spr[h].last_sound = SoundPlayEffect( 4,junk, 800 ,h,0);
  2027. if (hold == 4)
  2028. spr[h].last_sound = SoundPlayEffect( 5,junk, 800,h,0 );
  2029.  
  2030. }
  2031.  
  2032. spr[h].mx = 0;
  2033. spr[h].my = 0;
  2034. spr[h].wait = thisTickCount + (rand() % 300)+200;
  2035.  
  2036. }
  2037.  
  2038. }
  2039. else
  2040. {
  2041.  
  2042. if ((spr[h].mx != 0) || (spr[h].my != 0))
  2043.  
  2044. {
  2045. spr[h].seq = spr[h].seq_orig;
  2046.  
  2047. }
  2048.  
  2049. }
  2050. }
  2051.  
  2052.  
  2053. if (spr[h].y > (playy-k[getpic(h)].box.bottom / 4))
  2054. {
  2055. changedir(9,h,spr[h].base_walk);
  2056. }
  2057.  
  2058. if (spr[h].x > (x-k[getpic(h)].box.right-10))
  2059. {
  2060. changedir(1,h,spr[h].base_walk);
  2061. }
  2062.  
  2063. if (spr[h].y < 10)
  2064. {
  2065. changedir(1,h,spr[h].base_walk);
  2066. }
  2067.  
  2068. if (spr[h].x < 10)
  2069. {
  2070. changedir(3,h,spr[h].base_walk);
  2071. }
  2072.  
  2073. automove(h);
  2074.  
  2075. if (check_if_move_is_legal(h) != 0)
  2076.  
  2077. {
  2078. changedir(autoreverse_diag(h),h,spr[h].base_walk);
  2079. }
  2080.  
  2081. }
  2082. // end duck_brain
  2083.  
  2084.  
  2085.  
  2086.  
  2087. int check_if_move_is_legal(int u)
  2088.  
  2089. {
  2090. //redink1 removed so move_nohard is active for all movements, not just active moves.
  2091. //if (spr[u].move_active)
  2092. if (spr[u].move_nohard == 1)
  2093. return(0);
  2094. if (u == 1) if (in_this_base(spr[u].seq, mDinkBasePush)) return(0);
  2095.  
  2096. if (u == 1) if (!no_cheat) if (debug_mode) return(0);
  2097. int hardness = 0;
  2098. if (spr[u].moveman > 0)
  2099. {
  2100. for (int i=1; i <= spr[u].moveman; i++)
  2101. {
  2102. hardness = get_hard(u,spr[u].lpx[i]-20 , spr[u].lpy[i]);
  2103. if (hardness == 2) if (spr[u].flying)
  2104. {
  2105. spr[u].moveman = 0;
  2106. // redink1 changed so flying works properly
  2107. return(0);
  2108. }
  2109. if (hardness > 0)
  2110. {
  2111.  
  2112. spr[u].x = spr[u].lpx[i-1];
  2113. spr[u].y = spr[u].lpy[i-1];
  2114. spr[u].moveman = 0;
  2115.  
  2116. if (push_active)
  2117. if (u == 1) if (hardness != 2) if (play.push_active == false)
  2118.  
  2119. {
  2120.  
  2121. push:
  2122. if ( (spr[u].dir == 2) | (spr[u].dir == 4) | (spr[u].dir == 6) | (spr[u].dir == 8) )
  2123. {
  2124. //he (dink) is definatly pushing on something
  2125. play.push_active = true;
  2126. play.push_dir = spr[u].dir;
  2127. play.push_timer = thisTickCount;
  2128.  
  2129. }
  2130. } else
  2131. {
  2132. if (play.push_dir != spr[1].dir) play.push_active = false;
  2133. }
  2134. return(hardness);
  2135. }
  2136.  
  2137. }
  2138.  
  2139. }
  2140.  
  2141.  
  2142. if (u == 1) play.push_active = false;
  2143. return(0);
  2144. }
  2145.  
  2146.  
  2147.  
  2148. void move(int u, int amount, char kind, char kindy)
  2149. {
  2150. int mx = 0;
  2151. int my = 0;
  2152. bool clearx;
  2153. bool cleary;
  2154. clearx = false;
  2155. cleary = false;
  2156.  
  2157. for (int i=1; i <= amount; i++)
  2158. {
  2159. spr[u].moveman++;
  2160. if (mx >= spr[u].mx) clearx = true;
  2161. if (my >= spr[u].my) clearx = true;
  2162.  
  2163. if ((clearx) & (cleary))
  2164. {
  2165. mx = 0;
  2166. my = 0;
  2167. clearx = false;
  2168. cleary = false;
  2169.  
  2170. }
  2171.  
  2172.  
  2173. if (kind == '+')
  2174. {
  2175. if (mx < spr[u].mx)
  2176. spr[u].x++;
  2177. mx++;
  2178.  
  2179. }
  2180. if (kind == '-')
  2181. {
  2182.  
  2183.  
  2184. if (mx < (spr[u].mx - (spr[u].mx * 2)))
  2185. spr[u].x--;
  2186. mx++;
  2187. }
  2188.  
  2189. if (kindy == '+')
  2190. {
  2191.  
  2192. if (my < spr[u].my)
  2193. spr[u].y++;
  2194. my++;
  2195. }
  2196. if (kindy == '-')
  2197. {
  2198.  
  2199. if (my < (spr[u].my - (spr[u].my * 2)))
  2200. spr[u].y--;
  2201. my++;
  2202. }
  2203.  
  2204. spr[u].lpx[spr[u].moveman] = spr[u].x;
  2205. spr[u].lpy[spr[u].moveman] = spr[u].y;
  2206. }
  2207.  
  2208.  
  2209. }
  2210.  
  2211.  
  2212.  
  2213. void bounce_brain(int h)
  2214. {
  2215. if (spr[h].y > (playy-k[getpic(h)].box.bottom))
  2216. {
  2217. spr[h].my -= (spr[h].my * 2);
  2218. }
  2219.  
  2220. if (spr[h].x > (x-k[getpic(h)].box.right))
  2221. {
  2222. spr[h].mx -= (spr[h].mx * 2);
  2223. }
  2224.  
  2225. if (spr[h].y < 0)
  2226. {
  2227. spr[h].my -= (spr[h].my * 2);
  2228. }
  2229.  
  2230.  
  2231. if (spr[h].x < 0)
  2232. {
  2233. spr[h].mx -= (spr[h].mx * 2);
  2234. }
  2235.  
  2236.  
  2237. spr[h].x += spr[h].mx;
  2238. spr[h].y += spr[h].my;
  2239.  
  2240.  
  2241. }
  2242. //end bounce brain
  2243.  
  2244. void grab_trick(int trick)
  2245. {
  2246. RECT rcRect;
  2247. HRESULT ddrval;
  2248. //Msg("making trick.");
  2249.  
  2250. if (no_transition)
  2251. {
  2252.  
  2253. move_screen = trick;
  2254. trig_man = true;
  2255.  
  2256. move_counter = 0;
  2257. return;
  2258. }
  2259. rcRect.left = playl;
  2260. rcRect.top = 0;
  2261. //redink1 fix so scroll works for entire screen
  2262. rcRect.right = 620;
  2263. rcRect.bottom = 400;
  2264.  
  2265. ddrval = lpDDSTrick->BltFast( 0, 0, lpDDSBack,
  2266. &rcRect, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
  2267.  
  2268. if (ddrval != DD_OK) dderror(ddrval);
  2269. move_screen = trick;
  2270. trig_man = true;
  2271.  
  2272. move_counter = 0;
  2273. }
  2274.  
  2275.  
  2276.  
  2277.  
  2278.  
  2279.  
  2280. void did_player_cross_screen(bool real, int h)
  2281. {
  2282.  
  2283. if (walk_off_screen == 1) return;
  2284. int middlex,middley;
  2285.  
  2286.  
  2287. //DO MATH TO SEE IF THEY HAVE CROSSED THE SCREEN, IF SO LOAD NEW ONE
  2288.  
  2289. if ((spr[h].x) < playl)
  2290. {
  2291. if ((map.loc[*pmap-1] > 0) && (screenlock == 0) )
  2292. {
  2293. //move one map to the left
  2294. if (real)
  2295. {
  2296. move_gonna = true;
  2297. return;
  2298. }
  2299. update_screen_time();
  2300. grab_trick(4);
  2301. *pmap -= 1;
  2302. load_map(map.loc[*pmap]);
  2303. if (map.indoor[*pmap] == 0) play.last_map = *pmap;
  2304.  
  2305. draw_map_game();
  2306. spr[h].x = 619;
  2307. spr[h].y = spr[h].lpy[0];
  2308. goto b1end;
  2309. } else
  2310. {
  2311. spr[h].x = playl;
  2312.  
  2313. }
  2314.  
  2315.  
  2316. }
  2317.  
  2318. if ((spr[h].x) > 619)
  2319. {
  2320. if ((map.loc[*pmap+1] > 0) && (screenlock == 0) )
  2321. {
  2322. //move one map to the right
  2323. if (real)
  2324. {
  2325. move_gonna = true;
  2326. return;
  2327. }
  2328.  
  2329. update_screen_time();
  2330. grab_trick(6);
  2331. *pmap += 1;
  2332. load_map(map.loc[*pmap]);
  2333. if (map.indoor[*pmap] == 0) play.last_map = *pmap;
  2334.  
  2335. draw_map_game();
  2336. spr[h].x = playl;
  2337. spr[h].y = spr[h].lpy[0];
  2338. goto b1end;
  2339. } else
  2340. {
  2341. spr[h].x = 619;
  2342. }
  2343. }
  2344.  
  2345. if (spr[h].y < 0)
  2346.  
  2347. {
  2348. if ((map.loc[*pmap-32] > 0) && (screenlock == 0) )
  2349. {
  2350. //move one map up
  2351. if (real)
  2352. {
  2353. move_gonna = true;
  2354. return;
  2355. }
  2356. update_screen_time();
  2357. grab_trick(8);
  2358. *pmap -= 32;
  2359. load_map(map.loc[*pmap]);
  2360. if (map.indoor[*pmap] == 0) play.last_map = *pmap;
  2361.  
  2362. spr[h].x = spr[h].lpx[0];
  2363. draw_map_game();
  2364. spr[h].y = 399;
  2365.  
  2366. goto b1end;
  2367. } else
  2368. {
  2369. spr[h].y = 0;
  2370. }
  2371. }
  2372.  
  2373.  
  2374. if ( (spr[h].y > 399 ) )
  2375. {
  2376. if ( (map.loc[*pmap+32] > 0) && (screenlock == 0) )
  2377. {
  2378. //move one map down
  2379. if (real)
  2380. {
  2381. move_gonna = true;
  2382. return;
  2383. }
  2384. update_screen_time();
  2385. grab_trick(2);
  2386. *pmap += 32;
  2387. load_map(map.loc[*pmap]);
  2388. if (map.indoor[*pmap] == 0) play.last_map = *pmap;
  2389.  
  2390. draw_map_game();
  2391. spr[h].y = 0;
  2392.  
  2393. spr[h].x = spr[h].lpx[0];
  2394.  
  2395. goto b1end;
  2396. } else
  2397. {
  2398. spr[h].y = 399;
  2399. }
  2400. }
  2401.  
  2402.  
  2403.  
  2404. b1end:;
  2405.  
  2406.  
  2407.  
  2408. }
  2409.  
  2410.  
  2411. bool run_through_tag_list_talk(int h)
  2412. {
  2413. RECT box;
  2414. int amount, amounty;
  2415.  
  2416. for (int i = 1; i <= last_sprite_created; i++)
  2417. {
  2418.  
  2419. if (spr[i].active) if (i != h) if (spr[i].brain != 8)
  2420. {
  2421.  
  2422.  
  2423. CopyRect(&box, &k[getpic(i)].hardbox);
  2424. OffsetRect(&box, spr[i].x, spr[i].y);
  2425.  
  2426. InflateRect(&box, 10,10);
  2427.  
  2428. amount = 50;
  2429. amounty = 35;
  2430. if (spr[h].dir == 6)
  2431. {
  2432. box.left -= amount;
  2433. }
  2434.  
  2435. if (spr[h].dir == 4)
  2436. {
  2437. box.right += amount;
  2438. }
  2439.  
  2440.  
  2441. if (spr[h].dir == 2)
  2442. {
  2443. box.top -= amounty;
  2444. }
  2445.  
  2446. if (spr[h].dir == 8)
  2447. {
  2448. box.bottom += amounty;
  2449. }
  2450.  
  2451. // draw_box(box, 33);
  2452.  
  2453. if (inside_box(spr[h].x, spr[h].y, box))
  2454. {
  2455. //Msg("Talking to sprite %d", i);
  2456. if (spr[i].script > 0)
  2457. {
  2458. //if ( (spr[i].brain == 0) | (spr[i].brain == 5) | (spr[i].brain == 6) | (spr[i].brain == 7))
  2459. //Msg("trying to find TALK in script %d", spr[i].script);
  2460. if (locate(spr[i].script, "TALK"))
  2461. {
  2462. kill_returning_stuff(spr[i].script);
  2463.  
  2464. run_script(spr[i].script);
  2465. return(true);
  2466. }
  2467.  
  2468.  
  2469. }
  2470.  
  2471. }
  2472.  
  2473.  
  2474. }
  2475.  
  2476.  
  2477. }
  2478.  
  2479.  
  2480. return(false);
  2481. }
  2482.  
  2483.  
  2484.  
  2485.  
  2486.  
  2487. void make_missile(int x1, int y1, int dir, int speed, int seq, int frame, int strength)
  2488. {
  2489. int crap = add_sprite(x1,y1,11,seq,frame);
  2490. spr[crap].speed = speed;
  2491. spr[crap].seq = seq;
  2492. spr[crap].timer = 0;
  2493. spr[crap].strength = strength;
  2494. spr[crap].flying = true;
  2495. changedir(dir, crap, 430);
  2496.  
  2497. }
  2498.  
  2499.  
  2500.  
  2501.  
  2502. void missile_brain( int h, bool repeat)
  2503. {
  2504. RECT box;
  2505. automove(h);
  2506.  
  2507. *pmissle_source = h;
  2508. int hard = check_if_move_is_legal(h);
  2509. if (repeat) if (spr[h].seq == 0) spr[h].seq = spr[h].seq_orig;
  2510. spr[1].hitpoints = *plife;
  2511.  
  2512. if (hard > 0) if (hard != 2)
  2513. {
  2514.  
  2515. //lets check to see if they hit a sprites hardness
  2516. if (hard > 100)
  2517. {
  2518. for (int ii = 1; ii < last_sprite_created; ii++)
  2519. {
  2520. if (spr[ii].sp_index == hard-100)
  2521. {
  2522. if (spr[ii].script > 0)
  2523. {
  2524. *pmissile_target = 1;
  2525. *penemy_sprite = 1;
  2526.  
  2527.  
  2528.  
  2529. if (locate(spr[ii].script, "HIT"))
  2530. {
  2531. kill_returning_stuff(spr[ii].script);
  2532. run_script(spr[ii].script);
  2533.  
  2534. }
  2535. }
  2536.  
  2537.  
  2538. if (spr[h].script > 0)
  2539. {
  2540. *pmissile_target = ii;
  2541. *penemy_sprite = 1;
  2542. if (locate(spr[h].script, "DAMAGE"))
  2543. {
  2544. kill_returning_stuff(spr[h].script);
  2545. run_script(spr[h].script);
  2546. }
  2547. } else
  2548. {
  2549.  
  2550. if (spr[h].attack_hit_sound == 0)
  2551. {
  2552. SoundPlayEffect( 9,22050, 0 ,0,0);
  2553. } else
  2554. {
  2555. SoundPlayEffect( spr[h].attack_hit_sound,spr[h].attack_hit_sound_speed, 0 ,0,0);
  2556. }
  2557.  
  2558.  
  2559. spr[h].active = 0;
  2560.  
  2561.  
  2562. }
  2563.  
  2564.  
  2565. //run missile end
  2566. return;
  2567. }
  2568.  
  2569. }
  2570.  
  2571. }
  2572. //run missile end
  2573.  
  2574. if (spr[h].script > 0)
  2575. {
  2576.  
  2577.  
  2578. *pmissile_target = 0;
  2579. if (locate(spr[h].script, "DAMAGE")) run_script(spr[h].script);
  2580. } else
  2581. {
  2582.  
  2583. if (spr[h].attack_hit_sound == 0)
  2584. {
  2585. SoundPlayEffect( 9,22050, 0 ,0,0);
  2586. } else
  2587. {
  2588. SoundPlayEffect( spr[h].attack_hit_sound,spr[h].attack_hit_sound_speed, 0 ,0,0);
  2589. }
  2590.  
  2591.  
  2592. spr[h].active = 0;
  2593. return;
  2594. }
  2595.  
  2596. }
  2597.  
  2598. if (spr[h].x > 1000) spr[h].active = false;
  2599. if (spr[h].y > 700) spr[h].active = false;
  2600. if (spr[h].y < -500) spr[h].active = false;
  2601. if (spr[h].x < -500) spr[h].active = false;
  2602.  
  2603. //did we hit anything that can die?
  2604.  
  2605. for (int j = 1; j <= last_sprite_created; j++)
  2606. {
  2607. if (spr[j].active) if (h != j) if (spr[j].nohit != 1) if (spr[j].notouch == false)
  2608. if (spr[h].brain_parm != j) if (spr[h].brain_parm2!= j) //if (spr[j].brain != 15) if
  2609. //(spr[j].brain != 11)
  2610. {
  2611. CopyRect(&box, &k[getpic(j)].hardbox);
  2612. OffsetRect(&box, spr[j].x, spr[j].y);
  2613.  
  2614. if (spr[h].range != 0)
  2615. InflateRect(&box, spr[h].range,spr[h].range);
  2616.  
  2617. if (debug_mode) draw_box(box, 33);
  2618.  
  2619.  
  2620. if (inside_box(spr[h].x, spr[h].y, box))
  2621. {
  2622.  
  2623. spr[j].notouch = true;
  2624. spr[j].notouch_timer = thisTickCount+100;
  2625. spr[j].target = 1;
  2626. *penemy_sprite = 1;
  2627. //change later to reflect REAL target
  2628. if (spr[h].script > 0)
  2629. {
  2630.  
  2631. *pmissile_target = j;
  2632. if (locate(spr[h].script, "DAMAGE")) run_script(spr[h].script);
  2633. } else
  2634. {
  2635.  
  2636. if (spr[h].attack_hit_sound == 0)
  2637. {
  2638. SoundPlayEffect( 9,22050, 0 ,0,0);
  2639. } else
  2640. {
  2641. SoundPlayEffect( spr[h].attack_hit_sound,spr[h].attack_hit_sound_speed, 0 ,0,0);
  2642. }
  2643.  
  2644. }
  2645.  
  2646.  
  2647. if ( spr[j].hitpoints > 0) if (spr[h].strength != 0)
  2648. {
  2649. int hit = 0;
  2650. if (spr[h].strength == 1) hit = spr[h].strength - spr[j].defense; else
  2651.  
  2652. hit = (spr[h].strength / 2) + ((rand() % (spr[h].strength / 2))+1)
  2653. - spr[j].defense;
  2654.  
  2655. if (hit < 0) hit = 0;
  2656.  
  2657.  
  2658. spr[j].damage += hit;
  2659. if (hit > 0)
  2660. {
  2661. random_blood(spr[j].x, spr[j].y-40, j);
  2662. }
  2663. spr[j].last_hit = 1;
  2664. //Msg("Damage done is %d..", spr[j].damage);
  2665. }
  2666.  
  2667. if (spr[j].script > 0)
  2668. {
  2669. //CHANGED did = h
  2670. *pmissile_target = 1;
  2671.  
  2672. if (locate(spr[j].script, "HIT"))
  2673. {
  2674. kill_returning_stuff(spr[j].script);
  2675. run_script(spr[j].script);
  2676. }
  2677. }
  2678.  
  2679. }
  2680. //run missile end
  2681.  
  2682. }
  2683. }
  2684.  
  2685. }
  2686.  
  2687.  
  2688. void missile_brain_expire(int h)
  2689. {
  2690. missile_brain(h, false);
  2691. if (spr[h].seq == 0) spr[h].active = 0;
  2692.  
  2693. }
  2694.  
  2695. void run_through_mouse_list(int h, bool special)
  2696. {
  2697. RECT box;
  2698. int amount, amounty;
  2699.  
  2700. for (int i = 1; i <= last_sprite_created; i++)
  2701. {
  2702.  
  2703. if (spr[i].active) if (i != h) if
  2704. ((spr[i].touch_damage != 0) )
  2705. {
  2706.  
  2707. if (spr[i].touch_damage != -1) if (spr[h].notouch) return;
  2708. CopyRect(&box, &k[getpic(i)].hardbox);
  2709. OffsetRect(&box, spr[i].x, spr[i].y);
  2710.  
  2711.  
  2712. if (inside_box(spr[h].x, spr[h].y, box))
  2713. {
  2714.  
  2715. if ((spr[i].touch_damage == -1) && (spr[i].script != 0))
  2716. {
  2717. Msg("running %d's script..",spr[i].script);
  2718. if (locate(spr[i].script, "CLICK")) run_script(spr[i].script);
  2719. }
  2720. else
  2721. {
  2722. if (spr[i].touch_damage == -1)
  2723. {
  2724. Msg("Sprites touch damage is set to -1 but there is no script set!");
  2725. } else
  2726. {
  2727. //lets hurt the guy
  2728. }
  2729.  
  2730. }
  2731.  
  2732. if (special) return;
  2733.  
  2734. }
  2735.  
  2736.  
  2737. }
  2738.  
  2739. }
  2740.  
  2741. if (special) SoundPlayEffect(19, 22050, 0, 0,0);
  2742.  
  2743. }
  2744.  
  2745.  
  2746.  
  2747.  
  2748. void mouse_brain(int h)
  2749. {
  2750.  
  2751. if (spr[h].move_active)
  2752. {
  2753. process_move(h);
  2754. return;
  2755. }
  2756.  
  2757.  
  2758. int diag = 0;
  2759.  
  2760. if (sjoy.right) diag++;
  2761. if (sjoy.left) diag++;
  2762. if (sjoy.down) diag++;
  2763. if (sjoy.up) diag++;
  2764.  
  2765.  
  2766. //*********************************PROCESS MOVEMENT
  2767.  
  2768. if (diag == 1)
  2769. {
  2770.  
  2771. if (sjoy.right)
  2772. {
  2773. move(h,spr[h].speed,'+','0');
  2774. changedir(6,h,spr[h].base_walk);
  2775. }
  2776.  
  2777.  
  2778. if (sjoy.left)
  2779. {
  2780. move(h,spr[h].speed,'-','0');
  2781. changedir(4,h,spr[h].base_walk);
  2782. }
  2783.  
  2784.  
  2785. if (sjoy.down)
  2786. {
  2787. move(h,spr[h].speed,'0','+');
  2788. changedir(2,h,spr[h].base_walk);
  2789. }
  2790.  
  2791.  
  2792. if (sjoy.up)
  2793. {
  2794. move(h,spr[h].speed,'0','-');
  2795. changedir(8,h,spr[h].base_walk);
  2796. }
  2797.  
  2798. }
  2799. // ***************** DIAGONAL!!!!
  2800.  
  2801. if (diag > 1)
  2802. {
  2803.  
  2804. if ( (sjoy.up) & (sjoy.left) )
  2805. {
  2806. changedir(7,h,spr[h].base_walk);
  2807. move(h,spr[h].speed - (spr[h].speed / 3),'-','-');
  2808.  
  2809. }
  2810.  
  2811. if ( (sjoy.down) & (sjoy.left))
  2812. {
  2813. changedir(1,h,spr[h].base_walk);
  2814. move(h,spr[h].speed - (spr[h].speed / 3),'-','+');
  2815.  
  2816. }
  2817.  
  2818. if ( (sjoy.down) & (sjoy.right))
  2819. {
  2820. changedir(3,h,spr[h].base_walk);
  2821. move(h,spr[h].speed - (spr[h].speed / 3),'+','+');
  2822. }
  2823.  
  2824.  
  2825. if ( (sjoy.up) & (sjoy.right))
  2826. {
  2827. changedir(9,h,spr[h].base_walk);
  2828. move(h,spr[h].speed - (spr[h].speed / 3),'+','-');
  2829. }
  2830.  
  2831. }
  2832.  
  2833.  
  2834.  
  2835.  
  2836. if ( (sjoy.button[1] == TRUE) | (mouse1) )
  2837. {
  2838.  
  2839. Msg("running through mouse list..");
  2840. run_through_mouse_list(h, true);
  2841. sjoy.button[1] = false;
  2842. mouse1 = false;
  2843.  
  2844. }
  2845.  
  2846. }
  2847.  
  2848. void process_bow( int h)
  2849. {
  2850. int timetowait = 100;
  2851.  
  2852.  
  2853. if (bow.wait < thisTickCount)
  2854. {
  2855. if (sjoy.right) spr[h].dir = 6;
  2856. if (sjoy.left) spr[h].dir = 4;
  2857. if (sjoy.up) spr[h].dir = 8;
  2858. if (sjoy.down) spr[h].dir = 2;
  2859. }
  2860.  
  2861.  
  2862.  
  2863. if (sjoy.right) if (sjoy.up)
  2864. {
  2865. spr[h].dir = 9;
  2866. bow.wait = thisTickCount + timetowait;
  2867. }
  2868. if (sjoy.left) if (sjoy.up)
  2869. {
  2870. spr[h].dir = 7;
  2871. bow.wait = thisTickCount + timetowait;
  2872. }
  2873. if (sjoy.right) if (sjoy.down)
  2874. {
  2875. spr[h].dir = 3;
  2876. bow.wait = thisTickCount + timetowait;
  2877.  
  2878. }
  2879. if (sjoy.left) if (sjoy.down)
  2880. {
  2881. spr[h].dir = 1;
  2882. bow.wait = thisTickCount + timetowait;
  2883.  
  2884. }
  2885. spr[h].pseq = 100+spr[h].dir;
  2886.  
  2887.  
  2888. if (bow.pull_wait < thisTickCount)
  2889. {
  2890. bow.pull_wait = thisTickCount + 10;
  2891. if (bow.hitme) bow.time += 7;
  2892.  
  2893.  
  2894. // bowsound->SetFrequency(22050+(bow.time*10));
  2895.  
  2896. if (bow.time > 500) bow.time = 500;
  2897. spr[h].pframe = (bow.time / 100)+1;
  2898. }
  2899.  
  2900.  
  2901. if (sjoy.letgo[1])
  2902. {
  2903. bow.active = false;
  2904. bow.last_power = bow.time;
  2905. run_script(bow.script);
  2906. // bowsound->Stop();
  2907. return;
  2908. }
  2909.  
  2910. }
  2911.  
  2912.  
  2913.  
  2914.  
  2915. void human_brain(int h)
  2916.  
  2917. {
  2918.  
  2919. int diag, x5;
  2920. int crap;
  2921. BOOL bad;
  2922.  
  2923. if (mode == 0) goto b1end;
  2924.  
  2925.  
  2926. if (spr[h].move_active)
  2927. {
  2928. process_move(h);
  2929. return;
  2930. }
  2931.  
  2932.  
  2933. if (spr[h].damage > 0)
  2934. {
  2935.  
  2936. draw_damage(h);
  2937.  
  2938. *plife -= spr[h].damage;
  2939.  
  2940. spr[h].damage = 0;
  2941. if (*plife < 0) *plife = 0;
  2942.  
  2943. int hurt = (rand() % 2)+1;
  2944.  
  2945. if (hurt == 1) SoundPlayEffect( 15,25050, 2000 ,0,0);
  2946. if (hurt == 2) SoundPlayEffect( 16,25050, 2000 ,0,0);
  2947.  
  2948.  
  2949. //draw blood
  2950.  
  2951. }
  2952.  
  2953.  
  2954. if (play.push_active)
  2955. {
  2956.  
  2957. if (play.push_dir == 2) if (!sjoy.down)
  2958. {
  2959. spr[h].nocontrol = false;
  2960. play.push_active = false;
  2961. }
  2962.  
  2963. if (play.push_dir == 4) if (!sjoy.left)
  2964. {
  2965. spr[h].nocontrol = false;
  2966. play.push_active = false;
  2967. }
  2968. if (play.push_dir == 6) if (!sjoy.right)
  2969. {
  2970. spr[h].nocontrol = false;
  2971. play.push_active = false;
  2972. }
  2973.  
  2974. if (play.push_dir == 8) if (!sjoy.up)
  2975. {
  2976. spr[h].nocontrol = false;
  2977. play.push_active = false;
  2978. }
  2979.  
  2980.  
  2981. }
  2982.  
  2983. if (spr[h].nocontrol) return;
  2984.  
  2985. if (talk.active) goto freeze;
  2986.  
  2987.  
  2988. if ( spr[h].freeze)
  2989.  
  2990. {
  2991. //they are frozen
  2992.  
  2993. if ( (sjoy.button[2] == TRUE) || (sjoy.key[32]))
  2994. {
  2995. //they hit the talk button while frozen, lets hurry up the process
  2996.  
  2997. for (int jj = 1; jj <= last_sprite_created; jj++)
  2998. {
  2999.  
  3000. // Msg("Checking %d, brain %d, script %d, my freeze is %d",jj, spr[jj].brain, spr[jj].script, spr[h].freeze);
  3001. if (spr[jj].brain == 8) if (spr[jj].script == play.last_talk)
  3002. {
  3003. //this sprite owns its freeze
  3004.  
  3005. spr[jj].kill_timer = 1;
  3006. //force the message to be over
  3007. }
  3008.  
  3009. }
  3010.  
  3011.  
  3012.  
  3013.  
  3014. }
  3015.  
  3016.  
  3017.  
  3018.  
  3019. goto freeze;
  3020. }
  3021. //****************************** KEYS THAT CAN BE PRESSED AT ANY TIME **************
  3022.  
  3023. //if (GetKeyboard(127) PostMessage(hWnd, WM_CLOSE, 0, 0);
  3024.  
  3025.  
  3026. if (bow.active)
  3027. {
  3028.  
  3029. //bow is active!!
  3030. process_bow(h);
  3031. return;
  3032. }
  3033.  
  3034.  
  3035.  
  3036. if (play.push_active) if (play.push_timer + 600 < thisTickCount)
  3037. {
  3038. spr[h].seq = mDinkBasePush+spr[h].dir;
  3039. spr[h].frame = 1;
  3040. spr[h].nocontrol = true;
  3041. //play.push_active = false;
  3042. run_through_tag_list_push(h);
  3043.  
  3044. return;
  3045. }
  3046.  
  3047.  
  3048.  
  3049. if ( (sjoy.button[2] == TRUE) )
  3050. {
  3051.  
  3052. if (!run_through_tag_list_talk(h))
  3053. {
  3054. //redink1 addition of 'not talking to anything' script
  3055. int sc = load_script("DNOTALK", 0, false);
  3056. if (sc != 0 && locate(sc,"MAIN"))
  3057. {
  3058. run_script(sc);
  3059. }
  3060. else
  3061. {
  3062.  
  3063. kill_text_owned_by(h);
  3064. int randy = (rand() % 6)+1;
  3065.  
  3066. #ifdef __GERMAN
  3067. if (randy == 1) say_text("`$Hier ist nichts.",h,0);
  3068. if (randy == 2) say_text("`$Huh?",h,0);
  3069. if (randy == 3) say_text("`$Ich bin mir ziemlich sicher ich kann dies weder ansprechen, noch benutzen.",h,0);
  3070. if (randy == 4) say_text("`$Was?",h,0);
  3071. if (randy == 5) say_text("`$Bah, LANGWEILIG.",h,0);
  3072. if (randy == 6) say_text("`$Hier passiert nichts.",h,0);
  3073.  
  3074. #endif
  3075.  
  3076. #ifdef __ENGLISH
  3077. if (randy == 1) say_text("`$I don't see anything here.",h,0);
  3078. if (randy == 2) say_text("`$Huh?",h,0);
  3079. if (randy == 3) say_text("`$I'm fairly sure I can't talk to or use that.",h,0);
  3080. if (randy == 4) say_text("`$What?",h,0);
  3081. if (randy == 5) say_text("`$I'm bored.",h,0);
  3082. if (randy == 6) say_text("`$Not much happening here.",h,0);
  3083. #endif
  3084. }
  3085. }
  3086.  
  3087.  
  3088. }
  3089.  
  3090.  
  3091. if ( (sjoy.button[1] == TRUE) && (weapon_script != 0) )
  3092. {
  3093.  
  3094.  
  3095.  
  3096. if (spr[h].base_hit > 0)
  3097. {
  3098.  
  3099.  
  3100. if (locate(weapon_script, "USE")) run_script(weapon_script);
  3101.  
  3102. goto b1end;
  3103.  
  3104. }
  3105.  
  3106. }
  3107.  
  3108.  
  3109. //added AGAIN 10-19-99
  3110. //Let's check keys for getting hit
  3111. if (but_timer < thisTickCount)
  3112. {
  3113. //redink1 Only accept keyboard input when console is not active.
  3114. if ( mConsoleActive == false )
  3115. {
  3116. for (x5=29; x5<255; x5++)
  3117. {
  3118. if (x5 == 32) x5++;
  3119. if (x5 == 54) x5++;
  3120. if (x5 == 55) x5++;
  3121. if (x5 == 37) x5++;
  3122. if (x5 == 38) x5++;
  3123. if (x5 == 39) x5++;
  3124. if (x5 == 40) x5++;
  3125. if (x5 == 77) x5++;
  3126.  
  3127.  
  3128. char msg[30];
  3129. if (GetKeyboard(x5))
  3130. {
  3131. sprintf(msg, "key-%d",x5);
  3132. but_timer = thisTickCount+200;
  3133.  
  3134. int mycrap = load_script(msg, 1, false);
  3135. if (locate(mycrap, "MAIN"))
  3136. {
  3137. run_script(mycrap);
  3138. goto b1end;
  3139. }
  3140. }
  3141. }
  3142. }
  3143. }
  3144.  
  3145.  
  3146. if ( sjoy.button[6] == TRUE )
  3147. {
  3148. int mycrap = load_script("BUTTON6", 1, false);
  3149. if (locate(mycrap, "MAIN")) run_script(mycrap);
  3150. goto b1end;
  3151. }
  3152.  
  3153. if ( sjoy.button[7] == TRUE )
  3154. {
  3155. int mycrap = load_script("BUTTON7", 1, false);
  3156. if (locate(mycrap, "MAIN")) run_script(mycrap);
  3157. goto b1end;
  3158. }
  3159.  
  3160. if ( sjoy.button[8] == TRUE )
  3161. {
  3162. int mycrap = load_script("BUTTON8", 1, false);
  3163. if (locate(mycrap, "MAIN")) run_script(mycrap);
  3164. goto b1end;
  3165. }
  3166.  
  3167. if ( sjoy.button[9] == TRUE )
  3168. {
  3169. int mycrap = load_script("BUTTON9", 1, false);
  3170. if (locate(mycrap, "MAIN")) run_script(mycrap);
  3171. goto b1end;
  3172. }
  3173.  
  3174. if ( sjoy.button[10] == TRUE )
  3175. {
  3176. int mycrap = load_script("BUTTON10", 1, false);
  3177. if (locate(mycrap, "MAIN")) run_script(mycrap);
  3178. goto b1end;
  3179. }
  3180.  
  3181. if (magic_script != 0) if (sjoy.joybit[3]) goto shootm;
  3182. if ( (sjoy.button[3] == TRUE) )
  3183. {
  3184. if (magic_script == 0)
  3185. {
  3186. //redink1 addition of 'no magic' script
  3187. int sc = load_script("DNOMAGIC", 0, false);
  3188. if (sc != 0 && locate(sc,"MAIN"))
  3189. {
  3190. run_script(sc);
  3191. }
  3192. else
  3193. {
  3194. int randy = (rand() % 6)+1;
  3195. kill_text_owned_by(h);
  3196.  
  3197.  
  3198. #ifdef __GERMAN
  3199.  
  3200. //if (randy == 3)
  3201. if (randy == 1) say_text("`$Ich muß erst die Magie erlernen, bevor ich dies ausprobieren kann..",h,0);
  3202. if (randy == 2) say_text("`$Ich gestikuliere hier wie wirr!",h,0);
  3203. if (randy == 3) say_text("`$Ich gestikuliere hier wie wirr!",h,0);
  3204. if (randy == 4) say_text("`$Ich gestikuliere hier wie wirr!",h,0);
  3205. if (randy == 5) say_text("`$Nichts ist passiert.",h,0);
  3206. if (randy == 6) say_text("`$Hokus pokus!",h,0);
  3207. #endif
  3208.  
  3209. #ifdef __ENGLISH
  3210. if (randy == 1) say_text("`$I don't know any magic.",h,0);
  3211. if (randy == 2) say_text("`$I'm no wizard!",h,0);
  3212. if (randy == 3) say_text("`$I need to learn magic before trying this.",h,0);
  3213. if (randy == 4) say_text("`$I'm gesturing wildly to no avail!",h,0); //redink1 removed an extra space
  3214. if (randy == 5) say_text("`$Nothing happened.",h,0);
  3215. if (randy == 6) say_text("`$Hocus pocus!",h,0);
  3216. #endif
  3217. }
  3218.  
  3219. goto b1end;
  3220. }
  3221.  
  3222. //player pressed 1
  3223. //lets magiced something
  3224. shootm:
  3225. if (*pmagic_level >= *pmagic_cost)
  3226. {
  3227. if (locate(magic_script, "USE")) run_script(magic_script);
  3228.  
  3229. goto b1end;
  3230. }
  3231. }
  3232.  
  3233. if (sjoy.button[4])
  3234. {
  3235. //redink1 addition of 'enter key/inventory' script
  3236. int sc = load_script("BUTTON4", 0, false);
  3237. if (sc != 0) {
  3238. if (locate(sc,"MAIN")) {
  3239. run_script(sc);
  3240. return;
  3241. }
  3242. }
  3243.  
  3244. item_screen = true;
  3245. SoundPlayEffect(18, 22050,0,0,0);
  3246. return;
  3247. }
  3248.  
  3249.  
  3250.  
  3251. /*if ( GetKeyboard(50) )
  3252. {
  3253.  
  3254. if (!no_cheat)
  3255. {
  3256. //player pressed 2
  3257. //lets add a duck with brain 2
  3258.  
  3259. crap = add_sprite(spr[h].x-20,spr[h].y-50,3,26,1);
  3260. spr[crap].speed = 1;
  3261. spr[crap].base_walk = 20;
  3262. spr[crap].exp = 11;
  3263. spr[crap].hitpoints = 5;
  3264. }
  3265. }*/
  3266.  
  3267.  
  3268. if ( (sjoy.button[5] == TRUE) )
  3269. {
  3270.  
  3271. if (!showb.active) if (!bow.active) if (!talk.active)
  3272. {
  3273. int sc = load_script("ESCAPE", 1000, false);
  3274. if (sc != 0) if (locate(sc,"MAIN")) run_script(sc);
  3275. return;
  3276. }
  3277. }
  3278.  
  3279. //redink1 Only accept keyboard input when console is not active.
  3280. if ( mConsoleActive == false )
  3281. {
  3282. if (GetKeyboard(66))
  3283. {
  3284. ResumeMidi();
  3285. }
  3286.  
  3287. if (GetKeyboard(78))
  3288. {
  3289. PauseMidi();
  3290. }
  3291. }
  3292.  
  3293. if (spr[h].skip > 0)
  3294.  
  3295. if (spr[h].skip <= spr[h].skiptimer)
  3296. {
  3297. spr[h].skiptimer = 0;
  3298. goto b1end;
  3299. }
  3300.  
  3301.  
  3302. diag = 0;
  3303. if (sjoy.right) diag++;
  3304. if (sjoy.left) diag++;
  3305. if (sjoy.down) diag++;
  3306. if (sjoy.up) diag++;
  3307.  
  3308.  
  3309. //*********************************PROCESS MOVEMENT
  3310.  
  3311. if (diag == 1)
  3312. {
  3313.  
  3314. if (sjoy.right)
  3315. {
  3316. move(h,spr[h].speed,'+','0');
  3317. changedir(6,h,spr[h].base_walk);
  3318. }
  3319.  
  3320.  
  3321. if (sjoy.left)
  3322. {
  3323. move(h,spr[h].speed,'-','0');
  3324. changedir(4,h,spr[h].base_walk);
  3325. }
  3326.  
  3327.  
  3328. if (sjoy.down)
  3329. {
  3330. move(h,spr[h].speed,'0','+');
  3331. changedir(2,h,spr[h].base_walk);
  3332.  
  3333. }
  3334.  
  3335.  
  3336. if (sjoy.up)
  3337. {
  3338. move(h,spr[h].speed,'0','-');
  3339. changedir(8,h,spr[h].base_walk);
  3340. }
  3341.  
  3342. }
  3343. // ***************** DIAGONAL!!!!
  3344.  
  3345.  
  3346. if (diag > 1) if (diag < 3)
  3347. {
  3348.  
  3349. if ( (sjoy.up) & (sjoy.left) )
  3350. {
  3351. changedir(7,h,spr[h].base_walk);
  3352. move(h,spr[h].speed - (spr[h].speed / 3),'-','-');
  3353.  
  3354. }
  3355.  
  3356. if ( (sjoy.down) & (sjoy.left))
  3357. {
  3358. changedir(1,h,spr[h].base_walk);
  3359. move(h,spr[h].speed - (spr[h].speed / 3),'-','+');
  3360.  
  3361. }
  3362.  
  3363. if ( (sjoy.down) & (sjoy.right))
  3364. {
  3365. changedir(3,h,spr[h].base_walk);
  3366. move(h,spr[h].speed - (spr[h].speed / 3),'+','+');
  3367. }
  3368.  
  3369.  
  3370. if ( (sjoy.up) & (sjoy.right))
  3371. {
  3372. changedir(9,h,spr[h].base_walk);
  3373. move(h,spr[h].speed - (spr[h].speed / 3),'+','-');
  3374. }
  3375.  
  3376. }
  3377.  
  3378.  
  3379. bad = FALSE;
  3380. if (sjoy.right) bad = TRUE;
  3381. if (sjoy.left) bad = TRUE;
  3382. if (sjoy.up) bad = TRUE;
  3383. if (sjoy.down) bad = TRUE;
  3384.  
  3385. if (bad)
  3386. {
  3387. if (spr[h].idle)
  3388. {
  3389. spr[h].frame = 1;
  3390. spr[h].idle = FALSE;
  3391. }
  3392. goto badboy;
  3393. }
  3394.  
  3395.  
  3396. if (not_in_this_base(spr[h].seq, spr[h].base_idle)) //unccoment to allow walk anim to end before idle anim to start
  3397. {
  3398. freeze:
  3399. if (spr[h].dir == 1) spr[h].dir = 2;
  3400. if (spr[h].dir == 3) spr[h].dir = 2;
  3401. if (spr[h].dir == 7) spr[h].dir = 8;
  3402. if (spr[h].dir == 9) spr[h].dir = 8;
  3403.  
  3404. if (spr[h].base_idle != 0) changedir(spr[h].dir,h,spr[h].base_idle);
  3405. spr[h].idle = TRUE;
  3406. }
  3407.  
  3408.  
  3409. badboy:
  3410.  
  3411.  
  3412.  
  3413. b1end:;
  3414.  
  3415. if ( (spr[h].dir == 2) | (spr[h].dir == 4) | (spr[h].dir == 6) | (spr[h].dir == 8)) goto smoothend;
  3416. crap = check_if_move_is_legal(h);
  3417. if (crap != 0)
  3418. {
  3419. if (pam.sprite[crap-100].prop != 0) flub_mode = crap;
  3420.  
  3421. //hit something, can we move around it?
  3422.  
  3423.  
  3424. if( (spr[h].seq == spr[h].base_walk + 4) |
  3425. (spr[h].seq == spr[h].base_walk + 6) )
  3426. {
  3427. int hardm = get_hard_play(h, spr[h].x, spr[h].y-1);
  3428. if (hardm == 0)
  3429. {
  3430. spr[h].y -= 1;
  3431.  
  3432. }
  3433.  
  3434. }
  3435.  
  3436.  
  3437.  
  3438.  
  3439.  
  3440.  
  3441.  
  3442. if( (spr[h].seq == spr[h].base_walk + 8) |
  3443. (spr[h].seq == spr[h].base_walk + 2) )
  3444. {
  3445. int hardm = get_hard_play(h, spr[h].x-1, spr[h].y);
  3446. if (hardm == 0)
  3447. {
  3448. spr[h].x -= 1;
  3449.  
  3450. }
  3451.  
  3452. }
  3453.  
  3454.  
  3455.  
  3456.  
  3457. if (spr[h].seq == spr[h].base_walk + 9)
  3458. {
  3459. int hardm = get_hard_play(h, spr[h].x+1, spr[h].y);
  3460. if (hardm == 0)
  3461. {
  3462. spr[h].x += 1;
  3463.  
  3464. } else
  3465. {
  3466. int hardm = get_hard_play(h, spr[h].x+1, spr[h].y+1);
  3467. if (hardm == 0)
  3468. {
  3469. spr[h].x += 1;
  3470. spr[h].y += 1;
  3471. } else
  3472. {
  3473. int hardm = get_hard_play(h, spr[h].x+1, spr[h].y+2);
  3474. if (hardm == 0)
  3475. {
  3476. spr[h].x += 1;
  3477. spr[h].y += 2;
  3478. } else
  3479. {
  3480. int hardm = get_hard_play(h, spr[h].x, spr[h].y-1);
  3481. if (hardm == 0)
  3482. {
  3483. spr[h].y -= 1;
  3484.  
  3485. } else
  3486. {
  3487. int hardm = get_hard_play(h, spr[h].x-1, spr[h].y-1);
  3488. if (hardm == 0)
  3489. {
  3490. spr[h].x -= 1;
  3491. spr[h].y -= 1;
  3492. }
  3493.  
  3494. }
  3495.  
  3496.  
  3497.  
  3498. }
  3499.  
  3500. }
  3501.  
  3502.  
  3503. }
  3504.  
  3505. }
  3506.  
  3507. if (spr[h].seq == spr[h].base_walk + 7)
  3508. {
  3509. int hardm = get_hard_play(h, spr[h].x-1, spr[h].y);
  3510. if (hardm == 0)
  3511. {
  3512. spr[h].x -= 1;
  3513.  
  3514. } else
  3515. {
  3516. int hardm = get_hard_play(h, spr[h].x-1, spr[h].y+1);
  3517. if (hardm == 0)
  3518. {
  3519. spr[h].x -= 1;
  3520. spr[h].y += 1;
  3521. } else
  3522. {
  3523. int hardm = get_hard_play(h, spr[h].x-1, spr[h].y+2);
  3524. if (hardm == 0)
  3525. {
  3526. spr[h].x -= 1;
  3527. spr[h].y += 2;
  3528. } else
  3529. {
  3530.  
  3531. int hardm = get_hard_play(h, spr[h].x, spr[h].y-1);
  3532. if (hardm == 0)
  3533. {
  3534. spr[h].y -= 1;
  3535. } else
  3536. {
  3537. int hardm = get_hard_play(h, spr[h].x+1, spr[h].y-1);
  3538. if (hardm == 0)
  3539. {
  3540. spr[h].x += 1;
  3541. spr[h].y -= 1;
  3542. }
  3543. }
  3544.  
  3545. }
  3546.  
  3547. }
  3548.  
  3549.  
  3550. }
  3551.  
  3552. }
  3553.  
  3554.  
  3555.  
  3556. if (spr[h].seq == spr[h].base_walk + 1)
  3557. {
  3558. int hardm = get_hard_play(h, spr[h].x-1, spr[h].y);
  3559. if (hardm == 0)
  3560. {
  3561. spr[h].x -= 1;
  3562. } else
  3563. {
  3564. int hardm = get_hard_play(h, spr[h].x-1, spr[h].y-1);
  3565. if (hardm == 0)
  3566. {
  3567. spr[h].x -= 1;
  3568. spr[h].y -= 1;
  3569. } else
  3570. {
  3571. int hardm = get_hard_play(h, spr[h].x-1, spr[h].y-2);
  3572. if (hardm == 0)
  3573. {
  3574. spr[h].x -= 1;
  3575. spr[h].y -= 2;
  3576. } else
  3577. {
  3578. int hardm = get_hard_play(h, spr[h].x, spr[h].y+1);
  3579. if (hardm == 0)
  3580. {
  3581.  
  3582. spr[h].y += 1;
  3583. } else
  3584. {
  3585. int hardm = get_hard_play(h, spr[h].x+1, spr[h].y+1);
  3586. if (hardm == 0)
  3587. {
  3588. spr[h].x += 1;
  3589. spr[h].y += 1;
  3590. }
  3591.  
  3592. }
  3593.  
  3594. }
  3595.  
  3596. }
  3597.  
  3598.  
  3599. }
  3600.  
  3601. }
  3602.  
  3603. if (spr[h].seq == spr[h].base_walk + 3)
  3604. {
  3605. int hardm = get_hard_play(h, spr[h].x+1, spr[h].y);
  3606. if (hardm == 0)
  3607. {
  3608. spr[h].x += 1;
  3609.  
  3610. } else
  3611. {
  3612. int hardm = get_hard_play(h, spr[h].x+1, spr[h].y-1);
  3613. if (hardm == 0)
  3614. {
  3615. spr[h].x += 1;
  3616. spr[h].y -= 1;
  3617. } else
  3618. {
  3619. int hardm = get_hard_play(h, spr[h].x+1, spr[h].y-2);
  3620. if (hardm == 0)
  3621. {
  3622. spr[h].x += 1;
  3623. spr[h].y -= 2;
  3624. } else
  3625. {
  3626. int hardm = get_hard_play(h, spr[h].x, spr[h].y+1);
  3627. if (hardm == 0)
  3628. {
  3629.  
  3630. spr[h].y += 1;
  3631. } else
  3632. {
  3633. int hardm = get_hard_play(h, spr[h].x-1, spr[h].y+1);
  3634. if (hardm == 0)
  3635. {
  3636. spr[h].x -= 1;
  3637. spr[h].y += 1;
  3638. }
  3639.  
  3640. }
  3641.  
  3642. }
  3643.  
  3644. }
  3645.  
  3646.  
  3647. }
  3648.  
  3649. }
  3650.  
  3651.  
  3652.  
  3653. }
  3654.  
  3655.  
  3656.  
  3657. smoothend:;
  3658.  
  3659. }
  3660.  
  3661. bool transition(void)
  3662. {
  3663. RECT rcRect;
  3664. HRESULT ddrval;
  3665. //we need to do our fancy screen transition
  3666. int dumb = 5;
  3667. //if (fps_final < 30) dumb = 50;
  3668. dumb = fps_final * 2;
  3669.  
  3670. move_counter += dumb;
  3671.  
  3672.  
  3673. if (no_transition)
  3674. {
  3675.  
  3676. total_trigger = false;
  3677. move_screen = 0;
  3678. move_counter = 0;
  3679. trig_man = 0;
  3680. //draw_map();
  3681. return(false);
  3682. }
  3683.  
  3684.  
  3685. //total_trigger = false;
  3686. //return(false);
  3687.  
  3688. if (move_screen == 4)
  3689. {
  3690. //move_counter =+ 20;
  3691.  
  3692. if (move_counter > 598) move_counter = 598;
  3693.  
  3694.  
  3695. rcRect.left = 0;
  3696. rcRect.right = 600 - move_counter;
  3697. rcRect.top = 0;
  3698. rcRect.bottom = 400;
  3699.  
  3700. ddrval = lpDDSBack->BltFast( move_counter+20, 0, lpDDSTrick,
  3701. &rcRect, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
  3702. if (ddrval != DD_OK) dderror(ddrval);
  3703.  
  3704. rcRect.left = 600 - move_counter; ;
  3705. rcRect.right = 600;
  3706. rcRect.top = 0;
  3707. rcRect.bottom = 400;
  3708.  
  3709. ddrval = lpDDSBack->BltFast( 20, 0, lpDDSTrick2,
  3710. &rcRect, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
  3711.  
  3712.  
  3713.  
  3714.  
  3715. if (ddrval != DD_OK) dderror(ddrval);
  3716.  
  3717. if (move_counter >= 595)
  3718. {
  3719. total_trigger = false;
  3720. move_screen = 0;
  3721. move_counter = 0;
  3722. trig_man = 0;
  3723. //draw_map();
  3724. return(false);
  3725. }
  3726.  
  3727. return(true);
  3728. }
  3729.  
  3730. if (move_screen == 6)
  3731. {
  3732. //move_counter =+ 20;
  3733.  
  3734.  
  3735. if (move_counter > 598) move_counter = 598;
  3736. rcRect.left = move_counter;
  3737. rcRect.right = 600; //redink1 fix so entire screen scrolls
  3738. rcRect.top = 0;
  3739. rcRect.bottom = 400; //redink1 fix so entire screen scrolls
  3740.  
  3741. ddrval = lpDDSBack->BltFast(20, 0, lpDDSTrick,
  3742. &rcRect, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
  3743. if (ddrval != DD_OK) dderror(ddrval);
  3744.  
  3745. rcRect.left = 0;
  3746. rcRect.right = move_counter;
  3747. rcRect.top = 0;
  3748. rcRect.bottom = 400; //redink1 fix so entire screen scrolls
  3749.  
  3750. ddrval = lpDDSBack->BltFast( 620 - move_counter, 0, lpDDSTrick2,
  3751. &rcRect, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
  3752.  
  3753. if (ddrval != DD_OK) dderror(ddrval);
  3754.  
  3755. if (move_counter >= 595)
  3756. {
  3757. total_trigger = false;
  3758. move_screen = 0;
  3759. move_counter = 0;
  3760. trig_man = 0;
  3761. //draw_map();
  3762. return(false);
  3763. }
  3764.  
  3765. return(true);
  3766. }
  3767.  
  3768.  
  3769. if (move_screen == 8)
  3770. {
  3771. //move_counter =+ 20;
  3772.  
  3773. if (move_counter > 398) move_counter = 398;
  3774.  
  3775.  
  3776. rcRect.left = 0;
  3777. rcRect.right = 600; //redink1 fix so entire screen scrolls
  3778.  
  3779. rcRect.top = 0;
  3780. rcRect.bottom = 400 - move_counter; //redink1 fix so entire screen scrolls
  3781.  
  3782. ddrval = lpDDSBack->BltFast( 20, move_counter, lpDDSTrick,
  3783. &rcRect, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
  3784. if (ddrval != DD_OK) dderror(ddrval);
  3785.  
  3786. rcRect.left = 0;
  3787. rcRect.right = 600; //redink1 fix so entire screen scrolls
  3788. rcRect.top = 400 - move_counter; ; //redink1 fix so entire screen scrolls
  3789. rcRect.bottom = 400; //redink1 fix so entire screen scrolls
  3790.  
  3791. ddrval = lpDDSBack->BltFast( 20, 0, lpDDSTrick2,
  3792. &rcRect, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
  3793.  
  3794.  
  3795.  
  3796.  
  3797. if (ddrval != DD_OK) dderror(ddrval);
  3798.  
  3799. if (move_counter >= 398)
  3800. {
  3801. total_trigger = false;
  3802. move_screen = 0;
  3803. move_counter = 0;
  3804. trig_man = 0;
  3805. //draw_map();
  3806. return(false);
  3807. }
  3808.  
  3809. return(true);
  3810. }
  3811.  
  3812.  
  3813.  
  3814. if (move_screen == 2)
  3815. {
  3816. //move_counter =+ 20;
  3817.  
  3818.  
  3819. if (move_counter > 398) move_counter = 398;
  3820. rcRect.left = 0;
  3821.  
  3822. rcRect.right = 600; //redink1 fix so entire screen scrolls
  3823. rcRect.top = move_counter;
  3824. rcRect.bottom = 400; //redink1 fix so entire screen scrolls
  3825.  
  3826. ddrval = lpDDSBack->BltFast(20, 0, lpDDSTrick,
  3827. &rcRect, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
  3828. if (ddrval != DD_OK) dderror(ddrval);
  3829.  
  3830. rcRect.left = 0;
  3831. rcRect.right = 600; //redink1 fix so entire screen scrolls
  3832.  
  3833. rcRect.top = 0;
  3834. rcRect.bottom = move_counter;
  3835.  
  3836. ddrval = lpDDSBack->BltFast( 20, 400 - move_counter, lpDDSTrick2, //redink1 fix so entire screen scrolls
  3837. &rcRect, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
  3838.  
  3839. if (ddrval != DD_OK) dderror(ddrval);
  3840.  
  3841. if (move_counter >= 398)
  3842. {
  3843. total_trigger = false;
  3844. move_screen = 0;
  3845. move_counter = 0;
  3846. trig_man = 0;
  3847. //draw_map();
  3848. return(false);
  3849. }
  3850.  
  3851. return(true);
  3852. }
  3853.  
  3854.  
  3855.  
  3856.  
  3857. return(false);
  3858. }
  3859.  
  3860.  
  3861.  
  3862.  
  3863. int find_sprite(int block)
  3864. {
  3865.  
  3866. for (int k = 1; k <= last_sprite_created; k++)
  3867. {
  3868. if (spr[k].sp_index == block)
  3869. {
  3870. return(k);
  3871. }
  3872.  
  3873. }
  3874.  
  3875. return(0);
  3876.  
  3877. }
  3878.  
  3879. int special_block(int block, int h)
  3880. {
  3881.  
  3882. if (pam.sprite[block].prop == 1)
  3883. {
  3884. //they touched a warp
  3885.  
  3886. if (pam.sprite[block].sound == 0)
  3887. SoundPlayEffect( 7,12000, 0 , 0,0); else
  3888. SoundPlayEffect( pam.sprite[block].sound,22050, 0 , 0,0);
  3889.  
  3890. if (pam.sprite[block].parm_seq != 0)
  3891. {
  3892. //we'll also play an animation here
  3893.  
  3894. int sprite = find_sprite(block);
  3895. if (sprite > 0)
  3896. {
  3897. spr[sprite].seq = pam.sprite[block].parm_seq;
  3898. process_warp = block;
  3899. }
  3900. return(1);
  3901. }
  3902. process_warp = block;
  3903. /*spr[1].x = pam.sprite[block].warp_x;
  3904. spr[1].y = pam.sprite[block].warp_y;
  3905. *pmap = pam.sprite[block].warp_map;
  3906.  
  3907. load_map(map.loc[pam.sprite[block].warp_map]);
  3908. draw_map();
  3909. */
  3910. return(1); //redraw screen with fade
  3911. }
  3912. return(0);
  3913. }
  3914.  
  3915. void CyclePalette()
  3916. {
  3917. //redink1 truecolor fadedown...
  3918. if (truecolor)
  3919. {
  3920. process_downcycle = true;
  3921. }
  3922. else
  3923. {
  3924. int reg[15];
  3925. int k;
  3926. bool done_this_time = true;
  3927.  
  3928. if(lpDDPal->GetEntries(0,0,256,pe)!=DD_OK)
  3929. {
  3930. Msg("error with getting entries");
  3931. return;
  3932. }
  3933. int lValue = (thisTickCount - lastTickCount) / 2;
  3934. for (int kk = 1; kk < 256; kk++)
  3935. {
  3936. if (pe[kk].peBlue != 0)
  3937. {
  3938. done_this_time = false;
  3939. if (pe[kk].peBlue > lValue)
  3940. pe[kk].peBlue -= lValue;
  3941. else
  3942. pe[kk].peBlue = 0;
  3943. }
  3944.  
  3945. if (pe[kk].peGreen != 0)
  3946. {
  3947. done_this_time = false;
  3948.  
  3949. if (pe[kk].peGreen > lValue)
  3950. pe[kk].peGreen -= lValue;
  3951. else
  3952. pe[kk].peGreen = 0;
  3953.  
  3954. }
  3955. if (pe[kk].peRed != 0)
  3956. {
  3957. done_this_time = false;
  3958.  
  3959. if (pe[kk].peRed > lValue)
  3960. pe[kk].peRed -= lValue;
  3961. else
  3962. pe[kk].peRed = 0;
  3963. }
  3964. }
  3965.  
  3966. lpDD->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN,NULL);
  3967.  
  3968.  
  3969. if(lpDDPal->SetEntries(0,0,256,pe) !=DD_OK)
  3970. {
  3971. Msg("error with setting entries");
  3972. return;
  3973. }
  3974.  
  3975.  
  3976. if (process_downcycle)
  3977. {
  3978. if (thisTickCount > cycle_clock)
  3979. {
  3980. process_downcycle = false;
  3981.  
  3982. if (cycle_script != 0)
  3983. {
  3984. int junk = cycle_script;
  3985. cycle_script = 0;
  3986. run_script(junk);
  3987.  
  3988.  
  3989. }
  3990. }
  3991. }
  3992. }
  3993. }
  3994.  
  3995.  
  3996. void up_cycle(void)
  3997. {
  3998. //redink1 added this for true-color fade support
  3999. if (truecolor)
  4000. {
  4001. process_upcycle = true;
  4002. }
  4003. else
  4004. {
  4005. bool donethistime = true;
  4006.  
  4007. if(lpDDPal->GetEntries(0,0,256,pe)!=DD_OK)
  4008. {
  4009. Msg("error with getting entries");
  4010. return;
  4011. }
  4012.  
  4013. //redink1 changed <= to < so it doesn't modify stuff it should not (i.e. fgold, somehow!?)
  4014. for (int kk = 1; kk < 256; kk++)
  4015. {
  4016.  
  4017.  
  4018. if (pe[kk].peBlue != real_pal[kk].peBlue)
  4019. {
  4020. if (pe[kk].peBlue > 246) pe[kk].peBlue++; else
  4021. pe[kk].peBlue += 10;
  4022. donethistime = false;
  4023. }
  4024.  
  4025. if (pe[kk].peBlue > real_pal[kk].peBlue) pe[kk].peBlue = real_pal[kk].peBlue;
  4026.  
  4027.  
  4028. if (pe[kk].peGreen != real_pal[kk].peGreen)
  4029. {
  4030.  
  4031. if (pe[kk].peGreen > 246) pe[kk].peGreen++; else
  4032. pe[kk].peGreen += 10;
  4033. donethistime = false;
  4034. }
  4035.  
  4036. if (pe[kk].peGreen > real_pal[kk].peGreen) pe[kk].peGreen = real_pal[kk].peGreen;
  4037.  
  4038. if (pe[kk].peRed != real_pal[kk].peRed)
  4039. {
  4040. if (pe[kk].peRed> 246) pe[kk].peRed++; else
  4041. pe[kk].peRed += 10;
  4042. donethistime = false;
  4043. }
  4044.  
  4045. if (pe[kk].peRed > real_pal[kk].peRed) pe[kk].peRed = real_pal[kk].peRed;
  4046.  
  4047.  
  4048. }
  4049.  
  4050.  
  4051. lpDD->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN,NULL);
  4052.  
  4053. if(lpDDPal->SetEntries(0,0,256,pe) !=DD_OK)
  4054. {
  4055. Msg("error with setting entries");
  4056. // return;
  4057. }
  4058.  
  4059. if (process_upcycle) if (donethistime)
  4060.  
  4061. {
  4062. process_upcycle = false;
  4063.  
  4064.  
  4065. if (cycle_script != 0)
  4066. {
  4067. int junk = cycle_script;
  4068. cycle_script = 0;
  4069. run_script(junk);
  4070.  
  4071. }
  4072.  
  4073. }
  4074. }
  4075.  
  4076. }
  4077. void draw_box(RECT box, int color)
  4078. {
  4079. DDBLTFX ddbltfx;
  4080.  
  4081. ddbltfx.dwSize = sizeof(ddbltfx);
  4082. ddbltfx.dwFillColor = color;
  4083.  
  4084.  
  4085. ddrval = lpDDSBack->Blt(&box ,NULL, NULL, DDBLT_COLORFILL| DDBLT_WAIT, &ddbltfx);
  4086.  
  4087.  
  4088. }
  4089.  
  4090. //redink1 added for true-color fade...
  4091. WORD GetMaskPos( DWORD dwMask )
  4092. {
  4093. WORD wPos = 0;
  4094. while( !(dwMask & (1 << wPos)) ) wPos++;
  4095. return wPos;
  4096. }
  4097.  
  4098. //redink1 added for true-color fade...
  4099. WORD GetNumberOfBits( DWORD dwMask )
  4100. {
  4101. WORD wBits = 0;
  4102. while( dwMask )
  4103. {
  4104. dwMask = dwMask & ( dwMask - 1 );
  4105. wBits++;
  4106. }
  4107. return wBits;
  4108. }
  4109.  
  4110. //redink1 added for true-color fade...
  4111. DDSURFACEDESC sdBack;
  4112.  
  4113. void ApplyFade16( unsigned short aValue, unsigned short* aBuffer, unsigned int aPitch )
  4114. {
  4115. unsigned int lJump( aPitch - 640 * 2 );
  4116. for ( unsigned short lYCoordinate( 0 ); lYCoordinate < 480; lYCoordinate++ )
  4117. {
  4118. for ( unsigned short lXCoordinate( 0 ); lXCoordinate < 640; lXCoordinate++ )
  4119. {
  4120. *aBuffer = m16BitFadeValues[*aBuffer][aValue];
  4121. aBuffer += 1;
  4122. }
  4123. aBuffer += lJump;
  4124. }
  4125. return;
  4126. }
  4127.  
  4128. void ApplyFade24( unsigned char aValue, unsigned char* aBuffer, unsigned int aPitch )
  4129. {
  4130. unsigned int lJump( aPitch - 640 * 3 );
  4131. for ( unsigned short lYCoordinate( 0 ); lYCoordinate < 480; lYCoordinate++ )
  4132. {
  4133. for ( unsigned short lXCoordinate( 0 ); lXCoordinate < 640; lXCoordinate++ )
  4134. {
  4135. if ( *((DWORD*)aBuffer) != 0xFFFFFF )
  4136. {
  4137. *aBuffer = m8BitFadeValues[*aBuffer][aValue];
  4138. aBuffer += 1;
  4139. *aBuffer = m8BitFadeValues[*aBuffer][aValue];
  4140. aBuffer += 1;
  4141. *aBuffer = m8BitFadeValues[*aBuffer][aValue];
  4142. aBuffer += 1;
  4143. }
  4144. else
  4145. {
  4146. aBuffer += 3;
  4147. }
  4148. }
  4149. aBuffer += lJump;
  4150. }
  4151. return;
  4152. }
  4153.  
  4154. void ApplyFade32( register unsigned char aValue, register unsigned char* aBuffer, unsigned int aPitch )
  4155. {
  4156. unsigned int lJump( aPitch - 640 * 4 );
  4157. for ( register unsigned short lYCoordinate( 0 ); lYCoordinate < 480; lYCoordinate++ )
  4158. {
  4159. for ( register unsigned short lXCoordinate( 0 ); lXCoordinate < 640; lXCoordinate++ )
  4160. {
  4161. if ( *((DWORD*)aBuffer) != 0xFFFFFF )
  4162. {
  4163. // Blue
  4164. *aBuffer = m8BitFadeValues[*aBuffer][aValue];
  4165. aBuffer += 1;
  4166.  
  4167. // Green
  4168. *aBuffer = m8BitFadeValues[*aBuffer][aValue];
  4169. aBuffer += 1;
  4170.  
  4171. // Red
  4172. *aBuffer = m8BitFadeValues[*aBuffer][aValue];
  4173. aBuffer += 2;
  4174. }
  4175. else
  4176. {
  4177. aBuffer += 4;
  4178. }
  4179. }
  4180. aBuffer += lJump;
  4181. }
  4182. return;
  4183. }
  4184.  
  4185. //redink1 and Invertigo fix for windowed/high color mode
  4186. void flip_it(void)
  4187. {
  4188. DDBLTFX ddbltfx;
  4189.  
  4190. RECT rcRectSrc; RECT rcRectDest;
  4191. POINT p;
  4192.  
  4193.  
  4194. /*int timer = GetTickCount() + 50;
  4195. while(GetTickCount() < timer)
  4196. {
  4197. }
  4198. */
  4199.  
  4200. //redink1 fix for true-color transition
  4201. //The idea is to apply the fade to the backbuffer right before the main flip/blt.
  4202. if (truecolor && (process_downcycle || process_upcycle || bFadedDown))
  4203. {
  4204. RECT r;
  4205. r.bottom = 480;
  4206. r.left = 0;
  4207. r.right = 640;
  4208. r.top = 0;
  4209.  
  4210. //Make sure we're not 'stuck'... i.e. fade down when already black, or fade up when not black
  4211. if (process_downcycle && bFadedDown || process_upcycle && !bFadedDown)
  4212. {
  4213. if (process_downcycle)
  4214. process_downcycle = false;
  4215. if (process_upcycle)
  4216. {
  4217. process_upcycle = false;
  4218. if ( mSwapped )
  4219. {
  4220. // if ( windowed )
  4221. // {
  4222. lpDDSFade->BltFast( 0, 0, lpDDSBack, &r, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
  4223. LPDIRECTDRAWSURFACE lTemp;
  4224. lTemp = lpDDSBack;
  4225. lpDDSBack = lpDDSFade;
  4226. lpDDSFade = lTemp;
  4227. /* }
  4228. else
  4229. {
  4230. DDSURFACEDESC ddsd;
  4231. lpDDSBack->GetSurfaceDesc( &ddsd );
  4232. ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
  4233.  
  4234. LPDIRECTDRAWSURFACE lTemp;
  4235. ddrval = lpDDSPrimary->GetAttachedSurface( &ddsd.ddsCaps, &lTemp );
  4236.  
  4237. lTemp->BltFast( 0, 0, lpDDSBack, &r, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
  4238.  
  4239. lpDDSBack->Release();
  4240. lpDDSBack = lTemp;
  4241. }
  4242. */ mSwapped = false;
  4243. }
  4244. }
  4245. if (cycle_script != 0)
  4246. {
  4247. int junk = cycle_script;
  4248. cycle_script = 0;
  4249. run_script(junk);
  4250. }
  4251. }
  4252. if ( process_downcycle || bFadedDown || process_upcycle )
  4253. {
  4254. if ( mSwapped == false )
  4255. {
  4256. // if ( windowed )
  4257. // {
  4258. lpDDSFade->BltFast( 0, 0, lpDDSBack, &r, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
  4259. LPDIRECTDRAWSURFACE lTemp;
  4260. lTemp = lpDDSBack;
  4261. lpDDSBack = lpDDSFade;
  4262. lpDDSFade = lTemp;
  4263. /* }
  4264. else
  4265. {
  4266. DDSURFACEDESC ddsd;
  4267. lpDDSBack->GetSurfaceDesc( &ddsd );
  4268. ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER | DDSCAPS_SYSTEMMEMORY;
  4269.  
  4270. lpDDSBack->Release();
  4271.  
  4272. LPDIRECTDRAWSURFACE lTemp;
  4273. ddrval = lpDDSPrimary->GetAttachedSurface( &ddsd.ddsCaps, &lTemp );
  4274.  
  4275. lTemp->BltFast( 0, 0, lpDDSBack, &r, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
  4276.  
  4277. lpDDSBack->Release();
  4278. lpDDSBack = lTemp;
  4279. }
  4280. */ mSwapped = true;
  4281. }
  4282.  
  4283. unsigned char lFadeValue = static_cast<unsigned char>( 30.0f * ( static_cast<float>( iTrueColorFadeTime ) / 400.0f ) );
  4284.  
  4285. if ( lFadeValue >= 30 )
  4286. {
  4287. iTrueColorFadeTime = 0;
  4288. if ( process_downcycle == true )
  4289. {
  4290. bFadedDown = true;
  4291. }
  4292. else if ( process_upcycle == true )
  4293. {
  4294. bFadedDown = false;
  4295. }
  4296. lFadeValue = 29;
  4297. }
  4298.  
  4299. if ( process_upcycle == true )
  4300. {
  4301. lFadeValue = 29 - lFadeValue;
  4302. }
  4303. else if ( bFadedDown == true )
  4304. {
  4305. lFadeValue = 29;
  4306. }
  4307.  
  4308. //Setup surface description data-structure
  4309. memset(&sdBack, 0, sizeof(DDSURFACEDESC));
  4310. sdBack.dwSize = sizeof(DDSURFACEDESC);
  4311.  
  4312. //Lock our surfaces
  4313. lpDDSBack->Lock(NULL, &sdBack, DDLOCK_DONOTWAIT, NULL);
  4314.  
  4315. //Copy backbuffer to fade surface
  4316. // HRESULT h = lpDDSFade->BltFast( 0, 0, lpDDSBack, &r, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
  4317.  
  4318. //Lock our surfaces
  4319. // lpDDSFade->Lock(NULL, &sdBack, DDLOCK_WAIT | DDLOCK_NOSYSLOCK, NULL);
  4320.  
  4321. if ( mColorDepth == ColorDepth16Bit_565 || mColorDepth == ColorDepth16Bit_555 )
  4322. {
  4323. unsigned short* lBuffer = (unsigned short*)sdBack.lpSurface;
  4324. ApplyFade16( lFadeValue, lBuffer, sdBack.lPitch );
  4325. }
  4326. else if ( mColorDepth == ColorDepth24Bit )
  4327. {
  4328. unsigned char* lBuffer = (unsigned char*)sdBack.lpSurface;
  4329. ApplyFade24( lFadeValue, lBuffer, sdBack.lPitch );
  4330. }
  4331. else if ( mColorDepth == ColorDepth32Bit )
  4332. {
  4333. unsigned char* lBuffer = (unsigned char*)sdBack.lpSurface;
  4334. ApplyFade32( lFadeValue, lBuffer, sdBack.lPitch );
  4335. }
  4336.  
  4337. iTrueColorFadeTime += fps_final;
  4338.  
  4339. lpDDSBack->Unlock( NULL );
  4340.  
  4341. if ( !windowed )
  4342. {
  4343. lpDDSFade->BltFast( 0, 0, lpDDSBack, &r, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
  4344. }
  4345.  
  4346. // lpDDSFade->Unlock( NULL );
  4347. // h = lpDDSBack->BltFast( 0, 0, lpDDSFade, &r, DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT);
  4348. }
  4349. }
  4350.  
  4351. if (!windowed)
  4352. {
  4353.  
  4354.  
  4355.  
  4356. while( 1 )
  4357. {
  4358. ddrval = lpDDSPrimary->Flip(NULL,DDFLIP_WAIT );
  4359. if( ddrval == DD_OK )
  4360. {
  4361. break;
  4362. }
  4363. if( ddrval == DDERR_SURFACELOST )
  4364. {
  4365.  
  4366. restoreAll();
  4367. if( ddrval != DD_OK )
  4368. {
  4369. break;
  4370. }
  4371. }
  4372. if( ddrval != DDERR_WASSTILLDRAWING )
  4373. {
  4374.  
  4375.  
  4376. }
  4377. }
  4378.  
  4379. } else
  4380. {
  4381. //windowed mode, no flipping
  4382. p.x = 0; p.y = 0;
  4383. ClientToScreen(hWndMain, &p);
  4384. GetClientRect(hWndMain, &rcRectDest);
  4385.  
  4386. //rcRectDest.top += winoffset;
  4387. rcRectDest.bottom = 480;
  4388. rcRectDest.right = 640;
  4389.  
  4390. OffsetRect(&rcRectDest, p.x, p.y);
  4391. SetRect(&rcRectSrc, 0, 0, 640, 480);
  4392.  
  4393. ddbltfx.dwSize = sizeof(ddbltfx);
  4394.  
  4395. ddbltfx.dwDDFX = DDBLTFX_NOTEARING;
  4396.  
  4397. lpDD->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL);
  4398. ddrval = lpDDSPrimary->Blt( &rcRectDest, lpDDSBack, &rcRectSrc, DDBLT_DDFX | DDBLT_WAIT, &ddbltfx);
  4399. }
  4400.  
  4401.  
  4402.  
  4403. }
  4404.  
  4405.  
  4406.  
  4407. void run_through_tag_list(int h, int strength)
  4408. {
  4409. RECT box;
  4410. int amount, amounty;
  4411.  
  4412. for (int i = 1; i <= last_sprite_created; i++)
  4413. {
  4414. if (spr[i].active) if (i != h) if
  4415. (! ( (spr[i].nohit == 1) && (spr[i].script == 0)) )
  4416. {
  4417.  
  4418. CopyRect(&box, &k[getpic(i)].hardbox);
  4419. OffsetRect(&box, spr[i].x, spr[i].y);
  4420.  
  4421. //InflateRect(&box, 10,10);
  4422.  
  4423. box.right += 5;
  4424. box.left -= 5;
  4425. box.top -= 5;
  4426. box.bottom += 10;
  4427. if (spr[h].range == 0)
  4428. amount = 28; else amount = spr[h].range;
  4429.  
  4430. if (spr[h].range == 0)
  4431.  
  4432. amounty = 36; else amounty = (spr[h].range + (spr[h].range / 6));
  4433.  
  4434. int range_amount = spr[h].range / 8;
  4435.  
  4436. if (spr[h].dir == 6)
  4437. {
  4438. box.top -= 10;
  4439. box.bottom += 10;
  4440. if (spr[h].range != 0) box.top -= range_amount;
  4441. if (spr[h].range != 0) box.bottom += range_amount;
  4442.  
  4443.  
  4444. box.left -= amount;
  4445. }
  4446.  
  4447. if (spr[h].dir == 4)
  4448. {
  4449. box.right += amount;
  4450.  
  4451. box.top -= 10;
  4452. box.bottom += 10;
  4453. if (spr[h].range != 0) box.top -= range_amount;
  4454. if (spr[h].range != 0) box.bottom += range_amount;
  4455.  
  4456. }
  4457.  
  4458.  
  4459. if (spr[h].dir == 2)
  4460. {
  4461. box.right += 10;
  4462. box.left -= 10;
  4463. box.top -= amounty;
  4464.  
  4465. if (spr[h].range != 0) box.right += range_amount;
  4466. if (spr[h].range != 0) box.left -= range_amount;
  4467.  
  4468. }
  4469.  
  4470. if (spr[h].dir == 8)
  4471. {
  4472. box.right += 10;
  4473. box.left -= 10;
  4474. box.bottom += amounty;
  4475.  
  4476. if (spr[h].range != 0) box.right += range_amount;
  4477. if (spr[h].range != 0) box.right -= range_amount;
  4478.  
  4479. }
  4480.  
  4481. if (debug_mode) draw_box(box, 33);
  4482.  
  4483. if (inside_box(spr[h].x, spr[h].y, box))
  4484. {
  4485. //redink1 addition for fixing missle_source problems
  4486. *pmissle_source = h;
  4487. if (spr[i].nohit == 1)
  4488. {
  4489. if (spr[i].script > 0)
  4490. {
  4491. //if ( (spr[i].brain == 0) | (spr[i].brain == 5) | (spr[i].brain == 6) | (spr[i].brain == 7))
  4492. *penemy_sprite = h;
  4493.  
  4494. if ( (spr[i].base_attack != -1) || (spr[i].touch_damage > 0))
  4495. spr[i].target = h;
  4496.  
  4497. if (locate(spr[i].script, "HIT"))
  4498. {
  4499. kill_returning_stuff(spr[i].script);
  4500. run_script(spr[i].script);
  4501. }
  4502.  
  4503.  
  4504. }
  4505.  
  4506.  
  4507. } else
  4508. {
  4509. //hit this personb/thing
  4510. if (spr[h].attack_hit_sound == 0)
  4511. {
  4512. SoundPlayEffect( 9,22050, 0 ,0,0);
  4513. } else
  4514. {
  4515. SoundPlayEffect( spr[h].attack_hit_sound,spr[h].attack_hit_sound_speed, 0 ,0,0);
  4516. }
  4517. if ( (spr[i].base_attack != -1) || (spr[i].touch_damage > 0))
  4518. spr[i].target = h;
  4519. if (spr[h].strength == 0)
  4520. {
  4521.  
  4522. } else
  4523. {
  4524. if ( (spr[i].hitpoints > 0) || (i == 1) )
  4525. {
  4526.  
  4527. spr[i].last_hit = h;
  4528. if ( hurt_thing(i, (spr[h].strength / 2) + ((rand() % ((spr[h].strength+1) / 2))+1), 0) > 0)
  4529. random_blood(spr[i].x, spr[i].y-40, i); //redink1
  4530. }
  4531.  
  4532. }
  4533. if (spr[i].script > 0)
  4534. {
  4535. //if ( (spr[i].brain == 0) | (spr[i].brain == 5) | (spr[i].brain == 6) | (spr[i].brain == 7))
  4536. spr[i].last_hit = h;
  4537. *penemy_sprite = h;
  4538. if ( (spr[i].base_attack != -1) || (spr[i].touch_damage > 0))
  4539. spr[i].target = h;
  4540.  
  4541. if (locate(spr[i].script, "HIT"))
  4542. {
  4543. kill_returning_stuff(spr[i].script);
  4544. run_script(spr[i].script);
  4545. }
  4546.  
  4547. }
  4548.  
  4549. }
  4550.  
  4551. }
  4552.  
  4553. }
  4554.  
  4555. }
  4556.  
  4557. }
  4558.  
  4559.  
  4560.  
  4561. void run_through_tag_list_push(int h)
  4562. {
  4563. RECT box;
  4564.  
  4565. for (int i = 1; i <= last_sprite_created; i++)
  4566. {
  4567. if (spr[i].active) if (i != h) if
  4568. ((spr[i].script != 0) )
  4569. {
  4570.  
  4571. CopyRect(&box, &k[getpic(i)].hardbox);
  4572. OffsetRect(&box, spr[i].x, spr[i].y);
  4573.  
  4574. //InflateRect(&box, 10,10);
  4575.  
  4576. box.right += 2;
  4577. box.left -= 2;
  4578. box.top -= 2;
  4579. box.bottom += 2;
  4580. //draw_box(box, 33);
  4581.  
  4582. if (inside_box(spr[h].x, spr[h].y, box))
  4583. {
  4584. if (locate(spr[i].script, "PUSH")) run_script(spr[i].script);
  4585. }
  4586.  
  4587. }
  4588.  
  4589. }
  4590.  
  4591. }
  4592.  
  4593.  
  4594.  
  4595.  
  4596. void run_through_touch_damage_list(int h)
  4597. {
  4598. RECT box;
  4599. int amount, amounty;
  4600. for (int i = 1; i <= last_sprite_created; i++)
  4601. {
  4602. if (spr[i].active) if (i != h) if
  4603. ((spr[i].touch_damage != 0) )
  4604. {
  4605.  
  4606. if (spr[i].touch_damage != -1) if (spr[h].notouch) return;
  4607. CopyRect(&box, &k[getpic(i)].hardbox);
  4608. OffsetRect(&box, spr[i].x, spr[i].y);
  4609.  
  4610. //InflateRect(&box, 10,10);
  4611.  
  4612. box.right += 2;
  4613. box.left -= 2;
  4614. box.top -= 2;
  4615. box.bottom += 2;
  4616. if (debug_mode)
  4617. draw_box(box, 33);
  4618.  
  4619.  
  4620. if (inside_box(spr[h].x, spr[h].y, box))
  4621. {
  4622.  
  4623. if ((spr[i].touch_damage == -1) && (spr[i].script != 0))
  4624. {
  4625. if (locate(spr[i].script, "TOUCH")) run_script(spr[i].script);
  4626. } else
  4627. {
  4628. if (spr[i].touch_damage == -1)
  4629. {
  4630. Msg("Sprites touch damage is set to -1 but there is no script set!");
  4631. } else
  4632. {
  4633. //lets hurt the guy
  4634.  
  4635. spr[h].notouch = true;
  4636. spr[h].notouch_timer = thisTickCount+400;
  4637. spr[h].last_hit = i;
  4638. if (spr[i].script != 0)
  4639. if (locate(spr[i].script, "TOUCH")) run_script(spr[i].script);
  4640. if (hurt_thing(h, spr[i].touch_damage, 0) > 0)
  4641. random_blood(spr[h].x, spr[h].y-40, h);
  4642.  
  4643.  
  4644. }
  4645.  
  4646. }
  4647.  
  4648.  
  4649.  
  4650. }
  4651.  
  4652.  
  4653. }
  4654.  
  4655. }
  4656.  
  4657. }
  4658.  
  4659.  
  4660.  
  4661.  
  4662. void process_warp_man(void)
  4663. {
  4664. RECT box_crap;
  4665. DDBLTFX ddbltfx;
  4666.  
  4667. int sprite = find_sprite(process_warp);
  4668.  
  4669.  
  4670. if (spr[sprite].seq == 0)
  4671. {
  4672. process_count++;
  4673. if (!truecolor || truecolor && process_count == 1) //redink1 Limit palette cycles for true color mode
  4674. CyclePalette();
  4675. if (process_count > 5 && !truecolor || truecolor && process_downcycle == false) //redink1 more limits for fade down stuff
  4676. {
  4677. ddbltfx.dwSize = sizeof(ddbltfx);
  4678.  
  4679. ddbltfx.dwFillColor = 0;
  4680. SetRect(&box_crap, 0,0,640,480);
  4681.  
  4682. ddrval = lpDDSBack->Blt(&box_crap ,NULL, NULL, DDBLT_COLORFILL| DDBLT_WAIT, &ddbltfx);
  4683.  
  4684. flip_it();
  4685.  
  4686. process_count = 0;
  4687. int block = process_warp;
  4688. update_screen_time();
  4689. spr[1].x = pam.sprite[block].warp_x;
  4690. spr[1].y = pam.sprite[block].warp_y;
  4691. *pmap = pam.sprite[block].warp_map;
  4692.  
  4693. //redink1 change so map indicator is correct on warp.
  4694. if (map.indoor[pam.sprite[block].warp_map] == 0)
  4695. play.last_map = pam.sprite[block].warp_map;
  4696.  
  4697. load_map(map.loc[pam.sprite[block].warp_map]);
  4698.  
  4699. draw_map_game();
  4700.  
  4701. process_upcycle = true;
  4702. process_warp = 0;
  4703. }
  4704.  
  4705. } else
  4706. {
  4707. process_count = 0;
  4708.  
  4709. }
  4710.  
  4711. }
  4712.  
  4713. void one_time_brain(int h)
  4714. {
  4715.  
  4716. //goes once then draws last frame to background
  4717.  
  4718. if (spr[h].move_active)
  4719. {
  4720. process_move(h);
  4721. return;
  4722. }
  4723.  
  4724. if (spr[h].follow > 0)
  4725. {
  4726. process_follow(h);
  4727. }
  4728.  
  4729.  
  4730. if (spr[h].seq == 0)
  4731. {
  4732. draw_sprite_game(lpDDSTwo,h);
  4733. spr[h].active = false;
  4734. return;
  4735. }
  4736.  
  4737. changedir(spr[h].dir,h,-1);
  4738. automove(h);
  4739.  
  4740. }
  4741.  
  4742. void one_time_brain_for_real(int h)
  4743. {
  4744.  
  4745. if (spr[h].move_active)
  4746. {
  4747. process_move(h);
  4748. }
  4749.  
  4750.  
  4751. if (spr[h].follow > 0)
  4752. {
  4753. process_follow(h);
  4754. }
  4755.  
  4756.  
  4757. if (spr[h].seq == 0)
  4758. {
  4759.  
  4760. spr[h].active = false;
  4761. return;
  4762. }
  4763. if (spr[h].dir > 0)
  4764. {
  4765. changedir(spr[h].dir,h,-1);
  4766. automove(h);
  4767. }
  4768. }
  4769.  
  4770.  
  4771. void scale_brain(int h)
  4772. {
  4773.  
  4774. if (spr[h].size == spr[h].brain_parm)
  4775. {
  4776. spr[h].active = false;
  4777.  
  4778.  
  4779. return;
  4780. }
  4781.  
  4782. int num = 5 * (base_timing / 4);
  4783.  
  4784.  
  4785.  
  4786. if (spr[h].size > spr[h].brain_parm)
  4787. {
  4788. if (spr[h].size - num < spr[h].brain_parm) num = spr[h].size - spr[h].brain_parm;
  4789. spr[h].size -= num;
  4790. }
  4791.  
  4792. if (spr[h].size < spr[h].brain_parm)
  4793. {
  4794. if (spr[h].size + num > spr[h].brain_parm) num = spr[h].brain_parm - spr[h].size;
  4795. spr[h].size += num;
  4796. }
  4797. if (spr[h].move_active)
  4798. {
  4799. process_move(h);
  4800. return;
  4801. }
  4802.  
  4803.  
  4804.  
  4805. if (spr[h].dir > 0)
  4806. {
  4807. changedir(spr[h].dir,h,-1);
  4808. automove(h);
  4809. }
  4810.  
  4811.  
  4812. }
  4813.  
  4814.  
  4815.  
  4816. void repeat_brain(int h)
  4817. {
  4818.  
  4819. if (spr[h].move_active)
  4820. {
  4821. process_move(h);
  4822. // return;
  4823. }
  4824.  
  4825.  
  4826. if (spr[h].seq_orig == 0) if (spr[h].sp_index != 0)
  4827. {
  4828. spr[h].seq_orig = pam.sprite[spr[h].sp_index].seq;
  4829. spr[h].frame = pam.sprite[spr[h].sp_index].frame;
  4830. spr[h].wait = 0;
  4831.  
  4832. //pam.sprite[spr[h].sp_index].frame;
  4833.  
  4834. }
  4835.  
  4836. if (spr[h].seq == 0) spr[h].seq = spr[h].seq_orig;
  4837.  
  4838. }
  4839.  
  4840.  
  4841. void text_brain(int h)
  4842. {
  4843.  
  4844.  
  4845.  
  4846. if ( (spr[h].damage == -1) && (spr[h].owner != 1000))
  4847. {
  4848.  
  4849. if (spr[spr[h].owner].active == false)
  4850. {
  4851. //msg("Killing text brain %d, because owner %d is dead.",h, spr[h].owner);
  4852. spr[h].active = false;
  4853. return;
  4854. }
  4855.  
  4856. //give this text the cords from it's owner sprite
  4857. spr[h].x = spr[spr[h].owner].x - spr[h].strength;
  4858.  
  4859.  
  4860. spr[h].y = spr[spr[h].owner].y - spr[h].defense;
  4861.  
  4862. if (spr[h].x < 1) spr[h].x = 1;
  4863.  
  4864. if (spr[h].y < 1) spr[h].y = 1;
  4865.  
  4866.  
  4867. } else
  4868. {
  4869. //Msg("automoving %d.. ", h);
  4870.  
  4871. if (spr[h].move_active)
  4872. {
  4873. process_move(h);
  4874. return;
  4875. }
  4876.  
  4877.  
  4878. automove(h);
  4879. }
  4880.  
  4881. }
  4882.  
  4883.  
  4884. void process_talk()
  4885. {
  4886.  
  4887. int px = 48, py = 44;
  4888.  
  4889. int sx = 184;
  4890. int sy = 94, sy_hold, sy_ho;
  4891. int spacing = 12;
  4892. int curxl = 126;
  4893. int curxr = 462;
  4894. int curyr = 200;
  4895. int curyl = 200;
  4896.  
  4897. int y_last = 0, y_hold = 0, y_ho;
  4898. HDC hdc;
  4899. RECT rcRect;
  4900. int i;
  4901. int x_depth = 335;
  4902. if (talk.newy != -5000)
  4903. sy = talk.newy;
  4904.  
  4905. sy_hold = sy;
  4906. sy_ho = sy;
  4907.  
  4908. check_seq_status(30);
  4909.  
  4910. int fake_page;
  4911. again:
  4912. ddrval = lpDDSBack->BltFast( px, py, k[seq[30].frame[2]].k,
  4913. &k[seq[30].frame[2]].box , DDBLTFAST_SRCCOLORKEY );
  4914.  
  4915. if (ddrval == DDERR_WASSTILLDRAWING) goto again;
  4916.  
  4917. again2:
  4918. ddrval = lpDDSBack->BltFast( px+169, py+42, k[seq[30].frame[3]].k,
  4919. &k[seq[30].frame[3]].box , DDBLTFAST_SRCCOLORKEY );
  4920. if (ddrval == DDERR_WASSTILLDRAWING) goto again2;
  4921.  
  4922. again3:
  4923. ddrval = lpDDSBack->BltFast( px+169+180, py+1, k[seq[30].frame[4]].k,
  4924. &k[seq[30].frame[4]].box , DDBLTFAST_SRCCOLORKEY );
  4925.  
  4926. if (ddrval == DDERR_WASSTILLDRAWING) goto again3;
  4927.  
  4928.  
  4929.  
  4930. int talk_hold = talk.cur;
  4931. if (sjoy.rightd) talk.cur++;
  4932. if (sjoy.downd) talk.cur++;
  4933. if (sjoy.upd) talk.cur--;
  4934. if (sjoy.leftd) talk.cur--;
  4935.  
  4936. if (play.mouse > 20)
  4937. {
  4938. talk.cur++;
  4939. play.mouse = 0;
  4940. }
  4941.  
  4942. if (play.mouse < -20)
  4943. {
  4944. talk.cur--;
  4945. play.mouse = 0;
  4946. }
  4947.  
  4948.  
  4949. if (talk_hold != talk.cur)
  4950. {
  4951. if (talk.cur >= talk.cur_view) if (talk.cur <= talk.cur_view_end)
  4952. SoundPlayEffect(11, 22050,0,0,0);
  4953. }
  4954.  
  4955. if (lpDDSBack->GetDC(&hdc) == DD_OK)
  4956. {
  4957.  
  4958. SelectObject (hdc, hfont_small);
  4959. SetBkMode(hdc, TRANSPARENT);
  4960.  
  4961.  
  4962.  
  4963. if (strlen(talk.buffer) > 0)
  4964. {
  4965.  
  4966. SetRect(&rcRect,sx,94,463,400);
  4967. if (talk.newy != -5000) rcRect.bottom = talk.newy+15;
  4968.  
  4969.  
  4970.  
  4971. SetTextColor(hdc,RGB(8,14,21));
  4972. DrawText(hdc,talk.buffer,strlen(talk.buffer),&rcRect,DT_VCENTER | DT_CENTER | DT_WORDBREAK);
  4973.  
  4974. if (talk.color >= 1 && talk.color <= 15)
  4975. {
  4976. SetTextColor(hdc,RGB(font_colors[talk.color].red, font_colors[talk.color].green, font_colors[talk.color].blue));
  4977. }
  4978. else
  4979. {
  4980. SetTextColor(hdc,RGB(255,255,255));
  4981. }
  4982.  
  4983. /*if (talk.color == 1) SetTextColor(hdc,RGB(49,90,140));
  4984. else if (talk.color == 2) SetTextColor(hdc,RGB(131,181,74));
  4985. else if (talk.color == 3) SetTextColor(hdc,RGB(99,242,247));
  4986.  
  4987. else if (talk.color == 4) SetTextColor(hdc,RGB(255,156,74)); //right
  4988.  
  4989.  
  4990. else if (talk.color == 5) SetTextColor(hdc,RGB(222,173,255));
  4991. else if (talk.color == 6) SetTextColor(hdc,RGB(244,188,73)); //right
  4992. else if (talk.color == 7) SetTextColor(hdc,RGB(173,173,173)); //right
  4993. else if (talk.color == 8) SetTextColor(hdc,RGB(85,85,85)); //right
  4994. else if (talk.color == 9) SetTextColor(hdc,RGB(148,198,255)); //right
  4995.  
  4996. else if (talk.color == 10) SetTextColor(hdc,RGB(0,255,0));
  4997. else if (talk.color == 13) SetTextColor(hdc,RGB(255,132,132));
  4998. else if (talk.color == 14) SetTextColor(hdc,RGB(255,255,2));
  4999. else if (talk.color == 15) SetTextColor(hdc,RGB(255,255,255));
  5000. else
  5001. SetTextColor(hdc,RGB(255,255,2));*/
  5002.  
  5003. OffsetRect(&rcRect, 1, 1);
  5004. DrawText(hdc,talk.buffer,strlen(talk.buffer),&rcRect,DT_VCENTER | DT_CENTER | DT_WORDBREAK);
  5005.  
  5006. SetTextColor(hdc,RGB(8,14,21));
  5007. }
  5008.  
  5009.  
  5010.  
  5011.  
  5012. //tabulate distance needed by text, LORDII experience helped here
  5013. recal:
  5014. for (i = talk.cur_view; i < talk.last; i++)
  5015. {
  5016. SetRect(&rcRect,sx,y_hold,463,x_depth+100);
  5017. y_hold = DrawText(hdc,talk.line[i],lstrlen(talk.line[i]),&rcRect,DT_CALCRECT | DT_CENTER | DT_WORDBREAK);
  5018. sy_hold += y_hold;
  5019.  
  5020. //Msg("Sy_hold = %d (%d)", sy_hold,i);
  5021.  
  5022. if (sy_hold > x_depth)
  5023. {
  5024.  
  5025. talk.cur_view_end = i-1;
  5026. //Msg("Sy is over, sp cur_view is %d ", talk.cur_view_end);
  5027. goto death;
  5028. }
  5029. }
  5030.  
  5031. talk.cur_view_end = i;
  5032.  
  5033. if (talk.cur_view == 1) if (talk.cur_view_end == talk.last)
  5034. {
  5035.  
  5036. //Msg("Small enough to fit on one screen, lets center it!");
  5037. sy += ( (x_depth - sy_hold) / 2) - 20;
  5038.  
  5039. }
  5040. death:
  5041.  
  5042.  
  5043. if (talk.cur > talk.last)
  5044. {
  5045. SoundPlayEffect(11, 22050,0,0,0);
  5046.  
  5047. talk.cur = 1;
  5048.  
  5049. }
  5050. if (talk.cur < 1)
  5051. {
  5052. SoundPlayEffect(11, 22050,0,0,0);
  5053.  
  5054. talk.cur = talk.last;
  5055. }
  5056.  
  5057.  
  5058. //if (talk.cur_view_end != talk.last)
  5059. {
  5060. //Msg("Talkcur is %d, talk cur view is %d", talk.cur, talk.cur_view);
  5061. //total options too large for page, lets scroll
  5062.  
  5063.  
  5064. if (talk.cur > talk.cur_view_end)
  5065. {
  5066. // Msg("advancing page: talkcur is %d, changing cur_view to same", talk.cur, talk.cur_view);
  5067. talk.cur_view = talk.cur;
  5068. talk.page ++;
  5069.  
  5070. // Msg("Page advanced to %d. (cur_end is %d, cur is %d)", talk.page,talk.cur_view_end, talk.cur);
  5071. goto fin;
  5072. }
  5073.  
  5074.  
  5075.  
  5076. if (talk.cur < talk.cur_view)
  5077.  
  5078. {
  5079. // Msg("Turning back the clock from page %d..", talk.page);
  5080.  
  5081. talk.cur_view = 1;
  5082. // talk.cur = 1;
  5083.  
  5084. talk.page--;
  5085. Msg("Page backed to %d.", talk.page);
  5086. fake_page = 1;
  5087. for (i = 1; i < talk.last; i++)
  5088. {
  5089. SetRect(&rcRect,sx,sy_ho,463,x_depth);
  5090.  
  5091. y_ho = DrawText(hdc,talk.line[i],lstrlen(talk.line[i]),&rcRect,DT_CALCRECT | DT_CENTER | DT_WORDBREAK);
  5092. sy_ho += y_ho;
  5093. //Msg("adding y_yo %d.. (on %d)", y_ho,i);
  5094. if (sy_ho > x_depth)
  5095. {
  5096. /*if (fake_page == talk.page)
  5097. {
  5098. goto fin;
  5099. }
  5100. */
  5101. fake_page++;
  5102. sy_ho = sy+ y_ho;
  5103. //Msg("Does fake page (%d) match desired page (%d) %d", fake_page, talk.page, i);
  5104. }
  5105. if (fake_page == talk.page)
  5106. {
  5107. talk.cur_view = i;
  5108. talk.cur_view_end = talk.cur;
  5109. //Msg("Going to fin with end being %d, and.cur being %d. View is %d.",
  5110. // talk.cur_view_end, talk.cur, talk.cur_view);
  5111. goto fin;
  5112. }
  5113.  
  5114. // Msg("Second: Sy is over, sp cur_view is %d", talk.cur_view_end);
  5115.  
  5116.  
  5117. }
  5118.  
  5119. talk.cur_view_end = i;
  5120.  
  5121.  
  5122. }
  5123.  
  5124.  
  5125. }
  5126.  
  5127.  
  5128.  
  5129. //Msg("talk last is %d. cur_view_end is %d, Cur is %d", talk.last, talk.cur_view_end, talk.cur);
  5130.  
  5131. // talk.cur_view_end = talk.last;
  5132.  
  5133. for ( i = talk.cur_view; i <= talk.cur_view_end; i++)
  5134.  
  5135. {
  5136. //lets figure out where to draw this line
  5137.  
  5138. SetRect(&rcRect,sx,sy,463,x_depth+100);
  5139. SetTextColor(hdc,RGB(8,14,21));
  5140. DrawText(hdc,talk.line[i],lstrlen(talk.line[i]),&rcRect, DT_CENTER | DT_WORDBREAK);
  5141. OffsetRect(&rcRect,-2,-2);
  5142. DrawText(hdc,talk.line[i],lstrlen(talk.line[i]),&rcRect,DT_CENTER | DT_WORDBREAK);
  5143.  
  5144. OffsetRect(&rcRect,1,1);
  5145. if (i == talk.cur)
  5146. {
  5147. curyl = sy-4;
  5148. curyr = sy-4;
  5149.  
  5150.  
  5151. SetTextColor(hdc,RGB(255,255,255));
  5152.  
  5153. }
  5154. else
  5155. SetTextColor(hdc,RGB(255,255,2));
  5156. y_last = DrawText(hdc,talk.line[i],lstrlen(talk.line[i]),&rcRect,DT_CENTER | DT_WORDBREAK);
  5157. sy += y_last;
  5158.  
  5159.  
  5160. }
  5161.  
  5162. fin:
  5163.  
  5164.  
  5165. // dum = GetTextFace(hdc,100,shit) ;
  5166. lpDDSBack->ReleaseDC(hdc);
  5167.  
  5168. if (talk.timer < thisTickCount)
  5169. {
  5170. talk.curf++;
  5171. talk.timer = thisTickCount+100;
  5172. }
  5173.  
  5174.  
  5175. if (talk.curf == 0) talk.curf = 1;
  5176.  
  5177. if (talk.curf > 7) talk.curf = 1;
  5178. again4:
  5179. ddrval = lpDDSBack->BltFast( curxl, curyl, k[seq[456].frame[talk.curf]].k,
  5180. &k[seq[456].frame[talk.curf]].box , DDBLTFAST_SRCCOLORKEY );
  5181. if (ddrval == DDERR_WASSTILLDRAWING) goto again4;
  5182.  
  5183. again5:
  5184. ddrval = lpDDSBack->BltFast( curxr, curyr, k[seq[457].frame[talk.curf]].k,
  5185. &k[seq[456].frame[talk.curf]].box , DDBLTFAST_SRCCOLORKEY );
  5186. if (ddrval == DDERR_WASSTILLDRAWING) goto again5;
  5187.  
  5188.  
  5189. }
  5190.  
  5191.  
  5192. if ( (sjoy.button[1]) | (mouse1))
  5193.  
  5194. {
  5195. mouse1 = false;
  5196. talk.active = false;
  5197. *presult = talk.line_return[talk.cur];
  5198. SoundPlayEffect(17, 22050,0,0,0);
  5199.  
  5200. if (talk.script != 0)
  5201. {
  5202. //we need to continue a script
  5203. run_script(talk.script);
  5204.  
  5205. }
  5206. }
  5207.  
  5208. }
  5209.  
  5210.  
  5211.  
  5212. void UpdateCursorPosition(int dx, int dy)
  5213. {
  5214.  
  5215. /*
  5216. * Pick up any leftover fuzz from last time. This is important
  5217. * when scaling down mouse motions. Otherwise, the user can
  5218. * drag to the right extremely slow for the length of the table
  5219. * and not get anywhere.
  5220. */
  5221. if (spr[1].active) if (spr[1].brain == 13)
  5222. {
  5223. spr[1].x += dx;
  5224. spr[1].y += dy;
  5225. /* Clip the cursor to our client area */
  5226.  
  5227. if (spr[1].x > 640) spr[1].x = 640;
  5228. if (spr[1].y > 480) spr[1].y = 480;
  5229. if (spr[1].x < 0) spr[1].x = 0;
  5230. if (spr[1].y < 0) spr[1].y = 0;
  5231. }
  5232. if (mode == 1)
  5233. {
  5234. play.mouse += dy;
  5235. //Msg("play mousey is now %d", play.mouse);
  5236. }
  5237.  
  5238. }
  5239.  
  5240.  
  5241. void Scrawl_OnMouseInput(void)
  5242. {
  5243.  
  5244. mouse1 = false;
  5245.  
  5246. BOOL fDone = 0;
  5247.  
  5248. while (!fDone) {
  5249.  
  5250. DIDEVICEOBJECTDATA od;
  5251.  
  5252. DWORD dwElements = 1;
  5253.  
  5254. HRESULT hr = g_pMouse->GetDeviceData(
  5255. sizeof(DIDEVICEOBJECTDATA), &od,
  5256. &dwElements, 0);
  5257.  
  5258. if (hr == DIERR_INPUTLOST) {
  5259. /*
  5260. * We had acquisition, but lost it. Try to reacquire it.
  5261. *
  5262. * WARNING! DO NOT ATTEMPT TO REACQUIRE IF YOU GET
  5263. * DIERR_NOTACQUIRED! Otherwise, you're extremely likely
  5264. * to get caught in an infinite loop: The acquire will fail,
  5265. * and you'll get another DIERR_NOTACQUIRED so you'll
  5266. * try to aquire again, and that'll fail, etc.
  5267. */
  5268. //PostMessage(hwnd, WM_SYNCACQUIRE, 0, 0L);
  5269. // break;
  5270.  
  5271. g_pMouse->Acquire();
  5272.  
  5273. }
  5274.  
  5275. /* Unable to read data or no data available */
  5276. if (FAILED(hr) || dwElements == 0) {
  5277. // Msg("No mouse data there.");
  5278. break;
  5279. }
  5280.  
  5281. /* Look at the element to see what happened */
  5282.  
  5283. switch (od.dwOfs) {
  5284.  
  5285. /* DIMOFS_X: Mouse horizontal motion */
  5286. case DIMOFS_X: UpdateCursorPosition(od.dwData, 0); break;
  5287.  
  5288.  
  5289. /* DIMOFS_Y: Mouse vertical motion */
  5290. case DIMOFS_Y: UpdateCursorPosition(0, od.dwData); break;
  5291.  
  5292. case DIDFT_BUTTON: if (od.dwData > 0) mouse1 = true; break;
  5293.  
  5294. }
  5295.  
  5296. }
  5297.  
  5298. }
  5299.  
  5300. void button_brain(int h )
  5301. {
  5302. RECT box;
  5303. if (spr[h].move_active)
  5304. {
  5305. process_move(h);
  5306. return;
  5307. }
  5308.  
  5309.  
  5310. if (spr[h].script == 0) return;
  5311.  
  5312. CopyRect(&box, &k[getpic(h)].hardbox);
  5313. OffsetRect(&box, spr[h].x, spr[h].y);
  5314.  
  5315. if (spr[h].brain_parm == 0)
  5316. {
  5317. if (inside_box(spr[1].x, spr[1].y, box))
  5318. {
  5319. spr[h].brain_parm = 1;
  5320.  
  5321. if (locate(spr[h].script, "BUTTONON"))
  5322. {
  5323. run_script(spr[h].script);
  5324.  
  5325. return;
  5326. }
  5327.  
  5328. }
  5329.  
  5330. }
  5331. else
  5332. {
  5333. if (!inside_box(spr[1].x, spr[1].y, box))
  5334. {
  5335. spr[h].brain_parm = 0;
  5336.  
  5337. if (locate(spr[h].script, "BUTTONOFF"))
  5338. {
  5339.  
  5340. run_script(spr[h].script);
  5341. return;
  5342. }
  5343.  
  5344. }
  5345.  
  5346. }
  5347.  
  5348.  
  5349. }
  5350.  
  5351. void draw_item(int num, bool magic, int mseq, int mframe)
  5352. {
  5353. int mx = 20;
  5354. int my = 0;
  5355. int vert = 0;
  5356. if (magic == false)
  5357. {
  5358. mx = 260;
  5359. my = 83;
  5360.  
  5361. vert = ((num-1) / 4);
  5362. mx += (((num-1) - (vert * 4)) * (18 + 65));
  5363. my += (vert * (20 + 55));
  5364. } else
  5365. {
  5366. mx = 45;
  5367. my = 83;
  5368.  
  5369. vert = ((num-1) / 2);
  5370. mx += (((num-1) - (vert * 2)) * (18 + 65));
  5371. my += (vert * (20 + 55));
  5372.  
  5373.  
  5374. }
  5375.  
  5376. again:
  5377.  
  5378. check_seq_status(mseq);
  5379.  
  5380. if (k[seq[mseq].frame[mframe]].k == NULL)
  5381. {
  5382.  
  5383. if (!magic)
  5384. {
  5385. Msg("Whups, item %d seq %d frame %d not loaded, killed it",
  5386. num, mseq, mframe);
  5387. play.item[num].active = false;
  5388. } else
  5389. {
  5390. Msg("Whups, magic %d seq %d frame %d not loaded, killed it",
  5391. num, mseq, mframe);
  5392. play.mitem[num].active = false;
  5393.  
  5394. }
  5395.  
  5396. return;
  5397. }
  5398.  
  5399. ddrval = lpDDSBack->BltFast( mx, my, k[seq[mseq].frame[mframe]].k,
  5400. &k[seq[mseq].frame[mframe]].box, DDBLTFAST_SRCCOLORKEY);
  5401.  
  5402. if( ddrval == DDERR_WASSTILLDRAWING ) goto again;
  5403.  
  5404.  
  5405. }
  5406.  
  5407.  
  5408. void process_item( void )
  5409. {
  5410.  
  5411. RECT rcRect;
  5412. rcRect.left = 0;
  5413. rcRect.top = 0;
  5414. rcRect.right = x;
  5415. rcRect.bottom = y;
  5416. int hor, virt;
  5417.  
  5418.  
  5419.  
  5420. while( 1 )
  5421. {
  5422. ddrval = lpDDSBack->BltFast( 0, 0, lpDDSTwo,
  5423. &rcRect, DDBLTFAST_NOCOLORKEY);
  5424.  
  5425. if( ddrval == DD_OK )
  5426. {
  5427. break;
  5428. }
  5429. if( ddrval == DDERR_SURFACELOST )
  5430. {
  5431. ddrval = restoreAll();
  5432. break;
  5433. }
  5434. if( ddrval != DDERR_WASSTILLDRAWING )
  5435. {
  5436. dderror(ddrval);
  5437. return;
  5438. }
  5439. }
  5440.  
  5441.  
  5442. check_seq_status(423);
  5443. //lets blit the main screen over it
  5444. again:
  5445. ddrval = lpDDSBack->BltFast( 20, 0, k[seq[423].frame[1]].k,
  5446. &k[seq[423].frame[1]].box, DDBLTFAST_SRCCOLORKEY);
  5447.  
  5448. if( ddrval == DDERR_WASSTILLDRAWING )
  5449. goto again;
  5450. //draw all currently owned items; magic
  5451. for (int i = 1; i < 9; i++)
  5452. {
  5453. if (play.mitem[i].active) draw_item(i, true, play.mitem[i].seq,play.mitem[i].frame);
  5454. }
  5455.  
  5456. //draw all currently owned items; normal
  5457. for ( i = 1; i < 17; i++)
  5458. {
  5459. if (play.item[i].active) draw_item(i, false, play.item[i].seq,play.item[i].frame);
  5460.  
  5461. }
  5462.  
  5463. //draw selection box around armed weapon
  5464. if (*pcur_weapon != 0) if (play.item[*pcur_weapon].active)
  5465. draw_item(*pcur_weapon, false, 423, 4);
  5466.  
  5467.  
  5468. //draw selection box around armed magic
  5469. if (*pcur_magic != 0) if (play.item[*pcur_magic].active)
  5470. draw_item(*pcur_magic, true, 423, 5);
  5471.  
  5472.  
  5473. //draw the selector around it, alternating from 2 to 3
  5474. if (play.curitem < 1) play.curitem = 1;
  5475.  
  5476.  
  5477. if (thisTickCount > item_timer)
  5478. {
  5479. if (item_pic == 2) item_pic = 3; else item_pic = 2;
  5480. item_timer = thisTickCount + 400;
  5481.  
  5482. }
  5483. draw_item(play.curitem, play.item_magic, 423, item_pic);
  5484.  
  5485.  
  5486.  
  5487.  
  5488. if (!play.item_magic)
  5489. {
  5490. hor = (play.curitem - (((play.curitem-1) / 4) * 4));
  5491. virt = ((play.curitem-1) / 4);
  5492.  
  5493.  
  5494.  
  5495. //choosing weapon/item
  5496.  
  5497. if (sjoy.button[1])
  5498. {
  5499. if (play.item[play.curitem].active)
  5500. {
  5501. //arm weapon
  5502. SoundPlayEffect(18, 42050,0,0,0);
  5503. if (*pcur_weapon != 0)
  5504. {
  5505. //disarm old weapon
  5506. if (locate(weapon_script, "DISARM")) run_script(weapon_script);
  5507. }
  5508. //load weapons script
  5509. *pcur_weapon = play.curitem;
  5510. weapon_script = load_script(play.item[*pcur_weapon].name, 1000, false);
  5511. if (locate(weapon_script, "ARM")) run_script(weapon_script);
  5512. if (locate(weapon_script, "ARMMOVIE")) run_script(weapon_script);
  5513.  
  5514. draw_status_all();
  5515. } else
  5516. {
  5517. //can't arm nothing, play sound
  5518. }
  5519. } else
  5520. if (sjoy.rightd)
  5521. {
  5522. if (hor < 4) play.curitem++;
  5523. SoundPlayEffect(11, 22050,0,0,0);
  5524. } else
  5525. if (sjoy.leftd)
  5526. {
  5527. if (hor > 1)
  5528. {
  5529. play.curitem--;
  5530. SoundPlayEffect(11, 22050,0,0,0);
  5531.  
  5532. }
  5533. else
  5534. {
  5535. SoundPlayEffect(11, 22050,0,0,0);
  5536.  
  5537. play.item_magic = true;
  5538. play.curitem = (virt * 2) + 2;
  5539. //switch to magic mode
  5540. }
  5541. } else
  5542.  
  5543.  
  5544. if (sjoy.downd)
  5545. {
  5546. if (virt < 3)
  5547. {
  5548. play.curitem += 4;
  5549. SoundPlayEffect(11, 22050,0,0,0);
  5550.  
  5551. }
  5552. } else
  5553.  
  5554. if (sjoy.upd)
  5555. {
  5556. if (virt > 0)
  5557. {
  5558. play.curitem -= 4;
  5559. SoundPlayEffect(11, 22050,0,0,0);
  5560.  
  5561. }
  5562. }
  5563.  
  5564.  
  5565. } else
  5566.  
  5567. {
  5568. hor = (play.curitem - (((play.curitem-1) / 2) * 2));
  5569. virt = ((play.curitem-1) / 2);
  5570.  
  5571. if (sjoy.button[1])
  5572. {
  5573. if (play.mitem[play.curitem].active)
  5574. {
  5575. //arm magic
  5576. SoundPlayEffect(18, 42050,0,0,0);
  5577. if (*pcur_magic != 0)
  5578. {
  5579. //disarm old weapon
  5580. if (locate(magic_script, "DISARM")) run_script(magic_script);
  5581. }
  5582. //load magics script
  5583. *pcur_magic = play.curitem;
  5584. magic_script = load_script(play.mitem[*pcur_magic].name, 1000, false);
  5585. if (locate(magic_script, "ARM")) run_script(magic_script);
  5586. if (locate(magic_script, "ARMMOVIE")) run_script(magic_script);
  5587. draw_status_all();
  5588. } else
  5589. {
  5590. //can't arm nothing, play sound
  5591. }
  5592. }
  5593.  
  5594. if (sjoy.rightd)
  5595. {
  5596. if (hor < 2)
  5597. {
  5598. play.curitem++;
  5599. SoundPlayEffect(11, 22050,0,0,0);
  5600.  
  5601. }
  5602. else
  5603. {
  5604. play.item_magic = false;
  5605. play.curitem = (virt * 4) +1;
  5606. SoundPlayEffect(11, 22050,0,0,0);
  5607.  
  5608. }
  5609. } else
  5610. if (sjoy.leftd)
  5611. {
  5612. if (hor > 1)
  5613. {
  5614. play.curitem--;
  5615. SoundPlayEffect(11, 22050,0,0,0);
  5616.  
  5617. }
  5618. else
  5619. {
  5620. }
  5621. } else
  5622.  
  5623.  
  5624. if (sjoy.downd)
  5625. {
  5626. if (virt < 3)
  5627. {
  5628. play.curitem += 2;
  5629. SoundPlayEffect(11, 22050,0,0,0);
  5630.  
  5631. }
  5632. } else
  5633.  
  5634. if (sjoy.upd)
  5635. {
  5636. if (virt > 0)
  5637. {
  5638. play.curitem -= 2;
  5639. SoundPlayEffect(11, 22050,0,0,0);
  5640.  
  5641. }
  5642. }
  5643.  
  5644. }
  5645. if (talk.active) process_talk();
  5646.  
  5647. //a special process callbacks for just stuff that was created in this mode?
  5648. // process_callbacks_special();
  5649. flip_it();
  5650.  
  5651. if (sjoy.button[4])
  5652. {
  5653. SoundPlayEffect(17, 22050,0,0,0);
  5654.  
  5655. item_screen = false;
  5656. }
  5657.  
  5658.  
  5659. }
  5660.  
  5661. void process_animated_tiles( void )
  5662. {
  5663. RECT rcRect;
  5664. int cool;
  5665. int flip;
  5666. int pa;
  5667.  
  5668. //process water tiles
  5669.  
  5670. if (water_timer < thisTickCount)
  5671. {
  5672.  
  5673. water_timer = thisTickCount + ((rand() % 2000));
  5674.  
  5675. flip = ((rand() % 2)+1);
  5676.  
  5677.  
  5678.  
  5679.  
  5680. for (int x=0; x<96; x++)
  5681. {
  5682. //redink1 fix for first broken water tile
  5683. if (pam.t[x].num >= 896) if (pam.t[x].num < (896+128))
  5684. {
  5685.  
  5686. cool = pam.t[x].num / 128;
  5687. pa = pam.t[x].num - (cool * 128);
  5688. rcRect.left = (pa * 50- (pa / 12) * 600);
  5689. rcRect.top = (pa / 12) * 50;
  5690. rcRect.right = rcRect.left + 50;
  5691. rcRect.bottom = rcRect.top + 50;
  5692.  
  5693.  
  5694. lpDDSTwo->BltFast( (x * 50 - ((x / 12) * 600))+playl, (x / 12) * 50, tiles[cool+flip],
  5695. &rcRect, DDBLTFAST_NOCOLORKEY| DDBLTFAST_WAIT );
  5696.  
  5697. }
  5698. }
  5699.  
  5700. }
  5701.  
  5702. //end of water processing
  5703.  
  5704.  
  5705. //if (water_timer < thisTickCount)
  5706. {
  5707.  
  5708. // water_timer = thisTickCount + ((rand() % 2000)+1000);
  5709.  
  5710. if (fire_forward) fire_flip++;
  5711. if (!fire_forward) fire_flip--;
  5712.  
  5713. if (fire_flip < 1)
  5714. {
  5715. fire_flip = 5;
  5716. fire_forward = false;
  5717. }
  5718.  
  5719. // if (fire_flip > 4)
  5720. // {
  5721. // fire_flip = 4;
  5722. //fire_forward = false;
  5723. //}
  5724.  
  5725.  
  5726.  
  5727. for (int x=0; x<96; x++)
  5728. {
  5729. //redink1 fix for first broken fire tile
  5730. if (pam.t[x].num >= 2304) if (pam.t[x].num < (2304+128))
  5731. {
  5732.  
  5733. cool = pam.t[x].num / 128;
  5734. pa = pam.t[x].num - (cool * 128);
  5735. rcRect.left = (pa * 50- (pa / 12) * 600);
  5736. rcRect.top = (pa / 12) * 50;
  5737. rcRect.right = rcRect.left + 50;
  5738. rcRect.bottom = rcRect.top + 50;
  5739.  
  5740.  
  5741. lpDDSTwo->BltFast( (x * 50 - ((x / 12) * 600))+playl, (x / 12) * 50, tiles[cool+fire_flip],
  5742. &rcRect, DDBLTFAST_NOCOLORKEY| DDBLTFAST_WAIT );
  5743.  
  5744. }
  5745. }
  5746.  
  5747. }
  5748.  
  5749. //end of water processing
  5750.  
  5751.  
  5752.  
  5753. }
  5754.  
  5755.  
  5756. void process_show_bmp( void )
  5757. {
  5758.  
  5759. RECT rcRect;
  5760. SetRect(&rcRect, 0,0,x, y);
  5761.  
  5762. again:
  5763. ddrval = lpDDSBack->BltFast( 0, 0, lpDDSTrick,
  5764. &rcRect, DDBLTFAST_NOCOLORKEY);
  5765.  
  5766. if( ddrval == DDERR_WASSTILLDRAWING ) goto again;
  5767.  
  5768.  
  5769. if (showb.showdot)
  5770. {
  5771. //let's display a nice dot to mark where they are on the map
  5772. int x = play.last_map - 1;
  5773.  
  5774.  
  5775. int mseq = 165;
  5776.  
  5777. showb.picframe++;
  5778. if (showb.picframe > index[mseq].last) showb.picframe = 1;
  5779. int mframe = showb.picframe;
  5780. lpDDSBack->BltFast( (x % 32) * 20, (x / 32) * 20, k[seq[mseq].frame[mframe]].k,
  5781. &k[seq[mseq].frame[mframe]].box, DDBLTFAST_SRCCOLORKEY| DDBLTFAST_WAIT );
  5782.  
  5783. }
  5784.  
  5785.  
  5786. if ( (sjoy.button[1])
  5787. || (sjoy.button[2])
  5788. || (sjoy.button[3])
  5789. || (sjoy.button[4])
  5790. || (sjoy.button[5])
  5791. || (sjoy.button[6])
  5792.  
  5793.  
  5794. )
  5795. {
  5796. showb.active = false;
  5797. if (showb.script != 0)
  5798. run_script(showb.script);
  5799. showb.stime = thisTickCount+2000;
  5800. but_timer = thisTickCount + 200;
  5801.  
  5802. int sprite = say_text_xy("", 1, 440, 0);
  5803. spr[sprite].noclip = 1;
  5804.  
  5805.  
  5806. if(lpDDPal->SetEntries(0,0,256,real_pal) !=DD_OK)
  5807. {
  5808. Msg("error with setting entries");
  5809. return;
  5810. }
  5811.  
  5812. }
  5813.  
  5814.  
  5815.  
  5816. /*if (!cd_inserted)
  5817. {
  5818.  
  5819.  
  5820. if (showb.stime > thisTickCount)
  5821. {
  5822. if (lpDDSBack->GetDC(&hdc) == DD_OK)
  5823. {
  5824. SelectObject (hdc, hfont_small);
  5825. SetBkMode(hdc, TRANSPARENT);
  5826. sprintf(msg, "Please wait, checking CD. (or Alt-Q to abort and exit program)");
  5827. rcRect.left = 0;
  5828. rcRect.top = 430;
  5829. rcRect.right = playx;
  5830. rcRect.bottom = 480;
  5831. SetTextColor(hdc, RGB(255,255,2));
  5832. DrawText(hdc,msg,lstrlen(msg),&rcRect,DT_CENTER | DT_WORDBREAK);
  5833. lpDDSBack->ReleaseDC(hdc);
  5834.  
  5835. }
  5836.  
  5837. }
  5838.  
  5839. }
  5840.  
  5841. */
  5842. }
  5843.  
  5844. void drawscreenlock( void )
  5845. {
  5846. HRESULT ddrval;
  5847.  
  5848. loop:
  5849. //draw the screenlock icon
  5850. ddrval = lpDDSBack->BltFast(0, 0, k[seq[423].frame[9]].k,
  5851. &k[seq[423].frame[9]].box , DDBLTFAST_NOCOLORKEY );
  5852.  
  5853. if (ddrval == DDERR_WASSTILLDRAWING ) goto loop;
  5854.  
  5855. //if (ddrval != DD_OK) dderror(ddrval);
  5856.  
  5857. loop2:
  5858. //draw the screenlock icon
  5859. ddrval = lpDDSBack->BltFast(620, 0, k[seq[423].frame[10]].k,
  5860. &k[seq[423].frame[10]].box , DDBLTFAST_NOCOLORKEY );
  5861.  
  5862. if (ddrval == DDERR_WASSTILLDRAWING ) goto loop2;
  5863. // if (ddrval != DD_OK) dderror(ddrval);
  5864.  
  5865.  
  5866. }
  5867.  
  5868.  
  5869.  
  5870. #include "update_frame.cpp"
  5871.  
  5872.  
  5873.  
  5874.  
  5875.  
  5876. /*
  5877. * finiObjects
  5878. *
  5879. * finished with all objects we use; release them
  5880. */
  5881. void finiObjects()
  5882. {
  5883. //wDeviceID = mciGetDeviceID("MCI_ALL_DEVICE_ID");
  5884.  
  5885. if (last_saved_game > 0)
  5886. {
  5887. Msg("Modifying saved game.");
  5888.  
  5889. if (!add_time_to_saved_game(last_saved_game))
  5890. Msg("Error modifying saved game.");
  5891. }
  5892.  
  5893. if (::sound_on)
  5894. {
  5895. mciSendCommand(CD_ID, MCI_CLOSE, 0, NULL);
  5896.  
  5897. Msg("Shutting down CD stuff.");
  5898. killcd(g_hWnd, 1);
  5899. }
  5900. log_path(false);
  5901.  
  5902.  
  5903.  
  5904. if( lpDD != NULL )
  5905. {
  5906.  
  5907. //change coop mode back
  5908.  
  5909. /*
  5910. if( lpDDSBack != NULL )
  5911. {
  5912. lpDDSBack->Release();
  5913. lpDDSBack = NULL;
  5914. }
  5915. */
  5916. if( lpDDPal != NULL )
  5917. {
  5918. lpDDPal->Release();
  5919. lpDDPal = NULL;
  5920. }
  5921.  
  5922. if( lpDDSPrimary != NULL )
  5923. {
  5924. lpDDSPrimary->Release();
  5925. lpDDSPrimary = NULL;
  5926. }
  5927. if (lpDD->RestoreDisplayMode() != DD_OK)
  5928. Msg("Error restoring display mode.");
  5929.  
  5930. /*
  5931. HRESULT ddrval = lpDD->SetCooperativeLevel( hWndMain, DDSCL_NORMAL);
  5932.  
  5933. if( ddrval != DD_OK )
  5934. {
  5935. Msg("Unable to set cooperative level on exit.");
  5936. }
  5937.  
  5938. */
  5939. lpDD->Release();
  5940. lpDD = NULL;
  5941.  
  5942. /*for (int oo = 1; oo <= max_sprites; oo++)
  5943. {
  5944.  
  5945. if( k[oo].k != NULL )
  5946. {
  5947.  
  5948. k[oo].k->Release();
  5949. k[oo].k = NULL;
  5950. }
  5951.  
  5952.  
  5953. }
  5954.  
  5955. */
  5956. }
  5957.  
  5958. //destroy direct input mouse stuff
  5959.  
  5960. if (g_pMouse)
  5961. {
  5962. g_pMouse->Unacquire();
  5963. g_pMouse->Release();
  5964. g_pMouse = NULL;
  5965. }
  5966.  
  5967. if (g_hevtMouse)
  5968. {
  5969. CloseHandle(g_hevtMouse);
  5970. g_hevtMouse = NULL;
  5971. }
  5972.  
  5973. if (g_pdi)
  5974. {
  5975. g_pdi->Release();
  5976. g_pdi = NULL;
  5977. }
  5978.  
  5979.  
  5980.  
  5981. if (sound_on)
  5982. DestroySound();
  5983.  
  5984.  
  5985. if (::sound_on)
  5986. {
  5987. //lets kill the cdaudio too
  5988. if (mciSendString("close all", NULL, 0, NULL) != 0)
  5989. {
  5990. Msg("Couldn't close all MCI events..");
  5991. // return(FALSE);
  5992. }
  5993.  
  5994. }
  5995.  
  5996. kill_all_scripts_for_real();
  5997. FastFileFini();
  5998. void kill_fonts();
  5999. kill_fonts();
  6000. g_b_kill_app = true;
  6001. ShowWindow(hWndMain, SW_HIDE);
  6002. SendMessage(hWndMain, WM_IMDONE, 0,0);
  6003. //PostQuitMessage(0);
  6004.  
  6005. } /* finiObjects */
  6006.  
  6007. BOOL initFail( HWND hwnd, char mess[200] )
  6008. {
  6009. MessageBox( hwnd, mess, TITLE, MB_OK );
  6010. finiObjects();
  6011. // DestroyWindow( hwnd );
  6012. return FALSE;
  6013.  
  6014. } /* initFail */
  6015.  
  6016.  
  6017. long FAR PASCAL WindowProc( HWND hWnd, UINT message,
  6018. WPARAM wParam, LPARAM lParam )
  6019. {
  6020. switch( message )
  6021. {
  6022. case WM_ACTIVATEAPP:
  6023. bActive = wParam;
  6024. break;
  6025.  
  6026. case WM_SETCURSOR:
  6027. if (!windowed)
  6028. {
  6029. SetCursor(NULL);
  6030. }
  6031. return TRUE;
  6032.  
  6033. case WM_CREATE:
  6034. break;
  6035. case WM_IMDONE:
  6036. Msg("Sending quit message.");
  6037. PostQuitMessage(0);
  6038. break;
  6039.  
  6040.  
  6041.  
  6042. case WM_KEYDOWN:
  6043. if ( mConsoleActive )
  6044. {
  6045. switch( wParam )
  6046. {
  6047. /*case VK_F1:
  6048. {
  6049. Msg("F1 pressed");
  6050. //g_pMouse->Unacquire();
  6051.  
  6052. int crap;
  6053. }
  6054. break;
  6055.  
  6056. case VK_F3:
  6057. {
  6058. fill_whole_hard();
  6059. fill_hard_sprites();
  6060. fill_back_sprites();
  6061. }
  6062. break;
  6063. */
  6064.  
  6065. /*case VK_F4:
  6066. {
  6067. process_downcycle = true;
  6068. cycle_clock = thisTickCount;
  6069. }
  6070. */
  6071. case VK_UP:
  6072. if ( mConsoleHistoryIndex > 0 )
  6073. {
  6074. mConsoleHistoryIndex -= 1;
  6075. mConsoleLine = mConsoleLineHistory[mConsoleHistoryIndex];
  6076. }
  6077. break;
  6078.  
  6079. case VK_DOWN:
  6080. mConsoleHistoryIndex += 1;
  6081. if ( mConsoleHistoryIndex < mConsoleLineHistory.size() )
  6082. {
  6083. mConsoleLine = mConsoleLineHistory[mConsoleHistoryIndex];
  6084. }
  6085. else
  6086. {
  6087. mConsoleHistoryIndex = mConsoleLineHistory.size();
  6088. mConsoleLine = "";
  6089. }
  6090. break;
  6091. default:
  6092. break;
  6093. }
  6094. }
  6095. break;
  6096. // redink1 addition of console
  6097. case WM_CHAR:
  6098. if ( mConsoleActive )
  6099. {
  6100. switch ( wParam )
  6101. {
  6102. case 0x08: // Process a backspace.
  6103. if ( mConsoleLine.length() > 0 )
  6104. {
  6105. mConsoleLine = mConsoleLine.substr( 0, mConsoleLine.length() - 1 );
  6106. }
  6107. break;
  6108.  
  6109. case 0x0A: // Process a linefeed
  6110. break;
  6111.  
  6112. case 0x1B: // Process an escape.
  6113. mConsoleActive = false;
  6114. mConsoleLine = "";
  6115. break;
  6116.  
  6117. case 0x09: // Process a tab.
  6118. break;
  6119.  
  6120. case 0x0D: // Process a carriage return, try to parse the string.
  6121. if ( mConsoleScript == 0 || rbuf[mConsoleScript] == NULL )
  6122. {
  6123. mConsoleScript = 0;
  6124. for (int k=1; k < max_scripts; k++)
  6125. {
  6126. if (rbuf[k] == NULL)
  6127. {
  6128. mConsoleScript = k;
  6129. rinfo[mConsoleScript] = (struct refinfo *) malloc( sizeof(struct refinfo));
  6130. memset(rinfo[mConsoleScript], 0, sizeof(struct refinfo));
  6131. rinfo[mConsoleScript]->sprite = 1000;
  6132. rinfo[mConsoleScript]->level = 1;
  6133. rbuf[mConsoleScript] = (char *) malloc( 255 );
  6134. break;
  6135. }
  6136. }
  6137. }
  6138. if ( mConsoleScript != 0 )
  6139. {
  6140. strncpy( rbuf[mConsoleScript], mConsoleLine.c_str(), 254 );
  6141. process_line(mConsoleScript, rbuf[mConsoleScript], false);
  6142. mConsoleReturnValue = returnint;
  6143. mConsoleLineHistory.push_back( mConsoleLine );
  6144. if ( mConsoleLineHistory.size() > 20 )
  6145. {
  6146. mConsoleLineHistory.erase( mConsoleLineHistory.begin() );
  6147. }
  6148. mConsoleHistoryIndex = mConsoleLineHistory.size();
  6149. }
  6150. mConsoleLine = "";
  6151. break;
  6152.  
  6153. default: // Process displayable characters.
  6154. mConsoleLine += static_cast<char>( wParam );
  6155. break;
  6156. }
  6157. // clear keyboard buffer
  6158. for (int x=0; x<256; x++)
  6159. {
  6160. if (GetKeyboard(x))
  6161. {
  6162. }
  6163. }
  6164. }
  6165. break;
  6166. //redink1 and Invertigo fix for Alt-F4/X button exiting problem
  6167. case WM_CLOSE:
  6168. finiObjects();
  6169. PostQuitMessage( 0 );
  6170. break;
  6171. }
  6172.  
  6173.  
  6174. //cycle through keys
  6175.  
  6176.  
  6177. return DefWindowProc(hWnd, message, wParam, lParam);
  6178.  
  6179. } /* WindowProc */
  6180.  
  6181.  
  6182.  
  6183.  
  6184.  
  6185.  
  6186. BOOL CheckJoyStickPresent (void)
  6187. {
  6188.  
  6189. // first tests if a joystick driver is present
  6190. // if TRUE it makes certain that a joystick is plugged in
  6191.  
  6192. if(joyGetNumDevs())
  6193. {
  6194. memset(&jinfo,0,sizeof(JOYINFOEX));
  6195. jinfo.dwSize=sizeof(JOYINFOEX);
  6196. jinfo.dwFlags=JOY_RETURNALL;
  6197. if(joyGetPosEx(JOYSTICKID1,&jinfo) == JOYERR_NOERROR)
  6198. {
  6199. Msg("Joystick IS plugged in");
  6200. return TRUE;
  6201. } else
  6202. {
  6203. Msg("Joystick not plugged in");
  6204.  
  6205. return FALSE;
  6206.  
  6207. }
  6208. Msg("No joysticks found");
  6209. }
  6210. return FALSE;
  6211. }
  6212.  
  6213.  
  6214.  
  6215.  
  6216. void load_batch(void)
  6217. {
  6218.  
  6219. FILE *stream;
  6220. char line[255];
  6221.  
  6222. spr[1].x = 200;
  6223. spr[1].y = 300;
  6224.  
  6225.  
  6226. Msg("Loading .ini");
  6227. if (!exist("dink.ini"))
  6228. {
  6229. Msg("File not found.");
  6230.  
  6231. sprintf(line,"Error finding the dink.ini file in the %s dir.",dir);
  6232. TRACE(line);
  6233.  
  6234. }
  6235.  
  6236. if( (stream = fopen( "dink.ini", "r" )) != NULL )
  6237. {
  6238.  
  6239. while(1)
  6240. {
  6241. if( fgets( line, 255, stream ) == NULL)
  6242. goto done;
  6243. else
  6244. {
  6245.  
  6246. pre_figure_out(line, 0);
  6247. }
  6248.  
  6249. }
  6250.  
  6251. done:
  6252. fclose( stream );
  6253. } else
  6254. {
  6255. TRACE("Dink.ini missing.");
  6256. }
  6257.  
  6258. program_idata();
  6259.  
  6260. }
  6261.  
  6262.  
  6263. //redink1 and Invertigo fix for windowed/high color mode
  6264. bool check_arg(char crap[255])
  6265. {
  6266. truecolor = false;
  6267. char shit[200];
  6268.  
  6269. // strupr(crap);
  6270. strcpy(dir, "dink");
  6271. for (int i=1; i <= 10; i++)
  6272. {
  6273. seperate_string(crap, i,' ',shit);
  6274. if (strnicmp(shit,"-window",strlen("-window")) == 0)
  6275. {
  6276. windowed = true;
  6277. truecolor = true;
  6278. // no_transition = true;
  6279. }
  6280.  
  6281. if (strnicmp(shit,"-dinkpal",strlen("-dinkpal")) == 0)
  6282. {
  6283. dinkpal = true;
  6284. }
  6285.  
  6286. if (strnicmp(shit,"-truecolor",strlen("-truecolor")) == 0)
  6287. {
  6288. truecolor = true;
  6289. }
  6290.  
  6291. if (strnicmp(shit,"-debug",strlen("-debug")) == 0)
  6292. {
  6293. debug_mode = true;
  6294. unlink("dink\\debug.txt");
  6295. }
  6296.  
  6297. if (strnicmp(shit,"-nojoy",strlen("-nojoy")) == 0)
  6298. {
  6299. disablejoystick = TRUE;
  6300. }
  6301. if (strnicmp(shit,"-noini",strlen("-noini")) == 0)
  6302. {
  6303. g_b_no_write_ini = true;
  6304. }
  6305.  
  6306. #ifndef __DEMO
  6307.  
  6308. if (strnicmp(shit,"-game",strlen("-game")) == 0)
  6309. {
  6310. seperate_string(crap, i+1,' ',shit);
  6311. strcpy(dir, shit);
  6312. Msg("Working directory %s requested.",dir);
  6313. }
  6314.  
  6315. #endif
  6316.  
  6317. #ifdef __DEMO
  6318. if (strnicmp(shit,"-game",strlen("-game")) == 0)
  6319. {
  6320. #ifdef __GERMAN
  6321. sprintf(shit,"Die Shareware-Version akzeptiert keine selbsterstellten Abenteuer oder Addons.",dir);
  6322. #endif
  6323. #ifdef __ENGLISH
  6324.  
  6325. sprintf(shit,"The shareware version cannot play player made quests or addons.",dir);
  6326. initFail(hWndMain, shit);
  6327. #endif
  6328.  
  6329. return(0);
  6330. }
  6331.  
  6332. #endif
  6333.  
  6334. if (strnicmp(shit,"-nosound",strlen("-nosound")) == 0) sound_on = false;
  6335.  
  6336. }
  6337.  
  6338. //redink1 code so DMOD version can't run D-Mods
  6339. #ifdef DMOD
  6340. strcpy(dir, ".");
  6341. #endif
  6342.  
  6343. if (chdir(dir) == -1)
  6344. {
  6345. #ifdef __ENGLISH
  6346. sprintf(shit,"Game dir \"%s\" not found!",dir);
  6347. #endif
  6348. #ifdef __GERMAN
  6349.  
  6350. sprintf(shit,"Spiele-direktory \"%s\" nicht gefunden!",dir);
  6351. #endif
  6352.  
  6353. initFail(hWndMain, shit);
  6354. exit(0);
  6355. return(0);
  6356. }
  6357.  
  6358.  
  6359. Msg("Dir is now %s.",dir);
  6360. return(true);
  6361. }
  6362. /*
  6363. * doInit - do work required for every instance of the application:
  6364. * create the window, initialize data
  6365. */
  6366.  
  6367.  
  6368. //redink1 and invertigo fix for windowed/high color mode
  6369. static BOOL doInit( HINSTANCE hInstance, int nCmdShow )
  6370. {
  6371. memset(id, '\0', sizeof(id));
  6372. // HRESULT dsrval;
  6373. // BOOL bUseDSound;
  6374. WNDCLASS wc;
  6375. DDSURFACEDESC ddsd;
  6376. DDSCAPS ddscaps;
  6377. HRESULT ddrval;
  6378. RECT rcRect;
  6379.  
  6380.  
  6381. char crap[30];
  6382. char crap1[10];
  6383.  
  6384. RECT rcRectSrc; RECT rcRectDest;
  6385. POINT p;
  6386. /*
  6387. * set up and register window class
  6388. */
  6389.  
  6390.  
  6391.  
  6392. wc.style = CS_HREDRAW | CS_VREDRAW;
  6393. wc.lpfnWndProc = WindowProc;
  6394. wc.cbClsExtra = 0;
  6395. wc.cbWndExtra = 0;
  6396. wc.hInstance = hInstance;
  6397. wc.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE(IDI_ICON1) );
  6398. wc.hCursor = LoadCursor( NULL, IDC_ARROW );
  6399. wc.hbrBackground = GetStockBrush(BLACK_BRUSH);
  6400. wc.lpszMenuName = NAME;
  6401. wc.lpszClassName = NAME;
  6402. RegisterClass( &wc );
  6403. /*
  6404. * create a window
  6405. */
  6406.  
  6407. windowed = false;
  6408. // hWndMain = hwnd;
  6409.  
  6410.  
  6411. if (!check_arg(command_line))
  6412. {
  6413. return(0);
  6414. //return initFail(hwnd, "Bad game directory. Check your -game setting.");
  6415. }
  6416.  
  6417.  
  6418.  
  6419.  
  6420.  
  6421. if (windowed)
  6422. {
  6423. /*hwnd = CreateWindowEx(
  6424. 0,
  6425. NAME,
  6426. TITLE,
  6427. // WS_POPUP,
  6428.  
  6429. WS_SYSMENU|WS_CAPTION,
  6430.  
  6431. 0,
  6432. 0,
  6433. 640, 480,
  6434. //GetSystemMetrics(SM_CXSCREEN),
  6435. //GetSystemMetrics(SM_CYSCREEN),
  6436. NULL,
  6437. NULL,
  6438. hInstance,
  6439. NULL );
  6440.  
  6441. if( !hwnd )
  6442. {
  6443. return FALSE;
  6444. }
  6445.  
  6446. // Now check actual size of client area
  6447. RECT check;
  6448. GetClientRect(hwnd, &check);
  6449. int ExtendWidth = 640 - (check.right - check.left);
  6450. int ExtendHeight = 480 - (check.bottom - check.top);
  6451.  
  6452. DestroyWindow(hwnd);*/
  6453.  
  6454. hwnd = CreateWindowEx(
  6455. 0,
  6456. NAME,
  6457. TITLE,
  6458. // WS_POPUP,
  6459.  
  6460. WS_SYSMENU|WS_CAPTION,
  6461.  
  6462. 0,
  6463. 0,
  6464. 640,480,
  6465. // GetSystemMetrics(SM_CXSCREEN),
  6466. // GetSystemMetrics(SM_CYSCREEN),
  6467. NULL,
  6468. NULL,
  6469. hInstance,
  6470. NULL );
  6471. hWndMain = hwnd;
  6472.  
  6473. if( !hwnd )
  6474. {
  6475. return FALSE;
  6476. }
  6477.  
  6478. RECT check;
  6479. GetClientRect(hwnd, &check);
  6480. int ExtendWidth = 640 - (check.right - check.left);
  6481. int ExtendHeight = 480 - (check.bottom - check.top);
  6482.  
  6483. MoveWindow( hWndMain, check.left, check.top, 640 + ExtendWidth, 480 + ExtendHeight, TRUE );
  6484.  
  6485. ShowWindow( hwnd, nCmdShow );
  6486. UpdateWindow( hwnd );
  6487. SetFocus( hwnd );
  6488. /*
  6489. * create the main DirectDraw object
  6490. */
  6491. ddrval = DirectDrawCreate( NULL, &lpDD, NULL );
  6492. if( ddrval != DD_OK )
  6493. {
  6494. return initFail(hwnd, "Couldn't use DirectX 8+... Install it first.");
  6495. }
  6496.  
  6497.  
  6498.  
  6499. // Get exclusive mode
  6500.  
  6501.  
  6502. // using DDSCL_NORMAL means we will coexist with GDI
  6503. ddrval = lpDD->SetCooperativeLevel( hwnd, DDSCL_NORMAL );
  6504.  
  6505. if( ddrval != DD_OK )
  6506. {
  6507. lpDD->Release();
  6508. return initFail(hwnd, "Couldn't make windowed screen.");
  6509.  
  6510. }
  6511. memset( &ddsd, 0, sizeof(ddsd) );
  6512. ddsd.dwSize = sizeof( ddsd );
  6513. ddsd.dwFlags = DDSD_CAPS;
  6514. ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
  6515.  
  6516. // The primary surface is not a page flipping surface this time
  6517. ddrval = lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL );
  6518.  
  6519. if( ddrval != DD_OK )
  6520. { lpDD->Release();
  6521. return initFail(hwnd, "Couldn't make primary surface.");
  6522.  
  6523.  
  6524. }
  6525.  
  6526. memset( &ddsd, 0, sizeof(ddsd) );
  6527. ddsd.dwSize = sizeof( ddsd );
  6528. ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
  6529. //redink1 added SYSTEMMEMORY to speed things up
  6530. ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
  6531. ddsd.dwWidth = 640;
  6532. ddsd.dwHeight = 480; // create the backbuffer separately
  6533.  
  6534. ddrval = lpDD->CreateSurface( &ddsd, &lpDDSBack, NULL );
  6535. if( ddrval != DD_OK )
  6536. { lpClipper-> Release();
  6537.  
  6538. lpDDSPrimary->Release();
  6539. lpDD->Release();
  6540. return initFail(hwnd, "Couldn't make Back buffer in Windowed mode.");
  6541. }
  6542.  
  6543.  
  6544.  
  6545. // Create a clipper to ensure that our drawing stays inside our window
  6546. ddrval = lpDD->CreateClipper( 0, &lpClipper, NULL );
  6547. if( ddrval != DD_OK )
  6548. {
  6549. lpDDSPrimary->Release();
  6550.  
  6551. lpDD->Release();
  6552. return initFail(hwnd, "Couldn't make a Clipper object, god knows why.");
  6553.  
  6554. }
  6555.  
  6556.  
  6557. // setting it to our hwnd gives the clipper the coordinates from our window
  6558. ddrval = lpClipper->SetHWnd( 0, hwnd );
  6559. if( ddrval != DD_OK )
  6560. {
  6561. lpClipper-> Release();
  6562. lpDDSPrimary->Release();
  6563.  
  6564. lpDD->Release();
  6565. return initFail(hwnd, "Couldn't give Clipper window cords.");
  6566.  
  6567. }
  6568. // attach the clipper to the primary surface
  6569. ddrval = lpDDSPrimary->SetClipper( lpClipper );
  6570. if( ddrval != DD_OK )
  6571. {
  6572. lpClipper-> Release();
  6573. lpDDSPrimary->Release();
  6574. lpDD->Release();
  6575.  
  6576. return initFail(hwnd, "Couldn't attach Clipper to primary buffer.");
  6577. }
  6578.  
  6579.  
  6580. }
  6581.  
  6582. if (!windowed)
  6583. {
  6584.  
  6585. hwnd = CreateWindowEx(
  6586. 0,
  6587. NAME,
  6588. TITLE,
  6589. WS_POPUP ,
  6590.  
  6591. //WS_SYSMENU|WS_CAPTION,
  6592.  
  6593. 0,
  6594. 0,
  6595. 640, 480,
  6596. // GetSystemMetrics(SM_CXSCREEN),
  6597. // GetSystemMetrics(SM_CYSCREEN),
  6598. NULL,
  6599. NULL,
  6600. hInstance,
  6601. NULL );
  6602. hWndMain = hwnd;
  6603.  
  6604. if( !hwnd )
  6605. {
  6606. return FALSE;
  6607. }
  6608.  
  6609. ShowWindow( hwnd, nCmdShow );
  6610. UpdateWindow( hwnd );
  6611. SetFocus( hwnd );
  6612.  
  6613.  
  6614. /*
  6615. * create the main DirectDraw object
  6616. */
  6617. ddrval = DirectDrawCreate( NULL, &lpDD, NULL );
  6618. if( ddrval != DD_OK )
  6619. {
  6620. return initFail(hwnd, "Couldn't use DirectX 3+... Install it first.");
  6621. }
  6622.  
  6623. // Get exclusive mode
  6624.  
  6625.  
  6626.  
  6627.  
  6628. ddrval = lpDD->SetCooperativeLevel( hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN );
  6629.  
  6630.  
  6631. if( ddrval != DD_OK )
  6632. {
  6633. return initFail(hwnd, "SetCooperative level failed.");
  6634. }
  6635.  
  6636.  
  6637. // Set the video mode to 640x480xX
  6638. if ( truecolor == true )
  6639. {
  6640. // Keep trying until one works, or not. There should be a way to see what DirectX supports... hrm
  6641. ddrval = lpDD->SetDisplayMode( x, y, 32 );
  6642. if ( ddrval != DD_OK )
  6643. {
  6644. ddrval = lpDD->SetDisplayMode( x, y, 24 );
  6645. if ( ddrval != DD_OK )
  6646. {
  6647. ddrval = lpDD->SetDisplayMode( x, y, 16 );
  6648. if ( ddrval != DD_OK )
  6649. {
  6650. return initFail( hwnd, "640 X 480, true color mode not supported." );
  6651. }
  6652. }
  6653. }
  6654. }
  6655. else
  6656. {
  6657. ddrval = lpDD->SetDisplayMode( x, y, 8 );
  6658. if ( ddrval != DD_OK )
  6659. {
  6660. return initFail( hwnd, "640 X 480, 8 bit not supported." );
  6661. }
  6662. }
  6663.  
  6664. // finiObjects();
  6665. // return false;
  6666.  
  6667. ZeroMemory(&hm, sizeof(hit_map));
  6668.  
  6669.  
  6670.  
  6671. // Create the primary surface with 1 back buffer
  6672. ddsd.dwSize = sizeof( ddsd );
  6673. ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
  6674. ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
  6675. DDSCAPS_FLIP |
  6676. DDSCAPS_COMPLEX;
  6677.  
  6678. ddsd.dwBackBufferCount = 1;
  6679. ddrval = lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL );
  6680. if( ddrval != DD_OK )
  6681. {
  6682. return initFail(hwnd, "Could not create primary surface.");
  6683. }
  6684.  
  6685. ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
  6686.  
  6687. /* if (ddsd.ddsCaps.dwCaps == DDCAPS_BLTSTRETCH)
  6688. {
  6689. return initFail(hwnd, "Hardware blit stretching available.");
  6690. }
  6691. */
  6692. ddrval = lpDDSPrimary->GetAttachedSurface(&ddscaps, &lpDDSBack);
  6693. if( ddrval != DD_OK )
  6694. {
  6695. return initFail(hwnd, "Could not create backbuffer,");
  6696. }
  6697.  
  6698. }
  6699.  
  6700. //redink1 init for color depth information
  6701. if (truecolor)
  6702. {
  6703. DDSURFACEDESC dds;
  6704. memset(&dds, 0, sizeof(DDSURFACEDESC));
  6705. dds.dwSize = sizeof(DDSURFACEDESC);
  6706. lpDDSBack->GetSurfaceDesc(&dds);
  6707. if ( dds.ddpfPixelFormat.dwGBitMask == 0x07E0 )
  6708. {
  6709. // 565
  6710. mColorDepth = ColorDepth16Bit_565;
  6711. m16BitFadeValues = new unsigned short[65536][30];
  6712.  
  6713. for ( unsigned short lFade( 0 ); lFade < 30; lFade++ )
  6714. {
  6715. float lFadeAdjustment( ( 30.0f - static_cast<float>( lFade ) ) / 30.0f );
  6716. for ( unsigned short lRed( 0 ); lRed < 32; lRed++ )
  6717. {
  6718. unsigned short lRedFadeValue = static_cast<unsigned short>( static_cast<float>( lRed ) * lFadeAdjustment ) << 11;
  6719. for ( unsigned short lGreen( 0 ); lGreen < 64; lGreen++ )
  6720. {
  6721. unsigned short lGreenFadeValue = static_cast<unsigned short>( static_cast<float>( lGreen ) * lFadeAdjustment ) << 5;
  6722. for ( unsigned short lBlue( 0 ); lBlue < 32; lBlue++ )
  6723. {
  6724. unsigned short lBlueFadeValue = static_cast<unsigned short>( static_cast<float>( lBlue ) * lFadeAdjustment );
  6725. if ( ( lRed << 11 | lGreen << 5 | lBlue ) == 0xFFFF )
  6726. {
  6727. lRedFadeValue = lRed << 11;
  6728. lGreenFadeValue = lGreen << 5;
  6729. lBlueFadeValue = lBlue;
  6730. }
  6731. m16BitFadeValues[ lRed << 11 | lGreen << 5 | lBlue ][ lFade ] = lRedFadeValue | lGreenFadeValue | lBlueFadeValue;
  6732. }
  6733. }
  6734. }
  6735. }
  6736. }
  6737. else if ( dds.ddpfPixelFormat.dwGBitMask == 0x03E0 )
  6738. {
  6739. // 555
  6740. mColorDepth = ColorDepth16Bit_555;
  6741. m16BitFadeValues = new unsigned short[65536][30];
  6742.  
  6743. for ( unsigned short lFade( 0 ); lFade < 30; lFade++ )
  6744. {
  6745. float lFadeAdjustment( ( 30.0f - static_cast<float>( lFade ) ) / 30.0f );
  6746. for ( unsigned short lRed( 0 ); lRed < 32; lRed++ )
  6747. {
  6748. unsigned short lRedFadeValue = static_cast<unsigned short>( static_cast<float>( lRed ) * lFadeAdjustment ) << 10;
  6749. for ( unsigned short lGreen( 0 ); lGreen < 32; lGreen++ )
  6750. {
  6751. unsigned short lGreenFadeValue = static_cast<unsigned short>( static_cast<float>( lGreen ) * lFadeAdjustment ) << 5;
  6752. for ( unsigned short lBlue( 0 ); lBlue < 32; lBlue++ )
  6753. {
  6754. unsigned short lBlueFadeValue = static_cast<unsigned short>( static_cast<float>( lBlue ) * lFadeAdjustment );
  6755. if ( ( lRed << 10 | lGreen << 5 | lBlue ) == 0xFFFF )
  6756. {
  6757. lRedFadeValue = lRed << 10;
  6758. lGreenFadeValue = lGreen << 5;
  6759. lBlueFadeValue = lBlue;
  6760. }
  6761. m16BitFadeValues[ lRed << 10 | lGreen << 5 | lBlue ][ lFade ] = lRedFadeValue | lGreenFadeValue | lBlueFadeValue;
  6762. }
  6763. }
  6764. }
  6765. }
  6766. }
  6767. else if ( dds.ddpfPixelFormat.dwRGBBitCount == 32 || dds.ddpfPixelFormat.dwRGBBitCount == 24 )
  6768. {
  6769. // 32 & 24
  6770. if ( dds.ddpfPixelFormat.dwRGBBitCount == 32 )
  6771. {
  6772. mColorDepth = ColorDepth32Bit;
  6773. }
  6774. else
  6775. {
  6776. mColorDepth = ColorDepth24Bit;
  6777. }
  6778. m8BitFadeValues = new unsigned char[256][30];
  6779. for ( unsigned char lFade( 0 ); lFade < 30; lFade++ )
  6780. {
  6781. double lFadeAdjustment( ( 30.0 - static_cast<double>( lFade ) ) / 30.0 );
  6782. for ( unsigned short lValue( 0 ); lValue <= 255; lValue++ )
  6783. {
  6784. m8BitFadeValues[lValue][lFade] = static_cast<unsigned char>( static_cast<double>( lValue ) * lFadeAdjustment );
  6785. }
  6786. }
  6787. }
  6788. else
  6789. {
  6790. mColorDepth = ColorDepthNotRecognized;
  6791. // No fade
  6792. }
  6793.  
  6794. dwRMask = dds.ddpfPixelFormat.dwRBitMask;
  6795. dwGMask = dds.ddpfPixelFormat.dwGBitMask;
  6796. dwBMask = dds.ddpfPixelFormat.dwBBitMask;
  6797. wRBits=GetNumberOfBits(dwRMask);
  6798. wGBits=GetNumberOfBits(dwGMask);
  6799. wBBits=GetNumberOfBits(dwBMask);
  6800.  
  6801. wRPos = GetMaskPos(dwRMask);
  6802. wGPos = GetMaskPos(dwGMask);
  6803. wBPos = GetMaskPos(dwBMask);
  6804.  
  6805. memset( &ddsd, 0, sizeof(ddsd) );
  6806. ddsd.dwSize = sizeof( ddsd );
  6807. ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
  6808. ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER | DDSCAPS_SYSTEMMEMORY;
  6809. ddsd.dwWidth = 640;
  6810. ddsd.dwHeight = 480;
  6811. ddrval = lpDD->CreateSurface( &ddsd, &lpDDSFade, NULL );
  6812. }
  6813.  
  6814. //init is finished, now lets load some more junk
  6815. //return initFail(hwnd, "Couldn't make a Clipper object, god knows why.");
  6816. // create and set the palette
  6817.  
  6818. // getCDTrackStartTimes();
  6819.  
  6820.  
  6821.  
  6822. if (exist("tiles\\TS01.bmp"))
  6823. lpDDPal = DDLoadPalette(lpDD, "tiles\\TS01.BMP"); else
  6824. lpDDPal = DDLoadPalette(lpDD, "..\\dink\\tiles\\TS01.BMP");
  6825. if (lpDDPal)
  6826. lpDDSPrimary->SetPalette(lpDDPal);
  6827.  
  6828. if(lpDDPal->GetEntries(0,0,256,real_pal)!=DD_OK)
  6829. {
  6830. Msg("error with getting entries in beginning");
  6831. }
  6832.  
  6833. //redink1 Faster true-color fades
  6834. /*if ( truecolor )
  6835. {
  6836. mPrecalculatedFadeValues = new std::map<DWORD, FadeValues>;
  6837. DWORD dwWhite = dwRMask | dwGMask | dwBMask;
  6838. PALETTEENTRY lPaletteEntries[256];
  6839. lpDDPal->GetEntries( 0, 0, 256, lPaletteEntries );
  6840. for ( int lPaletteEntry = 0; lPaletteEntry < 256; lPaletteEntry++ )
  6841. {
  6842. DWORD lColor = ( lPaletteEntries[lPaletteEntry].peRed >> (8 - wRBits) << wRPos |
  6843. lPaletteEntries[lPaletteEntry].peGreen >> (8 - wGBits) << wGPos |
  6844. lPaletteEntries[lPaletteEntry].peBlue >> (8 - wBBits) << wBPos );
  6845. mPrecalculatedFadeValues->[lColor].reserve(256);
  6846. for ( int lFadeValue = 0; lFadeValue < 256; lFadeValue += 1 )
  6847. {
  6848. DWORD red = (lColor & dwRMask) << (8 - wRBits) >> wRPos;
  6849. red = (red >= lFadeValue ? red - lFadeValue : 0);
  6850.  
  6851. DWORD green = (lColor & dwGMask) << (8 - wGBits) >> wGPos;
  6852. green = (green >= lFadeValue ? green - lFadeValue : 0);
  6853.  
  6854. DWORD blue = (lColor & dwBMask) << (8 - wBBits) >> wBPos;
  6855. blue = (blue >= lFadeValue ? blue - lFadeValue : 0);
  6856.  
  6857. DWORD lResult = ( red >> (8 - wRBits) << wRPos |
  6858. green >> (8 - wGBits) << wGPos |
  6859. blue >> (8 - wBBits) << wBPos );
  6860. mPrecalculatedFadeValues[lColor].push_back( lResult );
  6861. }
  6862. }
  6863. }*/
  6864.  
  6865. if (exist("tiles\\splash.bmp"))
  6866. lpDDPal = DDLoadPalette(lpDD, "tiles\\SPLASH.BMP"); else
  6867. lpDDPal = DDLoadPalette(lpDD, "..\\dink\\tiles\\SPLASH.BMP");
  6868.  
  6869. if (lpDDPal)
  6870. lpDDSPrimary->SetPalette(lpDDPal);
  6871.  
  6872.  
  6873. //crashes here!
  6874. Msg("loading tilescreens...");
  6875.  
  6876. for (int h=1; h < tile_screens; h++)
  6877. {
  6878. if (h < 10) strcpy(crap1,"0"); else strcpy(crap1, "");
  6879. sprintf(crap, "TILES\\TS%s%d.BMP",crap1,h);
  6880.  
  6881. if (!exist(crap))
  6882. {
  6883. sprintf(crap, "..\\DINK\\TILES\\TS%s%d.BMP",crap1,h);
  6884. }
  6885.  
  6886. tiles[h] = DDTileLoad(lpDD, crap, 0, 0,h);
  6887.  
  6888.  
  6889. if( tiles[h] == NULL )
  6890. {
  6891. return initFail(hwnd, "Couldn't find one of the tilescreens!");
  6892. } else
  6893. {
  6894. //tilerect[h].right = lpDD->dwWidth;
  6895.  
  6896. DDSetColorKey(tiles[h], RGB(0,0,0));
  6897. }
  6898. }
  6899. Msg("Done with tilescreens...");
  6900.  
  6901. // Create the offscreen surface, by loading our bitmap.
  6902. //lpDDSOne = DDLoadBitmap(lpDD, szBitmap, 0, 0);
  6903. if (sound_on)
  6904. {
  6905. Msg("Initting sound");
  6906. sound_on = InitSound(hwnd);
  6907. }
  6908.  
  6909.  
  6910. #ifdef __DEMO
  6911.  
  6912. PlayMidi("4.MID");
  6913. #endif
  6914. srand( (unsigned)time( NULL ) );
  6915.  
  6916. if (exist("tiles\\splash.bmp"))
  6917. lpDDSTwo = DDLoadBitmap(lpDD, "tiles\\splash.BMP", 0, 0); else
  6918. lpDDSTwo = DDLoadBitmap(lpDD, "..\\dink\\tiles\\splash.BMP", 0, 0);
  6919. DDSetColorKey(lpDDSTwo, RGB(0,0,0));
  6920. #ifndef __DEMO
  6921.  
  6922. getCDTrackStartTimes();
  6923.  
  6924. if (cd_inserted)
  6925. PlayCD(g_hWnd, 7);
  6926. #endif
  6927.  
  6928. if ( disablejoystick == FALSE )
  6929. {
  6930. if (CheckJoyStickPresent() == FALSE)
  6931. {
  6932. // return initFail(hwnd, "Could not init the joystick.");
  6933. joystick = FALSE;
  6934. } else
  6935. {
  6936. joystick = TRUE;
  6937. }
  6938. }
  6939.  
  6940. rcRect.left = 0;
  6941. rcRect.top = 0;
  6942. rcRect.right = x;
  6943. rcRect.bottom = y;
  6944.  
  6945. //if (lpDDSBack->GetBltStatus( DDGBS_ISBLTDONE) == DD_OK)
  6946. //draw version #
  6947.  
  6948.  
  6949.  
  6950. ddrval = lpDDSBack->BltFast( 0, 0, lpDDSTwo,
  6951. &rcRect, DDBLTFAST_NOCOLORKEY);
  6952.  
  6953. if (!windowed)
  6954. {
  6955. while( 1 )
  6956. {
  6957. ddrval = lpDDSPrimary->Flip(NULL,DDFLIP_WAIT );
  6958. if( ddrval == DD_OK )
  6959. {
  6960. break;
  6961. }
  6962. if( ddrval == DDERR_SURFACELOST )
  6963. {
  6964. ddrval = restoreAll();
  6965. if( ddrval != DD_OK )
  6966. {
  6967. break;
  6968. }
  6969. }
  6970. if( ddrval != DDERR_WASSTILLDRAWING )
  6971. {
  6972.  
  6973. // ddrval = DD_OK;
  6974. dderror(ddrval);
  6975. // return;
  6976. // ddrval = DD_OK;
  6977. }
  6978. //goto done;
  6979. }
  6980. } else
  6981. {
  6982.  
  6983. // instead of a flip, this will work for Windowed mode:
  6984. // first we need to figure out where on the primary surface our window lives
  6985. p.x = 0; p.y = 0; ClientToScreen(hwnd, &p);
  6986. GetClientRect(hwnd, &rcRectDest);
  6987. OffsetRect(&rcRectDest, p.x, p.y);
  6988. SetRect(&rcRectSrc, 0, 0, 640, 480);
  6989. ddrval = lpDDSPrimary->Blt( &rcRectDest, lpDDSBack, &rcRectSrc, DDBLT_WAIT, NULL);
  6990. }
  6991.  
  6992.  
  6993.  
  6994.  
  6995. //dinks normal walk
  6996.  
  6997.  
  6998. Msg("loading batch");
  6999. load_batch();
  7000.  
  7001.  
  7002. Msg("done loading batch");
  7003.  
  7004.  
  7005. load_hard();
  7006.  
  7007. //Activate dink, but don't really turn him on
  7008. //spr[1].active = TRUE;
  7009. spr[1].timer = 33;
  7010.  
  7011. //copy from player info
  7012. spr[1].x = play.x;
  7013. spr[1].y = play.y;
  7014.  
  7015.  
  7016.  
  7017. if (exist("tiles\\TS01.bmp"))
  7018. lpDDPal = DDLoadPalette(lpDD, "tiles\\TS01.BMP"); else
  7019. lpDDPal = DDLoadPalette(lpDD, "..\\dink\\tiles\\TS01.BMP");
  7020. if (lpDDPal)
  7021. lpDDSPrimary->SetPalette(lpDDPal);
  7022.  
  7023. Msg("Loading splash");
  7024. if (exist("tiles\\SPLASH.bmp"))
  7025. lpDDSTrick = DDLoadBitmap(lpDD, "tiles\\SPLASH.BMP", 0, 0); else
  7026. lpDDSTrick = DDLoadBitmap(lpDD, "..\\dink\\tiles\\SPLASH.BMP", 0, 0);
  7027. DDSetColorKey(lpDDSTrick, RGB(0,0,0));
  7028.  
  7029. if (exist("tiles\\SPLASH.bmp"))
  7030. lpDDSTrick2 = DDLoadBitmap(lpDD, "tiles\\SPLASH.BMP", 0, 0); else
  7031. lpDDSTrick2 = DDLoadBitmap(lpDD, "..\\dink\\tiles\\SPLASH.BMP", 0, 0);
  7032. DDSetColorKey(lpDDSTrick2, RGB(0,0,0));
  7033.  
  7034. // ** SETUP **
  7035.  
  7036. rcRect.left = 0;
  7037. rcRect.top = 0;
  7038. rcRect.right = 639;
  7039. rcRect.bottom = 79;
  7040. last_sprite_created = 1;
  7041.  
  7042. mode = 0;
  7043.  
  7044. load_info();
  7045. for (int x=0; x<256; x++)
  7046. {
  7047. if (GetKeyboard(x))
  7048. {
  7049. }
  7050. } //clear keyboard buffer
  7051.  
  7052. for (int u = 1; u <= 10; u++)
  7053. play.button[u] = u;
  7054.  
  7055.  
  7056. for (int x1=1; x1 <= 10; x1++)
  7057. {
  7058. sjoy.letgo[x1] = TRUE;
  7059. }
  7060.  
  7061. //lets run our init script
  7062. int script = load_script("main", 0, true);
  7063. locate(script, "main");
  7064. run_script(script);
  7065. //lets attach our vars to the scripts
  7066.  
  7067. attach();
  7068.  
  7069.  
  7070. //init_mouse(hwnd);
  7071.  
  7072. memset( &spr, NULL, sizeof(spr) );
  7073. init_font_colors();
  7074. initfonts("Arial");
  7075. //g_pMouse->Acquire();
  7076.  
  7077.  
  7078. return TRUE;
  7079.  
  7080. } /* doInit */
  7081.  
  7082.  
  7083. #include <sys/types.h>
  7084. #include <sys/stat.h>
  7085.  
  7086. bool random_date(char file[255])
  7087.  
  7088. {
  7089. //let's randomize the date on this file to trick Windows
  7090. //cacheing into doing it right!
  7091.  
  7092. int fh, result;
  7093.  
  7094. unsigned int nbytes = BUFSIZ; /* Open a file */
  7095.  
  7096. if( (fh = _open( file, _O_RDWR | _O_CREAT, _S_IREAD
  7097. | _S_IWRITE )) != -1 )
  7098. {
  7099. Msg( "File length before: %ld\n", _filelength( fh ) );
  7100. if( ( result = _chsize( fh, _filelength( fh )+((rand() % 1000)+1) ) ) == 0 )
  7101. Msg( "Size successfully changed\n" );
  7102. else
  7103. Msg( "Problem in changing the size\n" );
  7104.  
  7105. Msg( "File length after: %ld\n", _filelength( fh ) );
  7106.  
  7107. _close( fh );
  7108.  
  7109. } else return(false);
  7110.  
  7111.  
  7112. return(true);
  7113. }
  7114.  
  7115.  
  7116.  
  7117.  
  7118. int dir_num ( char path[255])
  7119. {
  7120.  
  7121. HANDLE dir;
  7122. WIN32_FIND_DATA fd;
  7123. unsigned long cnt;
  7124.  
  7125. char *dename;
  7126.  
  7127. /*
  7128. * build a header
  7129. */
  7130.  
  7131. char search_specs[255];
  7132.  
  7133. sprintf(search_specs, "%s\\*.*",path);
  7134. cnt = 0;
  7135. ODS( "ASking for dir info." );
  7136. dir = FindFirstFile( search_specs, &fd );
  7137. if( dir == NULL )
  7138. {
  7139. ODS( "Could not open current directory\n" );
  7140. return(0);
  7141. }
  7142.  
  7143.  
  7144. while( 1 )
  7145. {
  7146. if( !(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
  7147. {
  7148. cnt++;
  7149.  
  7150. dename = fd.cAlternateFileName;
  7151. if( dename[0] == 0 ) {
  7152. dename = fd.cFileName;
  7153. }
  7154. Msg( "File %d: %s \r", cnt, dename );
  7155.  
  7156. }
  7157. if( !FindNextFile( dir, &fd ) ) {
  7158. break;
  7159. }
  7160. }
  7161.  
  7162. FindClose( dir );
  7163. ODS("All done finding files.");
  7164. return(cnt);
  7165. }
  7166.  
  7167. void getdir(char final[])
  7168. {
  7169. //converted to non CString version that spits back path + filename seperately.
  7170. //Using GetModuleFileName instead of ParamStr, works with Win2000/nt.
  7171. char dir[255];
  7172. char path[255];
  7173. GetModuleFileName(NULL, path, 255);
  7174. char c_cur = 0;
  7175.  
  7176. for (int k=strlen(path);path[k] != '\\'; k--)
  7177. {
  7178. c_cur = k;
  7179. }
  7180. strcpy(dir, "");
  7181. //copy file name
  7182. strncat((char*)&dir, &path[c_cur], strlen(path)-c_cur);
  7183. path[c_cur] = 0; //truncate
  7184. strcpy(final, path);
  7185.  
  7186. }
  7187. /*
  7188. * WinMain - initialization, message loop
  7189. */
  7190. int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  7191. LPSTR lpCmdLine, int nCmdShow)
  7192. {
  7193. sound_support = ((rand() % 200000)+1);
  7194.  
  7195. mycode = ((rand() % 200000)+1);
  7196. char crap2[256];
  7197.  
  7198.  
  7199. // strcpy(crap2, GetCommandLine());
  7200. ///*
  7201. getdir((char*)&crap2);
  7202.  
  7203.  
  7204.  
  7205. // crap2[strlen(crap2)-1] = 0;
  7206.  
  7207. // char st_temp[500];
  7208. // getdir(st_temp, crap2);
  7209.  
  7210. strcpy(dinkpath, crap2);
  7211.  
  7212.  
  7213.  
  7214.  
  7215. if (chdir(crap2))
  7216. {
  7217. char crap[256];
  7218. sprintf(crap, "Dink Error: Couldn't change to dir %s. Why?", crap2);
  7219. initFail(hWndMain, crap2);
  7220. return(0);
  7221. }
  7222.  
  7223.  
  7224.  
  7225.  
  7226.  
  7227. #ifdef __DEMO
  7228.  
  7229. //if (chdir("story"))
  7230. Msg("Error finding story dir.");
  7231. mcc = sound_support;
  7232.  
  7233. if (dir_num("dink\\story") != 250+9)
  7234. {
  7235.  
  7236. mcc = 0;
  7237.  
  7238. #ifdef __GERMAN
  7239. sprintf(crap, "Die Shareware-Version akzeptiert keine selbsterstellten Abenteuer.", crap2);
  7240. #endif
  7241.  
  7242. #ifdef __ENGLISH
  7243.  
  7244. sprintf(crap, "Shareware version cannot run player made quests.", crap2);
  7245. #endif
  7246.  
  7247.  
  7248.  
  7249. initFail(hWndMain, crap);
  7250. return(0);
  7251. }
  7252.  
  7253. //if (chdir(".."))
  7254.  
  7255. #endif
  7256.  
  7257. if (exist("cd.dat")) burn_revision = 1;
  7258.  
  7259.  
  7260. //int junk = GetTickCount() + 5000;
  7261.  
  7262. //yeah:
  7263. // if (junk > GetTickCount()) goto yeah;
  7264.  
  7265. //random_date("DMOVIE.EXE");
  7266.  
  7267.  
  7268. MSG msg;
  7269. lpCmdLine = lpCmdLine;
  7270.  
  7271. command_line = lpCmdLine;
  7272. /*
  7273. if (compare("", command_line))
  7274. {
  7275. if (exist("DMOVIE.EXE"))
  7276. {
  7277. Msg("No command line. Let's run movies.");
  7278. char run_this[255];
  7279. sprintf(run_this, "%s\\DMOVIE.EXE",dinkpath);
  7280.  
  7281. int myreturn = _execl( run_this,run_this, NULL );
  7282. if (myreturn == 1)
  7283. {
  7284. ODS("Spawn error: Path not found.");
  7285.  
  7286. }
  7287. if (myreturn == 2)
  7288. {
  7289. ODS("Spawn error: Not enough memory.");
  7290.  
  7291. }
  7292.  
  7293.  
  7294. return(0);
  7295. }
  7296. } else
  7297. {
  7298.  
  7299. // Msg("Older version of Dink detected.");
  7300. }
  7301. */
  7302. MyhInstance = hInstance;
  7303. hPrevInstance = hPrevInstance;
  7304. //return(0);
  7305. if( !doInit( hInstance, nCmdShow ) )
  7306. {
  7307.  
  7308. // return FALSE;
  7309. }
  7310.  
  7311. log_path(true);
  7312.  
  7313.  
  7314.  
  7315.  
  7316.  
  7317. while( 1 )
  7318. {
  7319. if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
  7320. {
  7321. // Msg("Got %d", msg.message);
  7322. if( !GetMessage( &msg, NULL, 0, 0 ) )
  7323. {
  7324. return msg.wParam;
  7325. }
  7326.  
  7327. //Msg("Got message - %d and %d", msg.wParam, msg.lParam);
  7328. TranslateMessage(&msg);
  7329. DispatchMessage(&msg);
  7330. }
  7331. else if( (bActive) || ( (debug_mode) && (windowed)) )
  7332. {
  7333. if (g_b_kill_app == false)
  7334. {
  7335. SetFocus( hwnd );
  7336. updateFrame();
  7337. }
  7338. //WaitMessage();
  7339.  
  7340. }
  7341. else
  7342. {
  7343. // make sure we go to sleep if we have nothing else to do
  7344. Sleep(1);
  7345. SetFocus( NULL );
  7346. WaitMessage();
  7347.  
  7348. }
  7349. }
  7350. } /* WinMain */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement