- Lua解読分析集
- Lua解読分析集/Game_Setup いまここ
- Lua解読分析集/Standalone Scenariosイベント
Game_Setup(シナリオ開始1秒後に行われる中立ユニットの配置など)の解読
目次
WeatherDrift()の実行=天候を設定する
WeatherDrift()
if DebugModeIsOn() then
WeatherReport('WEATHER INITIALISED')
end
CivilianAirTraffic=中立航空ユニット生成
コードはBrassDrumから
最初の各設定
math.randomseed(os.time())
math.random()
--Tool_EmulateNoConsole()
local missionList = {}
airportsテーブル
飛行場ユニットのリストテーブル
local airports = {
{name = "Abu Dhabi International Airport", guid = "0e88cc5f-3fcd-44c7-a181-29202e45f4af"},
{name = "Dubai International Airport", guid = "3c75917a-ae36-4f56-be43-c54fb6d3c0d5"},
--以下省略
}
aircraftテーブル
航空ユニットのリストテーブル
local aircraft = {
{dbid=2421, ferryRange=3800, loadoutid=14761}, --Boeing 737-700ER -- Commercial (Commercial), 2008
{dbid=2424, ferryRange=4260, loadoutid=14762}, --Boeing 767-300 -- Commercial (Commercial), 1988
{dbid=2425, ferryRange=5625, loadoutid=14765}, --Boeing 767-400ER -- Commercial (Commercial), 2002
--以下省略
}
ReturnRandomAircraftEntry()
aircraftテーブルからエントリをランダム選択する(ReturnRandomAircraftEntry().guidでGUIDが取得される)
local function ReturnRandomAircraftEntry()
return aircraft[math.random(1, #aircraft)]
end
目的飛行場選択関係関数
ReturnFerryRangeFromGUID(aircraftGUID)
aircraftテーブルから航空ユニットの航続距離ferryRangeを取得する
local function ReturnFerryRangeFromGUID(aircraftGUID)
local result
local unit = ScenEdit_GetUnit({guid = aircraftGUID})
for k, v in ipairs(aircraft) do
if unit.dbid == v.dbid then
result = v.ferryRange
end
end
return result
end
GenerateListOfPossibleDestinations_ByRange(safeRange, aircraftGUID)
後述するGenerateListOfPossibleDestinations_GUID()の派生で,関数引数として直接指定されたsafeRange距離内にある飛行場ユニットのリストをresultテーブルとして取得する+航空ユニットと飛行場ユニットの距離をrangeとして定義する
local function GenerateListOfPossibleDestinations_ByRange(safeRange, aircraftGUID)
local unit = ScenEdit_GetUnit({guid = aircraftGUID})
local result = {}
for k, v in ipairs(airports) do
local tripDistance = Tool_Range(aircraftGUID, v.guid)
if tripDistance < safeRange then
local tableEntry = {name = v.name, guid = v.guid, range = tripDistance}
table.insert(result, tableEntry)
end
end
return result
end
SortListOfAirportsByRange(airportTable)
GenerateListOfPossibleDestinations_GUID(aircraftGUID),あるいはGenerateListOfPossibleDestinations_ByRange(safeRange, aircraftGUID)で取得した飛行場リストテーブルからrangeの値だけを抽出したテーブルをつくり距離の小さい分に整列する,それをもとに飛行場テーブルを距離の大きい順に整列する
local function SortListOfAirportsByRange(airportTable)
local rangeTable, result = {}, {}
for k, v in ipairs(airportTable) do
table.insert(rangeTable, v.range)
end
table.sort(rangeTable)
for i = #rangeTable, 1, -1 do
rangeValue = rangeTable[i]
for key, value in ipairs(airportTable) do
if value.range == rangeValue then
table.insert(result, value)
end
end
end
return result
end
ChooseOneOfFurthestDestinations(airportTable)
SortListOfAirportsByRange(airportTable)で整列した飛行場テーブルから最も距離の大きい3飛行場ユニットのうち一つを選択する(航空ユニットの回送目的地となる)
local function ChooseOneOfFurthestDestinations(airportTable)
local airportTable = SortListOfAirportsByRange(airportTable)
local tableLength = #airportTable
if tableLength > 3 then
tableLength = 3
end
local result = airportTable[math.random(1, tableLength)]
return result
end
GenerateListOfPossibleDestinations_GUID(aircraftGUID)
指定した航空ユニットのsafeRange =ferryRange*0.8の距離内にある飛行場ユニットのリストをresultテーブルとして取得する+航空ユニットと飛行場ユニットの距離をrangeとして定義する
この関数を使うCreateMissionAndAssignAircraft_Random(aircraftGUID)が使用されていないので
こちらも使用されていない模様
local function GenerateListOfPossibleDestinations_GUID(aircraftGUID)
local unit = ScenEdit_GetUnit({guid = aircraftGUID})
local safeRange = ReturnFerryRangeFromGUID(aircraftGUID) * 0.8
local result = {}
for k, v in ipairs(airports) do
local tripDistance = Tool_Range(aircraftGUID, v.guid)
if tripDistance < safeRange then
local tableEntry = {name = v.name, guid = v.guid, range = tripDistance}
table.insert(result, tableEntry)
end
end
return result
end
回送ミッション生成関連関数
ThisFerryMissionExists(missionName)
回送ミッション" missionName"がmissionListテーブル内に存在するか=ミッションとして存在するか確認
local function ThisFerryMissionExists(missionName)
local result = false
for k, v in ipairs(missionList) do
if v == missionName then
return true
end
end
return false
end
AddMissionToList(missionName)
ミッション名"missionName"をmissionListテーブルに追加する
local function AddMissionToList(missionName)
table.insert(missionList, missionName)
end
GenerateFerryMission(destinationName)
ThisFerryMissionExists(missionName)によりdestinationNameという名称のミッションがあるかを確認し:
- ある場合→そのままmissionテーブルを取得する
- ない場合→目的地飛行場ユニット名により命名される回送ミッションを生成する+missionテーブルを取得する
local function GenerateFerryMission(destinationName)
local mission
if ThisFerryMissionExists(destinationName) then
mission = ScenEdit_GetMission("Civilian", destinationName)
else
mission = ScenEdit_AddMission("Civilian", destinationName, "ferry", {destination = destinationName})
ScenEdit_SetMission("Civilian", mission.guid, {FerryBehavior = "Random", flightSize = 1})
AddMissionToList(mission.name)
end
return mission
end
CreateMissionAndAssignAircraft_Random(aircraftGUID)
ミッション生成+ユニット編入の実行部分(目的地をランダム決定するもの)
GenerateAircraft() では別の部分で目的地をランダム決定しているため,この関数は使用されていない模様
local function CreateMissionAndAssignAircraft_Random(aircraftGUID)
local airportTable = GenerateListOfPossibleDestinations_GUID(aircraftGUID)
local destinationName = ChooseOneOfFurthestDestinations(airportTable).name
Tool_EmulateNoConsole()
GenerateFerryMission(destinationName)
ScenEdit_AssignUnitToMission(aircraftGUID, destinationName)
end
CreateMissionAndAssignAircraft(aircraftGUID, destinationName)
ミッション生成+ユニット編入の実行部分(目的地を引数指定するもの)
local function CreateMissionAndAssignAircraft(aircraftGUID, destinationName)
Tool_EmulateNoConsole()
local mission = GenerateFerryMission(destinationName)
ScenEdit_AssignUnitToMission(aircraftGUID, destinationName)
return mission
end
その他関数
GenerateRandomAircraftName()
航空ユニットのユニット名を生成する
「(IATA航空会社コードとしてアルファベット2ケタ)+(3桁の数字)」なので"AB-133"のようになる
local function GenerateRandomAircraftName()
local result
local flightNumber = math.random(100, 999)
result = RandomLetter() .. RandomLetter() .. "-" .. flightNumber
return result
end
NameIsADuplicate(nameString)
Civilian陣営のユニットを調べて生成するユニット名が重複していないかのチェック(使用していない模様)
local function NameIsADuplicate(nameString)
Tool_EmulateNoConsole()
local unit = ScenEdit_GetUnit({side = "Civilian", name = nameString})
if unit == nil then
return true
else
return false
end
end
RandomiseReadyTime(aircraftGUID)
航空ユニットの準備時間を0-240分の間でランダム設定する
local function RandomiseReadyTime(aircraftGUID)
local unit = ScenEdit_GetUnit({guid = aircraftGUID})
ScenEdit_SetLoadout(
{
unitName = unit.guid,
loadoutid = 0,
TimeToReady_Minutes = math.random(0, (4 * 60))
}
)
end
GenerateAircraft()
生成実行部
- airportsテーブルからランダムに選択して航空ユニットが収容される飛行場ユニットhomebaseを決定する
- homebaseからのsafeRange=aircraftテーブル内のferryRange範囲内にある飛行場ユニットを目的地候補として取得,目的地候補のなかから航空ユニットの回送目的地destinationを決定する
- 航空ユニット生成
- 航空ユニットの準備時間設定
- 回送ミッション生成(目的地destination)+航空ユニット編入
local function GenerateAircraft()
--1
local error_Count = 0
::redoGenerateAircraft::
local aircraft = ReturnRandomAircraftEntry()
local homebase = nil
local homebaseList = airports
homebase = homebaseList[math.random(1, #homebaseList)]
--2
local destination, destinationList
local safeRange = ReturnFerryRangeFromDBID(aircraft.dbid)
destinationList = GenerateListOfPossibleDestinations_ByRange(safeRange, homebase.guid)
destination = ChooseOneOfFurthestDestinations(destinationList)
--3
local unit =
ScenEdit_AddUnit(
{
side = "Civilian",
type = "Aircraft",
dbid = aircraft.dbid,
name = GenerateRandomAircraftName(),
base = homebase.guid,
loadoutid = aircraft.loadoutid
}
)
--4
RandomiseReadyTime(unit.guid)
--5
CreateMissionAndAssignAircraft(unit.name, destination.name)
local result = ScenEdit_GetUnit({guid = unit.guid})
return result
end
実行部分
- 100個の航空ユニットを生成(シナリオに直接関係しないユニットが100近く+さらに中立水上ユニットなどがあると処理落ち確実,生成数は減らしてよいかも)
for i = 1, 100 do
GenerateAircraft()
end
CivilianShipping=水上ユニット生成(方法1)
ウェイポイントを設定する複雑バージョン コードはOperation Brass Drumから
shipListテーブル
生成候補のユニットサブタイプリスト
Passenger(客船),Pleasure(ヨットなど),Commercial(通常商船)の3種類
local shipList = {
{
name = "Commercial",
{dbid=775, prefix='MV ', category ='Commercial'}, --Commercial Container Vessel - Feeder [1600 TEU, 20000 DWT]
{dbid=2027, prefix='MV ', category ='Commercial'}, --Commercial Container Vessel - Feedermax [3000 TEU, 30000 DWT]
{dbid=2029, prefix='MV ', category ='Commercial'}, --Commercial Container Vessel - New Panamax [13500 TEU, 155000]
--以下省略
},
{
name = "Pleasure",
{dbid=2696, prefix='MV ', category ='Pleasure'}, --Civilian Go Fast [13m]
{dbid=1474, prefix='MY ', category ='Pleasure'}, --Civilian Motor Yacht [13m]
{dbid=1475, prefix='MY ', category ='Pleasure'}, --Civilian Motor Yacht [38m]
--以下省略
},
{
name = "Passenger",
{dbid=384, prefix='MS ', category ='Passenger'}, --Commercial Cruise Liner [135000 GT]
{dbid=2024, prefix='MS ', category ='Passenger'}, --Commercial Cruise Liner [45000 GT]
--以下省略
}
}
shipNamesテーブル
ユニット名リスト
local shipNames = {
{
name = "Commercial",
'Ad Lib',
'Aquitania',
--以下省略
},
{
name = "Pleasure",
'Acid',
'Adore',
'Alexis Mateo',
--以下省略
},
{
name = "Passenger",
'Adultery Carnival',
'Astronomical Bar-Tab',
--以下省略
},
}
rpListテーブル
ユニットのウェイポイントとして使用するRPのテーブル
local rpList_1 = {
{name = 'Shipping Route A1', radius = 50},
{name = 'Shipping Route A2', radius = 50},
{name = 'Shipping Route A3', radius = 50},
{name = 'Shipping Route A4', radius = 50},
{name = 'Shipping Route A5', radius = 50},
{name = 'Shipping Route A6', radius = 50},
}
local rpList_2 = {
{name = 'Shipping Route B1', radius = 50},
{name = 'Shipping Route B2', radius = 50},
{name = 'Shipping Route B3', radius = 50},
{name = 'Shipping Route B4', radius = 50},
{name = 'Shipping Route B5', radius = 50},
{name = 'Shipping Route B6', radius = 50},
}
local rpList_3 = {
{name = 'Shipping Route C1', radius = 50},
{name = 'Shipping Route C2', radius = 50},
{name = 'Shipping Route C3', radius = 50},
{name = 'Shipping Route C4', radius = 50},
{name = 'Shipping Route C5', radius = 50},
{name = 'Shipping Route C6', radius = 50},
}
AddRandomShipping(latitude, longitude, ship_type)
ユニットを生成する関数
local function AddRandomShipping(latitude, longitude, ship_type)
-- ship_typeとして"Commercial"を設定したとする
--shipListテーブル内からname=Commercialの入れ子テーブルをshipSubListとしてを取得する
for k,v in ipairs (shipList) do
if v.name == ship_type then shipSubList = v end
end
-- shipSubListに入っているユニットサブタイプをランダムで取得する(shipEntry.dbidでDBIDが取得できる)
local shipEntry = shipSubList[math.random(1,#shipSubList)]
--shipNamesテーブル内からname=Commercialを含む入れ子テーブルを取得しランダムでユニット名を取得
--取得したユニット名は同じ名前のユニットが再度生成されないようテーブル内から削除する
for k,v in ipairs (shipNames) do
if v.name == ship_type then
randomName = math.random(1,#v)
shipName = v[randomName]
table.remove(v,randomName)
end
end
--ユニットを生成する("MV Shipname"のようなユニット名になる)
local addedShip = ScenEdit_AddUnit({side='Civilian',
name = shipEntry.prefix..shipName,
type = 'Ship',
dbid = shipEntry.dbid,
side = 'Civilian',
latitude = latitude,
longitude = longitude})
return addedShip
end
AddInitialHeadingAndSpeed(guid)
ユニットの第1ウェイポイントの方向へ方位を設定+速力5ktに設定
function AddInitialHeadingAndSpeed(guid)
local unit = ScenEdit_GetUnit({guid=guid})
local initialHeading = Tool_Bearing(
{
latitude=unit.latitude,
longitude=unit.longitude
},
{
latitude=unit.course[1].latitude,
longitude=unit.course[1].longitude,
}
)
local initialSpeed = 5
ScenEdit_SetUnit({guid=guid,speed=initialSpeed,heading=initialHeading})
end
生成実行部分
70-100隻の船舶をランダムで追加する
local shippingAmount = math.random(70,100)
for i = 1, shippingAmount do
--船舶のサブタイプを決定する
if i <= shippingAmount * 0.8 then
shipType = 'Commercial'
elseif i <= shippingAmount * 0.95 then
shipType = 'Pleasure'
else
shipType = 'Passenger'
end
--どのrpList利用するか+rpListのうちどのRPをrandomRPとしてユニット生成位置にするかを決定する
local rpList
local chance = math.random(1,3)
if chance == 1 then
rpList = rpList_1
elseif chance == 2 then
rpList = rpList_2
elseif chance == 3 then
rpList = rpList_3
end
local randomRPNumber = math.random(1,#rpList)
local randomRP = rpList[randomRPNumber]
--ユニットの生成位置をRPからのランダム位置(50nm以内)で決める
local referencePoint = ScenEdit_GetReferencePoint({side='Civilian',name=randomRP.name})
local randomPos = CircularRandomPosition(referencePoint.latitude,referencePoint.longitude,randomRP.radius)
--ユニット生成位置が陸上で生成失敗したときの戻り位置
local redoCounter = 0
::redoRandomPosition::
--ユニットのウェイポイントを設定する(rpListの各RPから20nm以内のランダム位置)
local shipCourse = {}
local chance = math.random(1,2) --各RPを進む方向か戻る方向かを決める
local startWP, waypoint
--進む方向
if randomRPNumber == 1 or (chance == 1 and randomRPNumber <= #rpList - 1) then
startWP = randomRPNumber + 1 --ユニット生成位置のひとつ次のRPからウェイポイント生成
for i = startWP, #rpList do
waypoint = ScenEdit_GetReferencePoint({
side='Civilian',
name=rpList[i].name})
waypointRandomPos = CircularRandomPosition(waypoint.latitude, waypoint.longitude, 20)
if OverWater(waypointRandomPos.latitude, waypointRandomPos.longitude) then
table.insert(shipCourse,waypointRandomPos)
end
end
--戻る方向
else
startWP = randomRPNumber - 1 --ユニット生成位置のひとつ前のRPからウェイポイント生成
for i = startWP, 1, -1 do
waypoint = ScenEdit_GetReferencePoint({
side='Civilian',
name=rpList[i].name})
waypointRandomPos = CircularRandomPosition(waypoint.latitude, waypoint.longitude, 20)
if OverWater(waypointRandomPos.latitude, waypointRandomPos.longitude) then
table.insert(shipCourse,waypointRandomPos)
end
end
end
--ユニット生成位置が海上ならユニット生成,ウェイポイント設定
if OverWater(randomPos.latitude,randomPos.longitude) then
unit = AddRandomShipping(randomPos.latitude,randomPos.longitude,shipType)
ScenEdit_SetUnit({guid=unit.guid,course=shipCourse})
AddInitialHeadingAndSpeed(unit.guid)
--ユニット生成位置が陸上の場合redoRandomPositionの位置からコードやり直し(500回まで)
elseif redoCounter < 500 then
redoCounter = redoCounter + 1
goto redoRandomPosition
else
print ('Unable to find a suitable position after 500 attempts.')
end
end
水上ユニット生成(方法2)
既存のミッションに参加させる簡単バージョン 漁船等はこちらを使って配置しているようだ
fishingVesselsテーブル
生成候補のユニットタイプリスト
local fishingVessels = {
{dbid = 20, prefix = "N/A", category = "Commercial"}, -- Civilian Dhow [15m] -- Civilian (Civilian)
{dbid = 357, prefix = "N/A", category = "Commercial"} -- Civilian Dhow [22m] -- Civilian (Civilian)
}
水上ユニット生成実行
- ランダムで48-96個のユニットを生成する
- fishingVesselsテーブルから一つ選択して生成ユニットのDBID決定
- RandomPosition()を使って生成位置を決定(陸上および水深25m以浅ならやり直し)
- ユニットを生成する
- ユニットをミッション"Fishing"に編入する
local numberOFCivFishingVessels = math.random(48, 96)
for i = 1, numberOFCivFishingVessels do
local randomType = fishingVessels[math.random(1, #fishingVessels)].dbid
local errorCount = 0
::redoPositionFishingVessels::
local position = RandomPosition(16, 19, 105, 110)
local elevation = World_GetElevation(position)
if elevation > -25 then
errorCount = errorCount + 1
if errorCount <= 500 then
goto redoPositionFishingVessels
else
BugMessage("Game_Setup", "Unable to place fishing vessel #" .. i .. " after 500 attempts!")
break
end
end
local unit =
ScenEdit_AddUnit(
{
side = "Civilian",
type = "Ship",
dbid = randomType,
name = "Fishing Vessel",
lat = position.latitude,
lon = position.longitude
}
)
ScenEdit_AssignUnitToMission(unit.guid, "Fishing")
end
水中ユニットの生成
水上ユニット生成(方法2)とやり方同じ
偽水中ユニット生成
False_DBIDsテーブル
偽水中ユニットのDBIDテーブル
local False_DBIDs = {
95, --Large
94, --Medium
93 --Small
}
別バージョン
local falseContactDBIDs = {
95, --Large
94, --Medium
93, --Small
653, --Magnetic
654, --Magnetic and acoustic
}
偽水中ユニット生成実行
local falseQty = math.random(24,32)
for i = 1,falseQty do
::redoPositionFalse::
local position = RandomPosition(49,50,-5,1)
local pos_elev = World_GetElevation(position)
if pos_elev > -10 or pos_elev < -500 then goto redoPositionFalse end
local randomType = math.random(1,3)
ScenEdit_AddUnit({side='Nature',type='Submarine',dbid=False_DBIDs[randomType],name='False Contact '..i,lat=position.latitude,lon=position.longitude})
end
別バージョン(やり直し回数を制限するためのカウンター付き)
local errorCount = 0
for i = 1,falseQty do
::redoPositionFalse::
local position = RandomPosition(-53,-49,-65,-55)
local elevation = World_GetElevation(position)
if elevation > -10 or elevation < -500 then
errorCount = errorCount + 1
if errorCount <= 500 then
goto redoPositionFalse
else
BugMessage('Game_Setup','Unable to place false contact #'..i..' after 500 attempts!')
break
end
end
local randomType = falseContactDBIDs[math.random(1,#falseContactDBIDs)]
ScenEdit_AddUnit({
side='Nature',
type='Submarine',
dbid=randomType, --dbid=falseContactDBIDs[randomType]のまちがい?
name='False Contact '..i,
lat=position.latitude,
lon=position.longitude
})
end
海洋生物ユニット生成
Biol_DBIDsテーブル
海洋生物ユニットのDBID
- CWDB
220 - fish
221 - orca(下の例で220が2つあるのは2/3の確率でfish,1/3の確率でwhaleを出せるようにするため)
92 - whale - DB3K
354 - fish
92 - whale
355 - orca
CWDB版
local Biol_DBIDs = {
220,
220,
92
}
DB3000版
--Randomly place biologicals; 60% fish, 20% Orca, 20% Whale
local biolDBIDs = {
354, --Fish
355, --Orcas
92 --Whale
}
海洋生物ユニット生成実行
local biolQty = math.random(24,32)
for i = 1,biolQty do
if i <= biolQty * 0.6 then
randomType = Biol_DBIDs[1]
elseif i <= biolQty * 0.8 then
randomType = Biol_DBIDs[2]
else
randomType = Biol_DBIDs[3]
end
::redoPositionBiologics::
local position = RandomPosition(49,50,-5,1)
local pos_elev = World_GetElevation(position)
if pos_elev > -25 then goto redoPositionBiologics end
local unit = ScenEdit_AddUnit({side='Nature',type='Submarine',dbid=randomType,name='Biol Contact '..i,lat=position.latitude,lon=position.longitude})
ScenEdit_AssignUnitToMission(unit.name, 'Wander')
end
各軍ユニットの位置ランダム移動
South China Crashから
ユニットのテーブル
local chinaUnitsToJitter = {
{name = "Shen Lian Cheng 781", guid = "d1d63bb4-49c0-48cd-ad03-ceeb9a3ea862", jitterRange = 20},
{name = "Zhong Shui 768", guid = "bd0d2bd1-1188-4682-937e-0305d247fa26", jitterRange = 20},
{name = "Lu Rong Yuan Yu 206", guid = "9bef247d-cedf-4153-8bbc-37a323be830e", jitterRange = 20},
{name = "Feng Hui 18", guid = "1c81dfc5-f7f5-49a5-a45a-d847acde7b34", jitterRange = 20},
{name = "Lu Rong Yuan Yu 168", guid = "8b4415f7-aa7d-436b-9577-9621fc7f8904", jitterRange = 20},
{name = "Hu Yu 912", guid = "65c614c2-fe85-4e6c-ab45-3aee49f9c3c5", jitterRange = 20},
{name = "Fu Yuan Yu 7088", guid = "2c92091d-0b01-458c-99bd-e6ba83597551", jitterRange = 20},
{name = "1002", guid = "cf1cdccd-42ed-4fc6-9926-dfa460f84082", jitterRange = 20},
{name = "330", guid = "db45d569-8744-443a-a231-3f73d442bbf1", jitterRange = 20},
{name = "Qinzhou", guid = "9b117eee-c8d4-42c0-a63e-766d45c8189a", jitterRange = 20}
}
local usUnitsToJitter = {
{name = "LCS 1 Freedom", guid = "520d37cd-0567-42c6-949c-5b9898e53ae6", jitterRange = 20},
{name = "LCS 3 Fort Worth", guid = "ff766d3d-9a49-4ae7-b0c7-ad383d874e12", jitterRange = 20},
{name = "DDG 97 Halsey", guid = "0142ae92-f854-4d6d-92c9-73f2272c9962", jitterRange = 20},
{name = "SSN 776 Hawaii", guid = "18cdf2f9-ea70-48fa-8d2d-9c82f6ebbff3", jitterRange = 20},
{name = "BRP Artemio Ricarte", guid = "d98f2eee-bdaa-4cc1-8926-bc5d0e28391f", jitterRange = 20},
{name = "BRP Emilio Jacinto", guid = "6d775420-25d9-4a61-8a06-c7b6c8d82a3b", jitterRange = 20}
}
JitterUnits(side)
CircularRandomPosition()関数と合わせてユニットをもとの位置からランダムに移動させる
function JitterUnits(side)
local sideJitterList
if side == 'PLAN' then
sideJitterList = chinaUnitsToJitter
else
sideJitterList = usUnitsToJitter
end
for k,v in ipairs (sideJitterList) do
local unit = ScenEdit_GetUnit({guid=v.guid})
local newPos = CircularRandomPosition(unit.latitude, unit.longitude, v.jitterRange)
if OverWater(newPos.latitude,newPos.longitude) then
ScenEdit_SetUnit({guid=unit.guid,latitude=newPos.latitude,longitude=newPos.longitude})
end
end
end
関数実行部
非プレイヤー陣営についてJitterUnits()関数を実行,inDevelopment=trueなら確認画面が出る.
local playerSide = ScenEdit_PlayerSide()
local computerSide
if playerSide == 'PLAN' then
computerSide = 'United States'
else
computerSide = 'PLAN'
end
if inDevelopment then
local userInput = string.upper(ScenEdit_MsgBox('Jitter units for '..computerSide..'?',1))
if userInput == 'OK' then JitterUnits(computerSide) end
else
JitterUnits(computerSide)
end