forked from github/server
WIP: still converting to clibs/selist
This commit is contained in:
parent
955997d58c
commit
d9213c8f25
2
clibs
2
clibs
|
@ -1 +1 @@
|
|||
Subproject commit 339ac5680ec9027c88c4516c72b9da8233b6f3e3
|
||||
Subproject commit daa9de08314a75a4d77ef4e08c713088a96a5ca5
|
|
@ -59,22 +59,18 @@ void free_donations(void) {
|
|||
transfers = 0;
|
||||
}
|
||||
|
||||
static void report_transfer(faction *f1, faction *f2, region *r, int amount) {
|
||||
struct message *msg = msg_message("donation",
|
||||
"from to amount", f1, f2, amount);
|
||||
r_addmessage(r, f1, msg);
|
||||
r_addmessage(r, f2, msg);
|
||||
msg_release(msg);
|
||||
static void report_transfer(void *data) {
|
||||
transfer *tf = (transfer *)data;
|
||||
if (tf->amount > 0) {
|
||||
struct message *msg = msg_message("donation",
|
||||
"from to amount", tf->f1, tf->f2, tf->amount);
|
||||
r_addmessage(tf->r, tf->f1, msg);
|
||||
r_addmessage(tf->r, tf->f2, msg);
|
||||
msg_release(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void report_donations(void)
|
||||
{
|
||||
ql_iter qli = qli_init(&transfers);
|
||||
|
||||
while (qli_more(qli)) {
|
||||
transfer *tf = (transfer *)qli_next(&qli);
|
||||
if (tf->amount > 0) {
|
||||
report_transfer(tf->f1, tf->f2, tf->r, tf->amount);
|
||||
}
|
||||
}
|
||||
selist_foreach(transfers, report_transfer);
|
||||
}
|
||||
|
|
|
@ -308,7 +308,7 @@ void ct_register(const curse_type * ct)
|
|||
unsigned int hash = tolower(ct->cname[0]) & 0xFF;
|
||||
quicklist **ctlp = cursetypes + hash;
|
||||
|
||||
ql_set_insert(ctlp, (void *)ct);
|
||||
selist_set_insert(ctlp, (void *)ct, NULL);
|
||||
++ct_changes;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ void free_spells(void) {
|
|||
|
||||
void add_spell(struct quicklist **slistp, spell * sp)
|
||||
{
|
||||
if (!ql_set_insert(slistp, sp)) {
|
||||
if (!selist_set_insert(slistp, sp, NULL)) {
|
||||
log_error("add_spell: the list already contains the spell '%s'.\n", sp->sname);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,30 @@
|
|||
#include "quicklist.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
bool ql_set_insert_ex(struct quicklist **qlp, void *data, int (*cmp_cb)(const void *lhs, const void *rhs));
|
||||
bool ql_set_find_ex(struct quicklist **qlp, int *qip, const void *data, int (*cmp_cb)(const void *lhs, const void *rhs));
|
||||
bool ql_set_remove(struct quicklist **qlp, const void *data)
|
||||
{
|
||||
int qi, qn;
|
||||
quicklist *ql = *qlp;
|
||||
|
||||
if (!ql)
|
||||
return false;
|
||||
|
||||
qn = selist_length(ql);
|
||||
for (qi = 0; qi != qn; ++qi) {
|
||||
void *qd = selist_get(ql, qi);
|
||||
if (qd == data) {
|
||||
return selist_delete(qlp, qi) == 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ql_set_insert(struct quicklist **qlp, void *data)
|
||||
{
|
||||
return selist_set_insert(qlp, data, NULL);
|
||||
}
|
||||
|
||||
bool ql_set_find(struct quicklist **qlp, int *qip, const void *data)
|
||||
{
|
||||
return selist_set_find(qlp, qip, data, NULL);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,11 @@
|
|||
|
||||
#define selist quicklist
|
||||
#define selist_free ql_free
|
||||
#define selist_delete ql_delete
|
||||
#define selist_foreach ql_foreach
|
||||
#define selist_get ql_get
|
||||
#define selist_replace ql_replace
|
||||
#define selist_length ql_length
|
||||
#define selist_push ql_push
|
||||
#define selist_empty ql_empty
|
||||
#define selist_advance ql_advance
|
||||
|
@ -12,3 +16,4 @@
|
|||
typedef void(*ql_cb)(void *);
|
||||
bool ql_set_insert_ex(struct quicklist **qlp, void *data, int (*cmp_cb)(const void *lhs, const void *rhs));
|
||||
bool ql_set_find_ex(struct quicklist **qlp, int *qip, const void *data, int (*cmp_cb)(const void *lhs, const void *rhs));
|
||||
|
||||
|
|
|
@ -99,18 +99,30 @@ bool travelthru_cansee(const struct region *r, const struct faction *f, const st
|
|||
return false;
|
||||
}
|
||||
|
||||
void travelthru_map(region * r, void(*cb)(region *, struct unit *, void *), void *cbdata)
|
||||
struct cb_data {
|
||||
void(*call)(region *, struct unit *, void *);
|
||||
void *data;
|
||||
struct region *r;
|
||||
};
|
||||
|
||||
void cb_map(void *data, void *ex) {
|
||||
struct cb_data *cb = (struct cb_data *)ex;
|
||||
struct unit *u = (struct unit *)data;
|
||||
cb->call(cb->r, u, cb->data);
|
||||
}
|
||||
|
||||
void travelthru_map(region * r, void(*cb)(region *, struct unit *, void *), void *data)
|
||||
{
|
||||
attrib *a;
|
||||
struct cb_data cbdata;
|
||||
|
||||
assert(r);
|
||||
cbdata.call = cb;
|
||||
cbdata.data = data;
|
||||
cbdata.r = r;
|
||||
a = a_find(r->attribs, &at_travelunit);
|
||||
if (a) {
|
||||
quicklist *ql;
|
||||
ql_iter qi;
|
||||
ql = (quicklist *)a->data.v;
|
||||
for (qi = qli_init(&ql); qli_more(qi);) {
|
||||
unit *u = (unit *)qli_next(&qi);
|
||||
cb(r, u, cbdata);
|
||||
}
|
||||
quicklist *ql = (quicklist *)a->data.v;
|
||||
selist_foreach_ex(ql, cb_map, &cbdata);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -215,7 +215,7 @@ const message_type *mt_register(message_type * type)
|
|||
unsigned int hash = hashstring(type->name) % MT_MAXHASH;
|
||||
quicklist **qlp = messagetypes + hash;
|
||||
|
||||
if (ql_set_insert(qlp, type)) {
|
||||
if (selist_set_insert(qlp, type, NULL)) {
|
||||
type->key = mt_id(type);
|
||||
}
|
||||
return type;
|
||||
|
|
Loading…
Reference in New Issue