Skip to main content

Python package used to access air vehicle telemetry while in War Thunder air battles

Project description

GitHub version PyPI version

Overview

Python package to access vehicle telemetry and match data in real-time while in War Thunder air battles (NOT tanks). Here are some things you can access/do with this package:

  • Get telemetry information on your vehicle and others identified on user's mini map
    • Data available for both user and other match player's vehicles:
      • Location in latitude/longitude (DD)
      • Heading angle
      • Airspeed
    • Data avilable only for user's vehicle:
      • Pitch angle
      • Roll angle
      • Flap state
      • Gear state
      • Altitude
  • Data on other objects identified on user's mini map
    • Object's location in latitude/longitude (DD)
      • Airfields have 2 locations, one for each end of the runway
    • Object's faction (friendly or enemy)
    • Object's type (fighter, bomber, heavy tank, etc)
  • Map name
  • Chat comments (anything typed into chat)
  • Match events (death, crash, etc)
  • Log data in an ACMI format compatible with Tacview

This library makes use of War Thunder's localhost server pages (http://localhost:8111/indicators, http://localhost:8111/state, http://localhost:8111/map.img, http://localhost:8111/map_obj.json, and http://localhost:8111/map_info.json, and more!) that the game automatically serves when you launch a game match. If it is an air battle, these pages will include JSON formatted data with valid airplane telemetry. This telemetry is then converted and returned to the calling function/user.

The data can then be easily used for any custom application (i.e. telemetry datalogger and grapher).

Example Use-Case:

https://github.com/PowerBroker2/Thunder_Viewer

To Install

pip install WarThunder

Example Python Script

from WarThunder import telemetry
from WarThunder import mapinfo
from pprint import pprint


def find_map_info():
    print('------------------------------------------------------')
    print('Map Info:')
    print('\tName:\t\t\t\t\t{}'.format(telem.map_info.grid_info['name']))
    print('\tUpper Left Hand Corner Coordinate:\t[{}, {}]'.format(telem.map_info.grid_info['ULHC_lat'], telem.map_info.grid_info['ULHC_lon']))
    print('\tSize:\t\t\t\t\t{}km x {}km'.format(telem.map_info.grid_info['size_km'], telem.map_info.grid_info['size_km']))
    print('')

def find_all_bomb_points():
    print('------------------------------------------------------')
    find_bomb_points(True)
    find_bomb_points(False)

def find_all_airfields():
    print('------------------------------------------------------')
    find_airfields(True)
    find_airfields(False)

def find_all_planes():
    print('------------------------------------------------------')
    find_planes(True)
    find_planes(False)

def find_all_tanks():
    print('------------------------------------------------------')
    find_tanks(True)
    find_tanks(False)

def find_all_AAAs():
    print('------------------------------------------------------')
    find_AAAs(True)
    find_AAAs(False)
    
def find_basic_telemetry():
    print('------------------------------------------------------')
    print('Basic Telemetry:')
    pprint(telem.basic_telemetry)
    print('')
    
def find_comments():
    print('------------------------------------------------------')
    print('Comments:')
    comments = telem.get_comments()
    
    if comments:
        pprint(comments)
    else:
        print('\tNone')
    print('')
    
def find_events():
    print('------------------------------------------------------')
    print('Events:')
    events = telem.get_events()
    
    if events:
        pprint(events)
    else:
        print('\tNone')
    print('')

def find_bomb_points(friendly=True):
    if friendly:
        print('Friendly Bomb Points:')
        bomb_points = [obj for obj in telem.map_info.defend_points() if obj.friendly]
    else:
        print('Enemy Bomb Points:')
        bomb_points = [obj for obj in telem.map_info.bombing_points() if not obj.friendly]
    
    if bomb_points:
        for bomb_point in bomb_points:
            print('\tBombing Point: {}'.format(bomb_point.position_ll))
    else:
        print('\tNone')
    print(' ')

def find_airfields(friendly=True):
    if friendly:
        print('Friendly Airfields:')
        airfields = [obj for obj in telem.map_info.airfields() if obj.friendly]
    else:
        print('Enemy Airfields:')
        airfields = [obj for obj in telem.map_info.airfields() if not obj.friendly]
    
    if airfields:
        for airfield in airfields:
            print('\tEast Coordinate:\t{}'.format(airfield.east_end_ll))
            print('\tSouth Coordinate:\t{}'.format(airfield.south_end_ll))
            print('\tRunway Heading:\t\t{} °'.format(airfield.runway_dir))
            print('\tRunway Length:\t\t{} km'.format(mapinfo.coord_dist(*airfield.east_end_ll, *airfield.south_end_ll)))
            print('')
    else:
        print('\tNone')
    print('')

def find_planes(friendly=True):
    if friendly:
        print('Friendly Planes:')
        planes = [obj for obj in telem.map_info.planes() if obj.friendly]
    else:
        print('Enemy Planes:')
        planes = [obj for obj in telem.map_info.planes() if not obj.friendly]
    
    if planes:
        for plane in planes:
            print('\tPosition:\t{}'.format(plane.position_ll))
            print('\tHeading:\t{}'.format(plane.hdg))
            print('')
    else:
        print('\tNone')
    print('')
    

def find_tanks(friendly=True):
    if friendly:
        print('Friendly Tanks:')
        tanks = [obj for obj in telem.map_info.tanks() if obj.friendly]
    else:
        print('Enemy Tanks:')
        tanks = [obj for obj in telem.map_info.tanks() if not obj.friendly]
    
    if tanks:
        for tank in tanks:
            print('\tPosition:\t{}'.format(tank.position_ll))
            print('\tHeading:\t{}'.format(tank.hdg))
            print('')
    else:
        print('\tNone')
    print('')

def find_AAAs(friendly=True):
    if friendly:
        print('Friendly AAAs:')
        AAAs = [obj for obj in telem.map_info.AAAs() if obj.friendly]
    else:
        print('Enemy AAAs:')
        AAAs = [obj for obj in telem.map_info.AAAs() if not obj.friendly]
    
    if AAAs:
        for AAA in AAAs:
            print('\tPosition:\t{}'.format(AAA.position_ll))
    else:
        print('\tNone')
    print('')


if __name__ == '__main__':
    try:
        telem = telemetry.TelemInterface()
        
        while not telem.get_telemetry():
            pass
        
        find_map_info()
        find_all_airfields()
        find_all_planes()
        find_all_tanks()
        find_all_bomb_points()
        find_all_AAAs()
        find_basic_telemetry()
        find_comments()
        find_events()
        
    except KeyboardInterrupt:
        print('Closing')

Example Output:

------------------------------------------------------
Map Info:
        Name:                                   Ruhr
        Upper Left Hand Corner Coordinate:      [51.73829303094487, 6.437537416826182]
        Size:                                   65km x 65km

------------------------------------------------------
Friendly Airfields:
        East Coordinate:        [51.43642186048186, 6.930164507472621]
        South Coordinate:       [51.42827500146132, 6.9187980201946795]
        Runway Heading:         41.012963528358455 °
        Runway Length:          1.2019773371283782 km


Enemy Airfields:
        None

------------------------------------------------------
Friendly Planes:
        Position:       [51.44442707177771, 6.9048435542278]
        Heading:        191.7501316630443

        Position:       [51.444117867741056, 6.904189278772745]
        Heading:        191.7327479963323

        Position:       [51.44454697658904, 6.904059699788993]
        Heading:        191.73257970022075

        Position:       [51.44424583467913, 6.903432678896212]
        Heading:        191.73146722121177


Enemy Planes:
        None

------------------------------------------------------
Friendly Tanks:
        None

Enemy Tanks:
        Position:       [51.448172861547235, 6.883101199222394]
        Heading:        0


------------------------------------------------------
Friendly Bomb Points:
        None
 
Enemy Bomb Points:
        None
 
------------------------------------------------------
Friendly AAAs:
        Position:       [51.43844836391245, 6.925201117152168]
        Position:       [51.43829338882834, 6.9249774559908275]
        Position:       [51.438609103385076, 6.925442639430436]
        Position:       [51.4276199323936, 6.924573106340005]
        Position:       [51.42778836500274, 6.924790301773768]
        Position:       [51.427463714376124, 6.924367280891929]
        Position:       [51.438792600079246, 6.9392408728402595]

Enemy AAAs:
        None

------------------------------------------------------
Basic Telemetry:
{'IAS': 0,
 'airframe': 'bf_110g_4',
 'altitude': 59.221455,
 'flapState': 0,
 'gearState': 100,
 'heading': 40.639851,
 'lat': 51.428588129131136,
 'lon': 6.919188108689251,
 'pitch': 10.894329,
 'roll': 0.010828}

------------------------------------------------------
Comments:
        None

------------------------------------------------------
Events:
{'events': [], 'damage': [{'id': 1, 'msg': 'yn1/error/82220002', 'sender': '', 'enemy': False, 'mode': ''}]}
{'damage': [{'enemy': False,
             'id': 1,
             'mode': '',
             'msg': 'yn1/error/82220002',
             'sender': ''}],
 'events': []}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

WarThunder-2.3.4.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

WarThunder-2.3.4-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file WarThunder-2.3.4.tar.gz.

File metadata

  • Download URL: WarThunder-2.3.4.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for WarThunder-2.3.4.tar.gz
Algorithm Hash digest
SHA256 4424ce6047d9b682dde5fceff808db8e71b3d460f0a8aa1c7ef4c45e8b84eb88
MD5 de4e0d173aeef0efd097c95e1e30ccd2
BLAKE2b-256 3b5af9c9d2eb251342462f489efa8a7b7cc00c7d6a40ca344adc04fb7f365afc

See more details on using hashes here.

File details

Details for the file WarThunder-2.3.4-py3-none-any.whl.

File metadata

  • Download URL: WarThunder-2.3.4-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for WarThunder-2.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 76eb1237629f77b1f5c1a5e0a205f257887ca037854033df3a7a01ab1e841c90
MD5 d86caf9fbce3f9c3c443b53129274b48
BLAKE2b-256 3c90a0f1c53ad021beee7c3f3446c166c43ded77d7d07994e2a8d3082409591c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page