DEADSOFTWARE

New implementation of module Items, *.cfg files now deprecated
[cavecraft.git] / src / CAVE.mpsrc
1 program CAVE;
3 uses
4 Items,
5 sign,
6 jsr75i,
7 drop,
8 invui,
9 vars,
10 randoms,
11 memory,
12 worldgen,
13 canvas,
14 safeload,
15 mobs,
16 console,
17 effects,
18 particles,
19 keyboard,
20 maps,
21 phy,
22 utils,
23 func,
24 CellUI,
25 furnace,
26 player,
27 items_logic,
28 chest,
29 inv,
30 items_store,
31 video,
32 Blocks;
34 const
35 version_map = 9;
37 var
38 keymode,updx,updy:integer;
39 seed,nextseed:integer;
40 free_ram:real;
42 light:array [0..15] of image;
43 bg:array[0..1] of image;
44 osad:array [0..1,0..7] of image;
45 back:array [0..8] of image;
46 gui:array [0..34] of image;
47 tue:array [0..9] of image;
49 sign_im:image;
50 sky:image;
51 sun:image;
52 moon:image;
53 moon_phase:integer;
54 toolus,toolind:integer;
55 osadki_ani:integer;
56 sav_fl:string;
57 global_light:integer;
58 world_typ:integer;
59 float:image;
61 msg:array [0..4] of string;
62 msg_time:array[0..4] of integer;
63 last_sleep_x,last_sleep_y:integer;
65 ifminimap:boolean;
66 gt:integer;
68 del,dt,time:integer;
70 deb:boolean;
72 procedure newworld;
73 var
74 ix,iy:integer;
75 begin
76 if nextseed=0 then seed:=getrelativetimems; else seed:=nextseed;
77 nextseed:=0;
78 srand(seed);
79 if world_typ=0 then genworld;
80 else
81 if world_typ=1 then genflat;
82 world_typ:=0;
83 player.setX(get_spawn_x*16+4);
84 player.setY(get_spawn_y*16);
85 pl_world:=0;
86 end;
88 procedure drwrect(x,y,w,h,t:integer);
89 var
90 i:integer;
91 begin
92 for i:=0 to t do
93 drawrect(x+i,y+i,w-i*2,h-i*2);
94 end;
96 procedure proc_fps;
97 begin
98 dt:=GetRelativeTimeMs - time;
99 time:=GetRelativeTimeMs;
100 fps:=1000/dt;
101 end;
103 procedure maxfps;
104 begin
105 if fps<s_max_fps then if del>0 then del:=del-1;
106 if fps>s_max_fps then if del<200 then del:=del+1;
107 delay(del);
108 end;
110 procedure ClearTextures;
111 var
112 no : image;
113 ix, iy, iz : integer;
114 begin
115 bg[0] := no;
116 bg[1] := no;
117 float := no;
118 compas := no;
119 for ix := 0 to 7 do
120 Vars.clock[ix] := no;
122 for ix := 0 to maxBlockTex do
123 begin
124 tex[ix] := no;
125 tex8[ix] := no;
126 end;
127 for ix := 0 to maxItemTex do
128 begin
129 item[ix] := no;
130 item8[ix] := no;
131 end;
133 for ix := 0 to 8 do
134 back[ix]:=no;
136 player.freeSkin;
138 for ix := 0 to 34 do
139 gui[ix] := no;
140 for ix := 0 to 9 do
141 tue[ix] := no;
142 for ix := 0 to 7 do
143 osad[0, ix] := no;
144 for ix := 0 to 7 do
145 osad[1, ix] := no;
147 for ix := 0 to 15 do
148 light[ix] := no;
150 Particles.FreeTextures;
151 Mobs.FreeTextures;
153 sky := no;
154 sun := no;
155 moon := no;
156 sign_im := no;
158 for ix := 0 to CONST_MAX_CURS do
159 LoadCurImg(no, ix);
161 //resetVirtualKeyboard(-1);
162 end;
164 procedure create_msg(s:string);
165 var
166 i,t:integer;
167 begin
168 for i:=3 downto 0 do
169 begin
170 if i=0 then break;
171 msg_time[i]:=msg_time[i-1];
172 msg[i]:=msg[i-1];
173 end;
174 msg_time[0]:=getrelativetimems;
175 msg[0]:=s;
176 end;
178 procedure loadtexture(path:string);
179 var
180 ix,iy,iz:integer;
181 im:image;
182 begin
183 cleartextures;
184 im:=ld_tex('background.png',path,'title/');
185 for ix:=0 to 1 do
186 bg[ix]:=rotate_image_from_image(im,ix*16,0,16,16,0);
187 float:=ld_tex('float.png',path,'gui/');
188 compas:=ld_tex('compass.png',path,'gui/');
189 im:=ld_tex('clock.png',path,'gui/');
190 for ix:=0 to 7 do
191 Vars.clock[ix]:=rotate_image_from_image(im,ix*16,0,16,16,0);
192 if load_back_tex then
193 begin
194 im:=ld_tex('back.png',path,'');
195 for ix:=0 to 8 do back[ix]:=rotate_image_from_image(im,ix*16,0,16,16,0);
196 end;
198 console.exec('textures.cfg', 'AUTO');
200 Player.LoadSkin('char_ani.png', path);
201 Mobs.LoadTextures(path);
203 im:=ld_tex('gui.png',path,'gui/');
204 gui[0]:=rotate_image_from_image(im,0,0,16,16,0);
205 LoadCurImg(gui[0], CUR_SELECT1);
206 gui[1]:=rotate_image_from_image(im,0,16,168,21,0);
207 gui[3]:=rotate_image_from_image(im,16,0,16,16,0);
208 LoadCurImg(gui[3], CUR_SELECT2);
209 gui[6]:=rotate_image_from_image(im,0,56,120,12,0);
210 gui[7]:=rotate_image_from_image(im,0,68,120,12,0);
211 gui[8]:=rotate_image_from_image(im,0,80,120,12,0);
212 gui[13]:=rotate_image_from_image(im,1,93,9,9,0);//hp
213 gui[14]:=rotate_image_from_image(im,12,93,9,9,0);//hp
214 gui[15]:=rotate_image_from_image(im,23,93,9,9,0);//hp
215 gui[17]:=rotate_image_from_image(im,120,56,18,18,0);
217 gui[26]:=rotate_image_from_image(im,89,93,9,9,0);//hunger
218 gui[27]:=rotate_image_from_image(im,100,93,9,9,0);//hunger
219 gui[28]:=rotate_image_from_image(im,111,93,9,9,0);//hunger
221 gui[29]:=rotate_image_from_image(im,67,93,9,9,0);//air
222 gui[30]:=rotate_image_from_image(im,78,93,9,9,0);//air
224 gui[31]:=rotate_image_from_image(im,122,93,9,9,0);//hp hardcore
225 gui[32]:=rotate_image_from_image(im,133,93,9,9,0);//hp hardcore
226 gui[33]:=rotate_image_from_image(im,144,93,9,9,0);//hp hardcore
228 gui[20]:=rotate_image_from_image(im,121,75,9,13,0);
229 gui[21]:=rotate_image_from_image(im,130,75,9,13,0);
230 gui[22]:=rotate_image_from_image(im,0,103,120,12,0);
232 if load_minimap_tex then gui[16]:=ld_tex('mapbg.png',path,'gui/');
234 for ix:=0 to 9 do tue[ix]:=rotate_image_from_image(im,16*ix,40,16,16,0);
236 if load_weather_tex then
237 begin
238 im:=ld_tex('rain.png',path,'terrain/');
239 for ix:=0 to 7 do osad[0,ix]:=rotate_image_from_image(im,16*ix,0,16,16,0);
240 im:=ld_tex('snow.png',path,'terrain/');
241 for ix:=0 to 7 do osad[1,ix]:=rotate_image_from_image(im,16*ix,0,16,16,0);
242 end;
244 if load_light_tex then
245 begin
246 im:=ld_tex('light.png',path,'terrain/');
247 for ix:=0 to 15 do light[ix]:=rotate_image_from_image(im,16*ix,0,16,16,0);
248 end;
250 Particles.LoadTextures(path);
252 im:=ld_tex('partition.png',path,'gui/');
253 gui[18]:=rotate_image_from_image(im,0,0,84,42,0);
254 gui[19]:=rotate_image_from_image(im,0,42,4,4,0);
256 if load_sky_siz<=0 then
257 sky:=ld_tex('sky.png',path,'terrain/');
258 else
259 sky:=resize_image(ld_tex('sky.png',path,'terrain/'),load_sky_siz,2);
261 if load_sm=1 then
262 begin
263 sun:=ld_tex('sun.png',path,'terrain/');
264 moon:=ld_tex('moon_phase_0.png',path,'terrain/moon_phases/');
265 end; else
266 if load_sm=2 then
267 begin
268 sun:=resize_image(ld_tex('sun.png',path,'terrain/'),(getWidth+getHeight)/5,(getWidth+getHeight)/5);
269 moon:=resize_image(ld_tex('moon_phase_0.png',path,'terrain/moon_phases/'),(getWidth+getHeight)/5,(getWidth+getHeight)/5);
270 end;
272 //load_virt_tex(ld_tex('touch.png',path,'gui/'));
273 end;
275 procedure cleargame;
276 var
277 ix,iy:integer;
278 begin
279 jmp:=false;
280 keymode:=0;
281 updx:=0;
282 updy:=0;
283 toolus:=0;
284 toolind:=0;
285 osadki_ani:=0;
286 global_light:=15;
287 pl_world:=0;
289 camx:=0;
290 camy:=0;
291 curx:=0;
292 cury:=0;
294 player.setX(0);
295 player.setY(0);
296 last_sleep_x:=0;
297 last_sleep_y:=0;
299 fly:=false;
300 game_time:=0;
301 clock_stage:=0;
302 hp:=20;
303 hunger:=20;
304 air:=21;
305 moon_phase:=0;
306 posi:=0;
307 velx:=0;
308 vely:=0;
309 invslot:=0;
311 osadki:=false;
313 //anim_del2:=0;
315 Inv.ResetData;
316 Chest.ResetData;
317 Furnace.ResetData;
318 Drop.ResetData;
319 Mobs.ResetData;
320 Particles.ResetData;
322 for ix:=0 to 255 do
323 begin
324 setBackMap(0, ix);
325 setBiomMap(0, ix);
326 for iy:=0 to 127 do
327 begin
328 setmap(0,ix,iy);
329 setmapinfo(0,ix,iy);
330 setmaplight(0,ix,iy);
331 end;
332 end;
334 for ix:=0 to 31 do
335 begin
336 b_sign[ix]:=false;
337 t_sign[ix]:='';
338 end;
340 for ix:=0 to CONST_MAX_LAYERS do
341 ClearLayer(ix);
342 end;
344 procedure drw_load_line(s:string;percent:integer);
345 var
346 ix,iy:integer;
347 begin
348 for ix:=0 to getWidth/16 do
349 for iy:=0 to getHeight/16 do
350 drawimage(bg[0],ix*16,iy*16);
351 drawfonttext(s,(getWidth/2)-(length(s)*8/2),(getHeight/2)-8);
352 setcolor(128,128,128);
353 fillrect(getwidth/2-50,getheight/2+6,100,3);
354 setcolor(128,255,128);
355 fillrect(getwidth/2-50,getheight/2+6,percent,3);
356 drawfonttext(integertostring(percent)+'%',getwidth/2-(length(integertostring(percent)+'%')*8)/2,getheight/2+12);
357 drawVideo;
358 end;
360 function getFlatMap(i:integer):integer;
361 var
362 ix, iy:integer;
363 begin
364 iy:=i div 256;
365 ix:=i-iy*256;
366 getFlatMap:=getmap(ix,iy);
367 end;
369 procedure setFlatMap(n, i:integer);
370 var
371 ix, iy:integer;
372 begin
373 iy:=i div 256;
374 ix:=i-iy*256;
375 setmap(n,ix,iy);
376 end;
378 function getFlatMapInfo(i:integer):integer;
379 var
380 ix, iy:integer;
381 begin
382 iy:=i div 256;
383 ix:=i-iy*256;
384 getFlatMapInfo:=getmapinfo(ix,iy);
385 end;
387 procedure setFlatMapInfo(n, i:integer);
388 var
389 ix, iy:integer;
390 begin
391 iy:=i div 256;
392 ix:=i-iy*256;
393 setmapinfo(n,ix,iy);
394 end;
396 procedure SaveMapRLE;
397 var
398 i:integer;
399 id, s:integer;
400 begin
401 repeat
402 id:=getFlatMap(i);
403 for s:=0 to 255 do
404 if (id<>getFlatMap(i+s)) or (i+s>32767) then
405 break;
407 write_byte(id);
408 write_byte(s-1);
410 i:=i+s;
411 until i>32767;
412 end;
414 procedure SaveMapInfoRLE;
415 var
416 i:integer;
417 id, s:integer;
418 begin
419 repeat
420 id:=getFlatMapInfo(i);
421 for s:=0 to 255 do
422 if (id<>getFlatMapInfo(i+s)) or (i+s>32767) then
423 break;
425 write_byte(id);
426 write_byte(s-1);
428 i:=i+s;
429 until i>32767;
430 end;
432 procedure LoadMapRLE;
433 var
434 i:integer;
435 id, s, j:integer;
436 begin
437 repeat
438 id:=read_byte;
439 s:=read_byte;
440 for j:=0 to s do
441 setFlatMap(id, i+j);
443 i:=i+s+1;
444 until i>32767;
445 end;
447 procedure LoadMapInfoRLE;
448 var
449 i:integer;
450 id, s, j:integer;
451 begin
452 repeat
453 id:=read_byte;
454 s:=read_byte;
455 for j:=0 to s do
456 setFlatMapInfo(id, i+j);
458 i:=i+s+1;
459 until i>32767;
460 end;
462 procedure saveworld(path:string);
463 var
464 ix,iy:integer;
465 world_name:string;
466 begin
467 if pl_world=0 then world_name:='world.sav';
468 else
469 if pl_world=1 then world_name:='nether.sav';
470 if file_exists(path)<>1 then if create_folder(path)=1 then debug('Folder created!');
471 if file_exists(path+world_name)>0 then delete_file(path+world_name);
472 if file_exists(path+world_name)<>1 then file_create(path+world_name);
473 if open_file(path+world_name)=1 then
474 begin
475 writeint(player.getX);
476 writeint(player.getY);
477 //Matrix
478 SaveMapRLE;
479 SaveMapInfoRLE;
480 drw_load_line('Background',50);
481 //Background and biomes
482 for ix:=0 to 255 do
483 begin
484 write_byte(getBackMap(ix));
485 write_byte(getBiomMap(ix));
486 end;
488 drw_load_line('Chests', 55);
489 Chest.SaveData;
490 drw_load_line('Furnaces', 60);
491 Furnace.SaveData;
492 drw_load_line('Mobs', 70);
493 Mobs.SaveData;
494 drw_load_line('Drop', 80);
495 Drop.SaveData;
496 drw_load_line('Particles', 85);
497 Particles.SaveData;
499 drw_load_line('Other', 90);
500 write_byte(updx);
501 write_byte(updy);
502 writebool(osadki);
503 write_byte(osadki_ani);
504 write_byte(global_light);
505 writebool(fly);
506 writeint(game_time);
507 write_byte(clock_stage);
508 for ix:=0 to 31 do
509 begin
510 writebool(b_sign[ix]);
511 writestr(t_sign[ix]);
512 end;
513 flush;
514 drw_load_line('Ready',100);
515 if close_file(path+world_name)=1 then debug('World Saved!');
516 end;
517 end;
519 procedure savegame(path:string);
520 var
521 ix,iy:integer;
522 begin
523 drw_load_line('Basic',0);
524 if file_exists(path+'player.dat')=1 then delete_file(path+'player.dat');
525 if file_exists(path)<>1 then if create_folder(path)=1 then debug('Folder created!');
526 if file_exists(path+'player.dat')<>1 then file_create(path+'player.dat');
527 if open_file(path+'player.dat')=1 then
528 begin
529 //Head
530 write_byte(version_map);
531 write_byte(gamemode);
532 writebool(cheats);
533 writeint(seed);
534 write_byte(pl_world);
535 //Player
536 writeint(last_sleep_x);
537 writeint(last_sleep_y);
538 write_byte(velx);
539 write_byte(vely);
540 write_byte(invslot);
541 write_byte(posi);
542 write_byte(hp);
543 write_byte(hunger);
544 write_byte(moon_phase);
545 writebool(jmp);
546 inv.saveData;
547 if close_file(path+'player.dat')=1 then debug('Saved!');
548 drw_load_line('Matrix',10);
549 saveworld(path);
550 end;
551 end;
554 function version_err(ver:integer):boolean;
555 var
556 ix,iy:integer;
557 begin
558 for ix:=0 to getWidth/16 do
559 for iy:=0 to getHeight/16 do
560 begin
561 drawimage(bg[0],ix*16,iy*16);
562 end;
563 if version_map=ver then version_err:=true; else
564 if version_map>ver then
565 begin
566 drawfonttext('Old save format!',(getWidth/2)-60,(getHeight/2)-4);
567 drawVideo;
568 delay(3000);
569 version_err:=false;
570 end; else
571 if version_map<ver then
572 begin
573 drawfonttext('New save format!',(getWidth/2)-60,(getHeight/2)-4);
574 drawVideo;
575 delay(3000);
576 version_err:=false;
577 end;
578 end;
581 function loadworld(path:string):boolean;
582 var
583 ix,iy,ver:integer;
584 world_name:string;
585 begin
586 if pl_world=0 then world_name:='world.sav';
587 else
588 if pl_world=1 then world_name:='nether.sav';
589 if file_exists(path)=1 then
590 begin
591 if file_exists(path+world_name)=1 then
592 begin
593 if open_file(path+world_name)=1 then
594 begin
595 player.setX(readint);
596 player.setY(readint);
597 //Matrix
598 LoadMapRLE;
599 LoadMapInfoRLE;
600 drw_load_line('Background',50);
601 //Background and biomes
602 for ix:=0 to 255 do
603 begin
604 setBackMap(read_byte, ix);
605 setBiomMap(read_byte, ix);
606 end;
607 drw_load_line('Chests', 55);
608 Chest.LoadData;
609 drw_load_line('Furnaces', 60);
610 Furnace.LoadData;
611 Mobs.LoadData;
612 drw_load_line('Drop', 80);
613 Drop.LoadData;
614 drw_load_line('Particles', 85);
615 Particles.LoadData;
617 drw_load_line('Other',90);
618 updx:=read_byte;
619 updy:=read_byte;
620 osadki:=readbool;
621 osadki_ani:=read_byte;
622 global_light:=read_byte;
623 fly:=readbool;
624 game_time:=readint;
625 clock_stage:=read_byte;
626 for ix:=0 to 31 do
627 begin
628 b_sign[ix]:=readbool;
629 t_sign[ix]:=readstr;
630 end;
631 drw_load_line('Ready',100);
632 ///////////////////////
633 if close_file(path+world_name)=1 then begin loadworld:=true; debug('World loaded!'); end;
634 end; else begin loadworld:=false; debug('File not opened!'); end;
635 end; else begin loadworld:=false; debug('File not exists!'); end;
636 end; else begin loadworld:=false; debug('Folder not exists!'); end;
637 end;
639 function loadgame(path:string):boolean;
640 var
641 ix,iy,ver:integer;
642 begin
643 drw_load_line('Basic',0);
644 if file_exists(path)=1 then
645 begin
646 if file_exists(path+'player.dat')=1 then
647 begin
648 if open_file(path+'player.dat')=1 then
649 begin
650 //Head
651 ver:=read_byte;
652 if version_err(ver)=false then
653 begin
654 if close_file(path+'player.dat')=1 then loadgame:=false;
655 exit;
656 end;
657 gamemode:=read_byte;
658 cheats:=readbool;
659 seed:=readint;
660 pl_world:=read_byte;
661 //Player;
662 last_sleep_x:=readint;
663 last_sleep_y:=readint;
664 velx:=read_byte;
665 vely:=read_byte;
666 invslot:=read_byte;
667 posi:=read_byte;
668 hp:=read_byte;
669 hunger:=read_byte;
670 moon_phase:=read_byte;
671 jmp:=readbool;
672 inv.loadData;
673 drw_load_line('Matrix',10);
674 if close_file(path+'player.dat')=1 then loadgame:=loadworld(path);
675 end; else loadgame:=false;
676 end; else loadgame:=false;
677 end; else loadgame:=false;
678 end;
680 procedure drawdeadlogo;
681 var
682 dead:image;
683 begin
684 setcolor(0,0,0);
685 fillrect(0,0,getWidth,getHeight);
686 dead:=loadimage('/dl');
687 drawimage(dead,(getWidth/2)-(getimagewidth(dead)/2),(getHeight/2)-(getimageheight(dead)/2));
688 drawfonttext(#119+#119+#119+#46+#100+#101+#97+#100+#115+#111+#102+#116+#119+#97+#114+#101+#46+#114+#117,getWidth/2-80,(getHeight/2)+(getimageheight(dead)/2));
689 drawfonttext('Loading...',(getWidth/2)-(40),getHeight-8);
690 drawVideo;
691 delay(500);
692 end;
694 procedure newgame;
695 var
696 ix,iy:integer;
697 begin
698 for ix:=0 to getWidth/16 do
699 for iy:=0 to getHeight/16 do
700 begin
701 drawimage(bg[0],ix*16,iy*16);
702 end;
703 drawfonttext('Generation World...',(getWidth/2)-(76),(getHeight/2)-4);
704 drawVideo;
705 delay(1);
706 cleargame;
707 game_time:=45000;
708 newworld;
709 //if s_spawn_mob then begin if pl_world=0 then begin megaspawn; end; else begin netherspawn; end; end;
710 if gamemode=1 then fly:=true else fly:=false;
711 debug('New game!');
712 end;
714 function gettext(text,text_f:string; max,typ:integer;):string;
715 var
716 textField_id:integer;
717 exitCmd,cli:command;
718 begin
719 clearForm;
720 exitCmd:=createCommand('Ok',CM_OK,1);
721 showForm;
722 addCommand(exitCmd);
723 textField_id:=formAddTextField(text,text_f,max,typ);
724 drawVideo;
725 delay(100);
726 repeat
727 cli:=getClickedCommand;
728 until cli=exitCmd;
729 gettext:=formGetText(textField_id);
730 showCanvas;
731 end;
733 procedure drw_btn(text:string; cur,ccur,h,ty:integer);
734 var
735 m_x,m_y,i:integer;
736 begin
737 m_x:=(getWidth/2)-(120/2);
738 m_y:=h+((getHeight/2))-((getimageheight(gui[7])-2*cur)/2)+((getimageheight(gui[7])+2)*cur);
739 if ty=0 then
740 begin
741 if ccur=cur then drawimage(gui[22],m_x+i*4,m_y); else drawimage(gui[6],m_x+i*8,m_y);
742 end; else
743 if ty=1 then
744 begin
745 if ccur=cur then drawimage(gui[8],m_x+i*8,m_y); else drawimage(gui[7],m_x+i*8,m_y);
746 end;
747 setclip(0,0,getwidth,getheight);
748 m_x:=(getWidth/2)-(length(text)*8/2);
749 m_y:=h+((getHeight/2))-((getimageheight(gui[7])-2*cur)/2)+((getimageheight(gui[7])+2)*cur)+((getimageheight(gui[7])-8)/2);
750 drawfonttext(text,m_x,m_y);
751 end;
753 procedure drw_txt(str:string; xx,n,t:integer);
754 var
755 m_x,m_y:integer;
756 begin
757 m_x:=(getWidth/2)-(length(str)*8/2);
758 m_y:=xx+32+(8*n);
759 if t=0 then drawfonttext(str,0,m_y); else
760 if t=1 then drawfonttext(str,m_x,m_y);
761 end;
763 function pos_end(s:string; c:char):integer;
764 var
765 i:integer;
766 begin
767 for i:=length(s)-1 downto 0 do
768 begin
769 if getchar(s,i)=c then
770 begin
771 pos_end:=i;
772 exit;
773 end;
774 end;
775 pos_end:=-1;
776 end;
778 function getroot(cancel_b:boolean):string;
779 var
780 m_cur,max_r,pars,ix,iy:integer;
781 rr:string;
782 im:image;
783 roots:array [0..15] of string;
784 begin
785 im:=rotate_image_from_image(ld_tex('background.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','title/'),16,0,16,16,0);
786 rr:=get_roots;
787 if cancel_b then roots[0]:='<CANCEL>';
788 if cancel_b then max_r:=1; else max_r:=0;
789 while pos(rr,'|')<>-1 do
790 begin
791 pars:=pos(rr,'|');
792 roots[max_r]:=copy(rr,0,pars-1);
793 rr:=copy(rr,pars+1,length(rr));
794 max_r:=max_r+1;
795 end;
796 max_r:=max_r-1;
797 repeat
798 updateKeys;
799 if clickedKey(KEY_FM_UP) then begin m_cur:=m_cur-1; if m_cur<0 then m_cur:=max_r; end;
800 if clickedKey(KEY_FM_DOWN) then begin m_cur:=m_cur+1; if m_cur>max_r then m_cur:=0; end;
801 if clickedKey(KEY_FM_SELECT) then
802 begin
803 if (m_cur=0) and (cancel_b) then
804 begin
805 getroot:='';
806 exit;
807 end;
808 else
809 begin
810 getroot:=roots[m_cur];
811 exit;
812 end;
813 end;
815 for ix:=0 to getWidth/16 do
816 for iy:=0 to getHeight/16 do
817 drawimage(im,ix*16,iy*16);
819 setcolor(0,0,0);
820 fillrect(0,m_cur*8,getWidth-1,8);
821 for ix:=0 to max_r do
822 begin
823 drawfonttext(roots[ix],0,ix*8);
824 end;
825 setcolor(255,255,255);
826 drawrect(0,m_cur*8,getWidth-1,8);
828 drawVideo;
829 delay(1);
830 until false;
831 end;
833 function filemanager(cancel_b:boolean):string;
834 var
835 m_cur,ix,iy,max_r,pars:integer;
836 im:image;
837 last,rr,root,path:string;
838 names:array [0..255] of string;
839 begin
840 im:=rotate_image_from_image(ld_tex('background.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','title/'),16,0,16,16,0);
841 names[0]:='<..>';
842 names[1]:='<OK>';
843 root:=getroot(cancel_b);
844 if root='' then
845 begin
846 filemanager:='';
847 exit;
848 end;
849 path:=root;
850 if cancel_b then names[2]:='<CANCEL>';
851 rr:=get_dirs(path);
852 if cancel_b then max_r:=3; else max_r:=2;
853 while pos(rr,'|')<>-1 do
854 begin
855 pars:=pos(rr,'|');
856 names[max_r]:=copy(rr,0,pars-1);
857 rr:=copy(rr,pars+1,length(rr));
858 max_r:=max_r+1;
859 end;
860 max_r:=max_r-1;
862 repeat
863 updateKeys;
864 if clickedKey(KEY_FM_UP) then begin m_cur:=m_cur-1; if m_cur<0 then m_cur:=max_r; end;
865 if clickedKey(KEY_FM_DOWN) then begin m_cur:=m_cur+1; if m_cur>max_r then m_cur:=0; end;
866 if clickedKey(KEY_FM_SELECT) then
867 begin
868 if m_cur=0 then
869 begin
870 debug('path:'+path);
871 debug('lol:'+pos_end(path,'/'));
872 if (path=root) or (path=root+'/') then
873 begin
874 root:=getroot(cancel_b);
875 if root='' then
876 begin
877 filemanager:='';
878 exit;
879 end;
880 path:=root;
881 end;
882 else
883 begin
884 path:=copy(path,0,pos_end(path,'/'));
885 if cancel_b then names[2]:='<CANCEL>';
886 rr:=get_dirs(path);
887 if cancel_b then max_r:=3; else max_r:=2;
888 while pos(rr,'|')<>-1 do
889 begin
890 pars:=pos(rr,'|');
891 names[max_r]:=copy(rr,0,pars-1);
892 rr:=copy(rr,pars+1,length(rr));
893 max_r:=max_r+1;
894 end;
895 max_r:=max_r-1;
896 end;
897 end; else
898 if m_cur=1 then
899 begin
900 debug('<OK>');
901 filemanager:=path;
902 exit;
903 end; else
904 if (m_cur=2) and (cancel_b) then
905 begin
906 debug('<CANCEL>');
907 filemanager:='';
908 exit;
909 end; else
910 begin
911 path:=path+'/'+names[m_cur];
913 if cancel_b then names[2]:='<CANCEL>';
914 rr:=get_dirs(path);
915 if cancel_b then max_r:=3; else max_r:=2;
916 while pos(rr,'|')<>-1 do
917 begin
918 pars:=pos(rr,'|');
919 names[max_r]:=copy(rr,0,pars-1);
920 rr:=copy(rr,pars+1,length(rr));
921 max_r:=max_r+1;
922 end;
923 max_r:=max_r-1;
924 m_cur:=0;
925 debug('path:'+path);
926 end;
927 end;
929 for ix:=0 to getWidth/16 do
930 for iy:=0 to getHeight/16 do
931 drawimage(im,ix*16,iy*16);
933 setcolor(0,0,0);
934 fillrect(0,m_cur*8,getWidth-1,8);
935 for ix:=0 to max_r do
936 begin
937 drawfonttext(names[ix],0,ix*8);
938 end;
939 setcolor(255,255,255);
940 drawrect(0,m_cur*8,getWidth-1,8);
942 drawVideo;
943 delay(1);
945 until false;
946 end;
948 procedure setsd(cancel_b:boolean);
949 var
950 s:string;
951 t:integer;
952 rs:recordstore;
953 begin
954 s:=filemanager(cancel_b);
955 if s<>'' then
956 begin
957 sd:=s;
958 if file_exists('/'+sd+'/cavecraft')<>1 then
959 if create_folder('/'+sd+'/cavecraft')=1 then debug('/cavecraft created!');
961 if file_exists('/'+sd+'/cavecraft/saves')<>1 then
962 if create_folder('/'+sd+'/cavecraft/saves')=1 then debug('/saves created!');
964 if file_exists('/'+sd+'/cavecraft/screenshots')<>1 then
965 if create_folder('/'+sd+'/cavecraft/screenshots')=1 then debug('/screenshots created!');
967 if file_exists('/'+sd+'/cavecraft/texturepacks')<>1 then
968 if create_folder('/'+sd+'/cavecraft/texturepacks')=1 then debug('/texturepacks created!');
970 deleteRecordStore('SD');
971 rs:=openRecordStore('SD');
972 t:=addRecordStoreEntry(rs,sd);
973 closeRecordStore(rs);
974 end;
975 end;
977 procedure start_uu;
978 var
979 rs:recordstore;
980 ss:string;
981 begin
982 drawdeadlogo;
983 //Load SD
984 rs:=openRecordStore('SD');
985 sd:=readRecordStoreEntry(rs,1);
986 closeRecordStore(rs);
987 console.exec('autoexec.cfg', 'AUTO');
988 if sd='' then
989 begin
990 init_touch;
991 if touchscreen then
992 load_key_tex:=1;
993 else
994 load_key_tex:=0;
995 //load_virt_tex(loadimage('/gui/touch.png'));
996 setsd(false);
997 end;
999 if file_exists('/'+sd+'/cavecraft')<>1 then
1000 if create_folder('/'+sd+'/cavecraft')=1 then debug('/cavecraft created!');
1002 if file_exists('/'+sd+'/cavecraft/saves')<>1 then
1003 if create_folder('/'+sd+'/cavecraft/saves')=1 then debug('/saves created!');
1005 if file_exists('/'+sd+'/cavecraft/screenshots')<>1 then
1006 if create_folder('/'+sd+'/cavecraft/screenshots')=1 then debug('/screenshots created!');
1008 if file_exists('/'+sd+'/cavecraft/texturepacks')<>1 then
1009 if create_folder('/'+sd+'/cavecraft/texturepacks')=1 then debug('/texturepacks created!');
1011 rs:=openRecordStore('TX');
1012 ss:=readRecordStoreEntry(rs,1);
1013 closeRecordStore(rs);
1015 if ss<>'' then
1016 begin
1017 tex_pack:=ss;
1018 LoadDrawFont('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1019 loadtexture('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1020 end;
1021 else
1022 begin
1023 LoadDrawFont('/');
1024 loadtexture('/');
1025 end;
1026 end;
1028 function question(text:string):boolean;
1029 var
1030 ix,iy,m_cur:integer;
1031 begin
1032 repeat
1033 updateKeys;
1034 if clickedKey(KEY_MENU_UP) then begin m_cur:=m_cur-1; if m_cur<0 then m_cur:=1; end;
1035 if clickedKey(KEY_MENU_DOWN) then begin m_cur:=m_cur+1; if m_cur>1 then m_cur:=0; end;
1036 if clickedKey(KEY_MENU_SELECT) then begin if m_cur=0 then question:=true; else question:=false; exit; end;
1037 for ix:=0 to getwidth/16 do for iy:=0 to getheight/16 do drawimage(bg[0],ix*16,iy*16);
1038 drawfonttext(text,getwidth/2-(length(text)*8)/2,getheight/2-16);
1039 drw_btn('Yes',0,m_cur,0,1);
1040 drw_btn('No',1,m_cur,0,1);
1041 drawVideo;
1042 delay(1);
1043 until false;
1044 end;
1046 function menu_game_new:boolean;
1047 var
1048 m_cur,tmp_gm,ix,iy,lol:integer;
1049 tmp_cheats,tmp_bon_chest:boolean;
1050 newgametxt:array[0..4] of string;
1051 name,tmp:string;
1052 begin
1053 m_cur:=-2;
1054 newgametxt[0]:='Survival';
1055 newgametxt[1]:='Creative';
1056 newgametxt[2]:='Hardcore';
1057 newgametxt[3]:='Normal';
1058 newgametxt[4]:='Flat';
1059 name:='New World';
1060 repeat
1061 updateKeys;
1062 if clickedKey(KEY_MENU_UP) then begin m_cur:=m_cur-1; if m_cur<-2 then m_cur:=5; end;
1063 if clickedKey(KEY_MENU_DOWN) then begin m_cur:=m_cur+1; if m_cur>5 then m_cur:=-2; end;
1064 if clickedKey(KEY_MENU_SELECT) then
1065 begin
1066 if m_cur=-2 then
1067 begin
1068 name:=gettext('Name:',name,10,TF_ANY);
1069 end; else
1070 if m_cur=-1 then
1071 begin
1072 tmp_gm:=tmp_gm+1; if tmp_gm>2 then tmp_gm:=0;
1073 if tmp_gm=0 then tmp_cheats:=false;
1074 if tmp_gm=1 then tmp_cheats:=true;
1075 if tmp_gm=2 then begin tmp_cheats:=false; tmp_bon_chest:=false; end;
1076 end; else
1077 if m_cur=0 then
1078 begin
1079 nextseed:=stringtointeger(gettext('Seed:',''+nextseed,10,TF_NUMERIC));
1080 end; else
1081 if m_cur=1 then
1082 begin
1083 world_typ:=world_typ+1;
1084 if world_typ>1 then world_typ:=0;
1085 end; else
1086 if m_cur=2 then
1087 begin
1088 if tmp_gm<2 then tmp_cheats:= not tmp_cheats;
1089 end; else
1090 if m_cur=3 then
1091 begin
1092 if tmp_gm<2 then tmp_bon_chest:= not tmp_bon_chest;
1093 end; else
1094 if m_cur=4 then
1095 begin
1096 gamemode:=tmp_gm;
1097 cheats:=tmp_cheats;
1098 bon_chest:=tmp_bon_chest;
1099 tmp:=name;
1100 while file_exists('/'+sd+'/cavecraft/saves/'+name)=1 do
1101 begin
1102 lol:=lol+1;
1103 name:=tmp+' '+lol;
1104 end;
1105 sav_fl:=name;
1106 newgame;
1107 menu_game_new:=true;
1108 break;
1109 end; else
1110 if m_cur=5 then
1111 begin
1112 break;
1113 end; else
1114 end;
1115 for ix:=0 to getWidth/16 do
1116 for iy:=0 to getHeight/16 do
1117 drawimage(bg[0],ix*16,iy*16);
1119 drw_btn('Name:'+name,-2,m_cur,0,1);
1120 drw_btn('Mode:'+newgametxt[tmp_gm],-1,m_cur,0,1);
1121 drw_btn('Seed:'+nextseed,0,m_cur,0,1);
1122 drw_btn('Type:'+newgametxt[world_typ+3],1,m_cur,0,1);
1123 if tmp_gm<2 then
1124 drw_btn('Cheats:'+tmp_cheats,2,m_cur,0,1);
1125 else
1126 drw_btn('Cheats:'+tmp_cheats,2,m_cur,0,0);
1127 if tmp_gm<2 then
1128 drw_btn('Chest:'+tmp_bon_chest,3,m_cur,0,1);
1129 else
1130 drw_btn('Chest:'+tmp_bon_chest,3,m_cur,0,0);
1131 drw_btn('Create',4,m_cur,0,1);
1132 drw_btn('Cancel',5,m_cur,0,1);
1134 drawVideo;
1135 delay(1);
1136 until false;
1137 end;
1139 procedure deleteworld(path:string);
1140 begin
1141 if file_exists(path+'player.dat')=1 then delete_file(path+'player.dat');
1142 if file_exists(path+'world.sav')=1 then delete_file(path+'world.sav');
1143 if file_exists(path+'nether.sav')=1 then delete_file(path+'nether.sav');
1144 if file_exists(path+'pic.png')=1 then delete_file(path+'pic.png');
1145 if file_exists(path)=1 then delete_file(path);
1146 if file_exists(path)=0 then debug('World deleted!');
1147 end;
1149 function menu_game:boolean;
1150 var
1151 ix,iy,pars,max_r,cur_name,m_cur:integer;
1152 mm_t_b:boolean;
1153 im_game:image;
1154 rr:string;
1155 names:array[0..255] of string;
1156 begin
1157 rr:=get_dirs('/'+sd+'/cavecraft/saves/');
1158 while pos(rr,'|')<>-1 do
1159 begin
1160 pars:=pos(rr,'|');
1161 names[max_r]:=copy(rr,0,pars-1);
1162 rr:=copy(rr,pars+1,length(rr));
1163 if file_exists('/'+sd+'/cavecraft/saves/'+names[max_r]+'/player.dat')=1 then max_r:=max_r+1;
1164 end;
1165 max_r:=max_r-1;
1166 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png')=1 then
1167 im_game:=safely_load_image_fs('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png');
1168 else im_game:=ld_tex('maps.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','');
1170 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/player.dat')=1 then
1171 mm_t_b:=true; else mm_t_b:=false;
1173 repeat
1174 updateKeys;
1175 if clickedKey(KEY_MENU_UP) then
1176 begin
1177 m_cur:=m_cur-1;
1178 if m_cur<0 then m_cur:=3;
1179 end;
1180 if clickedKey(KEY_MENU_DOWN) then
1181 begin
1182 m_cur:=m_cur+1;
1183 if m_cur>3 then m_cur:=0;
1184 end;
1186 if (max_r >= 0) and clickedKey(KEY_MENU_LEFT) then
1187 begin
1188 cur_name:=cur_name-1;
1189 if cur_name<0 then cur_name:=0;
1190 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png')=1 then
1191 im_game:=safely_load_image_fs('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png');
1192 else im_game:=ld_tex('maps.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','');
1194 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/player.dat')=1 then
1195 end;
1196 if (max_r >= 0) and clickedKey(KEY_MENU_RIGHT) then
1197 begin
1198 cur_name:=cur_name+1;
1199 if cur_name>max_r then cur_name:=max_r;
1200 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png')=1 then
1201 im_game:=safely_load_image_fs('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png');
1202 else im_game:=ld_tex('maps.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','');
1204 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/player.dat')=1 then
1205 end;
1206 if clickedKey(KEY_MENU_SELECT) then
1207 begin
1208 if m_cur=0 then
1209 begin
1210 if max_r>-1 then
1211 if loadgame('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/') then
1212 begin
1213 sav_fl:=names[cur_name];
1214 menu_game:=true;
1215 break;
1216 end;
1217 end; else
1218 if m_cur=1 then
1219 begin
1220 if menu_game_new then begin menu_game:=true; break; end;
1221 end; else
1222 if m_cur=2 then
1223 begin
1224 debug('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/');
1225 if max_r>-1 then
1226 if question('Are you sure?')=true then deleteworld('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/');
1227 cur_name:=0;
1228 max_r:=0;
1229 rr:=get_dirs('/'+sd+'/cavecraft/saves/');
1230 while pos(rr,'|')<>-1 do
1231 begin
1232 pars:=pos(rr,'|');
1233 names[max_r]:=copy(rr,0,pars-1);
1234 rr:=copy(rr,pars+1,length(rr));
1235 max_r:=max_r+1;
1236 end;
1237 max_r:=max_r-1;
1238 if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png')=1 then
1239 im_game:=safely_load_image_fs('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/pic.png');
1240 else im_game:=ld_tex('maps.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','');
1241 end; else
1242 if m_cur=3 then
1243 begin
1244 break;
1245 end;
1246 end;
1248 for ix:=0 to getWidth/16 do
1249 for iy:=1 to 7 do
1250 drawimage(bg[1],ix*16,iy*16);
1251 for ix:=0 to getWidth/16 do
1252 drawimage(bg[0],ix*16,0);
1253 for ix:=0 to getWidth/16 do
1254 for iy:=8 to getHeight/16 do
1255 drawimage(bg[0],ix*16,iy*16);
1257 if max_r>-1 then
1258 begin
1259 setcolor(0,0,0);
1260 fillrect(32,24,getWidth-64,96);
1261 setclip(32,24,getWidth-64,96);
1262 drawimage(im_game,(getWidth/2)-(32),32);
1263 drawfonttext(names[cur_name],(getWidth/2)-(length(names[cur_name])*8/2),104);
1264 setclip(0,0,getWidth,getHeight);
1265 setcolor(128,128,128);
1266 drawrect(32,24,getWidth-64,96);
1267 if cur_name>0 then drawimage(gui[20],0,58);
1268 if cur_name<max_r then drawimage(gui[21],getWidth-9,58);
1269 end;
1270 else
1271 begin
1272 setcolor(0,0,0);
1273 fillrect(32,24,getWidth-64,96);
1274 setclip(32,24,getWidth-64,96);
1275 drawfonttext('No saves!',(getWidth/2)-(length('No saves!')*8/2),104);
1276 setclip(0,0,getWidth,getHeight);
1277 setcolor(128,128,128);
1278 drawrect(32,24,getWidth-64,96);
1279 end;
1281 if mm_t_b then drw_btn('Play',0,m_cur,32,1); else drw_btn('Play',0,m_cur,32,0);
1282 drw_btn('Create new',1,m_cur,32,1);
1283 if mm_t_b then drw_btn('Delete',2,m_cur,32,1); else drw_btn('Delete',2,m_cur,32,0);
1284 drw_btn('Back',3,m_cur,32,1);
1285 if not mm_t_b then cur_name:=cur_name+1;
1287 drawVideo;
1288 delay(1);
1289 until false;
1290 end;
1292 procedure menu_tex;
1293 var
1294 ix,iy,pars,max_r,cur_name,m_cur,t:integer;
1295 im_game:image;
1296 rr:string;
1297 names:array[0..255] of string;
1298 rs:recordstore;
1299 begin
1300 rr:=get_dirs('/'+sd+'/cavecraft/texturepacks/');
1301 names[0]:='Default';
1302 max_r:=1;
1303 while pos(rr,'|')<>-1 do
1304 begin
1305 pars:=pos(rr,'|');
1306 names[max_r]:=copy(rr,0,pars-1);
1307 rr:=copy(rr,pars+1,length(rr));
1308 max_r:=max_r+1;
1309 end;
1310 max_r:=max_r-1;
1311 im_game:=loadimage('/pack.png');
1313 repeat
1314 updateKeys;
1315 if clickedKey(KEY_MENU_UP) then
1316 begin
1317 m_cur:=m_cur-1;
1318 if m_cur<0 then m_cur:=1;
1319 end;
1320 if clickedKey(KEY_MENU_DOWN) then
1321 begin
1322 m_cur:=m_cur+1;
1323 if m_cur>1 then m_cur:=0;
1324 end;
1326 if clickedKey(KEY_MENU_LEFT) then
1327 begin
1328 cur_name:=cur_name-1;
1329 if cur_name<0 then cur_name:=0;
1330 im_game:=ld_tex('pack.png','/'+sd+'/cavecraft/texturepacks/'+names[cur_name]+'/','');
1331 end;
1332 if clickedKey(KEY_MENU_RIGHT) then
1333 begin
1334 cur_name:=cur_name+1;
1335 if cur_name>max_r then cur_name:=max_r;
1336 im_game:=ld_tex('pack.png','/'+sd+'/cavecraft/texturepacks/'+names[cur_name]+'/','');
1337 end;
1338 if clickedKey(KEY_MENU_SELECT) then
1339 begin
1340 if m_cur=0 then begin
1341 if cur_name>0 then
1342 begin
1343 debug("Select TexturePack @ /" + sd + "/cavecraft/texturepacks/" + names[cur_name]);
1344 tex_pack:=names[cur_name];
1345 LoadDrawFont('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1346 loadtexture('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1347 deleteRecordStore('TX');
1348 rs:=openRecordStore('TX');
1349 t:=addRecordStoreEntry(rs,tex_pack);
1350 closeRecordStore(rs);
1352 LoadDrawFont('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1353 loadtexture('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
1354 end;
1355 else
1356 begin
1357 debug("Cancel Select TecturePack");
1358 tex_pack:='';
1359 loadtexture('/');
1360 deleteRecordStore('TX');
1361 rs:=openRecordStore('TX');
1362 t:=addRecordStoreEntry(rs,'');
1363 closeRecordStore(rs);
1364 end;
1365 end;
1366 if m_cur=1 then break;
1367 break;
1368 end;
1370 for ix:=0 to getWidth/16 do
1371 for iy:=1 to 7 do
1372 drawimage(bg[1],ix*16,iy*16);
1373 for ix:=0 to getWidth/16 do
1374 drawimage(bg[0],ix*16,0);
1375 for ix:=0 to getWidth/16 do
1376 for iy:=8 to getHeight/16 do
1377 drawimage(bg[0],ix*16,iy*16);
1379 if max_r>-1 then
1380 begin
1381 setcolor(0,0,0);
1382 fillrect(32,24,getWidth-64,96);
1383 setclip(32,24,getWidth-64,96);
1384 drawimage(im_game,(getWidth/2)-(32),32);
1385 drawfonttext(names[cur_name],(getWidth/2)-(length(names[cur_name])*8/2),104);
1386 setclip(0,0,getWidth,getHeight);
1387 setcolor(128,128,128);
1388 drawrect(32,24,getWidth-64,96);
1389 if cur_name>0 then drawimage(gui[20],0,58);
1390 if cur_name<max_r then drawimage(gui[21],getWidth-9,58);
1391 end;
1393 drw_btn('Done',0,m_cur,32,1);
1394 drw_btn('Back',1,m_cur,32,1);
1396 drawVideo;
1397 delay(1);
1398 until false;
1399 end;
1401 procedure menu_sett;
1402 var
1403 ix,iy,m_cur:integer;
1404 begin
1405 m_cur:=-3;
1406 repeat
1407 updateKeys;
1408 if clickedKey(KEY_MENU_UP) then
1409 begin
1410 m_cur:=m_cur-1;
1411 if m_cur<-3 then m_cur:=5;
1412 end;
1413 if clickedKey(KEY_MENU_DOWN) then
1414 begin
1415 m_cur:=m_cur+1;
1416 if m_cur>5 then m_cur:=-3;
1417 end;
1418 if clickedKey(KEY_MENU_SELECT) then
1419 begin
1420 if m_cur=-3 then
1421 begin
1422 light_type:=light_type+1;
1423 if light_type>2 then light_type:=0;
1424 end; else
1425 if m_cur=-2 then
1426 begin
1427 ifosad:=not ifosad;
1428 end; else
1429 if m_cur=-1 then
1430 begin
1431 Particles.enabled := not Particles.enabled;
1432 end; else
1433 if m_cur=0 then
1434 begin
1435 drawgui:=not drawgui;
1436 end; else
1437 if m_cur=1 then
1438 begin
1439 if question('Are you sure?')=true then
1440 begin
1441 if load_key_tex=0 then
1442 begin
1443 load_key_tex:=1;
1444 init_touch;
1445 //load_virt_tex(ld_tex('touch.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','gui/'));
1446 end;
1447 else
1448 if load_key_tex=1 then
1449 begin
1450 load_key_tex:=0;
1451 resetVirtualKeyboard(-1);
1452 end;
1453 end;
1454 end;
1455 if m_cur=2 then
1456 begin
1457 s_jpeg_quality:=stringtointeger(gettext('JPEG quality:',''+s_jpeg_quality,3,TF_NUMERIC));
1458 if s_jpeg_quality>100 then s_jpeg_quality:=100; else
1459 if s_jpeg_quality<0 then s_jpeg_quality:=0;
1460 end; else
1461 if m_cur=3 then
1462 begin
1463 setsd(true);
1464 end; else
1465 if m_cur=4 then
1466 begin
1467 deleteRecordStore('S');
1468 deleteRecordStore('SD');
1469 deleteRecordStore('TX');
1470 halt;
1471 end; else
1472 if m_cur=5 then
1473 begin
1474 save_settings;
1475 break;
1476 end; else
1477 end;
1479 for ix:=0 to getWidth/16 do
1480 for iy:=0 to getHeight/16 do
1481 drawimage(bg[0],ix*16,iy*16);
1483 drw_btn('Light:'+light_type,-3,m_cur,0,1);
1484 drw_btn('Weather:'+ifosad,-2,m_cur,0,1);
1485 drw_btn('Particles:' + Particles.enabled, -1, m_cur, 0, 1);
1486 drw_btn('Hide GUI:'+not drawgui,0,m_cur,0,1);
1487 drw_btn('Touch:'+(load_key_tex>0),1,m_cur,0,1);
1488 drw_btn('JPEG:'+s_jpeg_quality,2,m_cur,0,1);
1489 drw_btn('Set Root',3,m_cur,0,1);
1490 drw_btn('Reset',4,m_cur,0,1);
1491 drw_btn('Back',5,m_cur,0,1);
1493 drawVideo;
1494 delay(1);
1495 until false;
1496 end;
1498 procedure menu_help;
1499 var
1500 ix,iy,cur:integer;
1501 begin
1502 repeat
1503 updateKeys;
1504 if clickedKey(KEY_MENU_SELECT) then break;
1505 if pressedKey(KEY_MENU_UP) then cur:=cur+1;
1506 if pressedKey(KEY_MENU_DOWN) then cur:=cur-1;
1508 for ix:=0 to getWidth/16 do
1509 for iy:=2 to (getHeight/16)-2 do
1510 drawimage(bg[1],ix*16,iy*16);
1512 for ix:=0 to getWidth/16 do
1513 for iy:=0 to 1 do
1514 drawimage(bg[0],ix*16,iy*16);
1516 for ix:=0 to getWidth/16 do
1517 for iy:=(getHeight/16)-2 to getHeight/16 do
1518 drawimage(bg[0],ix*16,iy*16);
1520 setclip(0,32,getWidth,(getHeight/16-4)*16);
1522 drw_txt('Controls:',cur,0,1);
1523 drw_txt('Left - Move left',cur,1,0);
1524 drw_txt('Right - Move right',cur,2,0);
1525 drw_txt('Up - Jump',cur,3,0);
1526 drw_txt('Down - Put a block under you',cur,4,0);
1527 drw_txt('1 - Inventory',cur,5,0);
1528 drw_txt('Duble 1 - Craft',cur,6,0);
1529 drw_txt('3 - Use block',cur,7,0);
1530 drw_txt('7 - Debug info',cur,8,0);
1531 drw_txt('Hold 7 - Console',cur,9,0);
1532 drw_txt('9 - Pause',cur,10,0);
1533 drw_txt('*, # - Browse inventory',cur,11,0);
1534 drw_txt('0 - Edit mode',cur,12,0);
1536 drw_txt('In inventory/chest:',cur,14,1);
1537 drw_txt('3 - Enject object',cur,15,0);
1538 drw_txt('Hold 3 - Enject stack',cur,16,0);
1539 drw_txt('5 - Move the stack',cur,17,0);
1540 drw_txt('Hold 5 - Divide stack',cur,18,0);
1542 setclip(0,0,getWidth,getHeight);
1544 drw_btn('Back',0,0,getHeight-getHeight/2-16-6,1);
1546 drawVideo;
1547 delay(1);
1548 until false;
1549 end;
1551 procedure menu_about;
1552 var
1553 ix,iy,cur:integer;
1554 begin
1555 repeat
1556 updateKeys;
1557 if clickedKey(KEY_MENU_SELECT) then break;
1558 if pressedKey(KEY_MENU_UP) then cur:=cur+1;
1559 if pressedKey(KEY_MENU_DOWN) then cur:=cur-1;
1561 for ix:=0 to getWidth/16 do
1562 for iy:=2 to (getHeight/16)-2 do
1563 drawimage(bg[1],ix*16,iy*16);
1565 for ix:=0 to getWidth/16 do
1566 for iy:=0 to 1 do
1567 drawimage(bg[0],ix*16,iy*16);
1569 for ix:=0 to getWidth/16 do
1570 for iy:=(getHeight/16)-2 to getHeight/16 do
1571 drawimage(bg[0],ix*16,iy*16);
1573 setclip(0,32,getWidth,(getHeight/16-4)*16);
1575 drw_txt('Developers:',cur,0,1);
1576 drw_txt(#68+#101+#97+#68+#68+#111+#111+#77+#69+#82+' - Programmer',cur,1,0);//dead
1577 drw_txt(#102+#114+#101+#100+#45+#98+#111+#121+' - Programmer',cur,2,0);//fred-boy
1578 drw_txt(#65+#110+#100+#114+#101+#121+#53+#57+' - Programmer',cur,3,0);//andrey59
1579 drw_txt(#89+#117+#82+#97+#78+#110+#78+#122+#90+#90+' - Artist',cur,4,0);//yura
1580 drw_txt(#83+#97+#115+#104+#97+#71+' - Artist and idea generator',cur,5,0);//sasha
1581 drw_txt(#66+#97+#74+#108+#101+#72+#84+#105+#72+' - Artist and tester',cur,6,0);//valentin
1582 drw_txt(#65+#103+#114+#101+#115+#115+#111+#82+' - Tester',cur,7,0);//agressor
1583 drw_txt(#118+#111+#108+#121+#97+#95+#110+#97+#115+#116+#97+#110+#101+' - Tester',cur,8,0);//volya
1584 drw_txt(#97+#98+#97+#100+#111+#110+' - Tester',cur,9,0);//abadon
1585 drw_txt(#77+#111+#110+#111+#103+#114+#111+#109+' - Tester',cur,10,0);//monogrom
1586 drw_txt(#75+#97+#108+#116+#101+#114+' - Tester',cur,11,0);//kalter
1588 drw_txt('Thanks:',cur,12,1);
1589 drw_txt('Piligrim and 0vZ - Lib_jsr75i',cur,13,0);
1590 drw_txt('Piligrim - Lib_effects',cur,14,0);
1591 drw_txt('Kurdt - Lib_canvas',cur,15,0);
1592 drw_txt('ViNT - Lib_png and Lib_bmp',cur,16,0);
1593 drw_txt('aleshka - Lib_jpeg',cur,17,0);
1594 drw_txt('Roman_V - Lib_safeload',cur,18,0);
1596 drw_txt('Site: '+#104+#116+#116+#112+#58+#47+#47+#100+#101+#97+#100+#115+#111+#102+#116+#119+#97+#114+#101+#46+#114+#117,cur,21,0);
1597 drw_txt(#68+#101+#97+#68+#83+#111+#102+#116+#87+#97+#114+#101+' 2012-'+getyear(getcurrenttime),cur,22,0);
1599 drw_txt('Hello! :D',cur,100,1);
1601 setclip(0,0,getWidth,getHeight);
1603 drw_btn('Back',0,0,getHeight-getHeight/2-16-6,1);
1605 drawVideo;
1606 delay(1);
1607 until false;
1608 end;
1610 function sm_siz:integer;
1611 begin
1612 sm_siz:=(getWidth+getHeight)/5;
1613 end;
1615 function sm_siz4:integer;
1616 begin
1617 sm_siz4:=sm_siz/4;
1618 end;
1620 procedure draw_menu_back;
1621 var
1622 ix, iy:integer;
1623 begin
1624 for ix:=0 to getWidth/16 do
1625 for iy:=0 to getHeight/16 do
1626 drawimage(bg[0],ix*16,iy*16);
1627 end;
1629 procedure menu;
1630 var
1631 m_cur,ix,iy,iz:integer;
1632 key,spl_i:integer;
1633 splash:string;
1634 res:resource;
1635 time:integer;
1636 cavelogo:image;
1637 spl_y,spl_del:integer;
1638 spl_y_b:boolean;
1639 begin
1640 cavelogo:=ld_tex('cavelogo.png','/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/','title/');
1641 splash:='#ERROR';
1642 spl_y:=getimageheight(cavelogo);
1643 spl_y_b:=true;
1644 spl_del:=getrelativetimems;
1645 res:=openResource('/title/splashes.txt');
1646 if ResourceAvailable(res) then
1647 begin
1648 spl_i:=stringtointeger(readline(res));
1649 iy:=random(spl_i-1)+1;
1650 debug('SPLASH #'+iy);
1651 for ix:=1 to iy do
1652 splash:=readline(res);
1653 closeresource(res);
1654 end;
1655 time:=getcurrenttime;
1656 if (getmonth(time)=5) and (getday(time)=7) then splash:='Happy birthday, DeaDDooMER!';
1657 if ((getmonth(time)=0) and (getday(time)<3)) or ((getmonth(time)=11) and (getday(time)>29)) then splash:='Happy New Year!';
1658 repeat
1659 proc_fps;
1660 updateKeys;
1661 if clickedKey(KEY_MENU_UP) then
1662 begin
1663 m_cur:=m_cur-1;
1664 if m_cur<0 then m_cur:=5;
1665 end;
1666 if clickedKey(KEY_MENU_DOWN) then
1667 begin
1668 m_cur:=m_cur+1;
1669 if m_cur>5 then m_cur:=0;
1670 end;
1671 if clickedKey(KEY_MENU_SELECT) then
1672 begin
1673 if m_cur=0 then begin if menu_game then break; end;
1674 else
1675 if m_cur=1 then menu_tex;
1676 else
1677 if m_cur=2 then menu_sett;
1678 else
1679 if m_cur=3 then menu_help;
1680 else
1681 if m_cur=4 then menu_about;
1682 else
1683 if m_cur=5 then begin save_settings; halt; end;
1684 end;
1686 draw_menu_back;
1688 drawimage(cavelogo,(getWidth/2)-(getimagewidth(cavelogo)/2),0);
1689 setcolor(255,255,0);
1691 DrawFontTextSpec(splash, (getWidth/2)-(length(splash)*FONT_SYM_SIZE/2), spl_y, FONT_YELLOW_COLOR, true);
1693 if spl_y_b then begin if getrelativetimems-spl_del>64 then begin spl_y:=spl_y+1; spl_del:=getrelativetimems; end; if spl_y>getimageheight(cavelogo)+2 then spl_y_b:=false; end;
1694 if not spl_y_b then begin if getrelativetimems-spl_del>64 then begin spl_y:=spl_y-1; spl_del:=getrelativetimems; end; if spl_y<getimageheight(cavelogo)+1 then spl_y_b:=true; end;
1695 drawfonttext(version,0,getHeight-8);
1697 drw_btn('Singleplayer',0,m_cur,0,1);
1698 drw_btn('Texture Packs',1,m_cur,0,1);
1699 drw_btn('Options',2,m_cur,0,1);
1700 drw_btn('Help',3,m_cur,0,1);
1701 drw_btn('About',4,m_cur,0,1);
1702 drw_btn('Quit Game',5,m_cur,0,1);
1704 drawVideo;
1705 maxfps;
1706 until false;
1707 end;
1709 function setBlock(invcur, x, y:integer):boolean;
1710 var
1711 item, sum, block, sblock:integer;
1712 begin
1713 item:=inv.getItem(invcur);
1714 sum:=inv.getSum(invcur);
1715 block:=getMap(x, y);
1716 sblock := Items.GetData(item);
1718 if (Items.GetType(item) = Items.block) and (Inv.IsNull(invcur) = false) then
1719 if Blocks.IsOverlapped(block) then
1720 // if (coll_xy(x, y)=false) or (getBlockColl(item)=0) then
1721 begin
1722 if set_block_code(sblock, x, y)=false then
1723 begin
1725 setmap(sblock, x, y);
1726 if gamemode<>1 then
1727 begin
1728 inv.setSum(inv.getSum(invcur)-1, invcur);
1729 inv.fixNull(invcur);
1730 end;
1732 setBlock:=true;
1733 end;
1734 end;
1735 end;
1737 procedure fishing;
1738 var
1739 x, y:integer;
1740 begin
1741 x:=player.getX;
1742 y:=player.getY;
1743 if (getrelativetimems-fish_time>5000) and (getmap(fx,fy)=50) then
1744 begin
1745 if (random(3)=2) and (getmap(fx,fy)=50) then
1746 begin
1747 drop.create(210,1,x,y);
1748 fish:=false;
1749 end;
1750 inv.setSum(inv.getSum(invslot)-1, invslot);
1751 inv.fixNull(invslot);
1752 fish:=false;
1753 end; else
1754 if (getrelativetimems-fish_time<5000) and (getmap(fx,fy)=50) and (fish=true) then
1755 begin
1756 if getmap(fx,fy-1)=50 then fy:=fy-1;
1757 end;
1758 end;
1760 procedure drawminimap;
1761 var
1762 ix,iy,tmp_gx,tmp_gy,minx,miny,maxx,maxy,loc_camx,loc_camy,x,y:integer;
1763 begin
1764 x:=player.getX;
1765 y:=player.getY;
1766 if load_minimap_tex then
1767 begin
1768 tmp_gx:=(getWidth/2)-(getimagewidth(gui[16])/2);
1769 tmp_gy:=(getHeight/2)-(getimageheight(gui[16])/2);
1770 end;
1771 else
1772 begin
1773 tmp_gx:=(getWidth/2)-(64/2);
1774 tmp_gy:=(getHeight/2)-(64/2);
1775 end;
1777 loc_camx:=(x+4)-(864/2);
1778 loc_camy:=(y+4)-(864/2);
1779 if loc_camx<0 then loc_camx:=0;
1780 if loc_camx>4096-864 then loc_camx:=4096-864;
1781 if loc_camy<0 then loc_camy:=0;
1782 if loc_camy>2048-864 then loc_camy:=2048-864;
1783 minx:=loc_camx/16;
1784 miny:=loc_camy/16;
1785 maxx:=(loc_camx+864)/16;
1786 maxy:=(loc_camy+864)/16;
1787 if minx<0 then minx:=0;
1788 if miny<0 then miny:=0;
1789 if maxx>255 then maxx:=255;
1790 if maxy>127 then maxy:=127;
1792 if load_minimap_tex then
1793 drawimage(gui[16],tmp_gx,tmp_gy);
1794 else
1795 begin
1796 setcolor(214,190,150);
1797 fillrect(tmp_gx,tmp_gy,64,64);
1798 end;
1800 for ix:=minx to maxx do
1801 for iy:=miny to maxy do
1802 begin
1803 if (getmap(ix,iy)=1) or (getmap(ix,iy)=2) or (getmap(ix,iy)=74) then setcolor(121,85,58); else
1804 if (getmap(ix,iy)=4) or (getmap(ix,iy)=9) or (getmap(ix,iy)=11) or (getmap(ix,iy)=28) or (getmap(ix,iy)=29) or ((getmap(ix,iy)>=77) and (getmap(ix,iy)<=86)) or ((getmap(ix,iy)>=88) and (getmap(ix,iy)<=101)) then setcolor(188,152,98); else
1805 if (getmap(ix,iy)=50) or (getmap(ix,iy)=62) then setcolor(38,92,255); else
1806 if getmap(ix,iy)=51 then setcolor(255,0,0); else
1807 if (getmap(ix,iy)=61) or (getmap(ix,iy)=32) then setcolor(255,255,255); else
1808 setcolor(127,127,127);
1810 if (getmap(ix,iy)<>0) then plot(tmp_gx+4+ix-minx,tmp_gy+4+iy-miny);
1811 end;
1812 setcolor(0,0,255);
1813 end;
1815 procedure draw_sign;
1816 var
1817 tmp:string;
1818 str:array[0..3] of string;
1819 i,j,tmp_gx,tmp_gy:integer;
1820 begin
1821 if load_gui_tex then
1822 begin
1823 tmp_gx:=(getWidth/2)-(getimagewidth(sign_im)/2);
1824 tmp_gy:=(getHeight/2)-(getimageheight(sign_im)/2);
1825 end;
1826 else
1827 begin
1828 tmp_gx:=(getWidth/2)-(120/2);
1829 tmp_gy:=(getHeight/2)-(60/2);
1830 end;
1832 tmp:=t_sign[getmapinfo(curx,cury)];
1833 while pos(tmp,#13)<>-1 do
1834 begin
1835 i:=pos(tmp,#13);
1836 str[j]:=copy(tmp,0,i);
1837 tmp:=copy(tmp,i+1,length(tmp));
1838 j:=j+1;
1839 end;
1841 if load_gui_tex then
1842 drawimage(sign_im,tmp_gx,tmp_gy);
1843 else
1844 begin
1845 setcolor(159,132,77);
1846 fillrect(tmp_gx,tmp_gy,120,60);
1847 end;
1849 drawfonttext(str[0],tmp_gx+(120/2)-(length(str[0])*8/2),tmp_gy+(60/4/2)+4);
1850 drawfonttext(str[1],tmp_gx+(120/2)-(length(str[1])*8/2),tmp_gy+(60/4/2)+8+4);
1851 drawfonttext(str[2],tmp_gx+(120/2)-(length(str[2])*8/2),tmp_gy+(60/4/2)+16+4);
1852 drawfonttext(str[3],tmp_gx+(120/2)-(length(str[3])*8/2),tmp_gy+(60/4/2)+24+4);
1853 end;
1855 procedure draw_back(ix,iy:integer);
1856 begin
1857 if getBiomMap(ix)=0 then
1858 begin
1859 if (getBackMap(ix)=iy) then drawimage(back[0],(ix*16)-camx,(iy*16)-camy); else
1860 if (getBackMap(ix)+1=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1861 if (getBackMap(ix)+2=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1862 if (getBackMap(ix)+3=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1863 if (getBackMap(ix)<iy) then drawimage(back[2],(ix*16)-camx,(iy*16)-camy);
1864 end; else
1865 if getBiomMap(ix)=1 then
1866 begin
1867 if (getBackMap(ix)=iy) then drawimage(back[4],(ix*16)-camx,(iy*16)-camy); else
1868 if (getBackMap(ix)+1=iy) then drawimage(back[4],(ix*16)-camx,(iy*16)-camy); else
1869 if (getBackMap(ix)+2=iy) then drawimage(back[6],(ix*16)-camx,(iy*16)-camy); else
1870 if (getBackMap(ix)+3=iy) then drawimage(back[6],(ix*16)-camx,(iy*16)-camy); else
1871 if (getBackMap(ix)<iy) then drawimage(back[2],(ix*16)-camx,(iy*16)-camy);
1872 end; else
1873 if getBiomMap(ix)=2 then
1874 begin
1875 if (getBackMap(ix)=iy) then drawimage(back[5],(ix*16)-camx,(iy*16)-camy); else
1876 if (getBackMap(ix)+1=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1877 if (getBackMap(ix)+2=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1878 if (getBackMap(ix)+3=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1879 if (getBackMap(ix)<iy) then drawimage(back[2],(ix*16)-camx,(iy*16)-camy);
1880 end; else
1881 if getBiomMap(ix)=3 then
1882 begin
1883 if (getBackMap(ix)=iy) then drawimage(back[7],(ix*16)-camx,(iy*16)-camy); else
1884 if (getBackMap(ix)+1=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1885 if (getBackMap(ix)+2=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1886 if (getBackMap(ix)+3=iy) then drawimage(back[1],(ix*16)-camx,(iy*16)-camy); else
1887 if (getBackMap(ix)<iy) then drawimage(back[2],(ix*16)-camx,(iy*16)-camy);
1888 end; else
1889 if getBiomMap(ix)=4 then
1890 begin
1891 drawimage(back[8],(ix*16)-camx,(iy*16)-camy);
1892 end;
1893 end;
1895 procedure draw;
1896 var
1897 ix,iy,iz,minx,miny,maxx,maxy,tmp_ax,tim,smy,pa_xo, x, y:integer;
1898 begin
1899 x:=player.getX;
1900 y:=player.getY;
1901 {===================[sky]===================}
1902 tim:=10000*getimagewidth(sky)/600000*game_time/10000;
1903 setcolor(effects.get(sky,tim,0,1),effects.get(sky,tim,0,2),effects.get(sky,tim,0,3));
1904 fillrect(0,0,getWidth,getHeight);
1905 srand(seed);
1906 if drw_stars then
1907 begin
1908 setcolor(effects.get(sky,tim,2,1),effects.get(sky,tim,2,2),effects.get(sky,tim,2,3));
1909 smy:=10000*getWidth*2/600000*game_time/10000;
1910 for iz:=1 to getWidth do
1911 begin
1912 ix:=rnd(getWidth*2)-getWidth+smy;
1913 if ix>getWidth then ix:=ix-getWidth*2;
1914 iy:=rnd(getHeight);
1915 if (ix>-1) and (ix<getWidth) then plot(ix,iy);
1916 end;
1917 end;
1919 if drw_sm then
1920 begin
1921 if load_sm>0 then
1922 begin
1923 smy:=10000*(getWidth+getimagewidth(sun))/300000*game_time/10000;
1924 drawimage(sun,smy-getimagewidth(sun),getHeight/2-getimageheight(sun)/2);
1925 end;
1926 else
1927 begin
1928 setcolor(255,213,74);
1929 smy:=10000*(getWidth+sm_siz)/300000*game_time/10000;
1930 fillrect(smy-sm_siz+sm_siz4,getHeight/2-sm_siz/2+sm_siz4,sm_siz-sm_siz4,sm_siz-sm_siz4);
1931 end;
1933 if load_sm>0 then
1934 begin
1935 smy:=10000*(getWidth+getimagewidth(moon))/300000*(game_time-300000)/10000;
1936 drawimage(moon,smy-getimagewidth(moon),getHeight/2-getimageheight(moon)/2);
1937 end;
1938 else
1939 begin
1940 setcolor(175,184,204);
1941 smy:=10000*(getWidth+sm_siz)/300000*(game_time-300000)/10000;
1942 fillrect(smy-sm_siz+sm_siz4,getHeight/2-sm_siz/2+sm_siz4,sm_siz-sm_siz4,sm_siz-sm_siz4);
1943 end;
1944 end;
1945 {===================[camera]===================}
1946 camx:=(x+4)-(getWidth/2);
1947 camy:=(y+4)-(getHeight/2);
1948 if camx<0 then camx:=0;
1949 if camx>4096-getWidth then camx:=4096-getWidth;
1950 if camy>2048-getHeight then camy:=2048-getHeight;
1951 {===================[max_draw]===================}
1952 minx:=camx/16;
1953 miny:=camy/16;
1954 maxx:=(camx+getWidth)/16;
1955 maxy:=(camy+getHeight)/16;
1956 if minx<0 then minx:=0;
1957 if miny<0 then miny:=0;
1958 if maxx>255 then maxx:=255;
1959 if maxy>127 then maxy:=127;
1960 {===================[draw_back]===================}
1961 for ix:=minx to maxx do
1962 for iy:=miny to maxy do
1963 begin
1964 if ifosad and osadki and (getBackMap(ix) >= iy) and Blocks.IsTransporent(getmap(ix, iy)) then begin
1965 if getBiomMap(ix) = 0 then drawimage(osad[0, osadki_ani], (ix * 16) - camx, (iy * 16) - camy)
1966 else if getBiomMap(ix) = 2 then drawimage(osad[1, osadki_ani], (ix * 16) - camx, (iy * 16) - camy)
1967 else if getBiomMap(ix) = 3 then drawimage(osad[0, osadki_ani], (ix * 16) - camx, (iy * 16) - camy)
1968 end;
1969 if drw_back and Blocks.IsTransporent(getmap(ix, iy)) then draw_back(ix, iy);
1970 if Blocks.IsForeground(getmap(ix,iy)) = false then draw_block(ix,iy);
1971 end;
1972 {===================[drop]===================}
1973 Drop.Draw(camx, camy);
1974 {===================[particles]===================}
1975 Particles.Draw(camx, camy);
1976 {===================[player]===================}
1977 Player.Draw(camx, camy);
1978 {===================[mobs]===================}
1979 Mobs.Draw(camx, camy);
1980 {===================[draw_blocks]===================}
1981 for ix:=minx to maxx do
1982 for iy:=miny to maxy do
1983 begin
1984 if Blocks.IsForeground(getmap(ix, iy)) then draw_block(ix, iy);
1986 setcolor(0, 0, 0);
1987 if light_type = 1 then
1988 begin
1989 if getmaplight(ix,iy) = 0 then
1990 fillrect((ix * 16) - camx, (iy * 16) - camy, 16, 16);
1991 end;
1992 else if light_type = 2 then
1993 begin
1994 if getmaplight(ix, iy) < 15 then
1995 drawimage(light[getmaplight(ix, iy)], (ix * 16) - camx, (iy * 16) - camy);
1996 end;
1997 end;
1999 // debug
2000 // drawimage(light[getmaplight(player.getX div 16, player.getY div 16)], 0, 0);
2002 if (toolus > 0) and (toolind < 10) and (getmap(curx,cury) > 0) then
2003 begin
2004 if toolind > 9 then
2005 toolind:=9;
2006 drawimage(tue[toolind], curx * 16 - camx, cury * 16 - camy);
2007 end;
2008 {===================[gui]===================}
2009 if drawgui then
2010 begin
2011 tmp_ax:=(getWidth/2)-(getImageWidth(gui[1])/2);
2013 if keymode=1 then
2014 drawimage(gui[0],curx*16-camx,cury*16-camy);
2016 DrawWindows;
2017 /*if keymode=2 then
2018 if gamemode<>1 then
2019 DrawPlayerInventory;
2020 else
2021 drawinv_c; else
2022 if keymode=3 then drawcraft; else
2023 if keymode=4 then drawchest; else
2024 if keymode=5 then draw_sign; else
2025 if keymode=6 then drawfurnace; else
2026 if ifminimap then drawminimap;*/
2028 drawimage(gui[1],tmp_ax,0);
2029 for ix:=0 to 8 do
2030 begin
2031 Items.Draw(inv.getItem(ix), inv.getSum(ix), (ix*16)+tmp_ax+ix*2+4, 1, true);
2032 end;
2033 drawimage(gui[17],(invslot*16)+tmp_ax+invslot*2+2,0);
2035 if gamemode<>1 then
2036 begin
2037 if gamemode=0 then
2038 begin
2039 for ix:=0 to (hp div 2)-1 do drawimage(gui[13],ix*9,getHeight-9);
2040 if (hp mod 2)<>0 then begin drawimage(gui[14],ix*9,getHeight-9); ix:=ix+1 end;
2041 for ix:=ix to 9 do drawimage(gui[15],ix*9,getHeight-9);
2042 end; else
2043 if gamemode=2 then
2044 begin
2045 for ix:=0 to (hp div 2)-1 do drawimage(gui[31],ix*9,getHeight-9);
2046 if (hp mod 2)<>0 then begin drawimage(gui[32],ix*9,getHeight-9); ix:=ix+1 end;
2047 for ix:=ix to 9 do drawimage(gui[33],ix*9,getHeight-9);
2048 end;
2050 for ix:=0 to (hunger div 2)-1 do drawimage(gui[26],ix*9,getHeight-18);
2051 if (hunger mod 2)<>0 then begin drawimage(gui[27],ix*9,getHeight-18); ix:=ix+1 end;
2052 for ix:=ix to 9 do drawimage(gui[28],ix*9,getHeight-18);
2054 if getmap((x+4)/16,y/16)=50 then
2055 begin
2056 for ix:=0 to (air div 2)-1 do drawimage(gui[29],ix*9,getHeight-27);
2057 if (air mod 2)<>0 then begin drawimage(gui[30],ix*9,getHeight-27); ix:=ix+1 end;
2058 end;
2059 end;
2061 for ix:=0 to 3 do
2062 begin
2063 drawfonttext(msg[ix],0,getHeight-20-ix*9);
2064 if getrelativetimems-msg_time[ix]>5000 then msg[ix]:='';
2065 end;
2066 end;
2067 end;
2069 procedure load_moon(path:string;phase:integer);
2070 var
2071 no:image;
2072 begin
2073 moon:=no;
2074 if load_sm=1 then
2075 begin
2076 moon:=ld_tex('moon_phase_'+phase+'.png',path,'terrain/moon_phases/');
2077 end; else
2078 if load_sm=2 then
2079 begin
2080 moon:=resize_image(ld_tex('moon_phase_'+phase+'.png',path,'terrain/moon_phases/'),(getWidth+getHeight)/5,(getWidth+getHeight)/5);
2081 end;
2082 end;
2084 procedure sleep;
2085 var
2086 i,ix,iy:integer;
2087 begin
2088 if game_time>300000 then
2089 begin
2090 if load_light_tex then
2091 begin
2092 keymode:=0;
2093 i:=15;
2094 while i>0 do
2095 begin
2096 for iy:=0 to getheight/16 do
2097 for ix:=0 to getwidth/16 do
2098 drawimage(light[i],ix*16,iy*16);
2099 i:=i-1;
2100 drawVideo;
2101 delay(100);
2102 end;
2103 moon_phase:=moon_phase+1;
2104 if moon_phase>7 then moon_phase:=0;
2105 load_moon('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/',moon_phase);
2106 game_time:=50000;
2107 last_sleep_x:=curx;
2108 last_sleep_y:=cury-1;
2109 i:=1;
2110 while i<15 do
2111 begin
2112 draw;
2113 for iy:=0 to getheight/16 do
2114 for ix:=0 to getwidth/16 do
2115 drawimage(light[i],ix*16,iy*16);
2116 i:=i+1;
2117 drawVideo;
2118 delay(100);
2119 end;
2120 end;
2121 else
2122 begin
2123 keymode:=0;
2124 i:=0;
2125 while i<=getheight do
2126 begin
2127 setcolor(0,0,0);
2128 fillrect(0,0,getwidth,i);
2129 i:=i+5;
2130 drawVideo;
2131 delay(50);
2132 end;
2133 moon_phase:=moon_phase+1;
2134 if moon_phase>7 then moon_phase:=0;
2135 load_moon('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/',moon_phase);
2136 game_time:=50000;
2137 last_sleep_x:=curx;
2138 last_sleep_y:=cury-1;
2139 i:=0;
2140 while i<=getheight do
2141 begin
2142 draw;
2143 setcolor(0,0,0);
2144 fillrect(0,i,getwidth,getheight);
2145 i:=i+5;
2146 drawVideo;
2147 delay(50);
2148 end;
2149 end;
2150 end; else create_msg('You can sleep only at night');
2151 end;
2153 procedure resetToolProgerss;
2154 begin
2155 toolus:=0;
2156 toolind:=0;
2157 end;
2159 procedure usetools(invcur, x, y:integer);
2160 var
2161 item, sum, block:integer;
2162 begin
2163 block:=getmap(x, y);
2164 item:=inv.getItem(invcur);
2165 sum:=inv.getSum(invcur);
2167 if gamemode=1 then
2168 destroy_block_cr(block, x, y);
2169 else
2170 if (block>0) then
2171 begin
2172 if (Items.GetType(item) = Items.tool) and (getBlockTool(block)=getToolType(item)) then
2173 toolus:=toolus+getToolSpeed(item);
2174 else
2175 toolus:=toolus+1;
2177 if toolus>=getBlockHP(block) then
2178 begin
2179 if ((Items.GetType(item) = Items.tool) and (getBlockTool(block)=getToolType(item)) and (getToolLvl(item)>=getBlockLvl(block))) or (getBlockLvl(block)<=0) then
2180 begin
2181 setMap(0, x, y);
2182 destroy_block_1(block, x, y);
2183 setMapInfo(0, x, y);
2184 end;
2185 else
2186 begin
2187 setMap(0, x, y);
2188 destroy_block_0(block, x, y);
2189 setMapInfo(0, x, y);
2190 end;
2192 if Items.GetType(item) = Items.tool then
2193 begin
2194 inv.setSum(inv.getSum(invcur)-1, invcur);
2195 inv.fixNull(invcur);
2196 end;
2198 toolus:=0;
2199 toolind:=0;
2200 end;
2201 end;
2203 if (toolus>0) and (toolus<=getBlockHP(block)) then
2204 toolind:=((toolus*100) div getBlockHP(block)) div 10;
2205 end;
2207 function rt_useweap:boolean;
2208 var
2209 x, y, w, h, i, damg:integer;
2210 item:integer;
2211 begin
2212 x:=player.getX;
2213 y:=player.getY;
2214 w:=player.getW;
2215 h:=player.getH;
2216 item:=inv.getItem(invslot);
2218 if Items.GetType(item) = Items.tool then
2219 damg:=getToolDamg(item);
2220 else
2221 damg:=1;
2223 if posi=0 then
2224 i:=Mobs.findAndHit(damg, x-TILE_SIZE, y, TILE_SIZE+(w/2), h, -2, -3);
2225 else
2226 i:=Mobs.findAndHit(damg, x+(w/2), y, TILE_SIZE+(w/2), h, 2, -3);
2228 if i<>-1 then
2229 begin
2230 inv.setSum(inv.getSum(invslot)-1, invslot);
2231 inv.fixNull(invslot);
2232 rt_useweap:=true;
2233 end;
2234 end;
2236 procedure rt_usetools;
2237 var
2238 x, y:integer;
2239 begin
2240 x:=player.getX;
2241 y:=player.getY;
2243 if posi=0 then curx:=(x div 16)-1; else curx:=(x div 16)+1;
2244 cury:=y div 16;
2245 if getmap(curx,cury)=0 then cury:=cury+1;
2247 if curx<0 then curx:=0;
2248 if curx>255 then curx:=255;
2249 if cury<0 then cury:=0;
2250 if cury>127 then cury:=127;
2252 usetools(invslot, curx, cury);
2253 end;
2255 procedure rt_usemob;
2256 var
2257 x, y:integer;
2258 begin
2259 x:=player.getX;
2260 y:=player.getY;
2262 if posi=0 then curx:=(x div 16)-1; else curx:=(x div 16)+1;
2263 cury:=y div 16;
2264 if getmap(curx,cury)=0 then cury:=cury+1;
2266 if curx<0 then curx:=0;
2267 if curx>255 then curx:=255;
2268 if cury<0 then cury:=0;
2269 if cury>127 then cury:=127;
2271 //usemob(curx,cury);
2272 end;
2274 procedure actionUse(invcur, x, y:integer);
2275 begin
2276 if setBlock(invcur, x, y)=false then
2277 if useBlock(invcur, x, y) then
2278 if useItem(invcur, x, y) then
2279 end;
2281 procedure rt_useblock;
2282 var
2283 x, y:integer;
2284 begin
2285 x:=player.getX;
2286 y:=player.getY;
2288 if posi=0 then curx:=(x div 16)-1; else curx:=(x div 16)+1;
2289 cury:=y div 16;
2290 if getmap(curx,cury)=0 then cury:=cury+1;
2292 if curx<0 then curx:=0;
2293 if curx>255 then curx:=255;
2294 if cury<0 then cury:=0;
2295 if cury>127 then cury:=127;
2297 actionUse(invslot, curx, cury);
2298 end;
2300 procedure go_to_nether;
2301 var
2302 ix:integer;
2303 begin
2304 portal_time:=getrelativetimems;
2305 savegame('/'+sd+'/cavecraft/saves/'+sav_fl+'/');
2306 pl_world:=1;
2307 drw_load_line('Matrix',10);
2308 if loadworld('/'+sd+'/cavecraft/saves/'+sav_fl+'/')=true then
2309 begin
2310 player.setX(get_spawn_x*16+4);
2311 player.setY((get_up(get_spawn_x)-1)*16);
2312 end;
2313 else
2314 begin
2315 {for ix:=0 to 31 do
2316 begin
2317 mob[ix].m_type:=0;
2318 mob[ix].m_x:=0;
2319 mob[ix].m_y:=0;
2320 mob[ix].m_posi:=0;
2321 mob[ix].m_velx:=0;
2322 mob[ix].m_vely:=0;
2323 mob[ix].m_ani:=0;
2324 mob[ix].m_min_vely:=0;
2325 mob[ix].m_hp:=0;
2326 mob[ix].m_del:=0;
2327 mob[ix].m_fall:=false;
2328 mob[ix].m_jmp:=false;
2329 mob[ix].m_velani:=false;
2330 end;}
2332 drop.resetData;
2333 gennether;
2334 //netherspawn;
2335 end;
2336 end;
2338 procedure go_to_world;
2339 begin
2340 portal_time:=getrelativetimems;
2341 savegame('/'+sd+'/cavecraft/saves/'+sav_fl+'/');
2342 pl_world:=0;
2343 drw_load_line('Matrix',10);
2344 if loadworld('/'+sd+'/cavecraft/saves/'+sav_fl+'/')=true then
2345 begin
2346 pl_world:=0;
2347 end;
2348 else
2349 begin
2350 debug('ERROR!!!');
2351 pl_world:=0;
2352 genworld;
2353 //megaspawn;
2354 end;
2355 end;
2357 procedure plr_is_dead_hardcore;
2358 begin
2359 keymode:=0;
2360 toolus:=0;
2361 toolind:=0;
2363 repeat
2364 updateKeys;
2365 if clickedKey(KEY_MENU_SELECT) then
2366 begin
2367 deleteworld('/'+sd+'/cavecraft/saves/'+sav_fl+'/');
2368 menu;
2369 exit;
2370 end;
2371 draw;
2372 drawfonttext('You died!',getwidth/2-32,getheight/2-16);
2374 drw_btn('Delete world',0,0,0,1);
2376 drawVideo;
2377 delay(1);
2378 until false;
2380 end;
2382 procedure plr_is_dead;
2383 var
2384 m_cur:integer;
2385 x, y:integer;
2386 begin
2387 x:=player.getX;
2388 y:=player.getY;
2389 keymode:=0;
2390 toolus:=0;
2391 toolind:=0;
2392 repeat
2393 updateKeys;
2394 if clickedKey(KEY_MENU_UP) then
2395 begin
2396 m_cur:=m_cur-1;
2397 if m_cur<0 then m_cur:=1;
2398 end;
2399 if clickedKey(KEY_MENU_DOWN) then
2400 begin
2401 m_cur:=m_cur+1;
2402 if m_cur>1 then m_cur:=0;
2403 end;
2404 if clickedKey(KEY_MENU_SELECT) then
2405 begin
2406 if m_cur=0 then
2407 begin
2408 if pl_world=0 then
2409 begin
2410 if last_sleep_x=0 then
2411 begin
2412 x:=get_spawn_x*16+4;
2413 y:=get_spawn_y*16;
2414 end; else
2415 begin
2416 x:=last_sleep_x*16+4;
2417 y:=last_sleep_y*16;
2418 end;
2419 end; else
2420 if pl_world=1 then
2421 begin
2422 go_to_world;
2423 if last_sleep_x=0 then
2424 begin
2425 x:=get_spawn_x*16+4;
2426 y:=get_spawn_y*16;
2427 end; else
2428 begin
2429 x:=last_sleep_x*16+4;
2430 y:=last_sleep_y*16;
2431 end;
2432 end;
2433 player.setX(x);
2434 player.setY(y);
2435 posi:=0;
2436 curx:=0;
2437 cury:=0;
2438 vely:=0;
2439 jmp:=false;
2440 hp:=20;
2441 hunger:=20;
2442 exit;
2443 end;
2444 else
2445 if m_cur=1 then begin menu; exit; end;
2446 end;
2448 draw;
2450 drawfonttext('You died!',getwidth/2-32,getheight/2-16);
2452 drw_btn('Respawn',0,m_cur,0,1);
2453 drw_btn('Main menu',1,m_cur,0,1);
2455 drawVideo;
2456 delay(1);
2457 until false;
2458 end;
2460 procedure fast_menu;
2461 var
2462 m_cur,i:integer;
2463 begin
2464 repeat
2465 updateKeys;
2466 if clickedKey(KEY_MENU_UP) then begin m_cur:=m_cur-1; if m_cur<0 then m_cur:=3; end;
2467 if clickedKey(KEY_MENU_DOWN) then begin m_cur:=m_cur+1; if m_cur>3 then m_cur:=0; end;
2468 if clickedKey(KEY_MENU_SELECT) then
2469 begin
2470 if m_cur=0 then
2471 begin
2472 exit;
2473 end; else
2474 if m_cur=1 then
2475 begin
2476 savegame('/'+sd+'/cavecraft/saves/'+sav_fl+'/');
2477 exit;
2478 end; else
2479 if m_cur=2 then
2480 begin
2481 menu_sett;
2482 end; else
2483 if m_cur=3 then
2484 begin
2485 //clear_gui(keymode);
2486 menu;
2487 exit;
2488 end;
2489 end;
2490 draw;
2491 drawfonttext('Game menu',getwidth/2-36,getheight/2-20);
2492 drw_btn('Back to Game',0,m_cur,0,1);
2493 drw_btn('Save Game',1,m_cur,0,1);
2494 drw_btn('Options',2,m_cur,0,1);
2495 drw_btn('Quit to Title',3,m_cur,0,1);
2497 drawVideo;
2498 delay(1);
2499 until false;
2500 end;
2502 procedure keyFastInv;
2503 begin
2504 if clickedKey(KEY_FASTINV_NEXT) then
2505 begin
2506 invslot:=invslot-1;
2507 if invslot<0 then
2508 invslot:=8;
2509 end;
2511 if clickedKey(KEY_FASTINV_PREV) then
2512 begin
2513 invslot:=invslot+1;
2514 if invslot>8 then
2515 invslot:=0;
2516 end;
2517 end;
2519 procedure keyConsole;
2520 begin
2521 if clickedKey(KEY_CHAT) then
2522 SetTimer(1000,T_CONSOLE);
2524 if pressedKey(KEY_CHAT) then
2525 begin
2526 if GetTimer(T_CONSOLE)=TIMER_OK then
2527 begin
2528 call_console;
2529 ResetTimer(T_CONSOLE);
2530 end;
2531 end;
2532 else
2533 begin
2534 if GetTimer(T_CONSOLE)>TIMER_OK then
2535 begin
2536 deb:= not deb;
2537 ResetTimer(T_CONSOLE);
2538 end;
2539 end;
2540 end;
2542 procedure keyInventory;
2543 begin
2544 if clickedKey(KEY_PLR_OPENINV) then
2545 if gamemode<>1 then
2546 OpenPlayerInventory;
2547 else
2548 OpenCreativeWindow;
2549 end;
2551 procedure keyhandler;
2552 begin
2553 updateKeys;
2555 if WindowKeyHanler then
2556 begin
2557 if keymode=0 then
2558 begin
2559 keyInventory;
2560 keyFastInv;
2561 keyConsole;
2563 if clickedKey(KEY_PLR_EDITMODE) then
2564 begin
2565 keymode:=1;
2566 curx:=player.getX div 16;
2567 cury:=player.getY div 16;
2568 end;
2570 if clickedKey(KEY_PLR_USE) then
2571 rt_usemob;
2573 if clickedKey(KEY_MENU) then
2574 fast_menu;
2576 if clickedKey(KEY_PLR_ATTACK) then
2577 if rt_useweap=false then
2578 debug('useweap');
2580 if pressedKey(KEY_PLR_ATTACK) then
2581 begin
2582 rt_usetools;
2583 playAnim(ANIM_HAND);
2584 end;
2585 else
2586 begin
2587 resetToolProgerss;
2588 cancelAnim(ANIM_HAND);
2589 end;
2591 if pressedKey(KEY_PLR_UP) then
2592 player.gotoUP;
2593 if pressedKey(KEY_PLR_DOWN) then
2594 player.gotoDOWN;
2595 if pressedKey(KEY_PLR_LEFT) then
2596 player.gotoLEFT;
2597 if pressedKey(KEY_PLR_RIGHT) then
2598 player.gotoRIGHT;
2599 end;
2600 else
2601 if keymode=1 then
2602 begin
2603 keyInventory;
2604 keyFastInv;
2605 keyConsole;
2607 if clickedKey(KEY_PLR_UP) then
2608 begin
2609 cury:=cury-1;
2610 if cury<0 then
2611 cury:=0;
2612 end;
2613 if clickedKey(KEY_PLR_DOWN) then
2614 begin
2615 cury:=cury+1;
2616 if cury>127 then
2617 cury:=127;
2618 end;
2619 if clickedKey(KEY_PLR_LEFT) then
2620 begin
2621 curx:=curx-1;
2622 if curx<0 then
2623 curx:=0;
2624 end;
2625 if clickedKey(KEY_PLR_RIGHT) then
2626 begin
2627 curx:=curx+1;
2628 if curx>255 then
2629 curx:=255;
2630 end;
2632 if clickedKey(KEY_PLR_EDITMODE) then
2633 keymode:=0;
2635 if clickedKey(KEY_PLR_USE) then
2636 actionUse(invslot, curx, cury);
2638 if pressedKey(KEY_PLR_ATTACK) then
2639 begin
2640 usetools(invslot, curx, cury);
2641 playAnim(ANIM_HAND);
2642 end;
2643 else
2644 begin
2645 resetToolProgerss;
2646 cancelAnim(ANIM_HAND);
2647 end;
2649 if clickedKey(KEY_MENU) then
2650 fast_menu;
2651 end;
2653 end;
2655 end;
2657 procedure phyhandler;
2658 var
2659 i:integer;
2660 begin
2661 Player.CalcPhysics;
2662 Mobs.UpdatePhy;
2663 Drop.CalcPhy;
2664 end;
2666 procedure light_fillrect(l,x,y,r:integer);
2667 var
2668 ix,iy,ym,yp,xm,xp:integer;
2669 begin
2670 ym:=y-r;
2671 yp:=y+r;
2672 xm:=x-r;
2673 xp:=x+r;
2674 for ix:=xm to xp do
2675 for iy:=ym to yp do
2676 setmaplight(getmaplight(ix,iy)+l,ix,iy);
2677 end;
2679 procedure light_rect(l,x,y,r:integer);
2680 var
2681 ix,iy,ym,yp,xm,xp:integer;
2682 begin
2683 ym:=y-r;
2684 yp:=y+r;
2685 xm:=x-r;
2686 xp:=x+r;
2687 for ix:=xm to xp do
2688 begin
2689 setmaplight(getmaplight(ix,ym)+l,ix,ym);
2690 setmaplight(getmaplight(ix,yp)+l,ix,yp);
2691 end;
2692 for iy:=ym+1 to yp-1 do
2693 begin
2694 setmaplight(getmaplight(xm,iy)+l,xm,iy);
2695 setmaplight(getmaplight(xp,iy)+l,xp,iy);
2696 end;
2697 end;
2699 procedure calc_light(m,x,y:integer);
2700 var
2701 ix,iy,l,ss,sf:integer;
2702 begin
2703 if light_type=1 then light_fillrect(m,x,y,m/2); else
2704 for l:=m downto 1 do
2705 begin
2706 if ss mod 2=0 then light_rect(l,x,y,ss/2);
2707 ss:=ss+1;
2708 end;
2709 end;
2711 procedure calc_sun(ix,m:integer);
2712 var
2713 iy,ss:integer;
2714 begin
2715 ss:=m;
2716 for iy:=0 to 127 do
2717 begin
2718 setmaplight(ss,ix,iy);
2719 if ss=0 then break;
2720 ss:=ss-getBlockTr(getmap(ix,iy));
2721 if ss<0 then ss:=0;
2722 end;
2723 for iy:=iy+1 to 127 do
2724 begin
2725 setmaplight(0,ix,iy);
2726 end;
2727 end;
2729 procedure kill_plr;
2730 var
2731 i:integer;
2732 begin
2733 hp:=0;
2734 for i:=0 to INV_SIZE do
2735 begin
2736 if inv.isNull(i)=false then
2737 player.dropItem(inv.getItem(i), inv.getSum(i));
2738 inv.setItem(0, i);
2739 inv.setSum(0, i);
2740 end;
2741 if gamemode<2 then plr_is_dead; else plr_is_dead_hardcore;
2742 end;
2744 procedure hunger_and_air;
2745 var
2746 x, y:integer;
2747 begin
2748 x:=player.getX;
2749 y:=player.getY;
2750 if gamemode<>1 then
2751 begin
2752 if getrelativetimems-hung_time>=90000/(gamemode+1) then
2753 begin
2754 hung_time:=getrelativetimems;
2755 hunger:=hunger-1;
2756 end;
2757 if getrelativetimems-hp_time>=5000*(gamemode+1) then
2758 begin
2759 if hunger>16 then
2760 begin
2761 hp_time:=getrelativetimems;
2762 hp:=hp+1;
2763 if hp>20 then hp:=20;
2764 end; else
2765 if hunger<1 then
2766 begin
2767 hp_time:=getrelativetimems;
2768 hp:=hp-1;
2769 if hp<1 then if gamemode<2 then hp:=1;
2770 end;
2771 end;
2773 if getmap((x+4)/16,y/16)=50 then
2774 begin
2775 if getrelativetimems-air_time>=500 then
2776 begin
2777 air:=air-1;
2778 air_time:=getrelativetimems;
2779 if air<1 then
2780 begin
2781 hp_time:=getrelativetimems;
2782 hp:=hp-2;
2783 end;
2784 end;
2785 end; else
2786 air:=21;
2787 end;
2788 end;
2790 procedure game;
2791 var
2792 ix,iy,minx,maxx,miny,maxy,fps_t,tim, x, y:integer;
2793 begin
2794 x:=player.getX;
2795 y:=player.getY;
2797 hunger_and_air;
2799 if hunger<0 then hunger:=0;
2800 if air<0 then air:=0;
2802 fps_t:=fps;
2803 if fps_t<1 then fps_t:=1;
2805 if bl_ani5_d then
2806 if bl_ani5_v=false then
2807 begin
2808 bl_ani5:=bl_ani5+1;
2809 if bl_ani5>4 then
2810 begin
2811 bl_ani5:=4;
2812 bl_ani5_v:=not bl_ani5_v;
2813 end;
2814 end;
2815 else
2816 begin
2817 bl_ani5:=bl_ani5-1;
2818 if bl_ani5<0 then
2819 begin
2820 bl_ani5:=0;
2821 bl_ani5_v:=not bl_ani5_v;
2822 end;
2823 end;
2824 bl_ani5_d:=not bl_ani5_d;
2826 drop.reflux;
2827 player.getDrop;
2829 game_time:=game_time+(600000 div (fps_t*1000));
2831 // Ускорение игрового времени в 10 раз
2832 // game_time := game_time + (600000 div (fps_t*100));
2834 if (game_time>600000) or (game_time<0) then
2835 begin
2836 game_time:=0;
2837 moon_phase:=moon_phase+1;
2838 if moon_phase>7 then moon_phase:=0;
2839 load_moon('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/',moon_phase);
2840 end;
2842 tim := 10000 * getimagewidth(sky) / 600000 * game_time / 10000;
2843 global_light := effects.get(sky, tim, 1, 1) div 16;
2845 if clock_stage<>game_time div 75000 then begin clock_stage:=clock_stage+1; if clock_stage>7 then clock_stage:=0; end;
2847 if x<0 then x:=0;
2848 if x+8>4094 then x:=4086;
2849 if getBlockColl(getmap(x div 16, y div 16))>0 then hp:=hp-1;
2850 if random(4096)=random(4096) then begin osadki:=not osadki; end;
2851 osadki_ani:=osadki_ani+1;
2852 if osadki_ani>7 then osadki_ani:=0;
2854 if Random(20) = Random(20) then Particles.Create(Particles.bubble, x, y);
2856 if gamemode=1 then begin hp:=666; hunger:=666; end;
2858 if inv.getItem(invslot)=186 then
2859 ifminimap:=true;
2860 else
2861 ifminimap:=false;
2863 //if s_spawn_mob then if random(4096)=1547 then megaspawn;
2865 Mobs.Update;
2866 Particles.Update;
2868 if light_type>0 then
2869 begin
2870 minx:=camx/16-1;
2871 maxx:=(camx+getWidth)/16+1;
2872 if minx<0 then minx:=0;
2873 if maxx>255 then maxx:=255;
2874 for ix:=minx to maxx do calc_sun(ix,global_light);
2875 end;
2877 minx:=camx/16-8;
2878 maxx:=(camx+getWidth)/16+16;
2879 miny:=camy/16-8;
2880 maxy:=(camy+getHeight)/16+16;
2881 if minx<0 then minx:=0;
2882 if maxx>255 then maxx:=255;
2883 if miny<0 then miny:=0;
2884 if maxy>127 then maxy:=127;
2885 for ix:=minx to maxx do
2886 for iy:=miny to maxy do
2887 begin
2888 if light_type=0 then setmaplight(15,ix,iy);
2889 else
2890 if light_type>0 then if getBlockLi(getmap(ix,iy))>0 then calc_light(getBlockLi(getmap(ix,iy)),ix,iy);
2891 end;
2893 minx:=(camx/16)-((getwidth/2)/16);
2894 miny:=(camy/16)-((getheight/2)/16);
2895 maxx:=(camx+(getWidth+getWidth/2))/16;
2896 maxy:=(camy+(getHeight+getHeight/2))/16;
2897 if minx<0 then minx:=0;
2898 if miny<0 then miny:=0;
2899 if maxx>255 then maxx:=255;
2900 if maxy>127 then maxy:=127;
2901 if updx<minx then updx:=minx;
2902 if updy<miny then updy:=miny;
2903 if updx>maxx then updx:=minx;
2904 if updy>maxy then updy:=miny;
2906 if bl_upd>0 then
2907 begin
2908 for ix:=0 to (((2*getWidth/16)*(2*getHeight/16))-1) div ((fps_t*bl_upd)) do
2909 begin
2910 updateBlock(updx, updy);
2911 updx:=updx+1;
2912 if updx>maxx then
2913 begin
2914 updx:=minx;
2915 updy:=updy+1;
2916 if updy>maxy then updy:=miny;
2917 end;
2918 end;
2919 end;
2921 {if coll_bl(110)=true then
2922 begin
2923 if getrelativetimems-portal_time>5000 then
2924 begin
2925 if pl_world=0 then begin go_to_nether; portal_time:=getrelativetimems; end; else
2926 if pl_world=1 then begin go_to_world; portal_time:=getrelativetimems; end;
2927 end;
2928 end;
2930 if coll_bl(51)=true then hp:=hp-1;
2932 if coll_bl(59)=true then
2933 begin
2934 if vely<0 then vely:=-1;
2935 else
2936 if vely>0 then vely:=1;
2937 end;}
2939 if gamemode<>1 then
2940 begin
2941 if hp>20 then hp:=20;
2942 if hunger>20 then hunger:=20;
2943 end;
2945 if y>2048 then kill_plr;
2946 if (hp<1) and (gamemode<>1) then kill_plr;
2947 if fish=true then fishing;
2949 if (fish=true) and (inv.getItem(invslot)<>152) then fish:=false;
2951 //if (keymode>3) and (cury<(y div 16)-4) then begin clear_gui(keymode); keymode:=0; curx:=x div 16; cury:=y div 16; end;
2953 if gamemode<>1 then
2954 begin
2955 if cury<(y div 16)-4 then cury:=(y div 16)-4;
2956 if cury>(y div 16)+5 then cury:=(y div 16)+5;
2957 if curx<(x div 16)-4 then curx:=(x div 16)-4;
2958 if curx>(x div 16)+4 then curx:=(x div 16)+4;
2959 end;
2961 UpdateFurnaces;
2962 end;
2964 procedure qt_start;
2965 var
2966 i:integer;
2967 begin
2968 drawgui:=true;
2969 LoadDrawFont('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');
2970 drawdeadlogo;
2971 start_uu;
2972 if load_key_tex=1 then init_touch;
2973 for i:=0 to 4 do
2974 begin
2975 msg[i]:='';
2976 msg_time[i]:=getrelativetimems;
2977 end;
2978 InitMap(MAP_W, MAP_H);
2979 menu;
2980 end;
2982 procedure draw_debug;
2983 var
2984 i : Integer;
2985 begin
2986 //drawfonttext('X:'+(x div 16-128),0,0);
2987 //drawfonttext('Y:'+integertostring(127-(y div 16)),0,8);
2988 drawfonttext('CURX:'+(curx-128),0,16);
2989 drawfonttext('CURY:'+cury,0,24);
2990 drawfonttext('UPDX:'+updx,0,32);
2991 drawfonttext('UPDY:'+updy,0,40);
2992 drawfonttext('FPS:'+fps,0,56);
2993 drawfonttext('Free RAM:'+free_ram/1024+' KB',0,64);
2994 drawfonttext('Total RAM:'+memory.get_totalmemory div 1024+' KB',0,72);
2995 drawfonttext('SEED:'+seed,0,88);
2996 drawfonttext('Game time:'+game_time,0,96);
2997 drawfonttext('Global light:' + global_light, 0, 104);
2999 for i := 0 to 15 do
3000 drawImage(light[i], getWidth - 16, 16 * i);
3001 end;
3003 function ItemToString(id : integer) : string;
3004 var
3005 name : string;
3006 begin
3007 if id = Items.none then name := 'none'
3008 else if id = Items.dirt then name := 'dirt'
3009 else if id = Items.grass then name := 'grass'
3010 else if id = Items.stone then name := 'stone'
3011 else if id = Items.oakWoodPlanks then name := 'oakWoodPlanks'
3012 else if id = Items.cobblestone then name := 'cobblestone'
3013 else if id = Items.bedrock then name := 'bedrock'
3014 else if id = Items.sand then name := 'sand'
3015 else if id = Items.gravel then name := 'gravel'
3016 else if id = Items.oakWood then name := 'oakWood'
3017 else if id = Items.obsidian then name := 'obsidian'
3018 else if id = Items.bookshelf then name := 'bookshelf'
3019 else if id = Items.mossStone then name := 'mossStone'
3020 else if id = Items.blockOfIron then name := 'blockOfIron'
3021 else if id = Items.blockOfGold then name := 'blockOfGold'
3022 else if id = Items.blockOfDiamond then name := 'blockOfDiamond'
3023 else if id = Items.goldOre then name := 'goldOre'
3024 else if id = Items.ironOre then name := 'ironOre'
3025 else if id = Items.coalOre then name := 'coalOre'
3026 else if id = Items.diamondOre then name := 'diamondOre'
3027 else if id = Items.redstoneOre then name := 'redstoneOre'
3028 else if id = Items.oakLeaves then name := 'oakLeaves'
3029 else if id = Items.redFlower then name := 'redFlower'
3030 else if id = Items.yellowFlower then name := 'yellowFlower'
3031 else if id = Items.redMooshroom then name := 'redMooshroom'
3032 else if id = Items.brownMooshroom then name := 'brownMooshroom'
3033 else if id = Items.torch then name := 'torch'
3034 else if id = Items.tnt then name := 'tnt'
3035 else if id = Items.chest then name := 'chest'
3036 else if id = Items.craftingTable then name := 'craftingTable'
3037 else if id = Items.cactus then name := 'cactus'
3038 else if id = Items.glass then name := 'glass'
3039 else if id = Items.wool1 then name := 'wool1'
3040 else if id = Items.wool2 then name := 'wool2'
3041 else if id = Items.wool3 then name := 'wool3'
3042 else if id = Items.wool4 then name := 'wool4'
3043 else if id = Items.wool5 then name := 'wool5'
3044 else if id = Items.wool6 then name := 'wool6'
3045 else if id = Items.wool7 then name := 'wool7'
3046 else if id = Items.wool8 then name := 'wool8'
3047 else if id = Items.wool9 then name := 'wool9'
3048 else if id = Items.wool10 then name := 'wool10'
3049 else if id = Items.wool11 then name := 'wool11'
3050 else if id = Items.wool12 then name := 'wool12'
3051 else if id = Items.wool13 then name := 'wool13'
3052 else if id = Items.wool14 then name := 'wool14'
3053 else if id = Items.wool15 then name := 'wool15'
3054 else if id = Items.wool16 then name := 'wool16'
3055 else if id = Items.snow then name := 'snow'
3056 else if id = Items.ladder then name := 'ladder'
3057 else if id = Items.water then name := 'water'
3058 else if id = Items.lava then name := 'lava'
3059 else if id = Items.oakSapling then name := 'oakSapling'
3060 else if id = Items.sponge then name := 'sponge'
3061 else if id = Items.lapisLazuliOre then name := 'lapisLazuliOre'
3062 else if id = Items.lapisLazuliBlock then name := 'lapisLazuliBlock'
3063 else if id = Items.sandstone then name := 'sandstone'
3064 else if id = Items.tallGrass then name := 'tallGrass'
3065 else if id = Items.deadBush then name := 'deadBush'
3066 else if id = Items.cobweb then name := 'cobweb'
3067 else if id = Items.bricks then name := 'bricks'
3068 else if id = Items.snowBlock then name := 'snowBlock'
3069 else if id = Items.ice then name := 'ice'
3070 else if id = Items.snowLayer then name := 'snowLayer'
3071 else if id = Items.clayBlock then name := 'clayBlock'
3072 else if id = Items.sugarCane then name := 'sugarCane'
3073 else if id = Items.pumpkin then name := 'pumpkin'
3074 else if id = Items.jackLantern then name := 'jackLantern'
3075 else if id = Items.stoneBricks then name := 'stoneBricks'
3076 else if id = Items.mossyStoneBricks then name := 'mossyStoneBricks'
3077 else if id = Items.crackedStoneBricks then name := 'crackedStoneBricks'
3078 else if id = Items.chiseledStokeBricks then name := 'chiseledStokeBricks'
3079 else if id = Items.ironBras then name := 'ironBras'
3080 else if id = Items.melonBlock then name := 'melonBlock'
3081 else if id = Items.mycelium then name := 'mycelium'
3082 else if id = Items.backgroundOakWood then name := 'backgroundOakWood'
3083 else if id = Items.spawner then name := 'spawner'
3084 else if id = Items.bed1 then name := 'bed1'
3085 else if id = Items.bed2 then name := 'bed2'
3086 else if id = Items.openWoodenDoor1 then name := 'openWoodenDoor1'
3087 else if id = Items.openWoodenDoor2 then name := 'openWoodenDoor2'
3088 else if id = Items.closedWoodenDoor1 then name := 'closedWoodenDoor1'
3089 else if id = Items.closedWoodenDoor2 then name := 'closedWoodenDoor2'
3090 else if id = Items.birchWood then name := 'birchWood'
3091 else if id = Items.backgroundBirchWood then name := 'backgroundBirchWood'
3092 else if id = Items.spruceWood then name := 'spruceWood'
3093 else if id = Items.backgroundSpruceWood then name := 'backgroundSpruceWood'
3094 else if id = Items.spruceLeaves then name := 'spruceLeaves'
3095 else if id = Items.redMushroomBlock1 then name := 'redMushroomBlock1'
3096 else if id = Items.redMushroomBlock2 then name := 'redMushroomBlock2'
3097 else if id = Items.brownMushroomBlock1 then name := 'brownMushroomBlock1'
3098 else if id = Items.brownMushroomBlock2 then name := 'brownMushroomBlock2'
3099 else if id = Items.oakFence then name := 'oakFence'
3100 else if id = Items.backgroundOakFence then name := 'backgroundOakFence'
3101 else if id = Items.backgroundOakWoodPlanks then name := 'backgroundOakWoodPlanks'
3102 else if id = Items.painting1 then name := 'painting1'
3103 else if id = Items.painting2 then name := 'painting2'
3104 else if id = Items.painting3 then name := 'painting3'
3105 else if id = Items.painting4 then name := 'painting4'
3106 else if id = Items.painting5 then name := 'painting5'
3107 else if id = Items.painting6 then name := 'painting6'
3108 else if id = Items.painting7 then name := 'painting7'
3109 else if id = Items.reservedBlockItem1 then name := 'reservedBlockItem1'
3110 else if id = Items.vines then name := 'vines'
3111 else if id = Items.sign then name := 'sign'
3112 else if id = Items.redstoneTorch then name := 'redstoneTorch'
3113 else if id = Items.furnace then name := 'furnace'
3114 else if id = Items.closedWoodenTrapdoor then name := 'closedWoodenTrapdoor'
3115 else if id = Items.openWoodenTrapdoor then name := 'openWoodenTrapdoor'
3116 else if id = Items.netherrack then name := 'netherrack'
3117 else if id = Items.netherPortal then name := 'netherPortal'
3118 else if id = Items.glowstone then name := 'glowstone'
3119 else if id = Items.birchLeaves then name := 'birchLeaves'
3120 else if id = Items.soulSand then name := 'soulSand'
3121 else if id = Items.birchSapling then name := 'birchSapling'
3122 else if id = Items.spruceSapling then name := 'spruceSapling'
3123 else if id = Items.redstoneLampOff then name := 'redstoneLampOff'
3124 else if id = Items.redstoneLampOn then name := 'redstoneLampOn'
3125 else if id = Items.backgroundObsidian then name := 'backgroundObsidian'
3126 else if id = Items.glassPlane then name := 'glassPlane'
3127 else if id = Items.farmland then name := 'farmland'
3128 else if id = Items.cake then name := 'cake'
3129 else if id = Items.reservedBlockItem2 then name := 'reservedBlockItem2'
3130 else if id = Items.reservedBlockItem3 then name := 'reservedBlockItem3'
3131 else if id = Items.reservedBlockItem4 then name := 'reservedBlockItem4'
3132 else if id = Items.reservedBlockItem5 then name := 'reservedBlockItem5'
3133 else if id = Items.reservedBlockItem6 then name := 'reservedBlockItem6'
3134 else if id = Items.stick then name := 'stick'
3135 else if id = Items.dandelionYellow then name := 'dandelionYellow'
3136 else if id = Items.roseRed then name := 'roseRed'
3137 else if id = Items.superSpecialUnneededTool then name := 'superSpecialUnneededTool'
3138 else if id = Items.pickaxe1 then name := 'pickaxe1'
3139 else if id = Items.pickaxe2 then name := 'pickaxe2'
3140 else if id = Items.pickaxe3 then name := 'pickaxe3'
3141 else if id = Items.pickaxe4 then name := 'pickaxe4'
3142 else if id = Items.pickaxe5 then name := 'pickaxe5'
3143 else if id = Items.shovel1 then name := 'shovel1'
3144 else if id = Items.shovel2 then name := 'shovel2'
3145 else if id = Items.shovel3 then name := 'shovel3'
3146 else if id = Items.shovel4 then name := 'shovel4'
3147 else if id = Items.shovel5 then name := 'shovel5'
3148 else if id = Items.axe1 then name := 'axe1'
3149 else if id = Items.axe2 then name := 'axe2'
3150 else if id = Items.axe3 then name := 'axe3'
3151 else if id = Items.axe4 then name := 'axe4'
3152 else if id = Items.axe5 then name := 'axe5'
3153 else if id = Items.shears then name := 'shears'
3154 else if id = Items.sword1 then name := 'sword1'
3155 else if id = Items.sword2 then name := 'sword2'
3156 else if id = Items.sword3 then name := 'sword3'
3157 else if id = Items.sword4 then name := 'sword4'
3158 else if id = Items.sword5 then name := 'sword5'
3159 else if id = Items.fishingRod then name := 'fishingRod'
3160 else if id = Items.lighter then name := 'lighter'
3161 else if id = Items.hoe1 then name := 'hoe1'
3162 else if id = Items.hoe2 then name := 'hoe2'
3163 else if id = Items.hoe3 then name := 'hoe3'
3164 else if id = Items.hoe4 then name := 'hoe4'
3165 else if id = Items.hoe5 then name := 'hoe5'
3166 else if id = Items.reservedToolItem then name := 'reservedToolItem'
3167 else if id = Items.coal then name := 'coal'
3168 else if id = Items.redstone then name := 'redstone'
3169 else if id = Items.diamond then name := 'diamond'
3170 else if id = Items.brick then name := 'brick'
3171 else if id = Items.ironIngot then name := 'ironIngot'
3172 else if id = Items.goldIngot then name := 'goldIngot'
3173 else if id = Items.lapisLazuli then name := 'lapisLazuli'
3174 else if id = Items.strand then name := 'strand'
3175 else if id = Items.snowball then name := 'snowball'
3176 else if id = Items.clay then name := 'clay'
3177 else if id = Items.book then name := 'book'
3178 else if id = Items.bucket then name := 'bucket'
3179 else if id = Items.waterBucket then name := 'waterBucket'
3180 else if id = Items.lavaBucket then name := 'lavaBucket'
3181 else if id = Items.milkBucket then name := 'milkBucket'
3182 else if id = Items.paper then name := 'paper'
3183 else if id = Items.melon then name := 'melon'
3184 else if id = Items.egg then name := 'egg'
3185 else if id = Items.door then name := 'door'
3186 else if id = Items.bed then name := 'bed'
3187 else if id = Items.spawnEggZombie then name := 'spawnEggZombie'
3188 else if id = Items.spawnEggSheep then name := 'spawnEggSheep'
3189 else if id = Items.spawnEggPig then name := 'spawnEggPig'
3190 else if id = Items.gunpowder then name := 'gunpowder'
3191 else if id = Items.bowl then name := 'bowl'
3192 else if id = Items.mushroomStew then name := 'mushroomStew'
3193 else if id = Items.map then name := 'map'
3194 else if id = Items.painting then name := 'painting'
3195 else if id = Items.rawPorkchop then name := 'rawPorkchop'
3196 else if id = Items.cookedPorkchop then name := 'cookedPorkchop'
3197 else if id = Items.rottenFlesh then name := 'rottenFlesh'
3198 else if id = Items.camera1 then name := 'camera1'
3199 else if id = Items.camera2 then name := 'camera2'
3200 else if id = Items.camera3 then name := 'camera3'
3201 else if id = Items.goldNugget then name := 'goldNugget'
3202 else if id = Items.sugar then name := 'sugar'
3203 else if id = Items.spiderEye then name := 'spiderEye'
3204 else if id = Items.feather then name := 'feather'
3205 else if id = Items.leather then name := 'leather'
3206 else if id = Items.rawBeef then name := 'rawBeef'
3207 else if id = Items.steak then name := 'steak'
3208 else if id = Items.apple then name := 'apple'
3209 else if id = Items.goldenApple then name := 'goldenApple'
3210 else if id = Items.rawChicken then name := 'rawChicken'
3211 else if id = Items.cookedChicken then name := 'cookedChicken'
3212 else if id = Items.spawnEggChicken then name := 'spawnEggChicken'
3213 else if id = Items.spawnEggCreeper then name := 'spawnEggCreeper'
3214 else if id = Items.flint then name := 'flint'
3215 else if id = Items.spawnEggCow then name := 'spawnEggCow'
3216 else if id = Items.spawnEggMooshroom then name := 'spawnEggMooshroom'
3217 else if id = Items.rawFish then name := 'rawFish'
3218 else if id = Items.cookedFish then name := 'cookedFish'
3219 else if id = Items.spawnEggPigman then name := 'spawnEggPigman'
3220 else if id = Items.spawnEggSpider then name := 'spawnEggSpider'
3221 else if id = Items.glowstoneDust then name := 'glowstoneDust'
3222 else if id = Items.clock then name := 'clock'
3223 else if id = Items.compass then name := 'compass'
3224 else if id = Items.seeds then name := 'seeds'
3225 else if id = Items.wheat then name := 'wheat'
3226 else if id = Items.bread then name := 'bread'
3227 else if id = Items.boneMeal then name := 'boneMeal'
3228 else if id = Items.melonSeeds then name := 'melonSeeds'
3229 else if id = Items.pumpkinSeeds then name := 'pumpkinSeeds'
3230 else name := '' + id;
3231 result := name;
3232 end;
3234 procedure PrintItem(id, typ, tex, max, info, texsource, indicator : integer; dividable : boolean);
3235 var
3236 name, tname, indname : string;
3237 begin
3238 name := ItemToString(id);
3240 if typ = Items.block then tname := 'block'
3241 else if typ = Items.tool then tname := 'tool'
3242 else if typ = Items.reserved then tname := 'reserved'
3243 else if typ = Items.orditem then tname := 'orditem'
3244 else tname := '' + typ;
3246 if indicator = Items.noindicator then indname := 'noindicator'
3247 else if indicator = Items.numeric then indname := 'numeric'
3248 else if indicator = Items.line then indname := 'line'
3249 else indname := '' + indicator;
3251 Debug(' InitItem(' + name + ', ' + tname + ', ' + tex + ', ' + max + ', ' + info + ', ' + texsource + ', ' + indname + ', ' + dividable + ');');
3252 end;
3254 procedure PrintItemTable;
3255 var
3256 id : integer;
3257 begin
3258 for id := 0 to 222 do begin
3259 PrintItem(
3260 id,
3261 Items.GetType(id),
3262 Items.GetTexture(id),
3263 Items.GetMaximum(id),
3264 Items.GetData(id),
3265 Items.GetTextureSource(id),
3266 Items.GetIndicatorType(id),
3267 Items.IsDividable(id)
3268 );
3269 end;
3271 for id := 0 to 194 do begin
3272 Debug(' InitOrdItem(' + ItemToString(Items.GetOrdinary(id)) + ');');
3273 end;
3274 end;
3276 begin
3277 qt_start;
3278 hung_time:=getrelativetimems;
3279 hp_time:=getrelativetimems;
3280 air_time:=getrelativetimems;
3281 portal_time:=getrelativetimems;
3283 PrintItemTable;
3285 repeat
3286 proc_fps;
3287 keyhandler;
3288 phyhandler;
3289 game;
3290 draw;
3291 drawfonttext(version,getWidth-(length(version)*8),getHeight-8);
3292 if getrelativetimems-msg_time[4]>500 then begin free_ram:=memory.get_freememory; if free_ram<0 then free_ram:=-free_ram; msg_time[4]:=getrelativetimems; end;
3293 if deb = true then
3294 draw_debug;
3296 drawVideo;
3297 maxfps;
3299 until false;
3300 end.