Commit graph

106 commits

Author SHA1 Message Date
Chris Beck
93fe16a832 lua: move metatable registration for lua_common
this gives better encapsulation
2014-12-25 13:42:54 -05:00
Chris Beck
e73c57ead7 move wml [endlevel] impl to lua, and split into many lua funcs
the [endlevel] tag does alot of things that could quite comfortably
be split into several parts, like setting the next scenario, the
end level text, message duration, credits. this commit adds
separate lua api for each of these, leaving the rest in end_level,
and the lua tag implementation calls these variously.
2014-12-24 16:17:24 -05:00
Chris Beck
d7bf5be356 move wml [animate_unit] to lua 2014-12-24 15:15:25 -05:00
Chris Beck
b6da5d0666 lua kernel: add accessor for event_info stack 2014-12-24 15:03:52 -05:00
Chris Beck
171f92a6a5 move wml [open_help] impl to lua
also fixes an issue where the help topic was being cast
unnecessarily to a tstring
2014-12-24 14:42:58 -05:00
Chris Beck
75767d3a77 move WML [kill] impl to lua 2014-12-24 05:43:37 -05:00
Chris Beck
9922b98fa3 move wml [inspect] impl to lua (and lua_gui2 namespace) 2014-12-24 05:00:44 -05:00
Chris Beck
ca58a71793 move WML [modify_side] implementation to lua 2014-12-24 04:44:25 -05:00
Chris Beck
0246026940 move WML [event] impl to lua, fixup core wml vs lua loading order
This commit moves [event] to be implemented in lua/wml-tags.lua.
It turns out that because of some questionable ordering in
data/core/_main.cfg, none of the tags defined in
data/lua/wml-tags.lua are actually defined at the time that core
is read, instead they are defined right after this. This is broken,
the entire wml library should be defined before core is read. Thus
we reorder some directives in data/core/_main.cfg to ensure this.

This commit adds lua callbacks `wesnoth.add_event_handler`,
`wesnoth.remove_event_handler` as well.
2014-12-24 04:21:58 -05:00
Chris Beck
0e365efc1a move WML [label] impl to lua 2014-12-24 03:16:49 -05:00
Chris Beck
29da15e1c0 move wml [end_turn] impl to lua 2014-12-24 03:07:49 -05:00
Chris Beck
177b4d5da1 move WML [color_adjust] impl to lua 2014-12-24 02:57:42 -05:00
Chris Beck
96c35f6560 move WML [redraw] impl to lua 2014-12-24 02:44:31 -05:00
Chris Beck
2cc38505dc move WML [scroll] implementation to lua 2014-12-24 01:06:44 -05:00
Chris Beck
defb9e5051 move replace_schedule impl to lua 2014-12-23 23:35:10 -05:00
Chris Beck
fa32be5602 add time_area registration impl to lua 2014-12-23 23:05:02 -05:00
Chris Beck
09ce8b5774 move clear_menu_item to lua implementation 2014-12-23 22:23:22 -05:00
Chris Beck
41e54fd009 move allow_undo, allow_end_turn impl's to lua 2014-12-23 22:08:45 -05:00
Chris Beck
0d76ac3be7 move the place, remove shroud WML tags to lua implementation 2014-12-23 21:04:45 -05:00
Chris Beck
eb71fc4d3b move "set_menu_item" to be implemented via lua rather than C++ 2014-12-23 19:34:17 -05:00
Chris Beck
78c42acc48 move game_events and lua kernel into class game_state
After this commit,

- almost all data which is part of the game in the sense of being
synchronized / saved is in the game_state class
- still missing is the code / data related to determining whose
turn is next
- the game state needs to be bound to a play_controller, via its
init function. This is needed so that lua / game_events manager
callbacks can be evaluated, but future refactor should make it
unnecessary
- bug # 23071 should be fixed

TODO:
- allow the game state to manage whose turn it is, leave only UI
 details in play_controller
- expose the lua kernel via the filter_context interface, and
make filters use it instead of resources
- make a proper copy ctor for game state, and improve encapsulation
2014-12-22 23:21:20 -05:00
Chris Beck
ecb4317102 fix a typo putt_recall_unit -> put_recall_unit 2014-12-20 21:09:16 -05:00
Chris Beck
1b92049f4e allow late binding of game display to lua kernel 2014-12-20 13:48:14 -05:00
Chris Beck
f5481ce961 make game_events::pump not a singleton
Instances of this are now owned by the manager.

It would be nice to refactor this to provide all of the front-
facing methods in the manager instead of in the pump, since the
pump itself is somewhat an implementation detail. But this is
nearly the "smallest" diff change that would remove the singleton
restriction.
2014-12-14 20:50:40 -05:00
Chris Beck
a3b06ad700 replace a filescope data structure with a member variable
In particular the stack of queued wml events used in the game lua
kernel.
2014-12-13 20:45:56 -05:00
Chris Beck
7eb4f78593 make wml_action closures run as methods of game_lua_kernel 2014-12-13 20:24:53 -05:00
Chris Beck
d02c376bd3 move "screen_needs_rebuild" from file scope to game_display object 2014-12-13 19:34:52 -05:00
Chris Beck
0459f8a574 make "reports" not a singleton object
This is necessary to make game_events not a singleton.
2014-12-13 01:28:57 -05:00
anonymissimus
a284ae892d make included boost headers more specific
This works around a compile problem in MSVC9.
(some conflict in those boost headers ?)
2014-11-30 18:32:37 +01:00
Chris Beck
b1be437b54 add "lua_chat" to replace chat_message in lua kernel
chat_message, from lua_api.?pp, relies on resources links
2014-11-24 21:16:23 -05:00
Chris Beck
67ac03b0e1 remove last resources:: links from game_lua_kernel 2014-11-24 20:42:53 -05:00
Chris Beck
217e4a0242 pass a reference to the play_controller to the game_lua_kernel
also expose pointer to whiteboard manager from a public getter in
the play controller
2014-11-24 20:32:05 -05:00
Chris Beck
e09a516935 replace resources::config_manager with game_config_manager::get()
This makes more sense, the main reason for resources was to hold
pointers to children of play_controller. For classes that are
legitimately singletons are essentially never destroyed or
reconstructed there's very little reason to put it in resources.
2014-11-24 19:49:54 -05:00
Chris Beck
9eaba64651 refactor game_lua_kernel not to use resources:: for gamestate
This commit changes the majority of the wesnoth callback functions
for the game lua kernel to be private methods of the game lua
kernel. The game lua kernel is given direct access, via it's ctor,
to references of many of the things provided by resources. The
call back functions are modified to access these private reference
variables instead of resources, and they are added to the
scripting environment using the lua cpp function mechanism.

This greatly improves encapsulation and will eventually lead to
eliminating the resources pointers from the game lua kernel
entirely.
2014-11-24 17:13:03 -05:00
Chris Beck
48a14ddadf move lua fcn 'wesnoth.tovconfig' to lua kernel base / lua common
there was no reason for it to only be in the game kernel, most
other vconfig functions were already in lua common.
2014-11-24 01:12:25 -05:00
Chris Beck
2c6af2f459 fix a camelcase identifier LuaKernel -> game_lua_kernel 2014-11-23 23:05:27 -05:00
Chris Beck
ad7c5c029c make 'extract_preload_scripts' a class member function 2014-11-23 22:49:12 -05:00
Chris Beck
f5e2204326 add assertions after many unchecked dynamic casts
These were all reported by coverity, and indeed seem to have been
assumed to work without failing at runtime.
2014-11-19 00:21:41 -05:00
Chris Beck
caeaa6ba67 refactor lua show_dialog
The lua show dialog used to get the video object from resources,
which is not ideal. In this version, lua kernel base internalizes
a pointer to the video object, and show_dialog is bound to a
method of the lua kernel base.

From now on, lua kernels which want to show dialogs need to be
constructed with a pointer to a CVideo, if it is null the lua will
fail with a runtime error.

The application lua kernel is constructed with the video for
game_launcher, and the game lua kernel is modified so that it is
owned by the play controller and not the game events manager, and
held in a boost scoped pointer rather than manually deleted. This
is because the game events manager doesn't have a video object,
also it conceptually seems independent of the lua kernel anyways.

The map generator lua kernels are constructed with NULL, but if a
user configuration dialog is provided (new feature) then when they
try to run it they will update with the mp_create's video pointer.
2014-11-17 17:03:00 -05:00
gfgtdf
6dee1366a5 notify server of wml controller changes
Previously this scenario would have resulted in OOS, becasue of the content of the "side turn" event:

[scenario]
	id= "03_MANYSIDES_TEST"
	name= _ "MP Sides Test"
	description= _ "This secnario is for testing side numbers"
	map_data= "border_size=1
usage=map

Rr^Vhc, Rr^Vhc, Rr^Vhc, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Rr^Vhc, Rr^Vhc, Rr^Vhc, Gg
Rr^Vhc, Rr^Vhc, Rr^Vhc, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Rr^Vhc, Rr^Vhc, Rr^Vhc, Gg
Rr^Vhc, Rr^Vhc, Rr^Vhc, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Rr^Vhc, Rr^Vhc, Rr^Vhc, Gg
Rr^Vhc, Rr^Vhc, Rr^Vhc, Gg, Ch, Ch, Gg, Ch, Ch, Gg, Rr^Vhc, Rr^Vhc, Rr^Vhc, Gg
Rr^Vhc, Rr^Vhc, Rr^Vhc, 1 Kh, Ch, Gg, Gg, Gg, Ch, 2 Kh, Rr^Vhc, Rr^Vhc, Rr^Vhc, Gg
Rr^Vhc, Rr^Vhc, Rr^Vhc, Gg, Gg, Ch, Gg, Ch, Gg, Gg, Rr^Vhc, Rr^Vhc, Rr^Vhc, Gg
Rr^Vhc, Rr^Vhc, Rr^Vhc, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Rr^Vhc, Rr^Vhc, Rr^Vhc, Gg
Rr^Vhc, Rr^Vhc, Rr^Vhc, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Rr^Vhc, Rr^Vhc, Rr^Vhc, Gg
Rr^Vhc, Rr^Vhc, Rr^Vhc, Gg, Gg, Gg, Gg, Gg, Gg, Gg, Rr^Vhc, Rr^Vhc, Rr^Vhc, Gg"

	experience_modifier=20%
	turns=-1
	{DEFAULT_SCHEDULE}
	allow_new_game = yes
	[side]
		side={NUMBER}
		id= "leader{NUMBER}"
		save_id= "leader{NUMBER}"
		controller={CONTROLLER}
		team_name={TEAMNAME}
		type = "Elvish Archer"
		canrecruit="yes"
		village_gold=5
		income=10
		share_maps=yes
		share_view=yes
        shroud=yes
		gold=200
		experience=40
		recruit=Elvish Archer,Elvish Fighter,Elvish Scout,Elvish Shaman
		x,y = {X} ,{Y}
	[/side]
	{NORMALSIDE  1 "human" "good" 3  2 }
	{NORMALSIDE  2 "ai" "evil" 4  2 }
	{NORMALSIDE  3 "human" "good" 5  2 }
	{NORMALSIDE  4 "ai" "evil" 6  2 }
	{NORMALSIDE  5 "human" "good" 7  2 }
	{NORMALSIDE  6 "ai" "evil" 8  2 }
	{NORMALSIDE  7 "human" "good" 9  3 }
	{NORMALSIDE  8 "ai" "evil" 9  3 }
	{NORMALSIDE  9 "human" "good" 3  6 }
	{NORMALSIDE 10 "ai" "evil" 4  6 }
	{NORMALSIDE 11 "human" "good" 5  6 }
	{NORMALSIDE 12 "ai" "evil" 6  6 }
	{NORMALSIDE 13 "human" "good" 7  6 }
	{NORMALSIDE 14 "ai" "evil" 3  6 }
	{NORMALSIDE 15 "human" "good" 9  6 }
	{NORMALSIDE 16 "ai" "evil" 10 6 }
	[event]
		name = "side turn"
		first_time_only = no
		[lua]
		code = <<
			local helper = wesnoth.require("lua/helper.lua")
			local controller = helper.rand("human,ai,null")
			local side_num = wesnoth.current.side + 1
			if side_num > #wesnoth.get_sides({}) then side_num = 1 end
			wesnoth.sides[side_num].controller = controller
		>>
		[/lua]
	[/event]
[/scenario]
2014-11-16 19:31:17 +01:00
Chris Beck
94728187af Merge branch 'lua_interpreter_dialog' 2014-11-13 13:25:24 -05:00
Chris Beck
2021a42d5b Add lua console
- Add an internal command logger to the lua kernel base, and expose
this.
- Redirect the internal lua `print` to the command logger.
- Add an external logger registration system to lua kernel, in
addition to the internal one.
- Add a lua console dialog which binds to a lua kernel base and
permits to review the contents of the logger and issue new commands,
and report errors.
- Add a hotkey binding to launch the lua console "`"
- Adds tab completion support to the lua console
2014-11-13 11:38:58 -05:00
gfgtdf
54e27d2d3f rename team::is_human() -> is_local_human
and is_ai -> is_local_ai
2014-11-12 23:11:15 +01:00
gfgtdf
f777c3ce18 get rid of preprocessor conditional
having 2 different implementations (one for c++11 and one for c++03)
makes the code harder to maintain.
2014-11-11 20:51:34 +01:00
Chris Beck
c4014bc39c Merge branch 'master' of https://github.com/wesnoth/wesnoth 2014-11-11 12:41:14 -05:00
Chris Beck
3b8e3b6d09 fix includes 2014-11-11 12:40:53 -05:00
gfgtdf
43e0ef1f26 revert d889982437
since https://github.com/wesnoth/wesnoth/pull/201 these tags shouldn't appear in the snapshot/scenario anymore.



reverts d889982437
2014-11-11 18:29:50 +01:00
Chris Beck
aa19f6eecd move gui2 dialog lua functions to the lua kernel base 2014-11-10 21:13:22 -05:00
Chris Beck
91f5778068 move all gui2 lua bindings to their own file 2014-11-10 20:12:09 -05:00
Chris Beck
63399b47e9 move some callbacks (gettext, file ops) to lua kernel base 2014-11-10 15:34:13 -05:00