DEADSOFTWARE

New implementation of module Items, *.cfg files now deprecated
[cavecraft.git] / src / items_logic.mpsrc
1 unit items_logic;
3 interface
4 function set_block_code(it,xx,yy:integer):boolean;//Выполнение кода при установке блока
5 procedure destroy_block_cr(id,xx,yy:integer);//Выполнение кода при разрушении блока в креативе
6 procedure destroy_block_0(id,xx,yy:integer);//Выполнение кода при разрушении блока не "тем" инструментом
7 procedure destroy_block_1(id,xx,yy:integer);//Выполнение кода при разрушении блока "нужным" инструментом
9 function useBlock(invcur, x, y:integer):boolean;
10 function useItem(invcur, x, y:integer):boolean;
12 procedure updateBlock(x, y:integer);
14 implementation
16 uses invui, maps, drop, console, furnace, png3, func, jpeg, mobs, vars, bmp, chest, inv, player, items_store, particles, worldgen, phy, sign, Blocks;
18 procedure usebonemeal(block:integer);
19 var
20 ix,iy,rnd_set:integer;
21 begin
22 if block=2 then
23 begin
24 for ix:=curx-4 to curx+4 do
25 for iy:=cury-4 to cury+4 do
26 begin
27 if (getmap(ix,iy+1)=2) and (getmap(ix,iy)=0) then
28 begin
29 rnd_set:=random(3);
30 if rnd_set=0 then setmap(22,ix,iy); else
31 if rnd_set=1 then setmap(23,ix,iy); else
32 if rnd_set=2 then setmap(57,ix,iy); else
33 end;
34 end;
35 inv.setSum(inv.getSum(invslot)-1, invslot);
36 inv.fixNull(invslot);
37 end; else
38 if block=122 then
39 begin
40 setmapinfo(3,curx,cury);
41 inv.setSum(inv.getSum(invslot)-1, invslot);
42 inv.fixNull(invslot);
43 end;
44 else
45 if (block=123) or (block=124) then
46 begin
47 setmapinfo(8,curx,cury);
48 inv.setSum(inv.getSum(invslot)-1, invslot);
49 inv.fixNull(invslot);
50 end;
51 else
52 if block=52 then
53 begin
54 genwood1(curx, cury);
55 inv.setSum(inv.getSum(invslot)-1, invslot);
56 inv.fixNull(invslot);
57 end;
58 else
59 if block=114 then
60 begin
61 genwood2(curx, cury);
62 inv.setSum(inv.getSum(invslot)-1, invslot);
63 inv.fixNull(invslot);
64 end;
65 else
66 if block=115 then
67 begin
68 genwood3(curx, cury);
69 inv.setSum(inv.getSum(invslot)-1, invslot);
70 inv.fixNull(invslot);
71 end;
72 end;
74 function searchportal(ix,iy:integer):boolean;
75 begin
76 if (getmap(ix+1,iy)=10) and (getmap(ix-1,iy-1)=10) and (getmap(ix+2,iy-1)=10) and (getmap(ix-1,iy-2)=10) and (getmap(ix+2,iy-2)=10) and (getmap(ix-1,iy-3)=10) and (getmap(ix+2,iy-3)=10) and (getmap(ix,iy-4)=10) and (getmap(ix+1,iy-4)=10) then
77 searchportal:=true; else
78 searchportal:=false;
79 end;
81 procedure create_screenshot_png;
82 var
83 screen:image;
84 date:string;
85 i,time:integer;
86 begin
87 time:=getCurrentTime;
88 screen:=ImageFromCanvas(0,0,getWidth,getHeight);
89 date:=''+getWeekDay(time)+'-'+getMonth(time)+'-'+getDay(time)+'_'+getHour(time)+'.'+getMinute(time)+'.'+getSecond(time);
90 i:=save_png(screen,sd+'/cavecraft/screenshots/'+date+'.png');
91 addToLog('Screenshot saved!');
92 end;
94 procedure create_screenshot_jpeg;
95 var
96 screen:image;
97 date:string;
98 time:integer;
99 begin
100 time:=getCurrentTime;
101 screen:=ImageFromCanvas(0,0,getWidth,getHeight);
102 date:=''+getWeekDay(time)+'-'+getMonth(time)+'-'+getDay(time)+'_'+getHour(time)+'.'+getMinute(time)+'.'+getSecond(time);
103 jpeg.saveimagetofile(screen,s_jpeg_quality,'/'+sd+'/cavecraft/screenshots/'+date+'.jpg');
104 addToLog('Screenshot saved!');
105 end;
107 procedure create_screenshot_bmp;
108 var
109 screen:image;
110 date:string;
111 time:integer;
112 begin
113 time:=getCurrentTime;
114 screen:=ImageFromCanvas(0,0,getWidth,getHeight);
115 date:=''+getWeekDay(time)+'-'+getMonth(time)+'-'+getDay(time)+'_'+getHour(time)+'.'+getMinute(time)+'.'+getSecond(time);
116 savebmp(screen,'/'+sd+'/cavecraft/screenshots/'+date+'.bmp');
117 addToLog('Screenshot saved!');
118 end;
120 procedure boom(rr,mm,xx,yy:integer);
121 var
122 ix,iy,iz,ir,imob,erru,minhp:integer;
123 rays:array [0..359] of integer;
124 mobs_minhp:array[0..31] of integer;
125 begin
126 {setmap(0,xx,yy);
127 setmapinfo(0,xx,yy);
128 for iz:=0 to 359 do
129 rays[iz]:=mm;
131 for ir:=1 to rr do
132 for iz:=0 to 359 do
133 if rays[iz]>0 then
134 begin
135 if (iz>=0) and (iz<=180) and (ir=1) then erru:=-1; else erru:=0;
136 if (iz>=180) and (iz<=360) and (ir=1) then erru:=1; else erru:=0;
137 ix:=xx+trunc(cos(iz)*ir)+erru;
138 iy:=yy+trunc(sin(iz)*ir)+erru;
139 rays[iz]:=rays[iz]-getBlockHp(getmap(ix,iy));
140 if rays[iz]<0 then rays[iz]:=0;
141 if coll_boom(ix,iy)=true then minhp:=minhp+(rays[iz]*2);
142 for imob:=0 to 31 do
143 if mob[imob].m_hp>0 then
144 begin
145 if mob_coll_boom(imob,ix,iy)=true then begin mobs_minhp[imob]:=mobs_minhp[imob]+(rays[iz]*2); mob[imob].m_hp:=0; end;
146 end;
147 if getmap(ix,iy)=27 then boom(4,100,ix,iy);
148 if getBlockHp(getmap(ix,iy))<=mm then
149 begin
150 if 30<=random(100) then destroy_block_1(getmap(ix,iy),ix,iy);
151 setmap(0,ix,iy);
152 Particles.Create(Particles.explosion, (ix * 16) + 8 - 16, (iy * 16) + 8 - 16);
153 end;
154 end;
155 minhp:=minhp/360;
156 hp:=hp-minhp;
157 for imob:=0 to 31 do
158 begin
159 mobs_minhp[imob]:=mobs_minhp[imob]/360;
160 mob[imob].m_hp:=mob[imob].m_hp-mobs_minhp[imob];
161 end;}
162 end;
164 procedure destroy_block_cr(id, xx, yy:integer);
165 begin
166 if id=27 then
167 begin
168 setmap(0,xx,yy);
169 setmapinfo(0,xx,yy);
170 end; else
171 if id=28 then
172 begin
173 setmap(0,xx,yy);
174 chest.destroy(false, xx, yy);
175 end; else
176 if id=62 then
177 begin
178 setmap(50,xx,yy);
179 end; else
180 if id=62 then
181 begin
182 setmap(0,xx,yy);
183 setmapinfo(0,xx,yy);
184 end; else
185 if id=66 then
186 begin
187 setmap(0,xx,yy);
188 setmapinfo(8,xx+1,yy);
189 end; else
190 if id=73 then
191 begin
192 setmap(0,xx,yy);
193 setmapinfo(8,xx+1,yy);
194 end; else
195 if id=77 then
196 begin
197 setmap(0,xx,yy);
198 setmap(0,xx+1,yy);
199 end; else
200 if id=78 then
201 begin
202 setmap(0,xx,yy);
203 setmap(0,xx-1,yy);
204 end; else
205 if id=79 then
206 begin
207 setmap(0,xx,yy);
208 setmap(0,xx,yy+1);
209 end; else
210 if id=80 then
211 begin
212 setmap(0,xx,yy);
213 setmap(0,xx,yy-1);
214 end; else
215 if id=81 then
216 begin
217 setmap(0,xx,yy);
218 setmap(0,xx,yy-1);
219 end; else
220 if id=82 then
221 begin
222 setmap(0,xx,yy);
223 setmap(0,xx,yy-1);
224 end; else
225 if id=102 then
226 begin
227 setmap(0,xx,yy);
228 chest.destroy(false, xx, yy);
229 end; else
230 if id=104 then
231 begin
232 setmap(0,xx,yy);
233 destsign(getmapinfo(xx,yy));
234 end; else
235 if (id = 106) or (id = 125) then
236 begin
237 setmap(0,xx,yy);
238 DestroyFurnace(xx, yy);
239 end; else
240 if id=121 then
241 begin
242 setmap(0,xx,yy);
243 setmapinfo(0,xx,yy);
244 end; else
245 if id=122 then
246 begin
247 setmap(0,xx,yy);
248 setmapinfo(0,xx,yy);
249 end; else
250 begin
251 setmap(0,xx,yy);
252 setmapinfo(0,xx,yy);
253 end;
254 end;
256 function set_block_code(it,xx,yy:integer):boolean;//Если false тогда блок устанавливается
257 begin
258 if it=28 then
259 begin
260 if chest.create(xx,yy)=-1 then set_block_code:=true;
261 end; else
262 if it=102 then
263 begin
264 if chest.create(xx,yy)=-1 then set_block_code:=true;
265 end;
266 if it=104 then
267 begin
268 if createsign(xx,yy)=-1 then set_block_code:=true;
269 end; else
270 if (it = 106) or (it = 125) then
271 begin
272 if CreateFurnace(xx, yy)=FURNACE_ERROR then
273 set_block_code:=true;
274 end; else
275 if it=121 then
276 begin
277 setmapinfo(16,xx,yy);
278 set_block_code:=false;
279 end; else
280 set_block_code:=false;
281 end;
283 procedure destroy_block_0(id,xx,yy:integer);
284 begin
285 if id=27 then
286 begin
287 setmapinfo(0,xx,yy);
288 end; else
289 if id=21 then
290 begin
291 if random(8)=random(8) then drop.create(201,1,xx*16+4,yy*16+4); else
292 if random(5)=random(5) then drop.create(52,1,xx*16+4,yy*16+4);
293 end; else
294 if id=28 then
295 begin
296 chest.destroy(false, xx, yy);
297 end; else
298 if id=57 then
299 begin
300 if random(4)=random(4) then drop.create(217,1,xx*16+4,yy*16+4);
301 end; else
302 if id=62 then
303 begin
304 setmap(50,xx,yy);
305 end; else
306 if id=62 then
307 begin
308 setmapinfo(0,xx,yy);
309 end; else
310 if id=77 then
311 begin
312 setmap(0,xx+1,yy);
313 end; else
314 if id=78 then
315 begin
316 setmap(0,xx-1,yy);
317 end; else
318 if id=79 then
319 begin
320 setmap(0,xx,yy+1);
321 end; else
322 if id=80 then
323 begin
324 setmap(0,xx,yy-1);
325 end; else
326 if id=81 then
327 begin
328 setmap(0,xx,yy+1);
329 end; else
330 if id=82 then
331 begin
332 setmap(0,xx,yy-1);
333 end; else
334 if id=102 then
335 begin
336 chest.destroy(true, xx, yy);
337 end; else
338 if id=104 then
339 begin
340 destsign(getmapinfo(xx,yy));
341 end; else
342 if (id = 106) or (id = 125) then
343 begin
344 DestroyFurnace(xx, yy);
345 end; else
346 if id=112 then
347 begin
348 if random(8)=random(8) then drop.create(201,1,xx*16+4,yy*16+4); else
349 if random(5)=random(5) then drop.create(114,1,xx*16+4,yy*16+4);
350 end; else
351 if id=87 then
352 begin
353 if random(10)=random(10) then drop.create(115,1,xx*16+4,yy*16+4);
354 end; else
355 if id=121 then
356 begin
357 setmap(0,xx,yy);
358 setmapinfo(0,xx,yy);
359 end; else
360 if id=122 then
361 begin
362 if getmapinfo(xx,yy)<3 then drop.create(217,random(4),xx*16+4,yy*16+4); else
363 if getmapinfo(xx,yy)=3 then begin drop.create(217,random(4),xx*16+4,yy*16+4); drop.create(218,1,xx*16+4,yy*16+4); end;
364 setmap(0,xx,yy);
365 setmapinfo(0,xx,yy);
366 end;
367 if (id=123) or (id=124) then
368 begin
369 drop.create(221+(id-123),random(4),xx*16+4,yy*16+4);
370 end;
371 //setmap(0,xx,yy);
372 //setmapinfo(0,xx,yy);
373 end;
375 procedure destroy_block_1(id,xx,yy:integer);
376 begin
377 if id=27 then
378 begin
379 setmap(0,xx,yy);
380 setmapinfo(0,xx,yy);
381 end; else
382 if id=2 then
383 begin
384 drop.create(1,1,xx*16+4,yy*16+4);
385 end; else
386 if id=3 then
387 begin
388 drop.create(5,1,xx*16+4,yy*16+4);
389 end; else
390 if id=8 then
391 begin
392 if random(10)=random(10) then drop.create(207,1,xx*16+4,yy*16+4); else
393 drop.create(8,1,xx*16+4,yy*16+4);
394 end; else
395 if id=11 then
396 begin
397 drop.create(170,3,xx*16+4,yy*16+4);
398 end; else
399 if id=18 then
400 begin
401 drop.create(160,1,xx*16+4,yy*16+4);
402 end; else
403 if id=19 then
404 begin
405 drop.create(162,1,xx*16+4,yy*16+4);
406 end; else
407 if id=20 then
408 begin
409 drop.create(161,4+random(2),xx*16+4,yy*16+4);
410 end; else
411 if id=28 then
412 begin
413 chest.destroy(true, xx, yy);
414 drop.create(28,1,xx*16+4,yy*16+4);
415 end; else
416 if id=48 then
417 begin
418 drop.create(1,1,xx*16+4,yy*16+4);
419 end; else
420 if id=50 then
421 begin
422 drop.create(0,0,xx*16+4,yy*16+4);
423 end; else
424 if id=51 then
425 begin
426 drop.create(0,0,xx*16+4,yy*16+4);
427 end; else
428 if id=54 then
429 begin
430 drop.create(166,4+random(4),xx*16+4,yy*16+4);
431 end; else
432 if id=59 then
433 begin
434 drop.create(167,1,xx*16+4,yy*16+4);
435 end; else
436 if id=61 then
437 begin
438 drop.create(168,4+random(2),xx*16+4,yy*16+4);
439 end; else
440 if id=62 then
441 begin
442 setmap(0,xx,yy);
443 end; else
444 if id=63 then
445 begin
446 drop.create(168,1,xx*16+4,yy*16+4);
447 end; else
448 if id=64 then
449 begin
450 drop.create(169,4,xx*16+4,yy*16+4);
451 end; else
452 if id=66 then
453 begin
454 setmapinfo(8,xx+1,yy);
455 drop.create(66,1,xx*16+4,yy*16+4);
456 end; else
457 if id=73 then
458 begin
459 drop.create(176,3+random(4),xx*16+4,yy*16+4);
460 setmapinfo(8,xx+1,yy);
461 end; else
462 if id=74 then
463 begin
464 drop.create(1,1,xx*16+4,yy*16+4);
465 end; else
466 if id=75 then
467 begin
468 drop.create(9,1,xx*16+4,yy*16+4);
469 end; else
470 if id=76 then
471 begin
472 setmapinfo(0,xx,yy);
473 end; else
474 if id=77 then
475 begin
476 drop.create(179,1,xx*16+4,yy*16+4);
477 setmap(0,xx+1,yy);
478 end; else
479 if id=78 then
480 begin
481 drop.create(179,1,xx*16+4,yy*16+4);
482 setmap(0,xx-1,yy);
483 end; else
484 if id=79 then
485 begin
486 drop.create(178,1,xx*16+4,yy*16+4);
487 setmap(0,xx,yy+1);
488 end; else
489 if id=80 then
490 begin
491 drop.create(178,1,xx*16+4,yy*16+4);
492 setmap(0,xx,yy-1);
493 end; else
494 if id=81 then
495 begin
496 drop.create(178,1,xx*16+4,yy*16+4);
497 setmap(0,xx,yy+1);
498 end; else
499 if id=82 then
500 begin
501 drop.create(178,1,xx*16+4,yy*16+4);
502 setmap(0,xx,yy-1);
503 end; else
504 if id=84 then
505 begin
506 drop.create(83,1,xx*16+4,yy*16+4);
507 end; else
508 if id=86 then
509 begin
510 drop.create(85,1,xx*16+4,yy*16+4);
511 end; else
512 if id=88 then
513 begin
514 drop.create(24,random(3)-1,xx*16+4,yy*16+4);
515 end; else
516 if id=89 then
517 begin
518 drop.create(24,random(3)-1,xx*16+4,yy*16+4);
519 end; else
520 if id=90 then
521 begin
522 drop.create(25,random(3)-1,xx*16+4,yy*16+4);
523 end; else
524 if id=91 then
525 begin
526 drop.create(25,random(3)-1,xx*16+4,yy*16+4);
527 end; else
528 if id=93 then
529 begin
530 drop.create(92,1,xx*16+4,yy*16+4);
531 end; else
532 if id=94 then
533 begin
534 drop.create(4,1,xx*16+4,yy*16+4);
535 end; else
536 if id=95 then
537 begin
538 drop.create(187,1,xx*16+4,yy*16+4);
539 end; else
540 if id=95 then
541 begin
542 drop.create(187,1,xx*16+4,yy*16+4);
543 end; else
544 if id=95 then
545 begin
546 drop.create(187,1,xx*16+4,yy*16+4);
547 end; else
548 if id=96 then
549 begin
550 drop.create(187,1,xx*16+4,yy*16+4);
551 end; else
552 if id=97 then
553 begin
554 drop.create(187,1,xx*16+4,yy*16+4);
555 end; else
556 if id=98 then
557 begin
558 drop.create(187,1,xx*16+4,yy*16+4);
559 end; else
560 if id=99 then
561 begin
562 drop.create(187,1,xx*16+4,yy*16+4);
563 end; else
564 if id=100 then
565 begin
566 drop.create(187,1,xx*16+4,yy*16+4);
567 end; else
568 if id=101 then
569 begin
570 drop.create(187,1,xx*16+4,yy*16+4);
571 end; else
572 if id=102 then
573 begin
574 chest.destroy(true, xx, yy);
575 drop.create(28,1,xx*16+4,yy*16+4);
576 end; else
577 if id=104 then
578 begin
579 destsign(getmapinfo(xx,yy));
580 drop.create(104,1,xx*16+4,yy*16+4);
581 end; else
582 if (id = 106) or (id = 125) then
583 begin
584 setmap(0,xx,yy);
585 DestroyFurnace(xx, yy);
586 end; else
587 if id=107 then
588 begin
589 drop.create(108,1,xx*16+4,yy*16+4);
590 end; else
591 if id=111 then
592 begin
593 drop.create(214,random(4)+1,xx*16+4,yy*16+4);
594 end; else
595 if id=117 then
596 begin
597 drop.create(116,1,xx*16+4,yy*16+4);
598 end; else
599 if id=118 then
600 begin
601 drop.create(10,1,xx*16+4,yy*16+4);
602 end; else
603 if id=120 then
604 begin
605 drop.create(1,1,xx*16+4,yy*16+4);
606 end; else
607 if id=121 then
608 begin
609 setmap(0,xx,yy);
610 setmapinfo(0,xx,yy);
611 end; else
612 if id=122 then
613 begin
614 if getmapinfo(xx,yy)<3 then drop.create(217,random(2),xx*16+4,yy*16+4); else
615 if getmapinfo(xx,yy)=3 then begin drop.create(217,random(2),xx*16+4,yy*16+4); drop.create(218,1,xx*16+4,yy*16+4); end;
616 setmap(0,xx,yy);
617 setmapinfo(0,xx,yy);
618 end; else
619 if (id=123) or (id=124) then
620 begin
621 drop.create(221+(id-123),random(4),xx*16+4,yy*16+4);
622 end; else
623 begin
624 setmapinfo(0,xx,yy);
625 drop.create(id,1,xx*16+4,yy*16+4);
626 end;
627 end;
629 procedure decItem(invcur:integer);
630 begin
631 if gamemode<>1 then
632 begin
633 inv.setSum(inv.getSum(invcur)-1, invcur);
634 inv.fixNull(invcur);
635 end;
636 end;
638 //Возвращает true если блок небыл использован.
639 function useBlock(invcur, x, y:integer):boolean;
640 var
641 item, sum, block, info:integer;
642 begin
643 item:=inv.getItem(invcur);
644 sum:=inv.getSum(invcur);
645 block:=getMap(x, y);
646 info:=getMapInfo(x, y);
648 if (block=28) or (block=102) then
649 begin
650 if info<=MAX_CHEST then
651 OpenChestWindow(info);
652 end;
653 else
654 if block=29 then
655 OpenFastCraftWindow(1);
656 else
657 if block=79 then
658 begin
659 setMap(81, x, y);
660 setMap(82, x, y+1);
661 end;
662 else
663 if block=80 then
664 begin
665 setMap(81, x, y-1);
666 setMap(82, x, y);
667 end;
668 else
669 if block=81 then
670 begin
671 setMap(79, x, y);
672 setMap(80, x, y+1);
673 end;
674 else
675 if block=82 then
676 begin
677 setMap(79, x, y-1);
678 setMap(80, x, y);
679 end;
680 /*else
681 if block=104 then
682 keymode:=5;*/
683 else
684 if (block = 106) or (block = 125) then
685 OpenFurnaceWindow(info);
686 else
687 if block=107 then
688 setMap(108, x, y);
689 else
690 if block=108 then
691 setMap(107, x, y);
692 else
693 if block=116 then
694 setMap(117, x, y);
695 else
696 if block=117 then
697 setMap(116, x, y);
698 else
699 if block=121 then
700 begin
701 if hunger<20 then
702 begin
703 hunger:=hunger+2;
704 info:=info-2;
705 if (info=14) or (info=2) then
706 info:=info-2;
707 if info<1 then
708 setMap(0, x, y);
709 else
710 setMapInfo(info, x, y);
711 end;
712 end;
713 else
714 useBlock:=true;
716 /*
719 if (getmap(curx,cury)=1) or (getmap(curx,cury)=2) or (getmap(curx,cury)=48) or (getmap(curx,cury)=74) then
720 begin
721 if (get_item(0, item)=1) and (get_tool(0, item)=6) and (sum>0) and (getmap(curx,cury-1)=0) then
722 begin
723 setmap(120,curx,cury);
724 inv.setSum(inv.getSum(invslot)-1, invslot);
725 inv.fixNull(invslot);
726 end;
727 end;
728 else
729 if (getmap(curx,cury)=77) or (getmap(curx,cury)=78) then
730 begin
731 if pl_world=0 then
732 sleep;
733 else
734 boom(4,100,curx,cury);
735 end;*/
736 end;
738 function useItem(invcur, x, y:integer):boolean;
739 var
740 item, sum, block, info:integer;
741 begin
742 if inv.isNull(invcur) then
743 useItem:=true;
745 item:=inv.getItem(invcur);
746 sum:=inv.getSum(invcur);
747 block:=getMap(x, y);
748 info:=getMapInfo(x, y);
750 if item=171 then
751 begin
752 if block=50 then
753 begin
754 inv.setItem(172, invcur);
755 setMap(0, x, y);
756 end;
757 else
758 if block=51 then
759 begin
760 inv.setItem(173, invcur);
761 setMap(0, x, y);
762 end;
763 end;
764 else
765 if item=220 then
766 usebonemeal(block);
767 else
768 if item=217 then
769 begin
770 if (block=120) and (getMap(x, y-1)=0) then
771 begin
772 setMap(122, x, y-1);
773 decItem(invcur);
774 end;
775 end;
776 else
777 if item=221 then
778 begin
779 if (block=120) and (getMap(x, y-1)=0) then
780 begin
781 setMap(123, x, y-1);
782 setMapInfo(1, x, y-1);
783 decItem(invcur);
784 end;
785 end;
786 else
787 if item=222 then
788 begin
789 if (block=120) and (getMap(x, y-1)=0) then
790 begin
791 setMap(124, x, y-1);
792 setMapInfo(1, x, y-1);
793 decItem(invcur);
794 end;
795 end;
796 else
797 if item=172 then
798 begin
799 if (block=0) then
800 begin
801 inv.setItem(171, invcur);
802 setMap(50, x, y);
803 end;
804 end;
805 else
806 if item=173 then
807 begin
808 if (block=0) then
809 begin
810 inv.setItem(171, invcur);
811 setMap(51, x, y);
812 end;
813 end;
814 else
815 if item=176 then
816 begin
817 if hunger<20 then
818 begin
819 hunger:=hunger+2;
820 if hunger>20 then
821 hunger:=20;
822 decItem(invcur);
823 end;
824 end;
825 else
826 if item=177 then
827 begin
828 {if random(10)=random(10) then
829 create_mob(4, x*16, y*16);}
830 decItem(invcur);
831 end;
832 else
833 if item=178 then
834 begin
835 if (block=0) and (getMap(x, y-1)=0) then
836 begin
837 setMap(81, x, y-1);
838 setMap(82, x, y);
839 decItem(invcur);
840 end;
841 end;
842 else
843 if item=179 then
844 begin
845 if (block=0) and (getMap(x+1, y)=0) then
846 begin
847 setMap(77, x, y);
848 setMap(78, x+1, y);
849 decItem(invcur);
850 end;
851 end;
852 else
853 if item=180 then
854 begin
855 if getBlockColl(block)=0 then
856 begin
857 Mobs.Create(Mobs.zomby, x * 16, y * 16);
858 decItem(invcur);
859 end;
860 end;
861 else
862 if item=181 then
863 begin
864 if getBlockColl(block)=0 then
865 begin
866 //create_mob(2, x*16, y*16);
867 decItem(invcur);
868 end;
869 end;
870 else
871 if item=182 then
872 begin
873 if getBlockColl(block)=0 then
874 begin
875 //create_mob(3, x*16, y*16);
876 decItem(invcur);
877 end;
878 end;
879 else
880 if item=185 then
881 begin
882 if hunger<20 then
883 begin
884 inv.setItem(184, invslot);
885 hunger:=hunger+6;
886 if hunger>20 then
887 hunger:=20;
888 end;
889 end;
890 else
891 if item=187 then
892 begin
893 if block=0 then
894 begin
895 setMap(95+random(7), x, y);
896 decItem(invcur);
897 end;
898 end;
899 else
900 if item=188 then
901 begin
902 if hunger<20 then
903 begin
904 hunger:=hunger+3;
905 if hunger>20 then
906 hunger:=20;
907 decItem(invcur);
908 end;
909 end;
910 else
911 if item=189 then
912 begin
913 if hunger<20 then
914 begin
915 hunger:=hunger+8;
916 if hunger>20 then
917 hunger:=20;
918 decItem(invcur);
919 end;
920 end;
921 else
922 if item=190 then
923 begin
924 if hunger<20 then
925 begin
926 hunger:=hunger+4;
927 if hunger>20 then
928 hunger:=20;
929 decItem(invcur);
930 end;
931 end;
932 else
933 if item=191 then
934 create_screenshot_png;
935 else
936 if item=192 then
937 create_screenshot_jpeg;
938 else
939 if item=193 then
940 create_screenshot_bmp;
941 else
942 if item=196 then
943 begin
944 if hunger<20 then
945 begin
946 hp:=hp-4;
947 hunger:=hunger+2;
948 if hunger>20 then
949 hunger:=20;
950 decItem(invcur);
951 end;
952 end;
953 else
954 if item=199 then
955 begin
956 if hunger<20 then
957 begin
958 hunger:=hunger+3;
959 if hunger>20 then
960 hunger:=20;
961 decItem(invcur);
962 end;
963 end;
964 else
965 if item=200 then
966 begin
967 if hunger<20 then
968 begin
969 hunger:=hunger+8;
970 if hunger>20 then
971 hunger:=20;
972 decItem(invcur);
973 end;
974 end;
975 else
976 if item=201 then
977 begin
978 if hunger<20 then
979 begin
980 hunger:=hunger+4;
981 if hunger>20 then
982 hunger:=20;
983 decItem(invcur);
984 end;
985 end;
986 else
987 if item=202 then
988 begin
989 if hp<20 then
990 begin
991 hp:=20;
992 decItem(invcur);
993 end;
994 end;
995 else
996 if item=203 then
997 begin
998 if hunger<20 then
999 begin
1000 hunger:=hunger+2;
1001 if hunger>20 then
1002 hunger:=20;
1003 decItem(invcur);
1004 end;
1005 end;
1006 else
1007 if item=204 then
1008 begin
1009 if hunger<20 then
1010 begin
1011 hunger:=hunger+6;
1012 if hunger>20 then
1013 hunger:=20;
1014 decItem(invcur);
1015 end;
1016 end;
1017 else
1018 if item=205 then
1019 begin
1020 if getBlockColl(block)=0 then
1021 begin
1022 //create_mob(4, x*16, y*16);
1023 decItem(invcur);
1024 end;
1025 end;
1026 else
1027 if item=206 then
1028 begin
1029 if getBlockColl(block)=0 then
1030 begin
1031 //create_mob(5, x*16, y*16);
1032 decItem(invcur);
1033 end;
1034 end;
1035 else
1036 if item=208 then
1037 begin
1038 if getBlockColl(block)=0 then
1039 begin
1040 //create_mob(6, x*16, y*16);
1041 decItem(invcur);
1042 end;
1043 end;
1044 else
1045 if item=209 then
1046 begin
1047 if getBlockColl(block)=0 then
1048 begin
1049 //create_mob(7, x*16, y*16);
1050 decItem(invcur);
1051 end;
1052 end;
1053 else
1054 if item=213 then
1055 begin
1056 if getBlockColl(block)=0 then
1057 begin
1058 //create_mob(8, x*16, y*16);
1059 decItem(invcur);
1060 end;
1061 end;
1062 else
1063 if item=212 then
1064 begin
1065 if getBlockColl(block)=0 then
1066 begin
1067 //create_mob(10, x*16, y*16);
1068 decItem(invcur);
1069 end;
1070 end;
1071 else
1072 if item=210 then
1073 begin
1074 if hunger<20 then
1075 begin
1076 hunger:=hunger+2;
1077 if hunger>20 then
1078 hunger:=20;
1079 decItem(invcur);
1080 end;
1081 end;
1082 else
1083 if item=211 then
1084 begin
1085 if hunger<20 then
1086 begin
1087 hunger:=hunger+5;
1088 if hunger>20 then
1089 hunger:=20;
1090 decItem(invcur);
1091 end;
1092 end;
1093 else
1094 if item=219 then
1095 begin
1096 if hunger<20 then
1097 begin
1098 hunger:=hunger+5;
1099 if hunger>20 then
1100 hunger:=20;
1101 decItem(invcur);
1102 end;
1103 end;
1104 else
1105 if item=153 then
1106 begin
1107 if block=10 then
1108 begin
1109 if searchportal(x , y)=true then
1110 begin
1111 genportal(x-1, y-4);
1112 decItem(invcur);
1113 end;
1114 else
1115 if searchportal(x-1, y)=true then
1116 begin
1117 genportal(x-2, y-4);
1118 decItem(invcur);
1119 end;
1120 end;
1121 else
1122 if block=27 then
1123 begin
1124 setmapinfo(getrelativetimems/1000-(getrelativetimems/1000 div 100*100),curx,cury);
1125 decItem(invcur);
1126 end;
1127 end;
1128 else
1129 if item=152 then
1130 begin
1131 if block=50 then
1132 begin
1133 fish:=true;
1134 fish_time:=getrelativetimems;
1135 fx:=curx;
1136 fy:=cury;
1137 end;
1138 end;
1139 else
1140 useItem:=true;
1141 end;
1143 procedure fluidLogic(x, y, ifbx, thenbx, ifby, thenby:integer);
1144 var
1145 block, blockXm1, blockXp1, blockYp1:integer;
1146 begin
1147 block:=getMap(x, y);
1148 blockXm1:=getMap(x-1, y);
1149 blockXp1:=getMap(x+1, y);
1150 blockYp1:=getMap(x, y+1);
1152 //Если внизу условный блок, то заменяем.
1153 if blockYp1=ifby then
1154 setMap(thenby, x, y+1);
1155 else
1156 //Если нижний блок можно уничтожить, то ставим туда копию
1157 if Blocks.IsOverlapped(blockYp1) then
1158 begin
1159 destroy_block_0(blockYp1, x, y+1);
1160 setMap(block, x, y+1);
1161 end;
1162 //Если ничего не можем, то пытаемся течь по сторонам
1163 else
1164 begin
1165 if blockXm1=ifbx then
1166 setMap(thenbx, x-1, y);
1167 else
1168 if Blocks.IsOverlapped(blockXm1) then
1169 begin
1170 destroy_block_1(blockXm1, x-1, y);
1171 setMap(block, x-1, y);
1172 end;
1174 if blockXp1=ifbx then
1175 setMap(thenbx, x+1, y);
1176 else
1177 if Blocks.IsOverlapped(blockXp1) then
1178 begin
1179 destroy_block_1(blockXp1, x+1, y);
1180 setMap(block, x+1, y);
1181 end;
1182 end;
1183 end;
1185 procedure updateBlock(x, y:integer);
1186 const
1187 GRASS_RND=128;
1188 TORCH_RND=10;
1189 SPAWN_RND=128;
1190 SPAWN_RAD=128;
1191 GENWOOD_RND=1024;
1192 LIAN_RND=32;
1193 CORN_RND=512;
1194 var
1195 plx, ply, block, light, info:integer;
1196 begin
1197 plx:=player.getX;
1198 ply:=player.getY;
1199 block:=getMap(x, y);
1200 light:=getMapLight(x, y);
1201 info:=getMapInfo(x, y);
1203 if block=2 then
1204 begin
1205 //Трава разрастается при условии что освещение выше чем 3
1206 if (light = 0) or (Blocks.IsOverlapped(getMap(x, y - 1)) = false) then
1207 setMap(1, x, y);
1208 else
1209 if light>3 then
1210 begin
1211 if (getMap(x-1, y)=1) and (getMap(x-1, y-1)=0) then
1212 if random(GRASS_RND)=random(GRASS_RND) then
1213 setMap(2, x-1, y);
1215 if (getMap(x+1, y)=1) and (getMap(x+1, y-1)=0) then
1216 if random(GRASS_RND)=random(GRASS_RND) then
1217 setMap(2, x+1, y);
1218 end;
1219 end;
1220 else
1221 if block=7 then
1222 begin
1223 if Blocks.IsOverlapped(getMap(x, y+1)) then
1224 begin
1225 setMap(0, x, y);
1226 setMap(7, x, y+1);
1227 end;
1228 end;
1229 else
1230 if block=8 then
1231 begin
1232 if Blocks.IsOverlapped(getMap(x, y+1)) then
1233 begin
1234 setMap(0, x, y);
1235 setMap(8, x, y+1);
1236 end;
1237 end;
1238 else
1239 if block=26 then
1240 begin
1241 if random(TORCH_RND)=random(TORCH_RND) then
1242 Particles.Create(Particles.graySmoke, x * 16 + 4, y * 16 + 4);
1243 end;
1244 else
1245 if block=50 then
1246 begin
1247 fluidLogic(x, y, 51, 10, 51, 10);
1248 end;
1249 else
1250 if block=51 then
1251 begin
1252 fluidLogic(x, y, 50, 5, 50, 3);
1253 end;
1254 else
1255 if block=63 then
1256 begin
1257 // В зимнем биоме снег не растапливается при сильном свете
1258 if ((light > 7) and (getBiomMap(x) <> 2)) or (getMap(x, y + 1) = 0) then
1259 setmap(0, x, y);
1260 end;
1261 else
1262 if block=74 then
1263 begin
1264 if Blocks.IsOverlapped(getMap(x, y-1))=false then
1265 setMap(1, x, y);
1266 else
1267 if light>3 then
1268 begin
1269 if (getMap(x-1, y)=1) and (getMap(x-1, y-1)=0) then
1270 if random(GRASS_RND)=random(GRASS_RND) then
1271 setMap(74, x-1, y);
1273 if (getMap(x+1, y)=1) and (getMap(x+1, y-1)=0) then
1274 if random(GRASS_RND)=random(GRASS_RND) then
1275 setMap(74, x+1, y);
1276 end;
1277 end;
1278 else
1279 if block=77 then
1280 begin
1281 if getmap(x+1, y)<>78 then
1282 setMap(0, x, y);
1283 end;
1284 else
1285 if block=78 then
1286 begin
1287 if getmap(x-1, y)<>77 then
1288 setMap(0, x, y);
1289 end;
1290 else
1291 if block=79 then
1292 begin
1293 if getmap( x, y+1)<>80 then
1294 setMap(0, x, y);
1295 end;
1296 else
1297 if block=80 then
1298 begin
1299 if getmap(x, y-1)<>79 then
1300 setMap(0, x, y);
1301 end;
1302 else
1303 if block=81 then
1304 begin
1305 if getmap(x, y+1)<>82 then
1306 setMap(0, x, y);
1307 end; else
1308 if block=82 then
1309 begin
1310 if getmap(x, y-1)<>81 then
1311 setmap(0, x, y);
1312 end; else
1313 if block=76 then
1314 begin
1315 {if CollTwoObj(plx, ply, player.getW, player.getH, x*16-SPAWN_RAD, y*16-SPAWN_RAD, x*16+SPAWN_RAD, y*16+SPAWN_RAD) then
1316 if random(SPAWN_RND)=random(SPAWN_RND) then
1317 create_mob(getMapInfo(x, y), x*16,(y-2)*16);}
1318 end;
1319 else
1320 if block=52 then
1321 begin
1322 if random(GENWOOD_RND)=random(GENWOOD_RND) then
1323 genwood1(x, y);
1324 end;
1325 else
1326 if block=114 then
1327 begin
1328 if random(GENWOOD_RND)=random(GENWOOD_RND) then
1329 genwood2(x, y);
1330 end;
1331 else
1332 if block=115 then
1333 begin
1334 if random(GENWOOD_RND)=random(GENWOOD_RND) then
1335 genwood3(x, y);
1336 end;
1337 else
1338 if block=103 then
1339 begin
1340 if (getmap(x, y-1)=0) then
1341 setmap(0, x, y);
1342 else
1343 if (getmap(x, y+1)=0) and (random(LIAN_RND)=random(LIAN_RND)) then
1344 setmap(103, x, y+1);
1345 end;
1346 else
1347 if block=105 then
1348 begin
1349 if random(TORCH_RND)=random(TORCH_RND) then
1350 Particles.Create(Particles.redSmoke, x * 16 + 4, y * 16 + 4);
1351 end;
1352 else
1353 if (block = 106) or (block = 125) then
1354 begin
1355 if furnaceBurn(getMapInfo(x, y)) then
1356 setmap(125, x, y);
1357 else
1358 setmap(106, x, y);
1359 end;
1360 else
1361 if block=110 then
1362 begin
1363 if (getmap(x-1, y)=0) or (getmap(x+1, y)=0) or (getmap(x, y-1)=0) or (getmap(x, y+1)=0) then
1364 setmap(0, x, y);
1365 end;
1366 else
1367 if block=30 then
1368 begin
1369 if (random(GENWOOD_RND) = random(GENWOOD_RND)) and (getMap(x, y + 2) <> 30) then
1370 setMap(30, x, y - 1);
1371 if (getMap(x, y + 1) <> 7) and (getMap(x, y + 1) <> 30) then
1372 begin
1373 setMap(0, x, y);
1374 destroy_block_1(block, x, y);
1375 end;
1376 end; else
1377 if block=65 then
1378 begin
1379 if (random(GENWOOD_RND)=random(GENWOOD_RND)) and (getMap(x, y+2)<>65) then
1380 setMap(65, x, y-1);
1381 if (getMap(x, y+1)=0) then
1382 begin
1383 setMap(0, x, y);
1384 destroy_block_1(block, x, y);
1385 end;
1386 end;
1387 else
1388 if block=122 then
1389 begin
1390 if random(CORN_RND)=random(CORN_RND) then
1391 info:=info+1;
1392 if info>3 then
1393 info:=3;
1394 if getmap(x, y+1)<>120 then
1395 setMap(0, x, y);
1396 setMapInfo(info, x, y);
1397 end; else
1398 if block=123 then
1399 begin
1400 if random(CORN_RND)=random(CORN_RND) then
1401 info:=info+1;
1402 if info>9 then
1403 info:=9;
1404 if getmap(x, y+1)<>120 then
1405 setMap(0, x, y);
1407 if (info=0) and (getMap(x-1, y)=0) and (getBlockColl(getMap(x-1, y+1))>0) then
1408 setmap(73, x-1, y);
1410 if (getMap(x-1, y)=73) and (getMapinfo(x, y)<>9) then
1411 info:=9;
1413 setMapInfo(info, x, y);
1414 end;
1415 else
1416 if block=124 then
1417 begin
1418 if random(CORN_RND)=random(CORN_RND) then
1419 info:=info+1;
1420 if info>9 then
1421 info:=9;
1422 if getmap(x, y+1)<>120 then
1423 setMap(0, x, y);
1425 if (info=0) and (getMap(x-1, y)=0) and (getBlockColl(getMap(x-1, y+1))>0) then
1426 setmap(66, x-1, y);
1428 if (getMap(x-1, y)=66) and (getMapinfo(x, y)<>9) then
1429 info:=9;
1431 setMapInfo(info, x, y);
1432 end;
1433 else
1434 if block=27 then
1435 begin
1436 if info<>0 then
1437 if getrelativetimems/1000-(getrelativetimems/1000 div 100*100)-info>3 then
1438 boom(4, 100, x, y);
1439 end;
1440 end;
1442 end.