Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions src/game/iw3/mp/components/cj_tas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
#include "events.h"
#include "cj_tas.h"

#define ANGLE2SHORT(x) ((int)((x) * 65536 / 360) & 65535)
#define SHORT2ANGLE(x) ((x) * (360.0 / 65536))

namespace iw3
{
namespace mp
Expand Down Expand Up @@ -97,7 +94,7 @@ void Cmd_Startplayback_f()
is_playing = true;
playback_start_time = 0; // Will be set on first UpdateCommand
recording_start_time = current_recording[0].serverTime;
CG_GameMessage(0, "Playback ^2started\n");
// CG_GameMessage(0, "Playback ^2started\n");
}

void Cmd_Stopplayback_f()
Expand All @@ -110,7 +107,7 @@ void Cmd_Stopplayback_f()

play_frame = 0;
is_playing = false;
CG_GameMessage(0, "Playback ^1stopped\n");
// CG_GameMessage(0, "Playback ^1stopped\n");
}

bool IsPlayback()
Expand Down Expand Up @@ -404,14 +401,14 @@ cj_tas::cj_tas()
cj_tas_rpg_lookdown_pitch =
Dvar_RegisterInt("cj_tas_rpg_lookdown_pitch", 70, -70, 70, 0, "RPG lookdown pitch angle");

Events::OnCG_DrawActive(
[]()
{
if (cj_tas::TAS_Enabled())
{
CG_DrawTAS();
}
});
// Events::OnCG_DrawActive(
// []()
// {
// if (cj_tas::TAS_Enabled())
// {
// CG_DrawTAS();
// }
// });

Events::OnCG_Init(
[]()
Expand Down
43 changes: 43 additions & 0 deletions src/game/iw3/mp/components/sv_bots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace mp
struct BotMovementInfo_t
{
int buttons;
bool is_mirroring_client;
int mirror_client_num;
};

BotMovementInfo_t g_botai[MAX_CLIENTS];
Expand Down Expand Up @@ -60,6 +62,23 @@ void SV_BotUserMove_Stub(client_t *cl)
if (g_clients[clientNum].sess.archiveTime == 0)
{
cmd.buttons = g_botai[clientNum].buttons;

// Handle mirrored mode
// TODO: fix angles?
if (g_botai[clientNum].is_mirroring_client)
{
const int mirror_num = g_botai[clientNum].mirror_client_num;
if (mirror_num < MAX_CLIENTS)
{
const usercmd_s &lastUsercmd = svsHeader->clients[mirror_num].lastUsercmd;
cmd.buttons = lastUsercmd.buttons;
cmd.angles[PITCH] = lastUsercmd.angles[PITCH];
cmd.angles[YAW] = lastUsercmd.angles[YAW];
// Ignore ROLL
cmd.forwardmove = lastUsercmd.forwardmove;
cmd.rightmove = lastUsercmd.rightmove;
}
}
}

cl->header.deltaMessage = cl->header.netchan.outgoingSequence - 1;
Expand Down Expand Up @@ -121,6 +140,29 @@ static void Scr_BotStop(scr_entref_t entref)
Scr_Error("Usage: <bot> botStop();");

g_botai[entref.entnum].buttons = 0;
g_botai[entref.entnum].is_mirroring_client = false;
}

static void Scr_BotMirror(scr_entref_t entref)
{
// Validate self is a player entity
GetPlayerEntity(entref);

if (Scr_GetNumParam() != 1)
Scr_Error("Usage: <bot> BotMirror(<client>);");

const gentity_s *targetEntity = Scr_GetEntity(0);
if (!targetEntity->client)
Scr_Error("not a player");

const int clientNum = targetEntity->client - g_clients;
if (entref.entnum == clientNum)
{
Scr_Error("BotMirror: a bot cannot mirror itself.");
}

g_botai[entref.entnum].is_mirroring_client = true;
g_botai[entref.entnum].mirror_client_num = clientNum;
}

sv_bots::sv_bots()
Expand All @@ -129,6 +171,7 @@ sv_bots::sv_bots()
SV_BotUserMove_Detour.Install();

Scr_AddMethod("botaction", Scr_BotAction, 0);
Scr_AddMethod("botmirror", Scr_BotMirror, 0);
Scr_AddMethod("botstop", Scr_BotStop, 0);

Events::OnVMShutdown(CleanBotArray);
Expand Down
5 changes: 4 additions & 1 deletion src/game/iw3/mp/symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace iw3
{
namespace mp
{
#define ANGLE2SHORT(x) ((int)((x) * 65536 / 360) & 65535)
#define SHORT2ANGLE(x) ((x) * (360.0 / 65536))

// Functions
static auto AngleDelta = reinterpret_cast<float (*)(float a1, float a2)>(0x821DABC0);
static auto AngleNormalize180 = reinterpret_cast<float (*)(float angle)>(0x820A0088);
Expand Down Expand Up @@ -135,7 +138,7 @@ static auto Scr_AddArray = reinterpret_cast<void (*)()>(0x82210538);
static auto Scr_AddInt = reinterpret_cast<void (*)(int value)>(0x822111C0);
static auto Scr_AddString = reinterpret_cast<void (*)(const char *value)>(0x82210F28);
static auto Scr_Error = reinterpret_cast<void (*)(const char *error)>(0x8220F6F0);
static auto Scr_GetEntity = reinterpret_cast<gentity_s *(*)(scr_entref_t * entref)>(0x8224EE68);
static auto Scr_GetEntity = reinterpret_cast<gentity_s *(*)(unsigned int index)>(0x8224EE68);
static auto Scr_GetFunction = reinterpret_cast<BuiltinFunction (*)(const char **pName, int *type)>(0x82256ED0);
static auto Scr_GetInt = reinterpret_cast<int (*)(unsigned int index)>(0x8220FD10);
static auto Scr_GetString = reinterpret_cast<char *(*)(unsigned int index)>(0x82211390);
Expand Down