Skip to content

Commit

Permalink
Support UserPatch 1.5 terrain reading (#53)
Browse files Browse the repository at this point in the history
* Support UserPatch 1.5 terrain reading

* Add UserPatch 1.5 game
  • Loading branch information
goto-bus-stop committed Aug 19, 2017
1 parent 550fa77 commit c3c741c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions resources/lang/en/game_versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Version::VERSION_USERPATCH12 => 'AOC UP1.2',
Version::VERSION_USERPATCH13 => 'AOC UP1.3',
Version::VERSION_USERPATCH14 => 'AOC UP1.4',
Version::VERSION_USERPATCH15 => 'AOC UP1.5',
Version::VERSION_AOFE21 => 'AOFE 2.1',
Version::VERSION_HD => 'HD Edition',
Version::VERSION_HD43 => 'HD Edition 4.3',
Expand Down
18 changes: 11 additions & 7 deletions src/Analyzers/TerrainAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,21 @@ public function __construct($size)

protected function run()
{
$version = $this->get(VersionAnalyzer::class);

$mapData = [];
for ($y = 0; $y < $this->sizeY; $y += 1) {
$mapData[$y] = [];
for ($x = 0; $x < $this->sizeX; $x += 1) {
$mapData[$y][$x] = new Tile(
$x,
$y,
/* terrainId */ ord($this->header[$this->position]),
/* elevation */ ord($this->header[$this->position + 1])
);
$this->position += 2;
$terrainId = ord($this->header[$this->position++]);
if ($terrainId === 0xFF) {
$terrainId = ord($this->header[$this->position++]);
// Skip UserPatch "original terrain ID" data.
$this->position++;
}
$elevation = ord($this->header[$this->position++]);

$mapData[$y][$x] = new Tile($x, $y, $terrainId, $elevation);
}
}
return $mapData;
Expand Down
4 changes: 4 additions & 0 deletions src/Analyzers/VersionAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class VersionAnalyzer extends Analyzer
Version::VERSION_USERPATCH12,
Version::VERSION_USERPATCH13,
Version::VERSION_USERPATCH14,
Version::VERSION_USERPATCH15,
Version::VERSION_AOFE21,
];

Expand Down Expand Up @@ -95,6 +96,7 @@ protected function run()
$analysis->isTrial = in_array($version, $this->trialVersions);
$analysis->isAoK = in_array($version, $this->aokVersions);
$analysis->isUserPatch = in_array($version, $this->userpatchVersions);
$analysis->isUserPatch15 = $version === Version::VERSION_USERPATCH15;
$analysis->isHDEdition = in_array($version, $this->hdVersions);
$analysis->isHDPatch4 = $analysis->isHDEdition && $subVersion >= 12.00;
$analysis->isAoC = $analysis->isUserPatch || $analysis->isHDEdition ||
Expand Down Expand Up @@ -163,6 +165,8 @@ private function getVersion($version, $subVersion)
case 'VER 9.C':
case 'VER 9.D':
return Version::VERSION_USERPATCH14;
case 'VER 9.E':
return Version::VERSION_USERPATCH15;
default:
return $version;
}
Expand Down
7 changes: 7 additions & 0 deletions src/Model/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ class Version
*/
const VERSION_USERPATCH14 = 11;

/**
* Version ID for UserPatch v1.5.
*
* @var int
*/
const VERSION_USERPATCH15 = 20;

/**
* Version ID for HD Edition.
*
Expand Down
5 changes: 5 additions & 0 deletions test/HeaderAnalyzerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ public function playersProvider()
['name' => 'Zuppi'],
['name' => 'JorDan_23'],
], 2],
['./recs/versions/up1.5.mgz', [
['name' => 'Myth'],
['name' => 'Louis IX'],
['name' => 'Athelred the Unready'],
], 3],
['./recs/ai/Lobsth_15-pop-scouts_ai.mgx', [
['name' => 'Eternal Lobster'],
['name' => 'Ernak the Hun'],
Expand Down
Binary file added test/recs/versions/up1.5.mgz
Binary file not shown.

0 comments on commit c3c741c

Please sign in to comment.