2020-04-13 18:12:09 -07:00
|
|
|
/*
|
2022-03-11 11:40:43 -08:00
|
|
|
* Copyright (c) 2016-2020 Marco Cawthorne <marco@icculus.org>
|
2020-04-13 18:12:09 -07:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2022-04-19 21:58:13 -07:00
|
|
|
var bool autocvar_sv_friendlyFire = false;
|
|
|
|
|
2020-04-13 18:12:09 -07:00
|
|
|
/* init */
|
|
|
|
void
|
2020-04-14 07:19:25 -07:00
|
|
|
CGameRules::InitPostEnts(void)
|
2020-04-13 18:12:09 -07:00
|
|
|
{
|
|
|
|
//print("Init!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* logic */
|
|
|
|
void
|
|
|
|
CGameRules::FrameStart(void)
|
|
|
|
{
|
|
|
|
//print("StartFrame!\n");
|
|
|
|
}
|
|
|
|
float
|
2020-05-02 20:26:06 -07:00
|
|
|
CGameRules::ConsoleCommand(base_player pl, string cmd)
|
2020-04-13 18:12:09 -07:00
|
|
|
{
|
2021-05-10 02:33:31 -07:00
|
|
|
return (0);
|
2020-04-13 18:12:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* client */
|
|
|
|
void
|
2020-10-30 03:28:59 -07:00
|
|
|
CGameRules::PlayerConnect(base_player pl)
|
2020-04-13 18:12:09 -07:00
|
|
|
{
|
|
|
|
//print("ClientConnect!\n");
|
|
|
|
}
|
|
|
|
void
|
2020-10-30 03:28:59 -07:00
|
|
|
CGameRules::PlayerDisconnect(base_player pl)
|
2020-04-13 18:12:09 -07:00
|
|
|
{
|
|
|
|
//print("ClientDisconnect!\n");
|
|
|
|
}
|
|
|
|
void
|
2020-05-02 20:26:06 -07:00
|
|
|
CGameRules::PlayerKill(base_player pl)
|
2020-04-20 10:25:15 -07:00
|
|
|
{
|
|
|
|
//print("PlayerKill!\n");
|
|
|
|
}
|
|
|
|
void
|
2020-05-02 20:26:06 -07:00
|
|
|
CGameRules::PlayerDeath(base_player pl)
|
2020-04-20 10:25:15 -07:00
|
|
|
{
|
|
|
|
//print("PlayerDeath!\n");
|
2022-03-02 09:14:58 -08:00
|
|
|
pl.Death();
|
2020-04-20 10:25:15 -07:00
|
|
|
}
|
|
|
|
void
|
2020-05-02 20:26:06 -07:00
|
|
|
CGameRules::PlayerPain(base_player pl)
|
2020-04-13 18:12:09 -07:00
|
|
|
{
|
|
|
|
//print("ClientKill!\n");
|
2022-03-02 09:14:58 -08:00
|
|
|
pl.Pain();
|
2020-04-13 18:12:09 -07:00
|
|
|
}
|
|
|
|
void
|
2020-05-02 20:26:06 -07:00
|
|
|
CGameRules::PlayerSpawn(base_player pl)
|
2020-04-13 18:12:09 -07:00
|
|
|
{
|
|
|
|
//print("PutClientInServer!\n");
|
|
|
|
}
|
|
|
|
void
|
2020-05-02 20:26:06 -07:00
|
|
|
CGameRules::PlayerPreFrame(base_player pl)
|
2020-04-13 18:12:09 -07:00
|
|
|
{
|
|
|
|
//print("PlayerPreThink!\n");
|
|
|
|
}
|
|
|
|
void
|
2020-05-02 20:26:06 -07:00
|
|
|
CGameRules::PlayerPostFrame(base_player pl)
|
2020-04-13 18:12:09 -07:00
|
|
|
{
|
|
|
|
//print("PlayerPostThink!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* level transitions */
|
|
|
|
void
|
|
|
|
CGameRules::LevelNewParms(void)
|
|
|
|
{
|
|
|
|
//print("LevelNewParms!\n");
|
|
|
|
}
|
|
|
|
void
|
2020-05-02 20:26:06 -07:00
|
|
|
CGameRules::LevelChangeParms(base_player pl)
|
2020-04-13 18:12:09 -07:00
|
|
|
{
|
|
|
|
//print("LevelChangeParms!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* spectator */
|
|
|
|
/*void
|
|
|
|
CGameRules::SpectatorConnect(player pl)
|
|
|
|
{
|
|
|
|
//print("SpectatorConnect!\n");
|
|
|
|
}
|
|
|
|
void
|
|
|
|
CGameRules::SpectatorDisconnect(player pl)
|
|
|
|
{
|
|
|
|
//print("SpectatorDisconnect!\n");
|
|
|
|
}
|
|
|
|
void
|
|
|
|
CGameRules::SpectatorThink(player pl)
|
|
|
|
{
|
|
|
|
//print("SpectatorThink!\n");
|
|
|
|
}*/
|
|
|
|
|
2020-04-23 12:02:38 -07:00
|
|
|
int
|
2020-04-23 20:37:54 -07:00
|
|
|
CGameRules::MaxItemPerSlot(int slot)
|
2020-04-23 12:02:38 -07:00
|
|
|
{
|
2021-09-16 12:16:37 -07:00
|
|
|
return (-1);
|
2020-04-23 12:02:38 -07:00
|
|
|
}
|
|
|
|
|
2020-04-26 04:17:19 -07:00
|
|
|
void
|
|
|
|
CGameRules::IntermissionStart(void)
|
|
|
|
{
|
|
|
|
if (m_iIntermission)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_iIntermission = TRUE;
|
|
|
|
m_flIntermissionTime = time + 5.0f;
|
2020-09-04 12:28:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CGameRules::IntermissionCycle(void)
|
|
|
|
{
|
2021-10-19 16:18:36 -07:00
|
|
|
static NSEntity cam;
|
|
|
|
NSEntity targ;
|
2020-09-04 12:28:06 -07:00
|
|
|
|
|
|
|
if (!m_iIntermission)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (time < m_flIntermissionCycle)
|
|
|
|
return;
|
2020-04-26 04:17:19 -07:00
|
|
|
|
|
|
|
/* make the clients aware */
|
|
|
|
WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET);
|
|
|
|
WriteByte(MSG_MULTICAST, EV_INTERMISSION);
|
2020-09-04 12:28:06 -07:00
|
|
|
|
2021-10-19 16:18:36 -07:00
|
|
|
cam = (NSEntity)find(cam, ::classname, "info_intermission");
|
2020-09-04 12:28:06 -07:00
|
|
|
|
|
|
|
if (cam) {
|
2021-10-19 16:18:36 -07:00
|
|
|
targ = (NSEntity)find(world, ::targetname, cam.target);
|
2020-09-04 12:28:06 -07:00
|
|
|
|
|
|
|
if (targ) {
|
|
|
|
vector foo;
|
|
|
|
foo = vectoangles(targ.origin - cam.origin);
|
|
|
|
|
|
|
|
WriteByte(MSG_MULTICAST, 1);
|
|
|
|
WriteFloat(MSG_MULTICAST, foo[0]);
|
|
|
|
WriteFloat(MSG_MULTICAST, foo[1]);
|
|
|
|
WriteFloat(MSG_MULTICAST, foo[2]);
|
|
|
|
WriteCoord(MSG_MULTICAST, cam.origin[0]);
|
|
|
|
WriteCoord(MSG_MULTICAST, cam.origin[1]);
|
|
|
|
WriteCoord(MSG_MULTICAST, cam.origin[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (entity pl = world; (pl = find(pl, ::classname, "player"));) {
|
|
|
|
setorigin(pl, cam.origin);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
WriteByte(MSG_MULTICAST, 0);
|
|
|
|
}
|
|
|
|
|
2020-04-26 04:17:19 -07:00
|
|
|
msg_entity = world;
|
|
|
|
multicast([0,0,0], MULTICAST_ALL);
|
2020-09-04 12:28:06 -07:00
|
|
|
|
|
|
|
if (!cam)
|
|
|
|
m_flIntermissionCycle = 0.0f;
|
|
|
|
else
|
|
|
|
m_flIntermissionCycle = time + 5.0f;
|
|
|
|
|
2020-04-26 04:17:19 -07:00
|
|
|
}
|
|
|
|
|
2022-03-29 15:20:52 -07:00
|
|
|
int
|
|
|
|
CGameRules::InIntermission(void)
|
|
|
|
{
|
|
|
|
return (m_iIntermission) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2021-09-16 12:16:37 -07:00
|
|
|
int
|
|
|
|
CGameRules::MonstersSpawn(void)
|
|
|
|
{
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
2022-03-02 09:14:58 -08:00
|
|
|
/* init */
|
|
|
|
float
|
|
|
|
CGameRules::IsTeamPlay(void)
|
|
|
|
{
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
|
2021-10-07 14:30:21 -07:00
|
|
|
void
|
|
|
|
CGameRules::DamageApply(entity t, entity c, float dmg, int w, damageType_t type)
|
|
|
|
{
|
|
|
|
/* Damage */
|
2022-04-02 09:21:49 -07:00
|
|
|
NSSurfacePropEntity eTarget = (NSSurfacePropEntity)t;
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if (t.takedamage == DAMAGE_NO)
|
|
|
|
return;
|
2021-10-07 14:30:21 -07:00
|
|
|
|
2021-12-17 20:27:36 -08:00
|
|
|
/* for armor damage */
|
2022-02-01 13:37:21 -08:00
|
|
|
float flArmor = 0;
|
|
|
|
float flNewDamage = 0;
|
2021-12-17 20:27:36 -08:00
|
|
|
|
2021-10-07 14:30:21 -07:00
|
|
|
/* player god mode */
|
2022-04-02 09:21:49 -07:00
|
|
|
if (eTarget.flags & FL_CLIENT && eTarget.flags & FL_GODMODE)
|
2021-10-07 14:30:21 -07:00
|
|
|
return;
|
|
|
|
|
2022-04-19 21:58:13 -07:00
|
|
|
/* friendly fire */
|
|
|
|
if (autocvar_sv_friendlyFire == false)
|
|
|
|
if (IsTeamPlay()) {
|
|
|
|
if (t.flags & FL_CLIENT && c.flags & FL_CLIENT)
|
|
|
|
if (t.team == c.team)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-07 14:30:21 -07:00
|
|
|
/* already dead, please avoid recursion */
|
2022-04-02 09:21:49 -07:00
|
|
|
if (eTarget.GetHealth() <= 0)
|
2021-10-07 14:30:21 -07:00
|
|
|
return;
|
|
|
|
|
2021-12-17 20:27:36 -08:00
|
|
|
/* before any calculation is done... */
|
|
|
|
g_dmg_iRealDamage = dmg;
|
|
|
|
|
2021-10-07 14:30:21 -07:00
|
|
|
/* only clients have armor */
|
2022-04-02 09:21:49 -07:00
|
|
|
if (eTarget.flags & FL_CLIENT) {
|
|
|
|
base_player tp = (base_player)t;
|
|
|
|
|
2022-04-08 12:37:45 -07:00
|
|
|
/* don't allow any damage */
|
|
|
|
if (PlayerCanAttack(tp) == false) {
|
|
|
|
g_dmg_eAttacker = c;
|
|
|
|
g_dmg_eTarget = t;
|
|
|
|
g_dmg_iDamage = 0;
|
|
|
|
g_dmg_iHitBody = 0;
|
|
|
|
g_dmg_iFlags = type;
|
|
|
|
g_dmg_iWeapon = w;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-07 14:30:21 -07:00
|
|
|
/* skip armor */
|
|
|
|
if not (type & DMG_SKIP_ARMOR)
|
|
|
|
if (tp.armor && dmg > 0) {
|
|
|
|
|
|
|
|
flNewDamage = dmg * 0.2;
|
|
|
|
flArmor = (dmg - flNewDamage) * 0.5;
|
|
|
|
|
|
|
|
if (flArmor > tp.armor) {
|
|
|
|
flArmor = tp.armor;
|
|
|
|
flArmor *= (1/0.5);
|
|
|
|
flNewDamage = dmg - flArmor;
|
|
|
|
tp.armor = 0;
|
|
|
|
} else {
|
|
|
|
tp.armor -= flArmor;
|
|
|
|
}
|
|
|
|
dmg = flNewDamage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dmg = rint(dmg);
|
2022-04-02 09:21:49 -07:00
|
|
|
eTarget.SetHealth(eTarget.GetHealth() - dmg);
|
2021-10-07 14:30:21 -07:00
|
|
|
|
|
|
|
/* the globals... */
|
|
|
|
g_dmg_eAttacker = c;
|
|
|
|
g_dmg_eTarget = t;
|
|
|
|
g_dmg_iDamage = dmg;
|
|
|
|
g_dmg_iHitBody = trace_surface_id;
|
|
|
|
g_dmg_iFlags = type;
|
|
|
|
g_dmg_iWeapon = w;
|
|
|
|
|
2021-12-17 20:27:36 -08:00
|
|
|
if (dmg > 0 || flArmor > 0) {
|
2021-12-17 18:20:30 -08:00
|
|
|
vector dmg_origin;
|
|
|
|
|
|
|
|
if (c.origin == [0,0,0])
|
|
|
|
dmg_origin = g_dmg_eTarget.origin;
|
2021-12-17 20:27:36 -08:00
|
|
|
else
|
|
|
|
dmg_origin = g_dmg_eAttacker.origin;
|
2021-12-17 18:20:30 -08:00
|
|
|
|
|
|
|
WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET);
|
|
|
|
WriteByte(MSG_MULTICAST, EV_DAMAGE);
|
|
|
|
WriteCoord(MSG_MULTICAST, dmg_origin[0]);
|
|
|
|
WriteCoord(MSG_MULTICAST, dmg_origin[1]);
|
|
|
|
WriteCoord(MSG_MULTICAST, dmg_origin[2]);
|
2021-12-17 20:27:36 -08:00
|
|
|
WriteInt(MSG_MULTICAST, g_dmg_iRealDamage);
|
2021-12-17 18:20:30 -08:00
|
|
|
WriteInt(MSG_MULTICAST, g_dmg_iFlags);
|
|
|
|
msg_entity = g_dmg_eTarget;
|
|
|
|
multicast([0,0,0], MULTICAST_ONE_R);
|
2021-10-07 14:30:21 -07:00
|
|
|
}
|
|
|
|
|
2022-04-02 09:21:49 -07:00
|
|
|
/* they died */
|
|
|
|
if (eTarget.GetHealth() <= 0) {
|
|
|
|
if (eTarget.flags & FL_CLIENT) {
|
|
|
|
PlayerDeath((player)eTarget);
|
2021-10-07 14:30:21 -07:00
|
|
|
} else {
|
2022-04-02 09:21:49 -07:00
|
|
|
eTarget.Death();
|
2021-10-07 14:30:21 -07:00
|
|
|
}
|
|
|
|
} else {
|
2022-04-02 09:21:49 -07:00
|
|
|
if (eTarget.flags & FL_CLIENT) {
|
|
|
|
PlayerPain((player)eTarget);
|
2021-10-07 14:30:21 -07:00
|
|
|
} else {
|
2022-04-02 09:21:49 -07:00
|
|
|
eTarget.Pain();
|
2021-10-07 14:30:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* checks if we can hit an entity at 5 of the same spots */
|
|
|
|
int
|
|
|
|
CGameRules::DamageCheckTrace(entity t, vector vecHitPos)
|
|
|
|
{
|
|
|
|
/* We're lazy. Who cares */
|
|
|
|
if (t.solid == SOLID_BSP) {
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
traceline(vecHitPos, t.origin, 1, self);
|
|
|
|
if (trace_fraction == 1) {
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
traceline(vecHitPos, t.origin + [15,15,0], 1, self);
|
|
|
|
if (trace_fraction == 1) {
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
traceline(vecHitPos, t.origin + [-15,-15,0], 1, self);
|
|
|
|
if (trace_fraction == 1) {
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
traceline(vecHitPos, t.origin + [-15,15,0], 1, self);
|
|
|
|
if (trace_fraction == 1) {
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
traceline(vecHitPos, t.origin + [15,-15,0], 1, self);
|
|
|
|
if (trace_fraction == 1) {
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CGameRules::DamageRadius(vector org, entity attacker, float dmg, float r, int check, int w)
|
|
|
|
{
|
|
|
|
float new_dmg;
|
|
|
|
float dist;
|
|
|
|
float diff;
|
|
|
|
vector pos;
|
|
|
|
|
|
|
|
for (entity e = world; (e = findfloat(e, ::takedamage, DAMAGE_YES));) {
|
|
|
|
pos[0] = e.absmin[0] + (0.5 * (e.absmax[0] - e.absmin[0]));
|
|
|
|
pos[1] = e.absmin[1] + (0.5 * (e.absmax[1] - e.absmin[1]));
|
|
|
|
pos[2] = e.absmin[2] + (0.5 * (e.absmax[2] - e.absmin[2]));
|
|
|
|
|
|
|
|
/* don't bother if it's not anywhere near us */
|
|
|
|
dist = vlen(org - pos);
|
|
|
|
if (dist > r)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* can we physically hit this thing? */
|
|
|
|
if (check == TRUE)
|
|
|
|
if (DamageCheckTrace(e, org) == FALSE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* calculate new damage values */
|
|
|
|
diff = (r - dist) / r;
|
|
|
|
new_dmg = rint(dmg * diff);
|
|
|
|
|
|
|
|
if (diff > 0) {
|
|
|
|
DamageApply(e, attacker, new_dmg, w, DMG_EXPLODE);
|
|
|
|
|
|
|
|
/* approximate, feel free to tweak */
|
|
|
|
if (e.movetype == MOVETYPE_WALK) {
|
|
|
|
makevectors(vectoangles(e.origin - org));
|
|
|
|
e.velocity += v_forward * (new_dmg * 5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-26 04:17:19 -07:00
|
|
|
void
|
|
|
|
CGameRules::IntermissionEnd(void)
|
|
|
|
{
|
|
|
|
if (!m_iIntermission)
|
|
|
|
return;
|
2020-09-04 12:28:06 -07:00
|
|
|
|
2020-04-26 04:17:19 -07:00
|
|
|
if (time < m_flIntermissionTime)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!(input_buttons & INPUT_BUTTON0) && !(input_buttons & INPUT_BUTTON2))
|
|
|
|
return;
|
|
|
|
|
2022-04-17 13:50:14 -07:00
|
|
|
localcmd("nextmap\n");
|
2020-04-26 04:17:19 -07:00
|
|
|
}
|
|
|
|
|
2020-04-13 18:12:09 -07:00
|
|
|
void
|
|
|
|
CGameRules::CGameRules(void)
|
|
|
|
{
|
2020-04-23 20:37:54 -07:00
|
|
|
forceinfokey(world, "teamplay", "0");
|
2020-04-13 18:12:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* our currently running mode */
|
|
|
|
CGameRules g_grMode;
|
2022-03-17 21:05:47 -07:00
|
|
|
|
|
|
|
int
|
|
|
|
Gamerules_IsTeamPlay(void)
|
|
|
|
{
|
|
|
|
return (g_grMode.IsTeamPlay()) ? TRUE : FALSE;
|
|
|
|
}
|
2022-04-08 12:37:45 -07:00
|
|
|
|
|
|
|
bool
|
|
|
|
CGameRules::PlayerCanAttack(base_player bp)
|
|
|
|
{
|
|
|
|
return true;
|
2022-04-17 13:50:14 -07:00
|
|
|
}
|