trap switches
[dd2d.git] / data / scripts / api / actor.dacs
blob0bf7391444f482e16b978442f11aee34bd7f39ef
1 module apiActor;
3 import apiMap; // for flags
6 // actor declaration
7 public extern field(Actor) string classtype; // set to "X_X" to schedule actor death
8 public extern field(Actor) string classname;
9 public extern field(Actor) string state; // used in action scripts; also, defines animation
10 public extern field(Actor) int x, y;   // coordinates
12 public extern field(Actor) uint flags; // actor flags (see AF_xxx)
14 // internal fields for animation
15 public extern field(Actor) string zAnimstate;
16 public extern field(Actor) int zAnimidx;
18 // each actor can have attached light (to avoid creating and destroying light objects at each frame)
19 public field(Actor) int attLightXOfs, attLightYOfs; // light offset from actor x,y
20 public field(Actor) uint attLightRGBX; // light rgb and radius (R is MSB, X(radius) is LSB)
21  // if (G==0 && B==1) -- this is colorless light, intensity in R
23 public field(Actor) uint plrnum; // >0: player
24 public field(Actor) uint invitems; // see INV_ITEM_xxx
26 // for d2d switches
27 public field(Actor) uint switchabf; // (d<<24)|(a<<16)|(b<<8)|flags
29 public /*extern*/ field(Actor) uint tag; // userdata
30 public /*extern*/ field(Actor) int xv, yv; // current velocity
31 public /*extern*/ field(Actor) int vx, vy; // desired velocity (usually)
32 public /*extern*/ field(Actor) int radius, height;   // radius, height
33 public /*extern*/ field(Actor) int hitpoints;
34 // starting monster stats (usually will not be changed by thinkers)
35 public /*extern*/ field(Actor) int painin, painout;
36 public /*extern*/ field(Actor) int xvel, yvel;
37 public /*extern*/ field(Actor) int slophit;
38 public /*extern*/ field(Actor) int angertime;
39 // instead of `ap`; used by the engine to animate actors
40 public /*extern*/ field(Actor) string animname;
41 public /*extern*/ field(Actor) string animstr;
42 public /*extern*/ field(Actor) int animidx;
43 // various monster and other actor's fields
44 public /*extern*/ field(Actor) Actor target;
45 public /*extern*/ field(Actor) uint dir;  // 1: right
46 public /*extern*/ field(Actor) int st; // `d` for switch -- revert time
47 public /*extern*/ field(Actor) int ftime;
48 public /*extern*/ field(Actor) int fobj; //???
49 public /*extern*/ field(Actor) int s; // for item too
50 public /*extern*/ field(Actor) int aim;
51 public /*extern*/ field(Actor) int life /*is "life"*/;
52 public /*extern*/ field(Actor) int pain;
53 public /*extern*/ field(Actor) int ac;
54 public /*extern*/ field(Actor) int tx;
55 public /*extern*/ field(Actor) int ty;
56 public /*extern*/ field(Actor) int ammo;
57 public /*extern*/ field(Actor) int atm; // anger time for monster (decreasing counter); cooldown time for switch
60 public void actorMarkDead (Actor me) { me.classtype = "X_X"; }
62 public auto isPlayer (Actor me) { return (me.plrnum > 0); }
63 public auto isMonster (Actor me) { return (me.classtype == "monster" && me.classname != "Player"); }
65 public auto isLeft (Actor me) { return (me.dir&ACTOR_DIR_RIGHT); }
66 public auto isRight (Actor me) { return !(me.dir&ACTOR_DIR_RIGHT); }
69 public auto hasRedKey (Actor me) { return !!(me.invitems&INV_ITEM_KEY_RED); }
70 public auto hasGreenKey (Actor me) { return !!(me.invitems&INV_ITEM_KEY_GREEN); }
71 public auto hasBlueKey (Actor me) { return !!(me.invitems&INV_ITEM_KEY_BLUE); }
73 public auto giveRedKey (Actor me) { me.invitems |= INV_ITEM_KEY_RED; }
74 public auto giveGreenKey (Actor me) { me.invitems |= INV_ITEM_KEY_GREEN; }
75 public auto giveBlueKey (Actor me) { me.invitems |= INV_ITEM_KEY_BLUE; }
78 uint packLightRGBX (int r, int g, int b, int radius) {
79   if (radius < 4) return 0;
80   if (r < 0) r = 0; else if (r > 255) r = 255;
81   if (g < 0) g = 0; else if (g > 255) g = 255;
82   if (b < 0) b = 0; else if (b > 255) b = 255;
83   if (radius > 255) radius = 255;
84   return (r<<24)|(g<<16)|(b<<8)|radius;
88 uint packLightColorless (int intens, int radius) {
89   if (radius < 4 || intens < 1) return 0;
90   if (intens > 255) intens = 255;
91   if (radius > 255) radius = 255;
92   return (intens<<24)|(0<<16)|(1<<8)|radius;
96 public void attachedLightRGBX (Actor me, int r, int g, int b, int radius) {
97   me.attLightRGBX = packLightRGBX(r, g, b, radius);
100 public void attachedLightColorless (Actor me, int intens, int radius) {
101   me.attLightRGBX = packLightColorless(intens, radius);
104 // monster state names
105 public const MNST_SLEEP  = "sleep";  // ÔÕÐÉÔ
106 public const MNST_GO     = "go";     // Õ×ÉÄÅÌ ÄÏÌÂÏ£ÂÁ, ÁÔÁËÕÅÔ
107 public const MNST_RUN    = "run";    // ÔÕÐÏ ÂÅÖÉÔ
108 public const MNST_CLIMB  = "climb";  // × ÐÒÙÖËÅ(?)
109 public const MNST_DIE    = "die";    // ÐÏÄÙÈÁÅÔ
110 public const MNST_DEAD   = "dead";   // ÐÏÄÏÈ
111 public const MNST_ATTACK = "attack"; // ÁÔÁËÕÅÔ ÒÕËÏÎÏÇÏÚÕÂÏÍ
112 public const MNST_SHOOT  = "shoot";  // ÓÔÒÅÌÑÅÔ
113 public const MNST_PAIN   = "pain";   // ËÏÎÞÁÅÔ ÏÔ ÂÏÌÉ
114 public const MNST_WAIT   = "wait";   // ÔÕÐÏ ÎÉÞÅÇÏ ÎÅ ÄÅÌÁÅÔ ×ÏÏÂÝÅ, ÏÖÉÄÁÑ ÈÕÊ ÚÎÁÅÔ ÞÅÇÏ 4 ÔÉËÁ
115 public const MNST_REVIVE = "revive"; // ÏÖÉ×ÁÅÔ
116 public const MNST_RUNOUT = "runout"; // Õ£ÂÙ×ÁÅÔ × ÔÕÍÁÎ
118 public const INV_ITEM_KEY_RED   = BIT(0);
119 public const INV_ITEM_KEY_GREEN = BIT(1);
120 public const INV_ITEM_KEY_BLUE  = BIT(2);
122 // player states
123 public const PLST_STAND = 0;
124 public const PLST_GO    = 1;
125 public const PLST_DIE   = 2;
126 public const PLST_SLOP  = 3;
127 public const PLST_DEAD  = 4;
128 public const PLST_MESS  = 5;
129 public const PLST_PLOUT = 6;
130 public const PLST_FALL  = 7;
132 // player keys
133 public const PLK_UP    = BIT(0);
134 public const PLK_DOWN  = BIT(1);
135 public const PLK_LEFT  = BIT(2);
136 public const PLK_RIGHT = BIT(3);
137 public const PLK_FIRE  = BIT(4);
138 public const PLK_JUMP  = BIT(5);
139 public const PLK_USE   = BIT(6);
141 public extern uint getPlayerButtons (uint pidx) pure;
143 // animation sequences
144 public const ACTOR_DIR_LEFT  = 0;
145 public const ACTOR_DIR_RIGHT = 1;
147 public extern void animClearFrames (string classtype, string classname, string state);
148 public extern void animAddFrame (string classtype, string classname, string state, uint dir, string sprname);
150 public extern void actorSetAnimation (Actor me, string state);
152 // note that spawned actor will not "think" in this turn
153 public extern Actor actorSpawn (string classtype, string classname, int x, int y, uint dir);
154 // flags: SWITCH_*
155 public extern Actor actorSpawnVanillaSwitch (string classname, int x, int y, uint flags, int tilex, int tiley);
158 public extern int getPlayerCount () pure;
159 //public extern Actor getPlayer () pure; // current player (if it's player script) or 0
160 public extern Actor getPlayerActor (uint pnum) pure;
162 //public extern int isPlayer (Actor a) pure;
164 public extern uint actorMove (Actor a);
165 public extern uint actorPressSwitches (Actor a);
166 public extern uint actorFallen (Actor a);
168 public const Z_HITWALL  = BIT(0);
169 public const Z_HITCEIL  = BIT(1);
170 public const Z_HITLAND  = BIT(2);
171 public const Z_FALLOUT  = BIT(3);
172 public const Z_INWATER  = BIT(4);
173 public const Z_HITWATER = BIT(5);
174 public const Z_HITAIR   = BIT(6);
175 public const Z_BLOCK    = BIT(7);
177 // "real" water type (for Z_HITWATER)
178 public const Z_WATER_0  = BIT(16);
179 public const Z_WATER_1  = BIT(17);
180 public const Z_WATER_2  = BIT(18);
182 // "texture" water type (for Z_HITWATER)
183 public const Z_WATER_T0  = BIT(19);
184 public const Z_WATER_T1  = BIT(20);
185 public const Z_WATER_T2  = BIT(21);
188 public extern uint gameMode () pure;
189 // game modes
190 public const GM_NOTPLAYING = 0;
191 public const GM_SINGLE     = 1;
192 public const GM_COOP       = 2;
193 public const GM_DEATHMATCH = 3;
196 // switch flags
197 public const SW_PL_PRESS = BIT(0);
198 public const SW_MN_PRESS = BIT(1);
199 public const SW_PL_NEAR = BIT(2);
200 public const SW_MN_NEAR = BIT(3);
201 public const SW_KEY_R = BIT(4);
202 public const SW_KEY_G = BIT(5);
203 public const SW_KEY_B = BIT(6);
206 // actor flags
207 public const AF_NOCOLLISION = BIT(0);
208 public const AF_NOGRAVITY   = BIT(1);
209 public const AF_NOTHINK     = BIT(2);
210 public const AF_NOONTOUCH   = BIT(3); // `onTouch` will never be called with `me` for this actor
211 public const AF_NODRAW      = BIT(4); // don't draw sprite
212 public const AF_NOLIGHT     = BIT(5); // no attached light
213 public const AF_NOANIMATE   = BIT(6); // don't do animation
214 public const AF_CAMERACHICK = BIT(7); // camera will follow this actor; if we have more than one camera chick... well, who knows
217 // hit types
218 public const HIT_SOME    = BIT(0);
219 public const HIT_ROCKET  = BIT(1);
220 public const HIT_BFG     = BIT(2);
221 public const HIT_TRAP    = BIT(3);
222 public const HIT_WATER   = BIT(4);
223 public const HIT_ELECTRO = BIT(5);
224 public const HIT_FLAME   = BIT(6);
227 public extern int actorsOverlap (Actor a, Actor b) pure;
229 /// remove actor from scene immediately; use `actorMarkDead()` instead
230 /// if you will use this in `*List*()`, everything will break!
231 public extern void actorRemove (Actor me);
232 //TODO: actormarkdead
235 public extern void actorListRewind ();
236 public extern Actor actorListNext ();
239 // return number of items in touchlist
240 //public extern int actorSetupPossibleTouchList (Actor me);
242 // continue until actor is valid, i.e. `if (!act) break;`
243 public extern void rewindTouchList ();
244 public extern Actor getNextTouchListItem ();
246 // note that current actor is not on grid when it's `think()` is called,
247 // so it won't go in any touchlist at all
250 public extern int getCheatNoDoors ();
251 public extern int getCheatNoWallClip ();
252 public extern int getCheatNoCeilClip ();
253 public extern int getCheatNoLiftClip ();
256 // ////////////////////////////////////////////////////////////////////////// //
257 public extern void dotAddBlood (int x, int y, int xv, int yv, int n);
258 public extern void dotAddSpark (int x, int y, int xv, int yv, int n);
259 public extern void dotAddWater (int x, int y, int xv, int yv, int n, int color);