Skip to content

Commit f29d1c6

Browse files
committed
[wip]
1 parent 425a143 commit f29d1c6

File tree

4 files changed

+152
-15
lines changed

4 files changed

+152
-15
lines changed

src/Analyzers/BodyAnalyzer.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,16 @@ protected function run()
288288
$this->readUnits($count)
289289
));
290290
break;
291+
case self::COMMAND_UNIT_AI_STATE:
292+
$numUnits = ord($this->body[$this->position++]);
293+
$stance = ord($this->body[$this->position++]);
294+
$this->push(new Actions\UnitAiStateAction(
295+
$this->rec,
296+
$this->currentTime,
297+
$stance,
298+
$this->readUnits($numUnits)
299+
));
300+
break;
291301
// player resign
292302
case self::COMMAND_RESIGN:
293303
$playerIndex = ord($this->body[$this->position]);
@@ -427,7 +437,7 @@ protected function run()
427437
}
428438
break;
429439
// tributing
430-
case self::COMMAND_TRIBUTE:
440+
case self::COMMAND_GIVE_ATTRIBUTE2:
431441
$playerIdFrom = ord($this->body[$this->position++]);
432442
$playerIdTo = ord($this->body[$this->position++]);
433443
$resourceId = ord($this->body[$this->position++]);

src/Model/Actions/AiOrderAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __construct(RecordedGame $rec, $time)
5151
public function __toString()
5252
{
5353
return sprintf(
54-
'AddAttribute(playerId=%d, attribute=%d, amount=%d)',
54+
'AiOrder(playerId=%d, attribute=%d, amount=%d)',
5555
$this->playerId,
5656
$this->attribute,
5757
$this->amount

src/Model/Actions/UnitAiStateAction.php

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,91 @@ class UnitAiStateAction extends Action
1616
*/
1717
const ID = 0x12;
1818

19-
// UnitAiState(num=%d, state=%d)
20-
private $num;
21-
private $state;
19+
const AGGRESSIVE = 0x00;
20+
const DEFENSIVE = 0x01;
21+
const STAND_GROUND = 0x02;
22+
const NO_ATTACK = 0x03;
23+
24+
/**
25+
* Current stance.
26+
*
27+
* @var int
28+
*/
29+
public $state;
30+
31+
/**
32+
* Units.
33+
*
34+
* @var int[]
35+
*/
36+
public $units = [];
2237

2338
/**
2439
* Create a ...
2540
*
2641
* @param \RecAnalyst\RecordedGame $rec Recorded game instance.
2742
* @param int $time Recorded game instance.
2843
*/
29-
public function __construct(RecordedGame $rec, $time)
44+
public function __construct(RecordedGame $rec, $time, $state, $units)
3045
{
3146
parent::__construct($rec, $time);
47+
48+
$this->state = $state;
49+
$this->units = $units;
50+
}
51+
52+
/**
53+
* Check whether the new stance is aggressive.
54+
*
55+
* @return bool True if the new stance is aggressive, false otherwise.
56+
*/
57+
public function isAggressive()
58+
{
59+
return $this->state === self::AGGRESSIVE;
60+
}
61+
62+
/**
63+
* Check whether the new stance is defensive.
64+
*
65+
* @return bool True if the new stance is defensive, false otherwise.
66+
*/
67+
public function isDefensive()
68+
{
69+
return $this->state === self::DEFENSIVE;
70+
}
71+
72+
/**
73+
* Check whether the new stance is standing ground.
74+
*
75+
* @return bool True if the new stance is standing ground, false otherwise.
76+
*/
77+
public function isStandGround()
78+
{
79+
return $this->state === self::STAND_GROUND;
80+
}
81+
82+
/**
83+
* Check whether the new stance is "No Attack".
84+
*
85+
* @return bool True if the new stance is passive, false otherwise.
86+
*/
87+
public function isNoAttack()
88+
{
89+
return $this->state === self::NO_ATTACK;
90+
}
91+
92+
/**
93+
* Get a string representation of the action.
94+
*
95+
* @return string
96+
*/
97+
public function __toString()
98+
{
99+
return sprintf(
100+
'UnitAiState(state=%d, units[%d]={%s})',
101+
$this->state,
102+
count($this->units),
103+
implode(', ', $this->units)
104+
);
32105
}
33106
}

src/Model/Actions/UnitOrderAction.php

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,77 @@ class UnitOrderAction extends Action
1616
*/
1717
const ID = 0x75;
1818

19-
// UnitOrder(num=%d, x=%.2f, y=%.2f, tId=%d, qId=%d, action=%d, param=%d)
20-
private $units;
21-
private $x;
22-
private $y;
23-
private $targetId;
24-
private $qid;
25-
private $action;
26-
private $parameter;
19+
/**
20+
* @var int[]
21+
*/
22+
public $units;
23+
24+
/**
25+
* @var float
26+
*/
27+
public $x;
28+
29+
/**
30+
* @var float
31+
*/
32+
public $y;
33+
34+
/**
35+
* @var int
36+
*/
37+
public $targetId;
38+
39+
/**
40+
* @var int
41+
*/
42+
public $qId;
43+
44+
/**
45+
* @var int
46+
*/
47+
public $action;
48+
49+
/**
50+
* @var int
51+
*/
52+
public $parameter;
2753

2854
/**
2955
* Create a ...
3056
*
3157
* @param \RecAnalyst\RecordedGame $rec Recorded game instance.
3258
* @param int $time Recorded game instance.
3359
*/
34-
public function __construct(RecordedGame $rec, $time)
60+
public function __construct(RecordedGame $rec, $time, $x, $y, $targetId, $qId, $action, $parameter, $units)
3561
{
3662
parent::__construct($rec, $time);
63+
64+
$this->x = $x;
65+
$this->y = $y;
66+
$this->targetId = $targetId;
67+
$this->qId = $qId;
68+
$this->action = $action;
69+
$this->parameter = $parameter;
70+
$this->units = $units;
71+
}
72+
73+
/**
74+
* Get a string representation of the action.
75+
*
76+
* @return string
77+
*/
78+
public function __toString()
79+
{
80+
return sprintf(
81+
'UnitOrder(x=%.2f, y=%.2f, targetId=%d, qId=%d, action=%d, parameter=%d, units[%d]={%s})',
82+
$this->x,
83+
$this->y,
84+
$this->targetId,
85+
$this->qId,
86+
$this->action,
87+
$this->parameter,
88+
count($this->units),
89+
implode(', ', $this->units)
90+
);
3791
}
3892
}

0 commit comments

Comments
 (0)