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 | |
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')
-rw-r--r-- | apps/plugins/blackjack.c | 280 | ||||
-rw-r--r-- | apps/plugins/bubbles.c | 130 | ||||
-rw-r--r-- | apps/plugins/calendar.c | 138 | ||||
-rw-r--r-- | apps/plugins/clix.c | 2 | ||||
-rw-r--r-- | apps/plugins/jewels.c | 2 | ||||
-rw-r--r-- | apps/plugins/lib/highscore.c | 3 | ||||
-rw-r--r-- | apps/plugins/rocklife.c | 2 | ||||
-rw-r--r-- | apps/plugins/spacerocks.c | 2 | ||||
-rw-r--r-- | apps/plugins/wormlet.c | 594 |
9 files changed, 410 insertions, 743 deletions
diff --git a/apps/plugins/blackjack.c b/apps/plugins/blackjack.c index e1a856967f..97b44b3d3c 100644 --- a/apps/plugins/blackjack.c +++ b/apps/plugins/blackjack.c | |||
@@ -406,7 +406,7 @@ struct highscore highest[NUM_SCORES]; | |||
406 | #endif | 406 | #endif |
407 | 407 | ||
408 | #ifdef HAVE_TOUCHSCREEN | 408 | #ifdef HAVE_TOUCHSCREEN |
409 | #ifndef BJACK_DOUBLEDOWN | 409 | #ifndef BJACK_DOUBLEDOWN |
410 | #define BJACK_DOUBLEDOWN BUTTON_MIDLEFT | 410 | #define BJACK_DOUBLEDOWN BUTTON_MIDLEFT |
411 | #define BJACK_DOUBLE_NAME "BUTTON_MIDLEFT" | 411 | #define BJACK_DOUBLE_NAME "BUTTON_MIDLEFT" |
412 | #endif | 412 | #endif |
@@ -475,27 +475,26 @@ typedef struct card { | |||
475 | typedef struct game_context { | 475 | typedef struct game_context { |
476 | struct card player_cards[2][22]; /* 22 Cards means the deal was all aces */ | 476 | struct card player_cards[2][22]; /* 22 Cards means the deal was all aces */ |
477 | struct card dealer_cards[22]; /* That is the worst-case scenario */ | 477 | struct card dealer_cards[22]; /* That is the worst-case scenario */ |
478 | unsigned int player_total; | 478 | unsigned int player_total; |
479 | unsigned int dealer_total; | 479 | unsigned int dealer_total; |
480 | signed int player_money; | 480 | signed int player_money; |
481 | unsigned int num_player_cards[2]; | 481 | unsigned int num_player_cards[2]; |
482 | unsigned int num_dealer_cards; | 482 | unsigned int num_dealer_cards; |
483 | unsigned int current_bet; | 483 | unsigned int current_bet; |
484 | unsigned int split_status; /* 0 = split hasn't been asked, * | 484 | unsigned int split_status; /* 0 = split hasn't been asked, * |
485 | * 1 = split did not occur * | 485 | * 1 = split did not occur * |
486 | * 2 = split occurred * | 486 | * 2 = split occurred * |
487 | * 3 = split occurred and 1st hand done */ | 487 | * 3 = split occurred and 1st hand done */ |
488 | bool is_blackjack; | 488 | bool is_blackjack; |
489 | bool end_hand; | 489 | bool end_hand; |
490 | bool asked_insurance; | 490 | bool asked_insurance; |
491 | bool resume; | 491 | bool resume; |
492 | bool dirty; | ||
493 | } game_context; | 492 | } game_context; |
494 | 493 | ||
495 | /***************************************************************************** | 494 | /***************************************************************************** |
496 | * blackjack_init() initializes blackjack data structures. | 495 | * blackjack_init() initializes blackjack data structures. |
497 | ******************************************************************************/ | 496 | ******************************************************************************/ |
498 | static void blackjack_init(struct game_context* bj) { | 497 | static void blackjack_init(struct game_context* bj) { |
499 | /* seed the rand generator */ | 498 | /* seed the rand generator */ |
500 | rb->srand(*rb->current_tick); | 499 | rb->srand(*rb->current_tick); |
501 | 500 | ||
@@ -504,7 +503,7 @@ static void blackjack_init(struct game_context* bj) { | |||
504 | dealer_y = LCD_HEIGHT/4 - CARD_HEIGHT/2; | 503 | dealer_y = LCD_HEIGHT/4 - CARD_HEIGHT/2; |
505 | player_x = 4; | 504 | player_x = 4; |
506 | player_y = LCD_HEIGHT - LCD_HEIGHT/4 - CARD_HEIGHT/2; | 505 | player_y = LCD_HEIGHT - LCD_HEIGHT/4 - CARD_HEIGHT/2; |
507 | 506 | ||
508 | /* check for resumed game */ | 507 | /* check for resumed game */ |
509 | if(bj->resume) return; | 508 | if(bj->resume) return; |
510 | 509 | ||
@@ -517,7 +516,7 @@ static void blackjack_init(struct game_context* bj) { | |||
517 | bj->end_hand = false; | 516 | bj->end_hand = false; |
518 | bj->split_status = 0; | 517 | bj->split_status = 0; |
519 | bj->is_blackjack = false; | 518 | bj->is_blackjack = false; |
520 | bj->asked_insurance = false; | 519 | bj->asked_insurance = false; |
521 | } | 520 | } |
522 | 521 | ||
523 | /***************************************************************************** | 522 | /***************************************************************************** |
@@ -526,7 +525,7 @@ static void blackjack_init(struct game_context* bj) { | |||
526 | static void blackjack_drawtable(struct game_context* bj) { | 525 | static void blackjack_drawtable(struct game_context* bj) { |
527 | unsigned int w, h, y_loc; | 526 | unsigned int w, h, y_loc; |
528 | char str[10]; | 527 | char str[10]; |
529 | 528 | ||
530 | #if LCD_HEIGHT <= 64 | 529 | #if LCD_HEIGHT <= 64 |
531 | rb->lcd_getstringsize("Bet", &w, &h); | 530 | rb->lcd_getstringsize("Bet", &w, &h); |
532 | rb->lcd_putsxy(LCD_WIDTH - w, 2*h + 1, "Bet"); | 531 | rb->lcd_putsxy(LCD_WIDTH - w, 2*h + 1, "Bet"); |
@@ -577,19 +576,19 @@ static unsigned int find_value(unsigned int number) { | |||
577 | /***************************************************************************** | 576 | /***************************************************************************** |
578 | * draw_card() draws a card to the screen. | 577 | * draw_card() draws a card to the screen. |
579 | ******************************************************************************/ | 578 | ******************************************************************************/ |
580 | static void draw_card(struct card temp_card, bool shown, unsigned int x, | 579 | static void draw_card(struct card temp_card, bool shown, |
581 | unsigned int y) { | 580 | unsigned int x, unsigned int y) { |
582 | if(shown) | 581 | if(shown) |
583 | rb->lcd_bitmap_part(card_deck, CARD_WIDTH*temp_card.num, | 582 | rb->lcd_bitmap_part(card_deck, CARD_WIDTH*temp_card.num, |
584 | CARD_HEIGHT*temp_card.suit, BMPWIDTH_card_deck, | 583 | CARD_HEIGHT*temp_card.suit, BMPWIDTH_card_deck, |
585 | x+1, y+1, CARD_WIDTH, CARD_HEIGHT); | 584 | x+1, y+1, CARD_WIDTH, CARD_HEIGHT); |
586 | else | 585 | else |
587 | rb->lcd_bitmap(card_back, x+1, y+1,CARD_WIDTH, CARD_HEIGHT); | 586 | rb->lcd_bitmap(card_back, x+1, y+1,CARD_WIDTH, CARD_HEIGHT); |
588 | #if LCD_DEPTH > 1 | 587 | #if LCD_DEPTH > 1 |
589 | rb->lcd_set_foreground(LCD_BLACK); | 588 | rb->lcd_set_foreground(LCD_BLACK); |
590 | #endif | 589 | #endif |
591 | 590 | ||
592 | /* Print outlines */ | 591 | /* Print outlines */ |
593 | #if CARD_WIDTH >= 26 | 592 | #if CARD_WIDTH >= 26 |
594 | rb->lcd_hline(x+2, x+CARD_WIDTH-1, y); | 593 | rb->lcd_hline(x+2, x+CARD_WIDTH-1, y); |
595 | rb->lcd_hline(x+2, x+CARD_WIDTH-1, y+CARD_HEIGHT+1); | 594 | rb->lcd_hline(x+2, x+CARD_WIDTH-1, y+CARD_HEIGHT+1); |
@@ -618,7 +617,7 @@ static struct card new_card(void) { | |||
618 | struct card new_card; | 617 | struct card new_card; |
619 | new_card.suit = rb->rand()%4; /* Random number 0-3 */ | 618 | new_card.suit = rb->rand()%4; /* Random number 0-3 */ |
620 | new_card.num = rb->rand()%13; /* Random number 0-12 */ | 619 | new_card.num = rb->rand()%13; /* Random number 0-12 */ |
621 | new_card.value = find_value(new_card.num); | 620 | new_card.value = find_value(new_card.num); |
622 | new_card.is_soft_ace = new_card.num == 0 ? true : false; | 621 | new_card.is_soft_ace = new_card.num == 0 ? true : false; |
623 | return new_card; | 622 | return new_card; |
624 | } | 623 | } |
@@ -645,7 +644,7 @@ static void deal_init_cards(struct game_context* bj) { | |||
645 | bj->player_cards[0][1] = new_card(); | 644 | bj->player_cards[0][1] = new_card(); |
646 | bj->player_total += bj->player_cards[0][1].value; | 645 | bj->player_total += bj->player_cards[0][1].value; |
647 | draw_card(bj->player_cards[0][1], true, player_x, player_y); | 646 | draw_card(bj->player_cards[0][1], true, player_x, player_y); |
648 | player_x += CARD_WIDTH + 4; | 647 | player_x += CARD_WIDTH + 4; |
649 | } | 648 | } |
650 | 649 | ||
651 | /***************************************************************************** | 650 | /***************************************************************************** |
@@ -669,7 +668,7 @@ static void redraw_board(struct game_context* bj) { | |||
669 | dealer_x += CARD_WIDTH + 4; | 668 | dealer_x += CARD_WIDTH + 4; |
670 | } | 669 | } |
671 | draw_card(bj->dealer_cards[i], true, dealer_x, dealer_y); | 670 | draw_card(bj->dealer_cards[i], true, dealer_x, dealer_y); |
672 | 671 | ||
673 | if (bj->num_dealer_cards > MAX_CARDS-1) | 672 | if (bj->num_dealer_cards > MAX_CARDS-1) |
674 | dealer_x += 10; | 673 | dealer_x += 10; |
675 | else | 674 | else |
@@ -682,7 +681,7 @@ static void redraw_board(struct game_context* bj) { | |||
682 | if (bj->split_status>1 || bj->num_player_cards[n]>MAX_CARDS) | 681 | if (bj->split_status>1 || bj->num_player_cards[n]>MAX_CARDS) |
683 | player_x += 10; | 682 | player_x += 10; |
684 | else | 683 | else |
685 | player_x += CARD_WIDTH + 4; | 684 | player_x += CARD_WIDTH + 4; |
686 | } | 685 | } |
687 | if (bj->split_status > 1) | 686 | if (bj->split_status > 1) |
688 | player_x = LCD_WIDTH/2 + 4; | 687 | player_x = LCD_WIDTH/2 + 4; |
@@ -709,12 +708,11 @@ static void update_total(struct game_context* bj) { | |||
709 | * check_for_aces() is passed an array of cards and returns where an ace is | 708 | * check_for_aces() is passed an array of cards and returns where an ace is |
710 | * located. Otherwise, returns -1. | 709 | * located. Otherwise, returns -1. |
711 | ******************************************************************************/ | 710 | ******************************************************************************/ |
712 | static signed int check_for_aces(struct card temp_cards[], | 711 | static signed int check_for_aces(struct card temp_cards[], unsigned int size) { |
713 | unsigned int size) { | ||
714 | unsigned int i; | 712 | unsigned int i; |
715 | for(i = 0; i < size; i++) { | 713 | for(i = 0; i < size; i++) { |
716 | if (temp_cards[i].is_soft_ace == true) | 714 | if (temp_cards[i].is_soft_ace == true) |
717 | return i; | 715 | return i; |
718 | } | 716 | } |
719 | return -1; | 717 | return -1; |
720 | } | 718 | } |
@@ -723,26 +721,26 @@ static signed int check_for_aces(struct card temp_cards[], | |||
723 | * check_totals() compares player and dealer totals. | 721 | * check_totals() compares player and dealer totals. |
724 | * 0: bust 1: loss, 2: push, 3: win, 4: blackjack, 5: something's not right... | 722 | * 0: bust 1: loss, 2: push, 3: win, 4: blackjack, 5: something's not right... |
725 | ******************************************************************************/ | 723 | ******************************************************************************/ |
726 | static unsigned int check_totals(struct game_context* bj) | 724 | static unsigned int check_totals(struct game_context* bj) { |
727 | { | ||
728 | unsigned int temp; | 725 | unsigned int temp; |
729 | if (bj->player_total > 21) | 726 | if (bj->player_total > 21) |
730 | temp = 0; | 727 | temp = 0; |
731 | else if (bj->player_total == 21 && bj->is_blackjack) | 728 | else if (bj->player_total == 21 && bj->is_blackjack) { |
732 | if (bj->dealer_total == 21 && bj->num_dealer_cards == 2) | 729 | if (bj->dealer_total == 21 && bj->num_dealer_cards == 2) |
733 | temp = 2; | 730 | temp = 2; |
734 | else | 731 | else |
735 | temp = 4; | 732 | temp = 4; |
733 | } | ||
736 | else if (bj->player_total == bj->dealer_total) | 734 | else if (bj->player_total == bj->dealer_total) |
737 | temp = 2; | 735 | temp = 2; |
738 | else if (bj->dealer_total > 21 && bj->player_total < 22) | 736 | else if (bj->dealer_total > 21 && bj->player_total < 22) |
739 | temp = 3; | 737 | temp = 3; |
740 | else if (bj->dealer_total > bj->player_total) | 738 | else if (bj->dealer_total > bj->player_total) |
741 | temp = 1; | 739 | temp = 1; |
742 | else if (bj->player_total > bj->dealer_total) | 740 | else if (bj->player_total > bj->dealer_total) |
743 | temp = 3; | 741 | temp = 3; |
744 | else | 742 | else |
745 | temp = 5; | 743 | temp = 5; |
746 | 744 | ||
747 | return temp; | 745 | return temp; |
748 | } | 746 | } |
@@ -752,24 +750,24 @@ static unsigned int check_totals(struct game_context* bj) | |||
752 | ******************************************************************************/ | 750 | ******************************************************************************/ |
753 | static void finish_dealer(struct game_context* bj) { | 751 | static void finish_dealer(struct game_context* bj) { |
754 | signed int temp = 0; | 752 | signed int temp = 0; |
755 | 753 | ||
756 | if (bj->dealer_total > 16 && bj->dealer_total < 22) | 754 | if (bj->dealer_total > 16 && bj->dealer_total < 22) |
757 | return; | 755 | return; |
758 | 756 | ||
759 | while (bj->dealer_total < 17) { | 757 | while (bj->dealer_total < 17) { |
760 | bj->dealer_cards[bj->num_dealer_cards] = new_card(); | 758 | bj->dealer_cards[bj->num_dealer_cards] = new_card(); |
761 | bj->dealer_total += bj->dealer_cards[bj->num_dealer_cards].value; | 759 | bj->dealer_total += bj->dealer_cards[bj->num_dealer_cards].value; |
762 | bj->num_dealer_cards++; | 760 | bj->num_dealer_cards++; |
763 | } | 761 | } |
764 | 762 | ||
765 | while (bj->dealer_total > 21) { | 763 | while (bj->dealer_total > 21) { |
766 | temp = check_for_aces(bj->dealer_cards, bj->num_dealer_cards); | 764 | temp = check_for_aces(bj->dealer_cards, bj->num_dealer_cards); |
767 | if(temp != -1) { | 765 | if(temp != -1) { |
768 | bj->dealer_cards[temp].is_soft_ace = false; | 766 | bj->dealer_cards[temp].is_soft_ace = false; |
769 | bj->dealer_total -= 10; | 767 | bj->dealer_total -= 10; |
770 | } | 768 | } |
771 | else | 769 | else |
772 | return; | 770 | return; |
773 | } | 771 | } |
774 | } | 772 | } |
775 | 773 | ||
@@ -783,31 +781,31 @@ static void finish_game(struct game_context* bj) { | |||
783 | do { | 781 | do { |
784 | finish_dealer(bj); | 782 | finish_dealer(bj); |
785 | } while (bj->dealer_total < 17); | 783 | } while (bj->dealer_total < 17); |
786 | 784 | ||
787 | redraw_board(bj); | 785 | redraw_board(bj); |
788 | rValue = check_totals(bj); | 786 | rValue = check_totals(bj); |
789 | 787 | ||
790 | if (rValue == 0) { | 788 | if (rValue == 0) { |
791 | rb->snprintf(str, sizeof(str), " Bust! "); | 789 | rb->snprintf(str, sizeof(str), " Bust! "); |
792 | bj->player_money -= bj->current_bet; | 790 | bj->player_money -= bj->current_bet; |
793 | } | 791 | } |
794 | else if (rValue == 1) { | 792 | else if (rValue == 1) { |
795 | rb->snprintf(str, sizeof(str), " Sorry, you lost. "); | 793 | rb->snprintf(str, sizeof(str), " Sorry, you lost. "); |
796 | bj->player_money -= bj->current_bet; | 794 | bj->player_money -= bj->current_bet; |
797 | } | 795 | } |
798 | else if (rValue == 2) { | 796 | else if (rValue == 2) { |
799 | rb->snprintf(str, sizeof(str), " Push "); | 797 | rb->snprintf(str, sizeof(str), " Push "); |
800 | } | 798 | } |
801 | else if (rValue == 3) { | 799 | else if (rValue == 3) { |
802 | rb->snprintf(str, sizeof(str), " You won! "); | 800 | rb->snprintf(str, sizeof(str), " You won! "); |
803 | bj->player_money+= bj->current_bet; | 801 | bj->player_money+= bj->current_bet; |
804 | } | 802 | } |
805 | else { | 803 | else { |
806 | rb->snprintf(str, sizeof(str), " Blackjack! "); | 804 | rb->snprintf(str, sizeof(str), " Blackjack! "); |
807 | bj->player_money += bj->current_bet * 3 / 2; | 805 | bj->player_money += bj->current_bet * 3 / 2; |
808 | } | 806 | } |
809 | rb->lcd_getstringsize(str, &w, &h); | 807 | rb->lcd_getstringsize(str, &w, &h); |
810 | 808 | ||
811 | #if LCD_HEIGHT <= 64 | 809 | #if LCD_HEIGHT <= 64 |
812 | rb->lcd_set_drawmode(DRMODE_BG+DRMODE_INVERSEVID); | 810 | rb->lcd_set_drawmode(DRMODE_BG+DRMODE_INVERSEVID); |
813 | rb->lcd_fillrect(0, LCD_HEIGHT/2, LCD_WIDTH, LCD_HEIGHT/2); | 811 | rb->lcd_fillrect(0, LCD_HEIGHT/2, LCD_WIDTH, LCD_HEIGHT/2); |
@@ -835,7 +833,7 @@ static bool blackjack_loadgame(struct game_context* bj) { | |||
835 | 833 | ||
836 | /* read in saved game */ | 834 | /* read in saved game */ |
837 | while(true) { | 835 | while(true) { |
838 | if(rb->read(fd, &bj->player_money, sizeof(bj->player_money)) <= 0) | 836 | if(rb->read(fd, &bj->player_money, sizeof(bj->player_money)) <= 0) |
839 | break; | 837 | break; |
840 | if(rb->read(fd, &bj->player_total, sizeof(bj->player_total)) <= 0) | 838 | if(rb->read(fd, &bj->player_total, sizeof(bj->player_total)) <= 0) |
841 | break; | 839 | break; |
@@ -845,19 +843,19 @@ static bool blackjack_loadgame(struct game_context* bj) { | |||
845 | break; | 843 | break; |
846 | if(rb->read(fd, &bj->num_dealer_cards, sizeof(bj->num_dealer_cards))<=0) | 844 | if(rb->read(fd, &bj->num_dealer_cards, sizeof(bj->num_dealer_cards))<=0) |
847 | break; | 845 | break; |
848 | if(rb->read(fd, &bj->current_bet, sizeof(bj->current_bet)) <= 0) | 846 | if(rb->read(fd, &bj->current_bet, sizeof(bj->current_bet)) <= 0) |
849 | break; | 847 | break; |
850 | if(rb->read(fd, &bj->is_blackjack, sizeof(bj->is_blackjack)) <= 0) | 848 | if(rb->read(fd, &bj->is_blackjack, sizeof(bj->is_blackjack)) <= 0) |
851 | break; | 849 | break; |
852 | if(rb->read(fd, &bj->split_status, sizeof(bj->split_status)) <= 0) | 850 | if(rb->read(fd, &bj->split_status, sizeof(bj->split_status)) <= 0) |
853 | break; | 851 | break; |
854 | if(rb->read(fd, &bj->asked_insurance, sizeof(bj->asked_insurance)) <= 0) | 852 | if(rb->read(fd, &bj->asked_insurance, sizeof(bj->asked_insurance)) <= 0) |
855 | break; | 853 | break; |
856 | if(rb->read(fd, &bj->end_hand, sizeof(bj->end_hand)) <= 0) | 854 | if(rb->read(fd, &bj->end_hand, sizeof(bj->end_hand)) <= 0) |
857 | break; | 855 | break; |
858 | if(rb->read(fd, &bj->player_cards, sizeof(bj->player_cards)) <= 0) | 856 | if(rb->read(fd, &bj->player_cards, sizeof(bj->player_cards)) <= 0) |
859 | break; | 857 | break; |
860 | if(rb->read(fd, &bj->dealer_cards, sizeof(bj->dealer_cards)) <= 0) | 858 | if(rb->read(fd, &bj->dealer_cards, sizeof(bj->dealer_cards)) <= 0) |
861 | break; | 859 | break; |
862 | bj->resume = true; | 860 | bj->resume = true; |
863 | loaded = true; | 861 | loaded = true; |
@@ -911,7 +909,7 @@ static unsigned int blackjack_get_yes_no(char message[20]) { | |||
911 | rb->strcat(message_no, " No"); | 909 | rb->strcat(message_no, " No"); |
912 | rb->lcd_getstringsize(message_yes, &w, &h); | 910 | rb->lcd_getstringsize(message_yes, &w, &h); |
913 | const char *stg[] = {message_yes, message_no}; | 911 | const char *stg[] = {message_yes, message_no}; |
914 | 912 | ||
915 | #if LCD_HEIGHT <= 64 | 913 | #if LCD_HEIGHT <= 64 |
916 | b = 2*h+1; | 914 | b = 2*h+1; |
917 | #else | 915 | #else |
@@ -928,10 +926,10 @@ static unsigned int blackjack_get_yes_no(char message[20]) { | |||
928 | rb->lcd_set_drawmode(DRMODE_SOLID); | 926 | rb->lcd_set_drawmode(DRMODE_SOLID); |
929 | #endif | 927 | #endif |
930 | rb->lcd_drawrect(LCD_WIDTH/2 - w/2 - 1, LCD_HEIGHT/2 + b - 1, w+3, h+4); | 928 | rb->lcd_drawrect(LCD_WIDTH/2 - w/2 - 1, LCD_HEIGHT/2 + b - 1, w+3, h+4); |
931 | 929 | ||
932 | while(!breakout) { | 930 | while(!breakout) { |
933 | rb->lcd_putsxy(LCD_WIDTH/2 - w/2, LCD_HEIGHT/2 + b +1, stg[choice]); | 931 | rb->lcd_putsxy(LCD_WIDTH/2 - w/2, LCD_HEIGHT/2 + b +1, stg[choice]); |
934 | rb->lcd_update_rect(LCD_WIDTH/2 - w/2 - 1, LCD_HEIGHT/2 + b -1, | 932 | rb->lcd_update_rect(LCD_WIDTH/2 - w/2 - 1, LCD_HEIGHT/2 + b -1, |
935 | w+3, h+4); | 933 | w+3, h+4); |
936 | button = rb->button_get(true); | 934 | button = rb->button_get(true); |
937 | 935 | ||
@@ -949,7 +947,7 @@ static unsigned int blackjack_get_yes_no(char message[20]) { | |||
949 | break; | 947 | break; |
950 | } | 948 | } |
951 | } | 949 | } |
952 | 950 | ||
953 | #if LCD_DEPTH > 1 | 951 | #if LCD_DEPTH > 1 |
954 | rb->lcd_set_foreground(FG_COLOR); | 952 | rb->lcd_set_foreground(FG_COLOR); |
955 | rb->lcd_set_background(BG_COLOR); | 953 | rb->lcd_set_background(BG_COLOR); |
@@ -961,16 +959,16 @@ static unsigned int blackjack_get_yes_no(char message[20]) { | |||
961 | * blackjack_get_amount() gets an amount from the player to be used | 959 | * blackjack_get_amount() gets an amount from the player to be used |
962 | ******************************************************************************/ | 960 | ******************************************************************************/ |
963 | static signed int blackjack_get_amount(char message[20], signed int lower_limit, | 961 | static signed int blackjack_get_amount(char message[20], signed int lower_limit, |
964 | signed int upper_limit, | 962 | signed int upper_limit, |
965 | signed int start) { | 963 | signed int start) { |
966 | int button; | 964 | int button; |
967 | char str[6]; | 965 | char str[9]; |
968 | bool changed = false; | 966 | bool changed = false; |
969 | unsigned int w, h; | 967 | unsigned int w, h; |
970 | signed int amount; | 968 | signed int amount; |
971 | 969 | ||
972 | rb->lcd_getstringsize("A", &w, &h); /* find the size of one character */ | 970 | rb->lcd_getstringsize("A", &w, &h); /* find the size of one character */ |
973 | 971 | ||
974 | if (start > upper_limit) | 972 | if (start > upper_limit) |
975 | amount = upper_limit; | 973 | amount = upper_limit; |
976 | else if (start < lower_limit) | 974 | else if (start < lower_limit) |
@@ -995,11 +993,11 @@ static signed int blackjack_get_amount(char message[20], signed int lower_limit, | |||
995 | rb->lcd_update(); | 993 | rb->lcd_update(); |
996 | #else | 994 | #else |
997 | rb->lcd_set_drawmode(DRMODE_BG+DRMODE_INVERSEVID); | 995 | rb->lcd_set_drawmode(DRMODE_BG+DRMODE_INVERSEVID); |
998 | rb->lcd_fillrect(LCD_WIDTH/2 - 9*w - 1, LCD_HEIGHT/2 - 4*h - 3, 37*w / 2, | 996 | rb->lcd_fillrect(LCD_WIDTH/2 - 9*w - 1, LCD_HEIGHT/2 - 4*h - 3, |
999 | 8*h -3); | 997 | 37*w / 2, 8*h -3); |
1000 | rb->lcd_set_drawmode(DRMODE_SOLID); | 998 | rb->lcd_set_drawmode(DRMODE_SOLID); |
1001 | rb->lcd_drawrect(LCD_WIDTH/2 - 9*w - 1, LCD_HEIGHT/2 - 4*h - 3, 37*w / 2, | 999 | rb->lcd_drawrect(LCD_WIDTH/2 - 9*w - 1, LCD_HEIGHT/2 - 4*h - 3, |
1002 | 8*h -3); | 1000 | 37*w / 2, 8*h -3); |
1003 | rb->lcd_putsxy(LCD_WIDTH/2 - 9*w, LCD_HEIGHT/2 - 4*h - 1, message); | 1001 | rb->lcd_putsxy(LCD_WIDTH/2 - 9*w, LCD_HEIGHT/2 - 4*h - 1, message); |
1004 | rb->snprintf(str, 9, "$%d", amount); | 1002 | rb->snprintf(str, 9, "$%d", amount); |
1005 | rb->lcd_putsxy(LCD_WIDTH/2 - 9*w, LCD_HEIGHT/2 - 3*h, str); | 1003 | rb->lcd_putsxy(LCD_WIDTH/2 - 9*w, LCD_HEIGHT/2 - 3*h, str); |
@@ -1021,21 +1019,21 @@ static signed int blackjack_get_amount(char message[20], signed int lower_limit, | |||
1021 | rb->lcd_putsxy(LCD_WIDTH/2 - 9*w, LCD_HEIGHT/2 + h, "UP: +10"); | 1019 | rb->lcd_putsxy(LCD_WIDTH/2 - 9*w, LCD_HEIGHT/2 + h, "UP: +10"); |
1022 | rb->lcd_putsxy(LCD_WIDTH/2 - 9*w, LCD_HEIGHT/2 + 2*h + 1, "DOWN: -10"); | 1020 | rb->lcd_putsxy(LCD_WIDTH/2 - 9*w, LCD_HEIGHT/2 + 2*h + 1, "DOWN: -10"); |
1023 | #endif | 1021 | #endif |
1024 | rb->lcd_update_rect(LCD_WIDTH/2 - 9*w - 2, LCD_HEIGHT/2 - 9*h/2, 37*w/2 + 1, | 1022 | rb->lcd_update_rect(LCD_WIDTH/2 - 9*w - 1, LCD_HEIGHT/2 - 4*h - 3, |
1025 | 8*h-2); | 1023 | 37*w / 2, 8*h -3); |
1026 | #endif | 1024 | #endif |
1027 | 1025 | ||
1028 | while(true) { | 1026 | while(true) { |
1029 | button = rb->button_get(true); | 1027 | button = rb->button_get(true); |
1030 | 1028 | ||
1031 | switch(button) { | 1029 | switch(button) { |
1032 | case BJACK_UP: | 1030 | case BJACK_UP: |
1033 | case (BJACK_UP|BUTTON_REPEAT): | 1031 | case (BJACK_UP|BUTTON_REPEAT): |
1034 | if (amount + 10 < upper_limit + 1) { | 1032 | if (amount + 10 < upper_limit + 1) { |
1035 | amount += 10; | 1033 | amount += 10; |
1036 | changed = true; | 1034 | changed = true; |
1037 | } | 1035 | } |
1038 | break; | 1036 | break; |
1039 | case BJACK_DOWN: | 1037 | case BJACK_DOWN: |
1040 | case (BJACK_DOWN|BUTTON_REPEAT): | 1038 | case (BJACK_DOWN|BUTTON_REPEAT): |
1041 | if (amount - 10 > lower_limit - 1) { | 1039 | if (amount - 10 > lower_limit - 1) { |
@@ -1074,9 +1072,9 @@ static signed int blackjack_get_amount(char message[20], signed int lower_limit, | |||
1074 | #endif | 1072 | #endif |
1075 | rb->lcd_clear_display(); | 1073 | rb->lcd_clear_display(); |
1076 | return amount; | 1074 | return amount; |
1077 | } | 1075 | } |
1078 | 1076 | ||
1079 | if(changed) { | 1077 | if(changed) { |
1080 | rb->snprintf(str, 9, "$%d", amount); | 1078 | rb->snprintf(str, 9, "$%d", amount); |
1081 | #if LCD_HEIGHT <= 64 | 1079 | #if LCD_HEIGHT <= 64 |
1082 | rb->lcd_puts(0, 2, str); | 1080 | rb->lcd_puts(0, 2, str); |
@@ -1097,7 +1095,7 @@ static signed int blackjack_get_amount(char message[20], signed int lower_limit, | |||
1097 | * blackjack_get_bet() gets the player's bet. | 1095 | * blackjack_get_bet() gets the player's bet. |
1098 | ******************************************************************************/ | 1096 | ******************************************************************************/ |
1099 | static void blackjack_get_bet(struct game_context* bj) { | 1097 | static void blackjack_get_bet(struct game_context* bj) { |
1100 | bj->current_bet = blackjack_get_amount("Please enter a bet", 10, | 1098 | bj->current_bet = blackjack_get_amount("Please enter a bet", 10, |
1101 | bj->player_money, bj->current_bet); | 1099 | bj->player_money, bj->current_bet); |
1102 | } | 1100 | } |
1103 | 1101 | ||
@@ -1133,11 +1131,11 @@ static void split(struct game_context* bj) { | |||
1133 | * insurance() see if the player wants to buy insurance and how much. | 1131 | * insurance() see if the player wants to buy insurance and how much. |
1134 | ******************************************************************************/ | 1132 | ******************************************************************************/ |
1135 | static unsigned int insurance(struct game_context* bj) { | 1133 | static unsigned int insurance(struct game_context* bj) { |
1136 | unsigned int insurance, max_amount; | 1134 | unsigned int insurance, max_amount; |
1137 | 1135 | ||
1138 | insurance = blackjack_get_yes_no("Buy Insurance?"); | 1136 | insurance = blackjack_get_yes_no("Buy Insurance?"); |
1139 | bj->asked_insurance = true; | 1137 | bj->asked_insurance = true; |
1140 | max_amount = bj->current_bet < (unsigned int)bj->player_money ? | 1138 | max_amount = bj->current_bet < (unsigned int)bj->player_money ? |
1141 | bj->current_bet/2 : (unsigned int)bj->player_money; | 1139 | bj->current_bet/2 : (unsigned int)bj->player_money; |
1142 | if (insurance == 1) return 0; | 1140 | if (insurance == 1) return 0; |
1143 | 1141 | ||
@@ -1153,7 +1151,10 @@ static unsigned int play_again(void) { | |||
1153 | return blackjack_get_yes_no("Play Again?"); | 1151 | return blackjack_get_yes_no("Play Again?"); |
1154 | } | 1152 | } |
1155 | 1153 | ||
1156 | void showhelp(void) { | 1154 | /***************************************************************************** |
1155 | * blackjack_help() displays help text. | ||
1156 | ******************************************************************************/ | ||
1157 | static bool blackjack_help(void) { | ||
1157 | #define WORDS (sizeof help_text / sizeof (char*)) | 1158 | #define WORDS (sizeof help_text / sizeof (char*)) |
1158 | static char *help_text[] = { | 1159 | static char *help_text[] = { |
1159 | "Blackjack", "", | 1160 | "Blackjack", "", |
@@ -1184,16 +1185,16 @@ void showhelp(void) { | |||
1184 | #endif | 1185 | #endif |
1185 | 1186 | ||
1186 | if (display_text(WORDS, help_text, formation, NULL)) | 1187 | if (display_text(WORDS, help_text, formation, NULL)) |
1187 | return; | 1188 | return true; |
1188 | do { | 1189 | do { |
1189 | button = rb->button_get(true); | 1190 | button = rb->button_get(true); |
1190 | if (rb->default_event_handler(button) == SYS_USB_CONNECTED) { | 1191 | if (rb->default_event_handler(button) == SYS_USB_CONNECTED) { |
1191 | return; | 1192 | return true; |
1192 | } | 1193 | } |
1193 | } while( ( button == BUTTON_NONE ) | 1194 | } while( ( button == BUTTON_NONE ) |
1194 | || ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); | 1195 | || ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); |
1195 | rb->lcd_setfont(FONT_SYSFIXED); | 1196 | rb->lcd_setfont(FONT_SYSFIXED); |
1196 | return; | 1197 | return false; |
1197 | } | 1198 | } |
1198 | 1199 | ||
1199 | /***************************************************************************** | 1200 | /***************************************************************************** |
@@ -1202,9 +1203,11 @@ void showhelp(void) { | |||
1202 | static unsigned int blackjack_menu(struct game_context* bj) { | 1203 | static unsigned int blackjack_menu(struct game_context* bj) { |
1203 | int selection=0; | 1204 | int selection=0; |
1204 | bool breakout = false; | 1205 | bool breakout = false; |
1205 | 1206 | ||
1206 | MENUITEM_STRINGLIST(menu,"BlackJack Menu",NULL,"Start Game","Resume Game", | 1207 | MENUITEM_STRINGLIST(menu, "BlackJack Menu", NULL, |
1207 | "High Scores", "Help", "Playback Control", "Quit"); | 1208 | "Start Game","Resume Game", |
1209 | "High Scores", "Help", | ||
1210 | "Playback Control", "Quit"); | ||
1208 | 1211 | ||
1209 | while(!breakout) { | 1212 | while(!breakout) { |
1210 | switch(rb->do_menu(&menu, &selection, NULL, false)) { | 1213 | switch(rb->do_menu(&menu, &selection, NULL, false)) { |
@@ -1215,7 +1218,6 @@ static unsigned int blackjack_menu(struct game_context* bj) { | |||
1215 | if(!blackjack_loadgame(bj)) { | 1218 | if(!blackjack_loadgame(bj)) { |
1216 | rb->splash(HZ*2, "Nothing to resume"); | 1219 | rb->splash(HZ*2, "Nothing to resume"); |
1217 | } else { | 1220 | } else { |
1218 | rb->splash(HZ*2, "Loading..."); | ||
1219 | breakout = true; | 1221 | breakout = true; |
1220 | } | 1222 | } |
1221 | break; | 1223 | break; |
@@ -1223,18 +1225,19 @@ static unsigned int blackjack_menu(struct game_context* bj) { | |||
1223 | highscore_show(NUM_SCORES, highest, NUM_SCORES, false); | 1225 | highscore_show(NUM_SCORES, highest, NUM_SCORES, false); |
1224 | break; | 1226 | break; |
1225 | case 3: | 1227 | case 3: |
1226 | showhelp(); | 1228 | if(blackjack_help()) |
1229 | return BJ_USB; | ||
1227 | break; | 1230 | break; |
1228 | case 4: | 1231 | case 4: |
1229 | if (playback_control(NULL)) | 1232 | if (playback_control(NULL)) |
1230 | return 1; | 1233 | return BJ_USB; |
1231 | break; | 1234 | break; |
1232 | case 5: | 1235 | case 5: |
1233 | return BJ_QUIT; | 1236 | return BJ_QUIT; |
1234 | 1237 | ||
1235 | case MENU_ATTACHED_USB: | 1238 | case MENU_ATTACHED_USB: |
1236 | return BJ_USB; | 1239 | return BJ_USB; |
1237 | 1240 | ||
1238 | default: | 1241 | default: |
1239 | break; | 1242 | break; |
1240 | } | 1243 | } |
@@ -1253,6 +1256,11 @@ static int blackjack(struct game_context* bj) { | |||
1253 | bool breakout = false; | 1256 | bool breakout = false; |
1254 | bool dbl_down = false; | 1257 | bool dbl_down = false; |
1255 | 1258 | ||
1259 | #if LCD_DEPTH > 1 | ||
1260 | rb->lcd_set_background(BG_COLOR); | ||
1261 | rb->lcd_set_foreground(FG_COLOR); | ||
1262 | #endif | ||
1263 | |||
1256 | /* don't resume by default */ | 1264 | /* don't resume by default */ |
1257 | bj->resume = false; | 1265 | bj->resume = false; |
1258 | 1266 | ||
@@ -1268,7 +1276,6 @@ static int blackjack(struct game_context* bj) { | |||
1268 | * init * | 1276 | * init * |
1269 | ********************/ | 1277 | ********************/ |
1270 | blackjack_init(bj); | 1278 | blackjack_init(bj); |
1271 | bj->current_bet=10; | ||
1272 | 1279 | ||
1273 | /******************** | 1280 | /******************** |
1274 | * play * | 1281 | * play * |
@@ -1279,21 +1286,21 @@ static int blackjack(struct game_context* bj) { | |||
1279 | bj->resume = false; | 1286 | bj->resume = false; |
1280 | redraw_board(bj); | 1287 | redraw_board(bj); |
1281 | if (bj->split_status == 2) { | 1288 | if (bj->split_status == 2) { |
1282 | todo=2; | 1289 | todo=2; |
1283 | player_x = bj->num_player_cards[0] * 10 + 4; | 1290 | player_x = bj->num_player_cards[0] * 10 + 4; |
1284 | } | 1291 | } |
1285 | else if (bj->split_status == 3) { | 1292 | else if (bj->split_status == 3) { |
1286 | player_x = bj->num_player_cards[1] * 10 + LCD_WIDTH/2 + 4; | 1293 | player_x = bj->num_player_cards[1] * 10 + LCD_WIDTH/2 + 4; |
1287 | todo=2; | 1294 | todo=2; |
1288 | done=1; | 1295 | done=1; |
1289 | } | 1296 | } |
1290 | |||
1291 | } | 1297 | } |
1292 | else { | 1298 | else { |
1293 | bj->player_money = 1000; | 1299 | bj->player_money = 1000; |
1300 | bj->current_bet = 10; | ||
1294 | blackjack_get_bet(bj); | 1301 | blackjack_get_bet(bj); |
1295 | if (bj->current_bet == 0) | 1302 | if (bj->current_bet == 0) |
1296 | return BJ_QUIT; | 1303 | return -1; |
1297 | rb->lcd_clear_display(); | 1304 | rb->lcd_clear_display(); |
1298 | deal_init_cards(bj); | 1305 | deal_init_cards(bj); |
1299 | blackjack_drawtable(bj); | 1306 | blackjack_drawtable(bj); |
@@ -1309,7 +1316,7 @@ static int blackjack(struct game_context* bj) { | |||
1309 | bj->end_hand = true; | 1316 | bj->end_hand = true; |
1310 | finish_game(bj); | 1317 | finish_game(bj); |
1311 | } | 1318 | } |
1312 | else if(bj->dealer_cards[1].is_soft_ace && !breakout && | 1319 | else if(bj->dealer_cards[1].is_soft_ace && !breakout && |
1313 | !bj->asked_insurance) { | 1320 | !bj->asked_insurance) { |
1314 | temp_var = insurance(bj); | 1321 | temp_var = insurance(bj); |
1315 | if (bj->dealer_total == 21) { | 1322 | if (bj->dealer_total == 21) { |
@@ -1328,7 +1335,7 @@ static int blackjack(struct game_context* bj) { | |||
1328 | rb->lcd_update(); | 1335 | rb->lcd_update(); |
1329 | } | 1336 | } |
1330 | } | 1337 | } |
1331 | if(!bj->end_hand && bj->split_status == 0 && | 1338 | if(!bj->end_hand && bj->split_status == 0 && |
1332 | bj->player_cards[0][0].num == bj->player_cards[0][1].num) { | 1339 | bj->player_cards[0][0].num == bj->player_cards[0][1].num) { |
1333 | split(bj); | 1340 | split(bj); |
1334 | redraw_board(bj); | 1341 | redraw_board(bj); |
@@ -1350,16 +1357,16 @@ static int blackjack(struct game_context* bj) { | |||
1350 | bj->num_player_cards[done]++; | 1357 | bj->num_player_cards[done]++; |
1351 | if (bj->num_player_cards[done] == MAX_CARDS + 1) { | 1358 | if (bj->num_player_cards[done] == MAX_CARDS + 1) { |
1352 | redraw_board(bj); | 1359 | redraw_board(bj); |
1353 | rb->lcd_update_rect(0, LCD_HEIGHT/2, LCD_WIDTH, | 1360 | rb->lcd_update_rect(0, LCD_HEIGHT/2, LCD_WIDTH, |
1354 | LCD_HEIGHT/2); | 1361 | LCD_HEIGHT/2); |
1355 | } | 1362 | } |
1356 | else if (bj->num_player_cards[done]>MAX_CARDS || todo > 1) { | 1363 | else if (bj->num_player_cards[done]>MAX_CARDS || todo > 1) { |
1357 | rb->lcd_update_rect(player_x, player_y, CARD_WIDTH+2, | 1364 | rb->lcd_update_rect(player_x, player_y, CARD_WIDTH+2, |
1358 | CARD_HEIGHT+2); | 1365 | CARD_HEIGHT+2); |
1359 | player_x += 10; | 1366 | player_x += 10; |
1360 | } | 1367 | } |
1361 | else { | 1368 | else { |
1362 | rb->lcd_update_rect(player_x, player_y, CARD_WIDTH+2, | 1369 | rb->lcd_update_rect(player_x, player_y, CARD_WIDTH+2, |
1363 | CARD_HEIGHT+2); | 1370 | CARD_HEIGHT+2); |
1364 | player_x += CARD_WIDTH + 4; | 1371 | player_x += CARD_WIDTH + 4; |
1365 | } | 1372 | } |
@@ -1370,7 +1377,8 @@ static int blackjack(struct game_context* bj) { | |||
1370 | bj->end_hand = true; | 1377 | bj->end_hand = true; |
1371 | break; | 1378 | break; |
1372 | case BJACK_DOUBLEDOWN: | 1379 | case BJACK_DOUBLEDOWN: |
1373 | if ((signed int)bj->current_bet * 2 < bj->player_money + 1&& | 1380 | if ((signed int)bj->current_bet * 2 < |
1381 | bj->player_money + 1 && | ||
1374 | bj->num_player_cards[0]==2 && todo==1) { | 1382 | bj->num_player_cards[0]==2 && todo==1) { |
1375 | double_down(bj); | 1383 | double_down(bj); |
1376 | dbl_down = true; | 1384 | dbl_down = true; |
@@ -1379,7 +1387,8 @@ static int blackjack(struct game_context* bj) { | |||
1379 | finish_game(bj); | 1387 | finish_game(bj); |
1380 | } | 1388 | } |
1381 | } | 1389 | } |
1382 | else if((signed int)bj->current_bet * 2 > bj->player_money){ | 1390 | else if((signed int)bj->current_bet * 2 > |
1391 | bj->player_money){ | ||
1383 | rb->splash(HZ, "Not enough money to double down."); | 1392 | rb->splash(HZ, "Not enough money to double down."); |
1384 | redraw_board(bj); | 1393 | redraw_board(bj); |
1385 | rb->lcd_update(); | 1394 | rb->lcd_update(); |
@@ -1395,7 +1404,7 @@ static int blackjack(struct game_context* bj) { | |||
1395 | } | 1404 | } |
1396 | 1405 | ||
1397 | while (bj->player_total > 21 && !bj->end_hand) { | 1406 | while (bj->player_total > 21 && !bj->end_hand) { |
1398 | temp = check_for_aces(bj->player_cards[done], | 1407 | temp = check_for_aces(bj->player_cards[done], |
1399 | bj->num_player_cards[done]); | 1408 | bj->num_player_cards[done]); |
1400 | if(temp != -1) { | 1409 | if(temp != -1) { |
1401 | bj->player_cards[done][temp].is_soft_ace = false; | 1410 | bj->player_cards[done][temp].is_soft_ace = false; |
@@ -1409,7 +1418,7 @@ static int blackjack(struct game_context* bj) { | |||
1409 | else | 1418 | else |
1410 | bj->end_hand = true; | 1419 | bj->end_hand = true; |
1411 | } | 1420 | } |
1412 | 1421 | ||
1413 | if (bj->end_hand) { | 1422 | if (bj->end_hand) { |
1414 | done++; | 1423 | done++; |
1415 | if(todo > 1) { | 1424 | if(todo > 1) { |
@@ -1426,7 +1435,7 @@ static int blackjack(struct game_context* bj) { | |||
1426 | bj->current_bet /= 2; | 1435 | bj->current_bet /= 2; |
1427 | rb->lcd_update_rect(LCD_WIDTH/2-w/2, LCD_HEIGHT/2-3*h/2, | 1436 | rb->lcd_update_rect(LCD_WIDTH/2-w/2, LCD_HEIGHT/2-3*h/2, |
1428 | w,h); | 1437 | w,h); |
1429 | rb->sleep(HZ*2); | 1438 | rb->sleep(HZ*2); |
1430 | bj->player_total = temp_var; | 1439 | bj->player_total = temp_var; |
1431 | finish_game(bj); | 1440 | finish_game(bj); |
1432 | rb->lcd_getstringsize(" Split 2 ", &w, &h); | 1441 | rb->lcd_getstringsize(" Split 2 ", &w, &h); |
@@ -1446,7 +1455,7 @@ static int blackjack(struct game_context* bj) { | |||
1446 | player_x += 10; | 1455 | player_x += 10; |
1447 | rb->lcd_update(); | 1456 | rb->lcd_update(); |
1448 | } | 1457 | } |
1449 | } | 1458 | } |
1450 | else | 1459 | else |
1451 | finish_game(bj); | 1460 | finish_game(bj); |
1452 | } | 1461 | } |
@@ -1462,7 +1471,11 @@ static int blackjack(struct game_context* bj) { | |||
1462 | return BJ_END; | 1471 | return BJ_END; |
1463 | else { /* User keeps playing */ | 1472 | else { /* User keeps playing */ |
1464 | breakout = false; | 1473 | breakout = false; |
1474 | temp = bj->current_bet; | ||
1475 | bj->current_bet = 0; | ||
1465 | redraw_board(bj); | 1476 | redraw_board(bj); |
1477 | rb->lcd_update(); | ||
1478 | bj->current_bet = temp; | ||
1466 | if(dbl_down) { | 1479 | if(dbl_down) { |
1467 | bj->current_bet /= 2; | 1480 | bj->current_bet /= 2; |
1468 | dbl_down = false; | 1481 | dbl_down = false; |
@@ -1477,7 +1490,7 @@ static int blackjack(struct game_context* bj) { | |||
1477 | blackjack_drawtable(bj); | 1490 | blackjack_drawtable(bj); |
1478 | rb->lcd_update(); | 1491 | rb->lcd_update(); |
1479 | } | 1492 | } |
1480 | } | 1493 | } |
1481 | } | 1494 | } |
1482 | /* Never reached */ | 1495 | /* Never reached */ |
1483 | return PLUGIN_OK; | 1496 | return PLUGIN_OK; |
@@ -1509,33 +1522,26 @@ enum plugin_status plugin_start(const void* parameter) | |||
1509 | /* fall through to BJ_END */ | 1522 | /* fall through to BJ_END */ |
1510 | 1523 | ||
1511 | case BJ_END: | 1524 | case BJ_END: |
1512 | if(!bj.resume) { | 1525 | if(!bj.resume && bj.player_money > 10) { |
1513 | /* There is no level, so store -1 to blank column */ | 1526 | /* There is no level, so store -1 to blank column */ |
1514 | int position = highscore_update(bj.player_money, -1, "", | 1527 | int position = highscore_update(bj.player_money, -1, "", |
1515 | highest, NUM_SCORES); | 1528 | highest, NUM_SCORES); |
1516 | if (position == 0) { | 1529 | if (position == 0) { |
1517 | rb->splash(HZ*2, "New High Score"); | 1530 | rb->splash(HZ*2, "New High Score"); |
1518 | } | 1531 | } |
1519 | if (position != -1) { | 1532 | if (position != -1) { |
1520 | highscore_show(position, highest, NUM_SCORES, false); | 1533 | highscore_show(position, highest, NUM_SCORES, false); |
1521 | bj.dirty=true; | ||
1522 | } else { | ||
1523 | rb->sleep(3); | ||
1524 | } | 1534 | } |
1525 | } | 1535 | } |
1526 | break; | 1536 | break; |
1527 | 1537 | ||
1528 | case BJ_USB: | 1538 | case BJ_USB: |
1529 | rb->lcd_setfont(FONT_UI); | 1539 | rb->lcd_setfont(FONT_UI); |
1530 | if(bj.dirty) { | 1540 | highscore_save(HIGH_SCORE,highest,NUM_SCORES); |
1531 | highscore_save(HIGH_SCORE,highest,NUM_SCORES); | ||
1532 | } | ||
1533 | return PLUGIN_USB_CONNECTED; | 1541 | return PLUGIN_USB_CONNECTED; |
1534 | 1542 | ||
1535 | case BJ_QUIT: | 1543 | case BJ_QUIT: |
1536 | if(bj.dirty) { | 1544 | highscore_save(HIGH_SCORE,highest,NUM_SCORES); |
1537 | highscore_save(HIGH_SCORE,highest,NUM_SCORES); | ||
1538 | } | ||
1539 | exit = true; | 1545 | exit = true; |
1540 | break; | 1546 | break; |
1541 | 1547 | ||
diff --git a/apps/plugins/bubbles.c b/apps/plugins/bubbles.c index d5d9987f68..ebf2051f1c 100644 --- a/apps/plugins/bubbles.c +++ b/apps/plugins/bubbles.c | |||
@@ -36,12 +36,13 @@ PLUGIN_HEADER | |||
36 | /* files */ | 36 | /* files */ |
37 | #define SCORE_FILE PLUGIN_GAMES_DIR "/bubbles.score" | 37 | #define SCORE_FILE PLUGIN_GAMES_DIR "/bubbles.score" |
38 | #define SAVE_FILE PLUGIN_GAMES_DIR "/bubbles.save" | 38 | #define SAVE_FILE PLUGIN_GAMES_DIR "/bubbles.save" |
39 | #define DATA_FILE PLUGIN_GAMES_DIR "/bubbles.data" | ||
39 | 40 | ||
40 | /* final game return status */ | 41 | /* final game return status */ |
41 | enum { | 42 | enum { |
42 | BB_LOSE, | 43 | BB_LOSE, |
43 | BB_QUIT, | 44 | BB_QUIT, |
44 | BB_QUIT_AND_SAVE, | 45 | BB_SAVE_AND_QUIT, |
45 | BB_USB, | 46 | BB_USB, |
46 | BB_END, | 47 | BB_END, |
47 | BB_WIN, | 48 | BB_WIN, |
@@ -1241,7 +1242,6 @@ struct tile { | |||
1241 | /* the game context struct | 1242 | /* the game context struct |
1242 | * score is the current score | 1243 | * score is the current score |
1243 | * level is the current level | 1244 | * level is the current level |
1244 | * highlevel is the highest level beaten | ||
1245 | * angle is the current cannon direction | 1245 | * angle is the current cannon direction |
1246 | * shots is the number of shots fired since last compression | 1246 | * shots is the number of shots fired since last compression |
1247 | * compress is the height of the compressor | 1247 | * compress is the height of the compressor |
@@ -1252,13 +1252,11 @@ struct tile { | |||
1252 | * elapsedlvl is level elapsed time in 1/100s of seconds | 1252 | * elapsedlvl is level elapsed time in 1/100s of seconds |
1253 | * elapsedshot is the shot elapsed time in 1/100s of seconds | 1253 | * elapsedshot is the shot elapsed time in 1/100s of seconds |
1254 | * startedshot is when the current shot began | 1254 | * startedshot is when the current shot began |
1255 | * resume denotes whether to resume the currently loaded game | ||
1256 | * playboard is the game playing board | 1255 | * playboard is the game playing board |
1257 | */ | 1256 | */ |
1258 | struct game_context { | 1257 | struct game_context { |
1259 | unsigned int score; | 1258 | unsigned int score; |
1260 | unsigned int level; | 1259 | unsigned int level; |
1261 | unsigned int highlevel; | ||
1262 | int angle; | 1260 | int angle; |
1263 | int shots; | 1261 | int shots; |
1264 | int compress; | 1262 | int compress; |
@@ -1276,6 +1274,8 @@ struct highscore highscores[NUM_SCORES]; | |||
1276 | 1274 | ||
1277 | /* used to denote available resume info */ | 1275 | /* used to denote available resume info */ |
1278 | static bool resume = false; | 1276 | static bool resume = false; |
1277 | static unsigned int highlevel = 0; /* the highest level beaten */ | ||
1278 | static unsigned int last_highlevel = 0; | ||
1279 | 1279 | ||
1280 | static void bubbles_init(struct game_context* bb); | 1280 | static void bubbles_init(struct game_context* bb); |
1281 | static bool bubbles_nextlevel(struct game_context* bb); | 1281 | static bool bubbles_nextlevel(struct game_context* bb); |
@@ -1291,7 +1291,6 @@ static void bubbles_anchored(struct game_context* bb, int row, int col); | |||
1291 | static int bubbles_fall(struct game_context* bb); | 1291 | static int bubbles_fall(struct game_context* bb); |
1292 | static int bubbles_checklevel(struct game_context* bb); | 1292 | static int bubbles_checklevel(struct game_context* bb); |
1293 | static void bubbles_recordscore(struct game_context* bb); | 1293 | static void bubbles_recordscore(struct game_context* bb); |
1294 | static void bubbles_savescores(struct game_context* bb); | ||
1295 | static bool bubbles_loadgame(struct game_context* bb); | 1294 | static bool bubbles_loadgame(struct game_context* bb); |
1296 | static void bubbles_savegame(struct game_context* bb); | 1295 | static void bubbles_savegame(struct game_context* bb); |
1297 | static inline void bubbles_setcolors(void); | 1296 | static inline void bubbles_setcolors(void); |
@@ -1326,15 +1325,14 @@ static void bubbles_init(struct game_context* bb) { | |||
1326 | static bool bubbles_nextlevel(struct game_context* bb) { | 1325 | static bool bubbles_nextlevel(struct game_context* bb) { |
1327 | int i, j, pos; | 1326 | int i, j, pos; |
1328 | 1327 | ||
1329 | /* save highest level */ | ||
1330 | if (bb->level > bb->highlevel) | ||
1331 | bb->highlevel = bb->level; | ||
1332 | |||
1333 | bb->level++; | 1328 | bb->level++; |
1334 | 1329 | ||
1335 | /* check if there are no more levels */ | 1330 | /* check if there are no more levels */ |
1336 | if(bb->level > NUM_LEVELS) return false; | 1331 | if(bb->level > NUM_LEVELS) return false; |
1337 | 1332 | ||
1333 | /* save highest level */ | ||
1334 | if (bb->level-1 > highlevel) | ||
1335 | highlevel = bb->level-1; | ||
1338 | 1336 | ||
1339 | /* set up the play board */ | 1337 | /* set up the play board */ |
1340 | rb->memset(bb->playboard, 0, sizeof(bb->playboard)); | 1338 | rb->memset(bb->playboard, 0, sizeof(bb->playboard)); |
@@ -2165,7 +2163,7 @@ static void bubbles_recordscore(struct game_context* bb) { | |||
2165 | 2163 | ||
2166 | int position; | 2164 | int position; |
2167 | 2165 | ||
2168 | position = highscore_update(bb->score, bb->level, "", | 2166 | position = highscore_update(bb->score, bb->level-1, "", |
2169 | highscores, NUM_SCORES); | 2167 | highscores, NUM_SCORES); |
2170 | if (position==0) | 2168 | if (position==0) |
2171 | rb->splash(HZ*2, "New High Score"); | 2169 | rb->splash(HZ*2, "New High Score"); |
@@ -2174,36 +2172,43 @@ static void bubbles_recordscore(struct game_context* bb) { | |||
2174 | } | 2172 | } |
2175 | 2173 | ||
2176 | /***************************************************************************** | 2174 | /***************************************************************************** |
2177 | * bubbles_loadscores() loads the high scores saved file. | 2175 | * bubbles_loaddata() loads highest level beaten. |
2178 | ******************************************************************************/ | 2176 | ******************************************************************************/ |
2179 | static void bubbles_loadscores(struct game_context* bb) { | 2177 | static void bubbles_loaddata(void) { |
2178 | int fd; | ||
2180 | 2179 | ||
2181 | int i; | 2180 | last_highlevel = highlevel = 0; |
2182 | int highlevel = 0; | 2181 | /* open data file */ |
2183 | /* highlevel and highscores */ | 2182 | fd = rb->open(DATA_FILE, O_RDONLY); |
2184 | highscore_load(SCORE_FILE, highscores, NUM_SCORES); | 2183 | if (fd < 0) return; |
2185 | 2184 | ||
2186 | /* level X in the high scores means one succeeded the level before (X-1) */ | 2185 | /* read in saved game */ |
2187 | for (i = 0; i < NUM_SCORES; i++) | 2186 | if (rb->read(fd, &highlevel, sizeof(highlevel)) < (long)sizeof(highlevel)) |
2188 | { | 2187 | { |
2189 | if (highscores[i].level-1 > highlevel) | 2188 | highlevel = 0; |
2190 | { | ||
2191 | highlevel = highscores[i].level-1; | ||
2192 | } | ||
2193 | } | 2189 | } |
2190 | if (highlevel >= NUM_LEVELS) | ||
2191 | highlevel = NUM_LEVELS-1; | ||
2192 | last_highlevel = highlevel; | ||
2194 | 2193 | ||
2195 | if (bb->highlevel < (unsigned)highlevel) | 2194 | rb->close(fd); |
2196 | bb->highlevel = highlevel; | ||
2197 | } | 2195 | } |
2198 | 2196 | ||
2199 | /***************************************************************************** | 2197 | /***************************************************************************** |
2200 | * bubbles_savescores() saves the high scores saved file. | 2198 | * bubbles_savedata() saves the current game state. |
2201 | ******************************************************************************/ | 2199 | ******************************************************************************/ |
2202 | static void bubbles_savescores(struct game_context* bb) { | 2200 | static void bubbles_savedata(void) { |
2201 | int fd; | ||
2203 | 2202 | ||
2204 | /* highscores */ | 2203 | if (last_highlevel >= highlevel) /* no need to save */ |
2205 | (void)bb; | 2204 | return; |
2206 | highscore_save(SCORE_FILE, highscores, NUM_SCORES+1); | 2205 | |
2206 | fd = rb->open(DATA_FILE, O_WRONLY|O_CREAT); | ||
2207 | if (fd < 0) return; | ||
2208 | |||
2209 | rb->write(fd, &highlevel, sizeof(highlevel)); | ||
2210 | |||
2211 | rb->close(fd); | ||
2207 | } | 2212 | } |
2208 | 2213 | ||
2209 | /***************************************************************************** | 2214 | /***************************************************************************** |
@@ -2225,6 +2230,9 @@ static bool bubbles_loadgame(struct game_context* bb) { | |||
2225 | } | 2230 | } |
2226 | 2231 | ||
2227 | rb->close(fd); | 2232 | rb->close(fd); |
2233 | |||
2234 | /* delete saved file */ | ||
2235 | rb->remove(SAVE_FILE); | ||
2228 | return ret; | 2236 | return ret; |
2229 | } | 2237 | } |
2230 | 2238 | ||
@@ -2266,8 +2274,8 @@ static inline void bubbles_setcolors(void) { | |||
2266 | * on usb connect and shutdown. | 2274 | * on usb connect and shutdown. |
2267 | ******************************************************************************/ | 2275 | ******************************************************************************/ |
2268 | static void bubbles_callback(void* param) { | 2276 | static void bubbles_callback(void* param) { |
2269 | struct game_context* bb = (struct game_context*) param; | 2277 | (void) param; |
2270 | bubbles_savescores(bb); | 2278 | highscore_save(SCORE_FILE, highscores, NUM_SCORES); |
2271 | } | 2279 | } |
2272 | 2280 | ||
2273 | /***************************************************************************** | 2281 | /***************************************************************************** |
@@ -2353,23 +2361,20 @@ static int bubbles_handlebuttons(struct game_context* bb, bool animblock, | |||
2353 | } | 2361 | } |
2354 | 2362 | ||
2355 | /***************************************************************************** | 2363 | /***************************************************************************** |
2356 | * bubbles() is the main game subroutine, it returns the final game status. | 2364 | * bubbles_menu() is the initial menu at the start of the game. |
2357 | ******************************************************************************/ | 2365 | ******************************************************************************/ |
2358 | static int bubbles(struct game_context* bb) { | 2366 | static int bubbles_menu(struct game_context* bb) { |
2359 | int buttonres; | 2367 | static unsigned int startlevel = 0; |
2360 | unsigned int startlevel = 0; | 2368 | int selected = resume?0:1; |
2361 | bool startgame = false; | 2369 | bool startgame = false; |
2362 | long timeout; | ||
2363 | 2370 | ||
2364 | /******************** | ||
2365 | * menu * | ||
2366 | ********************/ | ||
2367 | MENUITEM_STRINGLIST(menu,"Bubbles Menu",NULL, | 2371 | MENUITEM_STRINGLIST(menu,"Bubbles Menu",NULL, |
2368 | "Resume Game", "Start New Game", | 2372 | "Resume Game", "Start New Game", |
2369 | "Level", "High Scores", "Playback Control", | 2373 | "Level", "High Scores", "Playback Control", |
2370 | "Quit", "Quit and Save"); | 2374 | "Quit", "Save and Quit"); |
2375 | |||
2371 | while(!startgame){ | 2376 | while(!startgame){ |
2372 | switch (rb->do_menu(&menu, NULL, NULL, false)) | 2377 | switch (rb->do_menu(&menu, &selected, NULL, false)) |
2373 | { | 2378 | { |
2374 | case 0: /* resume game */ | 2379 | case 0: /* resume game */ |
2375 | if (!resume) | 2380 | if (!resume) |
@@ -2379,11 +2384,8 @@ static int bubbles(struct game_context* bb) { | |||
2379 | } | 2384 | } |
2380 | else | 2385 | else |
2381 | { | 2386 | { |
2382 | startlevel = bb->level - 1; | ||
2383 | startgame = true; | 2387 | startgame = true; |
2384 | } | 2388 | } |
2385 | /* delete saved file */ | ||
2386 | rb->remove(SAVE_FILE); | ||
2387 | break; | 2389 | break; |
2388 | case 1: /* new game */ | 2390 | case 1: /* new game */ |
2389 | bb->level = startlevel; | 2391 | bb->level = startlevel; |
@@ -2393,7 +2395,7 @@ static int bubbles(struct game_context* bb) { | |||
2393 | case 2: /* choose level */ | 2395 | case 2: /* choose level */ |
2394 | startlevel++; | 2396 | startlevel++; |
2395 | rb->set_int("Choose start level", "", UNIT_INT, &startlevel, | 2397 | rb->set_int("Choose start level", "", UNIT_INT, &startlevel, |
2396 | NULL, 1, 1, MIN(NUM_LEVELS,bb->highlevel+1), NULL); | 2398 | NULL, 1, 1, highlevel+1, NULL); |
2397 | startlevel--; | 2399 | startlevel--; |
2398 | break; | 2400 | break; |
2399 | case 3: /* High scores */ | 2401 | case 3: /* High scores */ |
@@ -2404,13 +2406,30 @@ static int bubbles(struct game_context* bb) { | |||
2404 | break; | 2406 | break; |
2405 | case 5: /* quit */ | 2407 | case 5: /* quit */ |
2406 | return BB_QUIT; | 2408 | return BB_QUIT; |
2407 | case 6: /* quit and save */ | 2409 | case 6: /* save and quit */ |
2408 | return BB_QUIT_AND_SAVE; | 2410 | return BB_SAVE_AND_QUIT; |
2409 | case MENU_ATTACHED_USB: | 2411 | case MENU_ATTACHED_USB: |
2410 | bubbles_callback(bb); | 2412 | bubbles_callback(bb); |
2411 | return BB_USB; | 2413 | return BB_USB; |
2412 | } | 2414 | } |
2413 | } | 2415 | } |
2416 | return 0; | ||
2417 | } | ||
2418 | |||
2419 | /***************************************************************************** | ||
2420 | * bubbles() is the main game subroutine, it returns the final game status. | ||
2421 | ******************************************************************************/ | ||
2422 | static int bubbles(struct game_context* bb) { | ||
2423 | int buttonres; | ||
2424 | long timeout; | ||
2425 | |||
2426 | /******************** | ||
2427 | * menu * | ||
2428 | ********************/ | ||
2429 | buttonres = bubbles_menu(bb); | ||
2430 | if(buttonres != 0) | ||
2431 | return buttonres; | ||
2432 | |||
2414 | /******************** | 2433 | /******************** |
2415 | * init * | 2434 | * init * |
2416 | ********************/ | 2435 | ********************/ |
@@ -2464,13 +2483,12 @@ enum plugin_status plugin_start(const void* parameter) { | |||
2464 | bool exit = false; | 2483 | bool exit = false; |
2465 | enum plugin_status ret = PLUGIN_OK; | 2484 | enum plugin_status ret = PLUGIN_OK; |
2466 | 2485 | ||
2467 | /* plugin init */ | ||
2468 | (void)parameter; | 2486 | (void)parameter; |
2469 | /* end of plugin init */ | ||
2470 | 2487 | ||
2471 | /* load files */ | 2488 | /* load files */ |
2472 | resume = bubbles_loadgame(&bb); | 2489 | resume = bubbles_loadgame(&bb); |
2473 | bubbles_loadscores(&bb); | 2490 | bubbles_loaddata(); |
2491 | highscore_load(SCORE_FILE, highscores, NUM_SCORES); | ||
2474 | rb->lcd_clear_display(); | 2492 | rb->lcd_clear_display(); |
2475 | 2493 | ||
2476 | /* start app */ | 2494 | /* start app */ |
@@ -2484,7 +2502,7 @@ enum plugin_status plugin_start(const void* parameter) { | |||
2484 | case BB_WIN: | 2502 | case BB_WIN: |
2485 | rb->splash(HZ*2, "You Win!"); | 2503 | rb->splash(HZ*2, "You Win!"); |
2486 | /* record high level */ | 2504 | /* record high level */ |
2487 | bb.highlevel = NUM_LEVELS; | 2505 | highlevel = NUM_LEVELS-1; |
2488 | /* record high score */ | 2506 | /* record high score */ |
2489 | bubbles_recordscore(&bb); | 2507 | bubbles_recordscore(&bb); |
2490 | break; | 2508 | break; |
@@ -2501,15 +2519,17 @@ enum plugin_status plugin_start(const void* parameter) { | |||
2501 | 2519 | ||
2502 | case BB_USB: | 2520 | case BB_USB: |
2503 | ret = PLUGIN_USB_CONNECTED; | 2521 | ret = PLUGIN_USB_CONNECTED; |
2522 | exit = true; | ||
2504 | break; | 2523 | break; |
2505 | 2524 | ||
2506 | case BB_QUIT_AND_SAVE: | 2525 | case BB_SAVE_AND_QUIT: |
2507 | rb->splash(HZ/2, "Saving Game and Scors"); | 2526 | rb->splash(HZ/2, "Saving Game ..."); |
2508 | bubbles_savescores(&bb); | ||
2509 | bubbles_savegame(&bb); | 2527 | bubbles_savegame(&bb); |
2510 | /* fall through */ | 2528 | /* fall through */ |
2511 | 2529 | ||
2512 | case BB_QUIT: | 2530 | case BB_QUIT: |
2531 | bubbles_savedata(); | ||
2532 | highscore_save(SCORE_FILE, highscores, NUM_SCORES); | ||
2513 | exit = true; | 2533 | exit = true; |
2514 | break; | 2534 | break; |
2515 | 2535 | ||
diff --git a/apps/plugins/calendar.c b/apps/plugins/calendar.c index 873a09b970..17116fe3e9 100644 --- a/apps/plugins/calendar.c +++ b/apps/plugins/calendar.c | |||
@@ -272,7 +272,7 @@ static int is_leap_year(int yr) | |||
272 | (!((yr) % 4) && ((yr) % 100)) || !((yr) % 400)) ? 1:0 ; | 272 | (!((yr) % 4) && ((yr) % 100)) || !((yr) % 400)) ? 1:0 ; |
273 | } | 273 | } |
274 | 274 | ||
275 | /* searches the weekday of the first day in month, | 275 | /* searches the weekday of the first day in month, |
276 | * relative to the given values */ | 276 | * relative to the given values */ |
277 | static int calc_weekday( struct shown *shown ) | 277 | static int calc_weekday( struct shown *shown ) |
278 | { | 278 | { |
@@ -343,19 +343,9 @@ static void draw_calendar(struct shown *shown) | |||
343 | int x,y,pos,days_per_month,j; | 343 | int x,y,pos,days_per_month,j; |
344 | char buffer[9]; | 344 | char buffer[9]; |
345 | const char *monthname[] = { | 345 | const char *monthname[] = { |
346 | "Jan", | 346 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
347 | "Feb", | 347 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" |
348 | "Mar", | 348 | }; |
349 | "Apr", | ||
350 | "May", | ||
351 | "Jun", | ||
352 | "Jul", | ||
353 | "Aug", | ||
354 | "Sep", | ||
355 | "Oct", | ||
356 | "Nov", | ||
357 | "Dec" | ||
358 | }; | ||
359 | if(use_system_font) | 349 | if(use_system_font) |
360 | rb->lcd_setfont(FONT_SYSFIXED); | 350 | rb->lcd_setfont(FONT_SYSFIXED); |
361 | rb->lcd_getstringsize("A",&w,&h); | 351 | rb->lcd_getstringsize("A",&w,&h); |
@@ -421,7 +411,7 @@ static int memos_in_shown_memory = 0; | |||
421 | 411 | ||
422 | static void load_memo(struct shown *shown) | 412 | static void load_memo(struct shown *shown) |
423 | { | 413 | { |
424 | int i, k, fp; | 414 | int k, fp; |
425 | bool exit = false; | 415 | bool exit = false; |
426 | char temp_memo1[2]; | 416 | char temp_memo1[2]; |
427 | char temp_memo2[3]; | 417 | char temp_memo2[3]; |
@@ -429,18 +419,6 @@ static void load_memo(struct shown *shown) | |||
429 | temp_memo1[1] = 0; | 419 | temp_memo1[1] = 0; |
430 | temp_memo2[2] = 0; | 420 | temp_memo2[2] = 0; |
431 | temp_memo4[4] = 0; | 421 | temp_memo4[4] = 0; |
432 | for (k = 0; k < memos_in_memory; k++) | ||
433 | { | ||
434 | memos[k].day = 0; | ||
435 | memos[k].month = 0; | ||
436 | memos[k].file_pointer_start = 0; | ||
437 | memos[k].file_pointer_end = 0; | ||
438 | memos[k].year = 0; | ||
439 | memos[k].type = 0; | ||
440 | memos[k].wday = 0; | ||
441 | for (i = 0; i < MAX_CHAR_MEMO_LEN; i++) | ||
442 | memos[k].message[i] = 0; | ||
443 | } | ||
444 | for (k = 1; k < 32; k++) | 422 | for (k = 1; k < 32; k++) |
445 | day_has_memo[k] = false; | 423 | day_has_memo[k] = false; |
446 | for (k = 0; k < 7; k++) | 424 | for (k = 0; k < 7; k++) |
@@ -449,12 +427,13 @@ static void load_memo(struct shown *shown) | |||
449 | fp = rb->open(ROCKBOX_DIR "/.memo",O_RDONLY); | 427 | fp = rb->open(ROCKBOX_DIR "/.memo",O_RDONLY); |
450 | if (fp > -1) | 428 | if (fp > -1) |
451 | { | 429 | { |
452 | int count = rb->filesize(fp); | ||
453 | rb->lseek(fp, 0, SEEK_SET); | 430 | rb->lseek(fp, 0, SEEK_SET); |
454 | while (!exit) | 431 | while (!exit) |
455 | { | 432 | { |
456 | memos[memos_in_memory].file_pointer_start = rb->lseek(fp, 0, | 433 | bool load_to_memory; |
457 | SEEK_CUR); | 434 | rb->memset(&memos[memos_in_memory].message, 0, MAX_CHAR_MEMO_LEN); |
435 | memos[memos_in_memory].file_pointer_start = | ||
436 | rb->lseek(fp, 0, SEEK_CUR); | ||
458 | if (rb->read(fp, temp_memo2, 2) == 2) | 437 | if (rb->read(fp, temp_memo2, 2) == 2) |
459 | memos[memos_in_memory].day = rb->atoi(&temp_memo2[0]); | 438 | memos[memos_in_memory].day = rb->atoi(&temp_memo2[0]); |
460 | else | 439 | else |
@@ -472,7 +451,7 @@ static void load_memo(struct shown *shown) | |||
472 | if (memos[memos_in_memory].year > (shown->year * 10)) | 451 | if (memos[memos_in_memory].year > (shown->year * 10)) |
473 | memos[memos_in_memory].year = (memos[memos_in_memory].year - | 452 | memos[memos_in_memory].year = (memos[memos_in_memory].year - |
474 | memos[memos_in_memory].month) / | 453 | memos[memos_in_memory].month) / |
475 | 100; | 454 | 100; |
476 | if (rb->read(fp, temp_memo1, 1) == 1) | 455 | if (rb->read(fp, temp_memo1, 1) == 1) |
477 | memos[memos_in_memory].wday = rb->atoi(&temp_memo1[0]); | 456 | memos[memos_in_memory].wday = rb->atoi(&temp_memo1[0]); |
478 | else | 457 | else |
@@ -481,48 +460,16 @@ static void load_memo(struct shown *shown) | |||
481 | memos[memos_in_memory].type = rb->atoi(&temp_memo1[0]); | 460 | memos[memos_in_memory].type = rb->atoi(&temp_memo1[0]); |
482 | else | 461 | else |
483 | memos[memos_in_memory].type = 0; | 462 | memos[memos_in_memory].type = 0; |
484 | for (k = 0; k <= count; k++) | 463 | load_to_memory = ((memos[memos_in_memory].type < 2) || |
464 | ((memos[memos_in_memory].type == 2) && | ||
465 | (memos[memos_in_memory].month == shown->mon)) || | ||
466 | ((memos[memos_in_memory].type > 2) && | ||
467 | (memos[memos_in_memory].month == shown->mon) && | ||
468 | (memos[memos_in_memory].year == shown->year))); | ||
469 | k = 0; | ||
470 | while (1) | ||
485 | { | 471 | { |
486 | if (rb->read(fp, temp_memo1, 1) == 1) | 472 | if (rb->read(fp, temp_memo1, 1) != 1) |
487 | { | ||
488 | if ( | ||
489 | (memos[memos_in_memory].type < 2) | ||
490 | || | ||
491 | ( | ||
492 | (memos[memos_in_memory].type == 2) | ||
493 | && | ||
494 | (memos[memos_in_memory].month == shown->mon) | ||
495 | ) | ||
496 | || | ||
497 | ( | ||
498 | (memos[memos_in_memory].type > 2) | ||
499 | && | ||
500 | (memos[memos_in_memory].month == shown->mon) | ||
501 | && | ||
502 | (memos[memos_in_memory].year == shown->year) | ||
503 | ) | ||
504 | ) | ||
505 | { | ||
506 | if (temp_memo1[0] == '\n') | ||
507 | { | ||
508 | if (memos[memos_in_memory].type > 0) | ||
509 | day_has_memo[memos[memos_in_memory].day] = | ||
510 | true; | ||
511 | else | ||
512 | wday_has_memo[memos[memos_in_memory].wday] = | ||
513 | true; | ||
514 | memos[memos_in_memory++].file_pointer_end = | ||
515 | rb->lseek(fp, 0, SEEK_CUR); | ||
516 | } | ||
517 | else if ( (temp_memo1[0] != '\r') && | ||
518 | (temp_memo1[0] != '\t') && | ||
519 | k < MAX_CHAR_MEMO_LEN-1 ) | ||
520 | memos[memos_in_memory].message[k] = temp_memo1[0]; | ||
521 | } | ||
522 | if (temp_memo1[0] == '\n') | ||
523 | break; | ||
524 | } | ||
525 | else | ||
526 | { | 473 | { |
527 | memos[memos_in_memory].day = 0; | 474 | memos[memos_in_memory].day = 0; |
528 | memos[memos_in_memory].month = 0; | 475 | memos[memos_in_memory].month = 0; |
@@ -535,6 +482,26 @@ static void load_memo(struct shown *shown) | |||
535 | exit = true; | 482 | exit = true; |
536 | break; | 483 | break; |
537 | } | 484 | } |
485 | if (load_to_memory) | ||
486 | { | ||
487 | if (temp_memo1[0] == '\n') | ||
488 | { | ||
489 | if (memos[memos_in_memory].type > 0) | ||
490 | day_has_memo[memos[memos_in_memory].day] = | ||
491 | true; | ||
492 | else | ||
493 | wday_has_memo[memos[memos_in_memory].wday] = | ||
494 | true; | ||
495 | memos[memos_in_memory++].file_pointer_end = | ||
496 | rb->lseek(fp, 0, SEEK_CUR); | ||
497 | } | ||
498 | else if ( (temp_memo1[0] != '\r') && | ||
499 | (temp_memo1[0] != '\t') && | ||
500 | k < MAX_CHAR_MEMO_LEN-1 ) | ||
501 | memos[memos_in_memory].message[k++] = temp_memo1[0]; | ||
502 | } | ||
503 | if (temp_memo1[0] == '\n') | ||
504 | break; | ||
538 | } | 505 | } |
539 | } | 506 | } |
540 | } | 507 | } |
@@ -546,7 +513,7 @@ static bool save_memo(int changed, bool new_mod, struct shown *shown) | |||
546 | int fp,fq; | 513 | int fp,fq; |
547 | fp = rb->open(ROCKBOX_DIR "/.memo",O_RDONLY | O_CREAT); | 514 | fp = rb->open(ROCKBOX_DIR "/.memo",O_RDONLY | O_CREAT); |
548 | fq = rb->creat(ROCKBOX_DIR "/~temp"); | 515 | fq = rb->creat(ROCKBOX_DIR "/~temp"); |
549 | if ( (fq != -1) && (fp != -1) ) | 516 | if ( (fq > -1) && (fp > -1) ) |
550 | { | 517 | { |
551 | int i; | 518 | int i; |
552 | char temp[MAX_CHAR_MEMO_LEN]; | 519 | char temp[MAX_CHAR_MEMO_LEN]; |
@@ -578,9 +545,9 @@ static bool save_memo(int changed, bool new_mod, struct shown *shown) | |||
578 | load_memo(shown); | 545 | load_memo(shown); |
579 | return true; | 546 | return true; |
580 | } | 547 | } |
581 | else if (fp != -1) | 548 | else if (fp > -1) |
582 | rb->close(fp); | 549 | rb->close(fp); |
583 | else if (fq != -1) | 550 | else if (fq > -1) |
584 | rb->close(fq); | 551 | rb->close(fq); |
585 | return false; | 552 | return false; |
586 | } | 553 | } |
@@ -714,7 +681,7 @@ static bool view_events(int selected, struct shown *shown) | |||
714 | rb->gui_synclist_set_nb_items(&gui_memos, memos_in_shown_memory); | 681 | rb->gui_synclist_set_nb_items(&gui_memos, memos_in_shown_memory); |
715 | rb->gui_synclist_select_item(&gui_memos, selected); | 682 | rb->gui_synclist_select_item(&gui_memos, selected); |
716 | rb->gui_synclist_draw(&gui_memos); | 683 | rb->gui_synclist_draw(&gui_memos); |
717 | 684 | ||
718 | while (!exit) | 685 | while (!exit) |
719 | { | 686 | { |
720 | button = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK); | 687 | button = rb->get_action(CONTEXT_LIST,TIMEOUT_BLOCK); |
@@ -746,19 +713,10 @@ static void update_memos_shown(struct shown *shown) | |||
746 | int i; | 713 | int i; |
747 | memos_in_shown_memory = 0; | 714 | memos_in_shown_memory = 0; |
748 | for (i = 0; i < memos_in_memory; i++) | 715 | for (i = 0; i < memos_in_memory; i++) |
749 | if ( | 716 | if (((memos[i].type >= 1) && |
750 | ( | 717 | (memos[i].day == shown->mday)) || |
751 | (memos[i].type >= 1) | 718 | ((memos[i].type < 1) && |
752 | && | 719 | (memos[i].wday == shown->wday))) |
753 | (memos[i].day == shown->mday) | ||
754 | ) | ||
755 | || | ||
756 | ( | ||
757 | (memos[i].type < 1) | ||
758 | && | ||
759 | (memos[i].wday == shown->wday) | ||
760 | ) | ||
761 | ) | ||
762 | pointer_array[memos_in_shown_memory++] = i; | 720 | pointer_array[memos_in_shown_memory++] = i; |
763 | } | 721 | } |
764 | 722 | ||
@@ -836,7 +794,7 @@ enum plugin_status plugin_start(const void* parameter) | |||
836 | struct shown shown; | 794 | struct shown shown; |
837 | bool exit = false; | 795 | bool exit = false; |
838 | int button; | 796 | int button; |
839 | 797 | ||
840 | (void)(parameter); | 798 | (void)(parameter); |
841 | 799 | ||
842 | calendar_init(&today, &shown); | 800 | calendar_init(&today, &shown); |
diff --git a/apps/plugins/clix.c b/apps/plugins/clix.c index 26a979ac54..2b5b7febeb 100644 --- a/apps/plugins/clix.c +++ b/apps/plugins/clix.c | |||
@@ -605,7 +605,7 @@ static int clix_menu(struct clix_game_state_t* state, bool ingame) | |||
605 | "Resume Game", | 605 | "Resume Game", |
606 | "Start New Game", | 606 | "Start New Game", |
607 | "Help", | 607 | "Help", |
608 | "High Score", | 608 | "High Scores", |
609 | "Playback Control", | 609 | "Playback Control", |
610 | "Quit"); | 610 | "Quit"); |
611 | 611 | ||
diff --git a/apps/plugins/jewels.c b/apps/plugins/jewels.c index 0393a502f0..71cd093963 100644 --- a/apps/plugins/jewels.c +++ b/apps/plugins/jewels.c | |||
@@ -1323,7 +1323,7 @@ static int jewels_game_menu(struct game_context* bj, bool ingame) | |||
1323 | "Start New Game", | 1323 | "Start New Game", |
1324 | "Mode", | 1324 | "Mode", |
1325 | "Help", | 1325 | "Help", |
1326 | "High Score", | 1326 | "High Scores", |
1327 | "Playback Control", | 1327 | "Playback Control", |
1328 | "Quit without Saving", | 1328 | "Quit without Saving", |
1329 | "Quit"); | 1329 | "Quit"); |
diff --git a/apps/plugins/lib/highscore.c b/apps/plugins/lib/highscore.c index 280c0c7724..20e472f9dc 100644 --- a/apps/plugins/lib/highscore.c +++ b/apps/plugins/lib/highscore.c | |||
@@ -129,7 +129,6 @@ void highscore_show(int position, struct highscore *scores, int num_scores, bool | |||
129 | rb->lcd_set_background(LCD_BLACK); | 129 | rb->lcd_set_background(LCD_BLACK); |
130 | rb->lcd_set_foreground(LCD_WHITE); | 130 | rb->lcd_set_foreground(LCD_WHITE); |
131 | #endif | 131 | #endif |
132 | rb->button_clear_queue(); | ||
133 | rb->lcd_clear_display(); | 132 | rb->lcd_clear_display(); |
134 | 133 | ||
135 | rb->lcd_setfont(FONT_UI); | 134 | rb->lcd_setfont(FONT_UI); |
@@ -174,6 +173,8 @@ void highscore_show(int position, struct highscore *scores, int num_scores, bool | |||
174 | } | 173 | } |
175 | } | 174 | } |
176 | rb->lcd_update(); | 175 | rb->lcd_update(); |
176 | rb->sleep(HZ/2); | ||
177 | rb->button_clear_queue(); | ||
177 | rb->button_get(true); | 178 | rb->button_get(true); |
178 | rb->lcd_setfont(FONT_SYSFIXED); | 179 | rb->lcd_setfont(FONT_SYSFIXED); |
179 | } | 180 | } |
diff --git a/apps/plugins/rocklife.c b/apps/plugins/rocklife.c index 8a1a1b35f2..5258121ea3 100644 --- a/apps/plugins/rocklife.c +++ b/apps/plugins/rocklife.c | |||
@@ -77,7 +77,7 @@ PLUGIN_HEADER | |||
77 | #define PATTERN_GROWTH_1 1 | 77 | #define PATTERN_GROWTH_1 1 |
78 | #define PATTERN_GROWTH_2 2 | 78 | #define PATTERN_GROWTH_2 2 |
79 | #define PATTERN_ACORN 3 | 79 | #define PATTERN_ACORN 3 |
80 | #define PATTERN_GLIDER_GUN 4 /* not yet implemented */ | 80 | #define PATTERN_GLIDER_GUN 4 |
81 | 81 | ||
82 | const struct button_mapping *plugin_contexts[] | 82 | const struct button_mapping *plugin_contexts[] |
83 | = {generic_directions, generic_actions}; | 83 | = {generic_directions, generic_actions}; |
diff --git a/apps/plugins/spacerocks.c b/apps/plugins/spacerocks.c index 32d48862ae..2e383c0d0d 100644 --- a/apps/plugins/spacerocks.c +++ b/apps/plugins/spacerocks.c | |||
@@ -644,7 +644,7 @@ static int spacerocks_menu(bool ingame) | |||
644 | "Resume Game", | 644 | "Resume Game", |
645 | "Start New Game", | 645 | "Start New Game", |
646 | "Help", | 646 | "Help", |
647 | "High Score", | 647 | "High Scores", |
648 | "Playback Control", | 648 | "Playback Control", |
649 | "Quit"); | 649 | "Quit"); |
650 | 650 | ||
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; |