really compiles! ;-)
[dd2d.git] / data / scripts / api / actor.dacs
blob46f0e7259c438febeccf2d5c4ce83016c25facb7
1 /* DooM2D: Midnight on the Firing Line
2  * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3  * Understanding is not required. Only obedience.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 module apiActor;
20 import apiMap; // for flags
23 // actor declaration
24 public extern field(Actor) string classtype; // set to "X_X" to schedule actor death
25 public extern field(Actor) string classname;
26 public extern field(Actor) string state; // used in action scripts; also, defines animation
27 public extern field(Actor) int x, y;   // coordinates
29 public extern field(Actor) uint flags; // actor flags (see AF_xxx)
31 // internal fields for animation
32 public extern field(Actor) string zAnimstate;
33 public extern field(Actor) int zAnimidx;
35 // each actor can have attached light (to avoid creating and destroying light objects at each frame)
36 public field(Actor) int attLightXOfs, attLightYOfs; // light offset from actor x,y
37 public field(Actor) uint attLightRGBX; // light rgb and radius (R is MSB, X(radius) is LSB)
38  // if (G==0 && B==1) -- this is colorless light, intensity in R
40 public field(Actor) uint plrnum; // >0: player
41 public field(Actor) uint invitems; // see INV_ITEM_xxx
43 // for d2d switches
44 public field(Actor) uint switchabf; // (d<<24)|(a<<16)|(b<<8)|flags
46 public /*extern*/ field(Actor) uint tag; // userdata
47 public /*extern*/ field(Actor) int xv, yv; // current velocity
48 public /*extern*/ field(Actor) int vx, vy; // desired velocity (usually)
49 public /*extern*/ field(Actor) int radius, height;   // radius, height
50 public /*extern*/ field(Actor) int hitpoints;
51 // starting monster stats (usually will not be changed by thinkers)
52 public /*extern*/ field(Actor) int painin, painout;
53 public /*extern*/ field(Actor) int xvel, yvel;
54 public /*extern*/ field(Actor) int slophit;
55 public /*extern*/ field(Actor) int angertime;
56 // instead of `ap`; used by the engine to animate actors
57 public /*extern*/ field(Actor) string animname;
58 public /*extern*/ field(Actor) string animstr;
59 public /*extern*/ field(Actor) int animidx;
60 // various monster and other actor's fields
61 public /*extern*/ field(Actor) Actor target;
62 public /*extern*/ field(Actor) uint dir;  // 1: right
63 public /*extern*/ field(Actor) int st; // `d` for switch -- revert time
64 public /*extern*/ field(Actor) int ftime;
65 public /*extern*/ field(Actor) int fobj; //???
66 public /*extern*/ field(Actor) int s; // for item too
67 public /*extern*/ field(Actor) int aim;
68 public /*extern*/ field(Actor) int life /*is "life"*/;
69 public /*extern*/ field(Actor) int pain;
70 public /*extern*/ field(Actor) int ac;
71 public /*extern*/ field(Actor) int tx;
72 public /*extern*/ field(Actor) int ty;
73 public /*extern*/ field(Actor) int ammo;
74 public /*extern*/ field(Actor) int atm; // anger time for monster (decreasing counter); cooldown time for switch
77 public void actorMarkDead (Actor me) { me.classtype = "X_X"; }
79 // is actor alive?
80 public auto alive (Actor me) { return (me && me.classtype != "X_X"); }
81 // is actor dead?
82 public auto dead (Actor me) { return (!me || me.classtype == "X_X"); }
84 // is monster/player dead?
85 public auto isDead (Actor me) {
86   if (me.dead) return true;
87   if (me.classtype != "monster") return true;
88   return (me.animname == MNST_DIE || me.animname == MNST_DEAD || me.animname == MNST_REVIVE);
91 public auto isPlayer (Actor me) { return (me.plrnum > 0); }
92 public auto isMonster (Actor me) { return (me.classtype == "monster" && me.classname != "Player"); }
94 public auto isLeft (Actor me) { return (me.dir&ACTOR_DIR_RIGHT); }
95 public auto isRight (Actor me) { return !(me.dir&ACTOR_DIR_RIGHT); }
98 public auto hasRedKey (Actor me) { return !!(me.invitems&INV_ITEM_KEY_RED); }
99 public auto hasGreenKey (Actor me) { return !!(me.invitems&INV_ITEM_KEY_GREEN); }
100 public auto hasBlueKey (Actor me) { return !!(me.invitems&INV_ITEM_KEY_BLUE); }
102 public auto giveRedKey (Actor me) { me.invitems |= INV_ITEM_KEY_RED; }
103 public auto giveGreenKey (Actor me) { me.invitems |= INV_ITEM_KEY_GREEN; }
104 public auto giveBlueKey (Actor me) { me.invitems |= INV_ITEM_KEY_BLUE; }
107 uint packLightRGBX (int r, int g, int b, int radius) {
108   if (radius < 4) return 0;
109   if (r < 0) r = 0; else if (r > 255) r = 255;
110   if (g < 0) g = 0; else if (g > 255) g = 255;
111   if (b < 0) b = 0; else if (b > 255) b = 255;
112   if (g == 0 && b == 1) b = 0; // so it won't become "colorless"
113   if (radius > 255) radius = 255;
114   return (r<<24)|(g<<16)|(b<<8)|radius;
118 uint packLightColorless (int intens, int radius) {
119   if (radius < 4 || intens < 1) return 0;
120   if (intens > 255) intens = 255;
121   if (radius > 255) radius = 255;
122   return (intens<<24)|(0<<16)|(1<<8)|radius;
126 public void attachedLightRGBX (Actor me, int r, int g, int b, int radius) {
127   me.attLightRGBX = packLightRGBX(r, g, b, radius);
130 public void attachedLightColorless (Actor me, int intens, int radius) {
131   me.attLightRGBX = packLightColorless(intens, radius);
134 // monster state names
135 public const MNST_SLEEP  = "sleep";  // ÔÕÐÉÔ
136 public const MNST_GO     = "go";     // Õ×ÉÄÅÌ ÄÏÌÂÏ£ÂÁ, ÁÔÁËÕÅÔ
137 public const MNST_RUN    = "run";    // ÔÕÐÏ ÂÅÖÉÔ
138 public const MNST_CLIMB  = "climb";  // × ÐÒÙÖËÅ(?)
139 public const MNST_DIE    = "die";    // ÐÏÄÙÈÁÅÔ
140 public const MNST_DEAD   = "dead";   // ÐÏÄÏÈ
141 public const MNST_ATTACK = "attack"; // ÁÔÁËÕÅÔ ÒÕËÏÎÏÇÏÚÕÂÏÍ
142 public const MNST_SHOOT  = "shoot";  // ÓÔÒÅÌÑÅÔ
143 public const MNST_PAIN   = "pain";   // ËÏÎÞÁÅÔ ÏÔ ÂÏÌÉ
144 public const MNST_WAIT   = "wait";   // ÔÕÐÏ ÎÉÞÅÇÏ ÎÅ ÄÅÌÁÅÔ ×ÏÏÂÝÅ, ÏÖÉÄÁÑ ÈÕÊ ÚÎÁÅÔ ÞÅÇÏ 4 ÔÉËÁ
145 public const MNST_REVIVE = "revive"; // ÏÖÉ×ÁÅÔ
146 public const MNST_RUNOUT = "runout"; // Õ£ÂÙ×ÁÅÔ × ÔÕÍÁÎ
148 public const INV_ITEM_KEY_RED   = BIT(0);
149 public const INV_ITEM_KEY_GREEN = BIT(1);
150 public const INV_ITEM_KEY_BLUE  = BIT(2);
152 // player states
153 public const PLST_STAND = 0;
154 public const PLST_GO    = 1;
155 public const PLST_DIE   = 2;
156 public const PLST_SLOP  = 3;
157 public const PLST_DEAD  = 4;
158 public const PLST_MESS  = 5;
159 public const PLST_PLOUT = 6;
160 public const PLST_FALL  = 7;
162 // player keys
163 public const PLK_UP    = BIT(0);
164 public const PLK_DOWN  = BIT(1);
165 public const PLK_LEFT  = BIT(2);
166 public const PLK_RIGHT = BIT(3);
167 public const PLK_FIRE  = BIT(4);
168 public const PLK_JUMP  = BIT(5);
169 public const PLK_USE   = BIT(6);
171 public extern uint getPlayerButtons (uint pidx) pure;
173 // animation sequences
174 public const ACTOR_DIR_LEFT  = 0;
175 public const ACTOR_DIR_RIGHT = 1;
177 public extern void animClearFrames (string classtype, string classname, string state);
178 public extern void animAddFrame (string classtype, string classname, string state, uint dir, string sprname);
180 public extern void actorSetAnimation (Actor me, string state);
182 // note that spawned actor will not "think" in this turn
183 public extern Actor actorSpawn (string classtype, string classname, int x, int y, uint dir);
184 // flags: SWITCH_*
185 //public extern Actor actorSpawnVanillaSwitch (string classname, int x, int y, uint flags, int tilex, int tiley);
187 // return previous one
188 public extern Actor setCameraChick (Actor act);
191 public extern int getPlayerCount () pure;
192 //public extern Actor getPlayer () pure; // current player (if it's player script) or 0
193 public extern Actor getPlayerActor (uint pnum) pure;
195 //public extern int isPlayer (Actor a) pure;
197 //public extern uint actorMove (Actor a);
198 //public extern uint actorPressSwitches (Actor a);
199 //public extern uint actorFallen (Actor a);
201 public const Z_HITWALL  = BIT(0);
202 public const Z_HITCEIL  = BIT(1);
203 public const Z_HITLAND  = BIT(2);
204 public const Z_FALLOUT  = BIT(3);
205 public const Z_INWATER  = BIT(4);
206 public const Z_HITWATER = BIT(5);
207 public const Z_HITAIR   = BIT(6);
208 public const Z_BLOCK    = BIT(7);
210 // "real" water type (for Z_HITWATER)
211 public const Z_WATER_0  = BIT(16);
212 public const Z_WATER_1  = BIT(17);
213 public const Z_WATER_2  = BIT(18);
215 // "texture" water type (for Z_HITWATER)
216 public const Z_WATER_T0  = BIT(19);
217 public const Z_WATER_T1  = BIT(20);
218 public const Z_WATER_T2  = BIT(21);
221 public extern uint gameMode () pure;
222 // game modes
223 public const GM_NOTPLAYING = 0;
224 public const GM_SINGLE     = 1;
225 public const GM_COOP       = 2;
226 public const GM_DEATHMATCH = 3;
229 // switch flags
230 public const SW_PL_PRESS = BIT(0);
231 public const SW_MN_PRESS = BIT(1);
232 public const SW_PL_NEAR = BIT(2);
233 public const SW_MN_NEAR = BIT(3);
234 public const SW_KEY_R = BIT(4);
235 public const SW_KEY_G = BIT(5);
236 public const SW_KEY_B = BIT(6);
239 // actor flags
240 public const AF_NOCOLLISION = BIT(0);
241 public const AF_NOGRAVITY   = BIT(1);
242 public const AF_NOTHINK     = BIT(2);
243 public const AF_NOONTOUCH   = BIT(3); // `onTouch` will never be called with `me` for this actor
244 public const AF_NODRAW      = BIT(4); // don't draw sprite
245 public const AF_NOLIGHT     = BIT(5); // no attached light
246 public const AF_NOANIMATE   = BIT(6); // don't do animation
247 public const AF_PIXEL       = BIT(7); // draw simple pixel for this actor; color is `s`
248 public const AF_TELEPORT    = BIT(8); // don't interpolate camera; will be autoreset on next frame
251 // hit types
252 public const HIT_SOME    = BIT(0);
253 public const HIT_ROCKET  = BIT(1);
254 public const HIT_BFG     = BIT(2);
255 public const HIT_TRAP    = BIT(3);
256 public const HIT_WATER   = BIT(4);
257 public const HIT_ELECTRO = BIT(5);
258 public const HIT_FLAME   = BIT(6);
261 public extern int actorsOverlap (Actor a, Actor b) pure;
263 /// remove actor from scene immediately; use `actorMarkDead()` instead
264 /// if you will use this in `*List*()`, everything will break!
265 public extern void actorRemove (Actor me);
266 //TODO: actormarkdead
269 public extern void actorListRewind ();
270 public extern Actor actorListNext ();
273 // return number of items in touchlist
274 //public extern int actorSetupPossibleTouchList (Actor me);
276 // continue until actor is valid, i.e. `if (!act) break;`
277 public extern void rewindTouchList ();
278 public extern Actor getNextTouchListItem ();
280 // note that current actor is not on grid when it's `think()` is called,
281 // so it won't go in any touchlist at all
284 public extern int getCheatNoDoors ();
285 public extern int getCheatNoWallClip ();
286 public extern int getCheatNoCeilClip ();
287 public extern int getCheatNoLiftClip ();
290 // ////////////////////////////////////////////////////////////////////////// //
291 public extern void dotAddBlood (int x, int y, int xv, int yv, int n);
292 public extern void dotAddSpark (int x, int y, int xv, int yv, int n);
293 public extern void dotAddWater (int x, int y, int xv, int yv, int n, int color);
296 // ////////////////////////////////////////////////////////////////////////// //
297 // lnum <= 0: next level
298 public extern void gactLevelExit (int lnum);