Commit graph

353 commits

Author SHA1 Message Date
mattsc
620da22082 AI: fix score assignment in castle switch candidate action 2019-12-06 08:14:56 -08:00
mattsc
f5990b7e95 ai_helper.get_attackable_enemies: add optional parameter 'avoid_map' 2019-12-06 08:14:56 -08:00
mattsc
891ca93710 ai_helper.put_labels: add two optional parameters 2019-12-06 08:14:45 -08:00
Celtic Minstrel
732b7942bb Replace all references to deprecated functions in the helper module
(and remove the require if this meant it was no longer used)
2019-12-02 01:10:34 -05:00
mattsc
fdb3f2e71a ai_helper.next_hop: add optional parameter 'avoid_map' 2019-11-29 19:22:56 -08:00
mattsc
4e80a8f028 ai_helper.next_hop: add option to use pre-evaluated path 2019-11-29 19:22:56 -08:00
mattsc
bb23781b17 ai_helper: new function find_path_with_avoid()
This lets the AI find paths around areas defined by [avoid] tags, rather than being stopped dead by them. See comments in the code for details.

The relevant custom cost function, custom_cost_with_avoid(), can be accessed directly as well.
2019-11-29 19:22:56 -08:00
mattsc
3e70358d8d AI: ensure all CAs respect unit guardian status
This adds the correct behavior for the castle_switch, move_to_any_enemy and place_healers CAs.  It was already in place for the other former ExpAI CAs (except for recruiting and spread_poison, for which it does not apply).

This automatically also adds this behavior to the Healer Support Micro AI.
2019-11-29 19:22:56 -08:00
Celtic Minstrel
3734bce276 Lua: Replace uses of deprecated (moved) sides functions 2019-11-23 14:41:03 -05:00
mattsc
1816ee5249 AI: add [filter_own] to all Experimental AI candidate actions 2019-11-21 19:15:11 -08:00
mattsc
997e08c5d3 Experimental AI: fix bug in move_to_any_enemy CA
Previously, if the best move found for a unit was its own position, the entire CA would be blacklisted and no other unit would be moved.
2019-11-21 13:04:26 -08:00
mattsc
626d7ee381 AI: add [filter_own] to all default AI candidate actions
This allows restricting each CA individually to only a subset of the units. It also means that several instances of the same CA can be used in the same AI configuration, in order to, for example, force the order in which units are dealt with, or to apply different settings to different units.
2019-11-21 12:09:33 -08:00
Celtic Minstrel
aaa2dc4ece Rollback possibility of wesnoth.get_units matching recall list units
Now it's renamed to wesnoth.units.find_on_map.

wesnoth.units.find implements the case of finding units on either the map or a recall list.
2019-11-15 22:39:09 -05:00
Celtic Minstrel
977f05d77f Lua: Replace uses of deprecated (moved) unit functions
Also backtracked the removal of wesnoth.get_recall_units, which is now available as wesnoth.units.find_on_recall - it's just more convenient than passing x=recall to wesnoth.units.find
2019-11-15 22:39:08 -05:00
mattsc
cbf99a6f00 Fred ExpAI recruiting: set initial conditions for first recruit
Without this, the AI always starts with whatever it considers the best unit without taking the level bonus into account. This mostly only matters when one sets high_level_fraction to a very large value (1 or larger) in order to force only high-level recruits. In other cases it makes no, or no significant, difference.
2019-10-08 13:24:13 -07:00
mattsc
a51dee6761 Exp AI recruiting: add randomness as an optional parameter
This was already an optional parameter for the Recruit Rushers Micro AI.
2019-10-08 12:47:31 -07:00
mattsc
6dc199d4f8 ExpAI recruiting: make high_level_fraction parameter configurable
This also sets its default value to zero, in order to have consistent default behavior with versions from before this parameter was introduced.

It also provides a macro so that the ExpAI can be used with custom parameters in a scenario config, and adds high_level_fraction as an optional parameter to the Recruit Rushers Micro AI.
2019-10-08 12:45:59 -07:00
mattsc
b8d1ef94f0 Experimental AI: make AI recruit higher level units
Because unit cost is penalized in the ExpAI, it recruits almost no higher level units. This adds a bonus for such units to be recruited at approximately the ratio defined in 'high_level_fraction'.
2019-10-08 07:15:47 -07:00
mattsc
036bf8b6ae Experimental AI: fix poisoners ignoring [avoid] tag 2019-10-05 19:24:40 -07:00
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 a781139536)
2018-10-07 03:24:56 +00:00
mattsc
56934ad576 Lua AIs: use ai_helper.get_locations_no_borders()
(cherry-picked from commit dcadab91a4)
2018-10-07 03:24:56 +00:00
mattsc
319c98d616 ai_helper: new function get_locations_no_borders()
(cherry-picked from commit 10463fdf60)
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 75843541bc)
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 a7d80240f2)
2018-10-07 03:24:54 +00:00
mattsc
7e63932c8e Lua AIs: remove commented-out debug code
(cherry-picked from commit 23f35546fc)
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 35ba820509)
2018-10-07 03:24:51 +00:00
mattsc
e78237c2a9 recruit_rushers CA: don't reserve village for passive leader
(cherry-picked from commit b92d8e8226)
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 0bcb98cf50)
2018-10-07 03:24:50 +00:00