more switches
[dd2d.git] / data / scripts / api / actor.dacs
blobcac40ba181723b44d129d3f772105a49c244e33d
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 // is actor alive?
63 public auto alive (Actor me) { return (me && me.classtype != "X_X"); }
64 // is actor dead?
65 public auto dead (Actor me) { return (!me || me.classtype == "X_X"); }
67 // is monster/player dead?
68 public auto isDead (Actor me) {
69   if (me.dead) return true;
70   if (me.classtype != "monster") return true;
71   return (me.animname == MNST_DIE || me.animname == MNST_DEAD || me.animname == MNST_REVIVE);
74 public auto isPlayer (Actor me) { return (me.plrnum > 0); }
75 public auto isMonster (Actor me) { return (me.classtype == "monster" && me.classname != "Player"); }
77 public auto isLeft (Actor me) { return (me.dir&ACTOR_DIR_RIGHT); }
78 public auto isRight (Actor me) { return !(me.dir&ACTOR_DIR_RIGHT); }
81 public auto hasRedKey (Actor me) { return !!(me.invitems&INV_ITEM_KEY_RED); }
82 public auto hasGreenKey (Actor me) { return !!(me.invitems&INV_ITEM_KEY_GREEN); }
83 public auto hasBlueKey (Actor me) { return !!(me.invitems&INV_ITEM_KEY_BLUE); }
85 public auto giveRedKey (Actor me) { me.invitems |= INV_ITEM_KEY_RED; }
86 public auto giveGreenKey (Actor me) { me.invitems |= INV_ITEM_KEY_GREEN; }
87 public auto giveBlueKey (Actor me) { me.invitems |= INV_ITEM_KEY_BLUE; }
90 uint packLightRGBX (int r, int g, int b, int radius) {
91   if (radius < 4) return 0;
92   if (r < 0) r = 0; else if (r > 255) r = 255;
93   if (g < 0) g = 0; else if (g > 255) g = 255;
94   if (b < 0) b = 0; else if (b > 255) b = 255;
95   if (radius > 255) radius = 255;
96   return (r<<24)|(g<<16)|(b<<8)|radius;
100 uint packLightColorless (int intens, int radius) {
101   if (radius < 4 || intens < 1) return 0;
102   if (intens > 255) intens = 255;
103   if (radius > 255) radius = 255;
104   return (intens<<24)|(0<<16)|(1<<8)|radius;
108 public void attachedLightRGBX (Actor me, int r, int g, int b, int radius) {
109   me.attLightRGBX = packLightRGBX(r, g, b, radius);
112 public void attachedLightColorless (Actor me, int intens, int radius) {
113   me.attLightRGBX = packLightColorless(intens, radius);
116 // monster state names
117 public const MNST_SLEEP  = "sleep";  // ÔÕÐÉÔ
118 public const MNST_GO     = "go";     // Õ×ÉÄÅÌ ÄÏÌÂÏ£ÂÁ, ÁÔÁËÕÅÔ
119 public const MNST_RUN    = "run";    // ÔÕÐÏ ÂÅÖÉÔ
120 public const MNST_CLIMB  = "climb";  // × ÐÒÙÖËÅ(?)
121 public const MNST_DIE    = "die";    // ÐÏÄÙÈÁÅÔ
122 public const MNST_DEAD   = "dead";   // ÐÏÄÏÈ
123 public const MNST_ATTACK = "attack"; // ÁÔÁËÕÅÔ ÒÕËÏÎÏÇÏÚÕÂÏÍ
124 public const MNST_SHOOT  = "shoot";  // ÓÔÒÅÌÑÅÔ
125 public const MNST_PAIN   = "pain";   // ËÏÎÞÁÅÔ ÏÔ ÂÏÌÉ
126 public const MNST_WAIT   = "wait";   // ÔÕÐÏ ÎÉÞÅÇÏ ÎÅ ÄÅÌÁÅÔ ×ÏÏÂÝÅ, ÏÖÉÄÁÑ ÈÕÊ ÚÎÁÅÔ ÞÅÇÏ 4 ÔÉËÁ
127 public const MNST_REVIVE = "revive"; // ÏÖÉ×ÁÅÔ
128 public const MNST_RUNOUT = "runout"; // Õ£ÂÙ×ÁÅÔ × ÔÕÍÁÎ
130 public const INV_ITEM_KEY_RED   = BIT(0);
131 public const INV_ITEM_KEY_GREEN = BIT(1);
132 public const INV_ITEM_KEY_BLUE  = BIT(2);
134 // player states
135 public const PLST_STAND = 0;
136 public const PLST_GO    = 1;
137 public const PLST_DIE   = 2;
138 public const PLST_SLOP  = 3;
139 public const PLST_DEAD  = 4;
140 public const PLST_MESS  = 5;
141 public const PLST_PLOUT = 6;
142 public const PLST_FALL  = 7;
144 // player keys
145 public const PLK_UP    = BIT(0);
146 public const PLK_DOWN  = BIT(1);
147 public const PLK_LEFT  = BIT(2);
148 public const PLK_RIGHT = BIT(3);
149 public const PLK_FIRE  = BIT(4);
150 public const PLK_JUMP  = BIT(5);
151 public const PLK_USE   = BIT(6);
153 public extern uint getPlayerButtons (uint pidx) pure;
155 // animation sequences
156 public const ACTOR_DIR_LEFT  = 0;
157 public const ACTOR_DIR_RIGHT = 1;
159 public extern void animClearFrames (string classtype, string classname, string state);
160 public extern void animAddFrame (string classtype, string classname, string state, uint dir, string sprname);
162 public extern void actorSetAnimation (Actor me, string state);
164 // note that spawned actor will not "think" in this turn
165 public extern Actor actorSpawn (string classtype, string classname, int x, int y, uint dir);
166 // flags: SWITCH_*
167 //public extern Actor actorSpawnVanillaSwitch (string classname, int x, int y, uint flags, int tilex, int tiley);
170 public extern int getPlayerCount () pure;
171 //public extern Actor getPlayer () pure; // current player (if it's player script) or 0
172 public extern Actor getPlayerActor (uint pnum) pure;
174 //public extern int isPlayer (Actor a) pure;
176 public extern uint actorMove (Actor a);
177 public extern uint actorPressSwitches (Actor a);
178 public extern uint actorFallen (Actor a);
180 public const Z_HITWALL  = BIT(0);
181 public const Z_HITCEIL  = BIT(1);
182 public const Z_HITLAND  = BIT(2);
183 public const Z_FALLOUT  = BIT(3);
184 public const Z_INWATER  = BIT(4);
185 public const Z_HITWATER = BIT(5);
186 public const Z_HITAIR   = BIT(6);
187 public const Z_BLOCK    = BIT(7);
189 // "real" water type (for Z_HITWATER)
190 public const Z_WATER_0  = BIT(16);
191 public const Z_WATER_1  = BIT(17);
192 public const Z_WATER_2  = BIT(18);
194 // "texture" water type (for Z_HITWATER)
195 public const Z_WATER_T0  = BIT(19);
196 public const Z_WATER_T1  = BIT(20);
197 public const Z_WATER_T2  = BIT(21);
200 public extern uint gameMode () pure;
201 // game modes
202 public const GM_NOTPLAYING = 0;
203 public const GM_SINGLE     = 1;
204 public const GM_COOP       = 2;
205 public const GM_DEATHMATCH = 3;
208 // switch flags
209 public const SW_PL_PRESS = BIT(0);
210 public const SW_MN_PRESS = BIT(1);
211 public const SW_PL_NEAR = BIT(2);
212 public const SW_MN_NEAR = BIT(3);
213 public const SW_KEY_R = BIT(4);
214 public const SW_KEY_G = BIT(5);
215 public const SW_KEY_B = BIT(6);
218 // actor flags
219 public const AF_NOCOLLISION = BIT(0);
220 public const AF_NOGRAVITY   = BIT(1);
221 public const AF_NOTHINK     = BIT(2);
222 public const AF_NOONTOUCH   = BIT(3); // `onTouch` will never be called with `me` for this actor
223 public const AF_NODRAW      = BIT(4); // don't draw sprite
224 public const AF_NOLIGHT     = BIT(5); // no attached light
225 public const AF_NOANIMATE   = BIT(6); // don't do animation
226 public const AF_CAMERACHICK = BIT(7); // camera will follow this actor; if we have more than one camera chick... well, who knows
229 // hit types
230 public const HIT_SOME    = BIT(0);
231 public const HIT_ROCKET  = BIT(1);
232 public const HIT_BFG     = BIT(2);
233 public const HIT_TRAP    = BIT(3);
234 public const HIT_WATER   = BIT(4);
235 public const HIT_ELECTRO = BIT(5);
236 public const HIT_FLAME   = BIT(6);
239 public extern int actorsOverlap (Actor a, Actor b) pure;
241 /// remove actor from scene immediately; use `actorMarkDead()` instead
242 /// if you will use this in `*List*()`, everything will break!
243 public extern void actorRemove (Actor me);
244 //TODO: actormarkdead
247 public extern void actorListRewind ();
248 public extern Actor actorListNext ();
251 // return number of items in touchlist
252 //public extern int actorSetupPossibleTouchList (Actor me);
254 // continue until actor is valid, i.e. `if (!act) break;`
255 public extern void rewindTouchList ();
256 public extern Actor getNextTouchListItem ();
258 // note that current actor is not on grid when it's `think()` is called,
259 // so it won't go in any touchlist at all
262 public extern int getCheatNoDoors ();
263 public extern int getCheatNoWallClip ();
264 public extern int getCheatNoCeilClip ();
265 public extern int getCheatNoLiftClip ();
268 // ////////////////////////////////////////////////////////////////////////// //
269 public extern void dotAddBlood (int x, int y, int xv, int yv, int n);
270 public extern void dotAddSpark (int x, int y, int xv, int yv, int n);
271 public extern void dotAddWater (int x, int y, int xv, int yv, int n, int color);
274 // ////////////////////////////////////////////////////////////////////////// //
275 // lnum <= 0: next level
276 public extern void gactLevelExit (int lnum);