示例#1
0
        public static edict_t G_PickTarget(string targetname)
        {
            int num_choices = 0;

            edict_t[] choice = new edict_t[MAXCHOICES];
            if (targetname == null)
            {
                gi.Dprintf("G_PickTarget called with null targetname\\n");
                return(null);
            }

            EdictIterator es = null;

            while ((es = G_Find(es, findByTarget, targetname)) != null)
            {
                choice[num_choices++] = es.o;
                if (num_choices == MAXCHOICES)
                {
                    break;
                }
            }

            if (num_choices == 0)
            {
                gi.Dprintf("G_PickTarget: target " + targetname + " not found\\n");
                return(null);
            }

            return(choice[Lib.Rand() % num_choices]);
        }
示例#2
0
        public static EdictIterator G_Find(EdictIterator from, EdictFindFilter eff, string s)
        {
            if (from == null)
            {
                from = new EdictIterator(0);
            }
            else
            {
                from.i++;
            }
            for (; from.i < num_edicts; from.i++)
            {
                from.o = g_edicts[from.i];
                if (from.o.classname == null)
                {
                    Com.Printf("edict with classname = null" + from.o.index);
                }

                if (!from.o.inuse)
                {
                    continue;
                }
                if (eff.Matches(from.o, s))
                {
                    return(from);
                }
            }

            return(null);
        }
示例#3
0
            public override bool Think(edict_t self)
            {
                edict_t ent;
                float   points;

                float[]       v = new float[] { 0, 0, 0 };
                float         dist;
                EdictIterator edit = null;

                if (self.s.frame == 0)
                {
                    ent = null;
                    while ((edit = GameBase.Findradius(edit, self.s.origin, self.dmg_radius)) != null)
                    {
                        ent = edit.o;
                        if (ent.takedamage == 0)
                        {
                            continue;
                        }
                        if (ent == self.owner)
                        {
                            continue;
                        }
                        if (!GameCombat.CanDamage(ent, self))
                        {
                            continue;
                        }
                        if (!GameCombat.CanDamage(ent, self.owner))
                        {
                            continue;
                        }
                        Math3D.VectorAdd(ent.mins, ent.maxs, v);
                        Math3D.VectorMA(ent.s.origin, 0.5F, v, v);
                        Math3D.VectorSubtract(self.s.origin, v, v);
                        dist   = Math3D.VectorLength(v);
                        points = (float)(self.radius_dmg * (1 - Math.Sqrt(dist / self.dmg_radius)));
                        if (ent == self.owner)
                        {
                            points = points * 0.5F;
                        }
                        GameBase.gi.WriteByte(Defines.svc_temp_entity);
                        GameBase.gi.WriteByte(Defines.TE_BFG_EXPLOSION);
                        GameBase.gi.WritePosition(ent.s.origin);
                        GameBase.gi.Multicast(ent.s.origin, Defines.MULTICAST_PHS);
                        GameCombat.T_Damage(ent, self, self.owner, self.velocity, ent.s.origin, Globals.vec3_origin, (int)points, 0, Defines.DAMAGE_ENERGY, Defines.MOD_BFG_EFFECT);
                    }
                }

                self.nextthink = GameBase.level.time + Defines.FRAMETIME;
                self.s.frame++;
                if (self.s.frame == 5)
                {
                    self.think = GameUtil.G_FreeEdictA;
                }
                return(true);
            }
示例#4
0
        public static edict_t G_FindEdict(EdictIterator from, EdictFindFilter eff, string s)
        {
            EdictIterator ei = G_Find(from, eff, s);

            if (ei == null)
            {
                return(null);
            }
            else
            {
                return(ei.o);
            }
        }
示例#5
0
            public override void Use(edict_t self, edict_t other, edict_t activator)
            {
                if (self.enemy == null)
                {
                    edict_t e;
                    e = null;
                    EdictIterator es = null;
                    while (true)
                    {
                        es = GameBase.G_Find(es, GameBase.findByTarget, self.target);
                        if (es == null)
                        {
                            break;
                        }
                        e = es.o;
                        if (Lib.Strcmp(e.classname, "light") != 0)
                        {
                            GameBase.gi.Dprintf(self.classname + " at " + Lib.Vtos(self.s.origin));
                            GameBase.gi.Dprintf("target " + self.target + " (" + e.classname + " at " + Lib.Vtos(e.s.origin) + ") is not a light\\n");
                        }
                        else
                        {
                            self.enemy = e;
                        }
                    }

                    if (null == self.enemy)
                    {
                        GameBase.gi.Dprintf(self.classname + " target " + self.target + " not found at " + Lib.Vtos(self.s.origin) + "\\n");
                        GameUtil.G_FreeEdict(self);
                        return;
                    }
                }

                self.timestamp = GameBase.level.time;
                target_lightramp_think.Think(self);
            }
示例#6
0
        public static EdictIterator Findradius(EdictIterator from, float[] org, float rad)
        {
            float[] eorg = new[] { 0f, 0f, 0f };
            int     j;

            if (from == null)
            {
                from = new EdictIterator(0);
            }
            else
            {
                from.i++;
            }
            for (; from.i < num_edicts; from.i++)
            {
                from.o = g_edicts[from.i];
                if (!from.o.inuse)
                {
                    continue;
                }
                if (from.o.solid == Defines.SOLID_NOT)
                {
                    continue;
                }
                for (j = 0; j < 3; j++)
                {
                    eorg[j] = org[j] - (from.o.s.origin[j] + (from.o.mins[j] + from.o.maxs[j]) * 0.5F);
                }
                if (Math3D.VectorLength(eorg) > rad)
                {
                    continue;
                }
                return(from);
            }

            return(null);
        }
示例#7
0
        public static void T_RadiusDamage(edict_t inflictor, edict_t attacker, float damage, edict_t ignore, float radius, int mod)
        {
            float         points;
            EdictIterator edictit = null;

            float[] v   = new float[] { 0, 0, 0 };
            float[] dir = new float[] { 0, 0, 0 };
            while ((edictit = GameBase.Findradius(edictit, inflictor.s.origin, radius)) != null)
            {
                edict_t ent = edictit.o;
                if (ent == ignore)
                {
                    continue;
                }
                if (ent.takedamage == 0)
                {
                    continue;
                }
                Math3D.VectorAdd(ent.mins, ent.maxs, v);
                Math3D.VectorMA(ent.s.origin, 0.5F, v, v);
                Math3D.VectorSubtract(inflictor.s.origin, v, v);
                points = damage - 0.5F * Math3D.VectorLength(v);
                if (ent == attacker)
                {
                    points = points * 0.5F;
                }
                if (points > 0)
                {
                    if (CanDamage(ent, inflictor))
                    {
                        Math3D.VectorSubtract(ent.s.origin, inflictor.s.origin, dir);
                        T_Damage(ent, inflictor, attacker, dir, inflictor.s.origin, Globals.vec3_origin, (int)points, (int)points, Defines.DAMAGE_RADIUS, mod);
                    }
                }
            }
        }
示例#8
0
            public override Boolean Think(edict_t self)
            {
                self.movetype     = Defines.MOVETYPE_NONE;
                self.solid        = Defines.SOLID_NOT;
                self.s.renderfx  |= Defines.RF_BEAM | Defines.RF_TRANSLUCENT;
                self.s.modelindex = 1;
                if ((self.spawnflags & 64) != 0)
                {
                    self.s.frame = 16;
                }
                else
                {
                    self.s.frame = 4;
                }
                if ((self.spawnflags & 2) != 0)
                {
                    self.s.skinnum = unchecked (( Int32 )0xf2f2f0f0);
                }
                else if ((self.spawnflags & 4) != 0)
                {
                    self.s.skinnum = unchecked (( Int32 )0xd0d1d2d3);
                }
                else if ((self.spawnflags & 8) != 0)
                {
                    self.s.skinnum = unchecked (( Int32 )0xf3f3f1f1);
                }
                else if ((self.spawnflags & 16) != 0)
                {
                    self.s.skinnum = unchecked (( Int32 )0xdcdddedf);
                }
                else if ((self.spawnflags & 32) != 0)
                {
                    self.s.skinnum = unchecked (( Int32 )0xe0e1e2e3);
                }
                if (null == self.enemy)
                {
                    if (self.target != null)
                    {
                        EdictIterator edit = GameBase.G_Find(null, GameBase.findByTarget, self.target);
                        if (edit == null)
                        {
                            GameBase.gi.Dprintf(self.classname + " at " + Lib.Vtos(self.s.origin) + ": " + self.target + " is a bad target\\n");
                        }
                        self.enemy = edit.o;
                    }
                    else
                    {
                        GameBase.G_SetMovedir(self.s.angles, self.movedir);
                    }
                }

                self.use   = target_laser_use;
                self.think = target_laser_think;
                if (0 == self.dmg)
                {
                    self.dmg = 1;
                }
                Math3D.VectorSet(self.mins, -8, -8, -8);
                Math3D.VectorSet(self.maxs, 8, 8, 8);
                GameBase.gi.Linkentity(self);
                if ((self.spawnflags & 1) != 0)
                {
                    Target_laser_on(self);
                }
                else
                {
                    Target_laser_off(self);
                }
                return(true);
            }
示例#9
0
        public static void BeginIntermission(edict_t targ)
        {
            int     i, n;
            edict_t ent, client;

            if (GameBase.level.intermissiontime != 0)
            {
                return;
            }
            GameBase.game.autosaved = false;
            for (i = 0; i < GameBase.maxclients.value; i++)
            {
                client = GameBase.g_edicts[1 + i];
                if (!client.inuse)
                {
                    continue;
                }
                if (client.health <= 0)
                {
                    PlayerClient.Respawn(client);
                }
            }

            GameBase.level.intermissiontime = GameBase.level.time;
            GameBase.level.changemap        = targ.map;
            if (GameBase.level.changemap.IndexOf('*') > -1)
            {
                if (GameBase.coop.value != 0)
                {
                    for (i = 0; i < GameBase.maxclients.value; i++)
                    {
                        client = GameBase.g_edicts[1 + i];
                        if (!client.inuse)
                        {
                            continue;
                        }
                        for (n = 1; n < GameItemList.itemlist.Length; n++)
                        {
                            if (GameItemList.itemlist[n] != null)
                            {
                                if ((GameItemList.itemlist[n].flags & Defines.IT_KEY) != 0)
                                {
                                    client.client.pers.inventory[n] = 0;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (0 == GameBase.deathmatch.value)
                {
                    GameBase.level.exitintermission = true;
                    return;
                }
            }

            GameBase.level.exitintermission = false;
            ent = GameBase.G_FindEdict(null, GameBase.findByClass, "info_player_intermission");
            if (ent == null)
            {
                ent = GameBase.G_FindEdict(null, GameBase.findByClass, "info_player_start");
                if (ent == null)
                {
                    ent = GameBase.G_FindEdict(null, GameBase.findByClass, "info_player_deathmatch");
                }
            }
            else
            {
                i = Lib.Rand() & 3;
                EdictIterator es = null;
                while (i-- > 0)
                {
                    es = GameBase.G_Find(es, GameBase.findByClass, "info_player_intermission");
                    if (es == null)
                    {
                        continue;
                    }
                    ent = es.o;
                }
            }

            Math3D.VectorCopy(ent.s.origin, GameBase.level.intermission_origin);
            Math3D.VectorCopy(ent.s.angles, GameBase.level.intermission_angle);
            for (i = 0; i < GameBase.maxclients.value; i++)
            {
                client = GameBase.g_edicts[1 + i];
                if (!client.inuse)
                {
                    continue;
                }
                MoveClientToIntermission(client);
            }
        }
示例#10
0
        public static void Monster_start_go(edict_t self)
        {
            float[] v = new float[] { 0, 0, 0 };
            if (self.health <= 0)
            {
                return;
            }
            if (self.target != null)
            {
                bool    notcombat;
                bool    fixup;
                edict_t target = null;
                notcombat = false;
                fixup     = false;
                EdictIterator edit = null;
                while ((edit = GameBase.G_Find(edit, GameBase.findByTarget, self.target)) != null)
                {
                    target = edit.o;
                    if (Lib.Strcmp(target.classname, "point_combat") == 0)
                    {
                        self.combattarget = self.target;
                        fixup             = true;
                    }
                    else
                    {
                        notcombat = true;
                    }
                }

                if (notcombat && self.combattarget != null)
                {
                    GameBase.gi.Dprintf(self.classname + " at " + Lib.Vtos(self.s.origin) + " has target with mixed types\\n");
                }
                if (fixup)
                {
                    self.target = null;
                }
            }

            if (self.combattarget != null)
            {
                edict_t       target = null;
                EdictIterator edit   = null;
                while ((edit = GameBase.G_Find(edit, GameBase.findByTarget, self.combattarget)) != null)
                {
                    target = edit.o;
                    if (Lib.Strcmp(target.classname, "point_combat") != 0)
                    {
                        GameBase.gi.Dprintf(self.classname + " at " + Lib.Vtos(self.s.origin) + " has bad combattarget " + self.combattarget + " : " + target.classname + " at " + Lib.Vtos(target.s.origin));
                    }
                }
            }

            if (self.target != null)
            {
                self.goalentity = self.movetarget = GameBase.G_PickTarget(self.target);
                if (null == self.movetarget)
                {
                    GameBase.gi.Dprintf(self.classname + " can't find target " + self.target + " at " + Lib.Vtos(self.s.origin) + "\\n");
                    self.target = null;
                    self.monsterinfo.pausetime = 100000000;
                    self.monsterinfo.stand.Think(self);
                }
                else if (Lib.Strcmp(self.movetarget.classname, "path_corner") == 0)
                {
                    Math3D.VectorSubtract(self.goalentity.s.origin, self.s.origin, v);
                    self.ideal_yaw = self.s.angles[Defines.YAW] = Math3D.Vectoyaw(v);
                    self.monsterinfo.walk.Think(self);
                    self.target = null;
                }
                else
                {
                    self.goalentity            = self.movetarget = null;
                    self.monsterinfo.pausetime = 100000000;
                    self.monsterinfo.stand.Think(self);
                }
            }
            else
            {
                self.monsterinfo.pausetime = 100000000;
                self.monsterinfo.stand.Think(self);
            }

            self.think     = Monster.monster_think;
            self.nextthink = GameBase.level.time + Defines.FRAMETIME;
        }
示例#11
0
        public static void EndDMLevel()
        {
            edict_t ent;
            string  s, t, f;
            string  seps = " ,\\n\\r";

            if (((int)dmflags.value & Defines.DF_SAME_LEVEL) != 0)
            {
                PlayerHud.BeginIntermission(CreateTargetChangeLevel(level.mapname));
                return;
            }

            if (sv_maplist.string_renamed.Length > 0)
            {
                s = sv_maplist.string_renamed;
                f = null;
                StringTokenizer tk = new StringTokenizer(s, seps);
                while (tk.RemainingTokens > 0)
                {
                    tk.MoveNext();
                    t = tk.Current;
                    if (f == null)
                    {
                        f = t;
                    }
                    if (t.EqualsIgnoreCase(level.mapname))
                    {
                        if (tk.RemainingTokens == 0)
                        {
                            if (f == null)
                            {
                                PlayerHud.BeginIntermission(CreateTargetChangeLevel(level.mapname));
                            }
                            else
                            {
                                PlayerHud.BeginIntermission(CreateTargetChangeLevel(f));
                            }
                        }
                        else
                        {
                            tk.MoveNext();
                            PlayerHud.BeginIntermission(CreateTargetChangeLevel(tk.Current));
                        }
                        return;
                    }
                }
            }

            if (level.nextmap.Length > 0)
            {
                PlayerHud.BeginIntermission(CreateTargetChangeLevel(level.nextmap));
            }
            else
            {
                EdictIterator edit = null;
                edit = G_Find(edit, findByClass, "target_changelevel");
                if (edit == null)
                {
                    PlayerHud.BeginIntermission(CreateTargetChangeLevel(level.mapname));
                    return;
                }

                ent = edit.o;
                PlayerHud.BeginIntermission(ent);
            }
        }
示例#12
0
            public override bool Think(edict_t self)
            {
                edict_t ent;
                edict_t ignore;

                float[] point = new float[] { 0, 0, 0 };
                float[] dir   = new float[] { 0, 0, 0 };
                float[] start = new float[] { 0, 0, 0 };
                float[] end   = new float[] { 0, 0, 0 };
                int     dmg;
                trace_t tr;

                if (GameBase.deathmatch.value != 0)
                {
                    dmg = 5;
                }
                else
                {
                    dmg = 10;
                }
                EdictIterator edit = null;

                while ((edit = GameBase.Findradius(edit, self.s.origin, 256)) != null)
                {
                    ent = edit.o;
                    if (ent == self)
                    {
                        continue;
                    }
                    if (ent == self.owner)
                    {
                        continue;
                    }
                    if (ent.takedamage == 0)
                    {
                        continue;
                    }
                    if (0 == (ent.svflags & Defines.SVF_MONSTER) && (null == ent.client) && (Lib.Strcmp(ent.classname, "misc_explobox") != 0))
                    {
                        continue;
                    }
                    Math3D.VectorMA(ent.absmin, 0.5F, ent.size, point);
                    Math3D.VectorSubtract(point, self.s.origin, dir);
                    Math3D.VectorNormalize(dir);
                    ignore = self;
                    Math3D.VectorCopy(self.s.origin, start);
                    Math3D.VectorMA(start, 2048, dir, end);
                    while (true)
                    {
                        tr = GameBase.gi.Trace(start, null, null, end, ignore, Defines.CONTENTS_SOLID | Defines.CONTENTS_MONSTER | Defines.CONTENTS_DEADMONSTER);
                        if (null == tr.ent)
                        {
                            break;
                        }
                        if ((tr.ent.takedamage != 0) && 0 == (tr.ent.flags & Defines.FL_IMMUNE_LASER) && (tr.ent != self.owner))
                        {
                            GameCombat.T_Damage(tr.ent, self, self.owner, dir, tr.endpos, Globals.vec3_origin, dmg, 1, Defines.DAMAGE_ENERGY, Defines.MOD_BFG_LASER);
                        }
                        if (0 == (tr.ent.svflags & Defines.SVF_MONSTER) && (null == tr.ent.client))
                        {
                            GameBase.gi.WriteByte(Defines.svc_temp_entity);
                            GameBase.gi.WriteByte(Defines.TE_LASER_SPARKS);
                            GameBase.gi.WriteByte(4);
                            GameBase.gi.WritePosition(tr.endpos);
                            GameBase.gi.WriteDir(tr.plane.normal);
                            GameBase.gi.WriteByte(self.s.skinnum);
                            GameBase.gi.Multicast(tr.endpos, Defines.MULTICAST_PVS);
                            break;
                        }

                        ignore = tr.ent;
                        Math3D.VectorCopy(tr.endpos, start);
                    }

                    GameBase.gi.WriteByte(Defines.svc_temp_entity);
                    GameBase.gi.WriteByte(Defines.TE_BFG_LASER);
                    GameBase.gi.WritePosition(self.s.origin);
                    GameBase.gi.WritePosition(tr.endpos);
                    GameBase.gi.Multicast(self.s.origin, Defines.MULTICAST_PHS);
                }

                self.nextthink = GameBase.level.time + Defines.FRAMETIME;
                return(true);
            }
示例#13
0
        public static void G_UseTargets(edict_t ent, edict_t activator)
        {
            edict_t t;

            CheckClassname(ent);
            if (ent.delay != 0)
            {
                t           = G_Spawn();
                t.classname = "DelayedUse";
                t.nextthink = GameBase.level.time + ent.delay;
                t.think     = Think_Delay;
                t.activator = activator;
                if (activator == null)
                {
                    GameBase.gi.Dprintf("Think_Delay with no activator\\n");
                }
                t.message    = ent.message;
                t.target     = ent.target;
                t.killtarget = ent.killtarget;
                return;
            }

            if ((ent.message != null) && (activator.svflags & Defines.SVF_MONSTER) == 0)
            {
                GameBase.gi.Centerprintf(activator, "" + ent.message);
                if (ent.noise_index != 0)
                {
                    GameBase.gi.Sound(activator, Defines.CHAN_AUTO, ent.noise_index, 1, Defines.ATTN_NORM, 0);
                }
                else
                {
                    GameBase.gi.Sound(activator, Defines.CHAN_AUTO, GameBase.gi.Soundindex("misc/talk1.wav"), 1, Defines.ATTN_NORM, 0);
                }
            }

            EdictIterator edit = null;

            if (ent.killtarget != null)
            {
                while ((edit = GameBase.G_Find(edit, GameBase.findByTarget, ent.killtarget)) != null)
                {
                    t = edit.o;
                    G_FreeEdict(t);
                    if (!ent.inuse)
                    {
                        GameBase.gi.Dprintf("entity was removed while using killtargets\\n");
                        return;
                    }
                }
            }

            if (ent.target != null)
            {
                edit = null;
                while ((edit = GameBase.G_Find(edit, GameBase.findByTarget, ent.target)) != null)
                {
                    t = edit.o;
                    if (Lib.Q_stricmp("func_areaportal", t.classname) == 0 && (Lib.Q_stricmp("func_door", ent.classname) == 0 || Lib.Q_stricmp("func_door_rotating", ent.classname) == 0))
                    {
                        continue;
                    }
                    if (t == ent)
                    {
                        GameBase.gi.Dprintf("WARNING: Entity used itself.\\n");
                    }
                    else
                    {
                        if (t.use != null)
                        {
                            t.use.Use(t, ent, activator);
                        }
                    }

                    if (!ent.inuse)
                    {
                        GameBase.gi.Dprintf("entity was removed while using targets\\n");
                        return;
                    }
                }
            }
        }