13
static Bill *alive, *strays;
14
static int counters[HORDE_COUNTER_MAX + 1];
16
#define MAX_BILLS 100 /* max Bills per level */
18
#define UNLINK(bill, list) \
20
if ((bill)->next != NULL) \
21
(bill)->next->prev = (bill)->prev; \
22
if ((bill)->prev != NULL) \
23
(bill)->prev->next = (bill)->next; \
24
else if ((bill) == list) \
25
(list) = (bill)->next; \
26
(bill)->prev = NULL; \
27
(bill)->next = NULL; \
30
#define PREPEND(bill, list) \
32
(bill)->next = (list); \
34
(list)->prev = (bill); \
39
on(unsigned int lev) {
40
int perlevel = (int)((8 + 3 * lev) * Game_scale(2));
41
return MIN(perlevel, MAX_BILLS);
45
max_at_once(unsigned int lev) {
46
return MIN(2 + lev / 4, 12);
50
between(unsigned int lev) {
51
return MAX(14 - lev / 3, 10);
54
/* Launches Bills whenever called */
59
int off_screen = counters[HORDE_COUNTER_OFF];
61
if (max == 0 || off_screen == 0)
63
n = RAND(1, MIN(max, off_screen));
73
while (alive != NULL) {
78
while (strays != NULL) {
83
counters[HORDE_COUNTER_OFF] = on(Game_level());
84
counters[HORDE_COUNTER_ON] = 0;
88
Horde_update(int iteration) {
90
int level = Game_level();
91
if (iteration % between(level) == 0)
92
launch(max_at_once(level));
93
for (bill = alive; bill != NULL; bill = next) {
103
for (bill = strays; bill != NULL; bill = bill->next)
105
for (bill = alive; bill != NULL; bill = bill->next)
110
Horde_move_bill(Bill *bill) {
112
PREPEND(bill, strays);
116
Horde_remove_bill(Bill *bill) {
117
if (bill->state == BILL_STATE_STRAY)
118
UNLINK(bill, strays);
121
Network_clear_stray(bill);
126
Horde_add_bill(Bill *bill) {
127
if (bill->state == BILL_STATE_STRAY)
128
PREPEND(bill, strays);
130
PREPEND(bill, alive);
134
Horde_clicked_stray(int x, int y) {
137
for (bill = strays; bill != NULL; bill = bill->next) {
138
if (!Bill_clickedstray(bill, x, y))
140
UNLINK(bill, strays);
147
Horde_process_click(int x, int y) {
151
for (bill = alive; bill != NULL; bill = bill->next) {
152
if (bill->state == BILL_STATE_DYING ||
153
!Bill_clicked(bill, x, y))
155
if (bill->state == BILL_STATE_AT) {
157
comp = Network_get_computer(bill->target_c);
161
Bill_set_dying(bill);
168
Horde_inc_counter(int counter, int val) {
169
counters[counter] += val;
173
Horde_get_counter(int counter) {
174
return counters[counter];