Initial commit

This commit is contained in:
Ambroise Garel
2025-07-22 10:22:50 +02:00
parent 16f53c8a47
commit edb28205cd
422 changed files with 17001 additions and 2 deletions

133
BuildScript/Mission.php Normal file
View File

@@ -0,0 +1,133 @@
<?php
function computeCenter($vertices)
{
$center = [ 0, 0 ];
foreach ($vertices as $vertex)
{
$center[0] += $vertex[0];
$center[1] += $vertex[1];
}
$center[0] /= count($vertices);
$center[1] /= count($vertices);
return $center;
}
function makeZoneLua($vertices, $index, $name, $color)
{
$center = computeCenter($vertices);
$lua = "[$index] =\n{\n";
$lua .= "radius = 10,\n";
$lua .= "zoneId = $index,\n";
$lua .= "color = $color,\n";
$lua .= "properties = { },\n";
$lua .= "hidden = false,\n";
$lua .= "x = ".strval($center[0]).",\n";
$lua .= "y = ".strval($center[1]).",\n";
$lua .= "name = \"$name\",\n";
$lua .= "type = 2,\n";
$lua .= "heading = 0,\n";
$lua .= "verticies =\n{\n";
for ($i = 1; $i <= 4; $i++) {
$lua .= "[$i] =\n{\n";
$lua .= "x = ".strval($vertices[$i - 1][0]).",\n";
$lua .= "y = ".strval($vertices[$i - 1][1]).",\n";
$lua .= "},\n";
}
$lua .= "},\n},\n";
return $lua;
}
function makeZones($theaterJson)
{
$lua = "";
$coalitionZoneCount = [1, 1];
$zoneCount = 1;
foreach (["blue", "red"] as $zoneType)
{
foreach ($theaterJson["territories"][$zoneType] as $zone)
{
$name = "ZONE";
switch ($zoneType)
{
case "blue":
$color = "{ [1] = 0, [2] = 0.125, [3] = 1, [4] = 0.35 }";
$name = "BLUFOR".strval($coalitionZoneCount[0]);
break;
case "red":
$color = "{ [1] = 1, [2] = 0.125, [3] = 0, [4] = 0.35 }";
$name = "REDFOR".strval($coalitionZoneCount[1]);
break;
}
$lua .= makeZoneLua($zone, $zoneCount, $name, $color);
$zoneCount++;
switch ($zoneType)
{
case "blue": $coalitionZoneCount[0]++; break;
case "red": $coalitionZoneCount[1]++; break;
}
}
}
if (isset($theaterJson["water"]))
{
$waterZonesCount = 1;
foreach ($theaterJson["water"] as $zone)
{
$lua .= makeZoneLua($zone, $zoneCount, "WATER".strval($waterZonesCount), "{ [1] = 0, [2] = 0.8, [3] = 1, [4] = 0.35 }");
$zoneCount++;
$waterZonesCount++;
}
}
$color = "{ [1] = 0.5, [2] = 0.5, [3] = 0.5, [4] = 0.35 }";
foreach (array_keys($theaterJson["targetZones"]) as $key)
{
$lua .= makeZoneLua($theaterJson["targetZones"][$key], $zoneCount, $key, $color);
$zoneCount++;
}
return $lua;
}
function createMissionTable($theaterJson)
{
$lua = file_get_contents("./Miz/Mission.lua");
$lua = str_replace("__THEATER__", $theaterJson["dcsID"], $lua);
$lua = str_replace("__MAP_CENTER_X__", strval($theaterJson["mapCenter"][0]), $lua);
$lua = str_replace("__MAP_CENTER_Y__", strval($theaterJson["mapCenter"][1]), $lua);
$lua = str_replace("__MAP_ZOOM__", strval($theaterJson["mapZoom"]), $lua);
$lua = str_replace("__MISSION_BRIEFING__", "", $lua); // TODO
$lua = str_replace("__MISSION_DESCRIPTION__", "The Universal Mission for DCS World is an attempt to create a fully dynamic single-player/PvE mission giving access to the whole content of DCS World.\\n\\nOpen the F10/Other submenu in the communication menu to begin.\\n\\nVisit github.com/akaAgar/the-universal-mission-for-dcs-world to learn more.", $lua);
$lua = str_replace("__MISSION_NAME__", "The Universal Mission - ".$theaterJson["displayName"], $lua);
$lua = str_replace("__WEATHER_TEMPERATURE__", strval($theaterJson["temperature"]), $lua);
$lua = str_replace("__PLAYER_AIRDROME_ID__", strval($theaterJson["player"]["airdromeID"]), $lua);
$lua = str_replace("__PLAYER_X__", strval($theaterJson["player"]["coordinates"][0]), $lua);
$lua = str_replace("__PLAYER_Y__", strval($theaterJson["player"]["coordinates"][1]), $lua);
$lua = str_replace("__ZONES__", makeZones($theaterJson), $lua);
$lua = str_replace("__BULLSEYE_BLUE_X__", strval($theaterJson["bullseye"]["blue"][0]), $lua);
$lua = str_replace("__BULLSEYE_BLUE_Y__", strval($theaterJson["bullseye"]["blue"][1]), $lua);
$lua = str_replace("__BULLSEYE_RED_X__", strval($theaterJson["bullseye"]["red"][0]), $lua);
$lua = str_replace("__BULLSEYE_RED_Y__", strval($theaterJson["bullseye"]["red"][1]), $lua);
$lua = str_replace("__DATE_DAY__", strval($theaterJson["dateTime"]["day"]), $lua);
$lua = str_replace("__DATE_MONTH__", strval($theaterJson["dateTime"]["month"]), $lua);
$lua = str_replace("__DATE_YEAR__", strval($theaterJson["dateTime"]["year"]), $lua);
$lua = str_replace("__START_TIME__", strval(($theaterJson["dateTime"]["hour"] * 60 + $theaterJson["dateTime"]["minute"]) * 60), $lua);
file_put_contents("_DebugOutput/Mission-".$theaterJson["dcsID"].".lua", $lua);
return $lua;
}
?>

73
BuildScript/Script.php Normal file
View File

@@ -0,0 +1,73 @@
<?php
function createScript($theaterJson, $debugMode)
{
echo " Concatenating script file...\n";
$lua = file_get_contents("./Script/Script.lua");
if ($debugMode)
$lua = str_replace("__DEBUG_MODE__", "true", $lua);
else
$lua = str_replace("__DEBUG_MODE__", "false", $lua);
// Replace all lignes in the format "--[[.*]]--" by the contents of the given Script subdirectory (e.g. "--[[LIBRARY]]--" means "all .lua files from the Script/Library subdirectory")
do
{
$matches = null;
preg_match_all("/--\[\[.*\]\]--/", $lua, $matches, PREG_OFFSET_CAPTURE);
if (count($matches[0]) == 0) break;
foreach ($matches[0] as $match)
{
$dirName = mb_substr($match[0], 4, strlen($match[0]) - 8);
$sourceDir = "./Script/".$dirName."/";
$replacement = "";
if (is_dir($sourceDir))
{
$files = scandir($sourceDir);
foreach ($files as $file)
{
if (!is_file($sourceDir.$file)) continue;
if (!str_ends_with(strtolower($file), ".lua")) continue;
$replacement .= trim(file_get_contents($sourceDir.$file), " \n\r,")."\n";
}
}
$lua = str_replace($match[0], $replacement, $lua);
}
} while (true);
// Replace all lignes in the format "--[[.*]]--" by the contents of the given Database subdirectory (e.g. "--{{LIBRARY}}--" means "all .lua files from the Database/Library subdirectory")
do
{
$matches = null;
preg_match_all("/--\{\{.*\}\}--/", $lua, $matches, PREG_OFFSET_CAPTURE);
if (count($matches[0]) == 0) break;
foreach ($matches[0] as $match)
{
$dirName = mb_substr($match[0], 4, strlen($match[0]) - 8);
$sourceDir = "./Database/".$dirName."/";
$replacement = "";
if (is_dir($sourceDir))
{
$files = scandir($sourceDir);
foreach ($files as $file)
{
if (!is_file($sourceDir.$file)) continue;
if (!str_ends_with(strtolower($file), ".lua")) continue;
$replacement .= trim(file_get_contents($sourceDir.$file), " \n\r,")."\n";
}
}
$lua = str_replace($match[0], $replacement, $lua);
}
} while (true);
file_put_contents("./_DebugOutput/Script-".$theaterJson["dcsID"].".lua", $lua);
return $lua;
}
?>

View File

@@ -0,0 +1,57 @@
<?php
function createWarehousesTable($theaterJson)
{
$lua = "warehouses =\n";
$lua .= "{\n";
$lua .= "\tairports =\n";
$lua .= "\t{\n";
foreach ($theaterJson["airbasesIDs"] as $airbaseID)
{
$lua .= "\t\t[$airbaseID] =\n";
$lua .= "\t\t{\n";
$lua .= "\t\t\tgasoline =\n";
$lua .= "\t\t\t{\n";
$lua .= "\t\t\t InitFuel = 100,\n";
$lua .= "\t\t\t},\n";
$lua .= "\t\t\tunlimitedMunitions = true,\n";
$lua .= "\t\t\tdynamicCargo = false,\n";
$lua .= "\t\t\tOperatingLevel_Air = 10,\n";
$lua .= "\t\t\tdiesel =\n";
$lua .= "\t\t\t{\n";
$lua .= "\t\t\t InitFuel = 100,\n";
$lua .= "\t\t\t},\n";
$lua .= "\t\t\tspeed = 16.666666,\n";
$lua .= "\t\t\tdynamicSpawn = false,\n";
$lua .= "\t\t\tunlimitedAircrafts = true,\n";
$lua .= "\t\t\tunlimitedFuel = true,\n";
$lua .= "\t\t\tmethanol_mixture =\n";
$lua .= "\t\t\t{\n";
$lua .= "\t\t\t InitFuel = 100,\n";
$lua .= "\t\t\t},\n";
$lua .= "\t\t\tperiodicity = 30,\n";
$lua .= "\t\t\tsuppliers = {},\n";
$lua .= "\t\t\tcoalition = \"NEUTRAL\",\n";
$lua .= "\t\t\tsize = 100,\n";
$lua .= "\t\t\tOperatingLevel_Eqp = 10,\n";
$lua .= "\t\t\tallowHotStart = false,\n";
$lua .= "\t\t\taircrafts = {},\n";
$lua .= "\t\t\tweapons = {},\n";
$lua .= "\t\t\tOperatingLevel_Fuel = 10,\n";
$lua .= "\t\t\tjet_fuel =\n";
$lua .= "\t\t\t{\n";
$lua .= "\t\t\t InitFuel = 100,\n";
$lua .= "\t\t\t},\n";
$lua .= "\t\t},\n";
}
$lua .= "\t},\n";
$lua .= "\twarehouses = {},\n";
$lua .= "}\n";
file_put_contents("_DebugOutput/Warehouses-".$theaterJson["dcsID"].".lua", $lua);
return $lua;
}
?>