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

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:

$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):

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:

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:

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:

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:

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:

$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.

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.