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

Password:

OGAMGEN.CPP Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

OGAMGEN.CPP

Go to the documentation of this file.
00001 //Filename    : OGAMGEN.CPP
00002 //Description : Game Generator
00003 
00004 #include <OVGA.H>
00005 #include <OBOX.H>
00006 #include <OFONT.H>
00007 #include <OMOUSE.H>
00008 #include <OBUTTON.H>
00009 #include <OLISTBOX.H>
00010 #include <OPOWER.H>
00011 #include <OWORLD.H>
00012 #include <OITEMRES.H>
00013 #include <OPERSON.H>
00014 #include <OGRPRES.H>
00015 #include <OGAMESET.H>
00016 #include <OGAME.H>
00017 #include <OHELPIF.H>
00018 
00019 //--------- Define constant ------------//
00020 
00021 enum {
00022     GEN_WIN_X1 = 45,
00023     GEN_WIN_Y1 = 30,
00024     GEN_WIN_X2 = 595,
00025     GEN_WIN_Y2 = 445
00026 };
00027 
00028 enum {
00029     GEN_HEADER_X1 = GEN_WIN_X1+10,
00030     GEN_HEADER_Y1 = GEN_WIN_Y1+10,
00031     GEN_HEADER_X2 = GEN_HEADER_X1+363,
00032     GEN_HEADER_Y2 = GEN_WIN_Y1+107
00033 };
00034 
00035 enum {
00036     GEN_TYPE_X1 = GEN_HEADER_X2+10,
00037     GEN_TYPE_Y1 = GEN_HEADER_Y1,
00038     GEN_TYPE_X2 = GEN_WIN_X2-10,
00039     GEN_TYPE_Y2 = GEN_HEADER_Y2
00040 };
00041 
00042 enum {
00043     GEN_BODY_X1 = GEN_WIN_X1+10,
00044     GEN_BODY_Y1 = GEN_HEADER_Y2+10,
00045     GEN_BODY_X2 = GEN_WIN_X2-10,
00046     GEN_BODY_Y2 = GEN_WIN_Y2-32
00047 };
00048 
00049 //-------- Define game settings ---------//
00050 
00051 enum { OPTION_TYPE_NUM = 2 };
00052 
00053 static char* option_des_array[] = {
00054     "Institution",                                  // 1
00055     "Characteristics",                              // 2
00056 };
00057 
00058 static char* screen_code_array[] = {
00059     "G_INST",                                       // 1
00060     "G_CHAR",                                       // 2
00061 };
00062 
00063 static short  normal_option_array[] = { 1, 2 };
00064 static short  disp_option_array[]   = { 1, 2 };
00065 
00066 //-------- Define static variables ---------//
00067 
00068 static Button  button_reset, button_ok, button_cancel;
00069 static ListBox type_list;
00070 static short   gen_mode;
00071 static short   option_type;
00072 
00073 static void    disp_type_rec(int,int,int,int);
00074 
00075 //------- Begin of function Game::generator -------//
00085 int Game::generator(int genMode) {
00086     //----- the settings available to change -----//
00087 
00088     int optionNum;
00089 
00090     switch(genMode) {
00091     case GEN_MODE_NEW:
00092         avail_option_array = normal_option_array;
00093         optionNum = 2;
00094         break;
00095 
00096     case GEN_MODE_DISP:
00097         avail_option_array = disp_option_array;
00098         optionNum = 2;
00099         break;
00100     }
00101 
00102     gen_mode = genMode;
00103 
00104   //--------- paint window -------------//
00105 
00106     power.open_report( GEN_WIN_X1, GEN_WIN_Y1, GEN_WIN_X2, GEN_WIN_Y2 );
00107 
00108     //---------- Window Title ------------//
00109 
00110     vga.d3_panel_down( GEN_HEADER_X1, GEN_HEADER_Y1, GEN_TYPE_X1-10, GEN_HEADER_Y2, 2 );
00111 
00112     icon_title.put( GEN_HEADER_X1+2, GEN_HEADER_Y1+2, "GAMESET" );
00113 
00114   //-------- option type selection --------------//
00115 
00116     type_list.init(GEN_TYPE_X1, GEN_TYPE_Y1, GEN_TYPE_X2, GEN_TYPE_Y2,
00117                    optionNum, disp_type_rec );
00118 
00119     type_list.open(option_type);
00120 
00121   //---------- create buttons --------------//
00122 
00123     if( gen_mode==GEN_MODE_DISP ) {
00124         button_ok.paint_text( GEN_WIN_X1+250, GEN_WIN_Y2-25, "Ok" );
00125     }
00126     else {
00127         int x = GEN_WIN_X1 + 168;
00128 
00129         button_reset.paint_text( x+53 , GEN_WIN_Y2-25, "Reset" );
00130 
00131         button_ok     .paint_text( x+105, GEN_WIN_Y2-25, "Ok"      );
00132         button_cancel .paint_text( x+145, GEN_WIN_Y2-25, "Cancel"  );
00133     }
00134 
00135     //------------ detect loop ---------------//
00136 
00137     int rc=1;
00138 
00139     gen_disp();
00140 
00141     while( !button_ok.detect(KEY_RETURN) ) {
00142         mouse.get_event();
00143 
00144         //--------- detect option type ----------//
00145 
00146         if( type_list.detect() > 0 ) {
00147             option_type = type_list.recno();
00148             gen_disp();
00149         }
00150 
00151         //---------- detect controls ------------//
00152 
00153         if( gen_mode == GEN_MODE_DISP ) {             // if display only
00154             if( mouse.single_click(1) )                 // right button to quit
00155                 break;
00156         }
00157         else {
00158             //-------- detect option body ---------//
00159 
00160             gen_detect();
00161 
00162             //-------- detect cancel button ---------//
00163 
00164             if( button_cancel.detect(KEY_ESC) ) {
00165                 rc = 0;
00166                 break;
00167             }
00168 
00169             //---- set all game settings to their default values ----//
00170 
00171             if( button_reset.detect() ) {
00172                 if( box.ask( "Reset all settings to their default values ?" ) ) {
00173                     default_setting();
00174                     gen_disp();
00175                 }
00176             }
00177         }
00178     }
00179 
00180     //------------------------------------------------//
00181 
00182     power.close_report();
00183 
00184     return rc;
00185 }
00186 
00187 //-------- End of function Game::generator -------//
00188 
00189 //------- Begin of function Game::gen_disp -------//
00193 void Game::gen_disp(int refreshFlag) {
00194     // 1 use texture background
00195     if( refreshFlag==INFO_REPAINT && avail_option_array[option_type-1]!=1 )
00196         vga.d3_panel_down( GEN_BODY_X1, GEN_BODY_Y1, GEN_BODY_X2, GEN_BODY_Y2, 2, 1, "T_GAMGEN" );
00197 
00198     switch( avail_option_array[option_type-1] ) {
00199     case 1:                                       // Institution
00200         // 1-display and generate the map, rather than only generate it
00201         gen_institution( GEN_BODY_X1, GEN_BODY_Y1, GEN_BODY_X2, GEN_BODY_Y2, 1 );
00202         break;
00203 
00204     case 2:                                       // Characteristics
00205         gen_characteristics( GEN_BODY_X1, GEN_BODY_Y1, GEN_BODY_X2, GEN_BODY_Y2, gen_mode );
00206         break;
00207     }
00208 }
00209 
00210 //-------- End of function Game::gen_disp -------//
00211 
00212 //------- Begin of function Game::gen_detect -------//
00214 void Game::gen_detect() {
00215     switch( avail_option_array[option_type-1] ) {
00216     case 1:                                       // Institution
00217         gen_institution_detect();
00218         break;
00219 
00220     case 2:                                       // Characteristics
00221         gen_characteristics_detect();
00222         break;
00223     }
00224 }
00225 
00226 //-------- End of function Game::gen_detect -------//
00227 
00228 //-------- Begin of static function disp_type_rec --------//
00229 //
00230 static void disp_type_rec(int recNo, int x1, int y1, int x2) {
00231     int optionId = avail_option_array[recNo-1];
00232 
00233     font_std.put( x1, y1, option_des_array[optionId-1], -1, 0, x2 );
00234 }
00235 
00236 //----------- End of static function disp_type_rec -----------//

Generated on Fri Aug 23 01:37:43 2002 for VirtualU by doxygen1.2.17