977 lines · 17.4 KB · C
RawDownload
#include <u.h>#include <libc.h>#include <stdio.h>#include "../dat.h"#include "../fns.h"#include "m_player.h"  char *ClientTeam (edict_t *ent){	char		*p;	static char	value[512]; 	value[0] = 0; 	if (!ent->client)		return value; 	strcpy(value, Info_ValueForKey (ent->client->pers.userinfo, "skin"));	p = strchr(value, '/');	if (!p)		return value; 	if ((int)(dmflags->value) & DF_MODELTEAMS)	{		*p = 0;		return value;	} 	// if ((int)(dmflags->value) & DF_SKINTEAMS)	return ++p;} qboolean OnSameTeam (edict_t *ent1, edict_t *ent2){	char	ent1Team [512];	char	ent2Team [512]; 	if (!((int)(dmflags->value) & (DF_MODELTEAMS | DF_SKINTEAMS)))		return false; 	strcpy (ent1Team, ClientTeam (ent1));	strcpy (ent2Team, ClientTeam (ent2)); 	if (strcmp(ent1Team, ent2Team) == 0)		return true;	return false;}  void SelectNextItem (edict_t *ent, int itflags){	gclient_t	*cl;	int			i, index;	gitem_t		*it; 	cl = ent->client; 	if (cl->chase_target) {		ChaseNext(ent);		return;	} 	// scan  for the next valid one	for (i=1 ; i<=MAX_ITEMS ; i++)	{		index = (cl->pers.selected_item + i)%MAX_ITEMS;		if (!cl->pers.inventory[index])			continue;		it = &itemlist[index];		if (!it->use)			continue;		if (!(it->flags & itflags))			continue; 		cl->pers.selected_item = index;		return;	} 	cl->pers.selected_item = -1;} void SelectPrevItem (edict_t *ent, int itflags){	gclient_t	*cl;	int			i, index;	gitem_t		*it; 	cl = ent->client; 	if (cl->chase_target) {		ChasePrev(ent);		return;	} 	// scan  for the next valid one	for (i=1 ; i<=MAX_ITEMS ; i++)	{		index = (cl->pers.selected_item + MAX_ITEMS - i)%MAX_ITEMS;		if (!cl->pers.inventory[index])			continue;		it = &itemlist[index];		if (!it->use)			continue;		if (!(it->flags & itflags))			continue; 		cl->pers.selected_item = index;		return;	} 	cl->pers.selected_item = -1;} void ValidateSelectedItem (edict_t *ent){	gclient_t	*cl; 	cl = ent->client; 	if (cl->pers.inventory[cl->pers.selected_item])		return;		// valid 	SelectNextItem (ent, -1);}  //================================================================================= /*==================Cmd_Give_f Give items to a client==================*/void Cmd_Give_f (edict_t *ent){	char		*name;	gitem_t		*it;	int			index;	int			i;	qboolean	give_all;	edict_t		*it_ent; 	if (deathmatch->value && !sv_cheats->value)	{		gi.cprintf (ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");		return;	} 	name = gi.args(); 	if (cistrcmp(name, "all") == 0)		give_all = true;	else		give_all = false; 	if (give_all || cistrcmp(gi.argv(1), "health") == 0)	{		if (gi.argc() == 3)			ent->health = atoi(gi.argv(2));		else			ent->health = ent->max_health;		if (!give_all)			return;	} 	if (give_all || cistrcmp(name, "weapons") == 0)	{		for (i=0 ; i<game.num_items ; i++)		{			it = itemlist + i;			if (!it->pickup)				continue;			if (!(it->flags & IT_WEAPON))				continue;			ent->client->pers.inventory[i] += 1;		}		if (!give_all)			return;	} 	if (give_all || cistrcmp(name, "ammo") == 0)	{		for (i=0 ; i<game.num_items ; i++)		{			it = itemlist + i;			if (!it->pickup)				continue;			if (!(it->flags & IT_AMMO))				continue;			Add_Ammo (ent, it, 1000);		}		if (!give_all)			return;	} 	if (give_all || cistrcmp(name, "armor") == 0)	{		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)			return;	} 	if (give_all || cistrcmp(name, "Power Shield") == 0)	{		it = FindItem("Power Shield");		it_ent = G_Spawn();		it_ent->classname = it->classname;		SpawnItem (it_ent, it);		Touch_Item (it_ent, ent, NULL, NULL);		if (it_ent->inuse)			G_FreeEdict(it_ent); 		if (!give_all)			return;	} 	if (give_all)	{		for (i=0 ; i<game.num_items ; i++)		{			it = itemlist + i;			if (!it->pickup)				continue;			if (it->flags & (IT_ARMOR|IT_WEAPON|IT_AMMO))				continue;			ent->client->pers.inventory[i] = 1;		}		return;	} 	it = FindItem (name);	if (!it)	{		name = gi.argv(1);		it = FindItem (name);		if (!it)		{			gi.cprintf (ent, PRINT_HIGH, "unknown item\n");			return;		}	} 	if (!it->pickup)	{		gi.cprintf (ent, PRINT_HIGH, "non-pickup item\n");		return;	} 	index = ITEM_INDEX(it); 	if (it->flags & IT_AMMO)	{		if (gi.argc() == 3)			ent->client->pers.inventory[index] = atoi(gi.argv(2));		else			ent->client->pers.inventory[index] += it->quantity;	}	else	{		it_ent = G_Spawn();		it_ent->classname = it->classname;		SpawnItem (it_ent, it);		Touch_Item (it_ent, ent, NULL, NULL);		if (it_ent->inuse)			G_FreeEdict(it_ent);	}}  /*==================Cmd_God_f Sets client to godmode argv(0) god==================*/void Cmd_God_f (edict_t *ent){	char	*msg; 	if (deathmatch->value && !sv_cheats->value)	{		gi.cprintf (ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");		return;	} 	ent->flags ^= FL_GODMODE;	if (!(ent->flags & FL_GODMODE) )		msg = "godmode OFF\n";	else		msg = "godmode ON\n"; 	gi.cprintf (ent, PRINT_HIGH, msg);}  /*==================Cmd_Notarget_f Sets client to notarget argv(0) notarget==================*/void Cmd_Notarget_f (edict_t *ent){	char	*msg; 	if (deathmatch->value && !sv_cheats->value)	{		gi.cprintf (ent, PRINT_HIGH, "You must run the server with '+set cheats 1' to enable this command.\n");		return;	} 	ent->flags ^= FL_NOTARGET;	if (!(ent->flags & FL_NOTARGET) )		msg = "notarget OFF\n";	else		msg = "notarget ON\n"; 	gi.cprintf (ent, PRINT_HIGH, msg);}  /*==================Cmd_Noclip_f argv(0) noclip==================*/void Cmd_Noclip_f (edict_t *ent){	char	*msg; 	if (deathmatch->value && !sv_cheats->value)	{		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";	} 	gi.cprintf (ent, PRINT_HIGH, msg);}  /*==================Cmd_Use_f Use an inventory item==================*/void Cmd_Use_f (edict_t *ent){	int			index;	gitem_t		*it;	char		*s; 	s = gi.args();	it = FindItem (s);	if (!it)	{		gi.cprintf (ent, PRINT_HIGH, "unknown item: %s\n", s);		return;	}	if (!it->use)	{		gi.cprintf (ent, PRINT_HIGH, "Item is not usable.\n");		return;	}	index = ITEM_INDEX(it);	if (!ent->client->pers.inventory[index])	{		gi.cprintf (ent, PRINT_HIGH, "Out of item: %s\n", s);		return;	} 	it->use (ent, it);}  /*==================Cmd_Drop_f Drop an inventory item==================*/void Cmd_Drop_f (edict_t *ent){	int			index;	gitem_t		*it;	char		*s; 	s = gi.args();	it = FindItem (s);	if (!it)	{		gi.cprintf (ent, PRINT_HIGH, "unknown item: %s\n", s);		return;	}	if (!it->drop)	{		gi.cprintf (ent, PRINT_HIGH, "Item is not dropable.\n");		return;	}	index = ITEM_INDEX(it);	if (!ent->client->pers.inventory[index])	{		gi.cprintf (ent, PRINT_HIGH, "Out of item: %s\n", s);		return;	} 	it->drop (ent, it);}  /*=================Cmd_Inven_f=================*/void Cmd_Inven_f (edict_t *ent){	int			i;	gclient_t	*cl; 	cl = ent->client; 	cl->showscores = false;	cl->showhelp = false; 	if (cl->showinventory)	{		cl->showinventory = false;		return;	} 	cl->showinventory = true; 	gi.WriteByte (svc_inventory);	for (i=0 ; i<MAX_ITEMS ; i++)	{		gi.WriteShort (cl->pers.inventory[i]);	}	gi.unicast (ent, true);} /*=================Cmd_InvUse_f=================*/void Cmd_InvUse_f (edict_t *ent){	gitem_t		*it; 	ValidateSelectedItem (ent); 	if (ent->client->pers.selected_item == -1)	{		gi.cprintf (ent, PRINT_HIGH, "No item to use.\n");		return;	} 	it = &itemlist[ent->client->pers.selected_item];	if (!it->use)	{		gi.cprintf (ent, PRINT_HIGH, "Item is not usable.\n");		return;	}	it->use (ent, it);

Lines 1–500 of 977.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t