Commit graph

462 commits

Author SHA1 Message Date
Celtic Minstrel
23aac4f72f Cleanup of fef953a48e
- Fix the rabbit AI
- Enable invoke_synced_command to also call (some) built-in commands
  and give an error message in the case of an unknown command
- Remove some unnecessary implementation details
2018-03-17 16:48:00 -04:00
gfgtdf
fef953a48e remove ai.synced_command
fixes #1649 . ai.synced_command could easily be used to implement all types of
undeteced cheats so it was removed. As a replacement this commit adds a
[custom_command] synced command that just calls
wesnoth.game_events.on_synced_command which calls a lua handler that
must first be set.
2018-03-16 13:43:05 +01:00
Charles Dang
a7f6862210 More include cleanups
Cleaned up unnecessary inclusions of:
* event.hpp
* exceptions.hpp
* formatter.hpp
* hash.hpp
* image.hpp
* sound.hpp
* team.hpp
* tstring.hpp
* wml_exception.hpp
2018-03-11 23:22:02 +11:00
Celtic Minstrel
afc60b9cc6 Rename the unit copy function (and make it non-static) 2018-03-11 01:36:17 -05:00
gfgtdf
a32f6aaf64 make sure units are always stored in unit_ptr step2
previously the unit ctor could invoke arbitrary umc lua code, for
example via advance_to -> add_modification ->
resources::lua_kernel->apply_effect and during that call the unit was
not owned by a unit_ptr, so the code could not use unit_ptr objects at
several places because the unit might not be owned by a unit_ptr object.
2018-03-11 01:36:16 -05:00
Charles Dang
950a156712 Addressed most of the remaining whitespace issues from #2613
[ci skip]
2018-03-11 14:59:37 +11:00
Celtic Minstrel
b0559eb0bf Use an enum for deprecation levels (C++ only)
This is not done for Lua and WML due to some complications.
It could still be done for them later, if desired.
2018-03-04 21:21:33 -05:00
Celtic Minstrel
5fc9d8d173 Use new deprecated_message() function wherever possible (C++)
This also covers handling of legacy DescriptionWML for [set_menu_item],
and tweaks its handling in the other cases (mainly [multiplayer_side]).

I added the next_dev_version constant intending to use it, but then
decided not to do so; however I left it in in case someone finds it useful.
2018-03-04 21:21:33 -05:00
gfgtdf
2e235f785d
allow specifying the next player number in end_turn
fixes #1392
2018-02-26 03:28:00 +01:00
Charles Dang
e270a7c665 Formatting cleanup: > > to '>>`
Allowed since C++11. Might as well use it everywhere.
2018-02-21 12:11:21 +11:00
Charles Dang
a77652986a Used std::distance instead of iterator arithmetic when possible 2018-02-20 11:33:52 +11:00
Celtic Minstrel
0dfb390a84
Fix wesnoth.set_village_owner ignoring the fire_event parameter
Looks like this was lost in the refactor that introduced the luaW_checklocation helper function.
If the location is specified as two separate parameters for x and y, this helper function
actually pops the y parameter from the stack so that further parameter tests can act
as if the location was a single parameter. Thus, the fire_event parameter, which used to
be 4th on the stack, is now moved down to 3rd.
2018-02-17 01:23:49 -05:00
Charles Dang
1196225017 Fix my fix to my fix to my fix to the wesnoth.set_village_owner impl
Should restore the behavior lost in 09906135b5 where in attempting to assign a village
to a new side that was defeated will have no effect. My changes made it that the village
would still be unassigned from the old side in that case.
2018-02-17 16:14:46 +11:00
Charles Dang
908b936c8c Fix my fix to my fix (fixup 0990613)
@gfgtdf

Turns out I forgot to consider the old village being unassigned, which would
make the exception on getting the old team a common occurrence. I've changed
the code to continue on if it can't unassign the village.

I also noticed a slight semantic change: unassignment of the old side used to
be skipped if the new was defeated, but now it's not. Dunno if that's a big deal.
2018-02-15 15:13:50 +11:00
Charles Dang
09906135b5 Refactor wesnoth.set_village_owner implementation
@gfgtdf pointed out that I didn't actually fix the underlying porblem that was causing
#2505 in 3e9654c3e4: if new_side was 0, board().team_is_defeated(board().get_team(new_side))
would throw an out-of-range exception and the village would never be un-assigned from the
old side.

I'm totally refactored the function to be easier to understand and match the desired behavior.
2018-02-15 14:39:41 +11:00
Charles Dang
3e9654c3e4 Fixed error when de-assigning village with [capture_village] (fixes #2505)
The code wasn't checking for a case where new_side was 0... not sure why that didn't cause
a problem before. Anyway, since I made get_team() throw if the side was invalid, I made the
code catch the out-of-range exception. That way we don't have to worry if either new or old
side is invalid.
2018-02-15 12:37:13 +11:00
Matthias Krüger
a2168d2e24 codespell fixes to /src 2018-02-08 21:54:09 +11:00
Charles Dang
d46f129d3c Added damage_inflicted member to wesnoth.current.event_context (fixes #2368) 2018-02-08 14:02:38 +11:00
Steve Cotton
07054112b0 Make [cancel_action] set_action_canceled (fixes #2430)
It was calling the getter instead of the setter.
2018-02-03 14:25:08 +11:00
Charles Dang
16ce2af32e Made display class no longer inherit from filter_context
The only function that display meaningfully implemented was get_disp_context. It did implement
get_tod_man, but only meaningfully in its two derived classes (it returned the result of
resources::tod_manager in display). Additionally, the long-ass comment in the header stated the
display class should *not* inherit from filter_context. Do note that get_disp_context was retained
as a display member function.

Upon further investigation, I found that there were only two places where the display class was
passed to unit_filter. All others passed resources::filter_con. The editor_display class was also
assigned to resources::filter_con in editor::context_manager. So, I removed the second filter_context
argument from unit_filter and initialized it from resources::filter_con in all cases.

unit_filter only used the filter_context to get its display_context and the unit_map within anyway.
When using display::get_disp_context in-game, that would return a game_board object. Using
resources::filter_con in the same context would return the game_state object that owned the
aforementioned game_board, and calling get_disp_context on that game_state would return the board
as well. So we end up in the same place.

To be complete, I also made editor::context_manager inherit from filter_context. It makes much more
sense, since it can nicely implement 2/4 of the fc functions. It also ensures resources::filter_con
is valid in the editor, in case it's needed. I'm not 100% sure it is, but since it was assigned
before (to editor_display), it's very likely.

Another side effect of the above is that get_tod_man is now implemented in a more apropos class
in the editor. Essentially, editor_display (where it was implemented before by reaching into the
context_manager) holds an editor_controller which holds a context_manager (where it's now implemented).
It wasn't even really needed in editor_display and was only called once.

Similarly, get_tod_man has been removed from game_display. Again, it was only present to "properly"
implement the function in display, which only existed because display inherited from filter_context.
And get_tod_man wasn't even needed in display, game_display, or editor_display (save for the one
aforementioned call)!!! AND in game_display, it simply dereferenced a pointer to the *actual* ToD
manager in the game_state class, WHICH IN AND OF ITSELF INHERITS FROM FILTER_CONTEXT!!!

I have removed the tod_manager pointer in game_display and replaced its use with resources::tod_manager,
which in the context of the game (where game_display) would be use, point to the same thing the class
pointer did. I suppose I could have left it, since I'm trying to remove/improve the use of the
resources pointers, but I felt it better to decouple the two classes (game_display and game_state)
slightly, especially since its main purpose for existing (overriding display::get_tod_man) no longer
exists.

Finally, some of the instances where a unit_filter object is created had to be changed to use brace
initialization or else the build failed. @celticminstrel tells me this might be because of some "most
vexing parse" issue.

Some formatting and virtual/override specifiers were also applied/added.

*huffs*
2018-01-29 15:54:01 +11:00
Jyrki Vesterinen
c8b0833b1a Make AI manager a singleton
Fixes #2372.

It turned out that the AI kept dangling references to the old Lua state,
and crashed while destroying AI contexts for destroyed sides.

The best way to avoid it is to ensure that game_state, which already owns
the Lua state, also owns the AI. That way, the AI will be destroyed before
the Lua state and a dangling reference can't stay.
2018-01-24 14:29:01 +11:00
Charles Dang
f23305f7e2 Formatting cleanup: T const& -> const T& 2018-01-23 01:26:23 +11:00
Charles Dang
da3a0ed7cf Added [lua] conditional tag
Also made conditions fail if they encountered a syntax or runtime error. This seems the
more logical behavior than passing.

WML conditional tags were split into their own Lua file. The one in lua/wml/object.lua
relies on local variables so was left there.
2018-01-22 23:03:16 +11:00
Gregory A Lundberg
b5f76eff79
Bump copyright to 2018 2018-01-19 00:02:20 -06:00
Charles Dang
29ff4bd644 Removed CVideo argument from help functions
Just used the singleton in the main show_help function.
2017-12-05 10:50:11 +11:00
Charles Dang
693735d90c Fixed a bunch of log output and code comment typos
[ci skip]
2017-11-24 01:14:03 +11:00
Charles Dang
f2b31ba082 Massive cleanup of GUI2 display/show and execute functions implementations and related CVideo arguments
This a two part commit. First:
----------------------------------------------------------------------------------------------------
Added and deployed two new helper macros for the standard implementations of the static execute
and display functions. I also made use of a variadic template in order greatly simplify code
maintenance. Now, even if the dialog's ctor parameters change, no one has to worry about updating
the associated execute/display functions (though of course, this only applies if the helper macros
are used). \o/

I did not deploy the macro in cases where there were multiple overloads or the functions did more
than just show their dialogs. I might add an additional __VA_ARGS_ parameter to the macros later.
Do note for the end_credits dialog I moved the default empty-string parameter from the display
function to the ctor.

Second:
----------------------------------------------------------------------------------------------------
Another change is that modal_dialog::show and modeless_dialog::show no longer take CVideo arguments.
Since the video argument couldn't be included in the parameter pack (maintaining the argument would
have meant making it the first one, which would be just as much work), and using CVideo::get_singleton
in the macros would require adding video.hpp includes in a whole bunch of files, I simply removed the
argument. I had been intending to do this for a while anyway.

This therefor also removes the CVideo argument from:
* All dialog display/execute functions.
* modal_dialog::show
* modal_dialog::build_window
* modeless_dialog::show
* modeless_dialog::build_window
* wml_exception::show
* gui2::show_message
* gui2::show_error_message
* gui2::show_transient_message
* gui2::show_transient_error_message
* gui2::show_wml_message
* gui2::build
* gui2:🪟:window
* gui2::dialogs::tip::show
* Various GUI2-related Lua functions. The video_dispatch helper was also removed.
* Any functions that took a CVideo argument for the sole purpose of passing it to one of the above.

Ya know, all these damn CVideo arguments didn't actually do anything, besides an occasional check to
CVideo::faked. At the end of the pipeline, they just got assigned to the video_ member of gui2::window.
Huge code bloat for nothing.
2017-11-20 19:24:41 +11:00
Jyrki Vesterinen
0c137c79cf Globally suppress -Wmaybe-uninitialized
We have needed to suppress it in a bunch of places because GCC has kept
giving false positives depending on optimization settings. When I noticed
yet another false positive when I attempted to build the game with PGO
profiling data using CMake, it was the last straw.

Let's just suppress the warning globally and move on with our lives.
2017-10-27 21:28:06 +03:00
newfrenchy83
c6408dbd95 Fix halo remaining/duplicating in some situations
Fixes halo remaining when a unit is killed with [put_unit] or replaced by
creating a new unit over it with the context menu, and duplicate halo when a
developer changes the properties with :unit.
2017-10-04 07:29:23 +03:00
gfgtdf
6a059111aa prevent user actions while executing unsynced wml actions 2
This should fix #2021. The reason why we didn't just add one events::command_disabler in the code that starts the unsyned event hander (moving the events::command_disabler up in wml_menu_item::fire_event) is the we want commnds_disables to be for the (wml) code that handles the menu items so that it knows that it can use issue synced commands via [do_command]
2017-09-20 21:23:23 +02:00
gfgtdf
7c71bab57c add wesnoth.current.user_can_invoke_commands
this attribute return whether we are in a context where the user coudl issue new commands.

This is mainly intended to be used to check whethere we can use [do_command] in the currently situation (for exampel if one wants to use [do_command] in a unsycned menu item)
2017-09-20 10:46:28 +02:00
Jyrki Vesterinen
79554179e9 Fix #1987: halo remained after killing an unit with the context menu
The cause for this bug was the whiteboard.

A unit destroys its halo when the unit itself is destroyed. Makes sense,
right? Unfortunately, units are managed by shared pointers, and therefore
are not destroyed until all references to them are gone. And the whiteboard
retains a reference to the most recently selected unit.

The obvious fix would be to use a weak (non-owning) pointer in the
whiteboard, but it's sadly not possible because unit_ptr is an
intrusive_ptr. It stores the reference count right in the unit itself, and
therefore the refcount is lost when the unit is destroyed: hence weak
pointers are impossible.

Thus, what I ended up doing was explicitly notifying the whiteboard when an
unit is killed, and releasing the reference when it happens. If anyone has
suggestions about a better implementation, I'd love to hear them.
2017-09-14 20:14:08 +03:00
Celtic Minstrel
00443dd8a4 Fixup d192d0712393 and move wesnoth.debug() to lua_kernel_base 2017-08-14 13:10:52 -04:00
Celtic Minstrel
f1fe86ab5f Merge pull request #1811 from GregoryLundberg/GL_CMake_clang
Fix Lua for CMake with clang

Fixes #1669
2017-07-25 19:57:37 -04:00
gfgtdf
821e27c34f add [cancel_action] implements #1427
this adds a new tag [cancel_action], it currently only has an effect in
move actions. It can be used in enter_hex/exit_hex events to abort the
current movement. It can also be used in moveto events where is
cancels possible following attacks (if the user issued a move+attack
action).

This also changes the behaviour of moveto and enter/exit_hex event so
that they now no longer cancel the movement automatically, also
[allow_undo] no longer has an effect on whether the move is cancelled,
it now only allows undoing of the move.
2017-07-25 21:19:05 +02:00
gfgtdf
974f09178c rename context_mutated -> undo_disabled 2017-07-25 21:19:05 +02:00
Gregory A Lundberg
8953f2aa0f Correct float/double literal causing implicit conversion 2017-07-25 12:12:09 -05:00
Celtic Minstrel
a5b613ba4c Lua: Allow specifying whether to fire event in put_unit even without an explicit location, and make it fire the event by default
Addresses #1817
2017-06-25 11:40:27 -04:00
Celtic Minstrel
6a091f0851 Lua: Support the extra wesnoth.match_unit arguments also in wesnoth.get_units 2017-06-25 00:37:53 -04:00
Celtic Minstrel
93b9a4f80e Expose the location filter reference unit to the Lua API 2017-06-25 00:37:51 -04:00
Celtic Minstrel
6234d2f6f6 Add error message if something other than a table is passed to animator:add as the options 2017-05-28 18:20:15 -04:00
Celtic Minstrel
8febe037db Promote wesnoth.game_config to lua_kernel_base 2017-05-23 23:55:40 -04:00
Celtic Minstrel
39dad27260 [modify_side][ai] with ai_algorithm now replaces the AI (fixes #1216) 2017-05-22 14:39:35 -04:00
Celtic Minstrel
c0e6940834 Prevent [modify_ai][ai] from cluttering AI config with empty stages 2017-05-22 00:34:08 -04:00
Charles Dang
57d825d114 Avoid some temporary tuples
[ci skip]
2017-05-22 14:06:05 +11:00
Celtic Minstrel
96ca0b026e Replace config_of with new variadic config constructor 2017-05-21 16:27:46 -04:00
Charles Dang
79ffbbe9b4 Game Events: include manager in pump header to avoid having its include in so many places 2017-05-21 07:52:42 +11:00
Celtic Minstrel
cee3698fae [sound_source] now starts playing the sound immediately 2017-05-11 18:57:55 -04:00
Celtic Minstrel
263aadcaa0 Lua: Allow clearing unit and side variables 2017-05-11 16:00:53 -04:00
Celtic Minstrel
e2ebfa31f6 Add an extra error-checking case for targets in Lua animators 2017-05-10 19:02:59 -04:00