void FirmInn::add_inn_unit(int raceId) { err_when( inn_unit_count >= MAX_INN_UNIT ); InnUnit *innUnit = inn_unit_array+inn_unit_count; RaceInfo *raceInfo = race_res[raceId]; int spyFlag = 0; // must determine before inn_unit_count increase if( count_soldier() >= MAX_INN_UNIT/2 ) spyFlag = 1; else if( count_spy() >= MAX_INN_UNIT/2 ) spyFlag = 0; else spyFlag = misc.random(2); memset( innUnit, 0, sizeof(InnUnit) ); inn_unit_count++; //---- determine whether the unit is a spy or a military unit ----// if( !spyFlag ) // a military unit { //------- create a unit now -----------// int unitRecno; if( misc.random(20)==0 ) // 5% have a hero { unitRecno = hero_res.create_hero( -1, -1, 0, 0, 0, 0, 1); // -1 - create the unit as an invisible unit } // last 1 - the heroes are for hire, check the HeroInfo::for_hire before adding it else //---- just create a unit, not a hero -----// { int unitId; int heroPower = 20 + misc.random(20); if( misc.random(2)==0 ) unitId = raceInfo->infantry_unit_id; else unitId = raceInfo->special_unit_id; unitRecno = hero_res.create_powerful_unit( -1, -1, 0, unitId, heroPower); // -1 - create the unit as an invisible unit } //--------------------------------------// if( !unitRecno ) { inn_unit_count--; return; } //--------------------------------------// Unit* unitPtr = unit_array[unitRecno]; err_when( !unitPtr->unit_id ); innUnit->hero_id = unitPtr->hero_id; innUnit->unit_id = unitPtr->unit_id; innUnit->skill = unitPtr->skill; innUnit->hit_points = unitPtr->hit_points; innUnit->item = unitPtr->item; unitPtr->item.clear(); unit_array.del(unitRecno); // delete the unit as it was created temporarily for setting skill and item values } else // a spy { switch( misc.random(3) ) { case 0: // civilian spy innUnit->unit_id = (char) raceInfo->civilian_unit_id; innUnit->skill.init(innUnit->unit_id, CITIZEN_COMBAT_LEVEL, 0); innUnit->spy_skill = 30+misc.random(40); break; case 1: // infantry spy innUnit->unit_id = (char) raceInfo->infantry_unit_id; innUnit->skill.init(innUnit->unit_id, 20+misc.random(30), 20+misc.random(30)); // a spy also have leadership and combat ability, but lower than units with leadership as their main skills innUnit->spy_skill = 30+misc.random(40); break; case 2: // special unit spy innUnit->unit_id = (char) raceInfo->special_unit_id; innUnit->skill.init(innUnit->unit_id, 30+misc.random(30), 10+misc.random(20)); // a spy also have leadership and combat ability, but lower than units with leadership as their main skills innUnit->spy_skill = 30+misc.random(40); break; default: err_here(); } if( misc.random(4)==0 ) innUnit->spy_skill += misc.random(30); else if( misc.random(2)==0 ) innUnit->spy_skill += misc.random(15); } err_when( !innUnit->unit_id ); // ------ randomly assign a unique id --------// // ###### begin Gilbert 23/2 ######// innUnit->unique_id = misc.rand_long(); // ###### end Gilbert 23/2 ######// // ------ set current hit point -------// innUnit->hit_points = (float) innUnit->max_hit_points(); //-------------------------------------------// innUnit->set_hire_cost(); innUnit->stay_count = 10 + misc.random(5); }
// -------- Begin of function FirmInn::disp_unit_list -------// // void FirmInn::disp_unit_list(int dispY1, int refreshFlag) { disp_unit_list_y1 = dispY1; // ##### begin Gilbert 7/12 #######// // count no. of units on each row int rowUnitCountOld[2] = { 0, 0 }; // no of soldier and no of spy counted rowUnitCountOld[0] = count_soldier(); rowUnitCountOld[1] = count_spy(); // ##### end Gilbert 7/12 #######// for( int inc = -1; inc <= 1; inc += 2 ) { err_when( inc == 0 ); // first round is descending draw to icon // second round is ascending to draw the frame int inAreaFlag = 4; // ##### begin Gilbert 7/10 ######// // initial rowUnitCount according to inc int rowUnitCount[2]; // no of soldier and no of spy counted if( inc >= 0 ) memset( rowUnitCount, 0, sizeof(rowUnitCount) ); else memcpy( rowUnitCount, rowUnitCountOld, sizeof(rowUnitCount) ); // ##### end Gilbert 7/10 ######// for( int i = inc>=0?1:inn_unit_count; i > 0 && i <= inn_unit_count; i +=inc ) { InnUnit *innUnit = inn_unit_array + i - 1; int row = innUnit->spy_skill <= 0 ? 0 : 1; // soldier on row 0, spy on row 1 // ##### begin Gilbert 7/10 ######// if( inc < 0 ) --rowUnitCount[row]; // decrease rowUnitCount before use // ##### end Gilbert 7/10 ######// int x = INFO_X1 + 67 + rowUnitCount[row] * UNIT_X_SPACING; int y = INFO_Y1 + 44 + row * UNIT_Y_SPACING; int yHp = INFO_Y1 + 7 + row * UNIT_Y_SPACING; int windowX1 = INFO_X1 + 16; int windowX2 = INFO_X1 + 218; int windowY1 = INFO_Y1 + 5 + row * 76; // 5,81 int windowY2 = windowY1 + 72 - 1 ; // ###### begin Gilbert 7/10 #######// if( inc >= 0 ) ++rowUnitCount[row]; // increase rowUnitCount after use // ###### end Gilbert 7/10 #######// if( inc < 0 ) { // first pass descending, draw unit icon info.draw_unit_icon( x+UNIT_X_SPACING/2, y, innUnit->unit_id, nation_recno, windowX1, windowY1, windowX2, windowY2, 1 ); } else { // second round is ascending to draw the frame if( info.draw_unit_icon( x+UNIT_X_SPACING/2, y, innUnit->unit_id, nation_recno, windowX1, windowY1, windowX2, windowY2, inAreaFlag | (i==selected_unit_id?3:0) ) & 4 ) { inAreaFlag = 0; // frame for mouse cursor is drawn, disable the frame } int fontHeight = font_whbl.max_font_height; if( innUnit->is_own_spy() ) // display spy icon { vga.active_buf->put_bitmap_trans( x+UNIT_X_SPACING/2-8, yHp-5, image_icon.read("U_SPY") ); } else if( innUnit->hero_id ) { vga.active_buf->put_bitmap_trans( x+UNIT_X_SPACING/2-8, yHp-5, image_icon.read("U_HERO") ); } else { if( row == 0 ) // display combat skill and leadership { font_whbl.center_put( x, yHp, x+UNIT_X_SPACING, yHp+fontHeight, m.format(innUnit->skill_level()) ); } else if( row == 1 ) // display spy skill { font_whbl.center_put( x, yHp, x+UNIT_X_SPACING, yHp+fontHeight, m.format(innUnit->spy_skill) ); } } if( innUnit->item.id ) { char *iconPtr = item_res.item_unit_interface(innUnit->item.id); if( iconPtr ) vga.active_buf->put_bitmap_trans( x+UNIT_X_SPACING/2 -((Bitmap *)iconPtr)->get_width()/2, yHp +53, iconPtr ); } } } } }