forked from github/server
refactor resource callbacks into callbacks module
This commit is contained in:
parent
437c9c2d2e
commit
6b7dcadf84
|
@ -311,8 +311,8 @@ void register_tolua_helpers(void)
|
||||||
|
|
||||||
callbacks.cast_spell = lua_callspell;
|
callbacks.cast_spell = lua_callspell;
|
||||||
callbacks.use_item = use_item_lua;
|
callbacks.use_item = use_item_lua;
|
||||||
res_produce_fun = produce_resource_lua;
|
callbacks.produce_resource = produce_resource_lua;
|
||||||
res_limit_fun = limit_resource_lua;
|
callbacks.limit_resource = limit_resource_lua;
|
||||||
|
|
||||||
register_function((pf_generic)lua_changeresource, "lua_changeresource");
|
register_function((pf_generic)lua_changeresource, "lua_changeresource");
|
||||||
register_item_give(lua_giveitem, "lua_giveitem");
|
register_item_give(lua_giveitem, "lua_giveitem");
|
||||||
|
|
|
@ -26,13 +26,16 @@ extern "C" {
|
||||||
struct castorder;
|
struct castorder;
|
||||||
struct order;
|
struct order;
|
||||||
struct unit;
|
struct unit;
|
||||||
|
struct region;
|
||||||
struct item_type;
|
struct item_type;
|
||||||
|
struct resource_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 (*use_item)(struct unit *u, const struct item_type *itype,
|
||||||
int amount, struct order *ord);
|
int amount, struct order *ord);
|
||||||
|
void(*produce_resource)(struct region *, const struct resource_type *, int);
|
||||||
|
int(*limit_resource)(const struct region *, const struct resource_type *);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct callback_struct callbacks;
|
extern struct callback_struct callbacks;
|
||||||
|
|
|
@ -11,10 +11,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include <kernel/config.h>
|
|
||||||
#include "resources.h"
|
#include "resources.h"
|
||||||
|
|
||||||
/* kernel includes */
|
/* kernel includes */
|
||||||
|
#include <kernel/config.h>
|
||||||
|
#include <kernel/callbacks.h>
|
||||||
#include "build.h"
|
#include "build.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "region.h"
|
#include "region.h"
|
||||||
|
@ -213,14 +214,11 @@ struct rawmaterial_type *rmt_create(struct resource_type *rtype)
|
||||||
return rmtype;
|
return rmtype;
|
||||||
}
|
}
|
||||||
|
|
||||||
int(*res_limit_fun)(const struct region *, const struct resource_type *);
|
|
||||||
void(*res_produce_fun)(struct region *, const struct resource_type *, int);
|
|
||||||
|
|
||||||
int limit_resource(const struct region *r, const resource_type *rtype)
|
int limit_resource(const struct region *r, const resource_type *rtype)
|
||||||
{
|
{
|
||||||
assert(!rtype->raw);
|
assert(!rtype->raw);
|
||||||
if (res_limit_fun) {
|
if (callbacks.limit_resource) {
|
||||||
return res_limit_fun(r, rtype);
|
return callbacks.limit_resource(r, rtype);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -228,7 +226,7 @@ int limit_resource(const struct region *r, const 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)
|
||||||
{
|
{
|
||||||
assert(!rtype->raw);
|
assert(!rtype->raw);
|
||||||
if (res_produce_fun) {
|
if (callbacks.produce_resource) {
|
||||||
res_produce_fun(r, rtype, amount);
|
callbacks.produce_resource(r, rtype, amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,11 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <util/variant.h>
|
||||||
|
|
||||||
struct building_type;
|
struct building_type;
|
||||||
struct race;
|
struct race;
|
||||||
|
struct region;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
RM_USED = 1 << 0, /* resource has been used */
|
RM_USED = 1 << 0, /* resource has been used */
|
||||||
|
@ -71,8 +74,6 @@ extern "C" {
|
||||||
int base, int divisor, const struct resource_type *rtype);
|
int base, int divisor, const struct resource_type *rtype);
|
||||||
struct rawmaterial_type *rmt_create(struct resource_type *rtype);
|
struct rawmaterial_type *rmt_create(struct resource_type *rtype);
|
||||||
|
|
||||||
extern int(*res_limit_fun)(const struct region *, const struct resource_type *);
|
|
||||||
extern void(*res_produce_fun)(struct region *, const struct resource_type *, int);
|
|
||||||
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);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue