Skip to content

Commit

Permalink
Merge pull request #69 from thot-experiment/master
Browse files Browse the repository at this point in the history
extract precise locations from replay parse
  • Loading branch information
howardchung authored May 20, 2024
2 parents ae7e7de + a35c1f0 commit fe1aa91
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
16 changes: 15 additions & 1 deletion processors/processExpand.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ function processExpand(entries, meta) {
* Place a copy of the entry in the output
* */
function expand(e) {
//if there are cooridnates, round to one decimal point
if (e.x) { e.x=parseFloat(e.x.toFixed(1)) }
if (e.y) { e.y=parseFloat(e.y.toFixed(1)) }
if (e.z) { e.z=parseFloat(e.z.toFixed(1)) }
//generate "key" for entries with x/y and no key
if (!e.key && e.x && e.y) {
e.key = JSON.stringify([
Math.round(e.x),
Math.round(e.y)
])
}
// set slot and player_slot
const slot = 'slot' in e ? e.slot : meta.hero_to_slot[e.unit];
output.push({ ...e, slot, player_slot: meta.slot_to_playerslot[slot] });
Expand Down Expand Up @@ -588,7 +599,10 @@ function processExpand(entries, meta) {
time: e.time,
slot: e.slot,
type: 'lane_pos',
key: JSON.stringify([e.x, e.y]),
key: JSON.stringify([
Math.round(e.x),
Math.round(e.y)
]),
posData: true,
});
}
Expand Down
43 changes: 30 additions & 13 deletions src/main/java/opendota/Parse.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public class Entry {
public Integer gold;
public Integer lh;
public Integer xp;
public Integer x;
public Integer y;
public Integer z;
public Float x;
public Float y;
public Float z;
public Float stuns;
public Integer hero_id;
public transient List<Item> hero_inventory;
Expand Down Expand Up @@ -128,6 +128,10 @@ public Entry(Integer time) {
}
}

private Float getPreciseLocation (Integer cell, Float vec) {
return (cell*128.0f+vec)/128;
}

private class Item {
String id;
// Charges can be used to determine how many items are stacked together on
Expand Down Expand Up @@ -724,8 +728,15 @@ public void onTickStart(Context ctx, boolean synthetic) {
// get the hero's coordinates
if (e != null) {
// System.err.println(e);
entry.x = getEntityProperty(e, "CBodyComponent.m_cellX", null);
entry.y = getEntityProperty(e, "CBodyComponent.m_cellY", null);
//CBodyComponent.m_cell[XY] * 128 + CBodyComponent.m_vec[XY]
Integer cx = getEntityProperty(e, "CBodyComponent.m_cellX", null);
Integer cy = getEntityProperty(e, "CBodyComponent.m_cellY", null);

Float vx = getEntityProperty(e, "CBodyComponent.m_vecX", null);
Float vy = getEntityProperty(e, "CBodyComponent.m_vecY", null);

entry.x = getPreciseLocation(cx,vx);
entry.y = getPreciseLocation(cy,vy);
// System.err.format("%s, %s\n", entry.x, entry.y);
// get the hero's entity name, ex: CDOTA_Hero_Zuus
entry.unit = e.getDtClass().getDtName();
Expand Down Expand Up @@ -955,17 +966,23 @@ public void onWardExistenceChanged(Context ctx, Entity e) {
private Entry buildWardEntry(Context ctx, Entity e) {
Entry entry = new Entry(time);
boolean isObserver = !e.getDtClass().getDtName().contains("TrueSight");
Integer x = getEntityProperty(e, "CBodyComponent.m_cellX", null);
Integer y = getEntityProperty(e, "CBodyComponent.m_cellY", null);
Integer z = getEntityProperty(e, "CBodyComponent.m_cellZ", null);

Integer cx = getEntityProperty(e, "CBodyComponent.m_cellX", null);
Integer cy = getEntityProperty(e, "CBodyComponent.m_cellY", null);
Integer cz = getEntityProperty(e, "CBodyComponent.m_cellZ", null);

Float vx = getEntityProperty(e, "CBodyComponent.m_vecX", null);
Float vy = getEntityProperty(e, "CBodyComponent.m_vecY", null);
Float vz = getEntityProperty(e, "CBodyComponent.m_vecZ", null);

Integer life_state = getEntityProperty(e, "m_lifeState", null);
Integer[] pos = { x, y };
entry.x = x;
entry.y = y;
entry.z = z;

entry.x = getPreciseLocation(cx,vx);
entry.y = getPreciseLocation(cy,vy);
entry.z = getPreciseLocation(cz,vz);

entry.type = isObserver ? "obs" : "sen";
entry.entityleft = life_state == 1;
entry.key = Arrays.toString(pos);
entry.ehandle = e.getHandle();

if (entry.entityleft) {
Expand Down

0 comments on commit fe1aa91

Please sign in to comment.