4
#include <libgnome/libgnome.h>
14
int Game::RAND(int lb, int ub) {
15
return (rand()%(ub-lb+1) + lb);
18
int Game::MAX(int x, int y) {
22
int Game::MIN(int x, int y) {
26
int Game::INTERSECT(int x1, int y1, int w1, int h1, int x2, int y2, int w2,
29
return (((x2-x1<=w1 && x2-x1>=0) || (x1-x2<=w2 && x1-x2>=0))
30
&& ((y2-y1<=h1 && y2-y1>=0) || (y1-y2<=h2 && y1-y2>=0)));
33
void Game::setup_level (int lev) {
37
ui.set_cursor(DEFAULTC);
39
iteration = efficiency = 0;
42
void Game::start(int lev) {
43
/* Looks like the high number we can get is 8+3*level, so ensure
44
G_MAXINT is not going to be passed and crash */
46
if (lev > G_MAXINT/8+3) return;
51
ui.set_pausebutton(TRUE);
59
void Game::update_info() {
61
sprintf (str, "Bill:%d/%d System:%d/%d/%d Level: %d Score:%d",
62
bill.on_screen, bill.off_screen, net.base, net.off,
63
net.win, level, score);
64
ui.draw_str(str, 5, scrheight-5);
65
efficiency += ((100*net.base-10*net.win)/net.units);
68
void Game::update_score (int action) {
70
case ENDLEVEL: score+=(level*efficiency/iteration); break;
71
default: score+=(action*action*BILLPOINTS);
75
void Game::warp_to_level (int lev) {
77
if (lev <= level || lev > G_MAXINT/8+3 ) return;
86
void Game::button_press(int x, int y) {
87
int i, counter=0, flag=0;
88
if (state != PLAYING) return;
90
if (bucket.clicked(x, y)) {
91
ui.set_cursor(BUCKETC);
94
for (i=0; i < bill.MAX_BILLS && !flag; i++) {
95
if (bill.list[i].state == bill.list[i].OFF
96
|| bill.list[i].state == bill.list[i].DYING)
98
if (bill.list[i].state == bill.list[i].STRAY &&
99
bill.list[i].clickedstray(x, y))
101
ui.set_cursor (bill.list[i].cargo);
105
else if (bill.list[i].state != bill.list[i].STRAY &&
106
bill.list[i].clicked(x, y))
108
if (bill.list[i].state == bill.list[i].AT)
109
net.computers[bill.list[i].target_c].busy=0;
110
bill.list[i].index = -1;
111
bill.list[i].cels = bill.dcels;
112
bill.list[i].x_offset = -2;
113
bill.list[i].y_offset = -15;
114
bill.list[i].state = bill.list[i].DYING;
118
if (counter) update_score(counter);
121
void Game::button_release(int x, int y) {
123
ui.set_cursor (DEFAULTC);
124
if (state != PLAYING || grabbed == EMPTY)
126
if (grabbed == BUCKET) {
128
for (i=0; i<net.ncables; i++)
129
if (net.cables[i].onspark(x, y)) {
130
net.cables[i].active=0;
131
net.cables[i].delay = spark.delay(level);
135
for (i=0; i<net.units; i++)
136
if (net.computers[i].oncomputer(x, y)
138
net.computers[i].compatible (bill.list[grabbed].cargo)
140
(net.computers[i].os == OS.WINGDOWS ||
141
net.computers[i].os == OS.OFF))
144
if (net.computers[i].os == OS.WINGDOWS)
148
net.computers[i].os = bill.list[grabbed].cargo;
149
bill.list[grabbed].state = bill.list[grabbed].OFF;
156
void Game::update() {
157
void show_scores(int);
168
if (!(bill.on_screen+bill.off_screen)) {
169
update_score(ENDLEVEL);
172
if ((net.base+net.off)<=1) state = END;
179
ui.popup_dialog(ENDGAME);
180
pos = gnome_score_log(score, NULL, TRUE);
183
ui.draw_centered(logo);
185
ui.set_pausebutton (FALSE);
189
ui.update_scorebox(level, score);
190
ui.popup_dialog (SCORE);
192
/* This is a bad kludge, but i don't think anybody can pass
193
the 268435458 level (G_MAXINT/8+3 in a normal pcs). */
194
if (++level < G_MAXINT/8+3)
204
static void parseAnArg(poptContext con, enum poptCallbackReason reason,
205
const struct poptOption *opt, const char *arg,
207
if (reason != POPT_CALLBACK_REASON_OPTION) return;
209
game.level = game.MAX(1, atoi(arg));
211
static const struct poptOption options[] = {
212
{ NULL, '\0', POPT_ARG_CALLBACK,
213
(void *) &parseAnArg, 0, NULL },
214
{ "warp", 'l', POPT_ARG_STRING, NULL, -1,
215
"Start at a different level", "LEVEL" },
217
{ NULL, '\0', 0, NULL, 0 }
220
void Game::main(int argc, char **argv) {
225
ui.initialize(argc, argv, options);
231
ui.draw_centered(logo);
246
if (level) start(level);
247
else ui.set_pausebutton(FALSE);
252
int main(int argc, char **argv) {
253
if (gnome_score_init("gnome-xbill")) {
254
printf("Couldn't set up score server\n");
257
game.main(argc, argv);