djcev.com

//

Git Repos / fte_dogmode / qc / items / armor.qc

Last update to this file was on 2025-03-30 at 19:29.

Show armor.qc

//==============================================================================
// armor.qc
//==============================================================================

//======================================================================
// constants
//======================================================================

#ifdef SSQC
const float ARMOR_GREEN_ABSORB = 0.3; // absorb percent; id1 0.3
const float ARMOR_GREEN_AMOUNT = 100; // amount per pickup; id1 100
const float ARMOR_GREEN_MAX = 125; // id1 125

const float ARMOR_YELLOW_ABSORB = 0.6; // id1 0.6
const float ARMOR_YELLOW_AMOUNT = 150; // id1 150
const float ARMOR_YELLOW_MAX = 175; // id1 175

const float ARMOR_RED_ABSORB = 0.8; // id1 0.8
const float ARMOR_RED_AMOUNT = 200; // id1 200
const float ARMOR_RED_MAX = 225; // id1 225

const float ARMOR_SHARD_AMOUNT = 5; // Q3 5

const float ARMOR_DAMAGE = 15; // damage armor deals when thrown
const float ARMOR_DAMAGE_SHARD = 5; // damage a shard deals when thrown

const float ARMOR_RESPAWN_SP = 30; // id1 30s
const float ARMOR_RESPAWN_DM = 20; // id1 20s
#endif

//======================================================================
// forward declarations
//======================================================================

// base_item_armor
#ifdef SSQC
// BASE_ITEM_ARMOR_ADDARMOR(p, idx)
entity(entity src, vector org, vector vel, float fl, void(entity) initfn)
spawn_item_armor;
void(entity grabber, entity armor) base_item_armor_grab;
void(entity attacker, float item_index) base_item_armor_fire;
void() base_item_armor_touch;
void(string key, string value) base_item_armor_init_field;
#endif
#if defined(CSQC) || defined(SSQC)
void(entity e) base_item_armor_init;
#endif
#ifdef SSQC
strip void() base_item_armor;
#endif

// item_armor1
#ifdef CSQC
void(float isnew) item_armor1_netreceive;
#endif
#ifdef SSQC
entity(entity src, vector org, vector vel, float fl) spawn_item_armor1;
#endif
#if defined(CSQC) || defined(SSQC)
void(entity e) item_armor1_init;
#endif
#ifdef SSQC
void() item_armor1;
#endif

// item_armor2
#ifdef CSQC
void(float isnew) item_armor2_netreceive;
#endif
#ifdef SSQC
entity(entity src, vector org, vector vel, float fl) spawn_item_armor2;
#endif
#if defined(CSQC) || defined(SSQC)
void(entity e) item_armor2_init;
#endif
#ifdef SSQC
void() item_armor2;
#endif

// item_armorInv
#ifdef CSQC
void(float isnew) item_armorInv_netreceive;
#endif
#ifdef SSQC
entity(entity src, vector org, vector vel, float fl) spawn_item_armorInv;
#endif
#if defined(CSQC) || defined(SSQC)
void(entity e) item_armorInv_init;
#endif
#ifdef SSQC
void() item_armorInv;
#endif

// item_armor_shard
#ifdef CSQC
void(float isnew) item_armor_shard_netreceive;
#endif
#ifdef SSQC
entity(entity src) item_armor_shard_drop;
entity(entity src, vector org, vector vel, float fl) spawn_item_armor_shard;
#endif
#if defined(CSQC) || defined(SSQC)
void(entity e) item_armor_shard_init;
#endif
#ifdef SSQC
void() item_armor_shard;
#endif

//------------------------------------------------------------------------------

//----------------------------------------------------------------------
// class base_item_armor: base_item
// {
#ifdef SSQC
//--------------------------------------------------------------
#define BASE_ITEM_ARMOR_ADDARMOR(p, idx) \
{ \
local float a_type, a_value, a_bit; \
/* silence a compiler warning -- CEV */ \
a_type = a_value = a_bit = 0; \
switch (idx) \
{ \
case ITEM_SEQ_ARMOR_GREEN: \
/* green armor */ \
a_type = ARMOR_GREEN_ABSORB; \
a_value = ARMOR_GREEN_AMOUNT; \
a_bit = IT_ARMOR1; \
break; \
case ITEM_SEQ_ARMOR_YELLOW: \
/* yellow armor */ \
a_type = ARMOR_YELLOW_ABSORB; \
a_value = ARMOR_YELLOW_AMOUNT; \
a_bit = IT_ARMOR2; \
break; \
case ITEM_SEQ_ARMOR_RED: \
/* red armor */ \
a_type = ARMOR_RED_ABSORB; \
a_value = ARMOR_RED_AMOUNT; \
a_bit = IT_ARMOR3; \
break; \
case ITEM_SEQ_ARMOR_SHARD: \
a_value = p.armorvalue + ARMOR_SHARD_AMOUNT; \
if (p.items & IT_ARMOR2) \
{ \
if (p.armorvalue >= ARMOR_YELLOW_MAX) \
return; \
if (a_value > ARMOR_YELLOW_MAX) \
a_value = ARMOR_YELLOW_MAX; \
a_type = ARMOR_YELLOW_ABSORB; \
a_bit = IT_ARMOR2; \
} \
else if (p.items & IT_ARMOR3) \
{ \
if (p.armorvalue >= ARMOR_RED_MAX) \
return; \
if (a_value > ARMOR_RED_MAX) \
a_value = ARMOR_RED_MAX; \
a_type = ARMOR_RED_ABSORB; \
a_bit = IT_ARMOR3; \
} \
else \
{ \
if (p.armorvalue >= ARMOR_GREEN_MAX) \
return; \
if (a_value > ARMOR_GREEN_MAX) \
a_value = ARMOR_GREEN_MAX; \
a_type = ARMOR_GREEN_ABSORB; \
a_bit = IT_ARMOR1; \
} \
break; \
default: \
dprint (sprintf("base_item_armor_touch: " \
"unknown armor type! seq %g, class " \
"%s!\n", idx, self.classname)); \
return; \
} \
if (p.armortype * p.armorvalue >= a_type * a_value) \
return; \
p.armortype = a_type; \
p.armorvalue = a_value; \
p.items = p.items - (p.items & \
(IT_ARMOR1 | IT_ARMOR2 | IT_ARMOR3)) + a_bit; \
}

//--------------------------------------------------------------
entity(entity src, vector org, vector vel, float fl,
void(entity) init_fn) spawn_item_armor =
{
local entity e = spawn ();
e.owner = src;
e.spawnflags = fl;
e.origin = org;
e.velocity = vel;
init_fn (e);
return e;
};

//--------------------------------------------------------------
void(entity grabber, entity armor) base_item_armor_grab =
{
BASE_ITEM_INVENTORY_ADD (armor, grabber)

sprint (grabber, sprintf("%s grabbed the %s\n",
grabber.netname, armor.netname));

// don't re-grab / immediately throw the item -- CEV
if (grabber.button6)
grabber.flags |= FL_THROW_HELD;

if (grabber.classtype == CT_PLAYER && grabber.SendEntity)
grabber.SendFlags |= NETFLAG_PLAYER_WEAPON;

// fire all targets / killtargets
local entity stemp = self;
local entity otemp = other;
other = grabber;
self = armor;
activator = other;
sub_usetargets ();
self = stemp;
other = otemp;

// remove or respawn -- CEV
BASE_ITEM_CHECKREMOVE (armor,
ARMOR_RESPAWN_SP, ARMOR_RESPAWN_DM)
};

//--------------------------------------------------------------
void(entity attacker, float item_index) base_item_armor_fire =
{
// add the armor -- CEV
BASE_ITEM_ARMOR_ADDARMOR (attacker, item_index)

// now remove the armor from inventory -- CEV
BASE_ITEM_INVENTORY_REMOVE (attacker)

// make sure the client knows -- CEV
if (attacker.classtype == CT_PLAYER && attacker.SendEntity)
attacker.SendFlags |= NETFLAG_PLAYER_ITEMS |
NETFLAG_PLAYER_HEALTH | NETFLAG_PLAYER_WEAPON;

// let the player know -- CEV
local item_info_t item = item_info[item_index];
BASE_ITEM_PICKUPMESSAGE (attacker, item, CHAN_ITEM_ARMOR)
};

//--------------------------------------------------------------
// was armor_touch -- CEV
//--------------------------------------------------------------
void() base_item_armor_touch =
{
// thrown item check -- CEV
if (base_item_touch_projectile())
return;

if (sub_checkvalidtouch(other) == FALSE)
return;

// don't touch() if the player isn't holding a weapon -- CEV
BASE_ENTITY_WEAPONLOOKUP (other)
if (item_index < ITEM_SEQ_W_START||item_index > ITEM_SEQ_W_END)
{
if (item_index == ITEM_SEQ_HANDS && other.button6 &&
!(other.flags & FL_THROW_HELD))
{
// self.attack_finished = time + 0.5;
base_item_armor_grab (other, self);
return;
}
else
{
return;
}
}

// add the armor -- CEV
BASE_ITEM_ARMOR_ADDARMOR (other, self.weapon)

// let the client (CSQC) know -- CEV
if (other.classtype == CT_PLAYER && other.SendEntity)
other.SendFlags |= NETFLAG_PLAYER_ITEMS |
NETFLAG_PLAYER_HEALTH;

// let the player know -- CEV
local item_info_t item = item_info[self.weapon];
BASE_ITEM_PICKUPMESSAGE (other, item, CHAN_ITEM_ARMOR)

// fire all targets / killtargets
activator = other;
sub_usetargets ();

// either remove the item or set up for respawning -- CEV
BASE_ITEM_CHECKREMOVE (self,
ARMOR_RESPAWN_SP, ARMOR_RESPAWN_DM)
};

//--------------------------------------------------------------
void(string key, string value) base_item_armor_init_field =
{
base_item_init_field (key, value);
};
#endif

#if defined(CSQC) || defined(SSQC)
//--------------------------------------------------------------
void(entity e) base_item_armor_init =
{
e.classgroup |= CG_ITEM_ARMOR;

local item_info_t item = item_info[e.weapon];

#ifdef SSQC
precache_model (item.world_model);
precache_sound (item.pickup_sound);
setmodel (e, item.world_model);
if (!e.skin)
e.skin = item.option;
#endif

#ifdef CSQC
setmodelindex (e, e.modelindex);
e.modelflags |= MF_ROTATE;
#endif

e.noise = item.pickup_sound;
e.netname = item.name;

base_item_init (e);
};
#endif

#ifdef SSQC
//--------------------------------------------------------------
strip void() base_item_armor =
{
base_item_armor_init (self);
};
#endif
// };

/*QUAKED item_armor1 (0 .5 .8) (-16 -16 0) (16 16 32) X X X X X SPAWN_SILENT TRIGGER_SPAWNED SUSPENDED_IN_AIR NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER RESPAWN_WITH_DM_EFFECTS NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
{
model ("progs/armor.mdl");
}
*/
//----------------------------------------------------------------------
// class item_armor1: base_item_armor
// {
#ifdef CSQC
//--------------------------------------------------------------
void(float isnew) item_armor1_netreceive =
{
// creates a number of variables, including netflags -- CEV
BASE_ITEM_NETRECEIVE (item_armor1_init)
};
#endif

#ifdef SSQC
//--------------------------------------------------------------
entity(entity src, vector org, vector vel, float fl) spawn_item_armor1 =
{
return spawn_item_armor (src, org, vel, fl, item_armor1_init);
};
#endif

#if defined(CSQC) || defined(SSQC)
//--------------------------------------------------------------
void(entity e) item_armor1_init =
{
e.classname = "item_armor1";
e.classtype = CT_ITEM_ARMOR_GREEN;

#ifdef SSQC
e.touch = base_item_armor_touch;
e.weapon = ITEM_SEQ_ARMOR_GREEN;
e.dmg = ARMOR_DAMAGE;
#endif

e.pos1 = '-16 -16 0';
e.pos2 = '16 16 56';

// StartItem
base_item_armor_init (e);
};
#endif

#ifdef SSQC
//--------------------------------------------------------------
void() item_armor1 =
{
// remap spawnflags, inhibit spawn, remap fields -- CEV
BASE_ITEM_PREINIT (base_item_armor_init_field)

item_armor1_init (self);
};
#endif
// };

/*QUAKED item_armor2 (0 .5 .8) (-16 -16 0) (16 16 32) X X X X X SPAWN_SILENT TRIGGER_SPAWNED SUSPENDED_IN_AIR NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER RESPAWN_WITH_DM_EFFECTS NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
{ model({ "path": ":progs/armor.mdl", "skin": 1 }); }
*/
//----------------------------------------------------------------------
// class item_armor2: base_item_armor
// {
#ifdef CSQC
//--------------------------------------------------------------
void(float isnew) item_armor2_netreceive =
{
// creates a number of variables, including netflags -- CEV
BASE_ITEM_NETRECEIVE (item_armor2_init)
};
#endif

#ifdef SSQC
//--------------------------------------------------------------
entity(entity src, vector org, vector vel, float fl) spawn_item_armor2 =
{
return spawn_item_armor (src, org, vel, fl, item_armor2_init);
};
#endif

#if defined(CSQC) || defined(SSQC)
//--------------------------------------------------------------
void(entity e) item_armor2_init =
{
e.classname = "item_armor2";
e.classtype = CT_ITEM_ARMOR_YELLOW;

#ifdef SSQC
e.touch = base_item_armor_touch;
e.weapon = ITEM_SEQ_ARMOR_YELLOW;
e.dmg = ARMOR_DAMAGE;
#endif

e.pos1 = '-16 -16 0';
e.pos2 = '16 16 56';

// StartItem
base_item_armor_init (e);
};
#endif

#ifdef SSQC
//--------------------------------------------------------------
void() item_armor2 =
{
// remap spawnflags, inhibit spawn, remap fields -- CEV
BASE_ITEM_PREINIT (base_item_armor_init_field)

item_armor2_init (self);
};
#endif
// };

/*QUAKED item_armorInv (0 .5 .8) (-16 -16 0) (16 16 32) X X X X X SPAWN_SILENT TRIGGER_SPAWNED SUSPENDED_IN_AIR NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER RESPAWN_WITH_DM_EFFECTS NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
{
model({ "path": ":progs/armor.mdl", "skin": 2 });
}
*/
//----------------------------------------------------------------------
// class item_armorInv: base_item_armor
// {
#ifdef CSQC
//--------------------------------------------------------------
void(float isnew) item_armorInv_netreceive =
{
// creates a number of variables, including netflags -- CEV
BASE_ITEM_NETRECEIVE (item_armorInv_init)
};
#endif

#ifdef SSQC
//--------------------------------------------------------------
entity(entity src, vector org, vector vel, float fl)
spawn_item_armorInv =
{
return spawn_item_armor (src, org, vel, fl, item_armorInv_init);
};
#endif

#if defined(CSQC) || defined(SSQC)
//--------------------------------------------------------------
void(entity e) item_armorInv_init =
{
e.classname = "item_armorInv";
e.classtype = CT_ITEM_ARMOR_RED;

#ifdef SSQC
e.touch = base_item_armor_touch;
e.weapon = ITEM_SEQ_ARMOR_RED;
e.dmg = ARMOR_DAMAGE;
#endif

e.pos1 = '-16 -16 0';
e.pos2 = '16 16 56';

// StartItem
base_item_armor_init (e);
};
#endif

#ifdef SSQC
//--------------------------------------------------------------
void() item_armorInv =
{
// remap spawnflags, inhibit spawn, remap fields -- CEV
BASE_ITEM_PREINIT (base_item_armor_init_field)

item_armorInv_init (self);
};
#endif
// };

//------------------------------------------------------------------------------
// item_armor_shard
//------------------------------------------------------------------------------
// class item_armor_shard: base_item_armor
// {
#ifdef CSQC
//--------------------------------------------------------------
void(float isnew) item_armor_shard_netreceive =
{
// creates a number of variables, including netflags -- CEV
BASE_ITEM_NETRECEIVE (item_armor_shard_init)
};
#endif

#ifdef SSQC
//--------------------------------------------------------------
entity(entity src) item_armor_shard_drop =
{
local vector vel;
vel_x = -100 + (random() * 200);
vel_y = -100 + (random() * 200);
vel_z = 300;
return spawn_item_armor_shard (src, src.origin - '0 0 24', vel,
SPAWNFLAG_ITEM_THROWN);
};

//--------------------------------------------------------------
entity(entity src, vector org, vector vel, float fl)
spawn_item_armor_shard =
{
return spawn_item_armor (src, org, vel, fl,
item_armor_shard_init);
};
#endif

#if defined(CSQC) || defined(SSQC)
//--------------------------------------------------------------
void(entity e) item_armor_shard_init =
{
e.classname = "item_armor_shard";
e.classtype = CT_ITEM_ARMOR_SHARD;

#ifdef SSQC
e.touch = base_item_armor_touch;
e.weapon = ITEM_SEQ_ARMOR_SHARD;
e.dmg = ARMOR_DAMAGE_SHARD;
#endif

e.pos1 = '-16 -16 0';
e.pos2 = '16 16 56';

// StartItem
base_item_armor_init (e);
};
#endif

#ifdef SSQC
//--------------------------------------------------------------
void() item_armor_shard =
{
// remap spawnflags, inhibit spawn, remap fields -- CEV
BASE_ITEM_PREINIT (base_item_armor_init_field)

item_armor_shard_init (self);
};
#endif
// };

Return to the top of this page or return to the overview of this repo.

Log armor.qc

Return to the top of this page or return to the overview of this repo.