]> icculus.org git repositories - divverent/darkplaces.git/blob - progs.h
added onground clearing before each move so that going down slopes doesn't resemble...
[divverent/darkplaces.git] / progs.h
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the 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, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20
21 #ifndef PROGS_H
22 #define PROGS_H
23
24 #include "pr_comp.h"                    // defs shared with qcc
25 #include "progdefs.h"                   // generated by program cdefs
26
27 typedef union eval_s
28 {
29         string_t                string;
30         float                   _float;
31         float                   vector[3];
32         func_t                  function;
33         int                             ivector[3];
34         int                             _int;
35         int                             edict;
36 } eval_t;
37
38 typedef struct link_s
39 {
40         int entitynumber;
41         struct link_s   *prev, *next;
42 } link_t;
43
44 #define ENTITYGRIDAREAS 16
45
46 typedef struct edict_engineprivate_s
47 {
48         // true if this edict is unused
49         qboolean free;
50         // sv.time when the object was freed (to prevent early reuse which could
51         // mess up client interpolation or obscure severe QuakeC bugs)
52         float freetime;
53
54         // physics grid areas this edict is linked into
55         link_t areagrid[ENTITYGRIDAREAS];
56         // since the areagrid can have multiple references to one entity,
57         // we should avoid extensive checking on entities already encountered
58         int areagridmarknumber;
59
60         // PROTOCOL_QUAKE, PROTOCOL_QUAKEDP, PROTOCOL_NEHAHRAMOVIE
61         // baseline values
62         entity_state_t baseline;
63
64         // LordHavoc: gross hack to make floating items still work
65         int suspendedinairflag;
66         // used by PushMove to keep track of where objects were before they were
67         // moved, in case they need to be moved back
68         vec3_t moved_from;
69         vec3_t moved_fromangles;
70 }
71 edict_engineprivate_t;
72
73 // the entire server entity structure
74 // NOTE: keep this small!  priv and v are dynamic but this struct is not!
75 typedef struct edict_s
76 {
77         // engine-private fields (stored in dynamically resized array)
78         edict_engineprivate_t *e;
79         // QuakeC fields (stored in dynamically resized array)
80         entvars_t *v;
81 }
82 edict_t;
83
84 // LordHavoc: in an effort to eliminate time wasted on GetEdictFieldValue...  see pr_edict.c for the functions which use these.
85 extern int eval_gravity;
86 extern int eval_button3;
87 extern int eval_button4;
88 extern int eval_button5;
89 extern int eval_button6;
90 extern int eval_button7;
91 extern int eval_button8;
92 extern int eval_buttonuse;
93 extern int eval_buttonchat;
94 extern int eval_glow_size;
95 extern int eval_glow_trail;
96 extern int eval_glow_color;
97 extern int eval_items2;
98 extern int eval_scale;
99 extern int eval_alpha;
100 extern int eval_renderamt; // HalfLife support
101 extern int eval_rendermode; // HalfLife support
102 extern int eval_fullbright;
103 extern int eval_ammo_shells1;
104 extern int eval_ammo_nails1;
105 extern int eval_ammo_lava_nails;
106 extern int eval_ammo_rockets1;
107 extern int eval_ammo_multi_rockets;
108 extern int eval_ammo_cells1;
109 extern int eval_ammo_plasma;
110 extern int eval_idealpitch;
111 extern int eval_pitch_speed;
112 extern int eval_viewmodelforclient;
113 extern int eval_nodrawtoclient;
114 extern int eval_exteriormodeltoclient;
115 extern int eval_drawonlytoclient;
116 extern int eval_ping;
117 extern int eval_movement;
118 extern int eval_pmodel;
119 extern int eval_punchvector;
120 extern int eval_viewzoom;
121 extern int eval_clientcolors;
122 extern int eval_tag_entity;
123 extern int eval_tag_index;
124 extern int eval_light_lev;
125 extern int eval_color;
126 extern int eval_style;
127 extern int eval_pflags;
128 extern int eval_cursor_active;
129 extern int eval_cursor_screen;
130 extern int eval_cursor_trace_start;
131 extern int eval_cursor_trace_endpos;
132 extern int eval_cursor_trace_ent;
133 extern int eval_colormod;
134 extern int eval_playermodel;
135 extern int eval_playerskin;
136
137 #define GETEDICTFIELDVALUE(ed, fieldoffset) (fieldoffset ? (eval_t *)((qbyte *)ed->v + fieldoffset) : NULL)
138
139
140 extern mfunction_t *SV_PlayerPhysicsQC;
141 extern mfunction_t *EndFrameQC;
142 //KrimZon - SERVER COMMANDS IN QUAKEC
143 extern mfunction_t *SV_ParseClientCommandQC;
144
145 //============================================================================
146
147 extern  dprograms_t             *progs;
148 extern  mfunction_t             *pr_functions;
149 extern  char                    *pr_strings;
150 extern  int                             pr_stringssize;
151 extern  ddef_t                  *pr_globaldefs;
152 extern  ddef_t                  *pr_fielddefs;
153 extern  dstatement_t    *pr_statements;
154 extern  globalvars_t    *pr_global_struct;
155 extern  float                   *pr_globals;                    // same as pr_global_struct
156
157 extern  int                             pr_edict_size;  // in bytes
158 extern  int                             pr_edictareasize; // LordHavoc: for bounds checking
159
160 extern  int                             pr_maxknownstrings;
161 extern  int                             pr_numknownstrings;
162 extern  const char              **pr_knownstrings;
163
164 //============================================================================
165
166 void PR_Init (void);
167 void PR_Shutdown (void);
168
169 void PR_ExecuteProgram (func_t fnum, const char *errormessage);
170 void PR_LoadProgs (const char *progsname);
171
172 #define PR_Alloc(buffersize) _PR_Alloc(buffersize, __FILE__, __LINE__)
173 #define PR_Free(buffer) _PR_Free(buffer, __FILE__, __LINE__)
174 #define PR_FreeAll() _PR_FreeAll(__FILE__, __LINE__)
175 void *_PR_Alloc (size_t buffersize, const char *filename, int fileline);
176 void _PR_Free (void *buffer, const char *filename, int fileline);
177 void _PR_FreeAll (const char *filename, int fileline);
178
179 void PR_Profile_f (void);
180
181 void PR_PrintState(void);
182 void PR_Crash (void);
183
184 void SV_IncreaseEdicts(void);
185
186 edict_t *ED_Alloc (void);
187 void ED_Free (edict_t *ed);
188 void ED_ClearEdict (edict_t *e);
189
190 void ED_Print(edict_t *ed);
191 void ED_Write (qfile_t *f, edict_t *ed);
192 const char *ED_ParseEdict (const char *data, edict_t *ent);
193
194 void ED_WriteGlobals (qfile_t *f);
195 void ED_ParseGlobals (const char *data);
196
197 void ED_LoadFromFile (const char *data);
198
199 edict_t *EDICT_NUM_ERROR(int n, char *filename, int fileline);
200 #define EDICT_NUM(n) (((n) >= 0 && (n) < sv.max_edicts) ? sv.edicts + (n) : EDICT_NUM_ERROR(n, __FILE__, __LINE__))
201 #define EDICT_NUM_UNSIGNED(n) (((n) < sv.max_edicts) ? sv.edicts + (n) : EDICT_NUM_ERROR(n, __FILE__, __LINE__))
202
203 //int NUM_FOR_EDICT_ERROR(edict_t *e);
204 #define NUM_FOR_EDICT(e) ((int)((edict_t *)(e) - sv.edicts))
205 //int NUM_FOR_EDICT(edict_t *e);
206
207 #define NEXT_EDICT(e) ((e) + 1)
208
209 #define EDICT_TO_PROG(e) (NUM_FOR_EDICT(e))
210 //int EDICT_TO_PROG(edict_t *e);
211 #define PROG_TO_EDICT(n) (EDICT_NUM(n))
212 //edict_t *PROG_TO_EDICT(int n);
213
214 //============================================================================
215
216 #define G_FLOAT(o) (pr_globals[o])
217 #define G_INT(o) (*(int *)&pr_globals[o])
218 #define G_EDICT(o) (PROG_TO_EDICT(*(int *)&pr_globals[o]))
219 #define G_EDICTNUM(o) NUM_FOR_EDICT(G_EDICT(o))
220 #define G_VECTOR(o) (&pr_globals[o])
221 #define G_STRING(o) (PR_GetString(*(string_t *)&pr_globals[o]))
222 //#define       G_FUNCTION(o) (*(func_t *)&pr_globals[o])
223
224 // FIXME: make these go away?
225 #define E_FLOAT(e,o) (((float*)e->v)[o])
226 //#define       E_INT(e,o) (((int*)e->v)[o])
227 //#define       E_VECTOR(e,o) (&((float*)e->v)[o])
228 #define E_STRING(e,o) (PR_GetString(*(string_t *)&((float*)e->v)[o]))
229
230 extern  int             type_size[8];
231
232 typedef void (*builtin_t) (void);
233 extern  builtin_t *pr_builtins;
234 extern int pr_numbuiltins;
235
236 extern int              pr_argc;
237
238 extern  int                     pr_trace;
239 extern  mfunction_t     *pr_xfunction;
240 extern  int                     pr_xstatement;
241
242 extern  unsigned short          pr_crc;
243
244 void PR_Execute_ProgsLoaded(void);
245
246 void ED_PrintEdicts (void);
247 void ED_PrintNum (int ent);
248
249 const char *PR_GetString(int num);
250 int PR_SetQCString(const char *s);
251 int PR_SetEngineString(const char *s);
252 char *PR_AllocString(int bufferlength);
253 void PR_FreeString(char *s);
254
255 #endif
256