Guest User

dragonfree

a guest
Oct 24th, 2010
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 148.49 KB | None | 0 0
  1. #include <stdint.h>
  2. #include <math.h>
  3. #include <defines.h>
  4. #include <powder.h>
  5. #include <air.h>
  6. #include <misc.h>
  7.  
  8.  
  9. int isplayer = 0;
  10. float player[27]; //[0] is a command cell, [3]-[18] are legs positions, [19] is index, [19]-[26] are accelerations
  11.  
  12. particle *parts;
  13. particle *cb_parts;
  14.  
  15. unsigned char bmap[YRES/CELL][XRES/CELL];
  16. unsigned char emap[YRES/CELL][XRES/CELL];
  17.  
  18. unsigned char cb_bmap[YRES/CELL][XRES/CELL];
  19. unsigned char cb_emap[YRES/CELL][XRES/CELL];
  20.  
  21. int pfree;
  22.  
  23. unsigned pmap[YRES][XRES];
  24. unsigned cb_pmap[YRES][XRES];
  25.  
  26.  
  27.  
  28. static int pn_junction_sprk(int x, int y, int pt)
  29. {
  30. unsigned r = pmap[y][x];
  31. if((r & 0xFF) != pt)
  32. return 0;
  33. r >>= 8;
  34. if(parts[r].type != pt)
  35. return 0;
  36.  
  37. parts[r].ctype = pt;
  38. parts[r].type = PT_SPRK;
  39. parts[r].life = 4;
  40. return 1;
  41. }
  42.  
  43. static void photoelectric_effect(int nx, int ny)
  44. {
  45. unsigned r = pmap[ny][nx];
  46.  
  47. if((r&0xFF) == PT_PSCN) {
  48. if((pmap[ny][nx-1] & 0xFF) == PT_NSCN ||
  49. (pmap[ny][nx+1] & 0xFF) == PT_NSCN ||
  50. (pmap[ny-1][nx] & 0xFF) == PT_NSCN ||
  51. (pmap[ny+1][nx] & 0xFF) == PT_NSCN)
  52. pn_junction_sprk(nx, ny, PT_PSCN);
  53. }
  54. }
  55.  
  56. static int eval_move(int pt, int nx, int ny, unsigned *rr)
  57. {
  58. unsigned r;
  59.  
  60. if(nx<0 || ny<0 || nx>=XRES || ny>=YRES)
  61. return 0;
  62.  
  63. r = pmap[ny][nx];
  64. if(r && (r>>8)<NPART)
  65. r = (r&~0xFF) | parts[r>>8].type;
  66. if(rr)
  67. *rr = r;
  68.  
  69. if((r&0xFF)==PT_VOID || (r&0xFF)==PT_BHOL)
  70. return 1;
  71.  
  72. if(pt==PT_NEUT && (r&0xFF)==PT_GLAS)
  73. return 2;
  74.  
  75. if(pt==PT_PHOT&&(
  76. (r&0xFF)==PT_GLAS || (r&0xFF)==PT_PHOT ||
  77. (r&0xFF)==PT_CLNE || (r&0xFF)==PT_PCLN ||
  78. (r&0xFF)==PT_GLOW ||
  79. (r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW || (r&0xFF)==PT_SLTW ||
  80. ((r&0xFF)==PT_LCRY&&parts[r>>8].life > 5)))
  81. return 2;
  82.  
  83. if(pt==PT_STKM) //Stick man's head shouldn't collide
  84. return 2;
  85.  
  86. if(bmap[ny/CELL][nx/CELL]==13 && ptypes[pt].falldown!=0 && pt!=PT_FIRE && pt!=PT_SMKE)
  87. return 0;
  88. if(ptypes[pt].falldown!=2 && bmap[ny/CELL][nx/CELL]==3)
  89. return 0;
  90. if((pt==PT_NEUT ||pt==PT_PHOT) && bmap[ny/CELL][nx/CELL]==7 && !emap[ny/CELL][nx/CELL])
  91. return 0;
  92.  
  93. if(bmap[ny/CELL][nx/CELL]==9)
  94. return 0;
  95.  
  96. if(ptypes[pt].falldown!=1 && bmap[ny/CELL][nx/CELL]==10)
  97. return 0;
  98.  
  99. if (r && ((r&0xFF) >= PT_NUM || !can_move[pt][(r&0xFF)]))
  100. return 0;
  101.  
  102. if(pt == PT_PHOT)
  103. return 2;
  104. return 1;
  105. }
  106.  
  107. static void create_cherenkov_photon(int pp);
  108. static void create_gain_photon(int pp);
  109.  
  110. int try_move(int i, int x, int y, int nx, int ny)
  111. {
  112. unsigned r, e;
  113.  
  114. if(x==nx && y==ny)
  115. return 1;
  116.  
  117. e = eval_move(parts[i].type, nx, ny, &r);
  118.  
  119. /* half-silvered mirror */
  120. if(!e && parts[i].type==PT_PHOT &&
  121. (((r&0xFF)==PT_BMTL && rand()<RAND_MAX/2) ||
  122. (pmap[y][x]&0xFF)==PT_BMTL))
  123. e = 2;
  124.  
  125. if(!e) {
  126. if(!legacy_enable && parts[i].type==PT_PHOT) {
  127. if((r & 0xFF) == PT_COAL || (r & 0xFF) == PT_BCOL)
  128. parts[r>>8].temp = parts[i].temp;
  129. if((r & 0xFF) < PT_NUM)
  130. parts[i].temp = parts[r>>8].temp =
  131. restrict_flt((parts[r>>8].temp+parts[i].temp)/2, MIN_TEMP, MAX_TEMP);
  132. }
  133. return 0;
  134. }
  135. if(e == 2) {
  136. if(parts[i].type == PT_PHOT && (r&0xFF)==PT_GLOW && !parts[r>>8].life)
  137. if(rand() < RAND_MAX/30) {
  138. parts[r>>8].life = 120;
  139. create_gain_photon(i);
  140. }
  141. if(parts[i].type == PT_NEUT && (r&0xFF)==PT_GLAS) {
  142. if(rand() < RAND_MAX/10)
  143. create_cherenkov_photon(i);
  144. }
  145. return 1;
  146. }
  147.  
  148. if((r&0xFF)==PT_VOID)
  149. {
  150. parts[i].type=PT_NONE;
  151. return 0;
  152. }
  153. if((r&0xFF)==PT_BHOL)
  154. {
  155. parts[i].type=PT_NONE;
  156. if(!legacy_enable)
  157. {
  158. parts[r>>8].temp = restrict_flt(parts[r>>8].temp+parts[i].temp/2, MIN_TEMP, MAX_TEMP);//3.0f;
  159. }
  160.  
  161. return 0;
  162. }
  163. if(parts[i].type==PT_CNCT && y<ny && (pmap[y+1][x]&0xFF)==PT_CNCT)
  164. return 0;
  165.  
  166. if(bmap[ny/CELL][nx/CELL]==12 && !emap[y/CELL][x/CELL])
  167. return 1;
  168. if((bmap[y/CELL][x/CELL]==12 && !emap[y/CELL][x/CELL]) && (bmap[ny/CELL][nx/CELL]!=12 && !emap[ny/CELL][nx/CELL]))
  169. return 0;
  170.  
  171. if(r && (r>>8)<NPART && ptypes[r&0xFF].falldown!=2 && bmap[y/CELL][x/CELL]==3)
  172. return 0;
  173.  
  174. if(parts[i].type == PT_PHOT)
  175. return 1;
  176.  
  177. e = r >> 8;
  178. if(r && e<NPART)
  179. {
  180. if(parts[e].type == PT_PHOT)
  181. return 1;
  182.  
  183. parts[e].x += x-nx;
  184. parts[e].y += y-ny;
  185. }
  186.  
  187. pmap[ny][nx] = (i<<8)|parts[i].type;
  188. pmap[y][x] = r;
  189.  
  190. return 1;
  191. }
  192. #define SURF_RANGE 10
  193. #define NORMAL_MIN_EST 3
  194. #define NORMAL_INTERP 20
  195. #define NORMAL_FRAC 16
  196.  
  197. #define REFRACT 0x80000000
  198.  
  199. /* heavy flint glass, for awesome refraction/dispersion
  200. this way you can make roof prisms easily */
  201. #define GLASS_IOR 1.9
  202. #define GLASS_DISP 0.07
  203.  
  204. static unsigned direction_to_map(float dx, float dy)
  205. {
  206. return (dx >= 0) |
  207. (((dx + dy) >= 0) << 1) | /* 567 */
  208. ((dy >= 0) << 2) | /* 4+0 */
  209. (((dy - dx) >= 0) << 3) | /* 321 */
  210. ((dx <= 0) << 4) |
  211. (((dx + dy) <= 0) << 5) |
  212. ((dy <= 0) << 6) |
  213. (((dy - dx) <= 0) << 7);
  214. }
  215.  
  216. static int is_blocking(int t, int x, int y)
  217. {
  218. if(t & REFRACT) {
  219. if(x<0 || y<0 || x>=XRES || y>=YRES)
  220. return 0;
  221. if((pmap[y][x] & 0xFF) == PT_GLAS)
  222. return 1;
  223. return 0;
  224. }
  225.  
  226. return !eval_move(t, x, y, NULL);
  227. }
  228.  
  229. static int is_boundary(int pt, int x, int y)
  230. {
  231. if(!is_blocking(pt,x,y))
  232. return 0;
  233. if(is_blocking(pt,x,y-1) && is_blocking(pt,x,y+1) && is_blocking(pt,x-1,y) && is_blocking(pt,x+1,y))
  234. return 0;
  235. return 1;
  236. }
  237.  
  238. static int find_next_boundary(int pt, int *x, int *y, int dm, int *em)
  239. {
  240. static int dx[8] = {1,1,0,-1,-1,-1,0,1};
  241. static int dy[8] = {0,1,1,1,0,-1,-1,-1};
  242. static int de[8] = {0x83,0x07,0x0E,0x1C,0x38,0x70,0xE0,0xC1};
  243. int i, ii, i0;
  244.  
  245. if(*x <= 0 || *x >= XRES-1 || *y <= 0 || *y >= YRES-1)
  246. return 0;
  247.  
  248. if(*em != -1) {
  249. i0 = *em;
  250. dm &= de[i0];
  251. } else
  252. i0 = 0;
  253.  
  254. for(ii=0; ii<8; ii++) {
  255. i = (ii + i0) & 7;
  256. if((dm & (1 << i)) && is_boundary(pt, *x+dx[i], *y+dy[i])) {
  257. *x += dx[i];
  258. *y += dy[i];
  259. *em = i;
  260. return 1;
  261. }
  262. }
  263.  
  264. return 0;
  265. }
  266.  
  267. int get_normal(int pt, int x, int y, float dx, float dy, float *nx, float *ny)
  268. {
  269. int ldm, rdm, lm, rm;
  270. int lx, ly, lv, rx, ry, rv;
  271. int i, j;
  272. float r, ex, ey;
  273.  
  274. if(!dx && !dy)
  275. return 0;
  276.  
  277. if(!is_boundary(pt, x, y))
  278. return 0;
  279.  
  280. ldm = direction_to_map(-dy, dx);
  281. rdm = direction_to_map(dy, -dx);
  282. lx = rx = x;
  283. ly = ry = y;
  284. lv = rv = 1;
  285. lm = rm = -1;
  286.  
  287. j = 0;
  288. for(i=0; i<SURF_RANGE; i++) {
  289. if(lv)
  290. lv = find_next_boundary(pt, &lx, &ly, ldm, &lm);
  291. if(rv)
  292. rv = find_next_boundary(pt, &rx, &ry, rdm, &rm);
  293. j += lv + rv;
  294. if(!lv && !rv)
  295. break;
  296. }
  297.  
  298. if(j < NORMAL_MIN_EST)
  299. return 0;
  300.  
  301. if((lx == rx) && (ly == ry))
  302. return 0;
  303.  
  304. ex = rx - lx;
  305. ey = ry - ly;
  306. r = 1.0f/hypot(ex, ey);
  307. *nx = ey * r;
  308. *ny = -ex * r;
  309.  
  310. return 1;
  311. }
  312.  
  313. int get_normal_interp(int pt, float x0, float y0, float dx, float dy, float *nx, float *ny)
  314. {
  315. int x, y, i;
  316.  
  317. dx /= NORMAL_FRAC;
  318. dy /= NORMAL_FRAC;
  319.  
  320. for(i=0; i<NORMAL_INTERP; i++) {
  321. x = (int)(x0 + 0.5f);
  322. y = (int)(y0 + 0.5f);
  323. if(is_boundary(pt, x, y))
  324. break;
  325. x0 += dx;
  326. y0 += dy;
  327. }
  328. if(i >= NORMAL_INTERP)
  329. return 0;
  330.  
  331. if(pt == PT_PHOT)
  332. photoelectric_effect(x, y);
  333.  
  334. return get_normal(pt, x, y, dx, dy, nx, ny);
  335. }
  336.  
  337. void kill_part(int i)
  338. {
  339. int x, y;
  340.  
  341. if(parts[i].type != PT_PHOT) {
  342. x = (int)(parts[i].x+0.5f);
  343. y = (int)(parts[i].y+0.5f);
  344.  
  345. if(x>=0 && y>=0 && x<XRES && y<YRES)
  346. pmap[y][x] = 0;
  347. }
  348.  
  349. parts[i].type = PT_NONE;
  350. parts[i].life = pfree;
  351. pfree = i;
  352. }
  353.  
  354. #ifdef WIN32
  355. _inline int create_part(int p, int x, int y, int t)
  356. #else
  357. inline int create_part(int p, int x, int y, int t)
  358. #endif
  359. {
  360. int i;
  361.  
  362. if(x<0 || y<0 || x>=XRES || y>=YRES)
  363. return -1;
  364.  
  365. if(t==SPC_HEAT||t==SPC_COOL)
  366. {
  367. if((pmap[y][x]&0xFF)!=PT_NONE&&(pmap[y][x]&0xFF)<PT_NUM)
  368. {
  369. if(t==SPC_HEAT&&parts[pmap[y][x]>>8].temp<MAX_TEMP)
  370. {
  371. parts[pmap[y][x]>>8].temp = restrict_flt(parts[pmap[y][x]>>8].temp + 4.0f, MIN_TEMP, MAX_TEMP);
  372. }
  373. if(t==SPC_COOL&&parts[pmap[y][x]>>8].temp>MIN_TEMP)
  374. {
  375. parts[pmap[y][x]>>8].temp = restrict_flt(parts[pmap[y][x]>>8].temp - 4.0f, MIN_TEMP, MAX_TEMP);
  376. }
  377. return pmap[y][x]>>8;
  378. }
  379. else
  380. {
  381. return -1;
  382. }
  383. }
  384. if(t==SPC_AIR)
  385. {
  386. pv[y/CELL][x/CELL] += 0.03f;
  387. if(y+CELL<YRES)
  388. pv[y/CELL+1][x/CELL] += 0.03f;
  389. if(x+CELL<XRES)
  390. {
  391. pv[y/CELL][x/CELL+1] += 0.03f;
  392. if(y+CELL<YRES)
  393. pv[y/CELL+1][x/CELL+1] += 0.03f;
  394. }
  395. return -1;
  396. }
  397. if(t==SPC_VACUUM)
  398. {
  399. pv[y/CELL][x/CELL] -= 0.03f;
  400. if(y+CELL<YRES)
  401. pv[y/CELL+1][x/CELL] -= 0.03f;
  402. if(x+CELL<XRES)
  403. {
  404. pv[y/CELL][x/CELL+1] -= 0.03f;
  405. if(y+CELL<YRES)
  406. pv[y/CELL+1][x/CELL+1] -= 0.03f;
  407. }
  408. return -1;
  409. }
  410.  
  411. if(t==PT_SPRK)
  412. {
  413. if((pmap[y][x]&0xFF)!=PT_METL &&
  414. (pmap[y][x]&0xFF)!=PT_PSCN &&
  415. (pmap[y][x]&0xFF)!=PT_NSCN &&
  416. (pmap[y][x]&0xFF)!=PT_NTCT &&
  417. (pmap[y][x]&0xFF)!=PT_PTCT &&
  418. (pmap[y][x]&0xFF)!=PT_WATR &&
  419. (pmap[y][x]&0xFF)!=PT_SLTW &&
  420. (pmap[y][x]&0xFF)!=PT_BMTL &&
  421. (pmap[y][x]&0xFF)!=PT_RBDM &&
  422. (pmap[y][x]&0xFF)!=PT_LRBD &&
  423. (pmap[y][x]&0xFF)!=PT_ETRD &&
  424. (pmap[y][x]&0xFF)!=PT_BRMT &&
  425. (pmap[y][x]&0xFF)!=PT_NBLE &&
  426. (pmap[y][x]&0xFF)!=PT_FRCM &&
  427. (pmap[y][x]&0xFF)!=PT_INWR &&
  428. (pmap[y][x]&0xFF)!=PT_IMTL)
  429. return -1;
  430. parts[pmap[y][x]>>8].type = PT_SPRK;
  431. parts[pmap[y][x]>>8].life = 4;
  432. parts[pmap[y][x]>>8].ctype = pmap[y][x]&0xFF;
  433. pmap[y][x] = (pmap[y][x]&~0xFF) | PT_SPRK;
  434. return pmap[y][x]>>8;
  435. }
  436.  
  437. if(p==-1)
  438. {
  439. if(pmap[y][x])
  440. return -1;
  441. if(pfree == -1)
  442. return -1;
  443. i = pfree;
  444. pfree = parts[i].life;
  445. }
  446. else
  447. i = p;
  448.  
  449. if(t==PT_GLAS)
  450. {
  451. parts[i].pavg[1] = pv[y/CELL][x/CELL];
  452. }
  453. if(t!=PT_STKM)
  454. {
  455. parts[i].x = (float)x;
  456. parts[i].y = (float)y;
  457. parts[i].type = t;
  458. parts[i].vx = 0;
  459. parts[i].vy = 0;
  460. parts[i].life = 0;
  461. parts[i].ctype = 0;
  462. parts[i].temp = ptypes[t].heat;
  463. parts[i].tmp = 0;
  464. }
  465. if(t==PT_ACID)
  466. {
  467. parts[i].life = 75;
  468. }
  469. /*Testing
  470. if(t==PT_WOOD){
  471. parts[i].life = 150;
  472. }
  473. End Testing*/
  474. if(t==PT_FUSE) {
  475. parts[i].life = 50;
  476. parts[i].tmp = 50;
  477. }
  478. if(t==PT_FSEP)
  479. parts[i].life = 50;
  480. if(t==PT_COAL) {
  481. parts[i].life = 110;
  482. parts[i].tmp = 50;
  483. }
  484. if(t==PT_BCOL)
  485. parts[i].life = 110;
  486. if(t==PT_FIRE)
  487. parts[i].life = rand()%50+120;
  488. if(t==PT_PLSM)
  489. parts[i].life = rand()%150+50;
  490. if(t==PT_HFLM)
  491. parts[i].life = rand()%150+50;
  492. if(t==PT_LAVA)
  493. parts[i].life = rand()%120+240;
  494. if(t==PT_NBLE)
  495. parts[i].life = 0;
  496. if(t==PT_ICEI)
  497. parts[i].ctype = PT_WATR;
  498. if(t==PT_NEUT)
  499. {
  500. float r = (rand()%128+128)/127.0f;
  501. float a = (rand()%360)*3.14159f/180.0f;
  502. parts[i].life = rand()%480+480;
  503. parts[i].vx = r*cosf(a);
  504. parts[i].vy = r*sinf(a);
  505. }
  506. if(t==PT_PHOT || t==PT_LASR )
  507. {
  508. float a = (rand()%8) * 0.78540f;
  509. parts[i].life = 680;
  510. parts[i].ctype = 0x3FFFFFFF;
  511. parts[i].vx = 4.0f*cosf(a);
  512. parts[i].vy = 4.0f*sinf(a);
  513. }
  514.  
  515. if(t!=PT_STKM && t!=PT_PHOT && t!=PT_NEUT)
  516. pmap[y][x] = t|(i<<8);
  517. else if(t==PT_STKM)
  518. {
  519. if(isplayer==0)
  520. {
  521. parts[i].x = (float)x;
  522. parts[i].y = (float)y;
  523. parts[i].type = PT_STKM;
  524. parts[i].vx = 0;
  525. parts[i].vy = 0;
  526. parts[i].life = 100;
  527. parts[i].ctype = 0;
  528. parts[i].temp = ptypes[t].heat;
  529.  
  530.  
  531.  
  532. player[3] = x-1; //Setting legs positions
  533. player[4] = y+6;
  534. player[5] = x-1;
  535. player[6] = y+6;
  536.  
  537. player[7] = x-3;
  538. player[8] = y+12;
  539. player[9] = x-3;
  540. player[10] = y+12;
  541.  
  542. player[11] = x+1;
  543. player[12] = y+6;
  544. player[13] = x+1;
  545. player[14] = y+6;
  546.  
  547. player[15] = x+3;
  548. player[16] = y+12;
  549. player[17] = x+3;
  550. player[18] = y+12;
  551.  
  552. isplayer = 1;
  553. }
  554. }
  555.  
  556. return i;
  557. }
  558.  
  559. static void create_gain_photon(int pp)
  560. {
  561. float xx, yy;
  562. int i, lr, temp_bin, nx, ny;
  563.  
  564. if(pfree == -1)
  565. return;
  566. i = pfree;
  567.  
  568. lr = rand() % 2;
  569.  
  570. if(lr) {
  571. xx = parts[pp].x - 0.3*parts[pp].vy;
  572. yy = parts[pp].y + 0.3*parts[pp].vx;
  573. } else {
  574. xx = parts[pp].x + 0.3*parts[pp].vy;
  575. yy = parts[pp].y - 0.3*parts[pp].vx;
  576. }
  577.  
  578. nx = (int)(xx + 0.5f);
  579. ny = (int)(yy + 0.5f);
  580.  
  581. if(nx<0 || ny<0 || nx>=XRES || ny>=YRES)
  582. return;
  583.  
  584. if((pmap[ny][nx] & 0xFF) != PT_GLOW)
  585. return;
  586.  
  587. pfree = parts[i].life;
  588.  
  589. parts[i].type = PT_PHOT;
  590. parts[i].life = 680;
  591. parts[i].x = xx;
  592. parts[i].y = yy;
  593. parts[i].vx = parts[pp].vx;
  594. parts[i].vy = parts[pp].vy;
  595. parts[i].temp = parts[pmap[ny][nx] >> 8].temp;
  596. parts[i].tmp = 0;
  597.  
  598. temp_bin = (int)((parts[i].temp-273.0f)*0.25f);
  599. if(temp_bin < 0) temp_bin = 0;
  600. if(temp_bin > 25) temp_bin = 25;
  601. parts[i].ctype = 0x1F << temp_bin;
  602. }
  603.  
  604. static void create_cherenkov_photon(int pp)
  605. {
  606. int i, lr, nx, ny;
  607. float r, eff_ior;
  608.  
  609. if(pfree == -1)
  610. return;
  611. i = pfree;
  612.  
  613. nx = (int)(parts[pp].x + 0.5f);
  614. ny = (int)(parts[pp].y + 0.5f);
  615. if((pmap[ny][nx] & 0xFF) != PT_GLAS)
  616. return;
  617.  
  618. if(hypotf(parts[pp].vx, parts[pp].vy) < 1.44f)
  619. return;
  620.  
  621. pfree = parts[i].life;
  622.  
  623. lr = rand() % 2;
  624.  
  625. parts[i].type = PT_PHOT;
  626. parts[i].ctype = 0x00000F80;
  627. parts[i].life = 680;
  628. parts[i].x = parts[pp].x;
  629. parts[i].y = parts[pp].y;
  630. parts[i].temp = parts[pmap[ny][nx] >> 8].temp;
  631. parts[i].tmp = 0;
  632.  
  633. if(lr) {
  634. parts[i].vx = parts[pp].vx - 2.5f*parts[pp].vy;
  635. parts[i].vy = parts[pp].vy + 2.5f*parts[pp].vx;
  636. } else {
  637. parts[i].vx = parts[pp].vx + 2.5f*parts[pp].vy;
  638. parts[i].vy = parts[pp].vy - 2.5f*parts[pp].vx;
  639. }
  640.  
  641. /* photons have speed of light. no discussion. */
  642. r = 1.269 / hypotf(parts[i].vx, parts[i].vy);
  643. parts[i].vx *= r;
  644. parts[i].vy *= r;
  645. }
  646.  
  647. #ifdef WIN32
  648. _inline void delete_part(int x, int y)
  649. #else
  650. inline void delete_part(int x, int y)
  651. #endif
  652. {
  653. unsigned i;
  654.  
  655. if(x<0 || y<0 || x>=XRES || y>=YRES)
  656. return;
  657. i = pmap[y][x];
  658. if(!i || (i>>8)>=NPART)
  659. return;
  660.  
  661. kill_part(i>>8);
  662. pmap[y][x] = 0; // just in case
  663. }
  664.  
  665. #ifdef WIN32
  666. _inline int is_wire(int x, int y)
  667. #else
  668. inline int is_wire(int x, int y)
  669. #endif
  670. {
  671. return bmap[y][x]==6 || bmap[y][x]==7 || bmap[y][x]==3 || bmap[y][x]==8 || bmap[y][x]==11 || bmap[y][x]==12;
  672. }
  673.  
  674. #ifdef WIN32
  675. _inline int is_wire_off(int x, int y)
  676. #else
  677. inline int is_wire_off(int x, int y)
  678. #endif
  679. {
  680. return (bmap[y][x]==6 || bmap[y][x]==7 || bmap[y][x]==3 || bmap[y][x]==8 || bmap[y][x]==11 || bmap[y][x]==12) && emap[y][x]<8;
  681. }
  682.  
  683. int get_wavelength_bin(int *wm)
  684. {
  685. int i, w0=30, wM=0;
  686.  
  687. if(!*wm)
  688. return -1;
  689.  
  690. for(i=0; i<30; i++)
  691. if(*wm & (1<<i)) {
  692. if(i < w0)
  693. w0 = i;
  694. if(i > wM)
  695. wM = i;
  696. }
  697.  
  698. if(wM-w0 < 5)
  699. return (wM+w0)/2;
  700.  
  701. i = rand() % (wM-w0-3);
  702. i += w0;
  703.  
  704. *wm &= 0x1F << i;
  705. return i + 2;
  706. }
  707.  
  708. void set_emap(int x, int y)
  709. {
  710. int x1, x2;
  711.  
  712. if(!is_wire_off(x, y))
  713. return;
  714.  
  715. // go left as far as possible
  716. x1 = x2 = x;
  717. while(x1>0)
  718. {
  719. if(!is_wire_off(x1-1, y))
  720. break;
  721. x1--;
  722. }
  723. while(x2<XRES/CELL-1)
  724. {
  725. if(!is_wire_off(x2+1, y))
  726. break;
  727. x2++;
  728. }
  729.  
  730. // fill span
  731. for(x=x1; x<=x2; x++)
  732. emap[y][x] = 16;
  733.  
  734. // fill children
  735.  
  736. if(y>1 && x1==x2 &&
  737. is_wire(x1-1, y-1) && is_wire(x1, y-1) && is_wire(x1+1, y-1) &&
  738. !is_wire(x1-1, y-2) && is_wire(x1, y-2) && !is_wire(x1+1, y-2))
  739. set_emap(x1, y-2);
  740. else if(y>0)
  741. for(x=x1; x<=x2; x++)
  742. if(is_wire_off(x, y-1))
  743. {
  744. if(x==x1 || x==x2 || y>=YRES/CELL-1 ||
  745. is_wire(x-1, y-1) || is_wire(x+1, y-1) ||
  746. is_wire(x-1, y+1) || !is_wire(x, y+1) || is_wire(x+1, y+1))
  747. set_emap(x, y-1);
  748. }
  749.  
  750. if(y<YRES/CELL-2 && x1==x2 &&
  751. is_wire(x1-1, y+1) && is_wire(x1, y+1) && is_wire(x1+1, y+1) &&
  752. !is_wire(x1-1, y+2) && is_wire(x1, y+2) && !is_wire(x1+1, y+2))
  753. set_emap(x1, y+2);
  754. else if(y<YRES/CELL-1)
  755. for(x=x1; x<=x2; x++)
  756. if(is_wire_off(x, y+1))
  757. {
  758. if(x==x1 || x==x2 || y<0 ||
  759. is_wire(x-1, y+1) || is_wire(x+1, y+1) ||
  760. is_wire(x-1, y-1) || !is_wire(x, y-1) || is_wire(x+1, y-1))
  761. set_emap(x, y+1);
  762. }
  763. }
  764.  
  765. #ifdef WIN32
  766. _inline int parts_avg(int ci, int ni)
  767. #else
  768. inline int parts_avg(int ci, int ni)
  769. #endif
  770. {
  771. int pmr = pmap[(int)((parts[ci].y + parts[ni].y)/2)][(int)((parts[ci].x + parts[ni].x)/2)];
  772. if((pmr>>8) < NPART && (pmr>>8) >= 1)
  773. {
  774. return parts[pmr>>8].type;
  775. }
  776. else
  777. {
  778. return PT_NONE;
  779. }
  780. }
  781.  
  782.  
  783. int nearest_part(int ci, int t)
  784. {
  785. int distance = sqrt(pow(XRES, 2)+pow(YRES, 2));
  786. int ndistance = 0;
  787. int id = -1;
  788. int i = 0;
  789. int cx = (int)parts[ci].x;
  790. int cy = (int)parts[ci].y;
  791. for(i=0; i<NPART; i++)
  792. {
  793. if(parts[i].type==t&&!parts[i].life&&i!=ci)
  794. {
  795. ndistance = abs((cx-parts[i].x)+(cy-parts[i].y));// Faster but less accurate Older: sqrt(pow(cx-parts[i].x, 2)+pow(cy-parts[i].y, 2));
  796. if(ndistance<distance)
  797. {
  798. distance = ndistance;
  799. id = i;
  800. }
  801. }
  802. }
  803. return id;
  804. }
  805.  
  806. void update_particles_i(pixel *vid, int start, int inc)
  807. {
  808. int i, j, x, y, t, nx, ny, r, a, s, lt, rt, fe, nt, lpv, nearp, pavg;
  809. uint16_t tempu1, tempu2;
  810. int16_t temps1, temps2;
  811. float tempf1, tempf2;
  812. float mv, dx, dy, ix, iy, lx, ly, d, pp, nrx, nry, dp;
  813. float nn, ct1, ct2;
  814. float pt = R_TEMP;
  815. float c_heat = 0.0f;
  816. int h_count = 0;
  817. int starti = (start*-1);
  818. for(i=start; i<(NPART-starti); i+=inc)
  819. if(parts[i].type)
  820. {
  821. //printf("parts[%d].type: %d\n", i, parts[i].type);
  822.  
  823. lx = parts[i].x;
  824. ly = parts[i].y;
  825. t = parts[i].type;
  826.  
  827. if(sys_pause&&!framerender)
  828. return;
  829.  
  830. if(parts[i].life && t!=PT_ACID && t!=PT_COAL && t!=PT_WOOD && t!=PT_NBLE && t!=PT_SWCH && t!=PT_STKM && t!=PT_FUSE && t!=PT_FSEP && t!=PT_BCOL)
  831. {
  832. if(!(parts[i].life==10&&(parts[i].type==PT_LCRY||parts[i].type==PT_PCLN||parts[i].type==PT_HSWC)))
  833. parts[i].life--;
  834. if(parts[i].life<=0 && t!=PT_METL && t!=PT_IMTL && t!=PT_FIRW && t!=PT_PCLN && t!=PT_HSWC && t!=PT_WATR && t!=PT_RBDM && t!=PT_LRBD && t!=PT_SLTW && t!=PT_BRMT && t!=PT_PSCN && t!=PT_NSCN && t!=PT_NTCT && t!=PT_PTCT && t!=PT_BMTL && t!=PT_SPRK && t!=PT_LAVA && t!=PT_ETRD&&t!=PT_LCRY && t!=PT_INWR && t!=PT_GLOW)
  835. {
  836. kill_part(i);
  837. continue;
  838. }
  839. if(parts[i].life<=0 && t==PT_SPRK)
  840. {
  841. t = parts[i].ctype;
  842. if(t!=PT_METL&&t!=PT_IMTL&&t!=PT_BMTL&&t!=PT_BRMT&&t!=PT_LRBD&&t!=PT_RBDM&&t!=PT_BTRY&&t!=PT_NBLE)
  843. parts[i].temp = R_TEMP + 273.15f;
  844. if(!t)
  845. t = PT_METL;
  846. parts[i].type = t;
  847. parts[i].life = 4;
  848. if(t == PT_WATR)
  849. parts[i].life = 64;
  850. if(t == PT_SLTW)
  851. parts[i].life = 54;
  852. }
  853. }
  854.  
  855. if(t==PT_SPRK&&parts[i].ctype==PT_SPRK)
  856. {
  857. kill_part(i);
  858. continue;
  859. }
  860.  
  861. x = (int)(parts[i].x+0.5f);
  862. y = (int)(parts[i].y+0.5f);
  863.  
  864.  
  865. if(x<0 || y<0 || x>=XRES || y>=YRES ||
  866. ((bmap[y/CELL][x/CELL]==1 ||
  867. bmap[y/CELL][x/CELL]==8 ||
  868. bmap[y/CELL][x/CELL]==9 ||
  869. (bmap[y/CELL][x/CELL]==2) ||
  870. (bmap[y/CELL][x/CELL]==3 && ptypes[t].falldown!=2) ||
  871. (bmap[y/CELL][x/CELL]==10 && ptypes[t].falldown!=1) ||
  872. (bmap[y/CELL][x/CELL]==13 && ptypes[t].falldown!=0 && parts[i].type!=PT_FIRE && parts[i].type!=PT_SMKE) ||
  873. (bmap[y/CELL][x/CELL]==6 && (t==PT_METL || t==PT_SPRK)) ||
  874. (bmap[y/CELL][x/CELL]==7 && !emap[y/CELL][x/CELL])) && (t!=PT_STKM)))
  875. {
  876. kill_part(i);
  877. continue;
  878. }
  879.  
  880. vx[y/CELL][x/CELL] *= ptypes[t].airloss;
  881. vy[y/CELL][x/CELL] *= ptypes[t].airloss;
  882. vx[y/CELL][x/CELL] += ptypes[t].airdrag*parts[i].vx;
  883. vy[y/CELL][x/CELL] += ptypes[t].airdrag*parts[i].vy;
  884. if(t==PT_GAS||t==PT_NBLE)
  885. {
  886. if(pv[y/CELL][x/CELL]<3.5f)
  887. pv[y/CELL][x/CELL] += ptypes[t].hotair*(3.5f-pv[y/CELL][x/CELL]);
  888. if(y+CELL<YRES && pv[y/CELL+1][x/CELL]<3.5f)
  889. pv[y/CELL+1][x/CELL] += ptypes[t].hotair*(3.5f-pv[y/CELL+1][x/CELL]);
  890. if(x+CELL<XRES)
  891. {
  892. pv[y/CELL][x/CELL+1] += ptypes[t].hotair*(3.5f-pv[y/CELL][x/CELL+1]);
  893. if(y+CELL<YRES)
  894. pv[y/CELL+1][x/CELL+1] += ptypes[t].hotair*(3.5f-pv[y/CELL+1][x/CELL+1]);
  895. }
  896. }
  897. else
  898. {
  899. pv[y/CELL][x/CELL] += ptypes[t].hotair;
  900. if(y+CELL<YRES)
  901. pv[y/CELL+1][x/CELL] += ptypes[t].hotair;
  902. if(x+CELL<XRES)
  903. {
  904. pv[y/CELL][x/CELL+1] += ptypes[t].hotair;
  905. if(y+CELL<YRES)
  906. pv[y/CELL+1][x/CELL+1] += ptypes[t].hotair;
  907. }
  908. }
  909.  
  910. if((ptypes[t].explosive&2) && pv[y/CELL][x/CELL]>2.5f)
  911. {
  912. parts[i].life = rand()%80+180;
  913. rt = parts[i].type = PT_FIRE;
  914. parts[i].temp = ptypes[PT_FIRE].heat + (ptypes[rt].flammable/2);
  915. pv[y/CELL][x/CELL] += 0.25f * CFDS;
  916. t = PT_FIRE;
  917. }
  918.  
  919. parts[i].vx *= ptypes[t].loss;
  920. parts[i].vy *= ptypes[t].loss;
  921.  
  922. if(t==PT_GOO && !parts[i].life)
  923. {
  924. if(pv[y/CELL][x/CELL]>1.0f)
  925. {
  926. parts[i].vx += ptypes[t].advection*vx[y/CELL][x/CELL];
  927. parts[i].vy += ptypes[t].advection*vy[y/CELL][x/CELL];
  928. parts[i].life = rand()%80+300;
  929. }
  930. }
  931. else
  932. {
  933. parts[i].vx += ptypes[t].advection*vx[y/CELL][x/CELL];
  934. parts[i].vy += ptypes[t].advection*vy[y/CELL][x/CELL] + ptypes[t].gravity;
  935. }
  936.  
  937. if(ptypes[t].diffusion)
  938. {
  939. parts[i].vx += ptypes[t].diffusion*(rand()/(0.5f*RAND_MAX)-1.0f);
  940. parts[i].vy += ptypes[t].diffusion*(rand()/(0.5f*RAND_MAX)-1.0f);
  941. }
  942.  
  943. // interpolator
  944. #ifdef WIN32
  945. mv = max(fabsf(parts[i].vx), fabsf(parts[i].vy));
  946. #else
  947. mv = fmaxf(fabsf(parts[i].vx), fabsf(parts[i].vy));
  948. #endif
  949. if(mv < ISTP)
  950. {
  951. parts[i].x += parts[i].vx;
  952. parts[i].y += parts[i].vy;
  953. ix = parts[i].x;
  954. iy = parts[i].y;
  955. }
  956. else
  957. {
  958. dx = parts[i].vx*ISTP/mv;
  959. dy = parts[i].vy*ISTP/mv;
  960. ix = parts[i].x;
  961. iy = parts[i].y;
  962. while(1)
  963. {
  964. mv -= ISTP;
  965. if(mv <= 0.0f)
  966. {
  967. // nothing found
  968. parts[i].x += parts[i].vx;
  969. parts[i].y += parts[i].vy;
  970. ix = parts[i].x;
  971. iy = parts[i].y;
  972. break;
  973. }
  974. ix += dx;
  975. iy += dy;
  976. nx = (int)(ix+0.5f);
  977. ny = (int)(iy+0.5f);
  978. if(nx<0 || ny<0 || nx>=XRES || ny>=YRES || pmap[ny][nx] || (bmap[ny/CELL][nx/CELL] && bmap[ny/CELL][nx/CELL]!=5))
  979. {
  980. parts[i].x = ix;
  981. parts[i].y = iy;
  982. break;
  983. }
  984. }
  985. }
  986.  
  987. a = nt = 0;
  988. for(nx=-1; nx<2; nx++)
  989. for(ny=-1; ny<2; ny++)
  990. if(x+nx>=0 && y+ny>0 &&
  991. x+nx<XRES && y+ny<YRES &&
  992. (!bmap[(y+ny)/CELL][(x+nx)/CELL] || bmap[(y+ny)/CELL][(x+nx)/CELL]==5))
  993. {
  994. if(!pmap[y+ny][x+nx])
  995. a = 1;
  996. if((pmap[y+ny][x+nx]&0xFF)!=t)
  997. nt = 1;
  998. }
  999. if(legacy_enable)
  1000. {
  1001. if(t==PT_WTRV && pv[y/CELL][x/CELL]>4.0f)
  1002. t = parts[i].type = PT_DSTW;
  1003. if(t==PT_OIL && pv[y/CELL][x/CELL]<-6.0f)
  1004. t = parts[i].type = PT_GAS;
  1005. if(t==PT_GAS && pv[y/CELL][x/CELL]>6.0f)
  1006. t = parts[i].type = PT_OIL;
  1007. if(t==PT_DESL && pv[y/CELL][x/CELL]>12.0f)
  1008. t = parts[i].type = PT_FIRE;
  1009. }
  1010. if(t==PT_GAS && pv[y/CELL][x/CELL]<-6.0f)
  1011. t = parts[i].type = PT_OIL;
  1012. if(t==PT_DESL && pv[y/CELL][x/CELL]>5.0f) // Only way I know to make it
  1013. t = parts[i].type = PT_FIRE; // combust under pressure.
  1014. if(t==PT_GAS && pv[y/CELL][x/CELL]>6.0f)
  1015. t = parts[i].type = PT_OIL;
  1016. if(t==PT_BMTL && pv[y/CELL][x/CELL]>2.5f)
  1017. t = parts[i].type = PT_BRMT;
  1018. if(t==PT_BRCK && pv[y/CELL][x/CELL]>2.8f)
  1019. t = parts[i].type = PT_STNE;
  1020. if(t==PT_WOOD && pv[y/CELL][x/CELL]>2.0f)
  1021. t = parts[i].type = PT_COAL;
  1022. //if(t==PT_GLAS && pv[y/CELL][x/CELL]>4.0f)
  1023. // t = parts[i].type = PT_BGLA;
  1024. if(t==PT_GLAS)
  1025. {
  1026. parts[i].pavg[0] = parts[i].pavg[1];
  1027. parts[i].pavg[1] = pv[y/CELL][x/CELL];
  1028. if(parts[i].pavg[1]-parts[i].pavg[0] > 0.05f || parts[i].pavg[1]-parts[i].pavg[0] < -0.05f)
  1029. {
  1030. parts[i].type = PT_BGLA;
  1031. }
  1032. }
  1033. if(t==PT_ICEI && pv[y/CELL][x/CELL]>0.8f)
  1034. t = parts[i].type = PT_SNOW;
  1035. if(t==PT_PLUT && 1>rand()%100 && ((int)(5.0f*pv[y/CELL][x/CELL]))>(rand()%1000))
  1036. {
  1037. t = PT_NEUT;
  1038. create_part(i, x, y, t);
  1039. }
  1040. if(t==PT_SPRK&&parts[i].ctype==PT_ETRD&&parts[i].life==1)
  1041. {
  1042. nearp = nearest_part(i, PT_ETRD);
  1043. if(nearp!=-1&&parts_avg(i, nearp)!=PT_INSL)
  1044. {
  1045. create_line((int)parts[i].x, (int)parts[i].y, (int)parts[nearp].x, (int)parts[nearp].y, 0, PT_PLSM);
  1046. t = parts[i].type = PT_ETRD;
  1047. parts[i].ctype = PT_NONE;
  1048. parts[i].life = 20;
  1049. parts[nearp].type = PT_SPRK;
  1050. parts[nearp].life = 9;
  1051. parts[nearp].ctype = PT_ETRD;
  1052. }
  1053. }
  1054.  
  1055. if(!legacy_enable)
  1056. {
  1057. int ctemp = pv[y/CELL][x/CELL]*2;
  1058. c_heat = 0.0f;
  1059. h_count = 0;
  1060. if(t==PT_ICEI && !parts[i].ctype)
  1061. parts[i].ctype = PT_WATR;
  1062. if(ptypes[t].hconduct>(rand()%250)&&!(parts[i].type==PT_HSWC&&parts[i].life!=10))
  1063. {
  1064. for(nx=-1; nx<2; nx++)
  1065. {
  1066. for(ny=-1; ny<2; ny++)
  1067. {
  1068. if(x+nx>=0 && y+ny>0 && x+nx<XRES && y+ny<YRES && (nx || ny))
  1069. {
  1070. r = pmap[y+ny][x+nx];
  1071. if((r>>8)>=NPART || !r)
  1072. continue;
  1073. if(parts[r>>8].type!=PT_NONE&&parts[i].type!=PT_NONE&&ptypes[parts[r>>8].type].hconduct>0&&!(parts[r>>8].type==PT_HSWC&&parts[r>>8].life!=10))
  1074. {
  1075. h_count++;
  1076. c_heat += parts[r>>8].temp;
  1077. }
  1078. }
  1079. }
  1080. }
  1081. pt = parts[i].temp = (c_heat+parts[i].temp)/(h_count+1);
  1082. for(nx=-1; nx<2; nx++)
  1083. {
  1084. for(ny=-1; ny<2; ny++)
  1085. {
  1086. if(x+nx>=0 && y+ny>0 && x+nx<XRES && y+ny<YRES && (nx || ny))
  1087. {
  1088. r = pmap[y+ny][x+nx];
  1089. if((r>>8)>=NPART || !r)
  1090. continue;
  1091. if(parts[r>>8].type!=PT_NONE&&parts[i].type!=PT_NONE&&ptypes[parts[r>>8].type].hconduct>0&&!(parts[r>>8].type==PT_HSWC&&parts[r>>8].life!=10))
  1092. {
  1093. parts[r>>8].temp = parts[i].temp;
  1094. }
  1095. }
  1096. }
  1097. }
  1098. if(pt>=pstates[t].btemp&&pstates[t].burn)
  1099. {
  1100. t = parts[i].type = pstates[t].burn;
  1101. if(t==PT_FIRE||t==PT_PLSM)
  1102. parts[i].life = rand()%50+120;
  1103. }
  1104. else if((pt<=pstates[t].stemp||(t==PT_LAVA&&(pt<=pstates[parts[i].ctype].ltemp)))&&pstates[t].solid)
  1105. {
  1106. if(t==PT_LAVA&&parts[i].ctype)
  1107. {
  1108. parts[i].life = 0;
  1109. if(parts[i].ctype==PT_THRM)
  1110. {
  1111. parts[i].tmp = 0;
  1112. parts[i].ctype = PT_BMTL;
  1113. }
  1114. t = parts[i].type = parts[i].ctype;
  1115. parts[i].ctype = PT_NONE;
  1116. }
  1117. else if(pstates[t].solid==PT_ICEI&&pt<=pstates[t].stemp)
  1118. {
  1119. parts[i].ctype = parts[i].type;
  1120. t = parts[i].type = PT_ICEI;
  1121. }
  1122. else
  1123. {
  1124. parts[i].life = 0;
  1125. t = parts[i].type = pstates[t].solid;
  1126. }
  1127. }
  1128. else if((pt>=pstates[t].ltemp&&(pt<=pstates[t].gtemp||!pstates[t].gas)&&pstates[t].state==ST_SOLID&&pstates[t].liquid)||(t==PT_ICEI&&pt>pstates[parts[i].ctype].stemp))
  1129. {
  1130. if(pstates[t].liquid==PT_LAVA)
  1131. {
  1132. parts[i].life = rand()%120+240;
  1133. parts[i].ctype = (parts[i].type==PT_BRMT)?PT_BMTL:parts[i].type;
  1134. parts[i].ctype = (parts[i].ctype==PT_SAND)?PT_GLAS:parts[i].ctype;
  1135. parts[i].ctype = (parts[i].ctype==PT_BGLA)?PT_GLAS:parts[i].ctype;
  1136. t = parts[i].type = pstates[t].liquid;
  1137. }
  1138. else if(t==PT_ICEI&&parts[i].ctype)
  1139. {
  1140. t = parts[i].type = parts[i].ctype;
  1141. parts[i].ctype = PT_NONE;
  1142. }
  1143. else
  1144. {
  1145. t = parts[i].type = pstates[t].liquid;
  1146. }
  1147. }
  1148. else if(pt-ctemp<=pstates[t].ltemp&&pstates[t].liquid&&pstates[t].state==ST_GAS)
  1149. {
  1150. t = parts[i].type = pstates[t].liquid;
  1151. }
  1152. else if(pt-ctemp>=pstates[t].gtemp&&(pstates[t].gas||parts[i].type==PT_LNTG)&&(pstates[t].state==ST_LIQUID||pstates[t].state==ST_SOLID))
  1153. {
  1154. if(t==PT_SLTW&&1>rand()%6)
  1155. {
  1156. t = parts[i].type = PT_SALT;
  1157. }
  1158. else
  1159. {
  1160. t = parts[i].type = pstates[t].gas;
  1161. pv[y/CELL][x/CELL] += 0.50f;
  1162. if(t==PT_FIRE)
  1163. parts[i].life = rand()%50+120;
  1164. if(t==PT_HFLM)
  1165. parts[i].life = rand()%50+120;
  1166. }
  1167. }
  1168. if(t==PT_URAN && pv[y/CELL][x/CELL]>0.0f)
  1169. {
  1170. float atemp = parts[i].temp + (-MIN_TEMP);
  1171. pt = parts[i].temp = (atemp*(1+(pv[y/CELL][x/CELL]/2000)))+MIN_TEMP;
  1172. }
  1173. if(t==PT_LAVA)
  1174. {
  1175. parts[i].life = restrict_flt((pt-700)/7, 0.0f, 400.0f);
  1176. if(parts[i].ctype==PT_THRM&&parts[i].tmp>0)
  1177. {
  1178. parts[i].tmp--;
  1179. parts[i].temp = 3500;
  1180. }
  1181. }
  1182. pt = parts[i].temp = restrict_flt(parts[i].temp, MIN_TEMP, MAX_TEMP);
  1183. }
  1184. }
  1185. if(t==PT_PTCT&&parts[i].temp>295.0f)
  1186. {
  1187. pt = parts[i].temp -= 2.5f;
  1188. }
  1189. if(t==PT_NTCT&&parts[i].temp>295.0f)
  1190. {
  1191. pt = parts[i].temp -= 2.5f;
  1192. }
  1193. if(t==PT_O2 && !(parts[i].tmp))
  1194. {
  1195. for(nx=-2;nx<3;nx++)
  1196. for(ny=-2;ny<3;ny++)
  1197. {
  1198. if(x+nx>=0 && y+ny>0 && x+nx<XRES && y+ny<YRES && (nx || ny))
  1199. {
  1200. r=pmap[y+ny][x+nx];
  1201. if ((r&0xFF)==PT_H2 && !(parts[i].tmp))
  1202. {
  1203. parts[i].type=PT_WATR;
  1204. parts[r>>8].type=PT_WATR;
  1205. }
  1206. }
  1207. }
  1208. }
  1209.  
  1210. if(t==PT_WATR || t==PT_ETRD || t==PT_SLTW || t==PT_METL || t==PT_IMTL || t==PT_RBDM || t==PT_LRBD || t==PT_BRMT || t==PT_PSCN || t==PT_NSCN || t==PT_NTCT || t==PT_PTCT || t==PT_BMTL || t==PT_SPRK|| t == PT_NBLE || t==PT_INWR)
  1211. {
  1212. nx = x % CELL;
  1213. if(nx == 0)
  1214. nx = x/CELL - 1;
  1215. else if(nx == CELL-1)
  1216. nx = x/CELL + 1;
  1217. else
  1218. nx = x/CELL;
  1219. ny = y % CELL;
  1220. if(ny == 0)
  1221. ny = y/CELL - 1;
  1222. else if(ny == CELL-1)
  1223. ny = y/CELL + 1;
  1224. else
  1225. ny = y/CELL;
  1226. if(nx>=0 && ny>=0 && nx<XRES/CELL && ny<YRES/CELL)
  1227. {
  1228. if(t==PT_WATR || t==PT_ETRD || t==PT_SLTW || t==PT_METL || t==PT_IMTL || t==PT_RBDM || t==PT_LRBD || t==PT_NSCN || t==PT_NTCT || t==PT_PTCT || t==PT_PSCN || t==PT_BRMT || t==PT_BMTL||t==PT_NBLE || t==PT_INWR)
  1229. {
  1230. if(emap[ny][nx]==12 && !parts[i].life)
  1231. {
  1232. parts[i].type = PT_SPRK;
  1233. parts[i].life = 4;
  1234. parts[i].ctype = t;
  1235. t = PT_SPRK;
  1236. }
  1237. }
  1238. else if(bmap[ny][nx]==6 || bmap[ny][nx]==7 || bmap[ny][nx]==3 || bmap[ny][nx]==8 || bmap[ny][nx]==11 || bmap[ny][nx]==12)
  1239. set_emap(nx, ny);
  1240. }
  1241. }
  1242.  
  1243. nx = x/CELL;
  1244. ny = y/CELL;
  1245. if(bmap[ny][nx]==6 && emap[ny][nx]<8)
  1246. set_emap(nx, ny);
  1247.  
  1248. fe = 0;
  1249. if(t==PT_THDR)
  1250. {
  1251. for(nx=-2; nx<3; nx++)
  1252. for(ny=-2; ny<3; ny++)
  1253. if(x+nx>=0 && y+ny>0 &&
  1254. x+nx<XRES && y+ny<YRES && (nx || ny))
  1255. {
  1256. r = pmap[y+ny][x+nx];
  1257. if((r>>8)>=NPART || !r)
  1258. continue;
  1259. if(((r&0xFF)==PT_METL || (r&0xFF)==PT_ETRD || (r&0xFF)==PT_IMTL || (r&0xFF)==PT_PSCN || (r&0xFF)==PT_NSCN || (r&0xFF)==PT_NTCT || (r&0xFF)==PT_PTCT || (r&0xFF)==PT_BMTL || (r&0xFF)==PT_RBDM || (r&0xFF)==PT_LRBD || (r&0xFF)==PT_BRMT||(r&0xFF)==PT_NBLE) || (r&0xFF)==PT_INWR && parts[r>>8].ctype!=PT_SPRK)
  1260.  
  1261. {
  1262. t = parts[i].type = PT_NONE;
  1263. parts[r>>8].ctype = parts[r>>8].type;
  1264. parts[r>>8].type = PT_SPRK;
  1265. parts[r>>8].life = 4;
  1266. }
  1267. else if((r&0xFF)!=PT_CLNE&&(r&0xFF)!=PT_THDR&&(r&0xFF)!=PT_SPRK&&(r&0xFF)!=PT_DMND&&(r&0xFF)!=PT_FIRE&&(r&0xFF)!=PT_NEUT&&(r&0xFF)!=PT_PHOT&&(r&0xFF))
  1268. {
  1269. pv[y/CELL][x/CELL] += 251.0f;
  1270. if(legacy_enable&&1>(rand()%200))
  1271. {
  1272. parts[i].life = rand()%50+120;
  1273. t = parts[i].type = PT_FIRE;
  1274. }
  1275. else
  1276. {
  1277. t = parts[i].type = PT_NONE;
  1278. }
  1279. }
  1280.  
  1281. if((r&0xFF)==PT_SPRT){
  1282. parts[i].type = PT_PLSM;
  1283. parts[r>>8].type = PT_PLSM;
  1284. }
  1285. }
  1286. }
  1287. if(t==PT_SPRT)
  1288. {
  1289. for(nx=-2; nx<3; nx++)
  1290. for(ny=-2; ny<3; ny++)
  1291. if(x+nx>=0 && y+ny>0 &&
  1292. x+nx<XRES && y+ny<YRES && (nx || ny))
  1293. {
  1294. r = pmap[y+ny][x+nx];
  1295. if((r>>8)>=NPART || !r)
  1296. continue;
  1297. if((r&0xFF)!=PT_CLNE&&(r&0xFF)!=PT_THDR&&(r&0xFF)!=PT_SPRK&&(r&0xFF)!=PT_DMND&&(r&0xFF)!=PT_FIRE&&(r&0xFF)!=PT_NEUT&&(r&0xFF)!=PT_PHOT&&(r&0xFF))
  1298. {
  1299. pv[y/CELL][x/CELL] += 0.1f;
  1300. if(legacy_enable&&1>(rand()%200))
  1301. {
  1302. parts[i].life = rand()%50+120;
  1303. t = parts[i].type = PT_FIRE;
  1304. }
  1305. else
  1306. {
  1307. t = parts[i].type = PT_SPRT;
  1308. }
  1309. }
  1310. }
  1311. }
  1312. else if (t==PT_ROBN)
  1313. {
  1314. if(parts[i].temp>1273.15f){
  1315. parts[i].type = PT_NEUT;
  1316. }
  1317. }
  1318. else if (t==PT_HETR){
  1319. for(nx=-1; nx<2; nx++)
  1320. for(ny=-1; ny<2; ny++)
  1321. if(x+nx>=0 && y+ny>0 && x+nx<XRES && y+ny<YRES &&
  1322. pmap[y+ny][x+nx] &&
  1323. (pmap[y+ny][x+nx]&0xFF)!=PT_HETR&&
  1324. (pmap[y+ny][x+nx]&0xFF)!=0xFF)
  1325. {
  1326. r = pmap[y+ny][x+nx];
  1327. if(parts[r>>8].temp+ (parts[r>>8].temp*0.2f)<=MAX_TEMP)
  1328. {parts[r>>8].temp += parts[r>>8].temp*0.2f;}
  1329. else {parts[r>>8].temp = 3500;}
  1330. }
  1331. }
  1332. else if(t==PT_ICEI || t==PT_SNOW)
  1333. {
  1334. for(nx=-2; nx<3; nx++)
  1335. for(ny=-2; ny<3; ny++)
  1336. if(x+nx>=0 && y+ny>0 &&
  1337. x+nx<XRES && y+ny<YRES && (nx || ny))
  1338. {
  1339. r = pmap[y+ny][x+nx];
  1340. if((r>>8)>=NPART || !r)
  1341. continue;
  1342. if(((r&0xFF)==PT_SALT || (r&0xFF)==PT_SLTW) && 1>(rand()%1000))
  1343. {
  1344. t = parts[i].type = PT_SLTW;
  1345. parts[r>>8].type = PT_SLTW;
  1346. }
  1347. if(legacy_enable)
  1348. {
  1349. if(((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW) && 1>(rand()%1000))
  1350. {
  1351. t = parts[i].type = PT_ICEI;
  1352. parts[r>>8].type = PT_ICEI;
  1353. }
  1354. if(t==PT_SNOW && ((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW) && 15>(rand()%1000))
  1355. t = parts[i].type = PT_WATR;
  1356. }
  1357. }
  1358. }
  1359. else if(t==PT_COAL)
  1360. {
  1361. if(parts[i].life<=0) {
  1362. t = PT_NONE;
  1363. kill_part(i);
  1364. create_part(-1, x, y, PT_COAL);
  1365. goto killed;
  1366. } else if(parts[i].life < 100) {
  1367. parts[i].life--;
  1368. create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_NONE);
  1369. }
  1370. if((pv[y/CELL][x/CELL] > 4.3f)&&parts[i].tmp>40)
  1371. parts[i].tmp=39;
  1372. else if(parts[i].tmp<40&&parts[i].tmp>0)
  1373. parts[i].tmp--;
  1374. else if(parts[i].tmp<=0) {
  1375. t = PT_NONE;
  1376. kill_part(i);
  1377. r = create_part(-1, x, y, PT_BCOL);
  1378. goto killed;
  1379. }
  1380. for(nx=-2; nx<3; nx++)
  1381. for(ny=-2; ny<3; ny++)
  1382. if(x+nx>=0 && y+ny>0 &&
  1383. x+nx<XRES && y+ny<YRES && (nx || ny))
  1384. {
  1385. r = pmap[y+ny][x+nx];
  1386. if((r>>8)>=NPART || !r)
  1387. continue;
  1388. if(((r&0xFF)==PT_COAL || (r&0xFF)==PT_PLSM) && 1>(rand()%500))
  1389. {
  1390. if(parts[i].life>100) {
  1391. parts[i].life = 99;
  1392. }
  1393. }
  1394. }
  1395. }
  1396. else if(t==PT_BCOL)
  1397. {
  1398. if(parts[i].life<=0) {
  1399. t = PT_NONE;
  1400. kill_part(i);
  1401. create_part(-1, x, y, PT_FIRE);
  1402. goto killed;
  1403. } else if(parts[i].life < 100) {
  1404. parts[i].life--;
  1405. create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_FIRE);
  1406. }
  1407.  
  1408. for(nx=-2; nx<3; nx++)
  1409. for(ny=-2; ny<3; ny++)
  1410. if(x+nx>=0 && y+ny>0 &&
  1411. x+nx<XRES && y+ny<YRES && (nx || ny))
  1412. {
  1413. r = pmap[y+ny][x+nx];
  1414. if((r>>8)>=NPART || !r)
  1415. continue;
  1416. if(((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM) && 1>(rand()%500))
  1417. {
  1418. if(parts[i].life>100) {
  1419. parts[i].life = 99;
  1420. }
  1421. }
  1422. }
  1423. }
  1424. else if(t==PT_FUSE)
  1425. {
  1426. if(parts[i].life<=0) {
  1427. t = PT_NONE;
  1428. kill_part(i);
  1429. r = create_part(-1, x, y, PT_PLSM);
  1430. parts[r].life = 50;
  1431. goto killed;
  1432. } else if (parts[i].life < 40) {
  1433. parts[i].life--;
  1434. if((rand()%100)==0) {
  1435. r = create_part(-1, (nx=x+rand()%3-1), (ny=y+rand()%3-1), PT_PLSM);
  1436. parts[r].life = 50;
  1437. }
  1438. }
  1439. if((pv[y/CELL][x/CELL] > 2.7f)&&parts[i].tmp>40)
  1440. parts[i].tmp=39;
  1441. else if(parts[i].tmp<40&&parts[i].tmp>0)
  1442. parts[i].tmp--;
  1443. else if(parts[i].tmp<=0) {
  1444. t = PT_NONE;
  1445. kill_part(i);
  1446. r = create_part(-1, x, y, PT_FSEP);
  1447. goto killed;
  1448. }
  1449. for(nx=-2; nx<3; nx++)
  1450. for(ny=-2; ny<3; ny++)
  1451. if(x+nx>=0 && y+ny>0 &&
  1452. x+nx<XRES && y+ny<YRES && (nx || ny))
  1453. {
  1454. r = pmap[y+ny][x+nx];
  1455. if((r>>8)>=NPART || !r)
  1456. continue;
  1457. if((r&0xFF)==PT_SPRK || ((parts[i].temp>=(273.15+700.0f)) && 1>(rand()%20)))
  1458. {
  1459. if(parts[i].life>40) {
  1460. parts[i].life = 39;
  1461. }
  1462. }
  1463. }
  1464. }
  1465. else if(t==PT_FSEP)
  1466. {
  1467. if(parts[i].life<=0) {
  1468. t = PT_NONE;
  1469. kill_part(i);
  1470. r = create_part(-1, x, y, PT_PLSM);
  1471. parts[r].life = 50;
  1472. goto killed;
  1473. } else if (parts[i].life < 40) {
  1474. parts[i].life--;
  1475. if((rand()%10)==0) {
  1476. r = create_part(-1, (nx=x+rand()%3-1), (ny=y+rand()%3-1), PT_PLSM);
  1477. parts[r].life = 50;
  1478. }
  1479. }
  1480. for(nx=-2; nx<3; nx++)
  1481. for(ny=-2; ny<3; ny++)
  1482. if(x+nx>=0 && y+ny>0 &&
  1483. x+nx<XRES && y+ny<YRES && (nx || ny))
  1484. {
  1485. r = pmap[y+ny][x+nx];
  1486. if((r>>8)>=NPART || !r)
  1487. continue;
  1488. if((r&0xFF)==PT_SPRK || (parts[i].temp>=(273.15+400.0f)) && 1>(rand()%15))
  1489. {
  1490. if(parts[i].life>40) {
  1491. parts[i].life = 39;
  1492. }
  1493. }
  1494. }
  1495. }
  1496. else if(t==PT_NTCT||t==PT_PTCT||t==PT_INWR)
  1497. {
  1498. for(nx=-2; nx<3; nx++)
  1499. for(ny=-2; ny<3; ny++)
  1500. if(x+nx>=0 && y+ny>0 &&
  1501. x+nx<XRES && y+ny<YRES && (nx || ny))
  1502. {
  1503. r = pmap[y+ny][x+nx];
  1504. if((r>>8)>=NPART || !r)
  1505. continue;
  1506. if((r&0xFF)==PT_SPRK && parts[r>>8].ctype==PT_METL && parts_avg(i, r>>8)!=PT_INSL)
  1507. {
  1508. parts[i].temp = 473.0f;
  1509. }
  1510. }
  1511. }
  1512. else if(t==PT_PLNT)
  1513. {
  1514. for(nx=-2; nx<3; nx++)
  1515. for(ny=-2; ny<3; ny++)
  1516. if(x+nx>=0 && y+ny>0 &&
  1517. x+nx<XRES && y+ny<YRES && (nx || ny))
  1518. {
  1519. r = pmap[y+ny][x+nx];
  1520. if((r>>8)>=NPART || !r)
  1521. continue;
  1522. if((r&0xFF)==PT_WATR && 1>(rand()%250))
  1523. {
  1524. t = parts[i].type = PT_PLNT;
  1525. parts[r>>8].type = PT_PLNT;
  1526. }
  1527. else if((r&0xFF)==PT_LAVA && 1>(rand()%250))
  1528. {
  1529. parts[i].life = 4;
  1530. t = parts[i].type = PT_FIRE;
  1531. }
  1532. //if(t==PT_SNOW && (r&0xFF)==PT_WATR && 15>(rand()%1000))
  1533. //t = parts[i].type = PT_WATR;
  1534. }
  1535. }
  1536. else if(t==PT_THRM)
  1537. {
  1538. for(nx=-2; nx<3; nx++)
  1539. for(ny=-2; ny<3; ny++)
  1540. if(x+nx>=0 && y+ny>0 && x+nx<XRES && y+ny<YRES && (nx || ny))
  1541. {
  1542. r = pmap[y+ny][x+nx];
  1543. if((r>>8)>=NPART || !r)
  1544. continue;
  1545. if(((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM || (r&0xFF)==PT_LAVA))
  1546. {
  1547. if(1>(rand()%500)) {
  1548. t = parts[i].type = PT_LAVA;
  1549. parts[i].ctype = PT_BMTL;
  1550. pt = parts[i].temp = 3500.0f;
  1551. pv[y/CELL][x/CELL] += 50.0f;
  1552. } else {
  1553. t = parts[i].type = PT_LAVA;
  1554. parts[i].life = 400;
  1555. parts[i].ctype = PT_THRM;
  1556. pt = parts[i].temp = 3500.0f;
  1557. parts[i].tmp = 20;
  1558. }
  1559. }
  1560. //if(t==PT_SNOW && (r&0xFF)==PT_WATR && 15>(rand()%1000))
  1561. //t = parts[i].type = PT_WATR;
  1562. }
  1563. }
  1564. else if(t==PT_WATR||t==PT_DSTW)
  1565. {
  1566. for(nx=-2; nx<3; nx++)
  1567. for(ny=-2; ny<3; ny++)
  1568. if(x+nx>=0 && y+ny>0 &&
  1569. x+nx<XRES && y+ny<YRES && (nx || ny))
  1570. {
  1571. r = pmap[y+ny][x+nx];
  1572. if((r>>8)>=NPART || !r)
  1573. continue;
  1574. if(((r&0xFF)==PT_FIRE || (r&0xFF)==PT_LAVA) && 1>(rand()%10) && legacy_enable)
  1575. {
  1576. t = parts[i].type = PT_WTRV;
  1577. }
  1578. else if((r&0xFF)==PT_SALT && 1>(rand()%250))
  1579. {
  1580. t = parts[i].type = PT_SLTW;
  1581. parts[r>>8].type = PT_SLTW;
  1582. }
  1583. if((((r&0xFF)==PT_WATR||(r&0xFF)==PT_SLTW)&&t==PT_DSTW) && 1>(rand()%500))
  1584. {
  1585. t = parts[i].type = PT_WATR;
  1586. }
  1587. if(((r&0xFF)==PT_SLTW&&t==PT_DSTW) && 1>(rand()%500))
  1588. {
  1589. t = parts[i].type = PT_SLTW;
  1590. }
  1591. if(((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD||(r&0xFF)==PT_FRCM) && (legacy_enable||pt>12.0f) && 1>(rand()%500))
  1592. {
  1593. parts[i].life = 4;
  1594. t = parts[i].type = PT_FIRE;
  1595.  
  1596. }
  1597. }
  1598. }
  1599. else if(t==PT_SLTW)
  1600. {
  1601. for(nx=-2; nx<3; nx++)
  1602. for(ny=-2; ny<3; ny++)
  1603. if(x+nx>=0 && y+ny>0 &&
  1604. x+nx<XRES && y+ny<YRES && (nx || ny))
  1605. {
  1606. r = pmap[y+ny][x+nx];
  1607. if((r>>8)>=NPART || !r)
  1608. continue;
  1609. if(((r&0xFF)==PT_FIRE || (r&0xFF)==PT_LAVA) && 1>(rand()%10) && legacy_enable)
  1610. {
  1611. t = parts[i].type = PT_SALT;
  1612. parts[r>>8].type = PT_WTRV;
  1613. }
  1614. else if((r&0xFF)==PT_SALT && 1>(rand()%10000))
  1615. {
  1616. parts[r>>8].type = PT_SLTW;
  1617. }
  1618. if(((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD||(r&0xFF)==PT_FRCM) && pt>12.0f && 1>(rand()%500))
  1619. {
  1620. parts[i].life = 4;
  1621. t = parts[i].type = PT_FIRE;
  1622.  
  1623. }
  1624. }
  1625. }
  1626. else if(t==PT_WTRV)
  1627. {
  1628. for(nx=-2; nx<3; nx++)
  1629. for(ny=-2; ny<3; ny++)
  1630. if(x+nx>=0 && y+ny>0 &&
  1631. x+nx<XRES && y+ny<YRES && (nx || ny))
  1632. {
  1633. r = pmap[y+ny][x+nx];
  1634. if((r>>8)>=NPART || !r)
  1635. continue;
  1636. if(((r&0xFF)==PT_WATR||(r&0xFF)==PT_DSTW||(r&0xFF)==PT_SLTW) && 1>(rand()%1000) && legacy_enable)
  1637. {
  1638. t = parts[i].type = PT_WATR;
  1639. parts[r>>8].type = PT_WATR;
  1640. }
  1641.  
  1642. if(((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD||(r&0xFF)==PT_FRCM) && pt>12.0f && 1>(rand()%500))
  1643. {
  1644. parts[i].life = 4;
  1645. t = parts[i].type = PT_FIRE;
  1646.  
  1647. }
  1648. if(((r&0xFF)==PT_ICEI || (r&0xFF)==PT_SNOW) && 1>(rand()%1000) && legacy_enable)
  1649. {
  1650. t = parts[i].type = PT_WATR;
  1651. if(1>(rand()%1000))
  1652. parts[r>>8].type = PT_WATR;
  1653. }
  1654. }
  1655. }
  1656. else if(t==PT_YEST)
  1657. {
  1658. for(nx=-2; nx<3; nx++)
  1659. for(ny=-2; ny<3; ny++)
  1660. if(x+nx>=0 && y+ny>0 &&
  1661. x+nx<XRES && y+ny<YRES && (nx || ny))
  1662. {
  1663. r = pmap[y+ny][x+nx];
  1664. if((r>>8)>=NPART || !r)
  1665. continue;
  1666. if((r&0xFF)==PT_DYST && 1>(rand()%30) && !legacy_enable)
  1667. {
  1668. t = parts[i].type = PT_DYST;
  1669. }
  1670. }
  1671. }
  1672. else if(t==PT_ACID)
  1673. {
  1674. for(nx=-2; nx<3; nx++)
  1675. for(ny=-2; ny<3; ny++)
  1676. if(x+nx>=0 && y+ny>0 && x+nx<XRES && y+ny<YRES && (nx || ny))
  1677. {
  1678. r = pmap[y+ny][x+nx];
  1679. if((r>>8)>=NPART || !r)
  1680. continue;
  1681. if((r&0xFF)!=PT_ACID)
  1682. {
  1683. if ((r&0xFF)==PT_PLEX || (r&0xFF)==PT_NITR || (r&0xFF)==PT_GUNP || (r&0xFF)==PT_RBDM || (r&0xFF)==PT_LRBD)
  1684. {
  1685. t = parts[i].type = PT_FIRE;
  1686. parts[i].life = 4;
  1687. parts[r>>8].type = PT_FIRE;
  1688. parts[r>>8].life = 4;
  1689. }
  1690. else if(((r&0xFF)!=PT_CLNE && ptypes[parts[r>>8].type].hardness>(rand()%1000))&&parts[i].life>=50)
  1691. {
  1692. parts[i].life--;
  1693. parts[r>>8].type = PT_NONE;
  1694. }
  1695. else if (parts[i].life==50)
  1696. {
  1697. parts[i].life = 0;
  1698. t = parts[i].type = PT_NONE;
  1699. }
  1700. }
  1701. }
  1702. }
  1703. else if(t==PT_NEUT)
  1704. {
  1705. rt = 3 + (int)pv[y/CELL][x/CELL];
  1706. for(nx=-1; nx<2; nx++)
  1707. for(ny=-1; ny<2; ny++)
  1708. if(x+nx>=0 && y+ny>0 &&
  1709. x+nx<XRES && y+ny<YRES && (nx || ny))
  1710. {
  1711. r = pmap[y+ny][x+nx];
  1712. if((r>>8)>=NPART || !r)
  1713. continue;
  1714. if((r&0xFF)==PT_WATR || (r&0xFF)==PT_ICEI || (r&0xFF)==PT_SNOW)
  1715. {
  1716. parts[i].vx *= 0.995;
  1717. parts[i].vy *= 0.995;
  1718. }
  1719. if((r&0xFF)==PT_PLUT && rt>(rand()%1000))
  1720. {
  1721. if(33>rand()%100)
  1722. {
  1723. create_part(r>>8, x+nx, y+ny, rand()%2 ? PT_LAVA : PT_URAN);
  1724. }
  1725. else
  1726. {
  1727. create_part(r>>8, x+nx, y+ny, PT_NEUT);
  1728. parts[r>>8].vx = 0.25f*parts[r>>8].vx + parts[i].vx;
  1729. parts[r>>8].vy = 0.25f*parts[r>>8].vy + parts[i].vy;
  1730. }
  1731. pv[y/CELL][x/CELL] += 200.0f * CFDS; //Used to be 2, some people said nukes weren't powerful enough
  1732. fe ++;
  1733. }
  1734. if((r&0xFF)==PT_GUNP && 15>(rand()%1000))
  1735. parts[r>>8].type = PT_DUST;
  1736. if((r&0xFF)==PT_DYST && 15>(rand()%1000))
  1737. parts[r>>8].type = PT_YEST;
  1738. if((r&0xFF)==PT_YEST) {
  1739. if(15>(rand()%100000)&&isplayer==0)
  1740. parts[r>>8].type = PT_STKM;
  1741. else
  1742. parts[r>>8].type = PT_DYST;
  1743. }
  1744.  
  1745. if((r&0xFF)==PT_WATR && 15>(rand()%100))
  1746. parts[r>>8].type = PT_DSTW;
  1747. if((r&0xFF)==PT_PLEX && 15>(rand()%1000))
  1748. parts[r>>8].type = PT_GOO;
  1749. if((r&0xFF)==PT_NITR && 15>(rand()%1000))
  1750. parts[r>>8].type = PT_DESL;
  1751. if((r&0xFF)==PT_PLNT && 5>(rand()%100))
  1752. parts[r>>8].type = PT_WOOD;
  1753. if((r&0xFF)==PT_DESL && 15>(rand()%1000))
  1754. parts[r>>8].type = PT_GAS;
  1755. if((r&0xFF)==PT_COAL && 5>(rand()%100))
  1756. parts[r>>8].type = PT_WOOD;
  1757. /*if(parts[r>>8].type>1 && parts[r>>8].type!=PT_NEUT && parts[r>>8].type-1!=PT_NEUT && parts[r>>8].type-1!=PT_STKM &&
  1758. (ptypes[parts[r>>8].type-1].menusection==SC_LIQUID||
  1759. ptypes[parts[r>>8].type-1].menusection==SC_EXPLOSIVE||
  1760. ptypes[parts[r>>8].type-1].menusection==SC_GAS||
  1761. ptypes[parts[r>>8].type-1].menusection==SC_POWDERS) && 15>(rand()%1000))
  1762. parts[r>>8].type--;*/
  1763. }
  1764. }
  1765. else if(t==PT_PHOT)
  1766. {
  1767. rt = 3 + (int)pv[y/CELL][x/CELL];
  1768. for(nx=0; nx<1; nx++)
  1769. for(ny=0; ny<1; ny++)
  1770. if(x+nx>=0 && y+ny>0 &&
  1771. x+nx<XRES && y+ny<YRES && (nx || ny))
  1772. {
  1773. r = pmap[y+ny][x+nx];
  1774. if((r>>8)>=NPART || !r)
  1775. continue;
  1776. if((r&0xFF)==PT_WATR || (r&0xFF)==PT_ICEI || (r&0xFF)==PT_SNOW)
  1777. {
  1778. parts[i].vx *= 0.995;
  1779. parts[i].vy *= 0.995;
  1780. }
  1781. }
  1782. }
  1783. else if(t==PT_LASR)
  1784. {
  1785. rt = 3 + (int)pv[y/CELL][x/CELL];
  1786. for(nx=0; nx<1; nx++)
  1787. for(ny=0; ny<1; ny++)
  1788. if(x+nx>=0 && y+ny>0 &&
  1789. x+nx<XRES && y+ny<YRES && (nx || ny))
  1790. {
  1791. r = pmap[y+ny][x+nx];
  1792. if((r>>8)>=NPART || !r)
  1793. continue;
  1794. if((r&0xFF)==PT_WATR || (r&0xFF)==PT_ICEI || (r&0xFF)==PT_SNOW)
  1795. {
  1796. parts[i].vx *= 0.995;
  1797. parts[i].vy *= 0.995;
  1798. }
  1799. }
  1800. }
  1801. else if(t==PT_LCRY)
  1802. {
  1803. for(nx=-1; nx<2; nx++)
  1804. for(ny=-1; ny<2; ny++)
  1805. if(x+nx>=0 && y+ny>0 &&
  1806. x+nx<XRES && y+ny<YRES && (nx || ny))
  1807. {
  1808. r = pmap[y+ny][x+nx];
  1809. if((r>>8)>=NPART || !r)
  1810. continue;
  1811. rt = parts[r>>8].type;
  1812. if(rt==PT_SPRK)
  1813. {
  1814. if(parts[r>>8].ctype==PT_PSCN)
  1815. {
  1816. parts[i].life = 10;
  1817. }
  1818. else if(parts[r>>8].ctype==PT_NSCN)
  1819. {
  1820. parts[i].life = 9;
  1821. }
  1822. }
  1823. if(rt==PT_LCRY)
  1824. {
  1825. if(parts[i].life==10&&parts[r>>8].life<10&&parts[r>>8].life>0)
  1826. {
  1827. parts[i].life = 9;
  1828. }
  1829. else if(parts[i].life==0&&parts[r>>8].life==10)
  1830. {
  1831. parts[i].life = 10;
  1832. }
  1833. }
  1834. }
  1835. }
  1836. else if(t==PT_PCLN)
  1837. {
  1838. for(nx=-2; nx<3; nx++)
  1839. for(ny=-2; ny<3; ny++)
  1840. if(x+nx>=0 && y+ny>0 &&
  1841. x+nx<XRES && y+ny<YRES && (nx || ny))
  1842. {
  1843. r = pmap[y+ny][x+nx];
  1844. if((r>>8)>=NPART || !r)
  1845. continue;
  1846. rt = parts[r>>8].type;
  1847. if(rt==PT_SPRK)
  1848. {
  1849. if(parts[r>>8].ctype==PT_PSCN)
  1850. {
  1851. parts[i].life = 10;
  1852. }
  1853. else if(parts[r>>8].ctype==PT_NSCN)
  1854. {
  1855. parts[i].life = 9;
  1856. }
  1857. }
  1858. if(rt==PT_PCLN)
  1859. {
  1860. if(parts[i].life==10&&parts[r>>8].life<10&&parts[r>>8].life>0)
  1861. {
  1862. parts[i].life = 9;
  1863. }
  1864. else if(parts[i].life==0&&parts[r>>8].life==10)
  1865. {
  1866. parts[i].life = 10;
  1867. }
  1868. }
  1869. }
  1870. }
  1871. else if(t==PT_HSWC)
  1872. {
  1873. for(nx=-2; nx<3; nx++)
  1874. for(ny=-2; ny<3; ny++)
  1875. if(x+nx>=0 && y+ny>0 &&
  1876. x+nx<XRES && y+ny<YRES && (nx || ny))
  1877. {
  1878. r = pmap[y+ny][x+nx];
  1879. if((r>>8)>=NPART || !r)
  1880. continue;
  1881. rt = parts[r>>8].type;
  1882. if(rt==PT_SPRK)
  1883. {
  1884. if(parts[r>>8].ctype==PT_PSCN)
  1885. {
  1886. parts[i].life = 10;
  1887. }
  1888. else if(parts[r>>8].ctype==PT_NSCN)
  1889. {
  1890. parts[i].life = 9;
  1891. }
  1892. }
  1893. if(rt==PT_HSWC)
  1894. {
  1895. if(parts[i].life==10&&parts[r>>8].life<10&&parts[r>>8].life>0)
  1896. {
  1897. parts[i].life = 9;
  1898. }
  1899. else if(parts[i].life==0&&parts[r>>8].life==10)
  1900. {
  1901. parts[i].life = 10;
  1902. }
  1903. }
  1904. }
  1905. }
  1906. else if(t==PT_AMTR)
  1907. {
  1908. for(nx=-1; nx<2; nx++)
  1909. for(ny=-1; ny<2; ny++)
  1910. if(x+nx>=0 && y+ny>0 &&
  1911. x+nx<XRES && y+ny<YRES && (nx || ny))
  1912. {
  1913. r = pmap[y+ny][x+nx];
  1914. if((r>>8)>=NPART || !r)
  1915. continue;
  1916. rt = parts[r>>8].type;
  1917. if((r&0xFF)!=PT_AMTR && (r&0xFF)!=PT_DMND && (r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && (r&0xFF)!=PT_NONE && (r&0xFF)!=PT_PHOT && (r&0xFF)!=PT_VOID && (r&0xFF)!=PT_BHOL && (r&0xFF)!=PT_LASR)
  1918. {
  1919. t = parts[i].life++;
  1920. if(parts[i].life==3)
  1921. {
  1922. parts[i].type = PT_NONE;
  1923. kill_part(i);
  1924. }
  1925. parts[r>>8].life = 0;
  1926. parts[r>>8].type = PT_NONE;
  1927. kill_part(r>>8);
  1928. if(2>(rand()/(RAND_MAX/100)))
  1929. create_part(r>>8, x+nx, y+ny, PT_PHOT);
  1930. pv[y/CELL][x/CELL] -= 5.0f;
  1931. continue;
  1932. }
  1933. }
  1934. }
  1935. else if(t==PT_SEED)
  1936. {
  1937. for(nx=-2; nx<3; nx++)
  1938. for(ny=-2; ny<3; ny++)
  1939. if(x+nx>=0 && y+ny>0 &&
  1940. x+nx<XRES && y+ny<YRES && (nx || ny))
  1941. {
  1942. r = pmap[y+ny][x+nx];
  1943. if((r>>8)>=NPART || !r)
  1944. continue;
  1945. if((r&0xFF)==PT_WATR)
  1946. {
  1947. t = parts[i].type = PT_PLNT;
  1948. }
  1949. }
  1950. }
  1951. else if(t==PT_SEED)
  1952. {
  1953. for(nx=-2; nx<3; nx++)
  1954. for(ny=-2; ny<3; ny++)
  1955. if(x+nx>=0 && y+ny>0 &&
  1956. x+nx<XRES && y+ny<YRES && (nx || ny))
  1957. {
  1958. r = pmap[y+ny][x+nx];
  1959. if((r>>8)>=NPART || !r)
  1960. continue;
  1961. if((r&0xFF)==PT_PLNT)
  1962. {
  1963. t = parts[i].type = PT_PLNT;
  1964. }
  1965. if((r&0xFF)==PT_FIRE)
  1966. {
  1967. parts[r].type = PT_NONE;
  1968. }
  1969. }
  1970. }
  1971. else if(t==PT_CHOC || t==PT_MCHC)
  1972. {
  1973. for(nx=-2; nx<3; nx++)
  1974. for(ny=-2; ny<3; ny++)
  1975. if(x+nx>=0 && y+ny>0 &&
  1976. x+nx<XRES && y+ny<YRES && (nx || ny))
  1977. {
  1978. r = pmap[y+ny][x+nx];
  1979. if((r>>8)>=NPART || !r)
  1980. continue;
  1981. if((r&0xFF)==PT_STKM)
  1982. {
  1983. t = parts[i].type = PT_NONE;
  1984. }
  1985. }
  1986. }
  1987. else if(t==PT_FIRW) {
  1988. if(parts[i].tmp==0) {
  1989. for(nx=-1; nx<2; nx++)
  1990. for(ny=-1; ny<2; ny++)
  1991. if(x+nx>=0 && y+ny>0 &&
  1992. x+nx<XRES && y+ny<YRES && (nx || ny))
  1993. {
  1994. r = pmap[y+ny][x+nx];
  1995. if((r>>8)>=NPART || !r)
  1996. continue;
  1997. rt = parts[r>>8].type;
  1998. if(rt==PT_FIRE||rt==PT_PLSM||rt==PT_THDR)
  1999. {
  2000. parts[i].tmp = 1;
  2001. parts[i].life = rand()%50+60;
  2002. }
  2003. }
  2004. }
  2005.  
  2006. else if(parts[i].tmp==1) {
  2007. if(parts[i].life==0) {
  2008. parts[i].tmp=2;
  2009. } else {
  2010. float newVel = parts[i].life/25;
  2011. parts[i].flags = parts[i].flags&0xFFFFFFFE;
  2012. if((pmap[(int)(ly-newVel)][(int)lx]&0xFF)==PT_NONE) {
  2013. parts[i].vy = -newVel;
  2014. ly-=newVel;
  2015. iy-=newVel;
  2016. }
  2017. }
  2018. }
  2019. else if(parts[i].tmp==2) {
  2020. int col = rand()%200+4;
  2021. for(nx=-2; nx<3; nx++) {
  2022. for(ny=-2; ny<3; ny++) {
  2023. if(x+nx>=0 && y+ny>0 && x+nx<XRES && y+ny<YRES && (nx || ny))
  2024. {
  2025. int tmul = rand()%7;
  2026. create_part(-1, x+nx, y+ny, PT_FIRW);
  2027. r = pmap[y+ny][x+nx];
  2028. if((r>>8)>=NPART || !r)
  2029. continue;
  2030. if(parts[r>>8].type==PT_FIRW) {
  2031. parts[r>>8].vx = (rand()%3-1)*tmul;
  2032. parts[r>>8].vy = (rand()%3-1)*tmul;
  2033. parts[r>>8].tmp = col;
  2034. parts[r>>8].life = rand()%100+100;
  2035. parts[r>>8].temp = 6000.0f;
  2036. }
  2037. }
  2038. }
  2039. }
  2040. pv[y/CELL][x/CELL] += 20;
  2041. kill_part(i);
  2042. } else if(parts[i].tmp>=3) {
  2043. if(parts[i].life<=0) {
  2044. kill_part(i);
  2045. }
  2046. }
  2047. }
  2048. else if(t==PT_BTRY)
  2049. {
  2050. rt = 3 + (int)pv[y/CELL][x/CELL];
  2051. for(nx=-2; nx<3; nx++)
  2052. for(ny=-2; ny<3; ny++)
  2053. if(x+nx>=0 && y+ny>0 &&
  2054. x+nx<XRES && y+ny<YRES && (nx || ny))
  2055. {
  2056. r = pmap[y+ny][x+nx];
  2057. if((r>>8)>=NPART || !r)
  2058. continue;
  2059. rt = parts[r>>8].type;
  2060. if(parts_avg(i,r>>8) != PT_INSL)
  2061. {
  2062. if((rt==PT_METL||rt==PT_IMTL||rt==PT_ETRD||rt==PT_BMTL||rt==PT_BRMT||rt==PT_LRBD||rt==PT_RBDM||rt==PT_PSCN||rt==PT_NSCN||rt==PT_NBLE)&&parts[r>>8].life==0 && abs(nx)+abs(ny) < 4)
  2063. {
  2064. parts[r>>8].life = 4;
  2065. parts[r>>8].ctype = rt;
  2066. parts[r>>8].type = PT_SPRK;
  2067. }
  2068. }
  2069. }
  2070. }
  2071. else if(t==PT_IBTR)
  2072. {
  2073. rt = 3 + (int)pv[y/CELL][x/CELL];
  2074. for(nx=-2; nx<3; nx++)
  2075. for(ny=-2; ny<3; ny++)
  2076. if(x+nx>=0 && y+ny>0 &&
  2077. x+nx<XRES && y+ny<YRES && (nx || ny))
  2078. {
  2079. r = pmap[y+ny][x+nx];
  2080. if((r>>8)>=NPART || !r)
  2081. continue;
  2082. rt = parts[r>>8].type;
  2083. if(parts_avg(i,r>>8) != PT_INSL)
  2084. {
  2085. if((rt==PT_METL||rt==PT_IMTL||rt==PT_ETRD||rt==PT_BMTL||rt==PT_BRMT||rt==PT_LRBD||rt==PT_RBDM||rt==PT_PSCN||rt==PT_NSCN||rt==PT_NBLE)&&parts[r>>8].life==0 && abs(nx)+abs(ny) < 4)
  2086. {
  2087. parts[r>>8].life = 4;
  2088. parts[r>>8].ctype = rt;
  2089. parts[r>>8].type = PT_SPRK;
  2090. }
  2091. }
  2092. }
  2093. }
  2094. else if(t==PT_FRCM)
  2095. {
  2096. for(nx=-2; nx<3; nx++)
  2097. for(ny=-2; ny<3; ny++)
  2098. if(x+nx>=0 && y+ny>0 &&
  2099. x+nx<XRES && y+ny<YRES && (nx || ny))
  2100. {
  2101. r = pmap[y+ny][x+nx];
  2102. if((r>>8)>=NPART || !r)
  2103. continue;
  2104. if((r&0xFF)==PT_WATR || (r&0xFF)==PT_SLTW || (r&0xFF)==PT_DSTW)
  2105. {
  2106. if(1>(rand()%70)){
  2107. t = parts[i].type = PT_THDR;
  2108. }else{
  2109. t = parts[i].type = PT_FIRE;
  2110. }
  2111. }
  2112. }
  2113. }
  2114. else if(t==PT_CDOX)
  2115. {
  2116. for(nx=-2; nx<3; nx++)
  2117. for(ny=-2; ny<3; ny++)
  2118. if(x+nx>=0 && y+ny>0 &&
  2119. x+nx<XRES && y+ny<YRES && (nx || ny))
  2120. {
  2121. r = pmap[y+ny][x+nx];
  2122. if((r>>8)>=NPART || !r)
  2123. continue;
  2124. if((r&0xFF)==PT_PLNT)
  2125. {
  2126. if(1>(rand()%30))
  2127. {
  2128. t = parts[i].type = PT_PLNT;
  2129. } else {
  2130. if(1>(rand()%30)){
  2131. t = parts[i].type = PT_O2;
  2132. }
  2133. }
  2134. }
  2135. }
  2136. }
  2137. else if(t==PT_CSTF)
  2138. {
  2139. for(nx=-1; nx<2; nx++)
  2140. for(ny=-1; ny<2; ny++)
  2141. if(x+nx>=0 && y+ny>0 && x+nx<XRES && y+ny<YRES &&
  2142. pmap[y+ny][x+nx] &&
  2143. (pmap[y+ny][x+nx]&0xFF)!=PT_CSTF&&
  2144. (pmap[y+ny][x+nx]&0xFF)!=0xFF)
  2145. {
  2146. r = pmap[y+ny][x+nx];
  2147. if(parts[r>>8].temp!=0.0f){parts[r>>8].temp = 0.0f;}
  2148. if(parts[i].temp!=0.0f){parts[i].temp = 0.0f;}
  2149. }
  2150. }
  2151. else if(t==PT_SWCH)
  2152. {
  2153. rt = 3 + (int)pv[y/CELL][x/CELL];
  2154. for(nx=-2; nx<3; nx++)
  2155. for(ny=-2; ny<3; ny++)
  2156. if(x+nx>=0 && y+ny>0 &&
  2157. x+nx<XRES && y+ny<YRES && (nx || ny))
  2158. {
  2159. r = pmap[y+ny][x+nx];
  2160. if((r>>8)>=NPART || !r)
  2161. continue;
  2162. rt = parts[r>>8].type;
  2163. if(parts[r>>8].type == PT_SWCH&&parts_avg(i,r>>8)!=PT_INSL)
  2164. {
  2165. if(parts[i].life==10&&parts[r>>8].life<10&&parts[r>>8].life>0)
  2166. {
  2167. parts[i].life = 9;
  2168. }
  2169. else if(parts[i].life==0&&parts[r>>8].life==10)
  2170. {
  2171. parts[i].life = 10;
  2172. }
  2173. }
  2174. }
  2175. }
  2176. if(t==PT_SWCH){
  2177. if((parts[i].life>0&&parts[i].life<10)|| parts[i].life == 11)
  2178. {
  2179. parts[i].life--;
  2180. }
  2181. }
  2182.  
  2183. if(t==PT_JKSN){
  2184. r = pmap[y+ny][x+nx];
  2185. if((r&0xFF)!=PT_BHOL&&(r&0xFF)!=PT_WHOL&&(r&0xFF)!=PT_DMND&&(r&0xFF)!=PT_IMTL&&(r&0xFF)!=PT_IBTR&&(r&0xFF)!=PT_MOVS&&(r&0xFF)!=PT_CLNE&&(r&0xFF)!=PT_VOID&&(r&0xFF)!=PT_CSTF&&(r&0xFF)!=PT_HETR&&(r&0xFF)!=PT_INSL&&(r&0xFF)!=PT_NONE&&(r&0xFF)!=PT_JKSN){
  2186. r = pmap[y+ny][x+nx];
  2187. parts[r>>8].type = PT_FIRE;
  2188. }
  2189. }
  2190. if(t==PT_FIRE || t==PT_PLSM || t==PT_LAVA || t==PT_SPRK || fe || t==PT_LASR || (t==PT_PHOT&&(1>rand()%10)))
  2191. {
  2192. for(nx=-2; nx<3; nx++)
  2193. for(ny=-2; ny<3; ny++)
  2194. if(x+nx>=0 && y+ny>0 &&
  2195. x+nx<XRES && y+ny<YRES && (nx || ny))
  2196. {
  2197. r = pmap[y+ny][x+nx];
  2198. if((r>>8)>=NPART || !r)
  2199. continue;
  2200. if(bmap[(y+ny)/CELL][(x+nx)/CELL] && bmap[(y+ny)/CELL][(x+nx)/CELL]!=5)
  2201. continue;
  2202. rt = parts[r>>8].type;
  2203. if((a || ptypes[rt].explosive) && ((rt!=PT_RBDM && rt!=PT_LRBD && rt!=PT_INSL && rt!=PT_SWCH) || t!=PT_SPRK) &&
  2204. (t!=PT_LAVA || parts[i].life>0 || (rt!=PT_STNE && rt!=PT_PSCN && rt!=PT_NSCN && rt!=PT_NTCT && rt!=PT_PTCT && rt!=PT_METL && rt!=PT_IMTL && rt!=PT_ETRD && rt!=PT_BMTL && rt!=PT_BRMT && rt!=PT_SWCH && rt!=PT_INWR)) &&
  2205. ptypes[rt].flammable && (ptypes[rt].flammable + (int)(pv[(y+ny)/CELL][(x+nx)/CELL]*10.0f))>(rand()%1000))
  2206. {
  2207. parts[r>>8].type = PT_FIRE;
  2208. parts[r>>8].temp = ptypes[PT_FIRE].heat + (ptypes[rt].flammable/2);
  2209. parts[r>>8].life = rand()%80+180;
  2210. if(ptypes[rt].explosive)
  2211. pv[y/CELL][x/CELL] += 0.25f * CFDS;
  2212. continue;
  2213. }
  2214. lpv = (int)pv[(y+ny)/CELL][(x+nx)/CELL];
  2215. if(lpv < 1) lpv = 1;
  2216. if(legacy_enable)
  2217. {
  2218. if(t!=PT_SPRK && ptypes[rt].meltable && ((rt!=PT_RBDM && rt!=PT_LRBD) || t!=PT_SPRK) && ((t!=PT_FIRE&&t!=PT_PLSM) || (rt!=PT_METL && rt!=PT_IMTL && rt!=PT_ETRD && rt!=PT_PSCN && rt!=PT_NSCN && rt!=PT_NTCT && rt!=PT_PTCT && rt!=PT_BMTL && rt!=PT_BRMT && rt!=PT_SALT && rt!=PT_INWR)) &&
  2219. ptypes[rt].meltable*lpv>(rand()%1000))
  2220. {
  2221. if(t!=PT_LAVA || parts[i].life>0)
  2222. {
  2223. parts[r>>8].ctype = (parts[r>>8].type==PT_BRMT)?PT_BMTL:parts[r>>8].type;
  2224. parts[r>>8].ctype = (parts[r>>8].ctype==PT_SAND)?PT_GLAS:parts[r>>8].ctype;
  2225. parts[r>>8].type = PT_LAVA;
  2226. parts[r>>8].life = rand()%120+240;
  2227. }
  2228. else
  2229. {
  2230. parts[i].life = 0;
  2231. t = parts[i].type = (parts[i].ctype)?parts[i].ctype:PT_STNE;
  2232. parts[i].ctype = PT_NONE;//rt;
  2233. goto killed;
  2234. }
  2235. }
  2236. if(t!=PT_SPRK && (rt==PT_ICEI || rt==PT_SNOW))
  2237. {
  2238. parts[r>>8].type = PT_WATR;
  2239. if(t==PT_FIRE)
  2240. {
  2241. parts[i].x = lx;
  2242. parts[i].y = ly;
  2243. kill_part(i);
  2244. goto killed;
  2245. }
  2246. if(t==PT_LAVA)
  2247. {
  2248. parts[i].life = 0;
  2249. t = parts[i].type = PT_STNE;
  2250. goto killed;
  2251. }
  2252. }
  2253. if(t!=PT_SPRK && (rt==PT_WATR || rt==PT_DSTW || rt==PT_SLTW))
  2254. {
  2255. kill_part(r>>8);
  2256. if(t==PT_FIRE)
  2257. {
  2258. parts[i].x = lx;
  2259. parts[i].y = ly;
  2260. kill_part(i);
  2261. goto killed;
  2262. }
  2263. if(t==PT_LAVA)
  2264. {
  2265. parts[i].life = 0;
  2266. t = parts[i].type = (parts[i].ctype)?parts[i].ctype:PT_STNE;
  2267. parts[i].ctype = PT_NONE;
  2268. goto killed;
  2269. }
  2270. }
  2271. }
  2272. pavg = parts_avg(i, r>>8);
  2273. if(rt==PT_SWCH && t==PT_SPRK)
  2274. {
  2275. pavg = parts_avg(r>>8, i);
  2276. if(parts[i].ctype == PT_PSCN&&pavg != PT_INSL)
  2277. parts[r>>8].life = 10;
  2278. if(parts[i].ctype == PT_NSCN&&pavg != PT_INSL)
  2279. parts[r>>8].life = 9;
  2280. if(!(parts[i].ctype == PT_PSCN||parts[i].ctype == PT_NSCN)&&parts[r>>8].life == 10&&pavg != PT_INSL)
  2281. {
  2282. parts[r>>8].type = PT_SPRK;
  2283. parts[r>>8].ctype = PT_SWCH;
  2284. parts[r>>8].life = 4;
  2285. }
  2286. }
  2287. pavg = parts_avg(i, r>>8);
  2288. if(pavg != PT_INSL)
  2289. {
  2290. if(t==PT_SPRK && (rt==PT_METL||rt==PT_IMTL||rt==PT_ETRD||rt==PT_BMTL||rt==PT_BRMT||rt==PT_LRBD||rt==PT_RBDM||rt==PT_PSCN||rt==PT_NSCN||rt==PT_NBLE) && parts[r>>8].life==0 &&
  2291. (parts[i].life<3 || ((r>>8)<i && parts[i].life<4)) && abs(nx)+abs(ny)<4)
  2292. {
  2293. if(!(rt==PT_PSCN&&parts[i].ctype==PT_NSCN)&&!(rt!=PT_PSCN&&!(rt==PT_NSCN&&parts[i].temp>=373.0f)&&parts[i].ctype==PT_NTCT)&&!(rt!=PT_PSCN&&!(rt==PT_NSCN&&parts[i].temp<=373.0f)&&parts[i].ctype==PT_PTCT)&&!(rt!=PT_PSCN&&!(rt==PT_NSCN)&&parts[i].ctype==PT_INWR) && pavg != PT_INSL &&!(parts[i].ctype==PT_SWCH&&(rt==PT_PSCN||rt==PT_NSCN)) )
  2294. {
  2295. parts[r>>8].type = PT_SPRK;
  2296. parts[r>>8].life = 4;
  2297. parts[r>>8].ctype = rt;
  2298. if(parts[r>>8].temp+10.0f<673.0f&&!legacy_enable&&!(rt==PT_LRBD||rt==PT_RBDM||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR))
  2299. parts[r>>8].temp = parts[r>>8].temp+10.0f;
  2300. }
  2301. }
  2302. if(t==PT_SPRK && rt==PT_NTCT && parts[r>>8].life==0 &&
  2303. (parts[i].life<3 || ((r>>8)<i && parts[i].life<4)) && abs(nx)+abs(ny)<4)
  2304. {
  2305. if((parts[i].ctype==PT_NSCN||parts[i].ctype==PT_NTCT||(parts[i].ctype==PT_PSCN&&parts[r>>8].temp>373.0f))&&pavg != PT_INSL)
  2306. {
  2307. parts[r>>8].type = PT_SPRK;
  2308. parts[r>>8].life = 4;
  2309. parts[r>>8].ctype = rt;
  2310. }
  2311. }
  2312. if(t==PT_SPRK && rt==PT_PTCT && parts[r>>8].life==0 &&
  2313. (parts[i].life<3 || ((r>>8)<i && parts[i].life<4)) && abs(nx)+abs(ny)<4)
  2314. {
  2315. if((parts[i].ctype==PT_NSCN||parts[i].ctype==PT_PTCT||(parts[i].ctype==PT_PSCN&&parts[r>>8].temp<373.0f))&&pavg != PT_INSL)
  2316. {
  2317. parts[r>>8].type = PT_SPRK;
  2318. parts[r>>8].life = 4;
  2319. parts[r>>8].ctype = rt;
  2320. }
  2321. }
  2322. if(t==PT_SPRK && rt==PT_INWR && parts[r>>8].life==0 &&
  2323. (parts[i].life<3 || ((r>>8)<i && parts[i].life<4)) && abs(nx)+abs(ny)<4)
  2324. {
  2325. if((parts[i].ctype==PT_NSCN||parts[i].ctype==PT_INWR||parts[i].ctype==PT_PSCN)&&pavg != PT_INSL)
  2326. {
  2327. parts[r>>8].type = PT_SPRK;
  2328. parts[r>>8].life = 4;
  2329. parts[r>>8].ctype = rt;
  2330. }
  2331. }
  2332. if(t==PT_SPRK && rt==PT_WATR && parts[r>>8].life==0 &&
  2333. (parts[i].life<2 || ((r>>8)<i && parts[i].life<3)) && abs(nx)+abs(ny)<4)
  2334. {
  2335. parts[r>>8].type = PT_SPRK;
  2336. parts[r>>8].life = 6;
  2337. parts[r>>8].ctype = rt;
  2338. }
  2339. if(t==PT_SPRK && rt==PT_SLTW && parts[r>>8].life==0 &&
  2340. (parts[i].life<2 || ((r>>8)<i && parts[i].life<3)) && abs(nx)+abs(ny)<4)
  2341. {
  2342. parts[r>>8].type = PT_SPRK;
  2343. parts[r>>8].life = 5;
  2344. parts[r>>8].ctype = rt;
  2345. }
  2346. if(t==PT_SPRK&&parts[i].ctype==PT_ETRD&&parts[i].life==5)
  2347. {
  2348. if(rt==PT_METL||rt==PT_IMTL||rt==PT_ETRD||rt==PT_BMTL||rt==PT_BRMT||rt==PT_LRBD||rt==PT_RBDM||rt==PT_PSCN||rt==PT_NSCN)
  2349. {
  2350. t = parts[i].type = PT_ETRD;
  2351. parts[i].ctype = PT_NONE;
  2352. parts[i].life = 20;
  2353. parts[r>>8].type = PT_SPRK;
  2354. parts[r>>8].life = 4;
  2355. parts[r>>8].ctype = rt;
  2356. }
  2357. }
  2358.  
  2359. if(t==PT_SPRK&&parts[i].ctype==PT_NBLE&&parts[i].life<=1)
  2360. {
  2361. parts[i].life = rand()%150+50;
  2362. parts[i].type = PT_PLSM;
  2363. parts[i].ctype = PT_NBLE;
  2364. parts[i].temp = 3500;
  2365. pv[y/CELL][x/CELL] += 1;
  2366. }
  2367. if(t==PT_SPRK&&parts[i].ctype==PT_SWCH&&parts[i].life<=1)
  2368. {
  2369. parts[i].type = PT_SWCH;
  2370. parts[i].life = 11;
  2371. }
  2372. }
  2373. }
  2374. killed:
  2375. if(parts[i].type == PT_NONE)
  2376. continue;
  2377. }
  2378. /*
  2379.  
  2380.  
  2381. STICKMAN SECTION
  2382.  
  2383.  
  2384. */
  2385. if(t==PT_STKM)
  2386. {
  2387. float dt = 0.9;///(FPSB*FPSB); //Delta time in square
  2388. //Tempirature handling
  2389. if(parts[i].temp<243)
  2390. parts[i].life -= 1;
  2391. if((parts[i].temp<309.6f) && (parts[i].temp>=243))
  2392. parts[i].temp += 1;
  2393.  
  2394. //Death
  2395. if(parts[i].life<1 || death == 1 || (pv[y/CELL][x/CELL]>=4.5f && player[2] != SPC_AIR) ) //If his HP is less that 0 or there is very big wind...
  2396. {
  2397. death = 0;
  2398. for(r=-2; r<=1; r++)
  2399. {
  2400. create_part(-1, x+r, y-2, player[2]);
  2401. create_part(-1, x+r+1, y+2, player[2]);
  2402. create_part(-1, x-2, y+r+1, player[2]);
  2403. create_part(-1, x+2, y+r, player[2]);
  2404. }
  2405. kill_part(i); //Kill him
  2406. goto killed;
  2407. }
  2408.  
  2409. parts[i].vy += -0.7*dt; //Head up!
  2410.  
  2411. //Verlet integration
  2412. pp = 2*player[3]-player[5]+player[19]*dt*dt;;
  2413. player[5] = player[3];
  2414. player[3] = pp;
  2415. pp = 2*player[4]-player[6]+player[20]*dt*dt;;
  2416. player[6] = player[4];
  2417. player[4] = pp;
  2418.  
  2419. pp = 2*player[7]-player[9]+player[21]*dt*dt;;
  2420. player[9] = player[7];
  2421. player[7] = pp;
  2422. pp = 2*player[8]-player[10]+(player[22]+1)*dt*dt;;
  2423. player[10] = player[8];
  2424. player[8] = pp;
  2425.  
  2426. pp = 2*player[11]-player[13]+player[23]*dt*dt;;
  2427. player[13] = player[11];
  2428. player[11] = pp;
  2429. pp = 2*player[12]-player[14]+player[24]*dt*dt;;
  2430. player[14] = player[12];
  2431. player[12] = pp;
  2432.  
  2433. pp = 2*player[15]-player[17]+player[25]*dt*dt;;
  2434. player[17] = player[15];
  2435. player[15] = pp;
  2436. pp = 2*player[16]-player[18]+(player[26]+1)*dt*dt;;
  2437. player[18] = player[16];
  2438. player[16] = pp;
  2439.  
  2440. //Setting acceleration to 0
  2441. player[19] = 0;
  2442. player[20] = 0;
  2443.  
  2444. player[21] = 0;
  2445. player[22] = 0;
  2446.  
  2447. player[23] = 0;
  2448. player[24] = 0;
  2449.  
  2450. player[25] = 0;
  2451. player[26] = 0;
  2452.  
  2453. //Go left
  2454. if (((int)(player[0])&0x01) == 0x01 && pstates[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_GAS)
  2455. {
  2456. if (pstates[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_LIQUID
  2457. && (pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF) != PT_LNTG)
  2458. {
  2459. if (pmap[(int)(player[8]-1)][(int)(player[7])])
  2460. {
  2461. player[21] = -3;
  2462. player[22] = -2;
  2463. player[19] = -2;
  2464. }
  2465.  
  2466. if (pmap[(int)(player[16]-1)][(int)(player[15])])
  2467. {
  2468. player[25] = -3;
  2469. player[26] = -2;
  2470. player[23] = -2;
  2471. }
  2472. }
  2473. else
  2474. {
  2475. if (pmap[(int)(player[8]-1)][(int)(player[7])]) //It should move another way in liquids
  2476. {
  2477. player[21] = -1;
  2478. player[22] = -1;
  2479. player[19] = -1;
  2480. }
  2481.  
  2482. if (pmap[(int)(player[16]-1)][(int)(player[15])])
  2483. {
  2484. player[25] = -1;
  2485. player[26] = -1;
  2486. player[23] = -1;
  2487. }
  2488. }
  2489. }
  2490.  
  2491. //Go right
  2492. if (((int)(player[0])&0x02) == 0x02 && pstates[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_GAS)
  2493. {
  2494. if (pstates[pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF].state != ST_LIQUID
  2495. && (pmap[(int)(parts[i].y+10)][(int)(parts[i].x)]&0xFF) != PT_LNTG)
  2496. {
  2497. if (pmap[(int)(player[8]-1)][(int)(player[7])])
  2498. {
  2499. player[21] = 3;
  2500. player[22] = -2;
  2501. player[19] = 2;
  2502. }
  2503.  
  2504. if (pmap[(int)(player[16]-1)][(int)(player[15])])
  2505. {
  2506. player[25] = 3;
  2507. player[26] = -2;
  2508. player[23] = 2;
  2509. }
  2510. }
  2511. else
  2512. {
  2513. if (pmap[(int)(player[8]-1)][(int)(player[7])])
  2514. {
  2515. player[21] = 1;
  2516. player[22] = -1;
  2517. player[19] = 1;
  2518. }
  2519.  
  2520. if (pmap[(int)(player[16]-1)][(int)(player[15])])
  2521. {
  2522. player[25] = 1;
  2523. player[26] = -1;
  2524. player[23] = 1;
  2525. }
  2526.  
  2527. }
  2528. }
  2529.  
  2530. //Jump
  2531. if (((int)(player[0])&0x04) == 0x04 && (pstates[pmap[(int)(player[8]-0.5)][(int)(player[7])]&0xFF].state != ST_GAS || pstates[pmap[(int)(player[16]-0.5)][(int)(player[15])]&0xFF].state != ST_GAS))
  2532. {
  2533. if (pmap[(int)(player[8]-0.5)][(int)(player[7])] || pmap[(int)(player[16]-0.5)][(int)(player[15])])
  2534. {
  2535. parts[i].vy = -5;
  2536. player[22] -= 1;
  2537. player[26] -= 1;
  2538. }
  2539. }
  2540.  
  2541. //Charge detector wall if foot inside
  2542. if(bmap[(int)(player[8]+0.5)/CELL][(int)(player[7]+0.5)/CELL]==6)
  2543. set_emap((int)player[7]/CELL, (int)player[8]/CELL);
  2544. if(bmap[(int)(player[16]+0.5)/CELL][(int)(player[15]+0.5)/CELL]==6)
  2545. set_emap((int)(player[15]+0.5)/CELL, (int)(player[16]+0.5)/CELL);
  2546.  
  2547. //Searching for particles near head
  2548. for(nx = -2; nx <= 2; nx++)
  2549. for(ny = 0; ny>=-2; ny--)
  2550. {
  2551. if(!pmap[ny+y][nx+x] || (pmap[ny+y][nx+x]>>8)>=NPART)
  2552. continue;
  2553. if(ptypes[pmap[ny+y][nx+x]&0xFF].falldown!=0 || (pmap[ny+y][nx+x]&0xFF) == PT_NEUT || (pmap[ny+y][nx+x]&0xFF) == PT_PHOT)
  2554. {
  2555. player[2] = pmap[ny+y][nx+x]&0xFF; //Current element
  2556. }
  2557. if((pmap[ny+y][nx+x]&0xFF) == PT_PLNT && parts[i].life<100) //Plant gives him 5 HP
  2558. {
  2559. if(parts[i].life<=95)
  2560. parts[i].life += 5;
  2561. else
  2562. parts[i].life = 100;
  2563. kill_part(pmap[ny+y][nx+x]>>8);
  2564. }
  2565.  
  2566. if((pmap[ny+y][nx+x]&0xFF) == PT_NEUT)
  2567. {
  2568. parts[i].life -= (102-parts[i].life)/2;
  2569. kill_part(pmap[ny+y][nx+x]>>8);
  2570. }
  2571. if(bmap[(ny+y)/CELL][(nx+x)/CELL]==4)
  2572. player[2] = SPC_AIR;
  2573. }
  2574.  
  2575. //Head position
  2576. nx = x + 3*((((int)player[1])&0x02) == 0x02) - 3*((((int)player[1])&0x01) == 0x01);
  2577. ny = y - 3*(player[1] == 0);
  2578.  
  2579. //Spawn
  2580. if(((int)(player[0])&0x08) == 0x08)
  2581. {
  2582. ny -= 2*(rand()%2)+1;
  2583. r = pmap[ny][nx];
  2584. if(!((r>>8)>=NPART))
  2585. {
  2586. if(pstates[r&0xFF].state == ST_SOLID)
  2587. {
  2588. create_part(-1, nx, ny, PT_SPRK);
  2589. }
  2590. else
  2591. {
  2592. if(player[2] == SPC_AIR)
  2593. create_parts(nx + 3*((((int)player[1])&0x02) == 0x02) - 3*((((int)player[1])&0x01) == 0x01), ny, 4, SPC_AIR);
  2594. else
  2595. create_part(-1, nx, ny, player[2]);
  2596.  
  2597. r = pmap[ny][nx];
  2598. if( ((r>>8) < NPART) && (r>>8)>=0 && player[2] != PT_PHOT && player[2] != SPC_AIR)
  2599. parts[r>>8].vx = parts[r>>8].vx + 5*((((int)player[1])&0x02) == 0x02) - 5*(((int)(player[1])&0x01) == 0x01);
  2600. if(((r>>8) < NPART) && (r>>8)>=0 && player[2] == PT_PHOT)
  2601. {
  2602. int random = abs(rand()%3-1)*3;
  2603. if (random==0)
  2604. {
  2605. parts[r>>8].life = 0;
  2606. parts[r>>8].type = PT_NONE;
  2607. }
  2608. else
  2609. {
  2610. parts[r>>8].vy = 0;
  2611. parts[r>>8].vx = (((((int)player[1])&0x02) == 0x02) - (((int)(player[1])&0x01) == 0x01))*random;
  2612. }
  2613. }
  2614.  
  2615. }
  2616. }
  2617. }
  2618.  
  2619. //Simulation of joints
  2620. d = 25/(pow((player[3]-player[7]), 2) + pow((player[4]-player[8]), 2)+25) - 0.5; //Fast distance
  2621. player[7] -= (player[3]-player[7])*d;
  2622. player[8] -= (player[4]-player[8])*d;
  2623. player[3] += (player[3]-player[7])*d;
  2624. player[4] += (player[4]-player[8])*d;
  2625.  
  2626. d = 25/(pow((player[11]-player[15]), 2) + pow((player[12]-player[16]), 2)+25) - 0.5;
  2627. player[15] -= (player[11]-player[15])*d;
  2628. player[16] -= (player[12]-player[16])*d;
  2629. player[11] += (player[11]-player[15])*d;
  2630. player[12] += (player[12]-player[16])*d;
  2631.  
  2632. d = 36/(pow((player[3]-parts[i].x), 2) + pow((player[4]-parts[i].y), 2)+36) - 0.5;
  2633. parts[i].vx -= (player[3]-parts[i].x)*d;
  2634. parts[i].vy -= (player[4]-parts[i].y)*d;
  2635. player[3] += (player[3]-parts[i].x)*d;
  2636. player[4] += (player[4]-parts[i].y)*d;
  2637.  
  2638. d = 36/(pow((player[11]-parts[i].x), 2) + pow((player[12]-parts[i].y), 2)+36) - 0.5;
  2639. parts[i].vx -= (player[11]-parts[i].x)*d;
  2640. parts[i].vy -= (player[12]-parts[i].y)*d;
  2641. player[11] += (player[11]-parts[i].x)*d;
  2642. player[12] += (player[12]-parts[i].y)*d;
  2643.  
  2644. //Side collisions checking
  2645. for(nx = -3; nx <= 3; nx++)
  2646. {
  2647. r = pmap[(int)(player[16]-2)][(int)(player[15]+nx)];
  2648. if(r && pstates[r&0xFF].state != ST_GAS && pstates[r&0xFF].state != ST_LIQUID)
  2649. player[15] -= nx;
  2650.  
  2651. r = pmap[(int)(player[8]-2)][(int)(player[7]+nx)];
  2652. if(r && pstates[r&0xFF].state != ST_GAS && pstates[r&0xFF].state != ST_LIQUID)
  2653. player[7] -= nx;
  2654. }
  2655.  
  2656. //Collision checks
  2657. for(ny = -2-(int)parts[i].vy; ny<=0; ny++)
  2658. {
  2659. r = pmap[(int)(player[8]+ny)][(int)(player[7]+0.5)]; //This is to make coding more pleasant :-)
  2660.  
  2661. //For left leg
  2662. if (r && (r&0xFF)!=PT_STKM)
  2663. {
  2664. if(pstates[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG) //Liquid checks //Liquid checks
  2665. {
  2666. if(parts[i].y<(player[8]-10))
  2667. parts[i].vy = 1*dt;
  2668. else
  2669. parts[i].vy = 0;
  2670. if(abs(parts[i].vx)>1)
  2671. parts[i].vx *= 0.5*dt;
  2672. }
  2673. else
  2674. {
  2675. if(pstates[r&0xFF].state != ST_GAS)
  2676. {
  2677. player[8] += ny-1;
  2678. parts[i].vy -= 0.5*parts[i].vy*dt;
  2679. }
  2680. }
  2681. player[9] = player[7];
  2682. }
  2683.  
  2684. r = pmap[(int)(player[16]+ny)][(int)(player[15]+0.5)];
  2685.  
  2686. //For right leg
  2687. if (r && (r&0xFF)!=PT_STKM)
  2688. {
  2689. if(pstates[r&0xFF].state == ST_LIQUID || (r&0xFF) == PT_LNTG)
  2690. {
  2691. if(parts[i].y<(player[16]-10))
  2692. parts[i].vy = 1*dt;
  2693. else
  2694. parts[i].vy = 0;
  2695. if(abs(parts[i].vx)>1)
  2696. parts[i].vx *= 0.5*dt;
  2697. }
  2698. else
  2699. {
  2700. if(pstates[r&0xFF].state != ST_GAS)
  2701. {
  2702. player[16] += ny-1;
  2703. parts[i].vy -= 0.5*parts[i].vy*dt;
  2704. }
  2705. }
  2706. player[17] = player[15];
  2707. }
  2708.  
  2709. //If it falls too fast
  2710. if (parts[i].vy>=30)
  2711. {
  2712. parts[i].y -= (10+ny)*dt;
  2713. parts[i].vy = -10*dt;
  2714. }
  2715.  
  2716. }
  2717.  
  2718. //Keeping legs distance
  2719. if (pow((player[7] - player[15]), 2)<16 && pow((player[8]-player[16]), 2)<1)
  2720. {
  2721. player[21] -= 0.2;
  2722. player[25] += 0.2;
  2723. }
  2724.  
  2725. if (pow((player[3] - player[11]), 2)<16 && pow((player[4]-player[12]), 2)<1)
  2726. {
  2727. player[19] -= 0.2;
  2728. player[23] += 0.2;
  2729. }
  2730.  
  2731. //If legs touch something
  2732. r = pmap[(int)(player[8]+0.5)][(int)(player[7]+0.5)];
  2733. if((r&0xFF)==PT_SPRK && r && (r>>8)<NPART) //If on charge
  2734. {
  2735. parts[i].life -= (int)(rand()/1000)+38;
  2736. }
  2737.  
  2738. if (r>0 && (r>>8)<NPART) //If hot or cold
  2739. {
  2740. if(parts[r>>8].temp>=323 || parts[r>>8].temp<=243)
  2741. {
  2742. parts[i].life -= 2;
  2743. player[26] -= 1;
  2744. }
  2745. }
  2746.  
  2747. if ((r&0xFF)==PT_ACID) //If on acid
  2748. parts[i].life -= 5;
  2749.  
  2750. if ((r&0xFF)==PT_PLUT) //If on plut
  2751. parts[i].life -= 1;
  2752.  
  2753. r = pmap[(int)(player[16]+0.5)][(int)(player[15]+0.5)];
  2754. if((r&0xFF)==PT_SPRK && r && (r>>8)<NPART) //If on charge
  2755. {
  2756. parts[i].life -= (int)(rand()/1000)+38;
  2757. }
  2758.  
  2759. if(r>0 && (r>>8)<NPART) //If hot or cold
  2760. {
  2761. if(parts[r>>8].temp>=323 || parts[r>>8].temp<=243)
  2762. {
  2763. parts[i].life -= 2;
  2764. player[22] -= 1;
  2765. }
  2766. }
  2767.  
  2768. if ((r&0xFF)==PT_ACID) //If on acid
  2769. parts[i].life -= 5;
  2770.  
  2771. if ((r&0xFF)==PT_PLUT) //If on plut
  2772. parts[i].life -= 1;
  2773.  
  2774. isplayer = 1;
  2775. }
  2776. if(t==PT_CLNE)
  2777. {
  2778. if(!parts[i].ctype)
  2779. {
  2780. for(nx=-1; nx<2; nx++)
  2781. for(ny=-1; ny<2; ny++)
  2782. if(x+nx>=0 && y+ny>0 &&
  2783. x+nx<XRES && y+ny<YRES &&
  2784. pmap[y+ny][x+nx] &&
  2785. (pmap[y+ny][x+nx]&0xFF)!=PT_CLNE &&
  2786. (pmap[y+ny][x+nx]&0xFF)!=PT_STKM &&
  2787. (pmap[y+ny][x+nx]&0xFF)!=0xFF)
  2788. parts[i].ctype = pmap[y+ny][x+nx]&0xFF;
  2789. }
  2790. else
  2791. create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype);
  2792. }
  2793. if(parts[i].type==PT_PCLN)
  2794. {
  2795. if(!parts[i].ctype)
  2796. for(nx=-1; nx<2; nx++)
  2797. for(ny=-1; ny<2; ny++)
  2798. if(x+nx>=0 && y+ny>0 &&
  2799. x+nx<XRES && y+ny<YRES &&
  2800. pmap[y+ny][x+nx] &&
  2801. (pmap[y+ny][x+nx]&0xFF)!=PT_CLNE &&
  2802. (pmap[y+ny][x+nx]&0xFF)!=PT_PCLN &&
  2803. (pmap[y+ny][x+nx]&0xFF)!=PT_SPRK &&
  2804. (pmap[y+ny][x+nx]&0xFF)!=PT_NSCN &&
  2805. (pmap[y+ny][x+nx]&0xFF)!=PT_PSCN &&
  2806. (pmap[y+ny][x+nx]&0xFF)!=PT_STKM &&
  2807. (pmap[y+ny][x+nx]&0xFF)!=0xFF)
  2808. parts[i].ctype = pmap[y+ny][x+nx]&0xFF;
  2809. if(parts[i].ctype && parts[i].life==10)
  2810. create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype);
  2811. }
  2812. if(t==PT_YEST)
  2813. {
  2814. if(parts[i].temp>303&&parts[i].temp<317) {
  2815. create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_YEST);
  2816. }
  2817. }
  2818. if(t==PT_PLSM&&parts[i].ctype == PT_NBLE&&parts[i].life <=1)
  2819. {
  2820. parts[i].type = PT_NBLE;
  2821. parts[i].life = 0;
  2822. }
  2823. if (t==PT_FIRE && parts[i].life <=1 && parts[i].temp<625)
  2824. {
  2825. t = parts[i].type = PT_SMKE;
  2826. parts[i].life = rand()%20+250;
  2827. }
  2828.  
  2829. nx = (int)(parts[i].x+0.5f);
  2830. ny = (int)(parts[i].y+0.5f);
  2831.  
  2832. if(nx<CELL || nx>=XRES-CELL ||
  2833. ny<CELL || ny>=YRES-CELL)
  2834. {
  2835. parts[i].x = lx;
  2836. parts[i].y = ly;
  2837. kill_part(i);
  2838. continue;
  2839. }
  2840.  
  2841. if(parts[i].type == PT_PHOT || parts[i].type == PT_LASR) {
  2842. rt = pmap[ny][nx] & 0xFF;
  2843.  
  2844. if(rt==PT_CLNE) {
  2845. lt = pmap[ny][nx] >> 8;
  2846. if(!parts[lt].ctype)
  2847. parts[lt].ctype = PT_PHOT;
  2848. }
  2849.  
  2850. lt = pmap[y][x] & 0xFF;
  2851.  
  2852. r = eval_move(PT_PHOT, nx, ny, NULL);
  2853.  
  2854. if(((rt==PT_GLAS && lt!=PT_GLAS) || (rt!=PT_GLAS && lt==PT_GLAS)) && r) {
  2855. if(!get_normal_interp(REFRACT|parts[i].type, x, y, parts[i].vx, parts[i].vy, &nrx, &nry)) {
  2856. kill_part(i);
  2857. continue;
  2858. }
  2859.  
  2860. r = get_wavelength_bin(&parts[i].ctype);
  2861. if(r == -1) {
  2862. kill_part(i);
  2863. continue;
  2864. }
  2865. nn = GLASS_IOR - GLASS_DISP*(r-15)/15.0f;
  2866. nn *= nn;
  2867.  
  2868. nrx = -nrx;
  2869. nry = -nry;
  2870. if(rt==PT_GLAS && lt!=PT_GLAS)
  2871. nn = 1.0f/nn;
  2872. ct1 = parts[i].vx*nrx + parts[i].vy*nry;
  2873. ct2 = 1.0f - (nn*nn)*(1.0f-(ct1*ct1));
  2874. if(ct2 < 0.0f) {
  2875. parts[i].vx -= 2.0f*ct1*nrx;
  2876. parts[i].vy -= 2.0f*ct1*nry;
  2877. parts[i].x = lx;
  2878. parts[i].y = ly;
  2879. nx = (int)(lx + 0.5f);
  2880. ny = (int)(ly + 0.5f);
  2881. } else {
  2882. ct2 = sqrtf(ct2);
  2883. ct2 = ct2 - nn*ct1;
  2884. parts[i].vx = nn*parts[i].vx + ct2*nrx;
  2885. parts[i].vy = nn*parts[i].vy + ct2*nry;
  2886. }
  2887. }
  2888. }
  2889.  
  2890. rt = parts[i].flags & FLAG_STAGNANT;
  2891. parts[i].flags &= ~FLAG_STAGNANT;
  2892. if(!try_move(i, x, y, nx, ny))
  2893. {
  2894. parts[i].x = lx;
  2895. parts[i].y = ly;
  2896. if(ptypes[t].falldown)
  2897. {
  2898. if(nx!=x && try_move(i, x, y, nx, y))
  2899. {
  2900. parts[i].x = ix;
  2901. parts[i].vx *= ptypes[t].collision;
  2902. parts[i].vy *= ptypes[t].collision;
  2903. }
  2904. else if(ny!=y && try_move(i, x, y, x, ny))
  2905. {
  2906. parts[i].y = iy;
  2907. parts[i].vx *= ptypes[t].collision;
  2908. parts[i].vy *= ptypes[t].collision;
  2909. }
  2910. else
  2911. {
  2912. r = (rand()%2)*2-1;
  2913. if(ny!=y && try_move(i, x, y, x+r, ny))
  2914. {
  2915. parts[i].x += r;
  2916. parts[i].y = iy;
  2917. parts[i].vx *= ptypes[t].collision;
  2918. parts[i].vy *= ptypes[t].collision;
  2919. }
  2920. else if(ny!=y && try_move(i, x, y, x-r, ny))
  2921. {
  2922. parts[i].x -= r;
  2923. parts[i].y = iy;
  2924. parts[i].vx *= ptypes[t].collision;
  2925. parts[i].vy *= ptypes[t].collision;
  2926. }
  2927. else if(nx!=x && try_move(i, x, y, nx, y+r))
  2928. {
  2929. parts[i].x = ix;
  2930. parts[i].y += r;
  2931. parts[i].vx *= ptypes[t].collision;
  2932. parts[i].vy *= ptypes[t].collision;
  2933. }
  2934. else if(nx!=x && try_move(i, x, y, nx, y-r))
  2935. {
  2936. parts[i].x = ix;
  2937. parts[i].y -= r;
  2938. parts[i].vx *= ptypes[t].collision;
  2939. parts[i].vy *= ptypes[t].collision;
  2940. }
  2941. else if(ptypes[t].falldown>1 && parts[i].vy>fabs(parts[i].vx))
  2942. {
  2943. s = 0;
  2944. if(!rt || nt)
  2945. rt = 50;
  2946. else
  2947. rt = 10;
  2948. for(j=x+r; j>=0 && j>=x-rt && j<x+rt && j<XRES; j+=r)
  2949. {
  2950. if(try_move(i, x, y, j, ny))
  2951. {
  2952. parts[i].x += j-x;
  2953. parts[i].y += ny-y;
  2954. x = j;
  2955. y = ny;
  2956. s = 1;
  2957. break;
  2958. }
  2959. if(try_move(i, x, y, j, y))
  2960. {
  2961. parts[i].x += j-x;
  2962. x = j;
  2963. s = 1;
  2964. break;
  2965. }
  2966. if((pmap[y][j]&255)!=t || (bmap[y/CELL][j/CELL] && bmap[y/CELL][j/CELL]!=5))
  2967. break;
  2968. }
  2969. if(parts[i].vy>0)
  2970. r = 1;
  2971. else
  2972. r = -1;
  2973. if(s)
  2974. for(j=y+r; j>=0 && j<YRES && j>=y-rt && j<x+rt; j+=r)
  2975. {
  2976. if(try_move(i, x, y, x, j))
  2977. {
  2978. parts[i].y += j-y;
  2979. break;
  2980. }
  2981. if((pmap[j][x]&255)!=t || (bmap[j/CELL][x/CELL] && bmap[j/CELL][x/CELL]!=5))
  2982. {
  2983. s = 0;
  2984. break;
  2985. }
  2986. }
  2987. parts[i].vx *= ptypes[t].collision;
  2988. parts[i].vy *= ptypes[t].collision;
  2989. if(!s)
  2990. parts[i].flags |= FLAG_STAGNANT;
  2991. }
  2992. else
  2993. {
  2994. parts[i].flags |= FLAG_STAGNANT;
  2995. parts[i].vx *= ptypes[t].collision;
  2996. parts[i].vy *= ptypes[t].collision;
  2997. }
  2998. }
  2999. }
  3000. else
  3001. {
  3002. parts[i].flags |= FLAG_STAGNANT;
  3003. if(t==PT_NEUT && 100>(rand()%1000))
  3004. {
  3005. kill_part(i);
  3006. continue;
  3007. }
  3008. else if(t==PT_NEUT || t==PT_PHOT || t==PT_LASR )
  3009. {
  3010. r = pmap[ny][nx];
  3011.  
  3012. /* this should be replaced with a particle type attribute ("photwl" or something) */
  3013. if((r & 0xFF) == PT_PSCN) parts[i].ctype = 0x00000000;
  3014. if((r & 0xFF) == PT_NSCN) parts[i].ctype = 0x00000000;
  3015. if((r & 0xFF) == PT_SPRK) parts[i].ctype = 0x00000000;
  3016. if((r & 0xFF) == PT_COAL) parts[i].ctype = 0x00000000;
  3017. if((r & 0xFF) == PT_BCOL) parts[i].ctype = 0x00000000;
  3018. if((r & 0xFF) == PT_PLEX) parts[i].ctype &= 0x1F00003E;
  3019. if((r & 0xFF) == PT_NITR) parts[i].ctype &= 0x0007C000;
  3020. if((r & 0xFF) == PT_NBLE) parts[i].ctype &= 0x3FFF8000;
  3021. if((r & 0xFF) == PT_LAVA) parts[i].ctype &= 0x3FF00000;
  3022. if((r & 0xFF) == PT_ACID) parts[i].ctype &= 0x1FE001FE;
  3023. if((r & 0xFF) == PT_DUST) parts[i].ctype &= 0x3FFFFFC0;
  3024. if((r & 0xFF) == PT_SNOW) parts[i].ctype &= 0x03FFFFFF;
  3025. if((r & 0xFF) == PT_GOO) parts[i].ctype &= 0x3FFAAA00;
  3026. if((r & 0xFF) == PT_PLNT) parts[i].ctype &= 0x0007C000;
  3027. if((r & 0xFF) == PT_PLUT) parts[i].ctype &= 0x001FCE00;
  3028. if((r & 0xFF) == PT_URAN) parts[i].ctype &= 0x003FC000;
  3029.  
  3030. if(get_normal_interp(t, lx, ly, parts[i].vx, parts[i].vy, &nrx, &nry)) {
  3031. dp = nrx*parts[i].vx + nry*parts[i].vy;
  3032. parts[i].vx -= 2.0f*dp*nrx;
  3033. parts[i].vy -= 2.0f*dp*nry;
  3034. nx = (int)(parts[i].x + parts[i].vx + 0.5f);
  3035. ny = (int)(parts[i].y + parts[i].vy + 0.5f);
  3036. if(try_move(i, x, y, nx, ny)) {
  3037. parts[i].x = (float)nx;
  3038. parts[i].y = (float)ny;
  3039. } else {
  3040. kill_part(i);
  3041. continue;
  3042. }
  3043. } else {
  3044. kill_part(i);
  3045. continue;
  3046. }
  3047.  
  3048. if(!parts[i].ctype) {
  3049. kill_part(i);
  3050. continue;
  3051. }
  3052. }
  3053.  
  3054. else
  3055. {
  3056. if(nx>x+ISTP) nx=x+ISTP;
  3057. if(nx<x-ISTP) nx=x-ISTP;
  3058. if(ny>y+ISTP) ny=y+ISTP;
  3059. if(ny<y-ISTP) ny=y-ISTP;
  3060. if(try_move(i, x, y, 2*x-nx, ny))
  3061. {
  3062. parts[i].x = (float)(2*x-nx);
  3063. parts[i].y = (float)iy;
  3064. parts[i].vx *= ptypes[t].collision;
  3065. }
  3066. else if(try_move(i, x, y, nx, 2*y-ny))
  3067. {
  3068. parts[i].x = (float)ix;
  3069. parts[i].y = (float)(2*y-ny);
  3070. parts[i].vy *= ptypes[t].collision;
  3071. }
  3072. else
  3073. {
  3074. parts[i].vx *= ptypes[t].collision;
  3075. parts[i].vy *= ptypes[t].collision;
  3076. }
  3077. }
  3078. }
  3079. }
  3080. if(nx<CELL || nx>=XRES-CELL || ny<CELL || ny>=YRES-CELL)
  3081. {
  3082. kill_part(i);
  3083. continue;
  3084. }
  3085. }
  3086. if(framerender) {
  3087. framerender = 0;
  3088. sys_pause = 1;
  3089. }
  3090. }
  3091.  
  3092. void update_particles(pixel *vid)
  3093. {
  3094. int i, j, x, y, t, nx, ny, r, cr,cg,cb, l = -1;
  3095. float lx, ly;
  3096. #ifdef MT
  3097. int pt = 0, pc = 0;
  3098. pthread_t *InterThreads;
  3099. #endif
  3100.  
  3101. isplayer = 0; //Needed for player spawning
  3102. memset(pmap, 0, sizeof(pmap));
  3103. r = rand()%2;
  3104. for(j=0; j<NPART; j++)
  3105. {
  3106. i = r ? (NPART-1-j) : j;
  3107. if(parts[i].type)
  3108. {
  3109. t = parts[i].type;
  3110. x = (int)(parts[i].x+0.5f);
  3111. y = (int)(parts[i].y+0.5f);
  3112. if(x>=0 && y>=0 && x<XRES && y<YRES && t!=PT_PHOT) {
  3113. if(t!=PT_NEUT || (pmap[y][x]&0xFF)!=PT_GLAS)
  3114. pmap[y][x] = t|(i<<8);
  3115. }
  3116. }
  3117. else
  3118. {
  3119. parts[i].life = l;
  3120. l = i;
  3121. }
  3122. }
  3123. pfree=l;
  3124. if(cmode==4)
  3125. {
  3126. for(y=0; y<YRES/CELL; y++)
  3127. {
  3128. for(x=0; x<XRES/CELL; x++)
  3129. {
  3130. if(bmap[y][x]==1)
  3131. for(j=0; j<CELL; j++)
  3132. for(i=0; i<CELL; i++)
  3133. {
  3134. pmap[y*CELL+j][x*CELL+i] = 0x7FFFFFFF;
  3135. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x808080);
  3136. drawblob(vid, (x*CELL+i), (y*CELL+j), 0x80, 0x80, 0x80);
  3137.  
  3138. }
  3139. if(bmap[y][x]==2)
  3140. for(j=0; j<CELL; j+=2)
  3141. for(i=(j>>1)&1; i<CELL; i+=2)
  3142. {
  3143. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x808080);
  3144. drawblob(vid, (x*CELL+i), (y*CELL+j), 0x80, 0x80, 0x80);
  3145. }
  3146. if(bmap[y][x]==3)
  3147. {
  3148. for(j=0; j<CELL; j++)
  3149. for(i=0; i<CELL; i++)
  3150. if(!((y*CELL+j)%2) && !((x*CELL+i)%2))
  3151. {
  3152. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0xC0C0C0);
  3153. drawblob(vid, (x*CELL+i), (y*CELL+j), 0xC0, 0xC0, 0xC0);
  3154. }
  3155. if(emap[y][x])
  3156. {
  3157. cr = cg = cb = 16;
  3158. cr += fire_r[y][x];
  3159. if(cr > 255) cr = 255;
  3160. fire_r[y][x] = cr;
  3161. cg += fire_g[y][x];
  3162. if(cg > 255) cg = 255;
  3163. fire_g[y][x] = cg;
  3164. cb += fire_b[y][x];
  3165. if(cb > 255) cb = 255;
  3166. fire_b[y][x] = cb;
  3167. }
  3168. }
  3169. if(bmap[y][x]==4)
  3170. for(j=0; j<CELL; j+=2)
  3171. for(i=(j>>1)&1; i<CELL; i+=2)
  3172. {
  3173. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x8080FF);
  3174. drawblob(vid, (x*CELL+i), (y*CELL+j), 0x80, 0x80, 0xFF);
  3175. }
  3176. if(bmap[y][x]==6)
  3177. {
  3178. for(j=0; j<CELL; j+=2)
  3179. for(i=(j>>1)&1; i<CELL; i+=2)
  3180. {
  3181. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0xFF8080);
  3182. drawblob(vid, (x*CELL+i), (y*CELL+j), 0xFF, 0x80, 0x80);
  3183. }
  3184. if(emap[y][x])
  3185. {
  3186. cr = 255;
  3187. cg = 32;
  3188. cb = 8;
  3189. cr += fire_r[y][x];
  3190. if(cr > 255) cr = 255;
  3191. fire_r[y][x] = cr;
  3192. cg += fire_g[y][x];
  3193. if(cg > 255) cg = 255;
  3194. fire_g[y][x] = cg;
  3195. cb += fire_b[y][x];
  3196. if(cb > 255) cb = 255;
  3197. fire_b[y][x] = cb;
  3198. }
  3199. }
  3200. if(bmap[y][x]==7)
  3201. {
  3202. if(emap[y][x])
  3203. {
  3204. cr = cg = cb = 128;
  3205. cr += fire_r[y][x];
  3206. if(cr > 255) cr = 255;
  3207. fire_r[y][x] = cr;
  3208. cg += fire_g[y][x];
  3209. if(cg > 255) cg = 255;
  3210. fire_g[y][x] = cg;
  3211. cb += fire_b[y][x];
  3212. if(cb > 255) cb = 255;
  3213. fire_b[y][x] = cb;
  3214. for(j=0; j<CELL; j++)
  3215. for(i=0; i<CELL; i++)
  3216. if(i&j&1)
  3217. {
  3218. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x808080);
  3219. drawblob(vid, (x*CELL+i), (y*CELL+j), 0x80, 0x80, 0x80);
  3220. }
  3221. }
  3222. else
  3223. {
  3224. for(j=0; j<CELL; j++)
  3225. for(i=0; i<CELL; i++)
  3226. pmap[y*CELL+j][x*CELL+i] = 0x7FFFFFFF;
  3227. for(j=0; j<CELL; j++)
  3228. for(i=0; i<CELL; i++)
  3229. if(!(i&j&1))
  3230. {
  3231. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x808080);
  3232. drawblob(vid, (x*CELL+i), (y*CELL+j), 0x80, 0x80, 0x80);
  3233. }
  3234. }
  3235. }
  3236. if(bmap[y][x]==8)
  3237. {
  3238. for(j=0; j<CELL; j++)
  3239. for(i=0; i<CELL; i++)
  3240. {
  3241. pmap[y*CELL+j][x*CELL+i] = 0x7FFFFFFF;
  3242. if(!((y*CELL+j)%2) && !((x*CELL+i)%2))
  3243. {
  3244. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0xC0C0C0);
  3245. drawblob(vid, (x*CELL+i), (y*CELL+j), 0xC0, 0xC0, 0xC0);
  3246. }
  3247. else
  3248. {
  3249. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x808080);
  3250. drawblob(vid, (x*CELL+i), (y*CELL+j), 0x80, 0x80, 0x80);
  3251. }
  3252. }
  3253. if(emap[y][x])
  3254. {
  3255. cr = cg = cb = 16;
  3256. cr += fire_r[y][x];
  3257. if(cr > 255) cr = 255;
  3258. fire_r[y][x] = cr;
  3259. cg += fire_g[y][x];
  3260. if(cg > 255) cg = 255;
  3261. fire_g[y][x] = cg;
  3262. cb += fire_b[y][x];
  3263. if(cb > 255) cb = 255;
  3264. fire_b[y][x] = cb;
  3265. }
  3266. }
  3267. if(bmap[y][x]==11)
  3268. {
  3269. for(j=0; j<CELL; j++)
  3270. for(i=0; i<CELL; i++)
  3271. {
  3272. //pmap[y*CELL+j][x*CELL+i] = 0x7FFFFFFF;
  3273. if(!((y*CELL+j)%2) && !((x*CELL+i)%2))
  3274. {
  3275. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0xFFFF22);
  3276. drawblob(vid, (x*CELL+i), (y*CELL+j), 0xFF, 0xFF, 0x22);
  3277. }
  3278.  
  3279. }
  3280. if(emap[y][x])
  3281. {
  3282. cr = cg = cb = 16;
  3283. cr += fire_r[y][x];
  3284. if(cr > 255) cr = 255;
  3285. fire_r[y][x] = cr;
  3286. cg += fire_g[y][x];
  3287. if(cg > 255) cg = 255;
  3288. fire_g[y][x] = cg;
  3289. cb += fire_b[y][x];
  3290. if(cb > 255) cb = 255;
  3291. fire_b[y][x] = cb;
  3292. }
  3293. }
  3294. if(bmap[y][x]==13)
  3295. {
  3296. for(j=0; j<CELL; j+=2)
  3297. {
  3298. for(i=(j>>1)&1; i<CELL; i+=2)
  3299. {
  3300. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x579777);
  3301. drawblob(vid, (x*CELL+i), (y*CELL+j), 0x57, 0x97, 0x77);
  3302. }
  3303. }
  3304. }
  3305. if(bmap[y][x]==9)
  3306. {
  3307. for(j=0; j<CELL; j+=2)
  3308. {
  3309. for(i=(j>>1)&1; i<CELL; i+=2)
  3310. {
  3311. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x3C3C3C);
  3312. drawblob(vid, (x*CELL+i), (y*CELL+j), 0x3C, 0x3C, 0x3C);
  3313. }
  3314. }
  3315. }
  3316. if(bmap[y][x]==10)
  3317. {
  3318. for(j=0; j<CELL; j+=2)
  3319. {
  3320. for(i=(j>>1)&1; i<CELL; i+=2)
  3321. {
  3322. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x575757);
  3323. drawblob(vid, (x*CELL+i), (y*CELL+j), 0x57, 0x57, 0x57);
  3324. }
  3325. }
  3326. }
  3327. if(bmap[y][x]==12)
  3328. {
  3329. if(emap[y][x])
  3330. {
  3331. for(j=0; j<CELL; j++)
  3332. {
  3333. for(i=(j)&1; i<CELL; i++)
  3334. {
  3335. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x242424);
  3336. drawblob(vid, (x*CELL+i), (y*CELL+j), 0x24, 0x24, 0x24);
  3337. }
  3338. }
  3339. for(j=0; j<CELL; j+=2)
  3340. {
  3341. for(i=(j)&1; i<CELL; i+=2)
  3342. {
  3343. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x000000);
  3344. }
  3345. }
  3346. }
  3347. else
  3348. {
  3349. for(j=0; j<CELL; j+=2)
  3350. {
  3351. for(i=(j)&1; i<CELL; i+=2)
  3352. {
  3353. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x242424);
  3354. drawblob(vid, (x*CELL+i), (y*CELL+j), 0x24, 0x24, 0x24);
  3355. }
  3356. }
  3357. }
  3358. if(emap[y][x])
  3359. {
  3360. cr = cg = cb = 16;
  3361. cr += fire_r[y][x];
  3362. if(cr > 255) cr = 255;
  3363. fire_r[y][x] = cr;
  3364. cg += fire_g[y][x];
  3365. if(cg > 255) cg = 255;
  3366. fire_g[y][x] = cg;
  3367. cb += fire_b[y][x];
  3368. if(cb > 255) cb = 255;
  3369. fire_b[y][x] = cb;
  3370. }
  3371. }
  3372. if(emap[y][x] && (!sys_pause||framerender))
  3373. emap[y][x] --;
  3374. }
  3375. }
  3376. }
  3377. else
  3378. {
  3379. for(y=0; y<YRES/CELL; y++)
  3380. {
  3381. for(x=0; x<XRES/CELL; x++)
  3382. {
  3383. if(bmap[y][x]==1)
  3384. for(j=0; j<CELL; j++)
  3385. for(i=0; i<CELL; i++)
  3386. {
  3387. pmap[y*CELL+j][x*CELL+i] = 0x7FFFFFFF;
  3388. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x808080);
  3389. }
  3390. if(bmap[y][x]==2)
  3391. for(j=0; j<CELL; j+=2)
  3392. for(i=(j>>1)&1; i<CELL; i+=2)
  3393. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x808080);
  3394. if(bmap[y][x]==3)
  3395. {
  3396. for(j=0; j<CELL; j++)
  3397. for(i=0; i<CELL; i++)
  3398. if(!((y*CELL+j)%2) && !((x*CELL+i)%2))
  3399. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0xC0C0C0);
  3400. if(emap[y][x])
  3401. {
  3402. cr = cg = cb = 16;
  3403. cr += fire_r[y][x];
  3404. if(cr > 255) cr = 255;
  3405. fire_r[y][x] = cr;
  3406. cg += fire_g[y][x];
  3407. if(cg > 255) cg = 255;
  3408. fire_g[y][x] = cg;
  3409. cb += fire_b[y][x];
  3410. if(cb > 255) cb = 255;
  3411. fire_b[y][x] = cb;
  3412. }
  3413. }
  3414. if(bmap[y][x]==4)
  3415. for(j=0; j<CELL; j+=2)
  3416. for(i=(j>>1)&1; i<CELL; i+=2)
  3417. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x8080FF);
  3418. if(bmap[y][x]==6)
  3419. {
  3420. for(j=0; j<CELL; j+=2)
  3421. for(i=(j>>1)&1; i<CELL; i+=2)
  3422. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0xFF8080);
  3423. if(emap[y][x])
  3424. {
  3425. cr = 255;
  3426. cg = 32;
  3427. cb = 8;
  3428. cr += fire_r[y][x];
  3429. if(cr > 255) cr = 255;
  3430. fire_r[y][x] = cr;
  3431. cg += fire_g[y][x];
  3432. if(cg > 255) cg = 255;
  3433. fire_g[y][x] = cg;
  3434. cb += fire_b[y][x];
  3435. if(cb > 255) cb = 255;
  3436. fire_b[y][x] = cb;
  3437. }
  3438. }
  3439. if(bmap[y][x]==7)
  3440. {
  3441. if(emap[y][x])
  3442. {
  3443. cr = cg = cb = 128;
  3444. cr += fire_r[y][x];
  3445. if(cr > 255) cr = 255;
  3446. fire_r[y][x] = cr;
  3447. cg += fire_g[y][x];
  3448. if(cg > 255) cg = 255;
  3449. fire_g[y][x] = cg;
  3450. cb += fire_b[y][x];
  3451. if(cb > 255) cb = 255;
  3452. fire_b[y][x] = cb;
  3453. for(j=0; j<CELL; j++)
  3454. for(i=0; i<CELL; i++)
  3455. if(i&j&1)
  3456. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x808080);
  3457. }
  3458. else
  3459. {
  3460. for(j=0; j<CELL; j++)
  3461. for(i=0; i<CELL; i++)
  3462. pmap[y*CELL+j][x*CELL+i] = 0x7FFFFFFF;
  3463. for(j=0; j<CELL; j++)
  3464. for(i=0; i<CELL; i++)
  3465. if(!(i&j&1))
  3466. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x808080);
  3467. }
  3468. }
  3469. if(bmap[y][x]==8)
  3470. {
  3471. for(j=0; j<CELL; j++)
  3472. for(i=0; i<CELL; i++)
  3473. {
  3474. pmap[y*CELL+j][x*CELL+i] = 0x7FFFFFFF;
  3475. if(!((y*CELL+j)%2) && !((x*CELL+i)%2))
  3476. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0xC0C0C0);
  3477. else
  3478. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x808080);
  3479. }
  3480. if(emap[y][x])
  3481. {
  3482. cr = cg = cb = 16;
  3483. cr += fire_r[y][x];
  3484. if(cr > 255) cr = 255;
  3485. fire_r[y][x] = cr;
  3486. cg += fire_g[y][x];
  3487. if(cg > 255) cg = 255;
  3488. fire_g[y][x] = cg;
  3489. cb += fire_b[y][x];
  3490. if(cb > 255) cb = 255;
  3491. fire_b[y][x] = cb;
  3492. }
  3493. }
  3494. if(bmap[y][x]==11)
  3495. {
  3496. for(j=0; j<CELL; j++)
  3497. for(i=0; i<CELL; i++)
  3498. {
  3499. //pmap[y*CELL+j][x*CELL+i] = 0x7FFFFFFF;
  3500. if(!((y*CELL+j)%2) && !((x*CELL+i)%2))
  3501. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0xFFFF22);
  3502.  
  3503. }
  3504. if(emap[y][x])
  3505. {
  3506. cr = cg = cb = 16;
  3507. cr += fire_r[y][x];
  3508. if(cr > 255) cr = 255;
  3509. fire_r[y][x] = cr;
  3510. cg += fire_g[y][x];
  3511. if(cg > 255) cg = 255;
  3512. fire_g[y][x] = cg;
  3513. cb += fire_b[y][x];
  3514. if(cb > 255) cb = 255;
  3515. fire_b[y][x] = cb;
  3516. }
  3517. }
  3518. if(bmap[y][x]==9)
  3519. {
  3520. for(j=0; j<CELL; j+=2)
  3521. {
  3522. for(i=(j>>1)&1; i<CELL; i+=2)
  3523. {
  3524. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x3C3C3C);
  3525. }
  3526. }
  3527. }
  3528. if(bmap[y][x]==13)
  3529. {
  3530. for(j=0; j<CELL; j+=2)
  3531. {
  3532. for(i=(j>>1)&1; i<CELL; i+=2)
  3533. {
  3534. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x579777);
  3535. }
  3536. }
  3537. }
  3538. if(bmap[y][x]==10)
  3539. {
  3540. for(j=0; j<CELL; j+=2)
  3541. {
  3542. for(i=(j>>1)&1; i<CELL; i+=2)
  3543. {
  3544. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x575757);
  3545. }
  3546. }
  3547. }
  3548. if(bmap[y][x]==12)
  3549. {
  3550. if(emap[y][x])
  3551. {
  3552. for(j=0; j<CELL; j++)
  3553. {
  3554. for(i=(j)&1; i<CELL; i++)
  3555. {
  3556. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x242424);
  3557. }
  3558. }
  3559. for(j=0; j<CELL; j+=2)
  3560. {
  3561. for(i=(j)&1; i<CELL; i+=2)
  3562. {
  3563. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x000000);
  3564. }
  3565. }
  3566. }
  3567. else
  3568. {
  3569. for(j=0; j<CELL; j+=2)
  3570. {
  3571. for(i=(j)&1; i<CELL; i+=2)
  3572. {
  3573. vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x242424);
  3574. }
  3575. }
  3576. }
  3577. if(emap[y][x])
  3578. {
  3579. cr = cg = cb = 16;
  3580. cr += fire_r[y][x];
  3581. if(cr > 255) cr = 255;
  3582. fire_r[y][x] = cr;
  3583. cg += fire_g[y][x];
  3584. if(cg > 255) cg = 255;
  3585. fire_g[y][x] = cg;
  3586. cb += fire_b[y][x];
  3587. if(cb > 255) cb = 255;
  3588. fire_b[y][x] = cb;
  3589. }
  3590. }
  3591. if(emap[y][x] && (!sys_pause||framerender))
  3592. emap[y][x] --;
  3593. }
  3594. }
  3595. }
  3596.  
  3597. update_particles_i(vid, 0, 1);
  3598.  
  3599. for(y=0; y<YRES/CELL; y++)
  3600. for(x=0; x<XRES/CELL; x++)
  3601. if(bmap[y][x]==5)
  3602. {
  3603. lx = x*CELL + CELL*0.5f;
  3604. ly = y*CELL + CELL*0.5f;
  3605. for(t=0; t<1024; t++)
  3606. {
  3607. nx = (int)(lx+0.5f);
  3608. ny = (int)(ly+0.5f);
  3609. if(nx<0 || nx>=XRES || ny<0 || ny>=YRES)
  3610. break;
  3611. addpixel(vid, nx, ny, 255, 255, 255, 64);
  3612. i = nx/CELL;
  3613. j = ny/CELL;
  3614. lx += vx[j][i]*0.125f;
  3615. ly += vy[j][i]*0.125f;
  3616. if(bmap[j][i]==5 && i!=x && j!=y)
  3617. break;
  3618. }
  3619. drawtext(vid, x*CELL, y*CELL-2, "\x8D", 255, 255, 255, 128);
  3620. }
  3621.  
  3622. }
  3623.  
  3624. void clear_area(int area_x, int area_y, int area_w, int area_h)
  3625. {
  3626. int cx = 0;
  3627. int cy = 0;
  3628. for(cy=0; cy<area_h; cy++)
  3629. {
  3630. for(cx=0; cx<area_w; cx++)
  3631. {
  3632. bmap[(cy+area_y)/CELL][(cx+area_x)/CELL] = 0;
  3633. delete_part(cx+area_x, cy+area_y);
  3634. }
  3635. }
  3636. }
  3637.  
  3638. void create_box(int x1, int y1, int x2, int y2, int c)
  3639. {
  3640. int i, j;
  3641. if(x1>x2)
  3642. {
  3643. i = x2;
  3644. x2 = x1;
  3645. x1 = i;
  3646. }
  3647. if(y1>y2)
  3648. {
  3649. j = y2;
  3650. y2 = y1;
  3651. y1 = j;
  3652. }
  3653. for(j=y1; j<=y2; j++)
  3654. for(i=x1; i<=x2; i++)
  3655. create_parts(i, j, 1, c);
  3656. }
  3657.  
  3658. int flood_parts(int x, int y, int c, int cm, int bm)
  3659. {
  3660. int x1, x2, dy = (c<PT_NUM)?1:CELL;
  3661. int co = c;
  3662. if(c>=122&&c<=122+UI_WALLCOUNT)
  3663. {
  3664. c = c-100;
  3665. }
  3666. if(cm==-1)
  3667. {
  3668. if(c==0)
  3669. {
  3670. cm = pmap[y][x]&0xFF;
  3671. if(!cm)
  3672. return 0;
  3673. }
  3674. else
  3675. cm = 0;
  3676. }
  3677. if(bm==-1)
  3678. {
  3679. if(c==30)
  3680. {
  3681. bm = bmap[y/CELL][x/CELL];
  3682. if(!bm)
  3683. return 0;
  3684. if(bm==1)
  3685. cm = 0xFF;
  3686. }
  3687. else
  3688. bm = 0;
  3689. }
  3690.  
  3691. if((pmap[y][x]&0xFF)!=cm || bmap[y/CELL][x/CELL]!=bm)
  3692. return 1;
  3693.  
  3694. // go left as far as possible
  3695. x1 = x2 = x;
  3696. while(x1>=CELL)
  3697. {
  3698. if((pmap[y][x1-1]&0xFF)!=cm || bmap[y/CELL][(x1-1)/CELL]!=bm)
  3699. break;
  3700. x1--;
  3701. }
  3702. while(x2<XRES-CELL)
  3703. {
  3704. if((pmap[y][x2+1]&0xFF)!=cm || bmap[y/CELL][(x2+1)/CELL]!=bm)
  3705. break;
  3706. x2++;
  3707. }
  3708.  
  3709. // fill span
  3710. for(x=x1; x<=x2; x++)
  3711. if(!create_parts(x, y, 0, co))
  3712. return 0;
  3713.  
  3714. // fill children
  3715. if(y>=CELL+dy)
  3716. for(x=x1; x<=x2; x++)
  3717. if((pmap[y-dy][x]&0xFF)==cm && bmap[(y-dy)/CELL][x/CELL]==bm)
  3718. if(!flood_parts(x, y-dy, co, cm, bm))
  3719. return 0;
  3720. if(y<YRES-CELL-dy)
  3721. for(x=x1; x<=x2; x++)
  3722. if((pmap[y+dy][x]&0xFF)==cm && bmap[(y+dy)/CELL][x/CELL]==bm)
  3723. if(!flood_parts(x, y+dy, co, cm, bm))
  3724. return 0;
  3725. return 1;
  3726. }
  3727.  
  3728. int create_parts(int x, int y, int r, int c)
  3729. {
  3730. int i, j, f = 0, u, v, oy, ox, b = 0, dw = 0; //n;
  3731.  
  3732. if(c == 125)
  3733. {
  3734. i = x / CELL;
  3735. j = y / CELL;
  3736. for(v=-1; v<2; v++)
  3737. for(u=-1; u<2; u++)
  3738. if(i+u>=0 && i+u<XRES/CELL &&
  3739. j+v>=0 && j+v<YRES/CELL &&
  3740. bmap[j+v][i+u] == 5)
  3741. return 1;
  3742. bmap[j][i] = 5;
  3743. return 1;
  3744. }
  3745. //LOLOLOLOLLOLOLOLO
  3746. if(c == 127)
  3747. {
  3748. b = 4;
  3749. dw = 1;
  3750. }
  3751. if(c == 122)
  3752. {
  3753. b = 8;
  3754. dw = 1;
  3755. }
  3756. if(c == 123)
  3757. {
  3758. b = 7;
  3759. dw = 1;
  3760. }
  3761. if(c == 124)
  3762. {
  3763. b = 6;
  3764. dw = 1;
  3765. }
  3766. if(c == 128)
  3767. {
  3768. b = 3;
  3769. dw = 1;
  3770. }
  3771. if(c == 129)
  3772. {
  3773. b = 2;
  3774. dw = 1;
  3775. }
  3776. if(c == 130)
  3777. {
  3778. b = 0;
  3779. dw = 1;
  3780. }
  3781. if(c == 131)
  3782. {
  3783. b = 1;
  3784. dw = 1;
  3785. }
  3786. if(c == 132)
  3787. {
  3788. b = 9;
  3789. dw = 1;
  3790. }
  3791. if(c == 133)
  3792. {
  3793. b = 10;
  3794. dw = 1;
  3795. }
  3796. if(c == 134)
  3797. {
  3798. b = 11;
  3799. dw = 1;
  3800. }
  3801. if(c == 135)
  3802. {
  3803. b = 12;
  3804. dw = 1;
  3805. }
  3806. if(c == 140)
  3807. {
  3808. b = 13;
  3809. dw = 1;
  3810. }
  3811. if(c == 255)
  3812. {
  3813. b = 255;
  3814. dw = 1;
  3815. }
  3816. if(dw==1)
  3817. {
  3818. r = r/CELL;
  3819. x = x/CELL;
  3820. y = y/CELL;
  3821. x -= r/2;
  3822. y -= r/2;
  3823. for (ox=x; ox<=x+r; ox++)
  3824. {
  3825. for (oy=y; oy<=y+r; oy++)
  3826. {
  3827. if(ox>=0&&ox<XRES/CELL&&oy>=0&&oy<YRES/CELL)
  3828. {
  3829. i = ox;
  3830. j = oy;
  3831. if(b==4)
  3832. {
  3833. fvx[j][i] = 0.0f;
  3834. fvy[j][i] = 0.0f;
  3835. }
  3836. bmap[j][i] = b;
  3837. }
  3838. }
  3839. }
  3840. return 1;
  3841. }
  3842. if(c == SPC_AIR || c == SPC_HEAT || c == SPC_COOL || c == SPC_VACUUM)
  3843. {
  3844. for(j=-r; j<=r; j++)
  3845. for(i=-r; i<=r; i++)
  3846. if(i*i+j*j<=r*r)
  3847. create_part(-1, x+i, y+j, c);
  3848. return 1;
  3849. }
  3850.  
  3851. if(c == 0)
  3852. {
  3853. for(j=-r; j<=r; j++)
  3854. for(i=-r; i<=r; i++)
  3855. if(i*i+j*j<=r*r)
  3856. delete_part(x+i, y+j);
  3857. return 1;
  3858. }
  3859.  
  3860. for(j=-r; j<=r; j++)
  3861. for(i=-r; i<=r; i++)
  3862. if(i*i+j*j<=r*r)
  3863. if(create_part(-1, x+i, y+j, c)==-1)
  3864. f = 1;
  3865. return !f;
  3866. }
  3867.  
  3868. void create_line(int x1, int y1, int x2, int y2, int r, int c)
  3869. {
  3870. int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
  3871. float e, de;
  3872. if(cp)
  3873. {
  3874. y = x1;
  3875. x1 = y1;
  3876. y1 = y;
  3877. y = x2;
  3878. x2 = y2;
  3879. y2 = y;
  3880. }
  3881. if(x1 > x2)
  3882. {
  3883. y = x1;
  3884. x1 = x2;
  3885. x2 = y;
  3886. y = y1;
  3887. y1 = y2;
  3888. y2 = y;
  3889. }
  3890. dx = x2 - x1;
  3891. dy = abs(y2 - y1);
  3892. e = 0.0f;
  3893. if(dx)
  3894. de = dy/(float)dx;
  3895. else
  3896. de = 0.0f;
  3897. y = y1;
  3898. sy = (y1<y2) ? 1 : -1;
  3899. for(x=x1; x<=x2; x++)
  3900. {
  3901. if(cp)
  3902. create_parts(y, x, r, c);
  3903. else
  3904. create_parts(x, y, r, c);
  3905. e += de;
  3906. if(e >= 0.5f)
  3907. {
  3908. y += sy;
  3909. if(c==135 || c==140 || c==134 || c==133 || c==132 || c==131 || c==129 || c==128 || c==127 || c==125 || c==124 || c==123 || c==122 || !r)
  3910. {
  3911. if(cp)
  3912. create_parts(y, x, r, c);
  3913. else
  3914. create_parts(x, y, r, c);
  3915. }
  3916. e -= 1.0f;
  3917. }
  3918. }
  3919. }
Add Comment
Please, Sign In to add comment