123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684 |
- /*
- * 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 <http://www.gnu.org/licenses/>.
- *
- */
- // Filename : OROCKRES.CPP
- // Description : rock resource
- // Owner : Gilbert
- #include <OROCKRES.h>
- #include <OGAMESET.h>
- #include <OMISC.h>
- #include <OWORLD.h>
- #include <OVGABUF.h>
- #include <OTERRAIN.h>
- #include <OCONFIG.h>
- #include <string.h>
- // ---------- Define constant ------------//
- //#define ROCK_DB "ROCK"
- //#define ROCK_BLOCK_DB "ROCKBLK"
- //#define ROCK_BITMAP_DB "ROCKBMP"
- //#define ROCK_ANIM_DB "ROCKANIM"
- // one rock is composed of one or many rock blocks
- // each rock block has one or many frames
- // each rock has its own animation sequence
- // any animation sequence can change to one of the two sequences
- // ------------ begin of function RockRes::RockRes -----------//
- RockRes::RockRes()
- {
- init_flag = 0;
- rock_info_count = 0;
- rock_info_array = NULL;
- rock_block_count = 0;
- rock_block_array = NULL;
- rock_bitmap_count = 0;
- rock_bitmap_array = NULL;
- rock_anim_count = 0;
- rock_anim_array = NULL;
- }
- // ------------ end of function RockRes::RockRes -----------//
- // ------------ begin of function RockRes::~RockRes -----------//
- RockRes::~RockRes()
- {
- deinit();
- }
- // ------------ end of function RockRes::~RockRes -----------//
- // ------------ begin of function RockRes::init -----------//
- void RockRes::init()
- {
- deinit();
- //----- open rock bitmap resource file -------//
- String str;
- str = DIR_RES;
- // str += "I_ROCK.RES";
- str += "I_ROCK";
- str += config.terrain_set;
- str += ".RES";
- res_bitmap.init_imported(str,1); // 1-read all into buffer
- //------- load database information --------//
- load_info();
- load_bitmap_info();
- load_block_info();
- load_anim_info();
- //----------------------------------------//
- init_flag=1;
- }
- // ------------ end of function RockRes::init -----------//
- // ------------ begin of function RockRes::deinit -----------//
- void RockRes::deinit()
- {
- if(init_flag)
- {
- mem_del(rock_info_array);
- mem_del(rock_block_array);
- mem_del(rock_bitmap_array);
- mem_del(rock_anim_array);
- rock_info_count = 0;
- rock_block_count = 0;
- rock_bitmap_count = 0;
- rock_anim_count = 0;
- res_bitmap.deinit();
- init_flag = 0;
- }
- }
- // ------------ end of function RockRes::deinit -----------//
- // ------------ begin of function RockRes::load_info -----------//
- void RockRes::load_info()
- {
- RockRec *rockRec;
- RockInfo *rockInfo;
- int i;
- //---- read in rock count and initialize rock info array ----//
- String rockDbName;
- rockDbName = DIR_RES;
- rockDbName += "ROCK";
- rockDbName += config.terrain_set;
- rockDbName += ".RES";
- Database rockDbObj(rockDbName, 1);
- //Database *dbRock = game_set.open_db(ROCK_DB); // only one database can be opened at a time, so we read ROCK.DBF first
- Database *dbRock = &rockDbObj;
- rock_info_count = (short) dbRock->rec_count();
- rock_info_array = (RockInfo*) mem_add( sizeof(RockInfo)*rock_info_count );
- memset( rock_info_array, 0, sizeof(RockInfo) * rock_info_count );
- //---------- read in ROCK.DBF ---------//
- for( i=0 ; i<rock_info_count ; i++ )
- {
- rockRec = (RockRec*) dbRock->read(i+1);
- rockInfo = rock_info_array+i;
- m.rtrim_fld( rockInfo->rock_name, rockRec->rock_id, rockRec->ROCKID_LEN );
- rockInfo->rock_type = rockRec->rock_type;
- rockInfo->loc_width = m.atoi(rockRec->loc_width, rockRec->LOC_LEN);
- rockInfo->loc_height = m.atoi(rockRec->loc_height, rockRec->LOC_LEN);
- // ###### begin Gilbert 2/5 ##########//
- if( rockRec->terrain_1 == 0 || rockRec->terrain_1 == ' ')
- rockInfo->terrain_1 = 0;
- else
- rockInfo->terrain_1 = TerrainRes::terrain_code(rockRec->terrain_1);
- if( rockRec->terrain_2 == 0 || rockRec->terrain_2 == ' ')
- rockInfo->terrain_2 = 0;
- else
- rockInfo->terrain_2 = TerrainRes::terrain_code(rockRec->terrain_2);
- // ###### end Gilbert 2/5 ##########//
- rockInfo->first_anim_recno = m.atoi(rockRec->first_anim_recno, rockRec->RECNO_LEN);
- if(rockInfo->first_anim_recno)
- rockInfo->max_frame = m.atoi(rockRec->max_frame, rockRec->MAX_FRAME_LEN);
- else
- rockInfo->max_frame = 1; // unanimated, rock anim recno must be -1
- rockInfo->first_block_recno = 0;
- }
- }
- // ------------ end of function RockRes::load_info -----------//
- // ------------ begin of function RockRes::load_bitmap_info -----------//
- void RockRes::load_bitmap_info()
- {
- RockBitmapRec *rockBitmapRec;
- RockBitmapInfo *rockBitmapInfo;
- int i;
- //---- read in rock count and initialize rock info array ----//
- String rockDbName;
- rockDbName = DIR_RES;
- rockDbName += "ROCKBMP";
- rockDbName += config.terrain_set;
- rockDbName += ".RES";
- Database rockDbObj(rockDbName, 1);
- // Database *dbRock = game_set.open_db(ROCK_BITMAP_DB); // only one database can be opened at a time, so we read ROCK.DBF first
- Database *dbRock = &rockDbObj;
- rock_bitmap_count = (short) dbRock->rec_count();
- rock_bitmap_array = (RockBitmapInfo*) mem_add( sizeof(RockBitmapInfo)*rock_bitmap_count );
- memset( rock_bitmap_array, 0, sizeof(RockBitmapInfo) * rock_bitmap_count );
- //---------- read in ROCKBMP.DBF ---------//
- for( i=0 ; i<rock_bitmap_count ; i++ )
- {
- rockBitmapRec = (RockBitmapRec*) dbRock->read(i+1);
- rockBitmapInfo = rock_bitmap_array+i;
- rockBitmapInfo->loc_x = m.atoi(rockBitmapRec->loc_x, rockBitmapRec->LOC_LEN);
- rockBitmapInfo->loc_y = m.atoi(rockBitmapRec->loc_y, rockBitmapRec->LOC_LEN);
- rockBitmapInfo->frame = m.atoi(rockBitmapRec->frame, rockBitmapRec->FRAME_NO_LEN);
- long bitmapOffset;
- memcpy( &bitmapOffset, rockBitmapRec->bitmap_ptr, sizeof(long) );
- rockBitmapInfo->bitmap_ptr = res_bitmap.read_imported(bitmapOffset);
- }
- }
- // ------------ end of function RockRes::load_bitmap_info -----------//
- // ------------ begin of function RockRes::load_block_info -----------//
- void RockRes::load_block_info()
- {
- RockBlockRec *rockBlockRec;
- RockBlockInfo *rockBlockInfo;
- int i;
- //---- read in rock count and initialize rock info array ----//
- String rockDbName;
- rockDbName = DIR_RES;
- rockDbName += "ROCKBLK";
- rockDbName += config.terrain_set;
- rockDbName += ".RES";
- Database rockDbObj(rockDbName, 1);
- // Database *dbRock = game_set.open_db(ROCK_BLOCK_DB); // only one database can be opened at a time, so we read ROCK.DBF first
- Database *dbRock = &rockDbObj;
- rock_block_count = (short) dbRock->rec_count();
- rock_block_array = (RockBlockInfo*) mem_add( sizeof(RockBlockInfo)*rock_block_count );
- memset( rock_block_array, 0, sizeof(RockBlockInfo) * rock_block_count );
- //---------- read in ROCKBLK.DBF ---------//
- for( i=0 ; i<rock_block_count ; i++ )
- {
- rockBlockRec = (RockBlockRec*) dbRock->read(i+1);
- rockBlockInfo = rock_block_array+i;
- rockBlockInfo->loc_x = m.atoi(rockBlockRec->loc_x, rockBlockRec->LOC_LEN);
- rockBlockInfo->loc_y = m.atoi(rockBlockRec->loc_y, rockBlockRec->LOC_LEN);
- rockBlockInfo->rock_recno = m.atoi(rockBlockRec->rock_recno, rockBlockRec->RECNO_LEN);
- rockBlockInfo->first_bitmap = m.atoi(rockBlockRec->first_bitmap, rockBlockRec->RECNO_LEN);
- // ------- validate rock_recno --------//
- err_when( rockBlockInfo->rock_recno <= 0 || rockBlockInfo->rock_recno > rock_info_count);
- RockInfo* rockInfo = rock_info_array+rockBlockInfo->rock_recno-1;
- err_when( strncmp(rockBlockRec->rock_id, rockInfo->rock_name, strlen(rockInfo->rock_name)));
- if(rockInfo->first_block_recno == 0)
- rockInfo->first_block_recno = i + 1;
- // ------- set block_offset in rockInfo ----------//
- if( rockBlockInfo->loc_x < MAX_ROCK_WIDTH &&
- rockBlockInfo->loc_y < MAX_ROCK_HEIGHT)
- {
- // store the rockBlockRecno (i.e. i+1) in rockInfo->block_offset
- // in order to find a rock block from rock recno and x offset, y offset
- // thus make RockRes::locate_block() faster
- rockInfo->block_offset[rockBlockInfo->loc_y][rockBlockInfo->loc_x] = i + 1;
- }
- #ifdef DEBUG
- // -------- validate loc_x and loc_y ----------//
- err_when( rockBlockInfo->loc_x >= rockInfo->loc_width );
- err_when( rockBlockInfo->loc_y >= rockInfo->loc_height );
- // -------- validate rockBitmapInfo -------//
- int blockFrame = rockInfo->max_frame;
- for(int f = 1; f <= blockFrame; ++f)
- {
- RockBitmapInfo *rockBitmapInfo = rock_bitmap_array + (rockBlockInfo->first_bitmap-1) + (f-1);
- err_when( rockBlockInfo->loc_x != rockBitmapInfo->loc_x);
- err_when( rockBlockInfo->loc_y != rockBitmapInfo->loc_y);
- err_when( f != rockBitmapInfo->frame);
- }
- #endif
- }
- }
- // ------------ end of function RockRes::load_block_info -----------//
- // ------------ begin of function RockRes::load_anim_info -----------//
- void RockRes::load_anim_info()
- {
- RockAnimRec *rockAnimRec;
- RockAnimInfo *rockAnimInfo;
- int i;
- //---- read in rock count and initialize rock info array ----//
- String rockDbName;
- rockDbName = DIR_RES;
- rockDbName += "ROCKANI";
- rockDbName += config.terrain_set;
- rockDbName += ".RES";
- Database rockDbObj(rockDbName, 1);
- // Database *dbRock = game_set.open_db(ROCK_ANIM_DB); // only one database can be opened at a time, so we read ROCK.DBF first
- Database *dbRock = &rockDbObj;
- rock_anim_count = (short) dbRock->rec_count();
- rock_anim_array = (RockAnimInfo*) mem_add( sizeof(RockAnimInfo)*rock_anim_count );
- memset( rock_anim_array, 0, sizeof(RockAnimInfo) * rock_anim_count );
- //---------- read in ROCKANIM.DBF ---------//
- for( i=0 ; i<rock_anim_count ; i++ )
- {
- rockAnimRec = (RockAnimRec*) dbRock->read(i+1);
- rockAnimInfo = rock_anim_array+i;
- rockAnimInfo->frame = m.atoi(rockAnimRec->frame, rockAnimRec->FRAME_NO_LEN);
- rockAnimInfo->delay = m.atoi(rockAnimRec->delay, rockAnimRec->DELAY_LEN);
- rockAnimInfo->next_frame = m.atoi(rockAnimRec->next_frame, rockAnimRec->FRAME_NO_LEN);
- rockAnimInfo->alt_next = m.atoi(rockAnimRec->alt_next, rockAnimRec->FRAME_NO_LEN);
- if( rockAnimInfo->alt_next == 0)
- rockAnimInfo->alt_next = rockAnimInfo->next_frame;
- #ifdef DEBUG
- char rockName[rockAnimRec->ROCKID_LEN+1];
- m.rtrim_fld( rockName, rockAnimRec->rock_id, rockAnimRec->ROCKID_LEN );
- // temporary set init_flag =1;
- init_flag = 1;
- short rockId = locate(rockName);
- init_flag = 0;
- err_when(!rockId);
-
- RockInfo *rockInfo = rock_info_array+rockId-1;
- // -------- validate rockAnimFrame -------//
- err_when( rockAnimInfo->frame <= 0 || rockAnimInfo->frame > rockInfo->max_frame);
- // --------- validate next_frame ---------//
- err_when( rockAnimInfo->next_frame <= 0 || rockAnimInfo->next_frame > rockInfo->max_frame);
- // --------- valudate alt_next -----------//
- err_when( rockAnimInfo->alt_next <= 0 || rockAnimInfo->alt_next > rockInfo->max_frame);
- #endif
- }
- }
- // ------------ end of function RockRes::load_anim_info -----------//
- // ------------ begin of function RockRes::get_rock_info -----------//
- RockInfo *RockRes::get_rock_info(short rockRecno)
- {
- err_when(rockRecno <= 0 || rockRecno > rock_info_count );
- return rock_info_array + rockRecno - 1;
- }
- // ------------ end of function RockRes::get_rock_info -----------//
- // ------------ begin of function RockRes::get_block_info -----------//
- RockBlockInfo *RockRes::get_block_info(short rockBlockRecno)
- {
- err_when(rockBlockRecno <= 0 || rockBlockRecno > rock_block_count);
- return rock_block_array + rockBlockRecno -1;
- }
- // ------------ end of function RockRes::get_block_info -----------//
- // ------------ begin of function RockRes::get_bitmap_info -----------//
- RockBitmapInfo *RockRes::get_bitmap_info(short rockBitmapRecno)
- {
- err_when( rockBitmapRecno <= 0 || rockBitmapRecno > rock_bitmap_count);
- return rock_bitmap_array + rockBitmapRecno - 1;
- }
- // ------------ end of function RockRes::get_bitmap_info -----------//
- // ------------ begin of function RockRes::get_anim_info -----------//
- RockAnimInfo *RockRes::get_anim_info(short rockAnimRecno )
- {
- static RockAnimInfo unanimatedInfo = { 1, 99, 1, 1, };
- if( rockAnimRecno == -1 ) // non-animated rock
- {
- return &unanimatedInfo;
- }
- err_when( rockAnimRecno <= 0 || rockAnimRecno > rock_anim_count );
- return rock_anim_array + rockAnimRecno - 1;
- }
- // ------------ end of function RockRes::get_anim_info -----------//
- // ------------ begin of function RockRes::get_bitmap_recno -----------//
- // return rockBitmapRecno
- short RockRes::get_bitmap_recno(short rockBlockRecno, char curFrame)
- {
- RockBlockInfo *rockBlockInfo = get_block_info(rockBlockRecno);
- #ifdef DEBUG
- // --------- validate curFrame -------------//
- RockInfo *rockInfo = get_rock_info(rockBlockInfo->rock_recno);
- err_when( curFrame <= 0 || curFrame > rockInfo->max_frame);
- #endif
- short rockBitmapRecno = rockBlockInfo->first_bitmap+curFrame-1;
- #ifdef DEBUG
- // --------- validate loc_x and loc_y ----------//
- RockBitmapInfo *rockBitmapInfo = get_bitmap_info(rockBitmapRecno);
- err_when( rockBlockInfo->loc_x != rockBitmapInfo->loc_x);
- err_when( rockBlockInfo->loc_y != rockBitmapInfo->loc_y);
- #endif
- return rockBitmapRecno;
- }
- // ------------ end of function RockRes::get_bitmap_recno -----------//
- // ------------ begin of function RockRes::choose_next -----------//
- // choose the next frame
- // <short> rockRecno rock recno
- // <char> curFrame the current frame no.
- // <long> path a random number, related to the probability of choosing alt_next
- // eg. choose_next(..,.., m.random(x)); prob of using alt_next is 1/x
- // return next frame no.
- char RockRes::choose_next(short rockRecno, char curFrame, long path)
- {
- // -------- validate rockRecno ---------//
- RockInfo *rockInfo = get_rock_info(rockRecno);
- // -------- validate curFrame ----------//
- err_when(curFrame <= 0 || curFrame > rockInfo->max_frame);
- RockAnimInfo *rockAnimInfo = get_anim_info(get_anim_recno(rockRecno, curFrame) );
- // -------- validate frame, next_frame and alt_next in rockAnimInfo -------/
- err_when(rockAnimInfo->frame != curFrame);
- err_when(get_anim_info(get_anim_recno(rockRecno, rockAnimInfo->next_frame))->frame != rockAnimInfo->next_frame);
- err_when(get_anim_info(get_anim_recno(rockRecno, rockAnimInfo->alt_next))->frame != rockAnimInfo->alt_next);
- return rockAnimInfo->choose_next(path);
- }
- // ------------ end of function RockRes::choose_next -----------//
- // ------------ begin of function RockRes::draw -----------//
- // draw the whole rock at location (xLoc, yLoc)
- // <short> rockRecno rock no.
- // <short> xLoc,yLoc where the rock is drawn
- // <char> curFrame frame no.
- void RockRes::draw(short rockRecno, short xLoc, short yLoc, char curFrame)
- {
- int yc, xc;
- RockInfo *rockInfo = rock_res.get_rock_info(rockRecno);
- short rockBlockRecno, rockBitmapRecno;
- for( yc = 0; yc < rockInfo->loc_height; ++yc)
- {
- for( xc = 0; xc < rockInfo->loc_width; ++xc)
- {
- if( (rockBlockRecno = locate_block(rockRecno, xc, yc)) != 0
- && (rockBitmapRecno = get_bitmap_recno(rockBlockRecno, curFrame)) != 0 )
- {
- get_bitmap_info(rockBitmapRecno)->draw(xLoc+xc, yLoc+yc);
- }
- }
- }
- }
- // ------------ end of function RockRes::draw -----------//
- // ------------ begin of function RockRes::draw_block -----------//
- // draw (offsetX, offsetY) of rockRecno at location (xLoc, yLoc)
- // <short> rockRecno rock no.
- // <short> offsetX, offsetY which cell of a rock
- // <short> xLoc,yLoc where the rock is drawn
- // <char> curFrame frame no.
- void RockRes::draw_block(short rockRecno, short xLoc, short yLoc,
- short offsetX, short offsetY, char curFrame)
- {
- RockInfo *rockInfo = rock_res.get_rock_info(rockRecno);
- short rockBlockRecno, rockBitmapRecno;
- err_when( !rockInfo );
- err_when( offsetX < 0 || offsetX >= rockInfo->loc_width );
- err_when( offsetY < 0 || offsetY >= rockInfo->loc_height );
- if( (rockBlockRecno = locate_block(rockRecno, offsetX, offsetY)) != 0
- && (rockBitmapRecno = get_bitmap_recno(rockBlockRecno, curFrame)) != 0 )
- {
- get_bitmap_info(rockBitmapRecno)->draw(xLoc, yLoc);
- }
- }
- // ------------ end of function RockRes::draw_block -----------//
- // ------------ begin of function RockRes::search -----------//
- //
- // search which rock id has the specified criteria
- //
- // <char*> rockTypes : a string of 'R', 'D', 'E', or NULL for any
- // <short> minWidth : minimum loc_width of RockInfo
- // <short> maxWidth : maximum loc_width of RockInfo
- // <short> minHeight : minimum loc_height of RockInfo
- // <short> maxHeight : maximum loc_height of RockInfo
- // <int> animatedFlag : 0 for non-animated (i.e. max_frame==1),
- // +ve for animated( max_frame > 1),
- // -ve for animated or non-animated (default : -1)
- // <int> findFirst : whether to find the first match (default : 0)
- //
- // return rock recno or 0 (for not found)
- //
- short RockRes::search(char *rockTypes, short minWidth, short maxWidth, short minHeight, short maxHeight,
- int animatedFlag, int findFirst, char terrainType )
- {
- // -------- search a rock by rock_type, width and height ---------//
- short rockRecno = 0;
- int findCount = 0;
- RockInfo *rockInfo;
- int i;
- for( i = 1, rockInfo = rock_info_array; i <= rock_info_count; ++i, ++rockInfo)
- {
- if( (!rockTypes || strchr(rockTypes,rockInfo->rock_type) )
- && (terrainType == 0 || rockInfo->valid_terrain(terrainType) )
- && rockInfo->loc_width >= minWidth && rockInfo->loc_width <= maxWidth
- && rockInfo->loc_height >= minHeight && rockInfo->loc_height <= maxHeight
- && (animatedFlag < 0 || animatedFlag == 0 && rockInfo->max_frame == 1 ||
- animatedFlag > 0 && rockInfo->max_frame > 1) )
- {
- ++findCount;
- if( findFirst )
- {
- rockRecno = i;
- break;
- }
- else if( m.random(findCount) == 0)
- {
- rockRecno = i;
- }
- }
- }
- return rockRecno;
- }
- // ------------ end of function RockRes::search -----------//
- // ------------ begin of function RockRes::locate -----------//
- // find a rock by name
- //
- // <char *> rockName : name of rock to find
- //
- // return rock recno or 0 (for not found)
- //
- short RockRes::locate(char *rockName)
- {
- // -------- search a rock by rock_type, width and height ---------//
- short rockRecno = 0;
- RockInfo *rockInfo;
- int i;
- for( i = 1, rockInfo = rock_info_array; i <= rock_info_count; ++i, ++rockInfo)
- {
- if( strcmp(rockName, rockInfo->rock_name) == 0 )
- {
- rockRecno = i;
- break;
- }
- }
- return rockRecno;
- }
- // ------------ end of function RockRes::locate -----------//
- // ------------ begin of function RockRes::locate_block -----------//
- // find a rock block by rock recno and x, y offset
- //
- // return rock block recno or 0 for not found
- short RockRes::locate_block(short rockRecno, short xLoc, short yLoc)
- {
- if( xLoc < MAX_ROCK_WIDTH && yLoc < MAX_ROCK_HEIGHT)
- {
- // if xLoc and yLoc is small enough, the block of offset x and offset y
- // can be found in block_offset,
- return get_rock_info(rockRecno)->block_offset[yLoc][xLoc];
- }
- else
- {
- // otherwise, linear search
- short rockBlockRecno = get_rock_info(rockRecno)->first_block_recno;
- RockBlockInfo *rockBlockInfo;
- for( rockBlockInfo = get_block_info(rockBlockRecno); rockBlockRecno <= rock_block_count
- && rockBlockInfo->rock_recno == rockRecno; ++rockBlockRecno, ++rockBlockInfo)
- {
- if( rockBlockInfo->loc_x == xLoc && rockBlockInfo->loc_y == yLoc)
- return rockBlockRecno;
- }
- return 0;
- }
- }
- // ------------ end of function RockRes::locate_block -----------//
- // ------------ begin of function RockRes::get_anim_recno -----------//
- // get the rockAnimRecno for a frame of a rock
- // <short> rockRecno rock recno
- // <char> curFrame the current frame no.
- //
- // return rockAnim recno
- //
- short RockRes::get_anim_recno(short rockRecno, char curFrame)
- {
- // -------- validate rockRecno ---------//
- RockInfo *rockInfo = get_rock_info(rockRecno);
- if( rockInfo->first_anim_recno )
- {
- #ifdef DEBUG
- // -------- validate curFrame ----------//
- err_when(curFrame <= 0 || curFrame > rockInfo->max_frame);
- RockAnimInfo *rockAnimInfo = get_anim_info(rockInfo->first_anim_recno + (curFrame-1) );
- // -------- validate frame, next_frame and alt_next in rockAnimInfo -------/
- err_when(rockAnimInfo->frame != curFrame);
- err_when(get_anim_info(rockInfo->first_anim_recno+rockAnimInfo->next_frame-1)->frame != rockAnimInfo->next_frame);
- err_when(get_anim_info(rockInfo->first_anim_recno+rockAnimInfo->alt_next-1)->frame != rockAnimInfo->alt_next);
- #endif
-
- return rockInfo->first_anim_recno + (curFrame-1);
- }
- else
- return -1; // a special recno for non-animated rock
- }
- // ------------ end of function RockRes::get_anim_recno -----------//
- // ------------ begin of function RockBitmapInfo::draw ---------//
- void RockBitmapInfo::draw(short xLoc, short yLoc)
- {
- //-------- check if the firm is within the view area --------//
- int x1 = xLoc * ZOOM_LOC_WIDTH - World::view_top_x;
- int x2 = x1 + width() -1;
- if( x1 >= ZOOM_WIDTH || x2 < 0)
- return;
- int y1 = yLoc * ZOOM_LOC_HEIGHT - World::view_top_y;
- int y2 = y1 + height() -1;
- if( y1 >= ZOOM_HEIGHT || y2 < 0)
- return;
- //---- only portion of the sprite is inside the view area ------//
- if( x1 < 0 || x2 >= ZOOM_WIDTH || y1 < 0 || y2 >= ZOOM_HEIGHT )
- {
- int srcX1 = x1<0 ? -x1 : 0;
- int srcY1 = y1<0 ? -y1 : 0;
- int srcX2 = (x2>=ZOOM_WIDTH ? ZOOM_WIDTH-1-x1 : width()-1);
- int srcY2 = (y2>=ZOOM_HEIGHT ? ZOOM_HEIGHT-1-y1 : height()-1);
- // ########## begin Gilbert 7/4 ###########//
- vga_back.put_bitmap_area_trans( x1+ZOOM_X1, y1+ZOOM_Y1,
- bitmap_ptr, srcX1, srcY1, srcX2, srcY2 );
- // ########## end Gilbert 7/4 ###########//
- }
- //---- the whole sprite is inside the view area ------//
- else
- {
- // ########## begin Gilbert 7/4 ###########//
- vga_back.put_bitmap_trans( x1+ZOOM_X1, y1+ZOOM_Y1, bitmap_ptr );
- // ########## end Gilbert 7/4 ###########//
- }
- }
- // ------------ end of function RockBitmapInfo::draw ---------//
|