//------- Begin of function FirmHarbor::assign_unit -----------// // void FirmHarbor::assign_unit(int unitRecno) { //------- if this is a construction worker -------// if( unit_array[unitRecno]->skill.skill_id == SKILL_CONSTRUCTION ) { set_builder(unitRecno); return; } //---------------------------------------// //if( ship_count==MAX_SHIP_IN_HARBOR ) // return; if(ship_count + (build_unit_id>0) == MAX_SHIP_IN_HARBOR) return; // leave a room for the building unit add_hosted_ship(unitRecno); unit_array[unitRecno]->deinit_sprite(); UnitMarine *unitPtr = (UnitMarine*) unit_array[unitRecno]; unitPtr->extra_move_in_beach = NO_EXTRA_MOVE; unitPtr->deinit_sprite(); //------------------------------------------------// if( firm_array.selected_recno == firm_recno ) info.disp(); }
//--------- Begin of function FirmCamp::assign_unit ---------// // void FirmCamp::assign_unit(int unitRecno) { Unit* unitPtr = unit_array[unitRecno]; //------- if this is a construction worker -------// if( unitPtr->skill.skill_id == SKILL_CONSTRUCTION ) { set_builder(unitRecno); return; } //-------- assign the unit ----------// int rankId = unit_array[unitRecno]->rank_id; if( rankId == RANK_GENERAL || rankId==RANK_KING ) { assign_overseer(unitRecno); } else { assign_worker(unitRecno); } }
//---------- Begin of function Firm::process_construction --------// // void Firm::process_construction() { if( !under_construction ) return; //--- can only do construction when the firm is not under attack ---// if( info.game_date <= last_attack_date+1 ) return; if( sys.frame_count%2!=0 ) // one build every 2 frames return; //------ increase the construction progress ------// Unit *unitPtr = NULL; // builder may be missing if built by scenario editor if( builder_recno ) { unitPtr = unit_array[builder_recno]; hit_points+=2; if( config.fast_build && nation_recno==nation_array.player_recno ) hit_points += 10; } //------- when the construction is complete ----------// if( hit_points >= max_hit_points() ) // finished construction { hit_points = (float) max_hit_points(); under_construction = 0; setup_date = info.game_date; // ##### begin Gilbert 15/10 ######// if( unitPtr && nation_recno == nation_array.player_recno ) se_res.far_sound(center_x, center_y, 1, 'S', unitPtr->sprite_id, "FINS", 'F', firm_id); // ##### end Gilbert 15/10 ######// err_when(builder_recno<=0 || unit_array.is_deleted(builder_recno)); err_when(unitPtr->nation_recno!=nation_recno); //---------------------------------------// // ##### begin Gilbert 15/10 ######// if( builder_recno && builder_stay_after_construction() ) // attempt to assign the unit into the firm. return 1 if assigned successfully // ##### end Gilbert 15/10 ######// builder_recno = 0; else set_builder(0); // if cannot assign it to the firm, mobilize it. } err_when (hit_points < 0 || hit_points > max_hit_points() ); }
//--------- Begin of function Firm::detect_basic_info ---------// // int Firm::detect_basic_info() { //--- click on the name area to center the map on it ---// if( mouse.single_click(INFO_X1, INFO_Y1, INFO_X2, INFO_Y1+21) ) { world.go_loc( center_x, center_y ); return 1; } //----------- Mobilize the builder ---------// int detectBuilder = builder_recno && !under_construction && unit_array[builder_recno]->is_own(); // this is your unit in your firm or it is a spy of yours in an enemy firm if( detectBuilder && button_builder.detect(0, 0, 1) ) // 1-detect right button also { if( !remote.is_enable() ) set_builder(0); else { // packet structure : <firm recno> short *shortPtr = (short *)remote.new_send_queue_msg(MSG_FIRM_MOBL_BUILDER, sizeof(short)); *shortPtr = firm_recno; } return 1; } //---------------------------------------// if( !own_firm() ) return 0; //---------- "Destruct" button -----------// if( button_destruct.detect(KEY_DEL) ) { if( under_construction ) cancel_construction(COMMAND_PLAYER); else destruct_firm(COMMAND_PLAYER); return 1; } //------------ "Sell" button -------------// if( button_sell.detect(KEY_DEL) ) { sell_firm(COMMAND_PLAYER); return 1; } return 0; }
//--------- Begin of function FirmInn::assign_unit ---------// // void FirmInn::assign_unit(int unitRecno) { //------- if this is a construction worker -------// if( unit_array[unitRecno]->skill.skill_id == SKILL_CONSTRUCTION ) { set_builder(unitRecno); return; } /* //--- can only assign if the unit is a spy cloaked into this firm's nation color ---// if( !unitPtr->spy_recno || unitPtr->nation_recno != nation_recno ) return; //---------------------------------------------// if( inn_unit_count == MAX_INN_UNIT ) return; err_when( inn_unit_count > MAX_INN_UNIT ); err_when( !unitRecno ); Unit* unitPtr = unit_array[unitRecno]; //--------- add the InnUnit --------// InnUnit *innUnit = inn_unit_array+inn_unit_count; inn_unit_count++; //--------- set InnUnit vars -----------------// innUnit->unit_id = unitPtr->unit_id; innUnit->skill = unitPtr->skill; innUnit->spy_recno = unitPtr->spy_recno; innUnit->set_hire_cost(); unitPtr->deinit_sprite(); */ }
//--------- Begin of function FirmBase::assign_unit ---------// // void FirmBase::assign_unit(int unitRecno) { Unit* unitPtr = unit_array[unitRecno]; //### begin alex 18/9 ###// /*//------ only assign units of the right race ------// if( unitPtr->race_id != race_id ) return;*/ //#### end alex 18/9 ####// //------- if this is a construction worker -------// if( unitPtr->skill.skill_id == SKILL_CONSTRUCTION ) { set_builder(unitRecno); return; } //### begin alex 18/9 ###// //------ only assign units of the right race ------// if( unitPtr->race_id != race_id ) return; //#### end alex 18/9 ####// //-------- assign the unit ----------// int rankId = unit_array[unitRecno]->rank_id; if( rankId == RANK_GENERAL || rankId==RANK_KING ) { assign_overseer(unitRecno); } else { assign_worker(unitRecno); } }
//---- Begin of function FirmMine::builder_stay_after_construction ----// // // This function is called by Firm::process_construction() // to assign the builder into the firm after the construction // of the firm is complete. // // return: <int> 1 - the builder has been successfully assigned // into the firm. // 0 - failed. // int FirmMine::builder_stay_after_construction() { //---------- only for AI ----------// if( !is_ai ) return 0; //--- if there is no linked town, use the builder to build one ---// if( linked_town_count==0 ) { int builderRecno = builder_recno; set_builder(0); // mobilize the builder and reset builder_recno ai_build_neighbor_town(builderRecno); // order the unit to build town return 1; } return 0; }
//--------- Begin of function Firm::init --------// // // It will initialize vars, and set the world matrix. // Before calling init(), firm_recno should be set // // Note : it will set world matrix regardless the existing location content, // so you must ensure that the location is clean by calling // world.zoom_matrix->add_firm_test() // // <int> xLoc, yLoc = the location of firm in the world map // <int> nationRecno = the recno of nation which build this firm // <int> firmId = id(type) of the firm // [char*] buildCode = the build code of the firm, no need to give if the firm just have one build type // [short] builderRecno = recno of the builder unit // void Firm::init(int xLoc, int yLoc, int nationRecno, int firmId, char* buildCode, short builderRecno) { FirmInfo* firmInfo = firm_res[firmId]; firm_id = firmId; if( buildCode ) firm_build_id = firmInfo->get_build_id(buildCode); if( !buildCode || !firm_build_id ) // some buildings like human offensive structures do not have different buildings for different nationality, so firm_build_id will be 0 firm_build_id = firmInfo->first_build_id; //----------- set vars -------------// nation_recno = nationRecno; setup_date = info.game_date; //----- set the firm's absolute positions on the map -----// FirmBuild* firmBuild = firm_res.get_build(firm_build_id); FirmBitmap* firmBitmap; race_id = firmInfo->get_race_id(buildCode); if( !race_id ) // some firms like human offensive structures do not have race_id. race_id = nation_array[nation_recno]->race_id; err_when( is_human() == (firmId >= FIRM_LAIR && firmId <= FIRM_MAGIC) ); // error when a human attempts to build a monster firm or a mosnter attempts to build a human firm loc_x1 = xLoc; loc_y1 = yLoc; loc_x2 = loc_x1 + firmBuild->loc_width - 1; loc_y2 = loc_y1 + firmBuild->loc_height - 1; center_x = (loc_x1 + loc_x2) / 2; center_y = (loc_y1 + loc_y2) / 2; region_id = world.get_region_id( center_x, center_y ); // get the height of the top left corner // altitude = world.get_corner(xLoc, yLoc)->get_altitude(); altitude = world.get_corner(loc_x2+1, loc_y2+1)->get_altitude(); abs_x1 = world.zoom_matrix->calc_abs_x(xLoc * LOCATE_WIDTH, yLoc * LOCATE_HEIGHT, altitude) + firmBuild->min_offset_x; abs_y1 = world.zoom_matrix->calc_abs_y(xLoc * LOCATE_WIDTH, yLoc * LOCATE_HEIGHT, altitude) + firmBuild->min_offset_y; abs_x2 = abs_x1 + firmBuild->max_bitmap_width - 1; abs_y2 = abs_y1 + firmBuild->max_bitmap_height - 1; //--------- set animation frame vars ---------// int bitmapCount; int firstBitmap; int frameCount = firmBuild->frame_count; int aniPartCount = firmBuild->ani_part_count; // ##### begin Gilbert 30/10 ######// err_when( aniPartCount < 0 ); err_when( aniPartCount > MAX_FRAME_COUNTERS ); // firm_cur_frame = (char*) mem_add( sizeof(char) *aniPartCount); // firm_remain_frame_delay = (char*) mem_add( sizeof(char) *aniPartCount); // ##### end Gilbert 30/10 ######// // even not animation_full_size will have aniPartCount = 1 (set in firmres.cpp) for (int i = 0; i < aniPartCount ; i++) { firm_cur_frame[i] = 1; if( firmBuild->animate_full_size ) // animate_full_size only supports animation of looping // it does not support random animation and in fact // it is now only used for no animation buildings firm_remain_frame_delay[i] = (char) firmBuild->frame_delay(1); else { // not animate_full_size supports animation of looping and // random animation and partial animation // unlike the animate_full_size animation, it search starting // from the 2nd frame for bitmaps (since now 1 frame may has more // than 1 bitmap) with same animation part no. of the currently // searching part no., i. Then assign this animation part's delay and // set its current_frame to the first found frame for ( int k=1; k <frameCount; k++ ) { firstBitmap = firmBuild->first_bitmap(k+1); bitmapCount = firmBuild->bitmap_count(k+1); int j; for ( j=0; j <bitmapCount; j++ ) { firmBitmap = firm_res.get_bitmap(firstBitmap + j); if( firmBitmap ) { if (firmBitmap->ani_part == (i + 1)) { firm_remain_frame_delay[i] = firmBitmap->delay; firm_cur_frame[i] = k + 1; break; } } } if (j < bitmapCount) break; } } } //--------- initialize gaming vars ----------// hit_points = (float) 0; place_max_hit_points = firmInfo->max_hit_points; // #### begin Gilbert 6/11 ######// defense_attribute = firmBuild->defense_attribute; // #### end Gilbert 6/11 ######// //------ set construction and builder -------// under_construction = firmInfo->buildable; // whether the firm is under construction, if the firm is not buildable it is completed in the first place if( !under_construction ) // if this firm doesn't been to be constructed, set its hit points to the maximum hit_points = place_max_hit_points; if( builderRecno ) set_builder(builderRecno); else builder_recno = 0; //------ update firm counter -------// firmInfo->total_firm_count++; if( nation_recno ) firmInfo->inc_nation_firm_count(nation_recno); //-------------------------------------------// if( nation_recno > 0 ) { Nation* nationPtr = nation_array[nation_recno]; is_ai = nationPtr->is_ai(); ai_processed = 1; //--------- increase firm counter -----------// nationPtr->nation_firm_count++; //-------- update last build date ------------// nationPtr->last_build_firm_date = info.game_date; } else { is_ai = 0; ai_processed = 0; } ai_status = FIRM_WITHOUT_ACTION; ai_link_checked = 1; // check the connected firms if ai_link_checked = 0; //--------------------------------------------// active_link_town_recno = 0; setup_link(); set_world_matrix(); init_name(); //----------- init AI -----------// if( nation_recno ) nation_array[nation_recno]->add_firm_info(firm_id, firm_recno); //-------- init derived ---------// init_derived(); // init_derived() before set_world_matrix() so that init_derived has access to the original land info. //-------- dynamic loading of firm bitmaps ---------// firmBuild->load_bitmap_res(); }