Commit graph

425 commits

Author SHA1 Message Date
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
Chris Beck
720f4cdb83 use setfuncs instead of register, so we can do partial define 2014-11-10 15:34:13 -05:00
Chris Beck
76141a0de1 new code for lua protected calls in lua_kernel_base
In initial commit of the new lua kernels, I introduced a problem
by trying to use luaW_pcall and lua_pcall interchangeably via
polymorphism. This doesn't work because their return types don't
match, and it's alot of work to change luaW_pcall syntax. Besides
this there's no reason we can't use the custom error handler
everywhere.

This commits adds protected_call and load_string functions to lua
kernel base. These are an intended replacement for luaW_pcall,
and replace the "run" function. They do better error reporting
and allow to specify an error handler.

The error reporting is very flexible -- by default we select a
an error reporting function associated polymorphically to the lua
kernel, so the in-game lua kernel can send chat messages, and
others can do something else. However an arbitrary handler may
be specified, and exceptions instead of logging may also be
requested.
2014-11-10 15:32:19 -05:00
Chris Beck
ecc714e41e add application lua kernel and game launcher lua wrapper object
The application lua kernel is meant to interpret scripts to drive
the client. Its main features are, it stores a script in its
registry and provides a C++ function to call it with a config
as its argument. Its initialization also creates a "game_launcher"
object, which stands as a limited lua proxy for the C++
game_launcher object.

The game_launcher object is a table, holding a pointer to the
actual game_launcher it represents, and with metamethods to return
version info and the command line arguments. It also holds
callbacks to set the script for the current application lua kernel,
and to call the "play_multiplayer" function of game_launcher.
Currently it is readonly and you cannot write to its fields,
although that may change to allow the target server to be reset,
etc.

Some minor changes that are included in this commit:
- the actual C++ game launcher object provides an accessor to the
command line options.
- the scripting/lua_types.hpp file now has include guards
2014-11-09 20:47:26 -05:00
Chris Beck
ca309d98b2 branch off "lua_common" functions from api defn file
This includes the gettext and vconfig impl functions, and many
macros used to write lua callbacks. This code can't properly go in
the lua_kernel_base files, so it goes here.
2014-11-09 18:45:14 -05:00
Chris Beck
4541412ebc add lua_kernel_base as a super class of game_lua_kernel
This class holds some "basic" initialization and methods that we
would want in any lua kernel. It is not pure virtual, it could
be instantiated.
2014-11-09 18:45:14 -05:00
Chris Beck
042b72a4b8 rename scripting/lua.?pp to game_lua_kernel.?pp 2014-11-09 18:45:14 -05:00
Renamed from src/scripting/lua.cpp (Browse further)