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.
@@ -4164,6 +4164,333 @@ function checkTriggers(ent, system) {
4164
4164
  }
4165
4165
  }
4166
4166
 
4167
+ // src/combat/specialDamage.ts
4168
+ init_esm();
4169
+
4170
+ // src/combat/damage.ts
4171
+ init_esm();
4172
+ init_armor();
4173
+ init_damageFlags();
4174
+ init_esm();
4175
+
4176
+ // src/imports.ts
4177
+ var MulticastType = /* @__PURE__ */ ((MulticastType2) => {
4178
+ MulticastType2[MulticastType2["All"] = 0] = "All";
4179
+ MulticastType2[MulticastType2["Pvs"] = 1] = "Pvs";
4180
+ MulticastType2[MulticastType2["Phs"] = 2] = "Phs";
4181
+ return MulticastType2;
4182
+ })(MulticastType || {});
4183
+
4184
+ // src/combat/damage.ts
4185
+ var EntityDamageFlags = /* @__PURE__ */ ((EntityDamageFlags2) => {
4186
+ EntityDamageFlags2[EntityDamageFlags2["GODMODE"] = 1] = "GODMODE";
4187
+ EntityDamageFlags2[EntityDamageFlags2["IMMORTAL"] = 2] = "IMMORTAL";
4188
+ EntityDamageFlags2[EntityDamageFlags2["NO_KNOCKBACK"] = 4] = "NO_KNOCKBACK";
4189
+ EntityDamageFlags2[EntityDamageFlags2["NO_DAMAGE_EFFECTS"] = 8] = "NO_DAMAGE_EFFECTS";
4190
+ return EntityDamageFlags2;
4191
+ })(EntityDamageFlags || {});
4192
+ function getDamageModifier(attacker, time) {
4193
+ if (!attacker) {
4194
+ return 1;
4195
+ }
4196
+ const client = attacker.client;
4197
+ if (!client) {
4198
+ return 1;
4199
+ }
4200
+ let modifier = 1;
4201
+ if (client.quad_time && client.quad_time > time) {
4202
+ modifier *= 4;
4203
+ }
4204
+ if (client.double_time && client.double_time > time) {
4205
+ modifier *= 2;
4206
+ }
4207
+ return modifier;
4208
+ }
4209
+ function applyKnockback(targ, attacker, dir, knockback, dflags) {
4210
+ const hasNoKnockback = hasAnyDamageFlag(dflags, 8 /* NO_KNOCKBACK */) || ((targ.flags ?? 0) & 4 /* NO_KNOCKBACK */) !== 0;
4211
+ if (hasNoKnockback || knockback === 0) {
4212
+ return { x: 0, y: 0, z: 0 };
4213
+ }
4214
+ const mass = Math.max(50, targ.mass ?? 200);
4215
+ const normalized = normalizeVec3(dir);
4216
+ const scale = attacker === targ ? 1600 : 500;
4217
+ const delta = scaleVec3(normalized, scale * knockback / mass);
4218
+ targ.velocity = addVec3(targ.velocity, delta);
4219
+ return delta;
4220
+ }
4221
+ function applyProtection(targ, point, normal, damage, dflags) {
4222
+ let take = damage;
4223
+ let psave = 0;
4224
+ let asave = 0;
4225
+ let remainingCells;
4226
+ let remainingArmor;
4227
+ if (targ.powerArmor) {
4228
+ const result = applyPowerArmor(damage, dflags, point, normal, targ.powerArmor);
4229
+ psave = result.saved;
4230
+ remainingCells = result.remainingCells;
4231
+ take -= psave;
4232
+ }
4233
+ if (targ.regularArmor) {
4234
+ const result = applyRegularArmor(take, dflags, targ.regularArmor);
4235
+ asave = result.saved;
4236
+ remainingArmor = result.remainingArmor;
4237
+ take -= asave;
4238
+ }
4239
+ return [Math.max(0, take), psave, asave, remainingCells, remainingArmor];
4240
+ }
4241
+ function targetCenter(ent) {
4242
+ if (ent.mins && ent.maxs) {
4243
+ return {
4244
+ x: ent.origin.x + (ent.mins.x + ent.maxs.x) * 0.5,
4245
+ y: ent.origin.y + (ent.mins.y + ent.maxs.y) * 0.5,
4246
+ z: ent.origin.z + (ent.mins.z + ent.maxs.z) * 0.5
4247
+ };
4248
+ }
4249
+ return ent.origin;
4250
+ }
4251
+ function T_Damage(targ, inflictor, attacker, dir, point, normal, damage, knockback, dflags, mod, time, multicast) {
4252
+ if (!targ.takedamage) {
4253
+ return null;
4254
+ }
4255
+ const modifier = getDamageModifier(attacker, time);
4256
+ const modifiedDamage = damage * modifier;
4257
+ const modifiedKnockback = knockback * modifier;
4258
+ const protectedByGod = !hasAnyDamageFlag(dflags, 32 /* NO_PROTECTION */) && ((targ.flags ?? 0) & 1 /* GODMODE */) !== 0 && modifiedDamage > 0;
4259
+ if (protectedByGod) {
4260
+ return {
4261
+ take: 0,
4262
+ psave: 0,
4263
+ asave: modifiedDamage,
4264
+ knocked: { x: 0, y: 0, z: 0 },
4265
+ killed: false
4266
+ };
4267
+ }
4268
+ const knocked = applyKnockback(targ, attacker, dir, modifiedKnockback, dflags);
4269
+ let [take, psave, asave, remainingCells, remainingArmor] = applyProtection(targ, point, normal, modifiedDamage, dflags);
4270
+ if (targ.monsterinfo && targ.monsterinfo.freeze_time > time && modifiedDamage > 0) {
4271
+ take = targ.health + 100;
4272
+ psave = 0;
4273
+ asave = 0;
4274
+ }
4275
+ if (targ.powerArmor && remainingCells !== void 0) {
4276
+ targ.powerArmor.cellCount = remainingCells;
4277
+ }
4278
+ if (targ.regularArmor) {
4279
+ targ.regularArmor.armorCount = remainingArmor ?? targ.regularArmor.armorCount;
4280
+ }
4281
+ let actualTake = take;
4282
+ if (actualTake > 0) {
4283
+ targ.health -= actualTake;
4284
+ if (multicast && !hasAnyDamageFlag(dflags, 1024 /* NO_DAMAGE_EFFECTS */)) {
4285
+ if (targ.classname === "player" || targ.monsterinfo) {
4286
+ multicast(point, 1 /* Pvs */, ServerCommand.temp_entity, TempEntity.BLOOD, point, normal);
4287
+ } else {
4288
+ }
4289
+ }
4290
+ }
4291
+ const killed = targ.health <= 0;
4292
+ if (killed) {
4293
+ if (targ.flags && targ.flags & 2 /* IMMORTAL */) {
4294
+ targ.health = Math.max(1, targ.health);
4295
+ } else if (targ.die) {
4296
+ targ.die(targ, inflictor, attacker, actualTake, point, mod);
4297
+ }
4298
+ } else if (actualTake > 0 && targ.pain) {
4299
+ targ.pain(targ, attacker, knockback, actualTake, mod);
4300
+ }
4301
+ return { take: actualTake, psave, asave, knocked, killed, remainingCells, remainingArmor };
4302
+ }
4303
+ function T_RadiusDamage(entities, inflictor, attacker, damage, ignore, radius, dflags, mod, time, options = {}, multicast) {
4304
+ const hits = [];
4305
+ const inflictorCenter = targetCenter(inflictor);
4306
+ const canDamage = options.canDamage ?? (() => true);
4307
+ for (const ent of entities) {
4308
+ if (ent === ignore || !ent.takedamage || !canDamage(ent, inflictor)) {
4309
+ continue;
4310
+ }
4311
+ const entCenter = ent.mins && ent.maxs ? closestPointToBox(inflictorCenter, addVec3(ent.origin, ent.mins), addVec3(ent.origin, ent.maxs)) : targetCenter(ent);
4312
+ const toTarget = subtractVec3(inflictorCenter, entCenter);
4313
+ const distance4 = lengthVec3(toTarget);
4314
+ if (radius > 0 && distance4 > radius) {
4315
+ continue;
4316
+ }
4317
+ const points = damage - 0.5 * distance4;
4318
+ if (points <= 0) {
4319
+ continue;
4320
+ }
4321
+ let adjustedDamage = points;
4322
+ if (ent === attacker) {
4323
+ adjustedDamage = points * 0.5;
4324
+ }
4325
+ const adjustedKnockback = adjustedDamage;
4326
+ const dir = normalizeVec3(subtractVec3(ent.origin, inflictorCenter));
4327
+ const result = T_Damage(ent, inflictor, attacker, dir, entCenter, dir, adjustedDamage, adjustedKnockback, dflags | 1 /* RADIUS */, mod, time, multicast);
4328
+ hits.push({ target: ent, result, appliedDamage: adjustedDamage });
4329
+ }
4330
+ return hits;
4331
+ }
4332
+
4333
+ // src/combat/specialDamage.ts
4334
+ var ZERO2 = { x: 0, y: 0, z: 0 };
4335
+ var EnvironmentalFlags = /* @__PURE__ */ ((EnvironmentalFlags2) => {
4336
+ EnvironmentalFlags2[EnvironmentalFlags2["IN_WATER"] = 1] = "IN_WATER";
4337
+ EnvironmentalFlags2[EnvironmentalFlags2["IMMUNE_LAVA"] = 2] = "IMMUNE_LAVA";
4338
+ EnvironmentalFlags2[EnvironmentalFlags2["IMMUNE_SLIME"] = 4] = "IMMUNE_SLIME";
4339
+ return EnvironmentalFlags2;
4340
+ })(EnvironmentalFlags || {});
4341
+ function applyDamageEvent(target, amount, mod, time) {
4342
+ return T_Damage(target, null, null, ZERO2, target.origin, ZERO2, amount, 0, 2 /* NO_ARMOR */, mod, time);
4343
+ }
4344
+ function applyEnvironmentalDamage(target, nowMs) {
4345
+ const events = [];
4346
+ let flags = target.environmentFlags ?? 0;
4347
+ let enteredWater = false;
4348
+ let leftWater = false;
4349
+ if (target.waterlevel === WaterLevel.None) {
4350
+ if ((flags & 1 /* IN_WATER */) !== 0) {
4351
+ flags &= ~1 /* IN_WATER */;
4352
+ leftWater = true;
4353
+ }
4354
+ if (target.airFinished < nowMs && target.painDebounceTime <= nowMs) {
4355
+ const elapsedSeconds = Math.floor((nowMs - target.airFinished) / 1e3);
4356
+ const amount = Math.min(15, 2 + 2 * elapsedSeconds);
4357
+ const result = applyDamageEvent(target, amount, 17 /* WATER */, nowMs / 1e3);
4358
+ target.painDebounceTime = nowMs + 1e3;
4359
+ events.push({ mod: 17 /* WATER */, amount, result });
4360
+ }
4361
+ } else {
4362
+ target.airFinished = nowMs + 9e3;
4363
+ if ((flags & 1 /* IN_WATER */) === 0) {
4364
+ flags |= 1 /* IN_WATER */;
4365
+ enteredWater = true;
4366
+ target.damageDebounceTime = 0;
4367
+ }
4368
+ if (target.damageDebounceTime <= nowMs) {
4369
+ if ((target.watertype & CONTENTS_LAVA) !== 0 && (flags & 2 /* IMMUNE_LAVA */) === 0) {
4370
+ const amount = 10 * target.waterlevel;
4371
+ const result = applyDamageEvent(target, amount, 19 /* LAVA */, nowMs / 1e3);
4372
+ target.damageDebounceTime = nowMs + 100;
4373
+ events.push({ mod: 19 /* LAVA */, amount, result });
4374
+ } else if ((target.watertype & CONTENTS_SLIME) !== 0 && (flags & 4 /* IMMUNE_SLIME */) === 0) {
4375
+ const amount = 4 * target.waterlevel;
4376
+ const result = applyDamageEvent(target, amount, 18 /* SLIME */, nowMs / 1e3);
4377
+ target.damageDebounceTime = nowMs + 100;
4378
+ events.push({ mod: 18 /* SLIME */, amount, result });
4379
+ }
4380
+ }
4381
+ }
4382
+ target.environmentFlags = flags;
4383
+ return { events, enteredWater, leftWater };
4384
+ }
4385
+ function calculateFallingDamage(context) {
4386
+ const {
4387
+ impactDelta,
4388
+ waterLevel,
4389
+ onLadder = false,
4390
+ isDead = false,
4391
+ isPlayerModel = true,
4392
+ isNoClip = false,
4393
+ grappleBlockingFallDamage = false,
4394
+ clampFreeFall = false,
4395
+ skipDamage = false
4396
+ } = context;
4397
+ if (isDead || !isPlayerModel || isNoClip || grappleBlockingFallDamage || waterLevel === WaterLevel.Under) {
4398
+ return { damage: 0, event: null, fallValue: 0, adjustedDelta: 0 };
4399
+ }
4400
+ let delta = impactDelta * impactDelta * 1e-4;
4401
+ if (waterLevel === WaterLevel.Waist) {
4402
+ delta *= 0.25;
4403
+ } else if (waterLevel === WaterLevel.Feet) {
4404
+ delta *= 0.5;
4405
+ }
4406
+ if (clampFreeFall) {
4407
+ delta = Math.min(30, delta);
4408
+ }
4409
+ if (delta < 1) {
4410
+ return { damage: 0, event: null, fallValue: 0, adjustedDelta: delta };
4411
+ }
4412
+ let event = null;
4413
+ let damage = 0;
4414
+ let fallValue = 0;
4415
+ if (delta < 15) {
4416
+ event = onLadder ? null : "footstep";
4417
+ } else {
4418
+ fallValue = Math.min(delta * 0.5, 40);
4419
+ if (delta > 30) {
4420
+ event = delta >= 55 ? "fallfar" : "fall";
4421
+ damage = Math.max(1, (delta - 30) * 0.5);
4422
+ } else {
4423
+ event = "fallshort";
4424
+ }
4425
+ }
4426
+ if (skipDamage) {
4427
+ damage = 0;
4428
+ }
4429
+ return { damage, event, fallValue, adjustedDelta: delta };
4430
+ }
4431
+ function applyFallingDamage(target, context) {
4432
+ const result = calculateFallingDamage(context);
4433
+ if (result.damage > 0 && !context.skipDamage) {
4434
+ T_Damage(
4435
+ target,
4436
+ null,
4437
+ null,
4438
+ { x: 0, y: 0, z: 1 },
4439
+ target.origin,
4440
+ ZERO2,
4441
+ result.damage,
4442
+ 0,
4443
+ 2 /* NO_ARMOR */,
4444
+ 23 /* FALLING */,
4445
+ 0
4446
+ );
4447
+ }
4448
+ return result;
4449
+ }
4450
+ function applyCrushDamage(crusher, target, options = {}) {
4451
+ const nonLivingDamage = options.nonLivingDamage ?? 1e5;
4452
+ const gibDamage = options.gibDamage ?? 100;
4453
+ const baseDamage = options.baseDamage ?? crusher.dmg ?? 10;
4454
+ const amount = !target.isMonster && !target.isClient ? nonLivingDamage : target.health < 1 ? gibDamage : baseDamage;
4455
+ const result = T_Damage(target, crusher, crusher, ZERO2, target.origin, ZERO2, amount, 1, 0 /* NONE */, 20 /* CRUSH */, 0);
4456
+ return { amount, result };
4457
+ }
4458
+ function absoluteBounds(ent) {
4459
+ const mins = ent.mins ?? ZERO2;
4460
+ const maxs = ent.maxs ?? ZERO2;
4461
+ return {
4462
+ mins: addVec3(ent.origin, mins),
4463
+ maxs: addVec3(ent.origin, maxs)
4464
+ };
4465
+ }
4466
+ function killBox(teleporter, targets, options = {}) {
4467
+ if (teleporter.movetype === 1 /* Noclip */) {
4468
+ return { events: [], cleared: true };
4469
+ }
4470
+ const mod = options.mod ?? 21 /* TELEFRAG */;
4471
+ const teleBounds = absoluteBounds(teleporter);
4472
+ const events = [];
4473
+ let cleared = true;
4474
+ for (const target of targets) {
4475
+ if (target === teleporter || target.inUse === false) {
4476
+ continue;
4477
+ }
4478
+ const solidity = target.solid ?? 0 /* Not */;
4479
+ if (!target.takedamage || solidity === 0 /* Not */ || solidity === 1 /* Trigger */ || solidity === 3 /* Bsp */) {
4480
+ continue;
4481
+ }
4482
+ if (!boxesIntersect(teleBounds, absoluteBounds(target))) {
4483
+ continue;
4484
+ }
4485
+ const result = T_Damage(target, teleporter, teleporter, ZERO2, target.origin, ZERO2, 1e5, 0, 32 /* NO_PROTECTION */, mod, 0);
4486
+ events.push({ target, result });
4487
+ if (!result || !result.killed || target.health > 0) {
4488
+ cleared = false;
4489
+ }
4490
+ }
4491
+ return { events, cleared };
4492
+ }
4493
+
4167
4494
  // src/physics/movement.ts
4168
4495
  var WATER_FRICTION = 2;
4169
4496
  var WATER_GRAVITY_SCALE = 0.1;
@@ -4253,6 +4580,14 @@ function runStep(ent, system, imports, gravity, frametime) {
4253
4580
  }
4254
4581
  timeLeft -= timeLeft * trace.fraction;
4255
4582
  if (trace.plane) {
4583
+ if (trace.plane.normal.z > 0.7 && velocity.z < 0) {
4584
+ const impactDelta = Math.abs(velocity.z);
4585
+ applyFallingDamage(ent, {
4586
+ impactDelta,
4587
+ waterLevel: ent.waterlevel,
4588
+ isDead: ent.deadflag !== 0
4589
+ });
4590
+ }
4256
4591
  velocity = clipVelocityVec3(velocity, trace.plane.normal, 1);
4257
4592
  }
4258
4593
  const speed = velocity.x * velocity.x + velocity.y * velocity.y + velocity.z * velocity.z;
@@ -5381,233 +5716,74 @@ var EntitySystem = class {
5381
5716
  const target = ref.targetIndex === null ? null : indexToEntity.get(ref.targetIndex) ?? null;
5382
5717
  assignField(ref.entity, ref.name, target);
5383
5718
  }
5384
- this.thinkScheduler.restore(snapshot.thinks, (index) => indexToEntity.get(index));
5385
- }
5386
- runTouches() {
5387
- const world = this.pool.world;
5388
- const activeEntities = [];
5389
- for (const entity of this.pool) {
5390
- if (entity === world) continue;
5391
- if (!entity.inUse || entity.freePending || entity.solid === 0 /* Not */) continue;
5392
- activeEntities.push(entity);
5393
- }
5394
- for (const first of activeEntities) {
5395
- const candidates = this.findInBox(first.absmin, first.absmax);
5396
- const firstBounds = computeBounds(first);
5397
- for (const second of candidates) {
5398
- if (first === second) continue;
5399
- if (!first.touch) continue;
5400
- const secondBounds = computeBounds(second);
5401
- if (!boundsIntersect(firstBounds, secondBounds)) continue;
5402
- first.touch(first, second);
5403
- }
5404
- }
5405
- }
5406
- registerTarget(entity) {
5407
- if (!entity.targetname) {
5408
- return;
5409
- }
5410
- let bucket = this.targetNameIndex.get(entity.targetname);
5411
- if (!bucket) {
5412
- bucket = /* @__PURE__ */ new Set();
5413
- this.targetNameIndex.set(entity.targetname, bucket);
5414
- }
5415
- bucket.add(entity);
5416
- }
5417
- unregisterTarget(entity) {
5418
- if (!entity.targetname) {
5419
- return;
5420
- }
5421
- const bucket = this.targetNameIndex.get(entity.targetname);
5422
- if (!bucket) {
5423
- return;
5424
- }
5425
- bucket.delete(entity);
5426
- if (bucket.size === 0) {
5427
- this.targetNameIndex.delete(entity.targetname);
5428
- }
5429
- }
5430
- useTargetsImmediate(entity, activator) {
5431
- if (entity.target) {
5432
- for (const target of this.findByTargetName(entity.target)) {
5433
- if (target === entity) {
5434
- continue;
5435
- }
5436
- target.use?.(target, entity, activator);
5437
- }
5438
- }
5439
- if (entity.killtarget) {
5440
- for (const victim of this.findByTargetName(entity.killtarget)) {
5441
- if (victim === entity) {
5442
- continue;
5443
- }
5444
- this.free(victim);
5445
- }
5446
- }
5447
- }
5448
- };
5449
-
5450
- // src/entities/misc.ts
5451
- init_esm();
5452
-
5453
- // src/combat/damage.ts
5454
- init_esm();
5455
- init_armor();
5456
- init_damageFlags();
5457
- init_esm();
5458
-
5459
- // src/imports.ts
5460
- var MulticastType = /* @__PURE__ */ ((MulticastType2) => {
5461
- MulticastType2[MulticastType2["All"] = 0] = "All";
5462
- MulticastType2[MulticastType2["Pvs"] = 1] = "Pvs";
5463
- MulticastType2[MulticastType2["Phs"] = 2] = "Phs";
5464
- return MulticastType2;
5465
- })(MulticastType || {});
5466
-
5467
- // src/combat/damage.ts
5468
- var EntityDamageFlags = /* @__PURE__ */ ((EntityDamageFlags2) => {
5469
- EntityDamageFlags2[EntityDamageFlags2["GODMODE"] = 1] = "GODMODE";
5470
- EntityDamageFlags2[EntityDamageFlags2["IMMORTAL"] = 2] = "IMMORTAL";
5471
- EntityDamageFlags2[EntityDamageFlags2["NO_KNOCKBACK"] = 4] = "NO_KNOCKBACK";
5472
- EntityDamageFlags2[EntityDamageFlags2["NO_DAMAGE_EFFECTS"] = 8] = "NO_DAMAGE_EFFECTS";
5473
- return EntityDamageFlags2;
5474
- })(EntityDamageFlags || {});
5475
- function getDamageModifier(attacker, time) {
5476
- if (!attacker) {
5477
- return 1;
5478
- }
5479
- const client = attacker.client;
5480
- if (!client) {
5481
- return 1;
5482
- }
5483
- let modifier = 1;
5484
- if (client.quad_time && client.quad_time > time) {
5485
- modifier *= 4;
5486
- }
5487
- if (client.double_time && client.double_time > time) {
5488
- modifier *= 2;
5489
- }
5490
- return modifier;
5491
- }
5492
- function applyKnockback(targ, attacker, dir, knockback, dflags) {
5493
- const hasNoKnockback = hasAnyDamageFlag(dflags, 8 /* NO_KNOCKBACK */) || ((targ.flags ?? 0) & 4 /* NO_KNOCKBACK */) !== 0;
5494
- if (hasNoKnockback || knockback === 0) {
5495
- return { x: 0, y: 0, z: 0 };
5496
- }
5497
- const mass = Math.max(50, targ.mass ?? 200);
5498
- const normalized = normalizeVec3(dir);
5499
- const scale = attacker === targ ? 1600 : 500;
5500
- const delta = scaleVec3(normalized, scale * knockback / mass);
5501
- targ.velocity = addVec3(targ.velocity, delta);
5502
- return delta;
5503
- }
5504
- function applyProtection(targ, point, normal, damage, dflags) {
5505
- let take = damage;
5506
- let psave = 0;
5507
- let asave = 0;
5508
- let remainingCells;
5509
- let remainingArmor;
5510
- if (targ.powerArmor) {
5511
- const result = applyPowerArmor(damage, dflags, point, normal, targ.powerArmor);
5512
- psave = result.saved;
5513
- remainingCells = result.remainingCells;
5514
- take -= psave;
5515
- }
5516
- if (targ.regularArmor) {
5517
- const result = applyRegularArmor(take, dflags, targ.regularArmor);
5518
- asave = result.saved;
5519
- remainingArmor = result.remainingArmor;
5520
- take -= asave;
5521
- }
5522
- return [Math.max(0, take), psave, asave, remainingCells, remainingArmor];
5523
- }
5524
- function targetCenter(ent) {
5525
- if (ent.mins && ent.maxs) {
5526
- return {
5527
- x: ent.origin.x + (ent.mins.x + ent.maxs.x) * 0.5,
5528
- y: ent.origin.y + (ent.mins.y + ent.maxs.y) * 0.5,
5529
- z: ent.origin.z + (ent.mins.z + ent.maxs.z) * 0.5
5530
- };
5531
- }
5532
- return ent.origin;
5533
- }
5534
- function T_Damage(targ, inflictor, attacker, dir, point, normal, damage, knockback, dflags, mod, time, multicast) {
5535
- if (!targ.takedamage) {
5536
- return null;
5537
- }
5538
- const modifier = getDamageModifier(attacker, time);
5539
- const modifiedDamage = damage * modifier;
5540
- const modifiedKnockback = knockback * modifier;
5541
- const protectedByGod = !hasAnyDamageFlag(dflags, 32 /* NO_PROTECTION */) && ((targ.flags ?? 0) & 1 /* GODMODE */) !== 0 && modifiedDamage > 0;
5542
- if (protectedByGod) {
5543
- return {
5544
- take: 0,
5545
- psave: 0,
5546
- asave: modifiedDamage,
5547
- knocked: { x: 0, y: 0, z: 0 },
5548
- killed: false
5549
- };
5550
- }
5551
- const knocked = applyKnockback(targ, attacker, dir, modifiedKnockback, dflags);
5552
- let [take, psave, asave, remainingCells, remainingArmor] = applyProtection(targ, point, normal, modifiedDamage, dflags);
5553
- if (targ.monsterinfo && targ.monsterinfo.freeze_time > time && modifiedDamage > 0) {
5554
- take = targ.health + 100;
5555
- psave = 0;
5556
- asave = 0;
5557
- }
5558
- if (targ.powerArmor && remainingCells !== void 0) {
5559
- targ.powerArmor.cellCount = remainingCells;
5560
- }
5561
- if (targ.regularArmor) {
5562
- targ.regularArmor.armorCount = remainingArmor ?? targ.regularArmor.armorCount;
5719
+ this.thinkScheduler.restore(snapshot.thinks, (index) => indexToEntity.get(index));
5563
5720
  }
5564
- let actualTake = take;
5565
- if (actualTake > 0) {
5566
- targ.health -= actualTake;
5567
- if (multicast && !hasAnyDamageFlag(dflags, 1024 /* NO_DAMAGE_EFFECTS */)) {
5568
- if (targ.classname === "player" || targ.monsterinfo) {
5569
- multicast(point, 1 /* Pvs */, ServerCommand.temp_entity, TempEntity.BLOOD, point, normal);
5570
- } else {
5721
+ runTouches() {
5722
+ const world = this.pool.world;
5723
+ const activeEntities = [];
5724
+ for (const entity of this.pool) {
5725
+ if (entity === world) continue;
5726
+ if (!entity.inUse || entity.freePending || entity.solid === 0 /* Not */) continue;
5727
+ activeEntities.push(entity);
5728
+ }
5729
+ for (const first of activeEntities) {
5730
+ const candidates = this.findInBox(first.absmin, first.absmax);
5731
+ const firstBounds = computeBounds(first);
5732
+ for (const second of candidates) {
5733
+ if (first === second) continue;
5734
+ if (!first.touch) continue;
5735
+ const secondBounds = computeBounds(second);
5736
+ if (!boundsIntersect(firstBounds, secondBounds)) continue;
5737
+ first.touch(first, second);
5571
5738
  }
5572
5739
  }
5573
5740
  }
5574
- const killed = targ.health <= 0;
5575
- if (killed) {
5576
- if (targ.flags && targ.flags & 2 /* IMMORTAL */) {
5577
- targ.health = Math.max(1, targ.health);
5578
- } else if (targ.die) {
5579
- targ.die(targ, inflictor, attacker, actualTake, point, mod);
5741
+ registerTarget(entity) {
5742
+ if (!entity.targetname) {
5743
+ return;
5580
5744
  }
5581
- } else if (actualTake > 0 && targ.pain) {
5582
- targ.pain(targ, attacker, knockback, actualTake, mod);
5745
+ let bucket = this.targetNameIndex.get(entity.targetname);
5746
+ if (!bucket) {
5747
+ bucket = /* @__PURE__ */ new Set();
5748
+ this.targetNameIndex.set(entity.targetname, bucket);
5749
+ }
5750
+ bucket.add(entity);
5583
5751
  }
5584
- return { take: actualTake, psave, asave, knocked, killed, remainingCells, remainingArmor };
5585
- }
5586
- function T_RadiusDamage(entities, inflictor, attacker, damage, ignore, radius, dflags, mod, time, options = {}, multicast) {
5587
- const hits = [];
5588
- const inflictorCenter = targetCenter(inflictor);
5589
- const canDamage = options.canDamage ?? (() => true);
5590
- for (const ent of entities) {
5591
- if (ent === ignore || !ent.takedamage || !canDamage(ent, inflictor)) {
5592
- continue;
5752
+ unregisterTarget(entity) {
5753
+ if (!entity.targetname) {
5754
+ return;
5593
5755
  }
5594
- const entCenter = ent.mins && ent.maxs ? closestPointToBox(inflictorCenter, addVec3(ent.origin, ent.mins), addVec3(ent.origin, ent.maxs)) : targetCenter(ent);
5595
- const toTarget = subtractVec3(inflictorCenter, entCenter);
5596
- const distance4 = lengthVec3(toTarget);
5597
- if (radius > 0 && distance4 > radius) {
5598
- continue;
5756
+ const bucket = this.targetNameIndex.get(entity.targetname);
5757
+ if (!bucket) {
5758
+ return;
5599
5759
  }
5600
- const points = damage - 0.5 * distance4;
5601
- if (points <= 0) {
5602
- continue;
5760
+ bucket.delete(entity);
5761
+ if (bucket.size === 0) {
5762
+ this.targetNameIndex.delete(entity.targetname);
5603
5763
  }
5604
- const adjustedDamage = ent === attacker ? points * 0.5 : points;
5605
- const dir = normalizeVec3(subtractVec3(ent.origin, inflictorCenter));
5606
- const result = T_Damage(ent, inflictor, attacker, dir, entCenter, dir, adjustedDamage, adjustedDamage, dflags | 1 /* RADIUS */, mod, time, multicast);
5607
- hits.push({ target: ent, result, appliedDamage: adjustedDamage });
5608
5764
  }
5609
- return hits;
5610
- }
5765
+ useTargetsImmediate(entity, activator) {
5766
+ if (entity.target) {
5767
+ for (const target of this.findByTargetName(entity.target)) {
5768
+ if (target === entity) {
5769
+ continue;
5770
+ }
5771
+ target.use?.(target, entity, activator);
5772
+ }
5773
+ }
5774
+ if (entity.killtarget) {
5775
+ for (const victim of this.findByTargetName(entity.killtarget)) {
5776
+ if (victim === entity) {
5777
+ continue;
5778
+ }
5779
+ this.free(victim);
5780
+ }
5781
+ }
5782
+ }
5783
+ };
5784
+
5785
+ // src/entities/misc.ts
5786
+ init_esm();
5611
5787
 
5612
5788
  // src/entities/misc/flyers.ts
5613
5789
  init_esm();
@@ -26011,168 +26187,6 @@ function populatePlayerStats(player, timeSeconds) {
26011
26187
  // src/index.ts
26012
26188
  init_esm();
26013
26189
 
26014
- // src/combat/specialDamage.ts
26015
- init_esm();
26016
- var ZERO2 = { x: 0, y: 0, z: 0 };
26017
- var EnvironmentalFlags = /* @__PURE__ */ ((EnvironmentalFlags2) => {
26018
- EnvironmentalFlags2[EnvironmentalFlags2["IN_WATER"] = 1] = "IN_WATER";
26019
- EnvironmentalFlags2[EnvironmentalFlags2["IMMUNE_LAVA"] = 2] = "IMMUNE_LAVA";
26020
- EnvironmentalFlags2[EnvironmentalFlags2["IMMUNE_SLIME"] = 4] = "IMMUNE_SLIME";
26021
- return EnvironmentalFlags2;
26022
- })(EnvironmentalFlags || {});
26023
- function applyDamageEvent(target, amount, mod, time) {
26024
- return T_Damage(target, null, null, ZERO2, target.origin, ZERO2, amount, 0, 2 /* NO_ARMOR */, mod, time);
26025
- }
26026
- function applyEnvironmentalDamage(target, nowMs) {
26027
- const events = [];
26028
- let flags = target.environmentFlags ?? 0;
26029
- let enteredWater = false;
26030
- let leftWater = false;
26031
- if (target.waterlevel === WaterLevel.None) {
26032
- if ((flags & 1 /* IN_WATER */) !== 0) {
26033
- flags &= ~1 /* IN_WATER */;
26034
- leftWater = true;
26035
- }
26036
- if (target.airFinished < nowMs && target.painDebounceTime <= nowMs) {
26037
- const elapsedSeconds = Math.floor((nowMs - target.airFinished) / 1e3);
26038
- const amount = Math.min(15, 2 + 2 * elapsedSeconds);
26039
- const result = applyDamageEvent(target, amount, 17 /* WATER */, nowMs / 1e3);
26040
- target.painDebounceTime = nowMs + 1e3;
26041
- events.push({ mod: 17 /* WATER */, amount, result });
26042
- }
26043
- } else {
26044
- target.airFinished = nowMs + 9e3;
26045
- if ((flags & 1 /* IN_WATER */) === 0) {
26046
- flags |= 1 /* IN_WATER */;
26047
- enteredWater = true;
26048
- target.damageDebounceTime = 0;
26049
- }
26050
- if (target.damageDebounceTime <= nowMs) {
26051
- if ((target.watertype & CONTENTS_LAVA) !== 0 && (flags & 2 /* IMMUNE_LAVA */) === 0) {
26052
- const amount = 10 * target.waterlevel;
26053
- const result = applyDamageEvent(target, amount, 19 /* LAVA */, nowMs / 1e3);
26054
- target.damageDebounceTime = nowMs + 100;
26055
- events.push({ mod: 19 /* LAVA */, amount, result });
26056
- } else if ((target.watertype & CONTENTS_SLIME) !== 0 && (flags & 4 /* IMMUNE_SLIME */) === 0) {
26057
- const amount = 4 * target.waterlevel;
26058
- const result = applyDamageEvent(target, amount, 18 /* SLIME */, nowMs / 1e3);
26059
- target.damageDebounceTime = nowMs + 100;
26060
- events.push({ mod: 18 /* SLIME */, amount, result });
26061
- }
26062
- }
26063
- }
26064
- target.environmentFlags = flags;
26065
- return { events, enteredWater, leftWater };
26066
- }
26067
- function calculateFallingDamage(context) {
26068
- const {
26069
- impactDelta,
26070
- waterLevel,
26071
- onLadder = false,
26072
- isDead = false,
26073
- isPlayerModel = true,
26074
- isNoClip = false,
26075
- grappleBlockingFallDamage = false,
26076
- clampFreeFall = false,
26077
- skipDamage = false
26078
- } = context;
26079
- if (isDead || !isPlayerModel || isNoClip || grappleBlockingFallDamage || waterLevel === WaterLevel.Under) {
26080
- return { damage: 0, event: null, fallValue: 0, adjustedDelta: 0 };
26081
- }
26082
- let delta = impactDelta * impactDelta * 1e-4;
26083
- if (waterLevel === WaterLevel.Waist) {
26084
- delta *= 0.25;
26085
- } else if (waterLevel === WaterLevel.Feet) {
26086
- delta *= 0.5;
26087
- }
26088
- if (clampFreeFall) {
26089
- delta = Math.min(30, delta);
26090
- }
26091
- if (delta < 1) {
26092
- return { damage: 0, event: null, fallValue: 0, adjustedDelta: delta };
26093
- }
26094
- let event = null;
26095
- let damage = 0;
26096
- let fallValue = 0;
26097
- if (delta < 15) {
26098
- event = onLadder ? null : "footstep";
26099
- } else {
26100
- fallValue = Math.min(delta * 0.5, 40);
26101
- if (delta > 30) {
26102
- event = delta >= 55 ? "fallfar" : "fall";
26103
- damage = Math.max(1, (delta - 30) * 0.5);
26104
- } else {
26105
- event = "fallshort";
26106
- }
26107
- }
26108
- if (skipDamage) {
26109
- damage = 0;
26110
- }
26111
- return { damage, event, fallValue, adjustedDelta: delta };
26112
- }
26113
- function applyFallingDamage(target, context) {
26114
- const result = calculateFallingDamage(context);
26115
- if (result.damage > 0 && !context.skipDamage) {
26116
- T_Damage(
26117
- target,
26118
- null,
26119
- null,
26120
- { x: 0, y: 0, z: 1 },
26121
- target.origin,
26122
- ZERO2,
26123
- result.damage,
26124
- 0,
26125
- 2 /* NO_ARMOR */,
26126
- 23 /* FALLING */,
26127
- 0
26128
- );
26129
- }
26130
- return result;
26131
- }
26132
- function applyCrushDamage(crusher, target, options = {}) {
26133
- const nonLivingDamage = options.nonLivingDamage ?? 1e5;
26134
- const gibDamage = options.gibDamage ?? 100;
26135
- const baseDamage = options.baseDamage ?? crusher.dmg ?? 10;
26136
- const amount = !target.isMonster && !target.isClient ? nonLivingDamage : target.health < 1 ? gibDamage : baseDamage;
26137
- const result = T_Damage(target, crusher, crusher, ZERO2, target.origin, ZERO2, amount, 1, 0 /* NONE */, 20 /* CRUSH */, 0);
26138
- return { amount, result };
26139
- }
26140
- function absoluteBounds(ent) {
26141
- const mins = ent.mins ?? ZERO2;
26142
- const maxs = ent.maxs ?? ZERO2;
26143
- return {
26144
- mins: addVec3(ent.origin, mins),
26145
- maxs: addVec3(ent.origin, maxs)
26146
- };
26147
- }
26148
- function killBox(teleporter, targets, options = {}) {
26149
- if (teleporter.movetype === 1 /* Noclip */) {
26150
- return { events: [], cleared: true };
26151
- }
26152
- const mod = options.mod ?? 21 /* TELEFRAG */;
26153
- const teleBounds = absoluteBounds(teleporter);
26154
- const events = [];
26155
- let cleared = true;
26156
- for (const target of targets) {
26157
- if (target === teleporter || target.inUse === false) {
26158
- continue;
26159
- }
26160
- const solidity = target.solid ?? 0 /* Not */;
26161
- if (!target.takedamage || solidity === 0 /* Not */ || solidity === 1 /* Trigger */ || solidity === 3 /* Bsp */) {
26162
- continue;
26163
- }
26164
- if (!boxesIntersect(teleBounds, absoluteBounds(target))) {
26165
- continue;
26166
- }
26167
- const result = T_Damage(target, teleporter, teleporter, ZERO2, target.origin, ZERO2, 1e5, 0, 32 /* NO_PROTECTION */, mod, 0);
26168
- events.push({ target, result });
26169
- if (!result || !result.killed || target.health > 0) {
26170
- cleared = false;
26171
- }
26172
- }
26173
- return { events, cleared };
26174
- }
26175
-
26176
26190
  // src/combat/weapon.ts
26177
26191
  var WeaponType = /* @__PURE__ */ ((WeaponType2) => {
26178
26192
  WeaponType2[WeaponType2["BLASTER"] = 0] = "BLASTER";