From c4c492a2d88cb48a50cd23fe86365f996d9885d5 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Tue, 29 Mar 2016 19:14:13 +0300 Subject: [PATCH] more switches --- d2dmap.d | 3 +++ d2dparts.d | 2 ++ data/scripts/api/actor.dacs | 2 +- data/scripts/api/switch.dacs | 14 ++++++++++-- data/scripts/d2dplayer.dacs | 10 +++++++- data/scripts/d2dswitches.dacs | 2 +- data/scripts/switch/dummypressactor.dacs | 22 ++++++++++++------ data/scripts/switch/press.dacs | 39 ++++++++++++++++++++++++++++++++ dengapi.d | 30 +++++++++++++++++++----- 9 files changed, 106 insertions(+), 18 deletions(-) create mode 100644 data/scripts/switch/press.dacs diff --git a/d2dmap.d b/d2dmap.d index 1f38ffa..c533fab 100644 --- a/d2dmap.d +++ b/d2dmap.d @@ -339,6 +339,7 @@ public: private: void calcMapSize () { + /* bool isEmpty(string dir) (int x, int y) if (dir == "col" || dir == "row") { while (x < MapSize && y < MapSize) { if (tiles[0][y*MapSize+x] || tiles[1][y*MapSize+x] || tiles[2][y*MapSize+x]) return false; @@ -351,6 +352,8 @@ private: while (width > 0 && isEmpty!"col"(width-1, 0)) --width; // fix height while (height > 0 && isEmpty!"row"(0, height-1)) --height; + */ + width = height = MapSize; } void load (string fname) { diff --git a/d2dparts.d b/d2dparts.d index 71f4380..28465c6 100644 --- a/d2dparts.d +++ b/d2dparts.d @@ -317,8 +317,10 @@ bool Z_checkAreaFit (int x, int y, scope int delegate (ubyte tt) dg) { int tx = x/8; int ty = y/8; auto fgt = map.tiles.ptr[LevelMap.Front].ptr[ty*map.width+tx]; + if (fgt >= map.walltypes.length) return false; if (map.walltypes[fgt]) return true; auto bgt = map.tiles.ptr[LevelMap.Back].ptr[ty*map.width+tx]; + if (bgt >= map.walltypes.length) return false; if (map.walltypes[bgt]&0x02) return true; } return false; diff --git a/data/scripts/api/actor.dacs b/data/scripts/api/actor.dacs index 625d470..cac40ba 100644 --- a/data/scripts/api/actor.dacs +++ b/data/scripts/api/actor.dacs @@ -164,7 +164,7 @@ public extern void actorSetAnimation (Actor me, string state); // note that spawned actor will not "think" in this turn public extern Actor actorSpawn (string classtype, string classname, int x, int y, uint dir); // flags: SWITCH_* -public extern Actor actorSpawnVanillaSwitch (string classname, int x, int y, uint flags, int tilex, int tiley); +//public extern Actor actorSpawnVanillaSwitch (string classname, int x, int y, uint flags, int tilex, int tiley); public extern int getPlayerCount () pure; diff --git a/data/scripts/api/switch.dacs b/data/scripts/api/switch.dacs index 49f35a5..a21021e 100644 --- a/data/scripts/api/switch.dacs +++ b/data/scripts/api/switch.dacs @@ -35,8 +35,13 @@ public auto switchTouch (Actor me, Actor other, int pressed) { int myx = me.x/CELW; int myy = me.y/CELH; + if (other.classname == "DummyPressActor") writeln("sx=", sx, "; sy=", sy, "; x=", x, "; y=", y, "; myx=", myx, "; myy=", myy); + if (myx >= sx && myx <= x && myy >= sy && myy <= y) { - if (me.classname == "DummyPressActor") return true; + if (other.classname == "DummyPressActor") { + if (other.atm == 1) writeln("*** PRESSACTOR ACTIVATED SWITCH ***"); + return (other.atm == 1); + } auto sflags = me.switchGetFlags(); //if (other.isPlayer) writeln("isPlayer:", other.isPlayer, "; PLP:", (sflags&SW_PL_PRESS), "; PLN:", (sflags&SW_MN_NEAR)); if (pressed) { @@ -59,12 +64,17 @@ public Actor switchWhoTouched (Actor me) { //writeln("switch touch: '", other.classtype, ":", other.classname, "'"); if (other.dead) continue; if (!other.isPlayer && !other.isMonster && other.classname != "DummyPressActor") continue; + if (other.classname == "DummyPressActor") writeln("DUMMYACTOR CHECK"); int press = 0; if (other.isPlayer) { auto btn = getPlayerButtons(other.plrnum); press = ((btn&PLK_USE) != 0); } - if (!me.switchTouch(other, press)) continue; + if (!me.switchTouch(other, press)) { + if (other.classname == "DummyPressActor") writeln("DUMMYACTOR FUCK"); + continue; + } + if (other.classname == "DummyPressActor") writeln("DUMMYACTOR OK"); //writeln(" switch: real touch"); // check keys auto sflags = me.switchGetFlags(); diff --git a/data/scripts/d2dplayer.dacs b/data/scripts/d2dplayer.dacs index 09c80de..5505747 100644 --- a/data/scripts/d2dplayer.dacs +++ b/data/scripts/d2dplayer.dacs @@ -265,13 +265,21 @@ public void think (Actor me) { //int st = Z_moveobj(me); dumpSt(st); writeln(st); PL_act(me); // fix level view - if (me.plrnum == 1) { + /*if (me.plrnum == 1)*/ { int tiltHeight = getMapViewHeight()/4; int vy = me.looky; if (vy < -tiltHeight) vy = -tiltHeight; else if (vy > tiltHeight) vy = tiltHeight; me.looky = vy; setMapViewPos(me.x, me.y+vy); } + if (me.atm > 0) --me.atm; + if (getPlayerButtons(me.plrnum)&PLK_FIRE) { + if (me.atm <= 0) { + me.atm = 4; + me.target = actorSpawn("switch", "DummyPressActor", me.x, me.y-12, ACTOR_DIR_LEFT); + me.target.atm = 2; // 1: act; 0: die + } + } } diff --git a/data/scripts/d2dswitches.dacs b/data/scripts/d2dswitches.dacs index 27ee0ee..21dd337 100644 --- a/data/scripts/d2dswitches.dacs +++ b/data/scripts/d2dswitches.dacs @@ -7,7 +7,7 @@ import switchDoorclose; // SW_SHUTDOOR import switchTrapclose; // SW_SHUTTRAP import switchDoor; // SW_DOOR import switchDoor5; // SW_DOOR5 -//import switchPress; // SW_PRESS +import switchPress; // SW_PRESS import switchTeleport; // SW_TELE //import switchSecret; // SW_SECRET import switchLiftup; // SW_LIFTUP diff --git a/data/scripts/switch/dummypressactor.dacs b/data/scripts/switch/dummypressactor.dacs index 4367ca7..39a305f 100644 --- a/data/scripts/switch/dummypressactor.dacs +++ b/data/scripts/switch/dummypressactor.dacs @@ -9,17 +9,25 @@ import stdlib; // setup actor properties public void initialize (Actor me) { -} - - -void action (Actor me) { - auto toucher = me.switchWhoTouched(); - if (toucher) me.switchToggleDoor; + me.radius = 8; + me.height = 16; + me.flags = /*AF_NOCOLLISION|*/AF_NOGRAVITY|/*AF_NOONTOUCH|*/AF_NODRAW|/*AF_NOLIGHT|*/AF_NOANIMATE; + // add attached light + me.attLightXOfs = 0; + me.attLightYOfs = -8; + me.attachedLightRGBX(255, 0, 255, 124); + writeln("*** PRESSACTOR SPAWNED *** x=", me.x, "; y=", me.y); } // thinker public void think (Actor me) { - if (me.atm <= 0) { me.actorMarkDead; return; } --me.atm; + if (me.atm <= 0) { + if (me.atm == 0) writeln("*** PRESSACTOR DIED ***"); + me.actorMarkDead; + return; + } else { + writeln("PRESSACTOR: atm=", me.atm); + } } diff --git a/data/scripts/switch/press.dacs b/data/scripts/switch/press.dacs new file mode 100644 index 0000000..b4f7015 --- /dev/null +++ b/data/scripts/switch/press.dacs @@ -0,0 +1,39 @@ +module switchPress is "switch" "Press"; + +import apiActor; +import apiMap; +import apiSwitch; +import stdlib; + + +// setup actor properties +public void initialize (Actor me) { + //me.flags = /*AF_NOCOLLISION|*/AF_NOGRAVITY|/*AF_NOONTOUCH|*/AF_NODRAW|/*AF_NOLIGHT|*/AF_NOANIMATE; + me.flags &= ~AF_NOLIGHT; + // add attached light + me.attLightXOfs = 0; + me.attLightYOfs = -8; + me.attachedLightRGBX(0, 0, 255, 124); + writeln("*** PRESS SWITCH ***"); +} + + +void action (Actor me) { + auto toucher = me.switchWhoTouched(); + if (toucher) { + me.atm = 9; // cooldown time + if (me.target.dead) { + int a = me.switchGetA(); + int b = me.switchGetB(); + me.target = actorSpawn("switch", "DummyPressActor", a*8+4, b*8+12, ACTOR_DIR_LEFT); + me.target.atm = 2; // 1: act; 0: die + me.target.invitems = toucher.invitems; // so keys will work + } + } +} + + +// thinker +public void think (Actor me) { + me.switchThink(&action); +} diff --git a/dengapi.d b/dengapi.d index 6b1f7c0..62b81ad 100644 --- a/dengapi.d +++ b/dengapi.d @@ -438,7 +438,7 @@ void setupDAPI () { FuncPool["actorRemove"] = function void (ActorId me) { if (me.valid) { - if ((me.flags!uint&AF_NOCOLLISION) == 0) ugActorModify!false(me); // remove from grid + if ((me.fget_flags&AF_NOCOLLISION) == 0) ugActorModify!false(me); // remove from grid Actor.remove(me); } }; @@ -478,6 +478,8 @@ void setupDAPI () { nextmapname = nmname; } }; + + FuncPool["actorSpawn"] = &actorSpawn; } @@ -545,6 +547,22 @@ public void loadAllMonsterGraphics () { } +ActorId actorSpawn (StrId classtype, StrId classname, int x, int y, uint dir) { + auto adef = findActorDef(classtype, classname); + if (adef is null) return ActorId(0); + auto aid = Actor.alloc; + aid.classtype = classtype; + aid.classname = classname; + aid.state = StrPool.MNST_SLEEP; + aid.x = x; + aid.y = y; + aid.dir = (dir ? 1 : 0); + adef.callInit(aid); + if ((aid.fget_flags&AF_NOCOLLISION) == 0) ugActorModify!true(aid); + return aid; +} + + public void loadMapMonsters () { assert(map !is null); ugClear(); @@ -565,11 +583,11 @@ public void loadMapMonsters () { aid.x = cast(int)thing.x; aid.y = cast(int)thing.y; aid.dir = cast(uint)(thing.right ? 1 : 0); - if (pnum == 0) aid.flags = aid.flags!uint|AF_CAMERACHICK; + if (pnum == 0) aid.flags = aid.fget_flags|AF_CAMERACHICK; auto adef = findD2DActorDef(thing.type); if (adef is null) assert(0); adef.callInit(aid); - if ((aid.flags!uint&AF_NOCOLLISION) == 0) ugActorModify!true(aid); + if ((aid.fget_flags&AF_NOCOLLISION) == 0) ugActorModify!true(aid); players[pnum] = aid; conwriteln("player #", pnum+1, " aid is ", aid.id); } @@ -603,10 +621,10 @@ public void loadMapMonsters () { aid.x = cast(int)thing.x; aid.y = cast(int)thing.y; aid.dir = cast(uint)(thing.right ? 1 : 0); - if (thing.type&0x8000) aid.flags = aid.flags!uint|AF_NOGRAVITY; + if (thing.type&0x8000) aid.flags = aid.fget_flags|AF_NOGRAVITY; //if (aid.classtype!string == "item" && aid.x!int < 64) { aid.x = 92; aid.y = aid.y!int-16; conwriteln("!!!"); } adef.callInit(aid); - if ((aid.flags!uint&AF_NOCOLLISION) == 0) ugActorModify!true(aid); + if ((aid.fget_flags&AF_NOCOLLISION) == 0) ugActorModify!true(aid); } // create switches @@ -630,7 +648,7 @@ public void loadMapMonsters () { aid.radius = 16; aid.height = 16; adef.callInit(aid); - if ((aid.flags!uint&AF_NOCOLLISION) == 0) ugActorModify!true(aid); // just in case + if ((aid.fget_flags&AF_NOCOLLISION) == 0) ugActorModify!true(aid); // just in case } else { conwriteln("switch definition 'switch:", swname, "' not found"); } -- 2.11.4.GIT