DEADSOFTWARE

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