Urban Dead Revive Radar

Coordinate Detection Code

Back to front page.

Prior to version 0.4, UDRR used coordinate detection code from UDMap. However, sometimes it gave wrong values for the player's location, so I decided to investigate.

Here is the original code:
001 function parse_city_coords(){
002   
003   /* coordinates of upper left tile */
004   inputs=document.getElementsByTagName("input");
005   
006   for(i=0; i<inputs.length; i++){
007     
008     /* searches for the top left cell in the map */
009     input = inputs[i];
010     if(coords = input.value.match( /^(\d+)-(\d+)$/ )){
011       
012       c = coords[1];
013       r = coords[2];
014       
015       r_mod = 0; c_mod = 0;
016       	
017       if(r % 10)
018         r_mod = 1;
019       
020       if(c % 10)
021         c_mod = 1;
022       
023       coords[1] = parseInt(coords[1])+c_mod;
024       coords[2] = parseInt(coords[2])+r_mod;
025       
026       return coords;
027     }
028   }
029 }

The player's location should be easy to determine: find the coordinates of the upper-left box on the minimap and add 1 to each. But notice what's going on in lines 15 through 21: only when the coordinate (X or Y) is divisible by 10 do they add 1 to the coordinates of the upper-left box. For all other cases, they leave the player's location as the coordinates of the upper-left box!

I've edited the code to remove this logic and simply add 1 to both the X and Y coordinates of the upper-left box to mark the player's location. This will create a problem on the northern-most and western-most edges of the map, so I need to handle that case as well (version 0.4 is broken in this regard). If anyone can explain to me why the creators of UDMap did it like they did, that would be most helpful (it seems like code that was there for a reason, not code that someone wrote in ignorance).

Back to front page.

Urban Dead Revive Radar was created by Matt Cooper. Feel free to use the code for any non-malicious purpose, and it would be great if you would contribute your work at least to me if not to the community at large.