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

Password:

Omatrix.h Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Omatrix.h

Go to the documentation of this file.
00001 //Filename   : OMATRIX.H
00002 //Description: Header file for the class Matrix
00003 
00004 #ifndef __OMATRIX_H
00005 #define __OMATRIX_H
00006 
00007 //------- Define constant for object_type; for DisplaySort::object_type --------//
00008 
00009 enum {
00010     OBJECT_FIRM,
00011     OBJECT_PLANT,
00012     OBJECT_VEHICLE,
00013     OBJECT_SPRITE,
00014 };
00015 
00016 //---------- Define struct DisplaySort ----------//
00017 
00019 struct DisplaySort {
00020     char  object_type;
00021     short object_recno;
00022     short depth;
00023     short loc_x,loc_y;
00024     short abs_x1, abs_x2, abs_y1, abs_y2;
00025     char* bitmap_ptr;
00026 };
00027 
00028 //--- Define constant values for Location::loc_type ---//
00029 
00030 enum {
00031     LOC_EMPTY,
00032     LOC_IS_FIRM,
00033     LOC_IS_ROAD,
00034     LOC_IS_ROAD_SUB,                                // the top-right, bottom-left & bottom-right of the road
00035     LOC_IS_PLANT,
00036     LOC_IS_SPRITE,
00037 };
00038 
00039 enum {
00040     LOCATE_WALK_LAND = 0x01,
00041     //LOCATE_HAS_SPRITE = 0x02,
00042 };
00043 
00044 //----------- Define class Location -----//
00045 
00049 struct Location {
00050 public:
00051     unsigned short loc_flag;
00052     char    loc_type;
00053     short    cargo_recno;
00054     short   extra_para;                           //char                extra_para;
00055     char    terrain_id;
00056 
00057 public:
00058     int   is_empty()            { return loc_type == LOC_EMPTY; }
00059     void    set_terrain(int terrainId)  { terrain_id = terrainId; set_walkable_on(); }
00060 
00061     //---------- for sprite animation functions ---------//
00062     int   is_walkable() {                         //  is_road() || is_road_sub(); }
00063         return loc_flag & LOCATE_WALK_LAND;
00064     }
00065     void    set_walkable_on()   { loc_flag |= LOCATE_WALK_LAND; }
00066     void    set_walkable_off()  { loc_flag &= ~LOCATE_WALK_LAND; }
00067 
00068     //---------- firm functions ---------//
00069 
00070     void    set_firm(int firmRecno);
00071     void    remove_firm();
00072 
00073     int   is_firm()   { return loc_type == LOC_IS_FIRM; }
00074     int   firm_recno()  { return cargo_recno; }
00075 
00076     //--------- plant functions ---------//
00077 
00078     int     is_plant()            { return loc_type==LOC_IS_PLANT; }
00079     void    set_plant(int plantId, int offsetX, int offsetY);
00080     void    remove_plant();
00081 
00082     int   plant_id()            { if( is_plant() ) return extra_para; else return 0; }
00083     int   plant_inner_x() {                       // a percentage from 0% to 100%
00084         return cargo_recno & 0xFF;
00085     }
00086     int   plant_inner_y() {                       // a percentage from 0% to 100%
00087         return cargo_recno >> 8;
00088     }
00089 
00090     //---------- road functions ---------//
00091 
00092     int   is_road()           { return loc_type == LOC_IS_ROAD; }
00093     int   is_road_sub()         { return loc_type == LOC_IS_ROAD_SUB; }
00094     void    set_road(int roadId);
00095     void    set_road_sub()          { loc_type=LOC_IS_ROAD_SUB; set_walkable_on();}
00096     void    remove_road();
00097     //TO? add remove_road_sub();
00098     int   road_id()           { if( is_road() ) return cargo_recno; else return 0; }
00099 
00100     //---------- sprite functions ---------//
00101 
00102     void    set_sprite(int spriteRecno);
00103     void    remove_sprite();
00104 
00105     int   has_sprite()    { return is_walkable() && extra_para; }
00106     int   sprite_recno()    { if ( has_sprite() ) return extra_para; else return 0; }
00107 };
00108 
00109 //--------- define class Matrix ------------//
00110 
00111 class DynArray;
00112 
00115 class Matrix {
00116 public:
00117     int      max_x_loc, max_y_loc;
00118     Location *loc_matrix;
00119     int      loc_width, loc_height;
00120 
00121     int      top_x_loc, top_y_loc;                // the top left location of current zoom window
00122     int   abs_top_x, abs_top_y;
00123     int      disp_x_loc, disp_y_loc;              // calculated in Matrix()
00124 
00125     int      win_x1, win_y1, win_x2, win_y2;
00126     int   win_width, win_height;
00127 
00128     char    save_image_flag;
00129     short*  save_image_buf;
00130     char   is_image_buf_latest;
00131 
00132     char    zoom_level;                           // any of ZOOM_SMALL, ZOOM_MEDIUM, or ZOOM_LARGE
00133 
00134     static DynArray disp_sort_array;
00135 
00136 public:
00137     Matrix();
00138     ~Matrix();
00139 
00140     void        init(int winX1, int winY1, int winX2, int winY2,
00141                      int locWidth, int locHeight, Location* locMatrix,
00142                      int maxXLoc, int maxYLoc, int zoomLevel, char saveImageFlag=0);
00143 
00144     virtual void  draw_all();                     // draw everything on the map
00145     virtual void  draw_update();                  // called each frame, only draw portions that need updating
00146     virtual int   detect()    { return 0; }
00147 
00148     void        reset_image_buf()   { is_image_buf_latest=0; }
00149 
00150     void        put_center_text(int x, int y, char* str);
00151 
00152     void        set_top_loc(int topXLoc, int topYLoc);
00153     void        loc_to_abs_top_left(int& absX, int& absY, int locX, int locY);
00154     void        loc_to_abs_center_left(int& absX, int& absY, int locX, int locY);
00155     void        loc_to_abs_bottom_right(int& absX, int& absY, int locX, int locY);
00156     void        abs_to_loc(int& locX, int& locY, int absX, int absY);
00157 
00158 protected:
00159 #if(GAME_VERSION>=200)
00160     virtual void  draw_text();                    // called by draw_all
00161 #endif
00162 
00163 private:
00164     void        draw_objects();
00165     void        draw_objects_now(DynArray* dispSortArray);
00166 
00167     void        draw_terrain(int xLoc, int yLoc, int terrainId);
00168     void        draw_plant(int xLoc, int yLoc, int terrainId);
00169     void        draw_bitmap(int absX, int absY, char* bmpPtr);
00170 };
00171 
00172 //------------------------------------------//
00173 #endif

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