diff options
author | Teruaki Kawashima <teru@rockbox.org> | 2009-08-03 16:30:08 +0000 |
---|---|---|
committer | Teruaki Kawashima <teru@rockbox.org> | 2009-08-03 16:30:08 +0000 |
commit | 2357ec4178de417c69d1ce0001ceac747e0512a3 (patch) | |
tree | d8ab876b9f914ecbb79624c0c270af5a83d01661 /apps/plugins/wormlet.c | |
parent | 3228756324a3afa579ac0da8319cc24bb0147f15 (diff) | |
download | rockbox-2357ec4178de417c69d1ce0001ceac747e0512a3.tar.gz rockbox-2357ec4178de417c69d1ce0001ceac747e0512a3.zip |
calendar: fix bug when add new event text longer than last entry.
blackjack: fix bug that bet becomes 10 when resume saved game.
bubbles: save high level to sparate file.
clix, spacerocks, jewels, bubbles: correct text of menu item.
wormlet: clean up code: removed unused defines and functions.
pluginlib display_text: insert sleep so that the screen doesn't quit immediately.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22143 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/wormlet.c')
-rw-r--r-- | apps/plugins/wormlet.c | 594 |
1 files changed, 138 insertions, 456 deletions
diff --git a/apps/plugins/wormlet.c b/apps/plugins/wormlet.c index 2ef9f990f4..97b2fded4f 100644 --- a/apps/plugins/wormlet.c +++ b/apps/plugins/wormlet.c | |||
@@ -63,10 +63,6 @@ PLUGIN_HEADER | |||
63 | #define MULTIPLAYER | 63 | #define MULTIPLAYER |
64 | #endif | 64 | #endif |
65 | 65 | ||
66 | #define PLAYERS_TEXT "UP/DN" | ||
67 | #define WORMS_TEXT "L/R" | ||
68 | #define KEY_CONTROL_TEXT "F1" | ||
69 | |||
70 | #elif (CONFIG_KEYPAD == ARCHOS_AV300_PAD) | 66 | #elif (CONFIG_KEYPAD == ARCHOS_AV300_PAD) |
71 | #define BTN_DIR_UP BUTTON_UP | 67 | #define BTN_DIR_UP BUTTON_UP |
72 | #define BTN_DIR_DOWN BUTTON_DOWN | 68 | #define BTN_DIR_DOWN BUTTON_DOWN |
@@ -79,10 +75,6 @@ PLUGIN_HEADER | |||
79 | #define BTN_STOPRESET BUTTON_ON | 75 | #define BTN_STOPRESET BUTTON_ON |
80 | #define BTN_TOGGLE_KEYS BUTTON_F1 | 76 | #define BTN_TOGGLE_KEYS BUTTON_F1 |
81 | 77 | ||
82 | #define PLAYERS_TEXT "UP/DN" | ||
83 | #define WORMS_TEXT "L/R" | ||
84 | #define KEY_CONTROL_TEXT "F1" | ||
85 | |||
86 | #elif (CONFIG_KEYPAD == ONDIO_PAD) | 78 | #elif (CONFIG_KEYPAD == ONDIO_PAD) |
87 | #define BTN_DIR_UP BUTTON_UP | 79 | #define BTN_DIR_UP BUTTON_UP |
88 | #define BTN_DIR_DOWN BUTTON_DOWN | 80 | #define BTN_DIR_DOWN BUTTON_DOWN |
@@ -92,9 +84,6 @@ PLUGIN_HEADER | |||
92 | #define BTN_QUIT (BUTTON_OFF|BUTTON_REL) | 84 | #define BTN_QUIT (BUTTON_OFF|BUTTON_REL) |
93 | #define BTN_STOPRESET (BUTTON_OFF|BUTTON_MENU) | 85 | #define BTN_STOPRESET (BUTTON_OFF|BUTTON_MENU) |
94 | 86 | ||
95 | #define PLAYERS_TEXT "UP/DN" | ||
96 | #define WORMS_TEXT "L/R" | ||
97 | |||
98 | #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \ | 87 | #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \ |
99 | (CONFIG_KEYPAD == IPOD_1G2G_PAD) | 88 | (CONFIG_KEYPAD == IPOD_1G2G_PAD) |
100 | 89 | ||
@@ -106,9 +95,6 @@ PLUGIN_HEADER | |||
106 | #define BTN_QUIT (BUTTON_SELECT|BUTTON_MENU) | 95 | #define BTN_QUIT (BUTTON_SELECT|BUTTON_MENU) |
107 | #define BTN_STOPRESET (BUTTON_SELECT|BUTTON_PLAY) | 96 | #define BTN_STOPRESET (BUTTON_SELECT|BUTTON_PLAY) |
108 | 97 | ||
109 | #define PLAYERS_TEXT "Menu/Play" | ||
110 | #define WORMS_TEXT "Left/Right" | ||
111 | |||
112 | #elif (CONFIG_KEYPAD == IRIVER_H300_PAD) || (CONFIG_KEYPAD == IRIVER_H100_PAD) | 98 | #elif (CONFIG_KEYPAD == IRIVER_H300_PAD) || (CONFIG_KEYPAD == IRIVER_H100_PAD) |
113 | 99 | ||
114 | #define BTN_DIR_UP BUTTON_UP | 100 | #define BTN_DIR_UP BUTTON_UP |
@@ -121,9 +107,6 @@ PLUGIN_HEADER | |||
121 | 107 | ||
122 | #define BTN_RC_QUIT BUTTON_RC_STOP | 108 | #define BTN_RC_QUIT BUTTON_RC_STOP |
123 | 109 | ||
124 | #define PLAYERS_TEXT "Up/Down" | ||
125 | #define WORMS_TEXT "Left/Right" | ||
126 | |||
127 | #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD) | 110 | #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD) |
128 | 111 | ||
129 | #define BTN_DIR_UP BUTTON_UP | 112 | #define BTN_DIR_UP BUTTON_UP |
@@ -134,9 +117,6 @@ PLUGIN_HEADER | |||
134 | #define BTN_QUIT BUTTON_POWER | 117 | #define BTN_QUIT BUTTON_POWER |
135 | #define BTN_STOPRESET BUTTON_REC | 118 | #define BTN_STOPRESET BUTTON_REC |
136 | 119 | ||
137 | #define PLAYERS_TEXT "Up/Down" | ||
138 | #define WORMS_TEXT "Left/Right" | ||
139 | |||
140 | #elif (CONFIG_KEYPAD == GIGABEAT_PAD) | 120 | #elif (CONFIG_KEYPAD == GIGABEAT_PAD) |
141 | 121 | ||
142 | #define BTN_DIR_UP BUTTON_UP | 122 | #define BTN_DIR_UP BUTTON_UP |
@@ -147,10 +127,6 @@ PLUGIN_HEADER | |||
147 | #define BTN_QUIT BUTTON_POWER | 127 | #define BTN_QUIT BUTTON_POWER |
148 | #define BTN_STOPRESET BUTTON_A | 128 | #define BTN_STOPRESET BUTTON_A |
149 | 129 | ||
150 | #define PLAYERS_TEXT "Up/Down" | ||
151 | #define WORMS_TEXT "Left/Right" | ||
152 | |||
153 | |||
154 | #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \ | 130 | #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \ |
155 | (CONFIG_KEYPAD == SANSA_C200_PAD) | 131 | (CONFIG_KEYPAD == SANSA_C200_PAD) |
156 | 132 | ||
@@ -162,9 +138,6 @@ PLUGIN_HEADER | |||
162 | #define BTN_QUIT BUTTON_POWER | 138 | #define BTN_QUIT BUTTON_POWER |
163 | #define BTN_STOPRESET BUTTON_REC | 139 | #define BTN_STOPRESET BUTTON_REC |
164 | 140 | ||
165 | #define PLAYERS_TEXT "Up/Down" | ||
166 | #define WORMS_TEXT "Left/Right" | ||
167 | |||
168 | #elif (CONFIG_KEYPAD == SANSA_CLIP_PAD) | 141 | #elif (CONFIG_KEYPAD == SANSA_CLIP_PAD) |
169 | 142 | ||
170 | #define BTN_DIR_UP BUTTON_UP | 143 | #define BTN_DIR_UP BUTTON_UP |
@@ -175,9 +148,6 @@ PLUGIN_HEADER | |||
175 | #define BTN_QUIT BUTTON_POWER | 148 | #define BTN_QUIT BUTTON_POWER |
176 | #define BTN_STOPRESET BUTTON_HOME | 149 | #define BTN_STOPRESET BUTTON_HOME |
177 | 150 | ||
178 | #define PLAYERS_TEXT "Up/Down" | ||
179 | #define WORMS_TEXT "Left/Right" | ||
180 | |||
181 | #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD) | 151 | #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD) |
182 | 152 | ||
183 | #define BTN_DIR_UP BUTTON_UP | 153 | #define BTN_DIR_UP BUTTON_UP |
@@ -188,9 +158,6 @@ PLUGIN_HEADER | |||
188 | #define BTN_QUIT (BUTTON_HOME|BUTTON_REPEAT) | 158 | #define BTN_QUIT (BUTTON_HOME|BUTTON_REPEAT) |
189 | #define BTN_STOPRESET (BUTTON_SELECT | BUTTON_UP) | 159 | #define BTN_STOPRESET (BUTTON_SELECT | BUTTON_UP) |
190 | 160 | ||
191 | #define PLAYERS_TEXT "Up/Down" | ||
192 | #define WORMS_TEXT "Left/Right" | ||
193 | |||
194 | #elif (CONFIG_KEYPAD == SANSA_M200_PAD) | 161 | #elif (CONFIG_KEYPAD == SANSA_M200_PAD) |
195 | 162 | ||
196 | #define BTN_DIR_UP BUTTON_UP | 163 | #define BTN_DIR_UP BUTTON_UP |
@@ -201,9 +168,6 @@ PLUGIN_HEADER | |||
201 | #define BTN_QUIT BUTTON_POWER | 168 | #define BTN_QUIT BUTTON_POWER |
202 | #define BTN_STOPRESET (BUTTON_SELECT | BUTTON_UP) | 169 | #define BTN_STOPRESET (BUTTON_SELECT | BUTTON_UP) |
203 | 170 | ||
204 | #define PLAYERS_TEXT "Up/Down" | ||
205 | #define WORMS_TEXT "Left/Right" | ||
206 | |||
207 | #elif (CONFIG_KEYPAD == IRIVER_H10_PAD) | 171 | #elif (CONFIG_KEYPAD == IRIVER_H10_PAD) |
208 | 172 | ||
209 | #define BTN_DIR_UP BUTTON_SCROLL_UP | 173 | #define BTN_DIR_UP BUTTON_SCROLL_UP |
@@ -214,9 +178,6 @@ PLUGIN_HEADER | |||
214 | #define BTN_QUIT BUTTON_POWER | 178 | #define BTN_QUIT BUTTON_POWER |
215 | #define BTN_STOPRESET BUTTON_REW | 179 | #define BTN_STOPRESET BUTTON_REW |
216 | 180 | ||
217 | #define PLAYERS_TEXT "Up/Down" | ||
218 | #define WORMS_TEXT "Left/Right" | ||
219 | |||
220 | #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) | 181 | #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD) |
221 | 182 | ||
222 | #define BTN_DIR_UP BUTTON_UP | 183 | #define BTN_DIR_UP BUTTON_UP |
@@ -227,9 +188,6 @@ PLUGIN_HEADER | |||
227 | #define BTN_QUIT BUTTON_BACK | 188 | #define BTN_QUIT BUTTON_BACK |
228 | #define BTN_STOPRESET BUTTON_MENU | 189 | #define BTN_STOPRESET BUTTON_MENU |
229 | 190 | ||
230 | #define PLAYERS_TEXT "Up/Down" | ||
231 | #define WORMS_TEXT "Left/Right" | ||
232 | |||
233 | #elif (CONFIG_KEYPAD == MROBE100_PAD) | 191 | #elif (CONFIG_KEYPAD == MROBE100_PAD) |
234 | 192 | ||
235 | #define BTN_DIR_UP BUTTON_UP | 193 | #define BTN_DIR_UP BUTTON_UP |
@@ -240,9 +198,6 @@ PLUGIN_HEADER | |||
240 | #define BTN_QUIT BUTTON_POWER | 198 | #define BTN_QUIT BUTTON_POWER |
241 | #define BTN_STOPRESET BUTTON_DISPLAY | 199 | #define BTN_STOPRESET BUTTON_DISPLAY |
242 | 200 | ||
243 | #define PLAYERS_TEXT "Up/Down" | ||
244 | #define WORMS_TEXT "Left/Right" | ||
245 | |||
246 | #elif CONFIG_KEYPAD == IAUDIO_M3_PAD | 201 | #elif CONFIG_KEYPAD == IAUDIO_M3_PAD |
247 | 202 | ||
248 | #define BTN_DIR_UP BUTTON_RC_VOL_UP | 203 | #define BTN_DIR_UP BUTTON_RC_VOL_UP |
@@ -253,9 +208,6 @@ PLUGIN_HEADER | |||
253 | #define BTN_QUIT BUTTON_RC_REC | 208 | #define BTN_QUIT BUTTON_RC_REC |
254 | #define BTN_STOPRESET BUTTON_RC_MODE | 209 | #define BTN_STOPRESET BUTTON_RC_MODE |
255 | 210 | ||
256 | #define PLAYERS_TEXT "VOL UP/DN" | ||
257 | #define WORMS_TEXT "REW/FF" | ||
258 | |||
259 | #elif (CONFIG_KEYPAD == COWOND2_PAD) | 211 | #elif (CONFIG_KEYPAD == COWOND2_PAD) |
260 | 212 | ||
261 | #define BTN_QUIT BUTTON_POWER | 213 | #define BTN_QUIT BUTTON_POWER |
@@ -270,9 +222,6 @@ PLUGIN_HEADER | |||
270 | #define BTN_QUIT BUTTON_BACK | 222 | #define BTN_QUIT BUTTON_BACK |
271 | #define BTN_STOPRESET BUTTON_MENU | 223 | #define BTN_STOPRESET BUTTON_MENU |
272 | 224 | ||
273 | #define PLAYERS_TEXT "Up/Down" | ||
274 | #define WORMS_TEXT "Left/Right" | ||
275 | |||
276 | #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD | 225 | #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD |
277 | 226 | ||
278 | #define BTN_DIR_UP BUTTON_UP | 227 | #define BTN_DIR_UP BUTTON_UP |
@@ -283,9 +232,6 @@ PLUGIN_HEADER | |||
283 | #define BTN_QUIT BUTTON_POWER | 232 | #define BTN_QUIT BUTTON_POWER |
284 | #define BTN_STOPRESET BUTTON_VIEW | 233 | #define BTN_STOPRESET BUTTON_VIEW |
285 | 234 | ||
286 | #define PLAYERS_TEXT "Up/Down" | ||
287 | #define WORMS_TEXT "Left/Right" | ||
288 | |||
289 | #elif (CONFIG_KEYPAD == ONDAVX747_PAD) || CONFIG_KEYPAD == MROBE500_PAD | 235 | #elif (CONFIG_KEYPAD == ONDAVX747_PAD) || CONFIG_KEYPAD == MROBE500_PAD |
290 | 236 | ||
291 | #define BTN_QUIT BUTTON_POWER | 237 | #define BTN_QUIT BUTTON_POWER |
@@ -315,16 +261,8 @@ PLUGIN_HEADER | |||
315 | #endif | 261 | #endif |
316 | #ifndef BTN_STOPRESET | 262 | #ifndef BTN_STOPRESET |
317 | #define BTN_STOPRESET BUTTON_TOPRIGHT | 263 | #define BTN_STOPRESET BUTTON_TOPRIGHT |
318 | |||
319 | #endif | 264 | #endif |
320 | #ifndef PLAYERS_TEXT | ||
321 | #define PLAYERS_TEXT "Up/Down" | ||
322 | #endif | 265 | #endif |
323 | #ifndef WORMS_TEXT | ||
324 | #define WORMS_TEXT "Left/Right" | ||
325 | #endif | ||
326 | #endif | ||
327 | |||
328 | 266 | ||
329 | #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64) | 267 | #if (LCD_WIDTH == 112) && (LCD_HEIGHT == 64) |
330 | #define FOOD_SIZE 3 | 268 | #define FOOD_SIZE 3 |
@@ -500,14 +438,14 @@ static int players = 1; | |||
500 | 438 | ||
501 | static struct configdata config[] = | 439 | static struct configdata config[] = |
502 | { | 440 | { |
503 | {TYPE_INT, 0, 1024, { .int_p = &highscore }, "highscore", NULL}, | 441 | {TYPE_INT, 0, 1024, { .int_p = &highscore }, "highscore", NULL}, |
504 | {TYPE_INT, 0, 15, { .int_p = &arghs_per_food }, "arghs per food", NULL}, | 442 | {TYPE_INT, 0, 15, { .int_p = &arghs_per_food }, "arghs per food", NULL}, |
505 | {TYPE_INT, 0, 15, { .int_p = &argh_size }, "argh size", NULL}, | 443 | {TYPE_INT, 0, 15, { .int_p = &argh_size }, "argh size", NULL}, |
506 | {TYPE_INT, 0, 15, { .int_p = &food_size }, "food size", NULL}, | 444 | {TYPE_INT, 0, 15, { .int_p = &food_size }, "food size", NULL}, |
507 | {TYPE_INT, 0, 3, { .int_p = &players }, "players", NULL}, | 445 | {TYPE_INT, 0, 3, { .int_p = &players }, "players", NULL}, |
508 | {TYPE_INT, 0, 3, { .int_p = &worm_count }, "worms", NULL}, | 446 | {TYPE_INT, 0, 3, { .int_p = &worm_count }, "worms", NULL}, |
509 | {TYPE_INT, 0, 20, { .int_p = &speed }, "speed", NULL}, | 447 | {TYPE_INT, 0, 20, { .int_p = &speed }, "speed", NULL}, |
510 | {TYPE_INT, 0, 15, { .int_p = &worm_food }, "Worm Growth Per Food", NULL} | 448 | {TYPE_INT, 0, 15, { .int_p = &worm_food }, "Worm Growth Per Food", NULL} |
511 | }; | 449 | }; |
512 | 450 | ||
513 | #ifdef DEBUG_WORMLET | 451 | #ifdef DEBUG_WORMLET |
@@ -524,7 +462,8 @@ static void set_debug_out(char *str){ | |||
524 | * @return int A value 0 <= value < 4 | 462 | * @return int A value 0 <= value < 4 |
525 | * Note the predefined constants NORTH, SOUTH, EAST, WEST | 463 | * Note the predefined constants NORTH, SOUTH, EAST, WEST |
526 | */ | 464 | */ |
527 | static int get_worm_dir(struct worm *w) { | 465 | static int get_worm_dir(struct worm *w) |
466 | { | ||
528 | int retVal ; | 467 | int retVal ; |
529 | if (w->dirx == 0) { | 468 | if (w->dirx == 0) { |
530 | if (w->diry == 1) { | 469 | if (w->diry == 1) { |
@@ -551,13 +490,14 @@ static int get_worm_dir(struct worm *w) { | |||
551 | * dir must be 0 <= dir < 4. Use predefined constants | 490 | * dir must be 0 <= dir < 4. Use predefined constants |
552 | * NORTH, SOUTH, EAST, WEST | 491 | * NORTH, SOUTH, EAST, WEST |
553 | */ | 492 | */ |
554 | static void set_worm_dir(struct worm *w, int dir) { | 493 | static void set_worm_dir(struct worm *w, int dir) |
494 | { | ||
555 | switch (dir) { | 495 | switch (dir) { |
556 | case WEST: | 496 | case WEST: |
557 | w->dirx = -1; | 497 | w->dirx = -1; |
558 | w->diry = 0; | 498 | w->diry = 0; |
559 | break; | 499 | break; |
560 | case NORTH: | 500 | case NORTH: |
561 | w->dirx = 0; | 501 | w->dirx = 0; |
562 | w->diry = - 1; | 502 | w->diry = - 1; |
563 | break; | 503 | break; |
@@ -569,7 +509,7 @@ static void set_worm_dir(struct worm *w, int dir) { | |||
569 | w->dirx = 0; | 509 | w->dirx = 0; |
570 | w->diry = 1; | 510 | w->diry = 1; |
571 | break; | 511 | break; |
572 | } | 512 | } |
573 | } | 513 | } |
574 | 514 | ||
575 | /** | 515 | /** |
@@ -577,7 +517,8 @@ static void set_worm_dir(struct worm *w, int dir) { | |||
577 | * is also a value for the number of bends that are in the worm. | 517 | * is also a value for the number of bends that are in the worm. |
578 | * @return int a positive value with 0 <= value < MAX_WORM_SEGMENTS | 518 | * @return int a positive value with 0 <= value < MAX_WORM_SEGMENTS |
579 | */ | 519 | */ |
580 | static int get_worm_array_length(struct worm *w) { | 520 | static int get_worm_array_length(struct worm *w) |
521 | { | ||
581 | /* initial simple calculation will be overwritten if wrong. */ | 522 | /* initial simple calculation will be overwritten if wrong. */ |
582 | int retVal = w->head - w->tail; | 523 | int retVal = w->head - w->tail; |
583 | 524 | ||
@@ -596,7 +537,8 @@ static int get_worm_array_length(struct worm *w) { | |||
596 | * w must not be null. | 537 | * w must not be null. |
597 | * @return int The length of the worm (>= 0). | 538 | * @return int The length of the worm (>= 0). |
598 | */ | 539 | */ |
599 | static int get_score(struct worm *w) { | 540 | static int get_score(struct worm *w) |
541 | { | ||
600 | int retval = 0; | 542 | int retval = 0; |
601 | int length = get_worm_array_length(w); | 543 | int length = get_worm_array_length(w); |
602 | int i; | 544 | int i; |
@@ -620,7 +562,7 @@ static int get_score(struct worm *w) { | |||
620 | minimum = MIN(startx, endx); | 562 | minimum = MIN(startx, endx); |
621 | maximum = MAX(startx, endx); | 563 | maximum = MAX(startx, endx); |
622 | } | 564 | } |
623 | retval += abs(maximum - minimum); | 565 | retval += abs(maximum - minimum); |
624 | } | 566 | } |
625 | return retval; | 567 | return retval; |
626 | } | 568 | } |
@@ -639,7 +581,9 @@ static int get_score(struct worm *w) { | |||
639 | * @param int height The height of the rectangle. | 581 | * @param int height The height of the rectangle. |
640 | * @return bool Returns true if the specified line intersects with the recangle. | 582 | * @return bool Returns true if the specified line intersects with the recangle. |
641 | */ | 583 | */ |
642 | static bool line_in_rect(int startx, int starty, int endx, int endy, int x, int y, int width, int height) { | 584 | static bool line_in_rect(int startx, int starty, int endx, int endy, |
585 | int x, int y, int width, int height) | ||
586 | { | ||
643 | bool retval = false; | 587 | bool retval = false; |
644 | int simple, simplemin, simplemax; | 588 | int simple, simplemin, simplemax; |
645 | int compa, compb, compmin, compmax; | 589 | int compa, compb, compmin, compmax; |
@@ -687,7 +631,8 @@ static bool line_in_rect(int startx, int starty, int endx, int endy, int x, int | |||
687 | * @param int height The height of the rect | 631 | * @param int height The height of the rect |
688 | * @return bool Returns true if the worm intersects with the rect | 632 | * @return bool Returns true if the worm intersects with the rect |
689 | */ | 633 | */ |
690 | static bool worm_in_rect(struct worm *w, int x, int y, int width, int height) { | 634 | static bool worm_in_rect(struct worm *w, int x, int y, int width, int height) |
635 | { | ||
691 | bool retval = false; | 636 | bool retval = false; |
692 | 637 | ||
693 | 638 | ||
@@ -722,7 +667,8 @@ static bool worm_in_rect(struct worm *w, int x, int y, int width, int height) { | |||
722 | * @return Returns true if the coordinate hits the food specified by | 667 | * @return Returns true if the coordinate hits the food specified by |
723 | * foodIndex. | 668 | * foodIndex. |
724 | */ | 669 | */ |
725 | static bool specific_food_collision(int foodIndex, int x, int y) { | 670 | static bool specific_food_collision(int foodIndex, int x, int y) |
671 | { | ||
726 | bool retVal = false; | 672 | bool retVal = false; |
727 | if (x >= foodx[foodIndex] && | 673 | if (x >= foodx[foodIndex] && |
728 | x < foodx[foodIndex] + food_size && | 674 | x < foodx[foodIndex] + food_size && |
@@ -740,7 +686,8 @@ static bool specific_food_collision(int foodIndex, int x, int y) { | |||
740 | * -1 is returned. | 686 | * -1 is returned. |
741 | * @return int -1 <= value < MAX_FOOD | 687 | * @return int -1 <= value < MAX_FOOD |
742 | */ | 688 | */ |
743 | static int food_collision(int x, int y) { | 689 | static int food_collision(int x, int y) |
690 | { | ||
744 | int i = 0; | 691 | int i = 0; |
745 | int retVal = -1; | 692 | int retVal = -1; |
746 | for (i = 0; i < MAX_FOOD; i++) { | 693 | for (i = 0; i < MAX_FOOD; i++) { |
@@ -761,8 +708,8 @@ static int food_collision(int x, int y) { | |||
761 | * @return Returns true if the coordinate hits the argh specified by | 708 | * @return Returns true if the coordinate hits the argh specified by |
762 | * arghIndex. | 709 | * arghIndex. |
763 | */ | 710 | */ |
764 | static bool specific_argh_collision(int arghIndex, int x, int y) { | 711 | static bool specific_argh_collision(int arghIndex, int x, int y) |
765 | 712 | { | |
766 | if ( x >= arghx[arghIndex] && | 713 | if ( x >= arghx[arghIndex] && |
767 | y >= arghy[arghIndex] && | 714 | y >= arghy[arghIndex] && |
768 | x < arghx[arghIndex] + argh_size && | 715 | x < arghx[arghIndex] + argh_size && |
@@ -782,7 +729,8 @@ static bool specific_argh_collision(int arghIndex, int x, int y) { | |||
782 | * @param int y The y coordinate. | 729 | * @param int y The y coordinate. |
783 | * @return int -1 <= value < argh_count <= MAX_ARGH | 730 | * @return int -1 <= value < argh_count <= MAX_ARGH |
784 | */ | 731 | */ |
785 | static int argh_collision(int x, int y) { | 732 | static int argh_collision(int x, int y) |
733 | { | ||
786 | int i = 0; | 734 | int i = 0; |
787 | int retVal = -1; | 735 | int retVal = -1; |
788 | 736 | ||
@@ -821,7 +769,8 @@ static bool worm_food_collision(struct worm *w, int foodIndex) | |||
821 | * @return Returns false if the specified argh is not hit within the next | 769 | * @return Returns false if the specified argh is not hit within the next |
822 | * moves. | 770 | * moves. |
823 | */ | 771 | */ |
824 | static bool worm_argh_collision_in_moves(struct worm *w, int argh_idx, int moves){ | 772 | static bool worm_argh_collision_in_moves(struct worm *w, int argh_idx, int moves) |
773 | { | ||
825 | bool retVal = false; | 774 | bool retVal = false; |
826 | int x1, y1, x2, y2; | 775 | int x1, y1, x2, y2; |
827 | x1 = w->x[w->head]; | 776 | x1 = w->x[w->head]; |
@@ -857,8 +806,8 @@ static bool worm_argh_collision(struct worm *w, int arghIndex) | |||
857 | * @param int index | 806 | * @param int index |
858 | * Ensure that 0 <= index < MAX_FOOD. | 807 | * Ensure that 0 <= index < MAX_FOOD. |
859 | */ | 808 | */ |
860 | static void make_food(int index) { | 809 | static void make_food(int index) |
861 | 810 | { | |
862 | int x = 0; | 811 | int x = 0; |
863 | int y = 0; | 812 | int y = 0; |
864 | bool collisionDetected = false; | 813 | bool collisionDetected = false; |
@@ -1002,8 +951,8 @@ static void draw_argh(int index) | |||
1002 | rb->lcd_set_foreground(COLOR_ARGH); | 951 | rb->lcd_set_foreground(COLOR_ARGH); |
1003 | #endif | 952 | #endif |
1004 | rb->lcd_fillrect(arghx[index] + FIELD_RECT_X, | 953 | rb->lcd_fillrect(arghx[index] + FIELD_RECT_X, |
1005 | arghy[index] + FIELD_RECT_Y, | 954 | arghy[index] + FIELD_RECT_Y, |
1006 | argh_size, argh_size); | 955 | argh_size, argh_size); |
1007 | #ifdef HAVE_LCD_COLOR | 956 | #ifdef HAVE_LCD_COLOR |
1008 | rb->lcd_set_foreground(COLOR_FG); | 957 | rb->lcd_set_foreground(COLOR_FG); |
1009 | #endif | 958 | #endif |
@@ -1020,24 +969,25 @@ static void virtual_player(struct worm *w); | |||
1020 | * @param int y The y coordinate at which the tail of the worm starts | 969 | * @param int y The y coordinate at which the tail of the worm starts |
1021 | * y must be 0 <= y < FIELD_RECT_WIDTH. | 970 | * y must be 0 <= y < FIELD_RECT_WIDTH. |
1022 | */ | 971 | */ |
1023 | static void init_worm(struct worm *w, int x, int y){ | 972 | static void init_worm(struct worm *w, int x, int y) |
1024 | /* initialize the worm size */ | 973 | { |
1025 | w->head = 1; | 974 | /* initialize the worm size */ |
1026 | w->tail = 0; | 975 | w->head = 1; |
976 | w->tail = 0; | ||
1027 | 977 | ||
1028 | w->x[w->head] = x + 1; | 978 | w->x[w->head] = x + 1; |
1029 | w->y[w->head] = y; | 979 | w->y[w->head] = y; |
1030 | 980 | ||
1031 | w->x[w->tail] = x; | 981 | w->x[w->tail] = x; |
1032 | w->y[w->tail] = y; | 982 | w->y[w->tail] = y; |
1033 | 983 | ||
1034 | /* set the initial direction the worm creeps to */ | 984 | /* set the initial direction the worm creeps to */ |
1035 | w->dirx = 1; | 985 | w->dirx = 1; |
1036 | w->diry = 0; | 986 | w->diry = 0; |
1037 | 987 | ||
1038 | w->growing = INITIAL_WORM_LENGTH - 1; | 988 | w->growing = INITIAL_WORM_LENGTH - 1; |
1039 | w->alive = true; | 989 | w->alive = true; |
1040 | w->fetch_worm_direction = virtual_player; | 990 | w->fetch_worm_direction = virtual_player; |
1041 | } | 991 | } |
1042 | 992 | ||
1043 | /** | 993 | /** |
@@ -1089,9 +1039,9 @@ static void init_wormlet(void) | |||
1089 | int i; | 1039 | int i; |
1090 | 1040 | ||
1091 | for (i = 0; i< worm_count; i++) { | 1041 | for (i = 0; i< worm_count; i++) { |
1092 | /* Initialize all the worm coordinates to center. */ | 1042 | /* Initialize all the worm coordinates to center. */ |
1093 | int x = (int)(FIELD_RECT_WIDTH / 2); | 1043 | int x = (int)(FIELD_RECT_WIDTH / 2); |
1094 | int y = (int)((FIELD_RECT_HEIGHT - 20)/ 2) + i * 10; | 1044 | int y = (int)((FIELD_RECT_HEIGHT - 20)/ 2) + i * 10; |
1095 | 1045 | ||
1096 | init_worm(&worms[i], x, y); | 1046 | init_worm(&worms[i], x, y); |
1097 | } | 1047 | } |
@@ -1223,12 +1173,12 @@ static void move_worm(struct worm *w) | |||
1223 | */ | 1173 | */ |
1224 | static void draw_worm(struct worm *w) | 1174 | static void draw_worm(struct worm *w) |
1225 | { | 1175 | { |
1226 | #ifdef HAVE_LCD_COLOR | ||
1227 | rb->lcd_set_foreground(COLOR_WORM); | ||
1228 | #endif | ||
1229 | /* draw the new head */ | 1176 | /* draw the new head */ |
1230 | int x = w->x[w->head]; | 1177 | int x = w->x[w->head]; |
1231 | int y = w->y[w->head]; | 1178 | int y = w->y[w->head]; |
1179 | #ifdef HAVE_LCD_COLOR | ||
1180 | rb->lcd_set_foreground(COLOR_WORM); | ||
1181 | #endif | ||
1232 | if (x >= 0 && x < FIELD_RECT_WIDTH && y >= 0 && y < FIELD_RECT_HEIGHT) { | 1182 | if (x >= 0 && x < FIELD_RECT_WIDTH && y >= 0 && y < FIELD_RECT_HEIGHT) { |
1233 | rb->lcd_drawpixel(x + FIELD_RECT_X, y + FIELD_RECT_Y); | 1183 | rb->lcd_drawpixel(x + FIELD_RECT_X, y + FIELD_RECT_Y); |
1234 | } | 1184 | } |
@@ -1325,7 +1275,8 @@ static void add_growing(struct worm *w, int len) { | |||
1325 | * @return struct worm* The worm that has been hit by x,y. If no worm | 1275 | * @return struct worm* The worm that has been hit by x,y. If no worm |
1326 | * was at the position NULL is returned. | 1276 | * was at the position NULL is returned. |
1327 | */ | 1277 | */ |
1328 | static struct worm* worm_collision(struct worm *w, int x, int y){ | 1278 | static struct worm* worm_collision(struct worm *w, int x, int y) |
1279 | { | ||
1329 | struct worm *retVal = NULL; | 1280 | struct worm *retVal = NULL; |
1330 | int i; | 1281 | int i; |
1331 | for (i = 0; (i < worm_count) && (retVal == NULL); i++) { | 1282 | for (i = 0; (i < worm_count) && (retVal == NULL); i++) { |
@@ -1366,7 +1317,8 @@ static bool field_collision(struct worm *w) | |||
1366 | * @return bool Returns false if x,y specifies a point outside the | 1317 | * @return bool Returns false if x,y specifies a point outside the |
1367 | * field of worms. | 1318 | * field of worms. |
1368 | */ | 1319 | */ |
1369 | static bool is_in_field_rect(int x, int y) { | 1320 | static bool is_in_field_rect(int x, int y) |
1321 | { | ||
1370 | bool retVal = false; | 1322 | bool retVal = false; |
1371 | retVal = (x >= 0 && x < FIELD_RECT_WIDTH && | 1323 | retVal = (x >= 0 && x < FIELD_RECT_WIDTH && |
1372 | y >= 0 && y < FIELD_RECT_HEIGHT); | 1324 | y >= 0 && y < FIELD_RECT_HEIGHT); |
@@ -1410,7 +1362,8 @@ static int check_collision(struct worm *w) | |||
1410 | * @param int y The y coordinate of the point | 1362 | * @param int y The y coordinate of the point |
1411 | * @return int A value usable as index in foodx and foody. | 1363 | * @return int A value usable as index in foodx and foody. |
1412 | */ | 1364 | */ |
1413 | static int get_nearest_food(int x, int y){ | 1365 | static int get_nearest_food(int x, int y) |
1366 | { | ||
1414 | int nearestfood = 0; | 1367 | int nearestfood = 0; |
1415 | int olddistance = FIELD_RECT_WIDTH + FIELD_RECT_HEIGHT; | 1368 | int olddistance = FIELD_RECT_WIDTH + FIELD_RECT_HEIGHT; |
1416 | int deltax = 0; | 1369 | int deltax = 0; |
@@ -1443,7 +1396,8 @@ static int get_nearest_food(int x, int y){ | |||
1443 | * @return Returns true if the worm will hit the position unless | 1396 | * @return Returns true if the worm will hit the position unless |
1444 | * it change its direction before the next move. | 1397 | * it change its direction before the next move. |
1445 | */ | 1398 | */ |
1446 | static bool is_in_front_of_worm(struct worm *w, int x, int y) { | 1399 | static bool is_in_front_of_worm(struct worm *w, int x, int y) |
1400 | { | ||
1447 | bool infront = false; | 1401 | bool infront = false; |
1448 | int deltax = x - w->x[w->head]; | 1402 | int deltax = x - w->x[w->head]; |
1449 | int deltay = y - w->y[w->head]; | 1403 | int deltay = y - w->y[w->head]; |
@@ -1463,7 +1417,8 @@ static bool is_in_front_of_worm(struct worm *w, int x, int y) { | |||
1463 | * @return Returns true if the worm will collide with the next move | 1417 | * @return Returns true if the worm will collide with the next move |
1464 | * unless it changes its direction. | 1418 | * unless it changes its direction. |
1465 | */ | 1419 | */ |
1466 | static bool will_worm_collide(struct worm *w) { | 1420 | static bool will_worm_collide(struct worm *w) |
1421 | { | ||
1467 | int x = w->x[w->head] + w->dirx; | 1422 | int x = w->x[w->head] + w->dirx; |
1468 | int y = w->y[w->head] + w->diry; | 1423 | int y = w->y[w->head] + w->diry; |
1469 | bool retVal = !is_in_field_rect(x, y); | 1424 | bool retVal = !is_in_field_rect(x, y); |
@@ -1487,7 +1442,8 @@ static bool will_worm_collide(struct worm *w) { | |||
1487 | * @param struct worm *w - The worm of which the direction | 1442 | * @param struct worm *w - The worm of which the direction |
1488 | * is altered. | 1443 | * is altered. |
1489 | */ | 1444 | */ |
1490 | static void virtual_player(struct worm *w) { | 1445 | static void virtual_player(struct worm *w) |
1446 | { | ||
1491 | bool isright; | 1447 | bool isright; |
1492 | int plana, planb, planc; | 1448 | int plana, planb, planc; |
1493 | /* find the next lunch */ | 1449 | /* find the next lunch */ |
@@ -1554,7 +1510,8 @@ static void score_board(void) | |||
1554 | int i; | 1510 | int i; |
1555 | int y = 0; | 1511 | int y = 0; |
1556 | rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); | 1512 | rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); |
1557 | rb->lcd_fillrect(FIELD_RECT_WIDTH + 2, 0, LCD_WIDTH - FIELD_RECT_WIDTH - 2, LCD_HEIGHT); | 1513 | rb->lcd_fillrect(FIELD_RECT_WIDTH + 2, 0, |
1514 | LCD_WIDTH - FIELD_RECT_WIDTH - 2, LCD_HEIGHT); | ||
1558 | rb->lcd_set_drawmode(DRMODE_SOLID); | 1515 | rb->lcd_set_drawmode(DRMODE_SOLID); |
1559 | for (i = 0; i < worm_count; i++) { | 1516 | for (i = 0; i < worm_count; i++) { |
1560 | int score = get_score(&worms[i]); | 1517 | int score = get_score(&worms[i]); |
@@ -1662,7 +1619,7 @@ static bool process_collisions(struct worm *w) | |||
1662 | else { | 1619 | else { |
1663 | if (worm_collision(w, w->x[w->head], w->y[w->head]) != NULL) { | 1620 | if (worm_collision(w, w->x[w->head], w->y[w->head]) != NULL) { |
1664 | w->alive = false; | 1621 | w->alive = false; |
1665 | } | 1622 | } |
1666 | } | 1623 | } |
1667 | } | 1624 | } |
1668 | } | 1625 | } |
@@ -1834,7 +1791,8 @@ static int run(void) | |||
1834 | * Just a test routine that checks that worm_food_collision works | 1791 | * Just a test routine that checks that worm_food_collision works |
1835 | * in some typical situations. | 1792 | * in some typical situations. |
1836 | */ | 1793 | */ |
1837 | static void test_worm_food_collision(void) { | 1794 | static void test_worm_food_collision(void) |
1795 | { | ||
1838 | int collision_count = 0; | 1796 | int collision_count = 0; |
1839 | int i; | 1797 | int i; |
1840 | rb->lcd_clear_display(); | 1798 | rb->lcd_clear_display(); |
@@ -1892,7 +1850,8 @@ static void test_worm_food_collision(void) { | |||
1892 | 1850 | ||
1893 | } | 1851 | } |
1894 | 1852 | ||
1895 | static bool expensive_worm_in_rect(struct worm *w, int rx, int ry, int rw, int rh){ | 1853 | static bool expensive_worm_in_rect(struct worm *w, int rx, int ry, int rw, int rh) |
1854 | { | ||
1896 | int x, y; | 1855 | int x, y; |
1897 | bool retVal = false; | 1856 | bool retVal = false; |
1898 | for (x = rx; x < rx + rw; x++){ | 1857 | for (x = rx; x < rx + rw; x++){ |
@@ -1905,7 +1864,8 @@ static bool expensive_worm_in_rect(struct worm *w, int rx, int ry, int rw, int r | |||
1905 | return retVal; | 1864 | return retVal; |
1906 | } | 1865 | } |
1907 | 1866 | ||
1908 | static void test_worm_argh_collision(void) { | 1867 | static void test_worm_argh_collision(void) |
1868 | { | ||
1909 | int i; | 1869 | int i; |
1910 | int dir; | 1870 | int dir; |
1911 | int collision_count = 0; | 1871 | int collision_count = 0; |
@@ -1955,7 +1915,8 @@ static void test_worm_argh_collision(void) { | |||
1955 | } | 1915 | } |
1956 | } | 1916 | } |
1957 | 1917 | ||
1958 | static int testline_in_rect(void) { | 1918 | static int testline_in_rect(void) |
1919 | { | ||
1959 | int testfailed = -1; | 1920 | int testfailed = -1; |
1960 | 1921 | ||
1961 | int rx = 10; | 1922 | int rx = 10; |
@@ -2164,7 +2125,8 @@ static int testline_in_rect(void) { | |||
2164 | /** | 2125 | /** |
2165 | * Just a test routine to test wether specific_worm_collision might work properly | 2126 | * Just a test routine to test wether specific_worm_collision might work properly |
2166 | */ | 2127 | */ |
2167 | static int test_specific_worm_collision(void) { | 2128 | static int test_specific_worm_collision(void) |
2129 | { | ||
2168 | int collisions = 0; | 2130 | int collisions = 0; |
2169 | int dir; | 2131 | int dir; |
2170 | int x = 0; | 2132 | int x = 0; |
@@ -2202,7 +2164,8 @@ static int test_specific_worm_collision(void) { | |||
2202 | return collisions; | 2164 | return collisions; |
2203 | } | 2165 | } |
2204 | 2166 | ||
2205 | static void test_make_argh(void){ | 2167 | static void test_make_argh(void) |
2168 | { | ||
2206 | int dir; | 2169 | int dir; |
2207 | int seed = 0; | 2170 | int seed = 0; |
2208 | int hit = 0; | 2171 | int hit = 0; |
@@ -2241,31 +2204,35 @@ static void test_make_argh(void){ | |||
2241 | for (worm_idx = 0; worm_idx < worm_count; worm_idx++){ | 2204 | for (worm_idx = 0; worm_idx < worm_count; worm_idx++){ |
2242 | if (expensive_worm_in_rect(&worms[worm_idx], x, y, argh_size, argh_size)) { | 2205 | if (expensive_worm_in_rect(&worms[worm_idx], x, y, argh_size, argh_size)) { |
2243 | int tries = 0; | 2206 | int tries = 0; |
2244 | rb->srand(seed); | 2207 | rb->srand(seed); |
2245 | 2208 | ||
2246 | tries = make_argh(0); | 2209 | tries = make_argh(0); |
2247 | if ((x == arghx[0] && y == arghy[0]) || tries < 2) { | 2210 | if ((x == arghx[0] && y == arghy[0]) || tries < 2) { |
2248 | failures ++; | 2211 | failures ++; |
2249 | } | 2212 | } |
2250 | 2213 | ||
2251 | rb->snprintf(buf, sizeof buf, "(%d;%d) fail%d try%d", x, y, failures, tries); | 2214 | rb->snprintf(buf, sizeof buf, "(%d;%d) fail%d try%d", |
2252 | rb->lcd_putsxy(0, LCD_HEIGHT - 8, buf); | 2215 | x, y, failures, tries); |
2253 | rb->lcd_update(); | 2216 | rb->lcd_putsxy(0, LCD_HEIGHT - 8, buf); |
2254 | rb->lcd_invertrect(x + FIELD_RECT_X, y+ FIELD_RECT_Y, argh_size, argh_size); | 2217 | rb->lcd_update(); |
2218 | rb->lcd_invertrect(x + FIELD_RECT_X, y+ FIELD_RECT_Y, | ||
2219 | argh_size, argh_size); | ||
2255 | rb->lcd_update(); | 2220 | rb->lcd_update(); |
2256 | draw_argh(0); | 2221 | draw_argh(0); |
2257 | rb->lcd_update(); | 2222 | rb->lcd_update(); |
2258 | rb->lcd_invertrect(x + FIELD_RECT_X, y + FIELD_RECT_Y, argh_size, argh_size); | 2223 | rb->lcd_invertrect(x + FIELD_RECT_X, y + FIELD_RECT_Y, |
2259 | rb->lcd_clearrect(arghx[0] + FIELD_RECT_X, arghy[0] + FIELD_RECT_Y, argh_size, argh_size); | 2224 | argh_size, argh_size); |
2225 | rb->lcd_clearrect(arghx[0] + FIELD_RECT_X, arghy[0] + FIELD_RECT_Y, | ||
2226 | argh_size, argh_size); | ||
2260 | 2227 | ||
2261 | if (failures > last_failures) { | 2228 | if (failures > last_failures) { |
2262 | rb->button_get(true); | 2229 | rb->button_get(true); |
2263 | } | 2230 | } |
2264 | last_failures = failures; | 2231 | last_failures = failures; |
2265 | hit ++; | 2232 | hit ++; |
2233 | } | ||
2266 | } | 2234 | } |
2267 | } | 2235 | } |
2268 | } | ||
2269 | } | 2236 | } |
2270 | 2237 | ||
2271 | static void test_worm_argh_collision_in_moves(void) { | 2238 | static void test_worm_argh_collision_in_moves(void) { |
@@ -2296,184 +2263,10 @@ static void test_worm_argh_collision_in_moves(void) { | |||
2296 | } | 2263 | } |
2297 | #endif /* DEBUG_WORMLET */ | 2264 | #endif /* DEBUG_WORMLET */ |
2298 | 2265 | ||
2299 | extern bool use_old_rect; | ||
2300 | |||
2301 | /** | ||
2302 | * These are additional functions required to set various wormlet settings | ||
2303 | * and to enable saving of settings and high score | ||
2304 | */ | ||
2305 | |||
2306 | /* | ||
2307 | Sets the total number of worms, both human and machine | ||
2308 | */ | ||
2309 | bool set_worm_num_worms(void) | ||
2310 | { | ||
2311 | bool ret; | ||
2312 | static const struct opt_items num_worms_option[3] = { | ||
2313 | { "1", -1 }, | ||
2314 | { "2", -1 }, | ||
2315 | { "3", -1 }, | ||
2316 | }; | ||
2317 | |||
2318 | ret = rb->set_option("Number Of Worms", &worm_count,INT, num_worms_option, 3, NULL); | ||
2319 | if (worm_count < players) { | ||
2320 | worm_count=players; | ||
2321 | } | ||
2322 | return ret; | ||
2323 | } | ||
2324 | |||
2325 | /* | 2266 | /* |
2326 | Sets the number of human players | 2267 | * Reverts default settings |
2327 | */ | 2268 | */ |
2328 | bool set_worm_num_players(void) | 2269 | static void default_settings(void) |
2329 | { | ||
2330 | bool ret; | ||
2331 | static const struct opt_items num_players_option[4] = { | ||
2332 | { "0", -1 }, | ||
2333 | { "1", -1 }, | ||
2334 | { "2", -1 }, | ||
2335 | { "3", -1 } | ||
2336 | }; | ||
2337 | |||
2338 | ret = rb->set_option("Number of Players", &players, INT,num_players_option , 4, NULL); | ||
2339 | if (players > worm_count) { | ||
2340 | worm_count = players; | ||
2341 | } | ||
2342 | if (players > 2) { | ||
2343 | use_remote = true; | ||
2344 | } | ||
2345 | return ret; | ||
2346 | } | ||
2347 | |||
2348 | /* | ||
2349 | Sets the size of each argh block created | ||
2350 | */ | ||
2351 | bool set_worm_argh_size(void) | ||
2352 | { | ||
2353 | static const struct opt_items argh_size_option[11] = { | ||
2354 | { "0", -1 }, | ||
2355 | { "1", -1 }, | ||
2356 | { "2", -1 }, | ||
2357 | { "3", -1 }, | ||
2358 | { "4", -1 }, | ||
2359 | { "5", -1 }, | ||
2360 | { "6", -1 }, | ||
2361 | { "7", -1 }, | ||
2362 | { "8", -1 }, | ||
2363 | { "9", -1 }, | ||
2364 | { "10", -1 } | ||
2365 | }; | ||
2366 | |||
2367 | return rb->set_option("Argh Size", &argh_size,INT,argh_size_option , 11, NULL); | ||
2368 | } | ||
2369 | |||
2370 | /* | ||
2371 | Sets the amount a worm grows per food | ||
2372 | */ | ||
2373 | bool set_worm_food(void) | ||
2374 | { | ||
2375 | static const struct opt_items worm_food_option[11] = { | ||
2376 | { "0", -1 }, | ||
2377 | { "1", -1 }, | ||
2378 | { "2", -1 }, | ||
2379 | { "3", -1 }, | ||
2380 | { "4", -1 }, | ||
2381 | { "5", -1 }, | ||
2382 | { "6", -1 }, | ||
2383 | { "7", -1 }, | ||
2384 | { "8", -1 }, | ||
2385 | { "9", -1 }, | ||
2386 | { "10", -1 } | ||
2387 | }; | ||
2388 | return rb->set_option("Worm Growth Per Food", &worm_food,INT,worm_food_option , 11, NULL); | ||
2389 | } | ||
2390 | |||
2391 | /* | ||
2392 | Sets the number of arghs created per food | ||
2393 | */ | ||
2394 | bool set_argh_per_food(void) | ||
2395 | { | ||
2396 | static const struct opt_items argh_food_option[5] = { | ||
2397 | { "0", -1 }, | ||
2398 | { "1", -1 }, | ||
2399 | { "2", -1 }, | ||
2400 | { "3", -1 }, | ||
2401 | { "4", -1 }, | ||
2402 | }; | ||
2403 | return rb->set_option("Arghs Per Food", &arghs_per_food,INT,argh_food_option , 5, NULL); | ||
2404 | } | ||
2405 | |||
2406 | /* | ||
2407 | Sets the number of ticks per move | ||
2408 | */ | ||
2409 | bool set_worm_speed(void) | ||
2410 | { | ||
2411 | bool ret; | ||
2412 | static const struct opt_items speed_option[19] = { | ||
2413 | { "0", -1 }, | ||
2414 | { "1", -1 }, | ||
2415 | { "2", -1 }, | ||
2416 | { "3", -1 }, | ||
2417 | { "4", -1 }, | ||
2418 | { "5", -1 }, | ||
2419 | { "6", -1 }, | ||
2420 | { "7", -1 }, | ||
2421 | { "8", -1 }, | ||
2422 | { "9", -1 }, | ||
2423 | { "10", -1 }, | ||
2424 | { "11", -1 }, | ||
2425 | { "12", -1 }, | ||
2426 | { "13", -1 }, | ||
2427 | { "14", -1 }, | ||
2428 | { "15", -1 }, | ||
2429 | { "16", -1 }, | ||
2430 | { "17", -1 }, | ||
2431 | { "18", -1 }, | ||
2432 | }; | ||
2433 | |||
2434 | |||
2435 | speed = 20 - speed; | ||
2436 | ret = rb->set_option("Worm Speed", &speed,INT,speed_option , 19, NULL); | ||
2437 | speed = 20 - speed; | ||
2438 | return ret; | ||
2439 | } | ||
2440 | |||
2441 | /* | ||
2442 | Sets the control style, which depends on the number of players, | ||
2443 | remote control existing, etc | ||
2444 | bool set_bool_options(char* string, bool* variable, | ||
2445 | char* yes_str, char* no_str, void (*function)(bool)) | ||
2446 | */ | ||
2447 | bool set_worm_control_style(void) | ||
2448 | { | ||
2449 | static const struct opt_items key1_option[2] = { | ||
2450 | { "Remote Control", -1 }, | ||
2451 | { "No Rem. Control", -1 }, | ||
2452 | }; | ||
2453 | |||
2454 | static const struct opt_items key2_option[2] = { | ||
2455 | { "2 Key Control", -1 }, | ||
2456 | { "4 Key COntrol", -1 }, | ||
2457 | }; | ||
2458 | |||
2459 | static const struct opt_items key3_option[1] = { | ||
2460 | { "Out of Control", -1 }, | ||
2461 | }; | ||
2462 | |||
2463 | if (players > 1) { | ||
2464 | rb->set_option("Control Style",&use_remote,INT, key1_option, 2, NULL); | ||
2465 | } else { | ||
2466 | if (players > 0) { | ||
2467 | rb->set_option("Control Style",&use_remote,INT, key2_option, 2, NULL); | ||
2468 | } | ||
2469 | else { | ||
2470 | rb->set_option("Control Style",&use_remote,INT, key3_option, 1, NULL); | ||
2471 | } | ||
2472 | } | ||
2473 | return false; | ||
2474 | } | ||
2475 | |||
2476 | void default_settings(void) | ||
2477 | { | 2270 | { |
2478 | arghs_per_food = ARGHS_PER_FOOD; | 2271 | arghs_per_food = ARGHS_PER_FOOD; |
2479 | argh_size = ARGH_SIZE; | 2272 | argh_size = ARGH_SIZE; |
@@ -2487,9 +2280,9 @@ void default_settings(void) | |||
2487 | } | 2280 | } |
2488 | 2281 | ||
2489 | /* | 2282 | /* |
2490 | Launches the wormlet game | 2283 | * Launches the wormlet game |
2491 | */ | 2284 | */ |
2492 | bool launch_wormlet(void) | 2285 | static bool launch_wormlet(void) |
2493 | { | 2286 | { |
2494 | int game_result = 1; | 2287 | int game_result = 1; |
2495 | 2288 | ||
@@ -2513,8 +2306,6 @@ bool launch_wormlet(void) | |||
2513 | return false; | 2306 | return false; |
2514 | } | 2307 | } |
2515 | 2308 | ||
2516 | /* End of settings/changes etc */ | ||
2517 | |||
2518 | /** | 2309 | /** |
2519 | * Main entry point | 2310 | * Main entry point |
2520 | */ | 2311 | */ |
@@ -2563,104 +2354,6 @@ enum plugin_status plugin_start(const void* parameter) | |||
2563 | { "Yes", -1 }, | 2354 | { "Yes", -1 }, |
2564 | }; | 2355 | }; |
2565 | 2356 | ||
2566 | static const struct opt_items num_worms_option[3] = { | ||
2567 | { "1", -1 }, | ||
2568 | { "2", -1 }, | ||
2569 | { "3", -1 } | ||
2570 | }; | ||
2571 | |||
2572 | #ifdef MULTIPLAYER | ||
2573 | static const struct opt_items num_players_option[4] = { | ||
2574 | #else | ||
2575 | static const struct opt_items num_players_option[2] = { | ||
2576 | #endif | ||
2577 | { "0", -1 }, | ||
2578 | { "1", -1 } | ||
2579 | #ifdef MULTIPLAYER | ||
2580 | ,{ "2", -1 }, | ||
2581 | { "3", -1 } | ||
2582 | #endif | ||
2583 | }; | ||
2584 | |||
2585 | static const struct opt_items argh_size_option[9] = { | ||
2586 | { "2", -1 }, | ||
2587 | { "3", -1 }, | ||
2588 | { "4", -1 }, | ||
2589 | { "5", -1 }, | ||
2590 | { "6", -1 }, | ||
2591 | { "7", -1 }, | ||
2592 | { "8", -1 }, | ||
2593 | { "9", -1 }, | ||
2594 | { "10", -1 } | ||
2595 | }; | ||
2596 | |||
2597 | static const struct opt_items food_size_option[9] = { | ||
2598 | { "2", -1 }, | ||
2599 | { "3", -1 }, | ||
2600 | { "4", -1 }, | ||
2601 | { "5", -1 }, | ||
2602 | { "6", -1 }, | ||
2603 | { "7", -1 }, | ||
2604 | { "8", -1 }, | ||
2605 | { "9", -1 }, | ||
2606 | { "10", -1 } | ||
2607 | }; | ||
2608 | |||
2609 | static const struct opt_items worm_food_option[16] = { | ||
2610 | { "0", -1 }, | ||
2611 | { "1", -1 }, | ||
2612 | { "2", -1 }, | ||
2613 | { "3", -1 }, | ||
2614 | { "4", -1 }, | ||
2615 | { "5", -1 }, | ||
2616 | { "6", -1 }, | ||
2617 | { "7", -1 }, | ||
2618 | { "8", -1 }, | ||
2619 | { "9", -1 }, | ||
2620 | { "10", -1 }, | ||
2621 | { "11", -1 }, | ||
2622 | { "12", -1 }, | ||
2623 | { "13", -1 }, | ||
2624 | { "14", -1 }, | ||
2625 | { "15", -1 } | ||
2626 | }; | ||
2627 | |||
2628 | static const struct opt_items argh_food_option[9] = { | ||
2629 | { "0", -1 }, | ||
2630 | { "1", -1 }, | ||
2631 | { "2", -1 }, | ||
2632 | { "3", -1 }, | ||
2633 | { "4", -1 }, | ||
2634 | { "5", -1 }, | ||
2635 | { "6", -1 }, | ||
2636 | { "7", -1 }, | ||
2637 | { "8", -1 } | ||
2638 | }; | ||
2639 | |||
2640 | static const struct opt_items speed_option[21] = { | ||
2641 | { "0", -1 }, | ||
2642 | { "1", -1 }, | ||
2643 | { "2", -1 }, | ||
2644 | { "3", -1 }, | ||
2645 | { "4", -1 }, | ||
2646 | { "5", -1 }, | ||
2647 | { "6", -1 }, | ||
2648 | { "7", -1 }, | ||
2649 | { "8", -1 }, | ||
2650 | { "9", -1 }, | ||
2651 | { "10", -1 }, | ||
2652 | { "11", -1 }, | ||
2653 | { "12", -1 }, | ||
2654 | { "13", -1 }, | ||
2655 | { "14", -1 }, | ||
2656 | { "15", -1 }, | ||
2657 | { "16", -1 }, | ||
2658 | { "17", -1 }, | ||
2659 | { "18", -1 }, | ||
2660 | { "19", -1 }, | ||
2661 | { "20", -1 } | ||
2662 | }; | ||
2663 | |||
2664 | static const struct opt_items remoteonly_option[1] = { | 2357 | static const struct opt_items remoteonly_option[1] = { |
2665 | { "Remote Control", -1 } | 2358 | { "Remote Control", -1 } |
2666 | }; | 2359 | }; |
@@ -2701,23 +2394,20 @@ enum plugin_status plugin_start(const void* parameter) | |||
2701 | launch_wormlet(); | 2394 | launch_wormlet(); |
2702 | break; | 2395 | break; |
2703 | case 1: | 2396 | case 1: |
2704 | new_setting = worm_count - 1; | 2397 | rb->set_int("Number of Worms", "", UNIT_INT, &worm_count, NULL, |
2705 | rb->set_option("Number of Worms", &new_setting, INT, num_worms_option, 3, NULL); | 2398 | 1, 1, 3, NULL); |
2706 | if (new_setting != worm_count) | ||
2707 | worm_count = new_setting + 1; | ||
2708 | if (worm_count < players) { | 2399 | if (worm_count < players) { |
2709 | worm_count = players; | 2400 | worm_count = players; |
2710 | } | 2401 | } |
2711 | break; | 2402 | break; |
2712 | case 2: | 2403 | case 2: |
2713 | new_setting = players; | ||
2714 | #ifdef MULTIPLAYER | 2404 | #ifdef MULTIPLAYER |
2715 | rb->set_option("Number of Players", &new_setting, INT, num_players_option , 4, NULL); | 2405 | rb->set_int("Number of Players", "", UNIT_INT, &players, NULL, |
2406 | 1, 0, 4, NULL); | ||
2716 | #else | 2407 | #else |
2717 | rb->set_option("Number of Players", &new_setting, INT, num_players_option , 2, NULL); | 2408 | rb->set_int("Number of Players", "", UNIT_INT, &players, NULL, |
2409 | 1, 0, 2, NULL); | ||
2718 | #endif | 2410 | #endif |
2719 | if (new_setting != players) | ||
2720 | players = new_setting; | ||
2721 | if (players > worm_count) { | 2411 | if (players > worm_count) { |
2722 | worm_count = players; | 2412 | worm_count = players; |
2723 | } | 2413 | } |
@@ -2726,63 +2416,55 @@ enum plugin_status plugin_start(const void* parameter) | |||
2726 | } | 2416 | } |
2727 | break; | 2417 | break; |
2728 | case 3: | 2418 | case 3: |
2729 | new_setting = use_remote; | ||
2730 | switch(players) { | 2419 | switch(players) { |
2731 | case 0: | 2420 | case 0: |
2732 | rb->set_option("Control Style",&new_setting,INT, nokey_option, 1, NULL); | 2421 | rb->set_option("Control Style",&use_remote,INT, |
2422 | nokey_option, 1, NULL); | ||
2733 | break; | 2423 | break; |
2734 | case 1: | 2424 | case 1: |
2735 | rb->set_option("Control Style",&new_setting,INT, key24_option, 2, NULL); | 2425 | rb->set_option("Control Style",&use_remote,INT, |
2426 | key24_option, 2, NULL); | ||
2736 | break; | 2427 | break; |
2737 | case 2: | 2428 | case 2: |
2738 | #ifdef REMOTE | 2429 | #ifdef REMOTE |
2739 | rb->set_option("Control Style",&new_setting,INT, remote_option, 2, NULL); | 2430 | rb->set_option("Control Style",&use_remote,INT, |
2431 | remote_option, 2, NULL); | ||
2740 | #else | 2432 | #else |
2741 | rb->set_option("Control Style",&new_setting,INT, key2_option, 1, NULL); | 2433 | rb->set_option("Control Style",&use_remote,INT, |
2434 | key2_option, 1, NULL); | ||
2742 | #endif | 2435 | #endif |
2743 | break; | 2436 | break; |
2744 | case 3: | 2437 | case 3: |
2745 | rb->set_option("Control Style",&new_setting,INT, remoteonly_option, 1, NULL); | 2438 | rb->set_option("Control Style",&use_remote,INT, |
2439 | remoteonly_option, 1, NULL); | ||
2746 | break; | 2440 | break; |
2747 | } | 2441 | } |
2748 | if (new_setting != use_remote) | ||
2749 | use_remote = new_setting; | ||
2750 | break; | 2442 | break; |
2751 | case 4: | 2443 | case 4: |
2752 | new_setting = worm_food; | 2444 | rb->set_int("Worm Growth Per Food", "", UNIT_INT, &worm_food, |
2753 | rb->set_option("Worm Growth Per Food", &new_setting,INT,worm_food_option , 16, NULL); | 2445 | NULL, 1, 0, 15, NULL); |
2754 | if (new_setting != worm_food) | ||
2755 | worm_food = new_setting; | ||
2756 | break; | 2446 | break; |
2757 | case 5: | 2447 | case 5: |
2758 | new_setting = speed; | 2448 | new_setting = 20 - speed; |
2759 | new_setting = 20 - new_setting; | 2449 | rb->set_int("Worm Speed", "", UNIT_INT, &new_setting, |
2760 | rb->set_option("Worm Speed", &new_setting,INT,speed_option , 21, NULL); | 2450 | NULL, 1, 0, 20, NULL); |
2761 | new_setting = 20 - new_setting; | 2451 | speed = 20 - new_setting; |
2762 | if (new_setting != speed) | ||
2763 | speed = new_setting; | ||
2764 | break; | 2452 | break; |
2765 | case 6: | 2453 | case 6: |
2766 | new_setting = arghs_per_food; | 2454 | rb->set_int("Arghs Per Food", "", UNIT_INT, &arghs_per_food, |
2767 | rb->set_option("Arghs Per Food", &new_setting,INT,argh_food_option , 9, NULL); | 2455 | NULL, 1, 0, 8, NULL); |
2768 | if (new_setting != arghs_per_food) | ||
2769 | arghs_per_food = new_setting; | ||
2770 | break; | 2456 | break; |
2771 | case 7: | 2457 | case 7: |
2772 | new_setting = argh_size-2; | 2458 | rb->set_int("Argh Size", "", UNIT_INT, &argh_size, |
2773 | rb->set_option("Argh Size", &new_setting,INT,argh_size_option , 9, NULL); | 2459 | NULL, 1, 2, 10, NULL); |
2774 | if (new_setting != argh_size) | ||
2775 | argh_size = new_setting+2; | ||
2776 | break; | 2460 | break; |
2777 | case 8: | 2461 | case 8: |
2778 | new_setting = food_size-2; | 2462 | rb->set_int("Food Size", "", UNIT_INT, &food_size, |
2779 | rb->set_option("Food Size", &new_setting,INT,food_size_option, 9, NULL); | 2463 | NULL, 1, 2, 10, NULL); |
2780 | if (new_setting != food_size) | ||
2781 | food_size = new_setting+2; | ||
2782 | break; | 2464 | break; |
2783 | case 9: | 2465 | case 9: |
2784 | new_setting = 0; | 2466 | new_setting = 0; |
2785 | rb->set_option("Reset Settings?", &new_setting,INT, noyes , 2, NULL); | 2467 | rb->set_option("Reset Settings?", &new_setting, INT, noyes , 2, NULL); |
2786 | if (new_setting == 1) | 2468 | if (new_setting == 1) |
2787 | default_settings(); | 2469 | default_settings(); |
2788 | break; | 2470 | break; |