99c78d037d2ec3a05c2889f7469befe5d4d439f2
5 version
= 'BETA 9 DEV B12';
14 s_jpeg_quality
:integer;
22 load_back_tex
:boolean;
23 load_weather_tex
:boolean;
24 load_light_tex
:boolean;
27 menu_background
:integer;
29 load_minimap_tex
:boolean;
31 //load_key_tex:integer;
39 EOFstr
, ENDstr
:boolean;
41 procedure save_settings
;
42 procedure load_settings
;
43 procedure call_console
;
44 procedure exec(s
, search
:string);
45 procedure addToLog(str
:string);
73 logSTR
: array [0..CON_LOG_SIZE
] of string;
78 stack
: array [0..0] of integer;
79 stack_pointer
:integer;
83 procedure resetStack(size
:integer);
90 putstatic field
'console', 'stack', '[I';
94 procedure pushStack(i
:integer;);
96 stack
[stack_pointer
]:=i
;
97 stack_pointer
:=stack_pointer
+1;
100 function popStack
:integer;
102 stack_pointer
:=stack_pointer
-1;
103 popStack
:=stack
[stack_pointer
];
110 tmp
:=stack
[stack_pointer
-2];
111 stack
[stack_pointer
-2]:=stack
[stack_pointer
-1];
112 stack
[stack_pointer
-1]:=tmp
;
117 stack
[stack_pointer
]:=stack
[stack_pointer
-1];
118 stack_pointer
:=stack_pointer
+1;
121 procedure resetTmpImg
;
128 procedure addToLog(str
:string);
133 for i
:=CON_LOG_SIZE
-1 downto 0 do
134 logSTR
[i
+1]:=logSTR
[i
];
138 procedure setTexture(img
:image
; name
:string; i
:integer);
144 tex8
[i
]:=resize_image(img
, 8, 8);
150 item8
[i
]:=resize_image(img
, 8, 8);
156 addToLog('Error: unknown texture type "'+name
+'"');
159 procedure save_settings
;
164 deleteRecordStore('S');
165 rs
:=openRecordStore('S');
166 t
:=addRecordStoreEntry(rs
,version
);
167 t
:=addRecordStoreEntry(rs
,''+light_type
);
168 t
:=addRecordStoreEntry(rs
,''+ifosad
);
169 t
:=addRecordStoreEntry(rs
, '' + Particles
.enabled
);
170 t
:=addRecordStoreEntry(rs
,''+drawgui
);
171 t
:=addRecordStoreEntry(rs
,''+s_jpeg_quality
);
172 t
:=addRecordStoreEntry(rs
,''+load_key_tex
);
173 closeRecordStore(rs
);
176 function sett_ld_bool(s
:string):boolean;
178 if s
='true' then sett_ld_bool
:=true;
181 procedure load_settings
;
185 rs
:=openRecordStore('S');
186 if readRecordStoreEntry(rs
,1)<>version
then
188 debug(readRecordStoreEntry(rs
,1));
189 closeRecordStore(rs
);
192 light_type
:=stringtointeger(readRecordStoreEntry(rs
,2));
193 ifosad
:=sett_ld_bool(readRecordStoreEntry(rs
,3));
194 Particles
.enabled
:= sett_ld_bool(readRecordStoreEntry(rs
, 4));
195 drawgui
:=sett_ld_bool(readRecordStoreEntry(rs
,5));
196 s_jpeg_quality
:=stringtointeger(readRecordStoreEntry(rs
,6));
197 load_key_tex
:=stringtointeger(readRecordStoreEntry(rs
,7));
198 closeRecordStore(rs
);
201 function isEOS(c
:integer):boolean;
206 if (ch
=#
$0A) or (ch
=#
$0D) then
210 function isSpace(c
:integer;):boolean;
215 if ((ch
=' ') or (ch
=#
$09) or (ch
=#
$0B) or isEOS(c
)) then
219 function nextByte(res
:resource
):integer;
232 function ReadString(res
:resource
):string;
240 if EOFstr
or ENDstr
then
243 tmpstr
:=tmpstr
+chr(b
);
248 function nextChar
:integer;
253 if length(parseStr
)>0 then
255 i
:=ord(getChar(parseStr
, 0));
256 parseStr
:=copy(parseStr
, 1, length(parseStr
));
269 procedure clearSpaces
;
278 {Symbol ';' is one line commentary}
288 if isSpace(i
)=false then
291 parseStr
:=chr(i
)+parseStr
;
297 function nextWord
:string;
316 parseStr
:=chr(i
)+parseStr
;
325 function strToBool(str
:string):boolean;
334 if StringToInteger(str
)<>0 then
340 //Перевод строки в целое число. base - система счисления
341 function Str2Dec(str
:string; base
:integer;):integer;
348 if GetChar(str
, 0)='-' then
354 for i
:=i
to length(str
)-1 do
357 if ((ch
>='0') and (ch
<='9')) then
360 if ((ch
>='A') and (ch
<=chr($36+base
))) then
364 addToLog('Error! I cant decode "'+str
+'" -> "'+ch
+'"');
378 function getVar(name
:string):integer;
382 if name
='SCREEN_W' then
385 if name
='SCREEN_H' then
388 addToLog('Unknown variable "'+name
+'"');
391 procedure setVar(name
:string; value
:integer);
395 addToLog('I cant set variable "'+name
+'"');
398 function DecodeInt(str
:string):integer;
405 addToLog('DecodeInt getted null string!');
411 head
:=getchar(str
, 0);
412 num
:=copy(str
, 1, length(str
));
424 DecodeInt
:=getVar(num
);
426 if (head
='0') and (getchar(str
, 1)='X') then
428 DecodeInt
:=Str2Dec(copy(str
, 2, length(str
)), 16);
431 if (head
='0') and (length(str
)>1) then
433 DecodeInt
:=Str2Dec(num
, 8);
438 DecodeInt
:=Str2Dec(num
, 2);
441 if ((head
>='0') and (head
<='9')) or (head
='-') then
443 DecodeInt
:=Str2Dec(str
, 10);
447 addToLog('Error! I cant decode "'+str
+'"');
450 procedure exeCommand(str
:string);
452 com
, tmp
, tmp2
:string;
460 com
:=UpCase(nextWord
);
462 if (cheats
) or (gamemode
=1) then
465 game_time
:=decodeInt(nextWord
);
468 fly
:=strToBool(nextWord
);
471 hp
:=decodeInt(nextWord
);
474 hunger
:=decodeInt(nextWord
);
477 player
.dropItem(decodeInt(nextWord
), decodeInt(nextWord
));
481 player
.setX(decodeInt(nextWord
));
482 player
.setY(decodeInt(nextWord
));
485 if com
='GAMEMODE' then
487 gamemode
:=decodeInt(nextWord
);
493 player
.setX(get_spawn_x
*16+4);
494 player
.setY(get_spawn_y
*16);
497 {if com='SPAWN_MOBS' then
498 s_spawn_mob:=strToBool(nextWord);
500 {if com='SURVIVAL' then
513 if com
='CLEAR_INVENTORY' then
521 if com
='I_AM_CHEATER' then
523 if nextWord
=#
$36+#
$36+#
$36 then
532 if com
='WEATHER' then
533 osadki
:=strToBool(nextWord
);
535 {if com='MEGASPAWN' then
538 if com
='REF_DRP' then
539 ref_drp
:=strToBool(nextWord
);
542 bl_upd
:=decodeInt(nextWord
);
544 if com
='GET_DRP' then
545 s_get_drp
:=strToBool(nextWord
);
547 if com
='MAX_FPS' then
548 s_max_fps
:=decodeInt(nextWord
); else
549 if com
='DRW_BACK' then
550 drw_back
:=strToBool(nextWord
);
552 {if com='DRW_MOBS' then
553 drw_mobs:=strToBool(nextWord);
555 if com
='DRP_PHY' then
556 drp_phy
:=strToBool(nextWord
);
559 drw_sm
:=strToBool(nextWord
);
563 s_jpeg_quality
:=decodeInt(nextWord
);
564 if s_jpeg_quality
>100 then
566 else if s_jpeg_quality
<0 then
570 if com
='LOAD_SM' then
571 load_sm
:=decodeInt(nextWord
);
573 if com
='S_WEATHER' then
574 ifosad
:=strToBool(nextWord
);
576 if com
='S_HIDE_GUI' then
577 drawgui
:=strToBool(nextWord
);
579 if com
='S_LIGHT' then
580 light_type
:=decodeInt(nextWord
);
582 if com
='S_PARTICLES' then
583 Particles
.enabled
:= strToBool(nextWord
);
585 if com
='LOAD_SKY' then
586 load_sky_siz
:=decodeInt(nextWord
);
588 {if com='LOAD_MOB_TEX' then
589 load_mob_tex:=strToBool(nextWord);
591 if com
='LOAD_BACK_TEX' then
592 load_back_tex
:=strToBool(nextWord
);
594 if com
='LOAD_WEATHER_TEX' then
595 load_weather_tex
:=strToBool(nextWord
);
597 if com
='LOAD_LIGHT_TEX' then
598 load_light_tex
:=strToBool(nextWord
);
600 if com
='LOAD_GUI_TEX' then
601 load_gui_tex
:=strToBool(nextWord
);
603 if com
='MENU_BACKGROUND' then
604 menu_background
:=decodeInt(nextWord
);
606 if com
='DRW_DRP' then
607 drw_drp
:=strToBool(nextWord
);
609 if com
='DRW_STARS' then
610 drw_stars
:=strToBool(nextWord
);
612 if com
='SV_SETT' then
615 if com
='LD_SETT' then
618 if com
='LOAD_MINIMAP_TEX' then
619 load_minimap_tex
:=strToBool(nextWord
);
627 if com
='RESET_FUELS' then
629 furnace
.setMaxFuel(decodeInt(nextWord
));
630 //addToLog('Max fuel: '+decodeInt(parsed_str[1]));
633 if com
='SET_FUEL' then
635 furnace
.initFuel(decodeInt(nextWord
),
637 decodeInt(nextWord
));
640 if com
='RESET_RECIPES' then
642 furnace
.setMaxRecipes(decodeInt(nextWord
));
643 //addToLog('Max recipes: '+decodeInt(parsed_str[1]));
646 if com
='SET_RECIPE' then
648 furnace
.initRecipe(decodeInt(nextWord
),
650 decodeInt(nextWord
));
653 if com
='RESET_CRAFTS' then
655 resetCrafts(decodeInt(nextWord
));
656 //addToLog('Max crafts: '+decodeInt(parsed_str[1]));
659 if com
='SET_CRAFT_IN' then
661 setCraftIn(decodeInt(nextWord
),
664 decodeInt(nextWord
));
667 if com
='SET_CRAFT_OUT' then
669 setCraftOUT(decodeInt(nextWord
),
672 decodeInt(nextWord
));
675 if com
='RESET_BLOCKS_TEX' then
677 initBlockTex(decodeInt(nextWord
));
680 if com
='RESET_ITEMS_TEX' then
682 initItemTex(decodeInt(nextWord
));
685 if com
='LOAD_TEX' then
687 regimg
:=ld_tex(nextWord
, '/'+sd
+'/cavecraft/texturepacks/'+tex_pack
+'/', '');
690 if com
='RESET_TEX' then
693 if com
='SET_TEX' then
696 decodeInt(nextWord
));
697 if com
='SET_CANV_TEX' then
701 setTexture(rotate_image_from_image(regimg
,
711 if com
='BIND_KEY' then
714 for i
:=0 to MAX_KEY_BIND
do
715 keyboard
.bindKey(decodeInt(tmp
), i
, decodeInt(nextWord
));
719 resetStack(decodeInt(nextWord
));
722 pushStack(decodeInt(nextWord
));
734 pushStack(popStack
+popStack
);
739 pushStack(popStack
-i
);
743 pushStack(popStack
*popStack
);
748 pushStack(popStack
/i
);
754 pushStack(popStack
mod i
);
758 setVar(nextWord
, decodeInt(nextWord
));
761 setVar(nextWord
, popStack
);
763 if com
='MAX_VKEYS' then
764 resetVirtualKeyboard(decodeInt(nextWord
));
766 if com
='SET_VKEY' then
767 bindVKey(decodeInt(nextWord
),
770 decodeInt(nextWord
));
772 if com
='SET_RESOLUTION' then
773 initVideo(decodeInt(nextWord
), decodeInt(nextWord
), strToBool(nextWord
));
775 //addToLog('Unknown command "'+com+'"');
778 procedure call_console
;
782 exitCmd
, exeCmd
, Clicked
:command
;
786 setFont(FONT_FACE_SYSTEM
,FONT_STYLE_PLAIN
,FONT_SIZE_SMALL
);
791 exitCmd
:=createCommand('Exit', CM_EXIT
, 1);
792 exeCmd
:=createCommand('Execute', CM_OK
, 1);
796 commandTxt
:=formAddTextField('Enter command:', ''+lastCommand
, 32, TF_ANY
);
798 for i
:=0 to CON_LOG_SIZE
do
799 tmpid
:=formAddString(logSTR
[i
]+chr(10));
805 Clicked
:=getClickedCommand
;
806 if Clicked
=exitCmd
then
808 lastCommand
:=formGetText(commandTxt
);
813 if Clicked
=exeCmd
then
815 str
:=formGetText(commandTxt
);
825 procedure exec(s
, search
:string);
831 search
:=UpCase(search
);
833 if search
='LOCAL' then
835 addToLog('Load file "'+s
+'" at LOCAL!');
836 res
:=OpenResource('/'+s
);
841 if open_file('/'+sd
+'/cavecraft/'+s
)=1 then
843 addToLog('Load file "'+s
+'" at SD!');
848 if search
='AUTO' then
850 addToLog('path "/'+sd
+'/cavecraft/'+s
+'"');
851 if file_exists('/'+sd
+'/cavecraft/'+s
)=1 then
853 if open_file('/'+sd
+'/cavecraft/'+s
)=1 then
855 addToLog('Load file "'+s
+'" at SD(AUTO)!');
861 addToLog('Load file "'+s
+'" at LOCAL(AUTO)!');
862 res
:=OpenResource('/'+s
);
867 addToLog('Unknown load type "'+search
+'", file "'+s
+'" not executed!');
871 if ResourceAvailable(res
) then
873 str
:=ReadString(res
);
875 //addToLog('Exec: "'+str+'"');
880 addToLog('Execute file "'+s
+'" not found!');