Replace CSQC_Parse_Damage with our own, add EV_DAMAGE. Make sure trigger_hurt

respects the 'damagetype' field. Add CSQC_UpdateSeat to make querying of
the current player seat easier (splitscreen).
This commit is contained in:
Marco Cawthorne 2021-12-17 18:20:30 -08:00
parent 8075616d6d
commit c2e4050bae
Signed by: eukara
GPG Key ID: C196CD8BA993248A
8 changed files with 110 additions and 30 deletions

View File

@ -17,10 +17,10 @@
/*
* engine specific callback for when dmg_ fields are set on the client side.
* might want to replace it at some point? probably not...
* hence why 'save' and 'take' are unused.
* hence why 'take' is unused.
*/
float
CSQC_Parse_Damage(float save, float take, vector abs_pos)
CSQC_Parse_Damage_New(vector abs_pos, int take, int flags)
{
int s = (float)getproperty(VF_ACTIVESEAT);
pSeat = &g_seats[s];
@ -32,6 +32,7 @@ CSQC_Parse_Damage(float save, float take, vector abs_pos)
if (abs_pos) {
pSeat->m_vecDamagePos = abs_pos;
pSeat->m_flDamageAlpha = 1.0f;
pSeat->m_iDamageFlags |= flags;
}
return (1);

View File

@ -69,6 +69,8 @@ float clframetime;
string(string modelname, int frame, float frametime) spriteframe = #0;
void CSQC_UpdateSeat(void);
void
drawstring_r(vector p, string t, vector s, vector c, float a, float f)
{
@ -133,6 +135,7 @@ struct
/* damage overlay */
float m_flDamageAlpha;
vector m_vecDamagePos;
int m_iDamageFlags;
/* +zoomin cmd */
int m_iZoomed;

View File

@ -49,7 +49,7 @@ DetailTex_Parse(string maptex, string detailtex, float xscale, float yscale)
xscale *= autocvar(r_detailtextures_xscale, 1.0, "X scale multiplier for detail tex");
yscale *= autocvar(r_detailtextures_yscale, 1.0, "Y scale multiplier for detail tex");
print(sprintf("DETAIL: %s %s %f %f\n", maptex, detailtex, xscale, yscale));
dprint(sprintf("DETAIL: %s %s %f %f\n", maptex, detailtex, xscale, yscale));
#if 1
shaderforname(strcat(maptex, "_detail"), sprintf(g_detail_shader, detailtex, xscale, yscale));

View File

@ -14,9 +14,16 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
void
CSQC_UpdateSeat(void)
{
int s = (float)getproperty(VF_ACTIVESEAT);
pSeat = &g_seats[s];
pSeatLocal = &g_seatslocal[s];
}
/* This file houses all of the callbacks and entry points the engine
calls by itself */
void
CSQC_Init(float apilevel, string enginename, float engineversion)
{
@ -445,9 +452,7 @@ Updates all our input related globals for use in other functions
float
CSQC_InputEvent(float fEventType, float fKey, float fCharacter, float fDeviceID)
{
int s = (float)getproperty(VF_ACTIVESEAT);
pSeat = &g_seats[s];
pSeatLocal = &g_seatslocal[s];
CSQC_UpdateSeat();
switch (fEventType) {
case IE_KEYDOWN:
@ -499,9 +504,7 @@ Hijacks and controls what input globals are being sent to the server
void
CSQC_Input_Frame(void)
{
int s = (float)getproperty(VF_ACTIVESEAT);
pSeat = &g_seats[s];
pSeatLocal = &g_seatslocal[s];
CSQC_UpdateSeat();
/* If we are inside a VGUI, don't let the client do stuff outside */
if (g_vguiWidgetCount > 0) {
@ -570,13 +573,22 @@ void
CSQC_Parse_Event(void)
{
/* always 0, unless it was sent with a MULTICAST_ONE or MULTICAST_ONE_R to p2+ */
int s = (float)getproperty(VF_ACTIVESEAT);
pSeat = &g_seats[s];
pSeatLocal = &g_seatslocal[s];
CSQC_UpdateSeat();
float fHeader = readbyte();
switch (fHeader) {
case EV_DAMAGE:
vector vecDmgPos;
int iDmgTake;
int iDmgFlags;
vecDmgPos[0] = readcoord();
vecDmgPos[1] = readcoord();
vecDmgPos[2] = readcoord();
iDmgTake = readint();
iDmgFlags = readint();
CSQC_Parse_Damage_New(vecDmgPos, iDmgTake, iDmgFlags);
break;
case EV_INTERMISSION:
int cam;
vector pos, ang;
@ -681,9 +693,7 @@ float
CSQC_ConsoleCommand(string sCMD)
{
/* the engine will hide the p1 etc commands... which is fun... */
int s = (float)getproperty(VF_ACTIVESEAT);
pSeat = &g_seats[s];
pSeatLocal = &g_seatslocal[s];
CSQC_UpdateSeat();
tokenize(sCMD);
@ -848,9 +858,7 @@ CSQC_ConsoleCommand(string sCMD)
void
CSQC_Parse_Print(string sMessage, float fLevel)
{
int s = (float)getproperty(VF_ACTIVESEAT);
pSeat = &g_seats[s];
pSeatLocal = &g_seatslocal[s];
CSQC_UpdateSeat();
/* This gives messages other than chat an orange tint */
if (fLevel == PRINT_CHAT) {
@ -887,9 +895,7 @@ Keep in mind that newlines need to be tokenized
float
CSQC_Parse_CenterPrint(string sMessage)
{
int s = (float)getproperty(VF_ACTIVESEAT);
pSeat = &g_seats[s];
pSeatLocal = &g_seatslocal[s];
CSQC_UpdateSeat();
pSeat->m_iCenterprintLines = tokenizebyseparator(sMessage, "\n");
@ -950,10 +956,7 @@ CSQC_Ent_Update(float new)
player pl = (player)self;
/* splitscreen */
int s = (float)getproperty(VF_ACTIVESEAT);
pSeat = &g_seats[s];
pSeatLocal = &g_seatslocal[s];
CSQC_UpdateSeat();
Predict_EntityUpdate(pl, new);

View File

@ -37,6 +37,31 @@ This entity was introduced in Quake (1996).
.float hurt_next;
typedef enumflags
{
HURTTYPE_GENERIC,
HURTTYPE_CRUSH,
HURTTYPE_BULLET,
HURTTYPE_SLASH,
HURTTYPE_BURN,
HURTTYPE_FREEZE,
HURTTYPE_FALL,
HURTTYPE_BLAST,
HURTTYPE_CLUB,
HURTTYPE_SHOCK,
HURTTYPE_SONIC,
HURTTYPE_ENERGYBEAM,
HURTTYPE_DROWN,
HURTTYPE_PARALYSE,
HURTTYPE_NERVEGAS,
HURTTYPE_POISON,
HURTTYPE_RADIATION,
HURTTYPE_DROWNRECOVER,
HURTTYPE_CHEMICAL,
HURTTYPE_SLOWBURN,
HURTTYPE_SLOWFREEZE,
} hurttype_e;
#define SF_HURT_ONCE 1 // Turn off once it fired the first time
#define SF_HURT_OFF 2 // Needs to be triggered in order to work again
#define SF_HURT_NOPLAYERS 8 // Don't hurt players
@ -49,6 +74,7 @@ class trigger_hurt:NSBrushTrigger
float m_flNextTrigger;
float m_flNextDmg;
float m_flDelay;
int m_iDamageType;
string m_strOnHurt;
string m_strOnHurtPlayer;
@ -68,6 +94,7 @@ void
trigger_hurt::Save(float handle)
{
SaveInt(handle, "damage", m_iDamage);
SaveInt(handle, "damagetype", m_iDamageType);
SaveFloat(handle, "nexttrigger", m_flNextTrigger);
SaveFloat(handle, "nextdmg", m_flNextDmg);
SaveFloat(handle, "delay", m_flDelay);
@ -83,6 +110,9 @@ trigger_hurt::Restore(string strKey, string strValue)
case "damage":
m_iDamage = ReadInt(strValue);
break;
case "damagetype":
m_iDamageType = ReadInt(strValue);
break;
case "nexttrigger":
m_flNextTrigger = ReadFloat(strValue);
break;
@ -152,7 +182,31 @@ trigger_hurt::touch(void)
}
}
Damage_Apply(other, this, m_iDamage, 0, DMG_GENERIC);
{
int type = 0;
if (m_iDamageType & HURTTYPE_BURN)
type |= DMG_BURN;
if (m_iDamageType & HURTTYPE_SLOWBURN)
type |= DMG_SLOWBURN;
if (m_iDamageType & HURTTYPE_FREEZE)
type |= DMG_FREEZE;
if (m_iDamageType & HURTTYPE_SLOWFREEZE)
type |= DMG_SLOWFREEZE;
if (m_iDamageType & HURTTYPE_SHOCK)
type |= DMG_ELECTRO;
if (m_iDamageType & HURTTYPE_DROWN)
type |= DMG_DROWN;
if (m_iDamageType & HURTTYPE_NERVEGAS)
type |= DMG_NERVEGAS;
if (m_iDamageType & HURTTYPE_POISON)
type |= DMG_POISON;
if (m_iDamageType & HURTTYPE_RADIATION)
type |= DMG_RADIATION;
if (m_iDamageType & HURTTYPE_CHEMICAL)
type |= DMG_CHEMICAL;
}
Damage_Apply(other, this, m_iDamage, 0, type);
dprint(sprintf("^2trigger_hurt::^3Touch^7: Hurting '%s' with %i\n",
other.netname, m_iDamage));
@ -194,6 +248,9 @@ trigger_hurt::SpawnKey(string strKey, string strValue)
case "dmg":
m_iDamage = stoi(strValue);
break;
case "damagetype":
m_iDamageType = stoi(strValue);
break;
case "wait":
m_flNextDmg = stof(strValue);
break;

View File

@ -226,8 +226,20 @@ CGameRules::DamageApply(entity t, entity c, float dmg, int w, damageType_t type)
g_dmg_iWeapon = w;
if (dmg > 0) {
t.dmg_take = dmg;
t.dmg_inflictor = c;
vector dmg_origin;
if (c.origin == [0,0,0])
dmg_origin = g_dmg_eTarget.origin;
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]);
WriteInt(MSG_MULTICAST, g_dmg_iDamage);
WriteInt(MSG_MULTICAST, g_dmg_iFlags);
msg_entity = g_dmg_eTarget;
multicast([0,0,0], MULTICAST_ONE_R);
} else if (t.max_health && t.health > t.max_health) {
t.health = t.max_health;
}

View File

@ -20,6 +20,7 @@ typedef enumflags
DMG_CRUSH,
DMG_BULLET,
DMG_SLASH,
DMG_FREEZE,
DMG_BURN,
DMG_VEHICLE,
DMG_FALL,
@ -36,9 +37,11 @@ typedef enumflags
DMG_POISON,
DMG_RADIATION,
DMG_DROWNRECOVER,
DMG_ACID,
DMG_CHEMICAL,
DMG_SLOWBURN,
DMG_SLOWFREEZE,
DMG_SKIP_ARMOR,
DMG_SKIP_RAGDOLL
} damageType_t;
#define DMG_ACID DMG_CHEMICAL

View File

@ -25,6 +25,7 @@ enum
EV_WEAPON_SECONDARYATTACK,
EV_WEAPON_RELOAD,
EV_WEAPON_PICKUP,
EV_DAMAGE,
EV_ANGLE,
EV_IMPACT,
EV_GIBHUMAN,