home *** CD-ROM | disk | FTP | other *** search
/ Gambler 19 / GAMBLERCD19.BIN / UTILS / 3D / BRONIE / DUAL_LAU.ZIP / src / g_cmds.c < prev    next >
C/C++ Source or Header  |  1998-01-14  |  12KB  |  652 lines

  1. #include "g_local.h"
  2. #include "m_player.h"
  3.  
  4.  
  5. void SelectNextItem (edict_t *ent)
  6. {
  7.     gclient_t    *cl;
  8.     int            i, index;
  9.     gitem_t        *it;
  10.  
  11.     cl = ent->client;
  12.  
  13.     // scan  for the next valid one
  14.     for (i=1 ; i<=MAX_ITEMS ; i++)
  15.     {
  16.         index = (cl->pers.selected_item + i)%MAX_ITEMS;
  17.         if (!cl->pers.inventory[index])
  18.             continue;
  19.         it = &itemlist[index];
  20.         if (!it->use)
  21.             continue;
  22.  
  23.         cl->pers.selected_item = index;
  24.         return;
  25.     }
  26.  
  27.     cl->pers.selected_item = -1;
  28. }
  29.  
  30. void SelectPrevItem (edict_t *ent)
  31. {
  32.     gclient_t    *cl;
  33.     int            i, index;
  34.     gitem_t        *it;
  35.  
  36.     cl = ent->client;
  37.  
  38.     // scan  for the next valid one
  39.     for (i=1 ; i<=MAX_ITEMS ; i++)
  40.     {
  41.         index = (cl->pers.selected_item + MAX_ITEMS - i)%MAX_ITEMS;
  42.         if (!cl->pers.inventory[index])
  43.             continue;
  44.         it = &itemlist[index];
  45.         if (!it->use)
  46.             continue;
  47.  
  48.         cl->pers.selected_item = index;
  49.         return;
  50.     }
  51.  
  52.     cl->pers.selected_item = -1;
  53. }
  54.  
  55.  
  56.  
  57. void ValidateSelectedItem (edict_t *ent)
  58. {
  59.     gclient_t    *cl;
  60.  
  61.     cl = ent->client;
  62.  
  63.     if (cl->pers.inventory[cl->pers.selected_item])
  64.         return;        // valid
  65.  
  66.     SelectNextItem (ent);
  67. }
  68.  
  69.  
  70. //=================================================================================
  71.  
  72. /*
  73. ==================
  74. Cmd_Give_f
  75.  
  76. Give items to a client
  77. ==================
  78. */
  79. void Cmd_Give_f (edict_t *ent)
  80. {
  81.     char        *name;
  82.     gitem_t        *it;
  83.     int            index;
  84.     int            i;
  85.     qboolean    give_all;
  86.  
  87.     if (deathmatch->value && !sv_cheats->value)
  88.     {
  89.         gi.cprintf (ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
  90.         return;
  91.     }
  92.  
  93.     name = gi.args();
  94.  
  95.     if (Q_stricmp(name, "all") == 0)
  96.         give_all = true;
  97.     else
  98.         give_all = false;
  99.  
  100.     if (give_all || Q_stricmp(name, "health") == 0)
  101.     {
  102.         if (gi.argc() == 3)
  103.             ent->health += atoi(gi.argv(2));
  104.         else
  105.             ent->health = ent->max_health;
  106.         if (!give_all)
  107.             return;
  108.     }
  109.  
  110.     if (give_all || Q_stricmp(name, "weapons") == 0)
  111.     {
  112.         for (i=0 ; i<game.num_items ; i++)
  113.         {
  114.             it = itemlist + i;
  115.             if (!it->pickup)
  116.                 continue;
  117.             if (!(it->flags & IT_WEAPON))
  118.                 continue;
  119.             ent->client->pers.inventory[i] += 1;
  120.         }
  121.         if (!give_all)
  122.             return;
  123.     }
  124.  
  125.     if (give_all || Q_stricmp(name, "ammo") == 0)
  126.     {
  127.         for (i=0 ; i<game.num_items ; i++)
  128.         {
  129.             it = itemlist + i;
  130.             if (!it->pickup)
  131.                 continue;
  132.             if (!(it->flags & IT_AMMO))
  133.                 continue;
  134.             Add_Ammo (ent, it, 1000);
  135.         }
  136.         if (!give_all)
  137.             return;
  138.     }
  139.  
  140.     if (give_all || Q_stricmp(name, "armor") == 0)
  141.     {
  142.         gitem_armor_t    *info;
  143.  
  144.         it = FindItem("Body Armor");
  145.         info = (gitem_armor_t *)it->info;
  146.         ent->client->pers.inventory[ITEM_INDEX(it)] = info->max_count;
  147.  
  148.         if (!give_all)
  149.             return;
  150.     }
  151.  
  152.     if (give_all)
  153.     {
  154.         for (i=0 ; i<game.num_items ; i++)
  155.         {
  156.             it = itemlist + i;
  157.             if (!it->pickup)
  158.                 continue;
  159.             if (it->flags & (IT_ARMOR|IT_WEAPON|IT_AMMO))
  160.                 continue;
  161.             ent->client->pers.inventory[i] = 1;
  162.         }
  163.         return;
  164.     }
  165.  
  166.     it = FindItem (name);
  167.     if (!it)
  168.     {
  169.         name = gi.argv(1);
  170.         it = FindItem (name);
  171.         if (!it)
  172.         {
  173.             gi.dprintf ("unknown item\n");
  174.             return;
  175.         }
  176.     }
  177.  
  178.     if (!it->pickup)
  179.     {
  180.         gi.dprintf ("non-pickup item\n");
  181.         return;
  182.     }
  183.  
  184.     index = ITEM_INDEX(it);
  185.  
  186.     if (it->flags & IT_WEAPON)
  187.     {
  188.         ent->client->pers.inventory[index] += 1;
  189.     }
  190.     else if (it->flags & IT_AMMO)
  191.     {
  192.         if (gi.argc() == 3)
  193.             ent->client->pers.inventory[index] += atoi(gi.argv(2));
  194.         else
  195.             ent->client->pers.inventory[index] += it->quantity;
  196.     }
  197.     else
  198.     {
  199.         ent->client->pers.inventory[index] += 1;
  200.     }
  201. }
  202.  
  203.  
  204. /*
  205. ==================
  206. Cmd_God_f
  207.  
  208. Sets client to godmode
  209.  
  210. argv(0) god
  211. ==================
  212. */
  213. void Cmd_God_f (edict_t *ent)
  214. {
  215.     char    *msg;
  216.  
  217.     if (deathmatch->value && !sv_cheats->value)
  218.     {
  219.         gi.cprintf (ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
  220.         return;
  221.     }
  222.  
  223.     ent->flags ^= FL_GODMODE;
  224.     if (!(ent->flags & FL_GODMODE) )
  225.         msg = "godmode OFF\n";
  226.     else
  227.         msg = "godmode ON\n";
  228.  
  229.     gi.cprintf (ent, PRINT_HIGH, msg);
  230. }
  231.  
  232.  
  233. /*
  234. ==================
  235. Cmd_Notarget_f
  236.  
  237. Sets client to notarget
  238.  
  239. argv(0) notarget
  240. ==================
  241. */
  242. void Cmd_Notarget_f (edict_t *ent)
  243. {
  244.     char    *msg;
  245.  
  246.     if (deathmatch->value && !sv_cheats->value)
  247.     {
  248.         gi.cprintf (ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
  249.         return;
  250.     }
  251.  
  252.     ent->flags ^= FL_NOTARGET;
  253.     if (!(ent->flags & FL_NOTARGET) )
  254.         msg = "notarget OFF\n";
  255.     else
  256.         msg = "notarget ON\n";
  257.  
  258.     gi.cprintf (ent, PRINT_HIGH, msg);
  259. }
  260.  
  261.  
  262. /*
  263. ==================
  264. Cmd_Noclip_f
  265.  
  266. argv(0) noclip
  267. ==================
  268. */
  269. void Cmd_Noclip_f (edict_t *ent)
  270. {
  271.     char    *msg;
  272.  
  273.     if (deathmatch->value && !sv_cheats->value)
  274.     {
  275.         gi.cprintf (ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");
  276.         return;
  277.     }
  278.  
  279.     if (ent->movetype == MOVETYPE_NOCLIP)
  280.     {
  281.         ent->movetype = MOVETYPE_WALK;
  282.         msg = "noclip OFF\n";
  283.     }
  284.     else
  285.     {
  286.         ent->movetype = MOVETYPE_NOCLIP;
  287.         msg = "noclip ON\n";
  288.     }
  289.  
  290.     gi.cprintf (ent, PRINT_HIGH, msg);
  291. }
  292.  
  293.  
  294. /*
  295. ==================
  296. Cmd_Use_f
  297.  
  298. Use an inventory item
  299. ==================
  300. */
  301. void Cmd_Use_f (edict_t *ent)
  302. {
  303.     int            index;
  304.     gitem_t        *it;
  305.     char        *s;
  306.  
  307.     s = gi.args();
  308.     it = FindItem (s);
  309.     if (!it)
  310.     {
  311.         gi.cprintf (ent, PRINT_HIGH, "unknown item: %s\n", s);
  312.         return;
  313.     }
  314.     index = ITEM_INDEX(it);
  315.     if (!ent->client->pers.inventory[index])
  316.     {
  317.         gi.cprintf (ent, PRINT_HIGH, "Out of item: %s\n", s);
  318.         return;
  319.     }
  320.  
  321.     it->use (ent, it);
  322. }
  323.  
  324.  
  325. /*
  326. ==================
  327. Cmd_Drop_f
  328.  
  329. Drop an inventory item
  330. ==================
  331. */
  332. void Cmd_Drop_f (edict_t *ent)
  333. {
  334.     int            index;
  335.     gitem_t        *it;
  336.     char        *s;
  337.  
  338.     if (!(deathmatch->value))    // no dropping in single player
  339.         return;
  340.  
  341.     s = gi.args();
  342.     it = FindItem (s);
  343.     if (!it)
  344.     {
  345.         gi.cprintf (ent, PRINT_HIGH, "unknown item: %s\n", s);
  346.         return;
  347.     }
  348.     index = ITEM_INDEX(it);
  349.     if (!ent->client->pers.inventory[index])
  350.     {
  351.         gi.cprintf (ent, PRINT_HIGH, "Out of item: %s\n", s);
  352.         return;
  353.     }
  354.  
  355.     it->drop (ent, it);
  356. }
  357.  
  358.  
  359. /*
  360. =================
  361. Cmd_Inven_f
  362. =================
  363. */
  364. void Cmd_Inven_f (edict_t *ent)
  365. {
  366.     int            i;
  367.     gclient_t    *cl;
  368.  
  369.     cl = ent->client;
  370.  
  371.     if (cl->showinventory)
  372.     {
  373.         cl->showinventory = false;
  374.         return;
  375.     }
  376.  
  377.     cl->showinventory = true;
  378.     cl->showscores = false;
  379.  
  380.     gi.WriteByte (svc_inventory);
  381.     for (i=0 ; i<MAX_ITEMS ; i++)
  382.     {
  383.         gi.WriteShort (cl->pers.inventory[i]);
  384.     }
  385.     gi.unicast (ent, true);
  386. }
  387.  
  388. /*
  389. =================
  390. Cmd_InvUse_f
  391. =================
  392. */
  393. void Cmd_InvUse_f (edict_t *ent)
  394. {
  395.     gitem_t        *it;
  396.  
  397.     ValidateSelectedItem (ent);
  398.  
  399.     if (ent->client->pers.selected_item == -1)
  400.     {
  401.         gi.cprintf (ent, PRINT_HIGH, "No item to use.\n");
  402.         return;
  403.     }
  404.  
  405.     it = &itemlist[ent->client->pers.selected_item];
  406.     if (!it->use)
  407.     {
  408.         gi.cprintf (ent, PRINT_HIGH, "Item is not usable.\n");
  409.         return;
  410.     }
  411.     it->use (ent, it);
  412. }
  413.  
  414. /*
  415. =================
  416. Cmd_WeapPrev_f
  417. =================
  418. */
  419. void Cmd_WeapPrev_f (edict_t *ent)
  420. {
  421.     gclient_t    *cl;
  422.     int            i, index;
  423.     gitem_t        *it;
  424.     int            selected_weapon;
  425.  
  426.     cl = ent->client;
  427.  
  428.     if (!cl->pers.weapon)
  429.         return;
  430.  
  431.     selected_weapon = ITEM_INDEX(cl->pers.weapon);
  432.  
  433.     // scan  for the next valid one
  434.     for (i=1 ; i<=MAX_ITEMS ; i++)
  435.     {
  436.         index = (selected_weapon + i)%MAX_ITEMS;
  437.         if (!cl->pers.inventory[index])
  438.             continue;
  439.         it = &itemlist[index];
  440.         if (!it->use)
  441.             continue;
  442.         if (! (it->flags & IT_WEAPON) )
  443.             continue;
  444.         it->use (ent, it);
  445.         if (cl->pers.weapon == it)
  446.             return;    // successful
  447.     }
  448. }
  449.  
  450. /*
  451. =================
  452. Cmd_WeapNext_f
  453. =================
  454. */
  455. void Cmd_WeapNext_f (edict_t *ent)
  456. {
  457.     gclient_t    *cl;
  458.     int            i, index;
  459.     gitem_t        *it;
  460.     int            selected_weapon;
  461.  
  462.     cl = ent->client;
  463.  
  464.     if (!cl->pers.weapon)
  465.         return;
  466.  
  467.     selected_weapon = ITEM_INDEX(cl->pers.weapon);
  468.  
  469.     // scan  for the next valid one
  470.     for (i=1 ; i<=MAX_ITEMS ; i++)
  471.     {
  472.         index = (selected_weapon + MAX_ITEMS - i)%MAX_ITEMS;
  473.         if (!cl->pers.inventory[index])
  474.             continue;
  475.         it = &itemlist[index];
  476.         if (!it->use)
  477.             continue;
  478.         if (! (it->flags & IT_WEAPON) )
  479.             continue;
  480.         it->use (ent, it);
  481.         if (cl->pers.weapon == it)
  482.             return;    // successful
  483.     }
  484. }
  485.  
  486. /*
  487. =================
  488. Cmd_InvDrop_f
  489. =================
  490. */
  491. void Cmd_InvDrop_f (edict_t *ent)
  492. {
  493.     gitem_t        *it;
  494.  
  495.     ValidateSelectedItem (ent);
  496.  
  497.     if (ent->client->pers.selected_item == -1)
  498.     {
  499.         gi.cprintf (ent, PRINT_HIGH, "No item to drop.\n");
  500.         return;
  501.     }
  502.  
  503.     it = &itemlist[ent->client->pers.selected_item];
  504.     if (!it->drop)
  505.     {
  506.         gi.cprintf (ent, PRINT_HIGH, "Item is not dropable.\n");
  507.         return;
  508.     }
  509.     it->drop (ent, it);
  510. }
  511.  
  512. /*
  513. =================
  514. Cmd_Kill_f
  515. =================
  516. */
  517. void Cmd_Kill_f (edict_t *ent)
  518. {
  519.     ent->flags &= ~FL_GODMODE;
  520.     ent->health = 0;
  521.     player_die (ent, ent, ent, 100000, vec3_origin);
  522.     // don't even bother waiting for death frames
  523.     ent->deadflag = DEAD_DEAD;
  524.     respawn (ent);
  525. }
  526.  
  527. /*
  528. =================
  529. Cmd_PutAway_f
  530. =================
  531. */
  532. void Cmd_PutAway_f (edict_t *ent)
  533. {
  534.     ent->client->showscores = false;
  535.     ent->client->showinventory = false;
  536. }
  537.  
  538. /*
  539. =================
  540. Cmd_Wave_f
  541. =================
  542. */
  543. void Cmd_Wave_f (edict_t *ent)
  544. {
  545.     int        i;
  546.  
  547.     i = atoi (gi.argv(1));
  548.  
  549.     // can't wave when ducked
  550.     if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
  551.         return;
  552.  
  553.     if (ent->client->anim_priority > ANIM_WAVE)
  554.         return;
  555.  
  556.     ent->client->anim_priority = ANIM_WAVE;
  557.  
  558.     switch (i)
  559.     {
  560.     case 0:
  561.         gi.cprintf (ent, PRINT_HIGH, "flipoff\n");
  562.         ent->s.frame = FRAME_flip01-1;
  563.         ent->client->anim_end = FRAME_flip12;
  564.         break;
  565.     case 1:
  566.         gi.cprintf (ent, PRINT_HIGH, "salute\n");
  567.         ent->s.frame = FRAME_salute01-1;
  568.         ent->client->anim_end = FRAME_salute11;
  569.         break;
  570.     case 2:
  571.         gi.cprintf (ent, PRINT_HIGH, "taunt\n");
  572.         ent->s.frame = FRAME_taunt01-1;
  573.         ent->client->anim_end = FRAME_taunt17;
  574.         break;
  575.     case 3:
  576.         gi.cprintf (ent, PRINT_HIGH, "wave\n");
  577.         ent->s.frame = FRAME_wave01-1;
  578.         ent->client->anim_end = FRAME_wave11;
  579.         break;
  580.     case 4:
  581.     default:
  582.         gi.cprintf (ent, PRINT_HIGH, "point\n");
  583.         ent->s.frame = FRAME_point01-1;
  584.         ent->client->anim_end = FRAME_point12;
  585.         break;
  586.     }
  587. }
  588.  
  589. /*
  590. =================
  591. ClientCommand
  592. =================
  593. */
  594. void ClientCommand (edict_t *ent)
  595. {
  596.     char    *cmd;
  597.  
  598.     if (!ent->client)
  599.         return;        // not fully in game yet
  600.  
  601.     cmd = gi.argv(0);
  602.     if (Q_stricmp (cmd, "use") == 0)
  603.         Cmd_Use_f (ent);
  604.     else if (Q_stricmp (cmd, "drop") == 0)
  605.         Cmd_Drop_f (ent);
  606.     else if (Q_stricmp (cmd, "give") == 0)
  607.         Cmd_Give_f (ent);
  608.     else if (Q_stricmp (cmd, "god") == 0)
  609.         Cmd_God_f (ent);
  610.     else if (Q_stricmp (cmd, "notarget") == 0)
  611.         Cmd_Notarget_f (ent);
  612.     else if (Q_stricmp (cmd, "noclip") == 0)
  613.         Cmd_Noclip_f (ent);
  614.     else if (Q_stricmp (cmd, "help") == 0)
  615.         Cmd_Help_f (ent);
  616.     else if (Q_stricmp (cmd, "inven") == 0)
  617.         Cmd_Inven_f (ent);
  618.     else if (Q_stricmp (cmd, "invnext") == 0)
  619.         SelectNextItem (ent);
  620.     else if (Q_stricmp (cmd, "invprev") == 0)
  621.         SelectPrevItem (ent);
  622.     else if (Q_stricmp (cmd, "invuse") == 0)
  623.         Cmd_InvUse_f (ent);
  624.     else if (Q_stricmp (cmd, "invdrop") == 0)
  625.         Cmd_InvDrop_f (ent);
  626.     else if (Q_stricmp (cmd, "weapprev") == 0)
  627.         Cmd_WeapPrev_f (ent);
  628.     else if (Q_stricmp (cmd, "weapnext") == 0)
  629.         Cmd_WeapNext_f (ent);
  630.     else if (Q_stricmp (cmd, "kill") == 0)
  631.         Cmd_Kill_f (ent);
  632.     else if (Q_stricmp (cmd, "putaway") == 0)
  633.         Cmd_PutAway_f (ent);
  634.     else if (Q_stricmp (cmd, "wave") == 0)
  635.         Cmd_Wave_f (ent);
  636.     else if (Q_stricmp (cmd, "gameversion") == 0)
  637.     {
  638.         gi.cprintf (ent, PRINT_HIGH, "%s : %s\n", GAMEVERSION, __DATE__);
  639.     }
  640.     else if (Q_stricmp (cmd, "fov") == 0)
  641.     {
  642.         ent->client->ps.fov = atoi(gi.argv(1));
  643.         if (ent->client->ps.fov < 1)
  644.             ent->client->ps.fov = 90;
  645.         else if (ent->client->ps.fov > 160)
  646.             ent->client->ps.fov = 160;
  647.     }
  648.     else
  649.         gi.cprintf (ent, PRINT_HIGH, "Bad command: %s\n", cmd);
  650. }
  651.  
  652.