Welcome
Welcome to the <strong>Tribal Wars Enhancer</strong> forums!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. <a href="/profile.php?mode=register">Join our community today</a> and help improve the tribal wars game!

[Achieved] Distance calculator

Archive of completed and closed feature requests

Moderators: enduo, Developers

[Achieved] Distance calculator

Postby mog on Sun Mar 09, 2008 10:00 pm

How about a distance calculator so you can see the distance from all your villages from the village screen for example?

Does anyone know the algorithm to calculate distance? Couldn't find it anywhere (tried google + tw wiki) but it's most likely just very basic geometry.
mog
Developer
 
Posts: 180
Joined: Fri Mar 07, 2008 9:10 pm

Postby timas on Sun Mar 09, 2008 11:19 pm

Interesting idea, I've been meaning to add it into the map (optionally) but this would be kind of neat too.

I don't know how the distance is calculated but I'm sure that with some twiddling I can find out, just haven't looked at it yet
timas
Developer
 
Posts: 503
Joined: Tue Feb 19, 2008 10:56 am

Postby johndoe on Thu Mar 13, 2008 12:32 pm

I'm quite surprised you don't see it, it's VERY basic math

a^2 + b^2 = c^2

c being the distance, and to measure the time it would take (also better known as Pythagoras)

sqrt(x^2 + y^2) * <speed of slowest unit> = <time it takes>

x and y are number of tiles
johndoe
 
Posts: 115
Joined: Thu Mar 13, 2008 12:28 pm

Postby mog on Thu Mar 13, 2008 1:12 pm

That would've be my first guess.

Unfortunately i don't algebra regularly, thanks for looking this up for me Mr Doe :)
mog
Developer
 
Posts: 180
Joined: Fri Mar 07, 2008 9:10 pm

Postby mog on Sun Mar 16, 2008 7:08 am

Ok. I added the calculator.

Image

It's been too long since i had use of algebra.. all libraries you work with nowdays abstract this kind of stuff away so you don't have to care about it. Thanks for reminding me again johndoe :D

And here's the code (it's for the new rewritten twenhancer)

Code: Select all
plugins.distancecalc = {
   'enhance_game_info_village' : function() {
      var target = xpathGetFirst("/html/body/table[3]/tbody/tr/td/table/tbody/tr[2]/td[2]").innerHTML;
      target = target.replace(/(.+)\((\d+\|\d+)\)\s(.+)/gi,"$2").split("|");
      html = "<table>";
      html += "<tr><th>Village name</th><th>Distance #1</th><th>Distance #2</th></tr>";
      var villages = twe.myVillages();
      for(var i=0; i<villages.length; i++) {
         v = villages[i];
         html += "<tr><td>"+v.name+"</td>";
         var distance_x = target[0]-v.x;
         var distance_y = target[1]-v.y;
         html += "<td>"+distance_x+"|"+distance_y+"</td>";
         var distance = Math.sqrt(Math.pow(distance_x,2) + Math.pow(distance_y,2));
         html += "<td>"+Math.round(distance*100)/100+"</td>";
         html += "</tr>";
      }
      html += "</div>";

      xpathGetFirst("/html/body/table[3]/tbody/tr/td").innerHTML += html;
   }
};
mog
Developer
 
Posts: 180
Joined: Fri Mar 07, 2008 9:10 pm

Postby system on Mon Mar 17, 2008 11:39 pm

Doesn't seem like it fits somewhere in the "Script on 10th of March". Has the script already changed that much or are you talking about a different rewrite?
system
Beta tester
 
Posts: 20
Joined: Mon Mar 17, 2008 4:20 am

Postby mog on Tue Mar 18, 2008 7:42 am

Yes, it's for the next version.
mog
Developer
 
Posts: 180
Joined: Fri Mar 07, 2008 9:10 pm


Return to Completed and closed features

Who is online

Users browsing this forum: No registered users and 0 guests