//------ Begin of function FirmMarket::ai_update_link_status ------// // void FirmMarket::ai_update_link_status() { //---- consider enabling/disabling links to firms ----// Nation* nationPtr = nation_array[nation_recno]; Firm* firmPtr; int rc; int i; for(i=0; i<linked_firm_count; i++) { err_when(!linked_firm_array[i] || firm_array.is_deleted(linked_firm_array[i])); firmPtr = firm_array[linked_firm_array[i]]; //-------- check product type ----------// rc = firmPtr->firm_id == FIRM_MINE || firmPtr->firm_id == FIRM_FACTORY; // for output raw materials to the factory to manufacture toggle_firm_link( i+1, rc, COMMAND_AI ); // enable the link } //----- always enable links to towns as there is no downsides for selling goods to the villagers ----// for(i=0; i<linked_town_count; i++) { err_when(!linked_town_array[i] || town_array.is_deleted(linked_town_array[i])); toggle_town_link( i+1, 1, COMMAND_AI ); // enable the link } }
//----- Begin of function FirmMarket::update_trade_link -----// // // Update the status of links to harbors and towns based // on the current trade treaty status. // void FirmMarket::update_trade_link() { Nation* ownNation = nation_array[nation_recno]; int tradeTreaty; //------ update links to towns -----// Town* townPtr; for( int i=0 ; i<linked_town_count ; i++ ) { townPtr = town_array[linked_town_array[i]]; if( !townPtr->nation_recno ) continue; if( townPtr->nation_recno ) { tradeTreaty = ownNation->get_relation(townPtr->nation_recno)->trade_treaty || townPtr->nation_recno==nation_recno; } else // if this is an independent town, it buys goods from the market if its resistance towards the nation is < 30 { tradeTreaty = townPtr->resistance(nation_recno) <= INDEPENDENT_LINK_RESISTANCE; } if( linked_town_enable_array[i] != (tradeTreaty ? LINK_EE : LINK_DD) ) toggle_town_link( i+1, tradeTreaty, COMMAND_AUTO, 1 ); // 1-toggle both side } }
//--------- Begin of function Firm::ai_update_link_status ---------// // // Updating link status of this firm with towns. // void Firm::ai_update_link_status() { err_when( firm_id == FIRM_CAMP ); // FirmCamp has its own ai_update_link_status(), this version shouldn't be called. if( !worker_array ) // if this firm does not need any workers. return; if( is_worker_full() ) // if this firm already has all the workers it needs. return; //------------------------------------------------// Nation* ownNation = nation_array[nation_recno]; int i, rc; for( i=0 ; i<linked_town_count ; i++ ) { Town* townPtr = town_array[linked_town_array[i]]; //--- enable link to hire people from the town ---// rc = townPtr->nation_recno==0 || // either it's an independent town or it's friendly or allied to our nation ownNation->get_relation_status(townPtr->nation_recno) >= NATION_FRIENDLY; toggle_town_link( i+1, rc, COMMAND_AI ); } }
//------- Begin of function Firm::draw_detect_link_line ---------// // // [int] actionDetect - 0 - this is a draw action // 1 - this is a detect action // (default: 0) // // return: <int> 1 - detected // 0 - not detected // int Firm::draw_detect_link_line(int actionDetect) { if( firm_id == FIRM_INN ) // FirmInn's link is only for scan for neighbor inns quickly, the link line is not displayed return 0; //--------------------------------------// int i, firmX, firmY, townX, townY; Firm* firmPtr; Town* townPtr; FirmInfo* firmInfo = firm_res[firm_id]; //-------- set source points ----------// int srcX = ( ZOOM_X1 + (loc_x1-world.zoom_matrix->top_x_loc) * ZOOM_LOC_WIDTH + ZOOM_X1 + (loc_x2-world.zoom_matrix->top_x_loc+1) * ZOOM_LOC_WIDTH ) / 2; int srcY = ( ZOOM_Y1 + (loc_y1-world.zoom_matrix->top_y_loc) * ZOOM_LOC_HEIGHT + ZOOM_Y1 + (loc_y2-world.zoom_matrix->top_y_loc+1) * ZOOM_LOC_HEIGHT ) / 2; //------ draw lines to linked firms ---------// int lineType; char* bitmapPtr; for( i=0 ; i<linked_firm_count ; i++ ) { firmPtr = firm_array[linked_firm_array[i]]; firmX = ( ZOOM_X1 + (firmPtr->loc_x1-world.zoom_matrix->top_x_loc) * ZOOM_LOC_WIDTH + ZOOM_X1 + (firmPtr->loc_x2-world.zoom_matrix->top_x_loc+1) * ZOOM_LOC_WIDTH ) / 2; firmY = ( ZOOM_Y1 + (firmPtr->loc_y1-world.zoom_matrix->top_y_loc) * ZOOM_LOC_HEIGHT + ZOOM_Y1 + (firmPtr->loc_y2-world.zoom_matrix->top_y_loc+1) * ZOOM_LOC_HEIGHT ) / 2; anim_line.draw_line(&vga_back, srcX, srcY, firmX, firmY, linked_firm_enable_array[i]==LINK_EE ); //----- check if this firm can toggle link or not -----// if( !can_toggle_firm_link(firmPtr->firm_recno) ) continue; //------ if the link is switchable -------// bitmapPtr = power.get_link_icon( linked_firm_enable_array[i], nation_recno==firmPtr->nation_recno ); if( actionDetect ) { if( own_firm() && world.zoom_matrix->detect_bitmap_clip( firmX-11, firmY-11, bitmapPtr ) ) { if( linked_firm_enable_array[i] & LINK_ED ) { toggle_firm_link( i+1, 0, COMMAND_PLAYER ); se_ctrl.immediate_sound("TURN_OFF"); } else { toggle_firm_link( i+1, 1, COMMAND_PLAYER ); se_ctrl.immediate_sound("TURN_ON"); } return 1; } } else { if( nation_recno == nation_array.player_recno ) world.zoom_matrix->put_bitmap_clip( firmX-11, firmY-11, bitmapPtr ); } } //------ draw lines to linked towns ---------// for( i=0 ; i<linked_town_count ; i++ ) { townPtr = town_array[linked_town_array[i]]; townX = ( ZOOM_X1 + (townPtr->loc_x1-world.zoom_matrix->top_x_loc) * ZOOM_LOC_WIDTH + ZOOM_X1 + (townPtr->loc_x2-world.zoom_matrix->top_x_loc+1) * ZOOM_LOC_WIDTH ) / 2; townY = ( ZOOM_Y1 + (townPtr->loc_y1-world.zoom_matrix->top_y_loc) * ZOOM_LOC_HEIGHT + ZOOM_Y1 + (townPtr->loc_y2-world.zoom_matrix->top_y_loc+1) * ZOOM_LOC_HEIGHT ) / 2; if( worker_array && selected_worker_id && worker_array[selected_worker_id-1].town_recno == townPtr->town_recno ) { lineType = -1; anim_line.thick_line(&vga_back, srcX, srcY, townX, townY, linked_town_enable_array[i]==LINK_EE, lineType ); } else { lineType = 0; anim_line.draw_line(&vga_back, srcX, srcY, townX, townY, linked_town_enable_array[i]==LINK_EE, lineType ); } //----- check if this firm can toggle link or not -----// if( !can_toggle_town_link() ) continue; //--------- draw link symbol -----------// bitmapPtr = power.get_link_icon( linked_town_enable_array[i], nation_recno==townPtr->nation_recno ); if( actionDetect ) { int rc = world.zoom_matrix->detect_bitmap_clip( townX-11, townY-11, bitmapPtr ); //------ left clicking to toggle link -------// if( rc==1 && own_firm() ) { if( linked_town_enable_array[i] & LINK_ED ) { toggle_town_link( i+1, 0, COMMAND_PLAYER ); se_ctrl.immediate_sound("TURN_OFF"); } else { toggle_town_link( i+1, 1, COMMAND_PLAYER ); se_ctrl.immediate_sound("TURN_ON"); } // // update RemoteMsg::firm_toggle_link_town() // if( firm_id == FIRM_CAMP && !remote.is_enable()) { if( townPtr->nation_recno ) townPtr->update_target_loyalty(); else townPtr->update_target_resistance(); townPtr->update_camp_link(); } return 1; } //------ right clicking to move workers ------// else if( rc==2 && selected_worker_id > 0 ) { //--- only when this worker is ours ----// if( firm_res[firm_id]->live_in_town && worker_array[selected_worker_id-1].is_nation(firm_recno, nation_array.player_recno) ) { if(townPtr->population>=MAX_TOWN_POPULATION) return 0; set_worker_home_town(townPtr->town_recno, COMMAND_PLAYER); se_ctrl.immediate_sound("PULL_MAN"); return 1; } } } else { if( nation_recno == nation_array.player_recno ) world.zoom_matrix->put_bitmap_clip( townX-11, townY-11, bitmapPtr ); } } return 0; }