Merge branch 'feature/t1126-landing-col-arcs'
@@ -2745,29 +2745,51 @@ GameCore.prototype.fieldSnapshot = function ()
2745
2745
* `col` is optional; a random eligible column is used otherwise.
2746
2746
* Returns the new block, or null if every column is locked or full.
2747
2747
*/
2748
GameCore.prototype.ingestGarbage = function (col)
2748
/**
2749
* Open columns a garbage block can fall into (not locked, not full).
2750
*/
2751
GameCore.prototype.eligibleGarbageColumns = function ()
2749
2752
{
2750
if (this.state !== 'playing')
2753
var eligible = [];
2754
for (var c = 0; c < this.width; c++)
2755
{
2756
if (this.isColumnLocked(c))
2757
{ continue; }
2758
if (this.groundedCount(c) >= this.height)
2759
{ continue; }
2760
eligible.push(c);
2761
}
2762
return eligible;
2763
};
2764
2765
/**
2766
* Choose a garbage column. If `preferred` is still open, it wins;
2767
* otherwise a random eligible column (t1126). Returns null if none.
2768
*/
2769
GameCore.prototype.pickGarbageColumn = function (preferred)
2770
{
2771
var eligible = this.eligibleGarbageColumns();
2772
if (!eligible.length)
2751
2773
{ return null; }
2752
var chosen = null;
2753
if (col != null && col >= 0 && col < this.width
2754
&& !this.isColumnLocked(col) && this.groundedCount(col) < this.height)
2755
{ chosen = col | 0; }
2756
else
2774
if (preferred != null && isFinite(preferred))
2757
2775
{
2758
var eligible = [];
2759
for (var c = 0; c < this.width; c++)
2776
var want = preferred | 0;
2777
for (var i = 0; i < eligible.length; i++)
2760
2778
{
2761
if (this.isColumnLocked(c))
2762
{ continue; }
2763
if (this.groundedCount(c) >= this.height)
2764
{ continue; }
2765
eligible.push(c);
2779
if (eligible[i] === want)
2780
{ return want; }
2766
2781
}
2767
if (!eligible.length)
2768
{ return null; }
2769
chosen = eligible[Math.floor(this.rng() * eligible.length) % eligible.length];
2770
2782
}
2783
return eligible[Math.floor(this.rng() * eligible.length) % eligible.length];
2784
};
2785
2786
GameCore.prototype.ingestGarbage = function (col)
2787
{
2788
if (this.state !== 'playing')
2789
{ return null; }
2790
var chosen = this.pickGarbageColumn(col);
2791
if (chosen == null)
2792
{ return null; }
2771
2793
var block = this.createBlock(chosen, this.height, COLOR_GRAY, STATE_FALLING);
2772
2794
block.vy = -this.planet.fallSpeed;
2773
2795
block.flame = false;
@@ -3770,6 +3792,9 @@ var EDGE = 16;
3770
3792
var MIN_TILE_FOR_SIDES = 18;
3771
3793
var MIN_VIEWPORT_FOR_SIDES = 960;
3772
3794
var LABEL_H = 32;
3795
/* Extra space above the field in the wide (sides) layout so
3796
enemy↔player arcs can route around the top edge (t1129). */
3797
var ARC_TOP_PAD = 100;
3773
3798
3774
3799
function canvasSize (n, mode, availH)
3775
3800
{
@@ -3864,7 +3889,8 @@ function plan (vw, vh, n, hudH, margin)
3864
3889
var availHSide = Math.max(80, vh - hudH - margin);
3865
3890
var probe = canvasSize(n, 'sides', availHSide);
3866
3891
var availWSide = Math.max(80, vw - margin * 2 - 2 * (probe.outerW + GAP));
3867
var tileSide = Math.max(14, Math.floor(Math.min(availWSide / 10, availHSide / 13)));
3892
var availHForField = Math.max(80, availHSide - ARC_TOP_PAD);
3893
var tileSide = Math.max(14, Math.floor(Math.min(availWSide / 10, availHForField / 13)));
3868
3894
var fieldWSide = tileSide * 10;
3869
3895
var fieldHSide = tileSide * 13;
3870
3896
var leftover = (vw - fieldWSide) / 2;
@@ -3873,9 +3899,10 @@ function plan (vw, vh, n, hudH, margin)
3873
3899
&& tileSide >= MIN_TILE_FOR_SIDES)
3874
3900
{
3875
3901
var fieldX = Math.floor((vw - fieldWSide) / 2);
3876
var fieldY = hudH + Math.floor((availHSide - fieldHSide) / 2);
3877
if (fieldY < hudH)
3878
{ fieldY = hudH; }
3902
var fieldY = hudH + ARC_TOP_PAD
3903
+ Math.floor((availHForField - fieldHSide) / 2);
3904
if (fieldY < hudH + ARC_TOP_PAD)
3905
{ fieldY = hudH + ARC_TOP_PAD; }
3879
3906
return finish('sides', tileSide, fieldX, fieldY, 0, probe,
3880
3907
sidePositions(n, fieldX, fieldY, fieldWSide, fieldHSide, probe, hudH));
3881
3908
}
@@ -3907,6 +3934,7 @@ var api = {
3907
3934
EDGE: EDGE,
3908
3935
MIN_TILE_FOR_SIDES: MIN_TILE_FOR_SIDES,
3909
3936
MIN_VIEWPORT_FOR_SIDES: MIN_VIEWPORT_FOR_SIDES,
3937
ARC_TOP_PAD: ARC_TOP_PAD,
3910
3938
LABEL_H: LABEL_H,
3911
3939
canvasSize: canvasSize,
3912
3940
sidePositions: sidePositions,
@@ -4421,6 +4449,174 @@ Online.easeInOutCubic = function (t)
4421
4449
return 1 - (u * u * u) / 2;
4422
4450
};
4423
4451
4452
/** Bounding box of the player's field in viewport pixels. */
4453
Online.playerFieldRect = function ()
4454
{
4455
var appRef = typeof app !== 'undefined' ? app : null;
4456
var canvas = appRef && appRef.scene && appRef.scene.canvas;
4457
if (canvas && canvas.getBoundingClientRect)
4458
{ return canvas.getBoundingClientRect(); }
4459
if (appRef && appRef.fieldW)
4460
{
4461
return {
4462
left: appRef.fieldX,
4463
top: appRef.fieldY,
4464
right: appRef.fieldX + appRef.fieldW,
4465
bottom: appRef.fieldY + appRef.fieldH,
4466
width: appRef.fieldW,
4467
height: appRef.fieldH
4468
};
4469
}
4470
return null;
4471
};
4472
4473
/**
4474
* True if (x, y) is inside the field's interior. The top edge (a few
4475
* pixels) is not interior: that is where arcs may land (t1128).
4476
*/
4477
Online.pointInFieldInterior = function (x, y, field, slop)
4478
{
4479
if (!field)
4480
{ return false; }
4481
slop = slop == null ? 6 : slop;
4482
return x > field.left + 0.5 && x < field.right - 0.5
4483
&& y > field.top + slop && y < field.bottom - 0.5;
4484
};
4485
4486
/**
4487
* Waypoints that route a player↔enemy arc around the field, never
4488
* through its interior: up the outside, across above the top edge,
4489
* then into the target (t1128). If both ends already sit at or above
4490
* the top, a simple two-point path is enough.
4491
*/
4492
Online.waypointsAroundField = function (start, end, field, clearance)
4493
{
4494
if (!start || !end)
4495
{ return [start || { x: 0, y: 0 }, end || { x: 0, y: 0 }]; }
4496
if (!field)
4497
{ return [start, end]; }
4498
clearance = clearance || 64;
4499
var top = field.top;
4500
var left = field.left;
4501
var right = field.right;
4502
var pad = 10;
4503
var apexY = Math.min(start.y, end.y, top) - clearance;
4504
if (apexY < 8)
4505
{ apexY = Math.max(8, top - Math.max(24, clearance * 0.5)); }
4506
4507
if (start.y <= top + 6 && end.y <= top + 6)
4508
{ return [start, end]; }
4509
4510
var w1x = start.x;
4511
var w2x = end.x;
4512
if (start.x < left)
4513
{ w1x = Math.min(start.x, left - pad); }
4514
else if (start.x > right)
4515
{ w1x = Math.max(start.x, right + pad); }
4516
if (end.x < left)
4517
{ w2x = Math.min(end.x, left - pad); }
4518
else if (end.x > right)
4519
{ w2x = Math.max(end.x, right + pad); }
4520
4521
return [
4522
start,
4523
{ x: w1x, y: apexY },
4524
{ x: w2x, y: apexY },
4525
end
4526
];
4527
};
4528
4529
/**
4530
* Point at parameter u ∈ [0, 1] along a polyline, with a small upward
4531
* bulge on each segment so the path reads as a "boogje".
4532
*/
4533
Online.pointOnPath = function (points, u)
4534
{
4535
u = u < 0 ? 0 : (u > 1 ? 1 : u);
4536
if (!points || !points.length)
4537
{ return { x: 0, y: 0 }; }
4538
if (points.length === 1)
4539
{ return { x: points[0].x, y: points[0].y }; }
4540
var lens = [];
4541
var total = 0;
4542
for (var i = 1; i < points.length; i++)
4543
{
4544
var dx = points[i].x - points[i - 1].x;
4545
var dy = points[i].y - points[i - 1].y;
4546
var L = Math.sqrt(dx * dx + dy * dy);
4547
if (L < 1)
4548
{ L = 1; }
4549
lens.push(L);
4550
total += L;
4551
}
4552
var dist = u * total;
4553
var acc = 0;
4554
for (var i = 0; i < lens.length; i++)
4555
{
4556
if (acc + lens[i] >= dist || i === lens.length - 1)
4557
{
4558
var t = (dist - acc) / lens[i];
4559
if (t < 0)
4560
{ t = 0; }
4561
if (t > 1)
4562
{ t = 1; }
4563
var a = points[i];
4564
var b = points[i + 1];
4565
var bump = 4 * 16 * t * (1 - t);
4566
return {
4567
x: a.x + (b.x - a.x) * t,
4568
y: a.y + (b.y - a.y) * t - bump
4569
};
4570
}
4571
acc += lens[i];
4572
}
4573
var last = points[points.length - 1];
4574
return { x: last.x, y: last.y };
4575
};
4576
4577
/** Sample a player↔enemy path; used by tests and the ticker. */
4578
Online.aroundFieldPoint = function (start, end, u, field, clearance)
4579
{
4580
var pts = this.waypointsAroundField(start, end, field, clearance);
4581
if (pts.length === 2)
4582
{
4583
var h = this.arcHeight(start, end);
4584
return this.arcPoint(start, end, u, h);
4585
}
4586
return this.pointOnPath(pts, u);
4587
};
4588
4589
Online.rememberLandCol = function (id, col)
4590
{
4591
if (id == null || col == null || !isFinite(col))
4592
{ return; }
4593
if (!this._pendingLandCol)
4594
{ this._pendingLandCol = Object.create(null); }
4595
this._pendingLandCol[String(id)] = col | 0;
4596
};
4597
4598
/** Resolve the landing column for an incoming shot (t1126). */
4599
Online.takeLandCol = function (incoming)
4600
{
4601
if (!incoming)
4602
{ return null; }
4603
if (incoming.land_col != null && isFinite(incoming.land_col))
4604
{ return incoming.land_col | 0; }
4605
if (!this._pendingLandCol)
4606
{ return null; }
4607
var keys = [];
4608
if (incoming.id != null)
4609
{ keys.push(String(incoming.id)); }
4610
if (incoming.client_id)
4611
{ keys.push(String(incoming.client_id)); }
4612
for (var i = 0; i < keys.length; i++)
4613
{
4614
if (this._pendingLandCol[keys[i]] != null)
4615
{ return this._pendingLandCol[keys[i]]; }
4616
}
4617
return null;
4618
};
4619
4424
4620
Online._miniCellSize = function (playerId)
4425
4621
{
4426
4622
var el = this.miniElement(playerId);
@@ -4495,6 +4691,21 @@ Online.spawnFlights = function (results, locals)
4495
4691
if (r.age != null && isFinite(r.age) && r.age * 1000 >= duration)
4496
4692
{ continue; }
4497
4693
4694
var landCol = null;
4695
if (r.land_col != null && isFinite(r.land_col))
4696
{ landCol = r.land_col | 0; }
4697
else if (meta.land_col != null && isFinite(meta.land_col))
4698
{ landCol = meta.land_col | 0; }
4699
else if (kind === 'enemy-to-player'
4700
&& typeof app !== 'undefined' && app.core && app.core.pickGarbageColumn)
4701
{ landCol = app.core.pickGarbageColumn(); }
4702
if (landCol != null)
4703
{
4704
this.rememberLandCol(sid, landCol);
4705
if (r.client_id)
4706
{ this.rememberLandCol(r.client_id, landCol); }
4707
}
4708
4498
4709
var start;
4499
4710
if (meta.startX != null && isFinite(meta.startX))
4500
4711
{ start = { x: meta.startX, y: meta.startY }; }
@@ -4507,9 +4718,15 @@ Online.spawnFlights = function (results, locals)
4507
4718
if (miss)
4508
4719
{ end = this._missEnd(start, kind === 'enemy-miss'); }
4509
4720
else if (kind === 'enemy-to-player')
4510
{ end = this._fieldTop(null); }
4721
{ end = this._fieldTop(landCol != null ? landCol : 4.5); }
4511
4722
else
4512
{ end = this._targetEnd(targetId, start); }
4723
{ end = this._targetEnd(targetId, start, landCol); }
4724
4725
// Hits are ingested as grey garbage; draw them grey (t1130).
4726
// Misses keep the sender's colour — nothing is received.
4727
var flightColor = miss
4728
? (r.color != null ? r.color : meta.color)
4729
: -1;
4513
4730
4514
4731
var startScale;
4515
4732
var endScale;
@@ -4544,7 +4761,7 @@ Online.spawnFlights = function (results, locals)
4544
4761
4545
4762
var layer = (kind === 'enemy-to-enemy' && back) ? back : front;
4546
4763
var el = document.createElement('img');
4547
el.src = colorSpriteUrl(r.color != null ? r.color : meta.color);
4764
el.src = colorSpriteUrl(flightColor);
4548
4765
el.alt = '';
4549
4766
el.className = 'flight' + (kind === 'enemy-to-enemy' ? ' flight-behind' : '');
4550
4767
el.style.width = full + 'px';
@@ -4560,6 +4777,9 @@ Online.spawnFlights = function (results, locals)
4560
4777
var height = miss
4561
4778
? Math.max(40, Math.min(160, Math.abs(end.y - start.y) * 0.35))
4562
4779
: this.arcHeight(start, end);
4780
var field = this.playerFieldRect();
4781
var around = !miss && (kind === 'enemy-to-player' || kind === 'player-to-enemy');
4782
var waypoints = around ? this.waypointsAroundField(start, end, field, height * 0.45) : null;
4563
4783
this._flights.push({
4564
4784
el: el,
4565
4785
start: start,
@@ -4574,7 +4794,11 @@ Online.spawnFlights = function (results, locals)
4574
4794
startScale: startScale,
4575
4795
endScale: endScale,
4576
4796
angle: Math.random() * 360,
4577
id: sid
4797
id: sid,
4798
landCol: landCol,
4799
field: field,
4800
waypoints: waypoints,
4801
color: flightColor
4578
4802
});
4579
4803
}
4580
4804
this._flightLocals = {};
@@ -4616,14 +4840,17 @@ Online._flightStart = function (col)
4616
4840
return { x: window.innerWidth / 2, y: window.innerHeight * 0.3 };
4617
4841
};
4618
4842
4619
Online._targetEnd = function (targetId, start)
4843
Online._targetEnd = function (targetId, start, col)
4620
4844
{
4621
4845
var el = targetId && this.miniElement(targetId);
4622
4846
if (el)
4623
4847
{
4624
4848
var canvas = el.querySelector('canvas') || el;
4625
4849
var r = canvas.getBoundingClientRect();
4626
return { x: r.left + r.width / 2, y: r.top + r.height / 2 };
4850
var x = r.left + r.width / 2;
4851
if (col != null && isFinite(col))
4852
{ x = r.left + ((col + 0.5) / 10) * r.width; }
4853
return { x: x, y: r.top + 4 };
4627
4854
}
4628
4855
return { x: start.x + (Math.random() - 0.5) * 80, y: 40 };
4629
4856
};
@@ -4683,6 +4910,18 @@ Online.tickFlights = function (now)
4683
4910
x = mt * mt * f.start.x + 2 * mt * e * f.ctrl.x + e * e * f.end.x;
4684
4911
y = mt * mt * f.start.y + 2 * mt * e * f.ctrl.y + e * e * f.end.y;
4685
4912
}
4913
else if (f.waypoints && f.waypoints.length > 2)
4914
{
4915
var pt = this.pointOnPath(f.waypoints, u);
4916
x = pt.x;
4917
y = pt.y;
4918
}
4919
else if (f.waypoints && f.field)
4920
{
4921
var pt = this.aroundFieldPoint(f.start, f.end, u, f.field, (f.height || 80) * 0.45);
4922
x = pt.x;
4923
y = pt.y;
4924
}
4686
4925
else
4687
4926
{
4688
4927
var pt = this.arcPoint(f.start, f.end, u, f.height || 80);
@@ -4725,6 +4964,7 @@ Online.clearFlights = function ()
4725
4964
this._flights = [];
4726
4965
this._flightLocals = {};
4727
4966
this._flightSeen = Object.create(null);
4967
this._pendingLandCol = Object.create(null);
4728
4968
};
4729
4969
4730
4970
if (typeof globalThis !== 'undefined')
@@ -5184,6 +5424,9 @@ OfflineBattle.prototype._dispatchShots = function (fromId, core, planet, playerC
5184
5424
target = targets[idx];
5185
5425
}
5186
5426
var clientId = fromId + '-' + shot.id + '-' + this.clock;
5427
var landCol = null;
5428
if (!miss && target && target.core && target.core.pickGarbageColumn)
5429
{ landCol = target.core.pickGarbageColumn(); }
5187
5430
var result = {
5188
5431
client_id: clientId,
5189
5432
miss: miss,
@@ -5192,7 +5435,8 @@ OfflineBattle.prototype._dispatchShots = function (fromId, core, planet, playerC
5192
5435
flight_duration: FLIGHT_DURATION,
5193
5436
from_id: fromId,
5194
5437
col: shot.col,
5195
y: shot.y
5438
y: shot.y,
5439
land_col: landCol
5196
5440
};
5197
5441
this.flightResults.push(result);
5198
5442
this.shotLocals.push({
@@ -5200,7 +5444,8 @@ OfflineBattle.prototype._dispatchShots = function (fromId, core, planet, playerC
5200
5444
col: shot.col,
5201
5445
y: shot.y,
5202
5446
color: shot.color,
5203
from_id: fromId
5447
from_id: fromId,
5448
land_col: landCol
5204
5449
});
5205
5450
if (!miss && target)
5206
5451
{
@@ -5208,7 +5453,8 @@ OfflineBattle.prototype._dispatchShots = function (fromId, core, planet, playerC
5208
5453
at: this.clock + FLIGHT_DURATION,
5209
5454
targetId: target.id,
5210
5455
color: shot.color,
5211
fromId: fromId
5456
fromId: fromId,
5457
landCol: landCol
5212
5458
});
5213
5459
}
5214
5460
}
@@ -5227,7 +5473,7 @@ OfflineBattle.prototype._deliver = function (playerCore)
5227
5473
}
5228
5474
var core = this.coreFor(ev.targetId, playerCore);
5229
5475
if (core && core.state === 'playing' && core.ingestGarbage)
5230
{ core.ingestGarbage(); }
5476
{ core.ingestGarbage(ev.landCol); }
5231
5477
}
5232
5478
this.pending = keep;
5233
5479
};
@@ -6716,7 +6962,8 @@ function tickOffline (dt)
6716
6962
color: s.color,
6717
6963
startX: start.x,
6718
6964
startY: start.y,
6719
from_id: s.from_id
6965
from_id: s.from_id,
6966
land_col: s.land_col
6720
6967
};
6721
6968
}
6722
6969
Online.spawnFlights(result.flights, locals);
@@ -7149,7 +7396,10 @@ function bindOnlineUi ()
7149
7396
if (!app.core || app.core.state !== 'playing')
7150
7397
{ return; }
7151
7398
for (var i = 0; i < incoming.length; i++)
7152
{ app.core.ingestGarbage(); }
7399
{
7400
var col = Online.takeLandCol ? Online.takeLandCol(incoming[i]) : incoming[i].land_col;
7401
app.core.ingestGarbage(col);
7402
}
7153
7403
};
7154
7404
Online.onFinished = function (lobby)
7155
7405
{ showPodium(lobby); };
@@ -2745,29 +2745,51 @@ GameCore.prototype.fieldSnapshot = function ()2745
* `col` is optional; a random eligible column is used otherwise.2745
* `col` is optional; a random eligible column is used otherwise.2746
* Returns the new block, or null if every column is locked or full.2746
* Returns the new block, or null if every column is locked or full.2747
*/2747
*/2748
GameCore.prototype.ingestGarbage = function (col)2748
/**2749
* Open columns a garbage block can fall into (not locked, not full).2750
*/2751
GameCore.prototype.eligibleGarbageColumns = function ()2749
{2752
{2750
if (this.state !== 'playing')2753
var eligible = [];2754
for (var c = 0; c < this.width; c++)2755
{2756
if (this.isColumnLocked(c))2757
{ continue; }2758
if (this.groundedCount(c) >= this.height)2759
{ continue; }2760
eligible.push(c);2761
}2762
return eligible;2763
};2764
2765
/**2766
* Choose a garbage column. If `preferred` is still open, it wins;2767
* otherwise a random eligible column (t1126). Returns null if none.2768
*/2769
GameCore.prototype.pickGarbageColumn = function (preferred)2770
{2771
var eligible = this.eligibleGarbageColumns();2772
if (!eligible.length)2751
{ return null; }2773
{ return null; }2752
var chosen = null;2774
if (preferred != null && isFinite(preferred))2753
if (col != null && col >= 0 && col < this.width2754
&& !this.isColumnLocked(col) && this.groundedCount(col) < this.height)2755
{ chosen = col | 0; }2756
else2757
{2775
{2758
var eligible = [];2776
var want = preferred | 0;2759
for (var c = 0; c < this.width; c++)2777
for (var i = 0; i < eligible.length; i++)2760
{2778
{2761
if (this.isColumnLocked(c))2779
if (eligible[i] === want)2762
{ continue; }2780
{ return want; }2763
if (this.groundedCount(c) >= this.height)2764
{ continue; }2765
eligible.push(c);2766
}2781
}2767
if (!eligible.length)2768
{ return null; }2769
chosen = eligible[Math.floor(this.rng() * eligible.length) % eligible.length];2770
}2782
}2783
return eligible[Math.floor(this.rng() * eligible.length) % eligible.length];2784
};2785
2786
GameCore.prototype.ingestGarbage = function (col)2787
{2788
if (this.state !== 'playing')2789
{ return null; }2790
var chosen = this.pickGarbageColumn(col);2791
if (chosen == null)2792
{ return null; }2771
var block = this.createBlock(chosen, this.height, COLOR_GRAY, STATE_FALLING);2793
var block = this.createBlock(chosen, this.height, COLOR_GRAY, STATE_FALLING);2772
block.vy = -this.planet.fallSpeed;2794
block.vy = -this.planet.fallSpeed;2773
block.flame = false;2795
block.flame = false;@@ -3770,6 +3792,9 @@ var EDGE = 16;3770
var MIN_TILE_FOR_SIDES = 18;3792
var MIN_TILE_FOR_SIDES = 18;3771
var MIN_VIEWPORT_FOR_SIDES = 960;3793
var MIN_VIEWPORT_FOR_SIDES = 960;3772
var LABEL_H = 32;3794
var LABEL_H = 32;3795
/* Extra space above the field in the wide (sides) layout so3796
enemy↔player arcs can route around the top edge (t1129). */3797
var ARC_TOP_PAD = 100;3773
3798
3774
function canvasSize (n, mode, availH)3799
function canvasSize (n, mode, availH)3775
{3800
{@@ -3864,7 +3889,8 @@ function plan (vw, vh, n, hudH, margin)3864
var availHSide = Math.max(80, vh - hudH - margin);3889
var availHSide = Math.max(80, vh - hudH - margin);3865
var probe = canvasSize(n, 'sides', availHSide);3890
var probe = canvasSize(n, 'sides', availHSide);3866
var availWSide = Math.max(80, vw - margin * 2 - 2 * (probe.outerW + GAP));3891
var availWSide = Math.max(80, vw - margin * 2 - 2 * (probe.outerW + GAP));3867
var tileSide = Math.max(14, Math.floor(Math.min(availWSide / 10, availHSide / 13)));3892
var availHForField = Math.max(80, availHSide - ARC_TOP_PAD);3893
var tileSide = Math.max(14, Math.floor(Math.min(availWSide / 10, availHForField / 13)));3868
var fieldWSide = tileSide * 10;3894
var fieldWSide = tileSide * 10;3869
var fieldHSide = tileSide * 13;3895
var fieldHSide = tileSide * 13;3870
var leftover = (vw - fieldWSide) / 2;3896
var leftover = (vw - fieldWSide) / 2;@@ -3873,9 +3899,10 @@ function plan (vw, vh, n, hudH, margin)3873
&& tileSide >= MIN_TILE_FOR_SIDES)3899
&& tileSide >= MIN_TILE_FOR_SIDES)3874
{3900
{3875
var fieldX = Math.floor((vw - fieldWSide) / 2);3901
var fieldX = Math.floor((vw - fieldWSide) / 2);3876
var fieldY = hudH + Math.floor((availHSide - fieldHSide) / 2);3902
var fieldY = hudH + ARC_TOP_PAD3877
if (fieldY < hudH)3903
+ Math.floor((availHForField - fieldHSide) / 2);3878
{ fieldY = hudH; }3904
if (fieldY < hudH + ARC_TOP_PAD)3905
{ fieldY = hudH + ARC_TOP_PAD; }3879
return finish('sides', tileSide, fieldX, fieldY, 0, probe,3906
return finish('sides', tileSide, fieldX, fieldY, 0, probe,3880
sidePositions(n, fieldX, fieldY, fieldWSide, fieldHSide, probe, hudH));3907
sidePositions(n, fieldX, fieldY, fieldWSide, fieldHSide, probe, hudH));3881
}3908
}@@ -3907,6 +3934,7 @@ var api = {3907
EDGE: EDGE,3934
EDGE: EDGE,3908
MIN_TILE_FOR_SIDES: MIN_TILE_FOR_SIDES,3935
MIN_TILE_FOR_SIDES: MIN_TILE_FOR_SIDES,3909
MIN_VIEWPORT_FOR_SIDES: MIN_VIEWPORT_FOR_SIDES,3936
MIN_VIEWPORT_FOR_SIDES: MIN_VIEWPORT_FOR_SIDES,3937
ARC_TOP_PAD: ARC_TOP_PAD,3910
LABEL_H: LABEL_H,3938
LABEL_H: LABEL_H,3911
canvasSize: canvasSize,3939
canvasSize: canvasSize,3912
sidePositions: sidePositions,3940
sidePositions: sidePositions,@@ -4421,6 +4449,174 @@ Online.easeInOutCubic = function (t)4421
return 1 - (u * u * u) / 2;4449
return 1 - (u * u * u) / 2;4422
};4450
};4423
4451
4452
/** Bounding box of the player's field in viewport pixels. */4453
Online.playerFieldRect = function ()4454
{4455
var appRef = typeof app !== 'undefined' ? app : null;4456
var canvas = appRef && appRef.scene && appRef.scene.canvas;4457
if (canvas && canvas.getBoundingClientRect)4458
{ return canvas.getBoundingClientRect(); }4459
if (appRef && appRef.fieldW)4460
{4461
return {4462
left: appRef.fieldX,4463
top: appRef.fieldY,4464
right: appRef.fieldX + appRef.fieldW,4465
bottom: appRef.fieldY + appRef.fieldH,4466
width: appRef.fieldW,4467
height: appRef.fieldH4468
};4469
}4470
return null;4471
};4472
4473
/**4474
* True if (x, y) is inside the field's interior. The top edge (a few4475
* pixels) is not interior: that is where arcs may land (t1128).4476
*/4477
Online.pointInFieldInterior = function (x, y, field, slop)4478
{4479
if (!field)4480
{ return false; }4481
slop = slop == null ? 6 : slop;4482
return x > field.left + 0.5 && x < field.right - 0.54483
&& y > field.top + slop && y < field.bottom - 0.5;4484
};4485
4486
/**4487
* Waypoints that route a player↔enemy arc around the field, never4488
* through its interior: up the outside, across above the top edge,4489
* then into the target (t1128). If both ends already sit at or above4490
* the top, a simple two-point path is enough.4491
*/4492
Online.waypointsAroundField = function (start, end, field, clearance)4493
{4494
if (!start || !end)4495
{ return [start || { x: 0, y: 0 }, end || { x: 0, y: 0 }]; }4496
if (!field)4497
{ return [start, end]; }4498
clearance = clearance || 64;4499
var top = field.top;4500
var left = field.left;4501
var right = field.right;4502
var pad = 10;4503
var apexY = Math.min(start.y, end.y, top) - clearance;4504
if (apexY < 8)4505
{ apexY = Math.max(8, top - Math.max(24, clearance * 0.5)); }4506
4507
if (start.y <= top + 6 && end.y <= top + 6)4508
{ return [start, end]; }4509
4510
var w1x = start.x;4511
var w2x = end.x;4512
if (start.x < left)4513
{ w1x = Math.min(start.x, left - pad); }4514
else if (start.x > right)4515
{ w1x = Math.max(start.x, right + pad); }4516
if (end.x < left)4517
{ w2x = Math.min(end.x, left - pad); }4518
else if (end.x > right)4519
{ w2x = Math.max(end.x, right + pad); }4520
4521
return [4522
start,4523
{ x: w1x, y: apexY },4524
{ x: w2x, y: apexY },4525
end4526
];4527
};4528
4529
/**4530
* Point at parameter u ∈ [0, 1] along a polyline, with a small upward4531
* bulge on each segment so the path reads as a "boogje".4532
*/4533
Online.pointOnPath = function (points, u)4534
{4535
u = u < 0 ? 0 : (u > 1 ? 1 : u);4536
if (!points || !points.length)4537
{ return { x: 0, y: 0 }; }4538
if (points.length === 1)4539
{ return { x: points[0].x, y: points[0].y }; }4540
var lens = [];4541
var total = 0;4542
for (var i = 1; i < points.length; i++)4543
{4544
var dx = points[i].x - points[i - 1].x;4545
var dy = points[i].y - points[i - 1].y;4546
var L = Math.sqrt(dx * dx + dy * dy);4547
if (L < 1)4548
{ L = 1; }4549
lens.push(L);4550
total += L;4551
}4552
var dist = u * total;4553
var acc = 0;4554
for (var i = 0; i < lens.length; i++)4555
{4556
if (acc + lens[i] >= dist || i === lens.length - 1)4557
{4558
var t = (dist - acc) / lens[i];4559
if (t < 0)4560
{ t = 0; }4561
if (t > 1)4562
{ t = 1; }4563
var a = points[i];4564
var b = points[i + 1];4565
var bump = 4 * 16 * t * (1 - t);4566
return {4567
x: a.x + (b.x - a.x) * t,4568
y: a.y + (b.y - a.y) * t - bump4569
};4570
}4571
acc += lens[i];4572
}4573
var last = points[points.length - 1];4574
return { x: last.x, y: last.y };4575
};4576
4577
/** Sample a player↔enemy path; used by tests and the ticker. */4578
Online.aroundFieldPoint = function (start, end, u, field, clearance)4579
{4580
var pts = this.waypointsAroundField(start, end, field, clearance);4581
if (pts.length === 2)4582
{4583
var h = this.arcHeight(start, end);4584
return this.arcPoint(start, end, u, h);4585
}4586
return this.pointOnPath(pts, u);4587
};4588
4589
Online.rememberLandCol = function (id, col)4590
{4591
if (id == null || col == null || !isFinite(col))4592
{ return; }4593
if (!this._pendingLandCol)4594
{ this._pendingLandCol = Object.create(null); }4595
this._pendingLandCol[String(id)] = col | 0;4596
};4597
4598
/** Resolve the landing column for an incoming shot (t1126). */4599
Online.takeLandCol = function (incoming)4600
{4601
if (!incoming)4602
{ return null; }4603
if (incoming.land_col != null && isFinite(incoming.land_col))4604
{ return incoming.land_col | 0; }4605
if (!this._pendingLandCol)4606
{ return null; }4607
var keys = [];4608
if (incoming.id != null)4609
{ keys.push(String(incoming.id)); }4610
if (incoming.client_id)4611
{ keys.push(String(incoming.client_id)); }4612
for (var i = 0; i < keys.length; i++)4613
{4614
if (this._pendingLandCol[keys[i]] != null)4615
{ return this._pendingLandCol[keys[i]]; }4616
}4617
return null;4618
};4619
4424
Online._miniCellSize = function (playerId)4620
Online._miniCellSize = function (playerId)4425
{4621
{4426
var el = this.miniElement(playerId);4622
var el = this.miniElement(playerId);@@ -4495,6 +4691,21 @@ Online.spawnFlights = function (results, locals)4495
if (r.age != null && isFinite(r.age) && r.age * 1000 >= duration)4691
if (r.age != null && isFinite(r.age) && r.age * 1000 >= duration)4496
{ continue; }4692
{ continue; }4497
4693
4694
var landCol = null;4695
if (r.land_col != null && isFinite(r.land_col))4696
{ landCol = r.land_col | 0; }4697
else if (meta.land_col != null && isFinite(meta.land_col))4698
{ landCol = meta.land_col | 0; }4699
else if (kind === 'enemy-to-player'4700
&& typeof app !== 'undefined' && app.core && app.core.pickGarbageColumn)4701
{ landCol = app.core.pickGarbageColumn(); }4702
if (landCol != null)4703
{4704
this.rememberLandCol(sid, landCol);4705
if (r.client_id)4706
{ this.rememberLandCol(r.client_id, landCol); }4707
}4708
4498
var start;4709
var start;4499
if (meta.startX != null && isFinite(meta.startX))4710
if (meta.startX != null && isFinite(meta.startX))4500
{ start = { x: meta.startX, y: meta.startY }; }4711
{ start = { x: meta.startX, y: meta.startY }; }@@ -4507,9 +4718,15 @@ Online.spawnFlights = function (results, locals)4507
if (miss)4718
if (miss)4508
{ end = this._missEnd(start, kind === 'enemy-miss'); }4719
{ end = this._missEnd(start, kind === 'enemy-miss'); }4509
else if (kind === 'enemy-to-player')4720
else if (kind === 'enemy-to-player')4510
{ end = this._fieldTop(null); }4721
{ end = this._fieldTop(landCol != null ? landCol : 4.5); }4511
else4722
else4512
{ end = this._targetEnd(targetId, start); }4723
{ end = this._targetEnd(targetId, start, landCol); }4724
4725
// Hits are ingested as grey garbage; draw them grey (t1130).4726
// Misses keep the sender's colour — nothing is received.4727
var flightColor = miss4728
? (r.color != null ? r.color : meta.color)4729
: -1;4513
4730
4514
var startScale;4731
var startScale;4515
var endScale;4732
var endScale;@@ -4544,7 +4761,7 @@ Online.spawnFlights = function (results, locals)4544
4761
4545
var layer = (kind === 'enemy-to-enemy' && back) ? back : front;4762
var layer = (kind === 'enemy-to-enemy' && back) ? back : front;4546
var el = document.createElement('img');4763
var el = document.createElement('img');4547
el.src = colorSpriteUrl(r.color != null ? r.color : meta.color);4764
el.src = colorSpriteUrl(flightColor);4548
el.alt = '';4765
el.alt = '';4549
el.className = 'flight' + (kind === 'enemy-to-enemy' ? ' flight-behind' : '');4766
el.className = 'flight' + (kind === 'enemy-to-enemy' ? ' flight-behind' : '');4550
el.style.width = full + 'px';4767
el.style.width = full + 'px';@@ -4560,6 +4777,9 @@ Online.spawnFlights = function (results, locals)4560
var height = miss4777
var height = miss4561
? Math.max(40, Math.min(160, Math.abs(end.y - start.y) * 0.35))4778
? Math.max(40, Math.min(160, Math.abs(end.y - start.y) * 0.35))4562
: this.arcHeight(start, end);4779
: this.arcHeight(start, end);4780
var field = this.playerFieldRect();4781
var around = !miss && (kind === 'enemy-to-player' || kind === 'player-to-enemy');4782
var waypoints = around ? this.waypointsAroundField(start, end, field, height * 0.45) : null;4563
this._flights.push({4783
this._flights.push({4564
el: el,4784
el: el,4565
start: start,4785
start: start,@@ -4574,7 +4794,11 @@ Online.spawnFlights = function (results, locals)4574
startScale: startScale,4794
startScale: startScale,4575
endScale: endScale,4795
endScale: endScale,4576
angle: Math.random() * 360,4796
angle: Math.random() * 360,4577
id: sid4797
id: sid,4798
landCol: landCol,4799
field: field,4800
waypoints: waypoints,4801
color: flightColor4578
});4802
});4579
}4803
}4580
this._flightLocals = {};4804
this._flightLocals = {};@@ -4616,14 +4840,17 @@ Online._flightStart = function (col)4616
return { x: window.innerWidth / 2, y: window.innerHeight * 0.3 };4840
return { x: window.innerWidth / 2, y: window.innerHeight * 0.3 };4617
};4841
};4618
4842
4619
Online._targetEnd = function (targetId, start)4843
Online._targetEnd = function (targetId, start, col)4620
{4844
{4621
var el = targetId && this.miniElement(targetId);4845
var el = targetId && this.miniElement(targetId);4622
if (el)4846
if (el)4623
{4847
{4624
var canvas = el.querySelector('canvas') || el;4848
var canvas = el.querySelector('canvas') || el;4625
var r = canvas.getBoundingClientRect();4849
var r = canvas.getBoundingClientRect();4626
return { x: r.left + r.width / 2, y: r.top + r.height / 2 };4850
var x = r.left + r.width / 2;4851
if (col != null && isFinite(col))4852
{ x = r.left + ((col + 0.5) / 10) * r.width; }4853
return { x: x, y: r.top + 4 };4627
}4854
}4628
return { x: start.x + (Math.random() - 0.5) * 80, y: 40 };4855
return { x: start.x + (Math.random() - 0.5) * 80, y: 40 };4629
};4856
};@@ -4683,6 +4910,18 @@ Online.tickFlights = function (now)4683
x = mt * mt * f.start.x + 2 * mt * e * f.ctrl.x + e * e * f.end.x;4910
x = mt * mt * f.start.x + 2 * mt * e * f.ctrl.x + e * e * f.end.x;4684
y = mt * mt * f.start.y + 2 * mt * e * f.ctrl.y + e * e * f.end.y;4911
y = mt * mt * f.start.y + 2 * mt * e * f.ctrl.y + e * e * f.end.y;4685
}4912
}4913
else if (f.waypoints && f.waypoints.length > 2)4914
{4915
var pt = this.pointOnPath(f.waypoints, u);4916
x = pt.x;4917
y = pt.y;4918
}4919
else if (f.waypoints && f.field)4920
{4921
var pt = this.aroundFieldPoint(f.start, f.end, u, f.field, (f.height || 80) * 0.45);4922
x = pt.x;4923
y = pt.y;4924
}4686
else4925
else4687
{4926
{4688
var pt = this.arcPoint(f.start, f.end, u, f.height || 80);4927
var pt = this.arcPoint(f.start, f.end, u, f.height || 80);@@ -4725,6 +4964,7 @@ Online.clearFlights = function ()4725
this._flights = [];4964
this._flights = [];4726
this._flightLocals = {};4965
this._flightLocals = {};4727
this._flightSeen = Object.create(null);4966
this._flightSeen = Object.create(null);4967
this._pendingLandCol = Object.create(null);4728
};4968
};4729
4969
4730
if (typeof globalThis !== 'undefined')4970
if (typeof globalThis !== 'undefined')@@ -5184,6 +5424,9 @@ OfflineBattle.prototype._dispatchShots = function (fromId, core, planet, playerC5184
target = targets[idx];5424
target = targets[idx];5185
}5425
}5186
var clientId = fromId + '-' + shot.id + '-' + this.clock;5426
var clientId = fromId + '-' + shot.id + '-' + this.clock;5427
var landCol = null;5428
if (!miss && target && target.core && target.core.pickGarbageColumn)5429
{ landCol = target.core.pickGarbageColumn(); }5187
var result = {5430
var result = {5188
client_id: clientId,5431
client_id: clientId,5189
miss: miss,5432
miss: miss,@@ -5192,7 +5435,8 @@ OfflineBattle.prototype._dispatchShots = function (fromId, core, planet, playerC5192
flight_duration: FLIGHT_DURATION,5435
flight_duration: FLIGHT_DURATION,5193
from_id: fromId,5436
from_id: fromId,5194
col: shot.col,5437
col: shot.col,5195
y: shot.y5438
y: shot.y,5439
land_col: landCol5196
};5440
};5197
this.flightResults.push(result);5441
this.flightResults.push(result);5198
this.shotLocals.push({5442
this.shotLocals.push({@@ -5200,7 +5444,8 @@ OfflineBattle.prototype._dispatchShots = function (fromId, core, planet, playerC5200
col: shot.col,5444
col: shot.col,5201
y: shot.y,5445
y: shot.y,5202
color: shot.color,5446
color: shot.color,5203
from_id: fromId5447
from_id: fromId,5448
land_col: landCol5204
});5449
});5205
if (!miss && target)5450
if (!miss && target)5206
{5451
{@@ -5208,7 +5453,8 @@ OfflineBattle.prototype._dispatchShots = function (fromId, core, planet, playerC5208
at: this.clock + FLIGHT_DURATION,5453
at: this.clock + FLIGHT_DURATION,5209
targetId: target.id,5454
targetId: target.id,5210
color: shot.color,5455
color: shot.color,5211
fromId: fromId5456
fromId: fromId,5457
landCol: landCol5212
});5458
});5213
}5459
}5214
}5460
}@@ -5227,7 +5473,7 @@ OfflineBattle.prototype._deliver = function (playerCore)5227
}5473
}5228
var core = this.coreFor(ev.targetId, playerCore);5474
var core = this.coreFor(ev.targetId, playerCore);5229
if (core && core.state === 'playing' && core.ingestGarbage)5475
if (core && core.state === 'playing' && core.ingestGarbage)5230
{ core.ingestGarbage(); }5476
{ core.ingestGarbage(ev.landCol); }5231
}5477
}5232
this.pending = keep;5478
this.pending = keep;5233
};5479
};@@ -6716,7 +6962,8 @@ function tickOffline (dt)6716
color: s.color,6962
color: s.color,6717
startX: start.x,6963
startX: start.x,6718
startY: start.y,6964
startY: start.y,6719
from_id: s.from_id6965
from_id: s.from_id,6966
land_col: s.land_col6720
};6967
};6721
}6968
}6722
Online.spawnFlights(result.flights, locals);6969
Online.spawnFlights(result.flights, locals);@@ -7149,7 +7396,10 @@ function bindOnlineUi ()7149
if (!app.core || app.core.state !== 'playing')7396
if (!app.core || app.core.state !== 'playing')7150
{ return; }7397
{ return; }7151
for (var i = 0; i < incoming.length; i++)7398
for (var i = 0; i < incoming.length; i++)7152
{ app.core.ingestGarbage(); }7399
{7400
var col = Online.takeLandCol ? Online.takeLandCol(incoming[i]) : incoming[i].land_col;7401
app.core.ingestGarbage(col);7402
}7153
};7403
};7154
Online.onFinished = function (lobby)7404
Online.onFinished = function (lobby)7155
{ showPodium(lobby); };7405
{ showPodium(lobby); };@@ -577,10 +577,6 @@ Aanname:
577
577
naar volle tegel; speler→vijand andersom; vijand→vijand blijven
578
578
klein. Missers hergebruiken de bestaande fade-en-wegvlieg-animatie;
579
579
vijand-missers starten kleiner (mini-schaal).
580
- Het visuele eindpunt van vijand→speler is de bovenkant van het
581
veld van de speler (midden, of de kolom als die bekend is). De
582
échte `ingestGarbage` kiest nog steeds een willekeurige kolom —
583
die hoeft niet overeen te komen met waar de boog landt.
584
580
- Vijand→vijand (bot-bot of remote-remote) worden in `#flights-back`
585
581
getekend (z-index 5, onder `#flights` z-index 6). Een CSS
586
582
`clip-path` spaart het rechthoek van het spelersveld uit, zodat
@@ -592,3 +588,55 @@ Aanname:
592
588
client de-dupliceert op id. Extra velden zijn backward compatible.
593
589
- Performance: alleen CSS-transforms, één tick per frame, beelden
594
590
verdwijnen na 1,2 s. Geen pooling nodig voor tientallen bots.
591
592
## t1126 — boogje eindigt in de kolom waar het blok verschijnt
593
594
- De landingskolom (`land_col`) wordt gekozen **bij het begin van de
595
vlucht**, niet pas bij aflevering, en dezelfde waarde geldt voor
596
het eindpunt van de boog én voor `ingestGarbage`.
597
- Offline: bij het afvuren kiest het doel-veld een open kolom
598
(`pickGarbageColumn`); die zit op het flight-resultaat en op de
599
pending delivery.
600
- Online: de server kiest `land_col` (0–9) bij `recordShots`, slaat
601
het op bij het schot, en stuurt het mee in `shot_results`,
602
`shot_flights` en `incoming`. Een late poll of mid-arc (`age`)
603
ziet dus dezelfde kolom. De client onthoudt `land_col` ook zelf
604
(`_pendingLandCol`) als vangnet.
605
- Als de gekozen kolom bij aflevering niet meer open is (vol of
606
vergrendeld in de 1,2 s vliegtijd), valt `ingestGarbage` terug op
607
een andere open kolom. Dat is zeldzaam; dan kan de boog van de
608
echte kolom afwijken.
609
- Speler→vijand en vijand→vijand richten óók op `land_col`: het
610
eindpunt is de bovenkant van die kolom op de mini van het doel
611
(makkelijk, zelfde veld).
612
613
## t1128 — vijand↔speler-boogjes gaan om het veld heen
614
615
- Boogjes tussen een vijand en het veld van de speler (beide
616
richtingen) mogen **niet over het binnenveld** bewegen. Het pad
617
gaat eerst omhoog aan de buitenkant, dan over de bovenrand, en
618
buigt pas daar de doelkolom in. Het eindpunt blijft de bovenkant
619
van `land_col`.
620
- Als begin- en eindpunt al boven de bovenrand liggen (smalle
621
layout, mini's boven het veld) is een gewone parabool genoeg:
622
die blijft vanzelf boven het veld.
623
- Vijand→vijand blijft een kleine parabool **achter** het veld
624
(`#flights-back` + clip-path), onveranderd.
625
626
## t1129 — padding boven het veld in de brede weergave
627
628
- Alleen in de **brede** (sides) layout krijgt het veld extra ruimte
629
bovenin (`ARC_TOP_PAD` = 100 px tussen HUD en veld, tegels iets
630
kleiner indien nodig) zodat de omweg-boogjes over de bovenrand
631
passen. Smal en mobiel blijven onveranderd (mini's boven het veld,
632
geen extra pad).
633
634
## t1130 — raak-schoten zijn visueel grijs
635
636
- Wat de ontvanger binnenkrijgt is altijd een grijs vuilblok
637
(`ingestGarbage`). Daarom worden **alle raak-schoten** — vijand→
638
speler, speler→vijand en vijand→vijand — als grijze blokjes
639
getekend (`images/block-gray.png`), niet in de kleur van de
640
schutter. Zo komt het boogje overeen met wat er landt.
641
- Missers houden de kleur van de schutter: daar wordt niets
642
ontvangen, het blokje vliegt weg en vervaagt zoals voorheen.
@@ -577,10 +577,6 @@ Aanname:577
naar volle tegel; speler→vijand andersom; vijand→vijand blijven577
naar volle tegel; speler→vijand andersom; vijand→vijand blijven578
klein. Missers hergebruiken de bestaande fade-en-wegvlieg-animatie;578
klein. Missers hergebruiken de bestaande fade-en-wegvlieg-animatie;579
vijand-missers starten kleiner (mini-schaal).579
vijand-missers starten kleiner (mini-schaal).580
- Het visuele eindpunt van vijand→speler is de bovenkant van het581
veld van de speler (midden, of de kolom als die bekend is). De582
échte `ingestGarbage` kiest nog steeds een willekeurige kolom —583
die hoeft niet overeen te komen met waar de boog landt.584
- Vijand→vijand (bot-bot of remote-remote) worden in `#flights-back`580
- Vijand→vijand (bot-bot of remote-remote) worden in `#flights-back`585
getekend (z-index 5, onder `#flights` z-index 6). Een CSS581
getekend (z-index 5, onder `#flights` z-index 6). Een CSS586
`clip-path` spaart het rechthoek van het spelersveld uit, zodat582
`clip-path` spaart het rechthoek van het spelersveld uit, zodat@@ -592,3 +588,55 @@ Aanname:592
client de-dupliceert op id. Extra velden zijn backward compatible.588
client de-dupliceert op id. Extra velden zijn backward compatible.593
- Performance: alleen CSS-transforms, één tick per frame, beelden589
- Performance: alleen CSS-transforms, één tick per frame, beelden594
verdwijnen na 1,2 s. Geen pooling nodig voor tientallen bots.590
verdwijnen na 1,2 s. Geen pooling nodig voor tientallen bots.591
592
## t1126 — boogje eindigt in de kolom waar het blok verschijnt593
594
- De landingskolom (`land_col`) wordt gekozen **bij het begin van de595
vlucht**, niet pas bij aflevering, en dezelfde waarde geldt voor596
het eindpunt van de boog én voor `ingestGarbage`.597
- Offline: bij het afvuren kiest het doel-veld een open kolom598
(`pickGarbageColumn`); die zit op het flight-resultaat en op de599
pending delivery.600
- Online: de server kiest `land_col` (0–9) bij `recordShots`, slaat601
het op bij het schot, en stuurt het mee in `shot_results`,602
`shot_flights` en `incoming`. Een late poll of mid-arc (`age`)603
ziet dus dezelfde kolom. De client onthoudt `land_col` ook zelf604
(`_pendingLandCol`) als vangnet.605
- Als de gekozen kolom bij aflevering niet meer open is (vol of606
vergrendeld in de 1,2 s vliegtijd), valt `ingestGarbage` terug op607
een andere open kolom. Dat is zeldzaam; dan kan de boog van de608
echte kolom afwijken.609
- Speler→vijand en vijand→vijand richten óók op `land_col`: het610
eindpunt is de bovenkant van die kolom op de mini van het doel611
(makkelijk, zelfde veld).612
613
## t1128 — vijand↔speler-boogjes gaan om het veld heen614
615
- Boogjes tussen een vijand en het veld van de speler (beide616
richtingen) mogen **niet over het binnenveld** bewegen. Het pad617
gaat eerst omhoog aan de buitenkant, dan over de bovenrand, en618
buigt pas daar de doelkolom in. Het eindpunt blijft de bovenkant619
van `land_col`.620
- Als begin- en eindpunt al boven de bovenrand liggen (smalle621
layout, mini's boven het veld) is een gewone parabool genoeg:622
die blijft vanzelf boven het veld.623
- Vijand→vijand blijft een kleine parabool **achter** het veld624
(`#flights-back` + clip-path), onveranderd.625
626
## t1129 — padding boven het veld in de brede weergave627
628
- Alleen in de **brede** (sides) layout krijgt het veld extra ruimte629
bovenin (`ARC_TOP_PAD` = 100 px tussen HUD en veld, tegels iets630
kleiner indien nodig) zodat de omweg-boogjes over de bovenrand631
passen. Smal en mobiel blijven onveranderd (mini's boven het veld,632
geen extra pad).633
634
## t1130 — raak-schoten zijn visueel grijs635
636
- Wat de ontvanger binnenkrijgt is altijd een grijs vuilblok637
(`ingestGarbage`). Daarom worden **alle raak-schoten** — vijand→638
speler, speler→vijand en vijand→vijand — als grijze blokjes639
getekend (`images/block-gray.png`), niet in de kleur van de640
schutter. Zo komt het boogje overeen met wat er landt.641
- Missers houden de kleur van de schutter: daar wordt niets642
ontvangen, het blokje vliegt weg en vervaagt zoals voorheen.@@ -74,6 +74,7 @@ CREATE TABLE IF NOT EXISTS shots (
74
74
CREATE INDEX IF NOT EXISTS shots_deliver ON shots (lobby_id, to_user, delivered, deliver_at);
75
75
SQL);
76
76
$this->ensureColumn('members', 'planet_id', "TEXT NOT NULL DEFAULT 'terra'");
77
$this->ensureColumn('shots', 'land_col', 'INTEGER');
77
78
}
78
79
79
80
private function ensureColumn(string $table, string $column, string $ddl): void
@@ -394,8 +395,8 @@ SQL);
394
395
$flight = (float) $lobby['flight_duration'];
395
396
$now = $this->nowf();
396
397
$ins = $this->pdo->prepare(
397
'INSERT INTO shots (lobby_id, from_user, to_user, color, client_id, created, deliver_at, delivered)
398
VALUES (?,?,?,?,?,?,?,0)'
398
'INSERT INTO shots (lobby_id, from_user, to_user, color, client_id, created, deliver_at, delivered, land_col)
399
VALUES (?,?,?,?,?,?,?,0,?)'
399
400
);
400
401
foreach ($shots as $shot) {
401
402
$color = isset($shot['color']) ? (int) $shot['color'] : -1;
@@ -403,13 +404,15 @@ SQL);
403
404
$miss = $targets === [] || (mt_rand() / mt_getrandmax()) < $missChance;
404
405
$to = null;
405
406
$toName = null;
407
$landCol = null;
406
408
if (!$miss) {
407
409
$pick = $targets[random_int(0, count($targets) - 1)];
408
410
$to = $pick['user_id'];
409
411
$toName = $pick['name'];
412
$landCol = random_int(0, 9);
410
413
}
411
414
$deliver = $now + $flight;
412
$ins->execute([$lobby['id'], $userId, $to, $color, $clientId, $now, $deliver]);
415
$ins->execute([$lobby['id'], $userId, $to, $color, $clientId, $now, $deliver, $landCol]);
413
416
$results[] = [
414
417
'id' => (int) $this->pdo->lastInsertId(),
415
418
'client_id' => $clientId,
@@ -422,6 +425,7 @@ SQL);
422
425
'color' => $color,
423
426
'flight_duration' => $flight,
424
427
'age' => 0.0,
428
'land_col' => $landCol,
425
429
];
426
430
}
427
431
return $results;
@@ -452,6 +456,7 @@ SQL);
452
456
'color' => (int) $r['color'],
453
457
'from_user' => $r['from_user'],
454
458
'client_id' => $r['client_id'],
459
'land_col' => isset($r['land_col']) && $r['land_col'] !== null ? (int) $r['land_col'] : null,
455
460
];
456
461
}
457
462
return $incoming;
@@ -603,6 +608,7 @@ SQL);
603
608
'flight_duration' => $flight,
604
609
'age' => $now - (float) $r['created'],
605
610
'deliver_at' => (float) $r['deliver_at'],
611
'land_col' => isset($r['land_col']) && $r['land_col'] !== null ? (int) $r['land_col'] : null,
606
612
];
607
613
}
608
614
return $out;
@@ -74,6 +74,7 @@ CREATE TABLE IF NOT EXISTS shots (74
CREATE INDEX IF NOT EXISTS shots_deliver ON shots (lobby_id, to_user, delivered, deliver_at);74
CREATE INDEX IF NOT EXISTS shots_deliver ON shots (lobby_id, to_user, delivered, deliver_at);75
SQL);75
SQL);76
$this->ensureColumn('members', 'planet_id', "TEXT NOT NULL DEFAULT 'terra'");76
$this->ensureColumn('members', 'planet_id', "TEXT NOT NULL DEFAULT 'terra'");77
$this->ensureColumn('shots', 'land_col', 'INTEGER');77
}78
}78
79
79
private function ensureColumn(string $table, string $column, string $ddl): void80
private function ensureColumn(string $table, string $column, string $ddl): void@@ -394,8 +395,8 @@ SQL);394
$flight = (float) $lobby['flight_duration'];395
$flight = (float) $lobby['flight_duration'];395
$now = $this->nowf();396
$now = $this->nowf();396
$ins = $this->pdo->prepare(397
$ins = $this->pdo->prepare(397
'INSERT INTO shots (lobby_id, from_user, to_user, color, client_id, created, deliver_at, delivered)398
'INSERT INTO shots (lobby_id, from_user, to_user, color, client_id, created, deliver_at, delivered, land_col)398
VALUES (?,?,?,?,?,?,?,0)'399
VALUES (?,?,?,?,?,?,?,0,?)'399
);400
);400
foreach ($shots as $shot) {401
foreach ($shots as $shot) {401
$color = isset($shot['color']) ? (int) $shot['color'] : -1;402
$color = isset($shot['color']) ? (int) $shot['color'] : -1;@@ -403,13 +404,15 @@ SQL);403
$miss = $targets === [] || (mt_rand() / mt_getrandmax()) < $missChance;404
$miss = $targets === [] || (mt_rand() / mt_getrandmax()) < $missChance;404
$to = null;405
$to = null;405
$toName = null;406
$toName = null;407
$landCol = null;406
if (!$miss) {408
if (!$miss) {407
$pick = $targets[random_int(0, count($targets) - 1)];409
$pick = $targets[random_int(0, count($targets) - 1)];408
$to = $pick['user_id'];410
$to = $pick['user_id'];409
$toName = $pick['name'];411
$toName = $pick['name'];412
$landCol = random_int(0, 9);410
}413
}411
$deliver = $now + $flight;414
$deliver = $now + $flight;412
$ins->execute([$lobby['id'], $userId, $to, $color, $clientId, $now, $deliver]);415
$ins->execute([$lobby['id'], $userId, $to, $color, $clientId, $now, $deliver, $landCol]);413
$results[] = [416
$results[] = [414
'id' => (int) $this->pdo->lastInsertId(),417
'id' => (int) $this->pdo->lastInsertId(),415
'client_id' => $clientId,418
'client_id' => $clientId,@@ -422,6 +425,7 @@ SQL);422
'color' => $color,425
'color' => $color,423
'flight_duration' => $flight,426
'flight_duration' => $flight,424
'age' => 0.0,427
'age' => 0.0,428
'land_col' => $landCol,425
];429
];426
}430
}427
return $results;431
return $results;@@ -452,6 +456,7 @@ SQL);452
'color' => (int) $r['color'],456
'color' => (int) $r['color'],453
'from_user' => $r['from_user'],457
'from_user' => $r['from_user'],454
'client_id' => $r['client_id'],458
'client_id' => $r['client_id'],459
'land_col' => isset($r['land_col']) && $r['land_col'] !== null ? (int) $r['land_col'] : null,455
];460
];456
}461
}457
return $incoming;462
return $incoming;@@ -603,6 +608,7 @@ SQL);603
'flight_duration' => $flight,608
'flight_duration' => $flight,604
'age' => $now - (float) $r['created'],609
'age' => $now - (float) $r['created'],605
'deliver_at' => (float) $r['deliver_at'],610
'deliver_at' => (float) $r['deliver_at'],611
'land_col' => isset($r['land_col']) && $r['land_col'] !== null ? (int) $r['land_col'] : null,606
];612
];607
}613
}608
return $out;614
return $out;@@ -268,6 +268,24 @@ if ($found) {
268
268
expect($found['miss'] === false, 'forced hit is not a miss');
269
269
expect($found['age'] >= 0 && $found['age'] < 2.0, 'age is seconds since created');
270
270
expect(almostEqual((float) $found['flight_duration'], METEORS_FLIGHT_DURATION), 'flight_duration on shot_flights');
271
expect(isset($found['land_col']) && $found['land_col'] >= 0 && $found['land_col'] <= 9, 'shot_flights has land_col 0–9');
272
expect(($shots[0]['land_col'] ?? null) === $found['land_col'], 'recordShots and shot_flights share land_col');
273
}
274
// Incoming carries the same land_col (t1126).
275
$targetId = $found['target_id'] ?? $shots[0]['target_id'];
276
$pdoLand = new PDO('sqlite:' . $tmp . '/meteors.sqlite');
277
$pdoLand->exec('UPDATE shots SET deliver_at = 0 WHERE client_id = "f1"');
278
$incLand = $store->viewFor($targetId);
279
$incHit = null;
280
foreach ($incLand['incoming'] as $row) {
281
if (($row['client_id'] ?? '') === 'f1') {
282
$incHit = $row;
283
break;
284
}
285
}
286
expect($incHit !== null, 'target receives incoming for the shot');
287
if ($incHit) {
288
expect(($incHit['land_col'] ?? null) === $found['land_col'], 'incoming.land_col matches the flight');
271
289
}
272
290
$view1 = $store->viewFor('local:test_user_1');
273
291
expect(count($view1['shot_flights']) >= 1, 'shooter also sees shot_flights (client de-dupes)');
@@ -268,6 +268,24 @@ if ($found) {268
expect($found['miss'] === false, 'forced hit is not a miss');268
expect($found['miss'] === false, 'forced hit is not a miss');269
expect($found['age'] >= 0 && $found['age'] < 2.0, 'age is seconds since created');269
expect($found['age'] >= 0 && $found['age'] < 2.0, 'age is seconds since created');270
expect(almostEqual((float) $found['flight_duration'], METEORS_FLIGHT_DURATION), 'flight_duration on shot_flights');270
expect(almostEqual((float) $found['flight_duration'], METEORS_FLIGHT_DURATION), 'flight_duration on shot_flights');271
expect(isset($found['land_col']) && $found['land_col'] >= 0 && $found['land_col'] <= 9, 'shot_flights has land_col 0–9');272
expect(($shots[0]['land_col'] ?? null) === $found['land_col'], 'recordShots and shot_flights share land_col');273
}274
// Incoming carries the same land_col (t1126).275
$targetId = $found['target_id'] ?? $shots[0]['target_id'];276
$pdoLand = new PDO('sqlite:' . $tmp . '/meteors.sqlite');277
$pdoLand->exec('UPDATE shots SET deliver_at = 0 WHERE client_id = "f1"');278
$incLand = $store->viewFor($targetId);279
$incHit = null;280
foreach ($incLand['incoming'] as $row) {281
if (($row['client_id'] ?? '') === 'f1') {282
$incHit = $row;283
break;284
}285
}286
expect($incHit !== null, 'target receives incoming for the shot');287
if ($incHit) {288
expect(($incHit['land_col'] ?? null) === $found['land_col'], 'incoming.land_col matches the flight');271
}289
}272
$view1 = $store->viewFor('local:test_user_1');290
$view1 = $store->viewFor('local:test_user_1');273
expect(count($view1['shot_flights']) >= 1, 'shooter also sees shot_flights (client de-dupes)');291
expect(count($view1['shot_flights']) >= 1, 'shooter also sees shot_flights (client de-dupes)');@@ -2061,29 +2061,51 @@ GameCore.prototype.fieldSnapshot = function ()
2061
2061
* `col` is optional; a random eligible column is used otherwise.
2062
2062
* Returns the new block, or null if every column is locked or full.
2063
2063
*/
2064
GameCore.prototype.ingestGarbage = function (col)
2064
/**
2065
* Open columns a garbage block can fall into (not locked, not full).
2066
*/
2067
GameCore.prototype.eligibleGarbageColumns = function ()
2065
2068
{
2066
if (this.state !== 'playing')
2069
var eligible = [];
2070
for (var c = 0; c < this.width; c++)
2071
{
2072
if (this.isColumnLocked(c))
2073
{ continue; }
2074
if (this.groundedCount(c) >= this.height)
2075
{ continue; }
2076
eligible.push(c);
2077
}
2078
return eligible;
2079
};
2080
2081
/**
2082
* Choose a garbage column. If `preferred` is still open, it wins;
2083
* otherwise a random eligible column (t1126). Returns null if none.
2084
*/
2085
GameCore.prototype.pickGarbageColumn = function (preferred)
2086
{
2087
var eligible = this.eligibleGarbageColumns();
2088
if (!eligible.length)
2067
2089
{ return null; }
2068
var chosen = null;
2069
if (col != null && col >= 0 && col < this.width
2070
&& !this.isColumnLocked(col) && this.groundedCount(col) < this.height)
2071
{ chosen = col | 0; }
2072
else
2090
if (preferred != null && isFinite(preferred))
2073
2091
{
2074
var eligible = [];
2075
for (var c = 0; c < this.width; c++)
2092
var want = preferred | 0;
2093
for (var i = 0; i < eligible.length; i++)
2076
2094
{
2077
if (this.isColumnLocked(c))
2078
{ continue; }
2079
if (this.groundedCount(c) >= this.height)
2080
{ continue; }
2081
eligible.push(c);
2095
if (eligible[i] === want)
2096
{ return want; }
2082
2097
}
2083
if (!eligible.length)
2084
{ return null; }
2085
chosen = eligible[Math.floor(this.rng() * eligible.length) % eligible.length];
2086
2098
}
2099
return eligible[Math.floor(this.rng() * eligible.length) % eligible.length];
2100
};
2101
2102
GameCore.prototype.ingestGarbage = function (col)
2103
{
2104
if (this.state !== 'playing')
2105
{ return null; }
2106
var chosen = this.pickGarbageColumn(col);
2107
if (chosen == null)
2108
{ return null; }
2087
2109
var block = this.createBlock(chosen, this.height, COLOR_GRAY, STATE_FALLING);
2088
2110
block.vy = -this.planet.fallSpeed;
2089
2111
block.flame = false;
@@ -2061,29 +2061,51 @@ GameCore.prototype.fieldSnapshot = function ()2061
* `col` is optional; a random eligible column is used otherwise.2061
* `col` is optional; a random eligible column is used otherwise.2062
* Returns the new block, or null if every column is locked or full.2062
* Returns the new block, or null if every column is locked or full.2063
*/2063
*/2064
GameCore.prototype.ingestGarbage = function (col)2064
/**2065
* Open columns a garbage block can fall into (not locked, not full).2066
*/2067
GameCore.prototype.eligibleGarbageColumns = function ()2065
{2068
{2066
if (this.state !== 'playing')2069
var eligible = [];2070
for (var c = 0; c < this.width; c++)2071
{2072
if (this.isColumnLocked(c))2073
{ continue; }2074
if (this.groundedCount(c) >= this.height)2075
{ continue; }2076
eligible.push(c);2077
}2078
return eligible;2079
};2080
2081
/**2082
* Choose a garbage column. If `preferred` is still open, it wins;2083
* otherwise a random eligible column (t1126). Returns null if none.2084
*/2085
GameCore.prototype.pickGarbageColumn = function (preferred)2086
{2087
var eligible = this.eligibleGarbageColumns();2088
if (!eligible.length)2067
{ return null; }2089
{ return null; }2068
var chosen = null;2090
if (preferred != null && isFinite(preferred))2069
if (col != null && col >= 0 && col < this.width2070
&& !this.isColumnLocked(col) && this.groundedCount(col) < this.height)2071
{ chosen = col | 0; }2072
else2073
{2091
{2074
var eligible = [];2092
var want = preferred | 0;2075
for (var c = 0; c < this.width; c++)2093
for (var i = 0; i < eligible.length; i++)2076
{2094
{2077
if (this.isColumnLocked(c))2095
if (eligible[i] === want)2078
{ continue; }2096
{ return want; }2079
if (this.groundedCount(c) >= this.height)2080
{ continue; }2081
eligible.push(c);2082
}2097
}2083
if (!eligible.length)2084
{ return null; }2085
chosen = eligible[Math.floor(this.rng() * eligible.length) % eligible.length];2086
}2098
}2099
return eligible[Math.floor(this.rng() * eligible.length) % eligible.length];2100
};2101
2102
GameCore.prototype.ingestGarbage = function (col)2103
{2104
if (this.state !== 'playing')2105
{ return null; }2106
var chosen = this.pickGarbageColumn(col);2107
if (chosen == null)2108
{ return null; }2087
var block = this.createBlock(chosen, this.height, COLOR_GRAY, STATE_FALLING);2109
var block = this.createBlock(chosen, this.height, COLOR_GRAY, STATE_FALLING);2088
block.vy = -this.planet.fallSpeed;2110
block.vy = -this.planet.fallSpeed;2089
block.flame = false;2111
block.flame = false;@@ -1359,7 +1359,8 @@ function tickOffline (dt)
1359
1359
color: s.color,
1360
1360
startX: start.x,
1361
1361
startY: start.y,
1362
from_id: s.from_id
1362
from_id: s.from_id,
1363
land_col: s.land_col
1363
1364
};
1364
1365
}
1365
1366
Online.spawnFlights(result.flights, locals);
@@ -1792,7 +1793,10 @@ function bindOnlineUi ()
1792
1793
if (!app.core || app.core.state !== 'playing')
1793
1794
{ return; }
1794
1795
for (var i = 0; i < incoming.length; i++)
1795
{ app.core.ingestGarbage(); }
1796
{
1797
var col = Online.takeLandCol ? Online.takeLandCol(incoming[i]) : incoming[i].land_col;
1798
app.core.ingestGarbage(col);
1799
}
1796
1800
};
1797
1801
Online.onFinished = function (lobby)
1798
1802
{ showPodium(lobby); };
@@ -1359,7 +1359,8 @@ function tickOffline (dt)1359
color: s.color,1359
color: s.color,1360
startX: start.x,1360
startX: start.x,1361
startY: start.y,1361
startY: start.y,1362
from_id: s.from_id1362
from_id: s.from_id,1363
land_col: s.land_col1363
};1364
};1364
}1365
}1365
Online.spawnFlights(result.flights, locals);1366
Online.spawnFlights(result.flights, locals);@@ -1792,7 +1793,10 @@ function bindOnlineUi ()1792
if (!app.core || app.core.state !== 'playing')1793
if (!app.core || app.core.state !== 'playing')1793
{ return; }1794
{ return; }1794
for (var i = 0; i < incoming.length; i++)1795
for (var i = 0; i < incoming.length; i++)1795
{ app.core.ingestGarbage(); }1796
{1797
var col = Online.takeLandCol ? Online.takeLandCol(incoming[i]) : incoming[i].land_col;1798
app.core.ingestGarbage(col);1799
}1796
};1800
};1797
Online.onFinished = function (lobby)1801
Online.onFinished = function (lobby)1798
{ showPodium(lobby); };1802
{ showPodium(lobby); };@@ -15,6 +15,9 @@ var EDGE = 16;
15
15
var MIN_TILE_FOR_SIDES = 18;
16
16
var MIN_VIEWPORT_FOR_SIDES = 960;
17
17
var LABEL_H = 32;
18
/* Extra space above the field in the wide (sides) layout so
19
enemy↔player arcs can route around the top edge (t1129). */
20
var ARC_TOP_PAD = 100;
18
21
19
22
function canvasSize (n, mode, availH)
20
23
{
@@ -109,7 +112,8 @@ function plan (vw, vh, n, hudH, margin)
109
112
var availHSide = Math.max(80, vh - hudH - margin);
110
113
var probe = canvasSize(n, 'sides', availHSide);
111
114
var availWSide = Math.max(80, vw - margin * 2 - 2 * (probe.outerW + GAP));
112
var tileSide = Math.max(14, Math.floor(Math.min(availWSide / 10, availHSide / 13)));
115
var availHForField = Math.max(80, availHSide - ARC_TOP_PAD);
116
var tileSide = Math.max(14, Math.floor(Math.min(availWSide / 10, availHForField / 13)));
113
117
var fieldWSide = tileSide * 10;
114
118
var fieldHSide = tileSide * 13;
115
119
var leftover = (vw - fieldWSide) / 2;
@@ -118,9 +122,10 @@ function plan (vw, vh, n, hudH, margin)
118
122
&& tileSide >= MIN_TILE_FOR_SIDES)
119
123
{
120
124
var fieldX = Math.floor((vw - fieldWSide) / 2);
121
var fieldY = hudH + Math.floor((availHSide - fieldHSide) / 2);
122
if (fieldY < hudH)
123
{ fieldY = hudH; }
125
var fieldY = hudH + ARC_TOP_PAD
126
+ Math.floor((availHForField - fieldHSide) / 2);
127
if (fieldY < hudH + ARC_TOP_PAD)
128
{ fieldY = hudH + ARC_TOP_PAD; }
124
129
return finish('sides', tileSide, fieldX, fieldY, 0, probe,
125
130
sidePositions(n, fieldX, fieldY, fieldWSide, fieldHSide, probe, hudH));
126
131
}
@@ -152,6 +157,7 @@ var api = {
152
157
EDGE: EDGE,
153
158
MIN_TILE_FOR_SIDES: MIN_TILE_FOR_SIDES,
154
159
MIN_VIEWPORT_FOR_SIDES: MIN_VIEWPORT_FOR_SIDES,
160
ARC_TOP_PAD: ARC_TOP_PAD,
155
161
LABEL_H: LABEL_H,
156
162
canvasSize: canvasSize,
157
163
sidePositions: sidePositions,
@@ -15,6 +15,9 @@ var EDGE = 16;15
var MIN_TILE_FOR_SIDES = 18;15
var MIN_TILE_FOR_SIDES = 18;16
var MIN_VIEWPORT_FOR_SIDES = 960;16
var MIN_VIEWPORT_FOR_SIDES = 960;17
var LABEL_H = 32;17
var LABEL_H = 32;18
/* Extra space above the field in the wide (sides) layout so19
enemy↔player arcs can route around the top edge (t1129). */20
var ARC_TOP_PAD = 100;18
21
19
function canvasSize (n, mode, availH)22
function canvasSize (n, mode, availH)20
{23
{@@ -109,7 +112,8 @@ function plan (vw, vh, n, hudH, margin)109
var availHSide = Math.max(80, vh - hudH - margin);112
var availHSide = Math.max(80, vh - hudH - margin);110
var probe = canvasSize(n, 'sides', availHSide);113
var probe = canvasSize(n, 'sides', availHSide);111
var availWSide = Math.max(80, vw - margin * 2 - 2 * (probe.outerW + GAP));114
var availWSide = Math.max(80, vw - margin * 2 - 2 * (probe.outerW + GAP));112
var tileSide = Math.max(14, Math.floor(Math.min(availWSide / 10, availHSide / 13)));115
var availHForField = Math.max(80, availHSide - ARC_TOP_PAD);116
var tileSide = Math.max(14, Math.floor(Math.min(availWSide / 10, availHForField / 13)));113
var fieldWSide = tileSide * 10;117
var fieldWSide = tileSide * 10;114
var fieldHSide = tileSide * 13;118
var fieldHSide = tileSide * 13;115
var leftover = (vw - fieldWSide) / 2;119
var leftover = (vw - fieldWSide) / 2;@@ -118,9 +122,10 @@ function plan (vw, vh, n, hudH, margin)118
&& tileSide >= MIN_TILE_FOR_SIDES)122
&& tileSide >= MIN_TILE_FOR_SIDES)119
{123
{120
var fieldX = Math.floor((vw - fieldWSide) / 2);124
var fieldX = Math.floor((vw - fieldWSide) / 2);121
var fieldY = hudH + Math.floor((availHSide - fieldHSide) / 2);125
var fieldY = hudH + ARC_TOP_PAD122
if (fieldY < hudH)126
+ Math.floor((availHForField - fieldHSide) / 2);123
{ fieldY = hudH; }127
if (fieldY < hudH + ARC_TOP_PAD)128
{ fieldY = hudH + ARC_TOP_PAD; }124
return finish('sides', tileSide, fieldX, fieldY, 0, probe,129
return finish('sides', tileSide, fieldX, fieldY, 0, probe,125
sidePositions(n, fieldX, fieldY, fieldWSide, fieldHSide, probe, hudH));130
sidePositions(n, fieldX, fieldY, fieldWSide, fieldHSide, probe, hudH));126
}131
}@@ -152,6 +157,7 @@ var api = {152
EDGE: EDGE,157
EDGE: EDGE,153
MIN_TILE_FOR_SIDES: MIN_TILE_FOR_SIDES,158
MIN_TILE_FOR_SIDES: MIN_TILE_FOR_SIDES,154
MIN_VIEWPORT_FOR_SIDES: MIN_VIEWPORT_FOR_SIDES,159
MIN_VIEWPORT_FOR_SIDES: MIN_VIEWPORT_FOR_SIDES,160
ARC_TOP_PAD: ARC_TOP_PAD,155
LABEL_H: LABEL_H,161
LABEL_H: LABEL_H,156
canvasSize: canvasSize,162
canvasSize: canvasSize,157
sidePositions: sidePositions,163
sidePositions: sidePositions,@@ -441,6 +441,9 @@ OfflineBattle.prototype._dispatchShots = function (fromId, core, planet, playerC
441
441
target = targets[idx];
442
442
}
443
443
var clientId = fromId + '-' + shot.id + '-' + this.clock;
444
var landCol = null;
445
if (!miss && target && target.core && target.core.pickGarbageColumn)
446
{ landCol = target.core.pickGarbageColumn(); }
444
447
var result = {
445
448
client_id: clientId,
446
449
miss: miss,
@@ -449,7 +452,8 @@ OfflineBattle.prototype._dispatchShots = function (fromId, core, planet, playerC
449
452
flight_duration: FLIGHT_DURATION,
450
453
from_id: fromId,
451
454
col: shot.col,
452
y: shot.y
455
y: shot.y,
456
land_col: landCol
453
457
};
454
458
this.flightResults.push(result);
455
459
this.shotLocals.push({
@@ -457,7 +461,8 @@ OfflineBattle.prototype._dispatchShots = function (fromId, core, planet, playerC
457
461
col: shot.col,
458
462
y: shot.y,
459
463
color: shot.color,
460
from_id: fromId
464
from_id: fromId,
465
land_col: landCol
461
466
});
462
467
if (!miss && target)
463
468
{
@@ -465,7 +470,8 @@ OfflineBattle.prototype._dispatchShots = function (fromId, core, planet, playerC
465
470
at: this.clock + FLIGHT_DURATION,
466
471
targetId: target.id,
467
472
color: shot.color,
468
fromId: fromId
473
fromId: fromId,
474
landCol: landCol
469
475
});
470
476
}
471
477
}
@@ -484,7 +490,7 @@ OfflineBattle.prototype._deliver = function (playerCore)
484
490
}
485
491
var core = this.coreFor(ev.targetId, playerCore);
486
492
if (core && core.state === 'playing' && core.ingestGarbage)
487
{ core.ingestGarbage(); }
493
{ core.ingestGarbage(ev.landCol); }
488
494
}
489
495
this.pending = keep;
490
496
};
@@ -441,6 +441,9 @@ OfflineBattle.prototype._dispatchShots = function (fromId, core, planet, playerC441
target = targets[idx];441
target = targets[idx];442
}442
}443
var clientId = fromId + '-' + shot.id + '-' + this.clock;443
var clientId = fromId + '-' + shot.id + '-' + this.clock;444
var landCol = null;445
if (!miss && target && target.core && target.core.pickGarbageColumn)446
{ landCol = target.core.pickGarbageColumn(); }444
var result = {447
var result = {445
client_id: clientId,448
client_id: clientId,446
miss: miss,449
miss: miss,@@ -449,7 +452,8 @@ OfflineBattle.prototype._dispatchShots = function (fromId, core, planet, playerC449
flight_duration: FLIGHT_DURATION,452
flight_duration: FLIGHT_DURATION,450
from_id: fromId,453
from_id: fromId,451
col: shot.col,454
col: shot.col,452
y: shot.y455
y: shot.y,456
land_col: landCol453
};457
};454
this.flightResults.push(result);458
this.flightResults.push(result);455
this.shotLocals.push({459
this.shotLocals.push({@@ -457,7 +461,8 @@ OfflineBattle.prototype._dispatchShots = function (fromId, core, planet, playerC457
col: shot.col,461
col: shot.col,458
y: shot.y,462
y: shot.y,459
color: shot.color,463
color: shot.color,460
from_id: fromId464
from_id: fromId,465
land_col: landCol461
});466
});462
if (!miss && target)467
if (!miss && target)463
{468
{@@ -465,7 +470,8 @@ OfflineBattle.prototype._dispatchShots = function (fromId, core, planet, playerC465
at: this.clock + FLIGHT_DURATION,470
at: this.clock + FLIGHT_DURATION,466
targetId: target.id,471
targetId: target.id,467
color: shot.color,472
color: shot.color,468
fromId: fromId473
fromId: fromId,474
landCol: landCol469
});475
});470
}476
}471
}477
}@@ -484,7 +490,7 @@ OfflineBattle.prototype._deliver = function (playerCore)484
}490
}485
var core = this.coreFor(ev.targetId, playerCore);491
var core = this.coreFor(ev.targetId, playerCore);486
if (core && core.state === 'playing' && core.ingestGarbage)492
if (core && core.state === 'playing' && core.ingestGarbage)487
{ core.ingestGarbage(); }493
{ core.ingestGarbage(ev.landCol); }488
}494
}489
this.pending = keep;495
this.pending = keep;490
};496
};@@ -485,6 +485,174 @@ Online.easeInOutCubic = function (t)
485
485
return 1 - (u * u * u) / 2;
486
486
};
487
487
488
/** Bounding box of the player's field in viewport pixels. */
489
Online.playerFieldRect = function ()
490
{
491
var appRef = typeof app !== 'undefined' ? app : null;
492
var canvas = appRef && appRef.scene && appRef.scene.canvas;
493
if (canvas && canvas.getBoundingClientRect)
494
{ return canvas.getBoundingClientRect(); }
495
if (appRef && appRef.fieldW)
496
{
497
return {
498
left: appRef.fieldX,
499
top: appRef.fieldY,
500
right: appRef.fieldX + appRef.fieldW,
501
bottom: appRef.fieldY + appRef.fieldH,
502
width: appRef.fieldW,
503
height: appRef.fieldH
504
};
505
}
506
return null;
507
};
508
509
/**
510
* True if (x, y) is inside the field's interior. The top edge (a few
511
* pixels) is not interior: that is where arcs may land (t1128).
512
*/
513
Online.pointInFieldInterior = function (x, y, field, slop)
514
{
515
if (!field)
516
{ return false; }
517
slop = slop == null ? 6 : slop;
518
return x > field.left + 0.5 && x < field.right - 0.5
519
&& y > field.top + slop && y < field.bottom - 0.5;
520
};
521
522
/**
523
* Waypoints that route a player↔enemy arc around the field, never
524
* through its interior: up the outside, across above the top edge,
525
* then into the target (t1128). If both ends already sit at or above
526
* the top, a simple two-point path is enough.
527
*/
528
Online.waypointsAroundField = function (start, end, field, clearance)
529
{
530
if (!start || !end)
531
{ return [start || { x: 0, y: 0 }, end || { x: 0, y: 0 }]; }
532
if (!field)
533
{ return [start, end]; }
534
clearance = clearance || 64;
535
var top = field.top;
536
var left = field.left;
537
var right = field.right;
538
var pad = 10;
539
var apexY = Math.min(start.y, end.y, top) - clearance;
540
if (apexY < 8)
541
{ apexY = Math.max(8, top - Math.max(24, clearance * 0.5)); }
542
543
if (start.y <= top + 6 && end.y <= top + 6)
544
{ return [start, end]; }
545
546
var w1x = start.x;
547
var w2x = end.x;
548
if (start.x < left)
549
{ w1x = Math.min(start.x, left - pad); }
550
else if (start.x > right)
551
{ w1x = Math.max(start.x, right + pad); }
552
if (end.x < left)
553
{ w2x = Math.min(end.x, left - pad); }
554
else if (end.x > right)
555
{ w2x = Math.max(end.x, right + pad); }
556
557
return [
558
start,
559
{ x: w1x, y: apexY },
560
{ x: w2x, y: apexY },
561
end
562
];
563
};
564
565
/**
566
* Point at parameter u ∈ [0, 1] along a polyline, with a small upward
567
* bulge on each segment so the path reads as a "boogje".
568
*/
569
Online.pointOnPath = function (points, u)
570
{
571
u = u < 0 ? 0 : (u > 1 ? 1 : u);
572
if (!points || !points.length)
573
{ return { x: 0, y: 0 }; }
574
if (points.length === 1)
575
{ return { x: points[0].x, y: points[0].y }; }
576
var lens = [];
577
var total = 0;
578
for (var i = 1; i < points.length; i++)
579
{
580
var dx = points[i].x - points[i - 1].x;
581
var dy = points[i].y - points[i - 1].y;
582
var L = Math.sqrt(dx * dx + dy * dy);
583
if (L < 1)
584
{ L = 1; }
585
lens.push(L);
586
total += L;
587
}
588
var dist = u * total;
589
var acc = 0;
590
for (var i = 0; i < lens.length; i++)
591
{
592
if (acc + lens[i] >= dist || i === lens.length - 1)
593
{
594
var t = (dist - acc) / lens[i];
595
if (t < 0)
596
{ t = 0; }
597
if (t > 1)
598
{ t = 1; }
599
var a = points[i];
600
var b = points[i + 1];
601
var bump = 4 * 16 * t * (1 - t);
602
return {
603
x: a.x + (b.x - a.x) * t,
604
y: a.y + (b.y - a.y) * t - bump
605
};
606
}
607
acc += lens[i];
608
}
609
var last = points[points.length - 1];
610
return { x: last.x, y: last.y };
611
};
612
613
/** Sample a player↔enemy path; used by tests and the ticker. */
614
Online.aroundFieldPoint = function (start, end, u, field, clearance)
615
{
616
var pts = this.waypointsAroundField(start, end, field, clearance);
617
if (pts.length === 2)
618
{
619
var h = this.arcHeight(start, end);
620
return this.arcPoint(start, end, u, h);
621
}
622
return this.pointOnPath(pts, u);
623
};
624
625
Online.rememberLandCol = function (id, col)
626
{
627
if (id == null || col == null || !isFinite(col))
628
{ return; }
629
if (!this._pendingLandCol)
630
{ this._pendingLandCol = Object.create(null); }
631
this._pendingLandCol[String(id)] = col | 0;
632
};
633
634
/** Resolve the landing column for an incoming shot (t1126). */
635
Online.takeLandCol = function (incoming)
636
{
637
if (!incoming)
638
{ return null; }
639
if (incoming.land_col != null && isFinite(incoming.land_col))
640
{ return incoming.land_col | 0; }
641
if (!this._pendingLandCol)
642
{ return null; }
643
var keys = [];
644
if (incoming.id != null)
645
{ keys.push(String(incoming.id)); }
646
if (incoming.client_id)
647
{ keys.push(String(incoming.client_id)); }
648
for (var i = 0; i < keys.length; i++)
649
{
650
if (this._pendingLandCol[keys[i]] != null)
651
{ return this._pendingLandCol[keys[i]]; }
652
}
653
return null;
654
};
655
488
656
Online._miniCellSize = function (playerId)
489
657
{
490
658
var el = this.miniElement(playerId);
@@ -559,6 +727,21 @@ Online.spawnFlights = function (results, locals)
559
727
if (r.age != null && isFinite(r.age) && r.age * 1000 >= duration)
560
728
{ continue; }
561
729
730
var landCol = null;
731
if (r.land_col != null && isFinite(r.land_col))
732
{ landCol = r.land_col | 0; }
733
else if (meta.land_col != null && isFinite(meta.land_col))
734
{ landCol = meta.land_col | 0; }
735
else if (kind === 'enemy-to-player'
736
&& typeof app !== 'undefined' && app.core && app.core.pickGarbageColumn)
737
{ landCol = app.core.pickGarbageColumn(); }
738
if (landCol != null)
739
{
740
this.rememberLandCol(sid, landCol);
741
if (r.client_id)
742
{ this.rememberLandCol(r.client_id, landCol); }
743
}
744
562
745
var start;
563
746
if (meta.startX != null && isFinite(meta.startX))
564
747
{ start = { x: meta.startX, y: meta.startY }; }
@@ -571,9 +754,15 @@ Online.spawnFlights = function (results, locals)
571
754
if (miss)
572
755
{ end = this._missEnd(start, kind === 'enemy-miss'); }
573
756
else if (kind === 'enemy-to-player')
574
{ end = this._fieldTop(null); }
757
{ end = this._fieldTop(landCol != null ? landCol : 4.5); }
575
758
else
576
{ end = this._targetEnd(targetId, start); }
759
{ end = this._targetEnd(targetId, start, landCol); }
760
761
// Hits are ingested as grey garbage; draw them grey (t1130).
762
// Misses keep the sender's colour — nothing is received.
763
var flightColor = miss
764
? (r.color != null ? r.color : meta.color)
765
: -1;
577
766
578
767
var startScale;
579
768
var endScale;
@@ -608,7 +797,7 @@ Online.spawnFlights = function (results, locals)
608
797
609
798
var layer = (kind === 'enemy-to-enemy' && back) ? back : front;
610
799
var el = document.createElement('img');
611
el.src = colorSpriteUrl(r.color != null ? r.color : meta.color);
800
el.src = colorSpriteUrl(flightColor);
612
801
el.alt = '';
613
802
el.className = 'flight' + (kind === 'enemy-to-enemy' ? ' flight-behind' : '');
614
803
el.style.width = full + 'px';
@@ -624,6 +813,9 @@ Online.spawnFlights = function (results, locals)
624
813
var height = miss
625
814
? Math.max(40, Math.min(160, Math.abs(end.y - start.y) * 0.35))
626
815
: this.arcHeight(start, end);
816
var field = this.playerFieldRect();
817
var around = !miss && (kind === 'enemy-to-player' || kind === 'player-to-enemy');
818
var waypoints = around ? this.waypointsAroundField(start, end, field, height * 0.45) : null;
627
819
this._flights.push({
628
820
el: el,
629
821
start: start,
@@ -638,7 +830,11 @@ Online.spawnFlights = function (results, locals)
638
830
startScale: startScale,
639
831
endScale: endScale,
640
832
angle: Math.random() * 360,
641
id: sid
833
id: sid,
834
landCol: landCol,
835
field: field,
836
waypoints: waypoints,
837
color: flightColor
642
838
});
643
839
}
644
840
this._flightLocals = {};
@@ -680,14 +876,17 @@ Online._flightStart = function (col)
680
876
return { x: window.innerWidth / 2, y: window.innerHeight * 0.3 };
681
877
};
682
878
683
Online._targetEnd = function (targetId, start)
879
Online._targetEnd = function (targetId, start, col)
684
880
{
685
881
var el = targetId && this.miniElement(targetId);
686
882
if (el)
687
883
{
688
884
var canvas = el.querySelector('canvas') || el;
689
885
var r = canvas.getBoundingClientRect();
690
return { x: r.left + r.width / 2, y: r.top + r.height / 2 };
886
var x = r.left + r.width / 2;
887
if (col != null && isFinite(col))
888
{ x = r.left + ((col + 0.5) / 10) * r.width; }
889
return { x: x, y: r.top + 4 };
691
890
}
692
891
return { x: start.x + (Math.random() - 0.5) * 80, y: 40 };
693
892
};
@@ -747,6 +946,18 @@ Online.tickFlights = function (now)
747
946
x = mt * mt * f.start.x + 2 * mt * e * f.ctrl.x + e * e * f.end.x;
748
947
y = mt * mt * f.start.y + 2 * mt * e * f.ctrl.y + e * e * f.end.y;
749
948
}
949
else if (f.waypoints && f.waypoints.length > 2)
950
{
951
var pt = this.pointOnPath(f.waypoints, u);
952
x = pt.x;
953
y = pt.y;
954
}
955
else if (f.waypoints && f.field)
956
{
957
var pt = this.aroundFieldPoint(f.start, f.end, u, f.field, (f.height || 80) * 0.45);
958
x = pt.x;
959
y = pt.y;
960
}
750
961
else
751
962
{
752
963
var pt = this.arcPoint(f.start, f.end, u, f.height || 80);
@@ -789,6 +1000,7 @@ Online.clearFlights = function ()
789
1000
this._flights = [];
790
1001
this._flightLocals = {};
791
1002
this._flightSeen = Object.create(null);
1003
this._pendingLandCol = Object.create(null);
792
1004
};
793
1005
794
1006
if (typeof globalThis !== 'undefined')
@@ -485,6 +485,174 @@ Online.easeInOutCubic = function (t)485
return 1 - (u * u * u) / 2;485
return 1 - (u * u * u) / 2;486
};486
};487
487
488
/** Bounding box of the player's field in viewport pixels. */489
Online.playerFieldRect = function ()490
{491
var appRef = typeof app !== 'undefined' ? app : null;492
var canvas = appRef && appRef.scene && appRef.scene.canvas;493
if (canvas && canvas.getBoundingClientRect)494
{ return canvas.getBoundingClientRect(); }495
if (appRef && appRef.fieldW)496
{497
return {498
left: appRef.fieldX,499
top: appRef.fieldY,500
right: appRef.fieldX + appRef.fieldW,501
bottom: appRef.fieldY + appRef.fieldH,502
width: appRef.fieldW,503
height: appRef.fieldH504
};505
}506
return null;507
};508
509
/**510
* True if (x, y) is inside the field's interior. The top edge (a few511
* pixels) is not interior: that is where arcs may land (t1128).512
*/513
Online.pointInFieldInterior = function (x, y, field, slop)514
{515
if (!field)516
{ return false; }517
slop = slop == null ? 6 : slop;518
return x > field.left + 0.5 && x < field.right - 0.5519
&& y > field.top + slop && y < field.bottom - 0.5;520
};521
522
/**523
* Waypoints that route a player↔enemy arc around the field, never524
* through its interior: up the outside, across above the top edge,525
* then into the target (t1128). If both ends already sit at or above526
* the top, a simple two-point path is enough.527
*/528
Online.waypointsAroundField = function (start, end, field, clearance)529
{530
if (!start || !end)531
{ return [start || { x: 0, y: 0 }, end || { x: 0, y: 0 }]; }532
if (!field)533
{ return [start, end]; }534
clearance = clearance || 64;535
var top = field.top;536
var left = field.left;537
var right = field.right;538
var pad = 10;539
var apexY = Math.min(start.y, end.y, top) - clearance;540
if (apexY < 8)541
{ apexY = Math.max(8, top - Math.max(24, clearance * 0.5)); }542
543
if (start.y <= top + 6 && end.y <= top + 6)544
{ return [start, end]; }545
546
var w1x = start.x;547
var w2x = end.x;548
if (start.x < left)549
{ w1x = Math.min(start.x, left - pad); }550
else if (start.x > right)551
{ w1x = Math.max(start.x, right + pad); }552
if (end.x < left)553
{ w2x = Math.min(end.x, left - pad); }554
else if (end.x > right)555
{ w2x = Math.max(end.x, right + pad); }556
557
return [558
start,559
{ x: w1x, y: apexY },560
{ x: w2x, y: apexY },561
end562
];563
};564
565
/**566
* Point at parameter u ∈ [0, 1] along a polyline, with a small upward567
* bulge on each segment so the path reads as a "boogje".568
*/569
Online.pointOnPath = function (points, u)570
{571
u = u < 0 ? 0 : (u > 1 ? 1 : u);572
if (!points || !points.length)573
{ return { x: 0, y: 0 }; }574
if (points.length === 1)575
{ return { x: points[0].x, y: points[0].y }; }576
var lens = [];577
var total = 0;578
for (var i = 1; i < points.length; i++)579
{580
var dx = points[i].x - points[i - 1].x;581
var dy = points[i].y - points[i - 1].y;582
var L = Math.sqrt(dx * dx + dy * dy);583
if (L < 1)584
{ L = 1; }585
lens.push(L);586
total += L;587
}588
var dist = u * total;589
var acc = 0;590
for (var i = 0; i < lens.length; i++)591
{592
if (acc + lens[i] >= dist || i === lens.length - 1)593
{594
var t = (dist - acc) / lens[i];595
if (t < 0)596
{ t = 0; }597
if (t > 1)598
{ t = 1; }599
var a = points[i];600
var b = points[i + 1];601
var bump = 4 * 16 * t * (1 - t);602
return {603
x: a.x + (b.x - a.x) * t,604
y: a.y + (b.y - a.y) * t - bump605
};606
}607
acc += lens[i];608
}609
var last = points[points.length - 1];610
return { x: last.x, y: last.y };611
};612
613
/** Sample a player↔enemy path; used by tests and the ticker. */614
Online.aroundFieldPoint = function (start, end, u, field, clearance)615
{616
var pts = this.waypointsAroundField(start, end, field, clearance);617
if (pts.length === 2)618
{619
var h = this.arcHeight(start, end);620
return this.arcPoint(start, end, u, h);621
}622
return this.pointOnPath(pts, u);623
};624
625
Online.rememberLandCol = function (id, col)626
{627
if (id == null || col == null || !isFinite(col))628
{ return; }629
if (!this._pendingLandCol)630
{ this._pendingLandCol = Object.create(null); }631
this._pendingLandCol[String(id)] = col | 0;632
};633
634
/** Resolve the landing column for an incoming shot (t1126). */635
Online.takeLandCol = function (incoming)636
{637
if (!incoming)638
{ return null; }639
if (incoming.land_col != null && isFinite(incoming.land_col))640
{ return incoming.land_col | 0; }641
if (!this._pendingLandCol)642
{ return null; }643
var keys = [];644
if (incoming.id != null)645
{ keys.push(String(incoming.id)); }646
if (incoming.client_id)647
{ keys.push(String(incoming.client_id)); }648
for (var i = 0; i < keys.length; i++)649
{650
if (this._pendingLandCol[keys[i]] != null)651
{ return this._pendingLandCol[keys[i]]; }652
}653
return null;654
};655
488
Online._miniCellSize = function (playerId)656
Online._miniCellSize = function (playerId)489
{657
{490
var el = this.miniElement(playerId);658
var el = this.miniElement(playerId);@@ -559,6 +727,21 @@ Online.spawnFlights = function (results, locals)559
if (r.age != null && isFinite(r.age) && r.age * 1000 >= duration)727
if (r.age != null && isFinite(r.age) && r.age * 1000 >= duration)560
{ continue; }728
{ continue; }561
729
730
var landCol = null;731
if (r.land_col != null && isFinite(r.land_col))732
{ landCol = r.land_col | 0; }733
else if (meta.land_col != null && isFinite(meta.land_col))734
{ landCol = meta.land_col | 0; }735
else if (kind === 'enemy-to-player'736
&& typeof app !== 'undefined' && app.core && app.core.pickGarbageColumn)737
{ landCol = app.core.pickGarbageColumn(); }738
if (landCol != null)739
{740
this.rememberLandCol(sid, landCol);741
if (r.client_id)742
{ this.rememberLandCol(r.client_id, landCol); }743
}744
562
var start;745
var start;563
if (meta.startX != null && isFinite(meta.startX))746
if (meta.startX != null && isFinite(meta.startX))564
{ start = { x: meta.startX, y: meta.startY }; }747
{ start = { x: meta.startX, y: meta.startY }; }@@ -571,9 +754,15 @@ Online.spawnFlights = function (results, locals)571
if (miss)754
if (miss)572
{ end = this._missEnd(start, kind === 'enemy-miss'); }755
{ end = this._missEnd(start, kind === 'enemy-miss'); }573
else if (kind === 'enemy-to-player')756
else if (kind === 'enemy-to-player')574
{ end = this._fieldTop(null); }757
{ end = this._fieldTop(landCol != null ? landCol : 4.5); }575
else758
else576
{ end = this._targetEnd(targetId, start); }759
{ end = this._targetEnd(targetId, start, landCol); }760
761
// Hits are ingested as grey garbage; draw them grey (t1130).762
// Misses keep the sender's colour — nothing is received.763
var flightColor = miss764
? (r.color != null ? r.color : meta.color)765
: -1;577
766
578
var startScale;767
var startScale;579
var endScale;768
var endScale;@@ -608,7 +797,7 @@ Online.spawnFlights = function (results, locals)608
797
609
var layer = (kind === 'enemy-to-enemy' && back) ? back : front;798
var layer = (kind === 'enemy-to-enemy' && back) ? back : front;610
var el = document.createElement('img');799
var el = document.createElement('img');611
el.src = colorSpriteUrl(r.color != null ? r.color : meta.color);800
el.src = colorSpriteUrl(flightColor);612
el.alt = '';801
el.alt = '';613
el.className = 'flight' + (kind === 'enemy-to-enemy' ? ' flight-behind' : '');802
el.className = 'flight' + (kind === 'enemy-to-enemy' ? ' flight-behind' : '');614
el.style.width = full + 'px';803
el.style.width = full + 'px';@@ -624,6 +813,9 @@ Online.spawnFlights = function (results, locals)624
var height = miss813
var height = miss625
? Math.max(40, Math.min(160, Math.abs(end.y - start.y) * 0.35))814
? Math.max(40, Math.min(160, Math.abs(end.y - start.y) * 0.35))626
: this.arcHeight(start, end);815
: this.arcHeight(start, end);816
var field = this.playerFieldRect();817
var around = !miss && (kind === 'enemy-to-player' || kind === 'player-to-enemy');818
var waypoints = around ? this.waypointsAroundField(start, end, field, height * 0.45) : null;627
this._flights.push({819
this._flights.push({628
el: el,820
el: el,629
start: start,821
start: start,@@ -638,7 +830,11 @@ Online.spawnFlights = function (results, locals)638
startScale: startScale,830
startScale: startScale,639
endScale: endScale,831
endScale: endScale,640
angle: Math.random() * 360,832
angle: Math.random() * 360,641
id: sid833
id: sid,834
landCol: landCol,835
field: field,836
waypoints: waypoints,837
color: flightColor642
});838
});643
}839
}644
this._flightLocals = {};840
this._flightLocals = {};@@ -680,14 +876,17 @@ Online._flightStart = function (col)680
return { x: window.innerWidth / 2, y: window.innerHeight * 0.3 };876
return { x: window.innerWidth / 2, y: window.innerHeight * 0.3 };681
};877
};682
878
683
Online._targetEnd = function (targetId, start)879
Online._targetEnd = function (targetId, start, col)684
{880
{685
var el = targetId && this.miniElement(targetId);881
var el = targetId && this.miniElement(targetId);686
if (el)882
if (el)687
{883
{688
var canvas = el.querySelector('canvas') || el;884
var canvas = el.querySelector('canvas') || el;689
var r = canvas.getBoundingClientRect();885
var r = canvas.getBoundingClientRect();690
return { x: r.left + r.width / 2, y: r.top + r.height / 2 };886
var x = r.left + r.width / 2;887
if (col != null && isFinite(col))888
{ x = r.left + ((col + 0.5) / 10) * r.width; }889
return { x: x, y: r.top + 4 };691
}890
}692
return { x: start.x + (Math.random() - 0.5) * 80, y: 40 };891
return { x: start.x + (Math.random() - 0.5) * 80, y: 40 };693
};892
};@@ -747,6 +946,18 @@ Online.tickFlights = function (now)747
x = mt * mt * f.start.x + 2 * mt * e * f.ctrl.x + e * e * f.end.x;946
x = mt * mt * f.start.x + 2 * mt * e * f.ctrl.x + e * e * f.end.x;748
y = mt * mt * f.start.y + 2 * mt * e * f.ctrl.y + e * e * f.end.y;947
y = mt * mt * f.start.y + 2 * mt * e * f.ctrl.y + e * e * f.end.y;749
}948
}949
else if (f.waypoints && f.waypoints.length > 2)950
{951
var pt = this.pointOnPath(f.waypoints, u);952
x = pt.x;953
y = pt.y;954
}955
else if (f.waypoints && f.field)956
{957
var pt = this.aroundFieldPoint(f.start, f.end, u, f.field, (f.height || 80) * 0.45);958
x = pt.x;959
y = pt.y;960
}750
else961
else751
{962
{752
var pt = this.arcPoint(f.start, f.end, u, f.height || 80);963
var pt = this.arcPoint(f.start, f.end, u, f.height || 80);@@ -789,6 +1000,7 @@ Online.clearFlights = function ()789
this._flights = [];1000
this._flights = [];790
this._flightLocals = {};1001
this._flightLocals = {};791
this._flightSeen = Object.create(null);1002
this._flightSeen = Object.create(null);1003
this._pendingLandCol = Object.create(null);792
};1004
};793
1005
794
if (typeof globalThis !== 'undefined')1006
if (typeof globalThis !== 'undefined')@@ -0,0 +1,146 @@
1
'use strict';
2
3
const { describe, it } = require('node:test');
4
const assert = require('node:assert/strict');
5
const { makeGame, GameCore, Planet, Rng } = require('./helpers.js');
6
const Offline = require('../src/offline.js');
7
const Online = require('../src/online.js');
8
const MiniLayout = require('../src/miniLayout.js');
9
10
describe('Garbage landing column (t1126)', () =>
11
{
12
it('pickGarbageColumn keeps a preferred open column', () =>
13
{
14
const g = makeGame({ noSpawn: true, seed: 3 });
15
assert.equal(g.pickGarbageColumn(4), 4);
16
assert.equal(g.ingestGarbage(4).col, 4);
17
});
18
19
it('pickGarbageColumn skips a full preferred column and still returns an open one', () =>
20
{
21
const g = makeGame({ noSpawn: true, seed: 3 });
22
for (let r = 0; r < 13; r++)
23
{ g.place(4, r, r % 5); }
24
const col = g.pickGarbageColumn(4);
25
assert.notEqual(col, 4);
26
assert.ok(col >= 0 && col < 10);
27
const block = g.ingestGarbage(4);
28
assert.notEqual(block.col, 4, 'ingest also skips the full preferred column');
29
assert.ok(block.col >= 0 && block.col < 10);
30
});
31
32
it('offline dispatch picks land_col and ingest uses the same column', () =>
33
{
34
const easy = Planet.createPlanet({ jumpsToClear: 1, fallTime: 5, riseTime: 3, id: 'easy' });
35
const hitRng = () => 0.99;
36
const battle = Offline.createBattle({ playerPlanet: easy, rng: hitRng, round: 1 });
37
const player = makeGame({ noSpawn: true });
38
// Bot shoots at the player: from_id is the bot.
39
const bot = battle.bots[0];
40
bot.core.outgoingShots.push({ id: 11, color: 2, col: 3, y: 13 });
41
battle.tick(0.01, player);
42
const flight = battle.flightResults.find((f) => f.from_id === bot.id && !f.miss);
43
assert.ok(flight, 'bot hit the player');
44
assert.equal(typeof flight.land_col, 'number');
45
assert.ok(flight.land_col >= 0 && flight.land_col < 10);
46
assert.equal(battle.pending[0].landCol, flight.land_col);
47
const before = player.blocks.length;
48
battle.tick(Offline.FLIGHT_DURATION + 0.05, player);
49
assert.equal(battle.pending.length, 0);
50
const greys = player.blocks.filter((b) => b.color === GameCore.COLOR_GRAY);
51
assert.ok(greys.length >= 1, 'player received grey garbage');
52
assert.equal(greys[greys.length - 1].col, flight.land_col,
53
'ingested column matches the flight land_col');
54
assert.ok(player.blocks.length > before);
55
});
56
});
57
58
describe('Around-field flight path (t1128)', () =>
59
{
60
const field = { left: 335, top: 173, right: 335 + 550, bottom: 173 + 715 };
61
62
it('routes a left-mini shot around the field into a given column', () =>
63
{
64
const start = { x: 250, y: 700 };
65
const end = {
66
x: field.left + (3 + 0.5) / 10 * (field.right - field.left),
67
y: field.top + 4
68
};
69
const pts = Online.waypointsAroundField(start, end, field, 72);
70
assert.ok(pts.length >= 2);
71
for (let i = 0; i <= 20; i++)
72
{
73
const u = i / 20;
74
const p = Online.aroundFieldPoint(start, end, u, field, 72);
75
assert.equal(Online.pointInFieldInterior(p.x, p.y, field), false,
76
'u=' + u + ' is inside the field at ' + p.x + ',' + p.y);
77
}
78
const landed = Online.aroundFieldPoint(start, end, 1, field, 72);
79
assert.ok(Math.abs(landed.x - end.x) < 0.5, 'ends at the landing column x');
80
assert.ok(Math.abs(landed.y - end.y) < 1, 'ends at the field top');
81
});
82
83
it('routes a player shot around the field to a right-hand mini', () =>
84
{
85
const start = {
86
x: field.left + (6 + 0.5) / 10 * (field.right - field.left),
87
y: field.top + 4
88
};
89
const end = { x: field.right + 80, y: 700 };
90
for (let i = 0; i <= 20; i++)
91
{
92
const p = Online.aroundFieldPoint(start, end, i / 20, field, 72);
93
assert.equal(Online.pointInFieldInterior(p.x, p.y, field), false,
94
'player→enemy u=' + (i / 20) + ' crosses the field');
95
}
96
});
97
98
it('a path already above the field stays as a simple arc above it', () =>
99
{
100
const start = { x: 400, y: 80 };
101
const end = { x: 600, y: field.top + 4 };
102
const pts = Online.waypointsAroundField(start, end, field, 72);
103
assert.equal(pts.length, 2, 'no extra waypoints when both ends are above');
104
for (let i = 0; i <= 16; i++)
105
{
106
const p = Online.aroundFieldPoint(start, end, i / 16, field, 72);
107
assert.equal(Online.pointInFieldInterior(p.x, p.y, field), false);
108
assert.ok(p.y <= field.top + 6, 'stays at or above the top edge, y=' + p.y);
109
}
110
});
111
});
112
113
describe('Wide-layout top padding (t1129)', () =>
114
{
115
it('leaves room above the field on a wide screen, not on narrow or mobile', () =>
116
{
117
const wide = MiniLayout.plan(1280, 900, 2, 70, 8);
118
assert.equal(wide.mode, 'sides');
119
assert.ok(wide.fieldY >= 70 + MiniLayout.ARC_TOP_PAD - 1,
120
'fieldY=' + wide.fieldY + ' should be at least hud+pad=' + (70 + MiniLayout.ARC_TOP_PAD));
121
assert.ok(wide.fieldY - 70 >= MiniLayout.ARC_TOP_PAD * 0.9);
122
123
const narrow = MiniLayout.plan(720, 800, 2, 70, 8);
124
assert.equal(narrow.mode, 'top');
125
// Unchanged: top band is hud + miniH, no arc pad.
126
assert.ok(narrow.miniH > 0);
127
assert.ok(narrow.fieldY >= 70 + narrow.miniH - 1);
128
129
const mobile = MiniLayout.plan(393, 851, 1, 60, 6);
130
assert.equal(mobile.mode, 'top');
131
});
132
});
133
134
describe('takeLandCol consistency (t1126)', () =>
135
{
136
it('prefers the server land_col and falls back to a remembered id', () =>
137
{
138
Online._pendingLandCol = Object.create(null);
139
assert.equal(Online.takeLandCol({ id: 9, land_col: 6 }), 6);
140
Online.rememberLandCol('abc', 2);
141
assert.equal(Online.takeLandCol({ client_id: 'abc' }), 2);
142
// Server value wins over the remembered one.
143
assert.equal(Online.takeLandCol({ client_id: 'abc', land_col: 8 }), 8);
144
assert.equal(Online.takeLandCol({ id: 1 }), null);
145
});
146
});
@@ -0,0 +1,146 @@1
'use strict';2
3
const { describe, it } = require('node:test');4
const assert = require('node:assert/strict');5
const { makeGame, GameCore, Planet, Rng } = require('./helpers.js');6
const Offline = require('../src/offline.js');7
const Online = require('../src/online.js');8
const MiniLayout = require('../src/miniLayout.js');9
10
describe('Garbage landing column (t1126)', () =>11
{12
it('pickGarbageColumn keeps a preferred open column', () =>13
{14
const g = makeGame({ noSpawn: true, seed: 3 });15
assert.equal(g.pickGarbageColumn(4), 4);16
assert.equal(g.ingestGarbage(4).col, 4);17
});18
19
it('pickGarbageColumn skips a full preferred column and still returns an open one', () =>20
{21
const g = makeGame({ noSpawn: true, seed: 3 });22
for (let r = 0; r < 13; r++)23
{ g.place(4, r, r % 5); }24
const col = g.pickGarbageColumn(4);25
assert.notEqual(col, 4);26
assert.ok(col >= 0 && col < 10);27
const block = g.ingestGarbage(4);28
assert.notEqual(block.col, 4, 'ingest also skips the full preferred column');29
assert.ok(block.col >= 0 && block.col < 10);30
});31
32
it('offline dispatch picks land_col and ingest uses the same column', () =>33
{34
const easy = Planet.createPlanet({ jumpsToClear: 1, fallTime: 5, riseTime: 3, id: 'easy' });35
const hitRng = () => 0.99;36
const battle = Offline.createBattle({ playerPlanet: easy, rng: hitRng, round: 1 });37
const player = makeGame({ noSpawn: true });38
// Bot shoots at the player: from_id is the bot.39
const bot = battle.bots[0];40
bot.core.outgoingShots.push({ id: 11, color: 2, col: 3, y: 13 });41
battle.tick(0.01, player);42
const flight = battle.flightResults.find((f) => f.from_id === bot.id && !f.miss);43
assert.ok(flight, 'bot hit the player');44
assert.equal(typeof flight.land_col, 'number');45
assert.ok(flight.land_col >= 0 && flight.land_col < 10);46
assert.equal(battle.pending[0].landCol, flight.land_col);47
const before = player.blocks.length;48
battle.tick(Offline.FLIGHT_DURATION + 0.05, player);49
assert.equal(battle.pending.length, 0);50
const greys = player.blocks.filter((b) => b.color === GameCore.COLOR_GRAY);51
assert.ok(greys.length >= 1, 'player received grey garbage');52
assert.equal(greys[greys.length - 1].col, flight.land_col,53
'ingested column matches the flight land_col');54
assert.ok(player.blocks.length > before);55
});56
});57
58
describe('Around-field flight path (t1128)', () =>59
{60
const field = { left: 335, top: 173, right: 335 + 550, bottom: 173 + 715 };61
62
it('routes a left-mini shot around the field into a given column', () =>63
{64
const start = { x: 250, y: 700 };65
const end = {66
x: field.left + (3 + 0.5) / 10 * (field.right - field.left),67
y: field.top + 468
};69
const pts = Online.waypointsAroundField(start, end, field, 72);70
assert.ok(pts.length >= 2);71
for (let i = 0; i <= 20; i++)72
{73
const u = i / 20;74
const p = Online.aroundFieldPoint(start, end, u, field, 72);75
assert.equal(Online.pointInFieldInterior(p.x, p.y, field), false,76
'u=' + u + ' is inside the field at ' + p.x + ',' + p.y);77
}78
const landed = Online.aroundFieldPoint(start, end, 1, field, 72);79
assert.ok(Math.abs(landed.x - end.x) < 0.5, 'ends at the landing column x');80
assert.ok(Math.abs(landed.y - end.y) < 1, 'ends at the field top');81
});82
83
it('routes a player shot around the field to a right-hand mini', () =>84
{85
const start = {86
x: field.left + (6 + 0.5) / 10 * (field.right - field.left),87
y: field.top + 488
};89
const end = { x: field.right + 80, y: 700 };90
for (let i = 0; i <= 20; i++)91
{92
const p = Online.aroundFieldPoint(start, end, i / 20, field, 72);93
assert.equal(Online.pointInFieldInterior(p.x, p.y, field), false,94
'player→enemy u=' + (i / 20) + ' crosses the field');95
}96
});97
98
it('a path already above the field stays as a simple arc above it', () =>99
{100
const start = { x: 400, y: 80 };101
const end = { x: 600, y: field.top + 4 };102
const pts = Online.waypointsAroundField(start, end, field, 72);103
assert.equal(pts.length, 2, 'no extra waypoints when both ends are above');104
for (let i = 0; i <= 16; i++)105
{106
const p = Online.aroundFieldPoint(start, end, i / 16, field, 72);107
assert.equal(Online.pointInFieldInterior(p.x, p.y, field), false);108
assert.ok(p.y <= field.top + 6, 'stays at or above the top edge, y=' + p.y);109
}110
});111
});112
113
describe('Wide-layout top padding (t1129)', () =>114
{115
it('leaves room above the field on a wide screen, not on narrow or mobile', () =>116
{117
const wide = MiniLayout.plan(1280, 900, 2, 70, 8);118
assert.equal(wide.mode, 'sides');119
assert.ok(wide.fieldY >= 70 + MiniLayout.ARC_TOP_PAD - 1,120
'fieldY=' + wide.fieldY + ' should be at least hud+pad=' + (70 + MiniLayout.ARC_TOP_PAD));121
assert.ok(wide.fieldY - 70 >= MiniLayout.ARC_TOP_PAD * 0.9);122
123
const narrow = MiniLayout.plan(720, 800, 2, 70, 8);124
assert.equal(narrow.mode, 'top');125
// Unchanged: top band is hud + miniH, no arc pad.126
assert.ok(narrow.miniH > 0);127
assert.ok(narrow.fieldY >= 70 + narrow.miniH - 1);128
129
const mobile = MiniLayout.plan(393, 851, 1, 60, 6);130
assert.equal(mobile.mode, 'top');131
});132
});133
134
describe('takeLandCol consistency (t1126)', () =>135
{136
it('prefers the server land_col and falls back to a remembered id', () =>137
{138
Online._pendingLandCol = Object.create(null);139
assert.equal(Online.takeLandCol({ id: 9, land_col: 6 }), 6);140
Online.rememberLandCol('abc', 2);141
assert.equal(Online.takeLandCol({ client_id: 'abc' }), 2);142
// Server value wins over the remembered one.143
assert.equal(Online.takeLandCol({ client_id: 'abc', land_col: 8 }), 8);144
assert.equal(Online.takeLandCol({ id: 1 }), null);145
});146
});@@ -116,12 +116,13 @@ LAYOUT_INFO = """() => {
116
116
}"""
117
117
118
118
119
INJECT_FLIGHTS = """() => {
119
120
INJECT_FLIGHTS = """(age) => {
121
if (age == null) age = 0.55;
120
122
const plan = app.miniLayout;
121
123
const field = app.scene.canvas.getBoundingClientRect();
122
const minis = [...document.querySelectorAll('#minis .mini')];
123
124
function anchor(id, inner) {
124
const el = document.querySelector('#minis .mini[data-player=\"' + id + '\"] canvas');
125
const el = document.querySelector('#minis .mini[data-player="' + id + '"] canvas');
125
126
if (!el) return { x: 80, y: 80 };
126
127
const r = el.getBoundingClientRect();
127
128
if (plan && plan.mode === 'sides') {
@@ -135,47 +136,88 @@ INJECT_FLIGHTS = """() => {
135
136
const bots = (app.battle.bots || []).map(b => b.id);
136
137
const a = bots[0] || 'bot-1';
137
138
const b = bots[1] || bots[0] || 'bot-2';
139
const landCol = 3;
138
140
const pStart = {
139
x: field.left + field.width / 2,
141
x: field.left + ((4 + 0.5) / 10) * field.width,
140
142
y: field.top + 4
141
143
};
142
144
if (typeof Online.clearFlights === 'function') Online.clearFlights();
143
145
const flights = [
144
{ id: 'vis-p2e', client_id: 'vis-p2e', from_id: 'player', target_id: a, miss: false, color: 0, flight_duration: 1.2, age: 0.55 },
145
{ id: 'vis-e2p', client_id: 'vis-e2p', from_id: a, target_id: 'player', miss: false, color: 1, flight_duration: 1.2, age: 0.55 },
146
{ id: 'vis-e2e', client_id: 'vis-e2e', from_id: a, target_id: b, miss: false, color: 2, flight_duration: 1.2, age: 0.55 },
147
{ id: 'vis-emiss', client_id: 'vis-emiss', from_id: b, target_id: null, miss: true, color: 3, flight_duration: 1.2, age: 0.45 }
146
{ id: 'vis-p2e', client_id: 'vis-p2e', from_id: 'player', target_id: a, miss: false, color: 0, flight_duration: 1.2, age: age, land_col: landCol },
147
{ id: 'vis-e2p', client_id: 'vis-e2p', from_id: a, target_id: 'player', miss: false, color: 1, flight_duration: 1.2, age: age, land_col: landCol },
148
{ id: 'vis-e2e', client_id: 'vis-e2e', from_id: a, target_id: b, miss: false, color: 2, flight_duration: 1.2, age: age, land_col: 7 },
149
{ id: 'vis-emiss', client_id: 'vis-emiss', from_id: b, target_id: null, miss: true, color: 3, flight_duration: 1.2, age: Math.min(age, 0.45) }
148
150
];
149
151
const aOut = anchor(a, true);
150
152
const bOut = anchor(b, true);
151
153
const locals = {
152
'vis-p2e': { from_id: 'player', color: 0, startX: pStart.x, startY: pStart.y, col: 4 },
153
'vis-e2p': { from_id: a, color: 1, startX: aOut.x, startY: aOut.y },
154
'vis-e2e': { from_id: a, color: 2, startX: aOut.x, startY: aOut.y },
154
'vis-p2e': { from_id: 'player', color: 0, startX: pStart.x, startY: pStart.y, col: 4, land_col: landCol },
155
'vis-e2p': { from_id: a, color: 1, startX: aOut.x, startY: aOut.y, land_col: landCol },
156
'vis-e2e': { from_id: a, color: 2, startX: aOut.x, startY: aOut.y, land_col: 7 },
155
157
'vis-emiss': { from_id: b, color: 3, startX: bOut.x, startY: bOut.y }
156
158
};
157
159
Online.spawnFlights(flights, locals);
158
160
Online.tickFlights();
159
161
const front = [...document.querySelectorAll('#flights .flight')].map(el => ({
160
cls: el.className,
162
src: el.getAttribute('src') || el.src,
161
163
transform: el.style.transform,
162
opacity: el.style.opacity,
163
164
parent: 'front'
164
165
}));
165
166
const back = [...document.querySelectorAll('#flights-back .flight')].map(el => ({
166
cls: el.className,
167
src: el.getAttribute('src') || el.src,
167
168
transform: el.style.transform,
168
opacity: el.style.opacity,
169
169
parent: 'back'
170
170
}));
171
const kinds = (Online._flights || []).map(f => {
172
const raw = Math.min(0.999, Math.max(0, (performance.now() - f.t0) / f.duration));
173
const u = Online.easeInOutCubic(raw);
174
let pt;
175
if (f.waypoints && f.waypoints.length > 2)
176
{ pt = Online.pointOnPath(f.waypoints, u); }
177
else if (f.kind === 'enemy-to-player' || f.kind === 'player-to-enemy')
178
{ pt = Online.aroundFieldPoint(f.start, f.end, u, f.field, (f.height || 80) * 0.45); }
179
else
180
{ pt = Online.arcPoint(f.start, f.end, u, f.height || 80); }
181
const samples = [];
182
if (f.kind === 'enemy-to-player' || f.kind === 'player-to-enemy')
183
{
184
for (let i = 0; i <= 16; i++)
185
{
186
const su = i / 16;
187
let sp;
188
if (f.waypoints && f.waypoints.length > 2)
189
{ sp = Online.pointOnPath(f.waypoints, su); }
190
else
191
{ sp = Online.aroundFieldPoint(f.start, f.end, su, f.field, (f.height || 80) * 0.45); }
192
samples.push({
193
u: su, x: sp.x, y: sp.y,
194
inside: Online.pointInFieldInterior(sp.x, sp.y, f.field)
195
});
196
}
197
}
198
return {
199
kind: f.kind, miss: f.miss,
200
startScale: f.startScale, endScale: f.endScale,
201
parent: (f.el && f.el.parentElement && f.el.parentElement.id) || '',
202
src: (f.el && (f.el.getAttribute('src') || f.el.src)) || '',
203
color: f.color,
204
landCol: f.landCol,
205
end: f.end,
206
pos: pt,
207
samples: samples,
208
insideNow: f.field ? Online.pointInFieldInterior(pt.x, pt.y, f.field) : false
209
};
210
});
211
const expectedEndX = field.left + ((landCol + 0.5) / 10) * field.width;
171
212
return {
172
213
front: front.length,
173
214
back: back.length,
174
kinds: (Online._flights || []).map(f => ({
175
kind: f.kind, miss: f.miss,
176
startScale: f.startScale, endScale: f.endScale,
177
parent: (f.el && f.el.parentElement && f.el.parentElement.id) || ''
178
}))
215
kinds,
216
expectedEndX,
217
field: { left: field.left, right: field.right, top: field.top, bottom: field.bottom },
218
pad: field.top,
219
hudH: app.hudH,
220
mode: plan.mode
179
221
};
180
222
}"""
181
223
@@ -186,6 +228,12 @@ def assert_sides(info, tag, expect_rows=False):
186
228
field = info["field"]
187
229
minis = info["minis"]
188
230
check(len(minis) >= 1, f"{tag}: at least one mini ({len(minis)})")
231
if field:
232
# t1129: room above the field for around-the-top arcs
233
gap = field["top"] - 50 # HUD is ~56–80; require a clear pad
234
check(field["top"] >= (info.get("hud") or 70) + 80
235
or field["y"] >= 70 + 80,
236
f"{tag}: wide layout has top padding (field.top={field['top']:.1f}, y={field.get('y')})")
189
237
if not field or not minis:
190
238
return
191
239
for i, m in enumerate(minis):
@@ -202,7 +250,6 @@ def assert_sides(info, tag, expect_rows=False):
202
250
check(m["top"] >= 50,
203
251
f"{tag}: mini {i} stays under the HUD (top={m['top']:.1f})")
204
252
if expect_rows and len(minis) >= 3:
205
# 3rd (index 2) is left, stacked above the first
206
253
check(minis[2]["bottom"] <= minis[0]["top"] + 4,
207
254
f"{tag}: third mini is stacked above the first "
208
255
f"(b={minis[2]['bottom']:.1f} vs top={minis[0]['top']:.1f})")
@@ -222,7 +269,7 @@ def assert_top(info, tag):
222
269
f"(bottom={m['bottom']:.1f} field.top={field['top']:.1f})")
223
270
224
271
225
def assert_flights(info, tag, expect_behind=True):
272
def assert_flights(info, tag, expect_behind=True, expect_around=True):
226
273
check(info["front"] >= 3, f"{tag}: front flights present ({info['front']})")
227
274
kinds = {k["kind"]: k for k in info["kinds"]}
228
275
check("player-to-enemy" in kinds, f"{tag}: player-to-enemy")
@@ -232,10 +279,33 @@ def assert_flights(info, tag, expect_behind=True):
232
279
k = kinds["player-to-enemy"]
233
280
check(k["startScale"] > k["endScale"],
234
281
f"{tag}: player-to-enemy shrinks ({k['startScale']:.2f}→{k['endScale']:.2f})")
282
check("gray" in (k.get("src") or "").lower() or k.get("color") == -1,
283
f"{tag}: player-to-enemy is grey (src={k.get('src')} color={k.get('color')})")
235
284
if "enemy-to-player" in kinds:
236
285
k = kinds["enemy-to-player"]
237
286
check(k["endScale"] > k["startScale"],
238
287
f"{tag}: enemy-to-player grows ({k['startScale']:.2f}→{k['endScale']:.2f})")
288
check(k.get("landCol") == 3,
289
f"{tag}: enemy-to-player landCol is 3 (got {k.get('landCol')})")
290
if k.get("end") and info.get("expectedEndX"):
291
check(abs(k["end"]["x"] - info["expectedEndX"]) < 3,
292
f"{tag}: arc ends at column 3 "
293
f"(end.x={k['end']['x']:.1f} expected={info['expectedEndX']:.1f})")
294
check("gray" in (k.get("src") or "").lower() or k.get("color") == -1,
295
f"{tag}: enemy-to-player is grey (src={k.get('src')} color={k.get('color')})")
296
if expect_around and k.get("samples"):
297
inside = [s for s in k["samples"] if s.get("inside")]
298
check(len(inside) == 0,
299
f"{tag}: enemy-to-player path stays outside the field "
300
f"({len(inside)} interior samples {inside[:3]})")
301
check(not k.get("insideNow"),
302
f"{tag}: enemy-to-player mid-arc is not over the field interior")
303
if "player-to-enemy" in kinds and expect_around:
304
k = kinds["player-to-enemy"]
305
inside = [s for s in (k.get("samples") or []) if s.get("inside")]
306
check(len(inside) == 0,
307
f"{tag}: player-to-enemy path stays outside the field "
308
f"({len(inside)} interior samples {inside[:3]})")
239
309
if "enemy-to-enemy" in kinds:
240
310
k = kinds["enemy-to-enemy"]
241
311
check(abs(k["startScale"] - k["endScale"]) < 0.05,
@@ -244,12 +314,17 @@ def assert_flights(info, tag, expect_behind=True):
244
314
f"{tag}: enemy-to-enemy is in #flights-back (got {k['parent']})")
245
315
if expect_behind:
246
316
check(info["back"] >= 1, f"{tag}: at least one behind-field flight")
317
check("gray" in (k.get("src") or "").lower() or k.get("color") == -1,
318
f"{tag}: enemy-to-enemy is grey (src={k.get('src')} color={k.get('color')})")
247
319
if "enemy-miss" in kinds:
248
320
k = kinds["enemy-miss"]
249
321
check(k["startScale"] < 0.7,
250
322
f"{tag}: enemy-miss starts small ({k['startScale']:.2f})")
251
323
check(k["parent"] == "flights",
252
324
f"{tag}: enemy-miss is in #flights (got {k['parent']})")
325
# Misses keep the sender colour (not forced grey).
326
check(k.get("color") != -1,
327
f"{tag}: enemy-miss keeps the sender colour (color={k.get('color')})")
253
328
254
329
255
330
def run_viewport(browser, url, name, width, height, is_mobile, round_n, expect_mode):
@@ -263,17 +338,30 @@ def run_viewport(browser, url, name, width, height, is_mobile, round_n, expect_m
263
338
open_offline(page, url, round_n=round_n)
264
339
page.wait_for_timeout(300)
265
340
info = page.evaluate(LAYOUT_INFO)
266
print(f"--- {name} layout:", {k: info[k] for k in ('mode', 'n', 'tile', 'vw', 'vh', 'sidesClass')})
341
print(f"--- {name} layout:", {k: info[k] for k in ('mode', 'n', 'tile', 'vw', 'vh', 'sidesClass')},
342
"fieldY", info.get("field") and info["field"].get("y"),
343
"field.top", info.get("field") and info["field"].get("top"))
267
344
if expect_mode == "sides":
268
345
assert_sides(info, name, expect_rows=(round_n >= 12))
269
346
else:
270
347
assert_top(info, name)
271
shot(page, f"t1125-{name}-layout.png")
348
shot(page, f"t1126-{name}-layout.png")
272
349
273
flights = page.evaluate(INJECT_FLIGHTS)
274
print(f"--- {name} flights:", flights)
350
# Mid-arc (age 0.55 of 1.2 s) — main verification frame
351
flights = page.evaluate(INJECT_FLIGHTS, 0.55)
352
print(f"--- {name} flights:", {k: flights[k] for k in ('front', 'back', 'expectedEndX', 'hudH', 'mode') if k in flights})
353
for knd in flights["kinds"]:
354
print(f" {knd['kind']}: color={knd.get('color')} landCol={knd.get('landCol')} "
355
f"src={knd.get('src')} insideNow={knd.get('insideNow')} "
356
f"end={knd.get('end')} pos={knd.get('pos')}")
275
357
assert_flights(flights, name)
276
shot(page, f"t1125-{name}-flights.png")
358
shot(page, f"t1126-{name}-midarc.png")
359
360
# Extra mid-path frames on the wide 2-bot view so the around-route is visible
361
if name == "desktop-wide":
362
for age, label in ((0.25, "early"), (0.85, "late")):
363
page.evaluate(INJECT_FLIGHTS, age)
364
shot(page, f"t1126-{name}-midarc-{label}.png")
277
365
context.close()
278
366
279
367
@@ -288,13 +376,9 @@ def main():
288
376
args=CHROME_ARGS,
289
377
headless=True,
290
378
)
291
# Desktop wide: 2 opponents (round 2) alternating L/R
292
379
run_viewport(browser, url, "desktop-wide", 1280, 900, False, 2, "sides")
293
# Many opponents, stacked rows (round 25 → 8 bots)
294
380
run_viewport(browser, url, "desktop-wide-many", 1400, 900, False, 25, "sides")
295
# Desktop narrow: top layout
296
381
run_viewport(browser, url, "desktop-narrow", 720, 800, False, 2, "top")
297
# Mobile
298
382
run_viewport(browser, url, "mobile", 393, 851, True, 2, "top")
299
383
browser.close()
300
384
finally:
@@ -116,12 +116,13 @@ LAYOUT_INFO = """() => {116
}"""116
}"""117
117
118
118
119
INJECT_FLIGHTS = """() => {119
120
INJECT_FLIGHTS = """(age) => {121
if (age == null) age = 0.55;120
const plan = app.miniLayout;122
const plan = app.miniLayout;121
const field = app.scene.canvas.getBoundingClientRect();123
const field = app.scene.canvas.getBoundingClientRect();122
const minis = [...document.querySelectorAll('#minis .mini')];123
function anchor(id, inner) {124
function anchor(id, inner) {124
const el = document.querySelector('#minis .mini[data-player=\"' + id + '\"] canvas');125
const el = document.querySelector('#minis .mini[data-player="' + id + '"] canvas');125
if (!el) return { x: 80, y: 80 };126
if (!el) return { x: 80, y: 80 };126
const r = el.getBoundingClientRect();127
const r = el.getBoundingClientRect();127
if (plan && plan.mode === 'sides') {128
if (plan && plan.mode === 'sides') {@@ -135,47 +136,88 @@ INJECT_FLIGHTS = """() => {135
const bots = (app.battle.bots || []).map(b => b.id);136
const bots = (app.battle.bots || []).map(b => b.id);136
const a = bots[0] || 'bot-1';137
const a = bots[0] || 'bot-1';137
const b = bots[1] || bots[0] || 'bot-2';138
const b = bots[1] || bots[0] || 'bot-2';139
const landCol = 3;138
const pStart = {140
const pStart = {139
x: field.left + field.width / 2,141
x: field.left + ((4 + 0.5) / 10) * field.width,140
y: field.top + 4142
y: field.top + 4141
};143
};142
if (typeof Online.clearFlights === 'function') Online.clearFlights();144
if (typeof Online.clearFlights === 'function') Online.clearFlights();143
const flights = [145
const flights = [144
{ id: 'vis-p2e', client_id: 'vis-p2e', from_id: 'player', target_id: a, miss: false, color: 0, flight_duration: 1.2, age: 0.55 },146
{ id: 'vis-p2e', client_id: 'vis-p2e', from_id: 'player', target_id: a, miss: false, color: 0, flight_duration: 1.2, age: age, land_col: landCol },145
{ id: 'vis-e2p', client_id: 'vis-e2p', from_id: a, target_id: 'player', miss: false, color: 1, flight_duration: 1.2, age: 0.55 },147
{ id: 'vis-e2p', client_id: 'vis-e2p', from_id: a, target_id: 'player', miss: false, color: 1, flight_duration: 1.2, age: age, land_col: landCol },146
{ id: 'vis-e2e', client_id: 'vis-e2e', from_id: a, target_id: b, miss: false, color: 2, flight_duration: 1.2, age: 0.55 },148
{ id: 'vis-e2e', client_id: 'vis-e2e', from_id: a, target_id: b, miss: false, color: 2, flight_duration: 1.2, age: age, land_col: 7 },147
{ id: 'vis-emiss', client_id: 'vis-emiss', from_id: b, target_id: null, miss: true, color: 3, flight_duration: 1.2, age: 0.45 }149
{ id: 'vis-emiss', client_id: 'vis-emiss', from_id: b, target_id: null, miss: true, color: 3, flight_duration: 1.2, age: Math.min(age, 0.45) }148
];150
];149
const aOut = anchor(a, true);151
const aOut = anchor(a, true);150
const bOut = anchor(b, true);152
const bOut = anchor(b, true);151
const locals = {153
const locals = {152
'vis-p2e': { from_id: 'player', color: 0, startX: pStart.x, startY: pStart.y, col: 4 },154
'vis-p2e': { from_id: 'player', color: 0, startX: pStart.x, startY: pStart.y, col: 4, land_col: landCol },153
'vis-e2p': { from_id: a, color: 1, startX: aOut.x, startY: aOut.y },155
'vis-e2p': { from_id: a, color: 1, startX: aOut.x, startY: aOut.y, land_col: landCol },154
'vis-e2e': { from_id: a, color: 2, startX: aOut.x, startY: aOut.y },156
'vis-e2e': { from_id: a, color: 2, startX: aOut.x, startY: aOut.y, land_col: 7 },155
'vis-emiss': { from_id: b, color: 3, startX: bOut.x, startY: bOut.y }157
'vis-emiss': { from_id: b, color: 3, startX: bOut.x, startY: bOut.y }156
};158
};157
Online.spawnFlights(flights, locals);159
Online.spawnFlights(flights, locals);158
Online.tickFlights();160
Online.tickFlights();159
const front = [...document.querySelectorAll('#flights .flight')].map(el => ({161
const front = [...document.querySelectorAll('#flights .flight')].map(el => ({160
cls: el.className,162
src: el.getAttribute('src') || el.src,161
transform: el.style.transform,163
transform: el.style.transform,162
opacity: el.style.opacity,163
parent: 'front'164
parent: 'front'164
}));165
}));165
const back = [...document.querySelectorAll('#flights-back .flight')].map(el => ({166
const back = [...document.querySelectorAll('#flights-back .flight')].map(el => ({166
cls: el.className,167
src: el.getAttribute('src') || el.src,167
transform: el.style.transform,168
transform: el.style.transform,168
opacity: el.style.opacity,169
parent: 'back'169
parent: 'back'170
}));170
}));171
const kinds = (Online._flights || []).map(f => {172
const raw = Math.min(0.999, Math.max(0, (performance.now() - f.t0) / f.duration));173
const u = Online.easeInOutCubic(raw);174
let pt;175
if (f.waypoints && f.waypoints.length > 2)176
{ pt = Online.pointOnPath(f.waypoints, u); }177
else if (f.kind === 'enemy-to-player' || f.kind === 'player-to-enemy')178
{ pt = Online.aroundFieldPoint(f.start, f.end, u, f.field, (f.height || 80) * 0.45); }179
else180
{ pt = Online.arcPoint(f.start, f.end, u, f.height || 80); }181
const samples = [];182
if (f.kind === 'enemy-to-player' || f.kind === 'player-to-enemy')183
{184
for (let i = 0; i <= 16; i++)185
{186
const su = i / 16;187
let sp;188
if (f.waypoints && f.waypoints.length > 2)189
{ sp = Online.pointOnPath(f.waypoints, su); }190
else191
{ sp = Online.aroundFieldPoint(f.start, f.end, su, f.field, (f.height || 80) * 0.45); }192
samples.push({193
u: su, x: sp.x, y: sp.y,194
inside: Online.pointInFieldInterior(sp.x, sp.y, f.field)195
});196
}197
}198
return {199
kind: f.kind, miss: f.miss,200
startScale: f.startScale, endScale: f.endScale,201
parent: (f.el && f.el.parentElement && f.el.parentElement.id) || '',202
src: (f.el && (f.el.getAttribute('src') || f.el.src)) || '',203
color: f.color,204
landCol: f.landCol,205
end: f.end,206
pos: pt,207
samples: samples,208
insideNow: f.field ? Online.pointInFieldInterior(pt.x, pt.y, f.field) : false209
};210
});211
const expectedEndX = field.left + ((landCol + 0.5) / 10) * field.width;171
return {212
return {172
front: front.length,213
front: front.length,173
back: back.length,214
back: back.length,174
kinds: (Online._flights || []).map(f => ({215
kinds,175
kind: f.kind, miss: f.miss,216
expectedEndX,176
startScale: f.startScale, endScale: f.endScale,217
field: { left: field.left, right: field.right, top: field.top, bottom: field.bottom },177
parent: (f.el && f.el.parentElement && f.el.parentElement.id) || ''218
pad: field.top,178
}))219
hudH: app.hudH,220
mode: plan.mode179
};221
};180
}"""222
}"""181
223
@@ -186,6 +228,12 @@ def assert_sides(info, tag, expect_rows=False):186
field = info["field"]228
field = info["field"]187
minis = info["minis"]229
minis = info["minis"]188
check(len(minis) >= 1, f"{tag}: at least one mini ({len(minis)})")230
check(len(minis) >= 1, f"{tag}: at least one mini ({len(minis)})")231
if field:232
# t1129: room above the field for around-the-top arcs233
gap = field["top"] - 50 # HUD is ~56–80; require a clear pad234
check(field["top"] >= (info.get("hud") or 70) + 80235
or field["y"] >= 70 + 80,236
f"{tag}: wide layout has top padding (field.top={field['top']:.1f}, y={field.get('y')})")189
if not field or not minis:237
if not field or not minis:190
return238
return191
for i, m in enumerate(minis):239
for i, m in enumerate(minis):@@ -202,7 +250,6 @@ def assert_sides(info, tag, expect_rows=False):202
check(m["top"] >= 50,250
check(m["top"] >= 50,203
f"{tag}: mini {i} stays under the HUD (top={m['top']:.1f})")251
f"{tag}: mini {i} stays under the HUD (top={m['top']:.1f})")204
if expect_rows and len(minis) >= 3:252
if expect_rows and len(minis) >= 3:205
# 3rd (index 2) is left, stacked above the first206
check(minis[2]["bottom"] <= minis[0]["top"] + 4,253
check(minis[2]["bottom"] <= minis[0]["top"] + 4,207
f"{tag}: third mini is stacked above the first "254
f"{tag}: third mini is stacked above the first "208
f"(b={minis[2]['bottom']:.1f} vs top={minis[0]['top']:.1f})")255
f"(b={minis[2]['bottom']:.1f} vs top={minis[0]['top']:.1f})")@@ -222,7 +269,7 @@ def assert_top(info, tag):222
f"(bottom={m['bottom']:.1f} field.top={field['top']:.1f})")269
f"(bottom={m['bottom']:.1f} field.top={field['top']:.1f})")223
270
224
271
225
def assert_flights(info, tag, expect_behind=True):272
def assert_flights(info, tag, expect_behind=True, expect_around=True):226
check(info["front"] >= 3, f"{tag}: front flights present ({info['front']})")273
check(info["front"] >= 3, f"{tag}: front flights present ({info['front']})")227
kinds = {k["kind"]: k for k in info["kinds"]}274
kinds = {k["kind"]: k for k in info["kinds"]}228
check("player-to-enemy" in kinds, f"{tag}: player-to-enemy")275
check("player-to-enemy" in kinds, f"{tag}: player-to-enemy")@@ -232,10 +279,33 @@ def assert_flights(info, tag, expect_behind=True):232
k = kinds["player-to-enemy"]279
k = kinds["player-to-enemy"]233
check(k["startScale"] > k["endScale"],280
check(k["startScale"] > k["endScale"],234
f"{tag}: player-to-enemy shrinks ({k['startScale']:.2f}→{k['endScale']:.2f})")281
f"{tag}: player-to-enemy shrinks ({k['startScale']:.2f}→{k['endScale']:.2f})")282
check("gray" in (k.get("src") or "").lower() or k.get("color") == -1,283
f"{tag}: player-to-enemy is grey (src={k.get('src')} color={k.get('color')})")235
if "enemy-to-player" in kinds:284
if "enemy-to-player" in kinds:236
k = kinds["enemy-to-player"]285
k = kinds["enemy-to-player"]237
check(k["endScale"] > k["startScale"],286
check(k["endScale"] > k["startScale"],238
f"{tag}: enemy-to-player grows ({k['startScale']:.2f}→{k['endScale']:.2f})")287
f"{tag}: enemy-to-player grows ({k['startScale']:.2f}→{k['endScale']:.2f})")288
check(k.get("landCol") == 3,289
f"{tag}: enemy-to-player landCol is 3 (got {k.get('landCol')})")290
if k.get("end") and info.get("expectedEndX"):291
check(abs(k["end"]["x"] - info["expectedEndX"]) < 3,292
f"{tag}: arc ends at column 3 "293
f"(end.x={k['end']['x']:.1f} expected={info['expectedEndX']:.1f})")294
check("gray" in (k.get("src") or "").lower() or k.get("color") == -1,295
f"{tag}: enemy-to-player is grey (src={k.get('src')} color={k.get('color')})")296
if expect_around and k.get("samples"):297
inside = [s for s in k["samples"] if s.get("inside")]298
check(len(inside) == 0,299
f"{tag}: enemy-to-player path stays outside the field "300
f"({len(inside)} interior samples {inside[:3]})")301
check(not k.get("insideNow"),302
f"{tag}: enemy-to-player mid-arc is not over the field interior")303
if "player-to-enemy" in kinds and expect_around:304
k = kinds["player-to-enemy"]305
inside = [s for s in (k.get("samples") or []) if s.get("inside")]306
check(len(inside) == 0,307
f"{tag}: player-to-enemy path stays outside the field "308
f"({len(inside)} interior samples {inside[:3]})")239
if "enemy-to-enemy" in kinds:309
if "enemy-to-enemy" in kinds:240
k = kinds["enemy-to-enemy"]310
k = kinds["enemy-to-enemy"]241
check(abs(k["startScale"] - k["endScale"]) < 0.05,311
check(abs(k["startScale"] - k["endScale"]) < 0.05,@@ -244,12 +314,17 @@ def assert_flights(info, tag, expect_behind=True):244
f"{tag}: enemy-to-enemy is in #flights-back (got {k['parent']})")314
f"{tag}: enemy-to-enemy is in #flights-back (got {k['parent']})")245
if expect_behind:315
if expect_behind:246
check(info["back"] >= 1, f"{tag}: at least one behind-field flight")316
check(info["back"] >= 1, f"{tag}: at least one behind-field flight")317
check("gray" in (k.get("src") or "").lower() or k.get("color") == -1,318
f"{tag}: enemy-to-enemy is grey (src={k.get('src')} color={k.get('color')})")247
if "enemy-miss" in kinds:319
if "enemy-miss" in kinds:248
k = kinds["enemy-miss"]320
k = kinds["enemy-miss"]249
check(k["startScale"] < 0.7,321
check(k["startScale"] < 0.7,250
f"{tag}: enemy-miss starts small ({k['startScale']:.2f})")322
f"{tag}: enemy-miss starts small ({k['startScale']:.2f})")251
check(k["parent"] == "flights",323
check(k["parent"] == "flights",252
f"{tag}: enemy-miss is in #flights (got {k['parent']})")324
f"{tag}: enemy-miss is in #flights (got {k['parent']})")325
# Misses keep the sender colour (not forced grey).326
check(k.get("color") != -1,327
f"{tag}: enemy-miss keeps the sender colour (color={k.get('color')})")253
328
254
329
255
def run_viewport(browser, url, name, width, height, is_mobile, round_n, expect_mode):330
def run_viewport(browser, url, name, width, height, is_mobile, round_n, expect_mode):@@ -263,17 +338,30 @@ def run_viewport(browser, url, name, width, height, is_mobile, round_n, expect_m263
open_offline(page, url, round_n=round_n)338
open_offline(page, url, round_n=round_n)264
page.wait_for_timeout(300)339
page.wait_for_timeout(300)265
info = page.evaluate(LAYOUT_INFO)340
info = page.evaluate(LAYOUT_INFO)266
print(f"--- {name} layout:", {k: info[k] for k in ('mode', 'n', 'tile', 'vw', 'vh', 'sidesClass')})341
print(f"--- {name} layout:", {k: info[k] for k in ('mode', 'n', 'tile', 'vw', 'vh', 'sidesClass')},342
"fieldY", info.get("field") and info["field"].get("y"),343
"field.top", info.get("field") and info["field"].get("top"))267
if expect_mode == "sides":344
if expect_mode == "sides":268
assert_sides(info, name, expect_rows=(round_n >= 12))345
assert_sides(info, name, expect_rows=(round_n >= 12))269
else:346
else:270
assert_top(info, name)347
assert_top(info, name)271
shot(page, f"t1125-{name}-layout.png")348
shot(page, f"t1126-{name}-layout.png")272
349
273
flights = page.evaluate(INJECT_FLIGHTS)350
# Mid-arc (age 0.55 of 1.2 s) — main verification frame274
print(f"--- {name} flights:", flights)351
flights = page.evaluate(INJECT_FLIGHTS, 0.55)352
print(f"--- {name} flights:", {k: flights[k] for k in ('front', 'back', 'expectedEndX', 'hudH', 'mode') if k in flights})353
for knd in flights["kinds"]:354
print(f" {knd['kind']}: color={knd.get('color')} landCol={knd.get('landCol')} "355
f"src={knd.get('src')} insideNow={knd.get('insideNow')} "356
f"end={knd.get('end')} pos={knd.get('pos')}")275
assert_flights(flights, name)357
assert_flights(flights, name)276
shot(page, f"t1125-{name}-flights.png")358
shot(page, f"t1126-{name}-midarc.png")359
360
# Extra mid-path frames on the wide 2-bot view so the around-route is visible361
if name == "desktop-wide":362
for age, label in ((0.25, "early"), (0.85, "late")):363
page.evaluate(INJECT_FLIGHTS, age)364
shot(page, f"t1126-{name}-midarc-{label}.png")277
context.close()365
context.close()278
366
279
367
@@ -288,13 +376,9 @@ def main():288
args=CHROME_ARGS,376
args=CHROME_ARGS,289
headless=True,377
headless=True,290
)378
)291
# Desktop wide: 2 opponents (round 2) alternating L/R292
run_viewport(browser, url, "desktop-wide", 1280, 900, False, 2, "sides")379
run_viewport(browser, url, "desktop-wide", 1280, 900, False, 2, "sides")293
# Many opponents, stacked rows (round 25 → 8 bots)294
run_viewport(browser, url, "desktop-wide-many", 1400, 900, False, 25, "sides")380
run_viewport(browser, url, "desktop-wide-many", 1400, 900, False, 25, "sides")295
# Desktop narrow: top layout296
run_viewport(browser, url, "desktop-narrow", 720, 800, False, 2, "top")381
run_viewport(browser, url, "desktop-narrow", 720, 800, False, 2, "top")297
# Mobile298
run_viewport(browser, url, "mobile", 393, 851, True, 2, "top")382
run_viewport(browser, url, "mobile", 393, 851, True, 2, "top")299
browser.close()383
browser.close()300
finally:384
finally: