From 43f4e78ff416dbf4e79bb735122d12997c8abf8b Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Sat, 19 Mar 2016 09:18:07 +0200 Subject: [PATCH] initial work for switch actors --- d2dadefs.d | 37 ++++++++++++++++++++++++++++--------- data/scripts/actor.dacs | 13 +++++++++++++ data/scripts/d2dswitches.dacs | 19 +++++++++++++++++++ data/scripts/dacsmain.txt | 1 + dengapi.d | 23 +++++++++++++++++++++++ 5 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 data/scripts/d2dswitches.dacs diff --git a/d2dadefs.d b/d2dadefs.d index 911ea5c..cf1f5d3 100644 --- a/d2dadefs.d +++ b/d2dadefs.d @@ -48,7 +48,7 @@ struct ActorDefD2D { StrId classname; ushort mapid; // thing id in map - this (string ctype, string cname, ushort thid) { + this (string ctype, string cname, ushort thid=0) { classtype = StrPool.intern(ctype); classname = StrPool.intern(cname); mapid = thid; @@ -123,7 +123,33 @@ shared static this () { ActorDefD2D("monster", "Robot", 218), ActorDefD2D("monster", "Man", 219), ]; - foreach (const ref ActorDefD2D d2da; d2dactordefs) d2dactordefsById[d2da.mapid] = d2da; + foreach (const ref ActorDefD2D d2da; d2dactordefs) { + if (d2da.mapid) d2dactordefsById[d2da.mapid] = d2da; + } +} + + +// ////////////////////////////////////////////////////////////////////////// // +public string getD2DSwitchClassName (uint swtype) { + switch (swtype) { + case 1: return "Exit"; // SW_EXIT + case 2: return "ExitSecret"; // SW_EXITS + case 3: return "DoorOpen"; // SW_OPENDOOR + case 4: return "DoorClose"; // SW_SHUTDOOR + case 5: return "TrapClose"; // SW_SHUTTRAP + case 6: return "Door"; // SW_DOOR + case 7: return "Door5"; // SW_DOOR5 + case 8: return "Press"; // SW_PRESS + case 9: return "Tele"; // SW_TELE + case 10: return "Secret"; // SW_SECRET + case 11: return "LiftUp"; // SW_LIFTUP + case 12: return "LiftDown"; // SW_LIFTDOWN + case 13: return "Trap"; // SW_TRAP + case 14: return "Lift"; // SW_LIFT + case 64: return "WinGame"; // SW_WINGAME + default: + } + return null; } @@ -141,7 +167,6 @@ public struct ImgSprite { public final class ActorDef { StrId classtype; StrId classname; - //uint id; // actor's unique id // animation sequences for stated; keyed by state strid StrId[][][uint] anims; // [statestrid][dir][pos] @@ -222,15 +247,9 @@ public final class ActorDef { return null; } - //private __gshared uint nextId = 1; - this (string ctype, string cname) { classtype = StrPool.intern(ctype); classname = StrPool.intern(cname); - //classtype = ctype; - //classname = cname; - //fullname = classtype~":"~classname; - //id = nextId++; } void clearAllFrames (StrId state) { diff --git a/data/scripts/actor.dacs b/data/scripts/actor.dacs index 9270253..f76f159 100644 --- a/data/scripts/actor.dacs +++ b/data/scripts/actor.dacs @@ -22,6 +22,9 @@ public field(Actor) uint attLightRGBX; // light rgb and radius (R is MSB, X(radi public field(Actor) uint plrnum; // >0: player +// for d2d switches +public field(Actor) uint switchabf; // (a<<16)|(b<<8)|flags + public /*extern*/ field(Actor) uint tag; // userdata public /*extern*/ field(Actor) int xv, yv; // current velocity public /*extern*/ field(Actor) int vx, vy; // desired velocity (usually) @@ -162,6 +165,16 @@ public const GM_COOP = 2; public const GM_DEATHMATCH = 3; +// switch flags +public const SW_PL_PRESS = BIT(0); +public const SW_MN_PRESS = BIT(1); +public const SW_PL_NEAR = BIT(2); +public const SW_MN_NEAR = BIT(3); +public const SW_KEY_R = BIT(4); +public const SW_KEY_G = BIT(5); +public const SW_KEY_B = BIT(6); + + // actor flags public const AF_NOCOLLISION = BIT(0); public const AF_NOGRAVITY = BIT(1); diff --git a/data/scripts/d2dswitches.dacs b/data/scripts/d2dswitches.dacs new file mode 100644 index 0000000..5710700 --- /dev/null +++ b/data/scripts/d2dswitches.dacs @@ -0,0 +1,19 @@ +module d2dswitches; + +/* +import switchExit; // SW_EXIT +import switchExitsecret; // SW_EXITS +import switchDooropen; // SW_OPENDOOR +import switchDoorclose; // SW_SHUTDOOR +import switchTrapclose; // SW_SHUTTRAP +import switchDoor; // SW_DOOR +import switchDoor5; // SW_DOOR5 +import switchPress; // SW_PRESS +import switchTele; // SW_TELE +import switchSecret; // SW_SECRET +import switchLiftup; // SW_LIFTUP +import switchLiftdown; // SW_LIFTDOWN +import switchTrap; // SW_TRAP +import switchLift; // SW_LIFT +import switchWingame; // SW_WINGAME +*/ diff --git a/data/scripts/dacsmain.txt b/data/scripts/dacsmain.txt index a116334..defa078 100644 --- a/data/scripts/dacsmain.txt +++ b/data/scripts/dacsmain.txt @@ -1,3 +1,4 @@ d2dmonsters d2ditems +d2dswitches d2dplayer diff --git a/dengapi.d b/dengapi.d index da43eaa..b80b2a6 100644 --- a/dengapi.d +++ b/dengapi.d @@ -500,6 +500,29 @@ public void loadMapMonsters () { if ((aid.flags!uint&AF_NOCOLLISION) == 0) ugActorModify!true(aid); } + // create switches + foreach (ref sw; map.switches) { + if (sw.type == 0) continue; // just in case + auto swname = getD2DSwitchClassName(sw.type); + if (swname.length == 0) { + conwriteln("unknown switch type ", sw.type); + continue; + } + if (auto adef = findActorDef("switch", swname)) { + auto aid = Actor.alloc; + aid.classtype = StrPool.intern("switch"); + aid.classname = StrPool.intern(swname); + aid.flags = AF_NOCOLLISION|AF_NOGRAVITY|AF_NOONTOUCH|AF_NODRAW|AF_NOLIGHT|AF_NOANIMATE; + aid.x = sw.x*8; + aid.y = sw.y*8; + aid.switchabf = (sw.a<<16)|(sw.b<<8)|sw.flags; + adef.callInit(aid); + if ((aid.flags!uint&AF_NOCOLLISION) == 0) ugActorModify!true(aid); // just in case + } else { + conwriteln("switch definition 'switch:", swname, "' not found"); + } + } + ActorDef.forEach((adef) { conwriteln("loading graphics for '", adef.classtype.get, ":", adef.classname.get, "'"); adef.loadGraphics(); -- 2.11.4.GIT