Skip to content

Commit

Permalink
Implement MultiQueue action from UserPatch.
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Oct 12, 2017
1 parent 1c0e746 commit e4cc4fb
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Analyzers/BodyAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class BodyAnalyzer extends Analyzer
const COMMAND_TRADE_ATTRIBUTE = 0x6D;
const COMMAND_REPAIR = 0x6E;
const COMMAND_UNLOAD = 0x6F;
const COMMAND_MULTI_QUEUE = 0x70;
const COMMAND_GATE = 0x72;
const COMMAND_FLARE = 0x73;
const COMMAND_SPECIAL = 0x74;
Expand Down Expand Up @@ -508,6 +509,25 @@ protected function run()
$this->units[$unitType] += $amount;
}
break;
case self::COMMAND_MULTI_QUEUE:
$this->position += 3;
$unitType = $this->readBody('v', 2);
$numBuildings = ord($this->body[$this->position++]);
$amount = ord($this->body[$this->position++]);
$buildings = [];

for ($i = 0; $i < $numBuildings; $i++) {
$buildings[] = $this->readBody('l', 4);
}

$this->push(new Actions\MultiQueueAction(
$this->rec,
$this->currentTime,
$buildings,
$unitType,
$amount
));
break;
case self::COMMAND_GAME:
$this->processGameAction();
break;
Expand Down
70 changes: 70 additions & 0 deletions src/Model/Actions/MultiQueueAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace RecAnalyst\Model\Actions;

use RecAnalyst\RecordedGame;

/**
* Represents a multiple building queue action, from UserPatch 1.4.
*/
class MultiQueueAction extends Action
{
/**
* The action ID.
*
* @var int
*/
const ID = 0x70;

/**
* Building IDs that the action applies to.
*
* @var int[]
*/
public $buildings;

/**
* ID of the unit type that is being queued.
*
* @var int
*/
public $typeId;

/**
* Amount of units that are being queued.
*
* @var int
*/
public $count;

/**
* Create a ...
*
* @param \RecAnalyst\RecordedGame $rec Recorded game instance.
* @param int $time Recorded game instance.
*/
public function __construct(RecordedGame $rec, $time, $buildings, $typeId, $count)
{
parent::__construct($rec, $time);

$this->buildings = $buildings;
$this->typeId = $typeId;
$this->count = $count;
}

/**
* Get a string representation of the action.
*
* @return string
*/
public function __toString()
{
return sprintf(
'MultiQueue(typeId=%d, count=%d, buildings[%d]={%s})',
$this->typeId,
$this->count,
count($this->buildings),
implode(', ', $this->buildings)
);
}
}

0 comments on commit e4cc4fb

Please sign in to comment.