Author Topic: On the Effectiveness of Roads  (Read 255 times)

Andrew

  • Game Master / Lead Developer
  • Administrator
  • Sr. Member
  • *****
  • Posts: 1797
  • Karma: +75/-7
  • Mildly Amused
    • View Profile
    • Lemuria Community Fan Site
On the Effectiveness of Roads
« on: May 27, 2017, 04:10:56 PM »
So, this has been a question that many people have asked I suspect, but how effective are roads in M&F?

Well, lets take a look. Traveling in M&F is handled by a command run several times throughout the day, appropriately titled "WorkerTravelCommand.php" that does all the heavy-lifting, for ever character going anywhere. The main things we're concerned about with this command are the following lines:

Code: [Select]
$geography->updateTravelSpeed($char);
Code: [Select]
$progress = $char->getProgress() + ($char->getSpeed() * $this->speedmod);
The first one is a call to the game's Geography Service to update the travel speed for a given character, which looks something like this (edited a bit for your viewing pleasure):

Code: [Select]
   public function updateTravelSpeed(Character $character) {
      $query = $this->em->createQuery(--FIND TRAVEL FOR A CHARACTER--);
      $query->setParameter(--DEFINE A CHARACTER AS THE ONE WE'RE GIVEN--);
      $length = $query->getSingleScalarResult();
      if ($length <= 0) return false;
      if ($character->getTravelAtSea()) {$base_speed = $this->base_speed;}
      else {$men = $character->getSoldiers()->count() + ($character->getEntourage()->count()/2);
         $base_speed = $this->base_speed / exp(sqrt($men/200));}
      if ($character->isNPC()) {$base_speed *= 0.9;}
      $query = $this->em->createQuery(--FIND ROADS NEAR A CHARACTER LISTING HIGHER QUALITY ROADS FIRST--);
      $query->setParameters(--A CHARACTER BEING THE ONE WE'RE LOOKING AT AND WITHIN THE ROAD BUFFER DISTANCE--);
      $query->setMaxResults(1);
      if ($road = $query->getOneOrNullResult()) {
         $road_mod = 1.0 + $road->getQuality()/10;
         $biome_mod = $this->getLocalBiome($character)->getTravel();
         if ($biome_mod < 1.0) {$biome_mod = min(1.0, $biome_mod + $road->getQuality()/20);}
         $combined_mod = $road_mod * $biome_mod;
         $base_speed *= $combined_mod;}
      else {$base_speed *= $this->getLocalBiome($character)->getTravel();}
      $speed = $base_speed / $length;
      $character->setSpeed($speed);
      return true;}

Okay, that's a foreign language to a lot of people, what does it mean? Well, this set of code expects that it's going to be given a character when called, and without it, it won't do anything. After that it proceeds to figure out if that character has travel set. Before we go too indepth, the base travel speed of the game is set to 12km a day. Where it starts to get interesting is around here:

Code: [Select]
      if ($character->getTravelAtSea()) {$base_speed = $this->base_speed;}
      else {$men = $character->getSoldiers()->count() + ($character->getEntourage()->count()/2);
         $base_speed = $this->base_speed / exp(sqrt($men/200));}

This chunk of code determines base travel speed. On water, this is always the same. On land though, this is determined by your soldier and entourage count. Entourage affect travel half as much as soldiers do, as we can see. What follows that is a bit outside my specialty, but from what I can understand, it calculates the square root of however many men you have divided by 200, then raises that square root to the power of e. For 200 men, this will set $base_speed as 4414.55329 (or thereabouts). The next line:

Code: [Select]
      if ($character->isNPC()) {$base_speed *= 0.9;}
Simply makes NPCs just a touch slower, so it's not as impossible for First Ones to catch them. In our 200 man example, their base speed is 3973.09796. That's followed by a query against the database for nearby roads, returning either the best road found or a null result, which is processed by the following lines:

Code: [Select]
      if ($road = $query->getOneOrNullResult()) {
         $road_mod = 1.0 + $road->getQuality()/10;
         $biome_mod = $this->getLocalBiome($character)->getTravel();
         if ($biome_mod < 1.0) {$biome_mod = min(1.0, $biome_mod + $road->getQuality()/20);}
         $combined_mod = $road_mod * $biome_mod;
         $base_speed *= $combined_mod;}
      else {$base_speed *= $this->getLocalBiome($character)->getTravel();}

If we have a level 3 road, as the best road available, $road_mod will be set to 1.3. For $biome_mod, here is a quick chart of how each biome affects travel speeds:

Grass = 1
Thin Grass = 1
Scrublands = 1
Thin Scrublands = 0.95
Deserts = 0.9
Marsh = 0.65
Forest = 0.8
Dense Forest = 0.75
Mountains = 0.6
Snow-covered Mountains = 0.5
Water = 1.5
Ocean = 1.5

So, if we're in a forest, $biome_mod gets set to 0.8. Since we're on a level 3 road though, the next line is the game accounting for the road making things easier, and with numbers plugged in looks like this:

Code: [Select]
         if ($biome_mod < 1.0) {$biome_mod = select smaller of: (1.0) OR (0.8 + 3/20);}
That brings our $biome_mod to be set to 0.95. With that worked out we combine the road and biome mods to get a $combined_mod of 1.235, which is then multiplied against our base speed to get a value of 5451.973318 or so.

After that, we simple calculate the distance that you will have traveled as a percent of the whole:

Code: [Select]
      $speed = $base_speed / $length;
And then return that to our WorkerTravelCommand.

Code: [Select]
$progress = $char->getProgress() + ($char->getSpeed() * $this->speedmod);
This takes the current progress you have and adds the product of your speed multiplied by 0.15, so people aren't moving so fast the game is impossible to play.

So, TLDR, what does it mean?

Roads can cut your travel time by up to a third.
Standing for the creation of interesting things since Year 1, Week 5, Day 4.
Favorite cold beverage: Strawberry Shake
My hobbies: Fixing computers, video games, anime, manga, some other stuff, sleep (in no particular order)

Amble

  • Jr. Member
  • **
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: On the Effectiveness of Roads
« Reply #1 on: May 28, 2017, 04:24:44 AM »
Thank you for this, that's really interesting. It seems to me that the estimated travel time when you set travel doesn't factor in the roads at all though. Is that true? If so, could you add a little text note to the estimate to say "..though roads may reduce travel time" because I've spent my time playing the game thinking roads didn't work at all.