Skip to content

Commit 3c1d21f

Browse files
committed
Implement reading Follow, Attack Ground, and Town Bell actions.
1 parent c7fbc37 commit 3c1d21f

File tree

3 files changed

+113
-11
lines changed

3 files changed

+113
-11
lines changed

src/Analyzers/BodyAnalyzer.php

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,37 @@ protected function run()
330330
$z
331331
));
332332
break;
333-
case self::COMMAND_UNIT_AI_STATE:
334-
$numUnits = ord($this->body[$this->position++]);
335-
$stance = ord($this->body[$this->position++]);
336-
$this->push(new Actions\UnitAiStateAction(
333+
case self::COMMAND_ADD_ATTRIBUTE:
334+
$playerId = ord($this->body[$this->position++]);
335+
$resourceType = ord($this->body[$this->position++]);
336+
$this->position += 1;
337+
$amount = $this->readBody('f', 4);
338+
339+
$this->push(new Actions\AddAttributeAction(
337340
$this->rec,
338341
$this->currentTime,
339-
$stance,
340-
$this->readUnits($numUnits)
342+
$playerId,
343+
$resourceType,
344+
$amount
345+
));
346+
break;
347+
// Old-style tributing.
348+
case self::COMMAND_GIVE_ATTRIBUTE:
349+
$playerIdFrom = ord($this->body[$this->position++]);
350+
$playerIdTo = ord($this->body[$this->position++]);
351+
$resourceId = ord($this->body[$this->position++]);
352+
$amount = $this->readBody('f', 4);
353+
// Market fees only apply to COMMAND_GIVE_ATTRIBUTE2.
354+
$marketFee = 0.0;
355+
356+
$this->push(new Actions\GiveAttributeAction(
357+
$this->rec,
358+
$this->currentTime,
359+
$playerIdFrom,
360+
$playerIdTo,
361+
$resourceId,
362+
$amount,
363+
$marketFee
341364
));
342365
break;
343366
// player resign
@@ -361,8 +384,29 @@ protected function run()
361384
$this->chatMessages[] = new ChatMessage($this->currentTime, null, $message);
362385
}
363386
break;
387+
case self::COMMAND_UNIT_AI_STATE:
388+
$numUnits = ord($this->body[$this->position++]);
389+
$stance = ord($this->body[$this->position++]);
390+
$this->push(new Actions\UnitAiStateAction(
391+
$this->rec,
392+
$this->currentTime,
393+
$stance,
394+
$this->readUnits($numUnits)
395+
));
396+
break;
397+
case self::COMMAND_FOLLOW:
398+
$numUnits = ord($this->body[$this->position++]);
399+
$this->position += 2;
400+
$target = $this->readBody('l', 4);
401+
402+
$this->push(new Actions\FollowAction(
403+
$this->rec,
404+
$this->currentTime,
405+
$target,
406+
$this->readUnits($numUnits)
407+
));
408+
break;
364409
case self::COMMAND_PATROL:
365-
$start = $this->position - 1;
366410
$numUnits = ord($this->body[$this->position++]);
367411
$numWaypoints = ord($this->body[$this->position++]);
368412
$this->position++;
@@ -500,6 +544,19 @@ protected function run()
500544
$objectId
501545
));
502546
break;
547+
case self::COMMAND_ATTACK_GROUND:
548+
$count = ord($this->body[$this->position++]);
549+
$this->position += 2;
550+
$x = $this->readBody('f', 4);
551+
$y = $this->readBody('f', 4);
552+
$this->push(new Actions\AttackGroundAction(
553+
$this->rec,
554+
$this->currentTime,
555+
$x,
556+
$y,
557+
$this->readUnits($count)
558+
));
559+
break;
503560
// AI trains unit
504561
case self::COMMAND_MAKE:
505562
$this->position += 3;
@@ -682,6 +739,18 @@ protected function run()
682739
$marketId
683740
));
684741
break;
742+
case self::COMMAND_TOWN_BELL:
743+
$this->position += 3;
744+
$unitId = $this->readBody('l', 4);
745+
$active = $this->readBody('l', 4);
746+
747+
$this->push(new Actions\TownBellAction(
748+
$this->rec,
749+
$this->currentTime,
750+
$unitId,
751+
$active
752+
));
753+
break;
685754
case self::COMMAND_GO_BACK_TO_WORK:
686755
$this->position += 3;
687756
$unitId = $this->readBody('l', 4);

src/Model/Actions/AttackGroundAction.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ class AttackGroundAction extends Action
3737
* @param \RecAnalyst\RecordedGame $rec Recorded game instance.
3838
* @param int $time Recorded game instance.
3939
*/
40-
public function __construct(RecordedGame $rec, $time)
40+
public function __construct(RecordedGame $rec, $time, $x, $y, $units)
4141
{
4242
parent::__construct($rec, $time);
43+
44+
$this->x = $x;
45+
$this->y = $y;
46+
$this->units = $units;
4347
}
4448

4549
/**

src/Model/Actions/FollowAction.php

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,46 @@ class FollowAction extends Action
1717
const ID = 0x14;
1818

1919
// Follow(num=%d, target=%d)
20-
private $num;
21-
private $target;
20+
/**
21+
* ID of the target unit to follow.
22+
*
23+
* @var int
24+
*/
25+
public $targetId;
26+
27+
/**
28+
* IDs of the units that should follow the target.
29+
*
30+
* @var int[]
31+
*/
32+
public $units;
2233

2334
/**
2435
* Create a ...
2536
*
2637
* @param \RecAnalyst\RecordedGame $rec Recorded game instance.
2738
* @param int $time Recorded game instance.
2839
*/
29-
public function __construct(RecordedGame $rec, $time)
40+
public function __construct(RecordedGame $rec, $time, $targetId, $units)
3041
{
3142
parent::__construct($rec, $time);
43+
44+
$this->targetId = $targetId;
45+
$this->units = $units;
46+
}
47+
48+
/**
49+
* Get a string representation of the action.
50+
*
51+
* @return string
52+
*/
53+
public function __toString()
54+
{
55+
return sprintf(
56+
'Follow(targetId=%d, units[%d]={%s})',
57+
$this->targetId,
58+
count($this->units),
59+
implode(', ', $this->units)
60+
);
3261
}
3362
}

0 commit comments

Comments
 (0)