Skip to content

Commit

Permalink
Implement reading Follow, Attack Ground, and Town Bell actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Dec 11, 2016
1 parent 913aa93 commit 4fa0ef5
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 11 deletions.
83 changes: 76 additions & 7 deletions src/Analyzers/BodyAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,37 @@ protected function run()
$z
));
break;
case self::COMMAND_UNIT_AI_STATE:
$numUnits = ord($this->body[$this->position++]);
$stance = ord($this->body[$this->position++]);
$this->push(new Actions\UnitAiStateAction(
case self::COMMAND_ADD_ATTRIBUTE:
$playerId = ord($this->body[$this->position++]);
$resourceType = ord($this->body[$this->position++]);
$this->position += 1;
$amount = $this->readBody('f', 4);

$this->push(new Actions\AddAttributeAction(
$this->rec,
$this->currentTime,
$stance,
$this->readUnits($numUnits)
$playerId,
$resourceType,
$amount
));
break;
// Old-style tributing.
case self::COMMAND_GIVE_ATTRIBUTE:
$playerIdFrom = ord($this->body[$this->position++]);
$playerIdTo = ord($this->body[$this->position++]);
$resourceId = ord($this->body[$this->position++]);
$amount = $this->readBody('f', 4);
// Market fees only apply to COMMAND_GIVE_ATTRIBUTE2.
$marketFee = 0.0;

$this->push(new Actions\GiveAttributeAction(
$this->rec,
$this->currentTime,
$playerIdFrom,
$playerIdTo,
$resourceId,
$amount,
$marketFee
));
break;
// player resign
Expand All @@ -345,8 +368,29 @@ protected function run()
$this->chatMessages[] = new ChatMessage($this->currentTime, null, $message);
}
break;
case self::COMMAND_UNIT_AI_STATE:
$numUnits = ord($this->body[$this->position++]);
$stance = ord($this->body[$this->position++]);
$this->push(new Actions\UnitAiStateAction(
$this->rec,
$this->currentTime,
$stance,
$this->readUnits($numUnits)
));
break;
case self::COMMAND_FOLLOW:
$numUnits = ord($this->body[$this->position++]);
$this->position += 2;
$target = $this->readBody('l', 4);

$this->push(new Actions\FollowAction(
$this->rec,
$this->currentTime,
$target,
$this->readUnits($numUnits)
));
break;
case self::COMMAND_PATROL:
$start = $this->position - 1;
$numUnits = ord($this->body[$this->position++]);
$numWaypoints = ord($this->body[$this->position++]);
$this->position++;
Expand Down Expand Up @@ -484,6 +528,19 @@ protected function run()
$objectId
));
break;
case self::COMMAND_ATTACK_GROUND:
$count = ord($this->body[$this->position++]);
$this->position += 2;
$x = $this->readBody('f', 4);
$y = $this->readBody('f', 4);
$this->push(new Actions\AttackGroundAction(
$this->rec,
$this->currentTime,
$x,
$y,
$this->readUnits($count)
));
break;
// AI trains unit
case self::COMMAND_MAKE:
$this->position += 3;
Expand Down Expand Up @@ -666,6 +723,18 @@ protected function run()
$marketId
));
break;
case self::COMMAND_TOWN_BELL:
$this->position += 3;
$unitId = $this->readBody('l', 4);
$active = $this->readBody('l', 4);

$this->push(new Actions\TownBellAction(
$this->rec,
$this->currentTime,
$unitId,
$active
));
break;
case self::COMMAND_GO_BACK_TO_WORK:
$this->position += 3;
$unitId = $this->readBody('l', 4);
Expand Down
6 changes: 5 additions & 1 deletion src/Model/Actions/AttackGroundAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ class AttackGroundAction extends Action
* @param \RecAnalyst\RecordedGame $rec Recorded game instance.
* @param int $time Recorded game instance.
*/
public function __construct(RecordedGame $rec, $time)
public function __construct(RecordedGame $rec, $time, $x, $y, $units)
{
parent::__construct($rec, $time);

$this->x = $x;
$this->y = $y;
$this->units = $units;
}

/**
Expand Down
35 changes: 32 additions & 3 deletions src/Model/Actions/FollowAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,46 @@ class FollowAction extends Action
const ID = 0x14;

// Follow(num=%d, target=%d)
private $num;
private $target;
/**
* ID of the target unit to follow.
*
* @var int
*/
public $targetId;

/**
* IDs of the units that should follow the target.
*
* @var int[]
*/
public $units;

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

$this->targetId = $targetId;
$this->units = $units;
}

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

0 comments on commit 4fa0ef5

Please sign in to comment.