📄 playerclient.java
字号:
EdictIterator edit = GameBase.G_Find(null, GameBase.findByClass, "info_player_deathmatch"); if (edit == null) return null; return edit.o; } public static edict_t SelectDeathmatchSpawnPoint() { if (0 != ((int) (GameBase.dmflags.value) & Defines.DF_SPAWN_FARTHEST)) return SelectFarthestDeathmatchSpawnPoint(); else return SelectRandomDeathmatchSpawnPoint(); } public static edict_t SelectCoopSpawnPoint(edict_t ent) { int index; edict_t spot = null; String target; //index = ent.client - game.clients; index = ent.client.index; // player 0 starts in normal player spawn point if (index == 0) return null; spot = null; EdictIterator es = null; // assume there are four coop spots at each spawnpoint while (true) { es = GameBase.G_Find(es, GameBase.findByClass, "info_player_coop"); if (es == null) return null; spot = es.o; if (spot == null) return null; // we didn't have enough... target = spot.targetname; if (target == null) target = ""; if (Lib.Q_stricmp(GameBase.game.spawnpoint, target) == 0) { // this is a coop spawn point for one of the clients here index--; if (0 == index) return spot; // this is it } } } /** * Chooses a player start, deathmatch start, coop start, etc. */ public static void SelectSpawnPoint(edict_t ent, float[] origin, float[] angles) { edict_t spot = null; if (GameBase.deathmatch.value != 0) spot = SelectDeathmatchSpawnPoint(); else if (GameBase.coop.value != 0) spot = SelectCoopSpawnPoint(ent); EdictIterator es = null; // find a single player start spot if (null == spot) { while ((es = GameBase.G_Find(es, GameBase.findByClass, "info_player_start")) != null) { spot = es.o; if (GameBase.game.spawnpoint.length() == 0 && spot.targetname == null) break; if (GameBase.game.spawnpoint.length() == 0 || spot.targetname == null) continue; if (Lib.Q_stricmp(GameBase.game.spawnpoint, spot.targetname) == 0) break; } if (null == spot) { if (GameBase.game.spawnpoint.length() == 0) { // there wasn't a spawnpoint without a // target, so use any es = GameBase.G_Find(es, GameBase.findByClass, "info_player_start"); if (es != null) spot = es.o; } if (null == spot) { GameBase.gi.error("Couldn't find spawn point " + GameBase.game.spawnpoint + "\n"); return; } } } Math3D.VectorCopy(spot.s.origin, origin); origin[2] += 9; Math3D.VectorCopy(spot.s.angles, angles); } public static void InitBodyQue() { int i; edict_t ent; GameBase.level.body_que = 0; for (i = 0; i < Defines.BODY_QUEUE_SIZE; i++) { ent = GameUtil.G_Spawn(); ent.classname = "bodyque"; } } public static void CopyToBodyQue(edict_t ent) { edict_t body; // grab a body que and cycle to the next one int i = (int) GameBase.maxclients.value + GameBase.level.body_que + 1; body = GameBase.g_edicts[i]; GameBase.level.body_que = (GameBase.level.body_que + 1) % Defines.BODY_QUEUE_SIZE; // FIXME: send an effect on the removed body GameBase.gi.unlinkentity(ent); GameBase.gi.unlinkentity(body); body.s = ent.s.getClone(); body.s.number = body.index; body.svflags = ent.svflags; Math3D.VectorCopy(ent.mins, body.mins); Math3D.VectorCopy(ent.maxs, body.maxs); Math3D.VectorCopy(ent.absmin, body.absmin); Math3D.VectorCopy(ent.absmax, body.absmax); Math3D.VectorCopy(ent.size, body.size); body.solid = ent.solid; body.clipmask = ent.clipmask; body.owner = ent.owner; body.movetype = ent.movetype; body.die = PlayerClient.body_die; body.takedamage = Defines.DAMAGE_YES; GameBase.gi.linkentity(body); } public static void respawn(edict_t self) { if (GameBase.deathmatch.value != 0 || GameBase.coop.value != 0) { // spectator's don't leave bodies if (self.movetype != Defines.MOVETYPE_NOCLIP) CopyToBodyQue(self); self.svflags &= ~Defines.SVF_NOCLIENT; PutClientInServer(self); // add a teleportation effect self.s.event = Defines.EV_PLAYER_TELEPORT; // hold in place briefly self.client.ps.pmove.pm_flags = pmove_t.PMF_TIME_TELEPORT; self.client.ps.pmove.pm_time = 14; self.client.respawn_time = GameBase.level.time; return; } // restart the entire server GameBase.gi.AddCommandString("menu_loadgame\n"); } private static boolean passwdOK(String i1, String i2) { if (i1.length() != 0 && !i1.equals("none") && !i1.equals(i2)) return false; return true; } /** * Only called when pers.spectator changes note that resp.spectator should * be the opposite of pers.spectator here */ public static void spectator_respawn(edict_t ent) { int i, numspec; // if the user wants to become a spectator, make sure he doesn't // exceed max_spectators if (ent.client.pers.spectator) { String value = Info.Info_ValueForKey(ent.client.pers.userinfo, "spectator"); if (!passwdOK(GameBase.spectator_password.string, value)) { GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "Spectator password incorrect.\n"); ent.client.pers.spectator = false; GameBase.gi.WriteByte(Defines.svc_stufftext); GameBase.gi.WriteString("spectator 0\n"); GameBase.gi.unicast(ent, true); return; } // count spectators for (i = 1, numspec = 0; i <= GameBase.maxclients.value; i++) if (GameBase.g_edicts[i].inuse && GameBase.g_edicts[i].client.pers.spectator) numspec++; if (numspec >= GameBase.maxspectators.value) { GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "Server spectator limit is full."); ent.client.pers.spectator = false; // reset his spectator var GameBase.gi.WriteByte(Defines.svc_stufftext); GameBase.gi.WriteString("spectator 0\n"); GameBase.gi.unicast(ent, true); return; } } else { // he was a spectator and wants to join the game // he must have the right password String value = Info.Info_ValueForKey(ent.client.pers.userinfo, "password"); if (!passwdOK(GameBase.spectator_password.string, value)) { GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "Password incorrect.\n"); ent.client.pers.spectator = true; GameBase.gi.WriteByte(Defines.svc_stufftext); GameBase.gi.WriteString("spectator 1\n"); GameBase.gi.unicast(ent, true); return; } } // clear client on respawn ent.client.resp.score = ent.client.pers.score = 0; ent.svflags &= ~Defines.SVF_NOCLIENT; PutClientInServer(ent); // add a teleportation effect if (!ent.client.pers.spectator) { // send effect GameBase.gi.WriteByte(Defines.svc_muzzleflash); //gi.WriteShort(ent - g_edicts); GameBase.gi.WriteShort(ent.index); GameBase.gi.WriteByte(Defines.MZ_LOGIN); GameBase.gi.multicast(ent.s.origin, Defines.MULTICAST_PVS); // hold in place briefly ent.client.ps.pmove.pm_flags = pmove_t.PMF_TIME_TELEPORT; ent.client.ps.pmove.pm_time = 14; } ent.client.respawn_time = GameBase.level.time; if (ent.client.pers.spectator) GameBase.gi.bprintf(Defines.PRINT_HIGH, ent.client.pers.netname + " has moved to the sidelines\n"); else GameBase.gi.bprintf(Defines.PRINT_HIGH, ent.client.pers.netname + " joined the game\n"); } /** * Called when a player connects to a server or respawns in a deathmatch. */ public static void PutClientInServer(edict_t ent) { float[] mins = { -16, -16, -24 }; float[] maxs = { 16, 16, 32 }; int index; float[] spawn_origin = { 0, 0, 0 }, spawn_angles = { 0, 0, 0 }; gclient_t client; int i; client_persistant_t saved = new client_persistant_t(); client_respawn_t resp = new client_respawn_t(); // find a spawn point // do it before setting health back up, so farthest // ranging doesn't count this client SelectSpawnPoint(ent, spawn_origin, spawn_angles); index = ent.index - 1; client = ent.client; // deathmatch wipes most client data every spawn if (GameBase.deathmatch.value != 0) { resp.set(client.resp); String userinfo = client.pers.userinfo; InitClientPersistant(client); userinfo = ClientUserinfoChanged(ent, userinfo); } else if (GameBase.coop.value != 0) { resp.set(client.resp); String userinfo = client.pers.userinfo; resp.coop_respawn.game_helpchanged = client.pers.game_helpchanged; resp.coop_respawn.helpchanged = client.pers.helpchanged; client.pers.set(resp.coop_respawn); userinfo = ClientUserinfoChanged(ent, userinfo); if (resp.score > client.pers.score) client.pers.score = resp.score; } else { resp.clear(); } // clear everything but the persistant data saved.set(client.pers); client.clear(); client.pers.set(saved); if (client.pers.health <= 0) InitClientPersistant(client); client.resp.set(resp); // copy some data from the client to the entity FetchClientEntData(ent); // clear entity values ent.groundentity = null; ent.client = GameBase.game.clients[index]; ent.takedamage = Defines.DAMAGE_AIM; ent.movetype = Defines.MOVETYPE_WALK; ent.viewheight = 22; ent.inuse = true; ent.classname = "player"; ent.mass = 200; ent.solid = Defines.SOLID_BBOX; ent.deadflag = Defines.DEAD_NO; ent.air_finished = GameBase.level.time + 12; ent.clipmask = Defines.MASK_PLAYERSOLID;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -