diff --git a/src/botlib/README b/src/botlib/README new file mode 100644 index 00000000..c367588b --- /dev/null +++ b/src/botlib/README @@ -0,0 +1,4 @@ +This is the NUCLIDE bot. + +He likes playing with you, when nobody else will. + diff --git a/src/botlib/bot.cpp b/src/botlib/bot.cpp new file mode 100644 index 00000000..fc565488 --- /dev/null +++ b/src/botlib/bot.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2016-2020 Marco Hladik + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +void +bot::PickName(void) +{ + int n = 0; + entity pbot = world; + for (int i = 1; (pbot = edict_num(i)); i++) { + if (clienttype(pbot) == CLIENTTYPE_BOT) { + n++; + } + } + forceinfokey(this, "name", sprintf("Bot %i", n)); +} + +void +bot::bot(void) +{ + PickName(); + ClientConnect(); + PutClientInServer(); +} + +entity +Bot_AddQuick(void) +{ + entity newbot; + entity oself; + + oself = self; + self = world; + self = spawnclient(); + + if (!self) { + print("^1Bot_AddQuick^7: Can't add bot. Server is full\n"); + self = oself; + return world; + } + + spawnfunc_bot(); + newbot = self; + self = oself; + return newbot; +} diff --git a/src/botlib/bot.h b/src/botlib/bot.h new file mode 100644 index 00000000..3d0f8bd2 --- /dev/null +++ b/src/botlib/bot.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2016-2020 Marco Hladik + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +enum +{ + BOT_PERSONALITY_NORMAL, + BOT_PERSONALITY_AGRESSIVE, + BOT_PERSONALITY_DEFENSIVE +}; + +class bot:player +{ + void(void) bot; + virtual void(void) PickName; +}; diff --git a/src/botlib/include.src b/src/botlib/include.src new file mode 100644 index 00000000..5cc63c7c --- /dev/null +++ b/src/botlib/include.src @@ -0,0 +1,6 @@ +#define BOT_INCLUDED + +#includelist +../botlib/bot.h +../botlib/bot.cpp +#endlist diff --git a/src/server/cstrike/input.c b/src/server/cstrike/input.c index 243e0865..74db8f56 100644 --- a/src/server/cstrike/input.c +++ b/src/server/cstrike/input.c @@ -36,6 +36,16 @@ Game_Input(void) if (self.impulse == 100) { Flashlight_Toggle(); } + + if (self.impulse == 240) { + entity bot = Bot_AddQuick(); + if (bot) { + entity oself = self; + self = bot; + CSEv_JoinAuto(); + self = oself; + } + } if (cvar("sv_cheats") == 1) { player pl = (player)self; diff --git a/src/server/valve/input.c b/src/server/valve/input.c index f614482d..3ff630c6 100644 --- a/src/server/valve/input.c +++ b/src/server/valve/input.c @@ -42,6 +42,9 @@ void Game_Input(void) if (self.impulse == 100) { Flashlight_Toggle(); } + + if (self.impulse == 240) + Bot_AddQuick(); if (cvar("sv_cheats") == 1) { player pl = (player)self; diff --git a/src/server/valve/progs.src b/src/server/valve/progs.src index 30125ab9..3eefbe86 100755 --- a/src/server/valve/progs.src +++ b/src/server/valve/progs.src @@ -112,6 +112,8 @@ damage.c ../valve/rules.c ../footsteps.c ../flashlight.c +../../botlib/include.src + input.c spawn.c ../vote.c