djcev.com

//

Git Repos / fte_dogmode / qc / items / ammo.qc

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

Show ammo.qc

//==============================================================================
// AMMO -- was in items.qc
//==============================================================================

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

#ifdef SSQC
//----------------------------------------------------------------------
// ammo spawnflags -- CEV
//----------------------------------------------------------------------
typedef enumflags
{
SPAWNFLAG_ITEM_AMMO_LARGE_BOX = 1 // large box
// SPAWNFLAG_ITEM_SPAWNSILENT = 32, // see base_item.qc -- CEV
// SPAWNFLAG_ITEM_SPAWNED = 64, // see base_item.qc -- CEV
// SPAWNFLAG_ITEM_SUSPENDED = 128, // see base_item.qc -- CEV
// SPAWNFLAG_NOT_ON_EASY = 256, // see base_entities.qc -- CEV
// SPAWNFLAG_NOT_ON_NORMAL = 512,
// SPAWNFLAG_NOT_ON_HARD_OR_NIGHTMARE = 1024,
// SPAWNFLAG_NOT_IN_DEATHMATCH = 2048,
// SPAWNFLAG_NOT_IN_COOP = 4096,
// SPAWNFLAG_NOT_IN_SP = 8192,
// SPAWNFLAG_NOT_ON_SKILL2 = 32768, // see base_entities.qc -- CEV
// SPAWNFLAG_NOT_ON_SKILL3 = 65536, // see base_entities.qc -- CEV
// SPAWNFLAG_CENTERPRINTALL = 131072 // see base_entities.qc -- CEV
// SPAWNFLAG_ITEM_RESPAWN = 2097152, // see base_item.qc -- CEV
// SPAWNFLAG_ITEM_THROWN = 4194304, // see base_item.qc -- CEV
// SPAWNFLAG_ITEM_DONTDROP = 8388608 // see base_item.qc -- CEV
} base_item_ammo_spawnflags;
#endif

#ifdef SSQC
const float ITEM_AMMO_DAMAGE_SMALL = 10;// damage a small box deals when thrown
const float ITEM_AMMO_DAMAGE_LARGE = 15;// same, but for large ammo boxes

const float AMMO_RESPAWN_TIME = 30; // ammo respawn time; id1 30s
const float AMMO_CELLS_SMALL = 6; // id1 6; small box of cells
const float AMMO_CELLS_BIG = 12; // id1 12; large box of cells
const float AMMO_CELLS_MAX = 100; // id1 maximum 100
const float AMMO_NAILS_SMALL = 25; // id1 25; small box of nails
const float AMMO_NAILS_BIG = 50; // id1 50; large box of nails
const float AMMO_NAILS_MAX = 200; // id1 maximum 200
const float AMMO_ROCKETS_SMALL = 5; // id1 5; small box of rockets
const float AMMO_ROCKETS_BIG = 10; // id1 10; large box of rockets
const float AMMO_ROCKETS_MAX = 100; // id1 maximum 100
const float AMMO_SHELLS_SMALL = 20; // id1 20; small box of shells
const float AMMO_SHELLS_BIG = 40; // id1 40; large box of shells
const float AMMO_SHELLS_MAX = 100; // id1 maximum 100
#endif

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

// base_item_ammo
#ifdef SSQC
// BASE_ITEM_AMMO_ADDAMMO(p, idx)
entity(entity src, vector org, vector vel, float fl, void(entity) initfn)
spawn_item_ammo_n;
void(entity grabber, entity ammo) base_item_ammo_grab;
void(entity attacker, float item_index) base_item_ammo_fire;
void() base_item_ammo_touch;
void(string key, string value) base_item_ammo_init_field;
#endif
#if defined(CSQC) || defined(SSQC)
void(entity e) base_item_ammo_init;
#endif
#ifdef SSQC
strip void() base_item_ammo;
#endif

// item_shells
#ifdef CSQC
void(float isnew) item_shells_netreceive;
#endif
#ifdef SSQC
entity(entity src, vector org, vector vel, float fl) spawn_item_shells;
#endif
#if defined(CSQC) || defined(SSQC)
void(entity e) item_shells_init;
#endif
#ifdef SSQC
void() item_shells;
#endif

// item_spikes
#ifdef CSQC
void(float isnew) item_spikes_netreceive;
#endif
#ifdef SSQC
entity(entity src, vector org, vector vel, float fl) spawn_item_spikes;
#endif
#if defined(CSQC) || defined(SSQC)
void(entity e) item_spikes_init;
#endif
#ifdef SSQC
void() item_spikes;
#endif

// item_rockets
#ifdef CSQC
void(float isnew) item_rockets_netreceive;
#endif
#ifdef SSQC
entity(entity src, vector org, vector vel, float fl) spawn_item_rockets;
#endif
#if defined(CSQC) || defined(SSQC)
void(entity e) item_rockets_init;
#endif
#ifdef SSQC
void() item_rockets;
#endif

// item_cells
#ifdef CSQC
void(float isnew) item_cells_netreceive;
#endif
#ifdef SSQC
entity(entity src, vector org, vector vel, float fl) spawn_item_cells;
#endif
#if defined(CSQC) || defined(SSQC)
void(entity e) item_cells_init;
#endif
#ifdef SSQC
void() item_cells;
#endif

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

//----------------------------------------------------------------------
// class base_item_ammo: base_item
// {
#ifdef SSQC
//--------------------------------------------------------------
#define BASE_ITEM_AMMO_ADDAMMO(p, idx) \
{ \
switch (idx) \
{ \
case ITEM_SEQ_AMMO_SHELLS_SMALL: \
if (p.ammo_shells >= AMMO_SHELLS_MAX) \
return; \
p.ammo_shells += AMMO_SHELLS_SMALL; \
break; \
case ITEM_SEQ_AMMO_SHELLS_LARGE: \
if (p.ammo_shells >= AMMO_SHELLS_MAX) \
return; \
p.ammo_shells += AMMO_SHELLS_BIG; \
break; \
case ITEM_SEQ_AMMO_NAILS_SMALL: \
if (p.ammo_nails >= AMMO_NAILS_MAX) \
return; \
p.ammo_nails += AMMO_NAILS_SMALL; \
break; \
case ITEM_SEQ_AMMO_NAILS_LARGE: \
if (p.ammo_nails >= AMMO_NAILS_MAX) \
return; \
p.ammo_nails += AMMO_NAILS_BIG; \
break; \
case ITEM_SEQ_AMMO_ROCKETS_SMALL: \
if (p.ammo_rockets >= AMMO_ROCKETS_MAX) \
return; \
p.ammo_rockets += AMMO_ROCKETS_SMALL; \
break; \
case ITEM_SEQ_AMMO_ROCKETS_LARGE: \
if (p.ammo_rockets >= AMMO_ROCKETS_MAX) \
return; \
p.ammo_rockets += AMMO_ROCKETS_BIG; \
break; \
case ITEM_SEQ_AMMO_CELLS_SMALL: \
if (p.ammo_cells >= AMMO_CELLS_MAX) \
return; \
p.ammo_cells += AMMO_CELLS_SMALL; \
break; \
case ITEM_SEQ_AMMO_CELLS_LARGE: \
if (p.ammo_cells >= AMMO_CELLS_MAX) \
return; \
p.ammo_cells += AMMO_CELLS_BIG; \
break; \
} \
}

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

//--------------------------------------------------------------
// base_item_ammo_grab -- player has 'grabbed' the item -- CEV
//--------------------------------------------------------------
void(entity grabber, entity ammo) base_item_ammo_grab =
{
BASE_ITEM_INVENTORY_ADD (ammo, grabber)

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

// let the player know -- CEV
sprint (grabber, sprintf("%s grabbed the %s\n",
grabber.netname, ammo.netname));

// let the client (CSQC) know -- CEV
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 = ammo;
activator = other;
sub_usetargets ();
self = stemp;
other = otemp;

// either remove the item or set up for respawning -- CEV
BASE_ITEM_CHECKREMOVE (ammo,
AMMO_RESPAWN_TIME, AMMO_RESPAWN_TIME)
};

//--------------------------------------------------------------
// base_item_ammo_fire
// player has pressed +attack while holding the item -- CEV
//--------------------------------------------------------------
void(entity attacker, float item_index) base_item_ammo_fire =
{
// open the ammo box, add the ammo -- CEV
BASE_ITEM_AMMO_ADDAMMO (attacker, item_index)

// restrict ammo to game maximums -- CEV
base_entity_boundammo (attacker);

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

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

// and make sure the player knows -- CEV
local item_info_t item = item_info[item_index];
BASE_ITEM_PICKUPMESSAGE (attacker, item, CHAN_ITEM_AMMO)
};

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

// proceed with normal SOLID_TRIGGER ammobox touch -- CEV
if (sub_checkvalidtouch(other) == FALSE)
return;

// ...except for this:
// 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_ammo_grab (other, self);
return;
}
else
{
return;
}
}

// add the ammo -- CEV
BASE_ITEM_AMMO_ADDAMMO (other, self.weapon)

// restrict other's ammo if over max -- CEV
base_entity_boundammo (other);

if (other.classtype == CT_PLAYER && other.SendEntity)
other.SendFlags |= NETFLAG_PLAYER_AMMO;

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

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

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

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

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

local item_info_t item = item_info[e.weapon];

#ifdef SSQC
e.touch = base_item_ammo_touch;
precache_model (item.world_model);
precache_sound (item.pickup_sound);
setmodel (e, item.world_model);
#endif

#ifdef CSQC
setmodelindex (e, e.modelindex);
#endif

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

base_item_init (e);

#ifdef SSQC
// set up rotation -- CEV
BASE_ITEM_THROW_ROTATION (e, item)
#endif
};
#endif

#ifdef SSQC
//--------------------------------------------------------------
strip void() base_item_ammo =
{
base_item_ammo_init (self);
};
#endif
// };

/*QUAKED item_shells (0 .5 .8) (0 0 0) (32 32 32) LARGE_BOX 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 ( {{ spawnflags & 1 -> { "path" : "maps/b_shell1.bsp" }, "maps/b_shell0.bsp" }} );
}
Box of 20 shells.
LARGE_BOX is a box of 40 shells.
*/
//----------------------------------------------------------------------
// class item_shells: base_item_ammo
// {
#ifdef CSQC
//--------------------------------------------------------------
void(float isnew) item_shells_netreceive =
{
// creates a number of variables, including netflags -- CEV
BASE_ITEM_NETRECEIVE (item_shells_init)
};
#endif

#ifdef SSQC
//--------------------------------------------------------------
entity(entity src, vector org, vector vel, float fl) spawn_item_shells =
{
return spawn_item_ammo_n (src, org, vel, fl, item_shells_init);
};
#endif

#if defined(CSQC) || defined(SSQC)
//--------------------------------------------------------------
void(entity e) item_shells_init =
{
e.classname = "item_shells";
e.classtype = CT_ITEM_AMMO_SHELLS;

#ifdef SSQC
if (e.spawnflags & SPAWNFLAG_ITEM_AMMO_LARGE_BOX)
{
e.weapon = ITEM_SEQ_AMMO_SHELLS_LARGE;
e.ammo_shells = AMMO_SHELLS_BIG;
e.dmg = ITEM_AMMO_DAMAGE_LARGE;
if !(e.particles_offset)
e.particles_offset = '16 16 16';
}
else
{
e.weapon = ITEM_SEQ_AMMO_SHELLS_SMALL;
e.ammo_shells = AMMO_SHELLS_SMALL;
e.dmg = ITEM_AMMO_DAMAGE_SMALL;
if !(e.particles_offset)
e.particles_offset = '12 12 12';
}
#endif

e.pos1 = '0 0 0';
e.pos2 = '32 32 56';

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

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

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

/*QUAKED item_spikes (0 .5 .8) (0 0 0) (32 32 32) LARGE_BOX 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 ( {{ spawnflags & 1 -> { "path" : "maps/b_nail1.bsp" }, "maps/b_nail0.bsp" }} );
}
Box of 25 nails.
LARGE_BOX is a box of 50 nails.
*/
//----------------------------------------------------------------------
// class item_spikes: base_item_ammo
// {
#ifdef CSQC
//--------------------------------------------------------------
void(float isnew) item_spikes_netreceive =
{
// creates a number of variables, including netflags -- CEV
BASE_ITEM_NETRECEIVE (item_spikes_init)
};
#endif

#ifdef SSQC
//--------------------------------------------------------------
entity(entity src, vector org, vector vel, float fl) spawn_item_spikes =
{
return spawn_item_ammo_n (src, org, vel, fl, item_spikes_init);
};
#endif

#if defined(CSQC) || defined(SSQC)
//--------------------------------------------------------------
void(entity e) item_spikes_init =
{
e.classname = "item_spikes";
e.classtype = CT_ITEM_AMMO_SPIKES;

#ifdef SSQC
if (e.spawnflags & SPAWNFLAG_ITEM_AMMO_LARGE_BOX)
{
e.weapon = ITEM_SEQ_AMMO_NAILS_LARGE;
e.ammo_nails = AMMO_NAILS_BIG;
e.dmg = ITEM_AMMO_DAMAGE_LARGE;
if !(e.particles_offset)
e.particles_offset = '16 16 16';
}
else
{
e.weapon = ITEM_SEQ_AMMO_NAILS_SMALL;
e.ammo_nails = AMMO_NAILS_SMALL;
e.dmg = ITEM_AMMO_DAMAGE_SMALL;
if !(e.particles_offset)
e.particles_offset = '12 12 12';
}
#endif

e.pos1 = '0 0 0';
e.pos2 = '32 32 56';

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

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

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

/*QUAKED item_rockets (0 .5 .8) (0 0 0) (32 32 32) LARGE_BOX 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 ( {{ spawnflags & 1 -> { "path" : "maps/b_rock1.bsp" }, "maps/b_rock0.bsp" }} );
}
*/
//----------------------------------------------------------------------
// class item_rockets: base_item_ammo
// {
#ifdef CSQC
//--------------------------------------------------------------
void(float isnew) item_rockets_netreceive =
{
// creates a number of variables, including netflags -- CEV
BASE_ITEM_NETRECEIVE (item_rockets_init)
};
#endif

#ifdef SSQC
//--------------------------------------------------------------
entity(entity src, vector org, vector vel, float fl)
spawn_item_rockets =
{
return spawn_item_ammo_n (src, org, vel, fl, item_rockets_init);
};
#endif

#if defined(CSQC) || defined(SSQC)
//--------------------------------------------------------------
void(entity e) item_rockets_init =
{
e.classname = "item_rockets";
e.classtype = CT_ITEM_AMMO_ROCKETS;

#ifdef SSQC
if (e.spawnflags & SPAWNFLAG_ITEM_AMMO_LARGE_BOX)
{
e.weapon = ITEM_SEQ_AMMO_ROCKETS_LARGE;
e.ammo_rockets = AMMO_ROCKETS_BIG;
e.dmg = ITEM_AMMO_DAMAGE_LARGE;
if !(e.particles_offset)
e.particles_offset = '16 8 16';
}
else
{
e.weapon = ITEM_SEQ_AMMO_ROCKETS_SMALL;
e.ammo_rockets = AMMO_ROCKETS_SMALL;
e.dmg = ITEM_AMMO_DAMAGE_SMALL;
if !(e.particles_offset)
e.particles_offset = '8 8 16';
}
#endif

e.pos1 = '0 0 0';
e.pos2 = '32 32 56';

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

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

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

/*QUAKED item_cells (0 .5 .8) (0 0 0) (32 32 32) LARGE_BOX 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 ( {{ spawnflags & 1 -> { "path" : "maps/b_batt1.bsp" }, "maps/b_batt0.bsp" }} );
}
Box of 6 cells.
LARGE_BOX is a box of 12 cells.
*/
//----------------------------------------------------------------------
// class item_cells: base_item_ammo
// {
#ifdef CSQC
//--------------------------------------------------------------
void(float isnew) item_cells_netreceive =
{
// creates a number of variables, including netflags -- CEV
BASE_ITEM_NETRECEIVE (item_cells_init)
};
#endif

#ifdef SSQC
//--------------------------------------------------------------
entity(entity src, vector org, vector vel, float fl) spawn_item_cells =
{
return spawn_item_ammo_n (src, org, vel, fl, item_cells_init);
};
#endif

#if defined(CSQC) || defined(SSQC)
//--------------------------------------------------------------
void(entity e) item_cells_init =
{
e.classname = "item_cells";
e.classtype = CT_ITEM_AMMO_CELLS;

#ifdef SSQC
if (e.spawnflags & SPAWNFLAG_ITEM_AMMO_LARGE_BOX)
{
e.weapon = ITEM_SEQ_AMMO_CELLS_LARGE;
e.ammo_cells = AMMO_CELLS_BIG;
e.dmg = ITEM_AMMO_DAMAGE_LARGE;
if !(e.particles_offset)
e.particles_offset = '16 16 16';
}
else
{
e.weapon = ITEM_SEQ_AMMO_CELLS_SMALL;
e.ammo_cells = AMMO_CELLS_SMALL;
e.dmg = ITEM_AMMO_DAMAGE_SMALL;
if !(e.particles_offset)
e.particles_offset = '12 12 12';
}
#endif

e.pos1 = '0 0 0';
e.pos2 = '32 32 56';

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

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

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

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

Log ammo.qc

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