Waste by distance: what is distance?

Contribute, display and discuss rulesets and modpacks for use in Freeciv here.
User avatar
Corbeau
Elite
Posts: 1291
Joined: Mon Jan 13, 2014 11:13 pm

Waste by distance: what is distance?

Post by Corbeau »

One more ruleset question:

"Output_Waste_By_Distance: For each tile in real distance that a city is from your capital, it gets amount of extra waste."

Just checking, how is distance calculated in this case? Suppose the capital is at (0, 0) and the other city is at (3, 4), is the distance 5 or 7?

Also, the explanation says "amount", but ruleset says "%" (which does sound more meaningful). However, percent of *what*? City base trade, meaning everything taken from the tiles, or whats left after base corruption is subtracted? It seems logical that it should the former, but better to ask...
--
* Freeciv LongTurn, a community of one-turn-per-day players and developers
* LongTurn Blog - information nexus with stuff and stuff and stuff
* Longturn Discord server; real-time chatting, discussing, quarrelling, trolling, gaslighting...
User avatar
GriffonSpade
Elite
Posts: 578
Joined: Mon Apr 29, 2013 4:41 pm

Re: Waste by distance: what is distance?

Post by GriffonSpade »

Corbeau wrote:One more ruleset question:

"Output_Waste_By_Distance: For each tile in real distance that a city is from your capital, it gets amount of extra waste."

Just checking, how is distance calculated in this case? Suppose the capital is at (0, 0) and the other city is at (3, 4), is the distance 5 or 7?

Also, the explanation says "amount", but ruleset says "%" (which does sound more meaningful). However, percent of *what*? City base trade, meaning everything taken from the tiles, or whats left after base corruption is subtracted? It seems logical that it should the former, but better to ask...
Well, that's going to depend on whether you're hex or square. But for square, I'm pretty sure it's SQRT(3^2+4^2) = SQRT(25) = 5. It forms a right triangle, after all.

No idea of how the specifics of it work, though?
User avatar
JTN
Elite
Posts: 473
Joined: Wed Jan 30, 2013 12:15 am

Re: Waste by distance: what is distance?

Post by JTN »

"Real" distance means the minimum number of tiles a unit could move through to get from A to B (ignoring terrain etc); it's not the Pythagorean distance. So for your (3,4) example on a square map, the distance is 4 (because the hypothetical unit could make 3 diagonal moves and one orthogonal one to get between the cities); the shape of the Gov_Center's influence is square. (This is sort of covered in doc/HACKING.)

This distance-dependent waste percentage is added to Output_Waste, the result multiplied by Output_Waste_Pct, and then applied to city output after that is modified by Output_Bonus/Output_Bonus_2. For trade these penalties are only applied on what's left after any reduction from notradesize/fulltradesize. (Most of this is in city_waste() although needs some context to understand)
User avatar
Corbeau
Elite
Posts: 1291
Joined: Mon Jan 13, 2014 11:13 pm

Re: Waste by distance: what is distance?

Post by Corbeau »

Thanks!
--
* Freeciv LongTurn, a community of one-turn-per-day players and developers
* LongTurn Blog - information nexus with stuff and stuff and stuff
* Longturn Discord server; real-time chatting, discussing, quarrelling, trolling, gaslighting...
User avatar
dunnoob
Elite
Posts: 327
Joined: Mon Dec 23, 2013 3:13 am
Location: Hamburg
Contact:

Re: Waste by distance: what is distance?

Post by dunnoob »

JTN wrote:city_waste()
Interesting stuff, the...

Code: Select all

      if (gov_center == NULL) {
        waste_all = TRUE; /* no gov center - no income */
      } else {
        waste_level += waste_by_dist * min_dist;
      }
...makes it hard to create a classic variant, where a palace isn't free (has to be built). It only works if all waste_by_distance effects explicitly require the existence of a palace (or rather, gov_center). I don't see how the waste_level works, is it really allowed to reach 100 for big distances? At least there is some code to limit the waste to at most everything. :lol:
User avatar
Corbeau
Elite
Posts: 1291
Joined: Mon Jan 13, 2014 11:13 pm

Re: Waste by distance: what is distance?

Post by Corbeau »

I definitely hope that there are failsafes installed because I'm creating a ruleset where the size of the empire will be limited by corruption, meaning there will be >100% corruption at finite distances.

And, while we're at it, does anyone know how is corruption/waste rounded? Up, down or to the nearest integer? (And which way in case of .5?)
--
* Freeciv LongTurn, a community of one-turn-per-day players and developers
* LongTurn Blog - information nexus with stuff and stuff and stuff
* Longturn Discord server; real-time chatting, discussing, quarrelling, trolling, gaslighting...
User avatar
GriffonSpade
Elite
Posts: 578
Joined: Mon Apr 29, 2013 4:41 pm

Re: Waste by distance: what is distance?

Post by GriffonSpade »

JTN wrote:"Real" distance means the minimum number of tiles a unit could move through to get from A to B (ignoring terrain etc); it's not the Pythagorean distance. So for your (3,4) example on a square map, the distance is 4 (because the hypothetical unit could make 3 diagonal moves and one orthogonal one to get between the cities); the shape of the Gov_Center's influence is square. (This is sort of covered in doc/HACKING.)

This distance-dependent waste percentage is added to Output_Waste, the result multiplied by Output_Waste_Pct, and then applied to city output after that is modified by Output_Bonus/Output_Bonus_2. For trade these penalties are only applied on what's left after any reduction from notradesize/fulltradesize. (Most of this is in city_waste() although needs some context to understand)
Ah, good to know.

Hmm. So the amount of corruption trade loss is [(X1 + Y) * (100 - Z)] * [A * B * C + D1]?
Where:
X1 = Output_Waste_By_Distance * [Real Distance]
Y = Output_Waste
Z = Output_Waste_Pct
A = Output_Bonus
B = Output_Bonus_2
C = [Base City Trade Resource Output]
D1 = [Base Trade Route Trade Resource Output] * [Trade Size Modifier]
dunnoob wrote:
JTN wrote:city_waste()
Interesting stuff, the...

Code: Select all

      if (gov_center == NULL) {
        waste_all = TRUE; /* no gov center - no income */
      } else {
        waste_level += waste_by_dist * min_dist;
      }
...makes it hard to create a classic variant, where a palace isn't free (has to be built). It only works if all waste_by_distance effects explicitly require the existence of a palace (or rather, gov_center). I don't see how the waste_level works, is it really allowed to reach 100 for big distances? At least there is some code to limit the waste to at most everything. :lol:
Yeah...I often find myself wishing mutually exclusive (A, B, C, etc. and building one automatically makes any of the others vanish) and 'upgrading' Small Wonders had support. So many things could be done with those! And palaces shouldn't be free. :P

I suppose it could be replaced with a flat Output_Waste if there's no Palace, but that might have some exploit if there are very large distances involved. Hmm. There's no way to cap the penalty from Output_Waste_By_Distance manually, is there?
Last edited by GriffonSpade on Tue Jan 16, 2018 1:28 am, edited 1 time in total.
User avatar
Corbeau
Elite
Posts: 1291
Joined: Mon Jan 13, 2014 11:13 pm

Re: Waste by distance: what is distance?

Post by Corbeau »

GriffonSpade wrote:Hmm. So the amount of corruption trade loss is [(X1 + Y) * Z] * [A * B * C + D1]?
Ok, just to make sure I got it 100%, you keep using the word "amount" but we're actually talking about percentage, right? If there are two cities at the same distance from the capital, one gets 20 trade on his tiles, the other gets 8, and if the first has corruption 5, then the other has 2, not also 5, correct?
--
* Freeciv LongTurn, a community of one-turn-per-day players and developers
* LongTurn Blog - information nexus with stuff and stuff and stuff
* Longturn Discord server; real-time chatting, discussing, quarrelling, trolling, gaslighting...
User avatar
GriffonSpade
Elite
Posts: 578
Joined: Mon Apr 29, 2013 4:41 pm

Re: Waste by distance: what is distance?

Post by GriffonSpade »

Alrighty, let's look at the code itself.
sets up
int R is [Effective Trade Resource]
int A is [Total Trade Resource] (Includes A * B * C of previous)
int B is [Size Penalty]
int C is [City Size]
int D is [No Trade Size]
int E is [Full Trade Size]

Note these variables set up as integers, which means they get truncated to integer after each operation.

If C <= D Then B = A
Else if C >= E Then B = 0
Else Then B = A * (E - C) / (E - D)
R = A - B

int X is Output_Waste
int Y is [Corruption Waste Per Distance]
int Z is Output_Waste_Pct
int W is [Corruption Waste Amount]

Y = Output_Waste_By_Dist * [Real Distance] / 100
W = R * [X + Y]
W -= W * Z / 100
W = MAX(W, 0)
W = MIN(W, R)

So no trade size and full trade size affect /ALL/ trade resource, not just that from trade routes? I don't see any kind of distinction made. Seems a bit heavy-handed against early civilizations, though. I've never used this option, so I should see if it negatively impacts early gameplay. Might be that this should have conditions restricting it.
Note that [Real Distance] is calculated to the nearest government center (Hence Min_Dist, as there could be multiple government centers.)
Note that there is no cap on corruption percentage, only on final amount.
Note that trade lost to [Size Penalty] is included in a city's corruption amount.
Note that if there is no government center, everything else is ignored and all trade is automatically corruption. Would be nice if we could set an Output_Waste_Max effect to cap it instead.

Because the final corruption amount is /iterative/, it's a bit hard to properly represent in a single equation.
[ ] represents integer truncation.
So it looks like this, I guess.

W = [[A - B] * [[(X * M + Y) / 100] - [[(X * M + Y) / 100] * Z / 100]] + B]

A is [Total Trade Resource]
B is [Size Penalty]
M is [Minimum Real Distance] (To a Government Center)
X is Output_Waste_By_Dist
Y is Output_Waste
Z is Output_Waste_Pct
W is [Corruption Waste Amount]

Or for step-by-step that's easier to read...
A2 = [A - B]
X2 = [(X * M + Y) / 100]
Z2 = [N * Z / 100]
W = [A2 * [X2 - Z2] + B]

A2 is [Effective Trade Resource]
X2 is [Base Corruption Percent]
Z2 is [Corruption Reduction Percent]

To calculate B:
If C <= D Then B = A
Else if C >= E Then B = 0
Else Then B = [A * (E - C) / (E - D)]

A is [Total Trade Resource]
B is [Size Penalty]
C is [City Size]
D is [No Trade Size]
E is [Full Trade Size]
User avatar
Corbeau
Elite
Posts: 1291
Joined: Mon Jan 13, 2014 11:13 pm

Re: Waste by distance: what is distance?

Post by Corbeau »

Rather than opening a new topic, let's continue this one to keep all things in one place.

So, corruption-by-distance. The question is: does it cap at 100% or it can go further?

For example, let's say that:
* corruption per distance-from-capital is 10% per tile
* Courthouse decreases corruption by 50%
* a city is 20 tiles away from capital
* a city gets, whatever, say, 10 Trade from tiles

Is the final corruption in the city
0 (zero) (original corruption is 200% because of distance, decreased to 100% by the Courthouse)?
or
5 (original corruption is capped at 100% and then halved by the Courthouse)?

edit: looking at the equations above, it seems it's the former case, meaning that percentage can go above 100%. But there are different claims, can someone confirm this?
--
* Freeciv LongTurn, a community of one-turn-per-day players and developers
* LongTurn Blog - information nexus with stuff and stuff and stuff
* Longturn Discord server; real-time chatting, discussing, quarrelling, trolling, gaslighting...
Post Reply