summaryrefslogtreecommitdiff
path: root/src/map/refine.p.h
blob: 3247d15c9e54c5ef65320a1237bd22a238f2e601 (plain) (blame)
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
/**
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
* Copyright (C) 2019  Hercules Dev Team
*
* Hercules is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef MAP_REFINE_P_H
#define MAP_REFINE_P_H

/** @file
 * Private header for the refine interface.
 **/

#include "refine.h"
#include "common/conf.h"
/* Enums */
enum refine_announce_condition {
	REFINE_ANNOUNCE_SUCCESS = 0x1,
	REFINE_ANNOUNCE_FAILURE = 0x2,
	REFINE_ANNOUNCE_ALWAYS = REFINE_ANNOUNCE_SUCCESS | REFINE_ANNOUNCE_FAILURE,
};

/* Structures */
struct s_refine_info {
	int chance[REFINE_CHANCE_TYPE_MAX][MAX_REFINE]; //< success chance
	int bonus[MAX_REFINE];                          //< cumulative fixed bonus damage
	int randombonus_max[MAX_REFINE];                //< cumulative maximum random bonus damage
	struct s_refine_requirement refine_requirements[MAX_REFINE]; //< The requirements used for refinery UI
};

struct refine_interface_dbs {
	struct s_refine_info refine_info[REFINE_TYPE_MAX];
};

/**
 * Refine Private Interface
 **/
struct refine_interface_private {
	struct refine_interface_dbs *dbs;

	/**
	 * Processes a refine_db.conf entry.
	 *
	 * @param r      Libconfig setting entry. It is expected to be valid and it
	 *               won't be freed (it is care of the caller to do so if
	 *               necessary)
	 * @param n      Ordinal number of the entry, to be displayed in case of
	 *               validation errors.
	 * @param source Source of the entry (file name), to be displayed in case of
	 *               validation errors.
	 * @return # of the validated entry, or 0 in case of failure.
	 **/
	int (*readdb_refine_libconfig_sub) (struct config_setting_t *r, const char *name, const char *source);

	/**
	 * Reads from a libconfig-formatted refine_db.conf file.
	 *
	 * @param *filename File name, relative to the database path.
	 * @return The number of found entries.
	 **/
	int (*readdb_refine_libconfig) (const char *filename);

	/**
	 * Converts refine database announce behvaior string to enum refine_announce_condition
	 * @param str the string to convert
	 * @param result pointer to where the converted value will be held
	 * @return true on success, false otherwise.
	**/
	bool (*announce_behavior_string2enum) (const char *str, unsigned int *result);

	/**
	 * Converts refine database failure behvaior string to enum refine_ui_failure_behavior
	 * @param str the string to convert
	 * @param result pointer to where the converted value will be held
	 * @return true on success, false otherwise.
	 **/
	bool (*failure_behavior_string2enum) (const char *str, enum refine_ui_failure_behavior *result);

	/**
	 * Processes a refine_db.conf RefineryUISettings items entry.
	 *
	 * @param elem   Libconfig setting entry. It is expected to be valid and it
	 *               won't be freed (it is care of the caller to do so if
	 *               necessary)
	 * @param req    a pointer to requirements struct to fill with the item data
	 * @param name   the current element name
	 * @param source Source of the entry (file name), to be displayed in case of
	 *               validation errors.
	 * @return true on success, false otherwise.
	 **/
	bool (*readdb_refinery_ui_settings_items) (const struct config_setting_t *elem, struct s_refine_requirement *req, const char *name, const char *source);

	/**
	 * Processes a refine_db.conf RefineryUISettings entry.
	 *
	 * @param elem   Libconfig setting entry. It is expected to be valid and it
	 *               won't be freed (it is care of the caller to do so if
	 *               necessary)
	 * @param type   the type index in refine database to fill the data
	 * @param name   the current element name
	 * @param source Source of the entry (file name), to be displayed in case of
	 *               validation errors.
	 * @return true on success, false otherwise.
	 **/
	bool (*readdb_refinery_ui_settings_sub) (const struct config_setting_t *elem, int type, const char *name, const char *source);

	/**
	 * Reads a refine_db.conf RefineryUISettings entry and sends it to be processed.
	 *
	 * @param r      Libconfig setting entry. It is expected to be valid and it
	 *               won't be freed (it is care of the caller to do so if
	 *               necessary)
	 * @param type   the type index in refine database to fill the data
	 * @param name   the current element name
	 * @param source Source of the entry (file name), to be displayed in case of
	 *               validation errors.
	 * @return true on success, false otherwise.
	 **/
	int (*readdb_refinery_ui_settings) (const struct config_setting_t *r, int type, const char *name, const char *source);

	/**
	 * Checks if a given item in player's inventory is refineable.
	 * @param sd player session data.
	 * @param item_index the item index in player's inventory.
	 * @return true if item is refineable, false otherwise.
	 **/
	bool (*is_refinable) (struct map_session_data *sd, int item_index);
};

#endif