djcev.com

//

Git Repos / fte_dogmode / qc / triggers / filter.qc

Last update to this file was on 2024-03-24 at 02:40.

Show filter.qc

//==============================================================================
// trigger_filter
//==============================================================================

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

const float FILTER_FIELD_STATE = 0;
const float FILTER_FIELD_HEALTH = 1;
const float FILTER_FIELD_WEAPON = 2;
const float FILTER_FIELD_FLAGS = 3;
const float FILTER_FIELD_SPAWNFLAGS = 4;
const float FILTER_FIELD_CLASSNAME = 5;
const float FILTER_FIELD_ESTATE = 6;
const float FILTER_FIELD_TARGETNAME = 8;
const float FILTER_FIELD_ITEMS = 10;
const float FILTER_FIELD_COUNT = 11;
const float FILTER_FIELD_CNT = 12;
const float FILTER_FIELD_TYPE = 13;

const float FILTER_FIELDTYPE_FLOAT = 0;
const float FILTER_FIELDTYPE_STRING = 1;
const float FILTER_FIELDTYPE_FLAG = 2;

const float FILTER_OP_EQUALS = 0;
const float FILTER_OP_LT = 1;
const float FILTER_OP_LTE = 2;
const float FILTER_OP_GT = 3;
const float FILTER_OP_GTE = 4;
const float FILTER_OP_BITMASK_AND = 5;
const float FILTER_OP_BITMASK_OR = 6;

//======================================================================
// fields
//======================================================================

.string include; // trigger_filter
.string type; // trigger_filter

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

void() trigger_filter_use;
void(entity e) trigger_filter_init;
void() trigger_filter;

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

//----------------------------------------------------------------------
// TODO CEV: this needs comments
//----------------------------------------------------------------------
// class trigger_filter: base_trigger
// {
//--------------------------------------------------------------
void() trigger_filter_use =
{
self.state = 0;

if (self.estate != STATE_ACTIVE)
return;

local entity targ;
local float fieldtype, op, result, targfloat;
local string targstring;

targfloat = fieldtype = op = result = 0;
targstring = "";

if (self.include != "")
{
targ = find (world, targetname, self.include);
if (!targ)
targ = find (world, targetname2,
self.include);
if (!targ)
return;
}
else
{
targ = activator;
}

op = self.weapon;

switch (self.style)
{
case FILTER_FIELD_STATE:
fieldtype = FILTER_FIELDTYPE_FLOAT;
targfloat = targ.state;
break;

case FILTER_FIELD_ESTATE:
fieldtype = FILTER_FIELDTYPE_FLOAT;
targfloat = targ.estate;
break;

case FILTER_FIELD_HEALTH:
fieldtype = FILTER_FIELDTYPE_FLOAT;
targfloat = targ.health;
break;

case FILTER_FIELD_COUNT:
fieldtype = FILTER_FIELDTYPE_FLOAT;
targfloat = targ.count;
break;

case FILTER_FIELD_CNT:
fieldtype = FILTER_FIELDTYPE_FLOAT;
targfloat = targ.cnt;
break;

case FILTER_FIELD_WEAPON:
fieldtype = FILTER_FIELDTYPE_FLOAT;
targfloat = targ.weapon;
break;

case FILTER_FIELD_FLAGS:
fieldtype = FILTER_FIELDTYPE_FLAG;
targfloat = targ.flags;
break;

case FILTER_FIELD_SPAWNFLAGS:
fieldtype = FILTER_FIELDTYPE_FLAG;
targfloat = targ.spawnflags;
break;

case FILTER_FIELD_ITEMS:
fieldtype = FILTER_FIELDTYPE_FLAG;
targfloat = targ.items;
break;

case FILTER_FIELD_CLASSNAME:
fieldtype = FILTER_FIELDTYPE_STRING;
targstring = targ.classname;
break;

case FILTER_FIELD_TARGETNAME:
fieldtype = FILTER_FIELDTYPE_STRING;
targstring = targ.targetname;
break;

case FILTER_FIELD_TYPE:
fieldtype = FILTER_FIELDTYPE_STRING;
targstring = targ.type;
break;
}

if (fieldtype == FILTER_FIELDTYPE_FLOAT)
{
if (op == FILTER_OP_EQUALS)
{
if (targfloat == self.count)
result = 1;
}
else if (op == FILTER_OP_LT)
{
if (targfloat < self.count)
result = 1;
}
else if (op == FILTER_OP_LTE)
{
if (targfloat <= self.count)
result = 1;
}
else if (op == FILTER_OP_GT)
{
if (targfloat > self.count)
result = 1;
}
else if (op == FILTER_OP_GTE)
{
if (targfloat >= self.count)
result = 1;
}
else if (op == FILTER_OP_BITMASK_AND)
{
if (targfloat & self.count)
result = 1;
}
else if (op == FILTER_OP_BITMASK_OR)
{
if (targfloat | self.count)
result = 1;
}
else
{
if (targfloat == self.count)
result = 1;
}
}
else if (fieldtype == FILTER_FIELDTYPE_FLAG)
{
if (op == FILTER_OP_EQUALS)
{
if (targfloat == self.aflag)
result = 1;
}
else if (op == FILTER_OP_BITMASK_AND)
{
if (targfloat & self.aflag)
result = 1;
}
else if (op == FILTER_OP_BITMASK_OR)
{
if (targfloat | self.aflag)
result = 1;
}
else
{
if (targfloat == self.aflag)
result = 1;
}
}
else if (fieldtype == FILTER_FIELDTYPE_STRING)
{
if (targstring == self.type)
result = 1;
}
else
{
objerror ("invalid fieldtype");
return;
}

if (self.spawnflags & 1)
// negate
result = 1 - result;

if (result)
{
self.state = 1;

// relay activator as owner
if (self.spawnflags & 2 && activator.owner)
activator = activator.owner;

sub_usetargets ();

if (other.classtype == CT_TRIGGER_EVERYTHING &&
other.spawnflags & 1 && other.wait)
{
other.attack_finished = time + other.wait;
}
}
};

//--------------------------------------------------------------
void(entity e) trigger_filter_init =
{
e.classname = "trigger_filter";
e.classtype = CT_TRIGGER_FILTER;
e.use = trigger_filter_use;
base_trigger_init (e);
};

//--------------------------------------------------------------
void() trigger_filter =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

trigger_filter_init (self);
};
// };

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

Log filter.qc

Date Commit Message Author + -
2024-03-24 2nd pass refactor, rework QC class structure cev +64 -34
2024-01-09 Continue OO / Class-based refactor cev +11 -10
2023-12-09 Start OO / class-based refactor, work on items cev +177 -167
2023-11-20 changes to movement, build environment, file reorg cev +226  

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