"no doors" cheat
[dd2d.git] / data / scripts / moveapi.dacs
blobb6609fb11f5a3a84ff473acaf851c5c563070d66
1 module moveapi;
3 import actor, mapapi, stdlib;
6 const MAX_YV = 30;
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) {
12   // start tile
13   int sx = max((x-r)/CELW, 0);
14   int sy = max((y-h+1)/CELH, 0);
15   // end tile
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
19   while (sx <= x) {
20     for (int j = sy; j <= y; ++j) {
21       int res = ccb(mapGetTypeTile(sx, j));
22       if (res) return res;
23     }
24     ++sx;
25   }
26   return 0;
30 // check "under feet" / "above head"
31 public int Z_checkerRHFeetHead (int x, int y, int r, int h, int function (int tiletype) ccb) {
32   //int origx = x;
33   int i = max((x-r)/CELW, 0);
34   x = min((x+r)/CELW, FLDW-1);
35   y = (y-h+1)/CELH;
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;
38   for (; i <= x; ++i) {
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);
42     if (res) return res;
43   }
44   return 0;
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);
59       if (res) return res;
60     }
61   }
62   return 0;
66 // ////////////////////////////////////////////////////////////////////////// //
67 int Z_canbreatheCCB (int fv) {
68   switch (fv) {
69     case TILE_EMPTY:
70     case TILE_DOORO:
71     case TILE_LIFTU:
72     case TILE_LIFTD:
73       return 1;
74     default:
75   }
76   return 0;
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;
114   return 0;
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;
152   }
153   return 0;
156 //#define wvel(v) if ((xv = abs(v)+1) > 5) v = Z_dec(v, xv/2-2)
159 public int Z_moveobj (Actor me) {
160   int xv, yv, lx, ly;
161   int/*uint8_t*/ inw;
163   int st = 0;
164   int x = me.x;
165   int y = me.y;
166   int r = me.radius;
167   int h = me.height;
169   if (/*!is_ghost_player(me)*/1) {
170     switch (Z_inlift(x, y, r, h)) {
171       case 0:
172         if (++me.yv > MAX_YV) --me.yv;
173         break;
174       case 1:
175         if (--me.yv < -5) ++me.yv;
176         break;
177       case 2:
178         if (me.yv > 5) --me.yv; else ++me.yv;
179         break;
180       default:
181     }
182   }
184   inw = Z_inwater(x, y, r, h);
185   //writeln("x=", x, "; y=", y, "; r=", r, "; h=", h, "; inw=", inw);
186   if (inw != 0) {
187     st |= Z_INWATER;
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);
192   }
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);
201   xv = me.xv+me.vx;
202   yv = me.yv+me.vy;
203   //writeln("  xv=", xv, "; yv=", yv);
205   while (xv || yv) {
206     //writeln("  *xv=", xv, "; yv=", yv);
207     if (x < -100 || x >= FLDW*CELW+100 || y < -100 || y >= FLDH*CELH+100) {
208       // out of map
209       st |= Z_FALLOUT;
210     }
212     //writeln("  x=", x, "; xv=", xv, "; c7(xv)=", clamp7(xv));
213     lx = x;
214     x += clamp7(xv);
215     //writeln("  x=", x);
217     if (is_monster(me)) {
218       // for monster
219       if (Z_isblocked(x, y, r, h, xv)) st |= Z_BLOCK;
220     }
222     if (!Z_canfit(/*is_dot(me),*/ x, y, r, h)) {
223       if (/*!is_ghost_player(me)*/1) {
224         /*
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)) {
229               me.vy = -8;
230               return Z_moveobj(me);
231             }
232           }
233         }
234         */
235         if (xv == 0) x = lx;
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;
239         st |= Z_HITWALL;
240       }
241     }
242     xv -= clamp7(xv);
243     //writeln("  xv=", xv);
245     ly = y;
246     y += clamp7(yv);
247     if (yv >= 8) --y;
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);
254         yv = me.vy = 1;
255         me.yv = 0;
256         st |= Z_HITCEIL;
257       }
258       if (yv > 0 && Z_canstand(/*me.type,*/ x, y, r)) {
259         y = ((y+1)&0xFFF8)-1;
260         yv = me.yv = me.vy = 0;
261         st |= Z_HITLAND;
262       }
263     }
264     yv -= clamp7(yv);
265     //writeln("  yv=", yv);
266   }
268   me.x = x;
269   me.y = y;
270   //writeln("  x=", x, "; y=", y);
272   if (Z_inwater(x, y, r, h)) {
273     st |= Z_INWATER;
274     if (!inw) st |= Z_HITWATER;
275   } else if (inw) {
276     st |= Z_HITAIR;
277   }
279   return st;