Skip to content

Commit 2237415

Browse files
committed
CHANGES:
- Added carriers and farps to airbase commands
1 parent cb58ee0 commit 2237415

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

core/utils/discord.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,9 +1073,11 @@ async def airbase_autocomplete(interaction: discord.Interaction, current: str) -
10731073
if not server or not server.current_mission:
10741074
return []
10751075
choices: list[app_commands.Choice[int]] = [
1076-
app_commands.Choice(name=x['name'], value=idx)
1076+
app_commands.Choice(name="{}".format(x['name'] if x.get('type', '') != 'FARP' else f"FARP {x['name']}"),
1077+
value=idx)
10771078
for idx, x in enumerate(server.current_mission.airbases)
1078-
if not current or current.casefold() in x['name'].casefold() or current.casefold() in x['code'].casefold()
1079+
if not current or current.casefold() in x['name'].casefold() or
1080+
current.casefold() in x.get('code', x.get('type')).casefold()
10791081
]
10801082
return choices[:25]
10811083
except Exception as ex:

plugins/mission/airbase.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,10 @@ def count_types_in_line(s: str) -> int:
221221
)
222222

223223
async def render(self, airbase: dict, data: dict):
224-
self.add_field(name=_('Code'), value=airbase['code'])
224+
if 'code' in airbase:
225+
self.add_field(name=_('Code'), value=airbase['code'])
226+
else:
227+
self.add_field(name=_('Type'), value=airbase['type'])
225228
self.add_field(name=_('Coalition'), value=Side(data['coalition']).name.title())
226229
self.add_field(name='_ _', value='_ _')
227230
self.add_field(name=_('Dynamic Spawns'),

plugins/mission/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2539,7 +2539,7 @@ async def handle_warehouse_uploads(self, message: discord.Message):
25392539
airports = data.get('coalitions', {}).get(coalition, {}).get('airbases')
25402540
else:
25412541
icao = match.group(1).upper()
2542-
airport = next((x for x in server.current_mission.airbases if x['code'] == icao), None)
2542+
airport = next((x for x in server.current_mission.airbases if x.get('code', x.get('type')) == icao), None)
25432543
if not airport:
25442544
await message.channel.send(_("Airport with ICAO {} not found.").format(icao))
25452545
return

plugins/mission/listener.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ async def unpause(self, server: Server, player: Player, params: list[str]):
10021002
async def send_atis(self, server: Server, player: Player, name: str) -> bool:
10031003
airbase = next((
10041004
x for x in server.current_mission.airbases
1005-
if (name.casefold() in x['name'].casefold()) or (name.upper() == x['code'])), None)
1005+
if (name.casefold() in x['name'].casefold()) or (name.upper() == x.get('code', x.get('type')))), None)
10061006

10071007
if not airbase:
10081008
airbase = await server.send_to_dcs_sync({

plugins/mission/lua/commands.lua

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ function dcsbot.getAirbases(json)
164164
local airdromes = Terrain.GetTerrainConfig("Airdromes")
165165
if (airdromes == nil) then
166166
utils.sendBotTable(msg, json.channel)
167+
return
167168
end
168169
for airdromeID, airdrome in pairs(airdromes) do
169170
if (airdrome.reference_point) and (airdrome.abandoned ~= true) then
@@ -211,6 +212,41 @@ function dcsbot.getAirbases(json)
211212
airbase.dynamic = DCS.getDynamicSpawnSettings(airdromeID, true)
212213
table.insert(msg.airbases, airbase)
213214
end
215+
end
216+
local farpsAndCarriers = DCS.getFarpsAndCarriersMissionData()
217+
for carrierID, carrier in pairs(farpsAndCarriers.carriers) do
218+
local airbase = {}
219+
airbase.name = carrier.name
220+
airbase.type = carrier.type
221+
airbase.coalition = carrier.coalition
222+
airbase.lat, airbase.lng = Terrain.convertMetersToLatLon(carrier.x, carrier.y)
223+
airbase.alt = Terrain.GetHeight(carrier.x, carrier.y)
224+
airbase.position = {}
225+
airbase.position.x = carrier.x
226+
airbase.position.y = airbase.alt
227+
airbase.position.z = carrier.y
228+
airbase.dynamic = DCS.getDynamicSpawnSettings(carrierID, true) or {
229+
dynamicSpawnAvailable = false,
230+
allowHotSpawn = false
231+
}
232+
table.insert(msg.airbases, airbase)
233+
end
234+
for farpID, farp in pairs(farpsAndCarriers.farps) do
235+
local airbase = {}
236+
airbase.name = farp.name
237+
airbase.type = farp.type
238+
airbase.coalition = farp.coalition
239+
airbase.lat, airbase.lng = Terrain.convertMetersToLatLon(farp.x, farp.y)
240+
airbase.alt = Terrain.GetHeight(farp.x, farp.y)
241+
airbase.position = {}
242+
airbase.position.x = farp.x
243+
airbase.position.y = airbase.alt
244+
airbase.position.z = farp.y
245+
airbase.dynamic = DCS.getDynamicSpawnSettings(farpID, true) or {
246+
dynamicSpawnAvailable = false,
247+
allowHotSpawn = false
248+
}
249+
table.insert(msg.airbases, airbase)
214250
end
215251
utils.sendBotTable(msg, json.channel)
216252
end

0 commit comments

Comments
 (0)