//--------- Begin of function FirmResearch::start_research --------// // // Start researching on the specific technology. // // <int> techId - id. of the technology to research. // void FirmResearch::start_research(int techId, char remoteAction) { TechInfo* techInfo = tech_res[techId]; err_when( !techInfo->can_research(nation_recno) ); if( !remoteAction && remote.is_enable()) { // packet structure : <firm recno> <tech Id> short *shortPtr = (short *)remote.new_send_queue_msg(MSG_F_RESEARCH_START, 2*sizeof(short) ); shortPtr[0] = firm_recno; shortPtr[1] = (short) techId; return; } //---- if the firm currently is already researching something ---// if( tech_id ) terminate_research(); //-------- set self parameters ---------// tech_id = techId; //------- set TechRes parameters -------// techInfo->inc_nation_is_researching(nation_recno); }
//--------- Begin of function FirmResearch::process_research --------// // // Process the current research. // void FirmResearch::process_research() { if( !tech_id ) return; //------- make a progress with the research ------// TechInfo* techInfo = tech_res[tech_id]; float progressPoint; if( config.fast_build && nation_recno==nation_array.player_recno ) progressPoint = (float) productivity / 100 + (float) 0.5; else progressPoint = (float) productivity / 300; int newLevel = techInfo->get_nation_tech_level(nation_recno)+1; float levelDivider = ((float)(newLevel+1)/2); // from 1.0 to 2.0 progressPoint = progressPoint * (float) 30 / techInfo->complex_level / levelDivider; // more complex and higher level technology will take longer to research int techId = tech_id; // techInfo->progress() will reset tech_id if the current research level is the max tech level, so we have to save it now if( techInfo->progress(nation_recno, progressPoint) ) { if( tech_id ) // TechRes::progress() may have called terminate_research() if the tech level reaches the maximum { int techId = tech_id; research_complete(); //----- research next level technology automatically -----// if( !firm_ai ) // for player's firm only { if( techInfo->get_nation_tech_level(nation_recno) < techInfo->max_tech_level ) { start_research( techId, COMMAND_AUTO ); if( firm_recno == firm_array.selected_recno ) info.disp(); } } } //--------- add news ---------// if( own_firm() ) { news_array.tech_researched( techId, tech_res[techId]->get_nation_tech_level(nation_recno) ); se_res.far_sound(center_x, center_y, 1, 'F', firm_id, "FINS", 'S', unit_res[tech_res[techId]->unit_id]->sprite_id); } } }
//----- Begin of function Nation::think_demand_tech -----// // int Nation::think_demand_tech() { if( m.random(10) > 0 ) // only 1/10 chance of calling this function return 0; Nation* nationPtr; int totalNation=nation_array.size(); int nationRecno=m.random(totalNation)+1; for( int i=totalNation ; i>0 ; i-- ) { if( ++nationRecno > totalNation ) nationRecno = 1; if( nation_array.is_deleted(nationRecno) || nationRecno==nation_recno ) continue; nationPtr = nation_array[nationRecno]; if( nationPtr->total_tech_level() == 0 ) continue; if( !should_diplomacy_retry(TALK_DEMAND_TECH, nationRecno) ) continue; //--- don't request from hostile or tense nations -----// if( get_relation(nationRecno)->status < NATION_NEUTRAL ) continue; //---- scan which tech that the nation has but we don't have ----// int techId; for( techId=1 ; techId<=tech_res.tech_count ; techId++ ) { TechInfo *techInfo = tech_res[techId]; if( techInfo->get_nation_tech_level(nation_recno)==0 && techInfo->get_nation_tech_level(nationRecno) > 0 ) { break; } } if( techId > tech_res.tech_count ) continue; //-------- send the message now ---------// talk_res.ai_send_talk_msg(nationRecno, nation_recno, TALK_DEMAND_TECH, techId); return 1; } return 0; }
//--------- Begin of function FirmResearch::disp_research_info ---------// // void FirmResearch::disp_research_info(int dispY1, int refreshFlag) { static short lastTechId=0; if( refreshFlag==INFO_UPDATE && lastTechId != tech_id ) { lastTechId = tech_id; info.disp(); } //---------------- paint the panel --------------// if( refreshFlag == INFO_REPAINT ) vga.d3_panel_up( INFO_X1, dispY1, INFO_X2, dispY1+50 ); if( !tech_id ) return; int x=INFO_X1+4, y=dispY1+4; //-------- display the icon of the researching item ---------// TechInfo* techInfo = tech_res[tech_id]; if( refreshFlag == INFO_REPAINT ) { vga.d3_panel_down( x, y, x+TECH_LARGE_ICON_WIDTH+3, y+TECH_LARGE_ICON_HEIGHT+3, 2 ); vga_front.put_bitmap( x+2, y+2, techInfo->tech_large_icon() ); //----------- display text ------------// x += TECH_LARGE_ICON_WIDTH+10; String str; str = techInfo->tech_des(); int researchVersion = techInfo->get_nation_tech_level(nation_recno)+1; // research the next non-researched version if( researchVersion > 1 ) { str += " "; str += m.roman_number(researchVersion); } font_san.put( x, y+4, str); } else { x += TECH_LARGE_ICON_WIDTH+10; } vga_front.indicator( 0, x-2, y+21, techInfo->get_progress(nation_recno), (float)100, VGA_GRAY ); }
//----- Begin of function Nation::consider_exchange_tech -----// // // talkMsg->talk_para1 - id. of the tech the talking nation offers. // talkMsg->talk_para2 - id. of the tech the talking nation requests. // talkMsg->talk_para3 - level of the tech the talking nation offers. // talkMsg->talk_para4 - level of the tech the talking nation requests. // int Nation::consider_exchange_tech(TalkMsg* talkMsg) { if( nation_array[talkMsg->to_nation_recno]->is_human() != is_human() ) return 0; int relationStatus = get_relation_status(talkMsg->to_nation_recno); if( relationStatus == RELATION_HOSTILE ) // no deal with hostile nations return 0; int giveLevel = talkMsg->talk_para3 - tech_res[talkMsg->talk_para1]->get_nation_tech_level(nation_recno); int gainLevel = talkMsg->talk_para4 - tech_res[talkMsg->talk_para2]->get_nation_tech_level(nation_recno); if( gainLevel < giveLevel ) // this's a bad deal { if( relationStatus < RELATION_FRIENDLY + (giveLevel-gainLevel-1) ) return 0; } if( gainLevel == giveLevel ) // this's a fair deal { if( relationStatus == RELATION_TENSE && pref_peacefulness < 50 ) return 0; if( relationStatus == RELATION_NEUTRAL && pref_peacefulness < 30 ) return 0; } //--- if we already have the technology, reject it ----// TechInfo* offeredTech = tech_res[talkMsg->talk_para1]; int ourTechLevel = offeredTech->get_nation_tech_level(nation_recno); if( ourTechLevel >= talkMsg->talk_para2 ) return 0; //----- if the offered tech is not useful to us, reject it ---// if( !offeredTech->is_useful_to_nation(nation_recno) ) return 0; //----------- improve relationship ----------// int relationChange = (talkMsg->talk_para2-ourTechLevel) * (5+pref_use_weapon/10); // increase relationship by 5 to 15 points change_ai_relation_level( talkMsg->from_nation_recno, relationChange ); return 1; }
//-------- Begin of static function i_disp_research_button --------// // void i_disp_research_button(ButtonCustom *button, int repaintBody) { int techId = button->custom_para.value; String str; TechInfo* techInfo = tech_res[techId]; str = techInfo->tech_des(); Firm *firmPtr = (Firm *) button->custom_para.ptr; int researchVersion = techInfo->get_nation_tech_level(firmPtr->nation_recno)+1; // research the next non-researched version if( researchVersion > 1 ) { str += " "; str += m.roman_number(researchVersion); } // ####### begin Gilbert 22/1 #######// short fontHeight = font_cara.font_height; // backup font_height font_cara.use_max_height(); if ( !button->enable_flag ) { vga.active_buf->put_bitmap( button->x1, button->y1, image_icon.read("BUILDUP2") ); font_cara.center_put(button->x1, button->y1, button->x2, button->y2, str ); vga.active_buf->bar_alpha(button->x1, button->y1, button->x2, button->y2, 1, 0); } else if ( button->pushed_flag ) { vga.active_buf->put_bitmap( button->x1, button->y1, image_icon.read("BUILDDW2") ); font_cara.center_put(button->x1+1, button->y1+1, button->x2+1, button->y2+1, str ); } else if (mouse.in_area(button->x1, button->y1, button->x2, button->y2)) { vga.active_buf->put_bitmap( button->x1, button->y1, image_icon.read("BUILDSE2") ); font_cara.center_put(button->x1, button->y1, button->x2, button->y2, str ); } else { vga.active_buf->put_bitmap( button->x1, button->y1, image_icon.read("BUILDUP2") ); font_cara.center_put(button->x1, button->y1, button->x2, button->y2, str ); } font_cara.font_height = fontHeight; // restore font height // ####### end Gilbert 22/1 #######// }
//-------- Begin of static function i_disp_research_button --------// // void i_disp_research_button(ButtonCustom *button, int repaintBody) { int x1 = button->x1; int y1 = button->y1; int x2 = button->x2; int y2 = button->y2; if( button->pushed_flag ) { vga.d3_panel2_down(x1, y1, x2, y2); x1++; y1++; } else { vga.d3_panel2_up(x1, y1, x2, y2); x2--; y2--; } //--------------------------------------------// TechInfo* techInfo = tech_res[button->custom_para.value]; // Vga::active_buf->d3_panel_down(x1+2, y1+2, x1+TECH_LARGE_ICON_WIDTH+7, y1+TECH_LARGE_ICON_HEIGHT+7, 2, 0 ); Vga::active_buf->put_bitmap(x1+4, y1+4, techInfo->tech_large_icon() ); //------ display research description -------// String str; str = techInfo->tech_des(); Firm *firmPtr = (Firm *) button->custom_para.ptr; int researchVersion = techInfo->get_nation_tech_level(firmPtr->nation_recno)+1; // research the next non-researched version if( researchVersion > 1 ) { str += " "; str += m.roman_number(researchVersion); } font_bible.put( x1+TECH_LARGE_ICON_WIDTH+12, y1+14, str ); }
// --------- begin of function FirmRese::disp_edit_mode -------// // void FirmResearch::disp_edit_mode(int& refreshFlag, int& y, int dispBG) { // if display background here, set dispBG to 0 FirmWork::disp_edit_mode( refreshFlag, y, dispBG); int x; int x1 = INFO_X1 + 12; int x2 = INFO_X2 - 5; // edit production progress edit_progress_enable = nation_recno && nation_array[nation_recno]->research_tech_id != 0; if( edit_progress_enable ) { TechInfo *techInfo = tech_res[nation_array[nation_recno]->research_tech_id]; String str; str = techInfo->tech_des(); int researchVersion = techInfo->get_nation_tech_level(nation_recno)+1; // research the next non-researched version if( researchVersion > 1 ) { str += " "; str += m.roman_number(researchVersion); } x = font_whbl.put( x1, y, str, 0, x2 ); y += 15; // str may be long, line feed here x = x1; x = edit_progress_x2 = font_blue.put( (edit_progress_x1=x), (edit_progress_y1=y), m.format((int)nation_array[nation_recno]->research_progress(), 3), 0, x2 ); edit_progress_y2 = edit_progress_y1+font_blue.max_font_height; y += 18; } else { y += 33; } }
//----- Begin of function Nation::think_exchange_tech -----// // int Nation::think_exchange_tech() { if( m.random(10) > 0 ) // only 1/10 chance of calling this function return 0; Nation* nationPtr; int totalNation=nation_array.size(); int nationRecno=m.random(totalNation)+1; for( int i=totalNation ; i>0 ; i-- ) { if( ++nationRecno > totalNation ) nationRecno = 1; if( nation_array.is_deleted(nationRecno) || nationRecno==nation_recno ) continue; nationPtr = nation_array[nationRecno]; if( nationPtr->total_tech_level() == 0 ) continue; if( !should_diplomacy_retry(TALK_EXCHANGE_TECH, nationRecno) ) continue; //--- don't request from hostile or tense nations -----// if( get_relation(nationRecno)->status < RELATION_NEUTRAL ) continue; //---- scan which tech that the nation has but we don't have ----// int getTechId=0, getTechLevel=0, giveTechId=0, giveTechLevel=0; int techId; for( techId=1 ; techId<=tech_res.tech_count ; techId++ ) { TechInfo *techInfo = tech_res[techId]; // ###### patch begin Gilbert 24/1 #####// // human kingdoms won't ask for fryhtan tech if( techInfo->is_monster_tech() && (is_human() || nationPtr->is_human()) ) continue; // won't give fryhtan tech to human // ###### patch end Gilbert 24/1 #####// // ####### begin Gilbert 24/12 ####// // for( int j=1 ; j<=techInfo->max_tech_level ; j++ ) for( int j=1 ; j<=techInfo->max_tech_level(nation_recno) || j<=techInfo->max_tech_level(nationRecno); j++ ) // ####### end Gilbert 24/12 ####// { if( !giveTechId ) { if( techInfo->get_nation_tech_level(nation_recno) >= j && techInfo->get_nation_tech_level(nationRecno) < j ) { giveTechId = techId; giveTechLevel = j; break; } } if( !getTechId ) { if( techInfo->get_nation_tech_level(nation_recno) < j && techInfo->get_nation_tech_level(nationRecno) >= j ) { getTechId = techId; getTechLevel = j; break; } } } } //---- if there is a tech we want to give and one we want to get ----// if( !giveTechId || !getTechId ) continue; //--------- send the diplomatic message now --------// // ###### patch begin Gilbert 24/1 #####// // talk_res.ai_send_talk_msg(nationRecno, nation_recno, TALK_EXCHANGE_TECH, // giveTechId, getTechId, giveTechLevel, getTechLevel ); talk_res.ai_send_talk_msg(nationRecno, nation_recno, TALK_EXCHANGE_TECH, giveTechId, getTechId, 0, giveTechLevel, getTechLevel ); // 0=don't force send // ###### end begin Gilbert 24/1 #####// return 1; } return 0; }
//---- Begin of function TalkRes::add_exchange_tech_choices ------// // // talk_para1 - id. of the tech you offer // talk_para2 - id. of the tech you request // talk_para3 - level of the tech you offer // talk_para4 - level of the tech you request // int TalkRes::add_exchange_tech_choices() { int i, j; int fromNationRecno = cur_talk_msg.from_nation_recno; int toNationRecno = cur_talk_msg.to_nation_recno; TechInfo* techInfo; String str; if( cur_talk_msg.talk_para1 && cur_talk_msg.talk_para2 ) return 0; if( !cur_talk_msg.talk_para1 ) choice_question = text_talk.str_ask_offer_tech(); // "Technology you offer?"; else choice_question = text_talk.str_ask_request_tech(); //"Technology you request?"; for( i=1 ; i<=tech_res.tech_count && talk_choice_count<MAX_TALK_CHOICE-1 ; i++ ) // -1 reserve one free space for "Cancel" { techInfo = tech_res[i]; // ---- cannot transfer mega weapon, must kill opponent king to get -----// // ###### begin Gilbert 6/5 ######// if( techInfo->class_id == TECH_CLASS_MEGA_WEAPON || techInfo->class_id == TECH_CLASS_OFFENSIVE_STRUCTURE ) { continue; } // ###### end Gilbert 6/5 ######// // ###### begin Gilbert 24/12 #######// int maxTechLevel = max( techInfo->max_tech_level(fromNationRecno), techInfo->max_tech_level(toNationRecno) ); // for( j=1 ; j<=techInfo->max_tech_level ; j++ ) for( j=1 ; j<=maxTechLevel ; j++ ) // ###### end Gilbert 24/12 #######// { int rc; if( !cur_talk_msg.talk_para1 ) // tech you offer { rc = techInfo->get_nation_tech_level(fromNationRecno) >= j && techInfo->get_nation_tech_level(toNationRecno) < j; } else // tech you request { rc = techInfo->get_nation_tech_level(fromNationRecno) < j && techInfo->get_nation_tech_level(toNationRecno) >= j; } if( rc ) { str = techInfo->tech_des(); if( techInfo->max_tech_level(0)>1 ) { str += " "; str += m.roman_number(j); } add_talk_choice( str, i, j ); // i-techId, j-version id. break; } } } return 1; }
// -------- begin of function FirmResearch::disp_firm_info --------// // void FirmResearch::disp_firm_info(int dispY1, int refreshFlag) { String str; int techId = nation_array[nation_recno]->research_tech_id; // ###### begin Gilbert 5/10 ######// //---------------- paint the panel --------------// // techId =1; if( !techId ) { // str = "No Technology is"; // font_snds.center_put( INFO_X1+7, INFO_Y1+31, INFO_X2, INFO_Y1+48, str ); // str = "currently being"; // font_snds.center_put( INFO_X1+7, INFO_Y1+60, INFO_X2, INFO_Y1+77, str ); // str = "researched."; // font_snds.center_put( INFO_X1+7, INFO_Y1+89, INFO_X2, INFO_Y1+106, str ); font_snds.center_put_paragraph( INFO_X1+45, INFO_Y1+31, INFO_X2-40, INFO_Y1+106, text_firm.str_no_research(), 16, 0, 0 ); } else { //-------- display the icon of the researching item ---------// int x = INFO_X1; int y = INFO_Y1; TechInfo* techInfo = tech_res[techId]; //----------- display text ------------// // str = "Research Progress"; font_snds.center_put( INFO_X1+7, INFO_Y1+11, INFO_X2, INFO_Y1+28, text_firm.str_research_progress() ); // <tech> <version> str = techInfo->tech_des(); int researchVersion = techInfo->get_nation_tech_level(nation_recno)+1; // research the next non-researched version if( researchVersion > 1 ) { str += " "; str += m.roman_number(researchVersion); } font_snds.center_put( INFO_X1+7, INFO_Y1+28, INFO_X2, INFO_Y1+45, str ); // str = "Completion Percent"; font_snds.center_put( INFO_X1+7, INFO_Y1+97, INFO_X2, INFO_Y1+114, text_firm.str_completion_percent() ); // <completion> % int researchProgress = (int) nation_array[nation_recno]->research_progress(); str = (int) researchProgress; str += " %"; font_snds.center_put( INFO_X1+7, INFO_Y1+97+18, INFO_X2, INFO_Y1+114+18, str ); short* hitPointBitmap =NULL; int ratio = researchProgress * 40 / 100; int size = researchProgress * 76 / 100; //106 x 35 --- 15 to 90 ie. 0 to 40 // hitPointBitmap = (short *)mem_add( BitmapW::size(15 +size, 35) ); // if (ratio <11) // vga.active_buf->put_bitmap_trans( INFO_X1 +62, INFO_Y1 +59, image_spict.read("MTR_10")); // else // if (ratio <40) // vga.active_buf->put_bitmap_trans( INFO_X1 +62, INFO_Y1 +59, image_spict.read("MTR_39")); // else // vga.active_buf->put_bitmap_trans( INFO_X1 +62, INFO_Y1 +59, image_spict.read("MTR_40")); // vga.active_buf->read_bitmapW( INFO_X1 +62, INFO_Y1 +59, INFO_X1 +75 +size, INFO_Y1 +90, hitPointBitmap ); // vga.active_buf->put_bitmap_trans( INFO_X1 +62, INFO_Y1 +59, image_spict.read("MTR_00")); // vga.active_buf->put_bitmapW( INFO_X1 +62, INFO_Y1 +59, hitPointBitmap ); // mem_del( hitPointBitmap ); // ----- put empty bar ------// vga.active_buf->put_bitmap_trans( INFO_X1 +62, INFO_Y1 +59, image_spict.read("MTR_00")); // ----- put bar content -----// if( size > 0 ) { char *barBitmap; if (ratio <11) barBitmap = image_spict.read("MTR_10"); else if (ratio <40) barBitmap = image_spict.read("MTR_39"); else barBitmap = image_spict.read("MTR_40"); vga.active_buf->put_bitmap_area_trans( INFO_X1+62, INFO_Y1+59, barBitmap, 0, 0, 13+size, ((Bitmap *)barBitmap)->get_height()-1 ); } } // int x1 = INFO_X1 +13; // int y1 = INFO_Y1 +235; // int x2 = INFO_X1 +13; // int y2 = INFO_Y1 +281; if( is_own() ) { if (!is_monster()) button_select_research.create( INFO_X1 +13, INFO_Y1 +281, 'A', "RESEARCH" ); else button_select_research.create( INFO_X1 +13, INFO_Y1 +281, 'A', "F_RESE" ); button_select_research.paint(); } // ###### end Gilbert 5/10 ######// }