?? p_client.c
字號:
ent->s.skinnum = ent - g_edicts - 1;
ent->s.modelindex = 255; // will use the skin specified model
ent->s.modelindex2 = 255; // custom gun model
// sknum is player num and weapon number
// weapon number will be added in changeweapon
ent->s.skinnum = ent - g_edicts - 1;
ent->s.frame = 0;
VectorCopy (spawn_origin, ent->s.origin);
ent->s.origin[2] += 1; // make sure off ground
VectorCopy (ent->s.origin, ent->s.old_origin);
// set the delta angle
for (i=0 ; i<3 ; i++)
client->ps.pmove.delta_angles[i] = ANGLE2SHORT(spawn_angles[i] - client->resp.cmd_angles[i]);
ent->s.angles[PITCH] = 0;
ent->s.angles[YAW] = spawn_angles[YAW];
ent->s.angles[ROLL] = 0;
VectorCopy (ent->s.angles, client->ps.viewangles);
VectorCopy (ent->s.angles, client->v_angle);
//ZOID
if (CTFStartClient(ent))
return;
//ZOID
if (!KillBox (ent))
{ // could't spawn in?
}
gi.linkentity (ent);
// force the current weapon up
client->newweapon = client->pers.weapon;
ChangeWeapon (ent);
}
/*
=====================
ClientBeginDeathmatch
A client has just connected to the server in
deathmatch mode, so clear everything out before starting them.
=====================
*/
void ClientBeginDeathmatch (edict_t *ent)
{
G_InitEdict (ent);
InitClientResp (ent->client);
// locate ent at a spawn point
PutClientInServer (ent);
if (level.intermissiontime)
{
MoveClientToIntermission (ent);
}
else
{
// send effect
gi.WriteByte (svc_muzzleflash);
gi.WriteShort (ent-g_edicts);
gi.WriteByte (MZ_LOGIN);
gi.multicast (ent->s.origin, MULTICAST_PVS);
}
gi.bprintf (PRINT_HIGH, "%s entered the game\n", ent->client->pers.netname);
// make sure all view stuff is valid
ClientEndServerFrame (ent);
}
/*
===========
ClientBegin
called when a client has finished connecting, and is ready
to be placed into the game. This will happen every level load.
============
*/
void ClientBegin (edict_t *ent)
{
int i;
ent->client = game.clients + (ent - g_edicts - 1);
if (deathmatch->value)
{
ClientBeginDeathmatch (ent);
return;
}
// if there is already a body waiting for us (a loadgame), just
// take it, otherwise spawn one from scratch
if (ent->inuse == true)
{
// the client has cleared the client side viewangles upon
// connecting to the server, which is different than the
// state when the game is saved, so we need to compensate
// with deltaangles
for (i=0 ; i<3 ; i++)
ent->client->ps.pmove.delta_angles[i] = ANGLE2SHORT(ent->client->ps.viewangles[i]);
}
else
{
// a spawn point will completely reinitialize the entity
// except for the persistant data that was initialized at
// ClientConnect() time
G_InitEdict (ent);
ent->classname = "player";
InitClientResp (ent->client);
PutClientInServer (ent);
}
if (level.intermissiontime)
{
MoveClientToIntermission (ent);
}
else
{
// send effect if in a multiplayer game
if (game.maxclients > 1)
{
gi.WriteByte (svc_muzzleflash);
gi.WriteShort (ent-g_edicts);
gi.WriteByte (MZ_LOGIN);
gi.multicast (ent->s.origin, MULTICAST_PVS);
gi.bprintf (PRINT_HIGH, "%s entered the game\n", ent->client->pers.netname);
}
}
// make sure all view stuff is valid
ClientEndServerFrame (ent);
}
/*
===========
ClientUserInfoChanged
called whenever the player updates a userinfo variable.
The game can override any of the settings in place
(forcing skins or names, etc) before copying it off.
============
*/
void ClientUserinfoChanged (edict_t *ent, char *userinfo)
{
char *s;
int playernum;
// check for malformed or illegal info strings
if (!Info_Validate(userinfo))
{
strcpy (userinfo, "\\name\\badinfo\\skin\\male/grunt");
}
// set name
s = Info_ValueForKey (userinfo, "name");
strncpy (ent->client->pers.netname, s, sizeof(ent->client->pers.netname)-1);
// set skin
s = Info_ValueForKey (userinfo, "skin");
playernum = ent-g_edicts-1;
// combine name and skin into a configstring
//ZOID
if (ctf->value)
CTFAssignSkin(ent, s);
else
//ZOID
gi.configstring (CS_PLAYERSKINS+playernum, va("%s\\%s", ent->client->pers.netname, s) );
//ZOID
// set player name field (used in id_state view)
gi.configstring (CS_GENERAL+playernum, ent->client->pers.netname);
//ZOID
// fov
if (deathmatch->value && ((int)dmflags->value & DF_FIXED_FOV))
{
ent->client->ps.fov = 90;
}
else
{
ent->client->ps.fov = atoi(Info_ValueForKey(userinfo, "fov"));
if (ent->client->ps.fov < 1)
ent->client->ps.fov = 90;
else if (ent->client->ps.fov > 160)
ent->client->ps.fov = 160;
}
// handedness
s = Info_ValueForKey (userinfo, "hand");
if (strlen(s))
{
ent->client->pers.hand = atoi(s);
}
// save off the userinfo in case we want to check something later
strncpy (ent->client->pers.userinfo, userinfo, sizeof(ent->client->pers.userinfo)-1);
}
/*
===========
ClientConnect
Called when a player begins connecting to the server.
The game can refuse entrance to a client by returning false.
If the client is allowed, the connection process will continue
and eventually get to ClientBegin()
Changing levels will NOT cause this to be called again, but
loadgames will.
============
*/
qboolean ClientConnect (edict_t *ent, char *userinfo)
{
char *value;
// check to see if they are on the banned IP list
value = Info_ValueForKey (userinfo, "ip");
if (SV_FilterPacket(value)) {
Info_SetValueForKey(userinfo, "rejmsg", "Banned.");
return false;
}
// check for a password
value = Info_ValueForKey (userinfo, "password");
if (*password->string && strcmp(password->string, "none") &&
strcmp(password->string, value)) {
Info_SetValueForKey(userinfo, "rejmsg", "Password required or incorrect.");
return false;
}
// they can connect
ent->client = game.clients + (ent - g_edicts - 1);
// if there is already a body waiting for us (a loadgame), just
// take it, otherwise spawn one from scratch
if (ent->inuse == false)
{
// clear the respawning variables
//ZOID -- force team join
ent->client->resp.ctf_team = -1;
ent->client->resp.id_state = true;
//ZOID
InitClientResp (ent->client);
if (!game.autosaved || !ent->client->pers.weapon)
InitClientPersistant (ent->client);
}
ClientUserinfoChanged (ent, userinfo);
if (game.maxclients > 1)
gi.dprintf ("%s connected\n", ent->client->pers.netname);
ent->client->pers.connected = true;
return true;
}
/*
===========
ClientDisconnect
Called when a player drops from the server.
Will not be called between levels.
============
*/
void ClientDisconnect (edict_t *ent)
{
int playernum;
if (!ent->client)
return;
gi.bprintf (PRINT_HIGH, "%s disconnected\n", ent->client->pers.netname);
//ZOID
CTFDeadDropFlag(ent);
CTFDeadDropTech(ent);
//ZOID
// send effect
gi.WriteByte (svc_muzzleflash);
gi.WriteShort (ent-g_edicts);
gi.WriteByte (MZ_LOGOUT);
gi.multicast (ent->s.origin, MULTICAST_PVS);
gi.unlinkentity (ent);
ent->s.modelindex = 0;
ent->solid = SOLID_NOT;
ent->inuse = false;
ent->classname = "disconnected";
ent->client->pers.connected = false;
playernum = ent-g_edicts-1;
gi.configstring (CS_PLAYERSKINS+playernum, "");
}
//==============================================================
edict_t *pm_passent;
// pmove doesn't need to know about passent and contentmask
trace_t PM_trace (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end)
{
if (pm_passent->health > 0)
return gi.trace (start, mins, maxs, end, pm_passent, MASK_PLAYERSOLID);
else
return gi.trace (start, mins, maxs, end, pm_passent, MASK_DEADSOLID);
}
unsigned CheckBlock (void *b, int c)
{
int v,i;
v = 0;
for (i=0 ; i<c ; i++)
v+= ((byte *)b)[i];
return v;
}
void PrintPmove (pmove_t *pm)
{
unsigned c1, c2;
c1 = CheckBlock (&pm->s, sizeof(pm->s));
c2 = CheckBlock (&pm->cmd, sizeof(pm->cmd));
Com_Printf ("sv %3i:%i %i\n", pm->cmd.impulse, c1, c2);
}
/*
==============
ClientThink
This will be called once for each client frame, which will
usually be a couple times for each server frame.
==============
*/
void ClientThink (edict_t *ent, usercmd_t *ucmd)
{
gclient_t *client;
edict_t *other;
int i, j;
pmove_t pm;
level.current_entity = ent;
client = ent->client;
if (level.intermissiontime)
{
client->ps.pmove.pm_type = PM_FREEZE;
// can exit intermission after five seconds
if (level.time > level.intermissiontime + 5.0
&& (ucmd->buttons & BUTTON_ANY) )
level.exitintermission = true;
return;
}
pm_passent = ent;
//ZOID
if (ent->client->chase_target) {
client->resp.cmd_angles[0] = SHORT2ANGLE(ucmd->angles[0]);
client->resp.cmd_angles[1] = SHORT2ANGLE(ucmd->angles[1]);
client->resp.cmd_angles[2] = SHORT2ANGLE(ucmd->angles[2]);
return;
}
//ZOID
// set up for pmove
memset (&pm, 0, sizeof(pm));
if (ent->movetype == MOVETYPE_NOCLIP)
client->ps.pmove.pm_type = PM_SPECTATOR;
else if (ent->s.modelindex != 255)
client->ps.pmove.pm_type = PM_GIB;
else if (ent->deadflag)
client->ps.pmove.pm_type = PM_DEAD;
else
client->ps.pmove.pm_type = PM_NORMAL;
client->ps.pmove.gravity = sv_gravity->value;
pm.s = client->ps.pmove;
for (i=0 ; i<3 ; i++)
{
pm.s.origin[i] = ent->s.origin[i]*8;
pm.s.velocity[i] = ent->velocity[i]*8;
}
if (memcmp(&client->old_pmove, &pm.s, sizeof(pm.s)))
{
pm.snapinitial = true;
// gi.dprintf ("pmove changed!\n");
}
pm.cmd = *ucmd;
pm.trace = PM_trace; // adds default parms
pm.pointcontents = gi.pointcontents;
// perform a pmove
gi.Pmove (&pm);
// save results of pmove
client->ps.pmove = pm.s;
client->old_pmove = pm.s;
for (i=0 ; i<3 ; i++)
{
ent->s.origin[i] = pm.s.origin[i]*0.125;
ent->velocity[i] = pm.s.velocity[i]*0.125;
}
VectorCopy (pm.mins, ent->mins);
VectorCopy (pm.maxs, ent->maxs);
client->resp.cmd_angles[0] = SHORT2ANGLE(ucmd->angles[0]);
client->resp.cmd_angles[1] = SHORT2ANGLE(ucmd->angles[1]);
client->resp.cmd_angles[2] = SHORT2ANGLE(ucmd->angles[2]);
if (ent->groundentity && !pm.groundentity && (pm.cmd.upmove >= 10) && (pm.waterlevel == 0))
{
gi.sound(ent, CHAN_VOICE, gi.soundindex("*jump1.wav"), 1, ATTN_NORM, 0);
PlayerNoise(ent, ent->s.origin, PNOISE_SELF);
}
ent->viewheight = pm.viewheight;
ent->waterlevel = pm.waterlevel;
ent->watertype = pm.watertype;
ent->groundentity = pm.groundentity;
if (pm.groundentity)
ent->groundentity_linkcount = pm.groundentity->linkcount;
if (ent->deadflag)
{
client->ps.viewangles[ROLL] = 40;
client->ps.viewangles[PITCH] = -15;
client->ps.viewangles[YAW] = client->killer_yaw;
}
else
{
VectorCopy (pm.viewangles, client->v_angle);
VectorCopy (pm.viewangles, client->ps.viewangles);
}
//ZOID
if (client->ctf_grapple)
CTFGrapplePull(client->ctf_grapple);
//ZOID
gi.linkentity (ent);
if (ent->movetype != MOVETYPE_NOCLIP)
G_TouchTriggers (ent);
// touch other objects
for (i=0 ; i<pm.numtouch ; i++)
{
other = pm.touchents[i];
for (j=0 ; j<i ; j++)
if (pm.touchents[j] == other)
break;
if (j != i)
continue; // duplicated
if (!other->touch)
continue;
other->touch (other, ent, NULL, NULL);
}
client->oldbuttons = client->buttons;
client->buttons = ucmd->buttons;
client->latched_buttons |= client->buttons & ~client->oldbuttons;
// save light level the player is standing on for
// monster sighting AI
ent->light_level = ucmd->lightlevel;
// fire weapon from final position if needed
if (client->latched_buttons & BUTTON_ATTACK
//ZOID
&& ent->movetype != MOVETYPE_NOCLIP
//ZOID
)
{
if (!client->weapon_thunk)
{
client->weapon_thunk = true;
Think_Weapon (ent);
}
}
//ZOID
//regen tech
CTFApplyRegeneration(ent);
//ZOID
//ZOID
for (i = 1; i <= maxclients->value; i++) {
other = g_edicts + i;
if (other->inuse && other->client->chase_target == ent)
UpdateChaseCam(other);
}
if (client->menudirty && client->menutime <= level.time) {
PMenu_Do_Update(ent);
gi.unicast (ent, true);
client->menutime = level.time;
client->menudirty = false;
}
//ZOID
}
/*
==============
ClientBeginServerFrame
This will be called once for each server frame, before running
any other entities in the world.
==============
*/
void ClientBeginServerFrame (edict_t *ent)
{
gclient_t *client;
int buttonMask;
if (level.intermissiontime)
return;
client = ent->client;
// run weapon animations if it hasn't been done by a ucmd_t
if (!client->weapon_thunk
//ZOID
&& ent->movetype != MOVETYPE_NOCLIP
//ZOID
)
Think_Weapon (ent);
else
client->weapon_thunk = false;
if (ent->deadflag)
{
// wait for any button just going down
if ( level.time > client->respawn_time)
{
// in deathmatch, only wait for attack button
if (deathmatch->value)
buttonMask = BUTTON_ATTACK;
else
buttonMask = -1;
if ( ( client->latched_buttons & buttonMask ) ||
(deathmatch->value && ((int)dmflags->value & DF_FORCE_RESPAWN) ) ||
CTFMatchOn())
{
respawn(ent);
client->latched_buttons = 0;
}
}
return;
}
// add player trail so monsters can follow
if (!deathmatch->value)
if (!visible (ent, PlayerTrail_LastSpot() ) )
PlayerTrail_Add (ent->s.old_origin);
client->latched_buttons = 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -