refactor stray fptr variable into callbacks module.

This commit is contained in:
Enno Rehling 2017-05-08 22:44:18 +02:00
parent 53dc475d9d
commit d9fca4dcb3
5 changed files with 11 additions and 9 deletions

View File

@ -310,11 +310,10 @@ void register_tolua_helpers(void)
at_register(&at_building_action); at_register(&at_building_action);
callbacks.cast_spell = lua_callspell; callbacks.cast_spell = lua_callspell;
callbacks.use_item = use_item_lua;
register_function((pf_generic)lua_changeresource, "lua_changeresource");
item_use_fun = use_item_lua;
res_produce_fun = produce_resource_lua; res_produce_fun = produce_resource_lua;
res_limit_fun = limit_resource_lua; res_limit_fun = limit_resource_lua;
register_function((pf_generic)lua_changeresource, "lua_changeresource");
register_item_give(lua_giveitem, "lua_giveitem"); register_item_give(lua_giveitem, "lua_giveitem");
} }

View File

@ -24,9 +24,15 @@ extern "C" {
#endif #endif
struct castorder; struct castorder;
struct order;
struct unit;
struct item_type;
struct callback_struct { struct callback_struct {
int (*cast_spell)(struct castorder *co, const char *fname); int (*cast_spell)(struct castorder *co, const char *fname);
int (*use_item)(struct unit *u, const struct item_type *itype,
int amount, struct order *ord);
}; };
extern struct callback_struct callbacks; extern struct callback_struct callbacks;

View File

@ -213,8 +213,6 @@ struct rawmaterial_type *rmt_create(struct resource_type *rtype)
return rmtype; return rmtype;
} }
int(*item_use_fun)(struct unit *u, const struct item_type *itype, int amount,
struct order *ord);
int(*res_limit_fun)(const struct region *, const struct resource_type *); int(*res_limit_fun)(const struct region *, const struct resource_type *);
void(*res_produce_fun)(struct region *, const struct resource_type *, int); void(*res_produce_fun)(struct region *, const struct resource_type *, int);

View File

@ -73,8 +73,6 @@ extern "C" {
extern int(*res_limit_fun)(const struct region *, const struct resource_type *); extern int(*res_limit_fun)(const struct region *, const struct resource_type *);
extern void(*res_produce_fun)(struct region *, const struct resource_type *, int); extern void(*res_produce_fun)(struct region *, const struct resource_type *, int);
extern int (*item_use_fun)(struct unit *, const struct item_type *, int amount,
struct order *ord);
int limit_resource(const struct region *r, const struct resource_type *rtype); int limit_resource(const struct region *r, const struct resource_type *rtype);
void produce_resource(struct region *r, const struct resource_type *rtype, int amount); void produce_resource(struct region *r, const struct resource_type *rtype, int amount);

View File

@ -45,6 +45,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* kernel includes */ /* kernel includes */
#include <kernel/alliance.h> #include <kernel/alliance.h>
#include <kernel/ally.h> #include <kernel/ally.h>
#include <kernel/callbacks.h>
#include <kernel/connection.h> #include <kernel/connection.h>
#include <kernel/curse.h> #include <kernel/curse.h>
#include <kernel/building.h> #include <kernel/building.h>
@ -3218,7 +3219,7 @@ static int use_item(unit * u, const item_type * itype, int amount, struct order
} }
if (itype->flags & ITF_CANUSE) { if (itype->flags & ITF_CANUSE) {
int result = item_use_fun(u, itype, amount, ord); int result = callbacks.use_item(u, itype, amount, ord);
if (result > 0) { if (result > 0) {
use_pooled(u, itype->rtype, GET_DEFAULT, result); use_pooled(u, itype->rtype, GET_DEFAULT, result);
} }