Currently Online

Latest Posts

Topic: maning military buildings

No0815
Avatar
Topic Opener
Joined: 2016-05-01, 14:52
Posts: 49
Ranking
Pry about Widelands
Posted at: 2016-05-07, 21:14

Sorry for raging again, but how on earth does the game decide, what soldiers are sent to a military building? I usually requires several automatic exchanges till finally one with the requested power level arrives, no matter if "Heroes" or "Rookies" is selected. In the second barbarian campaign scenario I just broke through to the Cidadel and now it took me more than half an hour with countless automatic and manual exchanges to finally man it with my actual best soldiers ...


Top Quote
king_of_nowhere
Avatar
Joined: 2014-09-15, 18:35
Posts: 1668
Ranking
One Elder of Players
Posted at: 2016-05-07, 21:59

the algorithm for it is straightforeward, and it works in such a way:

  • the soldiers are stored in the warehouse. they are stored as an array, a sort of numbered list; the last soldier to enter in the warehouse is put last in the list.

  • when a new military site is completed, the first soldiers in the list are sent.

  • when a military site is fully occupied, the program starts confronting soldiers in the building with soldiers in warehouses. it follows strictly the order of the array, so it finds the first soldier in the warehouse that is better than one soldier in the building, and it send that soldier.

  • when the swap has happened, it looks for another soldier.

yes, if the training of your soldiers has improved over time, then you will have an array of soldiers getting gradually better. if the warehouse is also far from the military site, then it will take a very long time to swap all the soldiers. as far as i can think, you only have two options:

1) you learn the micromanaging to only get fully promoted soldiers out of your training sites, and to get those soldiers directly into the building.

2) you wait until it swaps all the soldiers.

by the way, it is much easier now to have fully promoted soldiers without micromanaging than it was in core 18.


Top Quote
No0815
Avatar
Topic Opener
Joined: 2016-05-01, 14:52
Posts: 49
Ranking
Pry about Widelands
Posted at: 2016-05-08, 15:27

Oh, okay, that's mightily inefficient. From player view it's probably the worst possible solution so is there a reason I don't see, to handle it that way?


Top Quote
einstein13
Avatar
Joined: 2013-07-29, 00:01
Posts: 1118
Ranking
One Elder of Players
Location: Poland
Posted at: 2016-05-08, 16:34

The main problem is a time. There is always not enough people working on Widelands, so basic/easiest solutions are implemented. Sometimes there is someone who make a patch for a feature and the problem is solved. For example less than year ago seafaring algorithm for ships & ports was upgraded from basic (not optimal) to more complicated (and better) one. That is the main reason why the algorithm is doing that way: easy and working face-smile.png


einstein13
calculations & maps packages: http://wuatek.no-ip.org/~rak/widelands/
backup website files: http://kartezjusz.ddns.net/upload/widelands/

Top Quote
king_of_nowhere
Avatar
Joined: 2014-09-15, 18:35
Posts: 1668
Ranking
One Elder of Players
Posted at: 2016-05-09, 00:01

yeah, as einstein said. an algorithm that sent the first soldiers available, and then would check among the available soldiers, one by one, for the first one to be more skilled than one in the fortress, was easy to code. an algorithm that would look for the best soldier available, then send it out... well, when said that way, it doesn't sound so difficult. probably it would be feasible enough. though, if military buildings were that fast filling themselves with the best soldiers, all the good soldiers would go in one building, and none would remain for the others. so maybe it was made that way also because, if on e is fighting on many fronts, the best soldiers will be roughly split among the fronts, without any micromanaging.


Top Quote
teppo

Joined: 2012-01-30, 09:42
Posts: 423
Ranking
Tribe Member
Posted at: 2016-05-09, 06:18

Exchanging solders to heroes/rookies was implemented, to reduce the benefits of manually micromanaging soldier placements.

The algorithm was intentionally made to be slow. New military buildings have a small handicap as a result of this. If one has enough resources, the handicap can be removed by building a new warehouse, too, and sending all the vacant soldiers there. Assuming that there is only one battle front. If there are two fronts, then it is tougher.


Top Quote
king_of_nowhere
Avatar
Joined: 2014-09-15, 18:35
Posts: 1668
Ranking
One Elder of Players
Posted at: 2016-05-09, 11:46

it's a bit easier now, since if you set "preferrably store the chosen ware here" in two warehouses it will split the ware (soldiers in this case) equallly among them. though there is no guarantee that the best soldiers will also be split equally. I proposed considering soldiers with different levels of training to be different wares, but that would require rewriting a lot of code.


Top Quote
No0815
Avatar
Topic Opener
Joined: 2016-05-01, 14:52
Posts: 49
Ranking
Pry about Widelands
Posted at: 2016-05-09, 21:07
int choose_best_soldier (int const* warehouse_soldier_array, int const array_size) {

  int soldier = -1;
  int best_level = -1;

  for (unsigned int i = 0; i < array_size; i++) {

    int soldier_strength = warehouse_soldier_array[i][HP] + warehouse_soldier_array[i][AT] + warehouse_soldier_array[i][DF] + warehouse_soldier_array[i][EV]

    if (soldier_strength > best_level) {
      soldier = warehouse_soldier_array[i];
      best_level = soldier_strength;
    }
    return soldier;
  }
}

Since I don't really know anything about C++ I had to research quite a bit and use some basic programming knowledge to throw this together. Variable names are just wild guesses and it might contain syntax errors but I guess it could basically work. Make a respective function to choose the weakest soldier instead and the problem should be solved.


Top Quote
Tibor

Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2016-05-09, 23:09

The code so sooo convoluted that such easy hack can not be simply plugged into.....

Very common situation is that there are no unassigned (idle in warehouses) soldiers and economy is to create a new one. And I found this comment in a code:

http://bazaar.launchpad.net/~widelands-dev/widelands/trunk/view/head:/src/economy/economy.cc#L876

It seems to me that this can lead to no new soldiers if only heroes are needed - or am I wrong? I dont understand the processes fully....

Anyway any help with coding is welcomed...


Top Quote
kaputtnik
Avatar
Joined: 2013-02-18, 20:48
Posts: 2433
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2016-05-10, 00:13

I couldn't say something to the code, but for a player i would say that if a military building is set to prefer Heroes, the code should send Heroes if Heroes are available (in a warehouse). And i think this was the behavior sometime (but i am not sure).

If you build a Castle (which prefers heroes by default) nearby the frontier to get some resistance to the enemy, it is somehow bad if it get filled with rookies first even if there are some heroes in a warehouse. Of course, currently one couldn't see how many heroes are in a warehouse...


Fight simulator for Widelands:
https://wide-fighter.netlify.app/

Top Quote