home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Gamer 3.2
/
1997-05_Disc_3.2.iso
/
QUAKECTF
/
SRC
/
BOT
/
BOTCAM.QC
< prev
next >
Wrap
Text File
|
1997-01-29
|
14KB
|
608 lines
float old_crosshair;
float old_r_drawviewmodel;
float old_viewsize;
//=============================================================
void () SaveViewSettings =
{
old_crosshair = cvar("crosshair");
old_r_drawviewmodel = cvar("r_drawviewmodel");
old_viewsize = cvar("viewsize");
};
//=============================================================
void () FullView =
{
stuffcmd(self, "crosshair 0\n");
stuffcmd(self, "r_drawviewmodel 0\n");
stuffcmd(self, "viewsize 120\n");
};
//=============================================================
void () RestoreViewSettings =
{
local string st;
stuffcmd(self, "crosshair ");
st = ftos(old_crosshair);
stuffcmd(self, st);
stuffcmd(self, "\n");
stuffcmd(self, "r_drawviewmodel ");
st = ftos(old_r_drawviewmodel);
stuffcmd(self, st);
stuffcmd(self, "\n");
stuffcmd(self, "viewsize ");
st = ftos(old_viewsize);
stuffcmd(self, st);
stuffcmd(self, "\n");
};
//=============================================================
// self is the player
//=============================================================
void () ToggleCamera =
{
if (self.classname != "player")
return;
if (self.observer_flags & PLAYER_USING_CAMERA)
self.observer_flags = self.observer_flags - PLAYER_USING_CAMERA;
else
self.observer_flags = self.observer_flags | PLAYER_USING_CAMERA;
if (self.observer_flags & PLAYER_USING_CAMERA)
{
sprint(self, "camera view ON\n");
if (!auto_camera_view)
ToggleAutoCamera();
self.observer_flags = self.observer_flags | PLAYER_NO_TARGET;
cur_camera_watch_ent = find(world, classname, "bot");
if (cur_camera_watch_ent == world)
sprint(self, "no bots to watch\n");
self.takedamage = DAMAGE_NO;
self.solid = SOLID_NOT;
self.movetype = MOVETYPE_NONE;
setmodel (self, string_null);
setsize(self, '0 0 0', '0 0 0');
self.weaponmodel = "";
self.weaponframe = 0;
self.weapon = 0;
//SaveViewSettings();
//FullView();
}
else
{
sprint(self, "camera view OFF\n");
if (auto_fov_control)
stuffcmd(self, "fov 90\n");
self.takedamage = DAMAGE_AIM;
self.solid = SOLID_SLIDEBOX;
self.movetype = MOVETYPE_WALK;
setmodel (self, "progs/player.mdl");
setsize(self, VEC_HULL_MIN, VEC_HULL_MAX);
self.weapon = IT_SHOTGUN;
//RestoreViewSettings();
}
};
//=============================================================
// self is the player
//=============================================================
void (entity ent) WatchEnt =
{
if (self.classname != "player")
return;
if (cur_camera_watch_ent != ent)
{
cur_camera_watch_ent = ent;
if (bot_debug >= 1)
{
if (cur_camera_watch_ent != world)
{
sprint(self, "watching ");
sprint(self, cur_camera_watch_ent.netname);
sprint(self, "\n");
}
else
{
sprint(self, "watching nothing\n");
}
}
}
};
//=============================================================
// self is the player
//=============================================================
void () ToggleAutoCamera =
{
if (self.classname != "player")
return;
auto_camera_view = !auto_camera_view;
if (auto_camera_view)
sprint(self, "auto-camera ON\n");
else
{
sprint(self, "auto-camera OFF\n");
stuffcmd(self, "fov 90\n");
}
};
//=============================================================
// self is the player
// this is kind of cool but in Quake 1.06 fov is not stored in
// demo files, so this is off by default.
//=============================================================
void () ToggleFOVControl =
{
if (self.classname != "player")
return;
auto_fov_control = !auto_fov_control;
if (auto_fov_control)
sprint(self, "auto-fov control ON\n");
else
{
sprint(self, "auto-fov control OFF\n");
stuffcmd(self, "fov 90\n");
}
};
//====================================================
// self is the bot
// trace out a few lines and try to see the thing
//====================================================
float (vector spot1, vector spot2) entvisible =
{
traceline (spot1, spot2, TRUE, self); // see through other monsters
if (trace_inopen && trace_inwater)
return FALSE; // sight line crossed contents
if (trace_fraction == 1)
return TRUE;
return FALSE;
};
//=============================================================
// self is the player
//=============================================================
entity (entity p) GetNextPlayerOrBot =
{
local entity p, bot;
bot = FindNextPlayerOrBot(p);
if (bot == world)
bot = find(world, classname, "player");
return bot;
};
//=============================================================
//=============================================================
void () AutoSetCameraWatchEnt =
{
local entity bot, best_bot, p;
local float num_bots_nearby, best_num_bots_nearby;
best_num_bots_nearby = 0;
best_bot = world;
bot = find(world, classname, "player");
while (bot != world)
{
num_bots_nearby = 0;
p = findradius(bot.origin, 700);
while (p != world)
{
if (p != bot)
if ((p.classname == "bot") || (p.classname == "player"))
if (!(p.observer_flags & PLAYER_NO_TARGET))
if (!(p.observer_flags & PLAYER_USING_CAMERA))
if (p.deadflag != DEAD_DEAD)
if (p.team != bot.team)
if (entvisible(p.origin, bot.origin))
{
num_bots_nearby = num_bots_nearby + 1;
}
p = p.chain;
}
if (bot.deadflag != DEAD_DEAD)
if (num_bots_nearby > best_num_bots_nearby)
{
best_bot = bot;
best_num_bots_nearby = num_bots_nearby;
}
bot = FindNextPlayerOrBot(bot);
}
// if can't find some action, find a game-relevant bot
local float found;
found = FALSE;
if (best_bot == world)
{
bot = find(world, classname, "player");
while ((bot != world) && (!found))
{
if (bot.player_flag & ITEM_ENEMY_FLAG)
{
best_bot = bot;
found = TRUE;
}
bot = FindNextPlayerOrBot(bot);
}
if (!found)
{
best_num_bots_nearby = 0;
best_bot = world;
bot = find(world, classname, "player");
while (bot != world)
{
num_bots_nearby = 0;
p = findradius(bot.origin, 700);
while (p != world)
{
if (p != bot)
if ((p.classname == "bot") || (p.classname == "player"))
if (!(p.observer_flags & PLAYER_NO_TARGET))
if (!(p.observer_flags & PLAYER_USING_CAMERA))
if (p.deadflag != DEAD_DEAD)
if (p.team == bot.team)
if (entvisible(p.origin, bot.origin))
{
num_bots_nearby = num_bots_nearby + 1;
}
p = p.chain;
}
if (bot.deadflag != DEAD_DEAD)
if (num_bots_nearby > best_num_bots_nearby)
{
best_bot = bot;
best_num_bots_nearby = num_bots_nearby;
}
bot = FindNextPlayerOrBot(bot);
}
// a team going to kick some ass
if (best_num_bots_nearby > 0)
{
found = TRUE;
}
}
// no action, no flag carrier, no same-team group
// look for a bot with pentagram
if (!found)
{
bot = find(world, classname, "player");
while ((bot != world) && (!found))
{
if (bot.invincible_finished > time)
{
best_bot = bot;
found = TRUE;
}
bot = FindNextPlayerOrBot(bot);
}
}
// look for a bot with quad
if (!found)
{
bot = find(world, classname, "player");
while ((bot != world) && (!found))
{
if (bot.super_damage_finished > time)
{
best_bot = bot;
found = TRUE;
}
bot = FindNextPlayerOrBot(bot);
}
}
// look for a bot with strength rune
if (!found)
{
bot = find(world, classname, "player");
while ((bot != world) && (!found))
{
if (bot.player_flag & ITEM_RUNE2_FLAG)
{
best_bot = bot;
found = TRUE;
}
bot = FindNextPlayerOrBot(bot);
}
}
// look for a bot with a rocket launcher
if (!found)
{
bot = find(world, classname, "player");
while ((bot != world) && (!found))
{
if (bot.items & IT_ROCKET_LAUNCHER)
{
best_bot = bot;
found = TRUE;
}
bot = FindNextPlayerOrBot(bot);
}
}
// look for a bot with a thunderbolt
if (!found)
{
bot = find(world, classname, "player");
while ((bot != world) && (!found))
{
if (bot.items & IT_LIGHTNING)
{
best_bot = bot;
found = TRUE;
}
bot = FindNextPlayerOrBot(bot);
}
}
// look for a bot with a grenade launcher
if (!found)
{
bot = find(world, classname, "player");
while ((bot != world) && (!found))
{
if (bot.items & IT_GRENADE_LAUNCHER)
{
best_bot = bot;
found = TRUE;
}
bot = FindNextPlayerOrBot(bot);
}
}
}
// still haven't found a bot? random bot.
if (best_bot == world)
{
local float nb;
nb = (next_bot_num - 1);
nb = nb + GetNumHumans();
nb = random() * nb;
nb = floor(nb);
bot = find(world, classname, "player");
while ((bot != world) && (!found))
{
if (nb == 0)
{
best_bot = bot;
found = TRUE;
}
nb = nb - 1;
if (nb < 0)
nb = 0;
bot = GetNextPlayerOrBot(bot);
}
}
if (best_bot == world)
dprint("can't find a bot to watch\n");
WatchEnt(best_bot);
};
//=============================================================
void (vector vec) SetPlayerFOV =
{
if (auto_fov_control)
{
local float vl;
vl = vlen(vec);
if (vl < 200)
stuffcmd(self, "fov 90\n");
else
{
// we want to map 200...700 to 90..40
vl = vl - 200;
vl = 500 - vl;
// now vl in the range 500..0
vl = vl / 10;
// now vl in the range 50..0
vl = vl + 40;
// now vl in the range 90..40
local string st;
st = ftos(vl);
stuffcmd(self, "fov ");
stuffcmd(self, st);
stuffcmd(self, "\n");
}
}
};
//=============================================================
// self is the player
//setorigin(self, org);
//self.angles = me.v_angle = ang;
//self.fixangle = TRUE; // turn this way immediately
//=============================================================
void (float force_update) SetPlayerViewPoint =
{
local entity bot, p;
local vector ang, vec;
local float force_update_camera, dot;
if (self.classname != "player")
return;
if (auto_camera_view)
AutoSetCameraWatchEnt();
bot = cur_camera_watch_ent;
if (bot == world)
return;
local vector watch_pos;
watch_pos = bot.origin;
local float nm_bots;
watch_pos = '0 0 0';
nm_bots = 0;
p = findradius(bot.origin, 700);
while (p != world)
{
if ((p.classname == "bot") || (p.classname == "player"))
if (!(p.observer_flags & PLAYER_NO_TARGET))
if (!(p.observer_flags & PLAYER_USING_CAMERA))
if (p.deadflag != DEAD_DEAD)
if (entvisible(p.origin, bot.origin))
{
watch_pos = watch_pos + p.origin;
nm_bots = nm_bots + 1;
}
p = p.chain;
}
watch_pos_x = watch_pos_x / nm_bots;
watch_pos_y = watch_pos_y / nm_bots;
watch_pos_z = watch_pos_z / nm_bots;
force_update_camera = force_update;
makevectors (self.angles);
vec = normalize (watch_pos - (last_camera_ent.origin + '0 0 30'));
dot = vec * v_forward;
if ((dot > -0.5) && (dot < 0.5))
force_update_camera = TRUE;
if (!entvisible(watch_pos, last_camera_ent.origin + '0 0 30'))
force_update_camera = TRUE;
// extra-nifty tracking camera view when bot is falling/flying
if ((!(bot.flags & FL_ONGROUND)) && (watch_pos == bot.origin))
force_update_camera = TRUE;
// update camera every 1 sec, or whenever we force an update
if ((time < (last_camera_update + 1)) && (!force_update_camera))
{
// no need to change camera position, but change fov if that is enabled
SetPlayerFOV(vec);
return;
}
p = findradius(bot.origin, 700);
while (p != world)
{
if (p != bot)
if (p.classname != "bot")
if (p.classname != "item_flag_team1")
if (p.classname != "item_flag_team2")
if (p.model != "progs/s_spike.mdl")
if (p.model != "progs/spike.mdl")
if (entvisible(watch_pos, p.origin + '0 0 30'))
{
// update player viewpoint if it's the same ent as last time,
// or if it's more than 0.3 seconds later
// i.e. don't be flashing from viewpoint to viewpoint faster
// than every 0.3 seconds... however this allows the same ent
// to change vector
if ((p == last_camera_ent) || (time > (last_camera_update + 0.5)))
{
last_camera_ent = p;
last_camera_update = time;
setorigin(self, p.origin + '0 0 30');
vec = watch_pos - (p.origin + '0 0 30');
vec_z = 0 - vec_z;
ang = vectoangles(vec);
self.angles = ang;
self.v_angle = ang;
self.fixangle = TRUE; // turn this way immediately
SetPlayerFOV(vec);
return;
}
}
p = p.chain;
}
};
//=============================================================
// self is the player
// this forces an update of the camera view...it's for
// doing in response to a button push, as a one-shot deal
//=============================================================
void () SetPlayerViewpointNow =
{
local float old_auto_camera_view;
old_auto_camera_view = auto_camera_view;
auto_camera_view = TRUE;
SetPlayerViewPoint(TRUE);
auto_camera_view = old_auto_camera_view;
};
//=============================================================
// self is the player
//=============================================================
void () WatchNextPlayerOrBot =
{
local entity bot;
local float found;
if (auto_camera_view)
ToggleAutoCamera(); // if we are auto-camera, turn it off first
bot = cur_camera_watch_ent;
found = FALSE;
while (!found)
{
bot = GetNextPlayerOrBot(bot);
if (!(bot.observer))
if (!(bot.observer_flags & PLAYER_USING_CAMERA))
if (!(bot.observer_flags & PLAYER_NO_TARGET))
{
found = TRUE;
}
}
WatchEnt(bot);
if (bot == world)
{
sprint(self, "nothing to watch\n");
}
else
{
sprint(self, "watching ");
sprint(self, bot.netname);
sprint(self, "\n");
}
};