DEADSOFTWARE

Fix load cfg files and textures
[cavecraft.git] / src / CAVE.mpsrc
index ccdef84c131cb89a5c76f85934566c3e4ab5663e..af345fdff2db525c4e5ca5a5aa1f44efbd8c4ba7 100644 (file)
@@ -32,8 +32,7 @@ uses
  video;\r
 \r
 const\r
- version='BETA 9';\r
- version_map=8;\r
+  version_map = 9;\r
 \r
 var\r
  keymode,updx,updy:integer;\r
@@ -54,7 +53,7 @@ var
  moon_phase:integer;\r
  toolus,toolind:integer;\r
  osadki_ani:integer;\r
- sd,sav_fl:string;\r
+ sav_fl:string;\r
  global_light:integer;\r
  world_typ:integer;\r
  float:image;\r
@@ -108,68 +107,70 @@ procedure maxfps;
   delay(del);\r
  end;\r
 \r
-procedure cleartextures;\r
- var\r
-  no:image;\r
-  ix,iy,iz:integer;\r
- begin\r
-  bg[0]:=no;\r
-  bg[1]:=no;\r
-  float:=no;\r
-  compas:=no;\r
-  for ix:=0 to 7 do clock[ix]:=no;\r
-\r
-  {for ix:=0 to maxBlockTex do\r
-   begin\r
-    tex[ix]:=no;\r
-    tex8[ix]:=no;\r
-   end;\r
-  for ix:=0 to maxItemTex do\r
-   begin\r
-    item[ix]:=no;\r
-    item8[ix]:=no;\r
-   end;}\r
- for ix:=0 to 8 do back[ix]:=no;\r
-\r
-  player.freeSkin;\r
-\r
-  for ix:=0 to 34 do\r
-   gui[ix]:=no;\r
-\r
-  for ix:=0 to 9 do tue[ix]:=no;\r
-\r
-  for ix:=0 to 7 do osad[0,ix]:=no;\r
-  for ix:=0 to 7 do osad[1,ix]:=no;\r
+procedure ClearTextures;\r
+  var\r
+    no : image;\r
+    ix, iy, iz : integer;\r
+  begin\r
+    bg[0] := no;\r
+    bg[1] := no;\r
+    float := no;\r
+    compas := no;\r
+    for ix := 0 to 7 do\r
+      clock[ix] := no;\r
+\r
+    for ix := 0 to maxBlockTex do\r
+      begin\r
+        tex[ix] := no;\r
+        tex8[ix] := no;\r
+      end;\r
+    for ix := 0 to maxItemTex do\r
+      begin\r
+        item[ix] := no;\r
+        item8[ix] := no;\r
+      end;\r
 \r
-  for ix:=0 to 15 do light[ix]:=no;\r
+    for ix := 0 to 8 do\r
+      back[ix]:=no;\r
 \r
-  for ix:=0 to 7 do\r
-   begin\r
-    pr_1[ix]:=no;\r
-    pr_2[ix]:=no;\r
-    pr_3[ix]:=no;\r
-    pr_4[ix]:=no;\r
-    pr_5[ix]:=no;\r
-   end;\r
-  bubble:=no;\r
+    player.freeSkin;\r
 \r
-  for ix:=0 to 15 do\r
-   pr_boom[ix]:=no;\r
+    for ix := 0 to 34 do\r
+      gui[ix] := no;\r
+    for ix := 0 to 9 do\r
+      tue[ix] := no;\r
+    for ix := 0 to 7 do\r
+      osad[0, ix] := no;\r
+    for ix := 0 to 7 do\r
+      osad[1, ix] := no;\r
 \r
-  mob.freeSkin;\r
+    for ix := 0 to 15 do\r
+      light[ix] := no;\r
+    for ix := 0 to 7 do\r
+      begin\r
+        pr_1[ix] := no;\r
+        pr_2[ix] := no;\r
+        pr_3[ix] := no;\r
+        pr_4[ix] := no;\r
+        pr_5[ix] := no;\r
+     end;\r
 \r
-  sky:=no;\r
+    bubble := no;\r
+    for ix := 0 to 15 do\r
+      pr_boom[ix] := no;\r
 \r
-  sun:=no;\r
-  moon:=no;\r
+    mob.freeSkin;\r
 \r
-  sign_im:=no;\r
+    sky := no;\r
+    sun := no;\r
+    moon := no;\r
+    sign_im := no;\r
 \r
-  for ix:=0 to CONST_MAX_CURS do\r
-   LoadCurImg(no, ix);\r
+    for ix := 0 to CONST_MAX_CURS do\r
+      LoadCurImg(no, ix);\r
 \r
-  //resetVirtualKeyboard(-1);\r
- end;\r
+    //resetVirtualKeyboard(-1);\r
 end;\r
 \r
 procedure create_msg(s:string);\r
  var\r
@@ -205,6 +206,8 @@ procedure loadtexture(path:string);
     for ix:=0 to 8 do back[ix]:=rotate_image_from_image(im,ix*16,0,16,16,0);\r
    end;\r
 \r
+  console.exec('textures.cfg', 'AUTO');\r
+\r
   player.loadSkin('char_ani.png', path);\r
   mob.loadSkin(path);\r
 \r
@@ -339,19 +342,7 @@ procedure cleargame;
 \r
   chest.resetData;\r
 \r
-  {for ix:=0 to 15 do\r
-   begin\r
-    b_furnace[ix]:=false;\r
-    for iy:=0 to 4 do\r
-     begin\r
-      furnace[ix,iy].item_i:=0;\r
-      furnace[ix,iy].sum_i:=0;\r
-      furnace_gg[ix].f_gor:=15;\r
-      furnace_gg[ix].fire_time:=0;\r
-      furnace_gg[ix].f_got:=0;\r
-      furnace_gg[ix].got_time:=0;\r
-     end;\r
-   end;}\r
+  furnace.resetData;\r
 \r
   drop.resetData;\r
 \r
@@ -513,9 +504,8 @@ procedure saveworld(path:string);
    if file_exists(path+world_name)<>1 then file_create(path+world_name);\r
    if open_file(path+world_name)=1 then\r
     begin\r
-      writeint(player.getX);\r
-      writeint(player.getX);\r
-     //Matrix\r
+     writeint(player.getX);\r
+     writeint(player.getY);\r
      //Matrix\r
      SaveMapRLE;\r
      SaveMapInfoRLE;\r
@@ -531,17 +521,7 @@ procedure saveworld(path:string);
      chest.saveData;\r
      drw_load_line('Furnaces',60);\r
      //Furnaces\r
-    /* for ix:=0 to 15 do\r
-      begin\r
-       writebool(b_furnace[ix]);\r
-       writeint(furnace_gg[ix].f_gor);\r
-       writeint(furnace_gg[ix].f_got);\r
-        for iy:=0 to 4 do\r
-         begin\r
-          write_byte(furnace[ix,iy].item_i);\r
-          writeint(furnace[ix,iy].sum_i);\r
-         end;\r
-       end;*/\r
+     furnace.saveData;\r
      drw_load_line('Mobs',70);\r
      //Mobs\r
      mob.saveData;\r
@@ -671,26 +651,15 @@ function loadworld(path:string):boolean;
      drw_load_line('Chests',55);\r
      //Chests\r
      chest.loadData;\r
-      drw_load_line('Furnaces',60);\r
+     drw_load_line('Furnaces',60);\r
      //Furnaces\r
-    /* for ix:=0 to 15 do\r
-      begin\r
-       b_furnace[ix]:=readbool;\r
-       furnace_gg[ix].f_gor:=readint;\r
-       furnace_gg[ix].f_got:=readint;\r
-        for iy:=0 to 4 do\r
-         begin\r
-          furnace[ix,iy].item_i:=read_byte;\r
-          furnace[ix,iy].sum_i:=readint;\r
-         end;\r
-       end;*/\r
-       drw_load_line('Mobs',70);\r
+     furnace.loadData;\r
      //Mobs\r
      mob.loadData;\r
-      drw_load_line('Drop',80);\r
+     drw_load_line('Drop',80);\r
      //Drop\r
      drop.loadData;\r
-      drw_load_line('Particles',85);\r
+     drw_load_line('Particles',85);\r
      //Particles\r
      max_particles:=readint;\r
      reset_particles(max_particles+1);\r
@@ -1073,7 +1042,7 @@ procedure start_uu;
   rs:=openRecordStore('SD');\r
   sd:=readRecordStoreEntry(rs,1);\r
   closeRecordStore(rs);\r
-  console.exec('autoexec.cfg', 'AUTO', true);\r
+  console.exec('autoexec.cfg', 'AUTO');\r
   if sd='' then\r
    begin\r
     init_touch;\r
@@ -1272,7 +1241,7 @@ function menu_game:boolean;
      if m_cur>3 then m_cur:=0;\r
     end;\r
 \r
-   if clickedKey(KEY_MENU_LEFT) then\r
+   if (max_r >= 0) and clickedKey(KEY_MENU_LEFT) then\r
     begin\r
      cur_name:=cur_name-1;\r
      if cur_name<0 then cur_name:=0;\r
@@ -1282,7 +1251,7 @@ function menu_game:boolean;
 \r
      if file_exists('/'+sd+'/cavecraft/saves/'+names[cur_name]+'/player.dat')=1 then\r
     end;\r
-   if clickedKey(KEY_MENU_RIGHT) then\r
+   if (max_r >= 0) and clickedKey(KEY_MENU_RIGHT) then\r
     begin\r
      cur_name:=cur_name+1;\r
      if cur_name>max_r then cur_name:=max_r;\r
@@ -1429,6 +1398,7 @@ procedure menu_tex;
     if m_cur=0 then begin\r
      if cur_name>0 then\r
       begin\r
+       debug("Select TexturePack @ /" + sd + "/cavecraft/texturepacks/" + names[cur_name]);\r
        tex_pack:=names[cur_name];\r
        LoadDrawFont('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');\r
        loadtexture('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');\r
@@ -1436,9 +1406,13 @@ procedure menu_tex;
        rs:=openRecordStore('TX');\r
        t:=addRecordStoreEntry(rs,tex_pack);\r
        closeRecordStore(rs);\r
+\r
+       LoadDrawFont('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');\r
+       loadtexture('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/');\r
       end;\r
      else\r
       begin\r
+       debug("Cancel Select TecturePack");\r
        tex_pack:='';\r
        loadtexture('/');\r
        deleteRecordStore('TX');\r
@@ -2076,16 +2050,32 @@ procedure draw;
   {===================[draw_blocks]===================}\r
   for ix:=minx to maxx do\r
   for iy:=miny to maxy do\r
-   begin\r
-    if getBlockFore(getmap(ix,iy))=true then\r
-     draw_block(ix,iy);\r
+    begin\r
+      if getBlockFore(getmap(ix, iy)) then\r
+        draw_block(ix, iy);\r
 \r
-    setcolor(0,0,0);\r
-    if (light_type=1) then begin if getmaplight(ix,iy)=0 then fillrect((ix*16)-camx,(iy*16)-camy,16,16); end;\r
-     else\r
-    if light_type=2 then begin if getmaplight(ix,iy)<15 then begin if (ix*16-camx<getWidth) and (ix*16-camx>0-16) and (iy*16-camy<getHeight) and (iy*16-camy>0-16) then drawimage(light[getmaplight(ix,iy)],(ix*16)-camx,(iy*16)-camy); end; end;\r
-   end;\r
-   if (toolus>0) and (toolind<10) and (getmap(curx,cury)>0) then begin if toolind>9 then toolind:=9; drawimage(tue[toolind],curx*16-camx,cury*16-camy); end;\r
+      setcolor(0, 0, 0);\r
+      if light_type = 1 then\r
+        begin\r
+          if getmaplight(ix,iy) = 0 then\r
+            fillrect((ix * 16) - camx, (iy * 16) - camy, 16, 16);\r
+        end;\r
+      else if light_type = 2 then\r
+        begin \r
+          if getmaplight(ix, iy) < 15 then\r
+             drawimage(light[getmaplight(ix, iy)], (ix * 16) - camx, (iy * 16) - camy);\r
+        end;\r
+     end;\r
+\r
+   // debug\r
+   // drawimage(light[getmaplight(player.getX div 16, player.getY div 16)], 0, 0);\r
+\r
+   if (toolus > 0) and (toolind < 10) and (getmap(curx,cury) > 0) then\r
+     begin\r
+       if toolind > 9 then\r
+         toolind:=9;\r
+       drawimage(tue[toolind], curx * 16 - camx, cury * 16 - camy);\r
+     end;\r
   {===================[gui]===================}\r
   if drawgui then\r
    begin\r
@@ -2511,6 +2501,8 @@ procedure plr_is_dead;
              y:=last_sleep_y*16;\r
             end;\r
          end;\r
+       player.setX(x);\r
+       player.setY(y);\r
        posi:=0;\r
        curx:=0;\r
        cury:=0;\r
@@ -2907,6 +2899,9 @@ procedure game;
 \r
   game_time:=game_time+(600000 div (fps_t*1000));\r
 \r
+// Ускорение игрового времени в 10 раз\r
+//  game_time := game_time + (600000 div (fps_t*100));\r
+\r
   if (game_time>600000) or (game_time<0) then\r
    begin\r
     game_time:=0;\r
@@ -2915,8 +2910,8 @@ procedure game;
     load_moon('/'+sd+'/cavecraft/texturepacks/'+tex_pack+'/',moon_phase);\r
    end;\r
 \r
-  tim:=10000*getimagewidth(sky)/600000*game_time/10000;\r
-  global_light:=effects.get(sky,tim,1,1) {and $F};\r
+  tim := 10000 * getimagewidth(sky) / 600000 * game_time / 10000;\r
+  global_light := effects.get(sky, tim, 1, 1) div 16;\r
 \r
   if clock_stage<>game_time div 75000 then begin clock_stage:=clock_stage+1; if clock_stage>7 then clock_stage:=0; end;\r
 \r
@@ -3056,6 +3051,27 @@ procedure qt_start;
   menu;\r
  end;\r
 \r
+procedure draw_debug;\r
+  var\r
+    i : Integer;\r
+  begin\r
+    //drawfonttext('X:'+(x div 16-128),0,0);\r
+    //drawfonttext('Y:'+integertostring(127-(y div 16)),0,8);\r
+    drawfonttext('CURX:'+(curx-128),0,16);\r
+    drawfonttext('CURY:'+cury,0,24);\r
+    drawfonttext('UPDX:'+updx,0,32);\r
+    drawfonttext('UPDY:'+updy,0,40);\r
+    drawfonttext('FPS:'+fps,0,56);\r
+    drawfonttext('Free RAM:'+free_ram/1024+' KB',0,64);\r
+    drawfonttext('Total RAM:'+memory.get_totalmemory div 1024+' KB',0,72);\r
+    drawfonttext('SEED:'+seed,0,88);\r
+    drawfonttext('Game time:'+game_time,0,96);\r
+    drawfonttext('Global light:' + global_light, 0, 104);\r
+\r
+    for i := 0 to 15 do\r
+      drawImage(light[i], getWidth - 16, 16 * i);\r
+  end;\r
+\r
 begin\r
  qt_start;\r
  hung_time:=getrelativetimems;\r
@@ -3070,20 +3086,8 @@ begin
   draw;\r
   drawfonttext(version,getWidth-(length(version)*8),getHeight-8);\r
   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;\r
-  if deb=true then\r
-   begin\r
-    //drawfonttext('X:'+(x div 16-128),0,0);\r
-    //drawfonttext('Y:'+integertostring(127-(y div 16)),0,8);\r
-    drawfonttext('CURX:'+(curx-128),0,16);\r
-    drawfonttext('CURY:'+cury,0,24);\r
-    drawfonttext('UPDX:'+updx,0,32);\r
-    drawfonttext('UPDY:'+updy,0,40);\r
-    drawfonttext('FPS:'+fps,0,56);\r
-    drawfonttext('Free RAM:'+free_ram/1024+' KB',0,64);\r
-    drawfonttext('Total RAM:'+memory.get_totalmemory div 1024+' KB',0,72);\r
-    drawfonttext('SEED:'+seed,0,88);\r
-    drawfonttext('Game time:'+game_time,0,96);\r
-   end;\r
+  if deb = true then\r
+    draw_debug;\r
 \r
   drawVideo;\r
   maxfps;\r