yquake2remaster/src/game/g_cmds.c

1338 lines
19 KiB
C
Raw Normal View History

/*
2011-09-27 15:59:09 +00:00
* Copyright (C) 1997-2001 Id Software, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
2011-09-28 06:20:21 +00:00
* Game command processing.
2011-09-27 15:59:09 +00:00
*
* =======================================================================
2012-04-29 13:57:33 +00:00
*/
2011-10-06 07:54:45 +00:00
#include "header/local.h"
2011-10-09 15:58:20 +00:00
#include "monster/misc/player.h"
2011-09-27 15:59:09 +00:00
char *
ClientTeam(edict_t *ent)
{
2011-09-27 15:59:09 +00:00
char *p;
static char value[512];
value[0] = 0;
2012-04-29 13:57:33 +00:00
if (!ent)
{
return value;
}
2012-04-29 13:57:33 +00:00
if (!ent->client)
2011-09-27 15:59:09 +00:00
{
return value;
2011-09-27 15:59:09 +00:00
}
2011-09-27 15:59:09 +00:00
strcpy(value, Info_ValueForKey(ent->client->pers.userinfo, "skin"));
p = strchr(value, '/');
2011-09-27 15:59:09 +00:00
if (!p)
2011-09-27 15:59:09 +00:00
{
return value;
2011-09-27 15:59:09 +00:00
}
if ((int)(dmflags->value) & DF_MODELTEAMS)
{
*p = 0;
return value;
}
return ++p;
}
2011-09-27 15:59:09 +00:00
qboolean
OnSameTeam(edict_t *ent1, edict_t *ent2)
{
2011-09-27 15:59:09 +00:00
char ent1Team[512];
char ent2Team[512];
if (!ent1 || !ent2)
{
return false;
}
if (!((int)(dmflags->value) & (DF_MODELTEAMS | DF_SKINTEAMS)))
2011-09-27 15:59:09 +00:00
{
return false;
2011-09-27 15:59:09 +00:00
}
2011-09-27 15:59:09 +00:00
strcpy(ent1Team, ClientTeam(ent1));
strcpy(ent2Team, ClientTeam(ent2));
if (strcmp(ent1Team, ent2Team) == 0)
2011-09-27 15:59:09 +00:00
{
return true;
2011-09-27 15:59:09 +00:00
}
return false;
}
2011-09-27 15:59:09 +00:00
void
SelectNextItem(edict_t *ent, int itflags)
{
2011-09-27 15:59:09 +00:00
gclient_t *cl;
int i, index;
gitem_t *it;
if (!ent)
{
return;
}
cl = ent->client;
2011-09-27 15:59:09 +00:00
if (cl->chase_target)
{
ChaseNext(ent);
return;
}
2011-09-27 15:59:09 +00:00
/* scan for the next valid one */
for (i = 1; i <= MAX_ITEMS; i++)
{
2011-09-27 15:59:09 +00:00
index = (cl->pers.selected_item + i) % MAX_ITEMS;
if (!cl->pers.inventory[index])
2011-09-27 15:59:09 +00:00
{
continue;
2011-09-27 15:59:09 +00:00
}
it = &itemlist[index];
2011-09-27 15:59:09 +00:00
if (!it->use)
2011-09-27 15:59:09 +00:00
{
continue;
2011-09-27 15:59:09 +00:00
}
if (!(it->flags & itflags))
2011-09-27 15:59:09 +00:00
{
continue;
2011-09-27 15:59:09 +00:00
}
cl->pers.selected_item = index;
return;
}
cl->pers.selected_item = -1;
}
2011-09-27 15:59:09 +00:00
void
SelectPrevItem(edict_t *ent, int itflags)
{
2011-09-27 15:59:09 +00:00
gclient_t *cl;
int i, index;
gitem_t *it;
if (!ent)
{
return;
}
cl = ent->client;
2011-09-27 15:59:09 +00:00
if (cl->chase_target)
{
ChasePrev(ent);
return;
}
2011-09-27 15:59:09 +00:00
/* scan for the next valid one */
for (i = 1; i <= MAX_ITEMS; i++)
{
2011-09-27 15:59:09 +00:00
index = (cl->pers.selected_item + MAX_ITEMS - i) % MAX_ITEMS;
if (!cl->pers.inventory[index])
2011-09-27 15:59:09 +00:00
{
continue;
2011-09-27 15:59:09 +00:00
}
it = &itemlist[index];
2011-09-27 15:59:09 +00:00
if (!it->use)
2011-09-27 15:59:09 +00:00
{
continue;
2011-09-27 15:59:09 +00:00
}
if (!(it->flags & itflags))
2011-09-27 15:59:09 +00:00
{
continue;
2011-09-27 15:59:09 +00:00
}
cl->pers.selected_item = index;
return;
}
cl->pers.selected_item = -1;
}
2011-09-27 15:59:09 +00:00
void
ValidateSelectedItem(edict_t *ent)
{
2011-09-27 15:59:09 +00:00
gclient_t *cl;
if (!ent)
{
return;
}
cl = ent->client;
if (cl->pers.inventory[cl->pers.selected_item])
2011-09-27 15:59:09 +00:00
{
return; /* valid */
2011-09-27 15:59:09 +00:00
}
2011-09-27 15:59:09 +00:00
SelectNextItem(ent, -1);
}
2011-09-27 15:59:09 +00:00
/* ================================================================================= */
/*
2011-09-27 15:59:09 +00:00
* Give items to a client
*/
void
Cmd_Give_f(edict_t *ent)
{
2011-09-27 15:59:09 +00:00
char *name;
gitem_t *it;
int index;
int i;
qboolean give_all;
edict_t *it_ent;
2012-04-29 13:57:33 +00:00
if (!ent)
{
return;
}
2012-04-29 13:57:33 +00:00
if ((deathmatch->value || coop->value) && !sv_cheats->value)
{
2011-09-27 15:59:09 +00:00
gi.cprintf( ent, PRINT_HIGH,
"You must run the server with '+set cheats 1' to enable this command.\n");
return;
}
name = gi.args();
if (Q_stricmp(name, "all") == 0)
2011-09-27 15:59:09 +00:00
{
give_all = true;
2011-09-27 15:59:09 +00:00
}
else
2011-09-27 15:59:09 +00:00
{
give_all = false;
2011-09-27 15:59:09 +00:00
}
2011-09-27 15:59:09 +00:00
if (give_all || (Q_stricmp(gi.argv(1), "health") == 0))
{
if (gi.argc() == 3)
2011-09-27 15:59:09 +00:00
{
2012-06-02 07:31:27 +00:00
ent->health = (int)strtol(gi.argv(2), (char **)NULL, 10);
2011-09-27 15:59:09 +00:00
}
else
2011-09-27 15:59:09 +00:00
{
ent->health = ent->max_health;
2011-09-27 15:59:09 +00:00
}
if (!give_all)
2011-09-27 15:59:09 +00:00
{
return;
2011-09-27 15:59:09 +00:00
}
}
2011-09-27 15:59:09 +00:00
if (give_all || (Q_stricmp(name, "weapons") == 0))
{
2011-09-27 15:59:09 +00:00
for (i = 0; i < game.num_items; i++)
{
it = itemlist + i;
2011-09-27 15:59:09 +00:00
if (!it->pickup)
2011-09-27 15:59:09 +00:00
{
continue;
2011-09-27 15:59:09 +00:00
}
if (!(it->flags & IT_WEAPON))
2011-09-27 15:59:09 +00:00
{
continue;
2011-09-27 15:59:09 +00:00
}
ent->client->pers.inventory[i] += 1;
}
2011-09-27 15:59:09 +00:00
if (!give_all)
2011-09-27 15:59:09 +00:00
{
return;
2011-09-27 15:59:09 +00:00
}
}
2011-09-27 15:59:09 +00:00
if (give_all || (Q_stricmp(name, "ammo") == 0))
{
2011-09-27 15:59:09 +00:00
for (i = 0; i < game.num_items; i++)
{
it = itemlist + i;
2011-09-27 15:59:09 +00:00
if (!it->pickup)
2011-09-27 15:59:09 +00:00
{
continue;
2011-09-27 15:59:09 +00:00
}
if (!(it->flags & IT_AMMO))
2011-09-27 15:59:09 +00:00
{
continue;
2011-09-27 15:59:09 +00:00
}
Add_Ammo(ent, it, 1000);
}
2011-09-27 15:59:09 +00:00
if (!give_all)
2011-09-27 15:59:09 +00:00
{
return;
2011-09-27 15:59:09 +00:00
}
}
2011-09-27 15:59:09 +00:00
if (give_all || (Q_stricmp(name, "armor") == 0))
{
2011-09-27 15:59:09 +00:00
gitem_armor_t *info;
it = FindItem("Jacket Armor");
ent->client->pers.inventory[ITEM_INDEX(it)] = 0;
it = FindItem("Combat Armor");
ent->client->pers.inventory[ITEM_INDEX(it)] = 0;
it = FindItem("Body Armor");
info = (gitem_armor_t *)it->info;
ent->client->pers.inventory[ITEM_INDEX(it)] = info->max_count;
if (!give_all)
2011-09-27 15:59:09 +00:00
{
return;
2011-09-27 15:59:09 +00:00
}
}
2011-09-27 15:59:09 +00:00
if (give_all || (Q_stricmp(name, "Power Shield") == 0))
{
it = FindItem("Power Shield");
it_ent = G_Spawn();
it_ent->classname = it->classname;
2011-09-27 15:59:09 +00:00
SpawnItem(it_ent, it);
Touch_Item(it_ent, ent, NULL, NULL);
if (it_ent->inuse)
2011-09-27 15:59:09 +00:00
{
G_FreeEdict(it_ent);
2011-09-27 15:59:09 +00:00
}
if (!give_all)
2011-09-27 15:59:09 +00:00
{
return;
2011-09-27 15:59:09 +00:00
}
}
if (give_all)
{
2011-09-27 15:59:09 +00:00
for (i = 0; i < game.num_items; i++)
{
it = itemlist + i;
2011-09-27 15:59:09 +00:00
if (!it->pickup)
2011-09-27 15:59:09 +00:00
{
continue;
2011-09-27 15:59:09 +00:00
}
if (it->flags & (IT_ARMOR | IT_WEAPON | IT_AMMO))
{
continue;
2011-09-27 15:59:09 +00:00
}
ent->client->pers.inventory[i] = 1;
}
2011-09-27 15:59:09 +00:00
return;
}
2011-09-27 15:59:09 +00:00
it = FindItem(name);
if (!it)
{
name = gi.argv(1);
2011-09-27 15:59:09 +00:00
it = FindItem(name);
if (!it)
{
2011-09-27 15:59:09 +00:00
gi.cprintf(ent, PRINT_HIGH, "unknown item\n");
return;
}
}
if (!it->pickup)
{
2011-09-27 15:59:09 +00:00
gi.cprintf(ent, PRINT_HIGH, "non-pickup item\n");
return;
}
index = ITEM_INDEX(it);
if (it->flags & IT_AMMO)
{
if (gi.argc() == 3)
2011-09-27 15:59:09 +00:00
{
2012-06-02 07:31:27 +00:00
ent->client->pers.inventory[index] = (int)strtol(gi.argv(2), (char **)NULL, 10);
2011-09-27 15:59:09 +00:00
}
else
2011-09-27 15:59:09 +00:00
{
ent->client->pers.inventory[index] += it->quantity;
2011-09-27 15:59:09 +00:00
}
}
else
{
it_ent = G_Spawn();
it_ent->classname = it->classname;
2011-09-27 15:59:09 +00:00
SpawnItem(it_ent, it);
Touch_Item(it_ent, ent, NULL, NULL);
if (it_ent->inuse)
2011-09-27 15:59:09 +00:00
{
G_FreeEdict(it_ent);
2011-09-27 15:59:09 +00:00
}
}
}
/*
2011-09-27 15:59:09 +00:00
* Sets client to godmode
*/
void
Cmd_God_f(edict_t *ent)
{
2011-09-27 15:59:09 +00:00
char *msg;
2012-04-29 13:57:33 +00:00
if (!ent)
{
return;
}
2012-04-29 13:57:33 +00:00
if ((deathmatch->value || coop->value) && !sv_cheats->value)
{
2011-09-27 15:59:09 +00:00
gi.cprintf( ent, PRINT_HIGH,
"You must run the server with '+set cheats 1' to enable this command.\n");
return;
}
ent->flags ^= FL_GODMODE;
2011-09-27 15:59:09 +00:00
if (!(ent->flags & FL_GODMODE))
{
msg = "godmode OFF\n";
2011-09-27 15:59:09 +00:00
}
else
2011-09-27 15:59:09 +00:00
{
msg = "godmode ON\n";
2011-09-27 15:59:09 +00:00
}
2011-09-27 15:59:09 +00:00
gi.cprintf(ent, PRINT_HIGH, msg);
}
/*
2011-09-27 15:59:09 +00:00
* Sets client to notarget
*/
void
Cmd_Notarget_f(edict_t *ent)
{
2011-09-27 15:59:09 +00:00
char *msg;
2012-04-29 13:57:33 +00:00
if (!ent)
{
return;
}
2012-04-29 13:57:33 +00:00
if ((deathmatch->value || coop->value) && !sv_cheats->value)
{
2011-09-27 15:59:09 +00:00
gi.cprintf( ent, PRINT_HIGH,
"You must run the server with '+set cheats 1' to enable this command.\n");
return;
}
ent->flags ^= FL_NOTARGET;
2011-09-27 15:59:09 +00:00
if (!(ent->flags & FL_NOTARGET))
{
msg = "notarget OFF\n";
2011-09-27 15:59:09 +00:00
}
else
2011-09-27 15:59:09 +00:00
{
msg = "notarget ON\n";
2011-09-27 15:59:09 +00:00
}
2011-09-27 15:59:09 +00:00
gi.cprintf(ent, PRINT_HIGH, msg);
}
/*
2011-09-27 15:59:09 +00:00
* argv(0) noclip
*/
void
Cmd_Noclip_f(edict_t *ent)
{
2011-09-27 15:59:09 +00:00
char *msg;
2012-04-29 13:57:33 +00:00
if (!ent)
{
return;
}
2012-04-29 13:57:33 +00:00
if ((deathmatch->value || coop->value) && !sv_cheats->value)
{
2011-09-27 15:59:09 +00:00
gi.cprintf( ent, PRINT_HIGH,
"You must run the server with '+set cheats 1' to enable this command.\n");
return;
}
if (ent->movetype == MOVETYPE_NOCLIP)
{
ent->movetype = MOVETYPE_WALK;
msg = "noclip OFF\n";
}
else
{
ent->movetype = MOVETYPE_NOCLIP;
msg = "noclip ON\n";
}
2011-09-27 15:59:09 +00:00
gi.cprintf(ent, PRINT_HIGH, msg);
}
/*
2011-09-27 15:59:09 +00:00
* Use an inventory item
*/
void
Cmd_Use_f(edict_t *ent)
{
2011-09-27 15:59:09 +00:00
int index;
gitem_t *it;
char *s;
2012-04-29 13:57:33 +00:00
if (!ent)
{
return;
}
2012-04-29 13:57:33 +00:00
s = gi.args();
2011-09-27 15:59:09 +00:00
it = FindItem(s);
if (!it)
{
2011-09-27 15:59:09 +00:00
gi.cprintf(ent, PRINT_HIGH, "unknown item: %s\n", s);
return;
}
2011-09-27 15:59:09 +00:00
if (!it->use)
{
2011-09-27 15:59:09 +00:00
gi.cprintf(ent, PRINT_HIGH, "Item is not usable.\n");
return;
}
2011-09-27 15:59:09 +00:00
index = ITEM_INDEX(it);
2011-09-27 15:59:09 +00:00
if (!ent->client->pers.inventory[index])
{
2011-09-27 15:59:09 +00:00
gi.cprintf(ent, PRINT_HIGH, "Out of item: %s\n", s);
return;
}
2011-09-27 15:59:09 +00:00
it->use(ent, it);
}
/*
2011-09-27 15:59:09 +00:00
* Drop an inventory item
*/
void
Cmd_Drop_f(edict_t *ent)
{
2011-09-27 15:59:09 +00:00
int index;
gitem_t *it;
2012-04-29 13:57:33 +00:00
char *s;
if (!ent)
{
return;
}
s = gi.args();
2011-09-27 15:59:09 +00:00
it = FindItem(s);
if (!it)
{
2011-09-27 15:59:09 +00:00
gi.cprintf(ent, PRINT_HIGH, "unknown item: %s\n", s);
return;
}
2011-09-27 15:59:09 +00:00
if (!it->drop)
{
2011-09-27 15:59:09 +00:00
gi.cprintf(ent, PRINT_HIGH, "Item is not dropable.\n");
return;
}
2011-09-27 15:59:09 +00:00
index = ITEM_INDEX(it);
2011-09-27 15:59:09 +00:00
if (!ent->client->pers.inventory[index])
{
2011-09-27 15:59:09 +00:00
gi.cprintf(ent, PRINT_HIGH, "Out of item: %s\n", s);
return;
}
2011-09-27 15:59:09 +00:00
it->drop(ent, it);
}
2011-09-27 15:59:09 +00:00
void
InventoryMessage(edict_t *ent)
{
2011-09-27 15:59:09 +00:00
int i;
if (!ent)
{
return;
}
gi.WriteByte(svc_inventory);
for (i = 0; i < MAX_ITEMS; i++)
{
gi.WriteShort(ent->client->pers.inventory[i]);
}
}
void
Cmd_Inven_f(edict_t *ent)
{
2011-09-27 15:59:09 +00:00
gclient_t *cl;
2012-04-29 13:57:33 +00:00
if (!ent)
{
return;
}
2012-04-29 13:57:33 +00:00
cl = ent->client;
cl->showscores = false;
cl->showhelp = false;
if (cl->showinventory)
{
cl->showinventory = false;
return;
}
cl->showinventory = true;
InventoryMessage(ent);
2011-09-27 15:59:09 +00:00
gi.unicast(ent, true);
}
2011-09-27 15:59:09 +00:00
void
Cmd_InvUse_f(edict_t *ent)
{
2011-09-27 15:59:09 +00:00
gitem_t *it;
2012-04-29 13:57:33 +00:00
if (!ent)
{
return;
}
2012-04-29 13:57:33 +00:00
2011-09-27 15:59:09 +00:00
ValidateSelectedItem(ent);
if (ent->client->pers.selected_item == -1)
{
2011-09-27 15:59:09 +00:00
gi.cprintf(ent, PRINT_HIGH, "No item to use.\n");
return;
}
it = &itemlist[ent->client->pers.selected_item];
2011-09-27 15:59:09 +00:00
if (!it->use)
{
2011-09-27 15:59:09 +00:00
gi.cprintf(ent, PRINT_HIGH, "Item is not usable.\n");
return;
}
2011-09-27 15:59:09 +00:00
it->use(ent, it);
}
2011-09-27 15:59:09 +00:00
void
Cmd_WeapPrev_f(edict_t *ent)
{
2011-09-27 15:59:09 +00:00
gclient_t *cl;
int i, index;
gitem_t *it;
int selected_weapon;
2012-04-29 13:57:33 +00:00
if (!ent)
{
return;
}
2012-04-29 13:57:33 +00:00
cl = ent->client;
if (!cl->pers.weapon)
2011-09-27 15:59:09 +00:00
{
return;
2011-09-27 15:59:09 +00:00
}
selected_weapon = ITEM_INDEX(cl->pers.weapon);
2011-09-27 15:59:09 +00:00
/* scan for the next valid one */
for (i = 1; i <= MAX_ITEMS; i++)
{
2011-09-27 15:59:09 +00:00
index = (selected_weapon + i) % MAX_ITEMS;
if (!cl->pers.inventory[index])
2011-09-27 15:59:09 +00:00
{
continue;
2011-09-27 15:59:09 +00:00
}
it = &itemlist[index];
2011-09-27 15:59:09 +00:00
if (!it->use)
2011-09-27 15:59:09 +00:00
{
continue;
2011-09-27 15:59:09 +00:00
}
if (!(it->flags & IT_WEAPON))
{
continue;
2011-09-27 15:59:09 +00:00
}
it->use(ent, it);
if (cl->pers.weapon == it)
2011-09-27 15:59:09 +00:00
{
return; /* successful */
}
}
}
2011-09-27 15:59:09 +00:00
void
Cmd_WeapNext_f(edict_t *ent)
{
2011-09-27 15:59:09 +00:00
gclient_t *cl;
int i, index;
gitem_t *it;
int selected_weapon;
2012-04-29 13:57:33 +00:00
if (!ent)
{
return;
}
2012-04-29 13:57:33 +00:00
cl = ent->client;
if (!cl->pers.weapon)
2011-09-27 15:59:09 +00:00
{
return;
2011-09-27 15:59:09 +00:00
}
selected_weapon = ITEM_INDEX(cl->pers.weapon);
2011-09-27 15:59:09 +00:00
/* scan for the next valid one */
for (i = 1; i <= MAX_ITEMS; i++)
{
2011-09-27 15:59:09 +00:00
index = (selected_weapon + MAX_ITEMS - i) % MAX_ITEMS;
if (!cl->pers.inventory[index])
2011-09-27 15:59:09 +00:00
{
continue;
2011-09-27 15:59:09 +00:00
}
it = &itemlist[index];
2011-09-27 15:59:09 +00:00
if (!it->use)
2011-09-27 15:59:09 +00:00
{
continue;
2011-09-27 15:59:09 +00:00
}
if (!(it->flags & IT_WEAPON))
{
continue;
2011-09-27 15:59:09 +00:00
}
it->use(ent, it);
if (cl->pers.weapon == it)
2011-09-27 15:59:09 +00:00
{
return; /* successful */
}
}
}
2011-09-27 15:59:09 +00:00
void
Cmd_WeapLast_f(edict_t *ent)
{
2011-09-27 15:59:09 +00:00
gclient_t *cl;
int index;
gitem_t *it;
2012-04-29 13:57:33 +00:00
if (!ent)
{
return;
}
2012-04-29 13:57:33 +00:00
cl = ent->client;
if (!cl->pers.weapon || !cl->pers.lastweapon)
2011-09-27 15:59:09 +00:00
{
return;
2011-09-27 15:59:09 +00:00
}
index = ITEM_INDEX(cl->pers.lastweapon);
2011-09-27 15:59:09 +00:00
if (!cl->pers.inventory[index])
2011-09-27 15:59:09 +00:00
{
return;
2011-09-27 15:59:09 +00:00
}
it = &itemlist[index];
2011-09-27 15:59:09 +00:00
if (!it->use)
2011-09-27 15:59:09 +00:00
{
return;
2011-09-27 15:59:09 +00:00
}
if (!(it->flags & IT_WEAPON))
{
return;
2011-09-27 15:59:09 +00:00
}
it->use(ent, it);
}
2011-09-27 15:59:09 +00:00
void
Cmd_InvDrop_f(edict_t *ent)
{
2011-09-27 15:59:09 +00:00
gitem_t *it;
2012-04-29 13:57:33 +00:00
if (!ent)
{
return;
}
2012-04-29 13:57:33 +00:00
2011-09-27 15:59:09 +00:00
ValidateSelectedItem(ent);
if (ent->client->pers.selected_item == -1)
{
2011-09-27 15:59:09 +00:00
gi.cprintf(ent, PRINT_HIGH, "No item to drop.\n");
return;
}
it = &itemlist[ent->client->pers.selected_item];
2011-09-27 15:59:09 +00:00
if (!it->drop)
{
2011-09-27 15:59:09 +00:00
gi.cprintf(ent, PRINT_HIGH, "Item is not dropable.\n");
return;
}
2011-09-27 15:59:09 +00:00
it->drop(ent, it);
}
2011-09-27 15:59:09 +00:00
void
Cmd_Kill_f(edict_t *ent)
2012-04-29 13:57:33 +00:00
{
if (!ent)
{
return;
}
2012-04-29 13:57:33 +00:00
2011-09-27 15:59:09 +00:00
if (((level.time - ent->client->respawn_time) < 5) ||
(ent->client->resp.spectator))
{
return;
2011-09-27 15:59:09 +00:00
}
ent->flags &= ~FL_GODMODE;
ent->health = 0;
meansOfDeath = MOD_SUICIDE;
2011-09-27 15:59:09 +00:00
player_die(ent, ent, ent, 100000, vec3_origin);
}
2011-09-27 15:59:09 +00:00
void
Cmd_PutAway_f(edict_t *ent)
2012-04-29 13:57:33 +00:00
{
if (!ent)
{
return;
}
2012-04-29 13:57:33 +00:00
ent->client->showscores = false;
ent->client->showhelp = false;
ent->client->showinventory = false;
}
2011-09-27 15:59:09 +00:00
int
PlayerSort(void const *a, void const *b)
{
2011-09-27 15:59:09 +00:00
int anum, bnum;
2012-04-29 13:57:33 +00:00
if (!a || !b)
{
return 0;
}
2012-04-29 13:57:33 +00:00
anum = *(int *)a;
bnum = *(int *)b;
anum = game.clients[anum].ps.stats[STAT_FRAGS];
bnum = game.clients[bnum].ps.stats[STAT_FRAGS];
if (anum < bnum)
2011-09-27 15:59:09 +00:00
{
return -1;
2011-09-27 15:59:09 +00:00
}
if (anum > bnum)
2011-09-27 15:59:09 +00:00
{
return 1;
2011-09-27 15:59:09 +00:00
}
return 0;
}
2011-09-27 15:59:09 +00:00
void
Cmd_Players_f(edict_t *ent)
{
2011-09-27 15:59:09 +00:00
int i;
int count;
char small[64];
char large[1280];
int index[256];
2012-04-29 13:57:33 +00:00
if (!ent)
{
return;
}
2012-04-29 13:57:33 +00:00
count = 0;
2011-09-27 15:59:09 +00:00
for (i = 0; i < maxclients->value; i++)
{
if (game.clients[i].pers.connected)
{
index[count] = i;
count++;
}
2011-09-27 15:59:09 +00:00
}
2011-09-27 15:59:09 +00:00
/* sort by frags */
qsort(index, count, sizeof(index[0]), PlayerSort);
2011-09-27 15:59:09 +00:00
/* print information */
large[0] = 0;
2011-09-27 15:59:09 +00:00
for (i = 0; i < count; i++)
{
2011-09-27 15:59:09 +00:00
Com_sprintf(small, sizeof(small), "%3i %s\n",
game.clients[index[i]].ps.stats[STAT_FRAGS],
game.clients[index[i]].pers.netname);
if (strlen(small) + strlen(large) > sizeof(large) - 100)
2012-04-29 13:57:33 +00:00
{
2011-09-27 15:59:09 +00:00
/* can't print all of them in one packet */
strcat(large, "...\n");
break;
}
2011-09-27 15:59:09 +00:00
strcat(large, small);
}
2011-09-27 15:59:09 +00:00
gi.cprintf(ent, PRINT_HIGH, "%s\n%i players\n", large, count);
}
2011-09-27 15:59:09 +00:00
void
Cmd_Wave_f(edict_t *ent)
{
2011-09-27 15:59:09 +00:00
int i;
2012-04-29 13:57:33 +00:00
if (!ent)
{
return;
}
2012-04-29 13:57:33 +00:00
2012-06-02 07:31:27 +00:00
i = (int)strtol(gi.argv(1), (char **)NULL, 10);
2011-09-27 15:59:09 +00:00
/* can't wave when ducked */
if (ent->client->ps.pmove.pm_flags & PMF_DUCKED)
2011-09-27 15:59:09 +00:00
{
return;
2011-09-27 15:59:09 +00:00
}
if (ent->client->anim_priority > ANIM_WAVE)
2011-09-27 15:59:09 +00:00
{
return;
2011-09-27 15:59:09 +00:00
}
ent->client->anim_priority = ANIM_WAVE;
switch (i)
{
2011-09-27 15:59:09 +00:00
case 0:
gi.cprintf(ent, PRINT_HIGH, "flipoff\n");
ent->s.frame = FRAME_flip01 - 1;
ent->client->anim_end = FRAME_flip12;
break;
case 1:
gi.cprintf(ent, PRINT_HIGH, "salute\n");
ent->s.frame = FRAME_salute01 - 1;
ent->client->anim_end = FRAME_salute11;
break;
case 2:
gi.cprintf(ent, PRINT_HIGH, "taunt\n");
ent->s.frame = FRAME_taunt01 - 1;
ent->client->anim_end = FRAME_taunt17;
break;
case 3:
gi.cprintf(ent, PRINT_HIGH, "wave\n");
ent->s.frame = FRAME_wave01 - 1;
ent->client->anim_end = FRAME_wave11;
break;
case 4:
default:
gi.cprintf(ent, PRINT_HIGH, "point\n");
ent->s.frame = FRAME_point01 - 1;
ent->client->anim_end = FRAME_point12;
break;
}
}
2011-09-27 15:59:09 +00:00
void
Cmd_Say_f(edict_t *ent, qboolean team, qboolean arg0)
{
int i, j;
2011-09-27 15:59:09 +00:00
edict_t *other;
char *p;
char text[2048];
gclient_t *cl;
2012-04-29 13:57:33 +00:00
if (!ent)
{
return;
}
2012-04-29 13:57:33 +00:00
2011-09-27 15:59:09 +00:00
if ((gi.argc() < 2) && !arg0)
{
return;
2011-09-27 15:59:09 +00:00
}
if (!((int)(dmflags->value) & (DF_MODELTEAMS | DF_SKINTEAMS)))
2011-09-27 15:59:09 +00:00
{
team = false;
2011-09-27 15:59:09 +00:00
}
if (team)
2011-09-27 15:59:09 +00:00
{
Com_sprintf(text, sizeof(text), "(%s): ", ent->client->pers.netname);
}
else
2011-09-27 15:59:09 +00:00
{
Com_sprintf(text, sizeof(text), "%s: ", ent->client->pers.netname);
}
if (arg0)
{
2011-09-27 15:59:09 +00:00
strcat(text, gi.argv(0));
strcat(text, " ");
strcat(text, gi.args());
}
else
{
p = gi.args();
if (*p == '"')
{
p++;
2011-09-27 15:59:09 +00:00
p[strlen(p) - 1] = 0;
}
2011-09-27 15:59:09 +00:00
strcat(text, p);
}
2011-09-27 15:59:09 +00:00
/* don't let text be too long for malicious reasons */
if (strlen(text) > 150)
2011-09-27 15:59:09 +00:00
{
text[150] = 0;
2011-09-27 15:59:09 +00:00
}
strcat(text, "\n");
if (flood_msgs->value)
2011-09-27 15:59:09 +00:00
{
cl = ent->client;
if (level.time < cl->flood_locktill)
{
gi.cprintf(ent, PRINT_HIGH, "You can't talk for %d more seconds\n",
(int)(cl->flood_locktill - level.time));
return;
}
i = cl->flood_whenhead - flood_msgs->value + 1;
if (i < 0)
{
i = (sizeof(cl->flood_when) / sizeof(cl->flood_when[0])) + i;
}
if (cl->flood_when[i] &&
(level.time - cl->flood_when[i] < flood_persecond->value))
{
cl->flood_locktill = level.time + flood_waitdelay->value;
gi.cprintf(ent, PRINT_CHAT,
"Flood protection: You can't talk for %d seconds.\n",
(int)flood_waitdelay->value);
return;
}
cl->flood_whenhead = (cl->flood_whenhead + 1) %
(sizeof(cl->flood_when) / sizeof(cl->flood_when[0]));
cl->flood_when[cl->flood_whenhead] = level.time;
}
if (dedicated->value)
2011-09-27 15:59:09 +00:00
{
gi.cprintf(NULL, PRINT_CHAT, "%s", text);
2011-09-27 15:59:09 +00:00
}
for (j = 1; j <= game.maxclients; j++)
{
other = &g_edicts[j];
2011-09-27 15:59:09 +00:00
if (!other->inuse)
2011-09-27 15:59:09 +00:00
{
continue;
2011-09-27 15:59:09 +00:00
}
if (!other->client)
2011-09-27 15:59:09 +00:00
{
continue;
2011-09-27 15:59:09 +00:00
}
if (team)
{
if (!OnSameTeam(ent, other))
2011-09-27 15:59:09 +00:00
{
continue;
2011-09-27 15:59:09 +00:00
}
}
2011-09-27 15:59:09 +00:00
gi.cprintf(other, PRINT_CHAT, "%s", text);
}
}
2011-09-27 15:59:09 +00:00
void
Cmd_PlayerList_f(edict_t *ent)
{
int i;
char st[80];
char text[1400];
edict_t *e2;
2012-04-29 13:57:33 +00:00
if (!ent)
{
return;
}
2012-04-29 13:57:33 +00:00
2011-09-27 15:59:09 +00:00
/* connect time, ping, score, name */
*text = 0;
2011-09-27 15:59:09 +00:00
for (i = 0, e2 = g_edicts + 1; i < maxclients->value; i++, e2++)
{
if (!e2->inuse)
2011-09-27 15:59:09 +00:00
{
continue;
2011-09-27 15:59:09 +00:00
}
Com_sprintf(st, sizeof(st), "%02d:%02d %4d %3d %s%s\n",
2011-09-27 15:59:09 +00:00
(level.framenum - e2->client->resp.enterframe) / 600,
((level.framenum - e2->client->resp.enterframe) % 600) / 10,
e2->client->ping,
e2->client->resp.score,
e2->client->pers.netname,
e2->client->resp.spectator ? " (spectator)" : "");
if (strlen(text) + strlen(st) > sizeof(text) - 50)
{
sprintf(text + strlen(text), "And more...\n");
gi.cprintf(ent, PRINT_HIGH, "%s", text);
return;
}
2011-09-27 15:59:09 +00:00
strcat(text, st);
}
2011-09-27 15:59:09 +00:00
gi.cprintf(ent, PRINT_HIGH, "%s", text);
}
2011-09-27 15:59:09 +00:00
void
ClientCommand(edict_t *ent)
{
2011-09-27 15:59:09 +00:00
char *cmd;
2012-04-29 13:57:33 +00:00
if (!ent)
{
return;
}
2012-04-29 13:57:33 +00:00
if (!ent->client)
2011-09-27 15:59:09 +00:00
{
return; /* not fully in game yet */
}
cmd = gi.argv(0);
2011-09-27 15:59:09 +00:00
if (Q_stricmp(cmd, "players") == 0)
{
2011-09-27 15:59:09 +00:00
Cmd_Players_f(ent);
return;
}
2011-09-27 15:59:09 +00:00
if (Q_stricmp(cmd, "say") == 0)
{
2011-09-27 15:59:09 +00:00
Cmd_Say_f(ent, false, false);
return;
}
2011-09-27 15:59:09 +00:00
if (Q_stricmp(cmd, "say_team") == 0)
{
2011-09-27 15:59:09 +00:00
Cmd_Say_f(ent, true, false);
return;
}
2011-09-27 15:59:09 +00:00
if (Q_stricmp(cmd, "score") == 0)
{
2011-09-27 15:59:09 +00:00
Cmd_Score_f(ent);
return;
}
2011-09-27 15:59:09 +00:00
if (Q_stricmp(cmd, "help") == 0)
{
2011-09-27 15:59:09 +00:00
Cmd_Help_f(ent);
return;
}
if (level.intermissiontime)
2011-09-27 15:59:09 +00:00
{
return;
2011-09-27 15:59:09 +00:00
}
2011-09-27 15:59:09 +00:00
if (Q_stricmp(cmd, "use") == 0)
{
Cmd_Use_f(ent);
}
else if (Q_stricmp(cmd, "drop") == 0)
{
Cmd_Drop_f(ent);
}
else if (Q_stricmp(cmd, "give") == 0)
{
Cmd_Give_f(ent);
}
else if (Q_stricmp(cmd, "god") == 0)
{
Cmd_God_f(ent);
}
else if (Q_stricmp(cmd, "notarget") == 0)
{
Cmd_Notarget_f(ent);
}
else if (Q_stricmp(cmd, "noclip") == 0)
{
Cmd_Noclip_f(ent);
}
else if (Q_stricmp(cmd, "inven") == 0)
{
Cmd_Inven_f(ent);
}
else if (Q_stricmp(cmd, "invnext") == 0)
{
SelectNextItem(ent, -1);
}
else if (Q_stricmp(cmd, "invprev") == 0)
{
SelectPrevItem(ent, -1);
}
else if (Q_stricmp(cmd, "invnextw") == 0)
{
SelectNextItem(ent, IT_WEAPON);
}
else if (Q_stricmp(cmd, "invprevw") == 0)
{
SelectPrevItem(ent, IT_WEAPON);
}
else if (Q_stricmp(cmd, "invnextp") == 0)
{
SelectNextItem(ent, IT_POWERUP);
}
else if (Q_stricmp(cmd, "invprevp") == 0)
{
SelectPrevItem(ent, IT_POWERUP);
}
else if (Q_stricmp(cmd, "invuse") == 0)
{
Cmd_InvUse_f(ent);
}
else if (Q_stricmp(cmd, "invdrop") == 0)
{
Cmd_InvDrop_f(ent);
}
else if (Q_stricmp(cmd, "weapprev") == 0)
{
Cmd_WeapPrev_f(ent);
}
else if (Q_stricmp(cmd, "weapnext") == 0)
{
Cmd_WeapNext_f(ent);
}
else if (Q_stricmp(cmd, "weaplast") == 0)
{
Cmd_WeapLast_f(ent);
}
else if (Q_stricmp(cmd, "kill") == 0)
{
Cmd_Kill_f(ent);
}
else if (Q_stricmp(cmd, "putaway") == 0)
{
Cmd_PutAway_f(ent);
}
else if (Q_stricmp(cmd, "wave") == 0)
{
Cmd_Wave_f(ent);
}
else if (Q_stricmp(cmd, "playerlist") == 0)
2011-09-27 15:59:09 +00:00
{
Cmd_PlayerList_f(ent);
2011-09-27 15:59:09 +00:00
}
else /* anything that doesn't match a command will be a chat */
{
Cmd_Say_f(ent, false, true);
}
}