Commit graph

106 commits

Author SHA1 Message Date
Chris Beck
0a4a385e50 move most of the remaining lua callbacks not to use boost bind 2015-04-10 15:38:48 -04:00
Chris Beck
97ce93af03 change many callbacks in game_lua_kernel to use lua extraspace 2015-04-10 15:23:22 -04:00
Chris Beck
f4c99b3a1a fixup wesnoth.wml_conditionals, add unit tests 2015-04-10 14:16:21 -04:00
Chris Beck
4bb26cebab add wml_conditionals support, in addition to wml_actions in lua 2015-04-10 12:37:25 -04:00
Chris Beck
03ab839f30 fixup a gcc pragma to exclude gcc 4.5.x and older
vultraz reported errors with tdm-gcc 4.5.2
2015-04-07 00:55:40 -04:00
Chris Beck
29c99fe870 ignore "maybe uninitialized" warning in game lua kernel.
This breaks compilation for gcc 4.9.2 with -O2, with an apparently
spurious warning.
2015-04-06 20:46:56 -04:00
gfgtdf
cd0029eac1 add accelerate in [delay]
If accelerate =yes (default no) then the delay time will be affected by
the acceleration set in the preferences.
See https://gna.org/bugs/?21335
2015-04-06 00:48:48 +02:00
Charles Dang
48f11240b1 Fixup d9a63b1c30
Turns out we want to invalidate both before and after handling shroud
2015-03-30 22:19:37 +11:00
Charles Dang
d9a63b1c30 Handle shroud last in [redraw]
Previously, it was handled first, meaning any events fired by clearing shroud would fire
before the screen was completely redrawn.
2015-03-30 21:54:38 +11:00
gfgtdf
43c10ec0cc add access to unit attacks to lua 2015-03-29 21:43:39 +02:00
gfgtdf
ed5650c758 add wesnoth.advance_unit lua function
previously this was only possible by storing the unit and then unstoring
with advance=yes. Unstoring a unit can cause a lot of overhead if the
unit is complicated. so i added a way to do it without [unstore_unit]
2015-03-28 21:37:26 +01:00
gfgtdf
c39598e723 fix resetting of variables in replay
I also moved wml_emnu_items member out of game_data to to prevent possible problems when resetting game_data.
2015-03-27 21:19:05 +01:00
gfgtdf
b892e16b94 include lua/... files after others
headers from lua/..  contain macros that can break other headers in
wesnoth, boost or other libraries.

In this case it was a macro
#define cast(t, exp) ((t)(exp))
defined in lua/llimits.h that broke a boost header.
2015-03-27 00:54:22 +01:00
gfgtdf
9b65db80a3 allow putting units on recall list for nonpersistent sides
persistent=no does not imply that the side does not have a recall list:
1) persisent=no did prevent units from this scenario to be carried over
to a next scenario but it did not prevent units from a previous scenario
to be carried over to this scenario.
2) [unit] in [side] and [unit] in action wml can give recall units to
nonpersistent sides.
3) The wiki does not mention that a side with persistent=no cannot have
recall units.

So i removed checks for [side]persistent= so that [unstore_unit] and
wesnoth.put_recall_unit can put units to the recall list and also tidied
up some other code that assumed sides with persistent=no to not have a
recall list.
2015-03-22 18:45:35 +01:00
gfgtdf
280dd8e7ed fix some indention 2015-03-22 01:39:55 +01:00
gfgtdf
30e670f5a8 refactor end_level_data, end_level_exception and LEVEL_RESULT
I removed the NONE value of LEVEL_RESULT because 'LEVEL_RESULT==NONE'
was basicly the same information as '!end_level_data.transient.disabled'

I removed end_level_data.transient.disabled and instead store the end
level_data as an optional<end_level_data> to remember whether we already
have an end_level_data

I removed the SKIP_TO_LINGER value of LEVEL_RESULT because it was not
possible that play_scenario returned SKIP_TO_LINGER (so i removed that
code in playcampaign.cpp that handled this case)

I replaced playsingle_controller::level_result_ and
end_level_exception/struct::result which both held more or less the same
data with end_level_data::is_vitory, in case of QUIT the
optional<end_level_data> is empty (none_t)

I also reordered the if cases in playsingle_controller::play_scenario to
simplify.
2015-03-01 03:54:53 +01:00
gfgtdf
c0c6f71725 fix compilation
msvc liked the previous code but travis said:
usr/include/boost/optional/optional.hpp:526:5: candidate constructor not
      viable: no known conversion from 'const config::attribute_value::yes_no'
      to 'argument_type' (aka 'const bool &') for 1st argument.
    optional ( argument_type val ) : base(val) {}
I hope travis likes this version.
2015-02-12 00:36:33 +01:00
gfgtdf
89c461c1c6 restore [endlvel] bonus= default behaviour
bonus= in [endlevel] previously defaulted to true, my last commit
resulted in bonus= defaulting false. this commit restores the previous
behaviour.
2015-02-11 22:40:34 +01:00
gfgtdf
7471b4eeec add side specific results in [endlevel]
adds [result] tags in [endlevel] as suggested in
http://gna.org/bugs/?4960
the following [endlevel] attributes can now be given side spcific:
'result', 'bonus', 'carryover_precentage', 'carryover_add'

In the normnal case we show a victory message on a client if any of the
local humans is victorious, but we have to watch out for border cases
like when there are no human sides and behave just like we did
previously in this case.

This also fixes a bug that the calculated carryover could be different
from what is shown in the message (see comment in playcampaign.cpp that
was removed by this commit)

This also removes some unused functions in carryover.cpp that were
incompatible with this commit.
2015-02-11 22:40:32 +01:00
gfgtdf
370e03ec82 remove code duplication of defeat_condition check
we don't use team_is_defeated in check_victory because we don't want to
iterate over units multiple times.
2015-01-24 14:18:22 +01:00
Elvish_Hunter
26216f6409 Lua set_village_owner(): moved checks for new_side before its first use 2015-01-24 11:51:48 +01:00
Elvish_Hunter
1454600ba4 Lua set_village_owner(): added checks for the new defeat conditions 2015-01-24 11:45:06 +01:00
Charles Dang
ac42e5e228 Elevate 63891c77a1 to work in all SLFs
The default with_border value is false. Certain functions, such as game_lua_kernel::intf_get_locations
pass an explicit true value to with_border. This commit allows any user-facing tags using those
(such as [store_locations]) to pass an explicit override.
2015-01-15 04:28:27 +11:00
Charles Dang
63891c77a1 Allow location storing to exclude borders by passing cfg.include_borders=false
Default behavior (including borders) is preserved without the key or if they key is set to yes
2015-01-15 03:35:14 +11:00
Chris Beck
2c6d4dacf7 Merge pull request #360 from cbeck88/menu_item_tests
add lua function "fire_wml_menu_item" and unit tests for menu items
2015-01-07 14:03:41 -05:00
Chris Beck
f015745e22 Revert "Always consider border hexes when filtering locations"
This reverts commit dc807a0ab6.

We agreed on irc that this commit is too hasty and requires more
testing.
2015-01-06 22:28:23 -05:00
Chris Beck
8459bf7104 add lua function "fire_wml_menu_item" and unit tests for menu items
this commit also changed slightly the way that wml menu events
are synced. previously they were run via "run_in_synced_context",
now they are run via "run_in_synced_context_if_not_already", which
makes it safe to fire them from lua (a synced context).
2015-01-06 21:42:52 -05:00
Chris Beck
7adde8af9c lua: change a reference variable to a non-reference type
This line was not an error -- it is legal in C++ to bind a const
reference to a temporary value. It's only slightly more confusing
than usual in this case because the string it is built from is
a C-string owned by lua, and the temporary std::string object is
implicit.

I don't believe this commit will even make any difference in the
compiled code, it's only slightly simpler and more readable.
2015-01-06 00:00:04 -05:00
Chris Beck
eaa078a86d initialize wml menu item handlers when they are set, not in ctor
this commit causes wml menu items to have their events registered
not during construction but only when "init_handler" is called.
it refactors the wmi_container object to do this when it
constructs new items via the [set_menu_item] path.

this is necessary because the items might be constructed before
the event queue even exists, and we want them to be able to
persist and be reactivated when a new campaign scenario starts.

more testing is necessary to determine if all code paths, including
carryover and reloading, are still working after this commit, and
the earlier commit 6fc1ac1bb2

See also discussion of bug #23115.
2015-01-05 12:47:32 -05:00
Charles Dang
1cab8b127f Eliminate a useless copy variable in intf_add_time_area 2015-01-04 23:32:37 +11:00
Charles Dang
e1e5169c95 Get [time_area] id from the config instead of passing it as a lua arg
This fixes [time_area] id= inadvertently becoming required, when it should be optional
2015-01-04 23:25:49 +11:00
Charles Dang
e9ed01ee5f Fixup HEAD
Restored a comma I accidentally deleted and fixed a minor style inconsistency
2015-01-04 23:19:11 +11:00
Charles Dang
8c7d6fecb7 Better code formatting for cpp_callbacks list
Especially used spaces as opposed to tabs
2015-01-04 22:37:24 +11:00
Charles Dang
dc807a0ab6 Always consider border hexes when filtering locations 2015-01-04 18:08:27 +11:00
Ignacio R. Morelle
57ae45387a New Year copyright update 2015-01-01 19:07:35 -03:00
Chris Beck
1f124ff2ee lua: give more specific errors for "unknown modifiable property" 2014-12-29 23:17:13 -05:00
Chris Beck
a1a2e0e527 lua: fixup 9eaba64651
This commit broke the lua unit modify method for unit.side, the
reason was that I wasn't sure how to handle a safety check that
required a reference to the gamestate -- I'm not totally convinced
that units should not be allowed to be made in lua if there is not
an active gamestate.

However instead of commenting out this line, I should have
replaced it with a version that does the same thing without the
safety check... not sure why I didn't do this the first time.

This fixes lua errors that occur in the test scenario startup.
2014-12-29 22:55:03 -05:00
gfgtdf
14616607f5 fix some spelling in comments. 2014-12-29 22:48:16 +01:00
Chris Beck
4d857e4794 lua: fixup 9922b98fa3
commit failed to register the "gamestate_inspector" fcn with the
lua environment
2014-12-29 11:59:06 -05:00
Chris Beck
9f67233f22 fixup fa32be5602
the previous commit forgot to actually register the functions
add/remove_time_area in the lua environment
2014-12-29 11:49:41 -05:00
Chris Beck
64ee2d8e10 Merge branch 'lua' 2014-12-28 19:05:46 -05:00
Chris Beck
497ed6f516 move wml [heal_unit] impl to lua 2014-12-28 17:39:39 -05:00
gfgtdf
7f0e7c890d better error on invalid variablename in wesnoth.set_variable
first we now throw a lua error instead of just giving a log message this
makes it easier to find the source of a bug becase we now get a
stacktrace.

Also we now give a more detailed error message.
2014-12-28 22:54:27 +01:00
Chris Beck
098d886db9 lua: move wesnoth.races code to its own file 2014-12-28 16:50:17 -05:00
Chris Beck
50794d6164 lua: fix some warnings from implicit int->bool (lua_toboolean) 2014-12-28 14:40:34 -05:00
Chris Beck
53b1309691 Merge branch 'lua' 2014-12-26 17:18:22 -05:00
Chris Beck
a669f25255 lua: move code related to getting unit types to its own file 2014-12-26 17:15:44 -05:00
Chris Beck
74053a8f8e fix bug #23113 unit-specific anims missing (tutorial delfador)
There were two bugs here:
In 6603de667b, in unit::advance_to,
the code fragment that resets the animation set based on the new
unit type was made to run after modifications had been processed.
Since modifications may introduce new animations, this caused these
to be discarded.

In d7bf5be356, [animate_unit] was
broken by accidentally not including it in the lua kernel
initialization routine.
2014-12-26 14:34:32 -05:00
Chris Beck
1969267d19 lua: move code related to get_sides metatable to its own file 2014-12-26 02:41:42 -05:00
Chris Beck
2486b8ba4b lua: refactor to use lua 5.2 syntax for custom metatables
In lua 5.0, the preferred way to define custom metatables is to
use registry keys defined by pushing pointers as lightuserdata to
lua. (These pointers can be pointers to arbitrary constant objects,
as long as they are unique.)

In lua 5.2, the preferred way is to use constant strings as the
registry indices, and several lua API functions are introduced:
"luaL_newmetatable, luaL_setmetatable, luaL_checkudata,
luaL_testudata" which greatly simplify the operations for creating
the metatable, assigning it to a userdata, and checking if the
userdata has that type.

This commit switches over the keys associated to textdomains,
translatable strings, vconfigs, and lua gui2 dialogs to use the
new style, and simplifies some of the implementation details in
the process. For instance, luaW_toconfig no longer has to have an
optional argument to an index on the stack where the tstring
metatable is... these details are handled by the lua API instead.
2014-12-25 23:58:00 -05:00