DEADSOFTWARE

Remove ascii crap
[cavecraft.git] / src / CAVE.mpsrc
index 0d305849e358ef1108de30fb24a68376cf90e8e9..df0d606ea05dda1b5cd380d4d7de9ccf4e9e909e 100644 (file)
@@ -10,7 +10,6 @@ uses
  memory,\r
  worldgen,\r
  canvas,\r
- items,\r
  safeload,\r
  mobs,\r
  console,\r
@@ -28,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
@@ -116,7 +120,7 @@ procedure ClearTextures;
     float := no;\r
     compas := no;\r
     for ix := 0 to 7 do\r
-      clock[ix] := no;\r
+      Vars.clock[ix] := no;\r
 \r
     for ix := 0 to maxBlockTex do\r
       begin\r
@@ -187,7 +191,7 @@ 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
@@ -684,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
@@ -1572,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
@@ -1592,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
@@ -1712,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
@@ -1961,20 +1964,13 @@ 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
@@ -1988,8 +1984,7 @@ procedure draw;
   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
@@ -2036,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
@@ -2164,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:=Mobs.findAndHit(damg, x-TILE_SIZE, y, TILE_SIZE+(w/2), h, -2, -3);\r
-  else\r
-   i:=Mobs.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
@@ -2725,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
@@ -2852,9 +2837,10 @@ 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
@@ -2893,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
@@ -3014,6 +3002,7 @@ begin
  hp_time:=getrelativetimems;\r
  air_time:=getrelativetimems;\r
  portal_time:=getrelativetimems;\r
+\r
  repeat\r
   proc_fps;\r
   keyhandler;\r