diff options
author | Teruaki Kawashima <teru@rockbox.org> | 2009-08-02 14:30:09 +0000 |
---|---|---|
committer | Teruaki Kawashima <teru@rockbox.org> | 2009-08-02 14:30:09 +0000 |
commit | ece0b227a4d5dbb3d6d71aca647d9f4236136392 (patch) | |
tree | 83d785b41949c2b6c347713beca931c38baaffed /apps/plugins | |
parent | e3f7184e608c15e2af7d73e6d18f38a9a3c2cf9c (diff) | |
download | rockbox-ece0b227a4d5dbb3d6d71aca647d9f4236136392.tar.gz rockbox-ece0b227a4d5dbb3d6d71aca647d9f4236136392.zip |
Superdom: introduce new enum for value to be returned in many places instead of mix of PLUGIN_USB_CONNECTED and numbers.
improve number input screen. check size of labels and use sysfont if they are too large. put them at center of each box.
use simplelist to show inventory(part of FS #7593).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22113 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/superdom.c | 594 |
1 files changed, 268 insertions, 326 deletions
diff --git a/apps/plugins/superdom.c b/apps/plugins/superdom.c index 3e1e23785a..6673810e29 100644 --- a/apps/plugins/superdom.c +++ b/apps/plugins/superdom.c | |||
@@ -165,16 +165,18 @@ char buf[255]; | |||
165 | #endif | 165 | #endif |
166 | #endif | 166 | #endif |
167 | 167 | ||
168 | #define SUPERDOM_QUIT 23 | 168 | enum { |
169 | RET_VAL_OK, | ||
170 | RET_VAL_USB, | ||
171 | RET_VAL_QUIT_ERR, /* quit or error */ | ||
172 | }; | ||
169 | 173 | ||
170 | void gen_interest(void); | 174 | void gen_interest(void); |
171 | int production_menu(void); | ||
172 | void init_resources(void); | 175 | void init_resources(void); |
173 | int select_square(void); | 176 | int select_square(void); |
174 | void update_score(void); | 177 | void update_score(void); |
175 | void gen_resources(void); | 178 | void gen_resources(void); |
176 | void draw_cursor(void); | 179 | void draw_cursor(void); |
177 | int calc_strength(int colour, int x, int y); | ||
178 | void draw_board(void); | 180 | void draw_board(void); |
179 | 181 | ||
180 | struct tile{ | 182 | struct tile{ |
@@ -352,7 +354,7 @@ void draw_board(void) { | |||
352 | ICON_WIDTH, ICON_HEIGHT); | 354 | ICON_WIDTH, ICON_HEIGHT); |
353 | } | 355 | } |
354 | #if LCD_DEPTH != 16 | 356 | #if LCD_DEPTH != 16 |
355 | rb->lcd_set_drawmode(DRMODE_SOLID); | 357 | rb->lcd_set_drawmode(DRMODE_SOLID); |
356 | #endif | 358 | #endif |
357 | } | 359 | } |
358 | } | 360 | } |
@@ -483,17 +485,16 @@ void update_score(void) { | |||
483 | rb->lcd_setfont(FONT_UI); | 485 | rb->lcd_setfont(FONT_UI); |
484 | } | 486 | } |
485 | 487 | ||
486 | int settings_menu_function(void) { | 488 | int settings_menu(void) { |
487 | int selection = 0; | 489 | int selection = 0; |
488 | 490 | ||
489 | MENUITEM_STRINGLIST(settings_menu,"Super Domination Settings",NULL, | 491 | MENUITEM_STRINGLIST(menu, "Super Domination Settings", NULL, |
490 | "Computer starting farms","Computer starting factories", | 492 | "Computer starting farms", "Computer starting factories", |
491 | "Human starting farms","Human starting factories", | 493 | "Human starting farms", "Human starting factories", |
492 | "Starting cash","Starting food","Moves per turn"); | 494 | "Starting cash", "Starting food", "Moves per turn"); |
493 | 495 | ||
494 | while(1) { | 496 | while(1) { |
495 | selection=rb->do_menu(&settings_menu,&selection, NULL, false); | 497 | switch(rb->do_menu(&menu, &selection, NULL, false)) { |
496 | switch(selection) { | ||
497 | case 0: | 498 | case 0: |
498 | rb->set_int("Computer starting farms", "", UNIT_INT, | 499 | rb->set_int("Computer starting farms", "", UNIT_INT, |
499 | &superdom_settings.compstartfarms, NULL, | 500 | &superdom_settings.compstartfarms, NULL, |
@@ -511,8 +512,8 @@ int settings_menu_function(void) { | |||
511 | break; | 512 | break; |
512 | case 3: | 513 | case 3: |
513 | rb->set_int("Human starting factories", "", UNIT_INT, | 514 | rb->set_int("Human starting factories", "", UNIT_INT, |
514 | &superdom_settings.humanstartinds, NULL, | 515 | &superdom_settings.humanstartinds, NULL, |
515 | 1, 0, 5, NULL); | 516 | 1, 0, 5, NULL); |
516 | break; | 517 | break; |
517 | case 4: | 518 | case 4: |
518 | rb->set_int("Starting cash", "", UNIT_INT, | 519 | rb->set_int("Starting cash", "", UNIT_INT, |
@@ -530,17 +531,17 @@ int settings_menu_function(void) { | |||
530 | 1, 1, 5, NULL); | 531 | 1, 1, 5, NULL); |
531 | break; | 532 | break; |
532 | case MENU_ATTACHED_USB: | 533 | case MENU_ATTACHED_USB: |
533 | return PLUGIN_USB_CONNECTED; | 534 | return RET_VAL_USB; |
534 | break; | 535 | break; |
535 | case GO_TO_PREVIOUS: | 536 | case GO_TO_PREVIOUS: |
536 | return 0; | 537 | return RET_VAL_OK; |
537 | break; | 538 | break; |
538 | } | 539 | } |
539 | } | 540 | } |
540 | return 0; | 541 | return RET_VAL_OK; |
541 | } | 542 | } |
542 | 543 | ||
543 | static int do_help(void) { | 544 | static int superdom_help(void) { |
544 | int button; | 545 | int button; |
545 | #define WORDS (sizeof help_text / sizeof (char*)) | 546 | #define WORDS (sizeof help_text / sizeof (char*)) |
546 | static char* help_text[] = { | 547 | static char* help_text[] = { |
@@ -557,44 +558,47 @@ static int do_help(void) { | |||
557 | }; | 558 | }; |
558 | 559 | ||
559 | if (display_text(WORDS, help_text, NULL, NULL)) | 560 | if (display_text(WORDS, help_text, NULL, NULL)) |
560 | return PLUGIN_USB_CONNECTED; | 561 | return RET_VAL_USB; |
561 | do { | 562 | do { |
562 | button = rb->button_get(true); | 563 | button = rb->button_get(true); |
563 | if ( rb->default_event_handler( button ) == SYS_USB_CONNECTED ) | 564 | if ( rb->default_event_handler( button ) == SYS_USB_CONNECTED ) |
564 | return PLUGIN_USB_CONNECTED; | 565 | return RET_VAL_USB; |
565 | } while( ( button == BUTTON_NONE ) | 566 | } while( ( button == BUTTON_NONE ) |
566 | || ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); | 567 | || ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); |
567 | 568 | ||
568 | return PLUGIN_OK; | 569 | return RET_VAL_OK; |
569 | } | 570 | } |
570 | 571 | ||
571 | int menu(void) { | 572 | int start_menu(void) { |
572 | int selection = 0; | 573 | int selection = 0; |
573 | 574 | ||
574 | MENUITEM_STRINGLIST(main_menu,"Super Domination Menu",NULL, | 575 | MENUITEM_STRINGLIST(menu, "Super Domination Menu", NULL, |
575 | "Play Super Domination","Settings","Help","Quit"); | 576 | "Play Super Domination", "Settings", |
577 | "Help", "Playback Control", "Quit"); | ||
576 | 578 | ||
577 | while(1) { | 579 | while(1) { |
578 | selection=rb->do_menu(&main_menu,&selection, NULL, false); | 580 | switch(rb->do_menu(&menu, &selection, NULL, false)) { |
579 | switch(selection) { | ||
580 | case 0: | 581 | case 0: |
581 | return 0; /* start playing */ | 582 | return RET_VAL_OK; /* start playing */ |
582 | break; | 583 | break; |
583 | case 1: | 584 | case 1: |
584 | if(settings_menu_function()==PLUGIN_USB_CONNECTED) | 585 | if(settings_menu()==RET_VAL_USB) |
585 | return PLUGIN_USB_CONNECTED; | 586 | return RET_VAL_USB; |
586 | break; | 587 | break; |
587 | case 2: | 588 | case 2: |
588 | if(do_help()==PLUGIN_USB_CONNECTED) | 589 | if(superdom_help()==RET_VAL_USB) |
589 | return PLUGIN_USB_CONNECTED; | 590 | return RET_VAL_USB; |
591 | break; | ||
592 | case 3: | ||
593 | if(playback_control(NULL)) | ||
594 | return RET_VAL_USB; | ||
590 | break; | 595 | break; |
591 | default: | 596 | default: |
592 | return 2; /* quit program */ | 597 | return RET_VAL_QUIT_ERR; |
593 | break; | 598 | break; |
594 | } | 599 | } |
595 | } | 600 | } |
596 | 601 | return RET_VAL_QUIT_ERR; | |
597 | return 3; | ||
598 | } | 602 | } |
599 | 603 | ||
600 | int save_game(void) { | 604 | int save_game(void) { |
@@ -613,7 +617,7 @@ int save_game(void) { | |||
613 | DEBUGF("Couldn't create/open file\n"); | 617 | DEBUGF("Couldn't create/open file\n"); |
614 | return -1; | 618 | return -1; |
615 | } | 619 | } |
616 | 620 | ||
617 | rb->write(fd, "SSGv3", 5); | 621 | rb->write(fd, "SSGv3", 5); |
618 | rb->write(fd, &gamestate, sizeof(gamestate)); | 622 | rb->write(fd, &gamestate, sizeof(gamestate)); |
619 | rb->write(fd, &humanres.cash, sizeof(humanres.cash)); | 623 | rb->write(fd, &humanres.cash, sizeof(humanres.cash)); |
@@ -649,15 +653,13 @@ int save_game(void) { | |||
649 | } | 653 | } |
650 | 654 | ||
651 | int ingame_menu(void) { | 655 | int ingame_menu(void) { |
652 | int selection = 0; | 656 | MENUITEM_STRINGLIST(menu, "Super Domination Menu", NULL, |
653 | 657 | "Return to game", "Save Game", | |
654 | MENUITEM_STRINGLIST(ingame_menu,"Super Domination Menu",NULL, | 658 | "Playback Control", "Quit"); |
655 | "Return to game","Save Game","Playback Control", "Quit"); | ||
656 | 659 | ||
657 | selection=rb->do_menu(&ingame_menu,&selection, NULL, false); | 660 | switch(rb->do_menu(&menu, NULL, NULL, false)) { |
658 | switch(selection) { | ||
659 | case 0: | 661 | case 0: |
660 | return 0; | 662 | return RET_VAL_OK; |
661 | break; | 663 | break; |
662 | case 1: | 664 | case 1: |
663 | if(!save_game()) | 665 | if(!save_game()) |
@@ -666,37 +668,36 @@ int ingame_menu(void) { | |||
666 | rb->splash(HZ, "Error in save"); | 668 | rb->splash(HZ, "Error in save"); |
667 | break; | 669 | break; |
668 | case 2: | 670 | case 2: |
669 | playback_control(NULL); | 671 | if(playback_control(NULL)) |
672 | return RET_VAL_USB; | ||
670 | break; | 673 | break; |
671 | case 3: | 674 | case 3: |
672 | return SUPERDOM_QUIT; | 675 | return RET_VAL_QUIT_ERR; |
673 | break; | 676 | break; |
674 | case MENU_ATTACHED_USB: | 677 | case MENU_ATTACHED_USB: |
675 | return PLUGIN_USB_CONNECTED; | 678 | return RET_VAL_USB; |
676 | break; | 679 | break; |
677 | case GO_TO_PREVIOUS: | 680 | case GO_TO_PREVIOUS: |
678 | return 0; | 681 | return RET_VAL_OK; |
679 | break; | 682 | break; |
680 | } | 683 | } |
681 | return 0; | 684 | return RET_VAL_OK; |
682 | } | 685 | } |
683 | 686 | ||
684 | int get_number(char* param, int* value) { | 687 | int get_number(char* param, int* value) { |
685 | //int numbers[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; | 688 | static const char *button_labels[4][3] = { |
686 | int numbers[3][3]; | 689 | { "1", "2", "3" }, |
690 | { "4", "5", "6" }, | ||
691 | { "7", "8", "9" }, | ||
692 | { "CLR", "0", "OK" } | ||
693 | }; | ||
687 | int i,j,x=0,y=0; | 694 | int i,j,x=0,y=0; |
688 | int height, width; | 695 | int height, width; |
689 | int button = 0; | 696 | int button = 0; |
690 | numbers[0][0] = 1; | ||
691 | numbers[0][1] = 2; | ||
692 | numbers[0][2] = 3; | ||
693 | numbers[1][0] = 4; | ||
694 | numbers[1][1] = 5; | ||
695 | numbers[1][2] = 6; | ||
696 | numbers[2][0] = 7; | ||
697 | numbers[2][1] = 8; | ||
698 | numbers[2][2] = 9; | ||
699 | rb->lcd_clear_display(); | 697 | rb->lcd_clear_display(); |
698 | rb->lcd_getstringsize("CLR", &width, &height); | ||
699 | if(width > NUM_BOX_WIDTH || height > NUM_BOX_HEIGHT) | ||
700 | rb->lcd_setfont(FONT_SYSFIXED); | ||
700 | /* Draw a 3x4 grid */ | 701 | /* Draw a 3x4 grid */ |
701 | for(i=0;i<=3;i++) { /* Vertical lines */ | 702 | for(i=0;i<=3;i++) { /* Vertical lines */ |
702 | rb->lcd_vline(NUM_MARGIN_X+(NUM_BOX_WIDTH*i), NUM_MARGIN_Y, | 703 | rb->lcd_vline(NUM_MARGIN_X+(NUM_BOX_WIDTH*i), NUM_MARGIN_Y, |
@@ -706,41 +707,47 @@ int get_number(char* param, int* value) { | |||
706 | rb->lcd_hline(NUM_MARGIN_X, NUM_MARGIN_X+(3*NUM_BOX_WIDTH), | 707 | rb->lcd_hline(NUM_MARGIN_X, NUM_MARGIN_X+(3*NUM_BOX_WIDTH), |
707 | NUM_MARGIN_Y+(NUM_BOX_HEIGHT*i)); | 708 | NUM_MARGIN_Y+(NUM_BOX_HEIGHT*i)); |
708 | } | 709 | } |
709 | for(i=0;i<3;i++) { | 710 | for(i=0;i<4;i++) { |
710 | for(j=0;j<3;j++) { | 711 | for(j=0;j<3;j++) { |
711 | rb->snprintf(buf, sizeof(buf), "%d", numbers[i][j]); | 712 | rb->lcd_getstringsize(button_labels[i][j], &width, &height); |
712 | rb->lcd_putsxy(NUM_MARGIN_X+(j*NUM_BOX_WIDTH)+10, | 713 | rb->lcd_putsxy( |
713 | NUM_MARGIN_Y+(i*NUM_BOX_HEIGHT)+8, buf); | 714 | NUM_MARGIN_X+(j*NUM_BOX_WIDTH)+NUM_BOX_WIDTH/2-width/2, |
715 | NUM_MARGIN_Y+(i*NUM_BOX_HEIGHT)+NUM_BOX_HEIGHT/2-height/2, | ||
716 | button_labels[i][j]); | ||
714 | } | 717 | } |
715 | } | 718 | } |
716 | rb->lcd_putsxy(NUM_MARGIN_X+5, NUM_MARGIN_Y+(3*NUM_BOX_HEIGHT)+8, "CLR"); | ||
717 | rb->lcd_putsxy(NUM_MARGIN_X+NUM_BOX_WIDTH+10, | ||
718 | NUM_MARGIN_Y+(3*NUM_BOX_HEIGHT)+8, "0"); | ||
719 | rb->lcd_putsxy(NUM_MARGIN_X+2*NUM_BOX_WIDTH+8, | ||
720 | NUM_MARGIN_Y+(3*NUM_BOX_HEIGHT)+8, "OK"); | ||
721 | rb->snprintf(buf,sizeof(buf), "%d", *value); | 719 | rb->snprintf(buf,sizeof(buf), "%d", *value); |
722 | rb->lcd_putsxy(NUM_MARGIN_X+10, NUM_MARGIN_Y+4*NUM_BOX_HEIGHT+10, buf); | 720 | rb->lcd_putsxy(NUM_MARGIN_X+10, NUM_MARGIN_Y+4*NUM_BOX_HEIGHT+10, buf); |
723 | rb->lcd_getstringsize(param, &width, &height); | 721 | rb->lcd_getstringsize(param, &width, &height); |
724 | rb->lcd_putsxy((LCD_WIDTH-width)/2, (NUM_MARGIN_Y-height)/2, param); | 722 | if(width < LCD_WIDTH) |
723 | rb->lcd_putsxy((LCD_WIDTH-width)/2, (NUM_MARGIN_Y-height)/2, param); | ||
724 | else | ||
725 | rb->lcd_puts_scroll(0, (NUM_MARGIN_Y/height-1)/2, param); | ||
725 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); | 726 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); |
726 | rb->lcd_fillrect(NUM_MARGIN_X+(NUM_BOX_WIDTH*x), | 727 | rb->lcd_fillrect(NUM_MARGIN_X+(NUM_BOX_WIDTH*x), |
727 | NUM_MARGIN_Y+(NUM_BOX_HEIGHT*y), NUM_BOX_WIDTH+1, | 728 | NUM_MARGIN_Y+(NUM_BOX_HEIGHT*y), |
728 | NUM_BOX_HEIGHT+1); | 729 | NUM_BOX_WIDTH+1, NUM_BOX_HEIGHT+1); |
729 | rb->lcd_set_drawmode(DRMODE_SOLID); | 730 | rb->lcd_set_drawmode(DRMODE_SOLID); |
730 | rb->lcd_update(); | 731 | rb->lcd_update(); |
731 | while(1) { | 732 | while(1) { |
732 | button = rb->button_get(true); | 733 | button = rb->button_get(true); |
734 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); | ||
735 | rb->lcd_fillrect(NUM_MARGIN_X+(NUM_BOX_WIDTH*x), | ||
736 | NUM_MARGIN_Y+(NUM_BOX_HEIGHT*y), | ||
737 | NUM_BOX_WIDTH+1, NUM_BOX_HEIGHT+1); | ||
738 | rb->lcd_set_drawmode(DRMODE_SOLID); | ||
733 | switch(button) { | 739 | switch(button) { |
734 | case SUPERDOM_OK: | 740 | case SUPERDOM_OK: |
735 | if(y!=3) { | 741 | if(y!=3) { |
736 | *value *= 10; | 742 | *value *= 10; |
737 | *value += numbers[y][x]; | 743 | *value += button_labels[y][x][0] - '0'; |
738 | } else if(x==0) { | 744 | } else if(x==0) { |
739 | *value /= 10; | 745 | *value /= 10; |
740 | } else if(x==1) { | 746 | } else if(x==1) { |
741 | *value *= 10; | 747 | *value *= 10; |
742 | } else if(x==2) { | 748 | } else if(x==2) { |
743 | return 0; | 749 | rb->lcd_setfont(FONT_UI); |
750 | return RET_VAL_OK; | ||
744 | } | 751 | } |
745 | rb->lcd_set_drawmode(DRMODE_BG|DRMODE_INVERSEVID); | 752 | rb->lcd_set_drawmode(DRMODE_BG|DRMODE_INVERSEVID); |
746 | rb->lcd_fillrect(0, NUM_MARGIN_Y+4*NUM_BOX_HEIGHT+10, | 753 | rb->lcd_fillrect(0, NUM_MARGIN_Y+4*NUM_BOX_HEIGHT+10, |
@@ -752,16 +759,12 @@ int get_number(char* param, int* value) { | |||
752 | break; | 759 | break; |
753 | case SUPERDOM_CANCEL: | 760 | case SUPERDOM_CANCEL: |
754 | *value = 0; | 761 | *value = 0; |
762 | rb->lcd_setfont(FONT_UI); | ||
755 | rb->splash(HZ, "Cancelled"); | 763 | rb->splash(HZ, "Cancelled"); |
756 | return 2; | 764 | return RET_VAL_QUIT_ERR; |
757 | break; | 765 | break; |
758 | #if CONFIG_KEYPAD != IRIVER_H10_PAD | 766 | #if CONFIG_KEYPAD != IRIVER_H10_PAD |
759 | case SUPERDOM_LEFT: | 767 | case SUPERDOM_LEFT: |
760 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); | ||
761 | rb->lcd_fillrect(NUM_MARGIN_X+(NUM_BOX_WIDTH*x), | ||
762 | NUM_MARGIN_Y+(NUM_BOX_HEIGHT*y), | ||
763 | NUM_BOX_WIDTH+1, NUM_BOX_HEIGHT+1); | ||
764 | rb->lcd_set_drawmode(DRMODE_SOLID); | ||
765 | if(x==0) { | 768 | if(x==0) { |
766 | #ifdef IPOD_STYLE | 769 | #ifdef IPOD_STYLE |
767 | if(y>0) | 770 | if(y>0) |
@@ -773,18 +776,8 @@ int get_number(char* param, int* value) { | |||
773 | } else { | 776 | } else { |
774 | x--; | 777 | x--; |
775 | } | 778 | } |
776 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); | ||
777 | rb->lcd_fillrect(NUM_MARGIN_X+(NUM_BOX_WIDTH*x), | ||
778 | NUM_MARGIN_Y+(NUM_BOX_HEIGHT*y), | ||
779 | NUM_BOX_WIDTH+1, NUM_BOX_HEIGHT+1); | ||
780 | rb->lcd_set_drawmode(DRMODE_SOLID); | ||
781 | break; | 779 | break; |
782 | case SUPERDOM_RIGHT: | 780 | case SUPERDOM_RIGHT: |
783 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); | ||
784 | rb->lcd_fillrect(NUM_MARGIN_X+(NUM_BOX_WIDTH*x), | ||
785 | NUM_MARGIN_Y+(NUM_BOX_HEIGHT*y), | ||
786 | NUM_BOX_WIDTH+1, NUM_BOX_HEIGHT+1); | ||
787 | rb->lcd_set_drawmode(DRMODE_SOLID); | ||
788 | if(x==2) { | 781 | if(x==2) { |
789 | #ifdef IPOD_STYLE | 782 | #ifdef IPOD_STYLE |
790 | if(y==3) | 783 | if(y==3) |
@@ -796,20 +789,10 @@ int get_number(char* param, int* value) { | |||
796 | } else { | 789 | } else { |
797 | x++; | 790 | x++; |
798 | } | 791 | } |
799 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); | ||
800 | rb->lcd_fillrect(NUM_MARGIN_X+(NUM_BOX_WIDTH*x), | ||
801 | NUM_MARGIN_Y+(NUM_BOX_HEIGHT*y), | ||
802 | NUM_BOX_WIDTH+1, NUM_BOX_HEIGHT+1); | ||
803 | rb->lcd_set_drawmode(DRMODE_SOLID); | ||
804 | break; | 792 | break; |
805 | #endif | 793 | #endif |
806 | #ifndef IPOD_STYLE | 794 | #ifndef IPOD_STYLE |
807 | case SUPERDOM_UP: | 795 | case SUPERDOM_UP: |
808 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); | ||
809 | rb->lcd_fillrect(NUM_MARGIN_X+(NUM_BOX_WIDTH*x), | ||
810 | NUM_MARGIN_Y+(NUM_BOX_HEIGHT*y), | ||
811 | NUM_BOX_WIDTH+1, NUM_BOX_HEIGHT+1); | ||
812 | rb->lcd_set_drawmode(DRMODE_SOLID); | ||
813 | if(y==0) { | 796 | if(y==0) { |
814 | #if CONFIG_KEYPAD == IRIVER_H10_PAD | 797 | #if CONFIG_KEYPAD == IRIVER_H10_PAD |
815 | if(x > 0) | 798 | if(x > 0) |
@@ -821,18 +804,8 @@ int get_number(char* param, int* value) { | |||
821 | } else { | 804 | } else { |
822 | y--; | 805 | y--; |
823 | } | 806 | } |
824 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); | ||
825 | rb->lcd_fillrect(NUM_MARGIN_X+(NUM_BOX_WIDTH*x), | ||
826 | NUM_MARGIN_Y+(NUM_BOX_HEIGHT*y), | ||
827 | NUM_BOX_WIDTH+1, NUM_BOX_HEIGHT+1); | ||
828 | rb->lcd_set_drawmode(DRMODE_SOLID); | ||
829 | break; | 807 | break; |
830 | case SUPERDOM_DOWN: | 808 | case SUPERDOM_DOWN: |
831 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); | ||
832 | rb->lcd_fillrect(NUM_MARGIN_X+(NUM_BOX_WIDTH*x), | ||
833 | NUM_MARGIN_Y+(NUM_BOX_HEIGHT*y), | ||
834 | NUM_BOX_WIDTH+1, NUM_BOX_HEIGHT+1); | ||
835 | rb->lcd_set_drawmode(DRMODE_SOLID); | ||
836 | if(y==3) { | 809 | if(y==3) { |
837 | #if CONFIG_KEYPAD == IRIVER_H10_PAD | 810 | #if CONFIG_KEYPAD == IRIVER_H10_PAD |
838 | if(x < 2) | 811 | if(x < 2) |
@@ -844,23 +817,25 @@ int get_number(char* param, int* value) { | |||
844 | } else { | 817 | } else { |
845 | y++; | 818 | y++; |
846 | } | 819 | } |
847 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); | ||
848 | rb->lcd_fillrect(NUM_MARGIN_X+(NUM_BOX_WIDTH*x), | ||
849 | NUM_MARGIN_Y+(NUM_BOX_HEIGHT*y), | ||
850 | NUM_BOX_WIDTH+1, NUM_BOX_HEIGHT+1); | ||
851 | rb->lcd_set_drawmode(DRMODE_SOLID); | ||
852 | break; | 820 | break; |
853 | #endif | 821 | #endif |
854 | default: | 822 | default: |
855 | if (rb->default_event_handler(button) == SYS_USB_CONNECTED) | 823 | if (rb->default_event_handler(button) == SYS_USB_CONNECTED) |
856 | { | 824 | { |
857 | return PLUGIN_USB_CONNECTED; | 825 | rb->lcd_setfont(FONT_UI); |
826 | return RET_VAL_USB; | ||
858 | } | 827 | } |
859 | break; | 828 | break; |
860 | } | 829 | } |
830 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); | ||
831 | rb->lcd_fillrect(NUM_MARGIN_X+(NUM_BOX_WIDTH*x), | ||
832 | NUM_MARGIN_Y+(NUM_BOX_HEIGHT*y), | ||
833 | NUM_BOX_WIDTH+1, NUM_BOX_HEIGHT+1); | ||
834 | rb->lcd_set_drawmode(DRMODE_SOLID); | ||
861 | rb->lcd_update(); | 835 | rb->lcd_update(); |
862 | } | 836 | } |
863 | return 0; | 837 | rb->lcd_setfont(FONT_UI); |
838 | return RET_VAL_OK; | ||
864 | } | 839 | } |
865 | 840 | ||
866 | bool tile_has_item(int type, int x, int y) { | 841 | bool tile_has_item(int type, int x, int y) { |
@@ -915,6 +890,7 @@ int buy_resources(int colour, int type, int x, int y, int nummen) { | |||
915 | 890 | ||
916 | bool human = (colour == COLOUR_LIGHT); | 891 | bool human = (colour == COLOUR_LIGHT); |
917 | int price = 0; | 892 | int price = 0; |
893 | int temp; | ||
918 | struct resources *res; | 894 | struct resources *res; |
919 | 895 | ||
920 | if(human) { | 896 | if(human) { |
@@ -945,30 +921,24 @@ int buy_resources(int colour, int type, int x, int y, int nummen) { | |||
945 | if(res->cash < price) { | 921 | if(res->cash < price) { |
946 | if(human) | 922 | if(human) |
947 | rb->splash(HZ, "Not enough money!"); | 923 | rb->splash(HZ, "Not enough money!"); |
948 | return 2; | 924 | return RET_VAL_QUIT_ERR; |
949 | } | 925 | } |
950 | if(human) { | 926 | if(human) { |
951 | rb->splashf(HZ, "Where do you want to place %s?", itemnames[0][type]); | 927 | rb->splashf(HZ, "Where do you want to place %s?", itemnames[0][type]); |
952 | switch(select_square()) { | 928 | if((temp = select_square()) != RET_VAL_OK) |
953 | case 2: | 929 | return temp; |
954 | return 2; | ||
955 | break; | ||
956 | case PLUGIN_USB_CONNECTED: | ||
957 | return PLUGIN_USB_CONNECTED; | ||
958 | break; | ||
959 | } | ||
960 | x = cursor.x; | 930 | x = cursor.x; |
961 | y = cursor.y; | 931 | y = cursor.y; |
962 | } | 932 | } |
963 | if(board[x][y].colour != colour) { | 933 | if(board[x][y].colour != colour) { |
964 | if(human) | 934 | if(human) |
965 | rb->splashf(HZ, "Can't %s on enemy territory", itemnames[1][type]); | 935 | rb->splashf(HZ, "Can't %s on enemy territory", itemnames[1][type]); |
966 | return 2; | 936 | return RET_VAL_QUIT_ERR; |
967 | } | 937 | } |
968 | if(type != 0 && tile_has_item(type, x, y)) { | 938 | if(type != 0 && tile_has_item(type, x, y)) { |
969 | if(human) | 939 | if(human) |
970 | rb->splashf(HZ, "There is already %s there", itemnames[2][type]); | 940 | rb->splashf(HZ, "There is already %s there", itemnames[2][type]); |
971 | return 2; | 941 | return RET_VAL_QUIT_ERR; |
972 | } | 942 | } |
973 | switch(type) { | 943 | switch(type) { |
974 | case 0: | 944 | case 0: |
@@ -1001,25 +971,25 @@ int buy_resources(int colour, int type, int x, int y, int nummen) { | |||
1001 | draw_board(); | 971 | draw_board(); |
1002 | rb->sleep(HZ); | 972 | rb->sleep(HZ); |
1003 | 973 | ||
1004 | return 0; | 974 | return RET_VAL_OK; |
1005 | } | 975 | } |
1006 | 976 | ||
1007 | int buy_resources_menu(void) { | 977 | int buy_resources_menu(void) { |
1008 | int selection,nummen; | 978 | int selection = 0,nummen; |
1009 | 979 | ||
1010 | MENUITEM_STRINGLIST(res_menu, "Buy Resources", NULL, "Buy men ($1)", | 980 | MENUITEM_STRINGLIST(menu, "Buy Resources", NULL, |
1011 | "Buy tank ($300)", "Buy plane ($600)", "Buy Farm ($1150)", | 981 | "Buy men ($1)", "Buy tank ($300)", "Buy plane ($600)", |
1012 | "Buy Factory ($1300)", "Buy Nuke ($2000)", | 982 | "Buy Farm ($1150)", "Buy Factory ($1300)", |
983 | "Buy Nuke ($2000)", | ||
1013 | "Finish buying"); | 984 | "Finish buying"); |
1014 | 985 | ||
1015 | while(1) { | 986 | while(1) { |
1016 | selection=rb->do_menu(&res_menu,&selection, NULL, false); | 987 | switch(rb->do_menu(&menu, &selection, NULL, false)) { |
1017 | switch(selection) { | ||
1018 | case 0: | 988 | case 0: |
1019 | nummen = 0; | 989 | nummen = 0; |
1020 | if(get_number("How many men would you like?", &nummen) | 990 | if(get_number("How many men would you like?", &nummen) |
1021 | == PLUGIN_USB_CONNECTED) | 991 | == RET_VAL_USB) |
1022 | return PLUGIN_USB_CONNECTED; | 992 | return RET_VAL_USB; |
1023 | if(!nummen) | 993 | if(!nummen) |
1024 | break; | 994 | break; |
1025 | /* fall through */ | 995 | /* fall through */ |
@@ -1029,21 +999,21 @@ int buy_resources_menu(void) { | |||
1029 | case 4: | 999 | case 4: |
1030 | case 5: | 1000 | case 5: |
1031 | if(buy_resources(COLOUR_LIGHT, selection, 0, 0, nummen) | 1001 | if(buy_resources(COLOUR_LIGHT, selection, 0, 0, nummen) |
1032 | == PLUGIN_USB_CONNECTED) | 1002 | == RET_VAL_USB) |
1033 | return PLUGIN_USB_CONNECTED; | 1003 | return RET_VAL_USB; |
1034 | break; | 1004 | break; |
1035 | case 6: | 1005 | case 6: |
1036 | return 0; | 1006 | return RET_VAL_OK; |
1037 | break; | 1007 | break; |
1038 | case MENU_ATTACHED_USB: | 1008 | case MENU_ATTACHED_USB: |
1039 | return PLUGIN_USB_CONNECTED; | 1009 | return RET_VAL_USB; |
1040 | break; | 1010 | break; |
1041 | case GO_TO_PREVIOUS: | 1011 | case GO_TO_PREVIOUS: |
1042 | return 0; | 1012 | return RET_VAL_OK; |
1043 | break; | 1013 | break; |
1044 | } | 1014 | } |
1045 | } | 1015 | } |
1046 | return 0; | 1016 | return RET_VAL_OK; |
1047 | } | 1017 | } |
1048 | 1018 | ||
1049 | int move_unit(int colour, int type, int fromx, int fromy, | 1019 | int move_unit(int colour, int type, int fromx, int fromy, |
@@ -1064,60 +1034,44 @@ int move_unit(int colour, int type, int fromx, int fromy, | |||
1064 | } | 1034 | } |
1065 | }; | 1035 | }; |
1066 | bool human = (colour == COLOUR_LIGHT); | 1036 | bool human = (colour == COLOUR_LIGHT); |
1037 | int temp; | ||
1067 | 1038 | ||
1068 | if(human) { | 1039 | if(human) { |
1069 | rb->splashf(HZ, "Select where you want to move %s from", | 1040 | rb->splashf(HZ, "Select where you want to move %s from", |
1070 | itemnames[0][type]); | 1041 | itemnames[0][type]); |
1071 | switch(select_square()) { | 1042 | if((temp = select_square()) != RET_VAL_OK) |
1072 | case 2: | 1043 | return temp; |
1073 | return 2; | ||
1074 | break; | ||
1075 | case PLUGIN_USB_CONNECTED: | ||
1076 | return PLUGIN_USB_CONNECTED; | ||
1077 | break; | ||
1078 | } | ||
1079 | fromx = cursor.x; | 1044 | fromx = cursor.x; |
1080 | fromy = cursor.y; | 1045 | fromy = cursor.y; |
1081 | } | 1046 | } |
1082 | if(board[fromx][fromy].colour != colour) { | 1047 | if(board[fromx][fromy].colour != colour) { |
1083 | if(human) | 1048 | if(human) |
1084 | rb->splash(HZ, "That isn't your territory"); | 1049 | rb->splash(HZ, "That isn't your territory"); |
1085 | return 2; | 1050 | return RET_VAL_QUIT_ERR; |
1086 | } | 1051 | } |
1087 | if(!tile_has_item(type, fromx, fromy)) { | 1052 | if(!tile_has_item(type, fromx, fromy)) { |
1088 | if(human) | 1053 | if(human) |
1089 | rb->splashf(HZ, "You don't have %s there", itemnames[1][type]); | 1054 | rb->splashf(HZ, "You don't have %s there", itemnames[1][type]); |
1090 | return 2; | 1055 | return RET_VAL_QUIT_ERR; |
1091 | } | 1056 | } |
1092 | if(type == 0) { | 1057 | if(type == 0) { |
1093 | if(human) { | 1058 | if(human) { |
1094 | nummen = board[fromx][fromy].men; | 1059 | nummen = board[fromx][fromy].men; |
1095 | switch(get_number("How many men do you want to move?", &nummen)) { | 1060 | if((temp = get_number("How many men do you want to move?", &nummen)) |
1096 | case 2: | 1061 | != RET_VAL_OK) |
1097 | return 2; | 1062 | return temp; |
1098 | break; | ||
1099 | case PLUGIN_USB_CONNECTED: | ||
1100 | return PLUGIN_USB_CONNECTED; | ||
1101 | break; | ||
1102 | } | ||
1103 | } | 1063 | } |
1104 | if(nummen > board[fromx][fromy].men) { | 1064 | if(nummen > board[fromx][fromy].men) { |
1105 | if(human) | 1065 | if(human) |
1106 | rb->splash(HZ, "You don't have that many troops."); | 1066 | rb->splash(HZ, "You don't have that many troops."); |
1107 | return 2; | 1067 | return RET_VAL_QUIT_ERR; |
1108 | } | 1068 | } |
1109 | } | 1069 | } |
1110 | if(human) { | 1070 | if(human) { |
1111 | rb->splashf(HZ, "Select where you want to move %s to", | 1071 | rb->splashf(HZ, "Select where you want to move %s to", |
1112 | itemnames[2][type]); | 1072 | itemnames[2][type]); |
1113 | switch(select_square()) { | 1073 | if((temp = select_square()) != RET_VAL_OK) |
1114 | case 2: | 1074 | return temp; |
1115 | return 2; | ||
1116 | break; | ||
1117 | case PLUGIN_USB_CONNECTED: | ||
1118 | return PLUGIN_USB_CONNECTED; | ||
1119 | break; | ||
1120 | } | ||
1121 | tox = cursor.x; | 1075 | tox = cursor.x; |
1122 | toy = cursor.y; | 1076 | toy = cursor.y; |
1123 | } | 1077 | } |
@@ -1126,12 +1080,12 @@ int move_unit(int colour, int type, int fromx, int fromy, | |||
1126 | (type != 2 && (abs(tox - fromx) > 1 || abs(toy - fromy) > 1))) { | 1080 | (type != 2 && (abs(tox - fromx) > 1 || abs(toy - fromy) > 1))) { |
1127 | if(human) | 1081 | if(human) |
1128 | rb->splash(HZ, "Invalid move"); | 1082 | rb->splash(HZ, "Invalid move"); |
1129 | return 2; | 1083 | return RET_VAL_QUIT_ERR; |
1130 | } | 1084 | } |
1131 | if(type != 0 && tile_has_item(type, tox, toy)) { | 1085 | if(type != 0 && tile_has_item(type, tox, toy)) { |
1132 | if(human) | 1086 | if(human) |
1133 | rb->splashf(HZ, "There is already %s there", itemnames[1][type]); | 1087 | rb->splashf(HZ, "There is already %s there", itemnames[1][type]); |
1134 | return 2; | 1088 | return RET_VAL_QUIT_ERR; |
1135 | } | 1089 | } |
1136 | switch(type) { | 1090 | switch(type) { |
1137 | case 0: | 1091 | case 0: |
@@ -1147,58 +1101,52 @@ int move_unit(int colour, int type, int fromx, int fromy, | |||
1147 | board[tox][toy].plane = true; | 1101 | board[tox][toy].plane = true; |
1148 | break; | 1102 | break; |
1149 | } | 1103 | } |
1150 | return 0; | 1104 | return RET_VAL_OK; |
1151 | } | 1105 | } |
1152 | 1106 | ||
1153 | int move_unit_menu(void) { | 1107 | int move_unit_menu(void) { |
1154 | int selection; | 1108 | int selection = 0; |
1155 | 1109 | ||
1156 | MENUITEM_STRINGLIST(move_unit_menu, "Move unit", NULL, "Move men", | 1110 | MENUITEM_STRINGLIST(menu, "Move unit", NULL, |
1157 | "Move tank", "Move plane"); | 1111 | "Move men", "Move tank", "Move plane"); |
1158 | selection=rb->do_menu(&move_unit_menu,&selection, NULL, false); | 1112 | switch(rb->do_menu(&menu, &selection, NULL, false)) { |
1159 | switch(selection) { | ||
1160 | case 0: | 1113 | case 0: |
1161 | case 1: | 1114 | case 1: |
1162 | case 2: | 1115 | case 2: |
1163 | switch(move_unit(COLOUR_LIGHT, selection, 0, 0, 0, 0, 0)) { | 1116 | switch(move_unit(COLOUR_LIGHT, selection, 0, 0, 0, 0, 0)) { |
1164 | case 0: | 1117 | case RET_VAL_OK: |
1165 | humanres.moves--; | 1118 | humanres.moves--; |
1166 | break; | 1119 | break; |
1167 | case PLUGIN_USB_CONNECTED: | 1120 | case RET_VAL_USB: |
1168 | return PLUGIN_USB_CONNECTED; | 1121 | return RET_VAL_USB; |
1169 | break; | 1122 | break; |
1170 | } | 1123 | } |
1171 | break; | 1124 | break; |
1172 | case MENU_ATTACHED_USB: | 1125 | case MENU_ATTACHED_USB: |
1173 | return PLUGIN_USB_CONNECTED; | 1126 | return RET_VAL_USB; |
1174 | } | 1127 | } |
1175 | return 0; | 1128 | return RET_VAL_OK; |
1176 | } | 1129 | } |
1177 | 1130 | ||
1178 | int launch_nuke(int colour, int nukex, int nukey, int targetx, int targety) { | 1131 | int launch_nuke(int colour, int nukex, int nukey, int targetx, int targety) { |
1179 | bool human = (colour == COLOUR_LIGHT); | 1132 | bool human = (colour == COLOUR_LIGHT); |
1133 | int temp; | ||
1180 | struct resources *res; | 1134 | struct resources *res; |
1181 | 1135 | ||
1182 | if(board[nukex][nukey].colour != colour) { | 1136 | if(board[nukex][nukey].colour != colour) { |
1183 | if(human) | 1137 | if(human) |
1184 | rb->splash(HZ, "That isn't your territory"); | 1138 | rb->splash(HZ, "That isn't your territory"); |
1185 | return 2; | 1139 | return RET_VAL_QUIT_ERR; |
1186 | } | 1140 | } |
1187 | if(! board[nukex][nukey].nuke) { | 1141 | if(! board[nukex][nukey].nuke) { |
1188 | if(human) | 1142 | if(human) |
1189 | rb->splashf(HZ, "You don't have %s there", "a nuke"); | 1143 | rb->splashf(HZ, "You don't have %s there", "a nuke"); |
1190 | return 2; | 1144 | return RET_VAL_QUIT_ERR; |
1191 | } | 1145 | } |
1192 | if(human) { | 1146 | if(human) { |
1193 | rb->splash(HZ, "Select place to target with nuke"); | 1147 | rb->splash(HZ, "Select place to target with nuke"); |
1194 | switch(select_square()) { | 1148 | if((temp = select_square()) != RET_VAL_OK) |
1195 | case 2: | 1149 | return temp; |
1196 | return 2; | ||
1197 | break; | ||
1198 | case PLUGIN_USB_CONNECTED: | ||
1199 | return PLUGIN_USB_CONNECTED; | ||
1200 | break; | ||
1201 | } | ||
1202 | targetx = cursor.x; | 1150 | targetx = cursor.x; |
1203 | targety = cursor.y; | 1151 | targety = cursor.y; |
1204 | } | 1152 | } |
@@ -1228,23 +1176,23 @@ int launch_nuke(int colour, int nukex, int nukey, int targetx, int targety) { | |||
1228 | board[targetx][targety].farm = false; | 1176 | board[targetx][targety].farm = false; |
1229 | /* TODO: Fallout carried by wind */ | 1177 | /* TODO: Fallout carried by wind */ |
1230 | 1178 | ||
1231 | return 0; | 1179 | return RET_VAL_OK; |
1232 | } | 1180 | } |
1233 | 1181 | ||
1234 | int movement_menu(void) { | 1182 | int movement_menu(void) { |
1235 | int selection, tempmenu; | 1183 | int selection = 0, temp; |
1236 | 1184 | ||
1237 | MENUITEM_STRINGLIST(move_menu, "Movement", NULL, "Move unit", | 1185 | MENUITEM_STRINGLIST(menu, "Movement", NULL, |
1238 | "Buy additional moves ($100)", "Launch nuclear missile", | 1186 | "Move unit", "Buy additional moves ($100)", |
1239 | "Check map", "Finish moving", "Game menu"); | 1187 | "Launch nuclear missile", "Check map", |
1188 | "Finish moving", "Game menu"); | ||
1240 | 1189 | ||
1241 | while(1) { | 1190 | while(1) { |
1242 | selection=rb->do_menu(&move_menu,&selection, NULL, false); | 1191 | switch(rb->do_menu(&menu, &selection, NULL, false)) { |
1243 | switch(selection) { | ||
1244 | case 0: | 1192 | case 0: |
1245 | if(humanres.moves) { | 1193 | if(humanres.moves) { |
1246 | if(move_unit_menu()==PLUGIN_USB_CONNECTED) | 1194 | if(move_unit_menu()==RET_VAL_USB) |
1247 | return PLUGIN_USB_CONNECTED; | 1195 | return RET_VAL_USB; |
1248 | } else { | 1196 | } else { |
1249 | rb->splash(HZ, "You have no more moves left." | 1197 | rb->splash(HZ, "You have no more moves left." |
1250 | " You can buy more for $100 each."); | 1198 | " You can buy more for $100 each."); |
@@ -1265,140 +1213,144 @@ int movement_menu(void) { | |||
1265 | } else { | 1213 | } else { |
1266 | rb->splash(HZ, "Select place to launch nuke from"); | 1214 | rb->splash(HZ, "Select place to launch nuke from"); |
1267 | switch(select_square()) { | 1215 | switch(select_square()) { |
1268 | case 0: | 1216 | case RET_VAL_OK: |
1269 | if(launch_nuke(COLOUR_LIGHT, cursor.x, cursor.y, | 1217 | if(launch_nuke(COLOUR_LIGHT, cursor.x, cursor.y, |
1270 | 0, 0) == PLUGIN_USB_CONNECTED) | 1218 | 0, 0) == RET_VAL_USB) |
1271 | return PLUGIN_USB_CONNECTED; | 1219 | return RET_VAL_USB; |
1272 | break; | 1220 | break; |
1273 | case PLUGIN_USB_CONNECTED: | 1221 | case RET_VAL_USB: |
1274 | return PLUGIN_USB_CONNECTED; | 1222 | return RET_VAL_USB; |
1275 | break; | 1223 | break; |
1276 | } | 1224 | } |
1277 | } | 1225 | } |
1278 | break; | 1226 | break; |
1279 | case 3: | 1227 | case 3: |
1280 | if(select_square() == PLUGIN_USB_CONNECTED) | 1228 | if(select_square() == RET_VAL_USB) |
1281 | return PLUGIN_USB_CONNECTED; | 1229 | return RET_VAL_USB; |
1282 | break; | 1230 | break; |
1283 | case 4: | 1231 | case 4: |
1284 | return 0; | 1232 | return RET_VAL_OK; |
1285 | break; | 1233 | break; |
1286 | case 5: | 1234 | case 5: |
1287 | tempmenu = ingame_menu(); | 1235 | if((temp = ingame_menu()) != RET_VAL_OK) |
1288 | switch(tempmenu) { | 1236 | return temp; |
1289 | case PLUGIN_USB_CONNECTED: | ||
1290 | return PLUGIN_USB_CONNECTED; | ||
1291 | break; | ||
1292 | case SUPERDOM_QUIT: | ||
1293 | return SUPERDOM_QUIT; | ||
1294 | break; | ||
1295 | } | ||
1296 | break; | 1237 | break; |
1297 | case MENU_ATTACHED_USB: | 1238 | case MENU_ATTACHED_USB: |
1298 | return PLUGIN_USB_CONNECTED; | 1239 | return RET_VAL_USB; |
1299 | break; | 1240 | break; |
1300 | } | 1241 | } |
1301 | } | 1242 | } |
1302 | return 0; | 1243 | return RET_VAL_OK; |
1244 | } | ||
1245 | |||
1246 | static char * inventory_data(int selected_item, void * data, | ||
1247 | char * buffer, size_t buffer_len) { | ||
1248 | (void)data; | ||
1249 | switch(selected_item) { | ||
1250 | case 0: | ||
1251 | rb->snprintf(buffer,buffer_len,"Men: %d", humanres.men); | ||
1252 | break; | ||
1253 | case 1: | ||
1254 | rb->snprintf(buffer,buffer_len,"Tanks: %d", humanres.tanks); | ||
1255 | break; | ||
1256 | case 2: | ||
1257 | rb->snprintf(buffer,buffer_len,"Planes: %d", humanres.planes); | ||
1258 | break; | ||
1259 | case 3: | ||
1260 | rb->snprintf(buffer,buffer_len,"Factories: %d", humanres.inds); | ||
1261 | break; | ||
1262 | case 4: | ||
1263 | rb->snprintf(buffer,buffer_len,"Farms: %d", humanres.farms); | ||
1264 | break; | ||
1265 | case 5: | ||
1266 | rb->snprintf(buffer,buffer_len,"Nukes: %d", humanres.nukes); | ||
1267 | break; | ||
1268 | case 6: | ||
1269 | rb->snprintf(buffer,buffer_len,"Cash: %d", humanres.cash); | ||
1270 | break; | ||
1271 | case 7: | ||
1272 | rb->snprintf(buffer,buffer_len,"Food: %d", humanres.food); | ||
1273 | break; | ||
1274 | case 8: | ||
1275 | rb->snprintf(buffer,buffer_len,"Bank: %d", humanres.bank); | ||
1276 | break; | ||
1277 | default: | ||
1278 | return NULL; | ||
1279 | } | ||
1280 | return buffer; | ||
1303 | } | 1281 | } |
1304 | 1282 | ||
1305 | int show_inventory(void) { | 1283 | int show_inventory(void) { |
1306 | char men[20], tanks[20], planes[20], inds[20], farms[20], nukes[20], | 1284 | struct simplelist_info info; |
1307 | cash[20], food[20], bank[20]; | 1285 | rb->simplelist_info_init(&info, "Inventory", 9, NULL); |
1308 | rb->snprintf(men, sizeof(men), "Men: %d", humanres.men); | 1286 | info.hide_selection = true; |
1309 | rb->snprintf(tanks, sizeof(tanks), "Tanks: %d", humanres.tanks); | 1287 | info.get_name = inventory_data; |
1310 | rb->snprintf(planes, sizeof(planes), "Planes: %d", humanres.planes); | 1288 | if(rb->simplelist_show_list(&info)) { |
1311 | rb->snprintf(inds, sizeof(inds), "Factories: %d", humanres.inds); | 1289 | return RET_VAL_USB; |
1312 | rb->snprintf(farms, sizeof(farms), "Farms: %d", humanres.farms); | ||
1313 | rb->snprintf(nukes, sizeof(nukes), "Nukes: %d", humanres.nukes); | ||
1314 | rb->snprintf(cash, sizeof(cash), "Cash: %d", humanres.cash); | ||
1315 | rb->snprintf(food, sizeof(food), "Food: %d", humanres.food); | ||
1316 | rb->snprintf(bank, sizeof(bank), "Bank: %d", humanres.bank); | ||
1317 | rb->lcd_clear_display(); | ||
1318 | rb->lcd_puts(1, 0, "Inventory"); | ||
1319 | rb->lcd_puts(2, 1, men); | ||
1320 | rb->lcd_puts(2, 2, tanks); | ||
1321 | rb->lcd_puts(2, 3, planes); | ||
1322 | rb->lcd_puts(2, 4, inds); | ||
1323 | rb->lcd_puts(2, 5, farms); | ||
1324 | rb->lcd_puts(2, 6, nukes); | ||
1325 | rb->lcd_puts(2, 7, cash); | ||
1326 | rb->lcd_puts(2, 8, food); | ||
1327 | rb->lcd_puts(2, 9, bank); | ||
1328 | rb->lcd_update(); | ||
1329 | if(rb->default_event_handler(rb->button_get(true)) == SYS_USB_CONNECTED) { | ||
1330 | return PLUGIN_USB_CONNECTED; | ||
1331 | } else { | 1290 | } else { |
1332 | return 0; | 1291 | return RET_VAL_OK; |
1333 | } | 1292 | } |
1334 | } | 1293 | } |
1335 | 1294 | ||
1336 | int production_menu(void) { | 1295 | int production_menu(void) { |
1337 | int selection, tempbank, tempmenu; | 1296 | int selection = 0, temp; |
1338 | 1297 | ||
1339 | MENUITEM_STRINGLIST(prod_menu, "Production", NULL, "Buy resources", | 1298 | MENUITEM_STRINGLIST(menu, "Production", NULL, |
1340 | "Show inventory", "Check map", "Invest money", | 1299 | "Buy resources", "Show inventory", "Check map", |
1341 | "Withdraw money", "Finish turn", "Game menu"); | 1300 | "Invest money", "Withdraw money", |
1301 | "Finish turn", "Game menu"); | ||
1342 | 1302 | ||
1343 | while(1) { | 1303 | while(1) { |
1344 | selection=rb->do_menu(&prod_menu,&selection, NULL, false); | 1304 | switch(rb->do_menu(&menu, &selection, NULL, false)) { |
1345 | switch(selection) { | ||
1346 | case 0: | 1305 | case 0: |
1347 | if(buy_resources_menu() == PLUGIN_USB_CONNECTED) | 1306 | if(buy_resources_menu() == RET_VAL_USB) |
1348 | return PLUGIN_USB_CONNECTED; | 1307 | return RET_VAL_USB; |
1349 | break; | 1308 | break; |
1350 | case 1: | 1309 | case 1: |
1351 | if(show_inventory() == PLUGIN_USB_CONNECTED) | 1310 | if(show_inventory() == RET_VAL_USB) |
1352 | return PLUGIN_USB_CONNECTED; | 1311 | return RET_VAL_USB; |
1353 | break; | 1312 | break; |
1354 | case 2: | 1313 | case 2: |
1355 | if(select_square() == PLUGIN_USB_CONNECTED) | 1314 | if(select_square() == RET_VAL_USB) |
1356 | return PLUGIN_USB_CONNECTED; | 1315 | return RET_VAL_USB; |
1357 | break; | 1316 | break; |
1358 | case 3: | 1317 | case 3: |
1359 | tempbank = humanres.cash; | 1318 | temp = humanres.cash; |
1360 | if(get_number("How much do you want to invest?", &tempbank) | 1319 | if(get_number("How much do you want to invest?", &temp) |
1361 | == PLUGIN_USB_CONNECTED) | 1320 | == RET_VAL_USB) |
1362 | return PLUGIN_USB_CONNECTED; | 1321 | return RET_VAL_USB; |
1363 | if(tempbank>humanres.cash) { | 1322 | if(temp > humanres.cash) { |
1364 | rb->splash(HZ, "You don't have that much cash to invest"); | 1323 | rb->splash(HZ, "You don't have that much cash to invest"); |
1365 | } else { | 1324 | } else { |
1366 | humanres.cash -= tempbank; | 1325 | humanres.cash -= temp; |
1367 | humanres.bank += tempbank; | 1326 | humanres.bank += temp; |
1368 | } | 1327 | } |
1369 | break; | 1328 | break; |
1370 | case 4: | 1329 | case 4: |
1371 | tempbank = 0; | 1330 | temp = humanres.bank; |
1372 | if(get_number("How much do you want to withdraw?", &tempbank) | 1331 | if(get_number("How much do you want to withdraw?", &temp) |
1373 | == PLUGIN_USB_CONNECTED) | 1332 | == RET_VAL_USB) |
1374 | return PLUGIN_USB_CONNECTED; | 1333 | return RET_VAL_USB; |
1375 | if(tempbank>humanres.bank) { | 1334 | if(temp > humanres.bank) { |
1376 | rb->splash(HZ, "You don't have that much cash to withdraw"); | 1335 | rb->splash(HZ, "You don't have that much cash to withdraw"); |
1377 | } else { | 1336 | } else { |
1378 | humanres.cash += tempbank; | 1337 | humanres.cash += temp; |
1379 | humanres.bank -= tempbank; | 1338 | humanres.bank -= temp; |
1380 | } | 1339 | } |
1381 | break; | 1340 | break; |
1382 | case 5: | 1341 | case 5: |
1383 | return 0; | 1342 | return RET_VAL_OK; |
1384 | break; | 1343 | break; |
1385 | case 6: | 1344 | case 6: |
1386 | tempmenu = ingame_menu(); | 1345 | if((temp = ingame_menu()) != RET_VAL_OK) |
1387 | switch(tempmenu) { | 1346 | return temp; |
1388 | case PLUGIN_USB_CONNECTED: | ||
1389 | return PLUGIN_USB_CONNECTED; | ||
1390 | break; | ||
1391 | case SUPERDOM_QUIT: | ||
1392 | return SUPERDOM_QUIT; | ||
1393 | break; | ||
1394 | } | ||
1395 | break; | 1347 | break; |
1396 | case MENU_ATTACHED_USB: | 1348 | case MENU_ATTACHED_USB: |
1397 | return PLUGIN_USB_CONNECTED; | 1349 | return RET_VAL_USB; |
1398 | break; | 1350 | break; |
1399 | } | 1351 | } |
1400 | } | 1352 | } |
1401 | return 0; | 1353 | return RET_VAL_OK; |
1402 | } | 1354 | } |
1403 | 1355 | ||
1404 | void init_resources(void) { | 1356 | void init_resources(void) { |
@@ -1443,10 +1395,10 @@ int select_square(void) { | |||
1443 | switch(button) { | 1395 | switch(button) { |
1444 | case SUPERDOM_CANCEL: | 1396 | case SUPERDOM_CANCEL: |
1445 | rb->splash(HZ, "Cancelled"); | 1397 | rb->splash(HZ, "Cancelled"); |
1446 | return 2; | 1398 | return RET_VAL_QUIT_ERR; |
1447 | break; | 1399 | break; |
1448 | case SUPERDOM_OK: | 1400 | case SUPERDOM_OK: |
1449 | return 0; | 1401 | return RET_VAL_OK; |
1450 | break; | 1402 | break; |
1451 | #if CONFIG_KEYPAD != IRIVER_H10_PAD | 1403 | #if CONFIG_KEYPAD != IRIVER_H10_PAD |
1452 | case SUPERDOM_LEFT: | 1404 | case SUPERDOM_LEFT: |
@@ -1523,7 +1475,7 @@ int select_square(void) { | |||
1523 | default: | 1475 | default: |
1524 | if (rb->default_event_handler(button) == SYS_USB_CONNECTED) | 1476 | if (rb->default_event_handler(button) == SYS_USB_CONNECTED) |
1525 | { | 1477 | { |
1526 | return PLUGIN_USB_CONNECTED; | 1478 | return RET_VAL_USB; |
1527 | } | 1479 | } |
1528 | } | 1480 | } |
1529 | } | 1481 | } |
@@ -1616,43 +1568,36 @@ int attack_territory(int colour, int x, int y) { | |||
1616 | } | 1568 | } |
1617 | 1569 | ||
1618 | int war_menu(void) { | 1570 | int war_menu(void) { |
1619 | int selection, tempmenu; | 1571 | int selection = 0, temp; |
1620 | 1572 | ||
1621 | MENUITEM_STRINGLIST(wartime_menu, "War!", NULL, | 1573 | MENUITEM_STRINGLIST(menu, "War!", NULL, |
1622 | "Select territory to attack", "Finish turn", "Game menu"); | 1574 | "Select territory to attack", |
1575 | "Finish turn", "Game menu"); | ||
1623 | 1576 | ||
1624 | while(humanres.moves) { | 1577 | while(humanres.moves) { |
1625 | selection=rb->do_menu(&wartime_menu,&selection, NULL, false); | 1578 | switch(rb->do_menu(&menu, &selection, NULL, false)) { |
1626 | switch(selection) { | ||
1627 | case 0: | 1579 | case 0: |
1628 | switch(select_square()) { | 1580 | switch(select_square()) { |
1629 | case 0: | 1581 | case RET_VAL_OK: |
1630 | if(attack_territory(COLOUR_LIGHT, cursor.x, cursor.y) | 1582 | if(attack_territory(COLOUR_LIGHT, cursor.x, cursor.y) |
1631 | >= 0) | 1583 | >= 0) |
1632 | humanres.moves--; | 1584 | humanres.moves--; |
1633 | break; | 1585 | break; |
1634 | case PLUGIN_USB_CONNECTED: | 1586 | case RET_VAL_USB: |
1635 | return PLUGIN_USB_CONNECTED; | 1587 | return RET_VAL_USB; |
1636 | break; | 1588 | break; |
1637 | } | 1589 | } |
1638 | break; | 1590 | break; |
1639 | case 1: | 1591 | case 1: |
1640 | return 0; | 1592 | return RET_VAL_OK; |
1641 | break; | 1593 | break; |
1642 | case 2: | 1594 | case 2: |
1643 | tempmenu = ingame_menu(); | 1595 | if((temp = ingame_menu()) != RET_VAL_OK) |
1644 | switch(tempmenu) { | 1596 | return temp; |
1645 | case PLUGIN_USB_CONNECTED: | ||
1646 | return PLUGIN_USB_CONNECTED; | ||
1647 | break; | ||
1648 | case SUPERDOM_QUIT: | ||
1649 | return SUPERDOM_QUIT; | ||
1650 | break; | ||
1651 | } | ||
1652 | break; | 1597 | break; |
1653 | } | 1598 | } |
1654 | } | 1599 | } |
1655 | return 0; | 1600 | return RET_VAL_OK; |
1656 | } | 1601 | } |
1657 | 1602 | ||
1658 | struct threat { | 1603 | struct threat { |
@@ -1908,7 +1853,7 @@ void computer_war(void) { | |||
1908 | int i, j; | 1853 | int i, j; |
1909 | bool found_target = true; | 1854 | bool found_target = true; |
1910 | struct cursor adj; | 1855 | struct cursor adj; |
1911 | 1856 | ||
1912 | while(found_target) { | 1857 | while(found_target) { |
1913 | found_target = false; | 1858 | found_target = false; |
1914 | for(i=1;i<11;i++) { | 1859 | for(i=1;i<11;i++) { |
@@ -2073,20 +2018,17 @@ enum plugin_status plugin_start(const void* parameter) | |||
2073 | } | 2018 | } |
2074 | } | 2019 | } |
2075 | 2020 | ||
2076 | bool play = false; | 2021 | switch(start_menu()) { |
2077 | while(!play) { | 2022 | case RET_VAL_OK: /* start playing */ |
2078 | switch(menu()) { | 2023 | break; |
2079 | case 0: | 2024 | case RET_VAL_QUIT_ERR: /* quit */ |
2080 | play = true; | 2025 | return PLUGIN_OK; |
2081 | break; | 2026 | break; |
2082 | case 2: | 2027 | case RET_VAL_USB: |
2083 | return PLUGIN_OK; | 2028 | return PLUGIN_USB_CONNECTED; |
2084 | break; | 2029 | break; |
2085 | case PLUGIN_USB_CONNECTED: | ||
2086 | return PLUGIN_USB_CONNECTED; | ||
2087 | break; | ||
2088 | } | ||
2089 | } | 2030 | } |
2031 | |||
2090 | init_resources(); | 2032 | init_resources(); |
2091 | init_board(); | 2033 | init_board(); |
2092 | gen_resources(); | 2034 | gen_resources(); |
@@ -2108,10 +2050,10 @@ startyear: | |||
2108 | startprod: | 2050 | startprod: |
2109 | gamestate = GS_PROD; | 2051 | gamestate = GS_PROD; |
2110 | switch(production_menu()) { | 2052 | switch(production_menu()) { |
2111 | case PLUGIN_USB_CONNECTED: | 2053 | case RET_VAL_USB: |
2112 | return PLUGIN_USB_CONNECTED; | 2054 | return PLUGIN_USB_CONNECTED; |
2113 | break; | 2055 | break; |
2114 | case SUPERDOM_QUIT: | 2056 | case RET_VAL_QUIT_ERR: |
2115 | return PLUGIN_OK; | 2057 | return PLUGIN_OK; |
2116 | break; | 2058 | break; |
2117 | } | 2059 | } |
@@ -2122,10 +2064,10 @@ startprod: | |||
2122 | startmove: | 2064 | startmove: |
2123 | gamestate = GS_MOVE; | 2065 | gamestate = GS_MOVE; |
2124 | switch(movement_menu()) { | 2066 | switch(movement_menu()) { |
2125 | case PLUGIN_USB_CONNECTED: | 2067 | case RET_VAL_USB: |
2126 | return PLUGIN_USB_CONNECTED; | 2068 | return PLUGIN_USB_CONNECTED; |
2127 | break; | 2069 | break; |
2128 | case SUPERDOM_QUIT: | 2070 | case RET_VAL_QUIT_ERR: |
2129 | return PLUGIN_OK; | 2071 | return PLUGIN_OK; |
2130 | break; | 2072 | break; |
2131 | } | 2073 | } |
@@ -2157,10 +2099,10 @@ startmove: | |||
2157 | startwar: | 2099 | startwar: |
2158 | gamestate = GS_WAR; | 2100 | gamestate = GS_WAR; |
2159 | switch(war_menu()) { | 2101 | switch(war_menu()) { |
2160 | case PLUGIN_USB_CONNECTED: | 2102 | case RET_VAL_USB: |
2161 | return PLUGIN_USB_CONNECTED; | 2103 | return PLUGIN_USB_CONNECTED; |
2162 | break; | 2104 | break; |
2163 | case SUPERDOM_QUIT: | 2105 | case RET_VAL_QUIT_ERR: |
2164 | return PLUGIN_OK; | 2106 | return PLUGIN_OK; |
2165 | break; | 2107 | break; |
2166 | } | 2108 | } |