Exemplo n.º 1
0
        bool OnSameTeam(gentity_t ent1, gentity_t ent2)
        {
            if (ent1.client == null || ent2.client == null)
                return false;

            if (ent2.client.sess.sessionTeam == ent1.client.sess.sessionTeam)
                return true;

            return false;
        }
Exemplo n.º 2
0
        bool CallSpawn(gentity_t ent)
        {
            if (ent.classname == null || ent.classname.Length == 0)
            {
                Common.Instance.WriteLine("CallSpawn: NULL classname");
                return false;
            }

            // check normal spawn functions
            for (int i = 0; i < spawns.Length; i++)
            {
                if (ent.classname.Equals(spawns[i].Name))
                {
                    // found it
                    spawns[i].Spawn(ent);
                    return true;
                }
            }
            return false;
        }
Exemplo n.º 3
0
        void player_die(gentity_t self, gentity_t inflictor, gentity_t attacker, int damage, MeansOfDeath mod)
        {
            if (self.client.ps.pm_type == Common.PMType.DEAD)
                return;

            if (level.intermissiontime > 0)
                return;

            self.client.ps.pm_type = Common.PMType.DEAD;
            int killer;
            string killerName = "";
            if (attacker != null)
            {
                killer = attacker.s.number;
                if (attacker.client != null)
                    killerName = attacker.client.pers.netname;
                else
                    killerName = "<non-client>";
            }
            else
            {
                killer = 1022;
                killerName = "<world>";
            }

            if (killer < 0 || killer >= 64)
            {
                killer = 1022;
                killerName = "<world>";
            }

            string obit = Enum.GetName(typeof(MeansOfDeath), mod);

            LogPrintf("Kill: {0} {1}: {2} killed {3} by {4}\n", killer, self.s.number, killerName, self.client.pers.netname, obit);

            self.enemy = attacker;

            // FIX: Add score

            Cmd_Score_f(self); // Score scores
            // send updated scores to any clients that are following this one,
            // or they would get stale scoreboards
            for (int j = 0; j < level.maxclients; j++)
            {
                gclient_t client;
                client = level.clients[j];

                if (client.pers.connected != clientConnected_t.CON_CONNECTED)
                    continue;

                if (client.sess.sessionTeam != team_t.TEAM_SPECTATOR)
                    continue;
                if (client.sess.spectatorClient == self.s.number)
                    Cmd_Score_f(g_entities[j]);
            }

            self.client.respawnTime = (int)level.time + 1700;
            Server.Instance.LinkEntity(GEntityToSharedEntity(self));
        }
Exemplo n.º 4
0
        /*
           ===========
           ClientSpawn

           Called every time a client is placed fresh in the world:
           after the first ClientBegin, and after each respawn
           Initializes all non-persistant parts of playerState
           ============
           */
        void ClientSpawn(gentity_t ent)
        {
            int index = ent.s.clientNum;
            gclient_t client = ent.client;

            Vector3 spawn_origin = Vector3.Zero;
            Vector3 spawn_angles = Vector3.Zero;
            spawn_origin = new Vector3(0, 100, -100);

            gentity_t spawnpoint;
            // find a spawn point
            // do it before setting health back up, so farthest
            // ranging doesn't count this client
            if (client.sess.sessionTeam == team_t.TEAM_SPECTATOR)
            {
                spawnpoint = SelectSpectatorSpawnPoint(ref spawn_origin, ref spawn_angles);
            }
            else
            {
                // the first spawn should be at a good looking spot
                if (!client.pers.initialSpawn && client.pers.localClient)
                {
                    client.pers.initialSpawn = true;
                    spawnpoint = SelectInitialSpawnPoint(ref spawn_origin, ref spawn_angles);
                }
                else
                {
                    // don't spawn near existing origin if possible
                    spawnpoint = SelectRandomFurthestSpawnPoint(client.ps.origin, ref spawn_origin, ref spawn_angles);
                }
            }

            client.pers.teamState.state = playerTeamStateState_t.TEAM_ACTIVE;

            // toggle the teleport bit so the client knows to not lerp
            // and never clear the voted flag
            Common.EntityFlags flags = ent.client.ps.eFlags & Common.EntityFlags.EF_TELEPORT_BIT;
            flags ^= Common.EntityFlags.EF_TELEPORT_BIT;

            // clear everything but the persistant data
            clientPersistant_t saved = client.pers;
            clientSession_t savedSess = client.sess;
            int savedPing = client.ps.ping;
            int accuracyhits = client.accuracy_hits;
            int accuracyshots = client.accuracy_shots;
            int[] persistant = new int[16];
            for (int i = 0; i < 16; i++)
            {
                persistant[i] = client.ps.persistant[i];
            }
            int eventSequence = client.ps.eventSequence;
            //client = new gclient_t();
            //ent.client = client;
            client.pers = saved;
            client.sess = savedSess;
            client.ps.ping = savedPing;
            client.accuracy_hits = accuracyhits;
            client.accuracy_shots = accuracyshots;
            client.lastkilled_client = -1;
            for (int i = 0; i < 16; i++)
            {
                client.ps.persistant[i] = persistant[i];
            }
            client.ps.eventSequence = eventSequence;
            client.ps.persistant[4]++;
            client.ps.persistant[3] = (int)client.sess.sessionTeam;

            client.airOutTime = (int)level.time + 12000;

            string userinfo = GetUserInfo(index);
            // set max health
            string val = Info.ValueForKey(userinfo, "handicap");
            if (val != null && val.Length > 0)
            {
                int ival;
                if (int.TryParse(val, out ival))
                {
                    if (ival <= 0 || ival > 100)
                        client.pers.maxHealth = 100;
                    else
                        client.pers.maxHealth = ival;
                }
            } else
                client.pers.maxHealth = 100;

            // clear entity values
            client.ps.stats[6] = client.pers.maxHealth;
            client.ps.eFlags = flags;

            ent.s.groundEntityNum = 1023; // none?
            //ent.client = level.clients[index];
            ent.takedamage = true;
            ent.inuse = true;
            ent.classname = "player";
            ent.r.contents = (int)brushflags.CONTENTS_MONSTER;
            ent.clipmask = (int)brushflags.MASK_PLAYERSOLID;
            ent.waterlevel = 0;
            // FIX: Add ent.die = player_die
            ent.flags = 0;
            ent.watertype = 0;
            ent.r.mins = Common.playerMins;
            ent.r.maxs = Common.playerMaxs;

            client.ps.clientNum = index;
            client.ps.stats[2] = 1 << 2;

            // health will count down towards max_health
            ent.health = client.ps.stats[0] = client.ps.stats[6] + 25;

            SetOrigin(ent, spawn_origin);
            client.ps.origin = spawn_origin;

            // the respawned flag will be cleared after the attack and jump keys come up
            client.ps.pm_flags |= PMFlags.RESPAWNED; // Respawned

            ent.client.pers.cmd = GetUserCommand(index);
            SetClientViewAngle(ent, spawn_angles);

            if (ent.client.sess.sessionTeam != team_t.TEAM_SPECTATOR)
            {
                KillBox(ent);
                Server.Instance.LinkEntity(GEntityToSharedEntity(ent));
            }

            // don't allow full run speed for a bit
            client.ps.pm_flags |= PMFlags.TIME_KNOCKBACK;
            client.ps.pm_time = 100;

            client.respawnTime = (int)level.time;
            client.inactivityTime = (int)level.time + 10000;
            client.latched_buttons = 0;

            if (level.intermissiontime == 1)
            {
                //MoveClientToIntermission(ent);
            }
            else
            {
                // fire the targets of the spawn point
                UseTargets(spawnpoint, ent);
            }

            // run a client frame to drop exactly to the floor,
            // initialize animations and other things
            client.ps.commandTime = (int)level.time - 100;
            ent.client.pers.cmd.serverTime = (int)level.time;
            Client_Think(ent);

            // positively link the client, even if the command times are weird
            if (ent.client.sess.sessionTeam != team_t.TEAM_SPECTATOR)
            {
                CGame.PlayerStateToEntityState(client.ps, ent.s, true);
                ent.r.currentOrigin = ent.client.ps.origin;
                Server.Instance.LinkEntity(GEntityToSharedEntity(ent));
            }

            // run the presend to set anything else
            ClientEndFrame(ent);

            // clear entity state values
            CGame.PlayerStateToEntityState(client.ps, ent.s, true);
        }
Exemplo n.º 5
0
        void SP_info_ladder(gentity_t ent)
        {
            ent.r.contents = (int)brushflags.CONTENTS_LADDER;
            //ent.spawnflags = 1;
            ent.r.svFlags = Common.svFlags.NOCLIENT;
            //ent.s.eType = 13;
            Vector3 size = (ent.r.absmax - ent.r.absmin)*0.5f;
            ent.r.currentOrigin = ent.r.absmin + size;
            ent.r.mins = -size;
            ent.r.maxs = size;

            Server.Instance.LinkEntity(GEntityToSharedEntity(ent));
        }
Exemplo n.º 6
0
        void SpectatorThink(gentity_t ent, Input.UserCommand ucmd)
        {
            gclient_t client = ent.client;
            if (client.sess.spectatorState != spectatorState_t.SPECTATOR_FOLLOW)
            {
                client.ps.pm_type = Common.PMType.SPECTATOR;
                client.ps.speed = sv_speed.Integer;  // faster than normal

                // set up for pmove
                pmove_t pm = new pmove_t();
                pm.Trace = new TraceDelegate(Server.Instance.SV_Trace);
                pm.ps = client.ps;
                pm.cmd = ucmd;
                pm.tracemask = (int)(brushflags.CONTENTS_SOLID | brushflags.CONTENTS_MOVEABLE | brushflags.CONTENTS_SLIME | brushflags.CONTENTS_OPAQUE);
                pm.pmove_fixed = CVars.Instance.VariableIntegerValue("pmove_fixed");
                pm.pmove_msec = CVars.Instance.VariableIntegerValue("pmove_msec");
                //pm.Trace += new TraceDelegate(Server.Instance.Trace);
                //pm.PointContents += new TraceContentsDelegate(Server.Instance.PointContents);
                pm.mins = Common.playerMins;
                pm.maxs = Common.playerMaxs;
                // perform a pmove
                Common.Instance.Pmove(pm);
                //if(!pm.ps.velocity.Equals(Vector3.Zero))
                //Common.Instance.WriteLine("vel: {0}", pm.ps.velocity);
                // save results of pmove
                ent.s.origin = client.ps.origin;

                Server.Instance.UnlinkEntity(GEntityToSharedEntity(ent));
            }
            client.oldbuttons = client.buttons;
            client.buttons = ucmd.buttons;
        }
Exemplo n.º 7
0
        void ParseField(string key, string value, gentity_t ent)
        {
            if (key.StartsWith("mins."))
            {
                if (ent.r.absmin == null)
                    ent.r.absmin = Vector3.Zero;
                if (key.EndsWith("x")) ent.r.absmin.X = float.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
                if (key.EndsWith("y")) ent.r.absmin.Y = float.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
                if (key.EndsWith("z")) ent.r.absmin.Z = float.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
            }
            else if (key.StartsWith("maxs."))
            {
                if (ent.r.absmax == null)
                    ent.r.absmax = Vector3.Zero;
                if (key.EndsWith("x")) ent.r.absmax.X = float.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
                if (key.EndsWith("y")) ent.r.absmax.Y = float.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
                if (key.EndsWith("z")) ent.r.absmax.Z = float.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
            } else
            switch (key)
            {
                case "classname":
                    ent.classname = value;
                    break;
                case "origin":
                    ent.s.origin = ParseVector(value);
                    break;
                case "model":
                    ent.model = value;
                    break;
                case "model2":
                    ent.model2 = value;
                    break;
                case "spawnflags":
                    ent.spawnflags = int.Parse(value);
                    break;
                case "speed":
                    ent.speed = float.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
                    break;
                case "target":
                    ent.target = value;
                    break;
                case "targetname":
                    ent.targetname = value;
                    break;
                case "message":
                    ent.message = value;
                    break;
                case "team":
                    ent.team = value;
                    break;
                case "wait":
                    ent.wait = float.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
                    break;
                case "random":
                    ent.random = float.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
                    break;
                case "count":
                    ent.count = int.Parse(value);
                    break;
                case "health":
                    ent.health = int.Parse(value);
                    break;
                case "dmg":
                    ent.damage = int.Parse(value);
                    break;
                case "angles":
                    ent.s.angles = ParseVector(value);
                    break;
                case "angle":
                    ent.s.angles = ParseAngleHack(value);
                    break;
                //case "":

                //    break;

            }
        }
Exemplo n.º 8
0
        /*
        ==============
        ClientEndFrame

        Called at the end of each server frame for each connected client
        A fast client will have multiple ClientThink for each ClientEdFrame,
        while a slow client may have multiple ClientEndFrame between ClientThink.
        ==============
        */
        private void ClientEndFrame(gentity_t ent)
        {
            if (ent.client.sess.sessionTeam == team_t.TEAM_SPECTATOR)
            {
                SpectatorClientEndFrame(ent);
                return;
            }

            clientPersistant_t pers = ent.client.pers;

            if (level.intermissiontime > 0)
                return;

            ent.client.ps.stats[0] = ent.health;

            // set the latest infor
            CGame.PlayerStateToEntityState(ent.client.ps, ent.s, true);
            SendPredictableEvents(ent.client.ps);
        }
Exemplo n.º 9
0
        void ClientTimerActions(gentity_t ent, int msec)
        {
            gclient_t client = ent.client;
            client.timeResidual += msec;

            while (client.timeResidual >= 1000)
            {
                client.timeResidual -= 1000;

                // count down health when over max
                if (ent.health > client.ps.stats[6])
                    ent.health--;
                // count down armor when over max
                if (client.ps.stats[3] > client.ps.stats[6])
                    client.ps.stats[3]--;
            }
        }
Exemplo n.º 10
0
        /*
        ==================
        ClientThink

        A new command has arrived from the client
        This will be called once for each client frame, which will
        usually be a couple times for each server frame on fast clients.
        ==================
        */
        public void Client_Think(gentity_t ent)
        {
            gclient_t client = ent.client;

            // don't think if the client is not yet connected (and thus not yet spawned in)
            if (client.pers.connected != clientConnected_t.CON_CONNECTED)
                return;

            Input.UserCommand ucmd = ent.client.pers.cmd;
            // sanity check the command time to prevent speedup cheating
            if(ucmd.serverTime > level.time + 200)
                ucmd.serverTime = (int)level.time + 200;
            if (ucmd.serverTime < level.time - 1000)
                ucmd.serverTime = (int)level.time - 1000;

            // mark the time we got info, so we can display the
            //ent.client.pers.cmd = Server.Instance.GetUsercmd(ent.s.clientNum);

            // phone jack if they don't get any for a while
            ent.client.lastCmdTime = (int)level.time;

            int msec = ucmd.serverTime - ent.client.ps.commandTime;
            // following others may result in bad times, but we still want
            // to check for follow toggles
            if (msec < 1 && ent.client.sess.spectatorState != spectatorState_t.SPECTATOR_FOLLOW)
                return;
            if (msec > 200)
                msec = 200;

            CVar pmove_msec = CVars.Instance.FindVar("pmove_msec");
            if (pmove_msec.Integer < 8)
                CVars.Instance.Set("pmove_msec", "8");
            else if (pmove_msec.Integer > 33)
                CVars.Instance.Set("pmove_msec", "33");

            if (CVars.Instance.FindVar("pmove_fixed").Bool || client.pers.pmoveFixed)
            {
                ucmd.serverTime = ((ucmd.serverTime + pmove_msec.Integer - 1) / pmove_msec.Integer) * pmove_msec.Integer;
            }

            //
            // check for exiting intermission
            //
            if (level.intermissiontime > 0)
            {
                //ClientIntermissionThink(client);
                return;
            }

            // spectators don't do much
            if (client.sess.sessionTeam == team_t.TEAM_SPECTATOR)
            {
                if (client.sess.spectatorState == spectatorState_t.SPECTATOR_SCOREBOARD)
                    return;
                //client.ps.speed = sv_speed.Integer;
                SpectatorThink(ent, ucmd);
                return;
            }

            // check for inactivity timer, but never drop the local client of a non-dedicated server
            //if (!ClientInactivityTimer(ent.client))
            //    return;

            if (client.noclip)
                client.ps.pm_type = Common.PMType.NOCLIP;
            else if (client.ps.stats[0] <= 0)
                client.ps.pm_type = Common.PMType.DEAD;
            else
                client.ps.pm_type = Common.PMType.NORMAL;

            // Gravity & speed
            client.ps.gravity = sv_gravity.Integer;
            client.ps.speed = sv_speed.Integer;

            // Set up for pmove
            int oldEventSequence = client.ps.eventSequence;
            pmove_t pm = new pmove_t();
               //#define	MASK_ALL				(-1)
            //#define	MASK_SOLID				(1)
            //#define	MASK_PLAYERSOLID		(1|0x10000|0x2000000)
            //#define	MASK_DEADSOLID			(1|0x10000)
            //#define	MASK_WATER				(32)
            //#define	MASK_OPAQUE				(1)
            //#define	MASK_SHOT				(1|0x2000000|0x4000000)
            pm.Trace = new TraceDelegate(Server.Instance.SV_Trace);
            pm.ps = client.ps;
            pm.cmd = ucmd;
            if (pm.ps.pm_type == Common.PMType.DEAD)
                pm.tracemask = (int)brushflags.MASK_PLAYERSOLID & ~(int)brushflags.CONTENTS_MONSTER;
            else
                pm.tracemask = (int)brushflags.MASK_PLAYERSOLID;
            pm.pmove_fixed = ((CVars.Instance.FindVar("pmove_fixed").Bool) | client.pers.pmoveFixed)?1:0;
            pm.pmove_msec = pmove_msec.Integer;
            client.oldOrigin = client.ps.origin;
            //pm.mins = Common.playerMins;
            //pm.maxs = Common.playerMaxs;
            Common.Instance.Pmove(pm);

            //client.ps.pm_type = Common.PMType.SPECTATOR;
            //client.ps.speed = 400;  // faster than normal

            // save results of pmove
            if (ent.client.ps.eventSequence != oldEventSequence)
                ent.eventTime = (int)level.time;
            if (g_smoothClients.Integer == 1)
            {

            }
            else
            {
                CGame.PlayerStateToEntityState(ent.client.ps, ent.s, true);
            }
            SendPredictableEvents(ent.client.ps);

            ent.r.currentOrigin = ent.s.pos.trBase;
            ent.r.mins = pm.mins;
            ent.r.maxs = pm.maxs;

            // execute client events
            //ClientEvents(ent, oldEventSequence);

            // link entity now, after any personal teleporters have been used
            Server.Instance.LinkEntity(GEntityToSharedEntity(ent));
            if (!ent.client.noclip)
            {
                //TouchTriggers(ent);
            }

            // NOTE: now copy the exact origin over otherwise clients can be snapped into solid
            ent.r.currentOrigin = ent.client.ps.origin;

            // touch other objects
            //ClientImpacts(ent, pm);

            // save results of triggers and client events
            if (ent.client.ps.eventSequence != oldEventSequence)
            {
                ent.eventTime = (int)level.time;
            }

            // swap and latch button actions
            client.oldbuttons = client.buttons;
            client.buttons = ucmd.buttons;
            client.latched_buttons |= client.buttons & ~client.oldbuttons;

            // check for respawning
            if (client.ps.stats[0] <= 0)
            {
                // wait for the attack button to be pressed
                if (level.time > client.respawnTime)
                {
                    // forcerespawn is to prevent users from waiting out powerups
                    if (g_forcerespawn.Integer > 0 && level.time - client.respawnTime > g_forcerespawn.Integer * 1000)
                    {
                        respawn(ent);
                        return;
                    }

                    // pressing attack or use is the normal respawn method
                    if ((ucmd.buttons & ((int)Input.ButtonDef.ATTACK | (int)Input.ButtonDef.USE)) > 0)
                        respawn(ent);

                }
                return;
            }

            ClientTimerActions(ent, msec);
        }
Exemplo n.º 11
0
 public sharedEntity GEntityToSharedEntity(gentity_t ent)
 {
     //sharedEntity sent = new sharedEntity();
     //sent.s = ent.s;
     //sent.r = ent.r;
     return ent.shEnt;
 }
Exemplo n.º 12
0
        /*
        ==============================
        G_UseTargets

        "activator" should be set to the entity that initiated the firing.

        Search for (string)targetname in all entities that
        match (string)self.target and call their .use function

        ==============================
        */
        void UseTargets(gentity_t ent, gentity_t activator)
        {
            if (ent == null)
                return;

            if (ent.target == null)
                return;

            gentity_t t = null;
            int tc = -1;
            while ((t = Find(ref tc, "targetname", ent.target)) != null)
            {
                if (t == ent)
                {
                    Common.Instance.WriteLine("WARNING: Entity used itself. :O");
                }
                else
                {
                    if (t.use != null)
                    {
                        t.use(t, ent, activator);
                    }
                }
                if (!ent.inuse)
                {
                    Common.Instance.WriteLine("entity was removed while using targets");
                    return;
                }
            }
        }
Exemplo n.º 13
0
        bool CheatsOk(gentity_t ent)
        {
            if (!g_cheats.Bool)
            {
                Server.Instance.SendServerCommand(Server.Instance.clients[ent.client.clientIndex], string.Format("print \"Cheats are not enabled on this server.\n\""));
                return false;
            }
            if (ent.health <= 0)
            {
                Server.Instance.SendServerCommand(Server.Instance.clients[ent.client.clientIndex], string.Format("print \"You must be alive to use this command.\n\""));
                return false;
            }

            return true;
        }
Exemplo n.º 14
0
        void SetTeam(gentity_t ent, int entNum, string s)
        {
            //
            // see what change is requested
            //
            gclient_t client = ent.client;
            team_t team = team_t.TEAM_FREE;
            spectatorState_t specState = spectatorState_t.SPECTATOR_NOT;

            s = s.ToLower();
            if (s.Equals("s") || s.Equals("spectator"))
            {
                team = team_t.TEAM_SPECTATOR;
                specState = spectatorState_t.SPECTATOR_FREE;
            }
            else if (g_gametype.Integer >= (int)GameType.TEAM)
            {
                specState = spectatorState_t.SPECTATOR_NOT;
                switch (s)
                {
                    case "red":
                    case "r":
                        team = team_t.TEAM_RED;
                        break;
                    case "blue":
                    case "b":
                        team = team_t.TEAM_BLUE;
                        break;
                    default:
                        team = PickTeam(ent.client.clientIndex);
                        break;
                }
            }
            else
                team = team_t.TEAM_FREE;

            // override decision if limiting the players
            if (g_gametype.Integer == (int)GameType.TOURNAMENT && level.numNonSpectatorClients >= 2)
                team = team_t.TEAM_SPECTATOR;
            else if (g_maxGameClients.Integer > 0 && level.numNonSpectatorClients >= g_maxGameClients.Integer)
                team = team_t.TEAM_SPECTATOR;

            team_t oldTeam = client.sess.sessionTeam;
            if (team == oldTeam && team != team_t.TEAM_SPECTATOR)
                return;

            //
            // execute the team change
            //

            client.pers.teamState.state = playerTeamStateState_t.TEAM_BEGIN;
            if (oldTeam != team_t.TEAM_SPECTATOR)
            {
                // kill the player
                ent.flags &= ~gentityFlags.FL_GODMODE;
                ent.client.ps.stats[0] = ent.health = 0;
                player_die(ent, ent, ent, 100000, MeansOfDeath.SUICIDE);
            }

            // they go to the end of the line for tournements
            if (team == team_t.TEAM_SPECTATOR)
                client.sess.spectatorTime = (int)level.time;

            client.sess.sessionTeam = team;
            client.sess.spectatorState = specState;
            client.sess.teamLeader = false;

            BroadcastTeamChange(client, oldTeam);

            // get and distribute relevent paramters
            ClientUserInfoChanged(entNum);

            Client_Begin(entNum);
        }
Exemplo n.º 15
0
 void SetOrigin(gentity_t ent, Vector3 origin)
 {
     ent.s.pos.trBase = origin;
     ent.s.pos.trType = Common.trType_t.TR_STATIONARY;
     ent.s.pos.trTime = 0;
     ent.s.pos.trDuration = 0;
     ent.s.pos.trDelta = Vector3.Zero;
     ent.r.currentOrigin = origin;
 }
Exemplo n.º 16
0
        private void FreeEntity(gentity_t ent)
        {
            Server.Instance.UnlinkEntity(GEntityToSharedEntity(ent));
            if (ent.neverFree)
                return;

            // Clear entity
            ent.classname = "freed";
            ent.freetime = level.time;
            ent.inuse = false;
            //ent = new gentity_t();
        }
Exemplo n.º 17
0
        private void SpectatorClientEndFrame(gentity_t ent)
        {
            // if we are doing a chase cam or a remote view, grab the latest info
            if (ent.client.sess.spectatorState == spectatorState_t.SPECTATOR_FOLLOW)
            {
                int clientNum = ent.client.sess.spectatorClient;
                // team follow1 and team follow2 go to whatever clients are playing
                if (clientNum == -1)
                    clientNum = level.follow1;
                else if (clientNum == -2)
                    clientNum = level.follow2;

                if (clientNum >= 0)
                {
                    gclient_t cl = level.clients[clientNum];
                    if (cl.pers.connected == clientConnected_t.CON_CONNECTED && cl.sess.sessionTeam != team_t.TEAM_SPECTATOR)
                    {
                        //int flags = (cl.ps.eFlags & ~())
                        ent.client.ps = cl.ps;
                        ent.client.ps.pm_flags |= PMFlags.FOLLOW;
                        ent.client.ps.eFlags = cl.ps.eFlags; // FIX
                        return;
                    }
                    else
                    {
                        // drop them to free spectators unless they are dedicated camera followers
                        if (ent.client.sess.spectatorClient >= 0)
                        {
                            ent.client.sess.spectatorState = spectatorState_t.SPECTATOR_FREE;
                            Client_Begin(ent.client.ps.clientNum);
                        }
                    }
                }
            }

            if (ent.client.sess.spectatorState == spectatorState_t.SPECTATOR_SCOREBOARD)
                ent.client.ps.pm_flags |= PMFlags.SCOREBOARD;
            else
                ent.client.ps.pm_flags &= ~PMFlags.SCOREBOARD;
        }
Exemplo n.º 18
0
 void InitEntity(gentity_t ent)
 {
     ent.inuse = true;
     ent.classname = "noclass";
     int entid = 1024;
     for (int i = 0; i < g_entities.Length; i++)
     {
         if (g_entities[i] == ent)
             entid = i;
     }
     ent.s.number = entid;
     ent.r.ownerNum = 1023; // None?
 }
Exemplo n.º 19
0
 private void StopFollowing(gentity_t gentity_t)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 20
0
 private void InitGentity(gentity_t e, int index)
 {
     e.inuse = true;
     e.classname = "noclass";
     e.s.number = index;
     e.r.ownerNum = 1023;
 }
Exemplo n.º 21
0
        gentity_t PickTarget(string name)
        {
            if (name == null || name.Length == 0)
            {
                Common.Instance.WriteLine("PickTarget: called with NULL parameter");
                return null;
            }

            gentity_t ent;
            int i = -1, numchoices = 0;
            gentity_t[] choice = new gentity_t[MAXCHOICES];
            while (true)
            {
                ent = Find(ref i, "targetname", name);
                if (ent == null)
                    break;
                choice[numchoices++] = ent;
                if (numchoices == MAXCHOICES)
                    break;
            }

            if (numchoices == 0)
            {
                Common.Instance.WriteLine("PickTarget: target {0} not found.", name);
                return null;
            }

            return choice[Common.Rand.Next() % numchoices];
        }
Exemplo n.º 22
0
        /*
        =================
        G_KillBox

        Kills all entities that would touch the proposed new positioning
        of ent.  Ent should be unlinked before calling this!
        =================
        */
        void KillBox(gentity_t ent)
        {
            Vector3 mins, maxs;
            mins = Vector3.Add(ent.client.ps.origin, ent.r.mins);
            maxs = Vector3.Add(ent.client.ps.origin, ent.r.maxs);
            int[] touch = new int[1024];
            int num = 0;//EntitiesInBox(mins, maxs, ref touch);

            gentity_t hit;
            for (int i = 0; i < num; i++)
            {
                hit = g_entities[touch[i]];
                if (hit.client == null)
                    continue;

                // nail it
                //Damage(hit, ent, ent, null, null, 100000);
            }
        }
Exemplo n.º 23
0
        /*
        ===========
        SelectRandomFurthestSpawnPoint

        Chooses a player start, deathmatch start, etc
        ============
        */
        gentity_t SelectRandomFurthestSpawnPoint(Vector3 avoid, ref Vector3 origin, ref Vector3 angles)
        {
            gentity_t spot;
            int numspots = 0;
            int i= 0,j=0;
            Vector3 delta;
            float dist;
            float[] list_dist = new float[128];
            gentity_t[] list_spot = new gentity_t[128];
            string[] names = new string[] { "info_player_terrorist", "info_player_counterterrorist", "info_player_start" };
            for (int nid = 0; nid < names.Length; nid++)
            {
                string name = names[nid];
                i = -1;
                while ((spot = Find(ref i, "classname", name)) != null)
                {
                    //if (SpotWouldTelefrag())
                    //    continue;

                    delta = Vector3.Subtract(spot.s.origin, avoid);
                    dist = delta.Length();

                    for (j = 0; j < numspots; j++)
                    {
                        if (dist > list_dist[j])
                        {
                            if (numspots >= 128)
                                numspots = 128 - 1;

                            for (int h = numspots; h >j; h--)
                            {
                                list_dist[h] = list_dist[h - 1];
                                list_spot[h] = list_spot[h - 1];
                            }

                            list_dist[j] = dist;
                            list_spot[j] = spot;

                            numspots++;
                            break;
                        }
                    }

                    if (j >= numspots && numspots < 128)
                    {
                        list_dist[numspots] = dist;
                        list_spot[numspots] = spot;
                        numspots++;
                    }
                }
            }

            if (numspots == 0)
            {
                int starti = -1;
                spot = Find(ref starti, "classname", "info_player_terrorist");

                if (spot == null)
                    Common.Instance.Error("Couldn't find a spawn point");

                origin = spot.s.origin;
                origin[2] += 9 - (Common.playerMins[2] - Common.playerMaxs[2])/2;
                angles = spot.s.angles;
                return spot;
            }

            // select a random spot from the spawn points furthest away
            int random = Common.Rand.Next(0,numspots);
            origin = list_spot[random].s.origin;
            origin[2] += 9 - (Common.playerMins[2] - Common.playerMaxs[2]) / 2;
            angles = list_spot[random].s.angles;

            return list_spot[random];
        }
Exemplo n.º 24
0
 private void RunClient(gentity_t ent)
 {
     if (g_synchrounousClients.Integer == 0)
         return;
     ent.client.pers.cmd.serverTime = (int)level.time;
     Client_Think(ent);
 }
Exemplo n.º 25
0
 void SP_info_player_start(gentity_t ent)
 {
     //ent.classname = "info_player_deathmatch";
     //SP_info_player_deathmatch(ent);
 }
Exemplo n.º 26
0
        private void RunThink(gentity_t ent)
        {
            float thinktime = ent.nextthink;
            if (thinktime <= 0)
                return;

            if (thinktime > level.time)
                return;

            ent.nextthink = 0;

            ent.RunThink(ent);
        }
Exemplo n.º 27
0
 void respawn(gentity_t ent)
 {
     ClientSpawn(ent);
 }
Exemplo n.º 28
0
 void SetClientViewAngle(gentity_t ent, Vector3 angle)
 {
     // set the delta angle
     int cmdAngle = (((int)angle[0] * 65535 / 360) & 65535);
     ent.client.ps.delta_angles[0] = cmdAngle - ent.client.pers.cmd.anglex;
     cmdAngle = (((int)angle[1] * 65535 / 360) & 65535);
     ent.client.ps.delta_angles[1] = cmdAngle - ent.client.pers.cmd.angley;
     cmdAngle = (((int)angle[2] * 65535 / 360) & 65535);
     ent.client.ps.delta_angles[2] = cmdAngle - ent.client.pers.cmd.anglez;
     ent.s.angles = angle;
     ent.client.ps.viewangles = ent.s.angles;
 }
Exemplo n.º 29
0
 public void RunThink(gentity_t ent)
 {
     think(ent);
 }
Exemplo n.º 30
0
        void G_SayTo(gentity_t ent, gentity_t other, SayMode mode, string color, string name, string message)
        {
            if (other == null || !other.inuse || other.client == null || other.client.pers.connected != clientConnected_t.CON_CONNECTED || (mode == SayMode.TEAM && !OnSameTeam(ent, other)))
                return;

            Server.Instance.SendServerCommand(Server.Instance.clients[other.client.clientIndex], string.Format("{0} \"{1}{2}{3}\"", (mode == SayMode.TEAM) ? "tchat" : "chat", name, "^" + color, message));
        }