quake2ts 0.0.463 → 0.0.465

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3975,6 +3975,333 @@ function checkTriggers(ent, system) {
3975
3975
  }
3976
3976
  }
3977
3977
 
3978
+ // src/combat/specialDamage.ts
3979
+ init_esm();
3980
+
3981
+ // src/combat/damage.ts
3982
+ init_esm();
3983
+ init_armor();
3984
+ init_damageFlags();
3985
+ init_esm();
3986
+
3987
+ // src/imports.ts
3988
+ var MulticastType = /* @__PURE__ */ ((MulticastType2) => {
3989
+ MulticastType2[MulticastType2["All"] = 0] = "All";
3990
+ MulticastType2[MulticastType2["Pvs"] = 1] = "Pvs";
3991
+ MulticastType2[MulticastType2["Phs"] = 2] = "Phs";
3992
+ return MulticastType2;
3993
+ })(MulticastType || {});
3994
+
3995
+ // src/combat/damage.ts
3996
+ var EntityDamageFlags = /* @__PURE__ */ ((EntityDamageFlags2) => {
3997
+ EntityDamageFlags2[EntityDamageFlags2["GODMODE"] = 1] = "GODMODE";
3998
+ EntityDamageFlags2[EntityDamageFlags2["IMMORTAL"] = 2] = "IMMORTAL";
3999
+ EntityDamageFlags2[EntityDamageFlags2["NO_KNOCKBACK"] = 4] = "NO_KNOCKBACK";
4000
+ EntityDamageFlags2[EntityDamageFlags2["NO_DAMAGE_EFFECTS"] = 8] = "NO_DAMAGE_EFFECTS";
4001
+ return EntityDamageFlags2;
4002
+ })(EntityDamageFlags || {});
4003
+ function getDamageModifier(attacker, time) {
4004
+ if (!attacker) {
4005
+ return 1;
4006
+ }
4007
+ const client = attacker.client;
4008
+ if (!client) {
4009
+ return 1;
4010
+ }
4011
+ let modifier = 1;
4012
+ if (client.quad_time && client.quad_time > time) {
4013
+ modifier *= 4;
4014
+ }
4015
+ if (client.double_time && client.double_time > time) {
4016
+ modifier *= 2;
4017
+ }
4018
+ return modifier;
4019
+ }
4020
+ function applyKnockback(targ, attacker, dir, knockback, dflags) {
4021
+ const hasNoKnockback = hasAnyDamageFlag(dflags, 8 /* NO_KNOCKBACK */) || ((targ.flags ?? 0) & 4 /* NO_KNOCKBACK */) !== 0;
4022
+ if (hasNoKnockback || knockback === 0) {
4023
+ return { x: 0, y: 0, z: 0 };
4024
+ }
4025
+ const mass = Math.max(50, targ.mass ?? 200);
4026
+ const normalized = normalizeVec3(dir);
4027
+ const scale = attacker === targ ? 1600 : 500;
4028
+ const delta = scaleVec3(normalized, scale * knockback / mass);
4029
+ targ.velocity = addVec3(targ.velocity, delta);
4030
+ return delta;
4031
+ }
4032
+ function applyProtection(targ, point, normal, damage, dflags) {
4033
+ let take = damage;
4034
+ let psave = 0;
4035
+ let asave = 0;
4036
+ let remainingCells;
4037
+ let remainingArmor;
4038
+ if (targ.powerArmor) {
4039
+ const result = applyPowerArmor(damage, dflags, point, normal, targ.powerArmor);
4040
+ psave = result.saved;
4041
+ remainingCells = result.remainingCells;
4042
+ take -= psave;
4043
+ }
4044
+ if (targ.regularArmor) {
4045
+ const result = applyRegularArmor(take, dflags, targ.regularArmor);
4046
+ asave = result.saved;
4047
+ remainingArmor = result.remainingArmor;
4048
+ take -= asave;
4049
+ }
4050
+ return [Math.max(0, take), psave, asave, remainingCells, remainingArmor];
4051
+ }
4052
+ function targetCenter(ent) {
4053
+ if (ent.mins && ent.maxs) {
4054
+ return {
4055
+ x: ent.origin.x + (ent.mins.x + ent.maxs.x) * 0.5,
4056
+ y: ent.origin.y + (ent.mins.y + ent.maxs.y) * 0.5,
4057
+ z: ent.origin.z + (ent.mins.z + ent.maxs.z) * 0.5
4058
+ };
4059
+ }
4060
+ return ent.origin;
4061
+ }
4062
+ function T_Damage(targ, inflictor, attacker, dir, point, normal, damage, knockback, dflags, mod, time, multicast) {
4063
+ if (!targ.takedamage) {
4064
+ return null;
4065
+ }
4066
+ const modifier = getDamageModifier(attacker, time);
4067
+ const modifiedDamage = damage * modifier;
4068
+ const modifiedKnockback = knockback * modifier;
4069
+ const protectedByGod = !hasAnyDamageFlag(dflags, 32 /* NO_PROTECTION */) && ((targ.flags ?? 0) & 1 /* GODMODE */) !== 0 && modifiedDamage > 0;
4070
+ if (protectedByGod) {
4071
+ return {
4072
+ take: 0,
4073
+ psave: 0,
4074
+ asave: modifiedDamage,
4075
+ knocked: { x: 0, y: 0, z: 0 },
4076
+ killed: false
4077
+ };
4078
+ }
4079
+ const knocked = applyKnockback(targ, attacker, dir, modifiedKnockback, dflags);
4080
+ let [take, psave, asave, remainingCells, remainingArmor] = applyProtection(targ, point, normal, modifiedDamage, dflags);
4081
+ if (targ.monsterinfo && targ.monsterinfo.freeze_time > time && modifiedDamage > 0) {
4082
+ take = targ.health + 100;
4083
+ psave = 0;
4084
+ asave = 0;
4085
+ }
4086
+ if (targ.powerArmor && remainingCells !== void 0) {
4087
+ targ.powerArmor.cellCount = remainingCells;
4088
+ }
4089
+ if (targ.regularArmor) {
4090
+ targ.regularArmor.armorCount = remainingArmor ?? targ.regularArmor.armorCount;
4091
+ }
4092
+ let actualTake = take;
4093
+ if (actualTake > 0) {
4094
+ targ.health -= actualTake;
4095
+ if (multicast && !hasAnyDamageFlag(dflags, 1024 /* NO_DAMAGE_EFFECTS */)) {
4096
+ if (targ.classname === "player" || targ.monsterinfo) {
4097
+ multicast(point, 1 /* Pvs */, ServerCommand.temp_entity, TempEntity.BLOOD, point, normal);
4098
+ } else {
4099
+ }
4100
+ }
4101
+ }
4102
+ const killed = targ.health <= 0;
4103
+ if (killed) {
4104
+ if (targ.flags && targ.flags & 2 /* IMMORTAL */) {
4105
+ targ.health = Math.max(1, targ.health);
4106
+ } else if (targ.die) {
4107
+ targ.die(targ, inflictor, attacker, actualTake, point, mod);
4108
+ }
4109
+ } else if (actualTake > 0 && targ.pain) {
4110
+ targ.pain(targ, attacker, knockback, actualTake, mod);
4111
+ }
4112
+ return { take: actualTake, psave, asave, knocked, killed, remainingCells, remainingArmor };
4113
+ }
4114
+ function T_RadiusDamage(entities, inflictor, attacker, damage, ignore, radius, dflags, mod, time, options = {}, multicast) {
4115
+ const hits = [];
4116
+ const inflictorCenter = targetCenter(inflictor);
4117
+ const canDamage = options.canDamage ?? (() => true);
4118
+ for (const ent of entities) {
4119
+ if (ent === ignore || !ent.takedamage || !canDamage(ent, inflictor)) {
4120
+ continue;
4121
+ }
4122
+ const entCenter = ent.mins && ent.maxs ? closestPointToBox(inflictorCenter, addVec3(ent.origin, ent.mins), addVec3(ent.origin, ent.maxs)) : targetCenter(ent);
4123
+ const toTarget = subtractVec3(inflictorCenter, entCenter);
4124
+ const distance4 = lengthVec3(toTarget);
4125
+ if (radius > 0 && distance4 > radius) {
4126
+ continue;
4127
+ }
4128
+ const points = damage - 0.5 * distance4;
4129
+ if (points <= 0) {
4130
+ continue;
4131
+ }
4132
+ let adjustedDamage = points;
4133
+ if (ent === attacker) {
4134
+ adjustedDamage = points * 0.5;
4135
+ }
4136
+ const adjustedKnockback = adjustedDamage;
4137
+ const dir = normalizeVec3(subtractVec3(ent.origin, inflictorCenter));
4138
+ const result = T_Damage(ent, inflictor, attacker, dir, entCenter, dir, adjustedDamage, adjustedKnockback, dflags | 1 /* RADIUS */, mod, time, multicast);
4139
+ hits.push({ target: ent, result, appliedDamage: adjustedDamage });
4140
+ }
4141
+ return hits;
4142
+ }
4143
+
4144
+ // src/combat/specialDamage.ts
4145
+ var ZERO2 = { x: 0, y: 0, z: 0 };
4146
+ var EnvironmentalFlags = /* @__PURE__ */ ((EnvironmentalFlags2) => {
4147
+ EnvironmentalFlags2[EnvironmentalFlags2["IN_WATER"] = 1] = "IN_WATER";
4148
+ EnvironmentalFlags2[EnvironmentalFlags2["IMMUNE_LAVA"] = 2] = "IMMUNE_LAVA";
4149
+ EnvironmentalFlags2[EnvironmentalFlags2["IMMUNE_SLIME"] = 4] = "IMMUNE_SLIME";
4150
+ return EnvironmentalFlags2;
4151
+ })(EnvironmentalFlags || {});
4152
+ function applyDamageEvent(target, amount, mod, time) {
4153
+ return T_Damage(target, null, null, ZERO2, target.origin, ZERO2, amount, 0, 2 /* NO_ARMOR */, mod, time);
4154
+ }
4155
+ function applyEnvironmentalDamage(target, nowMs) {
4156
+ const events = [];
4157
+ let flags = target.environmentFlags ?? 0;
4158
+ let enteredWater = false;
4159
+ let leftWater = false;
4160
+ if (target.waterlevel === WaterLevel.None) {
4161
+ if ((flags & 1 /* IN_WATER */) !== 0) {
4162
+ flags &= ~1 /* IN_WATER */;
4163
+ leftWater = true;
4164
+ }
4165
+ if (target.airFinished < nowMs && target.painDebounceTime <= nowMs) {
4166
+ const elapsedSeconds = Math.floor((nowMs - target.airFinished) / 1e3);
4167
+ const amount = Math.min(15, 2 + 2 * elapsedSeconds);
4168
+ const result = applyDamageEvent(target, amount, 17 /* WATER */, nowMs / 1e3);
4169
+ target.painDebounceTime = nowMs + 1e3;
4170
+ events.push({ mod: 17 /* WATER */, amount, result });
4171
+ }
4172
+ } else {
4173
+ target.airFinished = nowMs + 9e3;
4174
+ if ((flags & 1 /* IN_WATER */) === 0) {
4175
+ flags |= 1 /* IN_WATER */;
4176
+ enteredWater = true;
4177
+ target.damageDebounceTime = 0;
4178
+ }
4179
+ if (target.damageDebounceTime <= nowMs) {
4180
+ if ((target.watertype & CONTENTS_LAVA) !== 0 && (flags & 2 /* IMMUNE_LAVA */) === 0) {
4181
+ const amount = 10 * target.waterlevel;
4182
+ const result = applyDamageEvent(target, amount, 19 /* LAVA */, nowMs / 1e3);
4183
+ target.damageDebounceTime = nowMs + 100;
4184
+ events.push({ mod: 19 /* LAVA */, amount, result });
4185
+ } else if ((target.watertype & CONTENTS_SLIME) !== 0 && (flags & 4 /* IMMUNE_SLIME */) === 0) {
4186
+ const amount = 4 * target.waterlevel;
4187
+ const result = applyDamageEvent(target, amount, 18 /* SLIME */, nowMs / 1e3);
4188
+ target.damageDebounceTime = nowMs + 100;
4189
+ events.push({ mod: 18 /* SLIME */, amount, result });
4190
+ }
4191
+ }
4192
+ }
4193
+ target.environmentFlags = flags;
4194
+ return { events, enteredWater, leftWater };
4195
+ }
4196
+ function calculateFallingDamage(context) {
4197
+ const {
4198
+ impactDelta,
4199
+ waterLevel,
4200
+ onLadder = false,
4201
+ isDead = false,
4202
+ isPlayerModel = true,
4203
+ isNoClip = false,
4204
+ grappleBlockingFallDamage = false,
4205
+ clampFreeFall = false,
4206
+ skipDamage = false
4207
+ } = context;
4208
+ if (isDead || !isPlayerModel || isNoClip || grappleBlockingFallDamage || waterLevel === WaterLevel.Under) {
4209
+ return { damage: 0, event: null, fallValue: 0, adjustedDelta: 0 };
4210
+ }
4211
+ let delta = impactDelta * impactDelta * 1e-4;
4212
+ if (waterLevel === WaterLevel.Waist) {
4213
+ delta *= 0.25;
4214
+ } else if (waterLevel === WaterLevel.Feet) {
4215
+ delta *= 0.5;
4216
+ }
4217
+ if (clampFreeFall) {
4218
+ delta = Math.min(30, delta);
4219
+ }
4220
+ if (delta < 1) {
4221
+ return { damage: 0, event: null, fallValue: 0, adjustedDelta: delta };
4222
+ }
4223
+ let event = null;
4224
+ let damage = 0;
4225
+ let fallValue = 0;
4226
+ if (delta < 15) {
4227
+ event = onLadder ? null : "footstep";
4228
+ } else {
4229
+ fallValue = Math.min(delta * 0.5, 40);
4230
+ if (delta > 30) {
4231
+ event = delta >= 55 ? "fallfar" : "fall";
4232
+ damage = Math.max(1, (delta - 30) * 0.5);
4233
+ } else {
4234
+ event = "fallshort";
4235
+ }
4236
+ }
4237
+ if (skipDamage) {
4238
+ damage = 0;
4239
+ }
4240
+ return { damage, event, fallValue, adjustedDelta: delta };
4241
+ }
4242
+ function applyFallingDamage(target, context) {
4243
+ const result = calculateFallingDamage(context);
4244
+ if (result.damage > 0 && !context.skipDamage) {
4245
+ T_Damage(
4246
+ target,
4247
+ null,
4248
+ null,
4249
+ { x: 0, y: 0, z: 1 },
4250
+ target.origin,
4251
+ ZERO2,
4252
+ result.damage,
4253
+ 0,
4254
+ 2 /* NO_ARMOR */,
4255
+ 23 /* FALLING */,
4256
+ 0
4257
+ );
4258
+ }
4259
+ return result;
4260
+ }
4261
+ function applyCrushDamage(crusher, target, options = {}) {
4262
+ const nonLivingDamage = options.nonLivingDamage ?? 1e5;
4263
+ const gibDamage = options.gibDamage ?? 100;
4264
+ const baseDamage = options.baseDamage ?? crusher.dmg ?? 10;
4265
+ const amount = !target.isMonster && !target.isClient ? nonLivingDamage : target.health < 1 ? gibDamage : baseDamage;
4266
+ const result = T_Damage(target, crusher, crusher, ZERO2, target.origin, ZERO2, amount, 1, 0 /* NONE */, 20 /* CRUSH */, 0);
4267
+ return { amount, result };
4268
+ }
4269
+ function absoluteBounds(ent) {
4270
+ const mins = ent.mins ?? ZERO2;
4271
+ const maxs = ent.maxs ?? ZERO2;
4272
+ return {
4273
+ mins: addVec3(ent.origin, mins),
4274
+ maxs: addVec3(ent.origin, maxs)
4275
+ };
4276
+ }
4277
+ function killBox(teleporter, targets, options = {}) {
4278
+ if (teleporter.movetype === 1 /* Noclip */) {
4279
+ return { events: [], cleared: true };
4280
+ }
4281
+ const mod = options.mod ?? 21 /* TELEFRAG */;
4282
+ const teleBounds = absoluteBounds(teleporter);
4283
+ const events = [];
4284
+ let cleared = true;
4285
+ for (const target of targets) {
4286
+ if (target === teleporter || target.inUse === false) {
4287
+ continue;
4288
+ }
4289
+ const solidity = target.solid ?? 0 /* Not */;
4290
+ if (!target.takedamage || solidity === 0 /* Not */ || solidity === 1 /* Trigger */ || solidity === 3 /* Bsp */) {
4291
+ continue;
4292
+ }
4293
+ if (!boxesIntersect(teleBounds, absoluteBounds(target))) {
4294
+ continue;
4295
+ }
4296
+ const result = T_Damage(target, teleporter, teleporter, ZERO2, target.origin, ZERO2, 1e5, 0, 32 /* NO_PROTECTION */, mod, 0);
4297
+ events.push({ target, result });
4298
+ if (!result || !result.killed || target.health > 0) {
4299
+ cleared = false;
4300
+ }
4301
+ }
4302
+ return { events, cleared };
4303
+ }
4304
+
3978
4305
  // src/physics/movement.ts
3979
4306
  var WATER_FRICTION = 2;
3980
4307
  var WATER_GRAVITY_SCALE = 0.1;
@@ -4064,6 +4391,14 @@ function runStep(ent, system, imports, gravity, frametime) {
4064
4391
  }
4065
4392
  timeLeft -= timeLeft * trace.fraction;
4066
4393
  if (trace.plane) {
4394
+ if (trace.plane.normal.z > 0.7 && velocity.z < 0) {
4395
+ const impactDelta = Math.abs(velocity.z);
4396
+ applyFallingDamage(ent, {
4397
+ impactDelta,
4398
+ waterLevel: ent.waterlevel,
4399
+ isDead: ent.deadflag !== 0
4400
+ });
4401
+ }
4067
4402
  velocity = clipVelocityVec3(velocity, trace.plane.normal, 1);
4068
4403
  }
4069
4404
  const speed = velocity.x * velocity.x + velocity.y * velocity.y + velocity.z * velocity.z;
@@ -5192,233 +5527,74 @@ var EntitySystem = class {
5192
5527
  const target = ref.targetIndex === null ? null : indexToEntity.get(ref.targetIndex) ?? null;
5193
5528
  assignField(ref.entity, ref.name, target);
5194
5529
  }
5195
- this.thinkScheduler.restore(snapshot.thinks, (index) => indexToEntity.get(index));
5196
- }
5197
- runTouches() {
5198
- const world = this.pool.world;
5199
- const activeEntities = [];
5200
- for (const entity of this.pool) {
5201
- if (entity === world) continue;
5202
- if (!entity.inUse || entity.freePending || entity.solid === 0 /* Not */) continue;
5203
- activeEntities.push(entity);
5204
- }
5205
- for (const first of activeEntities) {
5206
- const candidates = this.findInBox(first.absmin, first.absmax);
5207
- const firstBounds = computeBounds(first);
5208
- for (const second of candidates) {
5209
- if (first === second) continue;
5210
- if (!first.touch) continue;
5211
- const secondBounds = computeBounds(second);
5212
- if (!boundsIntersect(firstBounds, secondBounds)) continue;
5213
- first.touch(first, second);
5214
- }
5215
- }
5216
- }
5217
- registerTarget(entity) {
5218
- if (!entity.targetname) {
5219
- return;
5220
- }
5221
- let bucket = this.targetNameIndex.get(entity.targetname);
5222
- if (!bucket) {
5223
- bucket = /* @__PURE__ */ new Set();
5224
- this.targetNameIndex.set(entity.targetname, bucket);
5225
- }
5226
- bucket.add(entity);
5227
- }
5228
- unregisterTarget(entity) {
5229
- if (!entity.targetname) {
5230
- return;
5231
- }
5232
- const bucket = this.targetNameIndex.get(entity.targetname);
5233
- if (!bucket) {
5234
- return;
5235
- }
5236
- bucket.delete(entity);
5237
- if (bucket.size === 0) {
5238
- this.targetNameIndex.delete(entity.targetname);
5239
- }
5240
- }
5241
- useTargetsImmediate(entity, activator) {
5242
- if (entity.target) {
5243
- for (const target of this.findByTargetName(entity.target)) {
5244
- if (target === entity) {
5245
- continue;
5246
- }
5247
- target.use?.(target, entity, activator);
5248
- }
5249
- }
5250
- if (entity.killtarget) {
5251
- for (const victim of this.findByTargetName(entity.killtarget)) {
5252
- if (victim === entity) {
5253
- continue;
5254
- }
5255
- this.free(victim);
5256
- }
5257
- }
5258
- }
5259
- };
5260
-
5261
- // src/entities/misc.ts
5262
- init_esm();
5263
-
5264
- // src/combat/damage.ts
5265
- init_esm();
5266
- init_armor();
5267
- init_damageFlags();
5268
- init_esm();
5269
-
5270
- // src/imports.ts
5271
- var MulticastType = /* @__PURE__ */ ((MulticastType2) => {
5272
- MulticastType2[MulticastType2["All"] = 0] = "All";
5273
- MulticastType2[MulticastType2["Pvs"] = 1] = "Pvs";
5274
- MulticastType2[MulticastType2["Phs"] = 2] = "Phs";
5275
- return MulticastType2;
5276
- })(MulticastType || {});
5277
-
5278
- // src/combat/damage.ts
5279
- var EntityDamageFlags = /* @__PURE__ */ ((EntityDamageFlags2) => {
5280
- EntityDamageFlags2[EntityDamageFlags2["GODMODE"] = 1] = "GODMODE";
5281
- EntityDamageFlags2[EntityDamageFlags2["IMMORTAL"] = 2] = "IMMORTAL";
5282
- EntityDamageFlags2[EntityDamageFlags2["NO_KNOCKBACK"] = 4] = "NO_KNOCKBACK";
5283
- EntityDamageFlags2[EntityDamageFlags2["NO_DAMAGE_EFFECTS"] = 8] = "NO_DAMAGE_EFFECTS";
5284
- return EntityDamageFlags2;
5285
- })(EntityDamageFlags || {});
5286
- function getDamageModifier(attacker, time) {
5287
- if (!attacker) {
5288
- return 1;
5289
- }
5290
- const client = attacker.client;
5291
- if (!client) {
5292
- return 1;
5293
- }
5294
- let modifier = 1;
5295
- if (client.quad_time && client.quad_time > time) {
5296
- modifier *= 4;
5297
- }
5298
- if (client.double_time && client.double_time > time) {
5299
- modifier *= 2;
5300
- }
5301
- return modifier;
5302
- }
5303
- function applyKnockback(targ, attacker, dir, knockback, dflags) {
5304
- const hasNoKnockback = hasAnyDamageFlag(dflags, 8 /* NO_KNOCKBACK */) || ((targ.flags ?? 0) & 4 /* NO_KNOCKBACK */) !== 0;
5305
- if (hasNoKnockback || knockback === 0) {
5306
- return { x: 0, y: 0, z: 0 };
5307
- }
5308
- const mass = Math.max(50, targ.mass ?? 200);
5309
- const normalized = normalizeVec3(dir);
5310
- const scale = attacker === targ ? 1600 : 500;
5311
- const delta = scaleVec3(normalized, scale * knockback / mass);
5312
- targ.velocity = addVec3(targ.velocity, delta);
5313
- return delta;
5314
- }
5315
- function applyProtection(targ, point, normal, damage, dflags) {
5316
- let take = damage;
5317
- let psave = 0;
5318
- let asave = 0;
5319
- let remainingCells;
5320
- let remainingArmor;
5321
- if (targ.powerArmor) {
5322
- const result = applyPowerArmor(damage, dflags, point, normal, targ.powerArmor);
5323
- psave = result.saved;
5324
- remainingCells = result.remainingCells;
5325
- take -= psave;
5326
- }
5327
- if (targ.regularArmor) {
5328
- const result = applyRegularArmor(take, dflags, targ.regularArmor);
5329
- asave = result.saved;
5330
- remainingArmor = result.remainingArmor;
5331
- take -= asave;
5332
- }
5333
- return [Math.max(0, take), psave, asave, remainingCells, remainingArmor];
5334
- }
5335
- function targetCenter(ent) {
5336
- if (ent.mins && ent.maxs) {
5337
- return {
5338
- x: ent.origin.x + (ent.mins.x + ent.maxs.x) * 0.5,
5339
- y: ent.origin.y + (ent.mins.y + ent.maxs.y) * 0.5,
5340
- z: ent.origin.z + (ent.mins.z + ent.maxs.z) * 0.5
5341
- };
5342
- }
5343
- return ent.origin;
5344
- }
5345
- function T_Damage(targ, inflictor, attacker, dir, point, normal, damage, knockback, dflags, mod, time, multicast) {
5346
- if (!targ.takedamage) {
5347
- return null;
5348
- }
5349
- const modifier = getDamageModifier(attacker, time);
5350
- const modifiedDamage = damage * modifier;
5351
- const modifiedKnockback = knockback * modifier;
5352
- const protectedByGod = !hasAnyDamageFlag(dflags, 32 /* NO_PROTECTION */) && ((targ.flags ?? 0) & 1 /* GODMODE */) !== 0 && modifiedDamage > 0;
5353
- if (protectedByGod) {
5354
- return {
5355
- take: 0,
5356
- psave: 0,
5357
- asave: modifiedDamage,
5358
- knocked: { x: 0, y: 0, z: 0 },
5359
- killed: false
5360
- };
5361
- }
5362
- const knocked = applyKnockback(targ, attacker, dir, modifiedKnockback, dflags);
5363
- let [take, psave, asave, remainingCells, remainingArmor] = applyProtection(targ, point, normal, modifiedDamage, dflags);
5364
- if (targ.monsterinfo && targ.monsterinfo.freeze_time > time && modifiedDamage > 0) {
5365
- take = targ.health + 100;
5366
- psave = 0;
5367
- asave = 0;
5368
- }
5369
- if (targ.powerArmor && remainingCells !== void 0) {
5370
- targ.powerArmor.cellCount = remainingCells;
5371
- }
5372
- if (targ.regularArmor) {
5373
- targ.regularArmor.armorCount = remainingArmor ?? targ.regularArmor.armorCount;
5530
+ this.thinkScheduler.restore(snapshot.thinks, (index) => indexToEntity.get(index));
5374
5531
  }
5375
- let actualTake = take;
5376
- if (actualTake > 0) {
5377
- targ.health -= actualTake;
5378
- if (multicast && !hasAnyDamageFlag(dflags, 1024 /* NO_DAMAGE_EFFECTS */)) {
5379
- if (targ.classname === "player" || targ.monsterinfo) {
5380
- multicast(point, 1 /* Pvs */, ServerCommand.temp_entity, TempEntity.BLOOD, point, normal);
5381
- } else {
5532
+ runTouches() {
5533
+ const world = this.pool.world;
5534
+ const activeEntities = [];
5535
+ for (const entity of this.pool) {
5536
+ if (entity === world) continue;
5537
+ if (!entity.inUse || entity.freePending || entity.solid === 0 /* Not */) continue;
5538
+ activeEntities.push(entity);
5539
+ }
5540
+ for (const first of activeEntities) {
5541
+ const candidates = this.findInBox(first.absmin, first.absmax);
5542
+ const firstBounds = computeBounds(first);
5543
+ for (const second of candidates) {
5544
+ if (first === second) continue;
5545
+ if (!first.touch) continue;
5546
+ const secondBounds = computeBounds(second);
5547
+ if (!boundsIntersect(firstBounds, secondBounds)) continue;
5548
+ first.touch(first, second);
5382
5549
  }
5383
5550
  }
5384
5551
  }
5385
- const killed = targ.health <= 0;
5386
- if (killed) {
5387
- if (targ.flags && targ.flags & 2 /* IMMORTAL */) {
5388
- targ.health = Math.max(1, targ.health);
5389
- } else if (targ.die) {
5390
- targ.die(targ, inflictor, attacker, actualTake, point, mod);
5552
+ registerTarget(entity) {
5553
+ if (!entity.targetname) {
5554
+ return;
5391
5555
  }
5392
- } else if (actualTake > 0 && targ.pain) {
5393
- targ.pain(targ, attacker, knockback, actualTake, mod);
5556
+ let bucket = this.targetNameIndex.get(entity.targetname);
5557
+ if (!bucket) {
5558
+ bucket = /* @__PURE__ */ new Set();
5559
+ this.targetNameIndex.set(entity.targetname, bucket);
5560
+ }
5561
+ bucket.add(entity);
5394
5562
  }
5395
- return { take: actualTake, psave, asave, knocked, killed, remainingCells, remainingArmor };
5396
- }
5397
- function T_RadiusDamage(entities, inflictor, attacker, damage, ignore, radius, dflags, mod, time, options = {}, multicast) {
5398
- const hits = [];
5399
- const inflictorCenter = targetCenter(inflictor);
5400
- const canDamage = options.canDamage ?? (() => true);
5401
- for (const ent of entities) {
5402
- if (ent === ignore || !ent.takedamage || !canDamage(ent, inflictor)) {
5403
- continue;
5563
+ unregisterTarget(entity) {
5564
+ if (!entity.targetname) {
5565
+ return;
5404
5566
  }
5405
- const entCenter = ent.mins && ent.maxs ? closestPointToBox(inflictorCenter, addVec3(ent.origin, ent.mins), addVec3(ent.origin, ent.maxs)) : targetCenter(ent);
5406
- const toTarget = subtractVec3(inflictorCenter, entCenter);
5407
- const distance4 = lengthVec3(toTarget);
5408
- if (radius > 0 && distance4 > radius) {
5409
- continue;
5567
+ const bucket = this.targetNameIndex.get(entity.targetname);
5568
+ if (!bucket) {
5569
+ return;
5410
5570
  }
5411
- const points = damage - 0.5 * distance4;
5412
- if (points <= 0) {
5413
- continue;
5571
+ bucket.delete(entity);
5572
+ if (bucket.size === 0) {
5573
+ this.targetNameIndex.delete(entity.targetname);
5414
5574
  }
5415
- const adjustedDamage = ent === attacker ? points * 0.5 : points;
5416
- const dir = normalizeVec3(subtractVec3(ent.origin, inflictorCenter));
5417
- const result = T_Damage(ent, inflictor, attacker, dir, entCenter, dir, adjustedDamage, adjustedDamage, dflags | 1 /* RADIUS */, mod, time, multicast);
5418
- hits.push({ target: ent, result, appliedDamage: adjustedDamage });
5419
5575
  }
5420
- return hits;
5421
- }
5576
+ useTargetsImmediate(entity, activator) {
5577
+ if (entity.target) {
5578
+ for (const target of this.findByTargetName(entity.target)) {
5579
+ if (target === entity) {
5580
+ continue;
5581
+ }
5582
+ target.use?.(target, entity, activator);
5583
+ }
5584
+ }
5585
+ if (entity.killtarget) {
5586
+ for (const victim of this.findByTargetName(entity.killtarget)) {
5587
+ if (victim === entity) {
5588
+ continue;
5589
+ }
5590
+ this.free(victim);
5591
+ }
5592
+ }
5593
+ }
5594
+ };
5595
+
5596
+ // src/entities/misc.ts
5597
+ init_esm();
5422
5598
 
5423
5599
  // src/entities/misc/flyers.ts
5424
5600
  init_esm();
@@ -25822,168 +25998,6 @@ function populatePlayerStats(player, timeSeconds) {
25822
25998
  // src/index.ts
25823
25999
  init_esm();
25824
26000
 
25825
- // src/combat/specialDamage.ts
25826
- init_esm();
25827
- var ZERO2 = { x: 0, y: 0, z: 0 };
25828
- var EnvironmentalFlags = /* @__PURE__ */ ((EnvironmentalFlags2) => {
25829
- EnvironmentalFlags2[EnvironmentalFlags2["IN_WATER"] = 1] = "IN_WATER";
25830
- EnvironmentalFlags2[EnvironmentalFlags2["IMMUNE_LAVA"] = 2] = "IMMUNE_LAVA";
25831
- EnvironmentalFlags2[EnvironmentalFlags2["IMMUNE_SLIME"] = 4] = "IMMUNE_SLIME";
25832
- return EnvironmentalFlags2;
25833
- })(EnvironmentalFlags || {});
25834
- function applyDamageEvent(target, amount, mod, time) {
25835
- return T_Damage(target, null, null, ZERO2, target.origin, ZERO2, amount, 0, 2 /* NO_ARMOR */, mod, time);
25836
- }
25837
- function applyEnvironmentalDamage(target, nowMs) {
25838
- const events = [];
25839
- let flags = target.environmentFlags ?? 0;
25840
- let enteredWater = false;
25841
- let leftWater = false;
25842
- if (target.waterlevel === WaterLevel.None) {
25843
- if ((flags & 1 /* IN_WATER */) !== 0) {
25844
- flags &= ~1 /* IN_WATER */;
25845
- leftWater = true;
25846
- }
25847
- if (target.airFinished < nowMs && target.painDebounceTime <= nowMs) {
25848
- const elapsedSeconds = Math.floor((nowMs - target.airFinished) / 1e3);
25849
- const amount = Math.min(15, 2 + 2 * elapsedSeconds);
25850
- const result = applyDamageEvent(target, amount, 17 /* WATER */, nowMs / 1e3);
25851
- target.painDebounceTime = nowMs + 1e3;
25852
- events.push({ mod: 17 /* WATER */, amount, result });
25853
- }
25854
- } else {
25855
- target.airFinished = nowMs + 9e3;
25856
- if ((flags & 1 /* IN_WATER */) === 0) {
25857
- flags |= 1 /* IN_WATER */;
25858
- enteredWater = true;
25859
- target.damageDebounceTime = 0;
25860
- }
25861
- if (target.damageDebounceTime <= nowMs) {
25862
- if ((target.watertype & CONTENTS_LAVA) !== 0 && (flags & 2 /* IMMUNE_LAVA */) === 0) {
25863
- const amount = 10 * target.waterlevel;
25864
- const result = applyDamageEvent(target, amount, 19 /* LAVA */, nowMs / 1e3);
25865
- target.damageDebounceTime = nowMs + 100;
25866
- events.push({ mod: 19 /* LAVA */, amount, result });
25867
- } else if ((target.watertype & CONTENTS_SLIME) !== 0 && (flags & 4 /* IMMUNE_SLIME */) === 0) {
25868
- const amount = 4 * target.waterlevel;
25869
- const result = applyDamageEvent(target, amount, 18 /* SLIME */, nowMs / 1e3);
25870
- target.damageDebounceTime = nowMs + 100;
25871
- events.push({ mod: 18 /* SLIME */, amount, result });
25872
- }
25873
- }
25874
- }
25875
- target.environmentFlags = flags;
25876
- return { events, enteredWater, leftWater };
25877
- }
25878
- function calculateFallingDamage(context) {
25879
- const {
25880
- impactDelta,
25881
- waterLevel,
25882
- onLadder = false,
25883
- isDead = false,
25884
- isPlayerModel = true,
25885
- isNoClip = false,
25886
- grappleBlockingFallDamage = false,
25887
- clampFreeFall = false,
25888
- skipDamage = false
25889
- } = context;
25890
- if (isDead || !isPlayerModel || isNoClip || grappleBlockingFallDamage || waterLevel === WaterLevel.Under) {
25891
- return { damage: 0, event: null, fallValue: 0, adjustedDelta: 0 };
25892
- }
25893
- let delta = impactDelta * impactDelta * 1e-4;
25894
- if (waterLevel === WaterLevel.Waist) {
25895
- delta *= 0.25;
25896
- } else if (waterLevel === WaterLevel.Feet) {
25897
- delta *= 0.5;
25898
- }
25899
- if (clampFreeFall) {
25900
- delta = Math.min(30, delta);
25901
- }
25902
- if (delta < 1) {
25903
- return { damage: 0, event: null, fallValue: 0, adjustedDelta: delta };
25904
- }
25905
- let event = null;
25906
- let damage = 0;
25907
- let fallValue = 0;
25908
- if (delta < 15) {
25909
- event = onLadder ? null : "footstep";
25910
- } else {
25911
- fallValue = Math.min(delta * 0.5, 40);
25912
- if (delta > 30) {
25913
- event = delta >= 55 ? "fallfar" : "fall";
25914
- damage = Math.max(1, (delta - 30) * 0.5);
25915
- } else {
25916
- event = "fallshort";
25917
- }
25918
- }
25919
- if (skipDamage) {
25920
- damage = 0;
25921
- }
25922
- return { damage, event, fallValue, adjustedDelta: delta };
25923
- }
25924
- function applyFallingDamage(target, context) {
25925
- const result = calculateFallingDamage(context);
25926
- if (result.damage > 0 && !context.skipDamage) {
25927
- T_Damage(
25928
- target,
25929
- null,
25930
- null,
25931
- { x: 0, y: 0, z: 1 },
25932
- target.origin,
25933
- ZERO2,
25934
- result.damage,
25935
- 0,
25936
- 2 /* NO_ARMOR */,
25937
- 23 /* FALLING */,
25938
- 0
25939
- );
25940
- }
25941
- return result;
25942
- }
25943
- function applyCrushDamage(crusher, target, options = {}) {
25944
- const nonLivingDamage = options.nonLivingDamage ?? 1e5;
25945
- const gibDamage = options.gibDamage ?? 100;
25946
- const baseDamage = options.baseDamage ?? crusher.dmg ?? 10;
25947
- const amount = !target.isMonster && !target.isClient ? nonLivingDamage : target.health < 1 ? gibDamage : baseDamage;
25948
- const result = T_Damage(target, crusher, crusher, ZERO2, target.origin, ZERO2, amount, 1, 0 /* NONE */, 20 /* CRUSH */, 0);
25949
- return { amount, result };
25950
- }
25951
- function absoluteBounds(ent) {
25952
- const mins = ent.mins ?? ZERO2;
25953
- const maxs = ent.maxs ?? ZERO2;
25954
- return {
25955
- mins: addVec3(ent.origin, mins),
25956
- maxs: addVec3(ent.origin, maxs)
25957
- };
25958
- }
25959
- function killBox(teleporter, targets, options = {}) {
25960
- if (teleporter.movetype === 1 /* Noclip */) {
25961
- return { events: [], cleared: true };
25962
- }
25963
- const mod = options.mod ?? 21 /* TELEFRAG */;
25964
- const teleBounds = absoluteBounds(teleporter);
25965
- const events = [];
25966
- let cleared = true;
25967
- for (const target of targets) {
25968
- if (target === teleporter || target.inUse === false) {
25969
- continue;
25970
- }
25971
- const solidity = target.solid ?? 0 /* Not */;
25972
- if (!target.takedamage || solidity === 0 /* Not */ || solidity === 1 /* Trigger */ || solidity === 3 /* Bsp */) {
25973
- continue;
25974
- }
25975
- if (!boxesIntersect(teleBounds, absoluteBounds(target))) {
25976
- continue;
25977
- }
25978
- const result = T_Damage(target, teleporter, teleporter, ZERO2, target.origin, ZERO2, 1e5, 0, 32 /* NO_PROTECTION */, mod, 0);
25979
- events.push({ target, result });
25980
- if (!result || !result.killed || target.health > 0) {
25981
- cleared = false;
25982
- }
25983
- }
25984
- return { events, cleared };
25985
- }
25986
-
25987
26001
  // src/combat/weapon.ts
25988
26002
  var WeaponType = /* @__PURE__ */ ((WeaponType2) => {
25989
26003
  WeaponType2[WeaponType2["BLASTER"] = 0] = "BLASTER";