123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421 |
- #include <OVGA.h>
- #include <OMOUSE.h>
- #include <OIMGRES.h>
- #include <OBUTTON.h>
- #include <OPLANT.h>
- #include <OTOWN.h>
- #include <ONATION.h>
- #include <OFIRM.h>
- #include <OSYS.h>
- #include <OPOWER.h>
- #include <OGAME.h>
- #include <OWORLD.h>
- #include <OTERRAIN.h>
- MapMatrix::MapMatrix()
- {
- init( MAP_X1, MAP_Y1, MAP_X2, MAP_Y2,
- MAP_WIDTH, MAP_HEIGHT,
- MAP_LOC_WIDTH, MAP_LOC_HEIGHT, 1 );
- }
- MapMatrix::~MapMatrix()
- {
- }
- void MapMatrix::init_para()
- {
- last_map_mode = MAP_NORMAL;
- map_mode = MAP_MODE_TERRAIN;
- power_mode = 0;
- }
- void MapMatrix::paint()
- {
- disp_mode_button();
- }
- void MapMatrix::disp_mode_button(int putFront)
- {
- char* iconName;
- switch(map_mode)
- {
- case MAP_MODE_TERRAIN:
- iconName = "MAP-1";
- break;
- case MAP_MODE_POWER:
- if( power_mode )
- iconName = "MAP-2B";
- else
- iconName = "MAP-2A";
- break;
- case MAP_MODE_SPOT:
- iconName = "MAP-3";
- break;
- default:
- err_here();
- }
- if( putFront )
- image_button.put_front( 579, 2, iconName, 1 );
- else
- image_button.put_back( 579, 2, iconName, 1 );
- }
- int MapMatrix::detect()
- {
- int x=586;
- #define MAP_MODE_BUTTON_WIDTH 40
- for( int i=0 ; i<MAP_MODE_COUNT ; i++, x+=MAP_MODE_BUTTON_WIDTH )
- {
- if( mouse.single_click( x, 7, x+MAP_MODE_BUTTON_WIDTH-1, 46 ) )
- {
- toggle_map_mode(i);
- return 1;
- }
- }
-
- return detect_area();
- }
- void MapMatrix::draw()
- {
- draw_map();
-
- if( save_image_buf )
- {
- vga_back.read_bitmap( image_x1, image_y1, image_x2, image_y2, save_image_buf );
- just_drawn_flag = 1;
- }
- }
- void MapMatrix::draw_map()
- {
- char* writePtr = vga_back.buf_ptr() + vga_back.buf_pitch() * image_y1 + image_x1;
- int lineRemain = vga_back.buf_pitch() - image_width;
- int x, y;
- Location* locPtr = world.loc_matrix;
- char* nationColorArray = nation_array.nation_power_color_array;
-
- sys.yield();
- int shadowMapDist = max_x_loc + 1;
- int tileYOffset;
- char tilePixel;
- Location* northWestPtr;
- switch(map_mode)
- {
- case MAP_MODE_TERRAIN:
- for( y=image_y1 ; y<=image_y2 ; y++, writePtr+=lineRemain )
- {
- tileYOffset = (y & TERRAIN_TILE_Y_MASK) * TERRAIN_TILE_WIDTH;
- for( x=image_x1 ; x<=image_x2 ; x++, writePtr++, locPtr++ )
- {
- if( locPtr->explored() )
- {
- if( locPtr->fire_str() > 0)
- *writePtr = (char) FIRE_COLOR;
- else if( locPtr->is_plant() )
- *writePtr = plant_res.plant_map_color;
- else
- {
- tilePixel = terrain_res.get_map_tile(locPtr->terrain_id)[tileYOffset + (x & TERRAIN_TILE_X_MASK)];
- if( y == image_y1 || x == image_x1)
- {
- *writePtr = tilePixel;
- }
- else
- {
- northWestPtr = locPtr - shadowMapDist;
- if( terrain_res[locPtr->terrain_id]->average_type >=
- terrain_res[northWestPtr->terrain_id]->average_type)
- {
- *writePtr = tilePixel;
- }
- else
- {
- *writePtr = (char) VGA_GRAY;
- }
- }
- }
- }
- else
- {
- *writePtr = UNEXPLORED_COLOR;
- }
- }
- }
- break;
- case MAP_MODE_SPOT:
- for( y=image_y1 ; y<=image_y2 ; y++, writePtr+=lineRemain )
- {
- for( x=image_x1 ; x<=image_x2 ; x++, writePtr++, locPtr++ )
- {
- if( locPtr->explored() )
- {
- if( locPtr->sailable() )
- *writePtr = (char) 0x32;
- else if( locPtr->has_hill() )
- *writePtr = (char) V_BROWN;
- else
- *writePtr = (char) VGA_GRAY+10;
- }
- else
- {
- *writePtr = UNEXPLORED_COLOR;
- }
- }
- }
- break;
- case MAP_MODE_POWER:
- for( y=image_y1 ; y<=image_y2 ; y++, writePtr+=lineRemain )
- {
- for( x=image_x1 ; x<=image_x2 ; x++, writePtr++, locPtr++ )
- {
- if( locPtr->explored() )
- {
- if( locPtr->sailable() )
- *writePtr = (char) 0x32;
- else if( locPtr->has_hill() )
- *writePtr = (char) V_BROWN;
- else if( locPtr->is_plant() )
- *writePtr = (char) V_DARK_GREEN;
- else
- *writePtr = nationColorArray[locPtr->power_nation_recno];
- }
- else
- {
- *writePtr = UNEXPLORED_COLOR;
- }
- }
- }
- break;
- }
- sys.yield();
- }
- void MapMatrix::disp()
- {
- if( !just_drawn_flag )
- {
- if( save_image_buf && map_mode==last_map_mode )
- vga_back.put_bitmap( image_x1, image_y1, save_image_buf );
- else
- {
- draw();
- last_map_mode = map_mode;
- }
- }
- just_drawn_flag=0;
- }
- void MapMatrix::draw_square()
- {
-
- static int squareFrameCount=0, squareFrameStep=1;
- int x1=image_x1+(cur_x_loc-top_x_loc)*loc_width;
- int y1=image_y1+(cur_y_loc-top_y_loc)*loc_height;
- int x2=x1+cur_cargo_width *loc_width-1;
- int y2=y1+cur_cargo_height*loc_height-1;
- vga_back.rect( x1, y1, x2, y2, 1, VGA_YELLOW + squareFrameCount );
- squareFrameCount += squareFrameStep;
- if( squareFrameCount==0 )
- squareFrameStep = 1;
- if( squareFrameCount==6 )
- squareFrameStep = -1;
- }
- void MapMatrix::toggle_map_mode(int modeId)
- {
- if( map_mode == modeId )
- {
- if( map_mode == MAP_MODE_POWER )
- power_mode = !power_mode;
- }
- else
- {
- map_mode = modeId;
- }
- disp_mode_button(1);
- refresh();
- }
- int MapMatrix::detect_area()
- {
- if( !mouse.press_area( image_x1,image_y1,image_x2,image_y2, 2 ) &&
- !mouse.any_click( image_x1,image_y1,image_x2,image_y2, 2 ) )
- {
- return 0;
- }
- int rc = 0;
- int lastXLoc = cur_x_loc;
- int lastYLoc = cur_y_loc;
-
- if( mouse.single_click( image_x1,image_y1,image_x2,image_y2 ) ||
- mouse.press_area( image_x1,image_y1,image_x2,image_y2, LEFT_BUTTON ) )
- {
- int xLoc = top_x_loc + (mouse.cur_x-image_x1)/loc_width;
- int yLoc = top_y_loc + (mouse.cur_y-image_y1)/loc_height;
-
- cur_x_loc = xLoc - world.zoom_matrix->disp_x_loc/2;
- cur_y_loc = yLoc - world.zoom_matrix->disp_y_loc/2;
- if( !valid_cur_box() )
- disp();
- rc=1;
- }
-
- if( cur_x_loc != lastXLoc || cur_y_loc != lastYLoc )
- {
- world.zoom_matrix->top_x_loc = cur_x_loc;
- world.zoom_matrix->top_y_loc = cur_y_loc;
- sys.zoom_need_redraw = 1;
- }
- return rc;
- }
|