super-coop/source/p_client.qc

1736 lines
40 KiB
Plaintext

// p_client.qc: player-adjacent functions
void() impulse_commands;
/*
=============================================================================
QUAKED FUNCTIONS
=============================================================================
*/
/*QUAKED info_player_start(1 0 0) (-16 -16 -24) (16 16 24)
The normal starting point for a level.
*/
void() info_player_start = {
};
/*QUAKED info_player_start2(1 0 0) (-16 -16 -24) (16 16 24)
Only used on start map for the return point from an episode.
*/
void() info_player_start2 = {
};
/*
saved out by quaked in region mode
*/
void() testplayerstart = {
};
/*QUAKED info_player_deathmatch(1 0 1) (-16 -16 -24) (16 16 24)
potential spawning position for deathmatch games
*/
void() info_player_deathmatch = {
};
/*QUAKED info_player_coop(1 0 1) (-16 -16 -24) (16 16 24)
potential spawning position for coop games
*/
void() info_player_coop = {
};
string(float pro) pronoun_subject = {
switch(pro) {
case PRO_NONE: return "none";
case PRO_FAE: return "fae";
case PRO_HE: return "he";
case PRO_IT: return "it";
case PRO_SHE: return "she";
case PRO_THEY: return "they";
case PRO_XEY: return "xey";
case PRO_ZE_H: return "ze";
case PRO_ZE_Z: return "ze";
default: return "unknown";
}
};
string(float pro) pronoun_possessive = {
switch(pro) {
case PRO_NONE: return "none";
case PRO_FAE: return "faer";
case PRO_HE: return "his";
case PRO_IT: return "its";
case PRO_SHE: return "her";
case PRO_THEY: return "their";
case PRO_XEY: return "xyr";
case PRO_ZE_H: return "hir";
case PRO_ZE_Z: return "zir";
default: return "unknown";
}
};
/*
=============================================================================
LEVEL CHANGING / INTERMISSION
=============================================================================
*/
/*QUAKED info_intermission(1 0.5 0.5) (-16 -16 -16) (16 16 16)
This is the camera point for the intermission.
Use mangle instead of angle, so you can set pitch or roll as well as yaw. 'pitch roll yaw'
*/
void() info_intermission = {
};
void() SetChangeParms = {
if(self.health <= 0 || self.lives == 0) {
SetNewParms();
return;
}
// remove items
self.items &= ~(IT_KEY1 | IT_KEY2 | IT_INVISIBILITY | IT_INVULNERABILITY |
IT_SUIT | IT_QUAD);
// cap super health
self.health = minmax(self.health, 50, 100);
parm1 = self.items;
parm2 = self.health;
parm3 = self.armorvalue;
parm4 = (self.ammo_shells < 25 ? 25 : self.ammo_shells);
parm5 = self.ammo_nails;
parm6 = self.ammo_rockets;
parm7 = self.ammo_cells;
parm8 = self.weapon;
parm9 = self.armortype * 100;
parm10 = self.pronoun;
};
void() SetNewParms = {
parm1 = IT_SHOTGUN | IT_AXE;
parm2 = 100;
parm3 = 0;
parm4 = 25;
parm5 = 0;
parm6 = 0;
parm7 = 0;
parm8 = IT_SHOTGUN;
parm9 = 0;
};
void() decode_level_parms = {
float ofs, ofs2, pro;
if(!deathmatch && world.model == "maps/start.bsp") {
SetNewParms(); // take away all stuff on starting new episode
}
self.items = parm1;
self.health = parm2;
self.armorvalue = parm3;
self.ammo_shells = parm4;
self.ammo_nails = parm5;
self.ammo_rockets = parm6;
self.ammo_cells = parm7;
self.weapon = parm8;
self.armortype = parm9 * 0.01;
self.pronoun = parm10;
if(ext_strings) {
ofs = strstrofs(self.netname, "(", 0);
if(ofs != -1) {
for(pro = PRO_NONE; pro < PRO_MAX; pro++) {
ofs2 = strstrofs(self.netname, pronoun_possessive(pro), ofs);
if(ofs2 == ofs + 1 && strstrofs(self.netname, ")", ofs) != -1) {
self.pronoun = pro;
break;
}
}
}
}
};
/*
============
find_intermission
Returns the entity to view from
============
*/
entity() find_intermission = {
entity spot;
float cyc;
// look for info_intermission first
spot = find(world, classname, "info_intermission");
if(spot) {
// pick a random one
for(cyc = random() * 4; cyc > 1; cyc--) {
spot = find(spot, classname, "info_intermission");
if(!spot) {
spot = find(spot, classname, "info_intermission");
}
}
return spot;
}
// then look for the start position
spot = find(world, classname, "info_player_start");
if(spot) {
return spot;
}
// testinfo_player_start is only found in regioned levels
spot = find(world, classname, "testplayerstart");
if(spot) {
return spot;
}
error_obj("find_intermission: no spot");
};
void() go_to_next_map = {
if(cvar("samelevel")) { // if samelevel is set, stay on same level
change_level(mapname);
} else {
change_level(nextmap);
}
};
void() intermission_exit = {
const string FINALE_E1_UNREGISTERED =
"As the corpse of the monstrous entity\n"
"Chthon sinks back into the lava whence\n"
"it rose, you grip the Rune of Earth\n"
"Magic tightly. Now that you have\n"
"conquered the Dimension of the Doomed,\n"
"realm of Earth Magic, you are ready to\n"
"complete your task in the other three\n"
"haunted lands of Quake. Or are you? If\n"
"you don't register Quake, you'll never\n"
"know what awaits you in the Realm of\n"
"Black Magic, the Netherworld, and the\n"
"Elder World!";
const string FINALE_E1 =
"As the corpse of the monstrous entity\n"
"Chthon sinks back into the lava whence\n"
"it rose, you grip the Rune of Earth\n"
"Magic tightly. Now that you have\n"
"conquered the Dimension of the Doomed,\n"
"realm of Earth Magic, you are ready to\n"
"complete your task. A Rune of magic\n"
"power lies at the end of each haunted\n"
"land of Quake. Go forth, seek the\n"
"totality of the four Runes!";
const string FINALE_E2 =
"The Rune of Black Magic throbs evilly in\n"
"your hand and whispers dark thoughts\n"
"into your brain. You learn the inmost\n"
"lore of the Hell-Mother; Shub-Niggurath!\n"
"You now know that she is behind all the\n"
"terrible plotting which has led to so\n"
"much death and horror. But she is not\n"
"inviolate! Armed with this Rune, you\n"
"realize that once all four Runes are\n"
"combined, the gate to Shub-Niggurath's\n"
"Pit will open, and you can face the\n"
"Witch-Goddess herself in her frightful\n"
"otherworld cathedral.";
const string FINALE_E3 =
"The charred viscera of diabolic horrors\n"
"bubble viscously as you seize the Rune\n"
"of Hell Magic. Its heat scorches your\n"
"hand, and its terrible secrets blight\n"
"your mind. Gathering the shreds of your\n"
"courage, you shake the devil's shackles\n"
"from your soul, and become ever more\n"
"hard and determined to destroy the\n"
"hideous creatures whose mere existence\n"
"threatens the souls and psyches of all\n"
"the population of Earth.";
const string FINALE_E4 =
"Despite the awful might of the Elder\n"
"World, you have achieved the Rune of\n"
"Elder Magic, capstone of all types of\n"
"arcane wisdom. Beyond good and evil,\n"
"beyond life and death, the Rune\n"
"pulsates, heavy with import. Patient and\n"
"potent, the Elder Being Shub-Niggurath\n"
"weaves her dire plans to clear off all\n"
"life from the Earth, and bring her own\n"
"foul offspring to our world! For all the\n"
"dwellers in these nightmare dimensions\n"
"are her descendants! Once all Runes of\n"
"magic power are united, the energy\n"
"behind them will blast open the Gateway\n"
"to Shub-Niggurath, and you can travel\n"
"there to foil the Hell-Mother's plots\n"
"in person.";
const string FINALE_RUNES =
"Now, you have all four Runes. You sense\n"
"tremendous invisible forces moving to\n"
"unseal ancient barriers. Shub-Niggurath\n"
"had hoped to use the Runes Herself to\n"
"clear off the Earth, but now instead,\n"
"you will use them to enter her home and\n"
"confront her as an avatar of avenging\n"
"Earth-life. If you defeat her, you will\n"
"be remembered forever as the savior of\n"
"the planet. If she conquers, it will be\n"
"as if you had never been born.";
// skip any text in deathmatch
if(deathmatch) {
go_to_next_map();
return;
}
intermission_exittime = time + 1;
intermission_running++;
//
// run some text if at the end of an episode
//
if(intermission_running == 2) {
if(world.model == "maps/e1m7.bsp") {
write_byte(MSG_ALL, SVC_CDTRACK);
write_byte(MSG_ALL, 2);
write_byte(MSG_ALL, 3);
if(!cvar("registered")) {
write_byte(MSG_ALL, SVC_FINALE);
write_string(MSG_ALL, FINALE_E1_UNREGISTERED);
} else {
write_byte(MSG_ALL, SVC_FINALE);
write_string(MSG_ALL, FINALE_E1);
}
return;
} else if(world.model == "maps/e2m6.bsp") {
write_byte(MSG_ALL, SVC_CDTRACK);
write_byte(MSG_ALL, 2);
write_byte(MSG_ALL, 3);
write_byte(MSG_ALL, SVC_FINALE);
write_string(MSG_ALL, FINALE_E2);
return;
} else if(world.model == "maps/e3m6.bsp") {
write_byte(MSG_ALL, SVC_CDTRACK);
write_byte(MSG_ALL, 2);
write_byte(MSG_ALL, 3);
write_byte(MSG_ALL, SVC_FINALE);
write_string(MSG_ALL, FINALE_E3);
return;
} else if(world.model == "maps/e4m7.bsp") {
write_byte(MSG_ALL, SVC_CDTRACK);
write_byte(MSG_ALL, 2);
write_byte(MSG_ALL, 3);
write_byte(MSG_ALL, SVC_FINALE);
write_string(MSG_ALL, FINALE_E4);
return;
}
go_to_next_map();
}
if(intermission_running == 3) {
if(!cvar("registered")) {
// shareware episode has been completed, go to sell screen
write_byte(MSG_ALL, SVC_SELLSCREEN);
return;
}
if((serverflags & 15) == 15) {
write_byte(MSG_ALL, SVC_FINALE);
write_string(MSG_ALL, FINALE_RUNES);
return;
}
}
go_to_next_map();
};
/*
============
intermission_think
When the player presses attack or jump, change to the next level
============
*/
void() intermission_think = {
if(time < intermission_exittime) {
return;
}
if(!self.button0 && !self.button1 && !self.button2) {
return;
}
intermission_exit();
};
void() execute_changelevel = {
entity pos;
intermission_running = 1;
// enforce a wait time before allowing changelevel
if(deathmatch) {
intermission_exittime = time + 5;
} else {
intermission_exittime = time + 2;
}
write_byte(MSG_ALL, SVC_CDTRACK);
write_byte(MSG_ALL, 3);
write_byte(MSG_ALL, 3);
pos = find_intermission();
other = find(world, classname, "player");
while(other != world) {
other.view_ofs = VEC_ORIGIN;
other.angles = other.v_angle = pos.mangle;
other.fixangle = TRUE; // turn this way immediately
other.nextthink = time + 0.5;
other.takedamage = DAMAGE_NO;
other.solid = SOLID_NOT;
other.movetype = MOVETYPE_NONE;
other.modelindex = 0;
other.spectating = SPECTATING_INTERMISSION;
set_origin(other, pos.origin);
other = find(other, classname, "player");
}
write_byte(MSG_ALL, SVC_INTERMISSION);
};
void() changelevel_finish = {
nextmap = self.map;
sub_use_targets();
if(self.spawnflags & CHANGELEVEL_NO_INTERMISSION && deathmatch == 0) {
go_to_next_map();
return;
}
self.touch = sub_null;
// we can't move people right now, because touch functions are called
// in the middle of C movement code, so set a think time to do it
self.think = execute_changelevel;
self.nextthink = time + 0.1;
};
void() set_challenge_reject = {
if(changelevel_challenge == CHALLENGE_ACTIVE) {
changelevel_challenge = CHALLENGE_REJECTED;
challenge_rejecter = self.netname;
}
};
void() changelevel_think = {
entity pl;
if(changelevel_challenge == CHALLENGE_REJECTED) {
pl = find(world, classname, "player");
while(pl != world) {
print_center(pl, "The travel was canceled by\n", challenge_rejecter);
pl = find(pl, classname, "player");
}
changelevel_challenge = CHALLENGE_NONE;
self.netname = string_null;
self.aflag = 0;
return;
}
if(self.aflag == 0) {
changelevel_finish();
return;
}
pl = find(world, classname, "player");
while(pl != world) {
print_center(pl,
self.netname,
"\ninitiated travel to\n",
self.map, "\n\n",
ftos(self.aflag), " seconds to travel");
pl = find(pl, classname, "player");
}
sound(self, CHAN_VOICE, "misc/talk.wav", 1, ATTN_NONE);
self.aflag--;
self.nextthink = time + 1;
};
void() changelevel_touch = {
entity pos;
if(other.classname != "player" || changelevel_challenge) {
return;
}
if(cvar("noexit") == 1 || (cvar("noexit") == 2 && mapname != "start")) {
ent_damage(other, self, self, 50000);
return;
}
if(sc_challenge) {
changelevel_challenge = CHALLENGE_ACTIVE;
self.netname = other.netname;
self.aflag = 10;
self.think = changelevel_think;
self.nextthink = time + 0.1;
} else {
if(coop || deathmatch) {
print_all(other.netname, " exited the level\n");
}
changelevel_finish();
}
};
/*QUAKED trigger_changelevel(0.5 0.5 0.5) ? NO_INTERMISSION
When the player touches this, they get sent to the map listed in the "map" variable. Unless the NO_INTERMISSION flag is set, the view will go to the info_intermission spot and display stats.
*/
void() trigger_changelevel = {
if(!self.map) {
error_obj("changelevel trigger doesn't have map");
}
init_trigger();
self.touch = changelevel_touch;
};
/*
=============================================================================
PLAYER GAME EDGE FUNCTIONS
=============================================================================
*/
void() become_spectator = {
float not_dead;
entity pl;
self.spectating = (self.lives ? SPECTATING_SPECTATING : SPECTATING_DEAD);
self.health = self.max_health;
self.armortype = 0;
self.armorvalue = 0;
self.items = 0;
self.weapon = 0;
self.ammo_shells = 0;
self.ammo_nails = 0;
self.ammo_rockets = 0;
self.ammo_cells = 0;
self.takedamage = DAMAGE_NO;
self.solid = SOLID_NOT;
self.movetype = MOVETYPE_NOCLIP;
self.flags |= FL_NOTARGET;
self.view_ofs = VEC_ORIGIN;
self.frame = 0;
self.modelindex = modelindex_eyes;
wep_set_current_ammo();
pl = find(world, classname, "player");
while(pl != world) {
not_dead += pl.lives;
pl = find(pl, classname, "player");
}
if(!not_dead) {
all_players_are_dead = time;
}
};
void() respawn = {
if(coop) {
// make a copy of the dead body for appearances sake
copy_to_body_queue(self);
// get the spawn parms as they were at level start
set_spawn_parms(self);
// respawn
player_respawned = TRUE;
PutClientInServer();
} else if(deathmatch) {
// make a copy of the dead body for appearances sake
copy_to_body_queue(self);
// set default spawn parms
SetNewParms();
// respawn
player_respawned = TRUE;
PutClientInServer();
} else {
// restart the map
cmd_server("restart\n");
}
};
float(vector v) check_spawn_point = {
return FALSE;
};
/*
============
select_spawn_point
Returns the entity to spawn at
============
*/
entity() select_spawn_point = {
entity spot;
entity thing;
float pcount;
// testinfo_player_start is only found in regioned levels
spot = find(world, classname, "testplayerstart");
if(spot) {
return spot;
}
// choose a info_player_deathmatch point
if(coop) {
lastspawn = find(lastspawn, classname, "info_player_coop");
if(lastspawn == world) {
lastspawn = find(lastspawn, classname, "info_player_start");
}
if(lastspawn != world) {
return lastspawn;
}
} else if(deathmatch) {
spot = lastspawn;
while(1) {
spot = find(spot, classname, "info_player_deathmatch");
if(spot != world) {
if(spot == lastspawn) {
return lastspawn;
}
pcount = 0;
thing = find_radius(spot.origin, 32);
while(thing) {
if(thing.classname == "player") {
pcount++;
}
thing = thing.chain;
}
if(pcount == 0) {
lastspawn = spot;
return spot;
}
}
}
}
if(serverflags) {
// return with a rune to start
spot = find(world, classname, "info_player_start2");
if(spot) {
return spot;
}
}
spot = find(world, classname, "info_player_start");
if(!spot) {
error("select_spawn_point: no info_player_start on level");
}
return spot;
};
/*
===========
PutClientInServer
called each time a player is spawned
============
*/
void() PutClientInServer = {
entity spot;
float respawned;
respawned = player_respawned;
player_respawned = FALSE;
if(sc_lives) {
if(respawned) {
self.lives--;
print_all(self.netname, " has ");
if(self.lives == 0) {
print_all("run out of lives...\n");
become_spectator();
return;
} else if(self.lives == 1) {
print_all("one life left!\n");
} else {
print_all(ftos(self.lives), " lives left\n");
}
} else if(self.lives == 0) {
self.lives = sc_lives;
print_dbg("lives reset to ", ftos(sc_lives), "\n");
}
} else {
self.lives = 1;
}
spot = select_spawn_point();
self.classname = "player";
self.health = 100;
self.takedamage = DAMAGE_AIM;
self.solid = SOLID_SLIDEBOX;
self.movetype = MOVETYPE_WALK;
self.show_hostile = 0;
self.max_health = 100;
self.flags = FL_CLIENT;
self.air_finished = time + 12;
self.dmg = 2; // initial water damage
self.super_damage_finished = 0;
self.radsuit_finished = 0;
self.invisible_finished = 0;
self.invincible_finished = 0;
self.effects = 0;
self.invincible_time = 0;
self.spectating = SPECTATING_NOT;
decode_level_parms();
wep_set_current_ammo();
self.attack_finished = time;
self.th_pain = player_pain;
self.th_die = player_die;
self.deadflag = DEAD_NO;
// pausetime is set by teleporters to keep the player from moving for a bit
self.pausetime = 0;
self.origin = spot.origin + '0 0 1';
self.oldorigin = self.origin;
self.angles = spot.angles;
self.fixangle = TRUE; // turn this way immediately
// oh, this is a hack!
set_model(self, "progs/eyes.mdl");
modelindex_eyes = self.modelindex;
set_model(self, "progs/player.mdl");
modelindex_player = self.modelindex;
set_size(self, '-16 -16 -24', '16 16 32');
self.view_ofs = '0 0 22';
self.velocity = VEC_ORIGIN;
player_stand1();
if(deathmatch || coop) {
make_vectors(self.angles);
spawn_tfog(self.origin + v_forward * 20);
}
spawn_tdeath(self.origin, self);
};
/*
===============================================================================
RULES
===============================================================================
*/
/*
go to the next level for deathmatch
only called if a time or frag limit has expired
*/
void() next_level = {
entity o;
if(mapname == "start") {
if(!cvar("registered")) {
mapname = "e1m1";
} else if(!(serverflags & 1)) {
mapname = "e1m1";
serverflags = serverflags | 1;
} else if(!(serverflags & 2)) {
mapname = "e2m1";
serverflags = serverflags | 2;
} else if(!(serverflags & 4)) {
mapname = "e3m1";
serverflags = serverflags | 4;
} else if(!(serverflags & 8)) {
mapname = "e4m1";
serverflags = serverflags - 7;
}
o = spawn();
o.map = mapname;
} else {
// find a trigger changelevel
o = find(world, classname, "trigger_changelevel");
// go back to start if no trigger_changelevel
if(!o) {
mapname = "start";
o = spawn();
o.map = mapname;
}
}
nextmap = o.map;
gameover = TRUE;
if(o.nextthink < time) {
o.think = execute_changelevel;
o.nextthink = time + 0.1;
}
};
/*
============
check_rules
Exit deathmatch games upon conditions
============
*/
void() check_rules = {
float timelimit, fraglimit;
if(gameover) { // someone else quit the game already
return;
}
timelimit = cvar("timelimit") * 60;
fraglimit = cvar("fraglimit");
if((timelimit && time >= timelimit) ||
(fraglimit && self.frags >= fraglimit)) {
next_level();
return;
}
};
//============================================================================
void() reset_death_vel = {
float forward;
if(self.flags & FL_ONGROUND) {
forward = vec_len(self.velocity);
forward = forward - 20;
if(forward <= 0) {
self.velocity = VEC_ORIGIN;
} else {
self.velocity = forward * normalize(self.velocity);
}
}
};
void() player_death_think = {
reset_death_vel();
// wait for all buttons released
if(self.deadflag == DEAD_DEAD) {
if(self.button2 || self.button1 || self.button0) {
return;
}
self.deadflag = DEAD_RESPAWNABLE;
return;
}
// wait for any button down
if(!self.button2 && !self.button1 && !self.button0) {
return;
}
self.button0 = 0;
self.button1 = 0;
self.button2 = 0;
respawn();
};
void() player_jump = {
vector start, end;
if(self.flags & FL_WATERJUMP) {
return;
}
if(self.waterlevel >= 2) {
if(self.watertype == CONTENT_WATER) {
self.velocity_z = 100;
} else if(self.watertype == CONTENT_SLIME) {
self.velocity_z = 80;
} else {
self.velocity_z = 50;
}
// play swiming sound
if(self.swim_flag < time) {
self.swim_flag = time + 1;
if(random() < 0.5) {
sound(self, CHAN_BODY, "misc/water1.wav", 1, ATTN_NORM);
} else {
sound(self, CHAN_BODY, "misc/water2.wav", 1, ATTN_NORM);
}
}
return;
}
if(!(self.flags & FL_ONGROUND) || !(self.flags & FL_JUMPRELEASED)) {
return; // don't pogo stick
}
self.flags -= (self.flags & FL_JUMPRELEASED);
self.flags -= FL_ONGROUND; // don't stairwalk
self.button2 = 0;
// player jumping sound
sound(self, CHAN_BODY, "player/plyrjmp8.wav", 1, ATTN_NORM);
self.velocity_z = self.velocity_z + 270;
};
/*
===========
water_move
============
*/
void() water_move = {
string water_snd;
if(self.movetype == MOVETYPE_NOCLIP || self.health < 0) {
return;
}
if(self.waterlevel != 3) {
if(self.air_finished < time) {
sound(self, CHAN_VOICE, "player/gasp2.wav", 1, ATTN_NORM);
} else if(self.air_finished < time + 9) {
sound(self, CHAN_VOICE, "player/gasp1.wav", 1, ATTN_NORM);
}
self.air_finished = time + 12;
self.dmg = 2;
} else if(self.air_finished < time) {
// drown!
if(self.pain_finished < time) {
self.dmg = self.dmg + 2;
if(self.dmg > 15) {
self.dmg = 10;
}
ent_damage(self, world, world, self.dmg);
self.pain_finished = time + 1;
}
}
if(!self.waterlevel) {
if(self.flags & FL_INWATER) {
// play leave water sound
sound(self, CHAN_BODY, "misc/outwater.wav", 1, ATTN_NORM);
self.flags = self.flags - FL_INWATER;
}
return;
}
switch(self.watertype) {
case CONTENT_LAVA:
if(self.dmgtime < time) {
if(self.radsuit_finished > time) {
self.dmgtime = time + 1;
} else {
self.dmgtime = time + 0.2;
}
ent_damage(self, world, world, 10 * self.waterlevel);
}
break;
case CONTENT_SLIME:
if(self.dmgtime < time && self.radsuit_finished < time) {
self.dmgtime = time + 1;
ent_damage(self, world, world, 4 * self.waterlevel);
}
break;
}
if(!(self.flags & FL_INWATER)) {
// player enter water sound
switch(self.watertype) {
case CONTENT_LAVA: water_snd = "player/inlava.wav"; break;
case CONTENT_WATER: water_snd = "player/inh2o.wav"; break;
case CONTENT_SLIME: water_snd = "player/slimbrn2.wav"; break;
}
sound(self, CHAN_BODY, water_snd, 1, ATTN_NORM);
self.flags = self.flags + FL_INWATER;
self.dmgtime = 0;
}
if(!(self.flags & FL_WATERJUMP)) {
self.velocity -= 0.8 * self.waterlevel * frametime * self.velocity;
}
};
void() check_water_jump = {
vector start, end;
// check for a jump-out-of-water
make_vectors(self.angles);
start = self.origin;
start_z = start_z + 8;
v_forward_z = 0;
normalize(v_forward);
end = start + v_forward * 24;
trace_line(start, end, TRUE, self);
if(trace_fraction < 1) {
// solid at waist
start_z = start_z + self.maxs_z - 8;
end = start + v_forward * 24;
self.movedir = trace_plane_normal * -50;
trace_line(start, end, TRUE, self);
if(trace_fraction == 1) {
// open at eye level
self.flags = self.flags | FL_WATERJUMP;
self.velocity_z = 225;
self.flags = self.flags - (self.flags & FL_JUMPRELEASED);
self.teleport_time = time + 2; // safety net
return;
}
}
};
/*
================
PlayerPreThink
Called every frame before physics are run
================
*/
void() PlayerPreThink = {
// otherwise a button could be missed between the think tics
if(intermission_running) {
intermission_think();
return;
} else if(self.spectating) {
return;
}
check_rules();
water_move();
if(self.waterlevel == 2) {
check_water_jump();
}
if(self.deadflag >= DEAD_DEAD) {
player_death_think();
return;
}
if(self.deadflag == DEAD_DYING) {
return; // dying, so do nothing
}
if(self.button2) {
player_jump();
} else {
self.flags = self.flags | FL_JUMPRELEASED;
}
// teleporters can force a non-moving pause time
if(time < self.pausetime) {
self.velocity = VEC_ORIGIN;
}
if(time > self.attack_finished && self.currentammo == 0 && self.weapon != IT_AXE) {
self.weapon = wep_best_weapon();
wep_set_current_ammo();
}
};
/*
================
check_powerups
Check for turning off powerups
================
*/
void() check_powerups = {
if(self.health <= 0 || self.spectating) {
return;
}
// invisibility
if(self.invisible_finished) {
// sound and screen flash when items starts to run out
if(self.invisible_sound < time) {
sound(self, CHAN_AUTO, "items/inv3.wav", 0.5, ATTN_IDLE);
self.invisible_sound = time + random() * 3 + 1;
}
if(self.invisible_finished < time + 3) {
if(self.invisible_time == 1) {
print_cl(self, "Ring of Shadows magic is fading\n");
cmd_client(self, "bf\n");
sound(self, CHAN_AUTO, "items/inv2.wav", 1, ATTN_NORM);
self.invisible_time = time + 1;
}
if(self.invisible_time < time) {
self.invisible_time = time + 1;
cmd_client(self, "bf\n");
}
}
if(self.invisible_finished < time) {
// just stopped
self.items = self.items - IT_INVISIBILITY;
self.invisible_finished = 0;
self.invisible_time = 0;
}
// use the eyes
self.frame = 0;
self.modelindex = modelindex_eyes;
} else {
self.modelindex = modelindex_player; // don't use eyes
}
// invincibility
if(self.invincible_finished) {
// sound and screen flash when items starts to run out
if(self.invincible_finished < time + 3) {
if(self.invincible_time == 1) {
print_cl(self, "Protection is almost burned out\n");
cmd_client(self, "bf\n");
sound(self, CHAN_AUTO, "items/protect2.wav", 1, ATTN_NORM);
self.invincible_time = time + 1;
}
if(self.invincible_time < time) {
self.invincible_time = time + 1;
cmd_client(self, "bf\n");
}
}
if(self.invincible_finished < time) {
// just stopped
self.items = self.items - IT_INVULNERABILITY;
self.invincible_time = 0;
self.invincible_finished = 0;
}
if(self.invincible_finished > time) {
self.effects = self.effects | EF_DIMLIGHT;
} else {
self.effects = self.effects - (self.effects & EF_DIMLIGHT);
}
}
// super damage
if(self.super_damage_finished) {
// sound and screen flash when items starts to run out
if(self.super_damage_finished < time + 3) {
if(self.super_time == 1) {
print_cl(self, "Quad Damage is wearing off\n");
cmd_client(self, "bf\n");
sound(self, CHAN_AUTO, "items/damage2.wav", 1, ATTN_NORM);
self.super_time = time + 1;
}
if(self.super_time < time) {
self.super_time = time + 1;
cmd_client(self, "bf\n");
}
}
if(self.super_damage_finished < time) {
// just stopped
self.items = self.items - IT_QUAD;
self.super_damage_finished = 0;
self.super_time = 0;
}
if(self.super_damage_finished > time) {
self.effects = self.effects | EF_DIMLIGHT;
} else {
self.effects = self.effects - (self.effects & EF_DIMLIGHT);
}
}
// suit
if(self.radsuit_finished) {
self.air_finished = time + 12; // don't drown
// sound and screen flash when items starts to run out
if(self.radsuit_finished < time + 3) {
if(self.rad_time == 1) {
print_cl(self, "Air supply in Biosuit expiring\n");
cmd_client(self, "bf\n");
sound(self, CHAN_AUTO, "items/suit2.wav", 1, ATTN_NORM);
self.rad_time = time + 1;
}
if(self.rad_time < time) {
self.rad_time = time + 1;
cmd_client(self, "bf\n");
}
}
if(self.radsuit_finished < time) {
// just stopped
self.items = self.items - IT_SUIT;
self.rad_time = 0;
self.radsuit_finished = 0;
}
}
};
/*
================
PlayerPostThink
Called every frame after physics are run
================
*/
void() PlayerPostThink = {
if(time >= self.attack_finished && self.impulse) {
impulse_commands();
}
if(self.spectating || self.deadflag) {
return;
}
// do weapon stuff
if(time >= self.attack_finished) {
wep_weapon_frame();
}
// check to see if player landed and play landing sound
if(self.jump_flag < -300 && self.flags & FL_ONGROUND && self.health > 0) {
if(self.watertype == CONTENT_WATER) {
sound(self, CHAN_BODY, "player/h2ojump.wav", 1, ATTN_NORM);
} else if(self.jump_flag < -650) {
ent_damage(self, world, world, 5);
sound(self, CHAN_VOICE, "player/land2.wav", 1, ATTN_NORM);
self.deathtype = "falling";
} else {
sound(self, CHAN_VOICE, "player/land.wav", 1, ATTN_NORM);
}
self.jump_flag = 0;
}
if(!(self.flags & FL_ONGROUND)) {
self.jump_flag = self.velocity_z;
}
check_powerups();
};
/*
===========
ClientConnect
called when a player connects to a server
============
*/
void() ClientConnect = {
print_all(self.netname, " entered the game\n");
// a client connecting during an intermission can cause problems
if(intermission_running) {
intermission_exit();
}
};
/*
===========
ClientDisconnect
called when a player disconnects from a server
============
*/
void() ClientDisconnect = {
// if the level end trigger has been activated, just return
// since they aren't *really* leaving
if(gameover) {
return;
}
// let everyone else know
print_all(self.netname, " left the game with ", ftos(self.frags), " frags\n");
if(!self.spectating) {
sound(self, CHAN_BODY, "player/tornoff2.wav", 1, ATTN_NONE);
set_suicide_frame();
}
};
void() cheat = {
if(((deathmatch || coop) && !sc_cheats) || self.spectating) {
return;
}
self.ammo_cells = AMMAX_CELLS;
self.ammo_nails = AMMAX_NAILS;
self.ammo_rockets = AMMAX_ROCKETS;
self.ammo_shells = AMMAX_SHELLS;
self.items |= IT_AXE |
IT_SHOTGUN |
IT_SUPER_SHOTGUN |
IT_NAILGUN |
IT_SUPER_NAILGUN |
IT_GRENADE_LAUNCHER |
IT_ROCKET_LAUNCHER |
IT_LIGHTNING |
IT_KEY1 | IT_KEY2;
self.weapon = IT_ROCKET_LAUNCHER;
wep_set_current_ammo();
};
void() cheat_quad = {
if(((deathmatch || coop) && !sc_cheats) || self.spectating) {
return;
}
self.super_time = 1;
self.super_damage_finished = time + 30;
self.items = self.items | IT_QUAD;
};
void(float pro) change_pronoun = {
pro = minmax(pro, PRO_NONE, PRO_MAX - 1);
self.pronoun = pro;
print_cl(self, "pronoun set to ",
pronoun_subject(pro), "/",
pronoun_possessive(pro), "\n");
};
void() spectate = {
switch(self.spectating) {
case SPECTATING_NOT:
print_all(self.netname, " has become a spectator\n");
become_spectator();
break;
case SPECTATING_SPECTATING:
print_all(self.netname, " has returned from spectating\n");
set_spawn_parms(self);
PutClientInServer();
break;
case SPECTATING_DEAD:
print_center(self,
"You have no life force left\n"
"and cannot return to\n"
"the mortal world yet");
break;
case SPECTATING_INTERMISSION:
case SPECTATING_FINALE:
print_center(self,
"You are incorporeal as you wait\n"
"for the next cycle\n"
"and cannot return to\n"
"the mortal world yet");
break;
}
};
void() impulse_commands = {
if(self.impulse >= 1 && self.impulse <= 8) {
wep_change_weapon(self.impulse);
} else if(self.impulse >= 20 && self.impulse < 40) {
change_pronoun(self.impulse - 20);
} else {
switch(self.impulse) {
case 9: cheat(); break;
case 10: wep_cycle_weapon(); break;
case 11: cheat_quad(); break;
case 12: wep_cycle_weapon_reverse(); break;
case 13: spectate(); break;
case 14: set_challenge_reject(); break;
}
}
self.impulse = 0;
};
float(entity targ, entity attacker) obit_teledeath = {
attacker.owner.frags++;
print_all(" was telefragged by ", attacker.owner.netname, "\n");
return TRUE;
};
float(entity targ, entity attacker) obit_teledeath2 = {
targ.frags--;
print_all("'s telefrag was deflected by satanic power\n");
return TRUE;
};
float(entity targ, entity attacker) obit_teledeath3 = {
targ.frags--;
attacker.owner.frags++;
print_all(" was telefragged by ",
attacker.owner.netname,
"'s satanic powers\n");
return TRUE;
};
float(entity targ, entity attacker) obit_suicide = {
targ.frags--;
if(targ.weapon == IT_LIGHTNING && targ.waterlevel > 1) {
print_all(" discharges into the water\n");
} else if(targ.weapon == IT_GRENADE_LAUNCHER) {
print_all(" tries to put the pin back in\n");
} else {
print_all(" becomes bored with ");
if(targ.pronoun != PRO_NONE) {
print_all(pronoun_possessive(targ.pronoun), " ");
}
print_all("life\n");
}
return TRUE;
};
float(entity targ, entity attacker) obit_teamkill = {
float rnum;
rnum = random();
attacker.frags--;
if(rnum < 0.25) {
print_all(" mows down a teammate\n");
} else if(rnum < 0.50) {
if(attacker.pronoun == PRO_NONE) {
print_all(" needs new glasses\n");
} else {
print_all(" checks ",
pronoun_possessive(attacker.pronoun),
" glasses\n");
}
} else if(rnum < 0.75) {
print_all(" gets a frag for the other team\n");
} else {
print_all(" loses another friend\n");
}
return TRUE;
};
float(entity targ, entity attacker) obit_pkill = {
string deathstring, deathstring2;
attacker.frags++;
switch(attacker.weapon) {
case IT_AXE:
deathstring = " was ax-murdered by ";
deathstring2 = "\n";
break;
case IT_SHOTGUN:
deathstring = " chewed on ";
deathstring2 = "'s boomstick\n";
break;
case IT_SUPER_SHOTGUN:
deathstring = " ate 2 loads of ";
deathstring2 = "'s buckshot\n";
break;
case IT_NAILGUN:
deathstring = " was nailed by ";
deathstring2 = "\n";
break;
case IT_SUPER_NAILGUN:
deathstring = " was punctured by ";
deathstring2 = "\n";
break;
case IT_GRENADE_LAUNCHER:
deathstring = " eats ";
deathstring2 = "'s pineapple\n";
if(targ.health < -40) {
deathstring = " was gibbed by ";
deathstring2 = "'s grenade\n";
}
break;
case IT_ROCKET_LAUNCHER:
deathstring = " rides ";
deathstring2 = "'s rocket\n";
if(targ.health < -40) {
deathstring = " was gibbed by ";
deathstring2 = "'s rocket\n" ;
}
break;
case IT_LIGHTNING:
deathstring = " accepts ";
if(attacker.waterlevel > 1) {
deathstring2 = "'s discharge\n";
} else {
deathstring2 = "'s hot lightning injection\n";
}
break;
}
print_all(targ.netname, deathstring, attacker.netname, deathstring2);
return TRUE;
};
float(entity targ, entity attacker) obit_monster = {
switch(attacker.classname) {
case "monster_army":
if(random() < 0.5) {
print_all(" was shot by a Grunt\n");
} else {
print_all(" was blasted by a Grunt\n");
}
break;
case "monster_demon1":
if(targ.pronoun == PRO_NONE) {
print_all(" had a Fiend lobotomy\n");
} else {
print_all(" had ",
pronoun_possessive(targ.pronoun),
" head ripped off by a Fiend\n");
}
break;
case "monster_dog":
if(random() < 0.5) {
print_all(" was eaten by a Rottweiler\n");
} else {
print_all(" was mauled by a Rottweiler\n");
}
break;
case "monster_enforcer":
if(random() < 0.5) {
print_all(" was lazed by an Enforcer\n");
} else {
print_all(" stood in an Enforcer's way\n");
}
break;
case "monster_fish":
if(targ.pronoun == PRO_NONE || random() < 0.5) {
print_all(" was fed to a Rotfish\n");
} else {
print_all(" enjoys ",
pronoun_possessive(targ.pronoun),
" new life under the sea\n");
}
break;
case "monster_hell_knight":
if(random() < 0.5) {
print_all(" was killed to death by a Death Knight\n");
} else {
print_all(" was slain by a Death Knight\n");
}
break;
case "monster_knight":
if(random() < 0.1) {
print_all(" was enamored by the Knight's intricate animations\n");
} else {
print_all(" was slashed by a Knight\n");
}
break;
case "monster_ogre":
if(random() < 0.05) {
print_all(" knows that it's all Ogre now\n");
} else {
print_all(" was destroyed by an Ogre\n");
}
break;
case "monster_oldone":
if(targ.pronoun == PRO_NONE) {
print_all(" became one with Shub-Niggurath\n");
} else {
print_all(" accepted ", pronoun_possessive(targ.pronoun), " fate\n");
}
break;
case "monster_shalrath":
if(random() < 0.5) {
print_all(" was merged with a Shalrath\n");
} else {
print_all(" couldn't evade the Vore\n");
}
break;
case "monster_shambler":
if(random() < 0.5) {
print_all(" was Shambled off this mortal coil\n");
} else {
print_all(" was fried by a Shambler\n");
}
break;
case "monster_tarbaby":
if(random() < 0.5) {
print_all(" was consumed by the Spawn\n");
} else {
print_all(" found ",
pronoun_possessive(targ.pronoun),
" place with the Spawn\n");
}
break;
case "monster_wizard":
if(random() < 0.5) {
print_all(" wasn't ready for the Wizard\n");
} else {
print_all(" was scragged by a Scrag\n");
}
break;
case "monster_zombie":
if(random() < 0.05) {
print_all(". You are the demons\nAnd then ",
targ.netname, " was a zombie.");
} else {
print_all(" joins the Zombies\n");
}
break;
default:
return FALSE;
}
return TRUE;
};
float(entity targ, entity attacker) obit_falling = {
if(targ.deathtype == "falling") {
targ.deathtype = string_null;
if(targ.pronoun == PRO_NONE) {
print_all(" hit the ground too hard\n");
} else {
print_all(" fell to ", pronoun_possessive(targ.pronoun), " death\n");
}
return TRUE;
} else {
return FALSE;
}
}
float(entity targ, entity attacker) obit_water = {
switch(targ.watertype) {
case CONTENT_SKY:
print_all(" tried to buy the sky and sell the sky\n");
break;
case CONTENT_WATER:
if(random() < 0.5) {
print_all(" sleeps with the fishes\n");
} else {
print_all(" was quite thirsty\n");
}
break;
case CONTENT_SLIME:
if(random() < 0.5) {
print_all(" gulped a load of slime\n");
} else {
print_all(" can't exist on slime alone\n");
}
break;
case CONTENT_LAVA:
if(targ.health < -15) {
print_all(" burst into flames\n");
} else if(random() < 0.5) {
print_all(" turned into hot slag\n");
} else {
print_all(" visits the Volcano God\n");
}
break;
default:
return FALSE;
}
return TRUE;
};
float(entity targ, entity attacker) obit_trap = {
switch(attacker.classname) {
case "explo_box":
print_all(" blew up\n"); break;
case "trap_shooter":
case "trap_spikeshooter":
print_all(" was spiked\n"); break;
case "fireball":
print_all(" ate a lavaball\n"); break;
case "trigger_changelevel":
if(targ.pronoun == PRO_NONE) {
print_all(" tried to leave\n");
} else {
print_all(" tried to leave, but ",
pronoun_subject(targ.pronoun),
" failed\n");
}
break;
default:
return FALSE;
}
return TRUE;
};
float(entity targ, entity attacker) obit_worldkill = {
targ.frags--;
if(attacker.flags & FL_MONSTER) {
return obit_monster(targ, attacker);
} else if(attacker.solid == SOLID_BSP && attacker != world) {
print_all(" was squished\n");
return TRUE;
} else {
return obit_falling(targ, attacker) ||
obit_water(targ, attacker) ||
obit_trap(targ, attacker);
}
};
/*
===========
client_obituary
called when a player dies
============
*/
void(entity targ, entity attacker) client_obituary = {
float did_message;
if(targ.classname != "player") {
return;
}
print_all(targ.netname);
switch(attacker.classname) {
case "teledeath":
did_message = obit_teledeath(targ, attacker);
break;
case "teledeath2":
did_message = obit_teledeath2(targ, attacker);
break;
case "teledeath3":
did_message = obit_teledeath3(targ, attacker);
break;
case "player":
if(targ == attacker) {
did_message = obit_suicide(targ, attacker);
} else if(teamplay == 2 && is_same_team(targ, attacker)) {
did_message = obit_teamkill(targ, attacker);
} else {
did_message = obit_pkill(targ, attacker);
}
break;
default:
did_message = obit_worldkill(targ, attacker);
break;
}
if(!did_message) {
// hell if I know; they're just dead!!!
print_all(" died\n");
}
};
/*
============
ClientKill
Player entered the suicide command
============
*/
void() ClientKill = {
if(!self.spectating) {
reset_death_vel();
self.frags--; // extra penalty
client_obituary(self, self);
set_suicide_frame();
self.modelindex = modelindex_player;
respawn();
}
};