1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
| # coding: utf-8
###########################Fonction#############################################
def extraction (namefile):
"""Extraction of mission report files from IL2 Great Battles.
The mission report are store in dictionnary by Event Type"""
# Import modules
import re
# Open mission report file
try :
missionreport = open(namefile, "r")
print ("Report mission file will be loaded")
except:
print ("The mission report are not found ")
# Create list
liste_all_events = []
### Defined regex pattern by Atype
# "INITIAL" Event Type (AType:0)
# T:0 AType:0 GDate:1943.11.2 GTime:15:45:0
# MFile:Multiplayer/Kuban_4\Kuban_4_Welcome_to_crimea2.msnbin MID:
# GType:2 CNTRS:0:0,101:1,201:2
# SETTS:000000000010000100000000110 MODS:0 PRESET:0 AQMID:0 ROUNDS: 1 POINTS: 5000
atype_0 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>0) GDate:(?P<date>\d{4}.\d{1,2}.\d{1,2}) GTime:\d{1,2}:\d{1,2}:\d{1,2} MFile:(?P<file_path>.+) MID:\d* GType:(?P<game_type_id>\d+) CNTRS:(?P<countries>[,:\d]+) SETTS:(?P<settings>\d+) MODS:(?P<mods>\d) PRESET:(?P<preset_id>\d)")
# "HIT" Event Type (AType:1)
# T:130277 AType:1 AMMO:BULLET_GER_7-92x57_AP AID:781354 TID:1040430
atype_1 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>1) AMMO:(?P<ammo>[-\w]+) AID:(?P<attacker_id>\d+) TID:(?P<target_id>\d+)$")
# "DAMAGED" Event Type (AType:2)
# T:194164 AType:2 DMG:0.0040 AID:1202220 TID:1178645 POS(280906.0000,5691.9624,145361.6250)
atype_2 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>2) DMG:(?P<damage>\S{5,6}) AID:(?P<attacker_id>[-\d]+) TID:(?P<target_id>[-\d]+) POS\((?P<posx>-?\d+\.\d+)\, ?(?P<posy>-?\d+\.\d+)\, ?(?P<posz>\d+\.\d+)\)$")
# "KILL" Event Type (AType:3)
# T:203 AType:3 AID:-1 TID:220160 POS(225177.4063,12.3517,239741.1250)
atype_3 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>3) AID:(?P<attacker_id>[-\d]+) TID:(?P<target_id>[-\d]+) POS\((?P<posx>-?\d+\.\d+)\, ?(?P<posy>-?\d+\.\d+)\, ?(?P<posz>\d+\.\d+)\)$")
# "PLAYER END" Event Type (AType:4)
# T:149016 AType:4 PLID:781354 PID:782378 BUL:2098 SH:0 BOMB:0 RCT:0 (241224.7031,56.4326,112470.3594)
atype_4 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>4) PLID:(?P<aircraft_id>\d+) PID:(?P<bot_id>\d+) BUL:(?P<cartridges>\d+) SH:(?P<shells>\d+) BOMB:(?P<bombs>\d+) RCT:(?P<rockets>\d+) \((?P<posx>-?\d+\.\d+)\, ?(?P<posy>-?\d+\.\d+)\, ?(?P<posz>\d+\.\d+)\)$")
# "TAKE OFF" Event Type (AType:5)
# T:91410 AType:5 PID:780326 POS(258321.4219, 63.3613, 48782.1484)
atype_5 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>5) PID:(?P<aircraft_id>\d+) POS\((?P<posx>-?\d+\.\d+)\, ?(?P<posy>-?\d+\.\d+)\, ?(?P<posz>\d+\.\d+)\)$")
# "LAND" Event Type (AType:6)
# T:146520 AType:6 PID:781354 POS(241226.5000, 56.3776, 112472.2734)
atype_6 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>6) PID:(?P<aircraft_id>\d+) POS\((?P<posx>-?\d+\.\d+)\, ?(?P<posy>-?\d+\.\d+)\, ?(?P<posz>\d+\.\d+)\)$")
# "MISSION END" Event Type (AType:7)
# T:450003 AType:7
atype_7 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>7).?$")
# "MISSION OBJECTIVE" Event Type (AType:8)
# T:3745 AType:8 OBJID:102 POS(37286.734,0.000,18839.822) COAL:1 TYPE:0 RES:1 ICTYPE:0
atype_8 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>8) OBJID:(?P<object_id>\d+) POS\((?P<pos>.+)\) COAL:(?P<coal_id>\d) TYPE:(?P<task_type_id>\d+) RES:(?P<success>\d) ICTYPE:(?P<icon_type_id>[\-\d]+)$")
# "AIRFIELD" Event Type (AType:9)
# T:10 AType:9 AID:39936 COUNTRY:101 POS(184785.5938, 2.6443, 240943.4375) IDS()
atype_9 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>9) AID:(?P<airfield_id>\d+) COUNTRY:(?P<country_id>\d{1,3}) POS\((?P<posx>-?\d+\.\d+)\, ?(?P<posy>-?\d+\.\d+)\, ?(?P<posz>\d+\.\d+)\) IDS\((?P<aircraft_id_list>[,\-\d]*)\)$")
# "PLAYER PLANE" Event Type (AType:10)
# T:68510 AType:10 PLID:700446 PID:701470 BUL:6450 SH:0 BOMB:6 RCT:0
#(259973.9219,49.4752,54857.3555) IDS:34c54268-1f3f-4206-ad8f-5d3c0370bcc2
# LOGIN:828dfc6b-8f3d-466e-ad09-d4901ff60abe NAME:player_name TYPE:Bf 110 G-2 COUNTRY:201
# FORM:0 FIELD:573440 INAIR:2 PARENT:-1 ISPL:1 ISTSTART:1 PAYLOAD:2 FUEL:0.6500
# SKIN:bf110g2/bf110g2_skin_13.dds WM:3
atype_10 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>10) PLID:(?P<aircraft_id>\d+) PID:(?P<bot_id>\d+) BUL:(?P<cartridges>\d+) SH:(?P<shells>\d+) BOMB:(?P<bombs>\d+) RCT:(?P<rockets>\d+) \((?P<posx>-?\d+\.\d+)\, ?(?P<posy>-?\d+\.\d+)\, ?(?P<posz>\d+\.\d+)\) IDS:(?P<profile_id>[-\w]{36}) LOGIN:(?P<account_id>[-\w]{36}) NAME:(?P<name>.*) TYPE:(?P<aircraft_name>[\w\(\) .\-_/]+) COUNTRY:(?P<country_id>\d{1,3}) FORM:(?P<form>\d+) FIELD:(?P<airfield_id>\d+) INAIR:(?P<airstart>\d) PARENT:(?P<parent_id>[-\d]+) ISPL:(?P<is_player>\d+) ISTSTART:(?P<is_tracking_stat>\d+) PAYLOAD:(?P<payload_id>\d+) FUEL:(?P<fuel>\S{5,6}) SKIN:(?P<skin>[\S ]*) WM:(?P<weapon_mods_id>\d+)")
# "GROUP INIT" Event Type (AType:11)
# T:1 AType:11 GID:115711 IDS:17407,26623,35839 LID:17407
atype_11 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>11) GID:(?P<group_id>\d+) IDS:(?P<members_id>[,\d]*) LID:(?P<leader_id>\d+)$")
# "OBJECT SPAWN" Event Type (AType:12)
# T:203 AType:12 ID:220160 TYPE:dugout[32266,0] COUNTRY:201 NAME:Bunker PID:-1 POS(225177.4063,12.3517,239741.1250)
atype_12 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>12) ID:(?P<object_id>\d+) TYPE:(?P<object_name>[ .\'\-\w\(\)/]*)(\[-?\d+,-?\d+\])* COUNTRY:(?P<country_id>\d{1,3}) NAME:(?P<name>.*) PID:(?P<parent_id>[-\d]+) POS\((?P<posx>-?\d+\.\d+)\, ?(?P<posy>-?\d+\.\d+)\, ?(?P<posz>\d+\.\d+)\)$")
# "INFLUENCE AERA" Event Type (AType:13)
# T:0 AType:13 AID:39936 COUNTRY:501 ENABLED:1 BC(0,0,0,0,0,0,0,0)
atype_13 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>13) AID:(?P<area_id>\d+) COUNTRY:(?P<country_id>\d{1,3}) ENABLED:(?P<enabled>\d) BC\((?P<in_air>[,\d]+)\)$")
# "INFLUENCE BOUNDARY" Event Type (AType:14)
# T:1 AType:14 AID:39936 BP((26968.0,74.3,22949.0),(30848.0,74.3,23891.0),(35717.0,74.3,23876.0),(55007.0,74.3,15026.0),
# (55001.0,74.3,55020.0),(-5018.0,74.3,55042.0),(-4991.0,74.3,34620.0),(2552.0,74.3,34401.0),(8185.0,74.3,29341.0),
# (17968.0,74.3,26690.0),(21055.0,74.3,27434.0),(22561.0,74.3,24669.0),(25287.6,74.3,24965.3))
atype_14 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>14) AID:(?P<area_id>\d+) BP(?P<boundary>[-,\(\)\.\d]+)$")
# "LOG VERSION" Event Type (AType:15)
# T:0 AType:15 VER:17
atype_15 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>15) VER:(?P<version>\d+)$")
# "BOT UNINIT" Event Type (AType:16)
# T:450029 AType:16 BOTID:2344974 POS(270953.3750,65.3429,149223.5313)
atype_16 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>16) BOTID:(?P<bot_id>\d+) POS\((?P<posx>-?\d+\.\d+)\, ?(?P<posy>-?\d+\.\d+)\, ?(?P<posz>\d+\.\d+)\)$")
# "POSITION CHANGED" Event Type (AType:17)
# T:58 AType:17 ID:107519 POS(39013.016,45.535,16807.107)
atype_17 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>17) ID:(?P<object_id>\d+) POS\((?P<posx>-?\d+\.\d+)\, ?(?P<posy>-?\d+\.\d+)\, ?(?P<posz>\d+\.\d+)\)$")
# "BOT LEAVE" Event Type (Eject ??) (AType:18)
# T:168858 AType:18 BOTID:1204267 PARENTID:1203243 POS(277889.3750,6450.9058,129604.6172)
atype_18 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>18) BOTID:(?P<bot_id>\d+) PARENTID:(?P<parent_id>[-\d]+) POS\((?P<posx>-?\d+\.\d+)\, ?(?P<posy>-?\d+\.\d+)\, ?(?P<posz>\d+\.\d+)\)$")
# "END OF THE TOUR" Event Type (AType:19)
# T:706771 AType:19
atype_19 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>19)$")
# "JOIN PLAYER" Event Type (AType:20)
# T:0 AType:20 USERID:52c04d8d-4616-4840-8648-dd9e9da4570a USERNICKID:de8bec6d-a6a0-42dd-945d-3804689a1dd5
atype_20 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>20) USERID:(?P<account_id>[-\w]{36}) USERNICKID:(?P<profile_id>[-\w]{36})$")
# "EXIT PLAYER" Event Type (AType:21)
# T:18573 AType:21 USERID:d5bc9e4c-055c-46c2-8ace-8a7daa9eed4a USERNICKID:e608236e-332a-4843-8421-8e013c59685f
atype_21 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>21) USERID:(?P<account_id>[-\w]{36}) USERNICKID:(?P<profile_id>[-\w]{36})$")
# "TANK EVENT (??)" Event Type (AType:22)
# T:36160 AType:22 PID:1684580 POS(223718.406, 10.337, 242309.250)
atype_22 = re.compile(r"^T:(?P<tik>\d+) AType:(?P<atype_id>22) PID:(?P<parent_id>[-\d]+) POS\((?P<posx>-?\d+\.\d+)\, ?(?P<posy>-?\d+\.\d+)\, ?(?P<posz>\d+\.\d+)\)$")
### Regex pattern list
RegexByAtype = [atype_0, atype_1, atype_2, atype_3, atype_4, atype_5, atype_6, atype_7,
atype_8, atype_9, atype_10, atype_11, atype_12, atype_13, atype_14,
atype_15, atype_16, atype_17, atype_18, atype_19, atype_20, atype_21,
atype_22]
# Detect Atype format
atype_regex = re.compile('AType:(\d+)')
#counter flag error line
counter_flag = 0
# Read mission report file line after line
while 1:
line = missionreport.readline()
counter_flag = counter_flag+1
if line != "":
atype_id = int(atype_regex.search(line).group(1))
if atype_id != None:
regex_pattern = RegexByAtype[atype_id] ### use pattern defined on RegexByAtype
event = regex_pattern.match(line) ### match line
if event != None :
dico_event = event.groupdict() ### create dico from regex group keys
liste_all_events.append(dico_event) ### append dico to the list
else :
print ("Error in match on line ", counter_flag)
print(line)
elif atype_id < 0 or atype_id >22:
print ("Some AType are unclassified on this programm on line ", counter_flag)
print(line)
continue
elif atype_id == None:
print ("atype_id are \"None\" on line ", counter_flag)
print(line)
break
# End of collect mission report
if line == "":
print ("End of mission report file. Please check error above")
break
return liste_all_events |