Commit graph

212 commits

Author SHA1 Message Date
mattsc
a781139536 generic_recruit_engine: remove unnecessary variable assignment 2018-09-07 09:50:51 -07:00
mattsc
dcadab91a4 Lua AIs: use ai_helper.get_locations_no_borders() 2018-09-07 09:50:42 -07:00
mattsc
10463fdf60 ai_helper: new function get_locations_no_borders() 2018-09-07 09:50:23 -07:00
mattsc
75843541bc 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.
2018-09-05 19:38:28 -07:00
mattsc
a7d80240f2 ai_helper: get_unit functions should only return live units
Live beiing defined as in get_live_units(), that is, non-petrified units
2018-09-05 19:34:44 -07:00
mattsc
23f35546fc Lua AIs: remove commented-out debug code 2018-09-03 14:48:10 -07:00
mattsc
35ba820509 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).
2018-09-03 11:05:49 -07:00
mattsc
b92d8e8226 recruit_rushers CA: don't reserve village for passive leader 2018-09-03 08:01:28 -07:00
mattsc
0bcb98cf50 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.
2018-09-03 07:40:27 -07:00
mattsc
45a3bf9363 Lua AIs: replace tabs with spaces 2018-09-02 15:08:24 -07:00
mattsc
3bfd59f28b 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.
2018-09-02 13:20:34 -07:00
mattsc
42b4430841 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.
2018-09-01 14:29:51 -07:00
mattsc
5474785718 Experimental AI: convert to using external CAs 2018-08-31 18:31:29 -07:00
mattsc
c2635abde1 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.
2018-08-31 07:04:58 -07:00
mattsc
35d257f8fd 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.
2018-08-30 17:37:12 -07:00
mattsc
a23f06dc20 Lua AIs: don't initiate variables as empty tables
... if they might not be needed.
2018-08-30 17:27:18 -07:00
mattsc
0e7c09f7b5 Lua AIs: no need to set variables to nil explicitely
This is mostly done for consistency across the Lua AI code
2018-08-30 07:35:57 -07:00
mattsc
cb423b2fbd Lua AIs: use math.huge to initialize extrema variables 2018-08-30 07:18:04 -07:00
mattsc
8a996c55b9 Lua AIs: remove inclusions of unused libraries 2018-08-29 08:00:32 -07:00
mattsc
5335a2af33 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.
2018-08-29 07:27:24 -07:00
mattsc
aa59ac5455 Lua AIs: avoid using __cfg for accessing weapon specials 2018-08-28 19:07:42 -07:00
mattsc
8af988c697 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.
2018-08-27 12:34:29 -07:00
mattsc
3f54908b0b Lua AIs: replace print() by std_print() 2018-08-27 07:30:24 -07:00
mattsc
83c4ef2418 Lua AIs: remove unused debug output 2018-08-27 07:29:24 -07:00
mattsc
a6866390df Lua AIs: use unit methods instead of wesnoth functions 2018-08-27 07:05:43 -07:00
mattsc
972ecc2f56 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.
2018-06-07 06:44:55 -07:00
mattsc
a6c0012689 Experimental AI recruiting: use math.huge instead of 9e99 2018-05-20 14:55:17 -07:00
mattsc
f810504306 Experimental AI: clear recruit cache when no recruit action found 2018-05-20 14:55:01 -07:00
mattsc
a65605c547 Fix Experimental AI not working without enemy units
An example are the first two turns of Dark Forecast.
2018-05-20 14:54:45 -07:00
mattsc
4b6681a300 Do not load helper.lua where it is not used any more 2018-05-13 20:53:01 -07:00
mattsc
1684e2f5da Remove unnecessary inclusions of helper.set_wml_action_metatable {} 2018-05-13 20:52:51 -07:00
mattsc
7c137e1a33 Lua code: replace deprecated helper.child_range() calls 2018-05-13 20:52:08 -07:00
mattsc
f0bb40590f Lua code: replace deprecated helper.get_child() calls 2018-05-13 20:51:56 -07:00
Charles Dang
3a90f86674 Addressed more whitespace issues from #2613
[ci skip]
2018-03-12 03:48:59 +11:00
Charles Dang
471c9e876a Addressed a large chunk of the whitespace issues from #2613
[ci skip]
2018-03-09 11:37:00 +11:00
Celtic Minstrel
dabf09fce1 Fix deprecation spam
This removes the Lua deprecation_message function in favour of exposing the C++ variant to Lua instead.
It also moves all deprecation messages to a separate logdomain, making them easily enabled en masse.
2018-03-04 21:21:33 -05:00
mattsc
3b2077fdc3 Fast Micro AI ai_helper functions: fix rarely occurring bug
When the AI moves a unit out of the way for another unit’s move, it is
occasionally possible for the former unit to use up all its movement
points (e.g. if it has few MP or on narrow crowded maps). If that unit
is on the list to be moved later during the same sequence, this caused
ai_helper.robust_move_and_attack() to return nil, which then made the
Fast Micro AI produce an error message.
2017-11-08 22:33:24 -08:00
Jozrael
e175bb1c7d Fix crash when unable to find closest enemy. 2017-10-02 14:43:16 -07:00
Celtic Minstrel
d192f07123 Implement standard deprecation system for Lua API
(as proposed by @DeFender1031)

All existing deprecation messages in the Lua code have been changed to
use the new deprecation system.

The goal is to eventually use an equivalent system for ALL areas of the API.
2017-08-14 12:36:09 -04:00
Celtic Minstrel
6efc5ae090 Replace helper.distance_between -> wesnoth.map.distance_between (fixes #1686) 2017-05-11 04:14:03 -04:00
Celtic Minstrel
0539a68eb4 Migrate ai_helper.LS_random_hex to location_set:random 2017-05-10 17:40:21 -04:00
Celtic Minstrel
f6c04e7dd1 Add functional.lua which implements higher-order functions
This covers all the main higher-order functions included in WFL, except zip.
The two already implemented in ai_helper have been replaced with redirection stubs.
2017-05-10 17:40:20 -04:00
Celtic Minstrel
9b635994e1 Add location_set.(of|to)_triples (migrated from ai_helper) 2017-05-10 17:40:14 -04:00
Celtic Minstrel
37f1c490a5 Lua: Use the second argument to error() where appropriate 2017-05-10 17:40:13 -04:00
Celtic Minstrel
8d4cf3cf62 Shorten requires where possible 2017-05-03 02:42:25 -04:00
mattsc
36b2b4e9a7 AI helper functions: consistently ignore shroud when path finding
This is the default Wesnoth AI behavior. It is done in a way that still
ignores hidden units.
2016-12-09 18:57:18 -08:00
mattsc
8d76ad32b0 ai_helper: new function find_path_with_shroud() 2016-12-09 18:53:40 -08:00
mattsc
70b9aea5a4 High-XP Attack CA: do not use AI leader for this type of attack
Otherwise it is too easy to exploit this by baiting the AI leader to
run into a trap, and it is too difficult for what it's worth to make
sure the attack location is safe. If only the side leader is left to do
such an attack, it's more often than not not a good idea to do so
anyway.
2016-11-01 06:27:38 -07:00
mattsc
fa48c9c2ac ai_helper: compare unit proxies directly, not by coordinate
This was not possible when this code was first written, but it is valid
syntax now.
2016-10-22 15:14:26 -07:00
mattsc
acecd77bb4 Lua AIs: use new syntax for iterating over attacks
This is both simpler and faster than the old syntax.
2016-10-22 13:54:32 -07:00