Add terrain affinity for tribe immovables

Bug #1338204 reported by SirVer
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
widelands
Fix Released
Wishlist
Unassigned

Bug Description

Only world trees have terrain affinity right now. Fields, vine and everything else that tribes plant should have affinity too.

This needs

1) adding affinity parsing for tribe immovablaes (conf files) into the engine.
2) defining terrain affinity and testing it.

I think we should do this for b19 if possible.

Tags: tribes

Related branches

SirVer (sirver)
Changed in widelands:
status: New → Incomplete
importance: Undecided → Wishlist
milestone: none → build19-rc1
Revision history for this message
Albert Einstein (w-aaaaa) wrote :

The simplest way to do that is to use terrain affinity from trees (https://bugs.launchpad.net/widelands/+bug/1328635). The model for this feature should be a bit easier :)
At first I thought about bringing only "fertility" from the stats and use that, but that can't work on some terrains (desert, winterland). There are two possibilities:
1. Take a value as a mean of fertility and humidity
2. Take a maximum value of them
Then we can use the value for the immovable like in the trees model, but probably not the same way (more fertile land can be used as well as exact fertile land: we can assume that farmers know that the seeds can be put less deep to very fertile soil and grow as well as deeper seeds on less fertile land).

Here is a sample of code of this model:
(according to http://bazaar.launchpad.net/~widelands-dev/widelands/terrain_affinity/view/head:/src/logic/terrain_affinity.cc)

TerrainAffinity::TerrainAffinity(const LuaTable& table, const std::string& immovable_name)
   : preferred_richness_(table.get_double("preferred_richness"))

double terrain_humidity = 0;
double terrain_fertility = 0;

(...)? How can we get the mean values of terrain affinity? I don't understand that part of code.

// it is like fertility, but the name already exists
const double terrain_richness = max(terrain_humidity,terrain_fertility);
// OR (depend on model):
const double terrain_richness = (terrain_humidity+terrain_fertility)/2;

const double sigma=0.0288; //The value can change- it is only to make a 0.1 wide slope of gauss
double pure_gauss=1.;
double advanced_gauss=0.95;

if(terrain_ruchness<preffered_richness()){
pure_gauss=exp(-pow2(terrain_richness-preffered_richness())/(2*pow2(sigma)));
advanced_gauss=pure_gauss*0.9+0.05;
}

return advanced_gauss;

END :)
As a result the possibility of growth is always more than 0.5 and less than or equals 0.95.
It is equal 0.95 for the value terrain_richness==preffered_richness() or more.
The slope of gauss begins on 0.1 value before preffered_richness(). So if there is:
terrain_richness == preffered_richness()-0.15, then possibility ~=0.05
terrain_richness == preffered_richness()-0.1, then possibility ~= 0.05
terrain_richness == preffered_richness()-0.05, then possibility ~= 0.5
terrain_richness == preffered_richness(), then possibility == 0.95
terrain_richness == preffered_richness()+0.05, then possibility == 0.95

This is only and idea. Feel free to discuss it.

Prefered richness should be about 0.5-0.8, because some lands (desert or winterwolrd) can be unplayable.

Revision history for this message
SirVer (sirver) wrote :

I hope that no new model is needed and the exact same logic can be reused.

Revision history for this message
Albert Einstein (w-aaaaa) wrote :

In my opinnion it is impossible to use "the exact same logic".
Why?

Information 1:
And we have only:
2 species for Barbarians (Wheat & Thatch Reed)
2 species for Empire (Wheat & Grape)
2 species for Atlanteans (Corn & Blackroot)

Information 2:
Almost every terrain type has at least one specie which grows on it very fast.
Without trees are terrains like some deserts, some mountains, water, lava, barren steppe, ...
We have lots of species of trees and every tree is exact the same for any tribe (one piece of wood from one tree).

Assumption:
Every pair of products has to be grown on every map.

If we use the same logic as for the trees, most of terrains will be desert for any of the tribe.

Example:
Let assume that Barbarians like greenland and their crops will like to grow only on greenland terrain. Also not every type of soil! Only some of them.
They will not grow on desert, ashes or ice.
That is the logic used for trees.

Another assumption here: Empire like deserts. And their crops will grow on desert terrain only.

The battle between both of the tribes will be known only from the type of terrain, not the playing of players. It is unequal for them.
(End of example)

Solution 1 (simple):
I vote for slight change of the model between trees and tribe immovables.
The only cange is for "better soil" (better than it is needed for seeds to grow).

Solution 2 (more complex):
We can use exact the same logic for each of the tribes, but then we have to multiply number of types of crops.
Every tribe can have one type of immovable (crops/ grapes/ ...) for each of type of land (wasteland, desert, ...). Then there will always be a possibility for the tribe to win with equal chances.

Sorry for the "scientific" form of statement, but I had no idea how to explain it clearly. I hope it is clear.

Revision history for this message
SirVer (sirver) wrote :

In the engine there is currently no distinction between a tree or a field, so all model changes will be a lot of work to implement. Don't you think the pickyness parameter can be put to use to make the model fit somehow?

Otherwise the easiest solution is to extend the model for trees to also capture your suggestion for tribe immovables.

Revision history for this message
Albert Einstein (w-aaaaa) wrote :

I will try to make good model for that, but I will last some time for me (I'm not online all the time now).
Next week probably I will have some about it.

Revision history for this message
Albert Einstein (w-aaaaa) wrote :

OK.
I've finished some calculations.
It wasn't too easy for me, but finally I have something.
Easy numbers:

Pickness = 0.0
Preferred temperature = 293.79
Preferred humidity = 0.464
Preferred fertility = 0.592

The same numbers for all the immovables. (Widelands economy reasons)

Then, the best soil (Meadow 1, Greenland) has probability about 0.777
It isn't too big.
Some worlds are not good to grow crops and all the stuff, like Winter or desert. Greenland is the best fit for every type of fields.

Of course the short description and calculations are available on my site (http://student.agh.edu.pl/~rak/widelands/)

Revision history for this message
Albert Einstein (w-aaaaa) wrote :

And one more question (I forgot about this idea):

Is it possible to make a small changes and test it? I mean: make a "patch" or whatever here and test the model. If it doesn't work at all, just go back to old model for tribe immovable? Is it possible?

The model can work in strange way, so in my opinion it shouldn't be used in official versions now. It HASTO BE TESTED BEFORE.

Revision history for this message
SirVer (sirver) wrote :

> Is it possible to make a small changes and test it? I mean: make a "patch" or whatever here and test the model. If it doesn't work at all, just go back to old model for tribe immovable? Is it possible?

not sure what you mean. We can always put something in the code, see how it works and remove it again it if makes trouble. THere is no old model for tribe immovables right now.

> The model can work in strange way, so in my opinion it shouldn't be used in official versions now. It HASTO BE TESTED BEFORE.

no worries, there are no official version until b19 - which will be a while still. The dev versions are meant for testing.

Revision history for this message
Albert Einstein (w-aaaaa) wrote :

> We can always put something in the code, see how it works and remove it again it if makes trouble.

This is my answer.

I don't understand everything about code and programming here, but as I understand, you wanted me to use current model for growing trees. This can be used here with values above for tribe immovables. It will work somehow, but in my opinion it will make fields grow slower than before (some people will not like that).

SirVer (sirver)
Changed in widelands:
milestone: build19-rc1 → none
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for widelands because there has been no activity for 60 days.]

Changed in widelands:
status: Incomplete → Expired
GunChleoc (gunchleoc)
Changed in widelands:
status: Expired → Incomplete
Changed in widelands:
status: Incomplete → Expired
GunChleoc (gunchleoc)
Changed in widelands:
status: Expired → Confirmed
GunChleoc (gunchleoc)
Changed in widelands:
milestone: none → build20-rc1
assignee: nobody → GunChleoc (gunchleoc)
status: Confirmed → In Progress
GunChleoc (gunchleoc)
Changed in widelands:
status: In Progress → Fix Committed
assignee: GunChleoc (gunchleoc) → nobody
tags: added: tribes
Revision history for this message
GunChleoc (gunchleoc) wrote :

Fixed in build20-rc1

Changed in widelands:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.