forked from devilesk/dota-map-coordinates
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocess_mapdata.py
More file actions
201 lines (185 loc) · 7.54 KB
/
process_mapdata.py
File metadata and controls
201 lines (185 loc) · 7.54 KB
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import json
import matplotlib.path as mplPath
import numpy as np
true_sight = {
'npc_dota_fort': 900,
'npc_dota_tower': 700,
'ent_dota_fountain': 1200
}
with open('data/mapdata.json', 'r') as f:
neutrals = []
landmark_auras = []
data = json.loads(f.read())['data']
if (data.get('trigger_multiple')):
for k in data['trigger_multiple']:
if ('neutralcamp' in k['name']):
neutrals.append(k)
else:
landmark_auras.append(k)
data['trigger_multiple'] = neutrals
data['landmark_aura'] = landmark_auras
## print k['name']
neutral_data = {}
with open('data/dota_pvp_prefab.vmap.txt', 'r') as f:
dump_on_next_brace = False
for line in f.readlines():
if 'VolumeName' in line:
VolumeName = line.strip('\n').split(" ")[-1].replace('"', '')
if 'PullType' in line:
PullType = line.strip('\n').split(" ")[-1].replace('"', '')
if 'NeutralType' in line:
NeutralType = line.strip('\n').split(" ")[-1].replace('"', '')
if 'npc_dota_neutral_spawner' in line:
dump_on_next_brace = True
if '}' in line and dump_on_next_brace:
dump_on_next_brace = False
neutral_data[VolumeName] = {
'PullType': PullType,
'NeutralType': NeutralType
}
landmarks = []
with open('data/dota_custom_default_000.vmap.txt', 'r') as f:
dump_on_next_brace = False
ent_type_found = False
for line in f.readlines():
if '"CMapEntity"' in line:
origin = [0,0]
if '"origin"' in line:
origin = [x.replace('"', '') for x in line.strip('\n').split(" ")[-3:]]
if '"model"' in line:
ent_type_found = True
if 'dark_statue_base' in line:
classname = 'statue'
elif 'old_well' in line:
classname = 'well'
elif 'cathedral' in line:
classname = 'mines'
elif 'ancient_giant_skeleton' in line:
classname = 'graveyard'
else:
ent_type_found = False
if ent_type_found and origin[0] and origin[1]:
dump_on_next_brace = True
if '}' in line and dump_on_next_brace:
dump_on_next_brace = False
landmarks.append({
'x': round(float(origin[0]), 2),
'y': round(float(origin[1]), 2),
'name': classname
})
origin = [0,0]
ent_type_found = False
data['landmarks'] = landmarks
with open('data/dota_pvp_prefab.vmap.txt', 'r') as f:
dump_on_next_brace = False
ent_type_found = False
class_infoplayer = False
ent_found_type = ''
# overriding miniboss spawner to avoid conflicts with prefab locations
data['npc_dota_miniboss_spawner'] = []
for line in f.readlines():
if 'CMapEntity' in line:
ent_type_found = False
class_infoplayer = False
origin = [0,0]
if 'info_player_start_dota' in line:
class_infoplayer = True
if 'roshan_location_2' in line and class_infoplayer:
ent_type_found = True
ent_found_type = 'npc_dota_roshan_spawner'
if 'miniboss_location' in line and class_infoplayer:
ent_type_found = True
ent_found_type = 'npc_dota_miniboss_spawner'
if '"origin"' in line:
origin = [x.replace('"', '') for x in line.strip('\n').split(" ")[-3:]]
if ent_type_found and origin[0] and origin[1]:
dump_on_next_brace = True
if '}' in line and dump_on_next_brace and ent_found_type:
data[ent_found_type].append({
'x': round(float(origin[0]), 2),
'y': round(float(origin[1]), 2),
'bounds': [
round(float(origin[0]), 2),
round(float(origin[1]), 2),
],
'team': 0
})
dump_on_next_brace = False
class_infoplayer = False
ent_type_found = False
ent_found_type = ''
for pt in data['npc_dota_neutral_spawner']:
point = [pt['x'], pt['y']]
if (data.get('trigger_multiple')):
for trigger in data['trigger_multiple']:
if ('neutralcamp' not in trigger['name']):
continue
points = []
for i in range(1, 5):
points.append([trigger[str(i)]['x'], trigger[str(i)]['y']])
bbPath = mplPath.Path(np.array(points))
if bbPath.contains_point(point):
pt['triggerName'] = trigger['name']
pt['pullType'] = neutral_data[trigger['name']]['PullType']
pt['neutralType'] = neutral_data[trigger['name']]['NeutralType']
break
meta = {}
coorddata = {}
for key in data:
print (key)
if key == 'trigger_multiple' or key == 'landmark_aura':
coorddata[key] = []
for obj in data[key]:
entity = {
'points': [],
'name': obj['name']
}
for i in range(1, 5):
entity['points'].append(obj[str(i)])
coorddata[key].append(entity)
elif key == 'landmarks':
coorddata[key] = data[key]
continue
else:
coorddata[key] = []
for obj in data[key]:
new_obj = {}
coords = {}
if type(obj) is str:
continue
for k in obj:
if k == 'team' or k == 'name' or k == 'z':
continue
elif k != 'x' and k != 'y' and k != 'pullType' and k != 'neutralType' and k != 'triggerName':
if obj[k] == 0:
continue
elif k == 'bat':
obj[k] = round(obj[k], 2)
new_obj[k] = obj[k]
else:
coords[k] = obj[k]
# if key == 'ent_dota_tree':
# # workaround for 7.33, whatever problem it had
# coords['x'] -= 32
# coords['y'] -= 32
if 'spawner' in key:
new_obj = {
'bounds': [ 0, 0 ]
}
if key == 'npc_dota_tower' or key == 'npc_dota_barracks':
subkey = obj['name'].split('_')[2]
coords['subType'] = subkey
meta[key + '_' + subkey] = new_obj
if key == 'npc_dota_tower':
meta[key + '_' + subkey]['trueSight'] = true_sight[key]
else:
meta[key] = new_obj
if key == 'npc_dota_fort' or key == 'ent_dota_fountain':
meta[key]['trueSight'] = true_sight[key]
coorddata[key].append(coords)
result = {
'data': coorddata,
'stats': meta
}
with open('mapdata.json', 'w') as g:
g.write(json.dumps(result))