forked from github/server
eliminated region_list use from wormholes
fixed a small memory leak
This commit is contained in:
parent
f00f537336
commit
3abcbb4717
2 changed files with 11 additions and 11 deletions
|
@ -16,7 +16,6 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct region_list;
|
|
||||||
struct newfaction;
|
struct newfaction;
|
||||||
|
|
||||||
typedef struct newfaction {
|
typedef struct newfaction {
|
||||||
|
|
|
@ -27,9 +27,10 @@
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
#include <util/rng.h>
|
|
||||||
#include <util/resolve.h>
|
|
||||||
#include <util/language.h>
|
#include <util/language.h>
|
||||||
|
#include <util/resolve.h>
|
||||||
|
#include <util/rng.h>
|
||||||
|
#include <util/quicklist.h>
|
||||||
#include <util/storage.h>
|
#include <util/storage.h>
|
||||||
|
|
||||||
/* libc includes */
|
/* libc includes */
|
||||||
|
@ -175,9 +176,9 @@ void create_wormholes(void)
|
||||||
{
|
{
|
||||||
#define WORMHOLE_CHANCE 10000
|
#define WORMHOLE_CHANCE 10000
|
||||||
const building_type *bt_wormhole = bt_find("wormhole");
|
const building_type *bt_wormhole = bt_find("wormhole");
|
||||||
region_list *rptr, *rlist = NULL;
|
quicklist *ql, *rlist = 0;
|
||||||
region *r = regions;
|
region *r = regions;
|
||||||
int i = 0, count = 0;
|
int qi, i = 0, count = 0;
|
||||||
region **match;
|
region **match;
|
||||||
|
|
||||||
if (bt_wormhole == NULL)
|
if (bt_wormhole == NULL)
|
||||||
|
@ -195,7 +196,7 @@ void create_wormholes(void)
|
||||||
}
|
}
|
||||||
if (r == NULL)
|
if (r == NULL)
|
||||||
break;
|
break;
|
||||||
add_regionlist(&rlist, r);
|
ql_push(&rlist, r);
|
||||||
++count;
|
++count;
|
||||||
r = r->next;
|
r = r->next;
|
||||||
}
|
}
|
||||||
|
@ -204,18 +205,18 @@ void create_wormholes(void)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
match = (region **) malloc(sizeof(region *) * count);
|
match = (region **) malloc(sizeof(region *) * count);
|
||||||
rptr = rlist;
|
|
||||||
while (i != count) {
|
for (ql = rlist,qi = 0; i != count; ql_advance(&ql, &qi, 1)) {
|
||||||
match[i++] = rptr->data;
|
match[i++] = (region *)ql_get(ql, qi);
|
||||||
rptr = rptr->next;
|
|
||||||
}
|
}
|
||||||
qsort(match, count, sizeof(region *), cmp_age);
|
qsort(match, count, sizeof(region *), cmp_age);
|
||||||
free_regionlist(rlist);
|
ql_free(rlist);
|
||||||
|
|
||||||
count /= 2;
|
count /= 2;
|
||||||
for (i = 0; i != count; ++i) {
|
for (i = 0; i != count; ++i) {
|
||||||
make_wormhole(bt_wormhole, match[i], match[i + count]);
|
make_wormhole(bt_wormhole, match[i], match[i + count]);
|
||||||
}
|
}
|
||||||
|
free(match);
|
||||||
}
|
}
|
||||||
|
|
||||||
void register_wormholes(void)
|
void register_wormholes(void)
|
||||||
|
|
Loading…
Reference in a new issue