Ejemplo n.º 1
0
        public static void Give_f(edict_t ent)
        {
            String  name;
            gitem_t it;
            Int32   index;
            Int32   i;
            Boolean give_all;
            edict_t it_ent;

            if (GameBase.deathmatch.value != 0 && GameBase.sv_cheats.value == 0)
            {
                SV_GAME.PF_cprintfhigh(ent, "You must run the server with '+set cheats 1' to enable this command.\\n");
                return;
            }

            name = Cmd.Args();
            if (0 == Lib.Q_stricmp(name, "all"))
            {
                give_all = true;
            }
            else
            {
                give_all = false;
            }
            if (give_all || 0 == Lib.Q_stricmp(Cmd.Argv(1), "health"))
            {
                if (Cmd.Argc() == 3)
                {
                    ent.health = Lib.Atoi(Cmd.Argv(2));
                }
                else
                {
                    ent.health = ent.max_health;
                }
                if (!give_all)
                {
                    return;
                }
            }

            if (give_all || 0 == Lib.Q_stricmp(name, "weapons"))
            {
                for (i = 1; i < GameBase.game.num_items; i++)
                {
                    it = GameItemList.itemlist[i];
                    if (null == it.pickup)
                    {
                        continue;
                    }
                    if (0 == (it.flags & Defines.IT_WEAPON))
                    {
                        continue;
                    }
                    ent.client.pers.inventory[i] += 1;
                }

                if (!give_all)
                {
                    return;
                }
            }

            if (give_all || 0 == Lib.Q_stricmp(name, "ammo"))
            {
                for (i = 1; i < GameBase.game.num_items; i++)
                {
                    it = GameItemList.itemlist[i];
                    if (null == it.pickup)
                    {
                        continue;
                    }
                    if (0 == (it.flags & Defines.IT_AMMO))
                    {
                        continue;
                    }
                    GameItems.Add_Ammo(ent, it, 1000);
                }

                if (!give_all)
                {
                    return;
                }
            }

            if (give_all || Lib.Q_stricmp(name, "armor") == 0)
            {
                gitem_armor_t info;
                it = GameItems.FindItem("Jacket Armor");
                ent.client.pers.inventory[GameItems.ITEM_INDEX(it)] = 0;
                it = GameItems.FindItem("Combat Armor");
                ent.client.pers.inventory[GameItems.ITEM_INDEX(it)] = 0;
                it   = GameItems.FindItem("Body Armor");
                info = ( gitem_armor_t )it.info;
                ent.client.pers.inventory[GameItems.ITEM_INDEX(it)] = info.max_count;
                if (!give_all)
                {
                    return;
                }
            }

            if (give_all || Lib.Q_stricmp(name, "Power Shield") == 0)
            {
                it               = GameItems.FindItem("Power Shield");
                it_ent           = GameUtil.G_Spawn();
                it_ent.classname = it.classname;
                GameItems.SpawnItem(it_ent, it);
                GameItems.Touch_Item(it_ent, ent, GameBase.dummyplane, null);
                if (it_ent.inuse)
                {
                    GameUtil.G_FreeEdict(it_ent);
                }
                if (!give_all)
                {
                    return;
                }
            }

            if (give_all)
            {
                for (i = 1; i < GameBase.game.num_items; i++)
                {
                    it = GameItemList.itemlist[i];
                    if (it.pickup != null)
                    {
                        continue;
                    }
                    if ((it.flags & (Defines.IT_ARMOR | Defines.IT_WEAPON | Defines.IT_AMMO)) != 0)
                    {
                        continue;
                    }
                    ent.client.pers.inventory[i] = 1;
                }

                return;
            }

            it = GameItems.FindItem(name);
            if (it == null)
            {
                name = Cmd.Argv(1);
                it   = GameItems.FindItem(name);
                if (it == null)
                {
                    SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "unknown item\\n");
                    return;
                }
            }

            if (it.pickup == null)
            {
                SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "non-pickup item\\n");
                return;
            }

            index = GameItems.ITEM_INDEX(it);
            if ((it.flags & Defines.IT_AMMO) != 0)
            {
                if (Cmd.Argc() == 3)
                {
                    ent.client.pers.inventory[index] = Lib.Atoi(Cmd.Argv(2));
                }
                else
                {
                    ent.client.pers.inventory[index] += it.quantity;
                }
            }
            else
            {
                it_ent           = GameUtil.G_Spawn();
                it_ent.classname = it.classname;
                GameItems.SpawnItem(it_ent, it);
                GameItems.Touch_Item(it_ent, ent, GameBase.dummyplane, null);
                if (it_ent.inuse)
                {
                    GameUtil.G_FreeEdict(it_ent);
                }
            }
        }