aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_mainmenu.cpp
blob: e9a7a13b9f25fe995ceea7948df7ce79c1a9974e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "cpp_api/s_mainmenu.h"
#include "cpp_api/s_internal.h"
#include "common/c_converter.h"

void ScriptApiMainMenu::setMainMenuData(MainMenuDataForScript *data)
{
	SCRIPTAPI_PRECHECKHEADER

	lua_getglobal(L, "gamedata");
	int gamedata_idx = lua_gettop(L);
	lua_pushstring(L, "errormessage");
	if (!data->errormessage.empty()) {
		lua_pushstring(L, data->errormessage.c_str());
	} else {
		lua_pushnil(L);
	}
	lua_settable(L, gamedata_idx);
	setboolfield(L, gamedata_idx, "reconnect_requested",
		data->reconnect_requested);
	lua_pop(L, 1);
}

void ScriptApiMainMenu::handleMainMenuEvent(std::string text)
{
	SCRIPTAPI_PRECHECKHEADER

	int error_handler = PUSH_ERROR_HANDLER(L);

	// Get handler function
	lua_getglobal(L, "core");
	lua_getfield(L, -1, "event_handler");
	lua_remove(L, -2); // Remove core
	if (lua_isnil(L, -1)) {
		lua_pop(L, 1); // Pop event_handler
		return;
	}
	luaL_checktype(L, -1, LUA_TFUNCTION);

	// Call it
	lua_pushstring(L, text.c_str());
	PCALL_RES(lua_pcall(L, 1, 0, error_handler));
	lua_pop(L, 1);  // Pop error handler
}

void ScriptApiMainMenu::handleMainMenuButtons(const StringMap &fields)
{
	SCRIPTAPI_PRECHECKHEADER

	int error_handler = PUSH_ERROR_HANDLER(L);

	// Get handler function
	lua_getglobal(L, "core");
	lua_getfield(L, -1, "button_handler");
	lua_remove(L, -2); // Remove core
	if (lua_isnil(L, -1)) {
		lua_pop(L, 1); // Pop button handler
		return;
	}
	luaL_checktype(L, -1, LUA_TFUNCTION);

	// Convert fields to a Lua table
	lua_newtable(L);
	StringMap::const_iterator it;
	for (it = fields.begin(); it != fields.end(); ++it) {
		const std::string &name = it->first;
		const std::string &value = it->second;
		lua_pushstring(L, name.c_str());
		lua_pushlstring(L, value.c_str(), value.size());
		lua_settable(L, -3);
	}

	// Call it
	PCALL_RES(lua_pcall(L, 1, 0, error_handler));
	lua_pop(L, 1);  // Pop error handler
}

">, wield_scale = {x = 1, y = 1, z = 2.5}, range = 10, tool_capabilities = { full_punch_interval = 0.5, max_drop_level = 3, groupcaps = { crumbly = caps, cracky = caps, snappy = caps, choppy = caps, oddly_breakable_by_hand = caps, -- dig_immediate group doesn't use value 1. Value 3 is instant dig dig_immediate = {times = {[2] = digtime, [3] = 0}, uses = 0, maxlevel = 256}, }, damage_groups = {fleshy = 10}, } }) else minetest.register_item(":", { type = "none", wield_image = "wieldhand.png", wield_scale = {x = 1, y = 1, z = 2.5}, tool_capabilities = { full_punch_interval = 0.9, max_drop_level = 0, groupcaps = { crumbly = {times = {[2] = 3.00, [3] = 0.70}, uses = 0, maxlevel = 1}, snappy = {times = {[3] = 0.40}, uses = 0, maxlevel = 1}, oddly_breakable_by_hand = {times = {[1] = 3.50, [2] = 2.00, [3] = 0.70}, uses = 0} }, damage_groups = {fleshy = 1}, } }) end -- Mese Pickaxe: special tool that digs "everything" instantly minetest.register_tool("basetools:pick_mese", { description = "Mese Pickaxe".."\n".. "Digs diggable nodes instantly", inventory_image = "basetools_mesepick.png", tool_capabilities = { full_punch_interval = 1.0, max_drop_level=3, groupcaps={ cracky={times={[1]=0.0, [2]=0.0, [3]=0.0}, maxlevel=255}, crumbly={times={[1]=0.0, [2]=0.0, [3]=0.0}, maxlevel=255}, snappy={times={[1]=0.0, [2]=0.0, [3]=0.0}, maxlevel=255}, choppy={times={[1]=0.0, [2]=0.0, [3]=0.0}, maxlevel=255}, dig_immediate={times={[1]=0.0, [2]=0.0, [3]=0.0}, maxlevel=255}, }, damage_groups = {fleshy=100}, }, }) -- -- Pickaxes: Dig cracky -- -- This should break after only 1 use minetest.register_tool("basetools:pick_dirt", { description = "Dirt Pickaxe".."\n".. "Digs cracky=3".."\n".. "1 use only", inventory_image = "basetools_dirtpick.png", tool_capabilities = { max_drop_level=0, groupcaps={ cracky={times={[3]=2.00}, uses=1, maxlevel=0} }, }, }) minetest.register_tool("basetools:pick_wood", { description = "Wooden Pickaxe".."\n".. "Digs cracky=3", inventory_image = "basetools_woodpick.png", tool_capabilities = { max_drop_level=0, groupcaps={ cracky={times={[3]=2.00}, uses=30, maxlevel=0} }, }, }) minetest.register_tool("basetools:pick_stone", { description = "Stone Pickaxe".."\n".. "Digs cracky=2..3", inventory_image = "basetools_stonepick.png", tool_capabilities = { max_drop_level=0, groupcaps={ cracky={times={[2]=1.20, [3]=0.80}, uses=60, maxlevel=0} }, }, }) minetest.register_tool("basetools:pick_steel", { description = "Steel Pickaxe".."\n".. "Digs cracky=1..3", inventory_image = "basetools_steelpick.png", tool_capabilities = { max_drop_level=1, groupcaps={ cracky={times={[1]=4.00, [2]=1.60, [3]=1.00}, uses=90, maxlevel=0} }, }, }) minetest.register_tool("basetools:pick_steel_l1", { description = "Steel Pickaxe Level 1".."\n".. "Digs cracky=1..3".."\n".. "maxlevel=1", inventory_image = "basetools_steelpick_l1.png", tool_capabilities = { max_drop_level=1, groupcaps={ cracky={times={[1]=4.00, [2]=1.60, [3]=1.00}, uses=90, maxlevel=1} }, }, }) minetest.register_tool("basetools:pick_steel_l2", { description = "Steel Pickaxe Level 2".."\n".. "Digs cracky=1..3".."\n".. "maxlevel=2", inventory_image = "basetools_steelpick_l2.png", tool_capabilities = { max_drop_level=1, groupcaps={ cracky={times={[1]=4.00, [2]=1.60, [3]=1.00}, uses=90, maxlevel=2} }, }, }) -- -- Shovels (dig crumbly) -- minetest.register_tool("basetools:shovel_wood", { description = "Wooden Shovel".."\n".. "Digs crumbly=3", inventory_image = "basetools_woodshovel.png", tool_capabilities = { max_drop_level=0, groupcaps={ crumbly={times={[3]=0.50}, uses=30, maxlevel=0} }, }, }) minetest.register_tool("basetools:shovel_stone", { description = "Stone Shovel".."\n".. "Digs crumbly=2..3", inventory_image = "basetools_stoneshovel.png", tool_capabilities = { max_drop_level=0, groupcaps={ crumbly={times={[2]=0.50, [3]=0.30}, uses=60, maxlevel=0} }, }, }) minetest.register_tool("basetools:shovel_steel", { description = "Steel Shovel".."\n".. "Digs crumbly=1..3", inventory_image = "basetools_steelshovel.png", tool_capabilities = { max_drop_level=1, groupcaps={ crumbly={times={[1]=1.00, [2]=0.70, [3]=0.60}, uses=90, maxlevel=0} }, }, }) -- -- Axes (dig choppy) -- minetest.register_tool("basetools:axe_wood", { description = "Wooden Axe".."\n".. "Digs choppy=3", inventory_image = "basetools_woodaxe.png", tool_capabilities = { max_drop_level=0, groupcaps={ choppy={times={[3]=0.80}, uses=30, maxlevel=0}, }, }, }) minetest.register_tool("basetools:axe_stone", { description = "Stone Axe".."\n".. "Digs choppy=2..3", inventory_image = "basetools_stoneaxe.png", tool_capabilities = { max_drop_level=0, groupcaps={ choppy={times={[2]=1.00, [3]=0.60}, uses=60, maxlevel=0}, }, }, }) minetest.register_tool("basetools:axe_steel", { description = "Steel Axe".."\n".. "Digs choppy=1..3", inventory_image = "basetools_steelaxe.png", tool_capabilities = { max_drop_level=1, groupcaps={ choppy={times={[1]=2.00, [2]=0.80, [3]=0.40}, uses=90, maxlevel=0}, }, }, }) -- -- Shears (dig snappy) -- minetest.register_tool("basetools:shears_wood", { description = "Wooden Shears".."\n".. "Digs snappy=3", inventory_image = "basetools_woodshears.png", tool_capabilities = { max_drop_level=0, groupcaps={ snappy={times={[3]=1.00}, uses=30, maxlevel=0}, }, }, }) minetest.register_tool("basetools:shears_stone", { description = "Stone Shears".."\n".. "Digs snappy=2..3", inventory_image = "basetools_stoneshears.png", tool_capabilities = { max_drop_level=0, groupcaps={ snappy={times={[2]=1.00, [3]=0.50}, uses=60, maxlevel=0}, }, }, }) minetest.register_tool("basetools:shears_steel", { description = "Steel Shears".."\n".. "Digs snappy=1..3",