From 2cd71387a4000a3d797b2fd20f2193af3d3e153b Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Sat, 2 Apr 2016 01:52:13 +0300 Subject: [PATCH] more constants --- data/scripts/api/map.dacs | 9 +++++---- data/scripts/api/move.dacs | 36 ++++++++++++++++++------------------ data/scripts/api/switch.dacs | 20 ++++++++++---------- data/scripts/d2dplayer.dacs | 4 ++-- data/scripts/maps/map01.dacs | 3 ++- data/scripts/switch/teleport.dacs | 4 ++-- dengapi.d | 3 +++ 7 files changed, 42 insertions(+), 37 deletions(-) diff --git a/data/scripts/api/map.dacs b/data/scripts/api/map.dacs index 6154da9..1446bb3 100644 --- a/data/scripts/api/map.dacs +++ b/data/scripts/api/map.dacs @@ -18,10 +18,11 @@ module apiMap; //FIXME: change to functions -public const FLDW = 100; -public const FLDH = 100; -public const CELW = 8; -public const CELH = 8; +//public const FLDW = 100; +//public const FLDH = 100; +public const TileSize = 8; +public extern int MapWidth () pure; +public extern int MapHeight () pure; // vanilla tile types diff --git a/data/scripts/api/move.dacs b/data/scripts/api/move.dacs index ef79fe0..3372abb 100644 --- a/data/scripts/api/move.dacs +++ b/data/scripts/api/move.dacs @@ -28,11 +28,11 @@ const MAX_YV = 30; /// check area, half of height public int Z_checkerRHHalf (int x, int y, int r, int h, int function (int tiletype) ccb) { // start tile - int sx = max((x-r)/CELW, 0); - int sy = max((y-h+1)/CELH, 0); + int sx = max((x-r)/TileSize, 0); + int sy = max((y-h+1)/TileSize, 0); // end tile - x = min((x+r)/CELW, FLDW-1); - y = min((y-h/2)/CELH, FLDH-1); + x = min((x+r)/TileSize, MapWidth-1); + y = min((y-h/2)/TileSize, MapHeight-1); if (sx > x || sy > y) return -1; // counts as true anyway while (sx <= x) { for (int j = sy; j <= y; ++j) { @@ -47,11 +47,11 @@ public int Z_checkerRHHalf (int x, int y, int r, int h, int function (int tilety public int Z_checkerRHHalfEx (int x, int y, int r, int h, int function (int tilefg, int tiletype) ccb) { // start tile - int sx = max((x-r)/CELW, 0); - int sy = max((y-h+1)/CELH, 0); + int sx = max((x-r)/TileSize, 0); + int sy = max((y-h+1)/TileSize, 0); // end tile - x = min((x+r)/CELW, FLDW-1); - y = min((y-h/2)/CELH, FLDH-1); + x = min((x+r)/TileSize, MapWidth-1); + y = min((y-h/2)/TileSize, MapHeight-1); if (sx > x || sy > y) return -1; // counts as true anyway while (sx <= x) { for (int j = sy; j <= y; ++j) { @@ -67,11 +67,11 @@ public int Z_checkerRHHalfEx (int x, int y, int r, int h, int function (int tile // check "under feet" / "above head" public int Z_checkerRHFeetHead (int x, int y, int r, int h, int function (int tiletype) ccb) { //int origx = x; - int i = max((x-r)/CELW, 0); - x = min((x+r)/CELW, FLDW-1); - y = (y-h+1)/CELH; + int i = max((x-r)/TileSize, 0); + x = min((x+r)/TileSize, MapWidth-1); + y = (y-h+1)/TileSize; //if (origx >= 160 && origx <= 168 && h > 2) { writeln("Z_checkerRHFeetHead: i=", i, "; x=", x, "; y=", y); } - if (y >= FLDH || y < 0) return 0; + if (y >= MapHeight || y < 0) return 0; for (; i <= x; ++i) { //if (origx >= 160 && origx <= 168 && h > 2) { writeln(" i=", i, "; y=", y, "; tt=", mapGetTypeTile(i, y)); } int res = ccb(mapGetTypeTile(i, y)); @@ -84,10 +84,10 @@ public int Z_checkerRHFeetHead (int x, int y, int r, int h, int function (int ti // check the whole occupied area public int Z_checkerRHWhole (int x, int y, int r, int h, int dy, int function (int tiletype) ccb) { - int sx = max((x-r)/CELW, 0); - int sy = max((y-h+1)/CELH, 0); - x = min((x+r)/CELW, FLDW-1); - y = min((y+dy)/CELH, FLDH-1); + int sx = max((x-r)/TileSize, 0); + int sy = max((y-h+1)/TileSize, 0); + x = min((x+r)/TileSize, MapWidth-1); + y = min((y+dy)/TileSize, MapHeight-1); if (sx > x || sy > y) return -1; // counts as true anyway for (int i = sx; i <= x; ++i) { for (int j = sy; j <= y; ++j) { @@ -278,7 +278,7 @@ public int Z_moveobj (Actor me) { while (xv || yv) { //writeln(" *xv=", xv, "; yv=", yv); - if (x < -100 || x >= FLDW*CELW+100 || y < -100 || y >= FLDH*CELH+100) { + if (x < -100 || x >= MapWidth*TileSize+100 || y < -100 || y >= MapHeight*TileSize+100) { // out of map st |= Z_FALLOUT; } @@ -299,7 +299,7 @@ public int Z_moveobj (Actor me) { if (gm_climb_stairs && is_player(me)) { // check if we can climb upstairs if (yv == 1 && (xv == 1 || xv == -1)) { - if (Z_canfit(me.type, x, y-CELH, r, h) && Z_canfit(me.type, x+Z_sign(xv)*(CELW-1), y-CELH, r, h)) { + if (Z_canfit(me.type, x, y-TileSize, r, h) && Z_canfit(me.type, x+Z_sign(xv)*(TileSize-1), y-TileSize, r, h)) { me.vy = -8; return Z_moveobj(me); } diff --git a/data/scripts/api/switch.dacs b/data/scripts/api/switch.dacs index 589a22f..9602b44 100644 --- a/data/scripts/api/switch.dacs +++ b/data/scripts/api/switch.dacs @@ -44,13 +44,13 @@ public auto switchTouch (Actor me, Actor other, int pressed) { if (me.dead || other.dead) return false; int x = other.x, y = other.y; - int sx = (x-other.radius)/CELW; - int sy = (y-other.height+1)/CELH; - x = (x+other.radius)/CELW; - y /= CELH; + int sx = (x-other.radius)/TileSize; + int sy = (y-other.height+1)/TileSize; + x = (x+other.radius)/TileSize; + y /= TileSize; - int myx = me.x/CELW; - int myy = me.y/CELH; + int myx = me.x/TileSize; + int myy = me.y/TileSize; if (other.classname == "DummyPressActor") writeln("sx=", sx, "; sy=", sy, "; x=", x, "; y=", y, "; myx=", myx, "; myy=", myy); @@ -199,13 +199,13 @@ public void switchLift (Actor me, int type/*SW_LIFT_XXX*/) { // `x` and `y` in tiles void processDoor (int x, int y, int cht, int chto, int chf, int f_ch) { - if (x < 0 || y < 0 || x >= FLDW || y >= FLDH) return; + if (x < 0 || y < 0 || x >= MapWidth || y >= MapHeight) return; if (mapGetTypeTile(x, y) != cht) return; int ex = x+1; for (; x && mapGetTypeTile(x-1, y) == cht; --x) {} - for (; ex < FLDW && mapGetTypeTile(ex, y) == cht; ++ex) {} - for (int mx = x; mx < ex; ++mx) mapSetTypeTile(mx, y, chto); //memset(fldm+y*FLDW+x, chto, ex-x); - if (f_ch) for (int mx = x; mx < ex; ++mx) mapSetTile(LAYER_FRONT, mx, y, chf); //if (f_ch) memset(fldf+y*FLDW+x, chf, ex-x); + for (; ex < MapWidth && mapGetTypeTile(ex, y) == cht; ++ex) {} + for (int mx = x; mx < ex; ++mx) mapSetTypeTile(mx, y, chto); //memset(fldm+y*MapWidth+x, chto, ex-x); + if (f_ch) for (int mx = x; mx < ex; ++mx) mapSetTile(LAYER_FRONT, mx, y, chf); //if (f_ch) memset(fldf+y*MapWidth+x, chf, ex-x); for (; x < ex; ++x) { processDoor(x, y-1, cht, chto, chf, f_ch); processDoor(x, y+1, cht, chto, chf, f_ch); diff --git a/data/scripts/d2dplayer.dacs b/data/scripts/d2dplayer.dacs index 4d746fc..34d7f83 100644 --- a/data/scripts/d2dplayer.dacs +++ b/data/scripts/d2dplayer.dacs @@ -279,7 +279,7 @@ public void think (Actor me) { //monsterThink(me); //writeln("canstand: ", Z_canstand(me.x, me.y, me.radius)); //writeln("cangodown: ", Z_cangodown(me.x, me.y, me.radius)); - //if (((st = Z_moveobj(&me.o))&Z_FALLOUT) && me.y >= FLDH*CELH+50) { + //if (((st = Z_moveobj(&me.o))&Z_FALLOUT) && me.y >= MapHeight*TileSize+50) { //int st = Z_moveobj(me); dumpSt(st); writeln(st); PL_act(me); // fix level view @@ -382,7 +382,7 @@ void PL_act (Actor me) { st = Z_moveobj(me); //writeln("st=", st); //dumpSt(st); - if ((st&Z_FALLOUT) && me.y >= FLDH*CELH+50) { + if ((st&Z_FALLOUT) && me.y >= MapHeight*TileSize+50) { writeln(" FALLING!"); switch (me.plrstate) { case PLST_DEAD: diff --git a/data/scripts/maps/map01.dacs b/data/scripts/maps/map01.dacs index f8d5d1c..40e6034 100644 --- a/data/scripts/maps/map01.dacs +++ b/data/scripts/maps/map01.dacs @@ -18,6 +18,7 @@ module mapsMap01 is "map" "map01"; import apiActor; +import apiMap; import miscLevellight; import miscAmbientlight; import stdlib; @@ -42,7 +43,7 @@ void putStaticLights () { miscLevellight.spawn(280, 330, 255, 64); // red light - miscLevellight.spawn(24*8+4, (24+18)*8-2+LYOfs, 150, 0, 0, 128); + miscLevellight.spawn(24*TileSize+4, (24+18)*TileSize-2+TileSize, 150, 0, 0, 128); //miscAmbientlight.spawn(10, 10, 550, 150, 255); //miscAmbientlight.spawn(10, 10, 550, 350, 128, 0, 0); diff --git a/data/scripts/switch/teleport.dacs b/data/scripts/switch/teleport.dacs index f97e5f7..b02066d 100644 --- a/data/scripts/switch/teleport.dacs +++ b/data/scripts/switch/teleport.dacs @@ -32,8 +32,8 @@ public void initialize (Actor me) { void action (Actor me) { auto toucher = me.switchWhoTouched(); if (toucher) { - int x = me.switchGetA*8+4; - int y = me.switchGetB*8+7; + int x = me.switchGetA*TileSize+4; + int y = me.switchGetB*TileSize+7; me.atm = 1; // cooldown time if (!Z_canfit(x, y, toucher.radius, toucher.height)) { //if (!swsnd) swsnd = Z_sound(sndnotele, 128); diff --git a/dengapi.d b/dengapi.d index 2cd4c48..3ef4178 100644 --- a/dengapi.d +++ b/dengapi.d @@ -540,6 +540,9 @@ void setupDAPI () { cameraChick = act; return res; }; + + FuncPool["MapWidth"] = function int () { return (map !is null ? map.width : 1); }; + FuncPool["MapHeight"] = function int () { return (map !is null ? map.height : 1); }; } -- 2.11.4.GIT