DEADSOFTWARE

Remove ascii crap
[cavecraft.git] / src / CAVE.mpsrc
index e23b86557999db0064020d785f14b54745bd2a30..df0d606ea05dda1b5cd380d4d7de9ccf4e9e909e 100644 (file)
@@ -6,14 +6,12 @@ uses
  drop,\r
  invui,\r
  vars,\r
- particles_store,\r
  randoms,\r
  memory,\r
  worldgen,\r
  canvas,\r
- items,\r
  safeload,\r
- mob,\r
+ mobs,\r
  console,\r
  effects,\r
  particles,\r
@@ -29,7 +27,12 @@ uses
  chest,\r
  inv,\r
  items_store,\r
- video;\r
+ video,\r
+ Blocks,\r
+ BlocksLogic,\r
+ Items,\r
+ ItemsLogic,\r
+ Tools;\r
 \r
 const\r
   version_map = 9;\r
@@ -53,7 +56,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
@@ -107,68 +110,59 @@ 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
-\r
-  for ix:=0 to 15 do light[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
+      Vars.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 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
+    for ix := 0 to 8 do\r
+      back[ix]:=no;\r
 \r
-  for ix:=0 to 15 do\r
-   pr_boom[ix]:=no;\r
+    player.freeSkin;\r
 \r
-  mob.freeSkin;\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
-  sky:=no;\r
+    for ix := 0 to 15 do\r
+      light[ix] := no;\r
 \r
-  sun:=no;\r
-  moon:=no;\r
+    Particles.FreeTextures;\r
+    Mobs.FreeTextures;\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
@@ -197,15 +191,17 @@ procedure loadtexture(path:string);
   compas:=ld_tex('compass.png',path,'gui/');\r
   im:=ld_tex('clock.png',path,'gui/');\r
   for ix:=0 to 7 do \r
-   clock[ix]:=rotate_image_from_image(im,ix*16,0,16,16,0);\r
+    Vars.clock[ix]:=rotate_image_from_image(im,ix*16,0,16,16,0);\r
   if load_back_tex then\r
    begin\r
     im:=ld_tex('back.png',path,'');\r
     for ix:=0 to 8 do back[ix]:=rotate_image_from_image(im,ix*16,0,16,16,0);\r
    end;\r
 \r
-  player.loadSkin('char_ani.png', path);\r
-  mob.loadSkin(path);\r
+  console.exec('textures.cfg', 'AUTO');\r
+\r
+  Player.LoadSkin('char_ani.png', path);\r
+  Mobs.LoadTextures(path);\r
 \r
   im:=ld_tex('gui.png',path,'gui/');\r
   gui[0]:=rotate_image_from_image(im,0,0,16,16,0);\r
@@ -254,22 +250,7 @@ procedure loadtexture(path:string);
     for ix:=0 to 15 do light[ix]:=rotate_image_from_image(im,16*ix,0,16,16,0);\r
    end;\r
 \r
-  if load_particles_tex then\r
-   begin\r
-    im:=ld_tex('particles.png',path,'terrain/');\r
-    for ix:=0 to 7 do\r
-     begin\r
-      pr_1[ix]:=rotate_image_from_image(im,8*ix,0,8,8,0);\r
-      pr_2[ix]:=rotate_image_from_image(im,8*ix,8,8,8,0);\r
-      pr_3[ix]:=rotate_image_from_image(im,8*ix,16,8,8,0);\r
-      pr_4[ix]:=rotate_image_from_image(im,8*ix,24,8,8,0);\r
-      pr_5[ix]:=rotate_image_from_image(im,8*ix,32,8,8,0);\r
-     end;\r
-    bubble:=rotate_image_from_image(im,0,40,8,8,0);\r
-    im:=ld_tex('explosion.png',path,'terrain/');\r
-    for ix:=0 to 15 do\r
-     pr_boom[ix]:=rotate_image_from_image(im,32*ix,0,32,32,0);\r
-   end;\r
+  Particles.LoadTextures(path);\r
 \r
   im:=ld_tex('partition.png',path,'gui/');\r
   gui[18]:=rotate_image_from_image(im,0,0,84,42,0);\r
@@ -334,18 +315,12 @@ procedure cleargame;
 \r
   //anim_del2:=0;\r
 \r
-  inv.resetData;\r
-\r
-  chest.resetData;\r
-\r
-  furnace.resetData;\r
-\r
-  drop.resetData;\r
-\r
-  mob.resetData;\r
-\r
-  //gb_up_pa:=0;\r
-  reset_particles(max_particles+1);\r
+  Inv.ResetData;\r
+  Chest.ResetData;\r
+  Furnace.ResetData;\r
+  Drop.ResetData;\r
+  Mobs.ResetData;\r
+  Particles.ResetData;\r
 \r
   for ix:=0 to 255 do\r
    begin\r
@@ -512,31 +487,19 @@ procedure saveworld(path:string);
        write_byte(getBackMap(ix));\r
        write_byte(getBiomMap(ix));\r
       end;\r
-     drw_load_line('Chests',55);\r
-     //Chests\r
-     chest.saveData;\r
-     drw_load_line('Furnaces',60);\r
-     //Furnaces\r
-     furnace.saveData;\r
-     drw_load_line('Mobs',70);\r
-     //Mobs\r
-     mob.saveData;\r
-     drw_load_line('Drop',80);\r
-     //Drop\r
-     drop.saveData;\r
-      drw_load_line('Particles',85);\r
-     //Particles\r
-     writeint(max_particles);\r
-     write_byte(gb_up_pa);\r
-     for ix:=0 to max_particles do\r
-      begin\r
-       write_byte(get_particle_type(ix));\r
-       write_byte(get_particle_ani(ix));\r
-       writeint(get_particle_x(ix));\r
-       writeint(get_particle_y(ix));\r
-      end;\r
-     drw_load_line('Other',90);\r
-     //Other\r
+\r
+     drw_load_line('Chests', 55);\r
+     Chest.SaveData;\r
+     drw_load_line('Furnaces', 60);\r
+     Furnace.SaveData;\r
+     drw_load_line('Mobs', 70);\r
+     Mobs.SaveData;\r
+     drw_load_line('Drop', 80);\r
+     Drop.SaveData;\r
+     drw_load_line('Particles', 85);\r
+     Particles.SaveData;\r
+\r
+     drw_load_line('Other', 90);\r
      write_byte(updx);\r
      write_byte(updy);\r
      writebool(osadki);\r
@@ -644,31 +607,17 @@ function loadworld(path:string):boolean;
        setBackMap(read_byte, ix);\r
        setBiomMap(read_byte, ix);\r
       end;\r
-     drw_load_line('Chests',55);\r
-     //Chests\r
-     chest.loadData;\r
-     drw_load_line('Furnaces',60);\r
-     //Furnaces\r
-     furnace.loadData;\r
-     //Mobs\r
-     mob.loadData;\r
-     drw_load_line('Drop',80);\r
-     //Drop\r
-     drop.loadData;\r
-     drw_load_line('Particles',85);\r
-     //Particles\r
-     max_particles:=readint;\r
-     reset_particles(max_particles+1);\r
-     gb_up_pa:=read_byte;\r
-     for ix:=0 to max_particles do\r
-      begin\r
-       set_particle_type(ix,read_byte);\r
-       set_particle_ani(ix,read_byte);\r
-       set_particle_x(ix,readint);\r
-       set_particle_y(ix,readint);\r
-      end;\r
-      drw_load_line('Other',90);\r
-     //Other\r
+     drw_load_line('Chests', 55);\r
+     Chest.LoadData;\r
+     drw_load_line('Furnaces', 60);\r
+     Furnace.LoadData;\r
+     Mobs.LoadData;\r
+     drw_load_line('Drop', 80);\r
+     Drop.LoadData;\r
+     drw_load_line('Particles', 85);\r
+     Particles.LoadData;\r
+\r
+     drw_load_line('Other',90);\r
      updx:=read_byte;\r
      updy:=read_byte;\r
      osadki:=readbool;\r
@@ -739,7 +688,7 @@ procedure drawdeadlogo;
   fillrect(0,0,getWidth,getHeight);\r
   dead:=loadimage('/dl');\r
   drawimage(dead,(getWidth/2)-(getimagewidth(dead)/2),(getHeight/2)-(getimageheight(dead)/2));\r
-  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));\r
+  drawfonttext('www.deadsoftware.ru',getWidth/2-80,(getHeight/2)+(getimageheight(dead)/2));\r
   drawfonttext('Loading...',(getWidth/2)-(40),getHeight-8);\r
   drawVideo;\r
   delay(500);\r
@@ -1038,7 +987,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
@@ -1394,6 +1343,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
@@ -1401,9 +1351,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
@@ -1477,7 +1431,7 @@ var
       end; else\r
      if m_cur=-1 then\r
       begin\r
-       s_particles:=not s_particles;\r
+       Particles.enabled := not Particles.enabled;\r
       end; else\r
      if m_cur=0 then\r
       begin\r
@@ -1531,7 +1485,7 @@ var
 \r
    drw_btn('Light:'+light_type,-3,m_cur,0,1);\r
    drw_btn('Weather:'+ifosad,-2,m_cur,0,1);\r
-   drw_btn('Particles:'+s_particles,-1,m_cur,0,1);\r
+   drw_btn('Particles:' + Particles.enabled, -1, m_cur, 0, 1);\r
    drw_btn('Hide GUI:'+not drawgui,0,m_cur,0,1);\r
    drw_btn('Touch:'+(load_key_tex>0),1,m_cur,0,1);\r
    drw_btn('JPEG:'+s_jpeg_quality,2,m_cur,0,1);\r
@@ -1622,17 +1576,17 @@ procedure menu_about;
    setclip(0,32,getWidth,(getHeight/16-4)*16);\r
 \r
    drw_txt('Developers:',cur,0,1);\r
-   drw_txt(#68+#101+#97+#68+#68+#111+#111+#77+#69+#82+' - Programmer',cur,1,0);//dead\r
-   drw_txt(#102+#114+#101+#100+#45+#98+#111+#121+' - Programmer',cur,2,0);//fred-boy\r
-   drw_txt(#65+#110+#100+#114+#101+#121+#53+#57+' - Programmer',cur,3,0);//andrey59\r
-   drw_txt(#89+#117+#82+#97+#78+#110+#78+#122+#90+#90+' - Artist',cur,4,0);//yura\r
-   drw_txt(#83+#97+#115+#104+#97+#71+' - Artist and idea generator',cur,5,0);//sasha\r
-   drw_txt(#66+#97+#74+#108+#101+#72+#84+#105+#72+' - Artist and tester',cur,6,0);//valentin\r
-   drw_txt(#65+#103+#114+#101+#115+#115+#111+#82+' - Tester',cur,7,0);//agressor\r
-   drw_txt(#118+#111+#108+#121+#97+#95+#110+#97+#115+#116+#97+#110+#101+' - Tester',cur,8,0);//volya\r
-   drw_txt(#97+#98+#97+#100+#111+#110+' - Tester',cur,9,0);//abadon\r
-   drw_txt(#77+#111+#110+#111+#103+#114+#111+#109+' - Tester',cur,10,0);//monogrom\r
-   drw_txt(#75+#97+#108+#116+#101+#114+' - Tester',cur,11,0);//kalter\r
+   drw_txt('DeaDDooMER - Programmer',cur,1,0);\r
+   drw_txt('fred-boy - Programmer',cur,2,0);\r
+   drw_txt('Andrey59 - Programmer',cur,3,0);\r
+   drw_txt('YuRaNnNzZZ - Artist',cur,4,0);\r
+   drw_txt('SashaG - Artist and idea generator',cur,5,0);\r
+   drw_txt('BaJleHTiH - Artist and tester',cur,6,0);\r
+   drw_txt('AgressoR - Tester',cur,7,0);\r
+   drw_txt('volya - Tester',cur,8,0);\r
+   drw_txt('abadon - Tester',cur,9,0);\r
+   drw_txt('Monogrom - Tester',cur,10,0);\r
+   drw_txt('Kalter - Tester',cur,11,0);\r
 \r
    drw_txt('Thanks:',cur,12,1);\r
    drw_txt('Piligrim and 0vZ - Lib_jsr75i',cur,13,0);\r
@@ -1642,8 +1596,8 @@ procedure menu_about;
    drw_txt('aleshka - Lib_jpeg',cur,17,0);\r
    drw_txt('Roman_V - Lib_safeload',cur,18,0);\r
 \r
-   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);\r
-   drw_txt(#68+#101+#97+#68+#83+#111+#102+#116+#87+#97+#114+#101+' 2012-'+getyear(getcurrenttime),cur,22,0);\r
+   drw_txt('Site: www.deadsoftware.ru',cur,21,0);\r
+   drw_txt('DeaDSoftWare 2012-2014',cur,22,0);\r
 \r
    drw_txt('Hello! :D',cur,100,1);\r
 \r
@@ -1762,11 +1716,10 @@ function setBlock(invcur, x, y:integer):boolean;
   item:=inv.getItem(invcur);\r
   sum:=inv.getSum(invcur);\r
   block:=getMap(x, y);\r
-  sblock:=getItemInfo(item);\r
+  sblock := Items.GetData(item);\r
 \r
-  if getItemType(item)=ITEM_TYPE_BLOCK then\r
-  if inv.isNull(invcur)=false then\r
-  if getBlockSet(block)=true then\r
+  if (Items.GetType(item) = Items.block) and (Inv.IsNull(invcur) = false) then\r
+  if Blocks.IsOverlapped(block) then\r
  // if (coll_xy(x, y)=false) or (getBlockColl(item)=0) then\r
    begin\r
     if set_block_code(sblock, x, y)=false then\r
@@ -2011,39 +1964,27 @@ procedure draw;
   for ix:=minx to maxx do\r
   for iy:=miny to maxy do\r
    begin\r
-    if ifosad then if (getBackMap(ix)>=iy) and (osadki=true) and getBlockTrans(getmap(ix,iy)) then\r
-     begin\r
-      if getBiomMap(ix)=0 then drawimage(osad[0,osadki_ani],(ix*16)-camx,(iy*16)-camy);\r
-       else\r
-      if getBiomMap(ix)=2 then drawimage(osad[1,osadki_ani],(ix*16)-camx,(iy*16)-camy);\r
-       else\r
-      if getBiomMap(ix)=3 then drawimage(osad[0,osadki_ani],(ix*16)-camx,(iy*16)-camy);\r
-     end;\r
-    if drw_back then\r
-     if getBlockTrans(getmap(ix,iy)) then\r
-      draw_back(ix,iy);\r
-\r
-    if getBlockFore(getmap(ix,iy))=false then\r
-     draw_block(ix,iy);\r
+    if ifosad and osadki and (getBackMap(ix) >= iy) and Blocks.IsTransporent(getmap(ix, iy)) then begin\r
+      if getBiomMap(ix) = 0 then drawimage(osad[0, osadki_ani], (ix * 16) - camx, (iy * 16) - camy)\r
+      else if getBiomMap(ix) = 2 then drawimage(osad[1, osadki_ani], (ix * 16) - camx, (iy * 16) - camy)\r
+      else if getBiomMap(ix) = 3 then drawimage(osad[0, osadki_ani], (ix * 16) - camx, (iy * 16) - camy)\r
+    end;\r
+    if drw_back and Blocks.IsTransporent(getmap(ix, iy)) then draw_back(ix, iy);\r
+    if Blocks.IsForeground(getmap(ix,iy)) = false then BlocksLogic.Draw(ix, iy, camx, camy);\r
    end;\r
   {===================[drop]===================}\r
-  drop.draw(camx, camy);\r
+  Drop.Draw(camx, camy);\r
   {===================[particles]===================}\r
-  if s_particles then draw_particle;\r
+  Particles.Draw(camx, camy);\r
   {===================[player]===================}\r
-  if hp>0 then\r
-   begin\r
-    player.draw(camx, camy);\r
-   end;\r
-\r
+  Player.Draw(camx, camy);\r
   {===================[mobs]===================}\r
-  mob.draw(camx, camy);\r
+  Mobs.Draw(camx, camy);\r
   {===================[draw_blocks]===================}\r
   for ix:=minx to maxx do\r
   for iy:=miny to maxy do\r
     begin\r
-      if getBlockFore(getmap(ix, iy)) then\r
-        draw_block(ix, iy);\r
+      if Blocks.IsForeground(getmap(ix, iy)) then BlocksLogic.Draw(ix, iy, camx, camy);\r
 \r
       setcolor(0, 0, 0);\r
       if light_type = 1 then\r
@@ -2090,7 +2031,7 @@ procedure draw;
     drawimage(gui[1],tmp_ax,0);\r
     for ix:=0 to 8 do\r
      begin\r
-      drawItem(inv.getItem(ix), inv.getSum(ix), (ix*16)+tmp_ax+ix*2+4, 1, true);\r
+      ItemsLogic.Draw(inv.getItem(ix), inv.getSum(ix), (ix*16)+tmp_ax+ix*2+4, 1, true);\r
      end;\r
     drawimage(gui[17],(invslot*16)+tmp_ax+invslot*2+2,0);\r
 \r
@@ -2218,82 +2159,72 @@ procedure resetToolProgerss;
   toolind:=0;\r
  end;\r
 \r
-procedure usetools(invcur, x, y:integer);\r
- var\r
-  item, sum, block:integer;\r
- begin\r
-  block:=getmap(x, y);\r
-  item:=inv.getItem(invcur);\r
-  sum:=inv.getSum(invcur);\r
-\r
-  if gamemode=1 then\r
-   destroy_block_cr(block, x, y);\r
-  else\r
-  if (block>0) then\r
-   begin\r
-    if (getItemType(item)=ITEM_TYPE_TOOL) and (getBlockTool(block)=getToolType(item)) then\r
-     toolus:=toolus+getToolSpeed(item);\r
-    else\r
-     toolus:=toolus+1;\r
-\r
-    if toolus>=getBlockHP(block) then\r
-     begin\r
-      if ((getItemType(item)=ITEM_TYPE_TOOL) and (getBlockTool(block)=getToolType(item)) and (getToolLvl(item)>=getBlockLvl(block))) or (getBlockLvl(block)<=0) then\r
-       begin\r
-        setMap(0, x, y);\r
-        destroy_block_1(block, x, y);\r
-        setMapInfo(0, x, y);\r
-       end;\r
-      else\r
-       begin\r
-        setMap(0, x, y);\r
-        destroy_block_0(block, x, y);\r
-        setMapInfo(0, x, y);\r
-       end;\r
-\r
-      if getItemType(item)=ITEM_TYPE_TOOL then\r
-       begin\r
-        inv.setSum(inv.getSum(invcur)-1, invcur);\r
-        inv.fixNull(invcur);\r
-       end;\r
-\r
-      toolus:=0;\r
-      toolind:=0;\r
-     end;\r
-   end;\r
+  procedure usetools(invcur, x, y : integer);\r
+    var\r
+      item, sum, block, tool : integer;\r
+  begin\r
+    block := GetMap(x, y);\r
+    item := Inv.GetItem(invcur);\r
+    sum := Inv.GetSum(invcur);\r
+    tool := Items.GetData(item);\r
+\r
+    if gamemode = 1 then begin\r
+      destroy_block_cr(block, x, y);\r
+    end else if block <> 0 then begin\r
+      if (Items.GetType(item) = Items.tool) and (Blocks.GetTool(block) = Tools.GetType(tool)) then begin\r
+        toolus := toolus + Tools.GetSpeed(tool);\r
+      end else begin\r
+        toolus := toolus + 1;\r
+      end;\r
 \r
-  if (toolus>0) and (toolus<=getBlockHP(block)) then\r
-   toolind:=((toolus*100) div getBlockHP(block)) div 10;\r
- end;\r
+      if toolus >= Blocks.GetResistant(block) then begin\r
+        Debug('usetools: tool = ' + tool);\r
+        if ((Items.GetType(item) = Items.tool) and (Blocks.GetTool(block) = Tools.GetType(tool)) and (Tools.GetLevel(tool) >= Blocks.GetLevel(block))) or (Blocks.GetLevel(block) <= 0) then begin\r
+          SetMap(0, x, y);\r
+          destroy_block_1(block, x, y);\r
+          SetMapInfo(0, x, y);\r
+        end else begin\r
+          SetMap(0, x, y);\r
+          destroy_block_0(block, x, y);\r
+          SetMapInfo(0, x, y);\r
+        end;\r
 \r
-function rt_useweap:boolean;\r
- var\r
-  x, y, w, h, i, damg:integer;\r
-  item:integer;\r
- begin\r
-  x:=player.getX;\r
-  y:=player.getY;\r
-  w:=player.getW;\r
-  h:=player.getH;\r
-  item:=inv.getItem(invslot);\r
+        if Items.GetType(item) = Items.tool then begin\r
+          Inv.SetSum(Inv.GetSum(invcur) - 1, invcur);\r
+          Inv.FixNull(invcur);\r
+        end;\r
 \r
-  if getItemType(item)=1 then\r
-   damg:=getToolDamg(item);\r
-  else\r
-   damg:=1;\r
+        toolus:=0;\r
+        toolind:=0;\r
+      end;\r
+    end;\r
 \r
-  if posi=0 then\r
-   i:=mob.findAndHit(damg, x-TILE_SIZE, y, TILE_SIZE+(w/2), h, -2, -3);\r
-  else\r
-   i:=mob.findAndHit(damg, x+(w/2), y, TILE_SIZE+(w/2), h, 2, -3);\r
+    if (toolus > 0) and (toolus <= Blocks.GetResistant(block)) then begin\r
+      toolind := ((toolus * 100) div Blocks.GetResistant(block)) div 10;\r
+    end;\r
+  end;\r
 \r
-  if i<>-1 then\r
-   begin\r
-    inv.setSum(inv.getSum(invslot)-1, invslot);\r
-    inv.fixNull(invslot);\r
-    rt_useweap:=true;\r
-   end;\r
- end;\r
+  function rt_useweap:boolean;\r
+    var\r
+      item : integer;\r
+      x, y, w, h, i, damg : integer;\r
+  begin\r
+    x := Player.GetX;\r
+    y := Player.GetY;\r
+    w := Player.GetW;\r
+    h := Player.GetH;\r
+    item := Inv.GetItem(invslot);\r
+    if Items.GetType(item) = Items.tool then damg := Tools.GetDamage(item) else damg := 1;\r
+\r
+    if posi=0 then i := Mobs.FindAndHit(damg, x - TILE_SIZE, y, TILE_SIZE + (w / 2), h, -2, -3);\r
+    else i := Mobs.FindAndHit(damg, x + (w / 2), y, TILE_SIZE + (w / 2), h, 2, -3);\r
+\r
+    if i >= 0 then begin\r
+      Inv.SetSum(Inv.GetSum(invslot) - 1, invslot);\r
+      Inv.FixNull(invslot);\r
+      rt_useweap := true;\r
+    end;\r
+  end;\r
 \r
 procedure rt_usetools;\r
  var\r
@@ -2720,9 +2651,9 @@ procedure phyhandler;
  var\r
   i:integer;\r
  begin\r
-  player.calcPhysics;\r
-  mob.updatePhy;\r
-  drop.calcPhy;\r
+  Player.CalcPhysics;\r
+  Mobs.UpdatePhy;\r
+  Drop.CalcPhy;\r
  end;\r
 \r
 procedure light_fillrect(l,x,y,r:integer);\r
@@ -2779,7 +2710,7 @@ procedure calc_sun(ix,m:integer);
    begin\r
     setmaplight(ss,ix,iy);\r
     if ss=0 then break;\r
-    ss:=ss-getBlockTr(getmap(ix,iy));\r
+    ss := ss - Blocks.GetLightAbsorbtion(getmap(ix, iy));\r
     if ss<0 then ss:=0;\r
    end;\r
   for iy:=iy+1 to 127 do\r
@@ -2906,14 +2837,15 @@ procedure game;
 \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
-  if x<0 then x:=0;\r
-  if x+8>4094 then x:=4086;\r
-  if getBlockColl(getmap(x div 16, y div 16))>0 then hp:=hp-1;\r
+  if x < 0 then x := 0;\r
+  else if x + 8 > 4094 then x := 4086;\r
+  if Blocks.IsSolid(getmap(x div 16, y div 16)) then hp := hp - 1;\r
+\r
   if random(4096)=random(4096) then begin osadki:=not osadki; end;\r
   osadki_ani:=osadki_ani+1;\r
   if osadki_ani>7 then osadki_ani:=0;\r
 \r
-  if random(20)=random(20) then create_particle(6,x,y);\r
+  if Random(20) = Random(20) then Particles.Create(Particles.bubble, x, y);\r
 \r
   if gamemode=1 then begin hp:=666; hunger:=666; end;\r
 \r
@@ -2924,9 +2856,8 @@ procedure game;
 \r
   //if s_spawn_mob then if random(4096)=1547 then megaspawn;\r
 \r
-  mob.update;\r
-\r
-  if particle_upd then update_particle;\r
+  Mobs.Update;\r
+  Particles.Update;\r
 \r
   if light_type>0 then\r
    begin\r
@@ -2948,9 +2879,11 @@ procedure game;
   for ix:=minx to maxx do\r
   for iy:=miny to maxy do\r
    begin\r
-    if light_type=0 then setmaplight(15,ix,iy);\r
-     else\r
-    if light_type>0 then if getBlockLi(getmap(ix,iy))>0 then calc_light(getBlockLi(getmap(ix,iy)),ix,iy);\r
+    if light_type = 0 then begin\r
+      SetMapLight(15, ix, iy);\r
+    end else if (light_type > 0) and (Blocks.GetLightEmission(getmap(ix, iy)) > 0) then begin\r
+      calc_light(Blocks.GetLightEmission(GetMap(ix, iy)), ix, iy);\r
+    end;\r
    end;\r
 \r
   minx:=(camx/16)-((getwidth/2)/16);\r
@@ -3069,6 +3002,7 @@ begin
  hp_time:=getrelativetimems;\r
  air_time:=getrelativetimems;\r
  portal_time:=getrelativetimems;\r
+\r
  repeat\r
   proc_fps;\r
   keyhandler;\r