14
/* speed at which OS drops */
17
/* speed of moving Bill */
21
#define WCELS 4 /* # of bill walking animation frames */
22
#define DCELS 5 /* # of bill dying animation frames */
23
#define ACELS 13 /* # of bill switching OS frames */
25
static Picture *lcels[WCELS], *rcels[WCELS], *acels[ACELS], *dcels[DCELS];
26
static int width, height;
29
get_border(int *x, int *y) {
31
int screensize = Game_screensize();
34
*x = RAND(0, screensize - width);
36
*y = RAND(0, screensize - height);
54
/* Adds a bill to the in state */
56
Bill_enter(Bill **billp) {
60
bill = xalloc(sizeof *bill);
62
bill->state = BILL_STATE_IN;
63
get_border(&bill->x, &bill->y);
66
bill->cargo = OS_WINGDOWS;
69
bill->target_c = RAND(0, Network_num_computers() - 1);
70
computer = Network_get_computer(bill->target_c);
71
bill->target_x = computer->x + Computer_width() - BILL_OFFSET_X;
72
bill->target_y = computer->y + BILL_OFFSET_Y;
73
Horde_inc_counter(HORDE_COUNTER_ON, 1);
74
Horde_inc_counter(HORDE_COUNTER_OFF, -1);
81
step_size(unsigned int level) {
82
return MIN(11 + level, 15);
85
/* Moves bill toward his target - returns whether or not he moved */
87
move(Bill *bill, int mode) {
88
int xdist = bill->target_x - bill->x;
89
int ydist = bill->target_y - bill->y;
90
int step = step_size(Game_level());
92
int signx = xdist >= 0 ? 1 : -1;
93
int signy = ydist >= 0 ? 1 : -1;
98
else if (xdist < step && ydist < step) {
99
bill->x = bill->target_x;
100
bill->y = bill->target_y;
103
dx = (xdist*step*signx)/(xdist+ydist);
104
dy = (ydist*step*signy)/(xdist+ydist);
120
draw_std(Bill *bill) {
121
if (bill->cargo >= 0)
122
OS_draw(bill->cargo, bill->x + bill->x_offset,
123
bill->y + bill->y_offset);
124
UI_draw(bill->cels[bill->index], bill->x, bill->y);
128
draw_at(Bill *bill) {
129
Computer *computer = Network_get_computer(bill->target_c);
130
if (bill->index > 6 && bill->index < 12)
131
OS_draw(0, bill->x + bill->sx, bill->y + bill->sy);
132
if (bill->cargo >= 0)
133
OS_draw(bill->cargo, bill->x + bill->x_offset,
134
bill->y + bill->y_offset);
135
UI_draw(bill->cels[bill->index], computer->x, computer->y);
139
draw_stray(Bill *bill) {
140
OS_draw(bill->cargo, bill->x, bill->y);
144
Bill_draw(Bill *bill) {
145
switch (bill->state) {
148
case BILL_STATE_DYING:
154
case BILL_STATE_STRAY:
162
/* Update Bill's position */
164
update_in(Bill *bill) {
165
int moved = move(bill, SLOW);
166
Computer *computer = Network_get_computer(bill->target_c);
167
if (!moved && computer->os != OS_WINGDOWS && !computer->busy) {
171
bill->state = BILL_STATE_AT;
177
i = RAND(0, Network_num_computers() - 1);
178
} while (i == bill->target_c);
179
computer = Network_get_computer(i);
181
bill->target_x = computer->x + Computer_width() - BILL_OFFSET_X;
182
bill->target_y = computer->y + BILL_OFFSET_Y;
185
bill->index %= WCELS;
186
bill->y_offset += (8 * (bill->index % 2) - 4);
189
/* Update Bill standing at a computer */
191
update_at(Bill *bill) {
192
Computer *computer = Network_get_computer(bill->target_c);
193
if (bill->index == 0 && computer->os == OS_OFF) {
195
if (computer->stray == NULL)
198
bill->cargo = computer->stray->cargo;
199
Horde_remove_bill(computer->stray);
200
computer->stray = NULL;
204
if (bill->index == 13) {
205
bill->y_offset = -15;
207
get_border(&bill->target_x, &bill->target_y);
210
bill->state = BILL_STATE_OUT;
214
bill->y_offset = height - OS_height();
215
switch (bill->index) {
234
if (computer->os != OS_OFF) {
235
Network_inc_counter(NETWORK_COUNTER_BASE, -1);
236
Network_inc_counter(NETWORK_COUNTER_OFF, 1);
237
bill->cargo = computer->os;
241
bill->x_offset += 21;
243
computer->os = OS_OFF;
244
bill->y_offset = -15;
249
bill->sy = bill->y_offset;
271
computer->os = OS_WINGDOWS;
272
Network_inc_counter(NETWORK_COUNTER_OFF, -1);
273
Network_inc_counter(NETWORK_COUNTER_WIN, 1);
281
/* Updates Bill fleeing with his ill gotten gain */
283
update_out(Bill *bill) {
284
int screensize = Game_screensize();
285
if (UI_intersect(bill->x, bill->y, width, height, 0, 0,
286
screensize, screensize))
290
bill->index %= WCELS;
291
bill->y_offset += (8*(bill->index%2)-4);
294
Horde_remove_bill(bill);
295
Horde_inc_counter(HORDE_COUNTER_ON, -1);
296
Horde_inc_counter(HORDE_COUNTER_OFF, 1);
301
/* Updates a Bill who is dying */
303
update_dying(Bill *bill) {
304
if (bill->index < DCELS - 1){
305
bill->y_offset += (bill->index * GRAVITY);
309
bill->y += bill->y_offset;
310
if (bill->cargo < 0 || bill->cargo == OS_WINGDOWS)
311
Horde_remove_bill(bill);
313
Horde_move_bill(bill);
314
bill->state = BILL_STATE_STRAY;
316
Horde_inc_counter(HORDE_COUNTER_ON, -1);
321
Bill_update(Bill *bill) {
322
switch (bill->state) {
332
case BILL_STATE_DYING:
341
Bill_set_dying(Bill *bill) {
345
bill->y_offset = -15;
346
bill->state = BILL_STATE_DYING;
350
Bill_clicked(Bill *bill, int locx, int locy) {
351
return (locx > bill->x && locx < bill->x + width &&
352
locy > bill->y && locy < bill->y + height);
356
Bill_clickedstray(Bill *bill, int locx, int locy) {
357
return (locx > bill->x && locx < bill->x + OS_width() &&
358
locy > bill->y && locy < bill->y + OS_height());
364
for (i = 0; i < WCELS - 1; i++) {
365
UI_load_picture_indexed("billL", i, 1, &lcels[i]);
366
UI_load_picture_indexed("billR", i, 1, &rcels[i]);
368
lcels[WCELS - 1] = lcels[1];
369
rcels[WCELS - 1] = rcels[1];
371
for (i = 0; i < DCELS; i++)
372
UI_load_picture_indexed("billD", i, 1, &dcels[i]);
373
width = UI_picture_width(dcels[0]);
374
height = UI_picture_height(dcels[0]);
376
for (i = 0; i < ACELS; i++)
377
UI_load_picture_indexed("billA", i, 1, &acels[i]);
391
Bill_get_state(Bill *bill) {