X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=qcsrc%2Fcommon%2Ftriggers%2Ftriggers.qc;h=9db38a10b9478a6f9b53272ed21d2dc6e7353dc4;hb=b093c2ea2c367cb9bb4ce2c0468346080938270c;hp=849d3e8acb27ef9efba748c6ab5bab0b14178ab7;hpb=5e813f65d212e2cfc5c32eae682c0a1b0c0f73da;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/triggers/triggers.qc b/qcsrc/common/triggers/triggers.qc index 849d3e8ac..9db38a10b 100644 --- a/qcsrc/common/triggers/triggers.qc +++ b/qcsrc/common/triggers/triggers.qc @@ -1,3 +1,4 @@ +#include "triggers.qh" void SUB_DontUseTargets(entity this, entity actor, entity trigger) { } void SUB_UseTargets(entity this, entity actor, entity trigger); @@ -20,23 +21,86 @@ void FixSize(entity e) } #ifdef SVQC +void generic_setactive(entity this, int act) +{ + if(act == ACTIVE_TOGGLE) + { + if(this.active == ACTIVE_ACTIVE) + { + this.active = ACTIVE_NOT; + } + else + { + this.active = ACTIVE_ACTIVE; + } + } + else + { + this.active = act; + } +} + +void generic_netlinked_setactive(entity this, int act) +{ + int old_status = this.active; + generic_setactive(this, act); + + if (this.active != old_status) + { + this.SendFlags |= SF_TRIGGER_UPDATE; + } +} + +void generic_netlinked_reset(entity this) +{ + IFTARGETED + { + if(this.spawnflags & START_ENABLED) + { + this.active = ACTIVE_ACTIVE; + } + else + { + this.active = ACTIVE_NOT; + } + } + else + { + this.active = ACTIVE_ACTIVE; + } + + this.SendFlags |= SF_TRIGGER_UPDATE; +} + +// Compatibility with old maps +void generic_netlinked_legacy_use(entity this, entity actor, entity trigger) +{ + LOG_WARNF("Entity %s was (de)activated by a trigger, please update map to use relays", this.targetname); + this.setactive(this, ACTIVE_TOGGLE); +} + +bool autocvar_g_triggers_debug = true; void trigger_init(entity this) { string m = this.model; EXACTTRIGGER_INIT; - if(m != "") - { - precache_model(m); - _setmodel(this, m); // no precision needed + if(autocvar_g_triggers_debug) + { + if(m != "") + { + precache_model(m); + _setmodel(this, m); // no precision needed + } + setorigin(this, this.origin); + if(this.scale) + setsize(this, this.mins * this.scale, this.maxs * this.scale); + else + setsize(this, this.mins, this.maxs); } - setorigin(this, this.origin); - if(this.scale) - setsize(this, this.mins * this.scale, this.maxs * this.scale); - else - setsize(this, this.mins, this.maxs); - BITSET_ASSIGN(this.effects, EF_NODEPTHTEST); + if(autocvar_g_triggers_debug) + BITSET_ASSIGN(this.effects, EF_NODEPTHTEST); } void trigger_link(entity this, bool(entity this, entity to, int sendflags) sendfunc) @@ -52,41 +116,52 @@ void trigger_common_write(entity this, bool withtarget) BITSET_ASSIGN(f, 1); if(this.origin != '0 0 0') BITSET_ASSIGN(f, 4); + if(this.movedir != '0 0 0') + BITSET_ASSIGN(f, 8); + if(this.angles != '0 0 0') + BITSET_ASSIGN(f, 16); WriteByte(MSG_ENTITY, f); if(withtarget) { - WriteString(MSG_ENTITY, this.target); - WriteString(MSG_ENTITY, this.target2); - WriteString(MSG_ENTITY, this.target3); - WriteString(MSG_ENTITY, this.target4); - WriteString(MSG_ENTITY, this.targetname); - WriteString(MSG_ENTITY, this.killtarget); + // probably some way to clean this up... + int targbits = 0; + if(this.target && this.target != "") targbits |= BIT(0); + if(this.target2 && this.target2 != "") targbits |= BIT(1); + if(this.target3 && this.target3 != "") targbits |= BIT(2); + if(this.target4 && this.target4 != "") targbits |= BIT(3); + if(this.targetname && this.targetname != "") targbits |= BIT(4); + if(this.killtarget && this.killtarget != "") targbits |= BIT(5); + + WriteByte(MSG_ENTITY, targbits); + + if(targbits & BIT(0)) + WriteString(MSG_ENTITY, this.target); + if(targbits & BIT(1)) + WriteString(MSG_ENTITY, this.target2); + if(targbits & BIT(2)) + WriteString(MSG_ENTITY, this.target3); + if(targbits & BIT(3)) + WriteString(MSG_ENTITY, this.target4); + if(targbits & BIT(4)) + WriteString(MSG_ENTITY, this.targetname); + if(targbits & BIT(5)) + WriteString(MSG_ENTITY, this.killtarget); } if(f & 4) - { - WriteCoord(MSG_ENTITY, this.origin.x); - WriteCoord(MSG_ENTITY, this.origin.y); - WriteCoord(MSG_ENTITY, this.origin.z); - } + WriteVector(MSG_ENTITY, this.origin); - WriteShort(MSG_ENTITY, this.modelindex); - WriteCoord(MSG_ENTITY, this.mins.x); - WriteCoord(MSG_ENTITY, this.mins.y); - WriteCoord(MSG_ENTITY, this.mins.z); - WriteCoord(MSG_ENTITY, this.maxs.x); - WriteCoord(MSG_ENTITY, this.maxs.y); - WriteCoord(MSG_ENTITY, this.maxs.z); - WriteByte(MSG_ENTITY, bound(1, this.scale * 16, 255)); + if(f & 8) + WriteVector(MSG_ENTITY, this.movedir); - WriteCoord(MSG_ENTITY, this.movedir_x); - WriteCoord(MSG_ENTITY, this.movedir_y); - WriteCoord(MSG_ENTITY, this.movedir_z); + if(f & 16) + WriteVector(MSG_ENTITY, this.angles); - WriteCoord(MSG_ENTITY, this.angles_x); - WriteCoord(MSG_ENTITY, this.angles_y); - WriteCoord(MSG_ENTITY, this.angles_z); + WriteShort(MSG_ENTITY, this.modelindex); + WriteVector(MSG_ENTITY, this.mins); + WriteVector(MSG_ENTITY, this.maxs); + WriteByte(MSG_ENTITY, bound(1, this.scale * 16, 255)); } #elif defined(CSQC) @@ -98,71 +173,58 @@ void trigger_common_read(entity this, bool withtarget) if(withtarget) { - if(this.target) { strunzone(this.target); } - this.target = strzone(ReadString()); - if(this.target2) { strunzone(this.target2); } - this.target2 = strzone(ReadString()); - if(this.target3) { strunzone(this.target3); } - this.target3 = strzone(ReadString()); - if(this.target4) { strunzone(this.target4); } - this.target4 = strzone(ReadString()); - if(this.targetname) { strunzone(this.targetname); } - this.targetname = strzone(ReadString()); - if(this.killtarget) { strunzone(this.killtarget); } - this.killtarget = strzone(ReadString()); + strfree(this.target); + strfree(this.target2); + strfree(this.target3); + strfree(this.target4); + strfree(this.targetname); + strfree(this.killtarget); + + int targbits = ReadByte(); + + this.target = ((targbits & BIT(0)) ? strzone(ReadString()) : string_null); + this.target2 = ((targbits & BIT(1)) ? strzone(ReadString()) : string_null); + this.target3 = ((targbits & BIT(2)) ? strzone(ReadString()) : string_null); + this.target4 = ((targbits & BIT(3)) ? strzone(ReadString()) : string_null); + this.targetname = ((targbits & BIT(4)) ? strzone(ReadString()) : string_null); + this.killtarget = ((targbits & BIT(5)) ? strzone(ReadString()) : string_null); } if(f & 4) - { - this.origin_x = ReadCoord(); - this.origin_y = ReadCoord(); - this.origin_z = ReadCoord(); - } + this.origin = ReadVector(); else this.origin = '0 0 0'; setorigin(this, this.origin); + if(f & 8) + this.movedir = ReadVector(); + else + this.movedir = '0 0 0'; + + if(f & 16) + this.angles = ReadVector(); + else + this.angles = '0 0 0'; + this.modelindex = ReadShort(); - this.mins_x = ReadCoord(); - this.mins_y = ReadCoord(); - this.mins_z = ReadCoord(); - this.maxs_x = ReadCoord(); - this.maxs_y = ReadCoord(); - this.maxs_z = ReadCoord(); + this.mins = ReadVector(); + this.maxs = ReadVector(); this.scale = ReadByte() / 16; setsize(this, this.mins, this.maxs); - - this.movedir_x = ReadCoord(); - this.movedir_y = ReadCoord(); - this.movedir_z = ReadCoord(); - - this.angles_x = ReadCoord(); - this.angles_y = ReadCoord(); - this.angles_z = ReadCoord(); } void trigger_remove_generic(entity this) { - if(this.target) { strunzone(this.target); } - this.target = string_null; - - if(this.target2) { strunzone(this.target2); } - this.target2 = string_null; - - if(this.target3) { strunzone(this.target3); } - this.target3 = string_null; - - if(this.target4) { strunzone(this.target4); } - this.target4 = string_null; - - if(this.targetname) { strunzone(this.targetname); } - this.target = string_null; - - if(this.killtarget) { strunzone(this.killtarget); } - this.killtarget = string_null; + strfree(this.target); + strfree(this.target2); + strfree(this.target3); + strfree(this.target4); + strfree(this.targetname); + strfree(this.killtarget); } #endif + /* ============================== SUB_UseTargets @@ -182,7 +244,8 @@ match (string)this.target and call their .use function ============================== */ -void SUB_UseTargets(entity this, entity actor, entity trigger) + +void SUB_UseTargets_Ex(entity this, entity actor, entity trigger, bool preventReuse) { // // check for a delay @@ -200,6 +263,7 @@ void SUB_UseTargets(entity this, entity actor, entity trigger) t.target2 = this.target2; t.target3 = this.target3; t.target4 = this.target4; + t.antiwall_flag = this.antiwall_flag; return; } @@ -253,11 +317,11 @@ void SUB_UseTargets(entity this, entity actor, entity trigger) int aw_flag = this.antiwall_flag; for(entity t = NULL; (t = find(t, targetname, s)); ) { - if(t.use) + if(t.use && (t.sub_target_used != time || !preventReuse)) { if(this.target_random) { - RandomSelection_Add(t, 0, string_null, 1, 0); + RandomSelection_AddEnt(t, 1, 0); } else { @@ -265,6 +329,8 @@ void SUB_UseTargets(entity this, entity actor, entity trigger) t.antiwall_flag = aw_flag; t.use(t, actor, this); + if(preventReuse) + t.sub_target_used = time; } } } @@ -272,10 +338,12 @@ void SUB_UseTargets(entity this, entity actor, entity trigger) } if(this.target_random && RandomSelection_chosen_ent) + { RandomSelection_chosen_ent.use(RandomSelection_chosen_ent, actor, this); + if(preventReuse) + RandomSelection_chosen_ent.sub_target_used = time; + } } -void SUB_UseTargets_self(entity this) -{ - SUB_UseTargets(this, NULL, NULL); -} +void SUB_UseTargets(entity this, entity actor, entity trigger) { SUB_UseTargets_Ex(this, actor, trigger, false); } +void SUB_UseTargets_PreventReuse(entity this, entity actor, entity trigger) { SUB_UseTargets_Ex(this, actor, trigger, true); }