Galcon 2: 32 players online!
:: Community ::
ForumsMessagesModsChat
 

Forums :: [ANCIENT] Desktop :: Mods :: travel time

You must sign in to post.

Page 1 / 1 1 

travel time :: May 15, 2007 @ 2:51pm

Ensign thirdparty

Joined: Dec 20, 2006
Posts: 291
Location: New Jersey, USA

Here's a little function I wrote: it takes as input two points, planets, or fleets, and returns a float with the estimated travel time in seconds to get from one to the other.  It's actually just a guess, but it seems to work reasonably accurately as far as I can tell.

Comments/refinements are welcome.

-----

import math

def traveltime(orig,dest,scale=1.0):
      if isinstance(orig,galcon.Planet): o = orig.pos
      elif isinstance(orig,galcon.Fleet): o = orig.get_rect().center
      else: o = orig
      if isinstance(dest,galcon.Planet): d = dest.pos
      elif isinstance(dest,galcon.Fleet): d = dest.get_rect().center
      else: d = dest

      return math.hypot(o[0]-d[0],o[1]-d[1])/(scale * FPS)

-----
post updated on May 15, 2007 @ 2:56pm
Re: travel time :: May 15, 2007 @ 6:26pm

Ensign assassin437

Joined: Jan 29, 2007
Posts: 1118
Location: Quantification

Sheriff
Here's a little function I wrote: it takes as input two points, planets, or fleets, and returns a float with the estimated travel time in seconds to get from one to the other.  It's actually just a guess, but it seems to work reasonably accurately as far as I can tell.

Comments/refinements are welcome.

-----

import math

def traveltime(orig,dest,scale=1.0):
      if isinstance(orig,galcon.Planet): o = orig.pos
      elif isinstance(orig,galcon.Fleet): o = orig.get_rect().center
      else: o = orig
      if isinstance(dest,galcon.Planet): d = dest.pos
      elif isinstance(dest,galcon.Fleet): d = dest.get_rect().center
      else: d = dest

      return math.hypot(o[0]-d[0],o[1]-d[1])/(scale * FPS)

-----


And how would one go about using it?
Re: travel time :: May 15, 2007 @ 7:21pm

Ensign thirdparty

Joined: Dec 20, 2006
Posts: 291
Location: New Jersey, USA

What use is it?!  It's a distance function!

I'm planning on writing a bot, and it needs to know how long a fleet will take to get somewhere so it can figure out how many new ships will have been produced in the mean time.

Somebody also asked for an editor option that would display for each planet how far away it is from the selected planet.  Automatic map generation algorithms might also want to know that.

And an improved user interface might display distance on the line linking the from_ objects to the hover object.  That's roughly what I did to test the code, adding the following to level.Level_:

----- <font size="1">

def paint(self,screen):
    r = classic.Level.paint(self,screen)
    if r != None: return r

    if self.player.hover != None:
        if len(self.player.from_) > 0:
            dist = int(traveltime(self.player.from_[0],self.player.hover,self.options.scale))
            text = 'travel time: %d seconds'%dist
            img = galcon.Font(15).render(text,1,(255,255,255))
            screen.blit(img,((SW-img.get_width())/2,SH-BORDER+(BORDER-img.get_height())/2))

</font> -----

edited because the forum has no preview tool
post updated on May 15, 2007 @ 7:27pm
Re: travel time :: May 16, 2007 @ 8:52am

Ensign assassin437

Joined: Jan 29, 2007
Posts: 1118
Location: Quantification

Sheriff
What use is it?!  It's a distance function!

I'm planning on writing a bot, and it needs to know how long a fleet will take to get somewhere so it can figure out how many new ships will have been produced in the mean time.

Somebody also asked for an editor option that would display for each planet how far away it is from the selected planet.  Automatic map generation algorithms might also want to know that.

And an improved user interface might display distance on the line linking the from_ objects to the hover object.  That's roughly what I did to test the code, adding the following to level.Level_:

----- <font size="1">

def paint(self,screen):
    r = classic.Level.paint(self,screen)
    if r != None: return r

    if self.player.hover != None:
        if len(self.player.from_) > 0:
            dist = int(traveltime(self.player.from_[0],self.player.hover,self.options.scale))
            text = 'travel time: %d seconds'%dist
            img = galcon.Font(15).render(text,1,(255,255,255))
            screen.blit(img,((SW-img.get_width())/2,SH-BORDER+(BORDER-img.get_height())/2))

</font> -----

edited because the forum has no preview tool


I had assumed that it was code of some kind that could be incorporated into the game to display the travel time. My bad.

Page 1 / 1 1 

You must sign in to post.