Page 1 of 2 1 2 LastLast
Results 1 to 10 of 18

Thread: This is how to interpret the barracks_status and tower_status results from the API

  1. #1

    This is how to interpret the barracks_status and tower_status results from the API

    tower_status_dire
    tower_status_radiant
    barracks_status_dire
    barracks_status_radiant

    These fields in the GetMatchDetails request contain an 11 bit or 6 bit integer that when represented in binary represents whether a building is dead or alive.
    1 = alive. 0 = dead.
    There are 11 towers, so there are 11 bits for the tower_status fields.


    For example, if barracks_status_dire is 1336, first we represent 1336 in binary, which is 10100111000.

    Now we take each individual 1 and 0, from left to right, and process them in the following order.

    Code:
    1	ANCIENT TOP
    2	ANCIENT BOTTOM
    3	TOP 3
    4	TOP 2
    5	TOP 1
    6	MIDDLE 3
    7	MIDDLE 2
    8	MIDDLE 1
    9	BOTTOM 3
    10	BOTTOM 2
    11	BOTTOM 1
    Credit to the interpret order goes to MuppetMaster42

    Let's use it on the 11 bit integer 1336, which is the binary value 10100111000

    Code:
    1	ANCIENT TOP	1	Alive
    2	ANCIENT BOTTOM	0
    3	TOP 3		1	Alive
    4	TOP 2		0
    5	TOP 1		0
    6	MIDDLE 3	1	Alive
    7	MIDDLE 2	1	Alive
    8	MIDDLE 1	1	Alive
    9	BOTTOM 3	0
    10	BOTTOM 2	0
    11	BOTTOM 1	0

    The TOP and BOTTOM positions are always the same, for Dire and Radiant.

    The barracks_status values are the same except there are only 6 barracks, so the bits are

    Code:
    1	TOP RANGED
    2	TOP MELEE
    3	MID RANGED
    4	MID MELEE
    5	BOT RANGED
    6	BOT MELEE
    Good luck!
    Last edited by walkingcarpet; 10-05-2012 at 10:23 AM. Reason: Fixed formatting, thanks Shinkai

  2. #2
    Basic Member Ruirize's Avatar
    Join Date
    May 2012
    Location
    Surrey, England
    Posts
    32
    Below is a C# implementation of these bit flags. Simply copy and paste these two enumerated value lists.

    Code:
    public enum DotATowerStatus
    {
        Tier1Bottom = 1,
        Tier2Bottom = 2,
        Tier3Bottom = 4,
        Tier1Middle = 8,
        Tier2Middle = 16,
        Tier3Middle = 32,
        Tier1Top= 64,
        Tier2Top = 128,
        Tier3Top = 256,
        AncientBottom = 512,
        AncientTop = 1024
    }
    public enum DotABarracksStatus
    {
        MeleeBottom = 1,
        RangedBottom = 2,
        MeleeMiddle = 4,
        RangedMiddle = 8,
        MeleeTop = 16,
        RangedTop = 32
    }
    If you want to see if a tower is alive, then you can do this:
    Code:
    DotATowerStatus CurrentTowerStatus = (DotATowerStatus)1336;
    if ((CurrentTowerStatus & DotATowerStatus.Tier1Middle) == DotATowerStatus.Tier1Middle)
    {
        // The tier 1 tower is still alive!
    }
    Last edited by Ruirize; 10-04-2012 at 12:23 PM.

  3. #3
    Anyone know how to fix the formatting in my examples, other than trying to manually space it? When I am in the editor it appears properly spaced.

  4. #4
    Basic Member Shinkai's Avatar
    Join Date
    May 2012
    Posts
    186
    Code:
    1	ANCIENT TOP
    2	ANCIENT BOTTOM
    3	TOP 3
    4	TOP 2
    5	TOP 1
    6	MIDDLE 3
    7	MIDDLE 2
    8	MIDDLE 1
    9	BOTTOM 3
    10	BOTTOM 2
    11	BOTTOM 1
    Code:
    1	ANCIENT TOP	1	Alive
    2	ANCIENT BOTTOM	0     
    3	TOP 3		1	Alive
    4	TOP 2		0
    5	TOP 1		0
    6	MIDDLE 3	1	Alive
    7	MIDDLE 2	1	Alive
    8	MIDDLE 1	1	Alive
    9	BOTTOM 3	0
    10	BOTTOM 2	0
    11	BOTTOM 1	0
    Code:
    1	TOP RANGED
    2	TOP MELEE
    3	MID RANGED
    4	MID MELEE
    5	BOT RANGED
    6	BOT MELEE
    Use " " which is tab character instead of whitespace. Copy the fixed codes from my post. More info here. Hitting tab in this editor won't give you the desired result, though. Work-around would be just either copying the tab character from notepad or from other posts or just write code section completely in another text editor.
    Last edited by Shinkai; 10-04-2012 at 09:37 AM.

  5. #5
    Yeah... for some reason the <table> tags are disabled on the advanced editor... no idea why. They would solve this scenario completely.

  6. #6
    Basic Member
    Join Date
    Oct 2011
    Posts
    72
    Has anyone written any code that turns the tower_status fields into a visual representation and wants to share it? I wrote some PHP code that turns the tower_status from the getLiveLeagueGames into a tower score. It's nothing fancy and outputs the score as "(Radiant Towers remaining) -- (Dire Towers Remaining)". The code assumes that the tower_status numbers are in the third position of an array called $bqArray that is of a variable size ($maxSize).

    Code:
     for( $i = 0; $i < $tower_statusSize; $i++ ){
                     $towerBin = decbin($tower_status[$i]);
                     $direBin = substr($towerBin, 1, 11);
                     $radBin = substr($towerBin, 11, 11);   
                     $radScore = 0; $direScore = 0;
                     for( $j = 0; $j < 11; $j++ ){
                         $radScore = $radScore + intval(substr($radBin,$j,1));
                         $direScore = $direScore + intval(substr($direBin,$j,1));
                     }
                     $towerScore = $radScore." -- ".$direScore;
                 }
    datdota.com -- Dota 2 Stats for the Professional Scene

  7. #7
    Basic Member MuppetMaster42's Avatar
    Join Date
    Nov 2011
    Location
    Australia
    Posts
    585
    Quote Originally Posted by Razumov View Post
    snip
    I have some simple code that converts it to a picture!
    example:
    http://zacher.com.au/dota/draw_map.php?r=0&d=1956
    (r & d are the uints with the data)

    I made this based on this post in the olden days epic thread: http://dev.dota2.com/showthread.php?...l=1#post309065
    If you click a bit further through those pages you'll find where someone linked the images I used.

    when I get home from work in a few hours I'll post up my code
    I'd do it from here but the network is poo head and it won't let me access my server to fetch the code....

  8. #8
    Basic Member MuppetMaster42's Avatar
    Join Date
    Nov 2011
    Location
    Australia
    Posts
    585
    as requested.
    personally I prefer using back-end php to render the image rather than using front-end javascript like some people have.
    It depends on how much traffic your server gets really.
    But the back-end php is guaranteed to work regardless of the client's browser & settings...

    The images can be found here:
    http://zacher.com.au/dota/images/map/

    the code:
    Code:
    <?php
    
    global $canvas, $canvas_dim, $icon_dim;
    
    $rad_status = sprintf('%011b', 0 );
    $dire_status = sprintf('%011b', 0 );
    if (isset($_GET["r"]) && isset($_GET["d"])) {
        $rad_status = sprintf('%011b', $_GET["r"] );
        $dire_status = sprintf('%011b', $_GET["d"] );
    }
    
    $folder = "images/map/";
    $canvas_dim = 1024;
    $icon_dim = 64;
    $modifier = 1;
    
    // If the thumb parameter is set - make everything thumbnailed
    if (isset($_GET["thumb"])) {
        $folder .= "thumb/";
        $canvas_dim = 512;
        $icon_dim = 32;
        $modifier = 0.5;
    }
    
    // load map
    $canvas = @imagecreatefromjpeg($folder . "dota_map.jpg");
    if ($canvas === false) {
        die("UNABLE TO LOAD IMAGE");
    }
    
    // load tower images
    $tower_dire = load_png($folder . "tower_dire.png");
    $tower_radiant = load_png($folder . "tower_radiant.png");
    
    // Radiant
    $positions = array(
        array(120, 775), // ancient top
        array(150, 800), // ancient bot
        
        array(70, 690),  // t3 top
        array(75, 560),  // t2 top
        array(75, 363),  // t1 top
        
        array(190, 730), // t3 mid
        array(270, 660), // t2 mid
        array(390, 540), // t1 mid
        
        array(230, 850), // t3 bot
        array(420, 870), // t2 bot
        array(800, 850), // t1 bot
    );
    
    for ($i = 0; $i < 11; $i++) {
        if ($rad_status[$i]) {
            draw_icon($tower_radiant, $positions[$i]);
        }
    }
    
    // Dire
    $positions = array(
        array(810, 160), // ancient top
        array(840, 185), // ancient bot
        
        array(710, 120), // t3 top
        array(540, 120), // t2 top
        array(160, 110), // t1 top
        
        array(745, 245), // t3 mid
        array(660, 330), // t2 mid
        array(540, 450), // t1 mid
        
        
        array(875, 290),  // t3 bot
        array(880, 440),  // t2 bot
        array(875, 597),  // t1 bot
    );
    
    for ($i = 0; $i < 11; $i++) {
        if ($dire_status[$i]) {
            draw_icon($tower_dire, $positions[$i]);
        }
    }
    
    // Output the data we send to the client
    header('Content-Type: image/jpg');
    imagejpeg($canvas);
    imagedestroy($canvas); 
    
    
    
    function draw_icon($icon, $coords) {
        global $canvas, $canvas_dim, $icon_dim, $modifier;
        
        // Scale the size as required
        $x = floor($coords[0] * $modifier);
        $y = floor($coords[1] * $modifier);
        
        if (!imagecopyresampled($canvas, $icon, $x, $y, 0, 0, $icon_dim, $icon_dim, $icon_dim, $icon_dim)) {
            die("UNABLE TO DRAW IMAGE");
        }
    }
    
    function load_png($file) {
        $pic = @imagecreatefrompng($file);
        if ($pic === false) {
            die("UNABLE TO LOAD IMAGE");
        }
        
        // make sure the images can be properly drawn together
        imagealphablending($pic, false);
        imagesavealpha($pic, true);
        
        return $pic;
    }
    
    ?>

  9. #9
    Basic Member
    Join Date
    Oct 2011
    Posts
    72
    Sweet, thanks. I'll try out that code and post some links with the results.
    datdota.com -- Dota 2 Stats for the Professional Scene

  10. #10
    Basic Member
    Join Date
    Oct 2011
    Posts
    72
    I'm having trouble duplicating the same results for barracks as they are described in the original post. Examples:

    Match ID: 162083844
    Radiant Rax api value: 3
    Binary of 3: 000011

    If I'm following the original post, I'm supposed to read that from left to right in this order with 0 indicating destroyed and 1 indicating remaining.

    1 TOP RANGED
    2 TOP MELEE
    3 MID RANGED
    4 MID MELEE
    5 BOT RANGED
    6 BOT MELEE

    So 000011 would indicated the top and mid rax are destroyed while the bottom are remaining. However,
    watching a replay of that game the top rax are remaining and the bottom and mid rax were destroyed.

    Match ID: 161913547
    Radiant Rax API value: 15
    Binary of 15: 001111

    Watching the replay, the Radiant mid and top rax remain while the bottom rax has been destroyed.

    Match ID: 160860759
    Radiant Rax API value: 48
    Binary of 48: 110000

    Watching the replay, the Radiant top and mid rax are destroyed, bottom are left remaining.

    Based on those three replays, it appears the order in the original post is incorrect. http://wiki.teamfortress.com/wiki/We...arracks_Status has the order:

    Bottom Ranged
    Bot Melee
    Mid Ranged
    Mid Melee
    Top Ranged
    Top Melee
    datdota.com -- Dota 2 Stats for the Professional Scene

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •