Annotation of quake1/pr_cmds.c, revision 1.1.1.2

1.1       root        1: 
                      2: #include "quakedef.h"
                      3: 
                      4: #define        RETURN_EDICT(e) (((int *)pr_globals)[OFS_RETURN] = EDICT_TO_PROG(e))
                      5: 
                      6: /*
                      7: ===============================================================================
                      8: 
                      9:                                                BUILT-IN FUNCTIONS
                     10: 
                     11: ===============================================================================
                     12: */
                     13: 
                     14: char *PF_VarString (int        first)
                     15: {
                     16:        int             i;
                     17:        static char out[256];
                     18:        
                     19:        out[0] = 0;
                     20:        for (i=first ; i<pr_argc ; i++)
                     21:        {
                     22:                strcat (out, G_STRING((OFS_PARM0+i*3)));
                     23:        }
                     24:        return out;
                     25: }
                     26: 
                     27: 
                     28: /*
                     29: =================
                     30: PF_errror
                     31: 
                     32: This is a TERMINAL error, which will kill off the entire server.
                     33: Dumps self.
                     34: 
                     35: error(value)
                     36: =================
                     37: */
                     38: void PF_error (void)
                     39: {
                     40:        char    *s;
                     41:        edict_t *ed;
                     42:        
                     43:        s = PF_VarString(0);
                     44:        Con_Printf ("======SERVER ERROR in %s:\n%s\n"
                     45:        ,pr_strings + pr_xfunction->s_name,s);
                     46:        ed = PROG_TO_EDICT(pr_global_struct->self);
                     47:        ED_Print (ed);
                     48: 
                     49:        Host_Error ("Program error");
                     50: }
                     51: 
                     52: /*
                     53: =================
                     54: PF_objerror
                     55: 
                     56: Dumps out self, then an error message.  The program is aborted and self is
                     57: removed, but the level can continue.
                     58: 
                     59: objerror(value)
                     60: =================
                     61: */
                     62: void PF_objerror (void)
                     63: {
                     64:        char    *s;
                     65:        edict_t *ed;
                     66:        
                     67:        s = PF_VarString(0);
                     68:        Con_Printf ("======OBJECT ERROR in %s:\n%s\n"
                     69:        ,pr_strings + pr_xfunction->s_name,s);
                     70:        ed = PROG_TO_EDICT(pr_global_struct->self);
                     71:        ED_Print (ed);
                     72:        ED_Free (ed);
                     73:        
                     74:        Host_Error ("Program error");
                     75: }
                     76: 
                     77: 
                     78: 
                     79: /*
                     80: ==============
                     81: PF_makevectors
                     82: 
                     83: Writes new values for v_forward, v_up, and v_right based on angles
                     84: makevectors(vector)
                     85: ==============
                     86: */
                     87: void PF_makevectors (void)
                     88: {
                     89:        AngleVectors (G_VECTOR(OFS_PARM0), pr_global_struct->v_forward, pr_global_struct->v_right, pr_global_struct->v_up);
                     90: }
                     91: 
                     92: /*
                     93: =================
                     94: PF_setorigin
                     95: 
                     96: This is the only valid way to move an object without using the physics of the world (setting velocity and waiting).  Directly changing origin will not set internal links correctly, so clipping would be messed up.  This should be called when an object is spawned, and then only if it is teleported.
                     97: 
                     98: setorigin (entity, origin)
                     99: =================
                    100: */
                    101: void PF_setorigin (void)
                    102: {
                    103:        edict_t *e;
                    104:        float   *org;
                    105:        
                    106:        e = G_EDICT(OFS_PARM0);
                    107:        org = G_VECTOR(OFS_PARM1);
                    108:        VectorCopy (org, e->v.origin);
                    109:        SV_LinkEdict (e, false);
                    110: }
                    111: 
                    112: 
                    113: void SetMinMaxSize (edict_t *e, float *min, float *max, qboolean rotate)
                    114: {
                    115:        float   *angles;
                    116:        vec3_t  rmin, rmax;
                    117:        float   bounds[2][3];
                    118:        float   xvector[2], yvector[2];
                    119:        float   a;
                    120:        vec3_t  base, transformed;
                    121:        int             i, j, k, l;
                    122:        
                    123:        for (i=0 ; i<3 ; i++)
                    124:                if (min[i] > max[i])
                    125:                        PR_RunError ("backwards mins/maxs");
                    126: 
                    127:        rotate = false;         // FIXME: implement rotation properly again
                    128: 
                    129:        if (!rotate)
                    130:        {
                    131:                VectorCopy (min, rmin);
                    132:                VectorCopy (max, rmax);
                    133:        }
                    134:        else
                    135:        {
                    136:        // find min / max for rotations
                    137:                angles = e->v.angles;
                    138:                
                    139:                a = angles[1]/180 * M_PI;
                    140:                
                    141:                xvector[0] = cos(a);
                    142:                xvector[1] = sin(a);
                    143:                yvector[0] = -sin(a);
                    144:                yvector[1] = cos(a);
                    145:                
                    146:                VectorCopy (min, bounds[0]);
                    147:                VectorCopy (max, bounds[1]);
                    148:                
                    149:                rmin[0] = rmin[1] = rmin[2] = 9999;
                    150:                rmax[0] = rmax[1] = rmax[2] = -9999;
                    151:                
                    152:                for (i=0 ; i<= 1 ; i++)
                    153:                {
                    154:                        base[0] = bounds[i][0];
                    155:                        for (j=0 ; j<= 1 ; j++)
                    156:                        {
                    157:                                base[1] = bounds[j][1];
                    158:                                for (k=0 ; k<= 1 ; k++)
                    159:                                {
                    160:                                        base[2] = bounds[k][2];
                    161:                                        
                    162:                                // transform the point
                    163:                                        transformed[0] = xvector[0]*base[0] + yvector[0]*base[1];
                    164:                                        transformed[1] = xvector[1]*base[0] + yvector[1]*base[1];
                    165:                                        transformed[2] = base[2];
                    166:                                        
                    167:                                        for (l=0 ; l<3 ; l++)
                    168:                                        {
                    169:                                                if (transformed[l] < rmin[l])
                    170:                                                        rmin[l] = transformed[l];
                    171:                                                if (transformed[l] > rmax[l])
                    172:                                                        rmax[l] = transformed[l];
                    173:                                        }
                    174:                                }
                    175:                        }
                    176:                }
                    177:        }
                    178:        
                    179: // set derived values
                    180:        VectorCopy (rmin, e->v.mins);
                    181:        VectorCopy (rmax, e->v.maxs);
                    182:        VectorSubtract (max, min, e->v.size);
                    183:        
                    184:        SV_LinkEdict (e, false);
                    185: }
                    186: 
                    187: /*
                    188: =================
                    189: PF_setsize
                    190: 
                    191: the size box is rotated by the current angle
                    192: 
                    193: setsize (entity, minvector, maxvector)
                    194: =================
                    195: */
                    196: void PF_setsize (void)
                    197: {
                    198:        edict_t *e;
                    199:        float   *min, *max;
                    200:        
                    201:        e = G_EDICT(OFS_PARM0);
                    202:        min = G_VECTOR(OFS_PARM1);
                    203:        max = G_VECTOR(OFS_PARM2);
                    204:        SetMinMaxSize (e, min, max, false);
                    205: }
                    206: 
                    207: 
                    208: /*
                    209: =================
                    210: PF_setmodel
                    211: 
                    212: setmodel(entity, model)
                    213: =================
                    214: */
                    215: void PF_setmodel (void)
                    216: {
                    217:        edict_t *e;
                    218:        char    *m, **check;
                    219:        model_t *mod;
                    220:        int             i;
                    221: 
                    222:        e = G_EDICT(OFS_PARM0);
                    223:        m = G_STRING(OFS_PARM1);
                    224: 
                    225: // check to see if model was properly precached
                    226:        for (i=0, check = sv.model_precache ; *check ; i++, check++)
                    227:                if (!strcmp(*check, m))
                    228:                        break;
                    229:                        
                    230:        if (!*check)
                    231:                PR_RunError ("no precache: %s\n", m);
                    232:                
                    233: 
                    234:        e->v.model = m - pr_strings;
                    235:        e->v.modelindex = i; //SV_ModelIndex (m);
                    236: 
                    237:        mod = sv.models[ (int)e->v.modelindex];  // Mod_ForName (m, true);
                    238:        
                    239:        if (mod)
                    240:                SetMinMaxSize (e, mod->mins, mod->maxs, true);
                    241:        else
                    242:                SetMinMaxSize (e, vec3_origin, vec3_origin, true);
                    243: }
                    244: 
                    245: /*
                    246: =================
                    247: PF_bprint
                    248: 
                    249: broadcast print to everyone on server
                    250: 
                    251: bprint(value)
                    252: =================
                    253: */
                    254: void PF_bprint (void)
                    255: {
                    256:        char            *s;
                    257: 
                    258:        s = PF_VarString(0);
1.1.1.2 ! root      259:        SV_BroadcastPrintf ("%s", s);
1.1       root      260: }
                    261: 
                    262: /*
                    263: =================
                    264: PF_sprint
                    265: 
                    266: single print to a specific client
                    267: 
                    268: sprint(clientent, value)
                    269: =================
                    270: */
                    271: void PF_sprint (void)
                    272: {
                    273:        char            *s;
                    274:        client_t        *client;
                    275:        int                     entnum;
                    276:        
                    277:        entnum = G_EDICTNUM(OFS_PARM0);
                    278:        s = PF_VarString(1);
                    279:        
                    280:        if (entnum < 1 || entnum > svs.maxclients)
                    281:        {
                    282:                Con_Printf ("tried to sprint to a non-client\n");
                    283:                return;
                    284:        }
                    285:                
                    286:        client = &svs.clients[entnum-1];
                    287:                
                    288:        MSG_WriteChar (&client->message,svc_print);
                    289:        MSG_WriteString (&client->message, s );
                    290: }
                    291: 
                    292: 
                    293: /*
                    294: =================
                    295: PF_centerprint
                    296: 
                    297: single print to a specific client
                    298: 
                    299: centerprint(clientent, value)
                    300: =================
                    301: */
                    302: void PF_centerprint (void)
                    303: {
                    304:        char            *s;
                    305:        client_t        *client;
                    306:        int                     entnum;
                    307:        
                    308:        entnum = G_EDICTNUM(OFS_PARM0);
                    309:        s = PF_VarString(1);
                    310:        
                    311:        if (entnum < 1 || entnum > svs.maxclients)
                    312:        {
                    313:                Con_Printf ("tried to sprint to a non-client\n");
                    314:                return;
                    315:        }
                    316:                
                    317:        client = &svs.clients[entnum-1];
                    318:                
                    319:        MSG_WriteChar (&client->message,svc_centerprint);
                    320:        MSG_WriteString (&client->message, s );
                    321: }
                    322: 
                    323: 
                    324: /*
                    325: =================
                    326: PF_normalize
                    327: 
                    328: vector normalize(vector)
                    329: =================
                    330: */
                    331: void PF_normalize (void)
                    332: {
                    333:        float   *value1;
                    334:        vec3_t  newvalue;
                    335:        float   new;
                    336:        
                    337:        value1 = G_VECTOR(OFS_PARM0);
                    338: 
                    339:        new = value1[0] * value1[0] + value1[1] * value1[1] + value1[2]*value1[2];
                    340:        new = sqrt(new);
                    341:        
                    342:        if (new == 0)
                    343:                newvalue[0] = newvalue[1] = newvalue[2] = 0;
                    344:        else
                    345:        {
                    346:                new = 1/new;
                    347:                newvalue[0] = value1[0] * new;
                    348:                newvalue[1] = value1[1] * new;
                    349:                newvalue[2] = value1[2] * new;
                    350:        }
                    351:        
                    352:        VectorCopy (newvalue, G_VECTOR(OFS_RETURN));    
                    353: }
                    354: 
                    355: /*
                    356: =================
                    357: PF_vlen
                    358: 
                    359: scalar vlen(vector)
                    360: =================
                    361: */
                    362: void PF_vlen (void)
                    363: {
                    364:        float   *value1;
                    365:        float   new;
                    366:        
                    367:        value1 = G_VECTOR(OFS_PARM0);
                    368: 
                    369:        new = value1[0] * value1[0] + value1[1] * value1[1] + value1[2]*value1[2];
                    370:        new = sqrt(new);
                    371:        
                    372:        G_FLOAT(OFS_RETURN) = new;
                    373: }
                    374: 
                    375: /*
                    376: =================
                    377: PF_vectoyaw
                    378: 
                    379: float vectoyaw(vector)
                    380: =================
                    381: */
                    382: void PF_vectoyaw (void)
                    383: {
                    384:        float   *value1;
                    385:        float   yaw;
                    386:        
                    387:        value1 = G_VECTOR(OFS_PARM0);
                    388: 
                    389:        if (value1[1] == 0 && value1[0] == 0)
                    390:                yaw = 0;
                    391:        else
                    392:        {
                    393:                yaw = (int) (atan2(value1[1], value1[0]) * 180 / M_PI);
                    394:                if (yaw < 0)
                    395:                        yaw += 360;
                    396:        }
                    397: 
                    398:        G_FLOAT(OFS_RETURN) = yaw;
                    399: }
                    400: 
                    401: 
                    402: /*
                    403: =================
                    404: PF_vectoangles
                    405: 
                    406: vector vectoangles(vector)
                    407: =================
                    408: */
                    409: void PF_vectoangles (void)
                    410: {
                    411:        float   *value1;
                    412:        float   forward;
                    413:        float   yaw, pitch;
                    414:        
                    415:        value1 = G_VECTOR(OFS_PARM0);
                    416: 
                    417:        if (value1[1] == 0 && value1[0] == 0)
                    418:        {
                    419:                yaw = 0;
                    420:                if (value1[2] > 0)
                    421:                        pitch = 90;
                    422:                else
                    423:                        pitch = 270;
                    424:        }
                    425:        else
                    426:        {
                    427:                yaw = (int) (atan2(value1[1], value1[0]) * 180 / M_PI);
                    428:                if (yaw < 0)
                    429:                        yaw += 360;
                    430: 
                    431:                forward = sqrt (value1[0]*value1[0] + value1[1]*value1[1]);
                    432:                pitch = (int) (atan2(value1[2], forward) * 180 / M_PI);
                    433:                if (pitch < 0)
                    434:                        pitch += 360;
                    435:        }
                    436: 
                    437:        G_FLOAT(OFS_RETURN+0) = pitch;
                    438:        G_FLOAT(OFS_RETURN+1) = yaw;
                    439:        G_FLOAT(OFS_RETURN+2) = 0;
                    440: }
                    441: 
                    442: /*
                    443: =================
                    444: PF_Random
                    445: 
                    446: Returns a number from 0<= num < 1
                    447: 
                    448: random()
                    449: =================
                    450: */
                    451: void PF_random (void)
                    452: {
                    453:        float           num;
                    454:                
                    455:        num = (rand ()&0x7fff) / ((float)0x7fff);
                    456:        
                    457:        G_FLOAT(OFS_RETURN) = num;
                    458: }
                    459: 
                    460: /*
                    461: =================
                    462: PF_particle
                    463: 
                    464: particle(origin, color, count)
                    465: =================
                    466: */
                    467: void PF_particle (void)
                    468: {
                    469:        float           *org, *dir;
                    470:        float           color;
                    471:        float           count;
                    472:                        
                    473:        org = G_VECTOR(OFS_PARM0);
                    474:        dir = G_VECTOR(OFS_PARM1);
                    475:        color = G_FLOAT(OFS_PARM2);
                    476:        count = G_FLOAT(OFS_PARM3);
                    477:        SV_StartParticle (org, dir, color, count);
                    478: }
                    479: 
                    480: 
                    481: /*
                    482: =================
                    483: PF_ambientsound
                    484: 
                    485: =================
                    486: */
                    487: void PF_ambientsound (void)
                    488: {
                    489:        char            **check;
                    490:        char            *samp;
                    491:        float           *pos;
                    492:        float           vol, attenuation;
                    493:        int                     i, soundnum;
                    494: 
                    495:        pos = G_VECTOR (OFS_PARM0);                     
                    496:        samp = G_STRING(OFS_PARM1);
                    497:        vol = G_FLOAT(OFS_PARM2);
                    498:        attenuation = G_FLOAT(OFS_PARM3);
                    499:        
                    500: // check to see if samp was properly precached
                    501:        for (soundnum=0, check = sv.sound_precache ; *check ; check++, soundnum++)
                    502:                if (!strcmp(*check,samp))
                    503:                        break;
                    504:                        
                    505:        if (!*check)
                    506:        {
                    507:                Con_Printf ("no precache: %s\n", samp);
                    508:                return;
                    509:        }
                    510: 
                    511: // add an svc_spawnambient command to the level signon packet
                    512: 
                    513:        MSG_WriteByte (&sv.signon,svc_spawnstaticsound);
                    514:        for (i=0 ; i<3 ; i++)
                    515:                MSG_WriteCoord(&sv.signon, pos[i]);
                    516: 
                    517:        MSG_WriteByte (&sv.signon, soundnum);
                    518: 
                    519:        MSG_WriteByte (&sv.signon, vol*255);
                    520:        MSG_WriteByte (&sv.signon, attenuation*64);
                    521: 
                    522: }
                    523: 
                    524: /*
                    525: =================
                    526: PF_sound
                    527: 
                    528: Each entity can have eight independant sound sources, like voice,
                    529: weapon, feet, etc.
                    530: 
                    531: Channel 0 is an auto-allocate channel, the others override anything
                    532: allready running on that entity/channel pair.
                    533: 
                    534: An attenuation of 0 will play full volume everywhere in the level.
                    535: Larger attenuations will drop off.
                    536: 
                    537: =================
                    538: */
                    539: void PF_sound (void)
                    540: {
                    541:        char            *sample;
                    542:        int                     channel;
                    543:        edict_t         *entity;
                    544:        int             volume;
                    545:        float attenuation;
                    546:                
                    547:        entity = G_EDICT(OFS_PARM0);
                    548:        channel = G_FLOAT(OFS_PARM1);
                    549:        sample = G_STRING(OFS_PARM2);
                    550:        volume = G_FLOAT(OFS_PARM3) * 255;
                    551:        attenuation = G_FLOAT(OFS_PARM4);
                    552:        
                    553:        if (volume < 0 || volume > 255)
                    554:                Sys_Error ("SV_StartSound: volume = %i", volume);
                    555: 
                    556:        if (attenuation < 0 || attenuation > 4)
                    557:                Sys_Error ("SV_StartSound: attenuation = %f", attenuation);
                    558: 
                    559:        if (channel < 0 || channel > 7)
                    560:                Sys_Error ("SV_StartSound: channel = %i", channel);
                    561: 
                    562:        SV_StartSound (entity, channel, sample, volume, attenuation);
                    563: }
                    564: 
                    565: /*
                    566: =================
                    567: PF_break
                    568: 
                    569: break()
                    570: =================
                    571: */
                    572: void PF_break (void)
                    573: {
                    574: Con_Printf ("break statement\n");
                    575: *(int *)-4 = 0;        // dump to debugger
                    576: //     PR_RunError ("break statement");
                    577: }
                    578: 
                    579: /*
                    580: =================
                    581: PF_traceline
                    582: 
                    583: Used for use tracing and shot targeting
                    584: Traces are blocked by bbox and exact bsp entityes, and also slide box entities
                    585: if the tryents flag is set.
                    586: 
                    587: traceline (vector1, vector2, tryents)
                    588: =================
                    589: */
                    590: void PF_traceline (void)
                    591: {
                    592:        float   *v1, *v2;
                    593:        trace_t trace;
                    594:        int             nomonsters;
                    595:        edict_t *ent;
                    596: 
                    597:        v1 = G_VECTOR(OFS_PARM0);
                    598:        v2 = G_VECTOR(OFS_PARM1);
                    599:        nomonsters = G_FLOAT(OFS_PARM2);
                    600:        ent = G_EDICT(OFS_PARM3);
                    601: 
                    602:        trace = SV_Move (v1, vec3_origin, vec3_origin, v2, nomonsters, ent);
                    603: 
                    604:        pr_global_struct->trace_allsolid = trace.allsolid;
                    605:        pr_global_struct->trace_startsolid = trace.startsolid;
                    606:        pr_global_struct->trace_fraction = trace.fraction;
                    607:        pr_global_struct->trace_inwater = trace.inwater;
                    608:        pr_global_struct->trace_inopen = trace.inopen;
                    609:        VectorCopy (trace.endpos, pr_global_struct->trace_endpos);
                    610:        VectorCopy (trace.plane.normal, pr_global_struct->trace_plane_normal);
                    611:        pr_global_struct->trace_plane_dist =  trace.plane.dist; 
                    612:        if (trace.ent)
                    613:                pr_global_struct->trace_ent = EDICT_TO_PROG(trace.ent);
                    614:        else
                    615:                pr_global_struct->trace_ent = EDICT_TO_PROG(sv.edicts);
                    616: }
                    617: 
1.1.1.2 ! root      618: 
        !           619: #ifdef QUAKE2
        !           620: extern trace_t SV_Trace_Toss (edict_t *ent, edict_t *ignore);
        !           621: 
        !           622: void PF_TraceToss (void)
        !           623: {
        !           624:        trace_t trace;
        !           625:        edict_t *ent;
        !           626:        edict_t *ignore;
        !           627: 
        !           628:        ent = G_EDICT(OFS_PARM0);
        !           629:        ignore = G_EDICT(OFS_PARM1);
        !           630: 
        !           631:        trace = SV_Trace_Toss (ent, ignore);
        !           632: 
        !           633:        pr_global_struct->trace_allsolid = trace.allsolid;
        !           634:        pr_global_struct->trace_startsolid = trace.startsolid;
        !           635:        pr_global_struct->trace_fraction = trace.fraction;
        !           636:        pr_global_struct->trace_inwater = trace.inwater;
        !           637:        pr_global_struct->trace_inopen = trace.inopen;
        !           638:        VectorCopy (trace.endpos, pr_global_struct->trace_endpos);
        !           639:        VectorCopy (trace.plane.normal, pr_global_struct->trace_plane_normal);
        !           640:        pr_global_struct->trace_plane_dist =  trace.plane.dist; 
        !           641:        if (trace.ent)
        !           642:                pr_global_struct->trace_ent = EDICT_TO_PROG(trace.ent);
        !           643:        else
        !           644:                pr_global_struct->trace_ent = EDICT_TO_PROG(sv.edicts);
        !           645: }
        !           646: #endif
        !           647: 
        !           648: 
1.1       root      649: /*
                    650: =================
                    651: PF_checkpos
                    652: 
                    653: Returns true if the given entity can move to the given position from it's
                    654: current position by walking or rolling.
                    655: FIXME: make work...
                    656: scalar checkpos (entity, vector)
                    657: =================
                    658: */
                    659: void PF_checkpos (void)
                    660: {
                    661: }
                    662: 
                    663: //============================================================================
                    664: 
                    665: byte   checkpvs[MAX_MAP_LEAFS/8];
                    666: 
                    667: int PF_newcheckclient (int check)
                    668: {
                    669:        int             i;
                    670:        byte    *pvs;
                    671:        edict_t *ent;
                    672:        mleaf_t *leaf;
                    673:        vec3_t  org;
                    674: 
                    675: // cycle to the next one
                    676: 
                    677:        if (check < 1)
                    678:                check = 1;
                    679:        if (check > svs.maxclients)
                    680:                check = svs.maxclients;
                    681: 
                    682:        if (check == svs.maxclients)
                    683:                i = 1;
                    684:        else
                    685:                i = check + 1;
                    686: 
                    687:        for ( ;  ; i++)
                    688:        {
                    689:                if (i == svs.maxclients+1)
                    690:                        i = 1;
                    691: 
                    692:                ent = EDICT_NUM(i);
                    693: 
                    694:                if (i == check)
                    695:                        break;  // didn't find anything else
                    696: 
                    697:                if (ent->free)
                    698:                        continue;
                    699:                if (ent->v.health <= 0)
                    700:                        continue;
                    701:                if ((int)ent->v.flags & FL_NOTARGET)
                    702:                        continue;
                    703: 
                    704:        // anything that is a client, or has a client as an enemy
                    705:                break;
                    706:        }
                    707: 
                    708: // get the PVS for the entity
                    709:        VectorAdd (ent->v.origin, ent->v.view_ofs, org);
                    710:        leaf = Mod_PointInLeaf (org, sv.worldmodel);
                    711:        pvs = Mod_LeafPVS (leaf, sv.worldmodel);
                    712:        memcpy (checkpvs, pvs, (sv.worldmodel->numleafs+7)>>3 );
                    713: 
                    714:        return i;
                    715: }
                    716: 
                    717: /*
                    718: =================
                    719: PF_checkclient
                    720: 
                    721: Returns a client (or object that has a client enemy) that would be a
                    722: valid target.
                    723: 
                    724: If there are more than one valid options, they are cycled each frame
                    725: 
                    726: If (self.origin + self.viewofs) is not in the PVS of the current target,
                    727: it is not returned at all.
                    728: 
                    729: name checkclient ()
                    730: =================
                    731: */
                    732: #define        MAX_CHECK       16
                    733: int c_invis, c_notvis;
                    734: void PF_checkclient (void)
                    735: {
                    736:        edict_t *ent, *self;
                    737:        mleaf_t *leaf;
                    738:        int             l;
                    739:        vec3_t  view;
                    740:        
                    741: // find a new check if on a new frame
                    742:        if (sv.time - sv.lastchecktime >= 0.1)
                    743:        {
                    744:                sv.lastcheck = PF_newcheckclient (sv.lastcheck);
                    745:                sv.lastchecktime = sv.time;
                    746:        }
                    747: 
                    748: // return check if it might be visible 
                    749:        ent = EDICT_NUM(sv.lastcheck);
                    750:        if (ent->free || ent->v.health <= 0)
                    751:        {
                    752:                RETURN_EDICT(sv.edicts);
                    753:                return;
                    754:        }
                    755: 
                    756: // if current entity can't possibly see the check entity, return 0
                    757:        self = PROG_TO_EDICT(pr_global_struct->self);
                    758:        VectorAdd (self->v.origin, self->v.view_ofs, view);
                    759:        leaf = Mod_PointInLeaf (view, sv.worldmodel);
                    760:        l = (leaf - sv.worldmodel->leafs) - 1;
                    761:        if ( (l<0) || !(checkpvs[l>>3] & (1<<(l&7)) ) )
                    762:        {
                    763: c_notvis++;
                    764:                RETURN_EDICT(sv.edicts);
                    765:                return;
                    766:        }
                    767: 
                    768: // might be able to see it
                    769: c_invis++;
                    770:        RETURN_EDICT(ent);
                    771: }
                    772: 
                    773: //============================================================================
                    774: 
                    775: 
                    776: /*
                    777: =================
                    778: PF_stuffcmd
                    779: 
                    780: Sends text over to the client's execution buffer
                    781: 
                    782: stuffcmd (clientent, value)
                    783: =================
                    784: */
                    785: void PF_stuffcmd (void)
                    786: {
                    787:        int             entnum;
                    788:        char    *str;
                    789:        client_t        *old;
                    790:        
                    791:        entnum = G_EDICTNUM(OFS_PARM0);
                    792:        if (entnum < 1 || entnum > svs.maxclients)
                    793:                PR_RunError ("Parm 0 not a client");
                    794:        str = G_STRING(OFS_PARM1);      
                    795:        
                    796:        old = host_client;
                    797:        host_client = &svs.clients[entnum-1];
                    798:        Host_ClientCommands ("%s", str);
                    799:        host_client = old;
                    800: }
                    801: 
                    802: /*
                    803: =================
                    804: PF_localcmd
                    805: 
                    806: Sends text over to the client's execution buffer
                    807: 
                    808: localcmd (string)
                    809: =================
                    810: */
                    811: void PF_localcmd (void)
                    812: {
                    813:        char    *str;
                    814:        
                    815:        str = G_STRING(OFS_PARM0);      
                    816:        Cbuf_AddText (str);
                    817: }
                    818: 
                    819: /*
                    820: =================
                    821: PF_cvar
                    822: 
                    823: float cvar (string)
                    824: =================
                    825: */
                    826: void PF_cvar (void)
                    827: {
                    828:        char    *str;
                    829:        
                    830:        str = G_STRING(OFS_PARM0);
                    831:        
                    832:        G_FLOAT(OFS_RETURN) = Cvar_VariableValue (str);
                    833: }
                    834: 
                    835: /*
                    836: =================
                    837: PF_cvar_set
                    838: 
                    839: float cvar (string)
                    840: =================
                    841: */
                    842: void PF_cvar_set (void)
                    843: {
                    844:        char    *var, *val;
                    845:        
                    846:        var = G_STRING(OFS_PARM0);
                    847:        val = G_STRING(OFS_PARM1);
                    848:        
                    849:        Cvar_Set (var, val);
                    850: }
                    851: 
                    852: /*
                    853: =================
                    854: PF_findradius
                    855: 
                    856: Returns a chain of entities that have origins within a spherical area
                    857: 
                    858: findradius (origin, radius)
                    859: =================
                    860: */
                    861: void PF_findradius (void)
                    862: {
                    863:        edict_t *ent, *chain;
                    864:        float   rad;
                    865:        float   *org;
                    866:        vec3_t  eorg;
                    867:        int             i, j;
                    868: 
                    869:        chain = (edict_t *)sv.edicts;
                    870:        
                    871:        org = G_VECTOR(OFS_PARM0);
                    872:        rad = G_FLOAT(OFS_PARM1);
                    873: 
                    874:        ent = NEXT_EDICT(sv.edicts);
                    875:        for (i=1 ; i<sv.num_edicts ; i++, ent = NEXT_EDICT(ent))
                    876:        {
                    877:                if (ent->free)
                    878:                        continue;
                    879:                if (ent->v.solid == SOLID_NOT)
                    880:                        continue;
                    881:                for (j=0 ; j<3 ; j++)
                    882:                        eorg[j] = org[j] - (ent->v.origin[j] + (ent->v.mins[j] + ent->v.maxs[j])*0.5);                  
                    883:                if (Length(eorg) > rad)
                    884:                        continue;
                    885:                        
                    886:                ent->v.chain = EDICT_TO_PROG(chain);
                    887:                chain = ent;
                    888:        }
                    889: 
                    890:        RETURN_EDICT(chain);
                    891: }
                    892: 
                    893: 
                    894: /*
                    895: =========
                    896: PF_dprint
                    897: =========
                    898: */
                    899: void PF_dprint (void)
                    900: {
1.1.1.2 ! root      901:        Con_DPrintf ("%s",PF_VarString(0));
1.1       root      902: }
                    903: 
                    904: char   pr_string_temp[128];
                    905: 
                    906: void PF_ftos (void)
                    907: {
                    908:        float   v;
                    909:        v = G_FLOAT(OFS_PARM0);
                    910:        
                    911:        if (v == (int)v)
                    912:                sprintf (pr_string_temp, "%d",(int)v);
                    913:        else
                    914:                sprintf (pr_string_temp, "%5.1f",v);
                    915:        G_INT(OFS_RETURN) = pr_string_temp - pr_strings;
                    916: }
                    917: 
                    918: void PF_fabs (void)
                    919: {
                    920:        float   v;
                    921:        v = G_FLOAT(OFS_PARM0);
                    922:        G_FLOAT(OFS_RETURN) = fabs(v);
                    923: }
                    924: 
                    925: void PF_vtos (void)
                    926: {
                    927:        sprintf (pr_string_temp, "'%5.1f %5.1f %5.1f'", G_VECTOR(OFS_PARM0)[0], G_VECTOR(OFS_PARM0)[1], G_VECTOR(OFS_PARM0)[2]);
                    928:        G_INT(OFS_RETURN) = pr_string_temp - pr_strings;
                    929: }
                    930: 
1.1.1.2 ! root      931: #ifdef QUAKE2
        !           932: void PF_etos (void)
        !           933: {
        !           934:        sprintf (pr_string_temp, "entity %i", G_EDICTNUM(OFS_PARM0));
        !           935:        G_INT(OFS_RETURN) = pr_string_temp - pr_strings;
        !           936: }
        !           937: #endif
        !           938: 
1.1       root      939: void PF_Spawn (void)
                    940: {
                    941:        edict_t *ed;
                    942:        ed = ED_Alloc();
                    943:        RETURN_EDICT(ed);
                    944: }
                    945: 
                    946: void PF_Remove (void)
                    947: {
                    948:        edict_t *ed;
                    949:        
                    950:        ed = G_EDICT(OFS_PARM0);
                    951:        ED_Free (ed);
                    952: }
                    953: 
                    954: 
                    955: // entity (entity start, .string field, string match) find = #5;
                    956: void PF_Find (void)
1.1.1.2 ! root      957: #ifdef QUAKE2
1.1       root      958: {
                    959:        int             e;      
                    960:        int             f;
                    961:        char    *s, *t;
                    962:        edict_t *ed;
1.1.1.2 ! root      963:        edict_t *first;
        !           964:        edict_t *second;
        !           965:        edict_t *last;
        !           966: 
        !           967:        first = second = last = (edict_t *)sv.edicts;
        !           968:        e = G_EDICTNUM(OFS_PARM0);
        !           969:        f = G_INT(OFS_PARM1);
        !           970:        s = G_STRING(OFS_PARM2);
        !           971:        if (!s)
        !           972:                PR_RunError ("PF_Find: bad search string");
        !           973:                
        !           974:        for (e++ ; e < sv.num_edicts ; e++)
        !           975:        {
        !           976:                ed = EDICT_NUM(e);
        !           977:                if (ed->free)
        !           978:                        continue;
        !           979:                t = E_STRING(ed,f);
        !           980:                if (!t)
        !           981:                        continue;
        !           982:                if (!strcmp(t,s))
        !           983:                {
        !           984:                        if (first == (edict_t *)sv.edicts)
        !           985:                                first = ed;
        !           986:                        else if (second == (edict_t *)sv.edicts)
        !           987:                                second = ed;
        !           988:                        ed->v.chain = EDICT_TO_PROG(last);
        !           989:                        last = ed;
        !           990:                }
        !           991:        }
        !           992: 
        !           993:        if (first != last)
        !           994:        {
        !           995:                if (last != second)
        !           996:                        first->v.chain = last->v.chain;
        !           997:                else
        !           998:                        first->v.chain = EDICT_TO_PROG(last);
        !           999:                last->v.chain = EDICT_TO_PROG((edict_t *)sv.edicts);
        !          1000:                if (second && second != last)
        !          1001:                        second->v.chain = EDICT_TO_PROG(last);
        !          1002:        }
        !          1003:        RETURN_EDICT(first);
        !          1004: }
        !          1005: #else
        !          1006: {
        !          1007:        int             e;      
        !          1008:        int             f;
        !          1009:        char    *s, *t;
        !          1010:        edict_t *ed;
        !          1011: 
1.1       root     1012:        e = G_EDICTNUM(OFS_PARM0);
                   1013:        f = G_INT(OFS_PARM1);
                   1014:        s = G_STRING(OFS_PARM2);
                   1015:        if (!s)
                   1016:                PR_RunError ("PF_Find: bad search string");
                   1017:                
                   1018:        for (e++ ; e < sv.num_edicts ; e++)
                   1019:        {
                   1020:                ed = EDICT_NUM(e);
                   1021:                if (ed->free)
                   1022:                        continue;
                   1023:                t = E_STRING(ed,f);
                   1024:                if (!t)
                   1025:                        continue;
                   1026:                if (!strcmp(t,s))
                   1027:                {
                   1028:                        RETURN_EDICT(ed);
                   1029:                        return;
                   1030:                }
                   1031:        }
1.1.1.2 ! root     1032: 
1.1       root     1033:        RETURN_EDICT(sv.edicts);
                   1034: }
1.1.1.2 ! root     1035: #endif
1.1       root     1036: 
                   1037: void PR_CheckEmptyString (char *s)
                   1038: {
                   1039:        if (s[0] <= ' ')
                   1040:                PR_RunError ("Bad string");
                   1041: }
                   1042: 
                   1043: void PF_precache_file (void)
                   1044: {      // precache_file is only used to copy files with qcc, it does nothing
                   1045:        G_INT(OFS_RETURN) = G_INT(OFS_PARM0);
                   1046: }
                   1047: 
                   1048: void PF_precache_sound (void)
                   1049: {
                   1050:        char    *s;
                   1051:        int             i;
                   1052:        
                   1053:        if (sv.state != ss_loading)
                   1054:                PR_RunError ("PF_Precache_*: Precache can only be done in spawn functions");
                   1055:                
                   1056:        s = G_STRING(OFS_PARM0);
                   1057:        G_INT(OFS_RETURN) = G_INT(OFS_PARM0);
                   1058:        PR_CheckEmptyString (s);
                   1059:        
                   1060:        for (i=0 ; i<MAX_SOUNDS ; i++)
                   1061:        {
                   1062:                if (!sv.sound_precache[i])
                   1063:                {
                   1064:                        sv.sound_precache[i] = s;
                   1065:                        return;
                   1066:                }
                   1067:                if (!strcmp(sv.sound_precache[i], s))
                   1068:                        return;
                   1069:        }
                   1070:        PR_RunError ("PF_precache_sound: overflow");
                   1071: }
                   1072: 
                   1073: void PF_precache_model (void)
                   1074: {
                   1075:        char    *s;
                   1076:        int             i;
                   1077:        
                   1078:        if (sv.state != ss_loading)
                   1079:                PR_RunError ("PF_Precache_*: Precache can only be done in spawn functions");
                   1080:                
                   1081:        s = G_STRING(OFS_PARM0);
                   1082:        G_INT(OFS_RETURN) = G_INT(OFS_PARM0);
                   1083:        PR_CheckEmptyString (s);
                   1084: 
                   1085:        for (i=0 ; i<MAX_MODELS ; i++)
                   1086:        {
                   1087:                if (!sv.model_precache[i])
                   1088:                {
                   1089:                        sv.model_precache[i] = s;
                   1090:                        sv.models[i] = Mod_ForName (s, true);
                   1091:                        return;
                   1092:                }
                   1093:                if (!strcmp(sv.model_precache[i], s))
                   1094:                        return;
                   1095:        }
                   1096:        PR_RunError ("PF_precache_model: overflow");
                   1097: }
                   1098: 
                   1099: 
                   1100: void PF_coredump (void)
                   1101: {
                   1102:        ED_PrintEdicts ();
                   1103: }
                   1104: 
                   1105: void PF_traceon (void)
                   1106: {
                   1107:        pr_trace = true;
                   1108: }
                   1109: 
                   1110: void PF_traceoff (void)
                   1111: {
                   1112:        pr_trace = false;
                   1113: }
                   1114: 
                   1115: void PF_eprint (void)
                   1116: {
                   1117:        ED_PrintNum (G_EDICTNUM(OFS_PARM0));
                   1118: }
                   1119: 
                   1120: /*
                   1121: ===============
                   1122: PF_walkmove
                   1123: 
                   1124: float(float yaw, float dist) walkmove
                   1125: ===============
                   1126: */
                   1127: void PF_walkmove (void)
                   1128: {
                   1129:        edict_t *ent;
                   1130:        float   yaw, dist;
                   1131:        vec3_t  move;
                   1132:        dfunction_t     *oldf;
                   1133:        int     oldself;
                   1134:        
                   1135:        ent = PROG_TO_EDICT(pr_global_struct->self);
                   1136:        yaw = G_FLOAT(OFS_PARM0);
                   1137:        dist = G_FLOAT(OFS_PARM1);
                   1138:        
                   1139:        if ( !( (int)ent->v.flags & (FL_ONGROUND|FL_FLY|FL_SWIM) ) )
                   1140:        {
                   1141:                G_FLOAT(OFS_RETURN) = 0;
                   1142:                return;
                   1143:        }
                   1144: 
                   1145:        yaw = yaw*M_PI*2 / 360;
                   1146:        
                   1147:        move[0] = cos(yaw)*dist;
                   1148:        move[1] = sin(yaw)*dist;
                   1149:        move[2] = 0;
                   1150: 
                   1151: // save program state, because SV_movestep may call other progs
                   1152:        oldf = pr_xfunction;
                   1153:        oldself = pr_global_struct->self;
                   1154:        
                   1155:        G_FLOAT(OFS_RETURN) = SV_movestep(ent, move, true);
                   1156:        
                   1157:        
                   1158: // restore program state
                   1159:        pr_xfunction = oldf;
                   1160:        pr_global_struct->self = oldself;
                   1161: }
                   1162: 
                   1163: /*
                   1164: ===============
                   1165: PF_droptofloor
                   1166: 
                   1167: void() droptofloor
                   1168: ===============
                   1169: */
                   1170: void PF_droptofloor (void)
                   1171: {
                   1172:        edict_t         *ent;
                   1173:        vec3_t          end;
                   1174:        trace_t         trace;
                   1175:        
                   1176:        ent = PROG_TO_EDICT(pr_global_struct->self);
                   1177: 
                   1178:        VectorCopy (ent->v.origin, end);
                   1179:        end[2] -= 256;
                   1180:        
                   1181:        trace = SV_Move (ent->v.origin, ent->v.mins, ent->v.maxs, end, false, ent);
                   1182: 
                   1183:        if (trace.fraction == 1 || trace.allsolid)
                   1184:                G_FLOAT(OFS_RETURN) = 0;
                   1185:        else
                   1186:        {
                   1187:                VectorCopy (trace.endpos, ent->v.origin);
                   1188:                SV_LinkEdict (ent, false);
                   1189:                ent->v.flags = (int)ent->v.flags | FL_ONGROUND;
                   1190:                ent->v.groundentity = EDICT_TO_PROG(trace.ent);
                   1191:                G_FLOAT(OFS_RETURN) = 1;
                   1192:        }
                   1193: }
                   1194: 
                   1195: /*
                   1196: ===============
                   1197: PF_lightstyle
                   1198: 
                   1199: void(float style, string value) lightstyle
                   1200: ===============
                   1201: */
                   1202: void PF_lightstyle (void)
                   1203: {
                   1204:        int             style;
                   1205:        char    *val;
                   1206:        client_t        *client;
                   1207:        int                     j;
                   1208:        
                   1209:        style = G_FLOAT(OFS_PARM0);
                   1210:        val = G_STRING(OFS_PARM1);
                   1211: 
                   1212: // change the string in sv
                   1213:        sv.lightstyles[style] = val;
                   1214:        
                   1215: // send message to all clients on this server
                   1216:        if (sv.state != ss_active)
                   1217:                return;
                   1218:        
                   1219:        for (j=0, client = svs.clients ; j<svs.maxclients ; j++, client++)
                   1220:                if (client->active || client->spawned)
                   1221:                {
                   1222:                        MSG_WriteChar (&client->message, svc_lightstyle);
                   1223:                        MSG_WriteChar (&client->message,style);
                   1224:                        MSG_WriteString (&client->message, val);
                   1225:                }
                   1226: }
                   1227: 
                   1228: void PF_rint (void)
                   1229: {
                   1230:        float   f;
                   1231:        f = G_FLOAT(OFS_PARM0);
                   1232:        if (f > 0)
                   1233:                G_FLOAT(OFS_RETURN) = (int)(f + 0.5);
                   1234:        else
                   1235:                G_FLOAT(OFS_RETURN) = (int)(f - 0.5);
                   1236: }
                   1237: void PF_floor (void)
                   1238: {
                   1239:        G_FLOAT(OFS_RETURN) = floor(G_FLOAT(OFS_PARM0));
                   1240: }
                   1241: void PF_ceil (void)
                   1242: {
                   1243:        G_FLOAT(OFS_RETURN) = ceil(G_FLOAT(OFS_PARM0));
                   1244: }
                   1245: 
                   1246: 
                   1247: /*
                   1248: =============
                   1249: PF_checkbottom
                   1250: =============
                   1251: */
                   1252: void PF_checkbottom (void)
                   1253: {
                   1254:        edict_t *ent;
                   1255:        
                   1256:        ent = G_EDICT(OFS_PARM0);
                   1257: 
                   1258:        G_FLOAT(OFS_RETURN) = SV_CheckBottom (ent);
                   1259: }
                   1260: 
                   1261: /*
                   1262: =============
                   1263: PF_pointcontents
                   1264: =============
                   1265: */
                   1266: void PF_pointcontents (void)
                   1267: {
                   1268:        float   *v;
                   1269:        
                   1270:        v = G_VECTOR(OFS_PARM0);
                   1271: 
                   1272:        G_FLOAT(OFS_RETURN) = SV_PointContents (v);     
                   1273: }
                   1274: 
                   1275: /*
                   1276: =============
                   1277: PF_nextent
                   1278: 
                   1279: entity nextent(entity)
                   1280: =============
                   1281: */
                   1282: void PF_nextent (void)
                   1283: {
                   1284:        int             i;
                   1285:        edict_t *ent;
                   1286:        
                   1287:        i = G_EDICTNUM(OFS_PARM0);
                   1288:        while (1)
                   1289:        {
                   1290:                i++;
                   1291:                if (i == sv.num_edicts)
                   1292:                {
                   1293:                        RETURN_EDICT(sv.edicts);
                   1294:                        return;
                   1295:                }
                   1296:                ent = EDICT_NUM(i);
                   1297:                if (!ent->free)
                   1298:                {
                   1299:                        RETURN_EDICT(ent);
                   1300:                        return;
                   1301:                }
                   1302:        }
                   1303: }
                   1304: 
                   1305: /*
                   1306: =============
                   1307: PF_aim
                   1308: 
                   1309: Pick a vector for the player to shoot along
                   1310: vector aim(entity, missilespeed)
                   1311: =============
                   1312: */
                   1313: cvar_t sv_aim = {"sv_aim", "0.93"};
                   1314: void PF_aim (void)
                   1315: {
                   1316:        edict_t *ent, *check, *bestent;
                   1317:        vec3_t  start, dir, end, bestdir;
                   1318:        int             i, j;
                   1319:        trace_t tr;
                   1320:        float   dist, bestdist;
                   1321:        float   speed;
                   1322:        
                   1323:        ent = G_EDICT(OFS_PARM0);
                   1324:        speed = G_FLOAT(OFS_PARM1);
                   1325: 
                   1326:        VectorCopy (ent->v.origin, start);
                   1327:        start[2] += 20;
                   1328: 
                   1329: // try sending a trace straight
                   1330:        VectorCopy (pr_global_struct->v_forward, dir);
                   1331:        VectorMA (start, 2048, dir, end);
                   1332:        tr = SV_Move (start, vec3_origin, vec3_origin, end, false, ent);
                   1333:        if (tr.ent && tr.ent->v.takedamage == DAMAGE_AIM
                   1334:        && (!teamplay.value || ent->v.team <=0 || ent->v.team != tr.ent->v.team) )
                   1335:        {
                   1336:                VectorCopy (pr_global_struct->v_forward, G_VECTOR(OFS_RETURN));
                   1337:                return;
                   1338:        }
                   1339: 
                   1340: 
                   1341: // try all possible entities
                   1342:        VectorCopy (dir, bestdir);
                   1343:        bestdist = sv_aim.value;
                   1344:        bestent = NULL;
                   1345:        
                   1346:        check = NEXT_EDICT(sv.edicts);
                   1347:        for (i=1 ; i<sv.num_edicts ; i++, check = NEXT_EDICT(check) )
                   1348:        {
                   1349:                if (check->v.takedamage != DAMAGE_AIM)
                   1350:                        continue;
                   1351:                if (check == ent)
                   1352:                        continue;
                   1353:                if (teamplay.value && ent->v.team > 0 && ent->v.team == check->v.team)
                   1354:                        continue;       // don't aim at teammate
                   1355:                for (j=0 ; j<3 ; j++)
                   1356:                        end[j] = check->v.origin[j]
                   1357:                        + 0.5*(check->v.mins[j] + check->v.maxs[j]);
                   1358:                VectorSubtract (end, start, dir);
                   1359:                VectorNormalize (dir);
                   1360:                dist = DotProduct (dir, pr_global_struct->v_forward);
                   1361:                if (dist < bestdist)
                   1362:                        continue;       // to far to turn
                   1363:                tr = SV_Move (start, vec3_origin, vec3_origin, end, false, ent);
                   1364:                if (tr.ent == check)
                   1365:                {       // can shoot at this one
                   1366:                        bestdist = dist;
                   1367:                        bestent = check;
                   1368:                }
                   1369:        }
                   1370:        
                   1371:        if (bestent)
                   1372:        {
                   1373:                VectorSubtract (bestent->v.origin, ent->v.origin, dir);
                   1374:                dist = DotProduct (dir, pr_global_struct->v_forward);
                   1375:                VectorScale (pr_global_struct->v_forward, dist, end);
                   1376:                end[2] = dir[2];
                   1377:                VectorNormalize (end);
                   1378:                VectorCopy (end, G_VECTOR(OFS_RETURN)); 
                   1379:        }
                   1380:        else
                   1381:        {
                   1382:                VectorCopy (bestdir, G_VECTOR(OFS_RETURN));
                   1383:        }
                   1384: }
                   1385: 
                   1386: /*
                   1387: ==============
                   1388: PF_changeyaw
                   1389: 
                   1390: This was a major timewaster in progs, so it was converted to C
                   1391: ==============
                   1392: */
                   1393: void PF_changeyaw (void)
                   1394: {
                   1395:        edict_t         *ent;
                   1396:        float           ideal, current, move, speed;
                   1397:        
                   1398:        ent = PROG_TO_EDICT(pr_global_struct->self);
                   1399:        current = anglemod( ent->v.angles[1] );
                   1400:        ideal = ent->v.ideal_yaw;
                   1401:        speed = ent->v.yaw_speed;
                   1402:        
                   1403:        if (current == ideal)
                   1404:                return;
                   1405:        move = ideal - current;
                   1406:        if (ideal > current)
                   1407:        {
                   1408:                if (move >= 180)
                   1409:                        move = move - 360;
                   1410:        }
                   1411:        else
                   1412:        {
                   1413:                if (move <= -180)
                   1414:                        move = move + 360;
                   1415:        }
                   1416:        if (move > 0)
                   1417:        {
                   1418:                if (move > speed)
                   1419:                        move = speed;
                   1420:        }
                   1421:        else
                   1422:        {
                   1423:                if (move < -speed)
                   1424:                        move = -speed;
                   1425:        }
                   1426:        
                   1427:        ent->v.angles[1] = anglemod (current + move);
                   1428: }
                   1429: 
1.1.1.2 ! root     1430: #ifdef QUAKE2
        !          1431: /*
        !          1432: ==============
        !          1433: PF_changepitch
        !          1434: ==============
        !          1435: */
        !          1436: void PF_changepitch (void)
        !          1437: {
        !          1438:        edict_t         *ent;
        !          1439:        float           ideal, current, move, speed;
        !          1440:        
        !          1441:        ent = G_EDICT(OFS_PARM0);
        !          1442:        current = anglemod( ent->v.angles[0] );
        !          1443:        ideal = ent->v.idealpitch;
        !          1444:        speed = ent->v.pitch_speed;
        !          1445:        
        !          1446:        if (current == ideal)
        !          1447:                return;
        !          1448:        move = ideal - current;
        !          1449:        if (ideal > current)
        !          1450:        {
        !          1451:                if (move >= 180)
        !          1452:                        move = move - 360;
        !          1453:        }
        !          1454:        else
        !          1455:        {
        !          1456:                if (move <= -180)
        !          1457:                        move = move + 360;
        !          1458:        }
        !          1459:        if (move > 0)
        !          1460:        {
        !          1461:                if (move > speed)
        !          1462:                        move = speed;
        !          1463:        }
        !          1464:        else
        !          1465:        {
        !          1466:                if (move < -speed)
        !          1467:                        move = -speed;
        !          1468:        }
        !          1469:        
        !          1470:        ent->v.angles[0] = anglemod (current + move);
        !          1471: }
        !          1472: #endif
        !          1473: 
1.1       root     1474: /*
                   1475: ===============================================================================
                   1476: 
                   1477: MESSAGE WRITING
                   1478: 
                   1479: ===============================================================================
                   1480: */
                   1481: 
                   1482: #define        MSG_BROADCAST   0               // unreliable to all
                   1483: #define        MSG_ONE                 1               // reliable to one (msg_entity)
                   1484: #define        MSG_ALL                 2               // reliable to all
                   1485: #define        MSG_INIT                3               // write to the init string
                   1486: 
                   1487: sizebuf_t *WriteDest (void)
                   1488: {
                   1489:        int             entnum;
                   1490:        int             dest;
                   1491:        edict_t *ent;
                   1492: 
                   1493:        dest = G_FLOAT(OFS_PARM0);
                   1494:        switch (dest)
                   1495:        {
                   1496:        case MSG_BROADCAST:
                   1497:                return &sv.datagram;
                   1498:        
                   1499:        case MSG_ONE:
                   1500:                ent = PROG_TO_EDICT(pr_global_struct->msg_entity);
                   1501:                entnum = NUM_FOR_EDICT(ent);
                   1502:                if (entnum < 1 || entnum > svs.maxclients)
                   1503:                        PR_RunError ("WriteDest: not a client");
                   1504:                return &svs.clients[entnum-1].message;
                   1505:                
                   1506:        case MSG_ALL:
                   1507:                return &sv.reliable_datagram;
                   1508:        
                   1509:        case MSG_INIT:
                   1510:                return &sv.signon;
                   1511: 
                   1512:        default:
                   1513:                PR_RunError ("WriteDest: bad destination");
                   1514:                break;
                   1515:        }
                   1516:        
                   1517:        return NULL;
                   1518: }
                   1519: 
                   1520: void PF_WriteByte (void)
                   1521: {
                   1522:        MSG_WriteByte (WriteDest(), G_FLOAT(OFS_PARM1));
                   1523: }
                   1524: 
                   1525: void PF_WriteChar (void)
                   1526: {
                   1527:        MSG_WriteChar (WriteDest(), G_FLOAT(OFS_PARM1));
                   1528: }
                   1529: 
                   1530: void PF_WriteShort (void)
                   1531: {
                   1532:        MSG_WriteShort (WriteDest(), G_FLOAT(OFS_PARM1));
                   1533: }
                   1534: 
                   1535: void PF_WriteLong (void)
                   1536: {
                   1537:        MSG_WriteLong (WriteDest(), G_FLOAT(OFS_PARM1));
                   1538: }
                   1539: 
                   1540: void PF_WriteAngle (void)
                   1541: {
                   1542:        MSG_WriteAngle (WriteDest(), G_FLOAT(OFS_PARM1));
                   1543: }
                   1544: 
                   1545: void PF_WriteCoord (void)
                   1546: {
                   1547:        MSG_WriteCoord (WriteDest(), G_FLOAT(OFS_PARM1));
                   1548: }
                   1549: 
                   1550: void PF_WriteString (void)
                   1551: {
                   1552:        MSG_WriteString (WriteDest(), G_STRING(OFS_PARM1));
                   1553: }
                   1554: 
                   1555: 
                   1556: void PF_WriteEntity (void)
                   1557: {
                   1558:        MSG_WriteShort (WriteDest(), G_EDICTNUM(OFS_PARM1));
                   1559: }
                   1560: 
                   1561: //=============================================================================
                   1562: 
                   1563: int SV_ModelIndex (char *name);
                   1564: 
                   1565: void PF_makestatic (void)
                   1566: {
                   1567:        edict_t *ent;
                   1568:        int             i;
                   1569:        
                   1570:        ent = G_EDICT(OFS_PARM0);
                   1571: 
                   1572:        MSG_WriteByte (&sv.signon,svc_spawnstatic);
                   1573: 
                   1574:        MSG_WriteByte (&sv.signon, SV_ModelIndex(pr_strings + ent->v.model));
                   1575: 
                   1576:        MSG_WriteByte (&sv.signon, ent->v.frame);
                   1577:        MSG_WriteByte (&sv.signon, ent->v.colormap);
                   1578:        MSG_WriteByte (&sv.signon, ent->v.skin);
                   1579:        for (i=0 ; i<3 ; i++)
                   1580:        {
                   1581:                MSG_WriteCoord(&sv.signon, ent->v.origin[i]);
                   1582:                MSG_WriteAngle(&sv.signon, ent->v.angles[i]);
                   1583:        }
                   1584: 
                   1585: // throw the entity away now
                   1586:        ED_Free (ent);
                   1587: }
                   1588: 
                   1589: //=============================================================================
                   1590: 
                   1591: /*
                   1592: ==============
                   1593: PF_setspawnparms
                   1594: ==============
                   1595: */
                   1596: void PF_setspawnparms (void)
                   1597: {
                   1598:        edict_t *ent;
                   1599:        int             i;
                   1600:        client_t        *client;
                   1601: 
                   1602:        ent = G_EDICT(OFS_PARM0);
                   1603:        i = NUM_FOR_EDICT(ent);
                   1604:        if (i < 1 || i > svs.maxclients)
                   1605:                PR_RunError ("Entity is not a client");
                   1606: 
                   1607:        // copy spawn parms out of the client_t
                   1608:        client = svs.clients + (i-1);
                   1609: 
                   1610:        for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
                   1611:                (&pr_global_struct->parm1)[i] = client->spawn_parms[i];
                   1612: }
                   1613: 
                   1614: /*
                   1615: ==============
                   1616: PF_changelevel
                   1617: ==============
                   1618: */
                   1619: void PF_changelevel (void)
                   1620: {
1.1.1.2 ! root     1621: #ifdef QUAKE2
        !          1622:        char    *s1, *s2;
        !          1623: 
        !          1624:        if (svs.changelevel_issued)
        !          1625:                return;
        !          1626:        svs.changelevel_issued = true;
        !          1627: 
        !          1628:        s1 = G_STRING(OFS_PARM0);
        !          1629:        s2 = G_STRING(OFS_PARM1);
        !          1630: 
        !          1631:        if ((int)pr_global_struct->serverflags & (SFL_NEW_UNIT | SFL_NEW_EPISODE))
        !          1632:                Cbuf_AddText (va("changelevel %s %s\n",s1, s2));
        !          1633:        else
        !          1634:                Cbuf_AddText (va("changelevel2 %s %s\n",s1, s2));
        !          1635: #else
1.1       root     1636:        char    *s;
                   1637: 
                   1638: // make sure we don't issue two changelevels
                   1639:        if (svs.changelevel_issued)
                   1640:                return;
                   1641:        svs.changelevel_issued = true;
                   1642:        
                   1643:        s = G_STRING(OFS_PARM0);
                   1644:        Cbuf_AddText (va("changelevel %s\n",s));
1.1.1.2 ! root     1645: #endif
1.1       root     1646: }
                   1647: 
                   1648: 
1.1.1.2 ! root     1649: #ifdef QUAKE2
        !          1650: 
        !          1651: #define        CONTENT_WATER   -3
        !          1652: #define CONTENT_SLIME  -4
        !          1653: #define CONTENT_LAVA   -5
        !          1654: 
        !          1655: #define FL_IMMUNE_WATER        131072
        !          1656: #define        FL_IMMUNE_SLIME 262144
        !          1657: #define FL_IMMUNE_LAVA 524288
        !          1658: 
        !          1659: #define        CHAN_VOICE      2
        !          1660: #define        CHAN_BODY       4
        !          1661: 
        !          1662: #define        ATTN_NORM       1
        !          1663: 
        !          1664: void PF_WaterMove (void)
        !          1665: {
        !          1666:        edict_t         *self;
        !          1667:        int                     flags;
        !          1668:        int                     waterlevel;
        !          1669:        int                     watertype;
        !          1670:        float           drownlevel;
        !          1671:        float           damage = 0.0;
        !          1672: 
        !          1673:        self = PROG_TO_EDICT(pr_global_struct->self);
        !          1674: 
        !          1675:        if (self->v.movetype == MOVETYPE_NOCLIP)
        !          1676:        {
        !          1677:                self->v.air_finished = sv.time + 12;
        !          1678:                G_FLOAT(OFS_RETURN) = damage;
        !          1679:                return;
        !          1680:        }
        !          1681: 
        !          1682:        if (self->v.health < 0)
        !          1683:        {
        !          1684:                G_FLOAT(OFS_RETURN) = damage;
        !          1685:                return;
        !          1686:        }
        !          1687: 
        !          1688:        if (self->v.deadflag == DEAD_NO)
        !          1689:                drownlevel = 3;
        !          1690:        else
        !          1691:                drownlevel = 1;
        !          1692: 
        !          1693:        flags = (int)self->v.flags;
        !          1694:        waterlevel = (int)self->v.waterlevel;
        !          1695:        watertype = (int)self->v.watertype;
        !          1696: 
        !          1697:        if (!(flags & (FL_IMMUNE_WATER + FL_GODMODE)))
        !          1698:                if (((flags & FL_SWIM) && (waterlevel < drownlevel)) || (waterlevel >= drownlevel))
        !          1699:                {
        !          1700:                        if (self->v.air_finished < sv.time)
        !          1701:                                if (self->v.pain_finished < sv.time)
        !          1702:                                {
        !          1703:                                        self->v.dmg = self->v.dmg + 2;
        !          1704:                                        if (self->v.dmg > 15)
        !          1705:                                                self->v.dmg = 10;
        !          1706: //                                     T_Damage (self, world, world, self.dmg, 0, FALSE);
        !          1707:                                        damage = self->v.dmg;
        !          1708:                                        self->v.pain_finished = sv.time + 1.0;
        !          1709:                                }
        !          1710:                }
        !          1711:                else
        !          1712:                {
        !          1713:                        if (self->v.air_finished < sv.time)
        !          1714: //                             sound (self, CHAN_VOICE, "player/gasp2.wav", 1, ATTN_NORM);
        !          1715:                                SV_StartSound (self, CHAN_VOICE, "player/gasp2.wav", 255, ATTN_NORM);
        !          1716:                        else if (self->v.air_finished < sv.time + 9)
        !          1717: //                             sound (self, CHAN_VOICE, "player/gasp1.wav", 1, ATTN_NORM);
        !          1718:                                SV_StartSound (self, CHAN_VOICE, "player/gasp1.wav", 255, ATTN_NORM);
        !          1719:                        self->v.air_finished = sv.time + 12.0;
        !          1720:                        self->v.dmg = 2;
        !          1721:                }
        !          1722:        
        !          1723:        if (!waterlevel)
        !          1724:        {
        !          1725:                if (flags & FL_INWATER)
        !          1726:                {       
        !          1727:                        // play leave water sound
        !          1728: //                     sound (self, CHAN_BODY, "misc/outwater.wav", 1, ATTN_NORM);
        !          1729:                        SV_StartSound (self, CHAN_BODY, "misc/outwater.wav", 255, ATTN_NORM);
        !          1730:                        self->v.flags = (float)(flags &~FL_INWATER);
        !          1731:                }
        !          1732:                self->v.air_finished = sv.time + 12.0;
        !          1733:                G_FLOAT(OFS_RETURN) = damage;
        !          1734:                return;
        !          1735:        }
        !          1736: 
        !          1737:        if (watertype == CONTENT_LAVA)
        !          1738:        {       // do damage
        !          1739:                if (!(flags & (FL_IMMUNE_LAVA + FL_GODMODE)))
        !          1740:                        if (self->v.dmgtime < sv.time)
        !          1741:                        {
        !          1742:                                if (self->v.radsuit_finished < sv.time)
        !          1743:                                        self->v.dmgtime = sv.time + 0.2;
        !          1744:                                else
        !          1745:                                        self->v.dmgtime = sv.time + 1.0;
        !          1746: //                             T_Damage (self, world, world, 10*self.waterlevel, 0, TRUE);
        !          1747:                                damage = (float)(10*waterlevel);
        !          1748:                        }
        !          1749:        }
        !          1750:        else if (watertype == CONTENT_SLIME)
        !          1751:        {       // do damage
        !          1752:                if (!(flags & (FL_IMMUNE_SLIME + FL_GODMODE)))
        !          1753:                        if (self->v.dmgtime < sv.time && self->v.radsuit_finished < sv.time)
        !          1754:                        {
        !          1755:                                self->v.dmgtime = sv.time + 1.0;
        !          1756: //                             T_Damage (self, world, world, 4*self.waterlevel, 0, TRUE);
        !          1757:                                damage = (float)(4*waterlevel);
        !          1758:                        }
        !          1759:        }
        !          1760:        
        !          1761:        if ( !(flags & FL_INWATER) )
        !          1762:        {       
        !          1763: 
        !          1764: // player enter water sound
        !          1765:                if (watertype == CONTENT_LAVA)
        !          1766: //                     sound (self, CHAN_BODY, "player/inlava.wav", 1, ATTN_NORM);
        !          1767:                        SV_StartSound (self, CHAN_BODY, "player/inlava.wav", 255, ATTN_NORM);
        !          1768:                if (watertype == CONTENT_WATER)
        !          1769: //                     sound (self, CHAN_BODY, "player/inh2o.wav", 1, ATTN_NORM);
        !          1770:                        SV_StartSound (self, CHAN_BODY, "player/inh2o.wav", 255, ATTN_NORM);
        !          1771:                if (watertype == CONTENT_SLIME)
        !          1772: //                     sound (self, CHAN_BODY, "player/slimbrn2.wav", 1, ATTN_NORM);
        !          1773:                        SV_StartSound (self, CHAN_BODY, "player/slimbrn2.wav", 255, ATTN_NORM);
        !          1774: 
        !          1775:                self->v.flags = (float)(flags | FL_INWATER);
        !          1776:                self->v.dmgtime = 0;
        !          1777:        }
        !          1778:        
        !          1779:        if (! (flags & FL_WATERJUMP) )
        !          1780:        {
        !          1781: //             self.velocity = self.velocity - 0.8*self.waterlevel*frametime*self.velocity;
        !          1782:                VectorMA (self->v.velocity, -0.8 * self->v.waterlevel * host_frametime, self->v.velocity, self->v.velocity);
        !          1783:        }
        !          1784: 
        !          1785:        G_FLOAT(OFS_RETURN) = damage;
        !          1786: }
        !          1787: 
        !          1788: 
        !          1789: void PF_sin (void)
        !          1790: {
        !          1791:        G_FLOAT(OFS_RETURN) = sin(G_FLOAT(OFS_PARM0));
        !          1792: }
        !          1793: 
        !          1794: void PF_cos (void)
        !          1795: {
        !          1796:        G_FLOAT(OFS_RETURN) = cos(G_FLOAT(OFS_PARM0));
        !          1797: }
        !          1798: 
        !          1799: void PF_sqrt (void)
        !          1800: {
        !          1801:        G_FLOAT(OFS_RETURN) = sqrt(G_FLOAT(OFS_PARM0));
        !          1802: }
        !          1803: #endif
        !          1804: 
1.1       root     1805: void PF_Fixme (void)
                   1806: {
                   1807:        PR_RunError ("unimplemented bulitin");
                   1808: }
                   1809: 
                   1810: 
                   1811: 
                   1812: builtin_t pr_builtin[] =
                   1813: {
1.1.1.2 ! root     1814: PF_Fixme,
1.1       root     1815: PF_makevectors,        // void(entity e)       makevectors             = #1;
                   1816: PF_setorigin,  // void(entity e, vector o) setorigin   = #2;
                   1817: PF_setmodel,   // void(entity e, string m) setmodel    = #3;
                   1818: PF_setsize,    // void(entity e, vector min, vector max) setsize = #4;
                   1819: PF_Fixme,      // void(entity e, vector min, vector max) setabssize = #5;
                   1820: PF_break,      // void() break                                         = #6;
                   1821: PF_random,     // float() random                                               = #7;
                   1822: PF_sound,      // void(entity e, float chan, string samp) sound = #8;
                   1823: PF_normalize,  // vector(vector v) normalize                   = #9;
                   1824: PF_error,      // void(string e) error                         = #10;
                   1825: PF_objerror,   // void(string e) objerror                              = #11;
                   1826: PF_vlen,       // float(vector v) vlen                         = #12;
                   1827: PF_vectoyaw,   // float(vector v) vectoyaw             = #13;
                   1828: PF_Spawn,      // entity() spawn                                               = #14;
                   1829: PF_Remove,     // void(entity e) remove                                = #15;
                   1830: PF_traceline,  // float(vector v1, vector v2, float tryents) traceline = #16;
                   1831: PF_checkclient,        // entity() clientlist                                  = #17;
                   1832: PF_Find,       // entity(entity start, .string fld, string match) find = #18;
                   1833: PF_precache_sound,     // void(string s) precache_sound                = #19;
                   1834: PF_precache_model,     // void(string s) precache_model                = #20;
                   1835: PF_stuffcmd,   // void(entity client, string s)stuffcmd = #21;
                   1836: PF_findradius, // entity(vector org, float rad) findradius = #22;
                   1837: PF_bprint,     // void(string s) bprint                                = #23;
                   1838: PF_sprint,     // void(entity client, string s) sprint = #24;
                   1839: PF_dprint,     // void(string s) dprint                                = #25;
                   1840: PF_ftos,       // void(string s) ftos                          = #26;
                   1841: PF_vtos,       // void(string s) vtos                          = #27;
                   1842: PF_coredump,
                   1843: PF_traceon,
                   1844: PF_traceoff,
                   1845: PF_eprint,     // void(entity e) debug print an entire entity
                   1846: PF_walkmove, // float(float yaw, float dist) walkmove
                   1847: PF_Fixme, // float(float yaw, float dist) walkmove
                   1848: PF_droptofloor,
                   1849: PF_lightstyle,
                   1850: PF_rint,
                   1851: PF_floor,
                   1852: PF_ceil,
                   1853: PF_Fixme,
                   1854: PF_checkbottom,
                   1855: PF_pointcontents,
                   1856: PF_Fixme,
                   1857: PF_fabs,
                   1858: PF_aim,
                   1859: PF_cvar,
                   1860: PF_localcmd,
                   1861: PF_nextent,
                   1862: PF_particle,
                   1863: PF_changeyaw,
                   1864: PF_Fixme,
                   1865: PF_vectoangles,
                   1866: 
                   1867: PF_WriteByte,
                   1868: PF_WriteChar,
                   1869: PF_WriteShort,
                   1870: PF_WriteLong,
                   1871: PF_WriteCoord,
                   1872: PF_WriteAngle,
                   1873: PF_WriteString,
                   1874: PF_WriteEntity,
                   1875: 
1.1.1.2 ! root     1876: #ifdef QUAKE2
        !          1877: PF_sin,
        !          1878: PF_cos,
        !          1879: PF_sqrt,
        !          1880: PF_changepitch,
        !          1881: PF_TraceToss,
        !          1882: PF_etos,
        !          1883: PF_WaterMove,
        !          1884: #else
1.1       root     1885: PF_Fixme,
                   1886: PF_Fixme,
                   1887: PF_Fixme,
                   1888: PF_Fixme,
                   1889: PF_Fixme,
                   1890: PF_Fixme,
                   1891: PF_Fixme,
1.1.1.2 ! root     1892: #endif
1.1       root     1893: 
                   1894: SV_MoveToGoal,
                   1895: PF_precache_file,
                   1896: PF_makestatic,
                   1897: 
                   1898: PF_changelevel,
                   1899: PF_Fixme,
                   1900: 
                   1901: PF_cvar_set,
                   1902: PF_centerprint,
                   1903: 
                   1904: PF_ambientsound,
                   1905: 
                   1906: PF_precache_model,
                   1907: PF_precache_sound,             // precache_sound2 is different only for qcc
                   1908: PF_precache_file,
                   1909: 
                   1910: PF_setspawnparms
                   1911: };
                   1912: 
                   1913: builtin_t *pr_builtins = pr_builtin;
                   1914: int pr_numbuiltins = sizeof(pr_builtin)/sizeof(pr_builtin[0]);
                   1915: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.