From: DeaDDooMER Date: Sun, 10 Sep 2017 19:17:34 +0000 (+0300) Subject: blocks.cfg -> Blocks.pas X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=bddd811f24b5890310e09e93a33600a58db39ec9;p=cavecraft.git blocks.cfg -> Blocks.pas --- diff --git a/libs/Lib_items_store.class b/libs/Lib_items_store.class index 161cba0..f07d13f 100644 Binary files a/libs/Lib_items_store.class and b/libs/Lib_items_store.class differ diff --git a/libs/Lib_items_store.java b/libs/Lib_items_store.java index ed2190b..75245bb 100644 --- a/libs/Lib_items_store.java +++ b/libs/Lib_items_store.java @@ -1,148 +1,32 @@ class Lib_items_store { /*Items*/ - static byte[] item_type; - static byte[] item_tex; - static int[] item_max; static byte[] item_info; - static byte[] item_flags; - /*Blocks*/ - static byte[] block_tex; - static int[] block_hp; - static byte[] block_coll; - static byte[] block_tool; - static byte[] block_lvl; - static byte[] block_flags; - static byte[] block_tr; - static byte[] block_li; + /*Craft*/ static byte[] [] craftIN_item; static byte[] [] craftIN_sum; static byte[] craftOUT_item; static int[] craftOUT_sum; static byte[] craftOUT_flag; + /*Tools*/ static byte[] tool_type; static byte[] tool_lvl; static byte[] tool_speed; static byte[] tool_damg; -/*Items*/ - public static void resetitems(int len) - { - try { - item_type = new byte[len]; - item_tex = new byte[len]; - item_max = new int[len]; - item_info = new byte[len]; - item_flags = new byte[len]; - } catch(Exception e) {e.printStackTrace();} - } - - public static void setitemdata(int id, int type, int tex, int max, int info, int flags) - { - try { - item_type[id] = (byte) type; - item_tex[id] = (byte) tex; - item_max[id] = max; - item_info[id] = (byte) info; - item_flags[id] = (byte) flags; - } catch(Exception e) {e.printStackTrace();} - } -/* - public static int getitemmax(int id) - { - try{ - return item_max[id]; - } catch(Exception e) { return 0;} - } -*/ - -/*Blocks*/ - - public static void resetblocks(int len) - { - try { - block_tex = new byte[len]; - block_hp = new int[len]; - block_coll = new byte[len]; - block_tool = new byte[len]; - block_lvl = new byte[len]; - block_flags = new byte[len]; - block_tr = new byte[len]; - block_li = new byte[len]; - } catch(Exception e) {e.printStackTrace();} - } - - public static void setblockdata(int id, int tex, int hp, int coll, int tool, int lvl, int flags, int tr, int li) - { - try { - block_tex[id] = (byte) tex; - block_hp[id] = hp; - block_coll[id] = (byte) coll; - block_tool[id] = (byte) tool; - block_lvl[id] = (byte) lvl; - block_flags[id] = (byte) flags; - block_tr[id] = (byte) tr; - block_li[id] = (byte) li; - } catch(Exception e) {e.printStackTrace();} - } + /* Items */ - public static int getblocktex(int id) - { - try { - return (int) block_tex[id] & 0xFF; - } catch(Exception e) { return 0;} - } + public static void resetitems(int len) + { + item_info = new byte[len]; + } - public static int getblockhp(int id) - { - try { - return block_hp[id]; - } catch(Exception e) { return 0;} - } - - public static int getblockcoll(int id) - { - try { - return (int) block_coll[id] & 0xFF; - } catch(Exception e) { return 0;} - } - - public static int getblocktool(int id) - { - try { - return (int) block_tool[id] & 0xFF; - } catch(Exception e) { return 0;} - } - - public static int getblocklvl(int id) - { - try { - return (int) block_lvl[id] & 0xFF; - } catch(Exception e) { return 0;} - } - - public static int getblockflags(int id) - { - try { - return (int) block_flags[id] & 0xFF; - } catch(Exception e) { return 0;} - } - - public static int getblocktr(int id) - { - try { - return (int) block_tr[id] & 0xFF; - } catch(Exception e) { return 0;} - } - - public static int getblockli(int id) - { - try { - return (int) block_li[id] & 0xFF; - } catch(Exception e) { return 0;} - } + public static void setitemdata(int id, int type, int tex, int max, int info, int flags) + { + item_info[id] = (byte) info; + } /*Craft*/ public static void resetcrafts(int len) diff --git a/src/Blocks.mpsrc b/src/Blocks.mpsrc deleted file mode 100644 index 49e86ed..0000000 --- a/src/Blocks.mpsrc +++ /dev/null @@ -1,28 +0,0 @@ -unit Blocks; - -interface - - function IsTransporent(id : integer) : boolean; - function IsForeground(id : integer) : boolean; - function IsOverlapped(id : integer) : boolean; - -implementation - - uses items_store; - - function IsTransporent(id : integer) : boolean; - begin - result := (items_store.GetBlockFlags(id) and 1) <> 0; - end; - - function IsForeground(id : integer) : boolean; - begin - result := (getBlockFlags(id) and 2) <> 0; - end; - - function IsOverlapped(id : integer) : boolean; - begin - result := (getBlockFlags(id) and 4) <> 0; - end; - -end. diff --git a/src/Blocks.pas b/src/Blocks.pas new file mode 100644 index 0000000..e93d632 --- /dev/null +++ b/src/Blocks.pas @@ -0,0 +1,349 @@ +unit Blocks; + +interface + + const (* Block id *) + none = 0; + dirt = 1; + grass = 2; + stone = 3; + oakWoodPlanks = 4; + cobblestone = 5; + bedrock = 6; + sand = 7; + gravel = 8; + oakWood = 9; + obsidian = 10; + bookshelf = 11; + mossStone = 12; + blockOfIron = 13; + blockOfGold = 14; + blockOfDiamond = 15; + goldOre = 16; + ironOre = 17; + coalOre = 18; + diamondOre = 19; + redstoneOre = 20; + oakLeaves = 21; + redFlower = 22; + yellowFlower = 23; + redMooshroom = 24; + brownMooshroom = 25; + torch = 26; + tnt = 27; + chest = 28; + craftingTable = 29; + cactus = 30; + glass = 31; + wool1 = 32; + wool2 = 33; + wool3 = 34; + wool4 = 35; + wool5 = 36; + wool6 = 37; + wool7 = 38; + wool8 = 39; + wool9 = 40; + wool10 = 41; + wool11 = 42; + wool12 = 43; + wool13 = 44; + wool14 = 45; + wool15 = 46; + wool16 = 47; + snow = 48; + ladder = 49; + water = 50; + lava = 51; + oakSapling = 52; + sponge = 53; + lapisLazuliOre = 54; + lapisLazuliBlock = 55; + sandstone = 56; + tallGrass = 57; + deadBush = 58; + cobweb = 59; + bricks = 60; + snowBlock = 61; + ice = 62; + snowLayer = 63; + clayBlock = 64; + sugarCane = 65; + pumpkin = 66; + jackLantern = 67; + stoneBricks = 68; + mossyStoneBricks = 69; + crackedStoneBricks = 70; + chiseledStokeBricks = 71; + ironBras = 72; + melonBlock = 73; + mycelium = 74; + backgroundOakWood = 75; + spawner = 76; + bed1 = 77; + bed2 = 78; + openWoodenDoor1 = 79; + openWoodenDoor2 = 80; + closedWoodenDoor1 = 81; + closedWoodenDoor2 = 82; + birchWood = 83; + backgroundBirchWood = 84; + spruceWood = 85; + backgroundSpruceWood = 86; + spruceLeaves = 87; + redMushroomBlock1 = 88; + redMushroomBlock2 = 89; + brownMushroomBlock1 = 90; + brownMushroomBlock2 = 91; + oakFence = 92; + backgroundOakFence = 93; + backgroundOakWoodPlanks = 94; + painting1 = 95; + painting2 = 96; + painting3 = 97; + painting4 = 98; + painting5 = 99; + painting6 = 100; + painting7 = 101; + giftChest = 102; + vines = 103; + sign = 104; + redstoneTorch = 105; + furnace = 106; + closedWoodenTrapdoor = 107; + openWoodenTrapdoor = 108; + netherrack = 109; + netherPortal = 110; + glowstone = 111; + birchLeaves = 112; + soulSand = 113; + birchSapling = 114; + spruceSapling = 115; + redstoneLampOff = 116; + redstoneLampOn = 117; + backgroundObsidian = 118; + glassPlane = 119; + farmland = 120; + cake = 121; + wheat = 122; + melonStem = 123; + pumpkinStem = 124; + burningFurnace = 125; + reservedBlock = 126; + + function GetTexture(id : integer) : integer; + function GetResistant(id : integer) : integer; + function GetTool(id : integer) : integer; + function GetLevel(id : integer) : integer; + function GetLightAbsorbtion(id : integer) : integer; + function GetLightEmission(id : integer) : integer; + + function IsTransporent(id : integer) : boolean; + function IsForeground(id : integer) : boolean; + function IsOverlapped(id : integer) : boolean; + function IsSolid(id : integer) : boolean; + +implementation + + uses items_store; + + const + lastBlock = 125; + + var + bltex, hp, tool, lvl, abslight, emmlight, flags : array [0..lastBlock] of integer; + + function GetTexture(id : integer) : integer; + begin + result := bltex[id]; + end; + + function GetResistant(id : integer) : integer; + begin + result := hp[id]; + end; + + function GetTool(id : integer) : integer; + begin + result := tool[id]; + end; + + function GetLevel(id : integer) : integer; + begin + result := lvl[id]; + end; + + function GetLightAbsorbtion(id : integer) : integer; + begin + result := abslight[id]; + end; + + function GetLightEmission(id : integer) : integer; + begin + result := emmlight[id]; + end; + + function IsTransporent(id : integer) : boolean; + begin + result := (flags[id] and (1 << 0)) <> 0; + end; + + function IsForeground(id : integer) : boolean; + begin + result := (flags[id] and (1 << 1)) <> 0; + end; + + function IsOverlapped(id : integer) : boolean; + begin + result := (flags[id] and (1 << 2)) <> 0; + end; + + function IsSolid(id : integer) : boolean; + begin + result := (flags[id] and (1 << 3)) <> 0; + end; + + procedure InitBlock(id, xtex, xhp, xtool, xlvl, xabslight, xemmlight : integer; solid, transporent, foreground, overlap : boolean); + begin + Assert((id >= 0) and (id <= lastBlock)); + bltex[id] := xtex; + hp[id] := xhp; + tool[id] := xtool; + lvl[id] := xlvl; + abslight[id] := xabslight; + emmlight[id] := xemmlight; + flags[id] := 0; + if transporent then flags[id] := flags[id] or (1 << 0); + if foreground then flags[id] := flags[id] or (1 << 1); + if overlap then flags[id] := flags[id] or (1 << 2); + if solid then flags[id] := flags[id] or (1 << 3); + end; + +initialization + InitBlock(none, 0, 0, 0, 0, 0, 0, false, true, false, true); + InitBlock(dirt, 1, 9, 2, 0, 15, 0, true, false, false, false); + InitBlock(grass, 2, 9, 2, 0, 15, 0, true, false, false, false); + InitBlock(stone, 3, 60, 1, 1, 15, 0, true, false, false, false); + InitBlock(oakWoodPlanks, 4, 30, 3, 0, 15, 0, true, false, false, false); + InitBlock(cobblestone, 5, 60, 1, 1, 15, 0, true, false, false, false); + InitBlock(bedrock, 6, 2147483647, 0, 0, 15, 0, true, false, false, false); + InitBlock(sand, 7, 9, 2, 0, 15, 0, true, false, false, false); + InitBlock(gravel, 8, 9, 2, 0, 15, 0, true, false, false, false); + InitBlock(oakWood, 9, 30, 3, 0, 15, 0, true, false, false, false); + InitBlock(obsidian, 10, 1000, 1, 5, 15, 0, true, false, false, false); + InitBlock(bookshelf, 11, 24, 3, 0, 0, 0, false, false, false, false); + InitBlock(mossStone, 12, 40, 1, 1, 15, 0, true, false, false, false); + InitBlock(blockOfIron, 13, 40, 1, 2, 15, 0, true, false, false, false); + InitBlock(blockOfGold, 14, 60, 1, 3, 15, 0, true, false, false, false); + InitBlock(blockOfDiamond, 15, 60, 1, 3, 15, 0, true, false, false, false); + InitBlock(goldOre, 16, 65, 1, 3, 15, 0, true, false, false, false); + InitBlock(ironOre, 17, 65, 1, 2, 15, 0, true, false, false, false); + InitBlock(coalOre, 18, 65, 1, 1, 15, 0, true, false, false, false); + InitBlock(diamondOre, 19, 65, 1, 3, 15, 0, true, false, false, false); + InitBlock(redstoneOre, 20, 65, 1, 3, 15, 6, true, false, false, false); + InitBlock(oakLeaves, 21, 3, 4, 1, 1, 0, true, false, false, false); + InitBlock(redFlower, 22, 0, 0, 0, 0, 0, false, true, false, true); + InitBlock(yellowFlower, 23, 0, 0, 0, 0, 0, false, true, false, true); + InitBlock(redMooshroom, 24, 0, 0, 0, 0, 0, false, true, false, true); + InitBlock(brownMooshroom, 25, 0, 0, 0, 0, 0, false, true, false, true); + InitBlock(torch, 26, 0, 0, 0, 0, 14, false, true, false, false); + InitBlock(tnt, 27, 0, 0, 0, 15, 0, true, false, false, false); + InitBlock(chest, 28, 39, 3, 0, 0, 0, false, false, false, false); + InitBlock(craftingTable, 29, 39, 3, 0, 0, 0, false, false, false, false); + InitBlock(cactus, 30, 6, 0, 0, 0, 0, true, true, false, false); + InitBlock(glass, 31, 6, 0, 1, 1, 0, true, true, false, false); + InitBlock(wool1, 32, 12, 0, 0, 0, 0, false, false, false, false); + InitBlock(wool2, 33, 12, 0, 0, 0, 0, false, false, false, false); + InitBlock(wool3, 34, 12, 0, 0, 0, 0, false, false, false, false); + InitBlock(wool4, 35, 12, 0, 0, 0, 0, false, false, false, false); + InitBlock(wool5, 36, 12, 0, 0, 0, 0, false, false, false, false); + InitBlock(wool6, 37, 12, 0, 0, 0, 0, false, false, false, false); + InitBlock(wool7, 38, 12, 0, 0, 0, 0, false, false, false, false); + InitBlock(wool8, 39, 12, 0, 0, 0, 0, false, false, false, false); + InitBlock(wool9, 40, 12, 0, 0, 0, 0, false, false, false, false); + InitBlock(wool10, 41, 12, 0, 0, 0, 0, false, false, false, false); + InitBlock(wool11, 42, 12, 0, 0, 0, 0, false, false, false, false); + InitBlock(wool12, 43, 12, 0, 0, 0, 0, false, false, false, false); + InitBlock(wool13, 44, 12, 0, 0, 0, 0, false, false, false, false); + InitBlock(wool14, 45, 12, 0, 0, 0, 0, false, false, false, false); + InitBlock(wool15, 46, 12, 0, 0, 0, 0, false, false, false, false); + InitBlock(wool16, 47, 12, 0, 0, 0, 0, false, false, false, false); + InitBlock(snow, 48, 9, 2, 0, 15, 0, true, false, false, false); + InitBlock(ladder, 49, 6, 0, 0, 0, 0, false, true, false, false); + InitBlock(water, 50, 2147483647, 0, 0, 1, 0, false, true, true, true); + InitBlock(lava, 55, 2147483647, 0, 0, 15, 15, false, true, true, true); + InitBlock(oakSapling, 60, 0, 0, 0, 0, 0, false, true, false, true); + InitBlock(sponge, 61, 9, 0, 0, 15, 0, true, false, false, false); + InitBlock(lapisLazuliOre, 62, 65, 1, 2, 15, 0, true, false, false, false); + InitBlock(lapisLazuliBlock, 63, 65, 1, 2, 15, 0, true, false, false, false); + InitBlock(sandstone, 64, 50, 1, 1, 15, 0, true, false, false, false); + InitBlock(tallGrass, 65, 0, 4, 1, 0, 0, false, true, false, true); + InitBlock(deadBush, 66, 0, 4, 1, 0, 0, false, true, false, true); + InitBlock(cobweb, 67, 60, 4, 1, 0, 0, false, true, false, true); + InitBlock(bricks, 68, 60, 1, 1, 15, 0, true, false, false, false); + InitBlock(snowBlock, 69, 3, 2, 0, 15, 0, true, false, false, false); + InitBlock(ice, 70, 8, 1, 6, 2, 0, true, true, false, false); + InitBlock(snowLayer, 71, 2, 2, 1, 1, 0, false, true, true, true); + InitBlock(clayBlock, 72, 9, 2, 0, 15, 0, true, false, false, false); + InitBlock(sugarCane, 73, 0, 0, 0, 0, 0, false, true, true, true); + InitBlock(pumpkin, 74, 15, 3, 0, 1, 0, true, false, false, false); + InitBlock(jackLantern, 75, 15, 3, 0, 1, 15, true, false, false, false); + InitBlock(stoneBricks, 76, 60, 1, 1, 15, 0, true, false, false, false); + InitBlock(mossyStoneBricks, 77, 60, 1, 1, 15, 0, true, false, false, false); + InitBlock(crackedStoneBricks, 78, 60, 1, 1, 15, 0, true, false, false, false); + InitBlock(chiseledStokeBricks, 79, 60, 1, 1, 15, 0, true, false, false, false); + InitBlock(ironBras, 80, 60, 1, 1, 0, 0, false, true, true, false); + InitBlock(melonBlock, 81, 15, 0, 0, 15, 0, true, false, false, false); + InitBlock(mycelium, 82, 8, 2, 0, 15, 0, true, false, false, false); + InitBlock(backgroundOakWood, 98, 30, 3, 0, 0, 0, false, false, false, false); + InitBlock(spawner, 83, 75, 0, 0, 0, 0, false, true, false, false); + InitBlock(bed1, 84, 3, 0, 0, 0, 0, false, true, false, false); + InitBlock(bed2, 85, 3, 0, 0, 0, 0, false, true, false, false); + InitBlock(openWoodenDoor1, 86, 30, 3, 0, 0, 0, false, true, false, false); + InitBlock(openWoodenDoor2, 102, 30, 3, 0, 0, 0, false, true, false, false); + InitBlock(closedWoodenDoor1, 88, 30, 3, 0, 0, 0, true, true, true, false); + InitBlock(closedWoodenDoor2, 104, 30, 3, 0, 0, 0, true, true, true, false); + InitBlock(birchWood, 90, 30, 3, 0, 0, 0, true, false, false, false); + InitBlock(backgroundBirchWood, 99, 30, 3, 0, 0, 0, false, false, false, false); + InitBlock(spruceWood, 91, 30, 3, 0, 0, 0, true, false, false, false); + InitBlock(backgroundSpruceWood, 100, 30, 3, 0, 0, 0, false, false, false, false); + InitBlock(spruceLeaves, 92, 3, 4, 1, 1, 0, true, false, false, false); + InitBlock(redMushroomBlock1, 93, 3, 3, 0, 2, 0, true, false, false, false); + InitBlock(redMushroomBlock2, 95, 3, 3, 0, 0, 0, false, false, false, false); + InitBlock(brownMushroomBlock1, 94, 3, 3, 0, 2, 0, true, false, false, false); + InitBlock(brownMushroomBlock2, 95, 3, 3, 0, 0, 0, false, false, false, false); + InitBlock(oakFence, 96, 30, 3, 0, 0, 0, true, true, false, false); + InitBlock(backgroundOakFence, 101, 30, 3, 0, 0, 0, false, true, false, false); + InitBlock(backgroundOakWoodPlanks, 97, 30, 3, 0, 0, 0, false, false, false, false); + InitBlock(painting1, 106, 0, 0, 0, 0, 0, false, true, false, true); + InitBlock(painting2, 107, 0, 0, 0, 0, 0, false, true, false, true); + InitBlock(painting3, 108, 0, 0, 0, 0, 0, false, true, false, true); + InitBlock(painting4, 109, 0, 0, 0, 0, 0, false, true, false, true); + InitBlock(painting5, 110, 0, 0, 0, 0, 0, false, true, false, true); + InitBlock(painting6, 111, 0, 0, 0, 0, 0, false, true, false, true); + InitBlock(painting7, 112, 0, 0, 0, 0, 0, false, true, false, true); + InitBlock(giftChest, 113, 30, 3, 0, 0, 15, false, false, false, false); + InitBlock(vines, 114, 3, 4, 1, 0, 0, false, true, true, true); + InitBlock(sign, 115, 15, 0, 0, 0, 0, false, true, false, false); + InitBlock(redstoneTorch, 116, 0, 0, 0, 0, 7, false, true, false, true); + InitBlock(furnace, 117, 40, 3, 0, 0, 0, false, false, false, false); + InitBlock(closedWoodenTrapdoor, 118, 30, 3, 0, 0, 0, true, true, true, false); + InitBlock(openWoodenTrapdoor, 119, 30, 3, 0, 0, 0, false, true, false, false); + InitBlock(netherrack, 120, 30, 1, 1, 15, 0, true, false, false, false); + InitBlock(netherPortal, 129, 2147483647, 0, 0, 0, 11, false, true, true, false); + InitBlock(glowstone, 121, 10, 1, 0, 0, 15, true, false, false, false); + InitBlock(birchLeaves, 135, 3, 4, 1, 1, 0, true, false, false, false); + InitBlock(soulSand, 122, 9, 2, 0, 15, 0, true, false, false, false); + InitBlock(birchSapling, 123, 0, 0, 0, 0, 0, false, true, false, true); + InitBlock(spruceSapling, 124, 0, 0, 0, 0, 0, false, true, false, true); + InitBlock(redstoneLampOff, 125, 10, 1, 0, 0, 0, true, false, false, false); + InitBlock(redstoneLampOn, 126, 10, 1, 0, 0, 15, true, false, false, false); + InitBlock(backgroundObsidian, 127, 1000, 1, 5, 15, 0, false, false, false, false); + InitBlock(glassPlane, 128, 6, 0, 1, 1, 0, false, true, false, false); + InitBlock(farmland, 136, 9, 2, 0, 15, 0, true, false, false, false); + InitBlock(cake, 137, 9, 0, 0, 0, 0, false, true, false, false); + InitBlock(wheat, 138, 1, 0, 0, 0, 0, false, true, false, true); + InitBlock(melonStem, 139, 1, 0, 0, 0, 0, false, true, false, true); + InitBlock(pumpkinStem, 139, 1, 0, 0, 0, 0, false, true, false, true); + InitBlock(burningFurnace, 134, 40, 3, 0, 0, 15, false, false, false, false); +end. diff --git a/src/BlocksLogic.pas b/src/BlocksLogic.pas new file mode 100644 index 0000000..d3fa264 --- /dev/null +++ b/src/BlocksLogic.pas @@ -0,0 +1,25 @@ +unit BlocksLogic; + +interface + + procedure Draw(x, y, camx, camy : integer); + +implementation + + uses Vars, Blocks, Maps; + + procedure Draw(x, y, camx, camy : integer); + const + tileSize = 16; + var + id : integer; + texid : integer; + begin + id := Maps.GetMap(x, y); + texid := Blocks.GetTexture(id); + DrawImage(tex[texid], x * tileSize - camx, y * tileSize - camy); + end; + +initialization + +end. diff --git a/src/CAVE.mpsrc b/src/CAVE.mpsrc index 830a6ab..a43998d 100644 --- a/src/CAVE.mpsrc +++ b/src/CAVE.mpsrc @@ -1,7 +1,6 @@ program CAVE; uses - Items, sign, jsr75i, drop, @@ -29,7 +28,10 @@ uses inv, items_store, video, - Blocks; + Blocks, + BlocksLogic, + Items, + ItemsLogic; const version_map = 9; @@ -1967,7 +1969,7 @@ procedure draw; else if getBiomMap(ix) = 3 then drawimage(osad[0, osadki_ani], (ix * 16) - camx, (iy * 16) - camy) end; if drw_back and Blocks.IsTransporent(getmap(ix, iy)) then draw_back(ix, iy); - if Blocks.IsForeground(getmap(ix,iy)) = false then draw_block(ix,iy); + if Blocks.IsForeground(getmap(ix,iy)) = false then BlocksLogic.Draw(ix, iy, camx, camy); end; {===================[drop]===================} Drop.Draw(camx, camy); @@ -1981,7 +1983,7 @@ procedure draw; for ix:=minx to maxx do for iy:=miny to maxy do begin - if Blocks.IsForeground(getmap(ix, iy)) then draw_block(ix, iy); + if Blocks.IsForeground(getmap(ix, iy)) then BlocksLogic.Draw(ix, iy, camx, camy); setcolor(0, 0, 0); if light_type = 1 then @@ -2028,7 +2030,7 @@ procedure draw; drawimage(gui[1],tmp_ax,0); for ix:=0 to 8 do begin - Items.Draw(inv.getItem(ix), inv.getSum(ix), (ix*16)+tmp_ax+ix*2+4, 1, true); + ItemsLogic.Draw(inv.getItem(ix), inv.getSum(ix), (ix*16)+tmp_ax+ix*2+4, 1, true); end; drawimage(gui[17],(invslot*16)+tmp_ax+invslot*2+2,0); @@ -2169,14 +2171,14 @@ procedure usetools(invcur, x, y:integer); else if (block>0) then begin - if (Items.GetType(item) = Items.tool) and (getBlockTool(block)=getToolType(item)) then + if (Items.GetType(item) = Items.tool) and (Blocks.GetTool(block) = getToolType(item)) then toolus:=toolus+getToolSpeed(item); else toolus:=toolus+1; - if toolus>=getBlockHP(block) then + if toolus >= Blocks.GetResistant(block) then begin - if ((Items.GetType(item) = Items.tool) and (getBlockTool(block)=getToolType(item)) and (getToolLvl(item)>=getBlockLvl(block))) or (getBlockLvl(block)<=0) then + if ((Items.GetType(item) = Items.tool) and (Blocks.GetTool(block) = getToolType(item)) and (getToolLvl(item) >= Blocks.GetLevel(block))) or (Blocks.GetLevel(block) <= 0) then begin setMap(0, x, y); destroy_block_1(block, x, y); @@ -2200,8 +2202,9 @@ procedure usetools(invcur, x, y:integer); end; end; - if (toolus>0) and (toolus<=getBlockHP(block)) then - toolind:=((toolus*100) div getBlockHP(block)) div 10; + if (toolus > 0) and (toolus <= Blocks.GetResistant(block)) then begin + toolind := ((toolus * 100) div Blocks.GetResistant(block)) div 10; + end; end; function rt_useweap:boolean; @@ -2717,7 +2720,7 @@ procedure calc_sun(ix,m:integer); begin setmaplight(ss,ix,iy); if ss=0 then break; - ss:=ss-getBlockTr(getmap(ix,iy)); + ss := ss - Blocks.GetLightAbsorbtion(getmap(ix, iy)); if ss<0 then ss:=0; end; for iy:=iy+1 to 127 do @@ -2844,9 +2847,10 @@ procedure game; if clock_stage<>game_time div 75000 then begin clock_stage:=clock_stage+1; if clock_stage>7 then clock_stage:=0; end; - if x<0 then x:=0; - if x+8>4094 then x:=4086; - if getBlockColl(getmap(x div 16, y div 16))>0 then hp:=hp-1; + if x < 0 then x := 0; + else if x + 8 > 4094 then x := 4086; + if Blocks.IsSolid(getmap(x div 16, y div 16)) then hp := hp - 1; + if random(4096)=random(4096) then begin osadki:=not osadki; end; osadki_ani:=osadki_ani+1; if osadki_ani>7 then osadki_ani:=0; @@ -2885,9 +2889,11 @@ procedure game; for ix:=minx to maxx do for iy:=miny to maxy do begin - if light_type=0 then setmaplight(15,ix,iy); - else - if light_type>0 then if getBlockLi(getmap(ix,iy))>0 then calc_light(getBlockLi(getmap(ix,iy)),ix,iy); + if light_type = 0 then begin + SetMapLight(15, ix, iy); + end else if (light_type > 0) and (Blocks.GetLightEmission(getmap(ix, iy)) > 0) then begin + calc_light(Blocks.GetLightEmission(GetMap(ix, iy)), ix, iy); + end; end; minx:=(camx/16)-((getwidth/2)/16); @@ -3106,7 +3112,7 @@ procedure draw_debug; else if id = Items.painting5 then name := 'painting5' else if id = Items.painting6 then name := 'painting6' else if id = Items.painting7 then name := 'painting7' - else if id = Items.reservedBlockItem1 then name := 'reservedBlockItem1' + else if id = Items.giftChest then name := 'giftChest' else if id = Items.vines then name := 'vines' else if id = Items.sign then name := 'sign' else if id = Items.redstoneTorch then name := 'redstoneTorch' @@ -3126,11 +3132,11 @@ procedure draw_debug; else if id = Items.glassPlane then name := 'glassPlane' else if id = Items.farmland then name := 'farmland' else if id = Items.cake then name := 'cake' - else if id = Items.reservedBlockItem2 then name := 'reservedBlockItem2' - else if id = Items.reservedBlockItem3 then name := 'reservedBlockItem3' - else if id = Items.reservedBlockItem4 then name := 'reservedBlockItem4' - else if id = Items.reservedBlockItem5 then name := 'reservedBlockItem5' - else if id = Items.reservedBlockItem6 then name := 'reservedBlockItem6' + else if id = Items.wheatBlock then name := 'wheatBlock' + else if id = Items.melonStem then name := 'melonStem' + else if id = Items.pumpkinStem then name := 'pumpkinStem' + else if id = Items.burningFurnace then name := 'burningFurnace' + else if id = Items.reservedBlockItem then name := 'reservedBlockItem' else if id = Items.stick then name := 'stick' else if id = Items.dandelionYellow then name := 'dandelionYellow' else if id = Items.roseRed then name := 'roseRed' @@ -3271,6 +3277,21 @@ procedure draw_debug; for id := 0 to 194 do begin Debug(' InitOrdItem(' + ItemToString(Items.GetOrdinary(id)) + ');'); end; + + for id := 0 to 125 do begin + Debug(' InitBlock(' + ItemToString(id) + ', ' + + Blocks.GetTexture(id) + ', ' + + Blocks.GetResistant(id) + ', ' + + Blocks.GetTool(id) + ', ' + + Blocks.GetLevel(id) + ', ' + + Blocks.GetLightAbsorbtion(id) + ', ' + + Blocks.GetLightEmission(id) + ', ' + + Blocks.IsSolid(id) + ', ' + + Blocks.IsTransporent(id) + ', ' + + Blocks.IsForeground(id) + ', ' + + Blocks.IsOverlapped(id) + ');' + ); + end; end; begin diff --git a/src/Items.pas b/src/Items.pas index 9ebb84e..48475d5 100644 --- a/src/Items.pas +++ b/src/Items.pas @@ -108,7 +108,7 @@ interface painting5 = 99; painting6 = 100; painting7 = 101; - reservedBlockItem1 = 102; + giftChest = 102; vines = 103; sign = 104; redstoneTorch = 105; @@ -128,11 +128,11 @@ interface glassPlane = 119; farmland = 120; cake = 121; - reservedBlockItem2 = 122; - reservedBlockItem3 = 123; - reservedBlockItem4 = 124; - reservedBlockItem5 = 125; - reservedBlockItem6 = 126; + wheatBlock = 122; + melonStem = 123; + pumpkinStem = 124; + burningFurnace = 125; + reservedBlockItem = 126; stick = 127; dandelionYellow = 128; roseRed = 129; @@ -251,9 +251,6 @@ interface function GetOrdinary(i : integer) : integer; - procedure DrawSmall(id, x, y : integer); - procedure Draw(id, sum, x, y : integer; drawIndicator : boolean); - implementation uses Vars, Func; @@ -340,37 +337,6 @@ implementation countOrdItems := countOrdItems + 1; end; - procedure DrawSmall(id, x, y : integer); - begin - if GetTextureSource(id) = 0 then DrawImage(Vars.tex8[itex[id]], x, y) - else if GetTextureSource(id) = 1 then DrawImage(Vars.item8[itex[id]], x, y) - end; - - procedure Draw(id, sum, x, y : integer; drawIndicator : boolean); - const - maxLength = 15; - maxHeight = 14; - redLength = 3; - var - class, len : integer; - begin - if sum <= 0 then exit; - - if GetTextureSource(id) = 0 then DrawImage(Vars.tex[itex[id]], x, y) - else if GetTextureSource(id) = 1 then DrawImage(Vars.item[itex[id]], x, y) - - if drawIndicator and (sum > 1) then begin - class := GetIndicatorType(id); - if class = numeric then begin - Func.DrawFontText('' + sum, x, y + 8) - end else if class = line then begin - len := sum * maxLength / imax[id]; - if len <= redLength then SetColor(255, 0, 0) else SetColor(0, 255, 0); - DrawLine(x, y + maxHeight, x + len, y + maxHeight); - end; - end; - end; - initialization InitItem(none, block, 0, 0, 0, 0, noindicator, false); InitItem(dirt, block, 1, 64, 1, 0, numeric, true); @@ -474,7 +440,7 @@ initialization InitItem(painting5, block, 110, 1, 99, 0, numeric, true); InitItem(painting6, block, 111, 1, 100, 0, numeric, true); InitItem(painting7, block, 112, 1, 101, 0, numeric, true); - InitItem(reservedBlockItem1, block, 0, 0, 0, 0, noindicator, false); + InitItem(giftChest, block, 113, 64, 102, 0, numeric, true); InitItem(vines, block, 114, 64, 103, 0, numeric, true); InitItem(sign, block, 98, 16, 104, 1, numeric, true); InitItem(redstoneTorch, block, 116, 64, 105, 0, numeric, true); @@ -494,11 +460,11 @@ initialization InitItem(glassPlane, block, 128, 64, 119, 0, numeric, true); InitItem(farmland, block, 136, 64, 120, 0, numeric, true); InitItem(cake, block, 137, 64, 121, 0, numeric, true); - InitItem(reservedBlockItem2, block, 0, 0, 0, 0, noindicator, false); - InitItem(reservedBlockItem3, block, 0, 0, 0, 0, noindicator, false); - InitItem(reservedBlockItem4, block, 0, 0, 0, 0, noindicator, false); - InitItem(reservedBlockItem5, block, 0, 0, 0, 0, noindicator, false); - InitItem(reservedBlockItem6, block, 0, 0, 0, 0, noindicator, false); + InitItem(wheatBlock, block, 142, 64, 122, 0, numeric, true); + InitItem(melonStem, block, 143, 64, 123, 0, numeric, true); + InitItem(pumpkinStem, block, 143, 64, 124, 0, numeric, true); + InitItem(burningFurnace, block, 134, 64, 125, 0, numeric, true); + InitItem(reservedBlockItem, block, 0, 0, 0, 0, noindicator, false); InitItem(stick, orditem, 0, 64, 0, 1, numeric, true); InitItem(dandelionYellow, orditem, 8, 64, 0, 1, numeric, true); InitItem(roseRed, orditem, 9, 64, 0, 1, numeric, true); diff --git a/src/ItemsLogic.pas b/src/ItemsLogic.pas new file mode 100644 index 0000000..497ab34 --- /dev/null +++ b/src/ItemsLogic.pas @@ -0,0 +1,52 @@ +unit ItemsLogic; + +interface + + procedure DrawSmall(id, x, y : integer); + procedure Draw(id, sum, x, y : integer; drawIndicator : boolean); + +implementation + + uses Items, Vars, Func; + + procedure DrawSmall(id, x, y : integer); + var + texid, source : integer; + begin + texid := Items.GetTexture(id); + source := Items.GetTextureSource(id); + if source = 0 then DrawImage(Vars.tex8[texid], x, y) + else if source = 1 then DrawImage(Vars.item8[texid], x, y) + end; + + procedure Draw(id, sum, x, y : integer; drawIndicator : boolean); + const + maxLength = 15; + maxHeight = 14; + redLength = 3; + var + texid, source, class, max, len : integer; + begin + if sum <= 0 then exit; + + texid := Items.GetTexture(id); + source := Items.GetTextureSource(id); + if source = 0 then DrawImage(Vars.tex[texid], x, y) + else if source = 1 then DrawImage(Vars.item[texid], x, y) + + if drawIndicator and (sum > 1) then begin + class := Items.GetIndicatorType(id); + if class = numeric then begin + Func.DrawFontText('' + sum, x, y + 8) + end else if class = line then begin + max := Items.GetMaximum(id); + len := sum * maxLength / max; + if len <= redLength then SetColor(255, 0, 0) else SetColor(0, 255, 0); + DrawLine(x, y + maxHeight, x + len, y + maxHeight); + end; + end; + end; + +initialization + +end. diff --git a/src/Phy.pas b/src/Phy.pas index 2b795c4..9157e68 100644 --- a/src/Phy.pas +++ b/src/Phy.pas @@ -20,7 +20,7 @@ interface implementation - uses items_store, maps, vars; + uses Maps, Vars, Blocks; const maxVelocity = 32; @@ -58,7 +58,7 @@ implementation function IsSolid(x, y : integer) : boolean; begin - isSolid := GetBlockColl(getMap(x, y)) <> 0; + result := Blocks.IsSolid(getMap(x, y)); end; function MapColl(x, y, w, h : integer) : boolean; diff --git a/src/Player.mpsrc b/src/Player.mpsrc index 947adf9..0a97db7 100644 --- a/src/Player.mpsrc +++ b/src/Player.mpsrc @@ -42,7 +42,7 @@ interface implementation - uses func, phy, vars, Canvas, drop, jsr75i, inv, Items; + uses func, phy, vars, Canvas, drop, jsr75i, inv, ItemsLogic; const PLAYER_W=8; @@ -188,9 +188,9 @@ implementation DrawImage(playerBody[posi], x - camx, y - camy); DrawImage(playerLegs[posi, animLegs], x - 2 - camx, y + 20 - camy); - if animHand = 0 then Items.DrawSmall(Inv.GetItem(invslot), x - camx, y + 14 - camy); - else if posi = POSI_RIGHT then Items.DrawSmall(Inv.GetItem(invslot), x + 10 - camx, y + 5 - camy + animHand); - else if posi = POSI_LEFT then Items.DrawSmall(Inv.GetItem(invslot), x - 10 - camx, y + 5 - camy + animHand); + if animHand = 0 then ItemsLogic.DrawSmall(Inv.GetItem(invslot), x - camx, y + 14 - camy); + else if posi = POSI_RIGHT then ItemsLogic.DrawSmall(Inv.GetItem(invslot), x + 10 - camx, y + 5 - camy + animHand); + else if posi = POSI_LEFT then ItemsLogic.DrawSmall(Inv.GetItem(invslot), x - 10 - camx, y + 5 - camy + animHand); if (animHand = 0) or (posi = POSI_RIGHT) then DrawImage(playerHand[posi, animHand], x + 2 - camx, y + 8 - camy); else DrawImage(playerHand[posi, animHand], x - 6 - camx, y + 8 - camy); diff --git a/src/cellui.mpsrc b/src/cellui.mpsrc index 3b14c3f..6115323 100644 --- a/src/cellui.mpsrc +++ b/src/cellui.mpsrc @@ -75,7 +75,7 @@ interface function FindCurrentWindowsType:boolean; implementation - uses vars, Canvas, console, furnace, chest, inv, func, items_store, Items; + uses vars, Canvas, console, furnace, chest, inv, func, items_store, Items, ItemsLogic; var layer:integer; last_cell: array [0..CONST_MAX_LAYERS] of integer; @@ -336,7 +336,7 @@ implementation for j:=0 to CONST_MAX_CELLS do if inv_type[i, j]<>CELL_TYPE_NULL then begin - Items.Draw(getItemIdx(j, i), getSumIdx(j, i), x+inv_x[i, j], y+inv_y[i, j], getCellFlagIndicator(i, j)); + ItemsLogic.Draw(getItemIdx(j, i), getSumIdx(j, i), x+inv_x[i, j], y+inv_y[i, j], getCellFlagIndicator(i, j)); end; end; diff --git a/src/console.pas b/src/console.pas index 3d227f8..378769b 100644 --- a/src/console.pas +++ b/src/console.pas @@ -640,25 +640,6 @@ procedure exeCommand(str:string); decodeInt(nextWord)); end; else - if com='RESET_BLOCKS' then - begin - resetBlocks(decodeInt(nextWord)+1); - //addToLog('Max blocks: '+decodeInt(parsed_str[1])); - end; - else - if com='SET_BLOCK' then - begin - setBlockData(decodeInt(nextWord), - decodeInt(nextWord), - decodeInt(nextWord), - decodeInt(nextWord), - decodeInt(nextWord), - decodeInt(nextWord), - decodeInt(nextWord), - decodeInt(nextWord), - decodeInt(nextWord)); - end; - else if com='RESET_TOOLS' then begin resetTools(decodeInt(nextWord)+1); diff --git a/src/drop.mpsrc b/src/drop.mpsrc index 3738c12..e71dabf 100644 --- a/src/drop.mpsrc +++ b/src/drop.mpsrc @@ -26,7 +26,9 @@ interface procedure loadData; implementation - uses phy, jsr75i, vars, items_store, func, Items; + + uses phy, jsr75i, vars, items_store, func, ItemsLogic; + const MAX_DROP=255; DROP_W=8; @@ -145,7 +147,7 @@ implementation begin if not drw_drp then exit; for i:=0 to 255 do if IsNull(i) = false then begin - Items.DrawSmall(drop_item[i], drop_x[i] - camx, drop_y[i] - camy); + ItemsLogic.DrawSmall(drop_item[i], drop_x[i] - camx, drop_y[i] - camy); end; end; diff --git a/src/func.mpsrc b/src/func.mpsrc index bce8640..1edb76f 100644 --- a/src/func.mpsrc +++ b/src/func.mpsrc @@ -3,8 +3,8 @@ unit func; interface function get_spawn_x:integer;//Возвращает блок по X где должен появиться игрок function get_spawn_y:integer;//Возвращает блок по Y где должен появиться игрок - procedure draw_block(xx,yy:integer); (* + procedure draw_block(xx,yy:integer); procedure drawSmallItem(item, x, y:integer); procedure drawItem(item, sum, x, y:integer; indicator:boolean;); *) @@ -115,6 +115,7 @@ function readstr:string; end; *) +(* procedure draw_block(xx,yy:integer); begin if (getmap(xx,yy)=123) or (getmap(xx,yy)=124) then @@ -169,6 +170,7 @@ function readstr:string; if getmap(xx,yy)<>0 then drawimage(tex[getBlockTex(getmap(xx,yy))],(xx*16)-camx,(yy*16)-camy); end; +*) (* procedure drawItem(item, sum, x, y:integer; indicator:boolean;); diff --git a/src/invui.mpsrc b/src/invui.mpsrc index 0fbac2e..3c4a8f0 100644 --- a/src/invui.mpsrc +++ b/src/invui.mpsrc @@ -10,7 +10,9 @@ interface function WindowKeyHanler:boolean; implementation - uses vars, CellUI, console, Canvas, utils, craft, furnace, func, items_store, player, keyboard, Items; + + uses vars, CellUI, console, Canvas, utils, craft, furnace, func, items_store, player, keyboard, Items, ItemsLogic; + const WINDOW_PLAYER_INV=1; WINDOW_DIV_ITEMS=2; @@ -176,11 +178,11 @@ implementation for i:=0 to 1 do for j:=0 to 1 do begin - Items.Draw(getCraftInItem(craftid, id), getCraftInSum(craftid, id), x+52+j*18, y+17+i*18, true); + ItemsLogic.Draw(getCraftInItem(craftid, id), getCraftInSum(craftid, id), x+52+j*18, y+17+i*18, true); id:=id+1; end; - Items.Draw(getCraftOutItem(craftid), getCraftOutSum(craftid), x+108, y+27, true); + ItemsLogic.Draw(getCraftOutItem(craftid), getCraftOutSum(craftid), x+108, y+27, true); i:=calcScrollBar(52, getImageHeight(fcScrollImg), MAX_FASTCRAFT_OFFSET, getOffset(0)); drawimage(fcScrollImg, x+156, y+66+i); @@ -409,8 +411,8 @@ implementation sum1:=GetWindowInfo(WINDOW_INFO_DIV_SUM1); sum2:=GetWindowInfo(WINDOW_INFO_DIV_SUM2); - Items.Draw(item, (sum1-sum2), x+8, y+8, true); - Items.Draw(item, sum2, x+64, y+8, true); + ItemsLogic.Draw(item, (sum1-sum2), x+8, y+8, true); + ItemsLogic.Draw(item, sum2, x+64, y+8, true); i:=calcScrollBar(72, getImageWidth(DivScrollImg), sum1, sum2); diff --git a/src/items_logic.mpsrc b/src/items_logic.mpsrc index 84db334..525f02d 100644 --- a/src/items_logic.mpsrc +++ b/src/items_logic.mpsrc @@ -852,7 +852,7 @@ procedure destroy_block_cr(id, xx, yy:integer); else if item=180 then begin - if getBlockColl(block)=0 then + if Blocks.IsSolid(block) = false then begin Mobs.Create(Mobs.zomby, x * 16, y * 16); decItem(invcur); @@ -861,7 +861,7 @@ procedure destroy_block_cr(id, xx, yy:integer); else if item=181 then begin - if getBlockColl(block)=0 then + if Blocks.IsSolid(block) = false then begin //create_mob(2, x*16, y*16); decItem(invcur); @@ -870,7 +870,7 @@ procedure destroy_block_cr(id, xx, yy:integer); else if item=182 then begin - if getBlockColl(block)=0 then + if Blocks.IsSolid(block) = false then begin //create_mob(3, x*16, y*16); decItem(invcur); @@ -1017,7 +1017,7 @@ procedure destroy_block_cr(id, xx, yy:integer); else if item=205 then begin - if getBlockColl(block)=0 then + if Blocks.IsSolid(block) = false then begin //create_mob(4, x*16, y*16); decItem(invcur); @@ -1026,7 +1026,7 @@ procedure destroy_block_cr(id, xx, yy:integer); else if item=206 then begin - if getBlockColl(block)=0 then + if Blocks.IsSolid(block) = false then begin //create_mob(5, x*16, y*16); decItem(invcur); @@ -1035,7 +1035,7 @@ procedure destroy_block_cr(id, xx, yy:integer); else if item=208 then begin - if getBlockColl(block)=0 then + if Blocks.IsSolid(block) = false then begin //create_mob(6, x*16, y*16); decItem(invcur); @@ -1044,7 +1044,7 @@ procedure destroy_block_cr(id, xx, yy:integer); else if item=209 then begin - if getBlockColl(block)=0 then + if Blocks.IsSolid(block) = false then begin //create_mob(7, x*16, y*16); decItem(invcur); @@ -1053,7 +1053,7 @@ procedure destroy_block_cr(id, xx, yy:integer); else if item=213 then begin - if getBlockColl(block)=0 then + if Blocks.IsSolid(block) = false then begin //create_mob(8, x*16, y*16); decItem(invcur); @@ -1062,7 +1062,7 @@ procedure destroy_block_cr(id, xx, yy:integer); else if item=212 then begin - if getBlockColl(block)=0 then + if Blocks.IsSolid(block) = false then begin //create_mob(10, x*16, y*16); decItem(invcur); @@ -1404,7 +1404,7 @@ procedure updateBlock(x, y:integer); if getmap(x, y+1)<>120 then setMap(0, x, y); - if (info=0) and (getMap(x-1, y)=0) and (getBlockColl(getMap(x-1, y+1))>0) then + if (info=0) and (getMap(x-1, y)=0) and Blocks.IsSolid(getMap(x-1, y+1)) then setmap(73, x-1, y); if (getMap(x-1, y)=73) and (getMapinfo(x, y)<>9) then @@ -1422,7 +1422,7 @@ procedure updateBlock(x, y:integer); if getmap(x, y+1)<>120 then setMap(0, x, y); - if (info=0) and (getMap(x-1, y)=0) and (getBlockColl(getMap(x-1, y+1))>0) then + if (info=0) and (getMap(x-1, y)=0) and Blocks.IsSolid(getMap(x-1, y+1)) then setmap(66, x-1, y); if (getMap(x-1, y)=66) and (getMapinfo(x, y)<>9) then