Commit graph

462 commits

Author SHA1 Message Date
Celtic Minstrel
153680400d Unify the Lua and WFL interfaces to the movement type
See changelog for details.
2019-11-23 00:59:36 -05:00
gfgtdf
1db9d63435
remove unused variable 2019-11-18 19:53:47 +01:00
gfgtdf
45a33e6e3a add wesnoth.create_side()
wesnoth.create_side() can create a side while the scenario
is running, this is especially useful for [modification]s
that can not define sides by default.
2019-11-18 18:56:38 +01:00
Celtic Minstrel
212a91113c Convert wesnoth.sides to a module and move several functions to it
The old names still work but are deprecated.

In addition, all the moved functions now accept either a side number or a side userdata as the first parameter.
2019-11-17 11:35:56 -05:00
Celtic Minstrel
498a3e98c4 Lua: Flip functions moved to the gui module
This means that they are now added to the gui module by default in C++, and only duplicated to the Wesnoth module in Lua.
2019-11-16 12:57:50 -05:00
Celtic Minstrel
f016ac7183 Lua: Flip functions moved to the interface module, as well as the theme_items table
This means that they are now added to the interface  module by default in C++, and only duplicated to the Wesnoth module in Lua.

Some additional functions were moved:
- wesnoth.scroll -> wesnoth.interface.scroll
- wesnoth.zoom -> wesnoth.interface.zoom
- wesnoth.get_mouseover_tile -> wesnoth.interface.get_hovered_hex
- wesnoth.color_adjust -> wesnoth.interface.color_adjust
- wesnoth.set_menu_item -> wesnoth.interface.set_menu_item
- wesnoth.clear_menu_item -> wesnoth.interface.clear_menu_item

Added wesnoth.units.get_hovered as an alias of wesnoth.interface.get_displayed_unit
2019-11-16 12:24:31 -05:00
Celtic Minstrel
abe117b08f fixup! Make the attacker argument to wesnoth.units.resistance optional 2019-11-15 23:29:58 -05:00
Celtic Minstrel
18df2fd910 Make the attacker argument to wesnoth.units.resistance optional 2019-11-15 22:39:09 -05: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
6a87f5d48d Remove Lua implementation of wesnoth.units.find_on_recall
Since there's already a native C++ version we might as well just use it.
2019-11-15 22:39:08 -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
Celtic Minstrel
4dc986f028 Lua: Flip functions moved to the units module
This means that they are now added to the units module by default in C++, and only duplicated to the Wesnoth module in Lua.

Some additional functions were moved:
- wesnoth.create_unit -> wesnoth.units.create
- wesnoth.get_units -> wesnoth.units.find
- wesnoth.get_unit -> wesnoth.units.get

Deprecated wesnoth.get_recall_units in favour of wesnoth.get_units, which has gained the ability to match units on the recall list if x="recall" or y="recall" appears in the filter at toplevel.

The wesnoth.units module now acts like a metatable for unit userdata, meaning that any functions (or attributes) added to the module will be visible through any unit.
2019-11-15 22:39:08 -05:00
Celtic Minstrel
3772e633fa Fix [modify_unit] optimized path producing an error on a recall list unit
Addresses #4556
2019-11-15 22:39:08 -05:00
Celtic Minstrel
595d102a23 Lua: Add optional variation parameter to unit:transform() 2019-11-10 14:17:57 -05:00
Charles Dang
de8077add6 Sneaky C-style arrays be hiding
Also dropped some unused code in unit_type.

And there's still one in language.cpp, but I'm not entirely sure if it's safe to
drop the last empty entry there so I left it.
2019-10-19 18:25:33 +11:00
Charles Dang
92c7d2fed0 Removed deprecated put_unit arg orders
x, y, unit and plain unit
2019-10-19 18:04:11 +11:00
josteph
7c6fbf343c [print]: Center the message within the map area
In master, this just moves the message down by the height of the top bar.

In themes where the left end of the map isn't at x=0, this makes [print]
centered within the main map, rather than centered within the rectangle
with corners (0,0) and (bottom right corner of the main map), regardless
of where the top and left ends of the map are with respect to the screen.

Currently, the [print] messages are vertically centered, whereas the
"Planning mode activated" message is vertically at one-third of the
height. We should perhaps make these consistent, but this commit
doesn't change that.
2019-10-14 23:59:27 +00:00
josteph
96a8d7d282 display: Remove a use of 0-index team numbers from the API 2019-10-14 02:18:28 +00:00
Charles Dang
4a3be684f4 Removed trailing tabs and whitespaces from C++ source
[ci skip]

I ran the same command from 9b7b1751fd.

Excludes:
* lua/
* spirit_po/
2019-08-04 22:31:10 +11:00
Charles Dang
2470984af3 Prepend 'SDL2/' to all SDL includes
This was needed to get the build working with vcpkg's version of SDL, where all the SDL files are
in their own SDL folder. However, our cmake config also has a note saying it was a deliberate choice
to move our SDL files *out* of their SDL2 folder due to certain distros (FreeBSD is mentioned) not
putting the files in said folder in the first place.
2019-07-22 15:35:55 +11:00
mattsc
02122f2eae wesnoth.find_path: deprecate old syntax for custom cost functions
The new syntax (using calculate= in the path options table) allows simultaneously setting the other path options, while there is no way to do so with the old syntax (passing the cost function as the last argument instead of the path options table).

We also remove the line allowing for an additional boolean argument to set ignore_teleports=. It does not make sense to single out this option from the others. Furthermore, this line makes it default to the opposite of the (more intuitive) default of the new syntax. For the record, this argument has not been in any released version yet and is not yet documented on the wiki.
2018-12-30 16:34:30 -08:00
Celtic Minstrel
ea9fddcd23 Support [disallow_end_turn]reason= and use it in the tutorial 2018-11-24 17:46:29 -05:00
Charles Dang
00a1edd149 Convert a bunch more C-style casts I missed in 0dc5656 to static_cast
(cherry picked from commit cb43d8b35f)
2018-10-28 02:53:11 +00:00
gfgtdf
50d94b3388 modifiable propertly game_config.do_healing
this controls whether during the next turn start the game will
heal units. I feel like 'game_config' is not a that good place
name for this but it is afaik the only place for those variables.
2018-10-22 01:34:20 +02:00
gfgtdf
eee9214e9a small game_lua_kernel cleanup 2018-10-21 17:42:24 +02:00
gfgtdf
082aa2afe2 add z_order attribute to wesnoth.add_tile_overlay fixes #3156
this probably won't work for halos yet.
2018-10-21 03:06:08 +02:00
gfgtdf
262549433f make wesnoth.simulate_combat a little more save against segfaults
it now keeps a unit_ptr to the unit to make sure the unit is not deleted
during whatever lua code the battle_context constructor calls. This can
be done because since the unit ctor refactor all unit objects are owned
by a unit_ptr (created by unit::create).

It might also be possible to refactor out the "unit * c_ptr" member of
lua_unit.
2018-10-21 03:06:08 +02:00
gfgtdf
dccda8294b allow wesnoth.simulate_combat to have defenders not on the map.
just like it does for attackers.
2018-10-21 03:06:07 +02:00
newfrenchy83
bcbac9fe33
Fix animation truncated after message
Closes #1617
Closes #3608
Closes #3631
2018-10-20 10:41:48 -05:00
gfgtdf
b340ce40ba fix dupicate function definition. 2018-10-20 13:29:32 +02:00
jostephd
e766cdc7cc WML: Support [filter_side] in [item]. (#3533)
* WML: Support [filter_side] in [item].

If [filter_side] is present then "team_name" is ignored.

Fixes #1477.

* WML: Compare [item]team_name to [side]team_name using intersection.

Fixes problems with substrings and when one or the other is a
comma-separated list. See #3533

* WML: Rename [item][filter_side] to [item][filter_team]

* Add changelog entry

(cherry-picked from commit 3a3b752881)
2018-10-07 03:25:20 +00:00
josteph
d5238ac5cb Commandline: --campaign-skip-story skips [message]s during prestart and start events
(cherry-picked from commit b64f4b42d6)
2018-10-07 03:25:20 +00:00
gfgtdf
bc89512a5c add game_config.combat experience
and make [harm_unit] use these values instead of hardcoded 8*level for
killing and level for combat.

(cherry-picked from commit 3591e82586)
2018-10-07 03:25:00 +00:00
gfgtdf
21e6b399e8 fix #3396 lua_function= doesn't work in [effect][filter]
unfortunately this adds an annoying const_cast. The old code 'worked around'
this by getting a nonconst reference to the same unit via the unit map,
which i think is not better just hides the issue.

(cherry-picked from commit 08b7d1b1ac)
2018-10-07 03:25:00 +00:00
newfrenchy83
c1a70068d5 Lua API: implicitly clear animator after playing it (#3536)
This prevents the animator from holding a strong reference to the target unit, which was keeping the unit object alive and thus preventing the unit halo, if any, from disappearing.

(cherry-picked from commit 7d6e2b2a10)
2018-10-07 03:24:59 +00:00
gfgtdf
e4c170f249 fix villages after terrain_mask
(cherry-picked from commit 6cd9de1202)
2018-10-07 03:24:14 +00:00
gfgtdf
6a10e12a6a add wesnoth.terrain_mask lua function
`[terrain_mask]` had multiple unexpected behviours, see for example #3364
in parituclar `wesnoth.wml_actions.terrain_mask { x =2, y=2, mask="Ww"}`
will change the tile at (1,2) instead of (2,2), so instead of reusing
the old terrain mask code i wrote a new function that behaves as one
would expect. `wesnoth.terrain_mask` does not have a `border=` parameter
but a `is_odd` parameter that specifies that a map is in the odd format
 __    __
/00\__/20\__
\__/10\__/30\
/01\__/21\__/
\__/11\__/31\
/02\__/22\__/
\__/  \__/

instead of the even map format
    __    __
 __/10\__/30\
/00\__/20\__/
\__/11\__/31\
/01\__/21\__/
\__/12\__/32\
   \__/  \__/

(Monospaced font required to see ascii images.)

The lua function also has a lua interfacte, meaning it does not take wml
tables but normal lua tables making it easier to use from lua code.

(cherry-picked from commit a3367ee848)
2018-10-07 03:24:13 +00:00
Jyrki Vesterinen
87c87aee3e Fix: halo (if any) remains when wesnoth.put_recall_unit() is used
Based on the suggested fix in #3425. Closes #3425.

(cherry-picked from commit 46bec21fa3)
2018-10-07 03:23:59 +00:00
gfgtdf
7ecf55b6ed ignore [delay] during preload,prestart and initial lua.
as the ingame ui is not shown yet, [delay] would only result in showing a black screen,

Also in the case of initial lua it might result in crashes because of the threaded loadingscren, or simply because parts of the ui are not initialized yet.

(cherry-picked from commit 97b5612691)
2018-10-07 03:23:53 +00:00
Martin Hrubý (hrubymar10)
674fda85b7 Migrate links to https if available - Fwd c18537edc0
(cherry-picked from commit bc4d22dc72)
2018-10-07 03:23:36 +00:00
Celtic Minstrel
5330405274 wesnoth.find_path: Allow specifying custom flags (in particular teleport) when using a custom cost function
(cherry-picked from commit 99233339dd)
2018-10-07 03:23:34 +00:00
gfgtdf
758fe79fe2 fix issues caused by empty save id
ee50171d13 broke some codes that relied on
unique save ids, that is in particular the statistic code and
scoped_recall_unit, so now these codes fallback to the side number if
the save id is empty.

(cherry-picked from commit c79e1645c8)
2018-10-07 03:22:27 +00:00
gfgtdf
d1db3fa32c fix [animate_unit] freezing the game
#2970
#3084

(cherry-picked from commit beeb5b43e2)
2018-10-07 03:21:51 +00:00
Charles Dang
19e3afb463 Convert C-style casts to static_cast
(cherry-picked from commit 0dc5656c32)
2018-10-07 03:21:02 +00:00
Charles Dang
399b589e60 Use std::time() instead of plain C time()
(cherry-picked from commit d26824901d)
2018-10-07 03:21:01 +00:00
Charles Dang
d9fb6c0bf5 Catch all exceptions (where possible) as const references
A few catch blocks modify something in their exceptions, so those are kept non-const.

(cherry-picked from commit 2bf4d68c87)
2018-10-07 03:20:58 +00:00
Charles Dang
2b65a8c5c8 Units: refactor display_context parameter out of ability functions
This was essentially only needed for the affects_side() helper. THAT'S IT. All this code just for
one single line... Anyway...

Utilized the display singleton's display_context getter instead. This also means fewer explicit
uses of resources::gameboard as the display_context object, meaning more compatibility with the
editor (not that that's relevant for most of the changed usecases, such as the AI, but it does
affect unit::get_abilities, which might be useful there in the future).

This also removes the display_context parameter from unit::invisible() since it was only passed to
unit::get_ability_bool().

unit::is_visible_to_team() also had its display_context parameter removed. It was used once as an
argument for invisible() and the other case was replaced with display::get_map().

(cherry-picked from commit 7e442cbb54)
2018-10-07 03:19:34 +00:00
Charles Dang
6f1263d34d Used UNUSED macro instead of (void) where applicable
(cherry-picked from commit 7a9ed8d363)
2018-10-07 03:18:04 +00:00
Charles Dang
45f871067f Use std::size_t everywhere instead of plain size_t
Excludes:
* spirit_po/
* xBRZ/

(cherry-picked from commit fc2a58f693)
2018-10-07 03:17:59 +00:00
Gregory A Lundberg
ef436639ae
Fix missing static keyword 2018-03-17 18:49:37 -05:00