Skip to content

Commit 1c0e746

Browse files
committed
Implement Flare action.
1 parent 3c1d21f commit 1c0e746

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed

src/Analyzers/BodyAnalyzer.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,40 @@ protected function run()
670670
$this->readUnits($count)
671671
));
672672
break;
673+
case self::COMMAND_FLARE:
674+
$this->position += 3;
675+
// Is this always 0xFF FF FF FF?
676+
$ffffffff = $this->readBody('l', 4);
677+
$this->position += 1;
678+
679+
// Whether each player can receive the flare.
680+
$visible = [];
681+
for ($i = 0; $i < 8; $i++) {
682+
$visible[$i] = ord($this->body[$this->position++]) !== 0;
683+
}
684+
685+
$this->position += 3;
686+
687+
// Flare location.
688+
$x = $this->readBody('f', 4);
689+
$y = $this->readBody('f', 4);
690+
691+
// Multiple players have the same player number (and color)
692+
// in coop games.
693+
$playerNumber = ord($this->body[$this->position++]);
694+
// But everyone has a unique player index.
695+
$playerIndex = ord($this->body[$this->position++]);
696+
697+
$this->push(new Actions\FlareAction(
698+
$this->rec,
699+
$this->currentTime,
700+
$playerNumber,
701+
$playerIndex,
702+
$x,
703+
$y,
704+
$visible
705+
));
706+
break;
673707
case self::COMMAND_UNIT_ORDER:
674708
$count = ord($this->body[$this->position++]);
675709
$this->position += 2;

src/Model/Actions/FlareAction.php

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,75 @@ class FlareAction extends Action
1616
*/
1717
const ID = 0x73;
1818

19+
/**
20+
* The number of the player that sent the flare.
21+
*
22+
* @var int
23+
*/
24+
public $playerNumber;
25+
26+
/**
27+
* The index of the player that sent the flare.
28+
* This can differ from the player number in coop games.
29+
*
30+
* @var int
31+
*/
32+
public $playerIndex;
33+
34+
/**
35+
* X-coordinate of the flare location.
36+
*
37+
* @var float
38+
*/
39+
public $x;
40+
41+
/**
42+
* Y-coordinate of the flare location.
43+
*
44+
* @var float
45+
*/
46+
public $y;
47+
48+
/**
49+
* Determines which player numbers can see the flare.
50+
*
51+
* @var bool[]
52+
*/
53+
public $visible;
54+
1955
/**
2056
* Create a ...
2157
*
2258
* @param \RecAnalyst\RecordedGame $rec Recorded game instance.
2359
* @param int $time Recorded game instance.
2460
*/
25-
public function __construct(RecordedGame $rec, $time)
61+
public function __construct(RecordedGame $rec, $time, $playerNumber, $playerIndex, $x, $y, $visible)
2662
{
2763
parent::__construct($rec, $time);
64+
65+
$this->playerNumber = $playerNumber;
66+
$this->playerIndex = $playerIndex;
67+
$this->x = $x;
68+
$this->y = $y;
69+
$this->visible = $visible;
70+
}
71+
72+
/**
73+
* Get a string representation of the action.
74+
*
75+
* @return string
76+
*/
77+
public function __toString()
78+
{
79+
return sprintf(
80+
'Flare(from=%d, fromIndex=%d, x=%.2f, y=%.2f, visible={%s})',
81+
$this->playerNumber,
82+
$this->playerIndex,
83+
$this->x,
84+
$this->y,
85+
implode(', ', array_map(function ($visible) {
86+
return $visible ? 'Y' : 'N';
87+
}, $this->visible))
88+
);
2889
}
2990
}

0 commit comments

Comments
 (0)