Virtual U.org
Get Personal Training on VU Today
    
Top shadow
 
 register/help
User Name:

Password:

Oopt2.cpp Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Oopt2.cpp

Go to the documentation of this file.
00001 //Filename    : OOPT2.CPP
00002 //Description : Optimization class - stage 2
00003 
00004 #include <OSYS.H>
00005 #include <OGAMESET.H>
00006 #include <OWORLDMT.H>
00007 #include <OBNDSLDR.H>
00008 #include <OVGA.H>
00009 #include <COLOR.H>
00010 #include <OFINANCE.H>
00011 #include <OFONT.H>
00012 #include <OGAMESTR.H>
00013 #include <OMOUSE.H>
00014 #include <OOPT.H>
00015 #include <OBUTTON.H>
00016 #include <OIFACE.H>
00017 #include <OIMGRES.H>
00018 #include <OTEXT.H>
00019 #include <OHELPIF.H>
00020 #include <OHELP.H>
00021 #include <OAUDIO.H>
00022 #include <OCONFIG.H>
00023 #include <OCHANCE.H>
00024 
00025 //------- Define constants -------//
00026 
00027 enum {
00028     REPORT_X1 = ZOOM_X1 + 15,
00029     REPORT_Y1 = ZOOM_Y1 + 25,
00030     REPORT_X2 = ZOOM_X2 - 15,
00031     REPORT_Y2 = ZOOM_Y2 - 60
00032 };
00033 
00034 enum {
00035     SEPARATOR_1 = REPORT_X1 + 300,
00036     SEPARATOR_2 = REPORT_X1 + 500,
00037     SEPARATOR_3 = REPORT_X1 + 620
00038 };
00039 
00040 enum {
00041     LINE_SPACING = 25,
00042     HEADING_HEIGHT = 30,
00043     FIRST_LINE_OFFSET = REPORT_Y1 + HEADING_HEIGHT + 20,
00044     DESCRIPTION_OFFSET = REPORT_X1 + 30,
00045     SLIDER_OFFSET = 1,
00046     DESCRIPTION_INDENT = 20,
00047     TARGET_OFFSET = SEPARATOR_1 + 15,
00048     TARGET_WIDTH = SEPARATOR_2 - SEPARATOR_1 - 30,
00049     TARGET_HEIGHT = 10,
00050     PREF_BUTTON_WIDTH = 16,
00051     PREF_BUTTON_HEIGHT = 16,
00052     PREF_BUTTON_DISTANCE = 10,
00053     PREF_BUTTON_OFFSET = 0,
00054     PREF_BUTTON_OFFSET1 = SEPARATOR_2 + 15,
00055     PREF_BUTTON_OFFSET2 = PREF_BUTTON_OFFSET1 + PREF_BUTTON_WIDTH + PREF_BUTTON_DISTANCE,
00056     PREF_BUTTON_OFFSET3 = PREF_BUTTON_OFFSET2 + PREF_BUTTON_WIDTH + PREF_BUTTON_DISTANCE,
00057     PREF_BUTTON_OFFSET4 = PREF_BUTTON_OFFSET3 + PREF_BUTTON_WIDTH + PREF_BUTTON_DISTANCE,
00058     RESULT_OFFSET = SEPARATOR_3 + 20,
00059     RESULT_LENGTH = 50
00060 };
00061 
00062 //-------- define static vars -----------//
00063 
00064 static Text result_text[COST_RISE_POLICY_COUNT];
00065 static Button help_button_array[COST_RISE_POLICY_COUNT];
00066 
00067 static char *title[] = {
00068     "Description",
00069     "Target",
00070     "      Preference",
00071     "Result"
00072 };
00073 
00074 static char *heading = "Allocation of net budget change";
00075 
00076 static char *pref_label[] = {
00077     "1", "2", "3", "R"
00078 };
00079 
00080 //------- Begin of function Optimization::init_stage_2 -----------//
00082 void Optimization::init_stage_2() {
00083     for (int i = 0; i < COST_RISE_POLICY_COUNT; i++) {
00084         for (int j = 0; j < PREF_COUNT; j++) {
00085             opt2_button_group_up_bitmap[i * PREF_COUNT + j] = NULL;
00086             opt2_button_group_down_bitmap[i * PREF_COUNT + j] = NULL;
00087         }
00088     }
00089 }
00090 
00091 //--------- End of function Optimization::init_stage_2 -----------//
00092 
00093 //------- Begin of function Optimization::deinit_stage_2 ---------//
00095 void Optimization::deinit_stage_2() {
00096     for (int i = 0; i < COST_RISE_POLICY_COUNT; i++) {
00097         delete opt2_button_group_array[i];
00098 
00099         if(opt2_button_group_array[i]) {
00100             opt2_button_group_array[i]=NULL;
00101         }
00102 
00103         opt2_slider_group[i].deinit();
00104 
00105         for (int j = 0; j < PREF_COUNT; j++) {
00106             if(opt2_button_group_up_bitmap[i * PREF_COUNT + j]) {
00107                 mem_del(opt2_button_group_up_bitmap[i * PREF_COUNT + j]);
00108                 opt2_button_group_up_bitmap[i * PREF_COUNT + j] = (short*)NULL;
00109             }
00110             if(opt2_button_group_down_bitmap[i * PREF_COUNT + j]) {
00111                 mem_del(opt2_button_group_down_bitmap[i * PREF_COUNT + j]);
00112                 opt2_button_group_down_bitmap[i * PREF_COUNT + j] = (short*)NULL;
00113             }
00114         }
00115 
00116         //              opt2_button_group_array[i]->button_pressed=2;
00117         result_text[i].deinit();
00118         // ##### begin Gilbert 28/04/2001 ######//
00119         help_button_array[i].deinit();
00120         // ##### end Gilbert 28/04/2001 ######//
00121     }
00122     stage_init_flag = 0;
00123 }
00124 
00125 //--------- End of function Optimization::deinit_stage_2 -------//
00126 
00127 //------- Begin of function Optimization::report_stage_2 -------//
00129 void Optimization::report_stage_2(int refreshFlag) {
00130     if (refreshFlag == INFO_REPAINT || refresh_optimization_screen ) {
00131         user_interface.brighten(REPORT_X1+100, ZOOM_Y1, REPORT_X2-100, REPORT_Y1);
00132         user_interface.brighten(REPORT_X1+4, REPORT_Y1+4, REPORT_X2-2, REPORT_Y2-2);
00133         user_interface.rect(REPORT_X1+100, ZOOM_Y1, REPORT_X2-100, REPORT_Y1);
00134         //              font_charts.center_put( REPORT_X1, ZOOM_Y1, REPORT_X2, REPORT_Y1, "Stage 2 : Expenditure by Function" );
00135         font_charts.center_put( REPORT_X1, ZOOM_Y1, REPORT_X2, REPORT_Y1, "Budget Allocations" );
00136 
00137         // current stage not init'ed
00138         if (stage_init_flag != 2 || refresh_optimization_screen ) {
00139             deinit();
00140             ButtonGroup *buttonGroupPtr;
00141             double *targetValue, *lowerBound, *upperBound, *importWeight, lowerLimit, upperLimit;
00142             int pressedButton;
00143 
00144             for (int i = 0; i < COST_RISE_POLICY_COUNT; i++) {
00145                 opt2_button_group_array[i] = new ButtonGroup(PREF_COUNT);
00146 
00147                 //##### begin fred 980904#####//
00148                 targetValue = &(finance.cost_rise_policy_array[i].target_value);
00149                 lowerBound = &(finance.cost_rise_policy_array[i].lower_bound);
00150                 upperBound = &(finance.cost_rise_policy_array[i].upper_bound);
00151                 importWeight = &(finance.cost_rise_policy_array[i].import_weight);
00152                 lowerLimit = (finance.cost_rise_policy_array[i].lower_limit);
00153                 upperLimit = (finance.cost_rise_policy_array[i].upper_limit);
00154 
00155                 //################begin chwg0930 BUGHERE ####################/
00156                 if(i==9)
00157                     importWeight = &(finance.cost_rise_policy_array[8].import_weight);
00158 
00159                 //                              opt2_slider_group[i].init(
00160                 //                                      TARGET_OFFSET, SLIDER_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1),
00161                 //                                      TARGET_WIDTH, TARGET_HEIGHT, targetValue, lowerBound, upperBound, *targetValue-(*targetValue-*lowerBound)*2, *targetValue+(*upperBound-*targetValue)*2);
00162                 opt2_slider_group[i].init(
00163                     TARGET_OFFSET, SLIDER_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1),
00164                     TARGET_WIDTH, TARGET_HEIGHT, targetValue, lowerBound, upperBound, lowerLimit, upperLimit,
00165                     1,V_YELLOW,V_GREEN,24);                 //## chea 110899 change by b.massy add 24(1dec)
00166                 //##### end fred 980904#####//
00167 
00168                 user_interface.create_button_bitmap(PREF_BUTTON_OFFSET1-2,
00169                                                     PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1)-2,
00170                                                     PREF_BUTTON_OFFSET1 + PREF_BUTTON_WIDTH,
00171                                                     PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1) + PREF_BUTTON_HEIGHT,
00172                                                     pref_label[0], &opt2_button_group_up_bitmap[PREF_COUNT * i], &opt2_button_group_down_bitmap[PREF_COUNT * i], &vga_back);
00173                 user_interface.create_button_bitmap(PREF_BUTTON_OFFSET2-2,
00174                                                     PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1)-2,
00175                                                     PREF_BUTTON_OFFSET2 + PREF_BUTTON_WIDTH,
00176                                                     PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1) + PREF_BUTTON_HEIGHT,
00177                                                     pref_label[1], &opt2_button_group_up_bitmap[PREF_COUNT * i + 1], &opt2_button_group_down_bitmap[PREF_COUNT * i + 1], &vga_back);
00178                 user_interface.create_button_bitmap(PREF_BUTTON_OFFSET3-2,
00179                                                     PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1)-2,
00180                                                     PREF_BUTTON_OFFSET3 + PREF_BUTTON_WIDTH,
00181                                                     PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1) + PREF_BUTTON_HEIGHT,
00182                                                     pref_label[2], &opt2_button_group_up_bitmap[PREF_COUNT * i + 2], &opt2_button_group_down_bitmap[PREF_COUNT * i + 2], &vga_back);
00183                 user_interface.create_button_bitmap(PREF_BUTTON_OFFSET4-2,
00184                                                     PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1)-2,
00185                                                     PREF_BUTTON_OFFSET4 + PREF_BUTTON_WIDTH,
00186                                                     PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1) + PREF_BUTTON_HEIGHT,
00187                                                     pref_label[3], &opt2_button_group_up_bitmap[PREF_COUNT * i + 3], &opt2_button_group_down_bitmap[PREF_COUNT * i + 3], &vga_back);
00188                 buttonGroupPtr = opt2_button_group_array[i];
00189 
00190                 //                              pressedButton = int(*importWeight * 2.0) - 1;
00191                 if(*importWeight==OPT_LOW_WEIGHT)
00192                     pressedButton =0;
00193                 if(*importWeight==OPT_MID_WEIGHT)
00194                     pressedButton =1;
00195                 if(*importWeight==OPT_HIGH_WEIGHT)
00196                     pressedButton =2;
00197 
00198                 if(finance.cost_rise_policy_array[i].required_flag) {
00199                     opt2_slider_group[i].enable_flag=0;
00200                     pressedButton = 3;
00201                 }
00202                 //                              else
00203                 //                              {
00204                 //                                      if(opt2_button_group_array[i]->button_pressed==3)
00205                 //                                              pressedButton = 1;
00206                 //                                      opt2_slider_group[i].enable_flag=1;
00207                 //                              }
00208 
00209                 //## chea captial campaign 230699
00210                 if(chance_event.capital_campaign_end_year>info.game_year) {
00211                     // disable
00212                     opt2_slider_group[PL_INST_ADVANCEMENT].enable_flag=0;
00213                     pressedButton = 3;
00214                 }
00215                 //## chea captial campaign 230699
00216 
00217                 (*buttonGroupPtr)[0].create_bitmapW(
00218                     PREF_BUTTON_OFFSET1-2,
00219                     PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1)-2,
00220                     PREF_BUTTON_OFFSET1 + PREF_BUTTON_WIDTH,
00221                     PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1) + PREF_BUTTON_HEIGHT,
00222                     ((pressedButton == 0) ? opt2_button_group_down_bitmap[PREF_COUNT * i] : opt2_button_group_up_bitmap[PREF_COUNT * i]) + 4);
00223                 (*buttonGroupPtr)[1].create_bitmapW(
00224                     PREF_BUTTON_OFFSET2-2,
00225                     PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1)-2,
00226                     PREF_BUTTON_OFFSET2 + PREF_BUTTON_WIDTH,
00227                     PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1) + PREF_BUTTON_HEIGHT,
00228                     ((pressedButton == 1) ? opt2_button_group_down_bitmap[PREF_COUNT * i + 1] : opt2_button_group_up_bitmap[PREF_COUNT * i + 1]) + 4);
00229                 (*buttonGroupPtr)[2].create_bitmapW(
00230                     PREF_BUTTON_OFFSET3-2,
00231                     PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1)-2,
00232                     PREF_BUTTON_OFFSET3 + PREF_BUTTON_WIDTH,
00233                     PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1) + PREF_BUTTON_HEIGHT,
00234                     ((pressedButton == 2) ? opt2_button_group_down_bitmap[PREF_COUNT * i + 2] : opt2_button_group_up_bitmap[PREF_COUNT * i + 2]) + 4);
00235                 (*buttonGroupPtr)[3].create_bitmapW(
00236                     PREF_BUTTON_OFFSET4-2,
00237                     PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1)-2,
00238                     PREF_BUTTON_OFFSET4 + PREF_BUTTON_WIDTH,
00239                     PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1) + PREF_BUTTON_HEIGHT,
00240                     ((pressedButton == 3) ? opt2_button_group_down_bitmap[PREF_COUNT * i + 3] : opt2_button_group_up_bitmap[PREF_COUNT * i + 3]) + 4);
00241 
00242                 buttonGroupPtr->button_pressed = pressedButton;
00243 
00244                 if(user_interface.backgd_flag==1)
00245                     help_button_array[i].create_text(REPORT_X1+10,
00246                                                      FIRST_LINE_OFFSET + LINE_SPACING * (i+1),
00247                                                      REPORT_X1+28,
00248                                                      FIRST_LINE_OFFSET + LINE_SPACING * (i+1)+18,
00249                                                      "?");
00250             }
00251 
00252             stage_init_flag = 2;
00253         }
00254 
00255         user_interface.h_line(REPORT_X1, REPORT_Y1+HEADING_HEIGHT, REPORT_X2-REPORT_X1);
00256         user_interface.v_line(SEPARATOR_1-1, REPORT_Y1+1, REPORT_Y2-REPORT_Y1-2);
00257         user_interface.v_line(SEPARATOR_2-1, REPORT_Y1+1, REPORT_Y2-REPORT_Y1-2);
00258         user_interface.v_line(SEPARATOR_3-1, REPORT_Y1+1, REPORT_Y2-REPORT_Y1-2);
00259         user_interface.rect(REPORT_X1, REPORT_Y1, REPORT_X2, REPORT_Y2, 2);
00260 
00261         font_chartsm.center_put( REPORT_X1+1, REPORT_Y1+1,
00262                                  SEPARATOR_1-1, REPORT_Y1+1+HEADING_HEIGHT, title[0] );
00263         font_chartsm.center_put( SEPARATOR_1+1, REPORT_Y1+1,
00264                                  SEPARATOR_2-1, REPORT_Y1+1+HEADING_HEIGHT, title[1] );
00265         font_chartsm.center_put( SEPARATOR_2+1, REPORT_Y1+1,
00266                                  SEPARATOR_3-1, REPORT_Y1+1+HEADING_HEIGHT, title[2] );
00267         font_chartsm.center_put( SEPARATOR_3+1, REPORT_Y1+1,
00268                                  REPORT_X2-1, REPORT_Y1+1+HEADING_HEIGHT, title[3] );
00269 
00270         if(user_interface.backgd_flag==1)
00271             image_interface.put_back(SEPARATOR_2+9,REPORT_Y1+7,"QUEST_UP");
00272 
00273         font_chartsm.put( DESCRIPTION_OFFSET, FIRST_LINE_OFFSET, heading);
00274 
00275         for (int i = 0; i < COST_RISE_POLICY_COUNT; i++) {
00276             font_chartsm.put(
00277                 DESCRIPTION_OFFSET + DESCRIPTION_INDENT,
00278                 FIRST_LINE_OFFSET + LINE_SPACING * (i + 1),
00279                 game_str_res.opt_stage2_str(i) );
00280 
00281             if(user_interface.backgd_flag==1)
00282                 image_interface.put_back(REPORT_X1+10,
00283                                          FIRST_LINE_OFFSET + LINE_SPACING * (i+1),"QUEST_UP");
00284             opt2_slider_group[i].paint();
00285 
00286             opt2_button_group_array[i]->paint(opt2_button_group_array[i]->button_pressed);
00287 
00288             opt2_slider_group[i].result_flag=optimization.is_optimized[1];
00289             opt2_slider_group[i].result_value = finance.cost_rise_policy_array[i].result_value;
00290             //                  opt2_slider_group[i].result_value=(double)((int)(opt2_slider_group[i].result_value*100.0)/100);
00291             result_text[i].init(
00292                 RESULT_OFFSET + RESULT_LENGTH-50,
00293                 FIRST_LINE_OFFSET + LINE_SPACING * (i + 1),
00294                 &(opt2_slider_group[i].result_value),24); //## chea 110899 change by b.massy add 24(1dec)
00295         }
00296 
00297         refresh_optimization_screen = 0;
00298     }
00299     else {                                          // refreshFlag == INFO_REFRESH
00300         vga.use_back();
00301         for (int i = 0; i < COST_RISE_POLICY_COUNT; i++) {
00302             opt2_slider_group[i].result_flag=optimization.is_optimized[1]; {
00303 
00304                 //                      if(optimization.is_optimized[1]==1)
00305                 opt2_slider_group[i].result_value = finance.cost_rise_policy_array[i].result_value;
00306 
00307                 // chwg0513
00308                 if(finance.cost_rise_policy_array[i].required_flag) {
00309                     opt2_slider_group[i].enable_flag=0;
00310                     opt2_button_group_array[i]->push(3);
00311                     double *importWeight = &(finance.cost_rise_policy_array[i].import_weight);
00312                     *importWeight = OPT_MID_WEIGHT;
00313                 }
00314                 //## chea 031299 11.2.3 to make the opt bar enable again this is when a bar is locked use in report and will release here
00315                 else if(finance.cost_rise_policy_array[i].required_flag == 0 && opt2_slider_group[i].enable_flag ==0) {
00316                     opt2_slider_group[i].enable_flag=1;
00317                     opt2_button_group_array[i]->push(1);
00318                     double *importWeight = &(finance.cost_rise_policy_array[i].import_weight);
00319                     *importWeight = OPT_MID_WEIGHT;
00320                 }
00321 
00322                 //                              else
00323                 //                              {
00324                 //                                      if(opt2_button_group_array[i]->button_pressed==3)
00325                 //                                                      opt2_button_group_array[i]->push(1);
00326                 //                                              opt2_slider_group[i].enable_flag=1;
00327                 //                              }
00328 
00329                 //                              short bltX, bltY, bltHeight;
00330                 //                              user_interface.v_line(
00331                 //                                      bltX = opt2_slider_group->bounded_slider_x1 + 4 + short(double(opt2_slider_group->bar_width) * (resultValue - opt2_slider_group[i].min_val) / (opt2_slider_group[i].max_val - opt2_slider_group[i].min_val)),
00332                 //                                      bltY = opt2_slider_group[i].bounded_slider_y1 - 2, bltHeight = opt2_slider_group[i].bounded_slider_y2 - opt2_slider_group[i].bounded_slider_y1 + 6, 1, V_RED);
00333                 //                              vga.blt_buf(bltX, bltY, bltX+1, bltY+bltHeight);
00334 
00335                 //                              vga.use_front();
00336                 //                              font_chartsm.right_put(
00337                 //                                      RESULT_OFFSET + RESULT_LENGTH,
00338                 //                                      FIRST_LINE_OFFSET + LINE_SPACING * (i + 1),
00339                 //                                      m.format(resultValue) );
00340                 result_text[i].paint();
00341                 vga.blt_buf(
00342                     RESULT_OFFSET + RESULT_LENGTH-50,
00343                     FIRST_LINE_OFFSET + LINE_SPACING * (i + 1),
00344                     RESULT_OFFSET + RESULT_LENGTH,
00345                     FIRST_LINE_OFFSET + LINE_SPACING * (i + 1) + 16
00346                     );
00347                 //
00348             }
00349             opt2_slider_group[i].refresh();
00350         }
00351     }
00352 }
00353 
00354 //---------- End of function Optimization::report_stage_2 -----//
00355 
00356 //-------- Begin of function Optimization::detect_stage_2 -----//
00358 int Optimization::detect_stage_2() {
00359     if (stage_init_flag != 2)
00360         return 0;
00361 
00362     help.set_help(TARGET_OFFSET, SLIDER_OFFSET + FIRST_LINE_OFFSET,
00363                   TARGET_OFFSET+TARGET_WIDTH,REPORT_Y2-20,"H8.1.1.");
00364     help.set_help(TARGET_OFFSET, SLIDER_OFFSET + FIRST_LINE_OFFSET,
00365                   TARGET_OFFSET+30,REPORT_Y2-20,"H8.1.2.");
00366     help.set_help(TARGET_OFFSET+TARGET_WIDTH-30, SLIDER_OFFSET + FIRST_LINE_OFFSET,
00367                   TARGET_OFFSET+TARGET_WIDTH,REPORT_Y2-20,"H8.1.3.");
00368     help.set_help(  SEPARATOR_2, SLIDER_OFFSET + FIRST_LINE_OFFSET,
00369                     SEPARATOR_3,REPORT_Y2-20,"H8.1.4.");
00370 
00371     int i, j;
00372 
00373     vga.use_back();
00374 
00375     //  if((sys.view_mode!=MODE_YEAR_END_REPORT)
00376     //          || optimization.is_optimized[1]==1)
00377     if (mouse.in_area( SEPARATOR_1, REPORT_Y1+1+HEADING_HEIGHT,
00378                        SEPARATOR_2, REPORT_Y2 )) {
00379         for (i = 0; i < COST_RISE_POLICY_COUNT; i++)
00380             if(!finance.cost_rise_policy_array[i].required_flag)
00381                 if (opt2_slider_group[i].detect()) {
00382                     optimization.is_optimize_slider_modified[1]=0;
00383                     return 1;
00384                 }
00385     }
00386 
00387     if (mouse.single_click(SEPARATOR_2+9,REPORT_Y1+7,SEPARATOR_2+27,REPORT_Y1+25)) {
00388         String str;
00389         str  = DIR_RES;
00390         str += "SCORE";
00391 
00392         ResTxt rs;
00393         rs.init(str);
00394         image_interface.put_back(SEPARATOR_2+9,REPORT_Y1+7,"QUEST_DN");
00395         vga.blt_buf(SEPARATOR_2+9,REPORT_Y1+7,SEPARATOR_2+27,REPORT_Y1+25);
00396         sys.back_view_mode=sys.view_mode;
00397         help_if.help_textlist.topic_id=rs.locate_topic("Preference");
00398         if(help_if.help_textlist.topic_id>0) {
00399             help_if.help_textlist.add_history(help_if.help_textlist.topic_id);
00400             sys.set_view_mode(MODE_HELP_DESC);
00401             sys.redraw_all_flag = 1;
00402             audio.play_wav("BEEPS-1",audio.int_to_DsVolume(config.sound_effect_volume));
00403         }
00404         return 1;
00405     }
00406 
00407     vga.use_front();
00408 
00409     // Unlock line if the state is IMPLEMENT
00410     for (i = 0; i < COST_RISE_POLICY_COUNT; i++)
00411         if (mouse.single_click(
00412             PREF_BUTTON_OFFSET4-2,
00413             PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1)-2,
00414             PREF_BUTTON_OFFSET4 + PREF_BUTTON_WIDTH,
00415             PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1) + PREF_BUTTON_HEIGHT)) {
00416             if(finance.cost_rise_policy_array[i].applied_flag!=P_IMPLEMENT)
00417                 if(finance.cost_rise_policy_array[i].required_flag) {
00418                     finance.cost_rise_policy_array[i].required_flag=0;
00419                     opt2_slider_group[i].enable_flag=1;
00420                     opt2_slider_group[i].refresh();
00421 
00422                     //## chea 090699
00423                     finance.cost_rise_policy_array[i].reset_constraint_policy();
00424                     //## chea 090699
00425 
00426                     opt2_button_group_array[i]->push(1);
00427 
00428                     //## chea 041099 try to release the opt button
00429                     optimization.is_optimize_slider_modified[1]=0;
00430 
00431                     double *importWeight = &(finance.cost_rise_policy_array[i].import_weight);
00432                     *importWeight = OPT_MID_WEIGHT;
00433                     sys.redraw_all_flag=1;
00434                     return 1;
00435                 }
00436 
00437         }
00438 
00439     if (mouse.single_click( SEPARATOR_2, REPORT_Y1+1+HEADING_HEIGHT,
00440                             SEPARATOR_3, REPORT_Y2 )) {
00441         for (i = 0; i < COST_RISE_POLICY_COUNT; i++) {
00442 
00443             if(!finance.cost_rise_policy_array[i].required_flag)
00444                 if  ( (j = opt2_button_group_array[i]->detect()) >= 0) {
00445 
00446                     //## chea 041099 try to release the opt button
00447                     optimization.is_optimize_slider_modified[1]=0;
00448 
00449                     // Lock the line when 'r' is pressed
00450                     if(j==3) {                                // addif to reset the bounds
00451                         finance.cost_rise_policy_array[i].required_flag=1;
00452                         opt2_slider_group[i].enable_flag=0;
00453                         opt2_slider_group[i].refresh();
00454 
00455                         finance.cost_rise_policy_array[i].set_constraint_policy();
00456 
00457                         sys.redraw_all_flag=1;
00458                     }
00459 
00460                     ButtonGroup *buttonGroupPtr = opt2_button_group_array[i];
00461                     vga.use_back();
00462                     for (int k = 0; k < PREF_COUNT; k++) {
00463                         (*buttonGroupPtr)[k].body_ptr =
00464                             (void *) ((k==j)?(opt2_button_group_down_bitmap[i*PREF_COUNT+k] + 4):(opt2_button_group_up_bitmap[i*PREF_COUNT+k] + 4));
00465                     }
00466                     buttonGroupPtr->paint(buttonGroupPtr->button_pressed);
00467 
00468                     vga.blt_buf(PREF_BUTTON_OFFSET1, PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1), PREF_BUTTON_OFFSET1 + PREF_BUTTON_WIDTH, PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1) + PREF_BUTTON_HEIGHT);
00469                     vga.blt_buf(PREF_BUTTON_OFFSET2, PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1), PREF_BUTTON_OFFSET2 + PREF_BUTTON_WIDTH, PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1) + PREF_BUTTON_HEIGHT);
00470                     vga.blt_buf(PREF_BUTTON_OFFSET3, PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1), PREF_BUTTON_OFFSET3 + PREF_BUTTON_WIDTH, PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1) + PREF_BUTTON_HEIGHT);
00471                     vga.blt_buf(PREF_BUTTON_OFFSET4, PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1), PREF_BUTTON_OFFSET4 + PREF_BUTTON_WIDTH, PREF_BUTTON_OFFSET + FIRST_LINE_OFFSET + LINE_SPACING * (i + 1) + PREF_BUTTON_HEIGHT);
00472 
00473                     double *importWeight = &(finance.cost_rise_policy_array[i].import_weight);
00474 
00475                     if(j==0)
00476                         *importWeight = OPT_LOW_WEIGHT;
00477                     else if(j==1)
00478                         *importWeight = OPT_MID_WEIGHT;
00479                     else if(j==2)
00480                         *importWeight = OPT_HIGH_WEIGHT;
00481 
00482                     //                                  *importWeight = double(j + 1) / 2.0;
00483                     return 1;
00484                 }
00485         }
00486     }
00487 
00488     vga.use_back();
00489 
00490     for (i = 0; i < COST_RISE_POLICY_COUNT; i++)
00491         if(help_button_array[i].detect()) {
00492             String str;
00493             str  = DIR_RES;
00494             str += "SCORE";
00495 
00496             ResTxt rs;
00497             rs.init(str);
00498 
00499             // ## chwg1203
00500             image_interface.put_back(REPORT_X1+10,
00501                                      FIRST_LINE_OFFSET + LINE_SPACING * (i+1),"QUEST_DN");
00502             vga.blt_buf(
00503                 REPORT_X1+10,
00504                 FIRST_LINE_OFFSET + LINE_SPACING * (i+1),
00505                 REPORT_X1+30,
00506                 FIRST_LINE_OFFSET + LINE_SPACING * (i+1) + 20);
00507 
00508             sys.back_view_mode=sys.view_mode;
00509             help_if.help_textlist.topic_id=rs.locate_topic(game_str_res.opt_stage2_str(i));
00510             if(help_if.help_textlist.topic_id>0) {
00511                 help_if.help_textlist.add_history(help_if.help_textlist.topic_id);
00512                 sys.set_view_mode(MODE_HELP_DESC);
00513                 sys.redraw_all_flag = 1;
00514                 audio.play_wav("BEEPS-1",audio.int_to_DsVolume(config.sound_effect_volume));
00515             }
00516             return 1;
00517         }
00518 
00519     return 0;
00520 }
00521 
00522 //---------- End of function Optimization::detect_stage_2 -----//

Generated on Fri Aug 23 01:38:09 2002 for VirtualU by doxygen1.2.17