Annotation of quake2/game/g_cmds.c, revision 1.1.1.2

1.1       root        1: #include "g_local.h"
                      2: #include "m_player.h"
                      3: 
                      4: 
                      5: char *ClientTeam (edict_t *ent)
                      6: {
                      7:        char            *p;
                      8:        static char     value[512];
                      9: 
                     10:        value[0] = 0;
                     11: 
                     12:        if (!ent->client)
                     13:                return value;
                     14: 
                     15:        strcpy(value, Info_ValueForKey (ent->client->pers.userinfo, "skin"));
                     16:        p = strchr(value, '/');
                     17:        if (!p)
                     18:                return value;
                     19: 
                     20:        if ((int)(dmflags->value) & DF_MODELTEAMS)
                     21:        {
                     22:                *p = 0;
                     23:                return value;
                     24:        }
                     25: 
                     26:        // if ((int)(dmflags->value) & DF_SKINTEAMS)
                     27:        return ++p;
                     28: }
                     29: 
                     30: qboolean OnSameTeam (edict_t *ent1, edict_t *ent2)
                     31: {
                     32:        char    ent1Team [512];
                     33:        char    ent2Team [512];
                     34: 
                     35:        if (!((int)(dmflags->value) & (DF_MODELTEAMS | DF_SKINTEAMS)))
                     36:                return false;
                     37: 
                     38:        strcpy (ent1Team, ClientTeam (ent1));
                     39:        strcpy (ent2Team, ClientTeam (ent2));
                     40: 
                     41:        if (strcmp(ent1Team, ent2Team) == 0)
                     42:                return true;
                     43:        return false;
                     44: }
                     45: 
                     46: 
                     47: void SelectNextItem (edict_t *ent, int itflags)
                     48: {
                     49:        gclient_t       *cl;
                     50:        int                     i, index;
                     51:        gitem_t         *it;
                     52: 
                     53:        cl = ent->client;
                     54: 
                     55:        // scan  for the next valid one
                     56:        for (i=1 ; i<=MAX_ITEMS ; i++)
                     57:        {
                     58:                index = (cl->pers.selected_item + i)%MAX_ITEMS;
                     59:                if (!cl->pers.inventory[index])
                     60:                        continue;
                     61:                it = &itemlist[index];
                     62:                if (!it->use)
                     63:                        continue;
                     64:                if (!(it->flags & itflags))
                     65:                        continue;
                     66: 
                     67:                cl->pers.selected_item = index;
                     68:                return;
                     69:        }
                     70: 
                     71:        cl->pers.selected_item = -1;
                     72: }
                     73: 
                     74: void SelectPrevItem (edict_t *ent, int itflags)
                     75: {
                     76:        gclient_t       *cl;
                     77:        int                     i, index;
                     78:        gitem_t         *it;
                     79: 
                     80:        cl = ent->client;
                     81: 
                     82:        // scan  for the next valid one
                     83:        for (i=1 ; i<=MAX_ITEMS ; i++)
                     84:        {
                     85:                index = (cl->pers.selected_item + MAX_ITEMS - i)%MAX_ITEMS;
                     86:                if (!cl->pers.inventory[index])
                     87:                        continue;
                     88:                it = &itemlist[index];
                     89:                if (!it->use)
                     90:                        continue;
                     91:                if (!(it->flags & itflags))
                     92:                        continue;
                     93: 
                     94:                cl->pers.selected_item = index;
                     95:                return;
                     96:        }
                     97: 
                     98:        cl->pers.selected_item = -1;
                     99: }
                    100: 
                    101: void ValidateSelectedItem (edict_t *ent)
                    102: {
                    103:        gclient_t       *cl;
                    104: 
                    105:        cl = ent->client;
                    106: 
                    107:        if (cl->pers.inventory[cl->pers.selected_item])
                    108:                return;         // valid
                    109: 
                    110:        SelectNextItem (ent, -1);
                    111: }
                    112: 
                    113: 
                    114: //=================================================================================
                    115: 
                    116: /*
                    117: ==================
                    118: Cmd_Give_f
                    119: 
                    120: Give items to a client
                    121: ==================
                    122: */
                    123: void Cmd_Give_f (edict_t *ent)
                    124: {
                    125:        char            *name;
                    126:        gitem_t         *it;
                    127:        int                     index;
                    128:        int                     i;
                    129:        qboolean        give_all;
                    130:        edict_t         *it_ent;
                    131: 
                    132:        if (deathmatch->value && !sv_cheats->value)
                    133:        {
                    134:                gi.cprintf (ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
                    135:                return;
                    136:        }
                    137: 
                    138:        name = gi.args();
                    139: 
                    140:        if (Q_stricmp(name, "all") == 0)
                    141:                give_all = true;
                    142:        else
                    143:                give_all = false;
                    144: 
                    145:        if (give_all || Q_stricmp(gi.argv(1), "health") == 0)
                    146:        {
                    147:                if (gi.argc() == 3)
                    148:                        ent->health = atoi(gi.argv(2));
                    149:                else
                    150:                        ent->health = ent->max_health;
                    151:                if (!give_all)
                    152:                        return;
                    153:        }
                    154: 
                    155:        if (give_all || Q_stricmp(name, "weapons") == 0)
                    156:        {
                    157:                for (i=0 ; i<game.num_items ; i++)
                    158:                {
                    159:                        it = itemlist + i;
                    160:                        if (!it->pickup)
                    161:                                continue;
                    162:                        if (!(it->flags & IT_WEAPON))
                    163:                                continue;
                    164:                        ent->client->pers.inventory[i] += 1;
                    165:                }
                    166:                if (!give_all)
                    167:                        return;
                    168:        }
                    169: 
                    170:        if (give_all || Q_stricmp(name, "ammo") == 0)
                    171:        {
                    172:                for (i=0 ; i<game.num_items ; i++)
                    173:                {
                    174:                        it = itemlist + i;
                    175:                        if (!it->pickup)
                    176:                                continue;
                    177:                        if (!(it->flags & IT_AMMO))
                    178:                                continue;
                    179:                        Add_Ammo (ent, it, 1000);
                    180:                }
                    181:                if (!give_all)
                    182:                        return;
                    183:        }
                    184: 
                    185:        if (give_all || Q_stricmp(name, "armor") == 0)
                    186:        {
                    187:                gitem_armor_t   *info;
                    188: 
                    189:                it = FindItem("Jacket Armor");
                    190:                ent->client->pers.inventory[ITEM_INDEX(it)] = 0;
                    191: 
                    192:                it = FindItem("Combat Armor");
                    193:                ent->client->pers.inventory[ITEM_INDEX(it)] = 0;
                    194: 
                    195:                it = FindItem("Body Armor");
                    196:                info = (gitem_armor_t *)it->info;
                    197:                ent->client->pers.inventory[ITEM_INDEX(it)] = info->max_count;
                    198: 
                    199:                if (!give_all)
                    200:                        return;
                    201:        }
                    202: 
                    203:        if (give_all || Q_stricmp(name, "Power Shield") == 0)
                    204:        {
                    205:                it = FindItem("Power Shield");
                    206:                it_ent = G_Spawn();
                    207:                it_ent->classname = it->classname;
                    208:                SpawnItem (it_ent, it);
                    209:                Touch_Item (it_ent, ent, NULL, NULL);
                    210:                if (it_ent->inuse)
                    211:                        G_FreeEdict(it_ent);
                    212: 
                    213:                if (!give_all)
                    214:                        return;
                    215:        }
                    216: 
                    217:        if (give_all)
                    218:        {
                    219:                for (i=0 ; i<game.num_items ; i++)
                    220:                {
                    221:                        it = itemlist + i;
                    222:                        if (!it->pickup)
                    223:                                continue;
                    224:                        if (it->flags & (IT_ARMOR|IT_WEAPON|IT_AMMO))
                    225:                                continue;
                    226:                        ent->client->pers.inventory[i] = 1;
                    227:                }
                    228:                return;
                    229:        }
                    230: 
                    231:        it = FindItem (name);
                    232:        if (!it)
                    233:        {
                    234:                name = gi.argv(1);
                    235:                it = FindItem (name);
                    236:                if (!it)
                    237:                {
1.1.1.2 ! root      238:                        gi.cprintf (ent, PRINT_HIGH, "unknown item\n");
1.1       root      239:                        return;
                    240:                }
                    241:        }
                    242: 
                    243:        if (!it->pickup)
                    244:        {
1.1.1.2 ! root      245:                gi.cprintf (ent, PRINT_HIGH, "non-pickup item\n");
1.1       root      246:                return;
                    247:        }
                    248: 
                    249:        index = ITEM_INDEX(it);
                    250: 
                    251:        if (it->flags & IT_AMMO)
                    252:        {
                    253:                if (gi.argc() == 3)
                    254:                        ent->client->pers.inventory[index] = atoi(gi.argv(2));
                    255:                else
                    256:                        ent->client->pers.inventory[index] += it->quantity;
                    257:        }
                    258:        else
                    259:        {
                    260:                it_ent = G_Spawn();
                    261:                it_ent->classname = it->classname;
                    262:                SpawnItem (it_ent, it);
                    263:                Touch_Item (it_ent, ent, NULL, NULL);
                    264:                if (it_ent->inuse)
                    265:                        G_FreeEdict(it_ent);
                    266:        }
                    267: }
                    268: 
                    269: 
                    270: /*
                    271: ==================
                    272: Cmd_God_f
                    273: 
                    274: Sets client to godmode
                    275: 
                    276: argv(0) god
                    277: ==================
                    278: */
                    279: void Cmd_God_f (edict_t *ent)
                    280: {
                    281:        char    *msg;
                    282: 
                    283:        if (deathmatch->value && !sv_cheats->value)
                    284:        {
                    285:                gi.cprintf (ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
                    286:                return;
                    287:        }
                    288: 
                    289:        ent->flags ^= FL_GODMODE;
                    290:        if (!(ent->flags & FL_GODMODE) )
                    291:                msg = "godmode OFF\n";
                    292:        else
                    293:                msg = "godmode ON\n";
                    294: 
                    295:        gi.cprintf (ent, PRINT_HIGH, msg);
                    296: }
                    297: 
                    298: 
                    299: /*
                    300: ==================
                    301: Cmd_Notarget_f
                    302: 
                    303: Sets client to notarget
                    304: 
                    305: argv(0) notarget
                    306: ==================
                    307: */
                    308: void Cmd_Notarget_f (edict_t *ent)
                    309: {
                    310:        char    *msg;
                    311: 
                    312:        if (deathmatch->value && !sv_cheats->value)
                    313:        {
                    314:                gi.cprintf (ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
                    315:                return;
                    316:        }
                    317: 
                    318:        ent->flags ^= FL_NOTARGET;
                    319:        if (!(ent->flags & FL_NOTARGET) )
                    320:                msg = "notarget OFF\n";
                    321:        else
                    322:                msg = "notarget ON\n";
                    323: 
                    324:        gi.cprintf (ent, PRINT_HIGH, msg);
                    325: }
                    326: 
                    327: 
                    328: /*
                    329: ==================
                    330: Cmd_Noclip_f
                    331: 
                    332: argv(0) noclip
                    333: ==================
                    334: */
                    335: void Cmd_Noclip_f (edict_t *ent)
                    336: {
                    337:        char    *msg;
                    338: 
                    339:        if (deathmatch->value && !sv_cheats->value)
                    340:        {
                    341:                gi.cprintf (ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
                    342:                return;
                    343:        }
                    344: 
                    345:        if (ent->movetype == MOVETYPE_NOCLIP)
                    346:        {
                    347:                ent->movetype = MOVETYPE_WALK;
                    348:                msg = "noclip OFF\n";
                    349:        }
                    350:        else
                    351:        {
                    352:                ent->movetype = MOVETYPE_NOCLIP;
                    353:                msg = "noclip ON\n";
                    354:        }
                    355: 
                    356:        gi.cprintf (ent, PRINT_HIGH, msg);
                    357: }
                    358: 
                    359: 
                    360: /*
                    361: ==================
                    362: Cmd_Use_f
                    363: 
                    364: Use an inventory item
                    365: ==================
                    366: */
                    367: void Cmd_Use_f (edict_t *ent)
                    368: {
                    369:        int                     index;
                    370:        gitem_t         *it;
                    371:        char            *s;
                    372: 
                    373:        s = gi.args();
                    374:        it = FindItem (s);
                    375:        if (!it)
                    376:        {
                    377:                gi.cprintf (ent, PRINT_HIGH, "unknown item: %s\n", s);
                    378:                return;
                    379:        }
                    380:        if (!it->use)
                    381:        {
                    382:                gi.cprintf (ent, PRINT_HIGH, "Item is not usable.\n");
                    383:                return;
                    384:        }
                    385:        index = ITEM_INDEX(it);
                    386:        if (!ent->client->pers.inventory[index])
                    387:        {
                    388:                gi.cprintf (ent, PRINT_HIGH, "Out of item: %s\n", s);
                    389:                return;
                    390:        }
                    391: 
                    392:        it->use (ent, it);
                    393: }
                    394: 
                    395: 
                    396: /*
                    397: ==================
                    398: Cmd_Drop_f
                    399: 
                    400: Drop an inventory item
                    401: ==================
                    402: */
                    403: void Cmd_Drop_f (edict_t *ent)
                    404: {
                    405:        int                     index;
                    406:        gitem_t         *it;
                    407:        char            *s;
                    408: 
                    409:        s = gi.args();
                    410:        it = FindItem (s);
                    411:        if (!it)
                    412:        {
                    413:                gi.cprintf (ent, PRINT_HIGH, "unknown item: %s\n", s);
                    414:                return;
                    415:        }
                    416:        if (!it->drop)
                    417:        {
                    418:                gi.cprintf (ent, PRINT_HIGH, "Item is not dropable.\n");
                    419:                return;
                    420:        }
                    421:        index = ITEM_INDEX(it);
                    422:        if (!ent->client->pers.inventory[index])
                    423:        {
                    424:                gi.cprintf (ent, PRINT_HIGH, "Out of item: %s\n", s);
                    425:                return;
                    426:        }
                    427: 
                    428:        it->drop (ent, it);
                    429: }
                    430: 
                    431: 
                    432: /*
                    433: =================
                    434: Cmd_Inven_f
                    435: =================
                    436: */
                    437: void Cmd_Inven_f (edict_t *ent)
                    438: {
                    439:        int                     i;
                    440:        gclient_t       *cl;
                    441: 
                    442:        cl = ent->client;
                    443: 
                    444:        cl->showscores = false;
                    445:        cl->showhelp = false;
                    446: 
                    447:        if (cl->showinventory)
                    448:        {
                    449:                cl->showinventory = false;
                    450:                return;
                    451:        }
                    452: 
                    453:        cl->showinventory = true;
                    454: 
                    455:        gi.WriteByte (svc_inventory);
                    456:        for (i=0 ; i<MAX_ITEMS ; i++)
                    457:        {
                    458:                gi.WriteShort (cl->pers.inventory[i]);
                    459:        }
                    460:        gi.unicast (ent, true);
                    461: }
                    462: 
                    463: /*
                    464: =================
                    465: Cmd_InvUse_f
                    466: =================
                    467: */
                    468: void Cmd_InvUse_f (edict_t *ent)
                    469: {
                    470:        gitem_t         *it;
                    471: 
                    472:        ValidateSelectedItem (ent);
                    473: 
                    474:        if (ent->client->pers.selected_item == -1)
                    475:        {
                    476:                gi.cprintf (ent, PRINT_HIGH, "No item to use.\n");
                    477:                return;
                    478:        }
                    479: 
                    480:        it = &itemlist[ent->client->pers.selected_item];
                    481:        if (!it->use)
                    482:        {
                    483:                gi.cprintf (ent, PRINT_HIGH, "Item is not usable.\n");
                    484:                return;
                    485:        }
                    486:        it->use (ent, it);
                    487: }
                    488: 
                    489: /*
                    490: =================
                    491: Cmd_WeapPrev_f
                    492: =================
                    493: */
                    494: void Cmd_WeapPrev_f (edict_t *ent)
                    495: {
                    496:        gclient_t       *cl;
                    497:        int                     i, index;
                    498:        gitem_t         *it;
                    499:        int                     selected_weapon;
                    500: 
                    501:        cl = ent->client;
                    502: 
                    503:        if (!cl->pers.weapon)
                    504:                return;
                    505: 
                    506:        selected_weapon = ITEM_INDEX(cl->pers.weapon);
                    507: 
                    508:        // scan  for the next valid one
                    509:        for (i=1 ; i<=MAX_ITEMS ; i++)
                    510:        {
                    511:                index = (selected_weapon + i)%MAX_ITEMS;
                    512:                if (!cl->pers.inventory[index])
                    513:                        continue;
                    514:                it = &itemlist[index];
                    515:                if (!it->use)
                    516:                        continue;
                    517:                if (! (it->flags & IT_WEAPON) )
                    518:                        continue;
                    519:                it->use (ent, it);
                    520:                if (cl->pers.weapon == it)
                    521:                        return; // successful
                    522:        }
                    523: }
                    524: 
                    525: /*
                    526: =================
                    527: Cmd_WeapNext_f
                    528: =================
                    529: */
                    530: void Cmd_WeapNext_f (edict_t *ent)
                    531: {
                    532:        gclient_t       *cl;
                    533:        int                     i, index;
                    534:        gitem_t         *it;
                    535:        int                     selected_weapon;
                    536: 
                    537:        cl = ent->client;
                    538: 
                    539:        if (!cl->pers.weapon)
                    540:                return;
                    541: 
                    542:        selected_weapon = ITEM_INDEX(cl->pers.weapon);
                    543: 
                    544:        // scan  for the next valid one
                    545:        for (i=1 ; i<=MAX_ITEMS ; i++)
                    546:        {
                    547:                index = (selected_weapon + MAX_ITEMS - i)%MAX_ITEMS;
                    548:                if (!cl->pers.inventory[index])
                    549:                        continue;
                    550:                it = &itemlist[index];
                    551:                if (!it->use)
                    552:                        continue;
                    553:                if (! (it->flags & IT_WEAPON) )
                    554:                        continue;
                    555:                it->use (ent, it);
                    556:                if (cl->pers.weapon == it)
                    557:                        return; // successful
                    558:        }
                    559: }
                    560: 
                    561: /*
                    562: =================
                    563: Cmd_WeapLast_f
                    564: =================
                    565: */
                    566: void Cmd_WeapLast_f (edict_t *ent)
                    567: {
                    568:        gclient_t       *cl;
                    569:        int                     index;
                    570:        gitem_t         *it;
                    571: 
                    572:        cl = ent->client;
                    573: 
                    574:        if (!cl->pers.weapon || !cl->pers.lastweapon)
                    575:                return;
                    576: 
                    577:        index = ITEM_INDEX(cl->pers.lastweapon);
                    578:        if (!cl->pers.inventory[index])
                    579:                return;
                    580:        it = &itemlist[index];
                    581:        if (!it->use)
                    582:                return;
                    583:        if (! (it->flags & IT_WEAPON) )
                    584:                return;
                    585:        it->use (ent, it);
                    586: }
                    587: 
                    588: /*
                    589: =================
                    590: Cmd_InvDrop_f
                    591: =================
                    592: */
                    593: void Cmd_InvDrop_f (edict_t *ent)
                    594: {
                    595:        gitem_t         *it;
                    596: 
                    597:        ValidateSelectedItem (ent);
                    598: 
                    599:        if (ent->client->pers.selected_item == -1)
                    600:        {
                    601:                gi.cprintf (ent, PRINT_HIGH, "No item to drop.\n");
                    602:                return;
                    603:        }
                    604: 
                    605:        it = &itemlist[ent->client->pers.selected_item];
                    606:        if (!it->drop)
                    607:        {
                    608:                gi.cprintf (ent, PRINT_HIGH, "Item is not dropable.\n");
                    609:                return;
                    610:        }
                    611:        it->drop (ent, it);
                    612: }
                    613: 
                    614: /*
                    615: =================
                    616: Cmd_Kill_f
                    617: =================
                    618: */
                    619: void Cmd_Kill_f (edict_t *ent)
                    620: {
                    621:        if((level.time - ent->client->respawn_time) < 5)
                    622:                return;
                    623:        ent->flags &= ~FL_GODMODE;
                    624:        ent->health = 0;
                    625:        meansOfDeath = MOD_SUICIDE;
                    626:        player_die (ent, ent, ent, 100000, vec3_origin);
                    627: }
                    628: 
                    629: /*
                    630: =================
                    631: Cmd_PutAway_f
                    632: =================
                    633: */
                    634: void Cmd_PutAway_f (edict_t *ent)
                    635: {
                    636:        ent->client->showscores = false;
                    637:        ent->client->showhelp = false;
                    638:        ent->client->showinventory = false;
                    639: }
                    640: 
                    641: 
                    642: int PlayerSort (void const *a, void const *b)
                    643: {
                    644:        int             anum, bnum;
                    645: 
                    646:        anum = *(int *)a;
                    647:        bnum = *(int *)b;
                    648: 
                    649:        anum = game.clients[anum].ps.stats[STAT_FRAGS];
                    650:        bnum = game.clients[bnum].ps.stats[STAT_FRAGS];
                    651: 
                    652:        if (anum < bnum)
                    653:                return -1;
                    654:        if (anum > bnum)
                    655:                return 1;
                    656:        return 0;
                    657: }
                    658: 
                    659: /*
                    660: =================
                    661: Cmd_Players_f
                    662: =================
                    663: */
                    664: void Cmd_Players_f (edict_t *ent)
                    665: {
                    666:        int             i;
                    667:        int             count;
                    668:        char    small[64];
                    669:        char    large[1280];
                    670:        int             index[256];
                    671: 
                    672:        count = 0;
                    673:        for (i = 0 ; i < maxclients->value ; i++)
                    674:                if (game.clients[i].pers.connected)
                    675:                {
                    676:                        index[count] = i;
                    677:                        count++;
                    678:                }
                    679: 
                    680:        // sort by frags
                    681:        qsort (index, count, sizeof(index[0]), PlayerSort);
                    682: 
                    683:        // print information
                    684:        large[0] = 0;
                    685: 
                    686:        for (i = 0 ; i < count ; i++)
                    687:        {
                    688:                Com_sprintf (small, sizeof(small), "%3i %s\n",
                    689:                        game.clients[index[i]].ps.stats[STAT_FRAGS],
                    690:                        game.clients[index[i]].pers.netname);
                    691:                if (strlen (small) + strlen(large) > sizeof(large) - 100 )
                    692:                {       // can't print all of them in one packet
                    693:                        strcat (large, "...\n");
                    694:                        break;
                    695:                }
                    696:                strcat (large, small);
                    697:        }
                    698: 
                    699:        gi.cprintf (ent, PRINT_HIGH, "%s\n%i players\n", large, count);
                    700: }
                    701: 
                    702: /*
                    703: =================
                    704: Cmd_Wave_f
                    705: =================
                    706: */
                    707: void Cmd_Wave_f (edict_t *ent)
                    708: {
                    709:        int             i;
                    710: 
                    711:        i = atoi (gi.argv(1));
                    712: 
                    713:        // can't wave when ducked
                    714:        if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
                    715:                return;
                    716: 
                    717:        if (ent->client->anim_priority > ANIM_WAVE)
                    718:                return;
                    719: 
                    720:        ent->client->anim_priority = ANIM_WAVE;
                    721: 
                    722:        switch (i)
                    723:        {
                    724:        case 0:
                    725:                gi.cprintf (ent, PRINT_HIGH, "flipoff\n");
                    726:                ent->s.frame = FRAME_flip01-1;
                    727:                ent->client->anim_end = FRAME_flip12;
                    728:                break;
                    729:        case 1:
                    730:                gi.cprintf (ent, PRINT_HIGH, "salute\n");
                    731:                ent->s.frame = FRAME_salute01-1;
                    732:                ent->client->anim_end = FRAME_salute11;
                    733:                break;
                    734:        case 2:
                    735:                gi.cprintf (ent, PRINT_HIGH, "taunt\n");
                    736:                ent->s.frame = FRAME_taunt01-1;
                    737:                ent->client->anim_end = FRAME_taunt17;
                    738:                break;
                    739:        case 3:
                    740:                gi.cprintf (ent, PRINT_HIGH, "wave\n");
                    741:                ent->s.frame = FRAME_wave01-1;
                    742:                ent->client->anim_end = FRAME_wave11;
                    743:                break;
                    744:        case 4:
                    745:        default:
                    746:                gi.cprintf (ent, PRINT_HIGH, "point\n");
                    747:                ent->s.frame = FRAME_point01-1;
                    748:                ent->client->anim_end = FRAME_point12;
                    749:                break;
                    750:        }
                    751: }
                    752: 
                    753: /*
                    754: ==================
                    755: Cmd_Say_f
                    756: ==================
                    757: */
                    758: void Cmd_Say_f (edict_t *ent, qboolean team, qboolean arg0)
                    759: {
1.1.1.2 ! root      760:        int             i, j;
1.1       root      761:        edict_t *other;
                    762:        char    *p;
                    763:        char    text[2048];
1.1.1.2 ! root      764:        gclient_t *cl;
1.1       root      765: 
                    766:        if (gi.argc () < 2 && !arg0)
                    767:                return;
                    768: 
                    769:        if (!((int)(dmflags->value) & (DF_MODELTEAMS | DF_SKINTEAMS)))
                    770:                team = false;
                    771: 
                    772:        if (team)
                    773:                Com_sprintf (text, sizeof(text), "(%s): ", ent->client->pers.netname);
                    774:        else
                    775:                Com_sprintf (text, sizeof(text), "%s: ", ent->client->pers.netname);
                    776: 
                    777:        if (arg0)
                    778:        {
                    779:                strcat (text, gi.argv(0));
                    780:                strcat (text, " ");
                    781:                strcat (text, gi.args());
                    782:        }
                    783:        else
                    784:        {
                    785:                p = gi.args();
                    786: 
                    787:                if (*p == '"')
                    788:                {
                    789:                        p++;
                    790:                        p[strlen(p)-1] = 0;
                    791:                }
                    792:                strcat(text, p);
                    793:        }
                    794: 
                    795:        // don't let text be too long for malicious reasons
                    796:        if (strlen(text) > 150)
                    797:                text[150] = 0;
                    798: 
                    799:        strcat(text, "\n");
                    800: 
1.1.1.2 ! root      801:        if (flood_msgs->value) {
        !           802:                cl = ent->client;
        !           803: 
        !           804:         if (level.time < cl->flood_locktill) {
        !           805:                        gi.cprintf(ent, PRINT_HIGH, "You can't talk for %d more seconds\n",
        !           806:                                (int)(cl->flood_locktill - level.time));
        !           807:             return;
        !           808:         }
        !           809:         i = cl->flood_whenhead - flood_msgs->value + 1;
        !           810:         if (i < 0)
        !           811:             i = (sizeof(cl->flood_when)/sizeof(cl->flood_when[0])) + i;
        !           812:                if (cl->flood_when[i] && 
        !           813:                        level.time - cl->flood_when[i] < flood_persecond->value) {
        !           814:                        cl->flood_locktill = level.time + flood_waitdelay->value;
        !           815:                        gi.cprintf(ent, PRINT_CHAT, "Flood protection:  You can't talk for %d seconds.\n",
        !           816:                                (int)flood_waitdelay->value);
        !           817:             return;
        !           818:         }
        !           819:                cl->flood_whenhead = (cl->flood_whenhead + 1) %
        !           820:                        (sizeof(cl->flood_when)/sizeof(cl->flood_when[0]));
        !           821:                cl->flood_when[cl->flood_whenhead] = level.time;
        !           822:        }
        !           823: 
1.1       root      824:        if (dedicated->value)
                    825:                gi.cprintf(NULL, PRINT_CHAT, "%s", text);
                    826: 
                    827:        for (j = 1; j <= game.maxclients; j++)
                    828:        {
                    829:                other = &g_edicts[j];
                    830:                if (!other->inuse)
                    831:                        continue;
                    832:                if (!other->client)
                    833:                        continue;
                    834:                if (team)
                    835:                {
                    836:                        if (!OnSameTeam(ent, other))
                    837:                                continue;
                    838:                }
                    839:                gi.cprintf(other, PRINT_CHAT, "%s", text);
                    840:        }
                    841: }
                    842: 
                    843: /*
                    844: =================
                    845: ClientCommand
                    846: =================
                    847: */
                    848: void ClientCommand (edict_t *ent)
                    849: {
                    850:        char    *cmd;
                    851: 
                    852:        if (!ent->client)
                    853:                return;         // not fully in game yet
                    854: 
                    855:        cmd = gi.argv(0);
                    856: 
                    857:        if (Q_stricmp (cmd, "players") == 0)
                    858:        {
                    859:                Cmd_Players_f (ent);
                    860:                return;
                    861:        }
                    862:        if (Q_stricmp (cmd, "say") == 0)
                    863:        {
                    864:                Cmd_Say_f (ent, false, false);
                    865:                return;
                    866:        }
                    867:        if (Q_stricmp (cmd, "say_team") == 0)
                    868:        {
                    869:                Cmd_Say_f (ent, true, false);
                    870:                return;
                    871:        }
                    872:        if (Q_stricmp (cmd, "score") == 0)
                    873:        {
                    874:                Cmd_Score_f (ent);
                    875:                return;
                    876:        }
                    877:        if (Q_stricmp (cmd, "help") == 0)
                    878:        {
                    879:                Cmd_Help_f (ent);
                    880:                return;
                    881:        }
                    882: 
                    883:        if (level.intermissiontime)
                    884:                return;
                    885: 
                    886:        if (Q_stricmp (cmd, "use") == 0)
                    887:                Cmd_Use_f (ent);
                    888:        else if (Q_stricmp (cmd, "drop") == 0)
                    889:                Cmd_Drop_f (ent);
                    890:        else if (Q_stricmp (cmd, "give") == 0)
                    891:                Cmd_Give_f (ent);
                    892:        else if (Q_stricmp (cmd, "god") == 0)
                    893:                Cmd_God_f (ent);
                    894:        else if (Q_stricmp (cmd, "notarget") == 0)
                    895:                Cmd_Notarget_f (ent);
                    896:        else if (Q_stricmp (cmd, "noclip") == 0)
                    897:                Cmd_Noclip_f (ent);
                    898:        else if (Q_stricmp (cmd, "inven") == 0)
                    899:                Cmd_Inven_f (ent);
                    900:        else if (Q_stricmp (cmd, "invnext") == 0)
                    901:                SelectNextItem (ent, -1);
                    902:        else if (Q_stricmp (cmd, "invprev") == 0)
                    903:                SelectPrevItem (ent, -1);
                    904:        else if (Q_stricmp (cmd, "invnextw") == 0)
                    905:                SelectNextItem (ent, IT_WEAPON);
                    906:        else if (Q_stricmp (cmd, "invprevw") == 0)
                    907:                SelectPrevItem (ent, IT_WEAPON);
                    908:        else if (Q_stricmp (cmd, "invnextp") == 0)
                    909:                SelectNextItem (ent, IT_POWERUP);
                    910:        else if (Q_stricmp (cmd, "invprevp") == 0)
                    911:                SelectPrevItem (ent, IT_POWERUP);
                    912:        else if (Q_stricmp (cmd, "invuse") == 0)
                    913:                Cmd_InvUse_f (ent);
                    914:        else if (Q_stricmp (cmd, "invdrop") == 0)
                    915:                Cmd_InvDrop_f (ent);
                    916:        else if (Q_stricmp (cmd, "weapprev") == 0)
                    917:                Cmd_WeapPrev_f (ent);
                    918:        else if (Q_stricmp (cmd, "weapnext") == 0)
                    919:                Cmd_WeapNext_f (ent);
                    920:        else if (Q_stricmp (cmd, "weaplast") == 0)
                    921:                Cmd_WeapLast_f (ent);
                    922:        else if (Q_stricmp (cmd, "kill") == 0)
                    923:                Cmd_Kill_f (ent);
                    924:        else if (Q_stricmp (cmd, "putaway") == 0)
                    925:                Cmd_PutAway_f (ent);
                    926:        else if (Q_stricmp (cmd, "wave") == 0)
                    927:                Cmd_Wave_f (ent);
                    928:        else    // anything that doesn't match a command will be a chat
                    929:                Cmd_Say_f (ent, false, true);
                    930: }

unix.superglobalmegacorp.com

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