From a06055f9714b9b3f7e8d736c2352f77709d988b6 Mon Sep 17 00:00:00 2001 From: Molgrum Date: Tue, 2 Oct 2007 15:17:22 +0000 Subject: [PATCH] Fixed bot support. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@2696 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/server/sv_phys.c | 44 +++++++++++++++++++++++++++++++++++++ engine/server/sv_sys_unix.c | 22 +++++++++++++++++++ engine/server/sv_sys_win.c | 33 ++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) diff --git a/engine/server/sv_phys.c b/engine/server/sv_phys.c index 62206e1f8..c529f07ac 100644 --- a/engine/server/sv_phys.c +++ b/engine/server/sv_phys.c @@ -2005,6 +2005,50 @@ qboolean SV_Physics (void) return false; } + if (/*sv.botsonthemap &&*/ progstype == PROG_QW) + { + //DP_QC_BOTCLIENT - make the bots move with qw physics. + //They only move when there arn't any players on the server, but they should move at the right kind of speed if there are... hopefully + //they might just be a bit lagged. they will at least be as smooth as other players are. + + usercmd_t ucmd; + static int old_bot_time; //I hate using floats for timers. + host_frametime = (Sys_Milliseconds() - old_bot_time) / 1000.0f; + client_t *oldhost; + if (1 || host_frametime >= 1 / 72.0f) + { + memset(&ucmd, 0, sizeof(ucmd)); + old_bot_time = Sys_Milliseconds(); + for (i = 1; i <= sv.allocated_client_slots; i++) + { + if (svs.clients[i-1].state && svs.clients[i-1].protocol == SCP_BAD) + { //then this is a bot + ucmd.msec = host_frametime*1000; + ucmd.angles[0] = svs.clients[i-1].edict->v->angles[0] * (65535/360.0f); + ucmd.angles[1] = svs.clients[i-1].edict->v->angles[1] * (65535/360.0f); + ucmd.angles[2] = svs.clients[i-1].edict->v->angles[2] * (65535/360.0f); + ucmd.forwardmove = svs.clients[i-1].edict->xv->movement[0]; + ucmd.sidemove = svs.clients[i-1].edict->xv->movement[1]; + ucmd.upmove = svs.clients[i-1].edict->xv->movement[2]; + ucmd.buttons = (svs.clients[i-1].edict->v->button0?1:0) | (ucmd.buttons = svs.clients[i-1].edict->v->button2?2:0); + + svs.clients[i-1].lastcmd = ucmd; //allow the other clients to predict this bot. + + oldhost = host_client; + host_client = &svs.clients[i-1]; + sv_player = host_client->edict; + SV_PreRunCmd(); + SV_RunCmd(&ucmd, false); + SV_PostRunCmd(); + + host_client = oldhost; + //sv_player = host_client->edict; + } + } + old_bot_time = Sys_Milliseconds(); + } + } + // don't bother running a frame if sys_ticrate seconds haven't passed host_frametime = realtime - old_time; diff --git a/engine/server/sv_sys_unix.c b/engine/server/sv_sys_unix.c index db74d877e..5251ea710 100644 --- a/engine/server/sv_sys_unix.c +++ b/engine/server/sv_sys_unix.c @@ -160,6 +160,28 @@ int Sys_DebugLog(char *file, char *fmt, ...) } return 1; } + +/* +================ +Sys_Milliseconds +================ +*/ +unsigned int Sys_Milliseconds (void) +{ + struct timeval tp; + struct timezone tzp; + int secbase; + + gettimeofday(&tp, &tzp); + + if (!secbase) + { + secbase = tp.tv_sec; + return tp.tv_usec/1000; + } + return (tp.tv_sec - secbase)*1000 + tp.tv_usec/1000; +} + /* ================ Sys_DoubleTime diff --git a/engine/server/sv_sys_win.c b/engine/server/sv_sys_win.c index 118b82514..fa9454862 100644 --- a/engine/server/sv_sys_win.c +++ b/engine/server/sv_sys_win.c @@ -364,6 +364,39 @@ void Sys_Error (const char *error, ...) Sys_Quit (); } +/* +================ +Sys_Milliseconds +================ +*/ +unsigned int Sys_Milliseconds (void) +{ + static DWORD starttime; + static qboolean first = true; + DWORD now; +// double t; + + now = timeGetTime(); + + if (first) { + first = false; + starttime = now; + return 0.0; + } + /* + if (now < starttime) // wrapped? + { + double r; + r = (now) + (LONG_MAX - starttime); + starttime = now; + return r; + } + + if (now - starttime == 0) + return 0.0; +*/ + return (now - starttime); +} /* ================