Merge lp:~widelands-dev/widelands/bug-1829471-worker-preciousness into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 9115
Proposed branch: lp:~widelands-dev/widelands/bug-1829471-worker-preciousness
Merge into: lp:widelands
Diff against target: 879 lines (+264/-158)
27 files modified
data/tribes/atlanteans.lua (+0/-1)
data/tribes/barbarians.lua (+0/-1)
data/tribes/buildings/productionsites/atlanteans/horsefarm/init.lua (+0/-1)
data/tribes/buildings/productionsites/barbarians/cattlefarm/init.lua (+0/-1)
data/tribes/buildings/productionsites/empire/donkeyfarm/init.lua (+0/-1)
data/tribes/empire.lua (+0/-1)
data/tribes/frisians.lua (+0/-1)
data/tribes/workers/atlanteans/horse/init.lua (+6/-0)
data/tribes/workers/atlanteans/soldier/init.lua (+6/-0)
data/tribes/workers/barbarians/ox/init.lua (+6/-0)
data/tribes/workers/barbarians/soldier/init.lua (+6/-0)
data/tribes/workers/empire/donkey/init.lua (+6/-0)
data/tribes/workers/empire/soldier/init.lua (+6/-0)
data/tribes/workers/frisians/reindeer/init.lua (+6/-0)
data/tribes/workers/frisians/soldier/init.lua (+6/-0)
doc/sphinx/source/lua_tribes_workers.rst.org (+62/-54)
src/ai/ai_help_structs.h (+1/-0)
src/ai/ai_hints.cc (+25/-1)
src/ai/ai_hints.h (+27/-5)
src/ai/defaultai.cc (+76/-64)
src/logic/map_objects/tribes/tribe_descr.cc (+0/-5)
src/logic/map_objects/tribes/tribe_descr.h (+0/-2)
src/logic/map_objects/tribes/tribes.cc (+1/-1)
src/logic/map_objects/tribes/ware_descr.cc (+5/-14)
src/logic/map_objects/tribes/ware_descr.h (+9/-5)
src/logic/map_objects/tribes/worker_descr.cc (+1/-0)
src/logic/map_objects/tribes/worker_descr.h (+9/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1829471-worker-preciousness
Reviewer Review Type Date Requested Status
hessenfarmer Approve
TiborB Approve
Review via email: mp+367608@code.launchpad.net

Commit message

Some AI code cleanups

- Implement AI hints for workers
- Deduce whether a building is a barracks or recruits other workers from building outputs
- Move ware preciousness into a new AI hint object
- Fixed warning about signed/unsigned comparisons.

Description of the change

There is an assert that is failing now. Since I am not very familiar with the AI code, I don't know why it is there. @Tibor: Do you remember why you put it there?

To post a comment you must log in.
Revision history for this message
TiborB (tiborb95) wrote :

See my comments below

BTW I am doing some training, I hope this will not interfere. Once it is merged, I will re-train too..

Revision history for this message
TiborB (tiborb95) wrote :

The logic is / was you cannot have max preciousness if you do not produce anything...

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks, that fixed it!

There should be no real impact on training from this branch. This is a pure refactoring without any intended semantic changes except that the reindeer farm now has a minimum preciousness of 2.

Revision history for this message
GunChleoc (gunchleoc) wrote :

BTW that assert is already broken in trunk.

Revision history for this message
TiborB (tiborb95) wrote :

I will investigate that assert....

Revision history for this message
TiborB (tiborb95) wrote :

I am getting the failing assert for atlanteans horsefarm and barbarian cattlefarm - in trunk... They have max_needed_preciousness 1.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 5015. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/534229981.
Appveyor build 4796. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1829471_worker_preciousness-4796.

Revision history for this message
TiborB (tiborb95) wrote :

Was you considering making barracks a recruitment? Because preciousness of barracks (output) is now hardcoded to 5, if I am right.

Revision history for this message
GunChleoc (gunchleoc) wrote :

I was only focusing on the code that hessenfarmer changed for the carrier2, but I think not having the barracks hard-coded would also be a good idea. I'll have a look.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Done. No need to investigate the assert failure in trunk further, because it is fixed in this branch. It slipped past us when we reviewed hessenfarmer's branch.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

The failed assert came definitly from my changes. I did not compile and test them in debug, cause my machine is so slow. Sorry about that.
The problem is we were handling the recruitment as a producing building so it needed preciousness while in another part we handled it like a non producing building asserting that preciousness is 0.

The desired behaviour should be to handle the barracks and the recruiter like any other building with some output. This needs 2 things the definition of a preciousness for the soldier and the second carrier and some good decisiongates to be taken into account for determining neededness and priority for both of them.

Revision history for this message
TiborB (tiborb95) wrote :

AI code is simply overcomplicated...
Animals are also workers?
Do we expect that same workers will have no preciousness set?

The overall change looks good to me

review: Approve
Revision history for this message
hessenfarmer (stephan-lutz) wrote :

As soon as a worker is produced by a building he needs a preciousness (if we think of schools for example). If it is created in the warehouses he does not need a preciousness.

Maybe we have a problem now with the frisian reindeer farm, as it will now be identified as a recruitment site. this will limit the number of them to 2 which is far too less in terms of fur production. In my opinion we need to ensure, that the normal production part of a building takes precedence. But I need to make some tests to confirm this issue.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Confirmed by looking at the code and fixed. It's fine that you're on release builds, I used to do that too before I bought my new machine.

And yes, animals are carriers, so they are workers.

Unlike for wares, preciousness is not mandatory for workers, since most of them aren't recruited by buildings.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

Hmm. I thought we are aiming at having more of the definition stuf in lua so we can change things without the need to recompile. I have the feeling that part of this branch is going in opposite direction. Fo the design of a new tribe I think I would like to have some flags in lua better than determine things from other values, cause this is giving us more flexibility.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

One thing I would like to have is a definition of normal AI limit to be able to have the limit values currently hardcoded in lua.

Revision history for this message
GunChleoc (gunchleoc) wrote :

There is a difference between hard-coding values like "preciousness = 5" and automatically deducing building types that get a completely different treatment and algorithm by the AI anyway.

Revision history for this message
GunChleoc (gunchleoc) wrote :

P.S. What we probably really should do here is to treat output workers in the exact same way as output wares and get rid of the special treatment code for recruiting sites, but that is out of scope for this branch.

Revision history for this message
GunChleoc (gunchleoc) wrote :

> One thing I would like to have is a definition of normal AI limit to be able to have the limit values currently hardcoded in lua.

Agreed, I have added it to the bug. I don't want to do it in this branch though, because then we will have to re-review the code in this branch for every new idea that we can come up. I prefer having separate branches for each issue.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

> There is a difference between hard-coding values like "preciousness = 5" and
> automatically deducing building types that get a completely different
> treatment and algorithm by the AI anyway.

Agreed on the difference. But not deducing the types and having flags instead gives us more flexibility. However for the moment being we will try to get this in until we need it the other way round again.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

I think the deduction of Recruitment of second carrier will not work this way as Outputs of recruitment sites contains the worker so it isn't empty. see inline comment as well

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

Forget my last comment. I had the wrong conception of bo.outputs

So for me Code looks good will test this tonight.

review: Approve
Revision history for this message
hessenfarmer (stephan-lutz) wrote :

I have tested it now and found no anomalies (just tested with release build)

so from my side this could go in, although I would keep the first bug open.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'data/tribes/atlanteans.lua'
--- data/tribes/atlanteans.lua 2018-07-29 13:49:09 +0000
+++ data/tribes/atlanteans.lua 2019-05-19 16:18:33 +0000
@@ -375,7 +375,6 @@
375 soldier = "atlanteans_soldier",375 soldier = "atlanteans_soldier",
376 ship = "atlanteans_ship",376 ship = "atlanteans_ship",
377 port = "atlanteans_port",377 port = "atlanteans_port",
378 barracks = "atlanteans_barracks",
379 ironore = "iron_ore",378 ironore = "iron_ore",
380 rawlog = "log",379 rawlog = "log",
381 refinedlog = "planks",380 refinedlog = "planks",
382381
=== modified file 'data/tribes/barbarians.lua'
--- data/tribes/barbarians.lua 2018-07-29 13:49:09 +0000
+++ data/tribes/barbarians.lua 2019-05-19 16:18:33 +0000
@@ -308,7 +308,6 @@
308 soldier = "barbarians_soldier",308 soldier = "barbarians_soldier",
309 ship = "barbarians_ship",309 ship = "barbarians_ship",
310 port = "barbarians_port",310 port = "barbarians_port",
311 barracks = "barbarians_barracks",
312 ironore = "iron_ore",311 ironore = "iron_ore",
313 rawlog = "log",312 rawlog = "log",
314 refinedlog = "blackwood",313 refinedlog = "blackwood",
315314
=== modified file 'data/tribes/buildings/productionsites/atlanteans/horsefarm/init.lua'
--- data/tribes/buildings/productionsites/atlanteans/horsefarm/init.lua 2019-05-15 06:29:24 +0000
+++ data/tribes/buildings/productionsites/atlanteans/horsefarm/init.lua 2019-05-19 16:18:33 +0000
@@ -31,7 +31,6 @@
31 },31 },
3232
33 aihints = {33 aihints = {
34 recruitment = true,
35 prohibited_till = 610,34 prohibited_till = 610,
36 },35 },
3736
3837
=== modified file 'data/tribes/buildings/productionsites/barbarians/cattlefarm/init.lua'
--- data/tribes/buildings/productionsites/barbarians/cattlefarm/init.lua 2019-05-15 06:29:24 +0000
+++ data/tribes/buildings/productionsites/barbarians/cattlefarm/init.lua 2019-05-19 16:18:33 +0000
@@ -31,7 +31,6 @@
31 },31 },
3232
33 aihints = {33 aihints = {
34 recruitment = true,
35 prohibited_till = 610,34 prohibited_till = 610,
36 },35 },
3736
3837
=== modified file 'data/tribes/buildings/productionsites/empire/donkeyfarm/init.lua'
--- data/tribes/buildings/productionsites/empire/donkeyfarm/init.lua 2019-05-15 06:29:24 +0000
+++ data/tribes/buildings/productionsites/empire/donkeyfarm/init.lua 2019-05-19 16:18:33 +0000
@@ -31,7 +31,6 @@
31 },31 },
3232
33 aihints = {33 aihints = {
34 recruitment = true,
35 prohibited_till = 610,34 prohibited_till = 610,
36 },35 },
3736
3837
=== modified file 'data/tribes/empire.lua'
--- data/tribes/empire.lua 2018-07-29 13:49:09 +0000
+++ data/tribes/empire.lua 2019-05-19 16:18:33 +0000
@@ -350,7 +350,6 @@
350 soldier = "empire_soldier",350 soldier = "empire_soldier",
351 ship = "empire_ship",351 ship = "empire_ship",
352 port = "empire_port",352 port = "empire_port",
353 barracks = "empire_barracks",
354 ironore = "iron_ore",353 ironore = "iron_ore",
355 rawlog = "log",354 rawlog = "log",
356 refinedlog = "planks",355 refinedlog = "planks",
357356
=== modified file 'data/tribes/frisians.lua'
--- data/tribes/frisians.lua 2019-02-28 11:03:51 +0000
+++ data/tribes/frisians.lua 2019-05-19 16:18:33 +0000
@@ -349,7 +349,6 @@
349 soldier = "frisians_soldier",349 soldier = "frisians_soldier",
350 ship = "frisians_ship",350 ship = "frisians_ship",
351 port = "frisians_port",351 port = "frisians_port",
352 barracks = "frisians_barracks",
353 ironore = "iron_ore",352 ironore = "iron_ore",
354 rawlog = "log",353 rawlog = "log",
355 refinedlog = "brick",354 refinedlog = "brick",
356355
=== modified file 'data/tribes/workers/atlanteans/horse/init.lua'
--- data/tribes/workers/atlanteans/horse/init.lua 2017-02-12 09:10:57 +0000
+++ data/tribes/workers/atlanteans/horse/init.lua 2019-05-19 16:18:33 +0000
@@ -24,4 +24,10 @@
24 ware_hotspot = {-2, 12},24 ware_hotspot = {-2, 12},
2525
26 animations = animations,26 animations = animations,
27
28 aihints = {
29 preciousness = {
30 atlanteans = 2
31 },
32 }
27}33}
2834
=== modified file 'data/tribes/workers/atlanteans/soldier/init.lua'
--- data/tribes/workers/atlanteans/soldier/init.lua 2019-05-18 12:05:22 +0000
+++ data/tribes/workers/atlanteans/soldier/init.lua 2019-05-19 16:18:33 +0000
@@ -284,6 +284,12 @@
284 pictures = path.list_files(dirname .. "evade_level?.png"),284 pictures = path.list_files(dirname .. "evade_level?.png"),
285 },285 },
286286
287 aihints = {
288 preciousness = {
289 atlanteans = 5
290 },
291 },
292
287 -- Random animations for battle293 -- Random animations for battle
288 -- TODO(GunChleoc): Make more animations to use the random function294 -- TODO(GunChleoc): Make more animations to use the random function
289 attack_success_w = {295 attack_success_w = {
290296
=== modified file 'data/tribes/workers/barbarians/ox/init.lua'
--- data/tribes/workers/barbarians/ox/init.lua 2017-02-12 09:10:57 +0000
+++ data/tribes/workers/barbarians/ox/init.lua 2019-05-19 16:18:33 +0000
@@ -25,4 +25,10 @@
25 ware_hotspot = { -2, 13 },25 ware_hotspot = { -2, 13 },
2626
27 animations = animations,27 animations = animations,
28
29 aihints = {
30 preciousness = {
31 barbarians = 2
32 },
33 }
28}34}
2935
=== modified file 'data/tribes/workers/barbarians/soldier/init.lua'
--- data/tribes/workers/barbarians/soldier/init.lua 2019-04-26 19:10:45 +0000
+++ data/tribes/workers/barbarians/soldier/init.lua 2019-05-19 16:18:33 +0000
@@ -110,6 +110,12 @@
110 pictures = path.list_files(dirname .. "evade_level?.png"),110 pictures = path.list_files(dirname .. "evade_level?.png"),
111 },111 },
112112
113 aihints = {
114 preciousness = {
115 barbarians = 5
116 },
117 },
118
113 -- Random animations for battle119 -- Random animations for battle
114 attack_success_w = {120 attack_success_w = {
115 atk_ok_w = all_levels_bar,121 atk_ok_w = all_levels_bar,
116122
=== modified file 'data/tribes/workers/empire/donkey/init.lua'
--- data/tribes/workers/empire/donkey/init.lua 2017-02-12 09:10:57 +0000
+++ data/tribes/workers/empire/donkey/init.lua 2019-05-19 16:18:33 +0000
@@ -24,4 +24,10 @@
24 ware_hotspot = { -2, 8 },24 ware_hotspot = { -2, 8 },
2525
26 animations = animations,26 animations = animations,
27
28 aihints = {
29 preciousness = {
30 empire = 2
31 },
32 }
27}33}
2834
=== modified file 'data/tribes/workers/empire/soldier/init.lua'
--- data/tribes/workers/empire/soldier/init.lua 2019-04-26 19:10:45 +0000
+++ data/tribes/workers/empire/soldier/init.lua 2019-05-19 16:18:33 +0000
@@ -110,6 +110,12 @@
110 pictures = path.list_files(dirname .. "evade_level?.png"),110 pictures = path.list_files(dirname .. "evade_level?.png"),
111 },111 },
112112
113 aihints = {
114 preciousness = {
115 empire = 5
116 },
117 },
118
113 -- Random animations for battle119 -- Random animations for battle
114 attack_success_w = {120 attack_success_w = {
115 atk_ok_w = all_levels_emp,121 atk_ok_w = all_levels_emp,
116122
=== modified file 'data/tribes/workers/frisians/reindeer/init.lua'
--- data/tribes/workers/frisians/reindeer/init.lua 2018-02-06 11:17:48 +0000
+++ data/tribes/workers/frisians/reindeer/init.lua 2019-05-19 16:18:33 +0000
@@ -24,4 +24,10 @@
24 ware_hotspot = { 0, 18 },24 ware_hotspot = { 0, 18 },
2525
26 animations = animations,26 animations = animations,
27
28 aihints = {
29 preciousness = {
30 frisians = 2
31 },
32 }
27}33}
2834
=== modified file 'data/tribes/workers/frisians/soldier/init.lua'
--- data/tribes/workers/frisians/soldier/init.lua 2019-05-18 20:43:25 +0000
+++ data/tribes/workers/frisians/soldier/init.lua 2019-05-19 16:18:33 +0000
@@ -434,6 +434,12 @@
434 pictures = path.list_files (dirname .. "evade_level?.png"),434 pictures = path.list_files (dirname .. "evade_level?.png"),
435 },435 },
436436
437 aihints = {
438 preciousness = {
439 frisians = 5
440 },
441 },
442
437 -- Random animations for battle443 -- Random animations for battle
438 attack_success_e = {444 attack_success_e = {
439 atk_ok_1_w = fri_rookie,445 atk_ok_1_w = fri_rookie,
440446
=== modified file 'doc/sphinx/source/lua_tribes_workers.rst.org'
--- doc/sphinx/source/lua_tribes_workers.rst.org 2018-11-30 10:36:42 +0000
+++ doc/sphinx/source/lua_tribes_workers.rst.org 2019-05-19 16:18:33 +0000
@@ -17,60 +17,68 @@
1717
18Workers are defined with Lua functions called ``new_<worker_type>_type{table}``. The contents of ``table`` depend on the type of worker that you are defining. The common properties shared by all workers are:18Workers are defined with Lua functions called ``new_<worker_type>_type{table}``. The contents of ``table`` depend on the type of worker that you are defining. The common properties shared by all workers are:
1919
20 **msgctxt**: The context that Gettext will use to disambiguate the20**msgctxt**: The context that Gettext will use to disambiguate the
21 translations for strings in this table.21translations for strings in this table.
2222
23 **name**: A string containing the internal name of this worker.23**name**: A string containing the internal name of this worker.
2424
25 **descname**: The translatable display name. Use ``pgettext`` with the25**descname**: The translatable display name. Use ``pgettext`` with the
26 ``msgctxt`` above to fetch the string.26``msgctxt`` above to fetch the string.
2727
28 **helptext_script**: The full path to the ``helptexts.lua`` script for this worker.28**helptext_script**: The full path to the ``helptexts.lua`` script for this worker.
2929
30 **icon**: The full path to the menu icon for this worker.30**icon**: The full path to the menu icon for this worker.
3131
32 **vision_range**32**vision_range**
33 The size of the radius that the worker sees.33 The size of the radius that the worker sees.
3434
35 **buildcost**35**buildcost**
36 *Optional*. A table with the wares and workers used by warehouses to36 *Optional*. A table with the wares and workers used by warehouses to
37 create this worker, containing warename - amount pairs, e.g.::37 create this worker, containing warename - amount pairs, e.g.::
3838
39 buildcost = { atlanteans_carrier = 1, hammer = 1 }39 buildcost = { atlanteans_carrier = 1, hammer = 1 }
4040
41 **default_target_quantity**:41**default_target_quantity**:
42 *Optional*. An int defining the default target quantity for the worker's42 *Optional*. An int defining the default target quantity for the worker's
43 tribe's economy. Use this if the worker is produced by a production site43 tribe's economy. Use this if the worker is produced by a production site
44 rather than the warehouses. For example, ``default_target_quantity = 10``44 rather than the warehouses. For example, ``default_target_quantity = 10``
4545
46 **experience**46**experience**
47 *Optional*. The amount of experience that the worker needs to gather47 *Optional*. The amount of experience that the worker needs to gather
48 in order to be transformend into a higher worker type. If `becomes`48 in order to be transformend into a higher worker type. If `becomes`
49 is defined, this needs to be set as well.49 is defined, this needs to be set as well.
5050
51 **becomes**51**becomes**
52 *Optional*. The name of the higher worker type that this worker will52 *Optional*. The name of the higher worker type that this worker will
53 transform to after gaining enough experience. If `experience`53 transform to after gaining enough experience. If `experience`
54 is defined, this needs to be set as well.54 is defined, this needs to be set as well.
5555
56 **animations**:56**animations**:
57 A table containing all animations for this worker.57 A table containing all animations for this worker.
58 Workers have an "idle" animation. They also have directional animations58 Workers have an "idle" animation. They also have directional animations
59 called "walk" and "walkload" which are defined with the help of59 called "walk" and "walkload" which are defined with the help of
60 :func:`add_walking_animations`, plus additional :ref:`animations` used in their60 :func:`add_walking_animations`, plus additional :ref:`animations` used in their
61 worker programs. The "idle" and "walk" animations are mandatory.61 worker programs. The "idle" and "walk" animations are mandatory.
6262
63 **programs**:63**programs**:
64 *Optional*. If the worker leaves the building to do his work, the :ref:`tribes_worker_programs` that define which type of space or resource the worker has to find64 *Optional*. If the worker leaves the building to do his work, the
65 on the map in order to do his work, and what that work is, including any65 :ref:`tribes_worker_programs` that define which type of space or resource
66 animations and sounds played.66 the worker has to find on the map in order to do his work, and what that
6767 work is, including any animations and sounds played.
68 **ware_hotspot**68
69 *Optional*. The x, y coordinates for adjusting the placement of the69**ware_hotspot**
70 ware being carried. The default value is ``{0, 15}``. Increase ``x``70 *Optional*. The x, y coordinates for adjusting the placement of the
71 to shift the ware to the left and ``y`` to shift it upwards. For example::71 ware being carried. The default value is ``{0, 15}``. Increase ``x``
7272 to shift the ware to the left and ``y`` to shift it upwards. For example::
73 ware_hotspot = { -2, 13 },73
74 ware_hotspot = { -2, 13 },
75
76**aihints**
77 *Optional*. A list of hints for the AI. Can contain the following optional entries:
78
79 **preciousness**: How precious this worker is to each tribe. For example,
80 ``{ atlanteans = 0, empire = 1 }``. You can use this for workers that are recruited.
81
7482
75.. _lua_tribes_workers_helptexts:83.. _lua_tribes_workers_helptexts:
7684
7785
=== modified file 'src/ai/ai_help_structs.h'
--- src/ai/ai_help_structs.h 2019-05-05 14:05:07 +0000
+++ src/ai/ai_help_structs.h 2019-05-19 16:18:33 +0000
@@ -477,6 +477,7 @@
477 bool requires_supporters;477 bool requires_supporters;
478478
479 // information needed for decision on new building construction479 // information needed for decision on new building construction
480 int16_t initial_preciousness;
480 int16_t max_preciousness;481 int16_t max_preciousness;
481 int16_t max_needed_preciousness;482 int16_t max_needed_preciousness;
482483
483484
=== modified file 'src/ai/ai_hints.cc'
--- src/ai/ai_hints.cc 2019-02-23 11:00:49 +0000
+++ src/ai/ai_hints.cc 2019-05-19 16:18:33 +0000
@@ -223,7 +223,6 @@
223BuildingHints::BuildingHints(std::unique_ptr<LuaTable> table)223BuildingHints::BuildingHints(std::unique_ptr<LuaTable> table)
224 : mines_(table->has_key("mines") ? table->get_string("mines") : ""),224 : mines_(table->has_key("mines") ? table->get_string("mines") : ""),
225 needs_water_(table->has_key("needs_water") ? table->get_bool("needs_water") : false),225 needs_water_(table->has_key("needs_water") ? table->get_bool("needs_water") : false),
226 recruitment_(table->has_key("recruitment") ? table->get_bool("recruitment") : false),
227 space_consumer_(table->has_key("space_consumer") ? table->get_bool("space_consumer") : false),226 space_consumer_(table->has_key("space_consumer") ? table->get_bool("space_consumer") : false),
228 expansion_(table->has_key("expansion") ? table->get_bool("expansion") : false),227 expansion_(table->has_key("expansion") ? table->get_bool("expansion") : false),
229 fighting_(table->has_key("fighting") ? table->get_bool("fighting") : false),228 fighting_(table->has_key("fighting") ? table->get_bool("fighting") : false),
@@ -274,3 +273,28 @@
274 }273 }
275 NEVER_HERE();274 NEVER_HERE();
276}275}
276
277
278// TODO(GunChleoc): WareDescr has a bare "preciousness" table that should be moved below a new "aihints" table.
279void WareWorkerHints::read_preciousness(const LuaTable& table) {
280 for (const std::string& key : table.keys<std::string>()) {
281 preciousnesses_.insert(std::make_pair(key, table.get_int(key)));
282 }
283}
284
285/// Returns the preciousness of the ware, or kInvalidWare if the tribe doesn't use the ware.
286int WareWorkerHints::preciousness(const std::string& tribename) const {
287 if (preciousnesses_.count(tribename) > 0) {
288 return preciousnesses_.at(tribename);
289 }
290 return Widelands::kInvalidWare;
291}
292
293WareHints::WareHints(const LuaTable& table) : WareWorkerHints() {
294 read_preciousness(table);
295}
296
297
298WorkerHints::WorkerHints(const LuaTable& table) : WareWorkerHints() {
299 read_preciousness(*table.get_table("preciousness"));
300}
277301
=== modified file 'src/ai/ai_hints.h'
--- src/ai/ai_hints.h 2019-02-23 11:00:49 +0000
+++ src/ai/ai_hints.h 2019-05-19 16:18:33 +0000
@@ -23,9 +23,11 @@
23#include <memory>23#include <memory>
24#include <stdint.h>24#include <stdint.h>
25#include <string>25#include <string>
26#include <unordered_map>
2627
27#include "base/log.h"28#include "base/log.h"
28#include "base/macros.h"29#include "base/macros.h"
30#include "logic/widelands.h"
29#include "scripting/lua_table.h"31#include "scripting/lua_table.h"
3032
31namespace Widelands {33namespace Widelands {
@@ -56,10 +58,6 @@
56 return needs_water_;58 return needs_water_;
57 }59 }
5860
59 bool for_recruitment() const {
60 return recruitment_;
61 }
62
63 bool is_space_consumer() const {61 bool is_space_consumer() const {
64 return space_consumer_;62 return space_consumer_;
65 }63 }
@@ -110,7 +108,6 @@
110private:108private:
111 const std::string mines_;109 const std::string mines_;
112 const bool needs_water_;110 const bool needs_water_;
113 const bool recruitment_;
114 const bool space_consumer_;111 const bool space_consumer_;
115 const bool expansion_;112 const bool expansion_;
116 const bool fighting_;113 const bool fighting_;
@@ -131,4 +128,29 @@
131 DISALLOW_COPY_AND_ASSIGN(BuildingHints);128 DISALLOW_COPY_AND_ASSIGN(BuildingHints);
132};129};
133130
131/// Hints common to wares and workers
132struct WareWorkerHints {
133 WareWorkerHints() = default;
134
135 /// Returns the preciousness of the ware/worker, or kInvalidWare if the tribe doesn't use the ware/worker or the worker has no preciousness defined for the tribe.
136 int preciousness(const std::string& tribename) const;
137
138protected:
139 void read_preciousness(const LuaTable& table);
140
141private:
142 // tribename, preciousness. No default.
143 std::unordered_map<std::string, int> preciousnesses_;
144};
145
146/// Hints for wares
147struct WareHints : WareWorkerHints {
148 explicit WareHints(const LuaTable& table);
149};
150
151/// Hints for workers
152struct WorkerHints : WareWorkerHints {
153 explicit WorkerHints(const LuaTable& table);
154};
155
134#endif // end of include guard: WL_AI_AI_HINTS_H156#endif // end of include guard: WL_AI_AI_HINTS_H
135157
=== modified file 'src/ai/defaultai.cc'
--- src/ai/defaultai.cc 2019-05-17 11:45:39 +0000
+++ src/ai/defaultai.cc 2019-05-19 16:18:33 +0000
@@ -52,7 +52,7 @@
52#include "logic/player.h"52#include "logic/player.h"
53#include "logic/playercommand.h"53#include "logic/playercommand.h"
5454
55// following is in miliseconds (widelands counts time in ms)55// following is in milliseconds (widelands counts time in ms)
56constexpr int kFieldInfoExpiration = 12 * 1000;56constexpr int kFieldInfoExpiration = 12 * 1000;
57constexpr int kMineFieldInfoExpiration = 20 * 1000;57constexpr int kMineFieldInfoExpiration = 20 * 1000;
58constexpr int kNewMineConstInterval = 19000;58constexpr int kNewMineConstInterval = 19000;
@@ -517,7 +517,7 @@
517 for (DescriptionIndex i = 0; i < static_cast<DescriptionIndex>(game().tribes().nrwares()); ++i) {517 for (DescriptionIndex i = 0; i < static_cast<DescriptionIndex>(game().tribes().nrwares()); ++i) {
518 wares.at(i).producers = 0;518 wares.at(i).producers = 0;
519 wares.at(i).consumers = 0;519 wares.at(i).consumers = 0;
520 wares.at(i).preciousness = game().tribes().get_ware_descr(i)->preciousness(tribe_->name());520 wares.at(i).preciousness = game().tribes().get_ware_descr(i)->ai_hints().preciousness(tribe_->name());
521 }521 }
522522
523 const DescriptionIndex& nr_buildings = game().tribes().nrbuildings();523 const DescriptionIndex& nr_buildings = game().tribes().nrbuildings();
@@ -637,9 +637,6 @@
637 if (bh.is_space_consumer()) {637 if (bh.is_space_consumer()) {
638 bo.set_is(BuildingAttribute::kSpaceConsumer);638 bo.set_is(BuildingAttribute::kSpaceConsumer);
639 }639 }
640 if (bh.for_recruitment()) {
641 bo.set_is(BuildingAttribute::kRecruitment);
642 }
643 bo.expansion_type = bh.is_expansion_type();640 bo.expansion_type = bh.is_expansion_type();
644 bo.fighting_type = bh.is_fighting_type();641 bo.fighting_type = bh.is_fighting_type();
645 bo.mountain_conqueror = bh.is_mountain_conqueror();642 bo.mountain_conqueror = bh.is_mountain_conqueror();
@@ -658,6 +655,7 @@
658 bo.set_is(BuildingAttribute::kPort);655 bo.set_is(BuildingAttribute::kPort);
659 }656 }
660 bo.max_trainingsites_proportion = 100;657 bo.max_trainingsites_proportion = 100;
658 bo.initial_preciousness = 0;
661 bo.max_preciousness = 0;659 bo.max_preciousness = 0;
662 bo.max_needed_preciousness = 0;660 bo.max_needed_preciousness = 0;
663661
@@ -684,6 +682,26 @@
684 for (const DescriptionIndex& temp_output : prod.output_ware_types()) {682 for (const DescriptionIndex& temp_output : prod.output_ware_types()) {
685 bo.outputs.push_back(temp_output);683 bo.outputs.push_back(temp_output);
686 }684 }
685
686 // Read information about worker outputs
687 if (prod.output_worker_types().size() > 0) {
688 for (const DescriptionIndex& temp_output : prod.output_worker_types()) {
689 if (temp_output == tribe_->soldier()) {
690 bo.set_is(BuildingAttribute::kBarracks);
691 }
692 const WorkerHints* worker_hints = tribe_->get_worker_descr(temp_output)->ai_hints();
693 if (worker_hints != nullptr) {
694 const int worker_preciousness = worker_hints->preciousness(tribe_->name());
695 if (worker_preciousness != Widelands::kInvalidWare) {
696 bo.initial_preciousness += worker_preciousness;
697 }
698 }
699 }
700 if (!bo.is(BuildingAttribute::kBarracks) && bo.outputs.empty()) {
701 bo.set_is(BuildingAttribute::kRecruitment);
702 }
703 }
704
687 for (const auto& temp_position : prod.working_positions()) {705 for (const auto& temp_position : prod.working_positions()) {
688 bo.positions.push_back(temp_position.first);706 bo.positions.push_back(temp_position.first);
689 }707 }
@@ -719,9 +737,6 @@
719 if (bh.is_shipyard()) {737 if (bh.is_shipyard()) {
720 bo.set_is(BuildingAttribute::kShipyard);738 bo.set_is(BuildingAttribute::kShipyard);
721 }739 }
722 if (building_index == tribe_->barracks()) {
723 bo.set_is(BuildingAttribute::kBarracks);
724 }
725 // Identify refined log producer740 // Identify refined log producer
726 if (bo.outputs.size() == 1 && bo.outputs[0] == tribe_->refinedlog()) {741 if (bo.outputs.size() == 1 && bo.outputs[0] == tribe_->refinedlog()) {
727 bo.set_is(BuildingAttribute::kLogRefiner);742 bo.set_is(BuildingAttribute::kLogRefiner);
@@ -2489,20 +2504,23 @@
24892504
2490 // Now verifying that all 'buildable' buildings has positive max_needed_preciousness2505 // Now verifying that all 'buildable' buildings has positive max_needed_preciousness
2491 // if they have outputs, all other must have zero max_needed_preciousness2506 // if they have outputs, all other must have zero max_needed_preciousness
2492 if ((bo.new_building == BuildingNecessity::kNeeded ||2507
2493 bo.new_building == BuildingNecessity::kForced ||2508 if (bo.new_building == BuildingNecessity::kForbidden) {
2494 bo.new_building == BuildingNecessity::kAllowed ||2509 bo.max_needed_preciousness = 0;
2495 bo.new_building == BuildingNecessity::kNeededPending) &&2510 } else if ((bo.new_building == BuildingNecessity::kNeeded ||
2496 (!bo.outputs.empty() || bo.is(BuildingAttribute::kBarracks))) {2511 bo.new_building == BuildingNecessity::kForced ||
2512 bo.new_building == BuildingNecessity::kAllowed ||
2513 bo.new_building == BuildingNecessity::kNeededPending) &&
2514 (!bo.outputs.empty() || bo.initial_preciousness > 0)) { // bo.initial_preciousness signals that we have a worker output
2515 bo.max_needed_preciousness = std::max(bo.max_needed_preciousness, bo.initial_preciousness);
2516 bo.max_preciousness = std::max(bo.max_preciousness, bo.initial_preciousness);
2517
2497 if (bo.max_needed_preciousness <= 0) {2518 if (bo.max_needed_preciousness <= 0) {
2498 throw wexception("AI: Max presciousness must not be <= 0 for building: %s",2519 throw wexception("AI: Max preciousness must not be <= 0 for building: %s",
2499 bo.desc->name().c_str());2520 bo.desc->name().c_str());
2500 }2521 }
2501 } else if (bo.new_building == BuildingNecessity::kForbidden) {
2502 bo.max_needed_preciousness = 0;
2503 } else {2522 } else {
2504 // For other situations we make sure max_needed_preciousness is zero2523 // For other situations we make sure max_needed_preciousness is zero
2505
2506 assert(bo.max_needed_preciousness == 0);2524 assert(bo.max_needed_preciousness == 0);
2507 }2525 }
25082526
@@ -2965,7 +2983,6 @@
2965 }2983 }
29662984
2967 } else if (bo.is(BuildingAttribute::kRecruitment)) {2985 } else if (bo.is(BuildingAttribute::kRecruitment)) {
2968 bo.max_needed_preciousness = 2;
2969 prio += bo.primary_priority;2986 prio += bo.primary_priority;
2970 prio -= bf->unowned_land_nearby * 2;2987 prio -= bf->unowned_land_nearby * 2;
2971 prio -= (bf->enemy_nearby) * 100;2988 prio -= (bf->enemy_nearby) * 100;
@@ -4487,7 +4504,7 @@
4487 gametime &&4504 gametime &&
4488 site.site->can_start_working() &&4505 site.site->can_start_working() &&
4489 get_stocklevel(*site.bo, gametime) >4506 get_stocklevel(*site.bo, gametime) >
4490 (std::abs(management_data.get_military_number_at(168)) / 5)) {4507 static_cast<unsigned int>((std::abs(management_data.get_military_number_at(168)) / 5))) {
44914508
4492 if (connected_to_wh) {4509 if (connected_to_wh) {
4493 game().send_player_dismantle(*site.site);4510 game().send_player_dismantle(*site.site);
@@ -4980,42 +4997,41 @@
4980 // Let deal with productionsites now4997 // Let deal with productionsites now
4981 // First we iterate over outputs of building, count warehoused stock4998 // First we iterate over outputs of building, count warehoused stock
4982 // and deciding if we have enough on stock (in warehouses)4999 // and deciding if we have enough on stock (in warehouses)
4983 bo.max_preciousness = 0;5000
4984 bo.max_needed_preciousness = 0;5001 // Calulate preciousness
49855002 bo.max_preciousness = bo.initial_preciousness;
4986 if (!bo.is(BuildingAttribute::kBarracks)) { // barracks are now excluded from calculation5003 bo.max_needed_preciousness = bo.initial_preciousness;
4987 // preciousness is assigned below in this fuction5004 for (uint32_t m = 0; m < bo.outputs.size(); ++m) {
4988 for (uint32_t m = 0; m < bo.outputs.size(); ++m) {5005 DescriptionIndex wt(static_cast<size_t>(bo.outputs.at(m)));
4989 DescriptionIndex wt(static_cast<size_t>(bo.outputs.at(m)));5006
49905007 uint16_t target = tribe_->get_ware_descr(wt)->default_target_quantity(tribe_->name());
4991 uint16_t target = tribe_->get_ware_descr(wt)->default_target_quantity(tribe_->name());5008 if (target == Widelands::kInvalidWare) {
4992 if (target == Widelands::kInvalidWare) {5009 target = kTargetQuantCap;
4993 target = kTargetQuantCap;5010 }
4994 }5011 target /= 3;
4995 target /= 3;5012
49965013 // at least 1
4997 // at least 15014 target = std::max<uint16_t>(target, 1);
4998 target = std::max<uint16_t>(target, 1);5015
49995016 // it seems there are wares with 0 preciousness (no entry in init files?), but we need
5000 // it seems there are wares with 0 preciousness (no entry in init files?), but we need5017 // positive value here.
5001 // positive value here.5018 // TODO(GunChleoc): Since we require in Tribes::postload() that this is set for all wares used by a tribe, something seems to be wrong here. It should always be > 0.
5002 const uint16_t preciousness =5019 const uint16_t preciousness =
5003 std::max<uint16_t>(wares.at(bo.outputs.at(m)).preciousness, 1);5020 std::max<uint16_t>(wares.at(bo.outputs.at(m)).preciousness, 1);
50045021
5005 if (calculate_stocklevel(wt) < target ||5022 if (calculate_stocklevel(wt) < target ||
5006 site_needed_for_economy == BasicEconomyBuildingStatus::kEncouraged) {5023 site_needed_for_economy == BasicEconomyBuildingStatus::kEncouraged) {
5007 if (bo.max_needed_preciousness < preciousness) {5024 if (bo.max_needed_preciousness < preciousness) {
5008 bo.max_needed_preciousness = preciousness;5025 bo.max_needed_preciousness = preciousness;
5009 }5026 }
5010 if (site_needed_for_economy == BasicEconomyBuildingStatus::kEncouraged) {5027 if (site_needed_for_economy == BasicEconomyBuildingStatus::kEncouraged) {
5011 bo.max_needed_preciousness +=5028 bo.max_needed_preciousness +=
5012 std::abs(management_data.get_military_number_at(144)) / 10;5029 std::abs(management_data.get_military_number_at(144)) / 10;
5013 }5030 }
5014 }5031 }
50155032
5016 if (bo.max_preciousness < preciousness) {5033 if (bo.max_preciousness < preciousness) {
5017 bo.max_preciousness = preciousness;5034 bo.max_preciousness = preciousness;
5018 }
5019 }5035 }
5020 }5036 }
50215037
@@ -5102,12 +5118,7 @@
5102 }5118 }
51035119
5104 if (bo.forced_after < gametime && bo.total_count() == 0 && !has_substitution_building) {5120 if (bo.forced_after < gametime && bo.total_count() == 0 && !has_substitution_building) {
5105 if (!bo.is(BuildingAttribute::kBarracks)) {5121 bo.max_needed_preciousness = bo.max_preciousness;
5106 bo.max_needed_preciousness = bo.max_preciousness;
5107 } else {
5108 // barracks has no genuine preciousness as of now
5109 bo.max_needed_preciousness = 5;
5110 }
5111 return BuildingNecessity::kForced;5122 return BuildingNecessity::kForced;
5112 } else if (bo.prohibited_till > gametime) {5123 } else if (bo.prohibited_till > gametime) {
5113 return BuildingNecessity::kForbidden;5124 return BuildingNecessity::kForbidden;
@@ -5417,7 +5428,8 @@
5417 bo.max_preciousness = bo.max_needed_preciousness;5428 bo.max_preciousness = bo.max_needed_preciousness;
5418 return BuildingNecessity::kNeeded;5429 return BuildingNecessity::kNeeded;
5419 } else {5430 } else {
5420 assert(bo.max_needed_preciousness == 0);5431 bo.max_needed_preciousness = 0;
5432 bo.max_preciousness = 0;
5421 return BuildingNecessity::kForbidden;5433 return BuildingNecessity::kForbidden;
5422 }5434 }
5423 } else if (bo.type == BuildingObserver::Type::kMine) {5435 } else if (bo.type == BuildingObserver::Type::kMine) {
@@ -5829,7 +5841,7 @@
5829 return BuildingNecessity::kNeeded;5841 return BuildingNecessity::kNeeded;
5830 } else if (bo.inputs.size() == 1 &&5842 } else if (bo.inputs.size() == 1 &&
5831 calculate_stocklevel(static_cast<size_t>(bo.inputs.at(0))) >5843 calculate_stocklevel(static_cast<size_t>(bo.inputs.at(0))) >
5832 std::abs(management_data.get_military_number_at(171))) {5844 static_cast<unsigned int>(std::abs(management_data.get_military_number_at(171)))) {
5833 return BuildingNecessity::kNeeded;5845 return BuildingNecessity::kNeeded;
5834 } else {5846 } else {
5835 return BuildingNecessity::kNotNeeded;5847 return BuildingNecessity::kNotNeeded;
58365848
=== modified file 'src/logic/map_objects/tribes/tribe_descr.cc'
--- src/logic/map_objects/tribes/tribe_descr.cc 2019-05-04 10:47:44 +0000
+++ src/logic/map_objects/tribes/tribe_descr.cc 2019-05-19 16:18:33 +0000
@@ -199,7 +199,6 @@
199 }199 }
200200
201 port_ = add_special_building(table.get_string("port"));201 port_ = add_special_building(table.get_string("port"));
202 barracks_ = add_special_building(table.get_string("barracks"));
203202
204 ironore_ = add_special_ware(table.get_string("ironore"));203 ironore_ = add_special_ware(table.get_string("ironore"));
205 rawlog_ = add_special_ware(table.get_string("rawlog"));204 rawlog_ = add_special_ware(table.get_string("rawlog"));
@@ -328,10 +327,6 @@
328 assert(tribes_.building_exists(port_));327 assert(tribes_.building_exists(port_));
329 return port_;328 return port_;
330}329}
331DescriptionIndex TribeDescr::barracks() const {
332 assert(tribes_.building_exists(barracks_));
333 return barracks_;
334}
335DescriptionIndex TribeDescr::ironore() const {330DescriptionIndex TribeDescr::ironore() const {
336 assert(tribes_.ware_exists(ironore_));331 assert(tribes_.ware_exists(ironore_));
337 return ironore_;332 return ironore_;
338333
=== modified file 'src/logic/map_objects/tribes/tribe_descr.h'
--- src/logic/map_objects/tribes/tribe_descr.h 2019-03-01 04:19:53 +0000
+++ src/logic/map_objects/tribes/tribe_descr.h 2019-05-19 16:18:33 +0000
@@ -116,7 +116,6 @@
116 DescriptionIndex soldier() const;116 DescriptionIndex soldier() const;
117 DescriptionIndex ship() const;117 DescriptionIndex ship() const;
118 DescriptionIndex port() const;118 DescriptionIndex port() const;
119 DescriptionIndex barracks() const;
120 DescriptionIndex ironore() const;119 DescriptionIndex ironore() const;
121 DescriptionIndex rawlog() const;120 DescriptionIndex rawlog() const;
122 DescriptionIndex refinedlog() const;121 DescriptionIndex refinedlog() const;
@@ -206,7 +205,6 @@
206 DescriptionIndex soldier_; // The soldier that this tribe uses205 DescriptionIndex soldier_; // The soldier that this tribe uses
207 DescriptionIndex ship_; // The ship that this tribe uses206 DescriptionIndex ship_; // The ship that this tribe uses
208 DescriptionIndex port_; // The port that this tribe uses207 DescriptionIndex port_; // The port that this tribe uses
209 DescriptionIndex barracks_; // The barracks to create soldiers
210 DescriptionIndex ironore_; // Iron ore208 DescriptionIndex ironore_; // Iron ore
211 DescriptionIndex rawlog_; // Simple log209 DescriptionIndex rawlog_; // Simple log
212 DescriptionIndex refinedlog_; // Refined log, e.g. wood or blackwood210 DescriptionIndex refinedlog_; // Refined log, e.g. wood or blackwood
213211
=== modified file 'src/logic/map_objects/tribes/tribes.cc'
--- src/logic/map_objects/tribes/tribes.cc 2019-05-16 09:15:03 +0000
+++ src/logic/map_objects/tribes/tribes.cc 2019-05-19 16:18:33 +0000
@@ -357,7 +357,7 @@
357357
358 // Verify that the preciousness has been set for all of the tribe's wares358 // Verify that the preciousness has been set for all of the tribe's wares
359 for (const DescriptionIndex wi : tribe_descr->wares()) {359 for (const DescriptionIndex wi : tribe_descr->wares()) {
360 if (tribe_descr->get_ware_descr(wi)->preciousness(tribe_descr->name()) == kInvalidWare) {360 if (tribe_descr->get_ware_descr(wi)->ai_hints().preciousness(tribe_descr->name()) == kInvalidWare) {
361 throw GameDataError("The ware '%s' needs to define a preciousness for tribe '%s'",361 throw GameDataError("The ware '%s' needs to define a preciousness for tribe '%s'",
362 tribe_descr->get_ware_descr(wi)->name().c_str(),362 tribe_descr->get_ware_descr(wi)->name().c_str(),
363 tribe_descr->name().c_str());363 tribe_descr->name().c_str());
364364
=== modified file 'src/logic/map_objects/tribes/ware_descr.cc'
--- src/logic/map_objects/tribes/ware_descr.cc 2019-02-23 11:00:49 +0000
+++ src/logic/map_objects/tribes/ware_descr.cc 2019-05-19 16:18:33 +0000
@@ -35,7 +35,8 @@
35 * /data/tribes/wares/armor/init.lua35 * /data/tribes/wares/armor/init.lua
36 */36 */
37WareDescr::WareDescr(const std::string& init_descname, const LuaTable& table)37WareDescr::WareDescr(const std::string& init_descname, const LuaTable& table)
38 : MapObjectDescr(MapObjectType::WARE, table.get_string("name"), init_descname, table) {38 : MapObjectDescr(MapObjectType::WARE, table.get_string("name"), init_descname, table),
39 ai_hints_(new WareHints(*table.get_table("preciousness"))) {
39 if (helptext_script().empty()) {40 if (helptext_script().empty()) {
40 throw GameDataError("Ware %s has no helptext script", name().c_str());41 throw GameDataError("Ware %s has no helptext script", name().c_str());
41 }42 }
@@ -51,19 +52,9 @@
51 for (const std::string& key : items_table->keys<std::string>()) {52 for (const std::string& key : items_table->keys<std::string>()) {
52 default_target_quantities_.emplace(key, items_table->get_int(key));53 default_target_quantities_.emplace(key, items_table->get_int(key));
53 }54 }
5455}
55 items_table = table.get_table("preciousness");56
56 for (const std::string& key : items_table->keys<std::string>()) {57
57 preciousnesses_.emplace(key, items_table->get_int(key));
58 }
59}
60
61int WareDescr::preciousness(const std::string& tribename) const {
62 if (preciousnesses_.count(tribename) > 0) {
63 return preciousnesses_.at(tribename);
64 }
65 return kInvalidWare;
66}
6758
68DescriptionIndex WareDescr::default_target_quantity(const std::string& tribename) const {59DescriptionIndex WareDescr::default_target_quantity(const std::string& tribename) const {
69 if (default_target_quantities_.count(tribename) > 0) {60 if (default_target_quantities_.count(tribename) > 0) {
7061
=== modified file 'src/logic/map_objects/tribes/ware_descr.h'
--- src/logic/map_objects/tribes/ware_descr.h 2019-02-27 19:00:36 +0000
+++ src/logic/map_objects/tribes/ware_descr.h 2019-05-19 16:18:33 +0000
@@ -21,12 +21,14 @@
21#define WL_LOGIC_MAP_OBJECTS_TRIBES_WARE_DESCR_H21#define WL_LOGIC_MAP_OBJECTS_TRIBES_WARE_DESCR_H
2222
23#include <cstring>23#include <cstring>
24#include <memory>
24#include <string>25#include <string>
25#include <unordered_map>26#include <unordered_map>
2627
27#include <stdint.h>28#include <stdint.h>
2829
29#include "base/macros.h"30#include "base/macros.h"
31#include "ai/ai_hints.h"
30#include "logic/map_objects/map_object.h"32#include "logic/map_objects/map_object.h"
31#include "scripting/lua_table.h"33#include "scripting/lua_table.h"
3234
@@ -52,9 +54,10 @@
52 ~WareDescr() override {54 ~WareDescr() override {
53 }55 }
5456
55 /// Returns the preciousness of the ware, or kInvalidWare if the tribe doesn't use the ware.57 /// AI hints for this ware type
56 /// It is used by the computer player.58 const WareHints& ai_hints() const {
57 int preciousness(const std::string& tribename) const;59 return *ai_hints_;
60 }
5861
59 /// How much of the ware type an economy should store in warehouses.62 /// How much of the ware type an economy should store in warehouses.
60 /// The special value kInvalidWare means that the target quantity of this ware type will never be63 /// The special value kInvalidWare means that the target quantity of this ware type will never be
@@ -82,8 +85,9 @@
82private:85private:
83 // tribename, quantity. No default.86 // tribename, quantity. No default.
84 std::unordered_map<std::string, int> default_target_quantities_;87 std::unordered_map<std::string, int> default_target_quantities_;
85 // tribename, preciousness. No default.88
86 std::unordered_map<std::string, int> preciousnesses_;89 // Hints for the AI
90 std::unique_ptr<WareHints> ai_hints_;
8791
88 std::set<DescriptionIndex> consumers_; // Buildings that consume this ware92 std::set<DescriptionIndex> consumers_; // Buildings that consume this ware
89 std::set<DescriptionIndex> producers_; // Buildings that produce this ware93 std::set<DescriptionIndex> producers_; // Buildings that produce this ware
9094
=== modified file 'src/logic/map_objects/tribes/worker_descr.cc'
--- src/logic/map_objects/tribes/worker_descr.cc 2019-05-05 14:05:07 +0000
+++ src/logic/map_objects/tribes/worker_descr.cc 2019-05-19 16:18:33 +0000
@@ -52,6 +52,7 @@
52 becomes_(table.has_key("experience") ? tribes.safe_worker_index(table.get_string("becomes")) :52 becomes_(table.has_key("experience") ? tribes.safe_worker_index(table.get_string("becomes")) :
53 INVALID_INDEX),53 INVALID_INDEX),
54 needed_experience_(table.has_key("becomes") ? table.get_int("experience") : INVALID_INDEX),54 needed_experience_(table.has_key("becomes") ? table.get_int("experience") : INVALID_INDEX),
55 ai_hints_(table.has_key("aihints") ? new WorkerHints(*table.get_table("aihints")) : nullptr),
55 tribes_(tribes) {56 tribes_(tribes) {
56 if (helptext_script().empty()) {57 if (helptext_script().empty()) {
57 throw GameDataError("Worker %s has no helptext script", name().c_str());58 throw GameDataError("Worker %s has no helptext script", name().c_str());
5859
=== modified file 'src/logic/map_objects/tribes/worker_descr.h'
--- src/logic/map_objects/tribes/worker_descr.h 2019-05-11 13:48:12 +0000
+++ src/logic/map_objects/tribes/worker_descr.h 2019-05-19 16:18:33 +0000
@@ -22,6 +22,7 @@
2222
23#include <memory>23#include <memory>
2424
25#include "ai/ai_hints.h"
25#include "base/macros.h"26#include "base/macros.h"
26#include "graphic/diranimations.h"27#include "graphic/diranimations.h"
27#include "logic/map_objects/bob.h"28#include "logic/map_objects/bob.h"
@@ -116,6 +117,11 @@
116 return programs_;117 return programs_;
117 }118 }
118119
120 /// AI hints for this worker type. Can be nullptr.
121 const WorkerHints* ai_hints() const {
122 return ai_hints_.get();
123 }
124
119protected:125protected:
120 Programs programs_;126 Programs programs_;
121127
@@ -145,6 +151,9 @@
145 std::set<DescriptionIndex> employers_;151 std::set<DescriptionIndex> employers_;
146152
147private:153private:
154 // Hints for the AI
155 std::unique_ptr<WorkerHints> ai_hints_;
156
148 const Tribes& tribes_;157 const Tribes& tribes_;
149 DISALLOW_COPY_AND_ASSIGN(WorkerDescr);158 DISALLOW_COPY_AND_ASSIGN(WorkerDescr);
150};159};

Subscribers

People subscribed via source and target branches

to status/vote changes: