/* * Seven Kingdoms: Ancient Adversaries * * Copyright 1997,1998 Enlight Software Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ //Filename : OWALLRES.CPP //Description : Wall resource object //Ownership : Gilbert #include #include #include #include #include #include #include #include //---------- #define constant ------------// #define WALL_DB "WALL" //------- Begin of function WallRes::WallRes -----------// WallRes::WallRes() { init_flag=0; selected_x_loc = -1; selected_y_loc = -1; } //--------- End of function WallRes::WallRes -----------// //---------- Begin of function WallRes::init -----------// // // This function must be called after a map is generated. // void WallRes::init() { deinit(); //----- open wall material bitmap resource file -------// String str; str = DIR_RES; str += "I_WALL.RES"; res_bitmap.init_imported(str,1); // 1-read all into buffer //------- load database information --------// load_wall_info(); init_flag=1; } //---------- End of function WallRes::init -----------// //---------- Begin of function WallRes::deinit -----------// void WallRes::deinit() { if( init_flag ) { mem_del(wall_info_array); mem_del(wall_index); init_flag=0; } } //---------- End of function WallRes::deinit -----------// //------- Begin of function WallRes::load_wall_info -------// // void WallRes::load_wall_info() { WallRec *wallRec; WallInfo *wallInfo; int i; long bitmapOffset; max_wall_id = 0; //---- read in wall count and initialize wall info array ----// Database *dbWall = game_set.open_db(WALL_DB); // only one database can be opened at a time, so we read FIRM.DBF first wall_count = (short) dbWall->rec_count(); wall_info_array = (WallInfo*) mem_add( sizeof(WallInfo)*wall_count ); memset( wall_info_array, 0, sizeof(WallInfo) * wall_count ); //---------- read in WALL.DBF ---------// for( i=0 ; iread(i+1); wallInfo = wall_info_array+i; wallInfo->wall_id = m.atoi( wallRec->wall_id, wallRec->WALL_ID_LEN); wallInfo->flags = 0; if( wallRec->gate_flag == 'Y' || wallRec->gate_flag == 'y') wallInfo->set_gate(); if( wallRec->trans_flag == 'Y' || wallRec->trans_flag == 'y') wallInfo->set_trans(); wallInfo->offset_x = m.atoi( wallRec->offset_x, wallRec->OFFSET_LEN); wallInfo->offset_y = m.atoi( wallRec->offset_y, wallRec->OFFSET_LEN); wallInfo->loc_off_x = m.atoi( wallRec->loc_off_x, wallRec->LOC_OFF_LEN); wallInfo->loc_off_y = m.atoi( wallRec->loc_off_y, wallRec->LOC_OFF_LEN); wallInfo->draw_wall_id = m.atoi( wallRec->draw_wall, wallRec->WALL_ID_LEN); memcpy( &bitmapOffset, wallRec->bitmap_ptr, sizeof(long) ); wallInfo->bitmap_ptr = res_bitmap.read_imported(bitmapOffset); if( wallInfo->wall_id > max_wall_id) max_wall_id = wallInfo->wall_id; } // --------- build wall_index ---------// if( max_wall_id > 0) { wall_index = (WallInfo **) mem_add(sizeof(WallInfo *) * max_wall_id); memset( wall_index, 0, sizeof(WallInfo *) * max_wall_id); for( i=0 ; iwall_abs_hit_point(); str += " / 100"; font_san.field( x, y, "Hit Points", x+80, str, INFO_X2-4, refreshFlag ); } //--------- End of function WallRes::disp_info ---------// //---------- Begin of function WallRes::operator[] -----------// WallInfo* WallRes::operator[](int wallId) { err_if( wallId<1 || wallId>max_wall_id ) err_now( "WallRes::operator[]" ); return wall_index[wallId-1]; } //------------ End of function WallRes::operator[] -----------// //------- Begin of function WallInfo::draw -----------// // // Draw the current wall on the map // void WallInfo::draw(int xLoc, int yLoc, char *remapTbl) { //----------- calculate absolute positions ------------// //-------- check if the wall is within the view area --------// int x1 = xLoc*ZOOM_LOC_WIDTH + offset_x - World::view_top_x; int x2 = x1 + bitmap_width() -1; if( x2 < 0 || x1 >= ZOOM_WIDTH ) // out of the view area, not even a slight part of it appears in the view area return; int y1 = yLoc*ZOOM_LOC_HEIGHT +offset_y - World::view_top_y; int y2 = y1 + bitmap_height() -1; if( y2 < 0 || y1 >= ZOOM_HEIGHT ) return; //------- decide which approach to use for displaying -----// //---- only portion of the sprite is inside the view area ------// if( x1 < 0 || x2 >= ZOOM_WIDTH || y1 < 0 || y2 >= ZOOM_HEIGHT ) { if(is_trans()) { if( remapTbl) vga_back.put_bitmap_area_trans_remap( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr, max(0,x1)-x1, max(0,y1)-y1, min(ZOOM_WIDTH-1,x2)-x1, min(ZOOM_HEIGHT-1,y2)-y1, remapTbl); else vga_back.put_bitmap_area_trans( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr, max(0,x1)-x1, max(0,y1)-y1, min(ZOOM_WIDTH-1,x2)-x1, min(ZOOM_HEIGHT-1,y2)-y1); } else { if( remapTbl) vga_back.put_bitmap_area_remap( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr, max(0,x1)-x1, max(0,y1)-y1, min(ZOOM_WIDTH-1,x2)-x1, min(ZOOM_HEIGHT-1,y2)-y1, remapTbl); else vga_back.put_bitmap_area( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr, max(0,x1)-x1, max(0,y1)-y1, min(ZOOM_WIDTH-1,x2)-x1, min(ZOOM_HEIGHT-1,y2)-y1); } } //---- the whole sprite is inside the view area ------// else { if(is_trans() ) { if( remapTbl) vga_back.put_bitmap_trans_remap( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr, remapTbl); else vga_back.put_bitmap_trans( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr); } else { if( remapTbl) vga_back.put_bitmap_remap( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr, remapTbl ); else vga_back.put_bitmap( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr); } } } //--------- End of function WallInfo::draw -----------// //------- Begin of function WallInfo::draw_at -----------// // // Draw the wall on the zoom map, given the exact pixel position to put // the bitmap. // // absBaseX, absBaseY - the absolute base (center-bottom) coordination // of the building. // // Draw the current plant on the map // void WallInfo::draw_at(int absBaseX, int absBaseY, char *remapTbl) { //-------- check if the wall is within the view area --------// int x1 = absBaseX - World::view_top_x; int x2 = x1 + bitmap_width() -1; if( x2 < 0 || x1 >= ZOOM_WIDTH ) // out of the view area, not even a slight part of it appears in the view area return; int y1 = absBaseY - World::view_top_y; int y2 = y1 + bitmap_height() -1; if( y2 < 0 || y1 >= ZOOM_HEIGHT ) return; //------- decide which approach to use for displaying -----// //---- only portion of the sprite is inside the view area ------// if( x1 < 0 || x2 >= ZOOM_WIDTH || y1 < 0 || y2 >= ZOOM_HEIGHT ) { // no put_bitmap_area_remap if(is_trans()) { if( remapTbl) vga_back.put_bitmap_area_trans_remap( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr, max(0,x1)-x1, max(0,y1)-y1, min(ZOOM_WIDTH-1,x2)-x1, min(ZOOM_HEIGHT-1,y2)-y1, remapTbl); else vga_back.put_bitmap_area_trans( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr, max(0,x1)-x1, max(0,y1)-y1, min(ZOOM_WIDTH-1,x2)-x1, min(ZOOM_HEIGHT-1,y2)-y1); } else { if( remapTbl) vga_back.put_bitmap_area_remap( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr, max(0,x1)-x1, max(0,y1)-y1, min(ZOOM_WIDTH-1,x2)-x1, min(ZOOM_HEIGHT-1,y2)-y1, remapTbl); else vga_back.put_bitmap_area( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr, max(0,x1)-x1, max(0,y1)-y1, min(ZOOM_WIDTH-1,x2)-x1, min(ZOOM_HEIGHT-1,y2)-y1); } } //---- the whole sprite is inside the view area ------// else { if(is_trans() ) { if( remapTbl) vga_back.put_bitmap_trans_remap( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr, remapTbl); else vga_back.put_bitmap_trans( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr); } else { if( remapTbl) vga_back.put_bitmap_remap( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr, remapTbl ); else vga_back.put_bitmap( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr); } } } //--------- End of function WallInfo::draw_at -----------//