scripts restructured; teleswitch now works
[dd2d.git] / data / scripts / api / switch.dacs
blob8d4007ca85c36e2f2c42f7240ccc549eb5e09c7b
1 module apiSwitch;
3 import apiActor;
4 import apiMap;
5 import stdlib;
8 public auto switchTouch (Actor me, Actor other) {
9   if (!me || !other) return false;
11   int x = other.x, y = other.y;
12   int sx = (x-other.radius)/CELW;
13   int sy = (y-other.height+1)/CELH;
14   x = (x+other.radius)/CELW;
15   y /= CELH;
17   int myx = me.x/CELW;
18   int myy = me.y/CELH;
20   return (myx >= sx && myx <= x && myy >= sy && myy <= y /*&& ((sw[i].f&0x8F)&t)*/);
24 public void switchOpenDoor (Actor me) {
25   int a = (me.switchabf>>16)&0xff;
26   int b = (me.switchabf>>8)&0xff;
27   //int j;
28   //swsnd = Z_sound(sndbdo, 128);
29   auto j = mapGetTile(LAYER_FRONT, a, b);
30   //cht = 2;
31   //chto = 3;
32   //chf = 0;
33   //f_ch = 1;
34   processDoor(a, b, TILE_DOORC, TILE_DOORO, 0, 1);
35   mapSetTile(LAYER_FRONT, a, b, j);
39 // `x` and `y` in tiles
40 void processDoor (int x, int y, int cht, int chto, int chf, int f_ch) {
41   if (x < 0 || y < 0 || x >= FLDW || y >= FLDH) return;
42   if (mapGetTypeTile(x, y) != cht) return;
43   int ex = x+1;
44   for (; x && mapGetTypeTile(x-1, y) == cht; --x) {}
45   for (; ex < FLDW && mapGetTypeTile(ex, y) == cht; ++ex) {}
46   for (int mx = x; mx < ex; ++mx) mapSetTypeTile(mx, y, chto); //memset(fldm+y*FLDW+x, chto, ex-x);
47   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);
48   for (; x < ex; ++x) {
49     processDoor(x, y-1, cht, chto, chf, f_ch);
50     processDoor(x, y+1, cht, chto, chf, f_ch);
51   }