Advertisement
Guest User

Untitled

a guest
Aug 26th, 2013
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 228.67 KB | None | 0 0
  1. /*
  2.  in game scripts
  3.    2 - find master key
  4.    3 - find crystal
  5.    4 - find shield - obj 8
  6.    5 - find sword - obj 9
  7.    6 - regular key chest
  8.    7 - blue flask
  9.    8 - garden// s master key
  10.    9 - lightning bomb
  11.   10 - blue flask chest
  12.   11 - lightning chest
  13.   12 - armour chest
  14.   13 - citadel master key
  15.   14 - end of game
  16.   15 - get sword3
  17.   16 - shield3
  18.   17 - armour3
  19.   20 key chest 1
  20.   60-lever
  21.  
  22.  monsters
  23.  1 - baby dragon
  24.  2 - one wing
  25.  3 - boss 1
  26.  4 - black knight
  27.  5 - fire hydra
  28.  6 - red dragon
  29.  7 - priest
  30.  8 - yellow fire dragon
  31.  9 - two wing
  32. 10 - dragon2
  33. 11 - final boss
  34. 12 - bat kitty
  35.  
  36.  chests
  37.   0 - regular flask
  38.  11 - key chest
  39.  14 - blue flask chest
  40.  15 - lightning chest
  41.  16 - armour chest
  42.  17 - citadel master key
  43.  18 - sword3
  44.  19 - shield3
  45.  20 - armour3
  46.  
  47. */
  48.  
  49. #include <stdlib.h>
  50. #include <stdio.h>
  51. #include <string.h>
  52. #include <math.h>
  53.  
  54. #include <SDL/SDL.h>
  55. #include <SDL/SDL_image.h>
  56.  
  57. #define MAXNPC      32
  58. #define MAXFLOAT    32
  59. #define MAXSPELL    32
  60. #define ice     0
  61. #define steel       1
  62. #define wood        2
  63. #define rock        3
  64. #define fire        4
  65.  
  66. // inventory items
  67. //#define flask     0
  68. //#define doubleflask   1
  69. //#define shock     2
  70. //#define normalkey 3
  71. //#define masterkey 4
  72.  
  73. #define sndbite     0
  74. #define sndcrystal  1
  75. #define snddoor     2
  76. #define sndenemyhit 3
  77. #define sndice      4
  78. #define sndlever    5
  79. #define sndlightning    6
  80. #define sndmetalhit 7
  81. #define sndpowerup  8
  82. #define sndrocks    9
  83. #define sndswordhit 10
  84. #define sndthrow    11
  85. #define sndchest    12
  86. #define sndfire     13
  87. #define sndbeep     14
  88.  
  89. typedef struct {
  90.     float   px;
  91.     float   py;
  92.     float   opx;
  93.     float   opy;
  94.     int walkdir;
  95.     float   walkframe;
  96.     float   walkspd;
  97.     float   attackframe;
  98.     float   attackspd;
  99.  
  100.     int hp;
  101.     int maxhp;
  102.     float   hpflash;
  103.     int hpflashb;
  104.     int level;
  105.     int sword;
  106.     int shield;
  107.     int armour;
  108.     int foundspell[6];
  109.     float   spellcharge[6];
  110.     int flasks;
  111.     int foundcrystal;
  112.     float   crystalcharge;
  113.     float   attackstrength;
  114.     float   spellstrength;
  115.     int spelldamage;
  116.     int sworddamage;
  117.  
  118.     int masterkey;
  119.  
  120.     int exp;
  121.     int nextlevel;
  122.  
  123.     int windowloc;
  124.     int pause;
  125.  
  126.     float   itemselshade;
  127.     int ysort;
  128. } PLAYERTYPE;
  129.  
  130. typedef struct {
  131.     float   x;
  132.     float   y;
  133.     int parentID;
  134.     int isbase;
  135.     int sprite;
  136.     int bonelength; // the // bone//  that connects the body sections
  137. } BODYSECTIONTYPE;
  138.  
  139.  
  140. typedef struct {
  141.     float   x;
  142.     float   y;
  143.     int spriteset;
  144.     int x1;     // patrol area
  145.     int y1;
  146.     int x2;
  147.     int y2;
  148.     int attitude;
  149.     int hp;
  150.  
  151.     int maxhp;
  152.     int item1;
  153.     int item2;
  154.     int item3;
  155.     int script;
  156.     float   frame;
  157.     float   frame2;     // end boss specific
  158.     int cframe;
  159.     int onmap;      // is this npc set to be genned in the mapfile
  160.  
  161.     int ticks;
  162.     int pause;
  163.     int shake;
  164.  
  165.     int movementmode;
  166.     int walkdir;
  167.     float   walkspd;
  168.     int movingdir;
  169.     int moving;
  170.  
  171.     int attacking;
  172.     float   attackframe;
  173.     int cattackframe;
  174.     float   attackspd;
  175.     int attackdelay;
  176.     int attacknext;
  177.     int attackattempt;
  178.  
  179.     int spelldamage;
  180.     int attackdamage;
  181.  
  182.  
  183.     // one wing and firehydra specific
  184.     BODYSECTIONTYPE bodysection[31];
  185.     float   swayangle;
  186.     float   swayspd;
  187.     float   headtargetx[4];
  188.     float   headtargety[4];
  189.     int castpause;
  190.  
  191.     // firehydra specific
  192.     int attacknext2[4];
  193.     int attacking2[4];
  194.     int attackframe2[4];
  195.  
  196.     // dragon2 specific
  197.     float   floating;
  198. } NPCTYPE;
  199.  
  200.  
  201. typedef struct {
  202.     int spellnum;
  203.     float   homex;
  204.     float   homey;
  205.     float   enemyx;
  206.     float   enemyy;
  207.  
  208.     float   frame;
  209.  
  210.     int damagewho;  // 0 = npc, 1 = player
  211.  
  212.     // for earthslide
  213.     float   rocky[9];
  214.     int rockimg[9];
  215.     int rockdeflect[9];
  216.  
  217.     float   strength;
  218.  
  219.     // fire
  220.     int legalive[5];
  221.  
  222.     // spell 6 specific
  223.     float   fireballs[7][4];    // x,y,targetx, targety
  224.     int nfballs;
  225.     int ballon[7];
  226.  
  227.     int npc;
  228. } SPELLTYPE;
  229.  
  230.  
  231.  
  232. typedef struct {
  233.     int x;  // xyloc on spriteimageset
  234.     int y;
  235.     int xofs;   // the actual place to paste the sprite in reference to the bodypart loc on screen
  236.     int yofs;
  237.     int w;  // w/h of the sprite in the imageset
  238.     int h;
  239. } ANIMSET2TYPE;
  240.  
  241.  
  242. void game_addFloatIcon(int ico, float xloc, float yloc);
  243. void game_addFloatText(char *stri, float xloc, float yloc, int col);
  244. void game_attack();
  245. void game_castspell(int spellnum, float homex, float homey, float enemyx, float enemyy, int damagewho);
  246. void game_checkhit();
  247. void game_checkinputs();
  248. void game_configmenu();
  249. void game_damagenpc(int npcnum, int damage, int spell);
  250. void game_damageplayer(int damage);
  251. void game_drawanims(int Layer);
  252. void game_drawhud();
  253. void game_drawnpcs(int mode);
  254. void game_drawover(int modx, int mody);
  255. void game_drawplayer();
  256. void game_drawview();
  257. void game_endofgame();
  258. void game_eventtext(char *stri);
  259. void game_handlewalking();
  260. void game_loadmap(int mapnum);
  261. void game_main();
  262. void game_newgame();
  263. void game_playgame();
  264. void game_processtrigger(int trignum);
  265. void game_saveloadnew();
  266. void game_showlogos();
  267. void game_swash();
  268. void game_theend();
  269. void game_title(int mode);
  270. void game_updanims();
  271. void game_updatey();
  272. void game_updmusic();
  273. void game_updnpcs();
  274. void game_updspells();
  275. void game_updspellsunder();
  276.  
  277. void sys_customLoad();
  278. void sys_initialize();
  279. void sys_line(SDL_Surface *buffer, int x1, int y1, int x2, int y2, int col);
  280. void sys_LoadAnims();
  281. void sys_LoadFont();
  282. void sys_LoadItemImgs();
  283. void sys_LoadTiles();
  284. void sys_LoadTriggers();
  285. void sys_print(SDL_Surface *buffer, char *stri, int xloc, int yloc, int col);
  286. void sys_progress(int w, int wm);
  287. void sys_LoadObjectDB();
  288. void sys_setupAudio();
  289. void sys_update();
  290.  
  291. // system
  292. SDL_Surface *video, *videobuffer, *videobuffer2, *videobuffer3;
  293. SDL_Surface *titleimg, *titleimg2, *inventoryimg;
  294. SDL_Surface *logosimg, *theendimg;
  295. SDL_Event event;
  296. int SCR_WIDTH, SCR_HEIGHT, SCR_BITS, SCR_TOPX, SCR_TOPY;
  297.  
  298. SDL_Surface *mapbg, *clipbg, *clipbg2;
  299. unsigned int clipsurround[4][4];
  300. int fullscreen;
  301. //int walklimits[7] = {5 * 16, 5 * 16, 14 * 16, 9 * 16, 320, 144};
  302. Uint8 *keys;
  303. float animspd;
  304. int rampdata[40][24];
  305. //JOYINFO joystickinfo;
  306. int curmap;
  307. SDL_Surface *fontchr[224][5]; // 256 - 32
  308. SDL_Surface *itemimg[21], *windowimg;
  309. SDL_Surface *spellimg;
  310.  
  311. int itemselon, curitem, itemticks;
  312. float itemyloc;
  313. int selenemyon, curenemy, forcepause;
  314. int roomlock; // set to disable any room jumps while in the room
  315. int scriptflag[100][10], saveslot;  // script, flag
  316.  
  317. // timer related - move to local later
  318. int ticks, tickspassed, nextticks;
  319. float fp, fps, fpsr;
  320. int secsingame, secstart;
  321.  
  322. extern char *story[38];
  323. SDL_Surface *mapimg[4];
  324. extern int invmap[4][7][13];
  325. extern char *story2[27];
  326.  
  327. // options
  328. int opfullscreen, opmusic, opeffects, opmusicvol, opeffectsvol;
  329.  
  330. SDL_Rect rc, rc2, rcSrc, rcDest, rcSrc2;
  331.  
  332.  
  333. int HWACCEL, HWSURFACE, maxlevel;
  334.  
  335. // inventory
  336. int inventoryalpha, inventory[6];
  337.  
  338. // -----------special case
  339. int dontdrawover;   // used in map24 so that the candles dont draw over the boss, default set to 0
  340.  
  341. // saveload info
  342. SDL_Surface *saveloadimg;
  343.  
  344.  
  345. // post info
  346. float postinfo[21][3];
  347. int nposts;
  348.  
  349. // cloud info
  350. SDL_Surface *cloudimg;
  351. float clouddeg;
  352. int cloudson;
  353.  
  354. // spell info
  355. SPELLTYPE spellinfo[MAXSPELL+1];
  356.  
  357.  
  358. // player info
  359. int movingup, movingdown, movingleft, movingright;
  360. PLAYERTYPE player;
  361. int attacking;
  362. PLAYERTYPE playera;
  363.  
  364.  
  365. // tile info
  366. SDL_Surface *tiles[4];
  367. int tileinfo[3][40][24][3]; // maplayer, x, y, tiledata (tile, tilelayer)
  368.  
  369. extern int elementmap[15][20];
  370.  
  371.  
  372. // animation info
  373. SDL_Surface *anims[100];
  374.         // id number 0&1 = players
  375. SDL_Surface *animsa[100];
  376.         // attack anims
  377. float playerattackofs[4][16][3];
  378.         // [dir] [frame] [x,y ofs, completed(0/1)]
  379.  
  380. float floattext[MAXFLOAT+1][4];
  381.         // [id] [framesleft, x, y, col]
  382. char *floatstri[MAXFLOAT+1];
  383.  
  384. float  floaticon[MAXFLOAT+1][4];
  385.         // [id] [framesleft, x, y, ico]
  386.  
  387. // special for animset2
  388. ANIMSET2TYPE animset2[7], animset9[7];
  389.  
  390. // object info
  391. float objectframe[256][2];
  392. int lastobj;
  393.         // frame!, curframe
  394. int objectinfo[33][6];
  395.         // nframes,xtiles,ytiles,speed,type,script, update?
  396. int objecttile[33][9][3][3][2];
  397.         // [objnum] [frame] [x] [y] [tile/layer]
  398. int objmap[21][15];
  399.  
  400. int objmapf[1000][21][15];
  401.         // [mapnum] x, y  set to 1 to make this objmap spot stay at -1
  402.  
  403. // trigger info
  404. int triggers[10000][9];
  405.         // [map#][index], [var]
  406.         // map#,x,y
  407. int triggerloc[320][240], ntriggers;
  408.  
  409. // npc info
  410. NPCTYPE npcinfo[MAXNPC+1];
  411. int lastnpc;
  412.  
  413. // music info
  414. int mgardens, mgardens2, mgardens3, mgardens4, mboss;
  415. int menabled, musicchannel, mendofgame, menuchannel, mmenu;
  416. int pgardens, pboss, ptown, pacademy, pcitadel;
  417. int loopseta = 0;
  418.  
  419. int sfx[21];
  420.  
  421. // room locks
  422. int roomlocks[201], saidlocked, canusekey, locktype, roomtounlock, saidjammed;
  423. // set to 1 for normal key, set to 2 for master, set to 0 if unlocked
  424.  
  425. // dialog
  426. int dialogflags[1000];
  427.  
  428. // ysort
  429. int ysort[2401], lasty, firsty;
  430.  
  431. int pmenu;
  432.  
  433. #undef main
  434. int main()
  435. {
  436.     sys_initialize();
  437.     game_showlogos();
  438.     game_main();
  439.  
  440.     return 0;
  441. }
  442.  
  443. // element tile locations
  444. int elementmap[15][20] = {
  445.     {  2, 2, 2, 2,-1,-1,-1, 2, 2, 2, 2, 2, 2,-1,-1,-1,-1,-1,-1,-1 },
  446.     {  2,-1,-1,-1,-1,-1,-1, 2, 2, 2, 2, 2, 2,-1,-1,-1,-1,-1,-1,-1 },
  447.     {  2,-1, 2, 2,-1,-1,-1, 2, 2, 2, 2, 2, 2,-1,-1,-1,-1,-1,-1,-1 },
  448.     {  2,-1, 2,-1, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 },
  449.     {  2, 2, 2, 2, 2,-1,-1,-1, 2,-1,-1, 2,-1,-1,-1,-1,-1,-1,-1,-1 },
  450.     { -1,-1,-1,-1, 2,-1, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 },
  451.     { -1,-1,-1,-1,-1, 0, 0, 2, 2, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 },
  452.     { -1,-1,-1,-1,-1, 2, 2, 2, 2, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 },
  453.     { -1,-1,-1,-1,-1, 2, 2, 2, 2, 2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 },
  454.     { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 },
  455.     { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 },
  456.     { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 },
  457.     { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 },
  458.     { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 },
  459.     { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 }
  460. };
  461.  
  462. char *story[38] = {
  463.     "Ever since I was a child",
  464.     "I remember being told the",
  465.     "Legend of the Griffon Knights,",
  466.     "who rid the world of the",
  467.     "Dragon Empire.  These great",
  468.     "heroes inspired us to become",
  469.     "knights as well.",
  470.     " ",
  471.     "Now, 500 years after the war",
  472.     "ended, the Dragons have",
  473.     "returned.  Cities are falling",
  474.     "from the lack of knights to",
  475.     "protect them.",
  476.     " ",
  477.     "We never saw it coming.",
  478.     " ",
  479.     "And now, here I am, making",
  480.     "my way into the lower town",
  481.     "of Fidelis, a small city on",
  482.     "the main continent. The rest",
  483.     "of my men have died over",
  484.     "the last couple days from",
  485.     "aerial attacks.",
  486.     " ",
  487.     "We believed we could find",
  488.     "shelter here, only to find",
  489.     "every last griffon dead,",
  490.     "the town burned to the ground,",
  491.     "and transformed into a garrison",
  492.     "for the Dragon forces.",
  493.     " ",
  494.     "In these dark times, I try to",
  495.     "draw strength from the stories",
  496.     "of those knights that risked",
  497.     "everything to protect their homeland,",
  498.     " ",
  499.     "and hope that I can die",
  500.     "with that honor as well."
  501. };
  502.  
  503. char *story2[27] = {
  504.     "After the fall of Margrave Gradius,",
  505.     "All the dragons, struck with panic,",
  506.     "evacuated the city immediately.",
  507.     " ",
  508.     "It\'s funny how without a leader",
  509.     "everyone is so weak.",
  510.     " ",
  511.     " ",
  512.     "But yet another leader will rise,",
  513.     "and another city will fall.",
  514.     " ",
  515.     " ",
  516.     "I should return home to Asherton",
  517.     "It\'s time to leave this place",
  518.     "and cleanse this blood stained",
  519.     "life of mine.",
  520.     " ",
  521.     "No one should have to see as much",
  522.     "death as I have.",
  523.     " ",
  524.     " ",
  525.     "Before, I said that I wanted",
  526.     "to die an honorable death.",
  527.     " ",
  528.     "Now I say that I have lived an",
  529.     "honorable life,",
  530.     "and I am free to die as I please."
  531. };
  532.  
  533. // map in inventory menu
  534. int invmap[4][7][13] = {
  535.     // map 0
  536.     {
  537.         {0,0,0,0,0,0,0,0,0,0,0,0,0},
  538.         {0,0,0,0,0,0,0,0,0,0,0,0,0},
  539.         {0,0,0,0,0,43,44,45,46,0,0,0,0},
  540.         {0,0,0,0,0,42,0,0,0,0,0,0,0},
  541.         {0,0,0,0,3,2,0,0,0,0,0,0,0},
  542.         {0,0,0,0,4,5,0,0,0,0,0,0,0},
  543.         {0,0,0,0,0,0,0,0,0,0,0,0,0}
  544.     },
  545.     // map 1
  546.     {
  547.         {0,0,0,0,0,0,0,0,0,0,0,0,0},
  548.         {0,0,0,24,0,0,0,0,0,0,0,0,0},
  549.         {0,0,19,20,21,22,0,0,0,27,0,0,0},
  550.         {0,0,16,17,18,0,0,0,29,30,31,0,0},
  551.         {0,0,12,0,13,14,0,32,33,34,35,36,0},
  552.         {0,8,7,6,9,10,0,37,38,39,40,41,0},
  553.         {0,0,0,0,0,0,0,0,0,0,0,0,0}
  554.     },
  555.     // map 2
  556.     {
  557.         {0,0,0,0,0,0,67,0,0,0,0,0,0},
  558.         {0,0,0,0,0,0,66,0,0,0,0,0,0},
  559.         {0,0,0,0,0,63,64,65,0,0,0,0,0},
  560.         {0,0,0,0,58,59,60,61,62,0,0,0,0},
  561.         {0,0,0,0,0,55,56,57,0,0,0,0,0},
  562.         {0,0,0,0,50,51,52,53,54,0,0,0,0},
  563.         {0,0,0,0,0,48,47,49,0,0,0,0,0}
  564.     },
  565.  
  566.     // map 3
  567.     {
  568.         {0,0,0,0,0,0,0,0,0,0,0,0,0},
  569.         {0,0,0,82,0,0,0,0,0,0,0,0,0},
  570.         {0,0,0,79,80,81,0,74,72,0,0,0,0},
  571.         {0,0,0,78,0,0,0,73,70,69,68,0,0},
  572.         {0,0,77,76,75,0,0,0,71,0,0,0,0},
  573.         {0,0,0,0,0,0,0,0,0,0,0,0,0},
  574.         {0,0,0,0,0,0,0,0,0,0,0,0,0}
  575.     }
  576. };
  577.  
  578. // CODE GOES HERE -------------------------------------------------------------
  579.  
  580. // copypaste from hRnd_CRT()
  581. static float RND()
  582. {
  583.     /* return between 0 and 1 (but never 1) */
  584.     return (float)rand() * (1.0 / ((float)RAND_MAX + 1.0));
  585. }
  586.  
  587. void game_addFloatIcon(int ico, float xloc, float yloc)
  588. {
  589.     int i = 0;
  590.     do {
  591.         if(floaticon[i][0] == 0) {
  592.             floaticon[i][0] = 32;
  593.             floaticon[i][1] = xloc;
  594.             floaticon[i][2] = yloc;
  595.             floaticon[i][3] = ico;
  596.             return;
  597.         }
  598.         i++;
  599.         if(i == MAXFLOAT+1) break;
  600.     } while(1);
  601. }
  602.  
  603. void game_addFloatText(char *stri, float xloc, float yloc, int col)
  604. {
  605.     int i = 0;
  606.     do {
  607.         if(floattext[i][0] == 0) {
  608.             floattext[i][0] = 32;
  609.             floattext[i][1] = xloc;
  610.             floattext[i][2] = yloc;
  611.             floattext[i][3] = col;
  612.             strcpy(floatstri[i], stri);
  613.             return;
  614.         }
  615.         i++;
  616.         if(i == MAXFLOAT+1) break;
  617.     } while(1);
  618. }
  619.  
  620. void game_attack()
  621. {
  622.     float npx, npy;
  623.  
  624.     npx = player.px + 12;
  625.     npy = player.py + 20;
  626.  
  627.     int lx = (int)npx / 16; //(int)npx / 16; //(npx - (npx % 16)) / 16;
  628.     int ly = (int)npy / 16; //(int)npy / 16; //(npy - (npy % 16)) / 16;
  629.  
  630.     // if facing up
  631.     if(player.walkdir == 0) {
  632.         if(ly > 0) {
  633.             int o2 = 0; // ??
  634.             int o = objmap[lx][ly - 1];
  635.             if(ly > 1 && curmap == 58) o2 = objmap[lx][ly - 2];
  636.             if(ly > 1 && curmap == 54) o2 = objmap[lx][ly - 2];
  637.  
  638.             // cst
  639.             if((objectinfo[o][4] == 1 && (o == 0 || o > 4)) || (objectinfo[o2][4] == 0 && o2 == 10)) {
  640.                 if(o2 == 10) o = 10;
  641.  
  642.                 int oscript = objectinfo[o][5];
  643.                 if(oscript == 0 && inventory[0] < 9) {
  644.                     inventory[0] = inventory[0] + 1;
  645.                     if(inventory[0] > 9) inventory[0] = 9;
  646.                     game_addFloatIcon(6, lx * 16, (ly - 1) * 16);
  647.  
  648.                     objmapf[curmap][lx][ly - 1] = 1;
  649.  
  650.                     if(menabled == 1 && opeffects == 1) {
  651.                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndpowerup))
  652.                         //FSOUND_setVolume(snd, opeffectsvol)
  653.                     }
  654.  
  655.                     if(objectinfo[o][4] == 1) objmap[lx][ly - 1] = 3;
  656.  
  657.                     game_eventtext("Found Flask!");
  658.                     itemticks = ticks + 215;
  659.                     return;
  660.                 }
  661.  
  662.                 if(oscript == 0 && inventory[0] == 9) {
  663.                     if(menabled == 1 && opeffects == 1) {
  664.                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndchest))
  665.                         //FSOUND_setVolume(snd, opeffectsvol)
  666.                     }
  667.  
  668.                     game_eventtext("Cannot Carry any more Flasks!");
  669.                     itemticks = ticks + 215;
  670.                     return;
  671.                 }
  672.  
  673.                 if(oscript == 2) {
  674.                     inventory[4] = inventory[4] + 1;
  675.  
  676.                     game_addFloatIcon(14, lx * 16, (ly - 1) * 16);
  677.  
  678.                     itemticks = ticks + 215;
  679.  
  680.                     if(curmap == 34) scriptflag[2][0] = 2;
  681.                     if(curmap == 62) scriptflag[8][0] = 2;
  682.                     if(curmap == 81) scriptflag[13][0] = 2;
  683.  
  684.                     if(menabled == 1 && opeffects == 1) {
  685.                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndpowerup))
  686.                         //FSOUND_setVolume(snd, opeffectsvol)
  687.                     }
  688.  
  689.                     if(objectinfo[o][4] == 1) objmap[lx][ly - 1] = 3;
  690.                     game_eventtext("Found the Temple Key!");
  691.                     return;
  692.                 }
  693.  
  694.                 if(oscript == 3) {
  695.                     player.foundcrystal = 1;
  696.                     player.crystalcharge = 0;
  697.  
  698.                     game_addFloatIcon(7, lx * 16, (ly - 1) * 16);
  699.  
  700.                     if(menabled == 1 && opeffects == 1) {
  701.                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndpowerup))
  702.                         //FSOUND_setVolume(snd, opeffectsvol)
  703.                     }
  704.  
  705.                     if(objectinfo[o][4] == 1) objmap[lx][ly - 1] = 3;
  706.  
  707.                     game_eventtext("Found the Infinite Crystal!");
  708.                     itemticks = ticks + 215;
  709.                     return;
  710.                 }
  711.  
  712.                 if(oscript == 4 && player.shield == 1) {
  713.                     player.shield = 2;
  714.  
  715.                     game_addFloatIcon(4, lx * 16, (ly - 1) * 16);
  716.  
  717.                     itemticks = ticks + 215;
  718.  
  719.                     if(menabled == 1 && opeffects == 1) {
  720.                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndpowerup))
  721.                         //FSOUND_setVolume(snd, opeffectsvol)
  722.                     }
  723.  
  724.                     if(objectinfo[o][4] == 1) objmap[lx][ly - 1] = 3;
  725.  
  726.                     game_eventtext("Found the Obsidian Shield!");
  727.                     objmapf[4][1][2] = 1;
  728.                     return;
  729.                 }
  730.  
  731.                 if(oscript == 5 && player.sword == 1) {
  732.                     player.sword = 2;
  733.  
  734.                     game_addFloatIcon(3, lx * 16, (ly - 1) * 16);
  735.  
  736.                     itemticks = ticks + 215;
  737.  
  738.                     if(menabled == 1 && opeffects == 1) {
  739.                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndpowerup))
  740.                         //FSOUND_setVolume(snd, opeffectsvol)
  741.                     }
  742.  
  743.                     if(objectinfo[o][4] == 1) objmap[lx][ly - 1] = 3;
  744.                     game_eventtext("Found the Fidelis Sword!");
  745.                     return;
  746.                 }
  747.  
  748.                 if(oscript == 6) {
  749.                     if(inventory[3] < 9) {
  750.                         inventory[3] = inventory[3] + 1;
  751.  
  752.                         for(int s = 20; s <= 23; s++) {
  753.                             if(scriptflag[s][0] == 1) {
  754.                                 scriptflag[s][0] = 2;
  755.                             }
  756.                         }
  757.  
  758.                         if(menabled == 1 && opeffects == 1) {
  759.                             //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndpowerup))
  760.                             //FSOUND_setVolume(snd, opeffectsvol)
  761.                         }
  762.  
  763.                         objmapf[curmap][lx][ly - 1] = 1;
  764.  
  765.                         if(objectinfo[o][4] == 1) objmap[lx][ly - 1] = 3;
  766.  
  767.                         game_eventtext("Found Key");
  768.                         game_addFloatIcon(16, lx * 16, (ly - 1) * 16);
  769.                     } else {
  770.                         if(menabled == 1 && opeffects == 1) {
  771.                             //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndchest))
  772.                             //FSOUND_setVolume(snd, opeffectsvol)
  773.                         }
  774.  
  775.                         game_eventtext("Cannot Carry Any More Keys");
  776.                     }
  777.                 }
  778.  
  779.                 if(oscript == 7 && inventory[1] < 9) {
  780.                     inventory[1] = inventory[1] + 1;
  781.                     if(inventory[1] > 9) inventory[1] = 9;
  782.                     game_addFloatIcon(12, lx * 16, (ly - 1) * 16);
  783.  
  784.                     objmapf[curmap][lx][ly - 1] = 1;
  785.  
  786.                     if(menabled == 1 && opeffects == 1) {
  787.                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndpowerup))
  788.                         //FSOUND_setVolume(snd, opeffectsvol)
  789.                     }
  790.  
  791.                     if(objectinfo[o][4] == 1) objmap[lx][ly - 1] = 3;
  792.  
  793.                     game_eventtext("Found Mega Flask!");
  794.                     itemticks = ticks + 215;
  795.                     return;
  796.                 }
  797.  
  798.                 if(oscript == 7 && inventory[1] == 9) {
  799.                     if(menabled == 1 && opeffects == 1) {
  800.                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndchest))
  801.                         //FSOUND_setVolume(snd, opeffectsvol)
  802.                     }
  803.  
  804.                     game_eventtext("Cannot Carry any more Mega Flasks!");
  805.                     itemticks = ticks + 215;
  806.                     return;
  807.                 }
  808.  
  809.                 if(oscript == 10 && inventory[1] < 9) {
  810.                     inventory[1] = inventory[1] + 1;
  811.                     if(inventory[1] > 9) inventory[1] = 9;
  812.                     game_addFloatIcon(12, lx * 16, (ly - 1) * 16);
  813.  
  814.                     objmapf[curmap][lx][ly - 1] = 1;
  815.  
  816.                     if(menabled == 1 && opeffects == 1) {
  817.                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndpowerup))
  818.                         //FSOUND_setVolume(snd, opeffectsvol)
  819.                     }
  820.  
  821.                     if(objectinfo[o][4] == 1) objmap[lx][ly - 1] = 3;
  822.  
  823.                     game_eventtext("Found Mega Flask!");
  824.                     itemticks = ticks + 215;
  825.                     return;
  826.                 }
  827.  
  828.                 if(oscript == 10 && inventory[1] == 9) {
  829.                     if(menabled == 1 && opeffects == 1) {
  830.                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndchest))
  831.                         //FSOUND_setVolume(snd, opeffectsvol)
  832.                     }
  833.  
  834.                     game_eventtext("Cannot Carry any more Mega Flasks!");
  835.                     itemticks = ticks + 215;
  836.                     return;
  837.                 }
  838.  
  839.                 if(oscript == 11 && inventory[2] < 9) {
  840.                     inventory[2] = inventory[2] + 1;
  841.                     if(inventory[2] > 9) inventory[2] = 9;
  842.                     game_addFloatIcon(17, lx * 16, (ly - 1) * 16);
  843.  
  844.                     objmapf[curmap][lx][ly - 1] = 1;
  845.  
  846.                     if(menabled == 1 && opeffects == 1) {
  847.                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndpowerup))
  848.                         //FSOUND_setVolume(snd, opeffectsvol)
  849.                     }
  850.  
  851.                     if(objectinfo[o][4] == 1) objmap[lx][ly - 1] = 3;
  852.  
  853.                     game_eventtext("Found Lightning Bomb!");
  854.                     itemticks = ticks + 215;
  855.                     return;
  856.                 }
  857.  
  858.                 if(oscript == 11 && inventory[2] == 9) {
  859.                     if(menabled == 1 && opeffects == 1) {
  860.                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndchest))
  861.                         //FSOUND_setVolume(snd, opeffectsvol)
  862.                     }
  863.  
  864.                     game_eventtext("Cannot Carry any more Lightning Bombs!");
  865.                     itemticks = ticks + 215;
  866.                     return;
  867.                 }
  868.  
  869.                 if(oscript == 12 && player.armour == 1) {
  870.                     player.armour = 2;
  871.  
  872.                     game_addFloatIcon(5, lx * 16, (ly - 1) * 16);
  873.  
  874.                     if(menabled == 1 && opeffects == 1) {
  875.                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndpowerup))
  876.                         //FSOUND_setVolume(snd, opeffectsvol)
  877.                     }
  878.  
  879.                     if(objectinfo[o][4] == 1) objmap[lx][ly - 1] = 3;
  880.  
  881.                     game_eventtext("Found the Fidelis Mail!");
  882.                     itemticks = ticks + 215;
  883.                     return;
  884.                 }
  885.  
  886.                 if(oscript == 60) {
  887.                     if(curmap == 58 && scriptflag[60][0] == 0) {
  888.                         scriptflag[60][0] = 1;
  889.  
  890.                         if(menabled == 1 && opeffects == 1) {
  891.                             //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndlever))
  892.                             //FSOUND_setVolume(snd, opeffectsvol)
  893.                         }
  894.  
  895.                     } else if(curmap == 58 && scriptflag[60][0] > 0) {
  896.                         if(menabled == 1 && opeffects == 1) {
  897.                             //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(snddoor))
  898.                             //FSOUND_setVolume(snd, opeffectsvol)
  899.                         }
  900.  
  901.                         game_eventtext("It's stuck!");
  902.                     }
  903.  
  904.                     if(curmap == 54 && scriptflag[60][0] == 1) {
  905.                         if(menabled == 1 && opeffects == 1) {
  906.                             //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndlever))
  907.                             //FSOUND_setVolume(snd, opeffectsvol)
  908.                         }
  909.  
  910.                         scriptflag[60][0] = 2;
  911.                     } else if(curmap == 54 && scriptflag[60][0] > 1) {
  912.                         if(menabled == 1 && opeffects == 1) {
  913.                             //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(snddoor))
  914.                             //FSOUND_setVolume(snd, opeffectsvol)
  915.                         }
  916.  
  917.                         game_eventtext("It's stuck!");
  918.                     }
  919.  
  920.                 }
  921.  
  922.                 if(oscript == 15 && player.sword < 3) {
  923.                     player.sword = 3;
  924.  
  925.                     game_addFloatIcon(18, lx * 16, (ly - 1) * 16);
  926.  
  927.                     itemticks = ticks + 215;
  928.  
  929.                     if(menabled == 1 && opeffects == 1) {
  930.                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndpowerup))
  931.                         //FSOUND_setVolume(snd, opeffectsvol)
  932.                     }
  933.  
  934.                     if(objectinfo[o][4] == 1) objmap[lx][ly - 1] = 3;
  935.                     game_eventtext("Found the Blood Sword!");
  936.                     objmapf[4][1][2] = 1;
  937.                     return;
  938.                 }
  939.  
  940.                 if(oscript == 16 && player.shield < 3) {
  941.                     player.shield = 3;
  942.                     game_addFloatIcon(19, lx * 16, (ly - 1) * 16);
  943.                     itemticks = ticks + 215;
  944.  
  945.                     if(menabled == 1 && opeffects == 1) {
  946.                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndpowerup))
  947.                         //FSOUND_setVolume(snd, opeffectsvol)
  948.                     }
  949.  
  950.                     if(objectinfo[o][4] == 1) objmap[lx][ly - 1] = 3;
  951.                     game_eventtext("Found the Entropy Shield!");
  952.                     objmapf[4][1][2] = 1;
  953.                     return;
  954.                 }
  955.  
  956.                 if(oscript == 17 && player.armour < 3) {
  957.                     player.armour = 3;
  958.                     game_addFloatIcon(20, lx * 16, (ly - 1) * 16);
  959.                     itemticks = ticks + 215;
  960.  
  961.                     if(menabled == 1 && opeffects == 1) {
  962.                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndpowerup))
  963.                         //FSOUND_setVolume(snd, opeffectsvol)
  964.                     }
  965.  
  966.                     if(objectinfo[o][4] == 1) objmap[lx][ly - 1] = 3;
  967.                     game_eventtext("Found the Rubyscale Armour!");
  968.                     objmapf[4][1][2] = 1;
  969.                     return;
  970.                 }
  971.  
  972.             }
  973.         }
  974.     }
  975.  
  976.     attacking = 1;
  977.     player.attackframe = 0;
  978.     movingup = 0;
  979.     movingdown = 0;
  980.     movingleft = 0;
  981.     movingright = 0;
  982.  
  983.     for(int i = 0; i <= 15; i++) {
  984.         for(int a = 0; a <= 3; a++) {
  985.             playerattackofs[a][i][2] = 0;
  986.         }
  987.     }
  988. }
  989.  
  990. void game_castspell(int spellnum, float homex, float homey, float enemyx, float enemyy, int damagewho)
  991. {
  992.     // spellnum 7 = sprite 6 spitfire
  993.     int i = 0;
  994.     do {
  995.         if(spellinfo[i].frame == 0) {
  996.             spellinfo[i].homex = homex;
  997.             spellinfo[i].homey = homey;
  998.             spellinfo[i].enemyx = enemyx;
  999.             spellinfo[i].enemyy = enemyy;
  1000.             spellinfo[i].spellnum = spellnum;
  1001.             int dw = 0;
  1002.             int npc = 0;
  1003.             if(damagewho > 0) {
  1004.                 dw = 1;
  1005.                 npc = damagewho;
  1006.             }
  1007.  
  1008.             spellinfo[i].damagewho = dw;
  1009.             spellinfo[i].npc = npc;
  1010.  
  1011.             spellinfo[i].frame = 32;
  1012.             if(damagewho == 0) {
  1013.                 spellinfo[i].strength = player.spellstrength / 100;
  1014.                 if(player.spellstrength == 100) spellinfo[i].strength = 1.5;
  1015.             }
  1016.  
  1017.             // set earthslide vars
  1018.             if(spellnum == 2) {
  1019.                 for(int f = 0; f <= 8; f++) {
  1020.                     spellinfo[i].rocky[f] = 0;
  1021.                     spellinfo[i].rockimg[f] = (int)(RND() * 4);
  1022.                     spellinfo[i].rockdeflect[f] = ((int)(RND() * 128) - 64) * 1.5;
  1023.                 }
  1024.             }
  1025.  
  1026.             // set fire vars
  1027.             if(spellnum == 3) {
  1028.                 for(int f = 0; f <= 4; f++) {
  1029.                     spellinfo[i].legalive[f] = 32;
  1030.                 }
  1031.             }
  1032.  
  1033.  
  1034.             // room fireball vars
  1035.             if(spellnum == 6) {
  1036.                 int nballs = 0;
  1037.                 for(int x = 0; x <= 19; x++) {
  1038.                     for(int y = 0; y <= 14; y++) {
  1039.                         if((objmap[x][y] == 1 || objmap[x][y] == 2) && nballs < 5 && (int)(RND() * 4) == 0) {
  1040.                             int ax = x * 16;
  1041.                             int ay = y * 16;
  1042.                             /*int bx = player.px + 4; // useless code ??
  1043.                             int by = player.py + 4;
  1044.                             float d = sqr((bx - ax) ^ 2 + (by - ay) ^ 2);
  1045.  
  1046.                             float tx = (bx - ax) / d;
  1047.                             float ty = (by - ay) / d;*/
  1048.  
  1049.                             spellinfo[i].fireballs[nballs][0] = ax;
  1050.                             spellinfo[i].fireballs[nballs][1] = ay;
  1051.                             spellinfo[i].fireballs[nballs][2] = 0;
  1052.                             spellinfo[i].fireballs[nballs][3] = 0;
  1053.  
  1054.                             spellinfo[i].ballon[nballs] = 1;
  1055.                             nballs = nballs + 1;
  1056.                         }
  1057.                     }
  1058.                 }
  1059.                 spellinfo[i].nfballs = nballs;
  1060.             }
  1061.  
  1062.             if(menabled == 1 && opeffects == 1) {
  1063.                 if(spellnum == 1) {
  1064.                     //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndthrow))
  1065.                     //FSOUND_setVolume(snd, opeffectsvol)
  1066.                 } else if(spellnum == 5) {
  1067.                     //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndcrystal))
  1068.                     //FSOUND_setVolume(snd, opeffectsvol)
  1069.                 } else if(spellnum == 8 || spellnum == 9) {
  1070.                     //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndlightning))
  1071.                     //FSOUND_setVolume(snd, opeffectsvol)
  1072.                 }
  1073.             }
  1074.  
  1075.             return;
  1076.         }
  1077.  
  1078.         i = i + 1;
  1079.         if(i == MAXSPELL+1) break;
  1080.     } while(1);
  1081. }
  1082.  
  1083. void game_checkhit()
  1084. {
  1085.     /*unsigned int *temp, bgc;*/
  1086.     float opx, opy, npx, npy;
  1087.     float damage;
  1088.  
  1089.     if(attacking == 1) {
  1090.         for(int i = 1; i <= lastnpc; i++) {
  1091.             if(npcinfo[i].hp > 0 && npcinfo[i].pause < ticks && (int)(RND() * 2) == 0) {
  1092.                 npx = npcinfo[i].x;
  1093.                 npy = npcinfo[i].y;
  1094.  
  1095.                 opx = npx;
  1096.                 opy = npy;
  1097.  
  1098.                 float xdif = player.px - npx;
  1099.                 float ydif = player.py - npy;
  1100.  
  1101.                 float ps = player.sword;
  1102.                 if(ps > 1) ps = ps * 0.75;
  1103.                     damage = (float)player.sworddamage * (1.0 + RND() * 1.0) * player.attackstrength / 100.0 * ps;
  1104.                     if(player.attackstrength == 100) damage = damage * 1.5;
  1105.  
  1106.                     int hit = 0;
  1107.                     if(player.walkdir == 0) {
  1108.                         if(abs(xdif) <= 8 && ydif >= 0 && ydif < 8) hit = 1;
  1109.                     } else if(player.walkdir == 1) {
  1110.                         if(abs(xdif) <= 8 && ydif <= 0 && ydif > -8) hit = 1;
  1111.                     } else if(player.walkdir == 2) {
  1112.                         if(abs(ydif) <= 8 && xdif >= -8 && xdif < 8) hit = 1;
  1113.                     } else if(player.walkdir == 3) {
  1114.                         if(abs(ydif) <= 8 && xdif <= 8 && xdif > -8) hit = 1;
  1115.                     }
  1116.  
  1117.                     if(hit == 1) {
  1118.                         if(menabled == 1 && opeffects == 1) {
  1119.                             //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndswordhit))
  1120.                             //FSOUND_setVolume(snd, opeffectsvol)
  1121.                         }
  1122.  
  1123.                         game_damagenpc(i, damage, 0);
  1124.                     }
  1125.             }
  1126.         }
  1127.     }
  1128. }
  1129.  
  1130. void game_checkinputs()
  1131. {
  1132.     int ntickdelay;
  1133.     //JoyGetPos (0, &joystickinfo)
  1134.  
  1135.     ntickdelay = 175;
  1136.  
  1137.     SDL_PollEvent(&event);
  1138.     keys = SDL_GetKeyState(NULL);
  1139.  
  1140.     nposts = 0;
  1141.  
  1142.     for(int i = 0; i <= 20; i++) {
  1143.         postinfo[i][0] = 0;
  1144.         postinfo[i][1] = 0;
  1145.     }
  1146.  
  1147.     for(int x = 0; x <= 19; x++) {
  1148.         for(int y = 0; y <= 14; y++) {
  1149.             int o = objmap[x][y];
  1150.             if(objectinfo[o][4] == 3) {
  1151.                 postinfo[nposts][0] = x * 16;
  1152.                 postinfo[nposts][1] = y * 16;
  1153.                 nposts = nposts + 1;
  1154.             }
  1155.         }
  1156.     }
  1157.  
  1158.     if(attacking == 1 || (forcepause == 1 && itemselon == 0)) return;
  1159.  
  1160.     if(event.type == SDL_KEYDOWN) {
  1161.         switch(event.key.keysym.sym) {
  1162.         case SDLK_ESCAPE:
  1163.             if(itemticks < ticks) game_title(1);
  1164.             break;
  1165.         case SDLK_RETURN:
  1166.             if(keys[SDLK_LALT] || keys[SDLK_RALT]) {
  1167.                 if(fullscreen && SDL_FULLSCREEN) {
  1168.                     fullscreen = HWACCEL | SDL_SWSURFACE;
  1169.                 } else {
  1170.                     fullscreen = SDL_FULLSCREEN | HWACCEL | HWSURFACE;
  1171.                 }
  1172.  
  1173.                 video = SDL_SetVideoMode(SCR_WIDTH, SCR_HEIGHT, SCR_BITS, fullscreen);
  1174.                 SDL_UpdateRect(video, 0, 0, SCR_WIDTH, SCR_HEIGHT);
  1175.             }
  1176.             break;
  1177.  
  1178.         case SDLK_SPACE:
  1179.             if(itemselon == 0 && itemticks < ticks) game_attack();
  1180.  
  1181.             //SDL_SaveBMP(video, "shot.bmp");
  1182.  
  1183.             if(itemselon == 1 && itemticks < ticks) {
  1184.                 if(curitem == 0 && inventory[0] > 0) {
  1185.                     itemticks = ticks + ntickdelay;
  1186.  
  1187.                     int heal = 50;
  1188.                     int maxh = player.maxhp - player.hp;
  1189.  
  1190.                     if(heal > maxh) heal = maxh;
  1191.  
  1192.                     player.hp = player.hp + heal;
  1193.  
  1194.                     //t$ = "+" + ltrim$(rtrim$(str$(heal)))
  1195.                     char text[256];
  1196.                     sprintf(text, "+%i", heal);
  1197.                     game_addFloatText(text, player.px + 16 - 4 * strlen(text), player.py + 16, 5);
  1198.  
  1199.                     inventory[0] = inventory[0] - 1;
  1200.  
  1201.                     if(menabled == 1 && opeffects == 1) {
  1202.                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndpowerup))
  1203.                         //FSOUND_setVolume(snd, opeffectsvol)
  1204.                     }
  1205.  
  1206.                     itemselon = 0;
  1207.                     forcepause = 0;
  1208.                 }
  1209.  
  1210.                 if(curitem == 1 && inventory[1] > 0) {
  1211.                     itemticks = ticks + ntickdelay;
  1212.  
  1213.                     int heal = 200;
  1214.                     int maxh = player.maxhp - player.hp;
  1215.  
  1216.                     if(heal > maxh) heal = maxh;
  1217.  
  1218.                     player.hp = player.hp + heal;
  1219.  
  1220.                     //t$ = "+" + ltrim$(rtrim$(str$(heal)))
  1221.                     char text[256];
  1222.                     sprintf(text, "+%i", heal);
  1223.                     game_addFloatText(text, player.px + 16 - 4 * strlen(text), player.py + 16, 5);
  1224.  
  1225.                     inventory[1] = inventory[1] - 1;
  1226.  
  1227.                     if(menabled == 1 && opeffects == 1) {
  1228.                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndpowerup))
  1229.                         //FSOUND_setVolume(snd, opeffectsvol)
  1230.                     }
  1231.  
  1232.                     itemselon = 0;
  1233.                     forcepause = 0;
  1234.  
  1235.                 }
  1236.  
  1237.                 if(curitem == 2 && inventory[2] > 0) {
  1238.                     game_castspell(8, player.px, player.py, npcinfo[curenemy].x, npcinfo[curenemy].y, 0);
  1239.  
  1240.                     forcepause = 1;
  1241.  
  1242.                     inventory[2] = inventory[2] - 1;
  1243.  
  1244.                     itemticks = ticks + ntickdelay;
  1245.                     selenemyon = 0;
  1246.                     itemselon = 0;
  1247.  
  1248.                 }
  1249.  
  1250.                 if(curitem == 3 && inventory[3] > 0 && canusekey == 1 && locktype == 1) {
  1251.                     roomlocks[roomtounlock] = 0;
  1252.                     game_eventtext("UnLocked!");
  1253.  
  1254.                     inventory[3] = inventory[3] - 1;
  1255.  
  1256.                     itemticks = ticks + ntickdelay;
  1257.                     selenemyon = 0;
  1258.                     itemselon = 0;
  1259.                     return;
  1260.                 }
  1261.  
  1262.                 if(curitem == 4 && inventory[4] > 0 && canusekey == 1 && locktype == 2) {
  1263.                     roomlocks[roomtounlock] = 0;
  1264.                     game_eventtext("UnLocked!");
  1265.  
  1266.                     inventory[4] = inventory[4] - 1;
  1267.  
  1268.                     itemticks = ticks + ntickdelay;
  1269.                     selenemyon = 0;
  1270.                     itemselon = 0;
  1271.                     return;
  1272.                 }
  1273.  
  1274.                 if(curitem == 5 && player.crystalcharge == 100) {
  1275.                     game_castspell(5, player.px, player.py, npcinfo[curenemy].x, npcinfo[curenemy].y, 0);
  1276.  
  1277.                     player.crystalcharge = 0;
  1278.  
  1279.                     forcepause = 1;
  1280.  
  1281.                     itemticks = ticks + ntickdelay;
  1282.                     selenemyon = 0;
  1283.                     itemselon = 0;
  1284.                 }
  1285.  
  1286.                 if(curitem > 5 && selenemyon == 1) {
  1287.                     if(curenemy <= lastnpc) {
  1288.                         game_castspell(curitem - 6, player.px, player.py, npcinfo[curenemy].x, npcinfo[curenemy].y, 0);
  1289.                     } else {
  1290.                         int pst = curenemy - lastnpc - 1;
  1291.                         game_castspell(curitem - 6, player.px, player.py, postinfo[pst][0], postinfo[pst][1], 0);
  1292.                     }
  1293.  
  1294.                     player.spellcharge[curitem - 6] = 0;
  1295.  
  1296.                     player.spellstrength = 0;
  1297.  
  1298.                     itemticks = ticks + ntickdelay;
  1299.                     selenemyon = 0;
  1300.                     itemselon = 0;
  1301.                     forcepause = 0;
  1302.                 }
  1303.  
  1304.                 if(curitem > 5 && selenemyon == 0 && itemselon == 1) {
  1305.                     if(player.spellcharge[curitem - 6] == 100) {
  1306.                         itemticks = ticks + ntickdelay;
  1307.  
  1308.                         selenemyon = 1;
  1309.  
  1310.                         int i = 0;
  1311.                         do {
  1312.                             if(npcinfo[i].hp > 0) {
  1313.                                 curenemy = i;
  1314.                                 goto __exit_do;
  1315.                             }
  1316.                             i = i + 1;
  1317.                             if(i == lastnpc + 1) {
  1318.                                 selenemyon = 0;
  1319.                                 goto __exit_do;
  1320.                             }
  1321.                         } while(1);
  1322.                     __exit_do:
  1323.  
  1324.                         if(nposts > 0 && selenemyon == 0) {
  1325.                             selenemyon = 1;
  1326.                             curenemy = lastnpc + 1;
  1327.                         }
  1328.                     }
  1329.  
  1330.                 }
  1331.             }
  1332.             break;
  1333.  
  1334.         case SDLK_LCTRL:
  1335.             if(itemticks < ticks) {
  1336.                 selenemyon = 0;
  1337.                 if(itemselon == 1) {
  1338.                     itemselon = 0;
  1339.                     itemticks = ticks + 220;
  1340.                     forcepause = 0;
  1341.                 } else {
  1342.                     itemselon = 1;
  1343.                     itemticks = ticks + 220;
  1344.                     forcepause = 1;
  1345.                     player.itemselshade = 0;
  1346.                 }
  1347.             }
  1348.             break;
  1349.  
  1350.         case SDLK_RCTRL:
  1351.             if(itemticks < ticks) {
  1352.                 selenemyon = 0;
  1353.                 if(itemselon == 1) {
  1354.                     itemselon = 0;
  1355.                     itemticks = ticks + 220;
  1356.                     forcepause = 0;
  1357.                 } else {
  1358.                     itemselon = 1;
  1359.                     itemticks = ticks + 220;
  1360.                     forcepause = 1;
  1361.                     player.itemselshade = 0;
  1362.                 }
  1363.             }
  1364.             break;
  1365.  
  1366.         default:
  1367.             ;
  1368.         }
  1369.     }
  1370.  
  1371.     if(itemselon == 0) {
  1372.         movingup = 0;
  1373.         movingdown = 0;
  1374.         movingleft = 0;
  1375.         movingright = 0;
  1376.         if(keys[SDLK_UP]) movingup = 1;
  1377.         if(keys[SDLK_DOWN]) movingdown = 1;
  1378.         if(keys[SDLK_LEFT]) movingleft = 1;
  1379.         if(keys[SDLK_RIGHT]) movingright = 1;
  1380.     } else {
  1381.         movingup = 0;
  1382.         movingdown = 0;
  1383.         movingleft = 0;
  1384.         movingright = 0;
  1385.  
  1386.         if(selenemyon == 1) {
  1387.             if(itemticks < ticks) {
  1388.                 if(keys[SDLK_LEFT]) {
  1389.                     int origin = curenemy;
  1390.                     do {
  1391.                         curenemy = curenemy - 1;
  1392.                         if(curenemy < 1) curenemy = lastnpc + nposts;
  1393.                         if(curenemy == origin) break;
  1394.                         if(curenemy <= lastnpc && npcinfo[curenemy].hp > 0) break;
  1395.                         if(curenemy > lastnpc) break;
  1396.                     } while(1);
  1397.                     itemticks = ticks + ntickdelay;
  1398.                 }
  1399.                 if(keys[SDLK_RIGHT]) {
  1400.                     int origin = curenemy;
  1401.                     do {
  1402.                         curenemy = curenemy + 1;
  1403.                         if(curenemy > lastnpc + nposts) curenemy = 1;
  1404.                         if(curenemy == origin) break;
  1405.                         if(curenemy <= lastnpc && npcinfo[curenemy].hp > 0) break;
  1406.                         if(curenemy > lastnpc) break;
  1407.                     } while(1);
  1408.                     itemticks = ticks + ntickdelay;
  1409.                 }
  1410.  
  1411.  
  1412.                 if(curenemy > lastnpc + nposts) curenemy = 1;
  1413.                 if(curenemy < 1) curenemy = lastnpc + nposts;
  1414.             }
  1415.         } else {
  1416.             if(itemticks < ticks) {
  1417.                 if(keys[SDLK_UP]) {
  1418.                     curitem = curitem - 1;
  1419.                     itemticks = ticks + ntickdelay;
  1420.                     if(curitem == 4) curitem = 9;
  1421.                     if(curitem == -1) curitem = 4;
  1422.                 }
  1423.                 if(keys[SDLK_DOWN]) {
  1424.                     curitem = curitem + 1;
  1425.                     itemticks = ticks + ntickdelay;
  1426.                     if(curitem == 5) curitem = 0;
  1427.                     if(curitem == 10) curitem = 5;
  1428.                 }
  1429.                 if(keys[SDLK_LEFT]) {
  1430.                     curitem = curitem - 5;
  1431.                     itemticks = ticks + ntickdelay;
  1432.                 }
  1433.                 if(keys[SDLK_RIGHT]) {
  1434.                     curitem = curitem + 5;
  1435.                     itemticks = ticks + ntickdelay;
  1436.                 }
  1437.  
  1438.                 if(curitem > 9) curitem = curitem - 10;
  1439.                 if(curitem < 0) curitem = curitem + 10;
  1440.             }
  1441.         }
  1442.     }
  1443. }
  1444.  
  1445. void game_checktrigger()
  1446. {
  1447.     int npx, npy, lx, ly;
  1448.  
  1449.     npx = player.px + 12;
  1450.     npy = player.py + 20;
  1451.  
  1452.     lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  1453.     ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  1454.  
  1455.     canusekey = 0;
  1456.  
  1457.     if(triggerloc[lx][ly] > -1) game_processtrigger(triggerloc[lx][ly]);
  1458. }
  1459.  
  1460. void game_configmenu()
  1461. {
  1462.     SDL_Surface *configwindow;
  1463.     int cursel, curselt, ofullscreen;
  1464.     int tickwait, keypause, ticks1;
  1465.  
  1466.     cursel = 0;
  1467.  
  1468.     ticks = SDL_GetTicks();
  1469.     tickwait = 100;
  1470.     keypause = ticks + tickwait;
  1471.  
  1472.     configwindow = SDL_DisplayFormat(videobuffer);
  1473.  
  1474.     configwindow = IMG_Load("art/configwindow.bmp");
  1475.     SDL_SetColorKey(configwindow, SDL_SRCCOLORKEY, SDL_MapRGB(configwindow->format, 255, 0, 255));
  1476.     SDL_SetAlpha(configwindow, SDL_SRCALPHA, 160);
  1477.  
  1478.     /*dim fil$(20)*/
  1479.  
  1480.     ticks1 = ticks;
  1481.     do {
  1482.         rc.x = 0;
  1483.         rc.y = 0;
  1484.  
  1485.         rc2.x = SCR_TOPX;
  1486.         rc2.y = SCR_TOPY;
  1487.         rc2.w = 320;
  1488.         rc2.h = 240;
  1489.  
  1490.         SDL_FillRect(videobuffer, NULL, 0);
  1491.  
  1492.         rcDest.x = 256 + 256 * cos(3.141592 / 180 * clouddeg * 40);
  1493.         rcDest.y = 192 + 192 * sin(3.141592 / 180 * clouddeg * 40);
  1494.         rcDest.w = 320;
  1495.         rcDest.h = 240;
  1496.  
  1497.         SDL_SetAlpha(cloudimg, SDL_SRCALPHA, 128);
  1498.         SDL_BlitSurface(cloudimg, &rcDest, videobuffer, NULL);
  1499.         SDL_SetAlpha(cloudimg, SDL_SRCALPHA, 64);
  1500.  
  1501.         rcDest.x = 256;
  1502.         rcDest.y = 192;
  1503.         rcDest.w = 320;
  1504.         rcDest.h = 240;
  1505.  
  1506.         SDL_SetAlpha(cloudimg, SDL_SRCALPHA, 128);
  1507.         SDL_BlitSurface(cloudimg, &rcDest, videobuffer, NULL);
  1508.         SDL_SetAlpha(cloudimg, SDL_SRCALPHA, 64);
  1509.  
  1510.         SDL_BlitSurface(configwindow, NULL, videobuffer, NULL);
  1511.  
  1512.         int sy = 38 + (240 - 38) / 2 - 88;
  1513.  
  1514.         for(int i = 0; i <= 21; i++) {
  1515.             char *vr[22] = {
  1516.                 "Resolution:", "",
  1517.                 "Bit Depth:", "", "", "",
  1518.                 "Start Fullscreen:", "", "",
  1519.                 "Music:", "", "",
  1520.                 "Sound Effects:", "", "",
  1521.                 "Music Volume:", "",
  1522.                 "Effects Volume:", "", "", "", ""
  1523.             };
  1524.             char *vl[22] = {
  1525.                 "320x240", "640x480",
  1526.                 "16", "24", "32", "",
  1527.                 "Yes", "No", "",
  1528.                 "On", "Off", "",
  1529.                 "On", "Off", "",
  1530.                 "[----------]", "",
  1531.                 "[----------]", "",
  1532.                 "Exit + Save", "",
  1533.                 "Exit"
  1534.             };
  1535.         /*
  1536.             lo = opmusicvol / 255 * 9
  1537.             if(lo < 0) lo = 0
  1538.             if(lo > 9) lo = 9
  1539.             la = lo
  1540.             lb = 9 - lo
  1541.  
  1542.             if(i = 15) vl$ = "[" + string$(la,"-") + "X" + string$(lb,"-") + "]"
  1543.  
  1544.             lo = opeffectsvol / 255 * 9
  1545.             if(lo < 0) lo = 0
  1546.             if(lo > 9) lo = 9
  1547.             la = lo
  1548.             lb = 9 - lo
  1549.  
  1550.             if(i = 17) vl$ = "[" + string$(la,"-") + "X" + string$(lb,"-") + "]"
  1551. */
  1552.             int cl = 3;
  1553.             if(i == 0 && SCR_WIDTH == 320) cl = 0;
  1554.             if(i == 1 && SCR_WIDTH == 640) cl = 0;
  1555.             if(i == 2 && SCR_BITS == 16) cl = 0;
  1556.             if(i == 3 && SCR_BITS == 24) cl = 0;
  1557.             if(i == 4 && SCR_BITS == 32) cl = 0;
  1558.             if(i == 6 && opfullscreen != 0) cl = 0;
  1559.             if(i == 7 && opfullscreen == 0) cl = 0;
  1560.             if(i == 9 && opmusic == 1) cl = 0;
  1561.             if(i == 10 && opmusic == 0) cl = 0;
  1562.             if(i == 12 && opeffects == 1) cl = 0;
  1563.             if(i == 13 && opeffects == 0) cl = 0;
  1564.  
  1565.             if(i > 18) cl = 0;
  1566.  
  1567.             sys_print(videobuffer, vr[i], 156 - 8 * strlen(vr[i]), sy + i * 8, 0);
  1568.             sys_print(videobuffer, vl[i], 164, sy + i * 8, cl);
  1569.         }
  1570.  
  1571.         //int y = 156;
  1572.         //int x = 160 - 9 * 4;
  1573.  
  1574.         curselt = cursel;
  1575.         if(cursel > 4) curselt = curselt + 1;
  1576.         if(cursel > 6) curselt = curselt + 1;
  1577.         if(cursel > 8) curselt = curselt + 1;
  1578.         if(cursel > 10) curselt = curselt + 1;
  1579.         if(cursel > 11) curselt = curselt + 1;
  1580.         if(cursel > 12) curselt = curselt + 1;
  1581.         if(cursel > 13) curselt = curselt + 1;
  1582.  
  1583.         rc.x = 148 + 3 * cos(3.14159 * 2 * itemyloc / 16.0);
  1584.         rc.y = sy + 8 * curselt - 4;
  1585.  
  1586.         SDL_BlitSurface(itemimg[15], NULL, videobuffer, &rc);
  1587.  
  1588.         rc.x = 0;
  1589.         rc.y = 0;
  1590.         rc.w = 320;
  1591.         rc.h = 240;
  1592.  
  1593.         float yy = 255.0;
  1594.         if(ticks < ticks1 + 1000) {
  1595.             yy = 255.0 * ((float)(ticks - ticks1) / 1000.0);
  1596.             if(yy < 0.0) yy = 0.0;
  1597.             if(yy > 255.0) yy = 255.0;
  1598.         }
  1599.  
  1600.         SDL_SetAlpha(videobuffer, SDL_SRCALPHA, (int)yy);
  1601.         SDL_BlitSurface(videobuffer, &rc, video, &rc2);
  1602.         SDL_SetAlpha(videobuffer, SDL_SRCALPHA, 255);
  1603.  
  1604.         SDL_Flip(video);
  1605.         SDL_PumpEvents();
  1606.  
  1607.         tickspassed = ticks;
  1608.         ticks = SDL_GetTicks();
  1609.  
  1610.         tickspassed = ticks - tickspassed;
  1611.         fpsr = (float)tickspassed / 24;
  1612.  
  1613.         fp = fp + 1;
  1614.         if(ticks > ticks) {
  1615.             ticks = ticks + 1000;
  1616.             fps = fp;
  1617.             fp = 0;
  1618.         }
  1619.  
  1620.         itemyloc = itemyloc + 0.75 * fpsr;
  1621.         while(itemyloc >= 16) itemyloc -= 16;
  1622.  
  1623.         if(keypause < ticks) {
  1624.             SDL_PollEvent(&event);
  1625.             keys = SDL_GetKeyState(NULL);
  1626.  
  1627.             if(event.type == SDL_KEYDOWN) {
  1628.                 keypause = ticks + tickwait;
  1629.  
  1630.                 if(keys[SDLK_ESCAPE]) break;
  1631.                 if(cursel == 11 || cursel == 12) {
  1632.                     //la = FSOUND_GetVolume (0)
  1633.                     //lb = FSOUND_GetVolume (1)
  1634.  
  1635.                     if(keys[SDLK_LEFT]) {
  1636.                         if(cursel == 11) {
  1637.                             opmusicvol = opmusicvol - 25;
  1638.                             if(opmusicvol < 0) opmusicvol = 0;
  1639.  
  1640.                             //FSOUND_SetVolume (musicchannel, opmusicvol)
  1641.                             //FSOUND_SetVolume (menuchannel, opmusicvol)
  1642.                         } else if(cursel == 12) {
  1643.                             opeffectsvol = opeffectsvol - 25;
  1644.                             if(opeffectsvol < 0) opeffectsvol = 0;
  1645.  
  1646.                             //FSOUND_SetVolume (FSOUND_ALL, opeffectsvol)
  1647.                             //FSOUND_SetVolume (musicchannel, opmusicvol)
  1648.                             //FSOUND_SetVolume (menuchannel, opmusicvol)
  1649.  
  1650.                             if(menabled == 1 && opeffects == 1) {
  1651.                                 //a = FSOUND_PlaySound(FSOUND_FREE, sfx(snddoor))
  1652.                                 //FSOUND_SetVolume (a, opeffectsvol)
  1653.                             }
  1654.                         }
  1655.                     }
  1656.                     if(keys[SDLK_RIGHT]) {
  1657.                         if(cursel == 11) {
  1658.                             opmusicvol = opmusicvol + 25;
  1659.                             if(opmusicvol > 255) opmusicvol = 255;
  1660.  
  1661.                             //FSOUND_SetVolume (musicchannel, opmusicvol)
  1662.                             //FSOUND_SetVolume (menuchannel, opmusicvol)
  1663.                         } else if(cursel == 12) {
  1664.                             opeffectsvol = opeffectsvol + 25;
  1665.                             if(opeffectsvol > 255) opeffectsvol = 255;
  1666.  
  1667.                             //FSOUND_SetVolume (FSOUND_ALL, opeffectsvol)
  1668.                             //FSOUND_SetVolume (musicchannel, opmusicvol)
  1669.                             //FSOUND_SetVolume (menuchannel, opmusicvol)
  1670.  
  1671.                             if(menabled == 1 && opeffects == 1) {
  1672.                                 //a = FSOUND_PlaySound(FSOUND_FREE, sfx(snddoor))
  1673.                                 //FSOUND_SetVolume (a, opeffectsvol)
  1674.                             }
  1675.                         }
  1676.                     }
  1677.                 }
  1678.  
  1679.                 if(keys[SDLK_UP]) cursel = cursel - 1;
  1680.                 if(keys[SDLK_DOWN]) cursel = cursel + 1;
  1681.                 //if(event.key.keysym.sym == SDLK_SPACE || event.key.keysym.sym == SDLK_RETURN) {
  1682.                 if(keys[SDLK_SPACE] || keys[SDLK_RETURN]) {
  1683.                     if(cursel == 0) {
  1684.                         fullscreen = opfullscreen | HWACCEL | HWSURFACE;
  1685.  
  1686.                         video = SDL_SetVideoMode(320, 240, SCR_BITS, fullscreen);
  1687.                         if(video == 0) {
  1688.                             video = SDL_SetVideoMode(SCR_WIDTH, SCR_HEIGHT, SCR_BITS, fullscreen);
  1689.                         } else {
  1690.                             SCR_WIDTH = 320;
  1691.                             SCR_HEIGHT = 240;
  1692.                             SCR_TOPX = 0;
  1693.                             SCR_TOPY = 0;
  1694.                         }
  1695.  
  1696.                         SDL_UpdateRect(video, 0, 0, SCR_WIDTH, SCR_HEIGHT);
  1697.                     }
  1698.                     if(cursel == 1) {
  1699.                         fullscreen = opfullscreen | HWACCEL | HWSURFACE;
  1700.  
  1701.                         video = SDL_SetVideoMode(640, 480, SCR_BITS, fullscreen);
  1702.                         if(video == 0) {
  1703.                             video = SDL_SetVideoMode(SCR_WIDTH, SCR_HEIGHT, SCR_BITS, fullscreen);
  1704.                         } else {
  1705.                             SCR_WIDTH = 640;
  1706.                             SCR_HEIGHT = 480;
  1707.                             SCR_TOPX = 160;
  1708.                             SCR_TOPY = 120;
  1709.                         }
  1710.  
  1711.                         SDL_UpdateRect(video, 0, 0, SCR_WIDTH, SCR_HEIGHT);
  1712.                     }
  1713.                     if(cursel == 2 || cursel == 3 || cursel == 4) {
  1714.                         fullscreen = opfullscreen | HWACCEL | HWSURFACE;
  1715.  
  1716.                         int b = 16;
  1717.                         if(cursel == 3) b = 24;
  1718.                         if(cursel == 4) b = 32;
  1719.                         video = SDL_SetVideoMode(SCR_WIDTH, SCR_HEIGHT, b, fullscreen);
  1720.                         if(video == 0) {
  1721.                             video = SDL_SetVideoMode(SCR_WIDTH, SCR_HEIGHT, SCR_BITS, fullscreen);
  1722.                         } else {
  1723.                             SCR_BITS = b;
  1724.                         }
  1725.  
  1726.                         SDL_UpdateRect(video, 0, 0, SCR_WIDTH, SCR_HEIGHT);
  1727.                     }
  1728.                     if(cursel == 5) {
  1729.                         ofullscreen = opfullscreen | HWACCEL | HWSURFACE;
  1730.                         fullscreen = SDL_FULLSCREEN | HWACCEL | HWSURFACE;
  1731.  
  1732.                         video = SDL_SetVideoMode(SCR_WIDTH, SCR_HEIGHT, SCR_BITS, fullscreen);
  1733.                         if(video == 0) {
  1734.                             video = SDL_SetVideoMode(SCR_WIDTH, SCR_HEIGHT, SCR_BITS, ofullscreen);
  1735.                         } else {
  1736.                             opfullscreen = SDL_FULLSCREEN;
  1737.                         }
  1738.  
  1739.                         SDL_UpdateRect(video, 0, 0, SCR_WIDTH, SCR_HEIGHT);
  1740.                     }
  1741.                     if(cursel == 6) {
  1742.                         ofullscreen = opfullscreen | HWACCEL | HWSURFACE;
  1743.                         fullscreen = 0 | HWACCEL | HWSURFACE;
  1744.  
  1745.                         video = SDL_SetVideoMode(SCR_WIDTH, SCR_HEIGHT, SCR_BITS, fullscreen);
  1746.                         if(video == 0) {
  1747.                             video = SDL_SetVideoMode(SCR_WIDTH, SCR_HEIGHT, SCR_BITS, ofullscreen);
  1748.                         } else {
  1749.                             opfullscreen = 0;
  1750.                         }
  1751.  
  1752.                         SDL_UpdateRect(video, 0, 0, SCR_WIDTH, SCR_HEIGHT);
  1753.                     }
  1754.                     if(cursel == 7 && opmusic == 0) {
  1755.                         opmusic = 1;
  1756.                         if(menabled == 1) {
  1757.                             //menuchannel = FSOUND_playSound(FSOUND_FREE, mmenu)
  1758.                             //FSOUND_SetVolume (menuchannel, opmusicvol)
  1759.                         }
  1760.                     }
  1761.                     if(cursel == 8 && opmusic == 1) {
  1762.                         opmusic = 0;
  1763.                         //FSOUND_StopSound(musicchannel)
  1764.                         //FSOUND_StopSound(menuchannel)
  1765.                     }
  1766.                     if(cursel == 9 && opeffects == 0) {
  1767.                         opeffects = 1;
  1768.                         if(menabled == 1) {
  1769.                             //a = FSOUND_PlaySound(FSOUND_FREE, sfx(snddoor))
  1770.                             //FSOUND_SetVolume (a, opeffectsvol)
  1771.                         }
  1772.                     }
  1773.  
  1774.                     if(cursel == 10 && opeffects == 1) opeffects = 0;
  1775.  
  1776.                     if(cursel == 13) {
  1777.                         /*open "config.ini" for(int input as #1
  1778.                             for(int i = 0; i <= 14; i++) {
  1779.                                 input #1, fil$(i)
  1780.                             }
  1781.                         close #1
  1782.                         open "config.ini" for(int output as #1
  1783.                             print #1, fil$(0)
  1784.                             print #1, SCR_WIDTH
  1785.                             print #1, fil$(2)
  1786.                             print #1, SCR_HEIGHT
  1787.                             print #1, fil$(4)
  1788.                             print #1, SCR_BITS
  1789.                             print #1, fil$(6)
  1790.                             print #1, fil$(7)
  1791.                             if(opfullscreen = 0) print #1, "FULLSCREEN:NO"
  1792.                             if(opfullscreen != 0) print #1, "FULLSCREEN:YES"
  1793.                             if(opmusic = 0) print #1, "MUSIC:NO"
  1794.                             if(opmusic = 1) print #1, "MUSIC:YES"
  1795.                             if(opeffects = 0) print #1, "SNDEFFECTS:NO"
  1796.                             if(opeffects = 1) print #1, "SNDEFFECTS:YES"
  1797.                             print #1, fil$(11)
  1798.                             print #1, opmusicvol
  1799.                             print #1, fil$(13)
  1800.                             print #1, opeffectsvol
  1801.                         close #1*/
  1802.  
  1803.                         break;
  1804.                     }
  1805.  
  1806.                     if(cursel == 14) {
  1807.                         // reset keys to avoid returning
  1808.                         keys[SDLK_SPACE] = keys[SDLK_RETURN] = 0;
  1809.                         break;
  1810.                     }
  1811.                 }
  1812.  
  1813.                 if(cursel == -1) cursel = 14;
  1814.                 if(cursel == 15) cursel = 0;
  1815.             }
  1816.         }
  1817.  
  1818.         clouddeg = clouddeg + 0.01 * fpsr;
  1819.         while(clouddeg >= 360) clouddeg = clouddeg - 360;
  1820.  
  1821.         SDL_Delay(10);
  1822.     } while(1);
  1823.  
  1824.     SDL_FreeSurface(configwindow);
  1825.     itemticks = ticks + 210;
  1826.  
  1827.     SDL_SetAlpha(cloudimg, SDL_SRCALPHA, 64);
  1828. }
  1829.  
  1830. void game_damagenpc(int npcnum, int damage, int spell)
  1831. {
  1832.     float npx, npy;
  1833.     int lx, ly, cx, cy, alive;
  1834.     char line[256];
  1835.     float ratio;
  1836.     int fcol, heal, ff;
  1837.  
  1838.     if(damage == 0) {
  1839.         strcpy(line, "miss!");
  1840.         fcol = 2;
  1841.     } else {
  1842.         ratio = 0;
  1843.         heal = 0;
  1844.         if(damage < 0) heal = 1;
  1845.         if(damage < 0) damage = -damage;
  1846.  
  1847.         if(heal == 0) {
  1848.             if(damage > npcinfo[npcnum].hp) {
  1849.                 ratio = (damage - npcinfo[npcnum].hp) / damage;
  1850.                 damage = npcinfo[npcnum].hp;
  1851.             }
  1852.         } else {
  1853.             if(damage > npcinfo[npcnum].maxhp - npcinfo[npcnum].hp) damage = npcinfo[npcnum].maxhp - npcinfo[npcnum].hp;
  1854.         }
  1855.  
  1856.         npcinfo[npcnum].pause = ticks + 900;
  1857.         if(npcinfo[npcnum].spriteset == 11) npcinfo[npcnum].pause = ticks + 900;
  1858.  
  1859.         if(heal == 0) npcinfo[npcnum].hp = npcinfo[npcnum].hp - damage;
  1860.         if(heal == 1) npcinfo[npcnum].hp = npcinfo[npcnum].hp + damage;
  1861.  
  1862.         if(npcinfo[npcnum].hp > npcinfo[npcnum].maxhp) npcinfo[npcnum].hp = npcinfo[npcnum].maxhp;
  1863.  
  1864.         sprintf(line, "-%i", damage);
  1865.         fcol = 1;
  1866.         if(spell == 0) player.attackstrength = ratio * 100;
  1867.  
  1868.         if(heal == 1) {
  1869.             sprintf(line, "+%i", damage);
  1870.             fcol = 5;
  1871.         }
  1872.     }
  1873.  
  1874.     game_addFloatText(line, npcinfo[npcnum].x + 12 - 4 * strlen(line), npcinfo[npcnum].y + 16, fcol);
  1875.  
  1876.  
  1877.     if(npcinfo[npcnum].spriteset == 12) game_castspell(9, npcinfo[npcnum].x, npcinfo[npcnum].y, player.px, player.py, npcnum);
  1878.  
  1879.     if(npcinfo[npcnum].hp < 0) npcinfo[npcnum].hp = 0;
  1880.  
  1881.     if(npcinfo[npcnum].hp == 0) {
  1882.         player.exp = player.exp + npcinfo[npcnum].maxhp;
  1883.  
  1884.         if(npcinfo[npcnum].spriteset == 1 || npcinfo[npcnum].spriteset == 7 || npcinfo[npcnum].spriteset == 6) {
  1885.             ff = (int)(RND() * player.level * 3);
  1886.             if(ff == 0) {
  1887.                 npx = npcinfo[npcnum].x + 12;
  1888.                 npy = npcinfo[npcnum].y + 20;
  1889.  
  1890.                 lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  1891.                 ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  1892.  
  1893.                 if(objmap[lx][ly] == -1) objmap[lx][ly] = 4;
  1894.             }
  1895.         }
  1896.  
  1897.         if(npcinfo[npcnum].spriteset == 2 || npcinfo[npcnum].spriteset == 9 || npcinfo[npcnum].spriteset == 4 || npcinfo[npcnum].spriteset == 5) {
  1898.             ff = (int)(RND() * player.level);
  1899.             if(ff == 0) {
  1900.                 npx = npcinfo[npcnum].x + 12;
  1901.                 npy = npcinfo[npcnum].y + 20;
  1902.  
  1903.                 lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  1904.                 ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  1905.  
  1906.                 if(objmap[lx][ly] == -1) objmap[lx][ly] = 12;
  1907.             }
  1908.         }
  1909.  
  1910.         if(npcinfo[npcnum].spriteset == 9 || npcinfo[npcnum].spriteset == 10 || npcinfo[npcnum].spriteset == 5) {
  1911.             ff = (int)(RND() * player.level * 2);
  1912.             if(ff == 0) {
  1913.                 npx = npcinfo[npcnum].x + 12;
  1914.                 npy = npcinfo[npcnum].y + 20;
  1915.  
  1916.                 lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  1917.                 ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  1918.  
  1919.                 if(objmap[lx][ly] == -1) objmap[lx][ly] = 13;
  1920.             }
  1921.         }
  1922.  
  1923.         // academy master key chest script
  1924.         if(npcinfo[npcnum].script == 2) {
  1925.             cx = 9;
  1926.             cy = 7;
  1927.  
  1928.             alive = 0;
  1929.             for(int i = 1; i <= lastnpc; i++) {
  1930.                 if(npcinfo[i].hp > 0) alive = 1;
  1931.             }
  1932.  
  1933.             if(alive == 0) {
  1934.                 objmap[cx][cy] = 5;
  1935.  
  1936.                 rcDest.x = cx * 8;
  1937.                 rcDest.y = cy * 8;
  1938.                 rcDest.w = 8;
  1939.                 rcDest.h = 8;
  1940.  
  1941.                 npx = player.px + 12;
  1942.                 npy = player.py + 20;
  1943.  
  1944.                 lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  1945.                 ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  1946.  
  1947.                 if(lx == cx && ly == cy) player.py = player.py + 16;
  1948.                 SDL_FillRect(clipbg2, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  1949.                 scriptflag[2][0] = 1;
  1950.             }
  1951.         }
  1952.  
  1953.         // academy crystal chest script
  1954.         if(npcinfo[npcnum].script == 3) {
  1955.             cx = 9;
  1956.             cy = 7;
  1957.  
  1958.             alive = 0;
  1959.             for(int i = 1; i <= lastnpc; i++) {
  1960.                 if(npcinfo[i].hp > 0) alive = 1;
  1961.             }
  1962.  
  1963.             if(alive == 0) {
  1964.                 objmap[cx][cy] = 6;
  1965.  
  1966.                 rcDest.x = cx * 8;
  1967.                 rcDest.y = cy * 8;
  1968.                 rcDest.w = 8;
  1969.                 rcDest.h = 8;
  1970.  
  1971.                 npx = player.px + 12;
  1972.                 npy = player.py + 20;
  1973.  
  1974.                 lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  1975.                 ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  1976.  
  1977.                 if(lx == cx && ly == cy) player.py = player.py + 16;
  1978.                 scriptflag[3][0] = 1;
  1979.                 SDL_FillRect(clipbg2, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  1980.             }
  1981.         }
  1982.  
  1983.         // tower shield chest script
  1984.         if(npcinfo[npcnum].script == 4 && scriptflag[4][0] == 0) {
  1985.                 triggerloc[9][7] = 5004;
  1986.  
  1987.                 int curtile = 40;
  1988.                 int curtilel = 0;
  1989.                 int curtilex = curtile % 20;
  1990.                 int curtiley = (curtile - curtilex) / 20;
  1991.  
  1992.                 int l = 0; // ?? not defined in original code
  1993.                 tileinfo[l][9][7][0] = curtile + 1;
  1994.                 tileinfo[l][9][7][1] = 0;
  1995.  
  1996.                 rcSrc.x = curtilex * 16;
  1997.                 rcSrc.y = curtiley * 16;
  1998.                 rcSrc.w = 16;
  1999.                 rcSrc.h = 16;
  2000.  
  2001.                 rcDest.x = 9 * 16;
  2002.                 rcDest.y = 7 * 16;
  2003.                 rcDest.w = 16;
  2004.                 rcDest.h = 16;
  2005.  
  2006.                 SDL_BlitSurface(tiles[curtilel], &rcSrc, mapbg, &rcDest);
  2007.         }
  2008.  
  2009.         // firehydra sword chest
  2010.         if(npcinfo[npcnum].script == 5) {
  2011.             cx = 9;
  2012.             cy = 6;
  2013.  
  2014.             alive = 0;
  2015.             for(int i = 1; i <= lastnpc; i++) {
  2016.                 if(npcinfo[i].hp > 0) alive = 1;
  2017.             }
  2018.  
  2019.             if(alive == 0) {
  2020.                 objmap[cx][cy] = 9;
  2021.  
  2022.                 rcDest.x = cx * 8;
  2023.                 rcDest.y = cy * 8;
  2024.                 rcDest.w = 8;
  2025.                 rcDest.h = 8;
  2026.  
  2027.                 npx = player.px + 12;
  2028.                 npy = player.py + 20;
  2029.  
  2030.                 lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  2031.                 ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  2032.  
  2033.                 if(lx == cx && ly == cy) player.py = player.py + 16;
  2034.                 scriptflag[5][0] = 1;
  2035.                 SDL_FillRect(clipbg2, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  2036.             }
  2037.  
  2038.         }
  2039.  
  2040.         // gardens master key script
  2041.         if(npcinfo[npcnum].script == 8 && scriptflag[6][0] == 0) {
  2042.             cx = 13;
  2043.             cy = 7;
  2044.  
  2045.             alive = 0;
  2046.             for(int i = 1; i <= lastnpc; i++) {
  2047.                 if(npcinfo[i].hp > 0) alive = 1;
  2048.             }
  2049.  
  2050.             if(alive == 0) {
  2051.                 objmap[cx][cy] = 5;
  2052.  
  2053.                 rcDest.x = cx * 8;
  2054.                 rcDest.y = cy * 8;
  2055.                 rcDest.w = 8;
  2056.                 rcDest.h = 8;
  2057.  
  2058.                 npx = player.px + 12;
  2059.                 npy = player.py + 20;
  2060.  
  2061.                 lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  2062.                 ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  2063.  
  2064.                 if(lx == cx && ly == cy) player.py = player.py + 16;
  2065.                 SDL_FillRect(clipbg2, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  2066.                 scriptflag[8][0] = 1;
  2067.             }
  2068.         }
  2069.  
  2070.         // regular key chest 1
  2071.         for(int s = 20; s <= 23; s++) {
  2072.             if(npcinfo[npcnum].script == s && scriptflag[s][0] < 2) {
  2073.                 cx = 9;
  2074.                 cy = 7;
  2075.  
  2076.                 alive = 0;
  2077.                 for(int i = 1; i <= lastnpc; i++) {
  2078.                     if(npcinfo[i].hp > 0) alive = 1;
  2079.                 }
  2080.  
  2081.                 if(alive == 0) {
  2082.                     objmap[cx][cy] = 11;
  2083.  
  2084.                     rcDest.x = cx * 8;
  2085.                     rcDest.y = cy * 8;
  2086.                     rcDest.w = 8;
  2087.                     rcDest.h = 8;
  2088.  
  2089.                     npx = player.px + 12;
  2090.                     npy = player.py + 20;
  2091.  
  2092.                     lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  2093.                     ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  2094.  
  2095.                     if(lx == cx && ly == cy) player.py = player.py + 16;
  2096.                     scriptflag[s][0] = 1;
  2097.                     SDL_FillRect(clipbg2, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  2098.                 }
  2099.             }
  2100.         }
  2101.  
  2102.         // pickup lightning bomb
  2103.         if(npcinfo[npcnum].script == 9 && (curmap == 41 && scriptflag[9][1] == 0)) {
  2104.             cx = 9;
  2105.             cy = 7;
  2106.  
  2107.             alive = 0;
  2108.             for(int i = 1; i <= lastnpc; i++) {
  2109.                 if(npcinfo[i].hp > 0) alive = 1;
  2110.             }
  2111.  
  2112.             if(alive == 0) {
  2113.                 objmap[cx][cy] = 13;
  2114.  
  2115.                 rcDest.x = cx * 8;
  2116.                 rcDest.y = cy * 8;
  2117.                 rcDest.w = 8;
  2118.                 rcDest.h = 8;
  2119.  
  2120.                 npx = player.px + 12;
  2121.                 npy = player.py + 20;
  2122.  
  2123.                 lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  2124.                 ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  2125.  
  2126.                 if(lx == cx && ly == cy) player.py = player.py + 16;
  2127.             }
  2128.         }
  2129.  
  2130.         // citadel armour chest
  2131.         if(npcinfo[npcnum].script == 12) {
  2132.             cx = 8;
  2133.             cy = 7;
  2134.  
  2135.             alive = 0;
  2136.             for(int i = 1; i <= lastnpc; i++) {
  2137.                 if(npcinfo[i].hp > 0) alive = 1;
  2138.             }
  2139.  
  2140.             if(alive == 0) {
  2141.                 objmap[cx][cy] = 16;
  2142.  
  2143.                 rcDest.x = cx * 8;
  2144.                 rcDest.y = cy * 8;
  2145.                 rcDest.w = 8;
  2146.                 rcDest.h = 8;
  2147.  
  2148.                 npx = player.px + 12;
  2149.                 npy = player.py + 20;
  2150.  
  2151.                 lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  2152.                 ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  2153.  
  2154.                 if(lx == cx && ly == cy) player.py = player.py + 16;
  2155.                 scriptflag[12][0] = 1;
  2156.                 SDL_FillRect(clipbg2, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  2157.             }
  2158.         }
  2159.  
  2160.         // citadel master key script
  2161.         if(npcinfo[npcnum].script == 13 && scriptflag[13][0] == 0) {
  2162.             cx = 11;
  2163.             cy = 10;
  2164.  
  2165.             alive = 0;
  2166.             for(int i = 1; i <= lastnpc; i++) {
  2167.                 if(npcinfo[i].hp > 0) alive = 1;
  2168.             }
  2169.  
  2170.             if(alive == 0) {
  2171.                 objmap[cx][cy] = 5;
  2172.  
  2173.                 rcDest.x = cx * 8;
  2174.                 rcDest.y = cy * 8;
  2175.                 rcDest.w = 8;
  2176.                 rcDest.h = 8;
  2177.  
  2178.                 npx = player.px + 12;
  2179.                 npy = player.py + 20;
  2180.  
  2181.                 lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  2182.                 ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  2183.  
  2184.                 if(lx == cx && ly == cy) player.py = player.py + 16;
  2185.                 SDL_FillRect(clipbg2, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  2186.                 scriptflag[13][0] = 1;
  2187.             }
  2188.         }
  2189.  
  2190.         // max ups
  2191.         if(npcinfo[npcnum].script == 15 && scriptflag[15][0] == 0) {
  2192.             alive = 0;
  2193.             for(int i = 1; i <= lastnpc; i++) {
  2194.                 if(npcinfo[i].hp > 0) alive = 1;
  2195.             }
  2196.  
  2197.             if(alive == 0) {
  2198.                 cx = 6;
  2199.                 cy = 8;
  2200.  
  2201.                 objmap[cx][cy] = 18;
  2202.  
  2203.                 rcDest.x = cx * 8;
  2204.                 rcDest.y = cy * 8;
  2205.                 rcDest.w = 8;
  2206.                 rcDest.h = 8;
  2207.  
  2208.                 npx = player.px + 12;
  2209.                 npy = player.py + 20;
  2210.  
  2211.                 lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  2212.                 ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  2213.  
  2214.                 if(lx == cx && ly == cy) player.py = player.py + 16;
  2215.                 SDL_FillRect(clipbg2, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  2216.                 scriptflag[15][0] = 1;
  2217.  
  2218.                 cx = 9;
  2219.                 cy = 8;
  2220.  
  2221.                 objmap[cx][cy] = 19;
  2222.  
  2223.                 rcDest.x = cx * 8;
  2224.                 rcDest.y = cy * 8;
  2225.                 rcDest.w = 8;
  2226.                 rcDest.h = 8;
  2227.  
  2228.                 npx = player.px + 12;
  2229.                 npy = player.py + 20;
  2230.  
  2231.                 lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  2232.                 ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  2233.  
  2234.                 if(lx == cx && ly == cy) player.py = player.py + 16;
  2235.                 SDL_FillRect(clipbg2, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  2236.  
  2237.                 scriptflag[16][0] = 1;
  2238.  
  2239.                 cx = 12;
  2240.                 cy = 8;
  2241.  
  2242.                 objmap[cx][cy] = 20;
  2243.  
  2244.                 rcDest.x = cx * 8;
  2245.                 rcDest.y = cy * 8;
  2246.                 rcDest.w = 8;
  2247.                 rcDest.h = 8;
  2248.  
  2249.                 npx = player.px + 12;
  2250.                 npy = player.py + 20;
  2251.  
  2252.                 lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  2253.                 ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  2254.  
  2255.                 if(lx == cx && ly == cy) player.py = player.py + 16;
  2256.                 SDL_FillRect(clipbg2, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  2257.                 scriptflag[17][0] = 1;
  2258.             }
  2259.         }
  2260.  
  2261.         if(npcinfo[npcnum].script == 14) game_endofgame();
  2262.     }
  2263. }
  2264.  
  2265. void game_damageplayer(int damage)
  2266. {
  2267.     char line[256];
  2268.  
  2269.     player.hp -= damage;
  2270.     if(player.hp < 0) player.hp = 0;
  2271.  
  2272.     sprintf(line, "-%i", damage);
  2273.     if(damage == 0) strcpy(line, "miss!");
  2274.  
  2275.     game_addFloatText(line, player.px + 12 - 4 * strlen(line), player.py + 16, 4);
  2276.  
  2277.     player.pause = ticks + 1000;
  2278. }
  2279.  
  2280. void game_drawanims(int Layer)
  2281. {
  2282.     for(int sx = 0; sx <= 19; sx++) {
  2283.         for(int sy = 0; sy <= 14; sy++) {
  2284.             int o = objmap[sx][sy];
  2285.  
  2286.             if(o > -1) {
  2287.                 int xtiles = objectinfo[o][1];
  2288.                 int ytiles = objectinfo[o][2];
  2289.                 int cframe = objectframe[o][1];
  2290.  
  2291.                 for(int x = 0; x <= xtiles - 1; x++) {
  2292.                     for(int y = 0; y <= ytiles - 1; y++) {
  2293.                         int x1 = (sx + x) * 16;
  2294.                         int y1 = (sy + y) * 16;
  2295.  
  2296.                         if(objecttile[o][cframe][x][y][1] == Layer) {
  2297.                             int c = objecttile[o][cframe][x][y][0];
  2298.                             c = c - 1;
  2299.                             int curtilel = 3;
  2300.                             int curtilex = c % 20;
  2301.                             int curtiley = (c - curtilex) / 20;
  2302.  
  2303.                             if(curmap == 58 && scriptflag[60][0] > 0) curtilex = 1;
  2304.                             if(curmap == 54 && scriptflag[60][0] > 1) curtilex = 1;
  2305.                             rcSrc.x = curtilex * 16;
  2306.                             rcSrc.y = curtiley * 16;
  2307.                             rcSrc.w = 16;
  2308.                             rcSrc.h = 16;
  2309.  
  2310.                             rcDest.x = x1;
  2311.                             rcDest.y = y1;
  2312.                             rcDest.w = 16;
  2313.                             rcDest.h = 16;
  2314.  
  2315.                             SDL_BlitSurface(tiles[curtilel], &rcSrc, videobuffer, &rcDest);
  2316.                         }
  2317.  
  2318.                         if(Layer == 1) {
  2319.                             for(int l = 1; l <= 2; l++) {
  2320.                                 int c = tileinfo[l][sx + x][sy + y][0];
  2321.                                 if(c > 0) {
  2322.                                     int cl = tileinfo[l][sx + x][sy + y][1];
  2323.  
  2324.                                     c = c - 1;
  2325.                                     int curtile = c;
  2326.                                     int curtilel = cl;
  2327.                                     int curtilex = c % 20;
  2328.                                     int curtiley = (c - curtilex) / 20;
  2329.  
  2330.                                     rcSrc.x = curtilex * 16;
  2331.                                     rcSrc.y = curtiley * 16;
  2332.                                     rcSrc.w = 16;
  2333.                                     rcSrc.h = 16;
  2334.  
  2335.                                     rcDest.x = (sx + x) * 16;
  2336.                                     rcDest.y = (sy + y) * 16;
  2337.                                     rcDest.w = 16;
  2338.                                     rcDest.h = 16;
  2339.  
  2340.                                     int pass = 1;
  2341.                                     if(curtilel == 1) {
  2342.                                         for(int ff = 0; ff <= 5; ff++) {
  2343.                                             int ffa = 20 * 5 - 1 + ff * 20;
  2344.                                             int ffb = 20 * 5 + 4 + ff * 20;
  2345.                                             if(curtile > ffa && curtile < ffb) pass = 0;
  2346.                                         }
  2347.                                     }
  2348.  
  2349.                                     if(pass == 1) SDL_BlitSurface(tiles[curtilel], &rcSrc, videobuffer, &rcDest);
  2350.                                 }
  2351.                             }
  2352.                         }
  2353.                     }
  2354.                 }
  2355.             }
  2356.         }
  2357.     }
  2358. }
  2359.  
  2360. void game_drawhud()
  2361. {
  2362.     char line[128];
  2363.     sprintf(line, "fps: %i, map: %i, fl: %i", (int)fps, curmap, scriptflag[60][0]);
  2364.     sys_print(videobuffer, line, 0, 0, 0);
  2365.  
  2366.     sprintf(line, "px: %f, py: %f", player.px, player.py);
  2367.     sys_print(videobuffer, line, 0, 8, 0);
  2368.  
  2369.     long ccc;
  2370.  
  2371.     rcSrc.x = 0;
  2372.     rcSrc.y = 0;
  2373.     rcSrc.w = 320;
  2374.     rcSrc.h = 240;
  2375.  
  2376.     SDL_FillRect(videobuffer2, &rcSrc, 0);
  2377.  
  2378.     for(int i = 0; i <= MAXFLOAT; i++) {
  2379.         if(floattext[i][0] > 0) {
  2380.             int fc = (int)floattext[i][3];
  2381.  
  2382.             if(fc == 1 || fc == 3) {
  2383.                 sys_print(videobuffer, floatstri[i], (int)(floattext[i][1]) + 0, (int)(floattext[i][2]) - 1, 2);
  2384.                 sys_print(videobuffer, floatstri[i], (int)(floattext[i][1]) + 0, (int)(floattext[i][2]) + 1, 2);
  2385.                 sys_print(videobuffer, floatstri[i], (int)(floattext[i][1]) - 1, (int)(floattext[i][2]) + 0, 2);
  2386.                 sys_print(videobuffer, floatstri[i], (int)(floattext[i][1]) + 1, (int)(floattext[i][2]) + 0, 2);
  2387.                 sys_print(videobuffer, floatstri[i], (int)(floattext[i][1]), (int)(floattext[i][2]), fc);
  2388.             }
  2389.             if(fc == 2) {
  2390.                 sys_print(videobuffer, floatstri[i], (int)(floattext[i][1]) + 0, (int)(floattext[i][2]) - 1, 3);
  2391.                 sys_print(videobuffer, floatstri[i], (int)(floattext[i][1]) + 0, (int)(floattext[i][2]) + 1, 3);
  2392.                 sys_print(videobuffer, floatstri[i], (int)(floattext[i][1]) - 1, (int)(floattext[i][2]) + 0, 3);
  2393.                 sys_print(videobuffer, floatstri[i], (int)(floattext[i][1]) + 1, (int)(floattext[i][2]) + 0, 3);
  2394.                 sys_print(videobuffer, floatstri[i], (int)(floattext[i][1]), (int)(floattext[i][2]), fc);
  2395.             }
  2396.  
  2397.             if(fc == 4) {
  2398.                 sys_print(videobuffer, floatstri[i], (int)(floattext[i][1]) + 0, (int)(floattext[i][2]) - 1, 3);
  2399.                 sys_print(videobuffer, floatstri[i], (int)(floattext[i][1]) + 0, (int)(floattext[i][2]) + 1, 3);
  2400.                 sys_print(videobuffer, floatstri[i], (int)(floattext[i][1]) - 1, (int)(floattext[i][2]) + 0, 3);
  2401.                 sys_print(videobuffer, floatstri[i], (int)(floattext[i][1]) + 1, (int)(floattext[i][2]) + 0, 3);
  2402.                 sys_print(videobuffer, floatstri[i], (int)(floattext[i][1]), (int)(floattext[i][2]), 1);
  2403.             }
  2404.  
  2405.             if(fc == 5) {
  2406.                 sys_print(videobuffer, floatstri[i], (int)(floattext[i][1]) + 0, (int)(floattext[i][2]) - 1, 3);
  2407.                 sys_print(videobuffer, floatstri[i], (int)(floattext[i][1]) + 0, (int)(floattext[i][2]) + 1, 3);
  2408.                 sys_print(videobuffer, floatstri[i], (int)(floattext[i][1]) - 1, (int)(floattext[i][2]) + 0, 3);
  2409.                 sys_print(videobuffer, floatstri[i], (int)(floattext[i][1]) + 1, (int)(floattext[i][2]) + 0, 3);
  2410.                 sys_print(videobuffer, floatstri[i], (int)(floattext[i][1]), (int)(floattext[i][2]), 0);
  2411.             }
  2412.  
  2413.  
  2414.             if(fc == 0) {
  2415.                 sys_print(videobuffer, floatstri[i], (int)(floattext[i][1]), (int)(floattext[i][2]), fc);
  2416.             }
  2417.         }
  2418.  
  2419.         if(floaticon[i][0] > 0) {
  2420.             int ico = floaticon[i][3];
  2421.             int ix = floaticon[i][1];
  2422.             int iy = floaticon[i][2];
  2423.  
  2424.             rcDest.x = ix;
  2425.             rcDest.y = iy;
  2426.  
  2427.             if(ico != 99) SDL_BlitSurface(itemimg[ico], NULL, videobuffer, &rcDest);
  2428.             if(ico == 99) {
  2429.                 SDL_SetAlpha(spellimg, SDL_SRCALPHA, (int)(RND() * 96) + 96);
  2430.  
  2431.                 rcSrc.x = 16 * (int)(RND() * 2);
  2432.                 rcSrc.y = 80;
  2433.                 rcSrc.w = 16;
  2434.                 rcSrc.h = 16;
  2435.  
  2436.                 rcDest.x = ix;
  2437.                 rcDest.y = iy;
  2438.  
  2439.                 SDL_BlitSurface(spellimg, &rcSrc, videobuffer, &rcDest);
  2440.  
  2441.                 SDL_SetAlpha(spellimg, SDL_SRCALPHA, 255);
  2442.             }
  2443.         }
  2444.     }
  2445.  
  2446.     if(itemselon == 0) {
  2447.         int sy = 211;
  2448.  
  2449.  
  2450.         int nx = 19 * 8 + 13;
  2451.         rcSrc.x = nx - 17 + 48;
  2452.         rcSrc.y = sy;
  2453.  
  2454.         if(player.foundcrystal == 1) {
  2455.             rcSrc.x = rcSrc.x + 17;
  2456.  
  2457.             SDL_BlitSurface(itemimg[7], NULL, videobuffer, &rcSrc);
  2458.  
  2459.             ccc = SDL_MapRGB(videobuffer->format, 0, 32, 32);
  2460.  
  2461.             rcSrc2.x = rcSrc.x;
  2462.             rcSrc2.y = sy + 16;
  2463.             rcSrc2.w = 16;
  2464.             rcSrc2.h = 4;
  2465.  
  2466.             SDL_FillRect(videobuffer, &rcSrc2, ccc);
  2467.  
  2468.             ccc = SDL_MapRGB(videobuffer->format, 0, 224, 64);
  2469.             if(player.crystalcharge == 100) ccc = SDL_MapRGB(videobuffer->format, 255, 128, 32);
  2470.  
  2471.             int mx = player.crystalcharge / 100 * 14;
  2472.             if(mx > 14) mx = 14;
  2473.  
  2474.             rcSrc2.x = rcSrc.x + 1;
  2475.             rcSrc2.y = sy + 17;
  2476.             rcSrc2.w = mx;
  2477.             rcSrc2.h = 2;
  2478.  
  2479.             SDL_FillRect(videobuffer, &rcSrc2, ccc);
  2480.  
  2481.  
  2482.             for(int i = 0; i <= 4; i++) {
  2483.                 rcSrc.x = rcSrc.x + 17;
  2484.  
  2485.                 if(player.foundspell[i] == 1) {
  2486.                     SDL_BlitSurface(itemimg[8 + i], NULL, videobuffer, &rcSrc);
  2487.  
  2488.                     ccc = SDL_MapRGB(videobuffer->format, 0, 32, 32);
  2489.  
  2490.                     rcSrc2.x = rcSrc.x;
  2491.                     rcSrc2.y = sy + 16;
  2492.                     rcSrc2.w = 16;
  2493.                     rcSrc2.h = 4;
  2494.  
  2495.                     SDL_FillRect(videobuffer, &rcSrc2, ccc);
  2496.  
  2497.                     ccc = SDL_MapRGB(videobuffer->format, 0, 224, 64);
  2498.                     if(player.spellcharge[i] == 100) ccc = SDL_MapRGB(videobuffer->format, 255, 128, 32);
  2499.  
  2500.                     mx = player.spellcharge[i] / 100 * 14;
  2501.                     if(mx > 14) mx = 14;
  2502.  
  2503.                     rcSrc2.x = rcSrc.x + 1;
  2504.                     rcSrc2.y = sy + 17;
  2505.                     rcSrc2.w = mx;
  2506.                     rcSrc2.h = 2;
  2507.  
  2508.                     SDL_FillRect(videobuffer, &rcSrc2, ccc);
  2509.                 }
  2510.             }
  2511.         }
  2512.         return;
  2513.     }
  2514.  
  2515.     if(selenemyon == 0) {
  2516.         rcDest.x = 0;
  2517.         rcDest.y = 0;
  2518.         rcDest.w = 320;
  2519.         rcDest.h = 240;
  2520.         rc2.x = 0;
  2521.         rc2.y = 0;
  2522.         SDL_SetAlpha(videobuffer2, SDL_SRCALPHA, (int)(player.itemselshade * 4));
  2523.         SDL_FillRect(videobuffer2, &rcDest, 0);
  2524.         SDL_BlitSurface(videobuffer2, NULL, videobuffer, &rc2);
  2525.  
  2526.         int sy = 202;
  2527.         rcSrc.x = 46;
  2528.         rcSrc.y = 46;
  2529.  
  2530.         SDL_SetAlpha(inventoryimg, SDL_SRCALPHA, 160); // 128
  2531.         SDL_BlitSurface(inventoryimg, NULL, videobuffer, &rcSrc);
  2532.         SDL_SetAlpha(inventoryimg, SDL_SRCALPHA, 255);
  2533.  
  2534.         int sx = 54;
  2535.         sy = 55;
  2536.  
  2537.         // draw map 9,77
  2538.         rcDest.x = 46 + 9;
  2539.         rcDest.y = 46 + 77;
  2540.  
  2541.         int amap = 0;
  2542.         if(curmap > 46) amap = 2;
  2543.         if(curmap > 67) amap = 3;
  2544.         if(curmap > 5 && curmap < 42) amap = 1;
  2545.         SDL_BlitSurface(mapimg[amap], NULL, videobuffer, &rcDest);
  2546.  
  2547.         ccc = SDL_MapRGB(videobuffer->format, 128 + 127 * sin(3.141592 * 2 * itemyloc / 16), 0, 0);
  2548.  
  2549.         for(int b = 0; b <= 6; b++) {
  2550.             for(int a = 0; a <= 12; a++) {
  2551.                 if(invmap[amap][b][a] == curmap) {
  2552.                     rcSrc2.x = 46 + 9 + a * 9 + 2;
  2553.                     rcSrc2.y = 46 + 77 + b * 9 + 1;
  2554.                     rcSrc2.w = 6;
  2555.                     rcSrc2.h = 6;
  2556.                 }
  2557.             }
  2558.         }
  2559.  
  2560.         SDL_FillRect(videobuffer, &rcSrc2, ccc);
  2561.  
  2562.         if(amap == 1) {
  2563.             sys_print(videobuffer, "L1", 46 + 9, 46 + 77, 0);
  2564.             sys_print(videobuffer, "L2", 46 + 9 + 7 * 9, 46 + 77, 0);
  2565.         }
  2566.  
  2567.         int cc = 0;
  2568.         if(player.hp <= player.maxhp * 0.25) cc = (int)(player.hpflash);
  2569.  
  2570.         sprintf(line, "Health: %i/%i", player.hp, player.maxhp);
  2571.         sys_print(videobuffer, line, sx, sy, cc);
  2572.  
  2573.         sprintf(line, "Level : %i", player.level);
  2574.         if(player.level == 22) strcpy(line, "Level : MAX");
  2575.         sys_print(videobuffer, line, sx, sy + 8, 0);
  2576.  
  2577.         int mx = player.exp / player.level * 14;
  2578.         if(mx > 14) mx = 14;
  2579.  
  2580.         ccc = SDL_MapRGB(videobuffer->format, 0, 32, 32);
  2581.  
  2582.         rcSrc2.x = sx + 64;
  2583.         rcSrc2.y = sy + 16;
  2584.         rcSrc2.w = 16;
  2585.         rcSrc2.h = 4;
  2586.  
  2587.         SDL_FillRect(videobuffer, &rcSrc2, ccc);
  2588.  
  2589.         ccc = SDL_MapRGB(videobuffer->format, 0, 224, 64);
  2590.  
  2591.         rcSrc2.x = sx + 65;
  2592.         rcSrc2.y = sy + 17;
  2593.         rcSrc2.w = mx;
  2594.         rcSrc2.h = 2;
  2595.  
  2596.         SDL_FillRect(videobuffer, &rcSrc2, ccc);
  2597.  
  2598.         mx = player.attackstrength / 100 * 54;
  2599.         if(mx > 54) mx = 54;
  2600.  
  2601.         int mx2 = player.spellstrength / 100 * 54;
  2602.         if(mx2 > 54) mx2 = 54;
  2603.  
  2604.         ccc = SDL_MapRGB(videobuffer->format, 0, 32, 32);
  2605.  
  2606.         rcSrc2.x = sx;
  2607.         rcSrc2.y = sy + 16;
  2608.         rcSrc2.w = 56;
  2609.         rcSrc2.h = 6;
  2610.  
  2611.         SDL_FillRect(videobuffer, &rcSrc2, ccc);
  2612.  
  2613.         ccc = SDL_MapRGB(videobuffer->format, 0, 64, 224);
  2614.         if(player.attackstrength == 100) ccc = SDL_MapRGB(videobuffer->format, 255, 128, 32);
  2615.  
  2616.         rcSrc2.x = sx + 1;
  2617.         rcSrc2.y = sy + 17;
  2618.         rcSrc2.w = mx;
  2619.         rcSrc2.h = 2;
  2620.  
  2621.         SDL_FillRect(videobuffer, &rcSrc2, ccc);
  2622.  
  2623.         ccc = SDL_MapRGB(videobuffer->format, 128, 0, 224);
  2624.         if(player.spellstrength == 100) ccc = SDL_MapRGB(videobuffer->format, 224, 0, 0);
  2625.  
  2626.         rcSrc2.x = sx + 1;
  2627.         rcSrc2.y = sy + 19;
  2628.         rcSrc2.w = mx2;
  2629.         rcSrc2.h = 2;
  2630.  
  2631.         SDL_FillRect(videobuffer, &rcSrc2, ccc);
  2632.  
  2633.         // time
  2634.         int ase = secstart + secsingame;
  2635.         int h = ((ase - (ase % 3600)) / 3600);
  2636.         ase = (ase - h * 3600);
  2637.         int m = ((ase - (ase % 60)) / 60);
  2638.         int s = (ase - m * 60);
  2639.  
  2640.         sprintf(line, "%02i:%02i:%02i", h, m, s);
  2641.         sys_print(videobuffer, line, 46 + 38 - strlen(line) * 4, 46 + 49, 0);
  2642.  
  2643.         sys_print(videobuffer, "Use", 193, 55, 0);
  2644.         sys_print(videobuffer, "Cast", 236, 55, 0);
  2645.  
  2646.         rcSrc.x = 128;
  2647.         rcSrc.y = 91;
  2648.  
  2649.         int ss = (player.sword - 1) * 3;
  2650.         if(player.sword == 3) ss = 18;
  2651.         SDL_BlitSurface(itemimg[ss], NULL, videobuffer, &rcSrc);
  2652.  
  2653.         rcSrc.x = rcSrc.x + 16;
  2654.         ss = (player.shield - 1) * 3 + 1;
  2655.         if(player.shield == 3) ss = 19;
  2656.         SDL_BlitSurface(itemimg[ss], NULL, videobuffer, &rcSrc);
  2657.  
  2658.         rcSrc.x = rcSrc.x + 16;
  2659.         ss = (player.armour - 1) * 3 + 2;
  2660.         if(player.armour == 3) ss = 20;
  2661.         SDL_BlitSurface(itemimg[ss], NULL, videobuffer, &rcSrc);
  2662.  
  2663.         for(int i = 0; i <= 4; i++) {
  2664.             sx = 188;
  2665.             sy = 70 + i * 24;
  2666.             rcSrc.x = sx;
  2667.             rcSrc.y = sy;
  2668.             if(i == 0) SDL_BlitSurface(itemimg[6], NULL, videobuffer, &rcSrc);
  2669.             if(i == 1) SDL_BlitSurface(itemimg[12], NULL, videobuffer, &rcSrc);
  2670.             if(i == 2) SDL_BlitSurface(itemimg[17], NULL, videobuffer, &rcSrc);
  2671.             if(i == 3) SDL_BlitSurface(itemimg[16], NULL, videobuffer, &rcSrc);
  2672.             if(i == 4) SDL_BlitSurface(itemimg[14], NULL, videobuffer, &rcSrc);
  2673.  
  2674.             sprintf(line, "x%i", inventory[i]);
  2675.             sys_print(videobuffer, line, sx + 17, sy + 7, 0);
  2676.         }
  2677.  
  2678.         if(player.foundcrystal == 1) {
  2679.             rcSrc.x = 243;
  2680.             rcSrc.y = 67;
  2681.             sy = 67;
  2682.  
  2683.             SDL_BlitSurface(itemimg[7], NULL, videobuffer, &rcSrc);
  2684.  
  2685.             ccc = SDL_MapRGB(videobuffer->format, 0, 32, 32);
  2686.  
  2687.             rcSrc2.x = rcSrc.x;
  2688.             rcSrc2.y = sy + 16;
  2689.             rcSrc2.w = 16;
  2690.             rcSrc2.h = 4;
  2691.  
  2692.             SDL_FillRect(videobuffer, &rcSrc2, ccc);
  2693.  
  2694.             ccc = SDL_MapRGB(videobuffer->format, 0, 224, 64);
  2695.             if(player.crystalcharge == 100) ccc = SDL_MapRGB(videobuffer->format, 255, 128, 32);
  2696.  
  2697.             mx = player.crystalcharge / 100 * 14;
  2698.             if(mx > 14) mx = 14;
  2699.  
  2700.             rcSrc2.x = rcSrc.x + 1;
  2701.             rcSrc2.y = sy + 17;
  2702.             rcSrc2.w = mx;
  2703.             rcSrc2.h = 2;
  2704.  
  2705.             SDL_FillRect(videobuffer, &rcSrc2, ccc);
  2706.  
  2707.  
  2708.             for(int i = 0; i <= 3; i++) {
  2709.                 rcSrc.x = 243;
  2710.                 rcSrc.y = 91 + i * 24;
  2711.                 sy = rcSrc.y;
  2712.  
  2713.                 if(player.foundspell[i] == 1) {
  2714.                     SDL_BlitSurface(itemimg[8 + i], NULL, videobuffer, &rcSrc);
  2715.  
  2716.                     ccc = SDL_MapRGB(videobuffer->format, 0, 32, 32);
  2717.  
  2718.                     rcSrc2.x = rcSrc.x;
  2719.                     rcSrc2.y = sy + 16;
  2720.                     rcSrc2.w = 16;
  2721.                     rcSrc2.h = 4;
  2722.  
  2723.                     SDL_FillRect(videobuffer, &rcSrc2, ccc);
  2724.  
  2725.                     ccc = SDL_MapRGB(videobuffer->format, 0, 224, 64);
  2726.                     if(player.spellcharge[i] == 100) ccc = SDL_MapRGB(videobuffer->format, 255, 128, 32);
  2727.  
  2728.                     mx = player.spellcharge[i] / 100 * 14;
  2729.                     if(mx > 14) mx = 14;
  2730.  
  2731.                     rcSrc2.x = rcSrc.x + 1;
  2732.                     rcSrc2.y = sy + 17;
  2733.                     rcSrc2.w = mx;
  2734.                     rcSrc2.h = 2;
  2735.  
  2736.                     SDL_FillRect(videobuffer, &rcSrc2, ccc);
  2737.                 }
  2738.             }
  2739.         }
  2740.  
  2741.         if(itemselon == 1) {
  2742.             for(int i = 0; i <= 4; i++) {
  2743.                 if(curitem == 5 + i) {
  2744.                     rcDest.x = (float)(243 - 12 + 3 * sin(3.141592 * 2 * itemyloc / 16));
  2745.                     rcDest.y = 67 + 24 * i;
  2746.                     SDL_BlitSurface(itemimg[15], NULL, videobuffer, &rcDest);
  2747.                 }
  2748.  
  2749.                 if(curitem == i) {
  2750.                     rcDest.x = (float)(189 - 12 + 3 * sin(3.141592 * 2 * itemyloc / 16));
  2751.                     rcDest.y = 70 + 24 * i;
  2752.                     SDL_BlitSurface(itemimg[15], NULL, videobuffer, &rcDest);
  2753.                 }
  2754.             }
  2755.         }
  2756.     }
  2757.  
  2758.     if(selenemyon == 1) {
  2759.         if(curenemy > lastnpc) {
  2760.             int pst = curenemy - lastnpc - 1;
  2761.             rcDest.x = postinfo[pst][0];
  2762.             rcDest.y = (float)(postinfo[pst][1] - 4 - sin(3.141592 / 8 * itemyloc));
  2763.         } else {
  2764.             rcDest.x = npcinfo[curenemy].x + 4;
  2765.             rcDest.y = (float)(npcinfo[curenemy].y + 4 - 16 - sin(3.141592 / 8 * itemyloc));
  2766.         }
  2767.  
  2768.         SDL_BlitSurface(itemimg[13], NULL, videobuffer, &rcDest);
  2769.     }
  2770. }
  2771.  
  2772. void game_drawnpcs(int mode)
  2773. {
  2774.     unsigned int ccc;
  2775.  
  2776.     ccc = SDL_MapRGB(videobuffer->format, 255, 128, 32);
  2777.  
  2778.     int lok = 0;
  2779.     if(mode == 1) lok = 1;
  2780.  
  2781.     int fst = firsty;
  2782.     int lst = lasty;
  2783.  
  2784.     if(mode == 0) lst = player.ysort;
  2785.     if(mode == 1) fst = player.ysort;
  2786.  
  2787.     for(int yy = fst; yy <= lst; yy++) {
  2788.  
  2789.         if(ysort[yy] > 0) {
  2790.             int i = ysort[yy];
  2791.  
  2792.             if(npcinfo[i].hp > 0) {
  2793.                 int npx = (int)(npcinfo[i].x);
  2794.                 int npy = (int)(npcinfo[i].y);
  2795.  
  2796.                 // if((npy <= player.py AND mode = 0) OR (npy > player.py AND mode = 1)) {
  2797.  
  2798.                 int sprite = npcinfo[i].spriteset;
  2799.  
  2800.                 int wdir = npcinfo[i].walkdir;
  2801.  
  2802.                 // spriteset1 specific
  2803.                 if(npcinfo[i].spriteset == 1) {
  2804.  
  2805.                     if(npcinfo[i].attacking == 0) {
  2806.  
  2807.                         int cframe = npcinfo[i].cframe;
  2808.  
  2809.                         rcSrc.x = (int)(cframe / 4) * 24;
  2810.                         rcSrc.y = wdir * 24;
  2811.                         rcSrc.w = 24;
  2812.                         rcSrc.h = 24;
  2813.  
  2814.                         rcDest.x = npx;
  2815.                         rcDest.y = npy;
  2816.                         rcDest.w = 24;
  2817.                         rcDest.h = 24;
  2818.  
  2819.                         if(npcinfo[i].pause > ticks && npcinfo[i].shake < ticks) {
  2820.                             npcinfo[i].shake = ticks + 50;
  2821.                             rcDest.x = rcDest.x + (int)(RND() * 3) - 1;
  2822.                             rcDest.y = rcDest.y + (int)(RND() * 3) - 1;
  2823.                         }
  2824.  
  2825.                         SDL_BlitSurface(anims[sprite], &rcSrc, videobuffer, &rcDest);
  2826.                     } else {
  2827.                         int cframe = npcinfo[i].cattackframe;
  2828.  
  2829.                         rcSrc.x = (int)(cframe / 4) * 24;
  2830.                         rcSrc.y = wdir * 24;
  2831.                         rcSrc.w = 24;
  2832.                         rcSrc.h = 24;
  2833.  
  2834.                         rcDest.x = npx;
  2835.                         rcDest.y = npy;
  2836.                         rcDest.w = 24;
  2837.                         rcDest.h = 24;
  2838.  
  2839.                         SDL_BlitSurface(animsa[sprite], &rcSrc, videobuffer, &rcDest);
  2840.                     }
  2841.  
  2842.                 }
  2843.  
  2844.                 // onewing
  2845.                 if(npcinfo[i].spriteset == 2) {
  2846.                     for(int f = 0; f <= 7; f++) {
  2847.                         int s = npcinfo[i].bodysection[f].sprite;
  2848.                         rcSrc.x = animset2[s].x;
  2849.                         rcSrc.y = animset2[s].y;
  2850.                         rcSrc.w = animset2[s].w;
  2851.                         rcSrc.h = animset2[s].h;
  2852.  
  2853.                         rcDest.x = npcinfo[i].bodysection[f].x - animset2[s].xofs;
  2854.                         rcDest.y = npcinfo[i].bodysection[f].y - animset2[s].yofs + 2;
  2855.  
  2856.                         SDL_BlitSurface(anims[2], &rcSrc, videobuffer, &rcDest);
  2857.                     }
  2858.  
  2859.                 }
  2860.  
  2861.                 // twowing
  2862.                 if(npcinfo[i].spriteset == 9) {
  2863.                     for(int f = 0; f <= 7; f++) {
  2864.                         int yp = 0;
  2865.  
  2866.                         if(f == 0 && (curmap == 53 || curmap == 57 || curmap == 61 || curmap == 65 || curmap == 56 || curmap > 66) && scriptflag[60][0] > 0) yp = 16;
  2867.                         int s = npcinfo[i].bodysection[f].sprite;
  2868.                         rcSrc.x = animset9[s].x;
  2869.                         rcSrc.y = animset9[s].y + yp;
  2870.                         rcSrc.w = animset9[s].w;
  2871.                         rcSrc.h = animset9[s].h;
  2872.  
  2873.                         rcDest.x = npcinfo[i].bodysection[f].x - animset9[s].xofs;
  2874.                         rcDest.y = npcinfo[i].bodysection[f].y - animset9[s].yofs + 2;
  2875.  
  2876.                         SDL_BlitSurface(anims[9], &rcSrc, videobuffer, &rcDest);
  2877.                     }
  2878.  
  2879.                 }
  2880.  
  2881.  
  2882.                 //  boss 1
  2883.                 if(npcinfo[i].spriteset == 3) {
  2884.                     if(npcinfo[i].attacking == 0) {
  2885.                         int cframe = npcinfo[i].cframe;
  2886.  
  2887.                         rcSrc.x = (int)(cframe / 4) * 24;
  2888.                         rcSrc.y = 0;
  2889.                         rcSrc.w = 24;
  2890.                         rcSrc.h = 48;
  2891.  
  2892.                         rcDest.x = npx - 2;
  2893.                         rcDest.y = npy - 24;
  2894.  
  2895.                         SDL_BlitSurface(anims[3], &rcSrc, videobuffer, &rcDest);
  2896.                     } else {
  2897.                         rcSrc.x = 4 * 24;
  2898.                         rcSrc.y = 0;
  2899.                         rcSrc.w = 24;
  2900.                         rcSrc.h = 48;
  2901.  
  2902.                         rcDest.x = npx - 2;
  2903.                         rcDest.y = npy - 24;
  2904.  
  2905.                         SDL_BlitSurface(anims[3], &rcSrc, videobuffer, &rcDest);
  2906.                     }
  2907.  
  2908.                 }
  2909.  
  2910.                 // black knight
  2911.                 if(npcinfo[i].spriteset == 4) {
  2912.                     if(npcinfo[i].attacking == 0) {
  2913.                         int cframe = npcinfo[i].cframe;
  2914.  
  2915.                         rcSrc.x = (int)(cframe / 4) * 24;
  2916.                         rcSrc.y = 0;
  2917.                         rcSrc.w = 24;
  2918.                         rcSrc.h = 48;
  2919.  
  2920.                         rcDest.x = npx - 2;
  2921.                         rcDest.y = npy - 24;
  2922.  
  2923.                         SDL_BlitSurface(anims[4], &rcSrc, videobuffer, &rcDest);
  2924.                     } else {
  2925.                         rcSrc.x = 4 * 24;
  2926.                         rcSrc.y = 0;
  2927.                         rcSrc.w = 24;
  2928.                         rcSrc.h = 48;
  2929.  
  2930.                         rcDest.x = npx - 2;
  2931.                         rcDest.y = npy - 24;
  2932.  
  2933.                         SDL_BlitSurface(anims[4], &rcSrc, videobuffer, &rcDest);
  2934.                     }
  2935.                 }
  2936.  
  2937.  
  2938.                 // firehydra
  2939.                 if(npcinfo[i].spriteset == 5) {
  2940.                     for(int ff = 0; ff <= 2; ff++) {
  2941.                         if(npcinfo[i].hp > 10 * ff * 20) {
  2942.                             rcSrc.x = 16 * (int)(RND() * 2);
  2943.                             rcSrc.y = 80;
  2944.                             rcSrc.w = 16;
  2945.                             rcSrc.h = 16;
  2946.  
  2947.                             rcDest.x = npcinfo[i].bodysection[10 * ff].x - 8;
  2948.                             rcDest.y = npcinfo[i].bodysection[10 * ff].y - 8;
  2949.  
  2950.                             int x = 192 + ((int)(itemyloc + ff * 5) % 3) * 64;
  2951.                             if(x > 255) x = 255;
  2952.                             SDL_SetAlpha(spellimg, SDL_SRCALPHA, x);
  2953.                             SDL_BlitSurface(spellimg, &rcSrc, videobuffer, &rcDest);
  2954.                             SDL_SetAlpha(spellimg, SDL_SRCALPHA, 255);
  2955.  
  2956.                             for(int f = 1; f <= 8; f++) {
  2957.                                 rcSrc.x = 16 * (int)(RND() * 2);
  2958.                                 rcSrc.y = 80;
  2959.                                 rcSrc.w = 16;
  2960.                                 rcSrc.h = 16;
  2961.  
  2962.                                 rcDest.x = npcinfo[i].bodysection[ff * 10 + f].x - 8 + (int)(RND() * 3) - 1;
  2963.                                 rcDest.y = npcinfo[i].bodysection[ff * 10 + f].y - 8 + (int)(RND() * 3) - 1;
  2964.  
  2965.                                 x = 192 + f % 3 * 64;
  2966.                                 if(x > 255) x = 255;
  2967.                                 SDL_SetAlpha(spellimg, SDL_SRCALPHA, x);
  2968.                                 SDL_BlitSurface(spellimg, &rcSrc, videobuffer, &rcDest);
  2969.                                 SDL_SetAlpha(spellimg, SDL_SRCALPHA, 255);
  2970.                             }
  2971.  
  2972.                             rcSrc.x = 0;
  2973.                             rcSrc.y = 0;
  2974.                             rcSrc.w = 42;
  2975.                             rcSrc.h = 36;
  2976.  
  2977.                             rcDest.x = npcinfo[i].bodysection[10 * ff + 9].x - 21;
  2978.                             rcDest.y = npcinfo[i].bodysection[10 * ff + 9].y - 21;
  2979.  
  2980.                             SDL_SetAlpha(spellimg, SDL_SRCALPHA, 192);
  2981.                             SDL_BlitSurface(anims[5], &rcSrc, videobuffer, &rcDest);
  2982.                             SDL_SetAlpha(spellimg, SDL_SRCALPHA, 255);
  2983.  
  2984.                         }
  2985.  
  2986.                     }
  2987.  
  2988.                 }
  2989.  
  2990.                 // red dragon
  2991.                 if(npcinfo[i].spriteset == 6) {
  2992.                     int cframe = npcinfo[i].cframe;
  2993.  
  2994.                     rcSrc.x = (int)(cframe / 4) * 24;
  2995.                     rcSrc.y = wdir * 24;
  2996.                     rcSrc.w = 24;
  2997.                     rcSrc.h = 24;
  2998.  
  2999.                     rcDest.x = npx;
  3000.                     rcDest.y = npy;
  3001.                     rcDest.w = 24;
  3002.                     rcDest.h = 24;
  3003.  
  3004.                     if(npcinfo[i].pause > ticks && npcinfo[i].shake < ticks) {
  3005.                         npcinfo[i].shake = ticks + 50;
  3006.                         rcDest.x = rcDest.x + (int)(RND() * 3) - 1;
  3007.                         rcDest.y = rcDest.y + (int)(RND() * 3) - 1;
  3008.                     }
  3009.  
  3010.                     SDL_BlitSurface(anims[sprite], &rcSrc, videobuffer, &rcDest);
  3011.                 }
  3012.  
  3013.                 // wizard
  3014.                 if(npcinfo[i].spriteset == 7) {
  3015.                     // if(npcinfo[i].attacking == 0) {
  3016.                         int cframe = npcinfo[i].cframe;
  3017.  
  3018.                         rcSrc.x = (int)(cframe / 4) * 24;
  3019.                         rcSrc.y = wdir * 24;
  3020.                         rcSrc.w = 24;
  3021.                         rcSrc.h = 24;
  3022.  
  3023.                         rcDest.x = npx;
  3024.                         rcDest.y = npy;
  3025.                         rcDest.w = 24;
  3026.                         rcDest.h = 24;
  3027.  
  3028.                         if(npcinfo[i].pause > ticks && npcinfo[i].shake < ticks) {
  3029.                             npcinfo[i].shake = ticks + 50;
  3030.                             rcDest.x = rcDest.x + (int)(RND() * 3) - 1;
  3031.                             rcDest.y = rcDest.y + (int)(RND() * 3) - 1;
  3032.                         }
  3033.                         SDL_BlitSurface(anims[sprite], &rcSrc, videobuffer, &rcDest);
  3034.                     // } else {
  3035.                         //cframe = npcinfo[i].cattackframe;
  3036.  
  3037.                         //rcSrc.x = (int)(cframe / 4) * 24;
  3038.                         //rcSrc.y = wdir * 24;
  3039.                         //rcSrc.w = 24;
  3040.                         //rcSrc.h = 24;
  3041.  
  3042.                         //rcDest.x = npx;
  3043.                         //rcDest.y = npy;
  3044.                         //rcDest.w = 24;
  3045.                         //rcDest.h = 24;
  3046.                     // SDL_BlitSurface(animsa(sprite), &rcSrc, videobuffer, &rcDest);
  3047.                     // }
  3048.                 }
  3049.  
  3050.  
  3051.                 // yellow dragon
  3052.                 if(npcinfo[i].spriteset == 8) {
  3053.                     int cframe = npcinfo[i].cframe;
  3054.  
  3055.                     rcSrc.x = (int)(cframe / 4) * 24;
  3056.                     rcSrc.y = wdir * 24;
  3057.                     rcSrc.w = 24;
  3058.                     rcSrc.h = 24;
  3059.  
  3060.                     rcDest.x = npx;
  3061.                     rcDest.y = npy;
  3062.                     rcDest.w = 24;
  3063.                     rcDest.h = 24;
  3064.  
  3065.                     if(npcinfo[i].pause > ticks && npcinfo[i].shake < ticks) {
  3066.                         npcinfo[i].shake = ticks + 50;
  3067.                         rcDest.x = rcDest.x + (int)(RND() * 3) - 1;
  3068.                         rcDest.y = rcDest.y + (int)(RND() * 3) - 1;
  3069.                     }
  3070.                     SDL_BlitSurface(anims[sprite], &rcSrc, videobuffer, &rcDest);
  3071.                 }
  3072.  
  3073.  
  3074.                 // dragon2
  3075.                 if(npcinfo[i].spriteset == 10) {
  3076.                     if(npcinfo[i].attacking == 0) {
  3077.                         npcinfo[i].floating = npcinfo[i].floating + 0.25 * fpsr;
  3078.                         while(npcinfo[i].floating >= 16) npcinfo[i].floating = npcinfo[i].floating - 16;
  3079.  
  3080.                         float frame = npcinfo[i].frame;
  3081.                         int cframe = npcinfo[i].cframe;
  3082.  
  3083.                         frame = frame + 0.5 * fpsr;
  3084.                         while(frame >= 16)
  3085.                             frame = frame - 16;
  3086.  
  3087.                         cframe = (int)(frame);
  3088.                         if(cframe > 16) cframe = 16 - 1;
  3089.                         if(cframe < 0) cframe = 0;
  3090.  
  3091.                         npcinfo[i].frame = frame;
  3092.                         npcinfo[i].cframe = cframe;
  3093.  
  3094.                         cframe = npcinfo[i].cframe;
  3095.  
  3096.                         rcSrc.x = 74 * wdir;
  3097.                         rcSrc.y = (int)(cframe / 4) * 48;
  3098.                         rcSrc.w = 74;
  3099.                         rcSrc.h = 48;
  3100.  
  3101.                         rcDest.x = npx + 12 - 37;
  3102.                         rcDest.y = (float)(npy + 12 - 32 - 3 * sin(3.141592 * 2 * npcinfo[i].floating / 16));
  3103.                         rcDest.w = 24;
  3104.                         rcDest.h = 24;
  3105.  
  3106.                         if(npcinfo[i].pause > ticks && npcinfo[i].shake < ticks) {
  3107.                             npcinfo[i].shake = ticks + 50;
  3108.                             rcDest.x = rcDest.x + (int)(RND() * 3) - 1;
  3109.                             rcDest.y = rcDest.y + (int)(RND() * 3) - 1;
  3110.                         }
  3111.  
  3112.                         SDL_BlitSurface(anims[sprite], &rcSrc, videobuffer, &rcDest);
  3113.                     } else {
  3114.                         npcinfo[i].floating = npcinfo[i].floating + 0.25 * fpsr;
  3115.                         while(npcinfo[i].floating >= 16) npcinfo[i].floating = npcinfo[i].floating - 16;
  3116.  
  3117.                         int cframe = npcinfo[i].cattackframe;
  3118.  
  3119.                         rcSrc.x = 74 * wdir;
  3120.                         rcSrc.y = (int)(cframe / 4) * 48;
  3121.                         rcSrc.w = 74;
  3122.                         rcSrc.h = 48;
  3123.  
  3124.                         rcDest.x = npx + 12 - 37;
  3125.                         rcDest.y = (float)(npy + 12 - 32 - 3 * sin(3.141592 * 2 * npcinfo[i].floating / 16));
  3126.                         rcDest.w = 24;
  3127.                         rcDest.h = 24;
  3128.  
  3129.                         SDL_BlitSurface(animsa[sprite], &rcSrc, videobuffer, &rcDest);
  3130.                     }
  3131.                 }
  3132.  
  3133.                 // end boss
  3134.                 if(npcinfo[i].spriteset == 11) {
  3135.  
  3136.                     npcinfo[i].floating = npcinfo[i].floating + .3 * fpsr;
  3137.                     while(npcinfo[i].floating >= 16) npcinfo[i].floating = npcinfo[i].floating - 16;
  3138.  
  3139.  
  3140.                     float frame = npcinfo[i].frame2;
  3141.                     int cframe = npcinfo[i].cframe;
  3142.  
  3143.                     frame = frame + 0.5 * fpsr;
  3144.                     while(frame >= 16)
  3145.                         frame = frame - 16;
  3146.  
  3147.                     npcinfo[i].frame2 = frame;
  3148.  
  3149.                     cframe = (int)(frame);
  3150.  
  3151.                     int sx = npx + 12 - 40;
  3152.                     int sy = (float)(npy + 12 - 50 - 3 * sin(3.141592 * 2 * npcinfo[i].floating / 16));
  3153.  
  3154.                     for(int fr = 0; fr <= 3; fr++) {
  3155.                         SDL_SetAlpha(spellimg, SDL_SRCALPHA, 128 + (int)(RND() * 96));
  3156.  
  3157.                         rcSrc.x = 16 * (int)(RND() * 2);
  3158.                         rcSrc.y = 80;
  3159.                         rcSrc.w = 16;
  3160.                         rcSrc.h = 16;
  3161.  
  3162.                         rcDest.x = sx + 32 + (int)(RND() * 3) - 1;
  3163.                         rcDest.y = sy - (int)(RND() * 6);
  3164.  
  3165.                         SDL_BlitSurface(spellimg, &rcSrc, videobuffer, &rcDest);
  3166.                     }
  3167.  
  3168.                     for(int ii = 0; ii <= 8; ii++) {
  3169.                         for(int i2 = 0; i2 <= 3; i2++) {
  3170.                             rcSrc.x = 16 * (int)(RND() * 2);
  3171.                             rcSrc.y = 80;
  3172.                             rcSrc.w = 16;
  3173.                             rcSrc.h = 16;
  3174.  
  3175.                             float fr3 = frame - 3 + i2;
  3176.                             if(fr3 < 0) fr3 = fr3 + 16;
  3177.  
  3178.                             rcDest.x = (float)(sx + 36 + ii * 8 - ii * cos(3.14159 * 2 * (fr3 - ii) / 16) * 2);
  3179.                             rcDest.y = (float)(sy + 16 + ii * sin(3.14159 * 2 * (fr3 - ii) / 16) * 3 - ii); //  * 4
  3180.  
  3181.                             SDL_SetAlpha(spellimg, SDL_SRCALPHA, i2 / 3 * 224);
  3182.  
  3183.                             SDL_BlitSurface(spellimg, &rcSrc, videobuffer, &rcDest);
  3184.  
  3185.                             int xloc = rcDest.x;
  3186.                             int yloc = rcDest.y;
  3187.                             int xdif = (xloc + 8) - (player.px + 12);
  3188.                             int ydif = (yloc + 8) - (player.py + 12);
  3189.  
  3190.                             if((abs(xdif) < 8 && abs(ydif) < 8) && player.pause < ticks) {
  3191.                                 float damage = (float)npcinfo[i].spelldamage * (1.0 + RND() * 0.5);
  3192.  
  3193.                                 if(player.hp > 0) {
  3194.                                     game_damageplayer(damage);
  3195.                                     if(menabled == 1 && opeffects == 1) {
  3196.                                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndfire))
  3197.                                         //FSOUND_setVolume(snd, opeffectsvol)
  3198.                                     }
  3199.                                 }
  3200.  
  3201.                             }
  3202.  
  3203.  
  3204.                             rcDest.x = (float)(sx + 36 - ii * 8 + ii * cos(3.14159 * 2 * (fr3 - ii) / 16) * 2);
  3205.                             rcDest.y = (float)(sy + 16 + ii * sin(3.14159 * 2 * (fr3 - ii) / 16) * 3 - ii); //  * 4
  3206.  
  3207.                             SDL_SetAlpha(spellimg, SDL_SRCALPHA, i2 / 3 * 224);
  3208.  
  3209.                             SDL_BlitSurface(spellimg, &rcSrc, videobuffer, &rcDest);
  3210.  
  3211.                             xloc = rcDest.x;
  3212.                             yloc = rcDest.y;
  3213.                             xdif = (xloc + 8) - (player.px + 12);
  3214.                             ydif = (yloc + 8) - (player.py + 12);
  3215.  
  3216.                             if((abs(xdif) < 8 && abs(ydif) < 8) && player.pause < ticks) {
  3217.                                 float damage = (float)npcinfo[i].spelldamage * (1.0 + RND() * 0.5);
  3218.  
  3219.                                 if(player.hp > 0) {
  3220.                                     game_damageplayer(damage);
  3221.                                     if(menabled == 1 && opeffects == 1) {
  3222.                                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndfire))
  3223.                                         //FSOUND_setVolume(snd, opeffectsvol)
  3224.                                     }
  3225.                                 }
  3226.                             }
  3227.                         }
  3228.                     }
  3229.  
  3230.                     SDL_SetAlpha(spellimg, SDL_SRCALPHA, 255);
  3231.  
  3232.                     if(npcinfo[i].attacking == 0) {
  3233.                         int cframe = (int)(frame);
  3234.                         rcSrc.x = 0;
  3235.                         rcSrc.y = 72 * (int)(cframe / 4);
  3236.                         rcSrc.w = 80;
  3237.                         rcSrc.h = 72;
  3238.  
  3239.                         rcDest.x = sx;
  3240.                         rcDest.y = sy;
  3241.  
  3242.                         if(npcinfo[i].pause > ticks && npcinfo[i].shake < ticks) {
  3243.                             npcinfo[i].shake = ticks + 50;
  3244.                             rcDest.x = rcDest.x + (int)(RND() * 3) - 1;
  3245.                             rcDest.y = rcDest.y + (int)(RND() * 3) - 1;
  3246.                         }
  3247.  
  3248.                         SDL_BlitSurface(anims[sprite], &rcSrc, videobuffer, &rcDest);
  3249.                     } else {
  3250.                         int cframe = (int)(npcinfo[i].cattackframe);
  3251.  
  3252.                         rcSrc.x = 0;
  3253.                         rcSrc.y = 72 * (int)(cframe / 4);
  3254.                         rcSrc.w = 80;
  3255.                         rcSrc.h = 72;
  3256.  
  3257.                         rcDest.x = sx;
  3258.                         rcDest.y = sy;
  3259.  
  3260.                         SDL_BlitSurface(animsa[sprite], &rcSrc, videobuffer, &rcDest);
  3261.                     }
  3262.                 }
  3263.  
  3264.                 // bat kitty
  3265.                 if(npcinfo[i].spriteset == 12) {
  3266.                     npcinfo[i].floating = npcinfo[i].floating + 1 * fpsr;
  3267.                     while(npcinfo[i].floating >= 16) npcinfo[i].floating = npcinfo[i].floating - 16;
  3268.  
  3269.                     float frame = npcinfo[i].frame;
  3270.                     int cframe = npcinfo[i].cframe;
  3271.  
  3272.                     frame = frame + 0.5 * fpsr;
  3273.                     while(frame >= 16)
  3274.                         frame = frame - 16;
  3275.  
  3276.                     cframe = (int)(frame);
  3277.                     if(cframe > 16) cframe = 16 - 1;
  3278.                     if(cframe < 0) cframe = 0;
  3279.  
  3280.                     npcinfo[i].frame = frame;
  3281.                     npcinfo[i].cframe = cframe;
  3282.  
  3283.                     cframe = npcinfo[i].cframe;
  3284.  
  3285.                     rcSrc.x = 0;
  3286.                     rcSrc.y = 0;
  3287.                     rcSrc.w = 99;
  3288.                     rcSrc.h = 80;
  3289.  
  3290.                     rcDest.x = npx + 12 - 50;
  3291.                     rcDest.y = (float)(npy + 12 - 64 + 2 * sin(3.141592 * 2 * npcinfo[i].floating / 16));
  3292.                     rcDest.w = 99;
  3293.                     rcDest.h = 80;
  3294.  
  3295.                     if(npcinfo[i].pause > ticks && npcinfo[i].shake < ticks) {
  3296.                         npcinfo[i].shake = ticks + 50;
  3297.                         rcDest.x = rcDest.x + (int)(RND() * 3) - 1;
  3298.                         rcDest.y = rcDest.y + (int)(RND() * 3) - 1;
  3299.                     }
  3300.  
  3301.                     SDL_BlitSurface(anims[sprite], &rcSrc, videobuffer, &rcDest);
  3302.                 }
  3303.  
  3304.                 rcDest.x = npx + 4;
  3305.                 rcDest.y = npy + 22;
  3306.                 rcDest.w = 16;
  3307.                 rcDest.h = 4;
  3308.  
  3309.                 SDL_FillRect(videobuffer, &rcDest, 0);
  3310.  
  3311.                 rcDest.x = npx + 5;
  3312.                 rcDest.y = npy + 23;
  3313.  
  3314.  
  3315.                 int ww = 14 * npcinfo[i].hp / npcinfo[i].maxhp;
  3316.                 if(ww > 14) ww = 14;
  3317.                 if(ww < 1) ww = 1;
  3318.  
  3319.                 rcDest.w = ww;
  3320.                 rcDest.h = 2;
  3321.  
  3322.  
  3323.                 SDL_FillRect(videobuffer, &rcDest, ccc);
  3324.  
  3325.                 int pass = 1;
  3326.  
  3327.                 if(npcinfo[i].spriteset == 3) pass = 0;
  3328.                 if(pass == 1) game_drawover(npx, npy);
  3329.  
  3330.             }
  3331.         }
  3332.     }
  3333. }
  3334.  
  3335. void game_drawover(int modx, int mody)
  3336. {
  3337.     int npx = modx + 12;
  3338.     int npy = mody + 20;
  3339.  
  3340.     int lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  3341.     int ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  3342.  
  3343.     for(int xo = -1; xo <= 1; xo++) {
  3344.         for(int yo = -1; yo <= 1; yo++) {
  3345.  
  3346.             int sx = lx + xo;
  3347.             int sy = ly + yo;
  3348.  
  3349.             int sx2 = sx * 16;
  3350.             int sy2 = sy * 16;
  3351.  
  3352.             if(sx > -1 && sx < 40 && sy > -1 && sy < 24) {
  3353.  
  3354.                 int curtile = tileinfo[2][sx][sy][0];
  3355.                 int curtilel = tileinfo[2][sx][sy][1];
  3356.  
  3357.                 if(curtile > 0) {
  3358.                     curtile = curtile - 1;
  3359.                     int curtilex = curtile % 20;
  3360.                     int curtiley = (curtile - curtilex) / 20;
  3361.  
  3362.                     rcSrc.x = curtilex * 16;
  3363.                     rcSrc.y = curtiley * 16;
  3364.                     rcSrc.w = 16;
  3365.                     rcSrc.h = 16;
  3366.  
  3367.                     rcDest.x = sx2;
  3368.                     rcDest.y = sy2;
  3369.                     rcDest.w = 16;
  3370.                     rcDest.h = 16;
  3371.  
  3372.                     int pass = 1;
  3373.                     if(curtilel == 1) {
  3374.                         for(int ff = 0; ff <= 5; ff++) {
  3375.                             int ffa = 20 * 5 - 1 + ff * 20;
  3376.                             int ffb = 20 * 5 + 4 + ff * 20;
  3377.                             if(curtile > ffa && curtile < ffb) pass = 0;
  3378.                         }
  3379.                     }
  3380.  
  3381.                     if(pass == 1) SDL_BlitSurface(tiles[curtilel], &rcSrc, videobuffer, &rcDest);
  3382.                 }
  3383.             }
  3384.         }
  3385.     }
  3386. }
  3387.  
  3388. void game_drawplayer()
  3389. {
  3390.     long ccc;
  3391.  
  3392.     int f = 0;
  3393.     if(player.armour == 3) f = 13;
  3394.  
  3395.     if(attacking == 0) {
  3396.         rcSrc.x = (int)(player.walkframe / 4) * 24;
  3397.         rcSrc.y = player.walkdir * 24;
  3398.         rcSrc.w = 24;
  3399.         rcSrc.h = 24;
  3400.  
  3401.         rcDest.x = (int)(player.px);
  3402.         rcDest.y = (int)(player.py);
  3403.         rcDest.w = 24;
  3404.         rcDest.h = 24;
  3405.  
  3406.         SDL_BlitSurface(anims[f], &rcSrc, videobuffer, &rcDest);
  3407.     } else {
  3408.         rcSrc.x = (int)(player.attackframe / 4) * 24;
  3409.         rcSrc.y = player.walkdir * 24;
  3410.         rcSrc.w = 24;
  3411.         rcSrc.h = 24;
  3412.  
  3413.         rcDest.x = (int)(player.px);
  3414.         rcDest.y = (int)(player.py);
  3415.         rcDest.w = 24;
  3416.         rcDest.h = 24;
  3417.  
  3418.         SDL_BlitSurface(animsa[f], &rcSrc, videobuffer, &rcDest);
  3419.  
  3420.     }
  3421.  
  3422.     ccc = SDL_MapRGB(videobuffer->format, 224, 224, 64);
  3423.  
  3424.     int pass = 0;
  3425.     if(player.hp <= player.maxhp * 0.25) pass = 1;
  3426.  
  3427.     if(pass == 1) {
  3428.         ccc = SDL_MapRGB(videobuffer->format, 255, 255, 255);
  3429.         if((int)(player.hpflash) == 1) ccc = SDL_MapRGB(videobuffer->format, 255, 0, 0);
  3430.     }
  3431.  
  3432.     int sss = 6;
  3433.     if(player.foundcrystal) sss = 8;
  3434.     int npx = player.px;
  3435.     int npy = player.py;
  3436.     rcDest.x = npx + 4;
  3437.     rcDest.y = npy + 22;
  3438.     rcDest.w = 16;
  3439.     rcDest.h = sss;
  3440.  
  3441.     SDL_FillRect(videobuffer, &rcDest, 0);
  3442.  
  3443.     rcDest.x = npx + 5;
  3444.     rcDest.y = npy + 23;
  3445.  
  3446.  
  3447.     int ww = 14 * player.hp / player.maxhp;
  3448.     if(ww > 14) ww = 14;
  3449.     if(ww < 1) ww = 1;
  3450.  
  3451.     rcDest.w = ww;
  3452.     rcDest.h = 2;
  3453.  
  3454.     SDL_FillRect(videobuffer, &rcDest, ccc);
  3455.  
  3456.     ccc = SDL_MapRGB(videobuffer->format, 0, 224, 64);
  3457.     if(player.attackstrength == 100) ccc = SDL_MapRGB(videobuffer->format, 255, 128, 32);
  3458.  
  3459.     ww = 14 * player.attackstrength / 100;
  3460.     if(ww > 14) ww = 14;
  3461.  
  3462.     int ww2 = 14 * player.spellstrength / 100;
  3463.     if(ww2 > 14) ww2 = 14;
  3464.  
  3465.     rcDest.w = ww;
  3466.     rcDest.h = 2;
  3467.     rcDest.y = rcDest.y + 2;
  3468.  
  3469.     SDL_FillRect(videobuffer, &rcDest, ccc);
  3470.  
  3471.     ccc = SDL_MapRGB(videobuffer->format, 128, 0, 224);
  3472.     if(player.spellstrength == 100) ccc = SDL_MapRGB(videobuffer->format, 224, 0, 0);
  3473.  
  3474.     rcDest.w = ww2;
  3475.     rcDest.h = 2;
  3476.     rcDest.y = rcDest.y + 2;
  3477.  
  3478.     SDL_FillRect(videobuffer, &rcDest, ccc);
  3479. }
  3480.  
  3481. void game_drawview()
  3482. {
  3483.     SDL_BlitSurface(mapbg, NULL, videobuffer, NULL);
  3484.  
  3485.     game_updspellsunder();
  3486.  
  3487.     game_drawanims(0);
  3488.  
  3489.     // ------dontdrawover = special case to make boss work right in room 24
  3490.     if(dontdrawover == 1) game_drawanims(1);
  3491.     game_drawnpcs(0);
  3492.  
  3493.     game_drawplayer();
  3494.  
  3495.     game_drawnpcs(1);
  3496.     if(dontdrawover == 0) game_drawanims(1);
  3497.  
  3498.     game_drawover((int)player.px, (int)player.py);
  3499.  
  3500.     game_updspells();
  3501.  
  3502.     if(cloudson == 1) {
  3503.         rcDest.x = (float)(256 + 256 * cos(3.141592 / 180 * clouddeg));
  3504.         rcDest.y = (float)(192 + 192 * sin(3.141592 / 180 * clouddeg));
  3505.         rcDest.w = 320;
  3506.         rcDest.h = 240;
  3507.  
  3508.         SDL_BlitSurface(cloudimg, &rcDest, videobuffer, NULL);
  3509.     }
  3510.  
  3511.     game_drawhud();
  3512.  
  3513.     rcDest.x = SCR_TOPX;
  3514.     rcDest.y = SCR_TOPY;
  3515.  
  3516.     SDL_BlitSurface(videobuffer, NULL, video, &rcDest);
  3517. }
  3518.  
  3519. void game_endofgame()
  3520. {
  3521.     float xofs;
  3522.     int ticks1, bticks, pauseticks, keypause;
  3523.  
  3524.     rcSrc.x = 0;
  3525.     rcSrc.y = 0;
  3526.     rcSrc.w = 320;
  3527.     rcSrc.h = 240;
  3528.  
  3529.     rc.x = 0;
  3530.     rc.y = 0;
  3531.     rc.w = 320;
  3532.     rc.h = 240;
  3533.  
  3534.     rc2.x = SCR_TOPX;
  3535.     rc2.y = SCR_TOPY;
  3536.     rc2.w = 320;
  3537.     rc2.h = 240;
  3538.  
  3539.     //x = 160 - 4 * len(stri$)
  3540.  
  3541.     ticks = SDL_GetTicks();
  3542.     pauseticks = ticks + 500;
  3543.     bticks = ticks;
  3544.  
  3545.     keypause = ticks + 220;
  3546.  
  3547.     float spd = 0.2;
  3548.  
  3549.     if(menabled == 1 && opmusic == 1) {
  3550.         //FSOUND_stopSound(FSOUND_ALL)
  3551.         //musicchannel = FSOUND_playSound(FSOUND_FREE, mendofgame)
  3552.         //FSOUND_setVolume(musicchannel, 0)
  3553.     }
  3554.  
  3555.     ticks1 = ticks;
  3556.     int ya = 0;
  3557.  
  3558.     SDL_FillRect(videobuffer2, &rc, 0);
  3559.     SDL_FillRect(videobuffer3, &rc, 0);
  3560.     SDL_BlitSurface(videobuffer, &rc, videobuffer2, &rc);
  3561.  
  3562.     do {
  3563.         float ld = ld + 4 * fpsr;
  3564.         if(ld > opmusicvol) ld = opmusicvol;
  3565.         if(menabled == 1 /*&& ldstop == 0*/) {
  3566.             //FSOUND_setVolume(musicchannel, ld!)
  3567.             //if(ld! = opmusicvol) ldstop = 1
  3568.         }
  3569.  
  3570.         ya = 0;
  3571.         if(ticks < ticks1 + 1500) {
  3572.             ya = (255 * (ticks - ticks1)) / 1500;
  3573.             if(ya < 0) ya = 0;
  3574.             if(ya > 255) ya = 255;
  3575.         } else {
  3576.             break;
  3577.         }
  3578.  
  3579.         SDL_FillRect(videobuffer, &rc, 0);
  3580.  
  3581.         SDL_SetAlpha(videobuffer, SDL_SRCALPHA, ya);
  3582.         SDL_BlitSurface(videobuffer2, &rc, videobuffer3, &rc);
  3583.         SDL_BlitSurface(videobuffer, &rc, videobuffer3, &rc);
  3584.         SDL_BlitSurface(videobuffer3, &rc, video, &rc2);
  3585.         SDL_SetAlpha(videobuffer, SDL_SRCALPHA, 255);
  3586.  
  3587.         SDL_Flip(video);
  3588.         SDL_PumpEvents();
  3589.  
  3590.         tickspassed = ticks;
  3591.         ticks = SDL_GetTicks();
  3592.  
  3593.         tickspassed = ticks - tickspassed;
  3594.         fpsr = (float)tickspassed / 24;
  3595.  
  3596.         fp = fp + 1;
  3597.         if(ticks > nextticks) {
  3598.             nextticks = ticks + 1000;
  3599.             fps = fp;
  3600.             fp = 0;
  3601.         }
  3602.     } while(1);
  3603.  
  3604.     ticks1 = ticks;
  3605.     ya = 0;
  3606.     float y = 140;
  3607.  
  3608.     do {
  3609.         rc.x = -xofs;
  3610.         rc.y = 0;
  3611.  
  3612.         SDL_BlitSurface(titleimg, &rcSrc, videobuffer, &rc);
  3613.  
  3614.         rc.x = -xofs + 320;
  3615.         rc.y = 0;
  3616.  
  3617.         SDL_BlitSurface(titleimg, &rcSrc, videobuffer, &rc);
  3618.  
  3619.         rc.x = 0;
  3620.         rc.y = 0;
  3621.  
  3622.         y = y - spd * fpsr;
  3623.         for(int i = 0; i <= 26; i++) {
  3624.             int yy = y + i * 10;
  3625.             if(yy > -8 && yy < 240) {
  3626.                 int x = 160 - strlen(story2[i]) * 4;
  3627.                 sys_print(videobuffer, story2[i], x, yy, 4);
  3628.             }
  3629.  
  3630.             if(yy < 10 && i == 25) break;
  3631.         }
  3632.  
  3633.         rc.x = 0;
  3634.         rc.y = 0;
  3635.         rc.w = 320;
  3636.         rc.h = 240;
  3637.  
  3638.         int ya = 255;
  3639.         if(ticks < ticks1 + 1000) {
  3640.             ya = 255 * (ticks - ticks1) / 1000;
  3641.             if(ya < 0) ya = 0;
  3642.             if(ya > 255) ya = 255;
  3643.         }
  3644.  
  3645.         SDL_SetAlpha(videobuffer, SDL_SRCALPHA, ya);
  3646.         SDL_BlitSurface(videobuffer, &rc, video, &rc2);
  3647.         SDL_SetAlpha(videobuffer, SDL_SRCALPHA, 255);
  3648.  
  3649.         SDL_Flip(video);
  3650.         SDL_PumpEvents();
  3651.  
  3652.         tickspassed = ticks;
  3653.         ticks = SDL_GetTicks();
  3654.  
  3655.         tickspassed = ticks - tickspassed;
  3656.         fpsr = (float)tickspassed / 24;
  3657.  
  3658.         fp = fp + 1;
  3659.         if(ticks > nextticks) {
  3660.             nextticks = ticks + 1000;
  3661.             fps = fp;
  3662.             fp = 0;
  3663.         }
  3664.  
  3665.         float add = 0.5 * fpsr;
  3666.         if(add > 1) add = 1;
  3667.         xofs = xofs + add;
  3668.         if(xofs >= 320) xofs = xofs - 320;
  3669.  
  3670.         SDL_PollEvent(&event);
  3671.         keys = SDL_GetKeyState(NULL);
  3672.  
  3673.         if(event.type == SDL_KEYDOWN) spd = 1;
  3674.         if(event.type == SDL_KEYUP) spd = 0.2;
  3675.  
  3676.         if(keys[SDLK_ESCAPE]) break;
  3677.     } while(1);
  3678.  
  3679.  
  3680.     rc.x = 0;
  3681.     rc.y = 0;
  3682.     rc.w = 320;
  3683.     rc.h = 240;
  3684.  
  3685.     ticks1 = ticks;
  3686.     y = 0;
  3687.  
  3688.     SDL_BlitSurface(videobuffer, &rc, videobuffer2, &rc);
  3689.  
  3690.     do {
  3691.         if(ticks < ticks1 + 1500) {
  3692.             int y = 255 * (ticks - ticks1) / 1500;
  3693.             if(y < 0) y = 0;
  3694.             if(y > 255) y = 255;
  3695.         else
  3696.             break;
  3697.         }
  3698.  
  3699.         SDL_FillRect(videobuffer, &rc, 0);
  3700.  
  3701.         SDL_SetAlpha(videobuffer, SDL_SRCALPHA, y);
  3702.         SDL_BlitSurface(videobuffer2, &rc, videobuffer3, &rc);
  3703.         SDL_BlitSurface(videobuffer, &rc, videobuffer3, &rc);
  3704.         SDL_BlitSurface(videobuffer3, &rc, video, &rc2);
  3705.         SDL_SetAlpha(videobuffer, SDL_SRCALPHA, 255);
  3706.  
  3707.         SDL_Flip(video);
  3708.         SDL_PumpEvents();
  3709.  
  3710.         tickspassed = ticks;
  3711.         ticks = SDL_GetTicks();
  3712.  
  3713.         tickspassed = ticks - tickspassed;
  3714.         fpsr = (float)tickspassed / 24;
  3715.  
  3716.         fp = fp + 1;
  3717.         if(ticks > nextticks) {
  3718.             nextticks = ticks + 1000;
  3719.             fps = fp;
  3720.             fp = 0;
  3721.         }
  3722.     } while(1);
  3723.  
  3724.  
  3725.     int keywait = 2000 + ticks;
  3726.  
  3727.     ticks1 = ticks;
  3728.     y = 0;
  3729.     do {
  3730.  
  3731.         SDL_BlitSurface(theendimg, &rcSrc, videobuffer, &rc);
  3732.  
  3733.         y = 255;
  3734.         if(ticks < ticks1 + 1000) {
  3735.             y = 255 * (ticks - ticks1) / 1000;
  3736.             if(y < 0) y = 0;
  3737.             if(y > 255) y = 255;
  3738.         }
  3739.  
  3740.         SDL_SetAlpha(videobuffer, SDL_SRCALPHA, y);
  3741.         SDL_BlitSurface(videobuffer, &rc, video, &rc2);
  3742.         SDL_SetAlpha(videobuffer, SDL_SRCALPHA, 255);
  3743.  
  3744.             SDL_Flip(video);
  3745.             SDL_PumpEvents();
  3746.  
  3747.             tickspassed = ticks;
  3748.             ticks = SDL_GetTicks();
  3749.  
  3750.             tickspassed = ticks - tickspassed;
  3751.             fpsr = (float)tickspassed / 24;
  3752.  
  3753.             fp = fp + 1;
  3754.             if(ticks > nextticks) {
  3755.                 nextticks = ticks + 1000;
  3756.                 fps = fp;
  3757.                 fp = 0;
  3758.             }
  3759.  
  3760.             SDL_PollEvent(&event);
  3761.             keys = SDL_GetKeyState(NULL);
  3762.  
  3763.             if(event.type == SDL_KEYDOWN && keywait < ticks) break;
  3764.  
  3765.     } while(1);
  3766.  
  3767.     SDL_FillRect(videobuffer2, &rc, 0);
  3768.     SDL_FillRect(videobuffer3, &rc, 0);
  3769.  
  3770.     game_theend();
  3771.  
  3772. }
  3773.  
  3774. void game_eventtext(char *stri)
  3775. {
  3776.     int x, fr, pauseticks, bticks;
  3777.  
  3778.     rcSrc.x = 0;
  3779.     rcSrc.y = 0;
  3780.     rcSrc.w = 320;
  3781.     rcSrc.h = 240;
  3782.  
  3783.     SDL_FillRect(videobuffer2, &rcSrc, 0);
  3784.     SDL_FillRect(videobuffer3, &rcSrc, 0);
  3785.  
  3786.     rc.x = 0;
  3787.     rc.y = 0;
  3788.  
  3789.     rc2.x = SCR_TOPX;
  3790.     rc2.y = SCR_TOPY;
  3791.     rc2.w = 320;
  3792.     rc2.h = 240;
  3793.  
  3794.     x = 160 - 4 * strlen(stri);
  3795.  
  3796.     ticks = SDL_GetTicks();
  3797.     pauseticks = ticks + 500;
  3798.     bticks = ticks;
  3799.  
  3800.     SDL_BlitSurface(videobuffer, NULL, videobuffer3, NULL);
  3801.     SDL_BlitSurface(video, &rc2, videobuffer2, NULL);
  3802.  
  3803.     do {
  3804.         SDL_PollEvent(&event);
  3805.         keys = SDL_GetKeyState(NULL);
  3806.  
  3807.         if(event.type == SDL_KEYDOWN && pauseticks < ticks) break;
  3808.         SDL_BlitSurface(videobuffer2, NULL, videobuffer, NULL);
  3809.  
  3810.         fr = 192;
  3811.  
  3812.         if(pauseticks > ticks) fr = 192 * (ticks - bticks) / 500;
  3813.         if(fr > 192) fr = 192;
  3814.  
  3815.         SDL_SetAlpha(windowimg, SDL_SRCALPHA, fr);
  3816.  
  3817.         SDL_BlitSurface(windowimg, NULL, videobuffer, &rc);
  3818.         if(pauseticks < ticks) sys_print(videobuffer, stri, x, 15, 0);
  3819.  
  3820.         SDL_SetAlpha(windowimg, SDL_SRCALPHA, 255);
  3821.         SDL_BlitSurface(videobuffer, NULL, video, &rc2);
  3822.  
  3823.         SDL_Flip(video);
  3824.         SDL_PumpEvents();
  3825.  
  3826.         tickspassed = ticks;
  3827.         ticks = SDL_GetTicks();
  3828.  
  3829.         tickspassed = ticks - tickspassed;
  3830.         fpsr = (float)tickspassed / 24.0;
  3831.  
  3832.         fp = fp + 1;
  3833.         if(ticks > nextticks) {
  3834.             nextticks = ticks + 1000;
  3835.             fps = fp;
  3836.             fp = 0;
  3837.         }
  3838.  
  3839.         SDL_Delay(10);
  3840.     } while(1);
  3841.  
  3842.     SDL_BlitSurface(videobuffer3, NULL, videobuffer, NULL);
  3843.  
  3844.     itemticks = ticks + 210;
  3845. }
  3846.  
  3847.  
  3848. void game_handlewalking()
  3849. {
  3850.     unsigned int *temp/*, c*/, bgc;
  3851.     float spd, /*ppx, ppy,*/ px, py, opx, opy;
  3852.     float nx, ny, npx, npy;
  3853.  
  3854.     int xmax = 20 * 16 - 25;
  3855.     int ymax = 15 * 16 - 25;
  3856.  
  3857.     px = player.px;
  3858.     py = player.py;
  3859.     opx = px;
  3860.     opy = py;
  3861.  
  3862.     spd = player.walkspd * fpsr;
  3863.  
  3864.     nx = (px / 2 + 6);
  3865.     ny = (py / 2 + 10);
  3866.  
  3867.     npx = px + 12;
  3868.     npy = py + 20;
  3869.     int lx = (int)npx / 16; //(npx - ((int)npx % 16)) / 16;
  3870.     int ly = (int)npy / 16; //(npy - ((int)npy % 16)) / 16;
  3871.  
  3872.     int ramp = rampdata[lx][ly];
  3873.     if(ramp == 1 && movingup) spd = spd * 2;
  3874.     if(ramp == 1 && movingdown) spd = spd * 2;
  3875.  
  3876.     if(ramp == 2 && movingleft) movingup = 1;
  3877.     if(ramp == 2 && movingright) movingdown = 1;
  3878.  
  3879.     if(ramp == 3 && movingright) movingup = 1;
  3880.     if(ramp == 3 && movingleft) movingdown = 1;
  3881.  
  3882.     for(int x = -1; x <= 1; x++) {
  3883.         for(int y = -1; y <= 1; y++) {
  3884.             int sx = nx + x;
  3885.             int sy = ny + y;
  3886.  
  3887.             clipsurround[x + 1][y + 1] = 0;
  3888.             if(sx > -1 && sx < 320 && sy > -1 && sy < 192) {
  3889.                 temp = clipbg->pixels + sy * clipbg->pitch + sx * clipbg->format->BytesPerPixel;
  3890.                 clipsurround[x + 1][y + 1] = *temp;
  3891.             }
  3892.         }
  3893.     }
  3894.  
  3895.     if(movingup) player.walkdir = 0;
  3896.     if(movingdown) player.walkdir = 1;
  3897.     if(movingleft) player.walkdir = 2;
  3898.     if(movingright) player.walkdir = 3;
  3899.  
  3900.     if(movingup && clipsurround[1][0] == 0) {
  3901.         py = py - spd;
  3902.         player.walkdir = 0;
  3903.     } else if(movingup && clipsurround[1][0] > 0) {
  3904.         // move upleft
  3905.         if(movingright == 0 && clipsurround[0][0] == 0) {
  3906.             py = py - spd;
  3907.             px = px - spd;
  3908.         }
  3909.  
  3910.         // move upright
  3911.         if(movingleft == 0 && clipsurround[2][0] == 0) {
  3912.             py = py - spd;
  3913.             px = px + spd;
  3914.         }
  3915.     }
  3916.     if(movingdown && clipsurround[1][2] == 0) {
  3917.         py = py + spd;
  3918.         player.walkdir = 1;
  3919.     } else if(movingdown && clipsurround[1][2] > 0) {
  3920.         // move downleft
  3921.         if(movingright == 0 && clipsurround[0][2] == 0) {
  3922.             py = py + spd;
  3923.             px = px - spd;
  3924.         }
  3925.  
  3926.         // move downright
  3927.         if(movingleft == 0 && clipsurround[2][2] == 0) {
  3928.             py = py + spd;
  3929.             px = px + spd;
  3930.         }
  3931.     }
  3932.     if(movingleft && clipsurround[0][1] == 0) {
  3933.         px = px - spd;
  3934.         player.walkdir = 2;
  3935.     } else if(movingleft && clipsurround[0][1] > 0) {
  3936.         // move leftup
  3937.         if(movingdown == 0 && clipsurround[0][0] == 0) {
  3938.             py = py - spd;
  3939.             px = px - spd;
  3940.         }
  3941.  
  3942.         // move leftdown
  3943.         if(movingup == 0 && clipsurround[0][2] == 0) {
  3944.             py = py + spd;
  3945.             px = px - spd;
  3946.         }
  3947.     }
  3948.     if(movingright && clipsurround[2][1] == 0) {
  3949.         px = px + spd;
  3950.         player.walkdir = 3;
  3951.     } else if(movingright && clipsurround[2][1] > 0) {
  3952.         // move rightup
  3953.         if(movingdown == 0 && clipsurround[2][0] == 0) {
  3954.             px = px + spd;
  3955.             py = py - spd;
  3956.         }
  3957.  
  3958.         // move rightdown
  3959.         if(movingup == 0 && clipsurround[2][2] == 0) {
  3960.             py = py + spd;
  3961.             px = px + spd;
  3962.         }
  3963.     }
  3964.  
  3965.     if(px < -8) px = -8;
  3966.     if(px > xmax) px = xmax;
  3967.     if(py < -8) py = -8;
  3968.     if(py > ymax) py = ymax;
  3969.  
  3970.     int pass = 1;
  3971.  
  3972.     int sx = (px / 2 + 6);
  3973.     int sy = (py / 2 + 10);
  3974.     temp = clipbg->pixels + sy * clipbg->pitch + sx * clipbg->format->BytesPerPixel;
  3975.     bgc = *temp;
  3976.     if(bgc > 0 && bgc != 1000) {
  3977.         px = opx;
  3978.         py = opy;
  3979.         pass = 0;
  3980.     }
  3981.  
  3982.     // push npc
  3983.     if(pass == 1) {
  3984.         for(int i = 1; i <= lastnpc; i++) {
  3985.             if(npcinfo[i].hp > 0) {
  3986.                 npx = npcinfo[i].x;
  3987.                 npy = npcinfo[i].y;
  3988.  
  3989.                 opx = npx;
  3990.                 opy = npy;
  3991.  
  3992.                 int xdif = player.px - npx;
  3993.                 int ydif = player.py - npy;
  3994.  
  3995.                 if(player.walkdir == 0) {
  3996.                     if(abs(xdif) <= 8 && ydif > 0 && ydif < 8) npcinfo[i].y = npcinfo[i].y - spd;
  3997.                 } else if(player.walkdir == 1) {
  3998.                     if(abs(xdif) <= 8 && ydif < 0 && ydif > -8) npcinfo[i].y = npcinfo[i].y + spd;
  3999.                 } else if(player.walkdir == 2) {
  4000.                     if(abs(ydif) <= 8 && xdif > 0 && xdif < 8) npcinfo[i].x = npcinfo[i].x - spd;
  4001.                 } else if(player.walkdir == 3) {
  4002.                     if(abs(ydif) <= 8 && xdif < 0 && xdif > -8) npcinfo[i].x = npcinfo[i].x + spd;
  4003.                 }
  4004.  
  4005.                 npx = npcinfo[i].x;
  4006.                 npy = npcinfo[i].y;
  4007.  
  4008.                 sx = (int)(npx / 2 + 6);
  4009.                 sy = (int)(npy / 2 + 10);
  4010.                 temp = clipbg->pixels + sy * clipbg->pitch + sx * clipbg->format->BytesPerPixel;
  4011.                 bgc = *temp;
  4012.  
  4013.                 if(bgc > 0) {
  4014.                     npcinfo[i].x = opx;
  4015.                     npcinfo[i].y = opy;
  4016.                 }
  4017.             }
  4018.         }
  4019.     }
  4020.  
  4021.     player.opx = player.px;
  4022.     player.opy = player.py;
  4023.     player.px = px;
  4024.     player.py = py;
  4025.  
  4026.     if(player.px != player.opx || player.py != player.opy) player.walkframe = player.walkframe + animspd * fpsr;
  4027.     if(player.walkframe >= 16) player.walkframe = player.walkframe - 16;
  4028.  
  4029.     // walking over items to pickup :::
  4030.     int o = objmap[lx][ly];
  4031.  
  4032.     if(o > -1) {
  4033.         // fsk
  4034.         if(objectinfo[o][4] == 2 && inventory[0] < 9) {
  4035.             objmap[lx][ly] = -1;
  4036.  
  4037.             inventory[0] = inventory[0] + 1;
  4038.             if(inventory[0] > 9) inventory[0] = 9;
  4039.             game_addFloatIcon(6, lx * 16, ly * 16);
  4040.  
  4041.             objmapf[curmap][lx][ly] = 1;
  4042.  
  4043.             if(menabled == 1 && opeffects == 1) {
  4044.                 //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndpowerup))
  4045.                 //FSOUND_setVolume(snd, opeffectsvol)
  4046.             }
  4047.         }
  4048.  
  4049.         if(objectinfo[o][5] == 7 && inventory[1] < 9) {
  4050.             objmap[lx][ly] = -1;
  4051.  
  4052.             inventory[1] = inventory[1] + 1;
  4053.             if(inventory[1] > 9) inventory[1] = 9;
  4054.             game_addFloatIcon(12, lx * 16, ly * 16);
  4055.  
  4056.             objmapf[curmap][lx][ly] = 1;
  4057.  
  4058.             if(menabled == 1 && opeffects == 1) {
  4059.                 //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndpowerup))
  4060.                 //FSOUND_setVolume(snd, opeffectsvol)
  4061.             }
  4062.         }
  4063.  
  4064.         if(objectinfo[o][5] == 9 && inventory[2] < 9 && (curmap == 41 && scriptflag[9][1] == 0)) {
  4065.             objmap[lx][ly] = -1;
  4066.  
  4067.             inventory[2] = inventory[2] + 1;
  4068.             if(inventory[2] > 9) inventory[2] = 9;
  4069.             game_addFloatIcon(17, lx * 16, ly * 16);
  4070.  
  4071.             objmapf[curmap][lx][ly] = 1;
  4072.             if(curmap == 41) scriptflag[9][1] = 1;
  4073.  
  4074.             if(menabled == 1 && opeffects == 1) {
  4075.                 //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndpowerup))
  4076.                 //FSOUND_setVolume(snd, opeffectsvol)
  4077.             }
  4078.  
  4079.         }
  4080.  
  4081.         if(objectinfo[o][5] == 9 && inventory[2] < 9) {
  4082.             objmap[lx][ly] = -1;
  4083.  
  4084.             inventory[2] = inventory[2] + 1;
  4085.             if(inventory[2] > 9) inventory[2] = 9;
  4086.             game_addFloatIcon(17, lx * 16, ly * 16);
  4087.  
  4088.             objmapf[curmap][lx][ly] = 1;
  4089.  
  4090.             if(menabled == 1 && opeffects == 1) {
  4091.                 //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndpowerup))
  4092.                 //FSOUND_setVolume(snd, opeffectsvol)
  4093.             }
  4094.  
  4095.         }
  4096.     }
  4097. }
  4098.  
  4099. void game_loadmap(int mapnum)
  4100. {
  4101. #define INPUT(A, B)             \
  4102.     do {                    \
  4103.         char line[256];         \
  4104.         fgets(line, sizeof(line), fp);  \
  4105.         sscanf(line, A, B);     \
  4106.     } while(0);
  4107.  
  4108.     unsigned int ccc;
  4109.     SDL_Rect trect;
  4110.     FILE *fp;
  4111.     char name[256];
  4112.     int tempmap[320][200];
  4113.  
  4114.     ccc = SDL_MapRGB(clipbg->format, 255,255,255);
  4115.  
  4116.     curmap = mapnum;
  4117.  
  4118.     trect.x = 0;
  4119.     trect.y = 0;
  4120.     trect.w = 320;
  4121.     trect.h = 240;
  4122.     SDL_FillRect(mapbg, &trect, 0);
  4123.     SDL_FillRect(clipbg, &trect, ccc);
  4124.     SDL_FillRect(clipbg2, &trect, ccc);
  4125.  
  4126.     forcepause = 0;
  4127.     cloudson = 0;
  4128.     if(mapnum < 6) cloudson = 1;
  4129.     if(mapnum > 41) cloudson = 1;
  4130.     if(mapnum > 47) cloudson = 0;
  4131.     if(mapnum == 52) cloudson = 1;
  4132.     if(mapnum == 60) cloudson = 1;
  4133.     if(mapnum == 50) cloudson = 1;
  4134.     if(mapnum == 54) cloudson = 1;
  4135.     if(mapnum == 58) cloudson = 1;
  4136.     if(mapnum == 62) cloudson = 1;
  4137.     if(mapnum == 83) cloudson = 1;
  4138.  
  4139.     // -----------special case
  4140.     dontdrawover = 0;
  4141.     if(mapnum == 24) dontdrawover = 1;
  4142.  
  4143.     if((mapnum == 53 || mapnum == 57 || mapnum == 61 || mapnum == 65 || mapnum == 62) && scriptflag[60][0] > 0) mapnum = mapnum + 100;
  4144.     if((mapnum == 161 || mapnum == 162) && scriptflag[60][0] == 2) mapnum = mapnum + 100;
  4145.  
  4146.     for(int i = 0; i <= MAXSPELL; i++)
  4147.         spellinfo[i].frame = 0;
  4148.  
  4149.     roomlock = 0;
  4150.  
  4151.     // read *.map file
  4152.     sprintf(name, "mapdb/%04i.map", mapnum); printf("Reading %s\n", name);
  4153.     fp = fopen(name, "r");
  4154.     for(int x = 0; x <= 319; x++)
  4155.         for(int y = 0; y <= 199; y++) {
  4156.             INPUT("%i", &tempmap[x][y]);
  4157.         }
  4158.     fclose(fp);
  4159.  
  4160.     for(int x = 0; x <= 319; x++)
  4161.         for(int y = 0; y <= 239; y++) {
  4162.             triggerloc[x][y] = -1;
  4163.         }
  4164.  
  4165.     // read *.trg file
  4166.     sprintf(name, "mapdb/%04i.trg", mapnum); printf("Reading %s\n", name);
  4167.     fp = fopen(name, "r");
  4168.  
  4169.     INPUT("%i", &ntriggers);
  4170.  
  4171.     for(int i = 0; i < ntriggers; i++) {
  4172.         int mapx, mapy, trig;
  4173.  
  4174.         INPUT("%i", &mapx);
  4175.         INPUT("%i", &mapy);
  4176.         INPUT("%i", &trig);
  4177.  
  4178.         triggerloc[mapx][mapy] = trig;
  4179.     }
  4180.     fclose(fp);
  4181.  
  4182.  
  4183.     for(int y = 0; y <= 23; y++)
  4184.         for(int x = 0; x <= 39; x++)
  4185.             rampdata[x][y] = tempmap[3 * 40 + x][y + 40];
  4186.  
  4187.  
  4188.     for(int y = 0; y <= 23; y++)
  4189.         for(int x = 0; x <= 39; x++)
  4190.             for(int l = 0; l <= 2; l++)
  4191.                 for(int a = 0; a <= 2; a++)
  4192.                     tileinfo[l][x][y][a] = 0;
  4193.  
  4194.     if(scriptflag[4][0] == 1 && curmap == 4) {
  4195.         triggerloc[9][7] = 5004;
  4196.         tempmap[9][7] = 41;
  4197.         tempmap[9][7 + 40] = 0;
  4198.     }
  4199.  
  4200.     for(int y = 0; y <= 23; y++) {
  4201.         for(int x = 0; x <= 39; x++) {
  4202.             for(int l = 0; l <= 2; l++) {
  4203.                 int lx, ly, curtile, curtilelayer;
  4204.                 int curtilel, curtilex, curtiley;
  4205.                 int pass, ffa, ffb;
  4206.  
  4207.                 ly = y;
  4208.                 lx = x + l * 40;
  4209.  
  4210.                 // tile
  4211.                 curtile = tempmap[lx][ly];
  4212.                 curtilelayer = tempmap[lx][ly + 40];
  4213.  
  4214.                 if(curtile > 0) {
  4215.                     curtile = curtile - 1;
  4216.                     curtilel = curtilelayer;
  4217.                     curtilex = curtile % 20;
  4218.                     curtiley = (curtile - curtilex) / 20;
  4219.  
  4220.                     tileinfo[l][x][y][0] = curtile + 1;
  4221.                     tileinfo[l][x][y][1] = curtilelayer;
  4222.  
  4223.                     rcSrc.x = curtilex * 16;
  4224.                     rcSrc.y = curtiley * 16;
  4225.                     rcSrc.w = 16;
  4226.                     rcSrc.h = 16;
  4227.  
  4228.                     rcDest.x = x * 16;
  4229.                     rcDest.y = y * 16;
  4230.                     rcDest.w = 16;
  4231.                     rcDest.h = 16;
  4232.  
  4233.                     pass = 0;
  4234.  
  4235.                     if(l == 2 && curtilel == 1) {
  4236.                         for(int ff = 0; ff <= 5; ff++) {
  4237.                             ffa = 20 * 5 - 1 + ff * 20;
  4238.                             ffb = 20 * 5 + 4 + ff * 20;
  4239.                             if(curtile > ffa && curtile < ffb) {
  4240.                                 SDL_SetAlpha(tiles[curtilel], SDL_SRCALPHA, 128);
  4241.                                 pass = 1;
  4242.                             }
  4243.                         }
  4244.                     }
  4245.                     if(l == 1 && curtilel == 2) {
  4246.                         for(int ff = 0; ff <= 4; ff++) {
  4247.                             ffa = 20 * (5 + ff) + 3;
  4248.                             if(curtile == ffa) {
  4249.                                 SDL_SetAlpha(tiles[curtilel], SDL_SRCALPHA, 192);
  4250.                                 pass = 1;
  4251.                             }
  4252.                         }
  4253.                     }
  4254.  
  4255.                     SDL_BlitSurface(tiles[curtilel], &rcSrc, mapbg, &rcDest);
  4256.                     SDL_SetAlpha(tiles[curtilel], SDL_SRCALPHA, 255);
  4257.  
  4258.                     rcDest.x = x * 8;
  4259.                     rcDest.y = y * 8;
  4260.                     rcDest.w = 8;
  4261.                     rcDest.h = 8;
  4262.  
  4263.                     SDL_FillRect(clipbg, &rcDest, 0);
  4264.                 }
  4265.  
  4266.             }
  4267.         }
  4268.     }
  4269.  
  4270.  
  4271.     for(int x = 0; x <= 39; x++) {
  4272.         for(int y = 0; y <= 23; y++) {
  4273.  
  4274.             int d = tempmap[3 * 40 + x][y];
  4275.  
  4276.             int clip = 0;
  4277.             int npc = 0;
  4278.             int obj = 0;
  4279.  
  4280.             if(scriptflag[4][0] == 1 && x == 9 && y == 7) d = 99;
  4281.  
  4282.             if(d > 0) {
  4283.                 clip = d % 2;
  4284.                 d = (d - clip) / 2;
  4285.                 npc = d % 2;
  4286.                 d = (d - npc) / 2;
  4287.                 obj = d % 2;
  4288.  
  4289.                 if(d == 99 && x == 9 && y == 7) clip = 1;
  4290.  
  4291.                 if(clip) {
  4292.                     if(d != 99) d = tempmap[6 * 40 + x][y];
  4293.                     if(d == 99) d = 1;
  4294.  
  4295.                     int x1 = x * 8;
  4296.                     int y1 = y * 8;
  4297.  
  4298.                     if(d == 1) {
  4299.                         for(int i = 0; i <= 7; i++) {
  4300.                             sys_line(clipbg, x1, y1 + i, x1 + 7 - i, y1 + i, ccc);
  4301.                         }
  4302.                     } else if(d == 2) {
  4303.                         sys_line(clipbg, x1, y1, x1 + 7, y1, ccc);
  4304.                         sys_line(clipbg, x1, y1 + 1, x1 + 7, y1 + 1, ccc);
  4305.                     } else if(d == 3) {
  4306.                         for(int i = 0; i <= 7; i++) {
  4307.                             sys_line(clipbg, x1 + i, y1 + i, x1 + 7, y1 + i, ccc);
  4308.                         }
  4309.                     } else if(d == 4) {
  4310.                         sys_line(clipbg, x1, y1, x1, y1 + 7, ccc);
  4311.                         sys_line(clipbg, x1 + 1, y1, x1 + 1, y1 + 7, ccc);
  4312.                     } else if(d == 5) {
  4313.                         rcDest.x = x1;
  4314.                         rcDest.y = y1;
  4315.                         rcDest.w = 8;
  4316.                         rcDest.h = 8;
  4317.                         SDL_FillRect(clipbg, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  4318.                     } else if(d == 6) {
  4319.                         sys_line(clipbg, x1 + 7, y1, x1 + 7, y1 + 7, ccc);
  4320.                         sys_line(clipbg, x1 + 6, y1, x1 + 6, y1 + 7, ccc);
  4321.                     } else if(d == 7) {
  4322.                         for(int i = 0; i <= 7; i++) {
  4323.                             sys_line(clipbg, x1, y1 + i, x1 + i, y1 + i, ccc);
  4324.                         }
  4325.                     } else if(d == 8) {
  4326.                         sys_line(clipbg, x1, y1 + 7, x1 + 7, y1 + 7, ccc);
  4327.                         sys_line(clipbg, x1, y1 + 7, x1 + 6, y1 + 6, ccc);
  4328.                     } else if(d == 9) {
  4329.                         for(int i = 0; i <= 7; i++) {
  4330.                             sys_line(clipbg, x1 + 7 - i, y1 + i, x1 + 7, y1 + i, ccc);
  4331.                         }
  4332.                     }
  4333.                 }
  4334.             }
  4335.         }
  4336.     }
  4337.  
  4338.     lastobj = 0;
  4339.     lastnpc = 0;
  4340.  
  4341.     for(int i = 0; i <= MAXNPC; i++)
  4342.         npcinfo[i].onmap = 0;
  4343.  
  4344.     for(int x = 0; x <= 19; x++) {
  4345.         for(int y = 0; y <= 19; y++) {
  4346.             int d = tempmap[3 * 40 + x][y];
  4347.  
  4348.             int clip = 0;
  4349.             int npc = 0;
  4350.             int obj = 0;
  4351.             if(d > 0) {
  4352.                 clip = d % 2;
  4353.                 d = (d - clip) / 2;
  4354.                 npc = d % 2;
  4355.                 d = (d - npc) / 2;
  4356.                 obj = d % 2;
  4357.             }
  4358.  
  4359.             objmap[x][y] = -1;
  4360.  
  4361.             if(obj == 1) {
  4362.  
  4363.                 int o = tempmap[5 * 40 + x][y];
  4364.  
  4365.                 if(objmapf[curmap][x][y] == 0) {
  4366.                     objmap[x][y] = o;
  4367.  
  4368.                     if(objectinfo[o][0] > 1) {
  4369.                         if(o > lastobj) lastobj = o;
  4370.                     }
  4371.  
  4372.                     int x1 = x * 8;
  4373.                     int y1 = y * 8;
  4374.  
  4375.                     rcDest.x = x1;
  4376.                     rcDest.y = y1;
  4377.                     rcDest.w = 8;
  4378.                     rcDest.h = 8;
  4379.  
  4380.                     if(objectinfo[o][4] == 1) SDL_FillRect(clipbg, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  4381.                     if(objectinfo[o][4] == 3) SDL_FillRect(clipbg, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  4382.                 }
  4383.             }
  4384.             if(npc == 1) {
  4385.                 int o = tempmap[4 * 40 + x][y];
  4386.  
  4387.                 if(o > lastnpc) lastnpc = o;
  4388.  
  4389.                 npcinfo[o].x = x * 16 - 4;
  4390.                 npcinfo[o].y = y * 16 - 5;
  4391.  
  4392.                 npcinfo[o].walkdir = 1;
  4393.                 npcinfo[o].onmap = 1;
  4394.             }
  4395.         }
  4396.     }
  4397.  
  4398.  
  4399.     if(curmap == 62 && scriptflag[8][0] > 0) lastnpc = 0;
  4400.     if(curmap == 73 && scriptflag[12][0] > 0) lastnpc = 0;
  4401.     if(curmap == 81 && scriptflag[13][0] > 0) lastnpc = 0;
  4402.  
  4403.     if(curmap == 73 && scriptflag[12][0] == 0) roomlock = 1;
  4404.     if(curmap == 81 && scriptflag[13][0] == 0) roomlock = 1;
  4405.     if(curmap == 83 && scriptflag[15][0] == 0) roomlock = 1;
  4406.     if(curmap == 82) roomlock = 1;
  4407.  
  4408.     // read *.npc file
  4409.     sprintf(name, "mapdb/%04i.npc", mapnum); printf("Reading %s\n", name);
  4410.     fp = fopen(name, "r");
  4411.  
  4412.     for(int i = 0; i <= MAXNPC; i++) {
  4413.         INPUT("%i", &npcinfo[i].spriteset);
  4414.         INPUT("%i", &npcinfo[i].x1);
  4415.         INPUT("%i", &npcinfo[i].y1);
  4416.         INPUT("%i", &npcinfo[i].x2);
  4417.         INPUT("%i", &npcinfo[i].y2);
  4418.         INPUT("%i", &npcinfo[i].movementmode);
  4419.         INPUT("%i", &npcinfo[i].hp);
  4420.         INPUT("%i", &npcinfo[i].item1);
  4421.         INPUT("%i", &npcinfo[i].item2);
  4422.         INPUT("%i", &npcinfo[i].item3);
  4423.         INPUT("%i", &npcinfo[i].script);
  4424.  
  4425.         // baby dragon
  4426.         if(npcinfo[i].spriteset == 1) {
  4427.             npcinfo[i].hp = 12;
  4428.             npcinfo[i].attackdelay = 2000;
  4429.  
  4430.             npcinfo[i].attackdamage = 2;
  4431.             npcinfo[i].spelldamage = 0;
  4432.  
  4433.             npcinfo[i].walkspd = 1;
  4434.  
  4435.             if(RND() * 5 == 0) npcinfo[i].hp = 0;
  4436.         }
  4437.  
  4438.         // onewing
  4439.         if(npcinfo[i].spriteset == 2) {
  4440.             npcinfo[i].hp = 200;
  4441.             npcinfo[i].attackdelay = 2000;
  4442.             npcinfo[i].swayspd = 1;
  4443.  
  4444.             npcinfo[i].attackdamage = 24;
  4445.             npcinfo[i].spelldamage = 30;
  4446.  
  4447.             npcinfo[i].walkspd = 1.4;
  4448.             npcinfo[i].castpause = ticks;
  4449.         }
  4450.  
  4451.         // boss1
  4452.         if(npcinfo[i].spriteset == 3) {
  4453.             npcinfo[i].hp = 300;
  4454.             npcinfo[i].attackdelay = 2200;
  4455.  
  4456.             npcinfo[i].attackdamage = 0;
  4457.             npcinfo[i].spelldamage = 30;
  4458.  
  4459.             npcinfo[i].walkspd = 1.2;
  4460.         }
  4461.  
  4462.         // black knights
  4463.         if(npcinfo[i].spriteset == 4) {
  4464.             npcinfo[i].hp = 200;
  4465.             npcinfo[i].attackdelay = 2800;
  4466.  
  4467.             npcinfo[i].attackdamage = 0;
  4468.             npcinfo[i].spelldamage = 30;
  4469.  
  4470.             npcinfo[i].walkspd = 1;
  4471.         }
  4472.  
  4473.         // boss2 firehydra
  4474.         if(npcinfo[i].spriteset == 5) {
  4475.             npcinfo[i].hp = 600;
  4476.             npcinfo[i].attackdelay = 2200;
  4477.  
  4478.             npcinfo[i].attackdamage = 50;
  4479.             npcinfo[i].spelldamage = 30;
  4480.  
  4481.             npcinfo[i].walkspd = 1.3;
  4482.  
  4483.             npcinfo[i].swayangle = 0;
  4484.         }
  4485.  
  4486.         // baby fire dragon
  4487.         if(npcinfo[i].spriteset == 6) {
  4488.             npcinfo[i].hp = 20;
  4489.             npcinfo[i].attackdelay = 1500;
  4490.  
  4491.             npcinfo[i].attackdamage = 0;
  4492.             npcinfo[i].spelldamage = 12;
  4493.  
  4494.             npcinfo[i].walkspd = 1;
  4495.  
  4496.             if(RND() * 5 == 0) npcinfo[i].hp = 0;
  4497.         }
  4498.  
  4499.         // priest1
  4500.         if(npcinfo[i].spriteset == 7) {
  4501.             npcinfo[i].hp = 40;
  4502.             npcinfo[i].attackdelay = 5000;
  4503.  
  4504.             npcinfo[i].attackdamage = 0;
  4505.             npcinfo[i].spelldamage = 8;
  4506.  
  4507.             npcinfo[i].walkspd = 1;
  4508.  
  4509.             if(RND() * 8 == 0) npcinfo[i].hp = 0;
  4510.         }
  4511.  
  4512.         // yellow fire dragon
  4513.         if(npcinfo[i].spriteset == 8) {
  4514.             npcinfo[i].hp = 100;
  4515.             npcinfo[i].attackdelay = 1500;
  4516.  
  4517.             npcinfo[i].attackdamage = 0;
  4518.             npcinfo[i].spelldamage = 24;
  4519.  
  4520.             npcinfo[i].walkspd = 1;
  4521.  
  4522.             if(RND() * 5 == 0) npcinfo[i].hp = 0;
  4523.         }
  4524.  
  4525.         // twowing
  4526.         if(npcinfo[i].spriteset == 9) {
  4527.             npcinfo[i].hp = 140;
  4528.             npcinfo[i].attackdelay = 2000;
  4529.             npcinfo[i].swayspd = 1;
  4530.  
  4531.             npcinfo[i].attackdamage = 30;
  4532.             npcinfo[i].spelldamage = 0;
  4533.  
  4534.             npcinfo[i].walkspd = 1;
  4535.  
  4536.             npcinfo[i].castpause = 0;
  4537.         }
  4538.  
  4539.         // dragon2
  4540.         if(npcinfo[i].spriteset == 10) {
  4541.             npcinfo[i].hp = 80;
  4542.             npcinfo[i].attackdelay = 1500;
  4543.  
  4544.             npcinfo[i].attackdamage = 24;
  4545.             npcinfo[i].spelldamage = 0;
  4546.  
  4547.             npcinfo[i].walkspd = 1;
  4548.  
  4549.             npcinfo[i].floating = RND() * 16;
  4550.         }
  4551.  
  4552.         // end boss
  4553.         if(npcinfo[i].spriteset == 11) {
  4554.             npcinfo[i].hp = 1200;
  4555.             npcinfo[i].attackdelay = 2000;
  4556.  
  4557.             npcinfo[i].attackdamage = 100;
  4558.             npcinfo[i].spelldamage = 60;
  4559.  
  4560.             npcinfo[i].walkspd = 1;
  4561.  
  4562.             npcinfo[i].floating = RND() * 16;
  4563.         }
  4564.  
  4565.         // bat kitty
  4566.         if(npcinfo[i].spriteset == 12) {
  4567.             npcinfo[i].hp = 800;
  4568.             npcinfo[i].attackdelay = 2000;
  4569.  
  4570.             npcinfo[i].attackdamage = 100;
  4571.             npcinfo[i].spelldamage = 50;
  4572.  
  4573.             npcinfo[i].walkspd = 1;
  4574.  
  4575.             npcinfo[i].floating = RND() * 16;
  4576.         }
  4577.  
  4578.         if(npcinfo[i].onmap == 0) npcinfo[i].hp = 0;
  4579.  
  4580.         npcinfo[i].maxhp = npcinfo[i].hp;
  4581.  
  4582.         npcinfo[i].attacking = 0;
  4583.         npcinfo[i].attackframe = 0;
  4584.         npcinfo[i].cattackframe = 0;
  4585.         npcinfo[i].attackspd = 1.5;
  4586.         npcinfo[i].attacknext = ticks + npcinfo[i].attackdelay * (1 + RND() * 2);
  4587.  
  4588.         if(npcinfo[i].spriteset == 2 || npcinfo[i].spriteset == 9) {
  4589.             npcinfo[i].bodysection[0].sprite = 0;
  4590.             npcinfo[i].bodysection[1].sprite = 1;
  4591.             npcinfo[i].bodysection[2].sprite = 2;
  4592.             npcinfo[i].bodysection[3].sprite = 3;
  4593.             npcinfo[i].bodysection[4].sprite = 4;
  4594.             npcinfo[i].bodysection[5].sprite = 3;
  4595.             npcinfo[i].bodysection[6].sprite = 3;
  4596.             npcinfo[i].bodysection[7].sprite = 5;
  4597.  
  4598.             npcinfo[i].bodysection[0].bonelength = 8;
  4599.             npcinfo[i].bodysection[1].bonelength = 7;
  4600.             npcinfo[i].bodysection[2].bonelength = 6;
  4601.             npcinfo[i].bodysection[3].bonelength = 4;
  4602.             npcinfo[i].bodysection[4].bonelength = 4;
  4603.             npcinfo[i].bodysection[5].bonelength = 4;
  4604.             npcinfo[i].bodysection[6].bonelength = 4;
  4605.  
  4606.             for(int f = 0; f <= 7; f++) {
  4607.                 npcinfo[i].bodysection[f].x = npcinfo[i].x + 12;
  4608.                 npcinfo[i].bodysection[f].y = npcinfo[i].y + 14;
  4609.             }
  4610.  
  4611.             npcinfo[i].headtargetx[0] = npcinfo[i].x + 12;
  4612.             npcinfo[i].headtargety[0] = npcinfo[i].y + 14;
  4613.  
  4614.         }
  4615.  
  4616.         if(npcinfo[i].spriteset == 5) {
  4617.             for(int f = 0; f <= 29; f++) {
  4618.                 npcinfo[i].bodysection[f].x = npcinfo[i].x + 12;
  4619.                 npcinfo[i].bodysection[f].y = npcinfo[i].y + 14;
  4620.             }
  4621.  
  4622.             for(int f = 0; f <= 2; f++) {
  4623.                 npcinfo[i].headtargetx[f] = npcinfo[i].x + 12;
  4624.                 npcinfo[i].headtargety[f] = npcinfo[i].y + 14;
  4625.  
  4626.                 npcinfo[i].attacking2[f] = 0;
  4627.                 npcinfo[i].attackframe2[f] = 0;
  4628.             }
  4629.         }
  4630.  
  4631.         if(npcinfo[i].script == 2) {
  4632.             roomlock = 1;
  4633.             if(scriptflag[2][0] > 0) {
  4634.                 roomlock = 0;
  4635.                 npcinfo[i].hp = 0;
  4636.             }
  4637.         }
  4638.  
  4639.         if(npcinfo[i].script == 3) {
  4640.             roomlock = 1;
  4641.             if(scriptflag[3][0] > 0) {
  4642.                 roomlock = 0;
  4643.                 npcinfo[i].hp = 0;
  4644.             }
  4645.         }
  4646.  
  4647.         if(npcinfo[i].script == 5) {
  4648.             roomlock = 1;
  4649.             if(scriptflag[5][0] > 0) {
  4650.                 roomlock = 0;
  4651.                 npcinfo[i].hp = 0;
  4652.             }
  4653.         }
  4654.  
  4655.         if(npcinfo[i].script == 15) {
  4656.             roomlock = 1;
  4657.             if(scriptflag[15][0] > 0) {
  4658.                 roomlock = 0;
  4659.                 npcinfo[i].hp = 0;
  4660.             }
  4661.         }
  4662.  
  4663.         npcinfo[i].pause = ticks;
  4664.     }
  4665.  
  4666.     fclose(fp);
  4667.  
  4668.  
  4669.     int cx, cy, npx, npy, lx, ly;
  4670.  
  4671.     // academy master key
  4672.     if(curmap == 34 && scriptflag[2][0] == 1) {
  4673.         cx = 9;
  4674.         cy = 7;
  4675.  
  4676.         objmap[cx][cy] = 5;
  4677.  
  4678.         rcDest.x = cx * 8;
  4679.         rcDest.y = cy * 8;
  4680.         rcDest.w = 8;
  4681.         rcDest.h = 8;
  4682.  
  4683.         npx = player.px + 12;
  4684.         npy = player.py + 20;
  4685.  
  4686.         lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  4687.         ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  4688.  
  4689.         if(lx == cx && ly == cy) player.py = player.py + 16;
  4690.  
  4691.         SDL_FillRect(clipbg, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  4692.     }
  4693.  
  4694.     // academy crystal
  4695.     if(curmap == 24 && player.foundcrystal == 0 && scriptflag[3][0] == 1) {
  4696.         cx = 9;
  4697.         cy = 7;
  4698.  
  4699.         objmap[cx][cy] = 6;
  4700.  
  4701.         rcDest.x = cx * 8;
  4702.         rcDest.y = cy * 8;
  4703.         rcDest.w = 8;
  4704.         rcDest.h = 8;
  4705.  
  4706.         npx = player.px + 12;
  4707.         npy = player.py + 20;
  4708.  
  4709.         lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  4710.         ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  4711.  
  4712.         if(lx == cx && ly == cy) player.py = player.py + 16;
  4713.  
  4714.         SDL_FillRect(clipbg, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  4715.     }
  4716.  
  4717.     // gardens master key
  4718.     if(curmap == 62 && scriptflag[8][0] == 1) {
  4719.         cx = 13;
  4720.         cy = 7;
  4721.  
  4722.         objmap[cx][cy] = 5;
  4723.  
  4724.         rcDest.x = cx * 8;
  4725.         rcDest.y = cy * 8;
  4726.         rcDest.w = 8;
  4727.         rcDest.h = 8;
  4728.  
  4729.         npx = player.px + 12;
  4730.         npy = player.py + 20;
  4731.  
  4732.         lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  4733.         ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  4734.  
  4735.         if(lx == cx && ly == cy) player.py = player.py + 16;
  4736.  
  4737.         SDL_FillRect(clipbg, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  4738.     }
  4739.  
  4740.     // gardens fidelis sword
  4741.     if(curmap == 66 && scriptflag[5][0] == 1 && player.sword == 1) {
  4742.         cx = 9;
  4743.         cy = 6;
  4744.  
  4745.         objmap[cx][cy] = 9;
  4746.  
  4747.         rcDest.x = cx * 8;
  4748.         rcDest.y = cy * 8;
  4749.         rcDest.w = 8;
  4750.         rcDest.h = 8;
  4751.  
  4752.         npx = player.px + 12;
  4753.         npy = player.py + 20;
  4754.  
  4755.         lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  4756.         ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  4757.  
  4758.         if(lx == cx && ly == cy) player.py = player.py + 16;
  4759.  
  4760.         SDL_FillRect(clipbg, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  4761.     }
  4762.  
  4763.     // citadel armour
  4764.     if(curmap == 73 && scriptflag[12][0] == 1 && player.armour == 1) {
  4765.         cx = 8;
  4766.         cy = 7;
  4767.  
  4768.         objmap[cx][cy] = 16;
  4769.  
  4770.         rcDest.x = cx * 8;
  4771.         rcDest.y = cy * 8;
  4772.         rcDest.w = 8;
  4773.         rcDest.h = 8;
  4774.  
  4775.         npx = player.px + 12;
  4776.         npy = player.py + 20;
  4777.  
  4778.         lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  4779.         ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  4780.  
  4781.         if(lx == cx && ly == cy) player.py = player.py + 16;
  4782.  
  4783.         SDL_FillRect(clipbg, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  4784.     }
  4785.  
  4786.     // citadel master key
  4787.     if(curmap == 81 && scriptflag[13][0] == 1) {
  4788.         cx = 11;
  4789.         cy = 10;
  4790.  
  4791.         objmap[cx][cy] = 5;
  4792.  
  4793.         rcDest.x = cx * 8;
  4794.         rcDest.y = cy * 8;
  4795.         rcDest.w = 8;
  4796.         rcDest.h = 8;
  4797.  
  4798.         npx = player.px + 12;
  4799.         npy = player.py + 20;
  4800.  
  4801.         lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  4802.         ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  4803.  
  4804.         if(lx == cx && ly == cy) player.py = player.py + 16;
  4805.  
  4806.         SDL_FillRect(clipbg, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  4807.     }
  4808.  
  4809.  
  4810.     // max ups
  4811.     if(curmap == 83 && scriptflag[15][0] == 1 && player.sword < 3) {
  4812.         cx = 6;
  4813.         cy = 8;
  4814.  
  4815.         objmap[cx][cy] = 18;
  4816.  
  4817.         rcDest.x = cx * 8;
  4818.         rcDest.y = cy * 8;
  4819.         rcDest.w = 8;
  4820.         rcDest.h = 8;
  4821.  
  4822.         npx = player.px + 12;
  4823.         npy = player.py + 20;
  4824.  
  4825.         lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  4826.         ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  4827.  
  4828.         if(lx == cx && ly == cy) player.py = player.py + 16;
  4829.  
  4830.         SDL_FillRect(clipbg, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  4831.     }
  4832.  
  4833.     if(curmap == 83 && scriptflag[16][0] == 1 && player.shield < 3) {
  4834.         cx = 9;
  4835.         cy = 8;
  4836.  
  4837.         objmap[cx][cy] = 19;
  4838.  
  4839.         rcDest.x = cx * 8;
  4840.         rcDest.y = cy * 8;
  4841.         rcDest.w = 8;
  4842.         rcDest.h = 8;
  4843.  
  4844.         npx = player.px + 12;
  4845.         npy = player.py + 20;
  4846.  
  4847.         lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  4848.         ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  4849.  
  4850.         if(lx == cx && ly == cy) player.py = player.py + 16;
  4851.  
  4852.         SDL_FillRect(clipbg, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  4853.     }
  4854.  
  4855.     if(curmap == 83 && scriptflag[17][0] == 1 && player.armour < 3) {
  4856.         cx = 12;
  4857.         cy = 8;
  4858.  
  4859.         objmap[cx][cy] = 20;
  4860.  
  4861.         rcDest.x = cx * 8;
  4862.         rcDest.y = cy * 8;
  4863.         rcDest.w = 8;
  4864.         rcDest.h = 8;
  4865.  
  4866.         npx = player.px + 12;
  4867.         npy = player.py + 20;
  4868.  
  4869.         lx = (int)npx / 16; //(npx - (npx % 16)) / 16;
  4870.         ly = (int)npy / 16; //(npy - (npy % 16)) / 16;
  4871.  
  4872.         if(lx == cx && ly == cy) player.py = player.py + 16;
  4873.  
  4874.         SDL_FillRect(clipbg, &rcDest, SDL_MapRGB(clipbg->format, 255,255,255));
  4875.         }
  4876.  
  4877.     SDL_BlitSurface(clipbg, NULL, clipbg2, NULL);
  4878. #undef INPUT
  4879. }
  4880.  
  4881. void game_main()
  4882. {
  4883.     game_title(0);
  4884.     game_saveloadnew();
  4885.  
  4886.     SDL_Quit();
  4887.     //FSOUND_StopSound(FSOUND_ALL);
  4888. }
  4889.  
  4890. void game_newgame()
  4891. {
  4892.     float xofs;
  4893.     float ld, add;
  4894.     int ticks, bticks, pauseticks, cnt = 0;
  4895.  
  4896.     rcSrc.x = 0;
  4897.     rcSrc.y = 0;
  4898.     rcSrc.w = 320;
  4899.     rcSrc.h = 240;
  4900.  
  4901.     SDL_FillRect(videobuffer2, &rcSrc, 0);
  4902.     SDL_FillRect(videobuffer3, &rcSrc, 0);
  4903.  
  4904.  
  4905.     rc.x = 0;
  4906.     rc.y = 0;
  4907.  
  4908.     rc2.x = SCR_TOPX;
  4909.     rc2.y = SCR_TOPY;
  4910.     rc2.w = 320;
  4911.     rc2.h = 240;
  4912.  
  4913.  
  4914.     //x = 160 - 4 * len(stri$) // ??
  4915.  
  4916.     ticks = SDL_GetTicks();
  4917.     pauseticks = ticks + 500;
  4918.     bticks = ticks;
  4919.  
  4920.  
  4921.     SDL_BlitSurface(videobuffer, NULL, videobuffer3, NULL);
  4922.     SDL_BlitSurface(video, &rc2, videobuffer2, NULL);
  4923.  
  4924.     //cursel = 0;
  4925.  
  4926.     //keypause = ticks + 220;
  4927.  
  4928.     fpsr = 0.0;
  4929.     int y = 140;
  4930.  
  4931.     if(menabled == 1 && opmusic == 1) {
  4932.         //FSOUND_stopSound(FSOUND_ALL);
  4933.         //musicchannel = FSOUND_playSound(FSOUND_FREE, mendofgame);
  4934.         //FSOUND_setVolume(musicchannel, 0);
  4935.     }
  4936.  
  4937.     secsingame = 0;
  4938.     secstart = 0;
  4939.  
  4940.     do {
  4941.         ld += 4 * fpsr;
  4942.         //if(ld > opmusicvol) ld = opmusicvol;
  4943.         if(menabled == 1 /*&& ldstop == 0*/) {
  4944.             //FSOUND_setVolume(musicchannel, ld!)
  4945.             //if ld! = opmusicvol then ldstop = 1
  4946.         }
  4947.  
  4948.         rc.x = -xofs;
  4949.         rc.y = 0;
  4950.  
  4951.         SDL_BlitSurface(titleimg, NULL, videobuffer, &rc);
  4952.  
  4953.         rc.x = -xofs + 320;
  4954.         rc.y = 0;
  4955.  
  4956.         SDL_BlitSurface(titleimg, NULL, videobuffer, &rc);
  4957.  
  4958.         rc.x = 0;
  4959.         rc.y = 0;
  4960.  
  4961.         if(++cnt >= 6) {
  4962.             cnt = 0;
  4963.             y--;
  4964.         }
  4965.  
  4966.         for(int i = 0; i <= 37; i++) {
  4967.             int yy, x;
  4968.  
  4969.             yy = y + i * 10;
  4970.             if(yy > -8 && yy < 240) {
  4971.                 x = 160 - strlen(story[i]) * 4;
  4972.                 sys_print(videobuffer, story[i], x, yy, 4);
  4973.             }
  4974.  
  4975.             if(yy < 10 && i == 37) goto __exit_do;
  4976.         }
  4977.  
  4978.         rc.x = 0;
  4979.         rc.y = 0;
  4980.         rc.w = 320;
  4981.         rc.h = 240;
  4982.  
  4983.         SDL_BlitSurface(videobuffer, &rc, video, &rc2);
  4984.         SDL_Flip(video);
  4985.  
  4986.         tickspassed = ticks;
  4987.         ticks = SDL_GetTicks();
  4988.  
  4989.         tickspassed = ticks - tickspassed;
  4990.         fpsr = (float)tickspassed / 24.0;
  4991.  
  4992.         fp = fp + 1;
  4993.         if(ticks > nextticks) {
  4994.             nextticks = ticks + 1000;
  4995.             fps = fp;
  4996.             fp = 0;
  4997.         }
  4998.  
  4999.         add = 0.5 * fpsr;
  5000.         if(add > 1) add = 1;
  5001.         xofs += add;
  5002.         if(xofs >= 320) xofs = xofs - 320;
  5003.  
  5004.         SDL_PollEvent(&event);
  5005.         keys = SDL_GetKeyState(NULL);
  5006.  
  5007.         if(event.type == SDL_KEYDOWN) cnt = 6;
  5008.         if(keys[SDLK_ESCAPE]) goto __exit_do;
  5009.  
  5010.         SDL_Delay(10);
  5011.     } while(1);
  5012. __exit_do:
  5013.  
  5014.     player.px = 0;
  5015.     player.py = 0;
  5016.     player.opx = 0;
  5017.     player.opy = 0;
  5018.     player.walkdir = 0;
  5019.     player.walkframe = 0;
  5020.     player.walkspd = 0;
  5021.     player.attackframe = 0;
  5022.     player.attackspd = 0;
  5023.     player.hp = 0;
  5024.     player.maxhp = 0;
  5025.     player.hpflash = 0;
  5026.     player.level = 0;
  5027.     player.sword = 0;
  5028.     player.shield = 0;
  5029.     player.armour = 0;
  5030.     for(int i = 0; i <= 5; i++) {
  5031.         player.foundspell[i] = 0;
  5032.         player.spellcharge[i] = 0;
  5033.     }
  5034.     player.flasks = 0;
  5035.     player.foundcrystal = 0;
  5036.     player.crystalcharge = 0;
  5037.     player.attackstrength = 0;
  5038.     player.spelldamage = 0;
  5039.     player.sworddamage = 0;
  5040.     player.masterkey = 0;
  5041.     player.exp = 0;
  5042.     player.nextlevel = 0;
  5043.  
  5044.     memset(scriptflag, 0, sizeof(scriptflag));
  5045.     memset(objmapf, 0, sizeof(objmapf));
  5046.     memset(inventory, 0, sizeof(inventory));
  5047.     memset(roomlocks, 0, sizeof(roomlocks));
  5048.  
  5049.     roomlocks[66] = 2;
  5050.     roomlocks[24] = 2;
  5051.     roomlocks[17] = 1;
  5052.     roomlocks[34] = 1;
  5053.     roomlocks[50] = 1;
  5054.     roomlocks[73] = 1;
  5055.     roomlocks[82] = 2;
  5056.  
  5057.     player.walkspd = 1.1;
  5058.     animspd = 0.5;
  5059.     attacking = 0;
  5060.     player.attackspd = 1.5;
  5061.  
  5062.     player.sword = 1;
  5063.     player.level = 1;
  5064.     player.nextlevel = 50;
  5065.     player.shield = 1;
  5066.     player.armour = 1;
  5067.     player.hp = 14;
  5068.     player.maxhp = player.hp;
  5069.  
  5070.     player.sworddamage = player.level * 2;
  5071.     player.spelldamage = player.level * 1.5;
  5072.  
  5073.     player.px = 15*16 - 4;
  5074.     player.py = 6*16 - 4;
  5075.     player.walkdir = 1;
  5076.  
  5077.     pgardens = 0;
  5078.     ptown = 0;
  5079.     pboss = 0;
  5080.     pacademy = 0;
  5081.     pcitadel = 0;
  5082.  
  5083.     game_loadmap(2);
  5084.  
  5085.     game_playgame();
  5086. }
  5087.  
  5088. void game_playgame()
  5089. {
  5090.     game_swash();
  5091.  
  5092.     if(pmenu == 1 && menabled == 1) {
  5093.         //FSOUND_stopSound(menuchannel);
  5094.         //pmenu = 0;
  5095.     }
  5096.  
  5097.     do {
  5098.         if(forcepause == 0) {
  5099.             game_updanims();
  5100.             game_updnpcs();
  5101.         }
  5102.  
  5103.         game_checktrigger();
  5104.         game_checkinputs();
  5105.  
  5106.         if(forcepause == 0) game_handlewalking();
  5107.  
  5108.         game_updatey();
  5109.         game_drawview();
  5110.  
  5111.         game_updmusic();
  5112.  
  5113.         sys_update();
  5114.     } while(1);
  5115. }
  5116.  
  5117. void game_processtrigger(int trignum)
  5118. {
  5119.     int trigtype, tx, ty, tmap, tjumpstyle, tsx, tsy;
  5120.  
  5121.     trigtype = triggers[trignum][0];
  5122.  
  5123.     if(roomlock == 1) return;
  5124.     // map jump------------------------------
  5125.     if(trigtype == 0) {
  5126.         tx = triggers[trignum][1];
  5127.         ty = triggers[trignum][2];
  5128.         tmap = triggers[trignum][3];
  5129.         tjumpstyle = triggers[trignum][4];
  5130.  
  5131.         if(roomlocks[tmap] > 0) {
  5132.             if(saidlocked == 0) game_eventtext("Locked");
  5133.             saidlocked = 1;
  5134.             canusekey = 1;
  5135.             locktype = roomlocks[tmap];
  5136.             roomtounlock = tmap;
  5137.             return;
  5138.         }
  5139.  
  5140.         if(tmap == 1) {
  5141.             if(saidjammed == 0) game_eventtext("Door Jammed!");
  5142.             saidjammed = 1;
  5143.             return;
  5144.         }
  5145.  
  5146.         saidlocked = 0;
  5147.         saidjammed = 0;
  5148.  
  5149.         // loc-sxy+oldmaploc
  5150.         if(tjumpstyle == 0) {
  5151.  
  5152.             tsx = triggers[trignum][5];
  5153.             tsy = triggers[trignum][6];
  5154.  
  5155.             player.px += (tx - tsx) * 16;
  5156.             player.py += (ty - tsy) * 16;
  5157.  
  5158.             // HACKFIX
  5159.             if(player.px < 0) player.px = 0;
  5160.             if(player.py < 0) player.py = 0;
  5161.  
  5162.             if(tmap > 0) {
  5163.                 if(menabled == 1 && opeffects == 1) {
  5164.                     //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(snddoor))
  5165.                     //FSOUND_setVolume(snd, opeffectsvol)
  5166.                 }
  5167.  
  5168.                 game_loadmap(tmap);
  5169.                 game_swash();
  5170.             }
  5171.         }
  5172.     }
  5173.  
  5174.     for(int i = 0; i <= MAXFLOAT; i++) {
  5175.         floattext[i][0] = 0;
  5176.         floaticon[i][0] = 0;
  5177.     }
  5178. }
  5179.  
  5180. void game_saveloadnew()
  5181. {
  5182.     float y, yy;
  5183.     int currow, curcol, lowerlock;
  5184.     int ticks, ticks1, tickpause;
  5185.     int plevel, sx, sy;
  5186.  
  5187.     rc2.x = SCR_TOPX;
  5188.     rc2.y = SCR_TOPY;
  5189.  
  5190.     SDL_SetAlpha(videobuffer, SDL_SRCALPHA, 255);
  5191.     SDL_SetAlpha(saveloadimg, SDL_SRCALPHA, 192);
  5192.  
  5193.     currow = 0;
  5194.     curcol = 0;
  5195.  
  5196.     lowerlock = 0;
  5197.  
  5198.     ticks = SDL_GetTicks();
  5199.     ticks1 = ticks;
  5200.     tickpause = ticks + 150;
  5201.  
  5202.     do {
  5203.         SDL_FillRect(videobuffer, NULL, 0);
  5204.  
  5205.         y = y + 1 * fpsr;
  5206.  
  5207.         rcDest.x = (float)(256 + 256 * cos(3.141592 / 180 * clouddeg * 40));
  5208.         rcDest.y = (float)(192 + 192 * sin(3.141592 / 180 * clouddeg * 40));
  5209.         rcDest.w = 320;
  5210.         rcDest.h = 240;
  5211.  
  5212.         SDL_SetAlpha(cloudimg, SDL_SRCALPHA, 128);
  5213.         SDL_BlitSurface(cloudimg, &rcDest, videobuffer, NULL);
  5214.         SDL_SetAlpha(cloudimg, SDL_SRCALPHA, 64);
  5215.  
  5216.  
  5217.         rcDest.x = 256; // + 256 * cos(3.141592 / 180 * clouddeg)
  5218.         rcDest.y = 192; // + 192 * sin(3.141592 / 180 * clouddeg)
  5219.         rcDest.w = 320;
  5220.         rcDest.h = 240;
  5221.  
  5222.         SDL_SetAlpha(cloudimg, SDL_SRCALPHA, 128);
  5223.         SDL_BlitSurface(cloudimg, &rcDest, videobuffer, NULL);
  5224.         SDL_SetAlpha(cloudimg, SDL_SRCALPHA, 64);
  5225.  
  5226.         SDL_BlitSurface(saveloadimg, NULL, videobuffer, NULL);
  5227.  
  5228.         SDL_PollEvent(&event);
  5229.         keys = SDL_GetKeyState(NULL);
  5230.  
  5231.         if(tickpause < ticks) {
  5232.             if(event.type == SDL_KEYDOWN) {
  5233.                 itemticks = ticks + 220;
  5234.  
  5235.                 if(keys[SDLK_RETURN] || keys[SDLK_SPACE]) {
  5236.                     // QUIT - non existent :)
  5237.                     if(currow == 0 && curcol == 4) {
  5238.                         SDL_Quit();
  5239.                         //FSOUND_StopSound (FSOUND_ALL);
  5240.                         exit(1);
  5241.                     }
  5242.                     // RETURN
  5243.                     if(currow == 0 && curcol == 3) {
  5244.                         // reset keys to avoid returning
  5245.                         keys[SDLK_RETURN] = keys[SDLK_SPACE] = 0;
  5246.                         return;
  5247.                     }
  5248.                     // NEW GAME
  5249.                     if(currow == 0 && curcol == 0) game_newgame();
  5250.  
  5251.                     // LOAD GAME
  5252.                     if(currow == 0 && curcol == 1) {
  5253.                         lowerlock = 1;
  5254.                         currow = 1 + saveslot;
  5255.                         tickpause = ticks + 125;
  5256.                     }
  5257.                     // SAVE GAME
  5258.                     if(currow == 0 && curcol == 2) {
  5259.                         lowerlock = 1;
  5260.                         currow = 1;
  5261.                         tickpause = ticks + 125;
  5262.                     }
  5263.  
  5264.  
  5265.                     if(lowerlock == 1 && curcol == 1 && tickpause < ticks) {
  5266.                         /*open "data\player" + ltrim$(rtrim$(str$(currow - 1))) + ".sav" for output as #1
  5267.  
  5268.  
  5269.                         print #1, player.level
  5270.  
  5271.                         print #1, (secstart + secsingame)
  5272.                         print #1, "a"
  5273.  
  5274.                         print #1, player.px
  5275.                         print #1, player.py
  5276.                         print #1, player.opx
  5277.                         print #1, player.opy
  5278.                         print #1, player.walkdir
  5279.                         print #1, player.walkframe
  5280.                         print #1, player.walkspd
  5281.                         print #1, player.attackframe
  5282.                         print #1, player.attackspd
  5283.                         print #1, player.hp
  5284.                         print #1, player.maxhp
  5285.                         print #1, player.hpflash
  5286.                         print #1, player.level
  5287.                         print #1, player.sword
  5288.                         print #1, player.shield
  5289.                         print #1, player.armour
  5290.                         for i = 0 to 5
  5291.                             print #1, player.foundspell(i)
  5292.                             print #1, player.spellcharge(i)
  5293.                         next
  5294.                         for a = 0 to 4
  5295.                             print #1, inventory(a)
  5296.                         next
  5297.                         print #1, player.foundcrystal
  5298.                         print #1, player.crystalcharge
  5299.                         print #1, player.attackstrength
  5300.                         print #1, player.spelldamage
  5301.                         print #1, player.sworddamage
  5302.                         print #1, player.masterkey
  5303.                         print #1, player.exp
  5304.                         print #1, player.nextlevel
  5305.                         for a = 0 to 99
  5306.                             for b = 0 to 9
  5307.                                 print #1, scriptflag (a,b)
  5308.                             next
  5309.                         next
  5310.                         print #1, curmap
  5311.  
  5312.                         for a = 0 to 999
  5313.                             for b = 0 to 20
  5314.                                 for c = 0 to 14
  5315.                                     print #1, objmapf(a, b, c)
  5316.                                 next
  5317.                             next
  5318.                         next
  5319.  
  5320.                         for a = 0 to 200
  5321.                             print #1, roomlocks(a)
  5322.                         next
  5323.  
  5324.                         print #1, player.spellstrength
  5325.  
  5326.                         close #1*/
  5327.  
  5328.                         secstart = secstart + secsingame;
  5329.                         secsingame = 0;
  5330.                         lowerlock = 0;
  5331.                         saveslot = currow - 1;
  5332.                         currow = 0;
  5333.                     }
  5334.  
  5335.                     if(lowerlock == 1 && curcol == 2 && tickpause < ticks) {
  5336.                         /*open "data\player" + ltrim$(rtrim$(str$(currow - 1))) + ".sav" for input as #1
  5337.  
  5338.  
  5339.                         input #1, player.level
  5340.  
  5341.                         input #1, secstart
  5342.                         input #1, aa$
  5343.  
  5344.  
  5345.                         input #1, player.px
  5346.                         input #1, player.py
  5347.                         input #1, player.opx
  5348.                         input #1, player.opy
  5349.                         input #1, player.walkdir
  5350.                         input #1, player.walkframe
  5351.                         input #1, player.walkspd
  5352.                         input #1, player.attackframe
  5353.                         input #1, player.attackspd
  5354.                         input #1, player.hp
  5355.                         input #1, player.maxhp
  5356.                         input #1, player.hpflash
  5357.                         input #1, player.level
  5358.                         input #1, player.sword
  5359.                         input #1, player.shield
  5360.                         input #1, player.armour
  5361.                         for i = 0 to 5
  5362.                             input #1, player.foundspell(i)
  5363.                             input #1, player.spellcharge(i)
  5364.                         next
  5365.                         for a = 0 to 4
  5366.                             input #1, inventory(a)
  5367.                         next
  5368.                         input #1, player.foundcrystal
  5369.                         input #1, player.crystalcharge
  5370.                         input #1, player.attackstrength
  5371.                         input #1, player.spelldamage
  5372.                         input #1, player.sworddamage
  5373.                         input #1, player.masterkey
  5374.                         input #1, player.exp
  5375.                         input #1, player.nextlevel
  5376.                         for a = 0 to 99
  5377.                             for b = 0 to 9
  5378.                                 input #1, scriptflag (a,b)
  5379.                             next
  5380.                         next
  5381.                         input #1, curmap
  5382.  
  5383.                         for a = 0 to 999
  5384.                             for b = 0 to 20
  5385.                                 for c = 0 to 14
  5386.                                     input #1, objmapf(a, b, c)
  5387.                                 next
  5388.                             next
  5389.                         next
  5390.  
  5391.                         for a = 0 to 200
  5392.                             input #1, roomlocks(a)
  5393.                         next
  5394.  
  5395.                         input #1, player.spellstrength
  5396.  
  5397.                         player.walkspd = 1.1
  5398.                         animspd = .5
  5399.                         attacking = 0
  5400.                         Player.attackspd = 1.5
  5401.  
  5402.                         pgardens = 0
  5403.                         ptown = 0
  5404.                         pboss = 0
  5405.                         pacademy = 0
  5406.                         pcitadel = 0
  5407.  
  5408.  
  5409.                         close #1*/
  5410.  
  5411.                         //FSOUND_stopSound(FSOUND_ALL);
  5412.  
  5413.                         secsingame = 0;
  5414.                         saveslot = currow - 1;
  5415.                         //cmap = curmap;
  5416.                         //game_loadmap(cmap);
  5417.                         //game_playgame();
  5418.                     }
  5419.  
  5420.                     tickpause = ticks + 125;
  5421.                 }
  5422.  
  5423.                 switch(event.key.keysym.sym) {
  5424.                 case SDLK_ESCAPE:
  5425.                     if(lowerlock == 0) return;
  5426.                     lowerlock = 0;
  5427.                     currow = 0;
  5428.                     tickpause = ticks + 125;
  5429.                     break;
  5430.                 case SDLK_DOWN:
  5431.                     if(lowerlock == 1) {
  5432.                         currow = currow + 1;
  5433.                         if(currow == 5) currow = 1;
  5434.                         tickpause = ticks + 125;
  5435.                     }
  5436.                     break;
  5437.  
  5438.                 case SDLK_UP:
  5439.                     if(lowerlock == 1) {
  5440.                         currow = currow - 1;
  5441.                         if(currow == 0) currow = 4;
  5442.                         tickpause = ticks + 125;
  5443.                     }
  5444.                     break;
  5445.  
  5446.                 case SDLK_LEFT:
  5447.                     if(lowerlock == 0) {
  5448.                         curcol = curcol - 1;
  5449.                         if(curcol == -1) curcol = 3;
  5450.                         tickpause = ticks + 125;
  5451.                     }
  5452.                     break;
  5453.  
  5454.                 case SDLK_RIGHT:
  5455.                     if(lowerlock == 0) {
  5456.                         curcol = curcol + 1;
  5457.                         if(curcol == 4) curcol = 0;
  5458.                         tickpause = ticks + 125;
  5459.                     }
  5460.                     break;
  5461.                 default:
  5462.                     ;
  5463.                 }
  5464.             }
  5465.         }
  5466.  
  5467.  
  5468.         // savestates---------------------------------
  5469.         // shit, read it only when needed!
  5470.  
  5471.         for(int ff = 0; ff <= 3; ff++) {
  5472.             FILE *fp;
  5473.             char line[256];
  5474.  
  5475.             sprintf(line,"data/player%i.sav", ff);
  5476.  
  5477.             fp = fopen(line, "r");
  5478.  
  5479.             fgets(line, sizeof(line), fp);
  5480.             sscanf(line, "%i", &plevel);
  5481.  
  5482.             if(plevel > 0) {
  5483.                 /*playera.level = plevel
  5484.  
  5485.                 input #1, asecstart
  5486.                 input #1, aa$
  5487.  
  5488.                 input #1, playera.px
  5489.                 input #1, playera.py
  5490.                 input #1, playera.opx
  5491.                 input #1, playera.opy
  5492.                 input #1, playera.walkdir
  5493.                 input #1, playera.walkframe
  5494.                 input #1, playera.walkspd
  5495.                 input #1, playera.attackframe
  5496.                 input #1, playera.attackspd
  5497.                 input #1, playera.hp
  5498.                 input #1, playera.maxhp
  5499.                 input #1, playera.hpflash
  5500.                 input #1, playera.level
  5501.                 input #1, playera.sword
  5502.                 input #1, playera.shield
  5503.                 input #1, playera.armour
  5504.                 for i = 0 to 5
  5505.                     input #1, playera.foundspell(i)
  5506.                     input #1, playera.spellcharge(i)
  5507.                 next
  5508.                 for i = 0 to 4
  5509.                     input #1, a
  5510.                 next
  5511.                 input #1, playera.foundcrystal
  5512.                 input #1, playera.crystalcharge
  5513.                 input #1, playera.attackstrength
  5514.                 input #1, playera.spelldamage
  5515.                 input #1, playera.sworddamage
  5516.                 input #1, playera.masterkey
  5517.                 input #1, playera.exp
  5518.                 input #1, playera.nextlevel
  5519.                 */
  5520.             }
  5521.             fclose(fp);
  5522.  
  5523.             if(plevel > 0) {
  5524.                 /*sx = 8
  5525.                 sy = 57 + ff * 48
  5526.  
  5527.                 ase = asecstart
  5528.                 h = ((ase - (ase mod 3600)) / 3600)
  5529.                 ase = (ase - h * 3600)
  5530.                 m = ((ase - (ase mod 60)) / 60)
  5531.                 s = (ase - m * 60)
  5532.  
  5533.                 h$ = ltrim$(rtrim$(str$(h)))
  5534.                 if len(h$) = 1 then h$ = "0" + h$
  5535.                 m$ = ltrim$(rtrim$(str$(m)))
  5536.                 if len(m$) = 1 then m$ = "0" + m$
  5537.                 s$ = ltrim$(rtrim$(str$(s)))
  5538.                 if len(s$) = 1 then s$ = "0" + s$
  5539.  
  5540.                 t$ = "Game Time: " + h$ + ":" + m$ + ":" + s$
  5541.                 sys_print(videobuffer, t$, 160 - len(t$) * 4, sy, 0
  5542.  
  5543.  
  5544.                 sy = sy + 11
  5545.  
  5546.                 sx  = 12
  5547.                 cc = 0
  5548.  
  5549.                 sys_print(videobuffer, "Health: "+ltrim$(rtrim$(str$(playera.hp))) + "/" + ltrim$(rtrim$(str$(playera.maxhp))), sx, sy, cc
  5550.  
  5551.                 f$ = ltrim$(rtrim$(str$(playera.level)))
  5552.                 if playera.level = 22 then f$ = "MAX"
  5553.                 sys_print(videobuffer, "Level : "+f$, sx, sy + 11, 0
  5554.  
  5555.  
  5556.                 rcSrc.x = sx + 15 * 8 + 24
  5557.                 rcSrc.y = sy + 1
  5558.  
  5559.                 ss = (playera.sword - 1) * 3
  5560.                 if playera.sword = 3 then ss = 18
  5561.                 SDL_BlitSurface(itemimg(ss), NULL, videobuffer, &rcSrc
  5562.  
  5563.                 rcSrc.x = rcSrc.x + 16
  5564.                 ss = (playera.shield - 1) * 3 + 1
  5565.                 if playera.shield = 3 then ss = 19
  5566.                 SDL_BlitSurface(itemimg(ss), NULL, videobuffer, &rcSrc
  5567.  
  5568.                 rcSrc.x = rcSrc.x + 16
  5569.                 ss = (playera.armour - 1) * 3 + 2
  5570.                 if playera.armour = 3 then ss = 20
  5571.                 SDL_BlitSurface(itemimg(ss), NULL, videobuffer, &rcSrc
  5572.  
  5573.                 nx = rcSrc.x + 13 + 3*8
  5574.                 rcSrc.x = nx - 17
  5575.  
  5576.                 if playera.foundcrystal = 1 then
  5577.                     rcSrc.x = rcSrc.x + 17
  5578.  
  5579.                     SDL_BlitSurface(itemimg(7), NULL, videobuffer, &rcSrc
  5580.  
  5581.                     ccc = SDL_MapRGB(videobuffer->format, 0, 32, 32)
  5582.  
  5583.                     for i = 0 to 4
  5584.                         rcSrc.x = rcSrc.x + 17
  5585.  
  5586.                         if playera.foundspell(i) = 1 then SDL_BlitSurface(itemimg(8 + i), NULL, videobuffer, &rcSrc
  5587.  
  5588.                     next
  5589.                 end if*/
  5590.             } else {
  5591.                 sx = 10;
  5592.                 sy = 57 + ff * 48;
  5593.                 sys_print(videobuffer, "Empty", 160 - 5 * 4, sy, 0);
  5594.             }
  5595.         }
  5596.         // ------------------------------------------
  5597.  
  5598.  
  5599.         if(currow == 0) {
  5600.             rcDest.y = 18;
  5601.             if(curcol == 0) rcDest.x = 10;
  5602.             if(curcol == 1) rcDest.x = 108;
  5603.             if(curcol == 2) rcDest.x = 170;
  5604.             if(curcol == 3) rcDest.x = 230;
  5605.             rcDest.x = (float)(rcDest.x + 2 + 2 * sin(3.14159 * 2 * itemyloc / 16));
  5606.         }
  5607.  
  5608.         if(currow > 0) {
  5609.             rcDest.x = (float)(0 + 2 * sin(3.14159 * 2 * itemyloc / 16));
  5610.             rcDest.y = (float)(53 + (currow - 1) * 48);
  5611.         }
  5612.  
  5613.         SDL_BlitSurface(itemimg[15], NULL, videobuffer, &rcDest);
  5614.  
  5615.  
  5616.         if(lowerlock == 1) {
  5617.             rcDest.y = 18;
  5618.             if(curcol == 1) rcDest.x = 108;
  5619.             if(curcol == 2) rcDest.x = 170;
  5620.             rcDest.x = rcDest.x; // + 2 + 2 * sin(-3.14159 * 2 * itemyloc / 16)
  5621.  
  5622.             SDL_BlitSurface(itemimg[15], NULL, videobuffer, &rcDest);
  5623.         }
  5624.  
  5625.         yy = 255.0;
  5626.         if(ticks < ticks1 + 1000) {
  5627.             yy = 255.0 * ((float)(ticks - ticks1) / 1000.0);
  5628.             if(yy < 0.0) yy = 0.0;
  5629.             if(yy > 255) yy = 255.0;
  5630.         }
  5631.  
  5632.         SDL_SetAlpha(videobuffer, SDL_SRCALPHA, (int)yy);
  5633.  
  5634.         SDL_BlitSurface(videobuffer, NULL, video, &rc2);
  5635.         SDL_SetAlpha(videobuffer, SDL_SRCALPHA, 255);
  5636.  
  5637.         SDL_Flip(video);
  5638.         SDL_PumpEvents();
  5639.  
  5640.         tickspassed = ticks;
  5641.         ticks = SDL_GetTicks();
  5642.  
  5643.         tickspassed = ticks - tickspassed;
  5644.         fpsr = tickspassed / 24;
  5645.  
  5646.         fp = fp + 1;
  5647.         if(ticks > nextticks) {
  5648.             nextticks = ticks + 1000;
  5649.             fps = fp;
  5650.             fp = 0;
  5651.         }
  5652.  
  5653.         clouddeg = clouddeg + 0.01 * fpsr;
  5654.         while(clouddeg >= 360) clouddeg = clouddeg - 360;
  5655.  
  5656.         itemyloc = itemyloc + 0.6 * fpsr;
  5657.         while(itemyloc >= 16) itemyloc = itemyloc - 16;
  5658.  
  5659.         SDL_Delay(10);
  5660.     } while(1);
  5661.  
  5662.     SDL_SetAlpha(cloudimg, SDL_SRCALPHA, 64);
  5663. }
  5664.  
  5665. void game_showlogos()
  5666. {
  5667.     float y;
  5668.     int ticks, ticks1, tickspassed, nextticks = 0, fp;
  5669.  
  5670.     rcSrc.x = 0;
  5671.     rcSrc.y = 0;
  5672.     rcSrc.w = 320;
  5673.     rcSrc.h = 240;
  5674.  
  5675.     rc.x = 0;
  5676.     rc.y = 0;
  5677.  
  5678.     rc2.x = SCR_TOPX;
  5679.     rc2.y = SCR_TOPY;
  5680.     rc2.w = 320;
  5681.     rc2.h = 240;
  5682.  
  5683.     ticks = SDL_GetTicks();
  5684.     ticks1 = ticks;
  5685.  
  5686.     y = 0.0;
  5687.  
  5688.     do {
  5689.         rc.x = 0;
  5690.         rc.y = 0;
  5691.         rc.w = 320;
  5692.         rc.h = 240;
  5693.  
  5694.         y = 255.0;
  5695.         if(ticks < ticks1 + 1000) {
  5696.             y = 255.0 * ((float)(ticks - ticks1) / 1000.0);
  5697.             if(y < 0.0) y = 0.0;
  5698.             if(y > 255.0) y = 255.0;
  5699.         }
  5700.  
  5701.         if(ticks > ticks1 + 3000) {
  5702.             y = 255.0 - 255.0 * ((float)(ticks - ticks1 - 3000.0) / 1000.0);
  5703.             if(y < 0.0) y = 0.0;
  5704.             if(y > 255.0) y = 255.0;
  5705.         }
  5706.  
  5707.         SDL_FillRect(videobuffer, &rc, 0);
  5708.  
  5709.         SDL_SetAlpha(logosimg, SDL_SRCALPHA, (int)y);
  5710.         SDL_BlitSurface(logosimg, NULL, videobuffer, NULL);
  5711.         SDL_SetAlpha(logosimg, SDL_SRCALPHA, 255);
  5712.  
  5713.  
  5714.         SDL_BlitSurface(videobuffer, &rc, video, &rc2);
  5715.  
  5716.         SDL_Flip(video);
  5717.         SDL_PumpEvents();
  5718.  
  5719.         tickspassed = ticks;
  5720.         ticks = SDL_GetTicks();
  5721.  
  5722.         tickspassed = ticks - tickspassed;
  5723.         fpsr = tickspassed / 24;
  5724.  
  5725.         fp += 1;
  5726.         if(ticks > nextticks) {
  5727.             nextticks = ticks + 1000;
  5728.             fps = fp;
  5729.             fp = 0;
  5730.         }
  5731.  
  5732.         SDL_Delay(10);
  5733.         if(ticks > ticks1 + 4000) break;
  5734.     } while(1);
  5735. }
  5736.  
  5737.  
  5738. void game_swash()
  5739. {
  5740.     float y;
  5741.  
  5742.     rcDest.x = 0;
  5743.     rcDest.y = 0;
  5744.     rcDest.w = 320;
  5745.     rcDest.h = 240;
  5746.  
  5747.     rc2.x = SCR_TOPX;
  5748.     rc2.y = SCR_TOPY;
  5749.  
  5750.     y = 0;
  5751.  
  5752.     do {
  5753.         y = y + 1 * fpsr;
  5754.  
  5755.         SDL_SetAlpha(videobuffer, SDL_SRCALPHA, (int)y);
  5756.         SDL_FillRect(videobuffer, &rcDest, 0);
  5757.         SDL_BlitSurface(videobuffer, &rcDest, video, &rc2);
  5758.  
  5759.         SDL_Flip(video);
  5760.         SDL_PumpEvents();
  5761.  
  5762.         tickspassed = ticks;
  5763.         ticks = SDL_GetTicks();
  5764.  
  5765.         tickspassed = ticks - tickspassed;
  5766.         fpsr = (float)tickspassed / 24.0;
  5767.  
  5768.         fp = fp + 1;
  5769.         if(ticks > nextticks) {
  5770.             nextticks = ticks + 1000;
  5771.             fps = fp;
  5772.             fp = 0;
  5773.         }
  5774.  
  5775.         clouddeg = clouddeg + 0.01 * fpsr;
  5776.         while(clouddeg >= 360) clouddeg = clouddeg - 360;
  5777.  
  5778.         if(y > 10) break;
  5779.     } while(1);
  5780.  
  5781.     y = 0;
  5782.     do {
  5783.         y = y + 1 * fpsr;
  5784.  
  5785.         SDL_SetAlpha(videobuffer, SDL_SRCALPHA, (int)(y * 25));
  5786.         SDL_BlitSurface(mapbg, NULL, videobuffer, NULL);
  5787.  
  5788.         if(cloudson == 1) {
  5789.             rcDest.x = (float)(256 + 256 * cos(3.141592 / 180 * clouddeg));
  5790.             rcDest.y = (float)(192 + 192 * sin(3.141592 / 180 * clouddeg));
  5791.             rcDest.w = 320;
  5792.             rcDest.h = 240;
  5793.  
  5794.             SDL_BlitSurface(cloudimg, &rcDest, videobuffer, NULL);
  5795.         }
  5796.  
  5797.         SDL_BlitSurface(videobuffer, NULL, video, &rc2);
  5798.         SDL_Flip(video);
  5799.         SDL_PumpEvents();
  5800.  
  5801.         tickspassed = ticks;
  5802.         ticks = SDL_GetTicks();
  5803.  
  5804.         tickspassed = ticks - tickspassed;
  5805.         fpsr = (float)tickspassed / 24.0;
  5806.  
  5807.         fp = fp + 1;
  5808.         if(ticks > nextticks) {
  5809.             nextticks = ticks + 1000;
  5810.             fps = fp;
  5811.             fp = 0;
  5812.         }
  5813.  
  5814.         clouddeg = clouddeg + 0.01 * fpsr;
  5815.         while(clouddeg >= 360) clouddeg = clouddeg - 360;
  5816.  
  5817.         if(y > 10) break;
  5818.     } while(1);
  5819.  
  5820.  
  5821.     SDL_SetAlpha(videobuffer, SDL_SRCALPHA, 255);
  5822. }
  5823.  
  5824. void game_theend()
  5825. {
  5826.     float y;
  5827.  
  5828.     rcDest.x = 0;
  5829.     rcDest.y = 0;
  5830.     rcDest.w = 320;
  5831.     rcDest.h = 240;
  5832.  
  5833.     rc2.x = SCR_TOPX;
  5834.     rc2.y = SCR_TOPY;
  5835.  
  5836.  
  5837.     y = 0;
  5838.     for(int i = 0; i <= MAXFLOAT; i++) {
  5839.         floattext[i][0] = 0;
  5840.         floaticon[i][0] = 0;
  5841.     }
  5842.  
  5843.     do {
  5844.         y = y + 1 * fpsr;
  5845.  
  5846.         SDL_SetAlpha(videobuffer, SDL_SRCALPHA, (int)y);
  5847.         SDL_FillRect(videobuffer, &rcDest, 0);
  5848.         SDL_BlitSurface(videobuffer, &rcDest, video, &rc2);
  5849.  
  5850.         SDL_Flip(video);
  5851.         SDL_PumpEvents();
  5852.  
  5853.         tickspassed = ticks;
  5854.         ticks = SDL_GetTicks();
  5855.  
  5856.         tickspassed = ticks - tickspassed;
  5857.         fpsr = (float)tickspassed / 24.0;
  5858.  
  5859.         fp = fp + 1;
  5860.         if(ticks > nextticks) {
  5861.             nextticks = ticks + 1000;
  5862.             fps = fp;
  5863.             fp = 0;
  5864.         }
  5865.  
  5866.         if(y > 100) break;
  5867.     } while(1);
  5868.  
  5869.     game_title(0);
  5870. }
  5871.  
  5872. void game_title(int mode)
  5873. {
  5874.     float xofs;
  5875.     int ticks, ticks1, keypause;
  5876.     int cursel, ldstop;
  5877.     int x, y;
  5878.  
  5879.     rcSrc.x = 0;
  5880.     rcSrc.y = 0;
  5881.     rcSrc.w = 320;
  5882.     rcSrc.h = 240;
  5883.  
  5884.     SDL_FillRect(videobuffer2, &rcSrc, 0);
  5885.     SDL_FillRect(videobuffer3, &rcSrc, 0);
  5886.  
  5887.     rc.x = 0;
  5888.     rc.y = 0;
  5889.  
  5890.     rc2.x = SCR_TOPX;
  5891.     rc2.y = SCR_TOPY;
  5892.     rc2.w = 320;
  5893.     rc2.h = 240;
  5894.  
  5895.     //x = 160 - 4 * len(stri$); // ??
  5896.  
  5897.     //pauseticks = ticks + 500; // ??
  5898.     ticks = SDL_GetTicks();
  5899.  
  5900.     SDL_BlitSurface(videobuffer, NULL, videobuffer3, NULL);
  5901.     SDL_BlitSurface(video, &rc2, videobuffer2, NULL);
  5902.  
  5903.     cursel = 0;
  5904.  
  5905.     keypause = ticks + 220;
  5906.  
  5907.     ticks1 = ticks;
  5908.  
  5909.     if(menabled == 1 && opmusic == 1) {
  5910.         //FSOUND_setVolume(musicchannel, 0);
  5911.         //FSOUND_setPaused(musicchannel, true);
  5912.  
  5913.         //menuchannel = FSOUND_playSound(FSOUND_FREE, mmenu);
  5914.         //FSOUND_setPaused(menuchannel, false);
  5915.         //FSOUND_setVolume(menuchannel, opmusicvol);
  5916.         pmenu = 1;
  5917.     }
  5918.  
  5919.     ldstop = 0;
  5920.  
  5921.     do {
  5922.         float ld = 0.0;
  5923.  
  5924.         ld += 4.0 * fpsr;
  5925.         //if(ld > opmusicvol) ld = opmusicvol;
  5926.         if(menabled == 1 && ldstop == 0) {
  5927.             //FSOUND_setVolume(menuchannel, ld);
  5928.             //if(ld == opmusicvol) ldstop = 1;
  5929.         }
  5930.  
  5931.         rc.x = -xofs;
  5932.         rc.y = 0;
  5933.  
  5934.         SDL_BlitSurface(titleimg, NULL, videobuffer, &rc);
  5935.  
  5936.         rc.x = -xofs + 320.0;
  5937.         rc.y = 0;
  5938.  
  5939.         SDL_BlitSurface(titleimg, NULL, videobuffer, &rc);
  5940.  
  5941.         rc.x = 0;
  5942.         rc.y = 0;
  5943.  
  5944.         SDL_BlitSurface(titleimg2, NULL, videobuffer, &rc);
  5945.  
  5946.         y = 172;
  5947.         x = 160 - 14 * 4;
  5948.  
  5949.         sys_print(videobuffer, "new game/save/load", x, y, 4);
  5950.         sys_print(videobuffer, "options", x, y + 16, 4);
  5951.         sys_print(videobuffer, "quit game", x, y + 32, 4);
  5952.         if(mode == 1) sys_print(videobuffer, "return", x, y + 48, 4);
  5953.  
  5954.         rc.x = (float)(x - 16 - 4 * cos(3.14159 * 2 * itemyloc / 16));
  5955.         rc.y = (float)(y - 4 + 16 * cursel);
  5956.  
  5957.         SDL_BlitSurface(itemimg[15], NULL, videobuffer, &rc);
  5958.  
  5959.         rc.x = 0;
  5960.         rc.y = 0;
  5961.         rc.w = 320;
  5962.         rc.h = 240;
  5963.  
  5964.         float yf = 255.0;
  5965.         if(ticks < ticks1 + 1000) {
  5966.             yf = 255.0 * ((float)(ticks - ticks1) / 1000.0);
  5967.             if(y < 0.0) yf = 0.0;
  5968.             if(y > 255.0) yf = 255.0;
  5969.         }
  5970.  
  5971.         SDL_SetAlpha(videobuffer, SDL_SRCALPHA, (int)yf);
  5972.         SDL_BlitSurface(videobuffer, &rc, video, &rc2);
  5973.         SDL_SetAlpha(videobuffer, SDL_SRCALPHA, 255);
  5974.  
  5975.         tickspassed = ticks;
  5976.         ticks = SDL_GetTicks();
  5977.  
  5978.         tickspassed = ticks - tickspassed;
  5979.         fpsr = (float)tickspassed / 24.0;
  5980.  
  5981.         fp = fp + 1;
  5982.         if(ticks > nextticks) {
  5983.             nextticks = ticks + 1000;
  5984.             fps = fp;
  5985.             fp = 0;
  5986.         }
  5987.  
  5988.         float add = 0.5 * fpsr;
  5989.         if(add > 1) add = 1;
  5990.  
  5991.         xofs = xofs + add;
  5992.         if(xofs >= 320.0) xofs -= 320.0;
  5993.  
  5994.         itemyloc += 0.75 * fpsr;
  5995.  
  5996.         while(itemyloc >= 16)
  5997.             itemyloc = itemyloc - 16;
  5998.  
  5999.         SDL_PollEvent(&event);
  6000.  
  6001.         if(keypause < ticks) {
  6002.             keys = SDL_GetKeyState(NULL);
  6003.  
  6004.             if(event.type == SDL_KEYDOWN) {
  6005.                 keypause = ticks + 150;
  6006.  
  6007.                 if(keys[SDLK_ESCAPE] && mode == 1) break;
  6008.                 else if(keys[SDLK_UP]) {
  6009.                     cursel--;
  6010.                     if(cursel < 0) cursel = (mode == 1 ? 3 : 2);
  6011.                 } else if(keys[SDLK_DOWN]) {
  6012.                     cursel++;
  6013.                     if(cursel >= (mode == 1 ? 4 : 3)) cursel = 0;
  6014.                 } else if(keys[SDLK_SPACE] || keys[SDLK_RETURN]) {
  6015.                     if(cursel == 0) {
  6016.                         game_saveloadnew();
  6017.                         ticks = SDL_GetTicks();
  6018.                         keypause = ticks + 150;
  6019.                         ticks1 = ticks;
  6020.                     } else if(cursel == 1) {
  6021.                         game_configmenu();
  6022.                         ticks = SDL_GetTicks();
  6023.                         keypause = ticks + 150;
  6024.                         ticks1 = ticks;
  6025.                     } else if(cursel == 2) {
  6026.                         //FSOUND_Close();
  6027.                         SDL_Quit();
  6028.                         exit(1);
  6029.                     } else if(cursel == 3) break;
  6030.                 }
  6031.             }
  6032.         }
  6033.  
  6034.         SDL_Flip(video);
  6035.         SDL_Delay(10);
  6036.     } while(1);
  6037.  
  6038.     itemticks = ticks + 210;
  6039.  
  6040.     if(menabled == 1 && opmusic == 1) {
  6041.         //FSOUND_stopSound(menuchannel);
  6042.         //FSOUND_setPaused(musicchannel, false);
  6043.         //FSOUND_setVolume(musicchannel, opmusicvol);
  6044.         pmenu = 0;
  6045.     }
  6046. }
  6047.  
  6048. void game_updanims()
  6049. {
  6050.     for(int i = 0; i <= lastobj; i++) {
  6051.         int nframes = objectinfo[i][0];
  6052.         int oanimspd = objectinfo[i][3];
  6053.         float frame = objectframe[i][0];
  6054.         int cframe = objectframe[i][1];
  6055.         objectinfo[i][6] = 0;
  6056.  
  6057.         if(nframes > 1) {
  6058.             frame = frame + oanimspd / 50 * fpsr;
  6059.             while(frame >= nframes)
  6060.                 frame = frame - nframes;
  6061.  
  6062.             cframe = (int)frame; // truncate fractional part
  6063.             if(cframe > nframes) cframe = nframes - 1;
  6064.             if(cframe < 0) cframe = 0;
  6065.  
  6066.             objectframe[i][0] = frame;
  6067.             objectframe[i][1] = cframe;
  6068.         }
  6069.     }
  6070. }
  6071.  
  6072. void game_updatey()
  6073. {
  6074.     int yy, ff;
  6075.  
  6076.     for(int i = 0; i <= 2400; i++)
  6077.         ysort[i] = -1;
  6078.  
  6079.     ff = (int)(player.py * 10);
  6080.     if(ff < 0) ff = 0; // HACKFIX or ysort[yy] may go out of bounds
  6081.     player.ysort = ff;
  6082.     ysort[ff] = 0;
  6083.  
  6084.     firsty = 2400;
  6085.     lasty = 0;
  6086.  
  6087.     for(int i = 1; i <= lastnpc; i++) {
  6088.         yy = (int)(npcinfo[i].y * 10);
  6089.  
  6090.         do {
  6091.             if(ysort[yy] == -1 || yy == 2400) break;
  6092.             yy = yy + 1;
  6093.         } while(1);
  6094.  
  6095.         ysort[yy] = i;
  6096.         if(yy < firsty) firsty = yy;
  6097.         if(yy > lasty) lasty = yy;
  6098.     }
  6099. }
  6100.  
  6101. void game_updmusic()
  6102. {
  6103.     /*
  6104.     iplaysound = 0
  6105.     if(menabled = 1 && opmusic = 1) {
  6106.  
  6107.     // if(curmap > 5 && curmap < 42) iplaysound = macademy
  6108.     // if(curmap > 47) iplaysound = mgardens
  6109.     iplaysound = mgardens
  6110.     if(roomlock = 1) iplaysound = mboss
  6111.  
  6112.     if(iplaysound = mboss && pboss) iplaysound = 0
  6113.     if(iplaysound = mgardens && pgardens) iplaysound = 0
  6114.  
  6115.     if(iplaysound > 0) {
  6116.         FSOUND_StopSound(musicchannel)
  6117.  
  6118.         pboss = 0
  6119.         pgardens = 0
  6120.         ptown = 0
  6121.         pacademy = 0
  6122.         pcitadel = 0
  6123.  
  6124.         if(iplaysound = mboss) pboss = 1
  6125.         if(iplaysound = mgardens) pgardens = 1
  6126.  
  6127.         musicchannel = FSOUND_PlaySound(FSOUND_FREE, iplaysound)
  6128.         FSOUND_setVolume(musicchannel, opmusicvol)
  6129.         else
  6130.  
  6131.         if(not FSOUND_isPlaying(musicchannel)) {
  6132.             loopseta = loopseta + 1
  6133.             if(loopseta = 4) loopseta = 0
  6134.  
  6135.             if(pgardens = 1) {
  6136.                 FSOUND_StopSound(musicchannel)
  6137.                 if(pgardens = 1 && loopseta = 0) musicchannel = FSOUND_PlaySound(FSOUND_FREE, mgardens)
  6138.                 if(pgardens = 1 && loopseta = 1) musicchannel = FSOUND_PlaySound(FSOUND_FREE, mgardens2)
  6139.                 if(pgardens = 1 && loopseta = 2) musicchannel = FSOUND_PlaySound(FSOUND_FREE, mgardens3)
  6140.                 if(pgardens = 1 && loopseta = 3) musicchannel = FSOUND_PlaySound(FSOUND_FREE, mgardens4)
  6141.             }
  6142.  
  6143.             FSOUND_setVolume(musicchannel, opmusicvol)
  6144.         }
  6145.  
  6146.         }
  6147.     }
  6148.     */
  6149. }
  6150.  
  6151. void game_updnpcs()
  6152. {
  6153.     float npx, npy, onpx, onpy;
  6154.     unsigned int *temp, dq, bgc;
  6155.     float nnxa, nnya, nnxb, nnyb;
  6156.     int pass = 0, checkpass;
  6157.     float wspd, xdif, ydif;
  6158.     int sx, sy;
  6159.     int dospell;
  6160.  
  6161.     for(int i = 1; i <= lastnpc; i++) {
  6162.         if(npcinfo[i].hp > 0) {
  6163.             //  is npc walking
  6164.             pass = 0;
  6165.             if(npcinfo[i].attacking == 0) pass = 1;
  6166.             if(npcinfo[i].spriteset == 5) pass = 1;
  6167.             if(pass == 1) {
  6168.                 int moveup = 0;
  6169.                 int movedown = 0;
  6170.                 int moveleft = 0;
  6171.                 int moveright = 0;
  6172.  
  6173.                 npx = npcinfo[i].x;
  6174.                 npy = npcinfo[i].y;
  6175.  
  6176.                 onpx = npx;
  6177.                 onpy = npy;
  6178.  
  6179.                 wspd = npcinfo[i].walkspd / 4;
  6180.  
  6181.                 if(npcinfo[i].spriteset == 10) wspd = wspd * 2;
  6182.                 int wdir = npcinfo[i].walkdir;
  6183.  
  6184.                 int mode = npcinfo[i].movementmode;
  6185.  
  6186.                 xdif = player.px - npx;
  6187.                 ydif = player.py - npy;
  6188.  
  6189.                 if(abs(xdif) < 4 * 16 && abs(ydif) < 4 * 16 && mode < 3) mode = 0;
  6190.                 if(npcinfo[i].hp < npcinfo[i].maxhp * 0.25) mode = 3;
  6191.  
  6192.                 if(npcinfo[i].pause > ticks) mode = -1;
  6193.                 if(npcinfo[i].spriteset == 2 && npcinfo[i].castpause > ticks) mode = -1;
  6194.  
  6195.                 if(mode == 3) {
  6196.                     mode = 1;
  6197.                     if(abs(xdif) < 4 * 16 && abs(ydif) < 4 * 16) mode = 3;
  6198.                 }
  6199.  
  6200.                 checkpass = 0;
  6201.  
  6202.                 // npc  AI CODE
  6203.                 // --------------
  6204.  
  6205.                 // *** aggressive
  6206.                 if(mode == 0) {
  6207.                     wspd = npcinfo[i].walkspd / 2;
  6208.  
  6209.                     xdif = player.px - npx;
  6210.                     ydif = player.py - npy;
  6211.  
  6212.                     if(abs(xdif) > abs(ydif)) {
  6213.                         if(xdif < 4) wdir = 2;
  6214.                         if(xdif > -4) wdir = 3;
  6215.                     } else {
  6216.                         if(ydif < 4) wdir = 0;
  6217.                         if(ydif > -4) wdir = 1;
  6218.                     }
  6219.  
  6220.                     if(xdif < 4) moveleft = 1;
  6221.                     if(xdif > -4) moveright = 1;
  6222.                     if(ydif < 4) moveup = 1;
  6223.                     if(ydif > -4) movedown = 1;
  6224.                 }
  6225.                 // *******************
  6226.  
  6227.                 // *** defensive
  6228.                 if(mode == 1) {
  6229.  
  6230.                     int movingdir = npcinfo[i].movingdir;
  6231.  
  6232.                     if(npcinfo[i].ticks > ticks + 100000) npcinfo[i].ticks = ticks;
  6233.  
  6234.                     if(npcinfo[i].ticks < ticks) {
  6235.                         npcinfo[i].ticks = ticks + 2000;
  6236.                         movingdir = (int)(RND() * 8);
  6237.                         npcinfo[i].movingdir = movingdir;
  6238.                     }
  6239.  
  6240.                     if(movingdir == 0) {
  6241.                         wdir = 2; // left
  6242.                         moveup = 1;
  6243.                         moveleft = 1;
  6244.                     } else if(movingdir == 1) {
  6245.                         wdir = 0; // up
  6246.                         moveup = 1;
  6247.                     } else if(movingdir == 2) {
  6248.                         wdir = 3; // right
  6249.                         moveup = 1;
  6250.                         moveright = 1;
  6251.                     } else if(movingdir == 3) {
  6252.                         wdir = 3; // right
  6253.                         moveright = 1;
  6254.                     } else if(movingdir == 4) {
  6255.                         wdir = 3; // right
  6256.                         moveright = 1;
  6257.                         movedown = 1;
  6258.                     } else if(movingdir == 5) {
  6259.                         wdir = 1; // down
  6260.                         movedown = 1;
  6261.                     } else if(movingdir == 6) {
  6262.                         wdir = 2; // left
  6263.                         movedown = 1;
  6264.                         moveleft = 1;
  6265.                     } else if(movingdir == 7) {
  6266.                         wdir = 2; // left
  6267.                         moveleft = 1;
  6268.                     }
  6269.  
  6270.                     checkpass = 1;
  6271.                 }
  6272.                 // *******************
  6273.  
  6274.                 // *** run away
  6275.                 if(mode == 3) {
  6276.                     wspd = npcinfo[i].walkspd / 2;
  6277.  
  6278.                     xdif = player.px - npx;
  6279.                     ydif = player.py - npy;
  6280.  
  6281.                     if(abs(xdif) > abs(ydif)) {
  6282.                         if(xdif < 4) wdir = 3;
  6283.                         if(xdif > -4) wdir = 2;
  6284.                     } else {
  6285.                         if(ydif < 4) wdir = 1;
  6286.                         if(ydif > -4) wdir = 0;
  6287.                     }
  6288.  
  6289.                     if(xdif < 4) moveright = 1;
  6290.                     if(xdif > -4) moveleft = 1;
  6291.                     if(ydif < 4) movedown = 1;
  6292.                     if(ydif > -4) moveup = 1;
  6293.                 }
  6294.                 // *******************
  6295.  
  6296.                 // -------------- ?? move*** vs movin***
  6297.                 int movinup = 0;
  6298.                 int movindown = 0;
  6299.                 int movinleft = 0;
  6300.                 int movinright = 0;
  6301.  
  6302.                 float xp = (npx / 2 + 6);
  6303.                 float yp = (npy / 2 + 10);
  6304.  
  6305.                 if(npcinfo[i].spriteset == 10) wspd = wspd * 2;
  6306.  
  6307.                 float ii = wspd * fpsr;
  6308.                 if(ii < 1) ii = 1;
  6309.  
  6310.                 SDL_LockSurface(clipbg);
  6311.  
  6312.                 if(moveup) {
  6313.                     sx = xp;
  6314.                     sy = yp - ii;
  6315.                     temp = clipbg->pixels + sy * clipbg->pitch + sx * clipbg->format->BytesPerPixel;
  6316.                     dq = *temp;
  6317.                     if(npcinfo[i].spriteset == 11) dq = 0;
  6318.  
  6319.                     if(dq == 0) movinup = 1;
  6320.                     if(dq > 0) {
  6321.                         sx = xp - ii;
  6322.                         sy = yp - ii;
  6323.                         temp = clipbg->pixels + sy * clipbg->pitch + sx * clipbg->format->BytesPerPixel;
  6324.                         dq = *temp;
  6325.                         if(npcinfo[i].spriteset == 11) dq = 0;
  6326.                         if(dq == 0) {
  6327.                             movinup = 1;
  6328.                             movinleft = 1;
  6329.                         }
  6330.                     }
  6331.                     if(dq > 0) {
  6332.                         sx = xp + ii;
  6333.                         sy = yp - ii;
  6334.                         temp = clipbg->pixels + sy * clipbg->pitch + sx * clipbg->format->BytesPerPixel;
  6335.                         dq = *temp;
  6336.                         if(npcinfo[i].spriteset == 11) dq = 0;
  6337.                         if(dq == 0) {
  6338.                             movinup = 1;
  6339.                             movinright = 1;
  6340.                         }
  6341.                     }
  6342.                 }
  6343.  
  6344.                 if(movedown) {
  6345.                     sx = xp;
  6346.                     sy = yp + ii;
  6347.                     temp = clipbg->pixels + sy * clipbg->pitch + sx * clipbg->format->BytesPerPixel;
  6348.                     dq = *temp;
  6349.                     if(npcinfo[i].spriteset == 11) dq = 0;
  6350.                     if(dq == 0) movindown = 1;
  6351.                     if(dq > 0) {
  6352.                         sx = xp - ii;
  6353.                         sy = yp + ii;
  6354.                         temp = clipbg->pixels + sy * clipbg->pitch + sx * clipbg->format->BytesPerPixel;
  6355.                         dq = *temp;
  6356.                         if(npcinfo[i].spriteset == 11) dq = 0;
  6357.                         if(dq == 0) {
  6358.                             movindown = 1;
  6359.                             movinleft = 1;
  6360.                         }
  6361.                     }
  6362.                     if(dq > 0) {
  6363.                         sx = xp + ii;
  6364.                         sy = yp + ii;
  6365.                         temp = clipbg->pixels + sy * clipbg->pitch + sx * clipbg->format->BytesPerPixel;
  6366.                         dq = *temp;
  6367.                         if(npcinfo[i].spriteset == 11) dq = 0;
  6368.                         if(dq == 0 ) {
  6369.                             movindown = 1;
  6370.                             movinright = 1;
  6371.                         }
  6372.                     }
  6373.                 }
  6374.  
  6375.                 if(moveleft) {
  6376.                     sx = xp - ii;
  6377.                     sy = yp;
  6378.                     temp = clipbg->pixels + sy * clipbg->pitch + sx * clipbg->format->BytesPerPixel;
  6379.                     dq = *temp;
  6380.                     if(npcinfo[i].spriteset == 11) dq = 0;
  6381.                     if(dq == 0) movinleft = 1;
  6382.                     if(dq > 0) {
  6383.                         sx = xp - ii;
  6384.                         sy = yp - ii;
  6385.                         temp = clipbg->pixels + sy * clipbg->pitch + sx * clipbg->format->BytesPerPixel;
  6386.                         dq = *temp;
  6387.                         if(npcinfo[i].spriteset == 11) dq = 0;
  6388.                         if(dq == 0) {
  6389.                             movinleft = 1;
  6390.                             movinup = 1;
  6391.                         }
  6392.                     }
  6393.                     if(dq > 0) {
  6394.                         sx = xp - ii;
  6395.                         sy = yp + ii;
  6396.                         temp = clipbg->pixels + sy * clipbg->pitch + sx * clipbg->format->BytesPerPixel;
  6397.                         dq = *temp;
  6398.                         if(npcinfo[i].spriteset == 11) dq = 0;
  6399.                         if(dq == 0) {
  6400.                             movinleft = 1;
  6401.                             movindown = 1;
  6402.                         }
  6403.                     }
  6404.                 }
  6405.  
  6406.                 if(moveright) {
  6407.                     sx = xp + ii;
  6408.                     sy = yp;
  6409.                     temp = clipbg->pixels + sy * clipbg->pitch + sx * clipbg->format->BytesPerPixel;
  6410.                     dq = *temp;
  6411.                     if(npcinfo[i].spriteset == 11) dq = 0;
  6412.                     if(dq == 0) movinright = 1;
  6413.                     if(dq > 0) {
  6414.                         sx = xp + ii;
  6415.                         sy = yp - ii;
  6416.                         temp = clipbg->pixels + sy * clipbg->pitch + sx * clipbg->format->BytesPerPixel;
  6417.                         dq = *temp;
  6418.                         if(npcinfo[i].spriteset == 11) dq = 0;
  6419.                         if(dq == 0) {
  6420.                             movinright = 1;
  6421.                             movinup = 1;
  6422.                         }
  6423.                     }
  6424.                     if(dq > 0) {
  6425.                         sx = xp + ii;
  6426.                         sy = yp + ii;
  6427.                         temp = clipbg->pixels + sy * clipbg->pitch + sx * clipbg->format->BytesPerPixel;
  6428.                         dq = *temp;
  6429.                         if(npcinfo[i].spriteset == 11) dq = 0;
  6430.                         if(dq == 0) {
  6431.                             movinright = 1;
  6432.                             movindown = 1;
  6433.                         }
  6434.                     }
  6435.                 }
  6436.  
  6437.                 if(movinup) npy = npy - wspd * fpsr;
  6438.                 if(movindown) npy = npy + wspd * fpsr;
  6439.                 if(movinleft) npx = npx - wspd * fpsr;
  6440.                 if(movinright) npx = npx + wspd * fpsr;
  6441.  
  6442.                 if(checkpass == 1) {
  6443.                     pass = 0;
  6444.                     if(npx >= npcinfo[i].x1 * 16 - 8 && npx <= npcinfo[i].x2 * 16 + 8 && npy >= npcinfo[i].y1 * 16 - 8 && npy <= npcinfo[i].y2 * 16 + 8) pass = 1;
  6445.                     if(pass == 0) {
  6446.                         npx = onpx;
  6447.                         npy = onpy;
  6448.                         npcinfo[i].ticks = ticks;
  6449.                     }
  6450.                 }
  6451.  
  6452.                 float aspd = wspd;
  6453.  
  6454.                 if(npcinfo[i].spriteset == 10) aspd = wspd / 2;
  6455.  
  6456.                 xp = (npx / 2 + 6);
  6457.                 yp = (npy / 2 + 10);
  6458.  
  6459.                 sx = xp;
  6460.                 sy = yp;
  6461.                 temp = clipbg->pixels + sy * clipbg->pitch + sx * clipbg->format->BytesPerPixel;
  6462.                 bgc = *temp;
  6463.  
  6464.                 SDL_UnlockSurface(clipbg);
  6465.  
  6466.                 float anpx = npx + 12;
  6467.                 float anpy = npy + 20;
  6468.  
  6469.                 int lx = (int)anpx / 16; //(anpx - (anpx % 16)) / 16;
  6470.                 int ly = (int)anpy / 16; //(anpy - (anpy % 16)) / 16;
  6471.  
  6472.                 if(triggerloc[lx][ly] > -1) bgc = 1;
  6473.                 if(npcinfo[i].spriteset == 11) bgc = 0;
  6474.  
  6475.                 int rst = 0;
  6476.  
  6477.                 if(npcinfo[i].spriteset == 11) {
  6478.                     if(npx < 40 || npx > 280 || npy < 36 || npy > 204) rst = 1;
  6479.                 }
  6480.  
  6481.                 if(bgc > 0 || rst == 1) {
  6482.                     npx = onpx;
  6483.                     npy = onpy;
  6484.                 }
  6485.  
  6486.                 npcinfo[i].x = npx;
  6487.                 npcinfo[i].y = npy;
  6488.  
  6489.                 npcinfo[i].walkdir = wdir;
  6490.                 npcinfo[i].moving = 0;
  6491.  
  6492.                 if(npx != onpx || npy != onpy) npcinfo[i].moving = 1;
  6493.  
  6494.                 if(npcinfo[i].moving == 1) {
  6495.                     float frame = npcinfo[i].frame;
  6496.                     int cframe = npcinfo[i].cframe;
  6497.  
  6498.                     frame = frame + aspd * fpsr;
  6499.                     while(frame >= 16)
  6500.                         frame = frame - 16;
  6501.  
  6502.                     cframe = (int)(frame);
  6503.                     if(cframe > 16) cframe = 16 - 1;
  6504.                     if(cframe < 0) cframe = 0;
  6505.  
  6506.                     npcinfo[i].frame = frame;
  6507.                     npcinfo[i].cframe = cframe;
  6508.                 }
  6509.  
  6510.                 // spriteset1 specific
  6511.                 if(npcinfo[i].spriteset == 1 && npcinfo[i].attackattempt < ticks) {
  6512.                     if(npcinfo[i].attacknext < ticks && npcinfo[i].pause < ticks && npcinfo[i].attacking == 0) {
  6513.                         npx = npcinfo[i].x;
  6514.                         npy = npcinfo[i].y;
  6515.  
  6516.                         xdif = player.px - npx;
  6517.                         ydif = player.py - npy;
  6518.  
  6519.                         if(abs(xdif) < 20 && abs(ydif) < 20) {
  6520.                             npcinfo[i].attackattempt = ticks + 100;
  6521.                             if((int)(RND() * 2) == 0) {
  6522.                                 if(menabled == 1 && opeffects == 1) {
  6523.                                     //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndenemyhit))
  6524.                                     //FSOUND_setVolume(snd, opeffectsvol)
  6525.                                 }
  6526.  
  6527.                                 npcinfo[i].attacking = 1;
  6528.                                 npcinfo[i].attackframe = 0;
  6529.                             }
  6530.                         }
  6531.                     }
  6532.                 }
  6533.  
  6534.                 // onewing specific
  6535.                 if(npcinfo[i].spriteset == 2) {
  6536.                     if(npcinfo[i].attacknext < ticks && npcinfo[i].pause < ticks && npcinfo[i].attacking == 0) {
  6537.                             npx = npcinfo[i].x;
  6538.                             npy = npcinfo[i].y;
  6539.  
  6540.                             xdif = player.px - npx;
  6541.                             ydif = player.py - npy;
  6542.  
  6543.                             if(abs(xdif) < 24 && abs(ydif) < 24) {
  6544.                                 float dist = sqrt(xdif * xdif + ydif * ydif);
  6545.  
  6546.                                 if((dist) < 24) {
  6547.                                     if(menabled == 1 && opeffects == 1) {
  6548.                                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndbite))
  6549.                                         //FSOUND_setVolume(snd, opeffectsvol)
  6550.                                     }
  6551.  
  6552.                                     npcinfo[i].attacking = 1;
  6553.                                     npcinfo[i].attackframe = 0;
  6554.  
  6555.                                     npcinfo[i].headtargetx[0] = player.px + 12;
  6556.                                     npcinfo[i].headtargety[0] = player.py - 4;
  6557.                                 }
  6558.                             }
  6559.  
  6560.                     }
  6561.  
  6562.                     dospell = 0;
  6563.  
  6564.                     if(npcinfo[i].attacking == 0 && npcinfo[i].castpause < ticks) {
  6565.                         npcinfo[i].swayspd = npcinfo[i].swayspd + npcinfo[i].swayspd / 200 * fpsr;
  6566.                         if(npcinfo[i].swayspd > 15) {
  6567.                             dospell = 1;
  6568.                             npcinfo[i].swayspd = 1;
  6569.                         }
  6570.  
  6571.                         // sway code
  6572.                         npcinfo[i].swayangle = npcinfo[i].swayangle + npcinfo[i].swayspd * fpsr;
  6573.                         if(npcinfo[i].swayangle >= 360) npcinfo[i].swayangle = npcinfo[i].swayangle - 360;
  6574.  
  6575.                         npcinfo[i].headtargetx[0] = npcinfo[i].x + (24 - npcinfo[i].swayspd / 2) * sin(3.14159 / 180 * npcinfo[i].swayangle) + 12;
  6576.                         npcinfo[i].headtargety[0] = npcinfo[i].y - 36 + 16 + 8 * sin(3.14159 * 2 / 180 * npcinfo[i].swayangle);
  6577.                     }
  6578.  
  6579.                     if(dospell == 1) {
  6580.                         npcinfo[i].pause = ticks + 3000;
  6581.                         npcinfo[i].attacknext = ticks + 4500;
  6582.                         npcinfo[i].castpause = ticks + 4500;
  6583.  
  6584.                         game_castspell(3, npcinfo[i].x, npcinfo[i].y, npcinfo[i].x, npcinfo[i].y, i);
  6585.  
  6586.                         npcinfo[i].headtargetx[0] = npcinfo[i].x;
  6587.                         npcinfo[i].headtargety[0] = npcinfo[i].y - 36 + 16;
  6588.                     }
  6589.  
  6590.                     // targethead code
  6591.                     xdif = npcinfo[i].bodysection[7].x - npcinfo[i].headtargetx[0];
  6592.                     ydif = npcinfo[i].bodysection[7].y - npcinfo[i].headtargety[0];
  6593.  
  6594.  
  6595.                     npcinfo[i].bodysection[7].x = npcinfo[i].bodysection[7].x  - xdif * 0.4 * fpsr;
  6596.                     npcinfo[i].bodysection[7].y = npcinfo[i].bodysection[7].y  - ydif * 0.4 * fpsr;
  6597.  
  6598.  
  6599.                     npcinfo[i].bodysection[0].x = npcinfo[i].x + 12;
  6600.                     npcinfo[i].bodysection[0].y = npcinfo[i].y + 12;
  6601.  
  6602.                     for(int f = 6; f >= 1; f--) {
  6603.                         xdif = npcinfo[i].bodysection[f + 1].x - npcinfo[i].bodysection[f - 1].x;
  6604.                         ydif = npcinfo[i].bodysection[f + 1].y - npcinfo[i].bodysection[f - 1].y;
  6605.  
  6606.                         float tx = npcinfo[i].bodysection[f - 1].x + xdif / 2;
  6607.                         float ty = npcinfo[i].bodysection[f - 1].y + ydif / 2;
  6608.  
  6609.                         npcinfo[i].bodysection[f].x = npcinfo[i].bodysection[f].x - (npcinfo[i].bodysection[f].x - tx) / 3;
  6610.                         npcinfo[i].bodysection[f].y = npcinfo[i].bodysection[f].y - (npcinfo[i].bodysection[f].y - ty) / 3;
  6611.                     }
  6612.                 }
  6613.  
  6614.                 // boss1 specific and blackknight
  6615.                 if(npcinfo[i].spriteset == 3 || npcinfo[i].spriteset == 4) {
  6616.                     if(npcinfo[i].attacknext < ticks && npcinfo[i].pause < ticks && npcinfo[i].attacking == 0) {
  6617.                         npcinfo[i].attacking = 1;
  6618.                         npcinfo[i].attackframe = 0;
  6619.  
  6620.                         game_castspell(1, npcinfo[i].x, npcinfo[i].y, player.px, player.py, i);
  6621.                     }
  6622.  
  6623.                     if(npcinfo[i].castpause < ticks) {
  6624.                         game_castspell(6, npcinfo[i].x, npcinfo[i].y, player.px, player.py, i);
  6625.                         npcinfo[i].castpause = ticks + 12000;
  6626.                     }
  6627.                 }
  6628.  
  6629.  
  6630.                 // firehydra specific
  6631.                 if(npcinfo[i].spriteset == 5) {
  6632.                     npcinfo[i].swayspd = 4;
  6633.  
  6634.                     // sway code
  6635.                     npcinfo[i].swayangle = npcinfo[i].swayangle + npcinfo[i].swayspd * fpsr;
  6636.                     if(npcinfo[i].swayangle >= 360) npcinfo[i].swayangle = npcinfo[i].swayangle - 360;
  6637.  
  6638.                     for(int ff = 0; ff <= 2; ff++) {
  6639.                         if(npcinfo[i].hp > 10 * ff * 20) {
  6640.                             if(npcinfo[i].pause < ticks && npcinfo[i].attacking2[ff] == 0 && npcinfo[i].attacknext2[ff] < ticks) {
  6641.                                 npx = npcinfo[i].x;
  6642.                                 npy = npcinfo[i].y;
  6643.  
  6644.                                 xdif = player.px - npx;
  6645.                                 ydif = player.py - npy;
  6646.  
  6647.                                 if(abs(xdif) < 48 && abs(ydif) < 48) {
  6648.                                     float dist = sqrt(xdif * xdif + ydif * ydif);
  6649.  
  6650.                                     if((dist) < 36) {
  6651.                                         if(menabled == 1 && opeffects == 1) {
  6652.                                             //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndbite))
  6653.                                             //FSOUND_setVolume(snd, opeffectsvol)
  6654.                                         }
  6655.  
  6656.                                         npcinfo[i].attacking = 1;
  6657.                                         npcinfo[i].attacking2[ff] = 1;
  6658.                                         npcinfo[i].attackframe2[ff] = 0;
  6659.  
  6660.                                         npcinfo[i].headtargetx[ff] = player.px + 12;
  6661.                                         npcinfo[i].headtargety[ff] = player.py - 4;
  6662.  
  6663.                                         npcinfo[i].swayangle = 0;
  6664.                                     }
  6665.                                 }
  6666.  
  6667.                             }
  6668.  
  6669.                             if(npcinfo[i].attacking2[ff] == 0) {
  6670.                                 npcinfo[i].headtargetx[ff] = npcinfo[i].x + 38 * sin(3.14159 / 180 * (npcinfo[i].swayangle + 120 * ff)) + 12;
  6671.                                 npcinfo[i].headtargety[ff] = npcinfo[i].y - 46 + 16 + 16 * sin(3.14159 * 2 / 180 * (npcinfo[i].swayangle + 120 * ff));
  6672.                             }
  6673.  
  6674.                             // targethead code
  6675.                             xdif = npcinfo[i].bodysection[10 * ff + 9].x - npcinfo[i].headtargetx[ff];
  6676.                             ydif = npcinfo[i].bodysection[10 * ff + 9].y - npcinfo[i].headtargety[ff];
  6677.  
  6678.                             npcinfo[i].bodysection[10 * ff + 9].x = npcinfo[i].bodysection[10 * ff + 9].x  - xdif * 0.4 * fpsr;
  6679.                             npcinfo[i].bodysection[10 * ff + 9].y = npcinfo[i].bodysection[10 * ff + 9].y  - ydif * 0.4 * fpsr;
  6680.  
  6681.                             npcinfo[i].bodysection[10 * ff].x = npcinfo[i].x + 12 + 8 * cos(3.141592 * 2 * (itemyloc / 16 + ff * 120 / 360));
  6682.                             npcinfo[i].bodysection[10 * ff].y = npcinfo[i].y + 12 + 8 * sin(3.141592 * 2 * (itemyloc / 16 + ff * 120 / 360));
  6683.  
  6684.                             for(int f = 8; f >= 1; f--) {
  6685.                                 xdif = npcinfo[i].bodysection[ff * 10 + f + 1].x - npcinfo[i].bodysection[ff * 10 + f - 1].x;
  6686.                                 ydif = npcinfo[i].bodysection[ff * 10 + f + 1].y - npcinfo[i].bodysection[ff * 10 + f - 1].y;
  6687.  
  6688.                                 float tx = npcinfo[i].bodysection[ff * 10 + f - 1].x + xdif / 2;
  6689.                                 float ty = npcinfo[i].bodysection[ff * 10 + f - 1].y + ydif / 2;
  6690.  
  6691.                                 npcinfo[i].bodysection[ff * 10 + f].x = npcinfo[i].bodysection[ff * 10 + f].x - (npcinfo[i].bodysection[ff * 10 + f].x - tx) / 3;
  6692.                                 npcinfo[i].bodysection[ff * 10 + f].y = npcinfo[i].bodysection[ff * 10 + f].y - (npcinfo[i].bodysection[ff * 10 + f].y - ty) / 3;
  6693.                             }
  6694.                         }
  6695.                     }
  6696.                 }
  6697.  
  6698.                 // spriteset6 specific
  6699.                 if(npcinfo[i].spriteset == 6 && npcinfo[i].attackattempt < ticks) {
  6700.                     if(npcinfo[i].attacknext < ticks && npcinfo[i].pause < ticks && npcinfo[i].attacking == 0) {
  6701.                         npx = npcinfo[i].x;
  6702.                         npy = npcinfo[i].y;
  6703.  
  6704.                         xdif = player.px - npx;
  6705.                         ydif = player.py - npy;
  6706.  
  6707.                         pass = 0;
  6708.                         if(abs(xdif) < 48 && abs(ydif) < 6) pass = 1;
  6709.                         if(abs(ydif) < 48 && abs(xdif) < 6) pass = 2;
  6710.  
  6711.                         if(pass > 0) {
  6712.                             npcinfo[i].attackattempt = ticks + 100;
  6713.                             if((int)(RND() * 2) == 0) {
  6714.                                 npcinfo[i].attacking = 1;
  6715.                                 npcinfo[i].attackframe = 0;
  6716.  
  6717.                                 if(pass == 1 && xdif < 0) {
  6718.                                     nnxa = npx - 8;
  6719.                                     nnya = npy + 4;
  6720.                                     nnxb = npx - 48 - 8;
  6721.                                     nnyb = npy + 4;
  6722.                                 } else if(pass == 1 && xdif > 0) {
  6723.                                     nnxa = npx + 16;
  6724.                                     nnya = npy + 4;
  6725.                                     nnxb = npx + 16 + 48;
  6726.                                     nnyb = npy + 4;
  6727.                                 } else if(pass == 2 && ydif < 0) {
  6728.                                     nnya = npy;
  6729.                                     nnxa = npx + 4;
  6730.                                     nnyb = npy - 48;
  6731.                                     nnxb = npx + 4;
  6732.                                 } else if(pass == 2 && ydif > 0) {
  6733.                                     nnya = npy + 20;
  6734.                                     nnxa = npx + 4;
  6735.                                     nnyb = npy + 20 + 48;
  6736.                                     nnxb = npx + 4;
  6737.                                 }
  6738.  
  6739.                                 game_castspell(7, nnxa, nnya, nnxb, nnyb, i);
  6740.                             }
  6741.                         }
  6742.                     }
  6743.                 }
  6744.  
  6745.                 // wizard1 specific
  6746.                 if(npcinfo[i].spriteset == 7) {
  6747.                     if(npcinfo[i].attacknext < ticks && npcinfo[i].pause < ticks && npcinfo[i].attacking == 0) {
  6748.                         npcinfo[i].attacking = 1;
  6749.                         npcinfo[i].attackframe = 0;
  6750.  
  6751.                         game_castspell(9, npcinfo[i].x, npcinfo[i].y, player.px, player.py, i);
  6752.                     }
  6753.  
  6754.                     if(npcinfo[i].castpause < ticks) {
  6755.                         // game_castspell 6, npcinfo[i].x, npcinfo[i].y, player.px, player.py, i
  6756.                         // npcinfo[i].castpause = ticks + 12000
  6757.                     }
  6758.  
  6759.                 }
  6760.  
  6761.                 // spriteset6 specific
  6762.                 if(npcinfo[i].spriteset == 8 && npcinfo[i].attackattempt < ticks) {
  6763.                     if(npcinfo[i].attacknext < ticks && npcinfo[i].pause < ticks && npcinfo[i].attacking == 0) {
  6764.                         npx = npcinfo[i].x;
  6765.                         npy = npcinfo[i].y;
  6766.  
  6767.                         xdif = player.px - npx;
  6768.                         ydif = player.py - npy;
  6769.  
  6770.                         pass = 0;
  6771.                         if(abs(xdif) < 56 && abs(ydif) < 6) pass = 1;
  6772.                         if(abs(ydif) < 56 && abs(xdif) < 6) pass = 2;
  6773.  
  6774.                         if(pass > 0) {
  6775.                             npcinfo[i].attackattempt = ticks + 100;
  6776.                             if((int)(RND() * 2) == 0) {
  6777.                                 npcinfo[i].attacking = 1;
  6778.                                 npcinfo[i].attackframe = 0;
  6779.  
  6780.                                 if(pass == 1 && xdif < 0) {
  6781.                                     nnxa = npx - 8;
  6782.                                     nnya = npy + 4;
  6783.                                     nnxb = npx - 56 - 8;
  6784.                                     nnyb = npy + 4;
  6785.                                     npcinfo[i].walkdir = 2;
  6786.                                 } else if(pass == 1 && xdif > 0) {
  6787.                                     nnxa = npx + 16;
  6788.                                     nnya = npy + 4;
  6789.                                     nnxb = npx + 16 + 56;
  6790.                                     nnyb = npy + 4;
  6791.                                     npcinfo[i].walkdir = 3;
  6792.                                 } else if(pass == 2 && ydif < 0) {
  6793.                                     nnya = npy;
  6794.                                     nnxa = npx + 4;
  6795.                                     nnyb = npy - 56;
  6796.                                     nnxb = npx + 4;
  6797.                                     npcinfo[i].walkdir = 0;
  6798.                                 } else if(pass == 2 && ydif > 0) {
  6799.                                     nnya = npy + 20;
  6800.                                     nnxa = npx + 4;
  6801.                                     nnyb = npy + 20 + 56;
  6802.                                     nnxb = npx + 4;
  6803.                                     npcinfo[i].walkdir = 1;
  6804.                                 }
  6805.  
  6806.                                 game_castspell(7, nnxa, nnya, nnxb, nnyb, i);
  6807.                             }
  6808.                         }
  6809.                     }
  6810.                 }
  6811.  
  6812.                 // twowing specific
  6813.                 if(npcinfo[i].spriteset == 9) {
  6814.                     if(npcinfo[i].attacknext < ticks && npcinfo[i].pause < ticks && npcinfo[i].attacking == 0) {
  6815.                             npx = npcinfo[i].bodysection[7].x;
  6816.                             npy = npcinfo[i].bodysection[7].y;
  6817.  
  6818.                             xdif = player.px - npx;
  6819.                             ydif = player.py - npy;
  6820.  
  6821.                             if(abs(xdif) < 24 && abs(ydif) < 24) {
  6822.                                 float dist = sqrt(xdif * xdif + ydif * ydif);
  6823.  
  6824.                                 if((dist) < 24) {
  6825.                                     if(menabled == 1 && opeffects == 1) {
  6826.                                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndbite))
  6827.                                         //FSOUND_setVolume(snd, opeffectsvol)
  6828.                                     }
  6829.  
  6830.                                     npcinfo[i].attacking = 1;
  6831.                                     npcinfo[i].attackframe = 0;
  6832.  
  6833.                                     npcinfo[i].headtargetx[0] = player.px + 12;
  6834.                                     npcinfo[i].headtargety[0] = player.py - 4;
  6835.                                 }
  6836.                             }
  6837.  
  6838.                     }
  6839.  
  6840.                     if(npcinfo[i].attacking == 0 && npcinfo[i].castpause < ticks) {
  6841.                         npcinfo[i].swayspd = 4;
  6842.  
  6843.                         // sway code
  6844.                         npcinfo[i].swayangle = npcinfo[i].swayangle + npcinfo[i].swayspd * fpsr;
  6845.                         if(npcinfo[i].swayangle >= 360) npcinfo[i].swayangle = npcinfo[i].swayangle - 360;
  6846.  
  6847.                         npcinfo[i].headtargetx[0] = npcinfo[i].x + (24 - npcinfo[i].swayspd / 2) * sin(3.14159 / 180 * npcinfo[i].swayangle) + 12;
  6848.                         npcinfo[i].headtargety[0] = npcinfo[i].y - 36 + 16 + 8 * sin(3.14159 * 2 / 180 * npcinfo[i].swayangle);
  6849.                     }
  6850.  
  6851.                     if(dospell == 1) {
  6852.                         npcinfo[i].pause = ticks + 3000;
  6853.                         npcinfo[i].attacknext = ticks + 5000;
  6854.                         npcinfo[i].castpause = ticks + 3000;
  6855.  
  6856.                         game_castspell(3, npcinfo[i].x, npcinfo[i].y, npcinfo[i].x, npcinfo[i].y, i);
  6857.  
  6858.                         npcinfo[i].headtargetx[0] = npcinfo[i].x;
  6859.                         npcinfo[i].headtargety[0] = npcinfo[i].y - 36 + 16;
  6860.                     }
  6861.  
  6862.                     // targethead code
  6863.                     xdif = npcinfo[i].bodysection[7].x - npcinfo[i].headtargetx[0];
  6864.                     ydif = npcinfo[i].bodysection[7].y - npcinfo[i].headtargety[0];
  6865.  
  6866.  
  6867.                     npcinfo[i].bodysection[7].x = npcinfo[i].bodysection[7].x  - xdif * 0.4 * fpsr;
  6868.                     npcinfo[i].bodysection[7].y = npcinfo[i].bodysection[7].y  - ydif * 0.4 * fpsr;
  6869.  
  6870.                     npcinfo[i].bodysection[0].x = npcinfo[i].x + 12;
  6871.                     npcinfo[i].bodysection[0].y = npcinfo[i].y + 12;
  6872.  
  6873.                     for(int f = 6; f >= 1; f--) {
  6874.                         xdif = npcinfo[i].bodysection[f + 1].x - npcinfo[i].bodysection[f - 1].x;
  6875.                         ydif = npcinfo[i].bodysection[f + 1].y - npcinfo[i].bodysection[f - 1].y;
  6876.  
  6877.                         float tx = npcinfo[i].bodysection[f - 1].x + xdif / 2;
  6878.                         float ty = npcinfo[i].bodysection[f - 1].y + ydif / 2;
  6879.  
  6880.                         npcinfo[i].bodysection[f].x = npcinfo[i].bodysection[f].x - (npcinfo[i].bodysection[f].x - tx) / 3;
  6881.                         npcinfo[i].bodysection[f].y = npcinfo[i].bodysection[f].y - (npcinfo[i].bodysection[f].y - ty) / 3;
  6882.                     }
  6883.  
  6884.                 }
  6885.  
  6886.                 // dragon2 specific
  6887.                 if(npcinfo[i].spriteset == 10 && npcinfo[i].attackattempt < ticks) {
  6888.                     if(npcinfo[i].attacknext < ticks && npcinfo[i].pause < ticks && npcinfo[i].attacking == 0) {
  6889.                         npx = npcinfo[i].x;
  6890.                         npy = npcinfo[i].y;
  6891.  
  6892.                         xdif = player.px - npx;
  6893.                         ydif = player.py - npy;
  6894.  
  6895.                         if(abs(xdif) < 32 && abs(ydif) < 32) {
  6896.                             npcinfo[i].attackattempt = ticks + 100;
  6897.                             if((int)(RND() * 2) == 0) {
  6898.                                 if(menabled == 1 && opeffects == 1) {
  6899.                                     //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndenemyhit))
  6900.                                     //FSOUND_setVolume(snd, opeffectsvol)
  6901.                                 }
  6902.  
  6903.                                 npcinfo[i].attacking = 1;
  6904.                                 npcinfo[i].attackframe = 0;
  6905.                             }
  6906.                         }
  6907.                     }
  6908.                 }
  6909.  
  6910.  
  6911.                 // endboss specific
  6912.                 if(npcinfo[i].spriteset == 11 && npcinfo[i].attackattempt < ticks) {
  6913.                     if(npcinfo[i].attacknext < ticks && npcinfo[i].pause < ticks && npcinfo[i].attacking == 0) {
  6914.                         npx = npcinfo[i].x;
  6915.                         npy = npcinfo[i].y;
  6916.  
  6917.                         xdif = player.px - npx;
  6918.                         ydif = player.py - npy;
  6919.  
  6920.                         if(abs(xdif) < 38 && abs(ydif) < 38) {
  6921.                             npcinfo[i].attackattempt = ticks + 100;
  6922.                             if((int)(RND() * 2) == 0) {
  6923.                                 if(menabled == 1 && opeffects == 1) {
  6924.                                     //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndice))
  6925.                                     //FSOUND_setVolume(snd, opeffectsvol)
  6926.                                 }
  6927.                                 npcinfo[i].attacking = 1;
  6928.                                 npcinfo[i].attackframe = 0;
  6929.                             }
  6930.                         }
  6931.                     }
  6932.                 }
  6933.             }
  6934.  
  6935.  
  6936.             int dist; float damage;
  6937.  
  6938.             npx = npcinfo[i].x;
  6939.             npy = npcinfo[i].y;
  6940.  
  6941.             int xp = (npx / 2 + 6);
  6942.             int yp = (npy / 2 + 10);
  6943.  
  6944.             rcSrc.x = xp - 1;
  6945.             rcSrc.y = yp - 1;
  6946.             rcSrc.w = 3;
  6947.             rcSrc.h = 3;
  6948.  
  6949.             if(npcinfo[i].pause < ticks) SDL_FillRect(clipbg, &rcSrc, i);
  6950.  
  6951.  
  6952.             pass = 0;
  6953.             if(npcinfo[i].attacking == 1) pass = 1;
  6954.             if(npcinfo[i].spriteset == 5) {
  6955.                 if(npcinfo[i].attacking2[0] == 1) pass = 1;
  6956.                 if(npcinfo[i].attacking2[1] == 1) pass = 1;
  6957.                 if(npcinfo[i].attacking2[2] == 1) pass = 1;
  6958.             }
  6959.  
  6960.             if(pass == 1) {
  6961.                 // spriteset1 specific
  6962.                 if(npcinfo[i].spriteset == 1) {
  6963.                     npcinfo[i].attackframe = npcinfo[i].attackframe + npcinfo[i].attackspd * fpsr;
  6964.                     if(npcinfo[i].attackframe >= 16) {
  6965.                         npcinfo[i].attackframe = 0;
  6966.                         npcinfo[i].attacking = 0;
  6967.                         npcinfo[i].attacknext = ticks + npcinfo[i].attackdelay;
  6968.                     }
  6969.  
  6970.                     npcinfo[i].cattackframe = (int)(npcinfo[i].attackframe);
  6971.  
  6972.                     npx = npcinfo[i].x;
  6973.                     npy = npcinfo[i].y;
  6974.  
  6975.                     xdif = player.px - npx;
  6976.                     ydif = player.py - npy;
  6977.  
  6978.                     dist = 10;
  6979.  
  6980.                     if(abs(xdif) < dist && abs(ydif) < dist && player.pause < ticks) {
  6981.                         npcinfo[i].attacknext = ticks + npcinfo[i].attackdelay;
  6982.                         // npcinfo[i].attackframe = 0;
  6983.                         // npcinfo[i].attacking = 0;
  6984.  
  6985.                         damage = (float)npcinfo[i].attackdamage * (0.5 + RND() * 1.0);
  6986.  
  6987.                         if(player.hp > 0) game_damageplayer(damage);
  6988.                     }
  6989.                 }
  6990.  
  6991.                 if(npcinfo[i].spriteset == 2) {
  6992.                     // targethead code
  6993.                     xdif = npcinfo[i].bodysection[7].x - npcinfo[i].headtargetx[0];
  6994.                     ydif = npcinfo[i].bodysection[7].y - npcinfo[i].headtargety[0];
  6995.  
  6996.                     npcinfo[i].bodysection[7].x = npcinfo[i].bodysection[7].x  - xdif * 0.4 * fpsr;
  6997.                     npcinfo[i].bodysection[7].y = npcinfo[i].bodysection[7].y  - ydif * 0.4 * fpsr;
  6998.  
  6999.                     npcinfo[i].bodysection[0].x = npcinfo[i].x + 12;
  7000.                     npcinfo[i].bodysection[0].y = npcinfo[i].y + 12;
  7001.  
  7002.                     for(int f = 6; f >= 1; f--) {
  7003.                         xdif = npcinfo[i].bodysection[f + 1].x - npcinfo[i].bodysection[f - 1].x;
  7004.                         ydif = npcinfo[i].bodysection[f + 1].y - npcinfo[i].bodysection[f - 1].y;
  7005.  
  7006.                         float tx = npcinfo[i].bodysection[f - 1].x + xdif / 2;
  7007.                         float ty = npcinfo[i].bodysection[f - 1].y + ydif / 2;
  7008.  
  7009.                         npcinfo[i].bodysection[f].x = npcinfo[i].bodysection[f].x - (npcinfo[i].bodysection[f].x - tx);
  7010.                         npcinfo[i].bodysection[f].y = npcinfo[i].bodysection[f].y - (npcinfo[i].bodysection[f].y - ty);
  7011.                     }
  7012.  
  7013.                     npcinfo[i].attackframe = npcinfo[i].attackframe + npcinfo[i].attackspd * fpsr;
  7014.                     if(npcinfo[i].attackframe >= 16) {
  7015.                         npcinfo[i].attackframe = 0;
  7016.                         npcinfo[i].attacking = 0;
  7017.                         npcinfo[i].attacknext = ticks + npcinfo[i].attackdelay;
  7018.                     }
  7019.  
  7020.                     npcinfo[i].cattackframe = (int)(npcinfo[i].attackframe);
  7021.  
  7022.                     npx = npcinfo[i].bodysection[7].x;
  7023.                     npy = (npcinfo[i].bodysection[7].y + 16);
  7024.  
  7025.                     xdif = (player.px + 12) - npx;
  7026.                     ydif = (player.py + 12) - npy;
  7027.  
  7028.                     dist = 8;
  7029.  
  7030.                     if(abs(xdif) < dist && abs(ydif) < dist && player.pause < ticks) {
  7031.                         npcinfo[i].attacknext = ticks + npcinfo[i].attackdelay;
  7032.                         // npcinfo[i].attackframe = 0
  7033.                         // npcinfo[i].attacking = 0
  7034.                         damage = (float)npcinfo[i].attackdamage * (1.0 + (RND() * 0.5));
  7035.                         if(player.hp > 0) game_damageplayer(damage);
  7036.                     }
  7037.                 }
  7038.  
  7039.  
  7040.                 // firehydra
  7041.                 if(npcinfo[i].spriteset == 5) {
  7042.                     for(int ff = 0; ff <= 2; ff++) {
  7043.                         if(npcinfo[i].attacking2[ff] == 1) {
  7044.                             xdif = npcinfo[i].bodysection[10 * ff + 9].x - npcinfo[i].headtargetx[ff];
  7045.                             ydif = npcinfo[i].bodysection[10 * ff + 9].y - npcinfo[i].headtargety[ff];
  7046.  
  7047.                             npcinfo[i].bodysection[10 * ff + 9].x = npcinfo[i].bodysection[10 * ff + 9].x  - xdif * .2 * fpsr;
  7048.                             npcinfo[i].bodysection[10 * ff + 9].y = npcinfo[i].bodysection[10 * ff + 9].y  - ydif * .2 * fpsr;
  7049.  
  7050.                             npcinfo[i].bodysection[10 * ff].x = npcinfo[i].x + 12 + 8 * cos(3.141592 * 2 * (itemyloc / 16 + ff * 120 / 360));
  7051.                             npcinfo[i].bodysection[10 * ff].y = npcinfo[i].y + 12 + 8 * sin(3.141592 * 2 * (itemyloc / 16 + ff * 120 / 360));
  7052.  
  7053.                             for(int f = 8; f >= 1; f--) {
  7054.                                 xdif = npcinfo[i].bodysection[ff * 10 + f + 1].x - npcinfo[i].bodysection[ff * 10 + f - 1].x;
  7055.                                 ydif = npcinfo[i].bodysection[ff * 10 + f + 1].y - npcinfo[i].bodysection[ff * 10 + f - 1].y;
  7056.  
  7057.                                 float tx = npcinfo[i].bodysection[ff * 10 + f - 1].x + xdif / 2;
  7058.                                 float ty = npcinfo[i].bodysection[ff * 10 + f - 1].y + ydif / 2;
  7059.  
  7060.                                 npcinfo[i].bodysection[ff * 10 + f].x = npcinfo[i].bodysection[ff * 10 + f].x - (npcinfo[i].bodysection[ff * 10 + f].x - tx) / 3;
  7061.                                 npcinfo[i].bodysection[ff * 10 + f].y = npcinfo[i].bodysection[ff * 10 + f].y - (npcinfo[i].bodysection[ff * 10 + f].y - ty) / 3;
  7062.                             }
  7063.  
  7064.                             npcinfo[i].attackframe2[ff] = npcinfo[i].attackframe2[ff] + npcinfo[i].attackspd * fpsr;
  7065.                             if(npcinfo[i].attackframe2[ff] >= 16) {
  7066.                                 npcinfo[i].attackframe2[ff] = 0;
  7067.                                 npcinfo[i].attacking2[ff] = 0;
  7068.                                 npcinfo[i].attacknext2[ff] = ticks + npcinfo[i].attackdelay;
  7069.                             }
  7070.  
  7071.                             npcinfo[i].cattackframe = (int)(npcinfo[i].attackframe);
  7072.  
  7073.                             npx = npcinfo[i].bodysection[10 * ff + 9].x;
  7074.                             npy = (npcinfo[i].bodysection[10 * ff + 9].y + 16);
  7075.  
  7076.                             xdif = (player.px + 12) - npx;
  7077.                             ydif = (player.py + 12) - npy;
  7078.  
  7079.                             dist = 8;
  7080.  
  7081.                             if(abs(xdif) < dist && abs(ydif) < dist && player.pause < ticks) {
  7082.                                 npcinfo[i].attacknext2[ff] = ticks + npcinfo[i].attackdelay;
  7083.                                 // npcinfo[i].attackframe2(ff) = 0
  7084.                                 // npcinfo[i].attacking2(ff) = 0
  7085.                                 damage = (float)npcinfo[i].attackdamage * (1.0 + RND() * 0.5);
  7086.                                 if(player.hp > 0) game_damageplayer(damage);
  7087.                             }
  7088.                         }
  7089.                     }
  7090.  
  7091.                 }
  7092.  
  7093.                 // twowing specific
  7094.                 if(npcinfo[i].spriteset == 9) {
  7095.                     // targethead code
  7096.                     xdif = npcinfo[i].bodysection[7].x - npcinfo[i].headtargetx[0];
  7097.                     ydif = npcinfo[i].bodysection[7].y - npcinfo[i].headtargety[0];
  7098.  
  7099.                     npcinfo[i].bodysection[7].x = npcinfo[i].bodysection[7].x - xdif * 0.4 * fpsr;
  7100.                     npcinfo[i].bodysection[7].y = npcinfo[i].bodysection[7].y - ydif * 0.4 * fpsr;
  7101.  
  7102.                     npcinfo[i].bodysection[0].x = npcinfo[i].x + 12;
  7103.                     npcinfo[i].bodysection[0].y = npcinfo[i].y + 12;
  7104.  
  7105.                     for(int f = 6; f >= 1; f--) {
  7106.                         xdif = npcinfo[i].bodysection[f + 1].x - npcinfo[i].bodysection[f - 1].x;
  7107.                         ydif = npcinfo[i].bodysection[f + 1].y - npcinfo[i].bodysection[f - 1].y;
  7108.  
  7109.                         float tx = npcinfo[i].bodysection[f - 1].x + xdif / 2;
  7110.                         float ty = npcinfo[i].bodysection[f - 1].y + ydif / 2;
  7111.  
  7112.                         npcinfo[i].bodysection[f].x = npcinfo[i].bodysection[f].x - (npcinfo[i].bodysection[f].x - tx);
  7113.                         npcinfo[i].bodysection[f].y = npcinfo[i].bodysection[f].y - (npcinfo[i].bodysection[f].y - ty);
  7114.                     }
  7115.  
  7116.                     npcinfo[i].attackframe = npcinfo[i].attackframe + npcinfo[i].attackspd * fpsr;
  7117.                     if(npcinfo[i].attackframe >= 16) {
  7118.                         npcinfo[i].attackframe = 0;
  7119.                         npcinfo[i].attacking = 0;
  7120.                         npcinfo[i].attacknext = ticks + npcinfo[i].attackdelay;
  7121.                     }
  7122.  
  7123.                     npcinfo[i].cattackframe = (int)(npcinfo[i].attackframe);
  7124.  
  7125.                     npx = npcinfo[i].bodysection[7].x;
  7126.                     npy = (npcinfo[i].bodysection[7].y + 16);
  7127.  
  7128.                     xdif = (player.px + 12) - npx;
  7129.                     ydif = (player.py + 12) - npy;
  7130.  
  7131.                     dist = 8;
  7132.  
  7133.                     if(abs(xdif) < dist && abs(ydif) < dist && player.pause < ticks) {
  7134.                         npcinfo[i].attacknext = ticks + npcinfo[i].attackdelay;
  7135.                         // npcinfo[i].attackframe = 0
  7136.                         // npcinfo[i].attacking = 0
  7137.                         damage = (float)npcinfo[i].attackdamage * (1.0 + RND() * 0.5);
  7138.                         if(player.hp > 0) game_damageplayer(damage);
  7139.                     }
  7140.                 }
  7141.  
  7142.                 // dragon 2 specific
  7143.                 if(npcinfo[i].spriteset == 10) {
  7144.  
  7145.                     npcinfo[i].attackframe = npcinfo[i].attackframe + npcinfo[i].attackspd * fpsr;
  7146.                     if(npcinfo[i].attackframe >= 16) {
  7147.                         npcinfo[i].attackframe = 0;
  7148.                         npcinfo[i].attacking = 0;
  7149.                         npcinfo[i].attacknext = ticks + npcinfo[i].attackdelay;
  7150.                     }
  7151.  
  7152.                     npcinfo[i].cattackframe = (int)(npcinfo[i].attackframe);
  7153.  
  7154.                     npx = npcinfo[i].x;
  7155.                     npy = npcinfo[i].y;
  7156.  
  7157.                     xdif = player.px - npx;
  7158.                     ydif = player.py - npy;
  7159.  
  7160.                     dist = 16 + npcinfo[i].attackframe;
  7161.  
  7162.                     if(abs(xdif) < dist && abs(ydif) < dist && player.pause < ticks) {
  7163.                         npcinfo[i].attacknext = ticks + npcinfo[i].attackdelay;
  7164.                         // npcinfo[i].attackframe = 0
  7165.                         // npcinfo[i].attacking = 0
  7166.                         damage = (float)npcinfo[i].attackdamage * (0.5 + RND() * 1.0);
  7167.                         if(player.hp > 0) game_damageplayer(damage);
  7168.                     }
  7169.                 }
  7170.  
  7171.                 // endboss specific
  7172.                 if(npcinfo[i].spriteset == 11) {
  7173.                     npcinfo[i].attackframe = npcinfo[i].attackframe + npcinfo[i].attackspd * fpsr;
  7174.                     if(npcinfo[i].attackframe >= 16) {
  7175.                         npcinfo[i].attackframe = 0;
  7176.                         npcinfo[i].attacking = 0;
  7177.                         npcinfo[i].attacknext = ticks + npcinfo[i].attackdelay;
  7178.                     }
  7179.  
  7180.                     npcinfo[i].cattackframe = (int)(npcinfo[i].attackframe);
  7181.  
  7182.                     npx = npcinfo[i].x;
  7183.                     npy = npcinfo[i].y;
  7184.  
  7185.                     xdif = player.px - npx;
  7186.                     ydif = player.py - npy;
  7187.  
  7188.                     dist = 36;
  7189.  
  7190.                     if(abs(xdif) < dist && abs(ydif) < dist && player.pause < ticks) {
  7191.                         npcinfo[i].attacknext = ticks + npcinfo[i].attackdelay;
  7192.                         // npcinfo[i].attackframe = 0
  7193.                         // npcinfo[i].attacking = 0
  7194.                         damage = (float)npcinfo[i].attackdamage * (0.5 + RND() * 1.0);
  7195.                         if(player.hp > 0) game_damageplayer(damage);
  7196.                     }
  7197.                 }
  7198.             }
  7199.             // -------end fight code
  7200.         }
  7201.     }
  7202. }
  7203.  
  7204. void game_updspells()
  7205. {
  7206.     int foundel[5];
  7207.     float npx, npy;
  7208.     long cl1, cl2, cl3;
  7209.     int ll[4][2];
  7210.  
  7211.     float xloc, yloc, xst, yst, xdif, ydif;
  7212.  
  7213.     for(int i = 0; i <= MAXSPELL; i++) {
  7214.         if(spellinfo[i].frame > 0) {
  7215.             int spellnum = spellinfo[i].spellnum;
  7216.  
  7217.             // water
  7218.             if(spellnum == 0 && forcepause == 0) {
  7219.                 float fr = (32 - spellinfo[i].frame);
  7220.  
  7221.                 ll[0][0] = -2;
  7222.                 ll[0][1] = -3;
  7223.                 ll[1][0] = 2;
  7224.                 ll[1][1] = -3;
  7225.                 ll[2][0] = -4;
  7226.                 ll[2][1] = -2;
  7227.                 ll[3][0] = 4;
  7228.                 ll[3][1] = -2;
  7229.  
  7230.                 for(int f = 0; f <= 3; f++) {
  7231.                     if(fr > f * 4 && fr < f * 4 + 16) {
  7232.                         float alf = 255;
  7233.  
  7234.                         if(fr < f * 4 + 8) {
  7235.                             int fi = (int)((fr - f * 4) * 3) % 4;
  7236.                             rcSrc.x = 32 + fi * 16;
  7237.                             rcSrc.y = 80;
  7238.                             rcSrc.w = 16;
  7239.                             rcSrc.h = 16;
  7240.  
  7241.                             xloc = spellinfo[i].enemyx + 12 + ll[f][0] * 16;
  7242.                             yloc = spellinfo[i].enemyy + 16 + ll[f][1] * 16;
  7243.  
  7244.                             rcDest.x = xloc;
  7245.                             rcDest.y = yloc;
  7246.  
  7247.                             alf = 255 * ((fr - f * 4) / 8);
  7248.                         }
  7249.  
  7250.                         if(fr >= f * 4 + 8) {
  7251.                             int fi = 0; // ??
  7252.  
  7253.                             if(f == 0 || f == 2) fi = 0;
  7254.                             if(f == 1 || f == 3) fi = 1;
  7255.                             rcSrc.x = 32 + fi * 16;
  7256.                             rcSrc.y = 80;
  7257.                             rcSrc.w = 16;
  7258.                             rcSrc.h = 16;
  7259.  
  7260.                             xst = spellinfo[i].enemyx + 12 + ll[f][0] * 16;
  7261.                             yst = spellinfo[i].enemyy + 16 + ll[f][1] * 16;
  7262.  
  7263.                             float xi = (spellinfo[i].enemyx - xst) * 2 / 8;
  7264.                             float yi = (spellinfo[i].enemyy - yst) * 2 / 8;
  7265.  
  7266.                             float fl = (fr - f * 4 - 8) / 2;
  7267.                             xloc = xst + xi * fl * fl;
  7268.                             yloc = yst + yi * fl * fl;
  7269.  
  7270.                             rcDest.x = xloc;
  7271.                             rcDest.y = yloc;
  7272.  
  7273.                             alf = 255;
  7274.                         }
  7275.  
  7276.                         if(xloc > -16 && xloc < 304 && yloc > -16 && yloc < 224) {
  7277.                             SDL_SetAlpha(spellimg, SDL_SRCALPHA, alf);
  7278.                             SDL_BlitSurface(spellimg, &rcSrc, videobuffer, &rcDest);
  7279.                             SDL_SetAlpha(spellimg, SDL_SRCALPHA, 255);
  7280.  
  7281.                             if(spellinfo[i].damagewho == 0) {
  7282.                                 for(int e = 1; e <= lastnpc; e++) {
  7283.  
  7284.                                     xdif = (xloc + 16) - (npcinfo[e].x + 12);
  7285.                                     ydif = (yloc + 16) - (npcinfo[e].y + 12);
  7286.  
  7287.                                     if((abs(xdif) < 16 && abs(ydif) < 16)) {
  7288.                                         float damage = (float)player.spelldamage * (1.0 + RND() * 0.5) * (float)spellinfo[i].strength;
  7289.  
  7290.                                         if(npcinfo[e].hp > 0 && npcinfo[e].pause < ticks) {
  7291.                                             game_damagenpc(e, damage, 1);
  7292.                                             if(menabled == 1 && opeffects == 1) {
  7293.                                                 //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndics))
  7294.                                                 //FSOUND_setVolume(snd, opeffectsvol)
  7295.                                             }
  7296.                                         }
  7297.                                     }
  7298.                                 }
  7299.                             }
  7300.  
  7301.                             // check for post damage
  7302.                             if(nposts > 0) {
  7303.                                 for(int e = 0; e <= nposts - 1; e++) {
  7304.                                     xdif = (xloc + 16) - (postinfo[e][0] + 8);
  7305.                                     ydif = (yloc + 16) - (postinfo[e][1] + 8);
  7306.  
  7307.                                     if((abs(xdif) < 16 && abs(ydif) < 16)) {
  7308.                                         objmapf[curmap][(int)postinfo[e][0] / 16][(int)postinfo[e][1] / 16] = 1;
  7309.                                         objmap[(int)postinfo[e][0] / 16][(int)postinfo[e][1] / 16] = -1;
  7310.  
  7311.                                         rcSrc.x = postinfo[e][0] / 2;
  7312.                                         rcSrc.y = postinfo[e][1] / 2;
  7313.                                         rcSrc.w = 8;
  7314.                                         rcSrc.h = 8;
  7315.  
  7316.                                         SDL_FillRect(clipbg2, &rcSrc, 0);
  7317.  
  7318.                                         game_addFloatIcon(99, postinfo[e][0], postinfo[e][1]);
  7319.  
  7320.                                         if(menabled == 1 && opeffects == 1) {
  7321.                                             //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndics))
  7322.                                             //FSOUND_setVolume(snd, opeffectsvol)
  7323.                                         }
  7324.                                     }
  7325.                                 }
  7326.                             }
  7327.                         }
  7328.                     }
  7329.                 }
  7330.             }
  7331.  
  7332.             // metal
  7333.             if(spellnum == 1 && forcepause == 0) {
  7334.                 float npx, npy, xdif, ydif;
  7335.                 int npc;
  7336.                 int fr = (int)((32 - spellinfo[i].frame)*4) % 3;
  7337.  
  7338.                 rcSrc.x = fr * 48;
  7339.                 rcSrc.y = 0;
  7340.                 rcSrc.w = 48;
  7341.                 rcSrc.h = 48;
  7342.  
  7343.                 float c1 = (32 - spellinfo[i].frame) / 16;
  7344.                 //float c = sin(3.14159 * 2 * c1);
  7345.  
  7346.                 float halfx = (spellinfo[i].homex-12) + ((spellinfo[i].enemyx-12) - (spellinfo[i].homex-12)) / 2;
  7347.                 float halfy = (spellinfo[i].homey-12) + ((spellinfo[i].enemyy-12) - (spellinfo[i].homey-12)) / 2;
  7348.  
  7349.                 float wdth = (halfx - spellinfo[i].homex) * 1.2;
  7350.                 float hight = (halfy - spellinfo[i].homey) * 1.2;
  7351.  
  7352.                 xloc = halfx + wdth * cos(3.14159 + 3.14159 * 2 * c1);
  7353.                 yloc = halfy + hight * sin(3.14159 + 3.14159 * 2 * c1);
  7354.  
  7355.                 rcDest.x = xloc;
  7356.                 rcDest.y = yloc;
  7357.  
  7358.                 SDL_BlitSurface(spellimg, &rcSrc, videobuffer, &rcDest);
  7359.  
  7360.                 spellinfo[i].frame = spellinfo[i].frame - 0.2 * fpsr;
  7361.                 if(spellinfo[i].frame < 0) spellinfo[i].frame = 0;
  7362.  
  7363.                 if(spellinfo[i].damagewho == 0) {
  7364.                     for(int e = 1; e <= lastnpc; e++) {
  7365.                         xdif = (xloc + 24) - (npcinfo[e].x + 12);
  7366.                         ydif = (yloc + 24) - (npcinfo[e].y + 12);
  7367.  
  7368.                         if((abs(xdif) < 24 && abs(ydif) < 24)) {
  7369.                             float damage = (float)player.spelldamage * (1.0 + RND() * 0.5) * (float)spellinfo[i].strength;
  7370.  
  7371.                             if(npcinfo[e].hp > 0 && npcinfo[e].pause < ticks) {
  7372.                                 game_damagenpc(e, damage, 1);
  7373.                                 if(menabled == 1 && opeffects == 1) {
  7374.                                     //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndmetalhit))
  7375.                                     //FSOUND_setVolume(snd, opeffectsvol)
  7376.                                 }
  7377.                             }
  7378.                         }
  7379.                     }
  7380.                 }
  7381.  
  7382.                 if(spellinfo[i].damagewho == 1) {
  7383.  
  7384.                     // --------- boss 1 specific
  7385.                     if(spellinfo[i].frame == 0 && npcinfo[spellinfo[i].npc].spriteset == 3) {
  7386.                         npc = spellinfo[i].npc;
  7387.                         npcinfo[npc].attackframe = 0;
  7388.                         npcinfo[npc].attacking = 0;
  7389.  
  7390.                         npcinfo[npc].pause = ticks + 1000;
  7391.                         npcinfo[npc].attacknext = ticks + 4000;
  7392.                     }
  7393.                     // ---------------
  7394.  
  7395.                     // --------- blackknight specific
  7396.                     if(spellinfo[i].frame == 0 && npcinfo[spellinfo[i].npc].spriteset == 4) {
  7397.                         npc = spellinfo[i].npc;
  7398.                         npcinfo[npc].attackframe = 0;
  7399.                         npcinfo[npc].attacking = 0;
  7400.  
  7401.                         npcinfo[npc].pause = ticks + 1000;
  7402.                         npcinfo[npc].attacknext = ticks + 3500;
  7403.                     }
  7404.                     // ---------------
  7405.  
  7406.                     xdif = (xloc + 24) - (player.px + 12);
  7407.                     ydif = (yloc + 24) - (player.py + 12);
  7408.  
  7409.                     if((abs(xdif) < 24 && abs(ydif) < 24) && player.pause < ticks) {
  7410.                         npx = player.px;
  7411.                         npy = player.py;
  7412.  
  7413.                         float damage = (float)npcinfo[spellinfo[i].npc].spelldamage * (1.0 + RND() * 0.5);
  7414.  
  7415.                         if(player.hp > 0) {
  7416.                             game_damageplayer(damage);
  7417.                             if(menabled == 1 && opeffects == 1) {
  7418.                                 //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndmetalhit))
  7419.                                 //FSOUND_setVolume(snd, opeffectsvol)
  7420.                             }
  7421.                         }
  7422.                     }
  7423.                 }
  7424.  
  7425.  
  7426.                 // check for(int post damage
  7427.                 if(nposts > 0) {
  7428.                     for(int e = 0; e <= nposts - 1; e++) {
  7429.                         xdif = (xloc + 24) - (postinfo[e][0] + 8);
  7430.                         ydif = (yloc + 24) - (postinfo[e][1] + 8);
  7431.  
  7432.                         if((abs(xdif) < 24 && abs(ydif) < 24)) {
  7433.                             objmapf[curmap][(int)postinfo[e][0] / 16][(int)postinfo[e][1] / 16] = 1;
  7434.                             objmap[(int)postinfo[e][0] / 16][(int)postinfo[e][1] / 16] = -1;
  7435.  
  7436.                             rcSrc.x = postinfo[e][0] / 2;
  7437.                             rcSrc.y = postinfo[e][1] / 2;
  7438.                             rcSrc.w = 8;
  7439.                             rcSrc.h = 8;
  7440.  
  7441.                             SDL_FillRect(clipbg2, &rcSrc, 0);
  7442.  
  7443.                             game_addFloatIcon(99, postinfo[e][0], postinfo[e][1]);
  7444.  
  7445.                             if(menabled == 1 && opeffects == 1) {
  7446.                                 //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndmetalhit))
  7447.                                 //FSOUND_setVolume(snd, opeffectsvol)
  7448.                             }
  7449.                         }
  7450.                     }
  7451.                 }
  7452.             }
  7453.  
  7454.             // earth
  7455.             if(spellnum == 2 && forcepause == 0) {
  7456.                 float hght = 240 - spellinfo[i].enemyy;
  7457.  
  7458.                 for(int f = 8; f >= 0; f--) {
  7459.  
  7460.                     float fr = (32 - spellinfo[i].frame);
  7461.  
  7462.                     if(fr > f && fr < f + 16) {
  7463.                         rcSrc.x = 32 * spellinfo[i].rockimg[f];
  7464.                         rcSrc.y = 48;
  7465.                         rcSrc.w = 32;
  7466.                         rcSrc.h = 32;
  7467.  
  7468.                         int scatter = 0;
  7469.                         if(fr < 8 + f) {
  7470.                             xloc = spellinfo[i].enemyx - 4;
  7471.                             yloc = spellinfo[i].enemyy * (1 - cos(3.14159 / 2 * (fr - f) / 8)); // ^ 2;
  7472.                             yloc *= yloc;
  7473.                         } else {
  7474.                             scatter = 1;
  7475.                             xloc = spellinfo[i].enemyx - 4 - spellinfo[i].rockdeflect[f] * sin(3.14159 / 2* ((fr - f) - 8) / 8);
  7476.                             yloc = spellinfo[i].enemyy + hght * (1 - cos(3.14159 / 2 * ((fr - f) - 8) / 8));
  7477.                         }
  7478.  
  7479.                         rcDest.x = xloc;
  7480.                         rcDest.y = yloc;
  7481.  
  7482.                         if(xloc > -16 && xloc < 304 && yloc > -16 && yloc < 224) {
  7483.                             SDL_BlitSurface(spellimg, &rcSrc, videobuffer, &rcDest);
  7484.  
  7485.                             if(scatter == 1) {
  7486.                                 if(spellinfo[i].damagewho == 0) {
  7487.                                     for(int e = 1; e <= lastnpc; e++) {
  7488.                                         xdif = (xloc + 16) - (npcinfo[e].x + 12);
  7489.                                         ydif = (yloc + 16) - (npcinfo[e].y + 12);
  7490.  
  7491.                                         if((abs(xdif) < 16 && abs(ydif) < 16)) {
  7492.                                             float damage = (float)player.spelldamage * (1.0 + RND() * 0.5) * (float)spellinfo[i].strength;
  7493.  
  7494.                                             if(npcinfo[e].hp > 0 && npcinfo[e].pause < ticks) {
  7495.                                                 game_damagenpc(e, damage, 1);
  7496.                                                 if(menabled == 1 && opeffects == 1) {
  7497.                                                     //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndrocks))
  7498.                                                     //FSOUND_setVolume(snd, opeffectsvol)
  7499.                                                 }
  7500.                                             }
  7501.                                         }
  7502.                                     }
  7503.                                 }
  7504.  
  7505.  
  7506.                                 // check for(int post damage
  7507.                                 if(nposts > 0) {
  7508.                                     for(int e = 0; e <= nposts - 1; e++) {
  7509.                                         xdif = (xloc + 16) - (postinfo[e][0] + 8);
  7510.                                         ydif = (yloc + 16) - (postinfo[e][1] + 8);
  7511.  
  7512.                                         if((abs(xdif) < 16 && abs(ydif) < 16)) {
  7513.                                             objmapf[curmap][(int)postinfo[e][0] / 16][(int)postinfo[e][1] / 16] = 1;
  7514.                                             objmap[(int)postinfo[e][0] / 16][(int)postinfo[e][1] / 16] = -1;
  7515.  
  7516.                                             rcSrc.x = postinfo[e][0] / 2;
  7517.                                             rcSrc.y = postinfo[e][1] / 2;
  7518.                                             rcSrc.w = 8;
  7519.                                             rcSrc.h = 8;
  7520.  
  7521.                                             SDL_FillRect(clipbg2, &rcSrc, 0);
  7522.  
  7523.                                             game_addFloatIcon(99, postinfo[e][0], postinfo[e][1]);
  7524.  
  7525.                                             if(menabled == 1 && opeffects == 1) {
  7526.                                                 //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndrocks))
  7527.                                                 //FSOUND_setVolume(snd, opeffectsvol)
  7528.                                             }
  7529.                                         }
  7530.                                     }
  7531.                                 }
  7532.                             }
  7533.                         }
  7534.                     }
  7535.                 }
  7536.  
  7537.                 spellinfo[i].frame = spellinfo[i].frame - 0.2 * fpsr;
  7538.                 if(spellinfo[i].frame < 0) spellinfo[i].frame = 0;
  7539.             }
  7540.  
  7541.             // crystal
  7542.             if(spellnum == 5) {
  7543.  
  7544.                 float fra = (32 - spellinfo[i].frame);
  7545.                 int fr = (int)((spellinfo[i].frame) * 2) % 8;
  7546.  
  7547.                 rcSrc.x = fr * 32;
  7548.                 rcSrc.y = 96 + 48;
  7549.                 rcSrc.w = 32;
  7550.                 rcSrc.h = 64;
  7551.  
  7552.                 rcDest.x = player.px - 4;
  7553.                 rcDest.y = player.py + 16 - 48;
  7554.  
  7555.                 int f = 160;
  7556.                 if(fra < 8) f = 192 * fra / 8;
  7557.                 if(fra > 24) f = 192 * (1 - (fra - 24) / 8);
  7558.  
  7559.                 SDL_SetAlpha(spellimg, SDL_SRCALPHA, f);
  7560.                 SDL_BlitSurface(spellimg, &rcSrc, videobuffer, &rcDest);
  7561.                 SDL_SetAlpha(spellimg, SDL_SRCALPHA, 255);
  7562.  
  7563.                 spellinfo[i].frame = spellinfo[i].frame - 0.3 * fpsr;
  7564.                 if(spellinfo[i].frame < 0) {
  7565.                     spellinfo[i].frame = 0;
  7566.                     forcepause = 0;
  7567.  
  7568.                     npx = player.px + 12;
  7569.                     npy = player.py + 20;
  7570.  
  7571.                     int lx = (int)npx / 16; //(npx - (npx MOD 16)) / 16
  7572.                     int ly = (int)npy / 16; //(npy - (npy MOD 16)) / 16
  7573.  
  7574.                     for(int f = 0; f <= 4; f++) {
  7575.                         foundel[f] = 0;
  7576.                     }
  7577.  
  7578.                     for(int xo = -2; xo <= 2; xo++) {
  7579.                         for(int yo = -2; yo <= 2; yo++) {
  7580.  
  7581.                             int sx = lx + xo;
  7582.                             int sy = ly + yo;
  7583.  
  7584.                             if(sx > -1 && sx < 20 && sy > -1 && sy < 15) {
  7585.                                 for(int l = 0; l <= 2; l++) {
  7586.                                     int curtile = tileinfo[l][sx][sy][0];
  7587.                                     int curtilel = tileinfo[l][sx][sy][1];
  7588.  
  7589.                                     if(curtile > 0) {
  7590.                                         curtile = curtile - 1;
  7591.                                         int curtilex = curtile % 20;
  7592.                                         int curtiley = (curtile - curtilex) / 20;
  7593.  
  7594.                                         int element = elementmap[curtiley][curtilex];
  7595.                                         if(element > -1 && curtilel == 0) foundel[element] = 1;
  7596.                                     }
  7597.                                 }
  7598.  
  7599.                                 int o = objmap[sx][sy];
  7600.                                 if(o > -1) {
  7601.                                     if(objectinfo[o][4] == 1) foundel[1] = 1;
  7602.                                     if(o == 1 || o == 2) {
  7603.                                         foundel[1] = 1;
  7604.                                         foundel[3] = 1;
  7605.                                     }
  7606.                                 }
  7607.                             }
  7608.                         }
  7609.                     }
  7610.  
  7611.                     char line[256];
  7612.                     strcpy(line, "Found... nothing...");
  7613.                     f = 0;
  7614.                     do {
  7615.                         if(foundel[f] == 1 && player.foundspell[f] == 0) {
  7616.                             player.foundspell[f] = 1;
  7617.                             player.spellcharge[f] = 0;
  7618.                             if(f == 0) strcpy(line, "Found... Water Essence");
  7619.                             if(f == 1) strcpy(line, "Found... Metal Essence");
  7620.                             if(f == 2) strcpy(line, "Found... Earth Essence");
  7621.                             if(f == 3) strcpy(line, "Found... Fire Essence");
  7622.                             break;
  7623.                         }
  7624.  
  7625.                         f=f+1;
  7626.                         if(f == 5) break;
  7627.                     } while(1);
  7628.  
  7629.                     game_eventtext(line);
  7630.                 }
  7631.             }
  7632.  
  7633.             // room fireballs
  7634.             if(spellnum == 6 && forcepause == 0) {
  7635.  
  7636.                 if(spellinfo[i].frame > 16) {
  7637.                     float fr = (32 - spellinfo[i].frame);
  7638.  
  7639.                     SDL_SetAlpha(spellimg, SDL_SRCALPHA, 192 * sin(3.14159 * fr / 4));
  7640.  
  7641.                     rcSrc.x = 16 * (int)(RND() * 2);
  7642.                     rcSrc.y = 80;
  7643.                     rcSrc.w = 16;
  7644.                     rcSrc.h = 16;
  7645.  
  7646.                     for(int ff = 0; ff <= spellinfo[i].nfballs - 1; ff++) {
  7647.  
  7648.                         xloc = spellinfo[i].fireballs[ff][0] + (int)(RND() * 3) - 1;
  7649.                         yloc = spellinfo[i].fireballs[ff][1] + (int)(RND() * 3) - 1;
  7650.  
  7651.                         rcDest.x = xloc;
  7652.                         rcDest.y = yloc;
  7653.  
  7654.                         SDL_BlitSurface(spellimg, &rcSrc, videobuffer, &rcDest);
  7655.                     }
  7656.  
  7657.                     SDL_SetAlpha(spellimg, SDL_SRCALPHA, 255);
  7658.                 } else {
  7659.                     SDL_SetAlpha(spellimg, SDL_SRCALPHA, 192);
  7660.  
  7661.                     rcSrc.x = 16 * (int)(RND() * 2);
  7662.                     rcSrc.y = 80;
  7663.                     rcSrc.w = 16;
  7664.                     rcSrc.h = 16;
  7665.  
  7666.                     for(int ff = 0; ff <= spellinfo[i].nfballs - 1; ff++) {
  7667.                         float ax = spellinfo[i].fireballs[ff][0];
  7668.                         float ay = spellinfo[i].fireballs[ff][1];
  7669.                         float bx = player.px + 4;
  7670.                         float by = player.py + 4;
  7671.                         float d = sqrt((bx - ax) * (bx - ax) + (by - ay) * (by - ay));
  7672.  
  7673.                         float tx = (bx - ax) / d;
  7674.                         float ty = (by - ay) / d;
  7675.  
  7676.                         spellinfo[i].fireballs[ff][2] += tx * 1.2 * fpsr;
  7677.                         spellinfo[i].fireballs[ff][3] += ty * 1.2 * fpsr;
  7678.  
  7679.                         if(spellinfo[i].ballon[ff] == 1) {
  7680.                             spellinfo[i].fireballs[ff][0] = ax + spellinfo[i].fireballs[ff][2] * 0.2 * fpsr;
  7681.                             spellinfo[i].fireballs[ff][1] = ay + spellinfo[i].fireballs[ff][3] * 0.2 * fpsr;
  7682.  
  7683.                             xloc = spellinfo[i].fireballs[ff][0] + (int)(RND() * 3) - 1;
  7684.                             yloc = spellinfo[i].fireballs[ff][1] + (int)(RND() * 3) - 1;
  7685.  
  7686.                             rcDest.x = xloc;
  7687.                             rcDest.y = yloc;
  7688.  
  7689.                             SDL_BlitSurface(spellimg, &rcSrc, videobuffer, &rcDest);
  7690.                         }
  7691.  
  7692.                         if(xloc < -1 || yloc < -1 || xloc > 304 || yloc > 224) spellinfo[i].ballon[ff] = 0;
  7693.                     }
  7694.  
  7695.                     SDL_SetAlpha(spellimg, SDL_SRCALPHA, 255);
  7696.                 }
  7697.  
  7698.                 spellinfo[i].frame = spellinfo[i].frame - 0.2 * fpsr;
  7699.                 if(spellinfo[i].frame < 0) spellinfo[i].frame = 0;
  7700.  
  7701.                 if(spellinfo[i].damagewho == 1) {
  7702.                     for(int ff = 0; ff <= spellinfo[i].nfballs - 1; ff++) {
  7703.                         if(spellinfo[i].ballon[ff] == 1) {
  7704.                             xloc = spellinfo[i].fireballs[ff][0] + (int)(RND() * 3) - 1;
  7705.                             yloc = spellinfo[i].fireballs[ff][1] + (int)(RND() * 3) - 1;
  7706.  
  7707.                             xdif = (xloc + 8) - (player.px + 12);
  7708.                             ydif = (yloc + 8) - (player.py + 12);
  7709.  
  7710.                             if((abs(xdif) < 8 && abs(ydif) < 8) && player.pause < ticks) {
  7711.                                 float damage = npcinfo[spellinfo[i].npc].spelldamage * (1 + RND() * 0.5) / 3;
  7712.  
  7713.                                 if(player.hp > 0) game_damageplayer(damage);
  7714.  
  7715.                                 if(menabled == 1 && opeffects == 1) {
  7716.                                      //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndfire))
  7717.                                      //FSOUND_setVolume(snd, opeffectsvol)
  7718.                                 }
  7719.                             }
  7720.                         }
  7721.                     }
  7722.                 }
  7723.             }
  7724.  
  7725.             // lightning bomb
  7726.             if(spellnum == 8) {
  7727.  
  7728.                 cl1 = SDL_MapRGB(videobuffer->format, 0, 32, 204);
  7729.                 cl2 = SDL_MapRGB(videobuffer->format, 142, 173, 191);
  7730.                 cl3 = SDL_MapRGB(videobuffer->format, 240, 240, 240);
  7731.  
  7732.                 float px = player.px + 12;
  7733.                 float py = player.py + 12;
  7734.  
  7735.                 int apx = px + (int)(RND() * 5 - 2);
  7736.                 int apy = py + (int)(RND() * 5 - 2);
  7737.  
  7738.                 for(int f = 0; f <= 0; f++) { // ??
  7739.                     int y = apy;
  7740.                     int orn = 0;
  7741.                     for(int x = apx; x <= 319; x++) {
  7742.                         int rn = (int)(RND() * 3);
  7743.  
  7744.                         if(orn == 0) y = y - 1;
  7745.                         if(orn == 2) y = y + 1;
  7746.  
  7747.                         sys_line(videobuffer,x, y - 1, x, y + 2, cl1);
  7748.                         sys_line(videobuffer,x, y, x, y + 1, cl3);
  7749.  
  7750.                         if(rn == 0) sys_line(videobuffer, x, y + 1, x, y + 1, cl2);
  7751.                         if(rn == 2) sys_line(videobuffer, x, y, x, y, cl2);
  7752.  
  7753.                         orn = rn;
  7754.  
  7755.                         if(spellinfo[i].damagewho == 0) {
  7756.                             for(int e = 1; e <= lastnpc; e++) {
  7757.  
  7758.                                 xdif = (x + 16) - (npcinfo[e].x + 12);
  7759.                                 ydif = (y + 16) - (npcinfo[e].y + 12);
  7760.  
  7761.                                 if((abs(xdif) < 8 && abs(ydif) < 8)) {
  7762.                                     float damage = 30 * (1 + RND() * 0.5);
  7763.  
  7764.                                     if(npcinfo[e].hp > 0 && npcinfo[e].pause < ticks) game_damagenpc(e, damage, 1);
  7765.                                 }
  7766.                             }
  7767.                         }
  7768.    
  7769.                         // check for post damage
  7770.                         if(nposts > 0) {
  7771.                             for(int e = 0; e <= nposts - 1; e++) {
  7772.                                 xdif = (xloc + 16) - (postinfo[e][0] + 8);
  7773.                                 ydif = (yloc + 16) - (postinfo[e][1] + 8);
  7774.  
  7775.                                 if((abs(xdif) < 16 && abs(ydif) < 16)) {
  7776.                                     objmapf[curmap][(int)postinfo[e][0] / 16][(int)postinfo[e][1] / 16] = 1;
  7777.                                     objmap[(int)postinfo[e][0] / 16][(int)postinfo[e][1] / 16] = -1;
  7778.  
  7779.                                     rcSrc.x = postinfo[e][0] / 2;
  7780.                                     rcSrc.y = postinfo[e][1] / 2;
  7781.                                     rcSrc.w = 8;
  7782.                                     rcSrc.h = 8;
  7783.  
  7784.                                     SDL_FillRect(clipbg2, &rcSrc, 0);
  7785.  
  7786.                                     game_addFloatIcon(99, postinfo[e][0], postinfo[e][1]);
  7787.                                 }
  7788.                             }
  7789.                         }
  7790.                     }
  7791.  
  7792.                     y = apy;
  7793.                     orn = 0;
  7794.                     for(int x = apx; x >= 0; x--) {
  7795.                         int rn = (int)(RND() * 3);
  7796.  
  7797.                         if(orn == 0) y = y - 1;
  7798.                         if(orn == 2) y = y + 1;
  7799.  
  7800.                         sys_line(videobuffer,x, y - 1, x, y + 2, cl1);
  7801.                         sys_line(videobuffer,x, y, x, y + 1, cl3);
  7802.  
  7803.                         if(rn == 0) sys_line(videobuffer, x, y + 1, x, y + 1, cl2);
  7804.                         if(rn == 2) sys_line(videobuffer, x, y, x, y, cl2);
  7805.  
  7806.                         orn = rn;
  7807.  
  7808.                         if(spellinfo[i].damagewho == 0) {
  7809.                             for(int e = 1; e <= lastnpc; e++) {
  7810.  
  7811.                                 xdif = (x + 16) - (npcinfo[e].x + 12);
  7812.                                 ydif = (y + 16) - (npcinfo[e].y + 12);
  7813.  
  7814.                                 if((abs(xdif) < 8 && abs(ydif) < 8)) {
  7815.                                     float damage = 30 * (1 + RND() * 0.5);
  7816.  
  7817.                                     if(npcinfo[e].hp > 0 && npcinfo[e].pause < ticks) game_damagenpc(e, damage, 1);
  7818.                                 }
  7819.                             }
  7820.                         }
  7821.  
  7822.                         // check for post damage
  7823.                         if(nposts > 0) {
  7824.                             for(int e = 0; e <= nposts - 1; e++) {
  7825.                                 xdif = (xloc + 16) - (postinfo[e][0] + 8);
  7826.                                 ydif = (yloc + 16) - (postinfo[e][1] + 8);
  7827.  
  7828.                                 if((abs(xdif) < 16 && abs(ydif) < 16)) {
  7829.                                     objmapf[curmap][(int)postinfo[e][0] / 16][(int)postinfo[e][1] / 16] = 1;
  7830.                                     objmap[(int)postinfo[e][0] / 16][(int)postinfo[e][1] / 16] = -1;
  7831.  
  7832.                                     rcSrc.x = postinfo[e][0] / 2;
  7833.                                     rcSrc.y = postinfo[e][1] / 2;
  7834.                                     rcSrc.w = 8;
  7835.                                     rcSrc.h = 8;
  7836.  
  7837.                                     SDL_FillRect(clipbg2, &rcSrc, 0);
  7838.  
  7839.                                     game_addFloatIcon(99, postinfo[e][0], postinfo[e][1]);
  7840.                                 }
  7841.                             }
  7842.                         }
  7843.                     }
  7844.  
  7845.                     int x = apx;
  7846.                     orn = 0;
  7847.                     for(int y = apy; y <= 239; y++) {
  7848.                         int rn = (int)(RND() * 3);
  7849.  
  7850.                         if(orn == 0) x = x - 1;
  7851.                         if(orn == 2) x = x + 1;
  7852.  
  7853.                         sys_line(videobuffer,x - 1, y, x + 2, y, cl1);
  7854.                         sys_line(videobuffer,x, y, x + 1, y, cl3);
  7855.  
  7856.                         if(rn == 0) sys_line(videobuffer, x + 1, y, x + 1, y, cl2);
  7857.                         if(rn == 2) sys_line(videobuffer, x, y, x, y, cl2);
  7858.  
  7859.                         orn = rn;
  7860.  
  7861.                         if(spellinfo[i].damagewho == 0) {
  7862.                             for(int e = 1; e <= lastnpc; e++) {
  7863.                                 xdif = (x + 16) - (npcinfo[e].x + 12);
  7864.                                 ydif = (y + 16) - (npcinfo[e].y + 12);
  7865.  
  7866.                                 if((abs(xdif) < 8 && abs(ydif) < 8)) {
  7867.                                     float damage = 30 * (1 + RND() * 0.5);
  7868.  
  7869.                                     if(npcinfo[e].hp > 0 && npcinfo[e].pause < ticks) game_damagenpc(e, damage, 1);
  7870.                                 }
  7871.                             }
  7872.                         }
  7873.  
  7874.                         // check for post damage
  7875.                         if(nposts > 0) {
  7876.                             for(int e = 0; e <= nposts - 1; e++) {
  7877.                                 xdif = (xloc + 16) - (postinfo[e][0] + 8);
  7878.                                 ydif = (yloc + 16) - (postinfo[e][1] + 8);
  7879.  
  7880.                                 if((abs(xdif) < 16 && abs(ydif) < 16)) {
  7881.                                     objmapf[curmap][(int)postinfo[e][0] / 16][(int)postinfo[e][1] / 16] = 1;
  7882.                                     objmap[(int)postinfo[e][0] / 16][(int)postinfo[e][1] / 16] = -1;
  7883.  
  7884.                                     rcSrc.x = postinfo[e][0] / 2;
  7885.                                     rcSrc.y = postinfo[e][1] / 2;
  7886.                                     rcSrc.w = 8;
  7887.                                     rcSrc.h = 8;
  7888.  
  7889.                                     SDL_FillRect(clipbg2, &rcSrc, 0);
  7890.  
  7891.                                     game_addFloatIcon(99, postinfo[e][0], postinfo[e][1]);
  7892.                                 }
  7893.                             }
  7894.                         }
  7895.                     }
  7896.  
  7897.                     x = apx;
  7898.                     orn = 0;
  7899.                     for(int y = apy; y >= 0; y--) {
  7900.                         int rn = (int)(RND() * 3);
  7901.  
  7902.                         if(orn == 0) x = x - 1;
  7903.                         if(orn == 2) x = x + 1;
  7904.  
  7905.                         sys_line(videobuffer,x - 1, y, x + 2, y, cl1);
  7906.                         sys_line(videobuffer,x, y, x + 1, y, cl3);
  7907.  
  7908.                         if(rn == 0) sys_line(videobuffer, x + 1, y, x + 1, y, cl2);
  7909.                         if(rn == 2) sys_line(videobuffer, x, y, x, y, cl2);
  7910.  
  7911.                         orn = rn;
  7912.  
  7913.                         if(spellinfo[i].damagewho == 0) {
  7914.                             for(int e = 1; e <= lastnpc; e++) {
  7915.                                 xdif = (x + 16) - (npcinfo[e].x + 12);
  7916.                                 ydif = (y + 16) - (npcinfo[e].y + 12);
  7917.  
  7918.                                 if((abs(xdif) < 8 && abs(ydif) < 8)) {
  7919.                                     float damage = 30 * (1 + RND() * 0.5);
  7920.  
  7921.                                     if(npcinfo[e].hp > 0 && npcinfo[e].pause < ticks) game_damagenpc(e, damage, 1);
  7922.                                 }
  7923.                             }
  7924.                         }
  7925.  
  7926.                         // check for post damage
  7927.                         if(nposts > 0) {
  7928.                             for(int e = 0; e <= nposts - 1; e++) {
  7929.                                 xdif = (xloc + 16) - (postinfo[e][0] + 8);
  7930.                                 ydif = (yloc + 16) - (postinfo[e][1] + 8);
  7931.  
  7932.                                 if((abs(xdif) < 16 && abs(ydif) < 16)) {
  7933.                                     objmapf[curmap][(int)postinfo[e][0] / 16][(int)postinfo[e][1] / 16] = 1;
  7934.                                     objmap[(int)postinfo[e][0] / 16][(int)postinfo[e][1] / 16] = -1;
  7935.  
  7936.                                     rcSrc.x = postinfo[e][0] / 2;
  7937.                                     rcSrc.y = postinfo[e][1] / 2;
  7938.                                     rcSrc.w = 8;
  7939.                                     rcSrc.h = 8;
  7940.  
  7941.                                     SDL_FillRect(clipbg2, &rcSrc, 0);
  7942.  
  7943.                                     game_addFloatIcon(99, postinfo[e][0], postinfo[e][1]);
  7944.                                 }
  7945.                             }
  7946.                         }
  7947.                     }
  7948.                 }
  7949.  
  7950.                 spellinfo[i].frame -= 0.5 * fpsr;
  7951.                 if(spellinfo[i].frame < 0) {
  7952.                     spellinfo[i].frame = 0;
  7953.                     forcepause = 0;
  7954.                 }
  7955.             }
  7956.  
  7957.             // wizard 1 lightning
  7958.             if(spellnum == 9) {
  7959.  
  7960.                 cl1 = SDL_MapRGB(videobuffer->format, 0, 32, 204);
  7961.                 cl2 = SDL_MapRGB(videobuffer->format, 142, 173, 191);
  7962.                 cl3 = SDL_MapRGB(videobuffer->format, 240, 240, 240);
  7963.  
  7964.                 int px = spellinfo[i].enemyx + 12;
  7965.                 int py = spellinfo[i].enemyy + 24;
  7966.  
  7967.                 int apx = px + (int)(RND() * 20 - 10);
  7968.                 int apy = py + (int)(RND() * 20 - 10);
  7969.  
  7970.                 int x = apx;
  7971.                 int orn = 0;
  7972.                 for(int y = 0; y <= apy; y++) {
  7973.                     if(y < 240) {
  7974.                         float xdif, ydif;
  7975.                         int rn = (int)(RND() * 3);
  7976.  
  7977.                         if(orn == 0) x = x - 1;
  7978.                         if(orn == 2) x = x + 1;
  7979.  
  7980.                         sys_line(videobuffer,x - 1, y, x + 2, y, cl1);
  7981.                         sys_line(videobuffer,x, y, x + 1, y, cl3);
  7982.  
  7983.                         if(rn == 0) sys_line(videobuffer, x + 1, y, x + 1, y, cl2);
  7984.                         if(rn == 2) sys_line(videobuffer, x, y, x, y, cl2);
  7985.  
  7986.                         orn = rn;
  7987.  
  7988.                         if(spellinfo[i].damagewho == 1) {
  7989.  
  7990.                             xdif = (x + 8) - (player.px + 12);
  7991.                             ydif = (y + 8) - (player.py + 12);
  7992.  
  7993.                             if((abs(xdif) < 8 && abs(ydif) < 8) && player.pause < ticks) {
  7994.                                 float damage = ((float)player.hp * 0.75) * (RND() * 0.5 + 0.5);
  7995.                                 if(damage < 5) damage = 5;
  7996.  
  7997.                                 if(npcinfo[spellinfo[i].npc].spriteset == 12) {
  7998.                                     if(damage < 50) damage = 40 + (int)(RND() * 40);
  7999.                                 }
  8000.  
  8001.                                 if(player.hp > 0) game_damageplayer(damage);
  8002.                             }
  8003.                         }
  8004.                     }
  8005.                 }
  8006.  
  8007.                 spellinfo[i].frame -= 0.5 * fpsr;
  8008.                 if(spellinfo[i].frame < 0) {
  8009.                     spellinfo[i].frame = 0;
  8010.  
  8011.                     npcinfo[spellinfo[i].npc].attacking = 0;
  8012.                     npcinfo[spellinfo[i].npc].attacknext = ticks + npcinfo[spellinfo[i].npc].attackdelay;
  8013.                 }
  8014.             }
  8015.         }
  8016.     }
  8017. }
  8018.  
  8019.  
  8020.  
  8021. void game_updspellsunder()
  8022. {
  8023.  
  8024.     unsigned int dq, *temp;
  8025.     /*float npx, npy, onpx, onpy;*/
  8026.  
  8027.     if(forcepause == 1) return;
  8028.  
  8029.     for(int i = 0; i <= MAXSPELL; i++) {
  8030.         if(spellinfo[i].frame > 0) {
  8031.             int spellnum = spellinfo[i].spellnum;
  8032.  
  8033.             // water
  8034.             if(spellnum == 0) {
  8035.                 int fra = (32 - spellinfo[i].frame);
  8036.                 int fr = (int)((32 - spellinfo[i].frame) * 2) % 4;
  8037.  
  8038.                 rcSrc.x = fr * 48;
  8039.                 rcSrc.y = 96;
  8040.                 rcSrc.w = 48;
  8041.                 rcSrc.h = 48;
  8042.  
  8043.                 rcDest.x = spellinfo[i].enemyx - 12;
  8044.                 rcDest.y = spellinfo[i].enemyy - 8;
  8045.  
  8046.                 int f = 160;
  8047.                 if(fra < 8) f = 160 * fra / 8;
  8048.                 if(fra > 24) f = 160 * (1 - (fra - 24) / 8);
  8049.  
  8050.                 SDL_SetAlpha(spellimg, SDL_SRCALPHA, f);
  8051.                 SDL_BlitSurface(spellimg, &rcSrc, videobuffer, &rcDest);
  8052.                 SDL_SetAlpha(spellimg, SDL_SRCALPHA, 255);
  8053.  
  8054.                 spellinfo[i].frame = spellinfo[i].frame - 0.2 * fpsr;
  8055.                 if(spellinfo[i].frame < 0) spellinfo[i].frame = 0;
  8056.  
  8057.  
  8058.                 for(int f = 1; f <= lastnpc; f++) {
  8059.                     int xdif = spellinfo[i].enemyx - npcinfo[f].x;
  8060.                     int ydif = spellinfo[i].enemyy - npcinfo[f].y;
  8061.  
  8062.                     float dist = sqrt(xdif * xdif + ydif * ydif);
  8063.  
  8064.                     if(dist > 20) dist = 20;
  8065.  
  8066.                     if(dist > 5) {
  8067.                         int xm = 1;
  8068.                         if(xdif < 0) xm = -1;
  8069.                         int ym = 1;
  8070.                         if(ydif < 0) ym = -1;
  8071.  
  8072.                         float ratio = (1 - dist / 25);
  8073.  
  8074.                         float newx = npcinfo[f].x + ratio * xdif / 3 * fpsr;
  8075.                         float newy = npcinfo[f].y + ratio * ydif / 3 * fpsr;
  8076.  
  8077.                         int sx = (newx / 2 + 6);
  8078.                         int sy = (newy / 2 + 10);
  8079.                         temp = clipbg->pixels + sy * clipbg->pitch + sx * clipbg->format->BytesPerPixel;
  8080.                         dq = *temp;
  8081.  
  8082.                         // SDL_UnLockSurface clipbg
  8083.  
  8084.                         if(dq == 0) {
  8085.                             npcinfo[f].x = newx;
  8086.                             npcinfo[f].y = newy;
  8087.                             // npcinfo[f].castpause = ticks + 200;
  8088.                         } else {
  8089.                             int xpass = 0;
  8090.                             int ypass = 0;
  8091.  
  8092.                             sx = (newx / 2 + 6);
  8093.                             sy = (npcinfo[f].y / 2 + 10);
  8094.                             temp = clipbg->pixels + sy * clipbg->pitch + sx * clipbg->format->BytesPerPixel;
  8095.                             dq = *temp;
  8096.  
  8097.                             if(dq == 0) xpass = 1;
  8098.  
  8099.  
  8100.                             sx = (npcinfo[f].x / 2 + 6);
  8101.                             sy = (newy / 2 + 10);
  8102.                             temp = clipbg->pixels + sy * clipbg->pitch + sx * clipbg->format->BytesPerPixel;
  8103.                             dq = *temp;
  8104.  
  8105.                             if(dq == 0) ypass = 1;
  8106.  
  8107.                             if(ypass == 1) {
  8108.                                 newx = npcinfo[f].x;
  8109.                             } else if(xpass == 1) {
  8110.                                 newy = npcinfo[f].y;
  8111.                             }
  8112.  
  8113.                             if(xpass == 1 || ypass == 1) {
  8114.                                 npcinfo[f].x = newx;
  8115.                                 npcinfo[f].y = newy;
  8116.                                 // npcinfo[f].castpause = ticks + 200;
  8117.                             }
  8118.                         }
  8119.                     }
  8120.                 }
  8121.             }
  8122.  
  8123.             // fire
  8124.             if(spellnum == 3) {
  8125.                 float fr = (32 - spellinfo[i].frame);
  8126.  
  8127.                 fr = fr*fr * (1 - cos(3.14159 / 4 + 3.14159 / 4 * fr / 32));
  8128.  
  8129.                 if(fr > 32) fr = 32;
  8130.  
  8131.                 float s = 8;
  8132.                 if(spellinfo[i].frame < 8) s = spellinfo[i].frame;
  8133.  
  8134.                 int fra = (int)fr;
  8135.  
  8136.                 for(int f = 0; f <= 4; f++) {
  8137.                     for(int x = 0; x <= fra; x += 2) {
  8138.                         if(spellinfo[i].legalive[f] >= x) {
  8139.                             SDL_SetAlpha(spellimg, SDL_SRCALPHA, 192 * sin(3.14159 * x / 32) * s / 8);
  8140.  
  8141.                             float an = 360 / 5 * f + x / 32 * 180;
  8142.  
  8143.                             rcSrc.x = 16 * (int)(RND() * 2);
  8144.                             rcSrc.y = 80;
  8145.                             rcSrc.w = 16;
  8146.                             rcSrc.h = 16;
  8147.  
  8148.                             float xloc = (float)(spellinfo[i].enemyx + 4 + x * 2 * cos(3.14159 / 180 * an) + (int)(RND() * 3) - 1);
  8149.                             float yloc = (float)(spellinfo[i].enemyy + 4 + x * 2 * sin(3.14159 / 180 * an) + (int)(RND() * 3) - 1);
  8150.                             rcDest.x = (int)xloc;
  8151.                             rcDest.y = (int)yloc;
  8152.  
  8153.                             if(xloc > -1 && xloc < 304 && yloc > -1 && yloc < 224) {
  8154.                                 SDL_BlitSurface(spellimg, &rcSrc, videobuffer, &rcDest);
  8155.  
  8156.                                 int sx = (xloc / 2 + 4);
  8157.                                 int sy = (yloc / 2 + 8);
  8158.                                 temp = clipbg->pixels + sy * clipbg->pitch + sx * clipbg->format->BytesPerPixel;
  8159.                                 dq = *temp;
  8160.  
  8161.                                 if(dq > 1000 && x > 4) spellinfo[i].legalive[f] = x;
  8162.  
  8163.                                 if(spellinfo[i].damagewho == 0) {
  8164.                                     for(int e = 1; e <= lastnpc; e++) {
  8165.                                         float xdif = (xloc + 8) - (npcinfo[e].x + 12);
  8166.                                         float ydif = (yloc + 8) - (npcinfo[e].y + 12);
  8167.  
  8168.                                         if((abs(xdif) < 8 && abs(ydif) < 8)) {
  8169.                                             float damage = (float)player.spelldamage * (1.0 + RND() * 0.5) * (float)spellinfo[i].strength;
  8170.  
  8171.                                             if(npcinfo[e].spriteset == 5) damage = -damage;
  8172.                                             if(npcinfo[e].spriteset == 11) damage = -damage;
  8173.                                             if(npcinfo[e].hp > 0 && npcinfo[e].pause < ticks) {
  8174.                                                 game_damagenpc(e, damage, 1);
  8175.                                                 if(menabled == 1 && opeffects == 1) {
  8176.                                                     //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndfire))
  8177.                                                     //FSOUND_setVolume(snd, opeffectsvol)
  8178.                                                 }
  8179.                                             }
  8180.                                         }
  8181.                                     }
  8182.                                 }
  8183.  
  8184.                                 if(spellinfo[i].damagewho == 1) {
  8185.                                     float xdif = (xloc + 8) - (player.px + 12);
  8186.                                     float ydif = (yloc + 8) - (player.py + 12);
  8187.  
  8188.                                     if((abs(xdif) < 8 && abs(ydif) < 8) && player.pause < ticks) {
  8189.                                         float damage = (float)npcinfo[spellinfo[i].npc].spelldamage * (1.0 + RND() * 0.5);
  8190.  
  8191.                                         if(player.hp > 0) {
  8192.                                             game_damageplayer(damage);
  8193.  
  8194.                                             if(menabled == 1 && opeffects == 1) {
  8195.                                                 //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndfire))
  8196.                                                 //FSOUND_setVolume(snd, opeffectsvol)
  8197.                                             }
  8198.                                         }
  8199.                                     }
  8200.                                 }
  8201.  
  8202.                                 // check for post damage
  8203.                                 if(nposts > 0) {
  8204.                                     for(int e = 0; e <= nposts - 1; e++) {
  8205.                                         float xdif = (xloc + 8) - (postinfo[e][0] + 8);
  8206.                                         float ydif = (yloc + 8) - (postinfo[e][1] + 8);
  8207.  
  8208.                                         if((abs(xdif) < 8 && abs(ydif) < 8)) {
  8209.                                             objmapf[curmap][(int)postinfo[e][0] / 16][(int)postinfo[e][1] / 16] = 1;
  8210.                                             objmap[(int)postinfo[e][0] / 16][(int)postinfo[e][1] / 16] = -1;
  8211.  
  8212.                                             rcSrc.x = postinfo[e][0] / 2;
  8213.                                             rcSrc.y = postinfo[e][1] / 2;
  8214.                                             rcSrc.w = 8;
  8215.                                             rcSrc.h = 8;
  8216.  
  8217.                                             SDL_FillRect(clipbg2, &rcSrc, 0);
  8218.  
  8219.                                             if(menabled == 1 && opeffects == 1) {
  8220.                                                 //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndfire))
  8221.                                                 //FSOUND_setVolume(snd, opeffectsvol)
  8222.                                             }
  8223.  
  8224.                                             game_addFloatIcon(99, postinfo[e][0], postinfo[e][1]);
  8225.                                         }
  8226.                                     }
  8227.                                 }
  8228.                             }
  8229.                         }
  8230.                     }
  8231.                 }
  8232.  
  8233.                 SDL_SetAlpha(spellimg, SDL_SRCALPHA, 255);
  8234.  
  8235.                 spellinfo[i].frame = spellinfo[i].frame - 0.2 * fpsr;
  8236.                 if(spellinfo[i].frame < 0) spellinfo[i].frame = 0;
  8237.  
  8238.  
  8239.             }
  8240.  
  8241.  
  8242.             // sprite 6 spitfire
  8243.             if(spellnum == 7) {
  8244.                 float xspan = spellinfo[i].enemyx - spellinfo[i].homex;
  8245.                 float yspan = spellinfo[i].enemyy - spellinfo[i].homey;
  8246.                 float fr = (32 - spellinfo[i].frame);
  8247.  
  8248.                 for(int f = 0; f <= 7; f++) {
  8249.                     int alpha = 0;
  8250.                     float xx = 0;
  8251.                     if(fr > f * 2 && fr < f * 2 + 16) xx = fr - f * 2;
  8252.                     if(xx < 8) alpha = 255 * xx / 8;
  8253.                     if(xx > 8) alpha = 255 * (1 - (xx - 8) / 8);
  8254.                     float yy = 16 * sin(3.141592 / 2 * xx / 16) - 8;
  8255.  
  8256.                     if(alpha < 0) alpha = 0;
  8257.                     if(alpha > 255) alpha = 255;
  8258.  
  8259.                     SDL_SetAlpha(spellimg, SDL_SRCALPHA, alpha);
  8260.  
  8261.                     rcSrc.x = 16 * (int)(RND() * 2);
  8262.                     rcSrc.y = 80;
  8263.                     rcSrc.w = 16;
  8264.                     rcSrc.h = 16;
  8265.  
  8266.                     float xloc = spellinfo[i].homex + xspan / 7 * f;
  8267.                     float yloc = spellinfo[i].homey + yspan / 7 * f - yy;
  8268.  
  8269.                     rcDest.x = xloc;
  8270.                     rcDest.y = yloc;
  8271.  
  8272.                     if(xloc > -16 && xloc < 320 && yloc > -16 && yloc < 240) {
  8273.                         SDL_BlitSurface(spellimg, &rcSrc, videobuffer, &rcDest);
  8274.  
  8275.                         if(spellinfo[i].damagewho == 1) {
  8276.                             float xdif = (xloc + 8) - (player.px + 12);
  8277.                             float ydif = (yloc + 8) - (player.py + 12);
  8278.  
  8279.                             if((abs(xdif) < 8 && abs(ydif) < 8) && player.pause < ticks && alpha > 64) {
  8280.                                 float damage = (float)npcinfo[spellinfo[i].npc].spelldamage * (1.0 + RND() * 0.5);
  8281.  
  8282.                                 if(player.hp > 0) {
  8283.                                     game_damageplayer(damage);
  8284.                                     if(menabled == 1 && opeffects == 1) {
  8285.                                         //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndfire))
  8286.                                         //FSOUND_setVolume(snd, opeffectsvol)
  8287.                                     }
  8288.                                 }
  8289.  
  8290.                             }
  8291.                         }
  8292.  
  8293.                     }
  8294.  
  8295.                 }
  8296.  
  8297.                 SDL_SetAlpha(spellimg, SDL_SRCALPHA, 255);
  8298.                 spellinfo[i].frame = spellinfo[i].frame - 0.5 * fpsr;
  8299.                 if(spellinfo[i].frame < 0) spellinfo[i].frame = 0;
  8300.  
  8301.                 if(spellinfo[i].frame == 0) {
  8302.                     npcinfo[spellinfo[i].npc].attacking = 0;
  8303.                     npcinfo[spellinfo[i].npc].attacknext = ticks + npcinfo[spellinfo[i].npc].attackdelay;
  8304.                 }
  8305.             }
  8306.         }
  8307.     }
  8308. }
  8309.  
  8310.  
  8311. #if 0
  8312. sub sys_customLoad ()
  8313.  
  8314.  
  8315.     dim temp as SDL_Surface ptr
  8316.  
  8317.     temp = IMG_Load("art/w.pcx")
  8318.  
  8319.     anim = 0
  8320.  
  8321.     playeranims = 4
  8322.     anims(anim) = SDL_CreateRGBSurface(SDL_SWSURFACE, 24 * 4, 24 * playeranims, SCR_BITS, video->format->rmask, video->format->gmask, video->format->bmask, video->format->amask)
  8323.  
  8324.     dim walkframeloc(4)
  8325.  
  8326.  
  8327.   walkframeloc(0) = 1
  8328.   walkframeloc(1) = 0
  8329.   walkframeloc(2) = 1
  8330.   walkframeloc(3) = 2
  8331.  
  8332.   ymod = 24
  8333.   ymod = 0
  8334.   FOR a = 0 TO 3
  8335.     FOR i = 0 TO 3
  8336.       // dqbget 5, a * 72 + i * 24, ymod, a * 72 + i * 24 + 23, ymod + 23, VARSEG(walkanim(0)), VARPTR(walkanim(walksize * (a * 3 + i)))
  8337.     b = walkframeloc(i)
  8338.     rcSrc.x = a * 72 + b * 24
  8339.     rcSrc.y = ymod
  8340.     rcSrc.w = 24
  8341.     rcSrc.h = 24
  8342.  
  8343.     rcDest.x = i * 24
  8344.     rcDest.y = a * 24
  8345.     rcDest.w = 24
  8346.     rcDest.h = 24
  8347.  
  8348.     SDL_BlitSurface(temp, &rcSrc, anims(anim), &rcDest
  8349.     NEXT
  8350.   NEXT
  8351.  
  8352.  
  8353.     d = SDL_SaveBMP(anims(anim), "art/anims" + str$(anim) + ".bmp")
  8354.  
  8355.     SDL_SetColorKey(anims(anim), SDL_SRCCOLORKEY, SDL_MapRGB(video->format, 255, 0, 255))
  8356.  
  8357.  
  8358.     SDL_FreeSurface(temp
  8359.  
  8360. end sub
  8361.  
  8362. #endif
  8363.  
  8364. void sys_initialize()
  8365. {
  8366.     int result;
  8367.     char line[128];
  8368.     char arg[128];
  8369.     FILE *fp;
  8370.  
  8371.     // init char *floatstri[MAXFLOAT]
  8372.     for(int i = 0; i <= MAXFLOAT; i++)
  8373.         floatstri[i] = malloc(64); // 64 bytes each string (should be enough)
  8374.  
  8375.     HWACCEL = 0;
  8376.     HWSURFACE = SDL_SWSURFACE;
  8377.  
  8378.     fp = fopen("config.ini", "r");
  8379.     if(fp) {
  8380.         while(fgets(line, sizeof(line), fp) != NULL) {
  8381.             sscanf(line, "%s", arg); // eliminate eol and eof by this
  8382.  
  8383.             if(strcmp(arg, "SCR_WIDTH:") == 0) {
  8384.                 fgets(line, sizeof(line), fp);
  8385.                 sscanf(line, "%i", &SCR_WIDTH);
  8386.             } else if(strcmp(arg, "SCR_HEIGHT:") == 0) {
  8387.                 fgets(line, sizeof(line), fp);
  8388.                 sscanf(line, "%i", &SCR_HEIGHT);
  8389.             } else if(strcmp(arg, "SCR_BITS:") == 0) {
  8390.                 fgets(line, sizeof(line), fp);
  8391.                 sscanf(line, "%i", &SCR_BITS);
  8392.             } else if(strcmp(arg, "HWACCEL:YES") == 0) {
  8393.                 HWACCEL = SDL_HWACCEL;
  8394.             } else if(strcmp(arg, "HWSURFACE:YES") == 0) {
  8395.                 HWSURFACE = SDL_HWSURFACE;
  8396.             } else if(strcmp(arg, "FULLSCREEN:YES") == 0) {
  8397.                 opfullscreen = SDL_FULLSCREEN;
  8398.             } else if(strcmp(arg, "MUSIC:YES") == 0) {
  8399.                 opmusic = 1;
  8400.             } else if(strcmp(arg, "SNDEFFECTS:YES") == 0) {
  8401.                 opeffects = 1;
  8402.             } else if(strcmp(arg, "opmusicvol:") == 0) {
  8403.                 fgets(line, sizeof(line), fp);
  8404.                 sscanf(line, "%i", &opmusicvol);
  8405.             } else if(strcmp(arg, "opeffectsvol:") == 0) {
  8406.                 fgets(line, sizeof(line), fp);
  8407.                 sscanf(line, "%i", &opeffectsvol);
  8408.             }
  8409.         }
  8410.  
  8411.         fclose(fp);
  8412.     }
  8413.  
  8414.     printf("SCR_WIDTH: %i\n", SCR_WIDTH);
  8415.     printf("SCR_HEIGHT: %i\n", SCR_HEIGHT);
  8416.     printf("SCR_BITS: %i\n", SCR_BITS);
  8417.  
  8418.     SCR_TOPX = SCR_WIDTH / 2 - 160;
  8419.     SCR_TOPY = SCR_HEIGHT / 2 - 120;
  8420.  
  8421.     fullscreen = opfullscreen | HWACCEL | SDL_SWSURFACE;
  8422.     // fullscreen = SDL_FULLSCREEN | HWACCEL | SDL_HWSURFACE;
  8423.  
  8424.     result = SDL_Init(SDL_INIT_EVERYTHING);
  8425.     if(result) {
  8426.         printf("Failed to init SDL\n");
  8427.         exit(1);
  8428.     }
  8429.  
  8430.     video = SDL_SetVideoMode(SCR_WIDTH, SCR_HEIGHT, SCR_BITS, fullscreen); // SDL_FULLSCREEN
  8431.     if(!video) {
  8432.         SDL_Quit();
  8433.         printf("Failed to init Video\n");
  8434.         exit(1);
  8435.     }
  8436.  
  8437.     SDL_WM_SetCaption("The Griffon Legend", NULL);
  8438.  
  8439.     SDL_ShowCursor(SDL_DISABLE);
  8440.  
  8441.     videobuffer = SDL_DisplayFormat(video);
  8442.     videobuffer2 = SDL_DisplayFormat(video);
  8443.     videobuffer3 = SDL_DisplayFormat(video);
  8444.     mapbg = SDL_CreateRGBSurface(HWSURFACE, 640, 480, SCR_BITS, video->format->Rmask, video->format->Gmask, video->format->Bmask, video->format->Amask);
  8445.     clipbg = SDL_CreateRGBSurface(SDL_SWSURFACE, 320, 240, SCR_BITS, video->format->Rmask, video->format->Gmask, video->format->Bmask, video->format->Amask);
  8446.     clipbg2 = SDL_DisplayFormat(video);
  8447.  
  8448.     for(int i = 0; i <= 3; i++) {
  8449.         char name[128];
  8450.  
  8451.         sprintf(name, "art/map%i.bmp", i + 1);
  8452.         mapimg[i] = SDL_DisplayFormat(video);
  8453.         mapimg[i] = IMG_Load(name);
  8454.         SDL_SetColorKey(mapimg[i], SDL_SRCCOLORKEY, SDL_MapRGB(mapimg[i]->format, 255, 0, 255));
  8455.     }
  8456.  
  8457.     cloudimg = IMG_Load("art/clouds.bmp");
  8458.     SDL_SetColorKey(cloudimg, SDL_SRCCOLORKEY, SDL_MapRGB(cloudimg->format, 255, 0, 255));
  8459.     SDL_SetAlpha(cloudimg, 0 | SDL_SRCALPHA, 96);
  8460.  
  8461.  
  8462.     saveloadimg = IMG_Load("art/saveloadnew.bmp");
  8463.     SDL_SetColorKey(saveloadimg, SDL_SRCCOLORKEY, SDL_MapRGB(saveloadimg->format, 255, 0, 255));
  8464.     SDL_SetAlpha(saveloadimg, 0 | SDL_SRCALPHA, 160);
  8465.  
  8466.     titleimg = IMG_Load("art/titleb.bmp");
  8467.     titleimg2 = IMG_Load("art/titlea.bmp");
  8468.     SDL_SetColorKey(titleimg2, SDL_SRCCOLORKEY, SDL_MapRGB(titleimg2->format, 255, 0, 255));
  8469.     //SDL_SetAlpha(titleimg2, 0 | SDL_SRCALPHA, 204);
  8470.  
  8471.     inventoryimg = IMG_Load("art/inventory.bmp");
  8472.     SDL_SetColorKey(inventoryimg, SDL_SRCCOLORKEY, SDL_MapRGB(inventoryimg->format, 255, 0, 255));
  8473.  
  8474.     logosimg = SDL_DisplayFormat(video);
  8475.     theendimg = SDL_DisplayFormat(video);
  8476.     logosimg = IMG_Load("art/logos.bmp");
  8477.     theendimg = IMG_Load("art/theend.bmp");
  8478.  
  8479.  
  8480.     sys_LoadTiles();
  8481.     sys_LoadTriggers();
  8482.     sys_LoadObjectDB();
  8483.     sys_LoadAnims();
  8484.     sys_LoadFont();
  8485.     sys_LoadItemImgs();
  8486.  
  8487.     fpsr = 1;
  8488.     nextticks = ticks + 1000;
  8489.  
  8490.     maxlevel = 22;
  8491.  
  8492.     for(int i = 0; i <= 15; i++) {
  8493.         playerattackofs[0][i][0] = 0; // -1// -(i + 1)
  8494.         playerattackofs[0][i][1] = -sin(3.14159 * 2 * (i + 1) / 16) * 2 - 1;
  8495.  
  8496.         playerattackofs[1][i][0] = 0; // i + 1
  8497.         playerattackofs[1][i][1] = -sin(3.14159 * 2 * (i + 1) / 16) * 2 + 1;
  8498.  
  8499.         playerattackofs[2][i][0] = -1; // -(i + 1)
  8500.         playerattackofs[2][i][1] = -sin(3.14159 * 2 * (i + 1) / 16) * 2;
  8501.  
  8502.         playerattackofs[3][i][0] = 1; // i + 1
  8503.         playerattackofs[3][i][1] = -sin(3.14159 * 2 * (i + 1) / 16) * 2;
  8504.     }
  8505.  
  8506.     sys_setupAudio();
  8507. }
  8508.  
  8509. void sys_line(SDL_Surface *buffer, int x1, int y1, int x2, int y2, int col)
  8510. {
  8511.     unsigned int *temp;
  8512.  
  8513.     SDL_LockSurface(buffer);
  8514.  
  8515.     int xdif = x2 - x1;
  8516.     int ydif = y2 - y1;
  8517.  
  8518.     if(xdif == 0) {
  8519.         for(int y = y1; y <= y2; y++) {
  8520.             temp = buffer->pixels + y * buffer->pitch + x1 * buffer->format->BytesPerPixel;
  8521.             *temp = col;
  8522.         }
  8523.     }
  8524.  
  8525.     if(ydif == 0) {
  8526.         for(int x = x1; x <= x2; x++) {
  8527.             temp = buffer->pixels + y1 * buffer->pitch + x * buffer->format->BytesPerPixel;
  8528.             *temp = col;
  8529.         }
  8530.     }
  8531.  
  8532.     SDL_UnlockSurface(buffer);
  8533. }
  8534.  
  8535. void sys_LoadAnims()
  8536. {
  8537.     //sys_customLoad();
  8538.  
  8539.     spellimg = IMG_Load("art/spells.bmp");
  8540.     SDL_SetColorKey(spellimg, SDL_SRCCOLORKEY, SDL_MapRGB(spellimg->format, 255, 0, 255));
  8541.  
  8542.     anims[0] = IMG_Load("art/anims0.bmp");
  8543.     SDL_SetColorKey(anims[0], SDL_SRCCOLORKEY, SDL_MapRGB(anims[0]->format, 255, 0, 255));
  8544.  
  8545.     animsa[0] = IMG_Load("art/anims0a.bmp");
  8546.     SDL_SetColorKey(animsa[0], SDL_SRCCOLORKEY, SDL_MapRGB(animsa[0]->format, 255, 0, 255));
  8547.  
  8548.     anims[13] = IMG_Load("art/anims0x.bmp");
  8549.     SDL_SetColorKey(anims[13], SDL_SRCCOLORKEY, SDL_MapRGB(anims[13]->format, 255, 0, 255));
  8550.  
  8551.     animsa[13] = IMG_Load("art/anims0xa.bmp");
  8552.     SDL_SetColorKey(animsa[13], SDL_SRCCOLORKEY, SDL_MapRGB(animsa[13]->format, 255, 0, 255));
  8553.  
  8554.     anims[1] = IMG_Load("art/anims1.bmp");
  8555.     SDL_SetColorKey(anims[1], SDL_SRCCOLORKEY, SDL_MapRGB(anims[1]->format, 255, 0, 255));
  8556.  
  8557.     animsa[1] = IMG_Load("art/anims1a.bmp");
  8558.     SDL_SetColorKey(animsa[1], SDL_SRCCOLORKEY, SDL_MapRGB(animsa[1]->format, 255, 0, 255));
  8559.  
  8560.     anims[2] = IMG_Load("art/anims2.bmp");
  8561.     SDL_SetColorKey(anims[2], SDL_SRCCOLORKEY, SDL_MapRGB(anims[2]->format, 255, 0, 255));
  8562.  
  8563.     // huge
  8564.     animset2[0].xofs = 8;
  8565.     animset2[0].yofs = 7;
  8566.     animset2[0].x = 123;
  8567.     animset2[0].y = 0;
  8568.     animset2[0].w = 18;
  8569.     animset2[0].h = 16;
  8570.     // big
  8571.     animset2[1].xofs = 7;
  8572.     animset2[1].yofs = 7;
  8573.     animset2[1].x = 107;
  8574.     animset2[1].y = 0;
  8575.     animset2[1].w = 16;
  8576.     animset2[1].h = 14;
  8577.     // med
  8578.     animset2[2].xofs = 6;
  8579.     animset2[2].yofs = 6;
  8580.     animset2[2].x = 93;
  8581.     animset2[2].y = 0;
  8582.     animset2[2].w = 14;
  8583.     animset2[2].h = 13;
  8584.     // small
  8585.     animset2[3].xofs = 4;
  8586.     animset2[3].yofs = 4;
  8587.     animset2[3].x = 83;
  8588.     animset2[3].y = 0;
  8589.     animset2[3].w = 10;
  8590.     animset2[3].h = 10;
  8591.     // wing
  8592.     animset2[4].xofs = 4;
  8593.     animset2[4].yofs = 20;
  8594.     animset2[4].x = 42;
  8595.     animset2[4].y = 0;
  8596.     animset2[4].w = 41;
  8597.     animset2[4].h = 33;
  8598.     // head
  8599.     animset2[5].xofs = 20;
  8600.     animset2[5].yofs = 18;
  8601.     animset2[5].x = 0;
  8602.     animset2[5].y = 0;
  8603.     animset2[5].w = 42;
  8604.     animset2[5].h = 36;
  8605.  
  8606.     anims[9] = IMG_Load("art/anims9.bmp");
  8607.     SDL_SetColorKey(anims[9], SDL_SRCCOLORKEY, SDL_MapRGB(anims[9]->format, 255, 0, 255));
  8608.  
  8609.     // huge
  8610.     animset9[0].xofs = 8;
  8611.     animset9[0].yofs = 7;
  8612.     animset9[0].x = 154;
  8613.     animset9[0].y = 0;
  8614.     animset9[0].w = 18;
  8615.     animset9[0].h = 16;
  8616.     // big
  8617.     animset9[1].xofs = 7;
  8618.     animset9[1].yofs = 7;
  8619.     animset9[1].x = 138;
  8620.     animset9[1].y = 0;
  8621.     animset9[1].w = 16;
  8622.     animset9[1].h = 14;
  8623.     // med
  8624.     animset9[2].xofs = 6;
  8625.     animset9[2].yofs = 6;
  8626.     animset9[2].x = 93 + 31;
  8627.     animset9[2].y = 0;
  8628.     animset9[2].w = 14;
  8629.     animset9[2].h = 13;
  8630.     // small
  8631.     animset9[3].xofs = 4;
  8632.     animset9[3].yofs = 4;
  8633.     animset9[3].x = 83 + 31;
  8634.     animset9[3].y = 0;
  8635.     animset9[3].w = 10;
  8636.     animset9[3].h = 10;
  8637.     // wing
  8638.     animset9[4].xofs = 36;
  8639.     animset9[4].yofs = 20;
  8640.     animset9[4].x = 42;
  8641.     animset9[4].y = 0;
  8642.     animset9[4].w = 72;
  8643.     animset9[4].h = 33;
  8644.     // head
  8645.     animset9[5].xofs = 20;
  8646.     animset9[5].yofs = 18;
  8647.     animset9[5].x = 0;
  8648.     animset9[5].y = 0;
  8649.     animset9[5].w = 42;
  8650.     animset9[5].h = 36;
  8651.  
  8652.     anims[3] = IMG_Load("art/anims3.bmp");
  8653.     SDL_SetColorKey(anims[3], SDL_SRCCOLORKEY, SDL_MapRGB(anims[3]->format, 255, 0, 255));
  8654.  
  8655.     anims[4] = IMG_Load("art/anims4.bmp");
  8656.     SDL_SetColorKey(anims[4], SDL_SRCCOLORKEY, SDL_MapRGB(anims[4]->format, 255, 0, 255));
  8657.  
  8658.     anims[5] = IMG_Load("art/anims5.bmp");
  8659.     SDL_SetColorKey(anims[5], SDL_SRCCOLORKEY, SDL_MapRGB(anims[5]->format, 255, 0, 255));
  8660.  
  8661.     anims[6] = IMG_Load("art/anims6.bmp");
  8662.     SDL_SetColorKey(anims[6], SDL_SRCCOLORKEY, SDL_MapRGB(anims[6]->format, 255, 0, 255));
  8663.  
  8664.     anims[7] = IMG_Load("art/anims7.bmp");
  8665.     SDL_SetColorKey(anims[7], SDL_SRCCOLORKEY, SDL_MapRGB(anims[7]->format, 255, 0, 255));
  8666.  
  8667.     anims[8] = IMG_Load("art/anims8.bmp");
  8668.     SDL_SetColorKey(anims[8], SDL_SRCCOLORKEY, SDL_MapRGB(anims[8]->format, 255, 0, 255));
  8669.  
  8670.     anims[10] = IMG_Load("art/anims10.bmp");
  8671.     SDL_SetColorKey(anims[10], SDL_SRCCOLORKEY, SDL_MapRGB(anims[10]->format, 255, 0, 255));
  8672.  
  8673.     animsa[10] = IMG_Load("art/anims10a.bmp");
  8674.     SDL_SetColorKey(animsa[10], SDL_SRCCOLORKEY, SDL_MapRGB(animsa[10]->format, 255, 0, 255));
  8675.  
  8676.     anims[11] = IMG_Load("art/anims11.bmp");
  8677.     SDL_SetColorKey(anims[11], SDL_SRCCOLORKEY, SDL_MapRGB(anims[11]->format, 255, 0, 255));
  8678.  
  8679.     animsa[11] = IMG_Load("art/anims11a.bmp");
  8680.     SDL_SetColorKey(animsa[11], SDL_SRCCOLORKEY, SDL_MapRGB(animsa[11]->format, 255, 0, 255));
  8681.  
  8682.     anims[12] = IMG_Load("art/anims12.bmp");
  8683.     SDL_SetColorKey(anims[12], SDL_SRCCOLORKEY, SDL_MapRGB(anims[12]->format, 255, 0, 255));
  8684. }
  8685.  
  8686. void sys_LoadItemImgs()
  8687. {
  8688.     SDL_Surface *temp;
  8689.  
  8690.     temp = IMG_Load("art/icons.bmp");
  8691.  
  8692.     for(int i = 0; i <= 20; i++) {
  8693.         itemimg[i] = SDL_CreateRGBSurface(SDL_SWSURFACE, 16, 16, SCR_BITS, video->format->Rmask, video->format->Gmask, video->format->Bmask, video->format->Amask);
  8694.         SDL_SetColorKey(itemimg[i], SDL_SRCCOLORKEY, SDL_MapRGB(itemimg[i]->format, 255, 0, 255));
  8695.  
  8696.         rcSrc.x = i * 16;
  8697.         rcSrc.y = 0;
  8698.         rcSrc.w = 16;
  8699.         rcSrc.h = 16;
  8700.  
  8701.         SDL_BlitSurface(temp, &rcSrc, itemimg[i], NULL);
  8702.     }
  8703.  
  8704.     SDL_FreeSurface(temp);
  8705. }
  8706.  
  8707. void sys_LoadFont()
  8708. {
  8709.     SDL_Surface *font;
  8710.  
  8711.     font = IMG_Load("art/font.bmp");
  8712.  
  8713.     for(int i = 32; i <= 255; i++)
  8714.         for(int f = 0; f <= 4; f++) {
  8715.             int i2 = i - 32;
  8716.  
  8717.             fontchr[i2][f] = SDL_CreateRGBSurface(SDL_SWSURFACE, 8, 8, SCR_BITS, video->format->Rmask, video->format->Gmask, video->format->Bmask, video->format->Amask);
  8718.             SDL_SetColorKey(fontchr[i2][f], SDL_SRCCOLORKEY, SDL_MapRGB(fontchr[i2][f]->format, 255, 0, 255));
  8719.  
  8720.             int col = i2 % 40;
  8721.  
  8722.             int row = (i2 - col) / 40;
  8723.  
  8724.             rcSrc.x = col * 8;
  8725.             rcSrc.y = row * 8 + f * 48;
  8726.             rcSrc.w = 8;
  8727.             rcSrc.h = 8;
  8728.  
  8729.             rcDest.x = 0;
  8730.             rcDest.y = 0;
  8731.             SDL_BlitSurface(font, &rcSrc, fontchr[i2][f], &rcDest);
  8732.         }
  8733.  
  8734.     SDL_FreeSurface(font);
  8735. }
  8736.  
  8737. void sys_LoadTiles()
  8738. {
  8739.     tiles[0] = IMG_Load("art/tx.bmp");
  8740.     tiles[1] = IMG_Load("art/tx1.bmp");
  8741.     tiles[2] = IMG_Load("art/tx2.bmp");
  8742.     tiles[3] = IMG_Load("art/tx3.bmp");
  8743.  
  8744.     for(int i = 0; i <= 3; i++)
  8745.         SDL_SetColorKey(tiles[i], SDL_SRCCOLORKEY, SDL_MapRGB(tiles[i]->format, 255, 0, 255));
  8746.  
  8747.     windowimg = IMG_Load("art/window.bmp");
  8748.     SDL_SetColorKey(windowimg, SDL_SRCCOLORKEY, SDL_MapRGB(windowimg->format, 255, 0, 255));
  8749. }
  8750.  
  8751. void sys_LoadTriggers()
  8752. {
  8753.     FILE *fp;
  8754.     char line[512];
  8755.  
  8756.     fp = fopen("data/triggers.dat", "r");
  8757.  
  8758.     for(int i = 0; i <= 9999; i++)
  8759.         for(int a = 0; a <= 8; a++) {
  8760.             fgets(line, sizeof(line), fp);
  8761.             sscanf(line, "%i", &triggers[i][a]);
  8762.         }
  8763.  
  8764.     fclose(fp);
  8765. }
  8766.  
  8767. void sys_LoadObjectDB()
  8768. {
  8769.     FILE *fp;
  8770.     char line[512];
  8771.     // DIM SHARED objectinfo(255, 6)
  8772.                 // nframes,xtiles,ytiles,speed,type,script, update?
  8773.  
  8774.     // DIM SHARED objecttile(255, 4, 2, 2, 1)
  8775.                 // [objnum] [frame] [x] [y] [tile/layer]
  8776.  
  8777.     fp = fopen("objectdb.dat", "r");
  8778.  
  8779.     for(int a = 0; a <= 32; a++) {
  8780.         for(int b = 0; b <= 5; b++) {
  8781.             fgets(line, sizeof(line), fp);
  8782.             sscanf(line, "%i", &objectinfo[a][b]);
  8783.         }
  8784.  
  8785.         for(int b = 0; b <= 8; b++) {
  8786.             for(int c = 0; c <= 2; c++) {
  8787.                 for(int d = 0; d <= 2; d++) {
  8788.                     for(int e = 0; e <= 1; e++) {
  8789.                         fgets(line, sizeof(line), fp);
  8790.                         sscanf(line, "%i", &objecttile[a][b][c][d][e]);
  8791.                     }
  8792.                 }
  8793.             }
  8794.         }
  8795.     }
  8796.  
  8797.     fclose(fp);
  8798. }
  8799.  
  8800. void sys_print(SDL_Surface *buffer, char *stri, int xloc, int yloc, int col)
  8801. {
  8802.     int l = strlen(stri);
  8803.  
  8804.     for(int i = 0; i < l; i++) {
  8805.         rcDest.x = xloc + i * 8;
  8806.         rcDest.y = yloc;
  8807.  
  8808.         SDL_BlitSurface(fontchr[stri[i] - 32][col], NULL, buffer, &rcDest);
  8809.     }
  8810. }
  8811.  
  8812. void sys_progress(int w, int wm)
  8813. {
  8814.         long ccc;
  8815.  
  8816.         ccc = SDL_MapRGB(videobuffer->format, 0, 255, 0);
  8817.  
  8818.         rcDest.w = w / wm * 74;
  8819.         SDL_FillRect(video, &rcDest, ccc);
  8820.         SDL_Flip(video);
  8821. }
  8822.  
  8823. void sys_setupAudio()
  8824. {
  8825.     SDL_Surface *loadimg;
  8826.  
  8827.     int menabled = 1;
  8828.     //FSOUND_Init(44100, 512, 0);
  8829.  
  8830.  
  8831.     char *stri = "Loading...";
  8832.     sys_print(video, stri, SCR_TOPX + 160 - 4 * strlen(stri), SCR_TOPY + 116, 0);
  8833.  
  8834.     loadimg = IMG_Load("art/load.bmp");
  8835.     SDL_SetColorKey(loadimg, SDL_SRCCOLORKEY, SDL_MapRGB(loadimg->format, 255, 0, 255));
  8836.  
  8837.     SDL_Flip(video);
  8838.  
  8839.     rcSrc.x = 0;
  8840.     rcSrc.y = 0;
  8841.     rcSrc.w = 88;
  8842.     rcSrc.h = 32;
  8843.  
  8844.     rcDest.x = SCR_TOPX + 160 - 44;
  8845.     rcDest.y = SCR_TOPY + 116 + 12;
  8846.  
  8847.     SDL_SetAlpha(loadimg, 0 | SDL_SRCALPHA, 160); // 128
  8848.     SDL_BlitSurface(loadimg, &rcSrc, video, &rcDest);
  8849.     SDL_SetAlpha(loadimg, 0 | SDL_SRCALPHA, 255);
  8850.  
  8851.  
  8852.     rcDest.x = SCR_TOPX + 160 - 44 + 7;
  8853.     rcDest.y = SCR_TOPY + 116 + 12 + 12;
  8854.     rcDest.h = 8;
  8855.  
  8856.  
  8857.     //mboss = FSOUND_Sample_Load(FSOUND_FREE, "music/boss.ogg", 0, 0, 0);
  8858.     //if(mboss == 0) {
  8859.     //  menabled = 0;
  8860.     //  FSOUND_Close();
  8861.     //}
  8862.  
  8863.     if(menabled == 1) {
  8864.         sys_progress(1, 21);
  8865.         //mgardens = FSOUND_Sample_Load(FSOUND_FREE, "music/gardens.ogg", 0, 0, 0);
  8866.         sys_progress(2, 21);
  8867.         //mgardens2 = FSOUND_Sample_Load(FSOUND_FREE, "music/gardens2.ogg", 0, 0, 0);
  8868.         sys_progress(3, 21);
  8869.         //mgardens3 = FSOUND_Sample_Load(FSOUND_FREE, "music/gardens3.ogg", 0, 0, 0);
  8870.         sys_progress(4, 21);
  8871.         //mgardens4 = FSOUND_Sample_Load(FSOUND_FREE, "music/gardens4.ogg", 0, 0, 0);
  8872.         sys_progress(5, 21);
  8873.         //mendofgame = FSOUND_Sample_Load(FSOUND_FREE, "music/endofgame.ogg", 0, 0, 0);
  8874.         sys_progress(6, 21);
  8875.         //mmenu = FSOUND_Sample_Load(FSOUND_FREE, "music/menu.ogg", 0, 0, 0);
  8876.         sys_progress(7, 21);
  8877.  
  8878.         //FSOUND_Sample_SetMode(mboss, FSOUND_LOOP_NORMAL);
  8879.         //FSOUND_Sample_SetMode(mgardens, FSOUND_LOOP_OFF);
  8880.         //FSOUND_Sample_SetMode(mgardens2, FSOUND_LOOP_OFF);
  8881.         //FSOUND_Sample_SetMode(mgardens3, FSOUND_LOOP_OFF);
  8882.         //FSOUND_Sample_SetMode(mgardens4, FSOUND_LOOP_OFF);
  8883.         //FSOUND_Sample_SetMode(mmenu, FSOUND_LOOP_NORMAL);
  8884.         //FSOUND_Sample_SetMode(mendofgame, FSOUND_LOOP_NORMAL);
  8885.  
  8886.         //sfx[0] = FSOUND_Sample_Load(FSOUND_FREE, "sfx/bite.ogg", 0, 0, 0);
  8887.         sys_progress(8, 21);
  8888.         //sfx[1] = FSOUND_Sample_Load(FSOUND_FREE, "sfx/crystal.ogg", 0, 0, 0);
  8889.         sys_progress(9, 21);
  8890.         //sfx[2] = FSOUND_Sample_Load(FSOUND_FREE, "sfx/door.ogg", 0, 0, 0);
  8891.         sys_progress(10, 21);
  8892.         //sfx[3] = FSOUND_Sample_Load(FSOUND_FREE, "sfx/enemyhit.ogg", 0, 0, 0);
  8893.         sys_progress(11, 21);
  8894.         //sfx[4] = FSOUND_Sample_Load(FSOUND_FREE, "sfx/ice.ogg", 0, 0, 0);
  8895.         sys_progress(12, 21);
  8896.         //sfx[5] = FSOUND_Sample_Load(FSOUND_FREE, "sfx/lever.ogg", 0, 0, 0);
  8897.         sys_progress(13, 21);
  8898.         //sfx[6] = FSOUND_Sample_Load(FSOUND_FREE, "sfx/lightning.ogg", 0, 0, 0);
  8899.         sys_progress(14, 21);
  8900.         //sfx[7] = FSOUND_Sample_Load(FSOUND_FREE, "sfx/metalhit.ogg", 0, 0, 0);
  8901.         sys_progress(15, 21);
  8902.         //sfx[8] = FSOUND_Sample_Load(FSOUND_FREE, "sfx/powerup.ogg", 0, 0, 0);
  8903.         sys_progress(16, 21);
  8904.         //sfx[9] = FSOUND_Sample_Load(FSOUND_FREE, "sfx/rocks.ogg", 0, 0, 0);
  8905.         sys_progress(17, 21);
  8906.         //sfx[10] = FSOUND_Sample_Load(FSOUND_FREE, "sfx/swordhit.ogg", 0, 0, 0);
  8907.         sys_progress(18, 21);
  8908.         //sfx[11] = FSOUND_Sample_Load(FSOUND_FREE, "sfx/throw.ogg", 0, 0, 0);
  8909.         sys_progress(19, 21);
  8910.         //sfx[12] = FSOUND_Sample_Load(FSOUND_FREE, "sfx/chest.ogg", 0, 0, 0);
  8911.         sys_progress(20, 21);
  8912.         //sfx[13] = FSOUND_Sample_Load(FSOUND_FREE, "sfx/fire.ogg", 0, 0, 0);
  8913.         sys_progress(21, 21);
  8914.         //sfx[14] = FSOUND_Sample_Load(FSOUND_FREE, "sfx/beep.ogg", 0, 0, 0);
  8915.  
  8916.         for(int i = 0; i <= 14; i++) {
  8917.             //FSOUND_Sample_SetMode(sfx[i], FSOUND_LOOP_OFF);
  8918.         }
  8919.     }
  8920. }
  8921.  
  8922. void sys_update()
  8923. {
  8924.     unsigned int *temp, bgc;
  8925.     int pa, sx, sy;
  8926.     float opx, opy, spd;
  8927.  
  8928.     // SDL_UpdateRect video, 0, 0, SCR_WIDTH, SCR_HEIGHT
  8929.     SDL_Flip(video);
  8930.     SDL_PumpEvents();
  8931.  
  8932.     tickspassed = ticks;
  8933.     ticks = SDL_GetTicks();
  8934.  
  8935.     tickspassed = ticks - tickspassed;
  8936.     fpsr = (float)tickspassed / 24.0;
  8937.  
  8938.     fp += 1;
  8939.     if(ticks > nextticks) {
  8940.         nextticks = ticks + 1000;
  8941.         fps = fp;
  8942.         fp = 0;
  8943.         secsingame = secsingame + 1;
  8944.     }
  8945.  
  8946.     SDL_LockSurface(clipbg);
  8947.  
  8948.     if(attacking == 1) {
  8949.         player.attackframe += player.attackspd * fpsr;
  8950.         if(player.attackframe >= 16) {
  8951.             attacking = 0;
  8952.             player.attackframe = 0;
  8953.             player.walkframe = 0;
  8954.         }
  8955.  
  8956.         pa = (int)(player.attackframe);
  8957.  
  8958.         for(int i = 0; i <= pa; i++) {
  8959.             if(playerattackofs[player.walkdir][i][2] == 0) {
  8960.                 playerattackofs[player.walkdir][i][2] = 1;
  8961.  
  8962.                 opx = player.px;
  8963.                 opy = player.py;
  8964.  
  8965.                 player.px = player.px + playerattackofs[player.walkdir][i][0];
  8966.                 player.py = player.py + playerattackofs[player.walkdir][i][1];
  8967.  
  8968.                 sx = (int)(player.px / 2 + 6);
  8969.                 sy = (int)(player.py / 2 + 10);
  8970.                 temp = clipbg->pixels + sy * clipbg->pitch + sx * clipbg->format->BytesPerPixel;
  8971.                 bgc = *temp;
  8972.                 if(bgc > 0) {
  8973.                     player.px = opx;
  8974.                     player.py = opy;
  8975.                 }
  8976.             }
  8977.         }
  8978.  
  8979.         player.opx = player.px;
  8980.         player.opy = player.py;
  8981.  
  8982.         game_checkhit();
  8983.     }
  8984.  
  8985.     for(int i = 0; i <= MAXFLOAT; i++) {
  8986.         if(floattext[i][0] > 0) {
  8987.             spd = 0.5 * fpsr;
  8988.             floattext[i][0] = floattext[i][0] - spd;
  8989.             floattext[i][2] = floattext[i][2] - spd;
  8990.             if(floattext[i][0] < 0) floattext[i][0] = 0;
  8991.         }
  8992.  
  8993.         if(floaticon[i][0] > 0) {
  8994.             spd = 0.5 * fpsr;
  8995.             floaticon[i][0] = floaticon[i][0] - spd;
  8996.             floaticon[i][2] = floaticon[i][2] - spd;
  8997.             if(floaticon[i][0] < 0) floaticon[i][0] = 0;
  8998.         }
  8999.     }
  9000.  
  9001.     if(player.level == maxlevel) player.exp = 0;
  9002.  
  9003.     if(player.exp >= player.nextlevel) {
  9004.         player.level = player.level + 1;
  9005.         game_addFloatText("LEVEL UP!", player.px + 16 - 36, player.py + 16, 3);
  9006.         player.exp = player.exp - player.nextlevel;
  9007.         // player.nextlevel = player.level * 75;
  9008.         player.nextlevel = player.nextlevel * 2;
  9009.         player.maxhp = player.maxhp + player.level * 3;
  9010.         if(player.maxhp > 999) player.maxhp = 999;
  9011.         player.hp = player.maxhp;
  9012.  
  9013.         player.sworddamage = player.level * 1.4;
  9014.         player.spelldamage = player.level * 1.3;
  9015.  
  9016.         if(menabled == 1 && opeffects == 1) {
  9017.             //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndpowerup))
  9018.             //FSOUND_setVolume(snd, opeffectsvol)
  9019.         }
  9020.     }
  9021.  
  9022.     SDL_UnlockSurface(clipbg);
  9023.     SDL_BlitSurface(clipbg2, NULL, clipbg, NULL);
  9024.  
  9025.     rc.x = player.px - 2;
  9026.     rc.y = player.py - 2;
  9027.     rc.w = 5;
  9028.     rc.h = 5;
  9029.  
  9030.     SDL_FillRect(clipbg, &rc, 1000);
  9031.  
  9032.     if(forcepause == 0) {
  9033.         if(player.foundcrystal == 1) player.crystalcharge += 5 * player.level * 0.001 * fpsr;
  9034.         if(player.crystalcharge > 100) player.crystalcharge = 100;
  9035.  
  9036.         for(int i = 0; i <= 4; i++) {
  9037.             if(player.foundspell[i] == 1) player.spellcharge[i] += 1 * player.level * 0.01 * fpsr;
  9038.             if(player.spellcharge[i] > 100) player.spellcharge[i] = 100;
  9039.         }
  9040.  
  9041.         player.attackstrength += (30 + 3 * (float)player.level) / 50 * fpsr;
  9042.  
  9043.         if(player.foundcrystal) {
  9044.             player.spellstrength += 3 * player.level * .01 * fpsr;
  9045.         }
  9046.     }
  9047.  
  9048.     if(player.attackstrength > 100) player.attackstrength = 100;
  9049.  
  9050.     if(player.spellstrength > 100) player.spellstrength = 100;
  9051.  
  9052.     itemyloc = itemyloc + 0.75 * fpsr;
  9053.     while(itemyloc >= 16) itemyloc -= 16;
  9054.  
  9055.     if(player.hp <= 0) game_theend();
  9056.  
  9057.     if(roomlock == 1) {
  9058.         roomlock = 0;
  9059.         for(int i = 1; i <= lastnpc; i++)
  9060.             if(npcinfo[i].hp > 0) roomlock = 1;
  9061.     }
  9062.  
  9063.     clouddeg = clouddeg + 0.1 * fpsr;
  9064.     while(clouddeg >= 360) clouddeg = clouddeg - 360;
  9065.  
  9066.     player.hpflash = player.hpflash + 0.1 * fpsr;
  9067.     if(player.hpflash >=2) {
  9068.         player.hpflash = 0;
  9069.         player.hpflashb = player.hpflashb + 1;
  9070.         if(player.hpflashb == 2) player.hpflashb = 0;
  9071.         if(menabled == 1 && opeffects == 1 && player.hpflashb == 0 && player.hp < player.maxhp / 4) {
  9072.             //snd = FSOUND_PlaySound(FSOUND_FREE, sfx(sndbeep))
  9073.             //FSOUND_setVolume(snd, opeffectsvol)
  9074.         }
  9075.     }
  9076.  
  9077.     // cloudson = 0
  9078.  
  9079.     if(itemselon == 1) player.itemselshade = player.itemselshade + 2 * fpsr;
  9080.     if(player.itemselshade > 24) player.itemselshade = 24;
  9081.  
  9082.     for(int i = 0; i <= 4; i++)
  9083.         if(inventory[i] > 9) inventory[i] = 9;
  9084. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement