Skip to content

Commit e4cc4fb

Browse files
committed
Implement MultiQueue action from UserPatch.
1 parent 1c0e746 commit e4cc4fb

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

src/Analyzers/BodyAnalyzer.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class BodyAnalyzer extends Analyzer
101101
const COMMAND_TRADE_ATTRIBUTE = 0x6D;
102102
const COMMAND_REPAIR = 0x6E;
103103
const COMMAND_UNLOAD = 0x6F;
104+
const COMMAND_MULTI_QUEUE = 0x70;
104105
const COMMAND_GATE = 0x72;
105106
const COMMAND_FLARE = 0x73;
106107
const COMMAND_SPECIAL = 0x74;
@@ -508,6 +509,25 @@ protected function run()
508509
$this->units[$unitType] += $amount;
509510
}
510511
break;
512+
case self::COMMAND_MULTI_QUEUE:
513+
$this->position += 3;
514+
$unitType = $this->readBody('v', 2);
515+
$numBuildings = ord($this->body[$this->position++]);
516+
$amount = ord($this->body[$this->position++]);
517+
$buildings = [];
518+
519+
for ($i = 0; $i < $numBuildings; $i++) {
520+
$buildings[] = $this->readBody('l', 4);
521+
}
522+
523+
$this->push(new Actions\MultiQueueAction(
524+
$this->rec,
525+
$this->currentTime,
526+
$buildings,
527+
$unitType,
528+
$amount
529+
));
530+
break;
511531
case self::COMMAND_GAME:
512532
$this->processGameAction();
513533
break;
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
namespace RecAnalyst\Model\Actions;
4+
5+
use RecAnalyst\RecordedGame;
6+
7+
/**
8+
* Represents a multiple building queue action, from UserPatch 1.4.
9+
*/
10+
class MultiQueueAction extends Action
11+
{
12+
/**
13+
* The action ID.
14+
*
15+
* @var int
16+
*/
17+
const ID = 0x70;
18+
19+
/**
20+
* Building IDs that the action applies to.
21+
*
22+
* @var int[]
23+
*/
24+
public $buildings;
25+
26+
/**
27+
* ID of the unit type that is being queued.
28+
*
29+
* @var int
30+
*/
31+
public $typeId;
32+
33+
/**
34+
* Amount of units that are being queued.
35+
*
36+
* @var int
37+
*/
38+
public $count;
39+
40+
/**
41+
* Create a ...
42+
*
43+
* @param \RecAnalyst\RecordedGame $rec Recorded game instance.
44+
* @param int $time Recorded game instance.
45+
*/
46+
public function __construct(RecordedGame $rec, $time, $buildings, $typeId, $count)
47+
{
48+
parent::__construct($rec, $time);
49+
50+
$this->buildings = $buildings;
51+
$this->typeId = $typeId;
52+
$this->count = $count;
53+
}
54+
55+
/**
56+
* Get a string representation of the action.
57+
*
58+
* @return string
59+
*/
60+
public function __toString()
61+
{
62+
return sprintf(
63+
'MultiQueue(typeId=%d, count=%d, buildings[%d]={%s})',
64+
$this->typeId,
65+
$this->count,
66+
count($this->buildings),
67+
implode(', ', $this->buildings)
68+
);
69+
}
70+
}

0 commit comments

Comments
 (0)