BlueGit

projects-timfalken-com meteors

feat: echo launch col and y on shot_flights (t1136)

Store from_col/from_y so every client can start an opponent's arc
at the real cell on their mini, matching Offline Strijd.

timfa Grok Bot · pushed by timfa

Authored 2026-11-13 · 4 days ago

Hash
c4babed26d43cda63eaf4b335738707c0510437c
Parent
abde86b0
2 files changed +18 −4
server/lib/Store.php +13 −3
@@ -75,6 +75,8 @@ CREATE INDEX IF NOT EXISTS shots_deliver ON shots (lobby_id, to_user, delivered,
75 75 SQL);
76 76 $this->ensureColumn('members', 'planet_id', "TEXT NOT NULL DEFAULT 'terra'");
77 77 $this->ensureColumn('shots', 'land_col', 'INTEGER');
78 $this->ensureColumn('shots', 'from_col', 'INTEGER');
79 $this->ensureColumn('shots', 'from_y', 'REAL');
78 80 }
79 81
80 82 private function ensureColumn(string $table, string $column, string $ddl): void
@@ -395,12 +397,14 @@ SQL);
395 397 $flight = (float) $lobby['flight_duration'];
396 398 $now = $this->nowf();
397 399 $ins = $this->pdo->prepare(
398 'INSERT INTO shots (lobby_id, from_user, to_user, color, client_id, created, deliver_at, delivered, land_col)
399 VALUES (?,?,?,?,?,?,?,0,?)'
400 'INSERT INTO shots (lobby_id, from_user, to_user, color, client_id, created, deliver_at, delivered, land_col, from_col, from_y)
401 VALUES (?,?,?,?,?,?,?,0,?,?,?)'
400 402 );
401 403 foreach ($shots as $shot) {
402 404 $color = isset($shot['color']) ? (int) $shot['color'] : -1;
403 405 $clientId = isset($shot['client_id']) ? (string) $shot['client_id'] : (string) ($shot['id'] ?? '');
406 $fromCol = isset($shot['col']) && $shot['col'] !== null && is_numeric($shot['col']) ? (int) $shot['col'] : null;
407 $fromY = isset($shot['y']) && $shot['y'] !== null && is_numeric($shot['y']) ? (float) $shot['y'] : null;
404 408 $miss = $targets === [] || (mt_rand() / mt_getrandmax()) < $missChance;
405 409 $to = null;
406 410 $toName = null;
@@ -412,7 +416,7 @@ SQL);
412 416 $landCol = random_int(0, 9);
413 417 }
414 418 $deliver = $now + $flight;
415 $ins->execute([$lobby['id'], $userId, $to, $color, $clientId, $now, $deliver, $landCol]);
419 $ins->execute([$lobby['id'], $userId, $to, $color, $clientId, $now, $deliver, $landCol, $fromCol, $fromY]);
416 420 $results[] = [
417 421 'id' => (int) $this->pdo->lastInsertId(),
418 422 'client_id' => $clientId,
@@ -426,6 +430,8 @@ SQL);
426 430 'flight_duration' => $flight,
427 431 'age' => 0.0,
428 432 'land_col' => $landCol,
433 'col' => $fromCol,
434 'y' => $fromY,
429 435 ];
430 436 }
431 437 return $results;
@@ -457,6 +463,8 @@ SQL);
457 463 'from_user' => $r['from_user'],
458 464 'client_id' => $r['client_id'],
459 465 'land_col' => isset($r['land_col']) && $r['land_col'] !== null ? (int) $r['land_col'] : null,
466 'col' => isset($r['from_col']) && $r['from_col'] !== null ? (int) $r['from_col'] : null,
467 'y' => isset($r['from_y']) && $r['from_y'] !== null ? (float) $r['from_y'] : null,
460 468 ];
461 469 }
462 470 return $incoming;
@@ -609,6 +617,8 @@ SQL);
609 617 'age' => $now - (float) $r['created'],
610 618 'deliver_at' => (float) $r['deliver_at'],
611 619 'land_col' => isset($r['land_col']) && $r['land_col'] !== null ? (int) $r['land_col'] : null,
620 'col' => isset($r['from_col']) && $r['from_col'] !== null ? (int) $r['from_col'] : null,
621 'y' => isset($r['from_y']) && $r['from_y'] !== null ? (float) $r['from_y'] : null,
612 622 ];
613 623 }
614 624 return $out;
@@ -75,6 +75,8 @@ CREATE INDEX IF NOT EXISTS shots_deliver ON shots (lobby_id, to_user, delivered,
75SQL);
75SQL);
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 $this->ensureColumn('shots', 'land_col', 'INTEGER');
78 $this->ensureColumn('shots', 'from_col', 'INTEGER');
79 $this->ensureColumn('shots', 'from_y', 'REAL');
78 }
80 }
79
81
80 private function ensureColumn(string $table, string $column, string $ddl): void
82 private function ensureColumn(string $table, string $column, string $ddl): void
@@ -395,12 +397,14 @@ SQL);
395 $flight = (float) $lobby['flight_duration'];
397 $flight = (float) $lobby['flight_duration'];
396 $now = $this->nowf();
398 $now = $this->nowf();
397 $ins = $this->pdo->prepare(
399 $ins = $this->pdo->prepare(
398 'INSERT INTO shots (lobby_id, from_user, to_user, color, client_id, created, deliver_at, delivered, land_col)
400 'INSERT INTO shots (lobby_id, from_user, to_user, color, client_id, created, deliver_at, delivered, land_col, from_col, from_y)
399 VALUES (?,?,?,?,?,?,?,0,?)'
401 VALUES (?,?,?,?,?,?,?,0,?,?,?)'
400 );
402 );
401 foreach ($shots as $shot) {
403 foreach ($shots as $shot) {
402 $color = isset($shot['color']) ? (int) $shot['color'] : -1;
404 $color = isset($shot['color']) ? (int) $shot['color'] : -1;
403 $clientId = isset($shot['client_id']) ? (string) $shot['client_id'] : (string) ($shot['id'] ?? '');
405 $clientId = isset($shot['client_id']) ? (string) $shot['client_id'] : (string) ($shot['id'] ?? '');
406 $fromCol = isset($shot['col']) && $shot['col'] !== null && is_numeric($shot['col']) ? (int) $shot['col'] : null;
407 $fromY = isset($shot['y']) && $shot['y'] !== null && is_numeric($shot['y']) ? (float) $shot['y'] : null;
404 $miss = $targets === [] || (mt_rand() / mt_getrandmax()) < $missChance;
408 $miss = $targets === [] || (mt_rand() / mt_getrandmax()) < $missChance;
405 $to = null;
409 $to = null;
406 $toName = null;
410 $toName = null;
@@ -412,7 +416,7 @@ SQL);
412 $landCol = random_int(0, 9);
416 $landCol = random_int(0, 9);
413 }
417 }
414 $deliver = $now + $flight;
418 $deliver = $now + $flight;
415 $ins->execute([$lobby['id'], $userId, $to, $color, $clientId, $now, $deliver, $landCol]);
419 $ins->execute([$lobby['id'], $userId, $to, $color, $clientId, $now, $deliver, $landCol, $fromCol, $fromY]);
416 $results[] = [
420 $results[] = [
417 'id' => (int) $this->pdo->lastInsertId(),
421 'id' => (int) $this->pdo->lastInsertId(),
418 'client_id' => $clientId,
422 'client_id' => $clientId,
@@ -426,6 +430,8 @@ SQL);
426 'flight_duration' => $flight,
430 'flight_duration' => $flight,
427 'age' => 0.0,
431 'age' => 0.0,
428 'land_col' => $landCol,
432 'land_col' => $landCol,
433 'col' => $fromCol,
434 'y' => $fromY,
429 ];
435 ];
430 }
436 }
431 return $results;
437 return $results;
@@ -457,6 +463,8 @@ SQL);
457 'from_user' => $r['from_user'],
463 'from_user' => $r['from_user'],
458 'client_id' => $r['client_id'],
464 'client_id' => $r['client_id'],
459 'land_col' => isset($r['land_col']) && $r['land_col'] !== null ? (int) $r['land_col'] : null,
465 'land_col' => isset($r['land_col']) && $r['land_col'] !== null ? (int) $r['land_col'] : null,
466 'col' => isset($r['from_col']) && $r['from_col'] !== null ? (int) $r['from_col'] : null,
467 'y' => isset($r['from_y']) && $r['from_y'] !== null ? (float) $r['from_y'] : null,
460 ];
468 ];
461 }
469 }
462 return $incoming;
470 return $incoming;
@@ -609,6 +617,8 @@ SQL);
609 'age' => $now - (float) $r['created'],
617 'age' => $now - (float) $r['created'],
610 'deliver_at' => (float) $r['deliver_at'],
618 'deliver_at' => (float) $r['deliver_at'],
611 'land_col' => isset($r['land_col']) && $r['land_col'] !== null ? (int) $r['land_col'] : null,
619 'land_col' => isset($r['land_col']) && $r['land_col'] !== null ? (int) $r['land_col'] : null,
620 'col' => isset($r['from_col']) && $r['from_col'] !== null ? (int) $r['from_col'] : null,
621 'y' => isset($r['from_y']) && $r['from_y'] !== null ? (float) $r['from_y'] : null,
612 ];
622 ];
613 }
623 }
614 return $out;
624 return $out;
server/tests/run.php +5 −1
@@ -245,7 +245,7 @@ $store->setReady('local:test_user_3', true);
245 245 $store->startGame('local:test_user_1');
246 246 $store->testMissOverride = 0.0;
247 247 $shots = $store->recordShots('local:test_user_1', [
248 ['client_id' => 'f1', 'color' => 2],
248 ['client_id' => 'f1', 'color' => 2, 'col' => 6, 'y' => 12.4],
249 249 ]);
250 250 $store->testMissOverride = null;
251 251 expect(count($shots) === 1, 'one recorded shot');
@@ -270,6 +270,10 @@ if ($found) {
270 270 expect(almostEqual((float) $found['flight_duration'], METEORS_FLIGHT_DURATION), 'flight_duration on shot_flights');
271 271 expect(isset($found['land_col']) && $found['land_col'] >= 0 && $found['land_col'] <= 9, 'shot_flights has land_col 0–9');
272 272 expect(($shots[0]['land_col'] ?? null) === $found['land_col'], 'recordShots and shot_flights share land_col');
273 expect(($shots[0]['col'] ?? null) === 6, 'shot_results echoes launch col');
274 expect(isset($shots[0]['y']) && abs((float) $shots[0]['y'] - 12.4) < 0.01, 'shot_results echoes launch y');
275 expect(($found['col'] ?? null) === 6, 'shot_flights has launch col (t1136)');
276 expect(isset($found['y']) && abs((float) $found['y'] - 12.4) < 0.01, 'shot_flights has launch y (t1136)');
273 277 }
274 278 // Incoming carries the same land_col (t1126).
275 279 $targetId = $found['target_id'] ?? $shots[0]['target_id'];
@@ -245,7 +245,7 @@ $store->setReady('local:test_user_3', true);
245$store->startGame('local:test_user_1');
245$store->startGame('local:test_user_1');
246$store->testMissOverride = 0.0;
246$store->testMissOverride = 0.0;
247$shots = $store->recordShots('local:test_user_1', [
247$shots = $store->recordShots('local:test_user_1', [
248 ['client_id' => 'f1', 'color' => 2],
248 ['client_id' => 'f1', 'color' => 2, 'col' => 6, 'y' => 12.4],
249]);
249]);
250$store->testMissOverride = null;
250$store->testMissOverride = null;
251expect(count($shots) === 1, 'one recorded shot');
251expect(count($shots) === 1, 'one recorded shot');
@@ -270,6 +270,10 @@ if ($found) {
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');
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');
272 expect(($shots[0]['land_col'] ?? null) === $found['land_col'], 'recordShots and shot_flights share land_col');
273 expect(($shots[0]['col'] ?? null) === 6, 'shot_results echoes launch col');
274 expect(isset($shots[0]['y']) && abs((float) $shots[0]['y'] - 12.4) < 0.01, 'shot_results echoes launch y');
275 expect(($found['col'] ?? null) === 6, 'shot_flights has launch col (t1136)');
276 expect(isset($found['y']) && abs((float) $found['y'] - 12.4) < 0.01, 'shot_flights has launch y (t1136)');
273}
277}
274// Incoming carries the same land_col (t1126).
278// Incoming carries the same land_col (t1126).
275$targetId = $found['target_id'] ?? $shots[0]['target_id'];
279$targetId = $found['target_id'] ?? $shots[0]['target_id'];