284 Commits

Author SHA1 Message Date
mattsc
f5b6b50565 Experimental AI: fix guardians being used for village actions 2019-09-19 19:16:48 -07:00
mattsc
e148d25d2a ExpAI grab villages CA: fix enemy distance rating under fog
ai_helper.get_closest_enemy() returns math.huge for the enemy distance if no enemy is visible to the AI. This fixes #4157.
2019-07-10 08:07:11 -07:00
mattsc
59397a40b5 ExpAI recruiting: fix AI crash for unit type with unknown race 2018-11-13 06:53:20 -08:00
mattsc
bc956b3e7f Lua AIs: fix experience for killing level 0 units 2018-11-09 06:52:08 -08:00
mattsc
1856377d35 Lua AIs: distinguish between healing locations and villages
There are rating contributions for hexes which heal (not all of which are villages) and others for hexes that provide income (villages). Previously only villages were considered for both types of hexes.
2018-11-07 12:24:31 -08:00
mattsc
8bca955ad5 ai_helper: new function get_healing_locations() 2018-11-07 12:17:55 -08:00
mattsc
c1343227e2 Generic recruit engine: cache pathfinding data
This results in a significant speed-up starting from the second recruit each turn.
2018-11-06 09:44:03 -08:00
mattsc
e379cf7333 Generic recruit engine: replace slow location filters 2018-11-06 09:38:33 -08:00
mattsc
0c57ae16e4 Lua AIs: do not use hard-coded values for modifiable parameters 2018-11-05 20:22:11 -08:00
mattsc
e3b2cbfc25 ExpAI recruiting: consider all villages not owned by allies
Instead of only the unowned villages.
2018-11-05 07:19:23 -08:00
mattsc
5e0df80ad0 ExpAI retreating: take healthy trait into account 2018-11-05 07:02:46 -08:00
mattsc
dcf951434e Micro AIs: support named locations for [micro_ai] tag keys 2018-11-05 07:02:33 -08:00
mattsc
8676d3eaf1 ExpAI recruiting: add optional 'enemy_types' parameter
Ths is the enemy type list to be considered if the AI has no information about the enemies to expect, that is, if no enemy units are on the map and no enemy recruit lists can be found. It can be used to prepare AI recruiting for enemy sides that get added later during a scenario.
2018-11-02 15:43:14 -07:00
mattsc
df4065c061 ai_helper: new function get_reachmap()
This is a generalized version of ai_helper.get_reachable_unocc(). It can include or exclude hexes with own units with moves > 0. It also allows passing an optional location set 'avoid_map' with hexes to be excluded.

In principle, this makes get_reachable_unocc() unnecessary, but we keep that function for backward compatibility.
2018-10-30 07:37:52 -07:00
mattsc
ae22b2e08f ai_helper: new function get_avoid_map()
The goal is to add [avoid] tag capabilitiy to most Micro AIs.
2018-10-29 07:06:46 -07:00
mattsc
a831edda6b ai_helper.get_closest_enemy: change return values
This is done for consistency with similar functions in mainline, and so that the function actual returns what it name says. This breaks backward compatibility, but note that the only practical difference for that is the order in which the arguments are returned, as both 'closest_enemy' and 'location' contain the enemy location in .x/.y format.
2018-10-27 16:24:13 -07:00
mattsc
5c73537412 ai_helper.lua: deprecate some functions 2018-10-26 07:19:13 -07:00
mattsc
cd8af96607 ai_helper.find_best_move: return nil instead of {} if no move found
This is done for consistency with similar functions in mainline. In principle this breaks backward compatibility.  However, while it is theoretically possible for this to happen, this function will generally always return at least the hex the unit is on, so it is very unlikely that this actually makes a difference somewhere.
2018-10-26 07:19:13 -07:00
mattsc
41bd835f76 Old patrol.lua: deprecation message should not be translatable 2018-10-24 19:53:45 -07:00
mattsc
e3b86f5648 Lua AIs: increase deprecation level of old ai/lua/patrol.lua 2018-10-24 19:51:53 -07:00
mattsc
5fe283d06c Lua AIs: use wesnoth.label instead of wml_action_metatable 2018-10-24 19:50:09 -07:00
mattsc
09e3891668 ai_helper.move_unit_out_of_way: prevent potential for divide-by-zero
dx = dy = 0 is a perfectly acceptable choice of values when there is no preferred direction.
2018-10-21 19:30:34 -07:00
mattsc
c5e41497e1 generic_recruit_engine: remove unnecessary variable assignment
(cherry-picked from commit a7811395363f9edd1a40adb11e0748bd0b81c385)
2018-10-07 03:24:56 +00:00
mattsc
56934ad576 Lua AIs: use ai_helper.get_locations_no_borders()
(cherry-picked from commit dcadab91a418f4f7392bab2544367df580d46ecf)
2018-10-07 03:24:56 +00:00
mattsc
319c98d616 ai_helper: new function get_locations_no_borders()
(cherry-picked from commit 10463fdf608ade3ff223a58ad7cc43a1e475b803)
2018-10-07 03:24:56 +00:00
mattsc
46efcf15fd Lua AIs: use ai_helper get_unit functions where applicable
The ai_helper functions are optimized for speed (as much as possible in a general setting) and do all the necessary tests.  For example, get_units_with_attacks() checks both whether the unit has attacks left, and whether it has any attacks in the first place.

(cherry-picked from commit 75843541bcf92e743b911ef49046c54a050e8a0f)
2018-10-07 03:24:55 +00:00
mattsc
44ceaa1874 ai_helper: get_unit functions should only return live units
Live beiing defined as in get_live_units(), that is, non-petrified units

(cherry-picked from commit a7d80240f2ca11b01e14120f80cd9ecace3eaa85)
2018-10-07 03:24:54 +00:00
mattsc
7e63932c8e Lua AIs: remove commented-out debug code
(cherry-picked from commit 23f35546fc31c6345acc24624039f16a92bbb8b7)
2018-10-07 03:24:52 +00:00
mattsc
4999b20bd1 Experimental AI: adjustments to candidate action scores
The relative ranking of the CA scores is not changed, except for one case when two CAs had the same score.

Reasons:
- All scores should be lower than the scores of the default Goto CA (200,000) and the default scores of most Micro AIs (300,000).
- Break tie, resulting in uncertain order of execution, of place_healers and retreat_injured CA. Healers should be placed first, to allow retreating injured units to adjacent hexes.
- Set default for generic_recruit_engine to slightly above default AI recruiting score. That way it takes effect even if the default CA is not removed.
- Increase move_to_any_enemy CA score from 1 to 1,000. It is still the lowest score that way, but allows for setting up custom CAs with even lower scores (even if it is just for end-of-turn statistics or the like).

(cherry-picked from commit 35ba82050954c2cee86321e05d6706993c08e143)
2018-10-07 03:24:51 +00:00
mattsc
e78237c2a9 recruit_rushers CA: don't reserve village for passive leader
(cherry-picked from commit b92d8e822639a90ca8bbfeaf8dea606e7cf4c8f2)
2018-10-07 03:24:51 +00:00
mattsc
aea3a4f7cb recruit_rushers CA: check if castle_switch CA is present
So that it is possible to use the recruit_rushers CA without the castle_switch CA.

(cherry-picked from commit 0bcb98cf5026710871d8b90919752c90808c56d0)
2018-10-07 03:24:50 +00:00
mattsc
c52ce11e49 Lua AIs: replace tabs with spaces
(cherry-picked from commit 45a3bf93636fb7b34b27a3411784d0484eeb18d6)
2018-10-07 03:24:49 +00:00
mattsc
ed406495d7 Lua AIs: do not use engine's 'data' variable unless necessary
Now that all the AIs use external CAs, there is no need to use the persistent 'data' variable any more, unless information is to be exchanged between different CAs or is supposed to be persistent across save/load cycles.

(cherry-picked from commit 3bfd59f28ba7f70a6ac32782e98cba9ca6c2a44a)
2018-10-07 03:24:48 +00:00
mattsc
2b6b1ed4fe Lua AIs: avoid calling wesnoth.get_terrain() more than needed
It probably doen't make a noticeable difference for these AIs, but in general we should not call the slow functions more than necessary.

(cherry-picked from commit 42b443084125ab7a989465e5f7f19835a17ba85b)
2018-10-07 03:24:45 +00:00
mattsc
800947594c Experimental AI: convert to using external CAs
(cherry-picked from commit 547478571871ffe59c5cf7ff59339a72a61c07dc)
2018-10-07 03:24:44 +00:00
mattsc
59c7162b51 Experimental AI: fix eval/exec debug output
This involves making the output independent of the stats CA (which is not used any more) and adding missing output to some CAs.

(cherry-picked from commit c2635abde1c6eea8bb74019ab78c61bddb219fff)
2018-10-07 03:24:43 +00:00
mattsc
8799772621 Lua AIs: don't compare variables with nil
... unless there is a difference between nil and false. Done mostly for consistency with all the other uses.

(cherry-picked from commit 35d257f8fd35fad70539dfdc57da69e38bc10536)
2018-10-07 03:24:43 +00:00
mattsc
e68a6eaba0 Lua AIs: don't initiate variables as empty tables
... if they might not be needed.

(cherry-picked from commit a23f06dc2052ece4d6de9fc1d80008f82761be4f)
2018-10-07 03:24:42 +00:00
mattsc
f761493c75 Lua AIs: no need to set variables to nil explicitely
This is mostly done for consistency across the Lua AI code

(cherry-picked from commit 0e7c09f7b549bb43aec248bad04fcf0bffef17d5)
2018-10-07 03:24:40 +00:00
mattsc
37e83f1262 Lua AIs: use math.huge to initialize extrema variables
(cherry-picked from commit cb423b2fbd40fdf5e14549a301fee06237bf4626)
2018-10-07 03:24:40 +00:00
mattsc
08825afce5 Lua AIs: remove inclusions of unused libraries
(cherry-picked from commit 8a996c55b968b14b04a551db46b7ab3de735696f)
2018-10-07 03:24:39 +00:00
mattsc
6ad4c7e42d Lua AI utility functions: fix for chance-to-hit specials without id
All mainline chance-to-hit weapon specials have ids, but it is not required for UMC specials.

(cherry-picked from commit 5335a2af335ffdce65097e26359e96a0cbe2c733)
2018-10-07 03:24:39 +00:00
mattsc
3906d78abd Lua AIs: avoid using __cfg for accessing weapon specials
(cherry-picked from commit aa59ac54557bc24615cb3f990bcd1dbf6f5d1ea9)
2018-10-07 03:24:39 +00:00
mattsc
b5c8c60ad0 Lua AIs: get unit cost/level directly from proxy unit
These used to be accessible only through unit.__cfg or wesnoth.unit_types.  The Fast Micro AI is not included here as it requires a larger clean-up.

(cherry-picked from commit 8af988c6972abe75e985d0e43bd8186fe4826cb6)
2018-10-07 03:24:37 +00:00
mattsc
fbbbcfc67e Lua AIs: replace print() by std_print()
(cherry-picked from commit 3f54908b0ba69173442107105889caeb891b922d)
2018-10-07 03:24:36 +00:00
mattsc
98e5f0892e Lua AIs: remove unused debug output
(cherry-picked from commit 83c4ef24189c9986eae7535b10ba4babb921e3b8)
2018-10-07 03:24:36 +00:00
mattsc
25b2024ee8 Lua AIs: use unit methods instead of wesnoth functions
(cherry-picked from commit a6866390dfa64097fa4cb099b39736c3e2220ce4)
2018-10-07 03:24:36 +00:00
mattsc
674a39a43e AI helper: improve efficiency of get_unit functions
The old method is very slightly faster in some circumstances (e.g. for
simple filters and when all units have moves/attacks/etc. left), but we
are talking fractions of micro seconds. By contrast, depending on the
filter used, the new method can save large amounts of evaluation time
once some units have move or attacked.

(cherry-picked from commit 972ecc2f56c3cc1391db165518324b1a3757431d)
2018-10-07 03:22:20 +00:00
mattsc
0c707294cb Experimental AI recruiting: use math.huge instead of 9e99
(cherry-picked from commit a6c0012689b39d74e2d9578f17010a048ef7d296)
2018-10-07 03:21:29 +00:00
mattsc
f1eacc51ad Experimental AI: clear recruit cache when no recruit action found
(cherry-picked from commit f810504306f7b97bd5e532793b36591ada8ba671)
2018-10-07 03:21:29 +00:00