2 // This code isn't #ifdef/#define protectable, don't try.
7 if (++profile > 1000000) // LordHavoc: increased runaway loop limit 10x
9 pr_xstatement = st - pr_statements;
10 Host_Error ("runaway loop error");
14 PR_PrintStatement (st);
20 OPC->_float = OPA->_float + OPB->_float;
23 OPC->vector[0] = OPA->vector[0] + OPB->vector[0];
24 OPC->vector[1] = OPA->vector[1] + OPB->vector[1];
25 OPC->vector[2] = OPA->vector[2] + OPB->vector[2];
28 OPC->_float = OPA->_float - OPB->_float;
31 OPC->vector[0] = OPA->vector[0] - OPB->vector[0];
32 OPC->vector[1] = OPA->vector[1] - OPB->vector[1];
33 OPC->vector[2] = OPA->vector[2] - OPB->vector[2];
36 OPC->_float = OPA->_float * OPB->_float;
39 OPC->_float = OPA->vector[0]*OPB->vector[0] + OPA->vector[1]*OPB->vector[1] + OPA->vector[2]*OPB->vector[2];
42 OPC->vector[0] = OPA->_float * OPB->vector[0];
43 OPC->vector[1] = OPA->_float * OPB->vector[1];
44 OPC->vector[2] = OPA->_float * OPB->vector[2];
47 OPC->vector[0] = OPB->_float * OPA->vector[0];
48 OPC->vector[1] = OPB->_float * OPA->vector[1];
49 OPC->vector[2] = OPB->_float * OPA->vector[2];
52 OPC->_float = OPA->_float / OPB->_float;
55 OPC->_float = (int)OPA->_float & (int)OPB->_float;
58 OPC->_float = (int)OPA->_float | (int)OPB->_float;
61 OPC->_float = OPA->_float >= OPB->_float;
64 OPC->_float = OPA->_float <= OPB->_float;
67 OPC->_float = OPA->_float > OPB->_float;
70 OPC->_float = OPA->_float < OPB->_float;
73 OPC->_float = OPA->_float && OPB->_float;
76 OPC->_float = OPA->_float || OPB->_float;
79 OPC->_float = !OPA->_float;
82 OPC->_float = !OPA->vector[0] && !OPA->vector[1] && !OPA->vector[2];
85 OPC->_float = !OPA->string || !*PR_GetString(OPA->string);
88 OPC->_float = !OPA->function;
91 OPC->_float = (OPA->edict == 0);
94 OPC->_float = OPA->_float == OPB->_float;
97 OPC->_float = (OPA->vector[0] == OPB->vector[0]) && (OPA->vector[1] == OPB->vector[1]) && (OPA->vector[2] == OPB->vector[2]);
100 OPC->_float = !strcmp(PR_GetString(OPA->string),PR_GetString(OPB->string));
103 OPC->_float = OPA->_int == OPB->_int;
106 OPC->_float = OPA->function == OPB->function;
109 OPC->_float = OPA->_float != OPB->_float;
112 OPC->_float = (OPA->vector[0] != OPB->vector[0]) || (OPA->vector[1] != OPB->vector[1]) || (OPA->vector[2] != OPB->vector[2]);
115 OPC->_float = strcmp(PR_GetString(OPA->string),PR_GetString(OPB->string));
118 OPC->_float = OPA->_int != OPB->_int;
121 OPC->_float = OPA->function != OPB->function;
127 case OP_STORE_FLD: // integers
129 case OP_STORE_FNC: // pointers
130 OPB->_int = OPA->_int;
133 OPB->ivector[0] = OPA->ivector[0];
134 OPB->ivector[1] = OPA->ivector[1];
135 OPB->ivector[2] = OPA->ivector[2];
140 case OP_STOREP_FLD: // integers
142 case OP_STOREP_FNC: // pointers
144 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
146 pr_xstatement = st - pr_statements;
147 Host_Error("Progs attempted to write to an out of bounds edict (%i)\n", OPB->_int);
151 ptr = (eval_t *)((qbyte *)sv.edictsfields + OPB->_int);
152 ptr->_int = OPA->_int;
156 if (OPB->_int < 0 || OPB->_int + 12 > pr_edictareasize)
158 pr_xstatement = st - pr_statements;
159 Host_Error("Progs attempted to write to an out of bounds edict (%i)\n", OPB->_int);
163 ptr = (eval_t *)((qbyte *)sv.edictsfields + OPB->_int);
164 ptr->vector[0] = OPA->vector[0];
165 ptr->vector[1] = OPA->vector[1];
166 ptr->vector[2] = OPA->vector[2];
170 pr_xstatement = st - pr_statements;
172 if ((unsigned int)(OPB->_int) >= (unsigned int)(progs->entityfields))
174 Host_Error("Progs attempted to address an invalid field (%i) in an edict\n", OPB->_int);
178 if (OPA->edict == 0 && sv.state == ss_active)
180 Host_Error ("assignment to world entity");
183 ed = PROG_TO_EDICT(OPA->edict);
184 OPC->_int = (qbyte *)((int *)ed->v + OPB->_int) - (qbyte *)sv.edictsfields;
192 pr_xstatement = st - pr_statements;
194 if ((unsigned int)(OPB->_int) >= (unsigned int)(progs->entityfields))
196 Host_Error("Progs attempted to read an invalid field in an edict (%i)\n", OPB->_int);
200 ed = PROG_TO_EDICT(OPA->edict);
201 OPC->_int = ((eval_t *)((int *)ed->v + OPB->_int))->_int;
205 pr_xstatement = st - pr_statements;
207 if (OPB->_int < 0 || OPB->_int + 2 >= progs->entityfields)
209 Host_Error("Progs attempted to read an invalid field in an edict (%i)\n", OPB->_int);
213 ed = PROG_TO_EDICT(OPA->edict);
214 OPC->vector[0] = ((eval_t *)((int *)ed->v + OPB->_int))->vector[0];
215 OPC->vector[1] = ((eval_t *)((int *)ed->v + OPB->_int))->vector[1];
216 OPC->vector[2] = ((eval_t *)((int *)ed->v + OPB->_int))->vector[2];
223 st += st->b - 1; // offset the s++
228 st += st->b - 1; // offset the s++
232 st += st->a - 1; // offset the s++
244 pr_xfunction->profile += profile - startprofile;
245 startprofile = profile;
246 pr_xstatement = st - pr_statements;
247 pr_argc = st->op - OP_CALL0;
249 Host_Error ("NULL function");
251 newf = &pr_functions[OPA->function];
253 if (newf->first_statement < 0)
255 // negative statements are built in functions
256 if ((-newf->first_statement) >= pr_numbuiltins)
257 Host_Error ("Bad builtin call number");
258 pr_xfunction->builtinsprofile++;
259 pr_builtins[-newf->first_statement] ();
262 st = pr_statements + PR_EnterFunction(newf);
267 pr_globals[OFS_RETURN] = pr_globals[(unsigned short) st->a];
268 pr_globals[OFS_RETURN+1] = pr_globals[(unsigned short) st->a+1];
269 pr_globals[OFS_RETURN+2] = pr_globals[(unsigned short) st->a+2];
271 st = pr_statements + PR_LeaveFunction();
272 if (pr_depth <= exitdepth)
274 if (pr_trace != cachedpr_trace)
275 goto chooseexecprogram;
279 ed = PROG_TO_EDICT(pr_global_struct->self);
280 ed->v->nextthink = pr_global_struct->time + 0.1;
281 ed->v->frame = OPA->_float;
282 ed->v->think = OPB->function;
285 // LordHavoc: to be enabled when Progs version 7 (or whatever it will be numbered) is finalized
288 OPC->_int = OPA->_int + OPB->_int;
291 OPC->_int = OPA->_int + (int) OPB->_float;
294 OPC->_float = OPA->_float + (float) OPB->_int;
297 OPC->_int = OPA->_int - OPB->_int;
300 OPC->_int = OPA->_int - (int) OPB->_float;
303 OPC->_float = OPA->_float - (float) OPB->_int;
306 OPC->_int = OPA->_int * OPB->_int;
309 OPC->_int = OPA->_int * (int) OPB->_float;
312 OPC->_float = OPA->_float * (float) OPB->_int;
315 OPC->vector[0] = (float) OPB->_int * OPA->vector[0];
316 OPC->vector[1] = (float) OPB->_int * OPA->vector[1];
317 OPC->vector[2] = (float) OPB->_int * OPA->vector[2];
321 float temp = 1.0f / OPB->_float;
322 OPC->vector[0] = temp * OPA->vector[0];
323 OPC->vector[1] = temp * OPA->vector[1];
324 OPC->vector[2] = temp * OPA->vector[2];
328 OPC->_int = OPA->_int / OPB->_int;
331 OPC->_int = OPA->_int / (int) OPB->_float;
334 OPC->_float = OPA->_float / (float) OPB->_int;
337 OPC->_float = OPA->_int;
340 OPC->_int = OPA->_float;
343 OPC->_int = OPA->_int & OPB->_int;
346 OPC->_int = OPA->_int | OPB->_int;
349 OPC->_int = OPA->_int & (int)OPB->_float;
352 OPC->_int = OPA->_int | (int)OPB->_float;
355 OPC->_float = (int)OPA->_float & OPB->_int;
358 OPC->_float = (int)OPA->_float | OPB->_int;
361 OPC->_float = OPA->_int >= OPB->_int;
364 OPC->_float = OPA->_int <= OPB->_int;
367 OPC->_float = OPA->_int > OPB->_int;
370 OPC->_float = OPA->_int < OPB->_int;
373 OPC->_float = OPA->_int && OPB->_int;
376 OPC->_float = OPA->_int || OPB->_int;
379 OPC->_float = (float)OPA->_int >= OPB->_float;
382 OPC->_float = (float)OPA->_int <= OPB->_float;
385 OPC->_float = (float)OPA->_int > OPB->_float;
388 OPC->_float = (float)OPA->_int < OPB->_float;
391 OPC->_float = (float)OPA->_int && OPB->_float;
394 OPC->_float = (float)OPA->_int || OPB->_float;
397 OPC->_float = OPA->_float >= (float)OPB->_int;
400 OPC->_float = OPA->_float <= (float)OPB->_int;
403 OPC->_float = OPA->_float > (float)OPB->_int;
406 OPC->_float = OPA->_float < (float)OPB->_int;
409 OPC->_float = OPA->_float && (float)OPB->_int;
412 OPC->_float = OPA->_float || (float)OPB->_int;
415 OPC->_float = !OPA->_int;
418 OPC->_float = OPA->_int == OPB->_int;
421 OPC->_float = (float)OPA->_int == OPB->_float;
424 OPC->_float = OPA->_float == (float)OPB->_int;
427 OPC->_float = OPA->_int != OPB->_int;
430 OPC->_float = (float)OPA->_int != OPB->_float;
433 OPC->_float = OPA->_float != (float)OPB->_int;
436 OPB->_int = OPA->_int;
440 if (OPB->_int < 0 || OPB->_int + 4 > pr_edictareasize)
442 pr_xstatement = st - pr_statements;
443 Host_Error("Progs attempted to write to an out of bounds edict\n");
447 ptr = (eval_t *)((qbyte *)sv.edictsfields + OPB->_int);
448 ptr->_int = OPA->_int;
452 if (OPA->edict < 0 || OPA->edict >= pr_edictareasize)
454 pr_xstatement = st - pr_statements;
455 Host_Error("Progs attempted to read an out of bounds edict number\n");
458 if (OPB->_int < 0 || OPB->_int >= progs->entityfields)
460 pr_xstatement = st - pr_statements;
461 Host_Error("Progs attempted to read an invalid field in an edict\n");
465 ed = PROG_TO_EDICT(OPA->edict);
466 OPC->_int = ((eval_t *)((int *)ed->v + OPB->_int))->_int;
472 case OP_GSTOREP_FLD: // integers
474 case OP_GSTOREP_FNC: // pointers
476 if (OPB->_int < 0 || OPB->_int >= pr_globaldefs)
478 pr_xstatement = st - pr_statements;
479 Host_Error("Progs attempted to write to an invalid indexed global\n");
483 pr_globals[OPB->_int] = OPA->_float;
487 if (OPB->_int < 0 || OPB->_int + 2 >= pr_globaldefs)
489 pr_xstatement = st - pr_statements;
490 Host_Error("Progs attempted to write to an invalid indexed global\n");
494 pr_globals[OPB->_int ] = OPA->vector[0];
495 pr_globals[OPB->_int+1] = OPA->vector[1];
496 pr_globals[OPB->_int+2] = OPA->vector[2];
500 i = OPA->_int + (int) OPB->_float;
502 if (i < 0 || i >= pr_globaldefs)
504 pr_xstatement = st - pr_statements;
505 Host_Error("Progs attempted to address an out of bounds global\n");
509 OPC->_float = pr_globals[i];
519 if (OPA->_int < 0 || OPA->_int >= pr_globaldefs)
521 pr_xstatement = st - pr_statements;
522 Host_Error("Progs attempted to read an invalid indexed global\n");
526 OPC->_float = pr_globals[OPA->_int];
531 if (OPA->_int < 0 || OPA->_int + 2 >= pr_globaldefs)
533 pr_xstatement = st - pr_statements;
534 Host_Error("Progs attempted to read an invalid indexed global\n");
538 OPC->vector[0] = pr_globals[OPA->_int ];
539 OPC->vector[1] = pr_globals[OPA->_int+1];
540 OPC->vector[2] = pr_globals[OPA->_int+2];
544 if (OPA->_int < 0 || OPA->_int >= st->b)
546 pr_xstatement = st - pr_statements;
547 Host_Error("Progs boundcheck failed at line number %d, value is < 0 or >= %d\n", st->b, st->c);
555 pr_xstatement = st - pr_statements;
556 Host_Error ("Bad opcode %i", st->op);