summaryrefslogtreecommitdiff
path: root/lib/mods/mods_aux.lua
blob: 1562a566db097454d0e85ca6d5f76d2918d341b4 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
-- Ok some functions that we dont need are dangerous
--[[
execute = nil
getenv = nil
setlocale = nil
exit = nil
openfile = nil
writeto = nil
readfrom = nil
appendto = nil
remove = nil
rename = nil
tmpname = nil
]]
modules = {}

current_module = nil

function setup_module(mod)
	-- For standart game, nothing needs to be done
	if not mod.layout then return end

	for k, e in mod.layout do
		module_reset_dir(k, e)
	end
end

function init_module(i)
	setup_module(get_module(i))
end

function max_modules()
	local i = 0
	for k, e in modules do
		if type(k) == "number" and type(e) == "table" then
			i = i + 1
		end
	end
	return i
end

function get_module_name(j)
	local i = 0
	for k, e in modules do
		if type(k) == "number" and type(e) == "table" then
			if i == j then return e.name end
			i = i + 1
		end
	end
end

function get_module_desc(j)
	local i = 0
	for k, e in modules do
		if type(k) == "number" and type(e) == "table" then
			if i == j then return e.desc end
			i = i + 1
		end
	end
end

function get_module(j)
	local i = 0
	for k, e in modules do
		if type(k) == "number" and type(e) == "table" then
			if i == j then return e end
			i = i + 1
		end
	end
end

function find_module(name)
	local i = 0
	for k, e in modules do
		if type(k) == "number" and type(e) == "table" then
			if name == e.name then return i end
			i = i + 1
		end
	end
end

function assign_current_module(name)
	current_module = get_module(find_module(name))
end

function get_module_info(type, subtype)
	if subtype then
		return current_module[type][subtype]
	else
		return current_module[type]
	end
end

function exec_module_info(type, ...)
	return call(current_module[type], arg)
end

function module_savefile_loadable(savefile_mod, savefile_death)
	for _, e in current_module.mod_savefiles do
		if e[1] == savefile_mod then
			if e[2] == "all" then
				return TRUE
			elseif e[2] == "alive" and savefile_death == FALSE then
				return TRUE
			elseif e[2] == "dead" and savefile_death == TRUE then
				return TRUE
			end
		end
	end
	return FALSE
end

function scan_extra_modules()
	scansubdir(ANGBAND_DIR_MODULES)
	for i = 0, scansubdir_max - 1 do
		if (scansubdir_result[i + 1] ~= ".") and (scansubdir_result[i + 1] ~= "..") then
			local dir = path_build(ANGBAND_DIR_MODULES, scansubdir_result[i + 1])
			local file = path_build(dir, "module.lua")
			if file_exist(file) == TRUE then
				tome_dofile_anywhere(dir, "module.lua")
			end
		end
	end
end

function add_module(t)
	assert(t.name, "No module name")
	assert(type(t.version) == "table", "No module version")
	assert(t.desc, "No module desc")
	assert(t.author, "No module author")
	assert(t.mod_savefiles, "No loadable savefiles module mark")

	for _, e in modules do
		if type(e) == "table" and e.name == t.name then
			error("Module name already defined: "..t.name)
		end
	end

	if type(t.author) == "string" then
		t.author = { t.author, "unknown@unknown.net" }
	end

	for k, e in t.mod_savefiles do
		if type(e) == "string" then t.mod_savefiles[k] = { e, "all" } end
	end

	if type(t.desc) == "table" then
		local d = ""
		for k, e in t.desc do
			d = d .. e
			if k < getn(t.desc) then
				d = d .. "\n"
			end
		end
		t.desc = d
	end

	if not t.rand_quest then t.rand_quest = FALSE end
	if not t.C_quest then t.C_quest = FALSE end

	if not t.base_dungeon then t.base_dungeon = 4 end
	if not t.death_dungeon then t.death_dungeon = 28 end

	if not t.astral_dungeon then t.astral_dungeon = 8 end
	if not t.astral_wild_x then t.astral_wild_x = 45 end
	if not t.astral_wild_y then t.astral_wild_y = 19 end

	if not t.random_artifact_weapon_chance then
		t.random_artifact_weapon_chance = 30
	end
	if not t.random_artifact_armor_chance then
		t.random_artifact_armor_chance = 20
	end
	if not t.random_artifact_jewelry_chance then
		t.random_artifact_jewelry_chance = 20
	end

	if not t.max_plev then t.max_plev = 50 end
	if not t.max_skill_overage then t.max_skill_overage = 4 end
	if not t.skill_per_level then t.skill_per_level = function() return 6 end end

	if not t.allow_birth then t.allow_birth = TRUE end

	tinsert(modules, t)
end