3 import actor, mapapi, stdlib;
9 // ////////////////////////////////////////////////////////////////////////// //
10 /// check area, half of height
11 public int Z_checkerRHHalf (int x, int y, int r, int h, int function (int tiletype) ccb) {
13 int sx = max((x-r)/CELW, 0);
14 int sy = max((y-h+1)/CELH, 0);
16 x = min((x+r)/CELW, FLDW-1);
17 y = min((y-h/2)/CELH, FLDH-1);
18 if (sx > x || sy > y) return -1; // counts as true anyway
20 for (int j = sy; j <= y; ++j) {
21 int res = ccb(mapGetTypeTile(sx, j));
30 // check "under feet" / "above head"
31 public int Z_checkerRHFeetHead (int x, int y, int r, int h, int function (int tiletype) ccb) {
33 int i = max((x-r)/CELW, 0);
34 x = min((x+r)/CELW, FLDW-1);
36 //if (origx >= 160 && origx <= 168 && h > 2) { writeln("Z_checkerRHFeetHead: i=", i, "; x=", x, "; y=", y); }
37 if (y >= FLDH || y < 0) return 0;
39 //if (origx >= 160 && origx <= 168 && h > 2) { writeln(" i=", i, "; y=", y, "; tt=", mapGetTypeTile(i, y)); }
40 int res = ccb(mapGetTypeTile(i, y));
41 //writeln(" Z_checkerRHFeetHead(", i, ", ", y, ") = ", res);
48 // check the whole occupied area
49 public int Z_checkerRHWhole (int x, int y, int r, int h, int dy, int function (int tiletype) ccb) {
50 int sx = max((x-r)/CELW, 0);
51 int sy = max((y-h+1)/CELH, 0);
52 x = min((x+r)/CELW, FLDW-1);
53 y = min((y+dy)/CELH, FLDH-1);
54 if (sx > x || sy > y) return -1; // counts as true anyway
55 for (int i = sx; i <= x; ++i) {
56 for (int j = sy; j <= y; ++j) {
57 int res = ccb(mapGetTypeTile(i, j));
58 //writeln(" Z_checkerRHWhole(", i, ", ", j, ") = ", res);
66 // ////////////////////////////////////////////////////////////////////////// //
67 int Z_canbreatheCCB (int fv) {
79 public int Z_canbreathe (int x, int y, int r, int h) { return (Z_checkerRHHalf(x, y, r, h, &Z_canbreatheCCB) != 0); }
82 // ////////////////////////////////////////////////////////////////////////// //
83 int Z_canstandCCB (int fv) { return (fv == TILE_WALL || fv == TILE_DOORC || fv == TILE_STEP ? 1 : 0); }
85 public int Z_canstand (int x, int y, int r) { return Z_checkerRHFeetHead(x, y, r, 0, &Z_canstandCCB); }
88 // ////////////////////////////////////////////////////////////////////////// //
89 int Z_cangodownCCB (int fv) { return (fv == TILE_STEP ? 1 : 0); }
91 public int Z_cangodown (int x, int y, int r) { return Z_checkerRHFeetHead(x, y, r, 0, &Z_cangodownCCB); }
94 // ////////////////////////////////////////////////////////////////////////// //
95 int Z_hitceilCCB (int fv) {
96 return (getCheatNoDoors ? (fv == TILE_WALL ? 1 : 0) : (fv == TILE_WALL || fv == TILE_DOORC ? 1 : 0));
99 public int Z_hitceil (int x, int y, int r, int h) {
100 //if (x >= 160 && x <= 168) writeln("=== hitceil: x=", x, "; y=", y, "; r=", r, "; h=", h);
101 return Z_checkerRHFeetHead(x, y, r, h+1, &Z_hitceilCCB); // `+1` due to checker specific
105 // ////////////////////////////////////////////////////////////////////////// //
106 int Z_canfitCCB (int fv) { return (fv == TILE_WALL || fv == TILE_DOORC ? 1 : 0); }
108 public int Z_canfit (int x, int y, int r, int h) { return 1-Z_checkerRHWhole(x, y, r, h, 0, &Z_canfitCCB); }
111 // ////////////////////////////////////////////////////////////////////////// //
112 int Z_inliftCCB (int fv) {
113 if (fv == TILE_LIFTU || fv == TILE_LIFTD) return fv-TILE_LIFTU+1;
117 public int Z_inlift (int x, int y, int r, int h) { return Z_checkerRHWhole(x, y, r, h, -1, &Z_inliftCCB); }
120 // ////////////////////////////////////////////////////////////////////////// //
121 int Z_isblockedCCB (int fv) { return (fv == TILE_MBLOCK ? 1 : 0); }
123 public int Z_isblocked (int x, int y, int r, int h, int xv) { return Z_checkerRHWhole(x, y, r, h, -1, &Z_isblockedCCB); }
126 // ////////////////////////////////////////////////////////////////////////// //
127 int Z_istrappedCCB (int fv) { return (fv == TILE_ACTTRAP ? 1 : 0); }
129 public int Z_istrapped (int x, int y, int r, int h) { return Z_checkerRHWhole(x, y, r, h, -1, &Z_istrappedCCB); }
132 // ////////////////////////////////////////////////////////////////////////// //
133 //static uint8_t wfront; // for splash
134 int Z_inwaterCCB (int fv) { return (fv >= TILE_WATER && fv <= TILE_ACID2 ? 1 : 0); /* wfront = fv;*/ }
136 public int Z_inwater (int x, int y, int r, int h/*, ref int wfront*/) { return (Z_checkerRHHalf(x, y, r, h, &Z_inwaterCCB) > 0); }
139 // ////////////////////////////////////////////////////////////////////////// //
140 int clamp7 (int v) { return (abs(v) <= 7 ? v : (v > 0 ? 7 : -7)); }
142 int is_monster (Actor me) { return (me.classtype == "monster" && me.classname != "Player"); }
144 //int is_dot (Actor me) { return false; }
145 //int is_ghost_player (Actor me) { return false; }
148 public int Z_dec (int n, int delta) {
149 if (abs(n) > delta) {
150 if (n > 0) return n-delta;
151 if (n < 0) return n+delta;
156 //#define wvel(v) if ((xv = abs(v)+1) > 5) v = Z_dec(v, xv/2-2)
159 public int Z_moveobj (Actor me) {
169 if (/*!is_ghost_player(me)*/1) {
170 switch (Z_inlift(x, y, r, h)) {
172 if (++me.yv > MAX_YV) --me.yv;
175 if (--me.yv < -5) ++me.yv;
178 if (me.yv > 5) --me.yv; else ++me.yv;
184 inw = Z_inwater(x, y, r, h);
185 //writeln("x=", x, "; y=", y, "; r=", r, "; h=", h, "; inw=", inw);
188 if ((xv = abs(me.xv)+1) > 5) me.xv = Z_dec(me.xv, xv/2-2);
189 if ((xv = abs(me.yv)+1) > 5) me.yv = Z_dec(me.yv, xv/2-2);
190 if ((xv = abs(me.vx)+1) > 5) me.vx = Z_dec(me.vx, xv/2-2);
191 if ((xv = abs(me.vy)+1) > 5) me.vy = Z_dec(me.vy, xv/2-2);
194 //writeln(" vx=", me.vx, "; vy=", me.vy);
195 me.vx = Z_dec(me.vx, 1);
196 me.vy = Z_dec(me.vy, 1);
197 //writeln(" vx=", me.vx, "; vy=", me.vy);
199 //writeln(" xv=", me.xv, "; yv=", me.yv);
203 //writeln(" xv=", xv, "; yv=", yv);
206 //writeln(" *xv=", xv, "; yv=", yv);
207 if (x < -100 || x >= FLDW*CELW+100 || y < -100 || y >= FLDH*CELH+100) {
212 //writeln(" x=", x, "; xv=", xv, "; c7(xv)=", clamp7(xv));
217 if (is_monster(me)) {
219 if (Z_isblocked(x, y, r, h, xv)) st |= Z_BLOCK;
222 if (!Z_canfit(/*is_dot(me),*/ x, y, r, h)) {
223 if (/*!is_ghost_player(me)*/1) {
225 if (gm_climb_stairs && is_player(me)) {
226 // check if we can climb upstairs
227 if (yv == 1 && (xv == 1 || xv == -1)) {
228 if (Z_canfit(me.type, x, y-CELH, r, h) && Z_canfit(me.type, x+Z_sign(xv)*(CELW-1), y-CELH, r, h)) {
230 return Z_moveobj(me);
236 else if (xv < 0) x = ((lx-r)&0xFFF8)+r;
237 else x = ((lx+r)&0xFFF8)-r+7;
238 xv = me.xv = me.vx = 0;
243 //writeln(" xv=", xv);
248 // moving up and hit the ceiling
249 if (/*!is_ghost_player(me)*/1) {
250 if (yv < 0 && Z_hitceil(/*me.type,*/ x, y, r, h)) {
251 //writeln("hitceil: x=", x, "; y=", y);
252 y = ((ly-h+1)&0xFFF8)+h-1;
253 //writeln(" newy=", y);
258 if (yv > 0 && Z_canstand(/*me.type,*/ x, y, r)) {
259 y = ((y+1)&0xFFF8)-1;
260 yv = me.yv = me.vy = 0;
265 //writeln(" yv=", yv);
270 //writeln(" x=", x, "; y=", y);
272 if (Z_inwater(x, y, r, h)) {
274 if (!inw) st |= Z_HITWATER;