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 public int Z_checkerRHHalfEx (int x, int y, int r, int h, int function (int tilefg, int tiletype) ccb) {
32 int sx = max((x-r)/CELW, 0);
33 int sy = max((y-h+1)/CELH, 0);
35 x = min((x+r)/CELW, FLDW-1);
36 y = min((y-h/2)/CELH, FLDH-1);
37 if (sx > x || sy > y) return -1; // counts as true anyway
39 for (int j = sy; j <= y; ++j) {
40 int res = ccb(mapGetTile(LAYER_FRONT, sx, j), mapGetTypeTile(sx, j));
49 // check "under feet" / "above head"
50 public int Z_checkerRHFeetHead (int x, int y, int r, int h, int function (int tiletype) ccb) {
52 int i = max((x-r)/CELW, 0);
53 x = min((x+r)/CELW, FLDW-1);
55 //if (origx >= 160 && origx <= 168 && h > 2) { writeln("Z_checkerRHFeetHead: i=", i, "; x=", x, "; y=", y); }
56 if (y >= FLDH || y < 0) return 0;
58 //if (origx >= 160 && origx <= 168 && h > 2) { writeln(" i=", i, "; y=", y, "; tt=", mapGetTypeTile(i, y)); }
59 int res = ccb(mapGetTypeTile(i, y));
60 //writeln(" Z_checkerRHFeetHead(", i, ", ", y, ") = ", res);
67 // check the whole occupied area
68 public int Z_checkerRHWhole (int x, int y, int r, int h, int dy, int function (int tiletype) ccb) {
69 int sx = max((x-r)/CELW, 0);
70 int sy = max((y-h+1)/CELH, 0);
71 x = min((x+r)/CELW, FLDW-1);
72 y = min((y+dy)/CELH, FLDH-1);
73 if (sx > x || sy > y) return -1; // counts as true anyway
74 for (int i = sx; i <= x; ++i) {
75 for (int j = sy; j <= y; ++j) {
76 int res = ccb(mapGetTypeTile(i, j));
77 //writeln(" Z_checkerRHWhole(", i, ", ", j, ") = ", res);
85 // ////////////////////////////////////////////////////////////////////////// //
86 int Z_canbreatheCCB (int fv) {
98 public int Z_canbreathe (int x, int y, int r, int h) { return (Z_checkerRHHalf(x, y, r, h, &Z_canbreatheCCB) != 0); }
101 // ////////////////////////////////////////////////////////////////////////// //
102 int Z_canstandCCB (int fv) { return (fv == TILE_WALL || fv == TILE_DOORC || fv == TILE_STEP ? 1 : 0); }
104 public int Z_canstand (int x, int y, int r) { return Z_checkerRHFeetHead(x, y, r, 0, &Z_canstandCCB); }
107 // ////////////////////////////////////////////////////////////////////////// //
108 int Z_cangodownCCB (int fv) { return (fv == TILE_STEP ? 1 : 0); }
110 public int Z_cangodown (int x, int y, int r) { return Z_checkerRHFeetHead(x, y, r, 0, &Z_cangodownCCB); }
113 // ////////////////////////////////////////////////////////////////////////// //
114 int Z_hitceilCCB (int fv) {
115 return (getCheatNoDoors ? (fv == TILE_WALL ? 1 : 0) : (fv == TILE_WALL || fv == TILE_DOORC ? 1 : 0));
118 public int Z_hitceil (int x, int y, int r, int h) {
119 //if (x >= 160 && x <= 168) writeln("=== hitceil: x=", x, "; y=", y, "; r=", r, "; h=", h);
120 return Z_checkerRHFeetHead(x, y, r, h+1, &Z_hitceilCCB); // `+1` due to checker specific
124 // ////////////////////////////////////////////////////////////////////////// //
125 int Z_canfitCCB (int fv) { return (fv == TILE_WALL || fv == TILE_DOORC ? 1 : 0); }
127 public int Z_canfit (int x, int y, int r, int h) { return 1-Z_checkerRHWhole(x, y, r, h, 0, &Z_canfitCCB); }
130 // ////////////////////////////////////////////////////////////////////////// //
131 int Z_inliftCCB (int fv) {
132 if (fv == TILE_LIFTU || fv == TILE_LIFTD) return fv-TILE_LIFTU+1;
136 public int Z_inlift (int x, int y, int r, int h) { return Z_checkerRHWhole(x, y, r, h, -1, &Z_inliftCCB); }
139 // ////////////////////////////////////////////////////////////////////////// //
140 int Z_isblockedCCB (int fv) { return (fv == TILE_MBLOCK ? 1 : 0); }
142 public int Z_isblocked (int x, int y, int r, int h, int xv) { return Z_checkerRHWhole(x, y, r, h, -1, &Z_isblockedCCB); }
145 // ////////////////////////////////////////////////////////////////////////// //
146 int Z_istrappedCCB (int fv) { return (fv == TILE_ACTTRAP ? 1 : 0); }
148 public int Z_istrapped (int x, int y, int r, int h) { return Z_checkerRHWhole(x, y, r, h, -1, &Z_istrappedCCB); }
151 // ////////////////////////////////////////////////////////////////////////// //
152 //static uint8_t wfront; // for splash
153 int Z_inwaterCCB (int fv) {
154 //return (fv >= TILE_WATER && fv <= TILE_ACID2 ? 1 : 0); /* wfront = fv;*/
156 case TILE_WATER: return Z_WATER_0;
157 case TILE_ACID1: return Z_WATER_1;
158 case TILE_ACID2: return Z_WATER_2;
164 public int Z_inwater (int x, int y, int r, int h/*, ref int wfront*/) { return Z_checkerRHHalf(x, y, r, h, &Z_inwaterCCB); }
167 int Z_inwaterCCBEx (int fg, int fv) {
168 //return (fv >= TILE_WATER && fv <= TILE_ACID2 ? 1 : 0); /* wfront = fv;*/
171 case TILE_WATER: res = Z_WATER_0; break;
172 case TILE_ACID1: res = Z_WATER_1; break;
173 case TILE_ACID2: res = Z_WATER_2; break;
177 int wt = mapGetWaterTexture(fg);
179 case 1: res |= Z_WATER_T0; break;
180 case 2: res |= Z_WATER_T1; break;
181 case 3: res |= Z_WATER_T2; break;
188 public int Z_inwaterEx (int x, int y, int r, int h/*, ref int wfront*/) { return Z_checkerRHHalfEx(x, y, r, h, &Z_inwaterCCBEx); }
191 // ////////////////////////////////////////////////////////////////////////// //
192 int clamp7 (int v) { return (abs(v) <= 7 ? v : (v > 0 ? 7 : -7)); }
194 int is_monster (Actor me) { return (me.classtype == "monster" && me.classname != "Player"); }
196 //int is_dot (Actor me) { return false; }
197 //int is_ghost_player (Actor me) { return false; }
200 public int Z_dec (int n, int delta) {
201 if (abs(n) > delta) {
202 if (n > 0) return n-delta;
203 if (n < 0) return n+delta;
208 //#define wvel(v) if ((xv = abs(v)+1) > 5) v = Z_dec(v, xv/2-2)
211 public int Z_moveobj (Actor me) {
221 if (/*!is_ghost_player(me)*/1) {
222 switch (Z_inlift(x, y, r, h)) {
224 if (++me.yv > MAX_YV) --me.yv;
227 if (--me.yv < -5) ++me.yv;
230 if (me.yv > 5) --me.yv; else ++me.yv;
236 inw = Z_inwater(x, y, r, h);
237 //writeln("x=", x, "; y=", y, "; r=", r, "; h=", h, "; inw=", inw);
240 if ((xv = abs(me.xv)+1) > 5) me.xv = Z_dec(me.xv, xv/2-2);
241 if ((xv = abs(me.yv)+1) > 5) me.yv = Z_dec(me.yv, xv/2-2);
242 if ((xv = abs(me.vx)+1) > 5) me.vx = Z_dec(me.vx, xv/2-2);
243 if ((xv = abs(me.vy)+1) > 5) me.vy = Z_dec(me.vy, xv/2-2);
246 //writeln(" vx=", me.vx, "; vy=", me.vy);
247 me.vx = Z_dec(me.vx, 1);
248 me.vy = Z_dec(me.vy, 1);
249 //writeln(" vx=", me.vx, "; vy=", me.vy);
251 //writeln(" xv=", me.xv, "; yv=", me.yv);
255 //writeln(" xv=", xv, "; yv=", yv);
258 //writeln(" *xv=", xv, "; yv=", yv);
259 if (x < -100 || x >= FLDW*CELW+100 || y < -100 || y >= FLDH*CELH+100) {
264 //writeln(" x=", x, "; xv=", xv, "; c7(xv)=", clamp7(xv));
269 if (is_monster(me)) {
271 if (Z_isblocked(x, y, r, h, xv)) st |= Z_BLOCK;
274 if (!Z_canfit(/*is_dot(me),*/ x, y, r, h)) {
275 if (/*!is_ghost_player(me)*/1) {
277 if (gm_climb_stairs && is_player(me)) {
278 // check if we can climb upstairs
279 if (yv == 1 && (xv == 1 || xv == -1)) {
280 if (Z_canfit(me.type, x, y-CELH, r, h) && Z_canfit(me.type, x+Z_sign(xv)*(CELW-1), y-CELH, r, h)) {
282 return Z_moveobj(me);
288 else if (xv < 0) x = ((lx-r)&0xFFF8)+r;
289 else x = ((lx+r)&0xFFF8)-r+7;
290 xv = me.xv = me.vx = 0;
295 //writeln(" xv=", xv);
300 // moving up and hit the ceiling
301 if (/*!is_ghost_player(me)*/1) {
302 if (yv < 0 && Z_hitceil(/*me.type,*/ x, y, r, h)) {
303 //writeln("hitceil: x=", x, "; y=", y);
304 y = ((ly-h+1)&0xFFF8)+h-1;
305 //writeln(" newy=", y);
310 if (yv > 0 && Z_canstand(/*me.type,*/ x, y, r)) {
311 y = ((y+1)&0xFFF8)-1;
312 yv = me.yv = me.vy = 0;
317 //writeln(" yv=", yv);
322 //writeln(" x=", x, "; y=", y);
324 int wtr = Z_inwaterEx(x, y, r, h);
327 if (!inw) st |= Z_HITWATER;
337 // ////////////////////////////////////////////////////////////////////////// //
338 public void Z_splash (Actor me, int n, int st) {
339 //Z_sound(bulsnd[0], 128);
340 //DOT_water(p->x, p->y-p->h/2, p->xv+p->vx, p->yv+p->vy, n, /*(int)walp[wfront]*/walp[wfront]->wanim-1);
341 //writeln("Z_splash: n=", n, "; wtx=", (st&(Z_WATER_0|Z_WATER_1|Z_WATER_2)));
343 if (st&Z_WATER_T0) wtt = 0;
344 else if (st&Z_WATER_T1) wtt = 1;
345 else if (st&Z_WATER_T2) wtt = 2;
347 //writeln("Z_splash: n=", n, "; wtt=", wtt);
348 dotAddWater(me.x, me.y-me.height/2, me.xv+me.vx, me.yv+me.vy, n, wtt);