//--------- Begin of function FirmArray::generate_firm ---------// // // Generate a firm for new games or when editing scenarios. // // <int> xLoc = the x location of the firm to be built // <int> yLoc = the y location of the firm to be built // <int> nationRecno = the nation which builds this firm // <int> firmId = firm type id. // [char*] buildCode = the build code of the firm, no need to give if the firm just have one build type // // Return : <int> the record no. of the newly added firm // int FirmArray::generate_firm(int xLoc, int yLoc, int nationRecno, int firmId, char* buildCode) { int firmRecno = build_firm(xLoc, yLoc, nationRecno, firmId, buildCode, 0, false, true); // true-no cost for building the firm if( !firmRecno ) // no space for building the firm return 0; firm_array[firmRecno]->complete_construction(); return firmRecno; }
//---- Begin of function FirmArray::upgrade_firm ----// // // Upgrade a firm from one type to another. The upgraded firm // must be derived from the original firm. // // <int> oldFirmRecno - the recno of the old firm. // <int> newFirmId - the id. of the new firm. // void FirmArray::upgrade_firm(int oldFirmRecno, int newFirmId) { int oldFirmId = firm_array[oldFirmRecno]->firm_id; int oldFirmSize = firm_class_size(oldFirmId); int newFirmSize = firm_class_size(newFirmId); // ##### begin Gilbert 4/11 ######// int oldSelectedRecno = firm_array.selected_recno; // del_firm may clear firm_array.selected_recno // ##### end Gilbert 4/11 ######// //---- backup this FirmArray first -----// Firm* oldFirmBackup; Firm* oldFirm = firm_array[oldFirmRecno]; oldFirmBackup = (Firm*) mem_add( oldFirmSize ); // use mem_add() instead of new new bypass calling construcnewr and destrucnewr memcpy( oldFirmBackup, oldFirm, oldFirmSize ); //--- reset the content of the derived class before deinit it so that it won't call deinit functions unnecessarily ---// if( oldFirm->firm_id == FIRM_CAMP ) { memset( (char*)oldFirm + sizeof(Firm), 0, sizeof(FirmCamp) - sizeof(Firm) ); } //--- delete this FirmArray and create a new FirmFort ---// del_firm( oldFirmRecno ); disable_reuse_interval(); // temporarily disable reuse interval checking new let the new fort use the same recno as the deleted camp. base_obj_array.disable_reuse_interval(); // temporarily disable reuse interval checking new let the new fort use the same recno as the deleted camp. int newFirmRecno = build_firm( oldFirmBackup->loc_x1, oldFirmBackup->loc_y1, oldFirmBackup->nation_recno, newFirmId, race_res[oldFirmBackup->race_id]->code, 0, 1 ); // 1-upgrade firm enable_reuse_interval(); base_obj_array.enable_reuse_interval(); Firm* newFirm = firm_array[newFirmRecno]; //---- copy the content of the original camp to the new fort ----// oldFirmBackup->upgrading_firm_id = 0; oldFirmBackup->firm_id = newFirm->firm_id; // as we copy firmBackUp to newFirm, we need to preserve some vars oldFirmBackup->firm_build_id = newFirm->firm_build_id; oldFirmBackup->base_obj_recno = newFirm->base_obj_recno; // ####### begin Gilbert 4/11 ######// // selected_recno = newFirmRecno; // ####### end Gilbert 4/11 ######// memcpy( (char*)newFirm + sizeof(void*), (char*)oldFirmBackup + sizeof(void*), oldFirmSize - sizeof(void*) ); //------ free oldFirmBackup -------// mem_del( oldFirmBackup ); // ##### begin Gilbert 4/11 ######// if( oldSelectedRecno == oldFirmRecno ) { firm_array.selected_recno = newFirmRecno; info.disp(); } // ##### end Gilbert 4/11 ######// }
void Unit::resume_original_action() { if( !original_action_mode ) return; //--------- If it is an attack action ---------// if( original_action_mode == ACTION_ATTACK_UNIT || original_action_mode == ACTION_ATTACK_FIRM || original_action_mode == ACTION_ATTACK_TOWN ) { resume_original_attack_action(); return; } //--------------------------------------------// if( original_action_x_loc<0 || original_action_x_loc>=MAX_WORLD_X_LOC || original_action_y_loc<0 || original_action_y_loc>=MAX_WORLD_Y_LOC ) { original_action_mode = 0; return; } short selectedArray[1]; selectedArray[0] = sprite_recno; // use unit_array.attack() instead of unit.attack_???() as we are unsure about what type of object the target is. Location* locPtr = world.get_loc(original_action_x_loc, original_action_y_loc); //--------- resume assign to town -----------// if( original_action_mode == ACTION_ASSIGN_TO_TOWN && locPtr->is_town() ) { if( locPtr->town_recno() == original_action_para && town_array[original_action_para]->nation_recno == nation_recno ) { unit_array.assign( original_action_x_loc, original_action_y_loc, 0, COMMAND_AUTO, selectedArray, 1 ); } } //--------- resume assign to firm ----------// else if( original_action_mode == ACTION_ASSIGN_TO_FIRM && locPtr->is_firm() ) { if( locPtr->firm_recno() == original_action_para && firm_array[original_action_para]->nation_recno == nation_recno ) { unit_array.assign( original_action_x_loc, original_action_y_loc, 0, COMMAND_AUTO, selectedArray, 1 ); } } //--------- resume build firm ---------// else if( original_action_mode == ACTION_BUILD_FIRM ) { if( world.can_build_firm( original_action_x_loc, original_action_y_loc, original_action_para, sprite_recno ) ) { build_firm( original_action_x_loc, original_action_y_loc, original_action_para, COMMAND_AUTO ); } } //--------- resume settle ---------// else if( original_action_mode == ACTION_SETTLE ) { if( world.can_build_town( original_action_x_loc, original_action_y_loc, sprite_recno ) ) { unit_array.settle( original_action_x_loc, original_action_y_loc, 0, COMMAND_AUTO, selectedArray, 1 ); } } //--------- resume move ----------// else if( original_action_mode == ACTION_MOVE ) { unit_array.move_to( original_action_x_loc, original_action_y_loc, 0, selectedArray, 1, COMMAND_AUTO ); } original_action_mode = 0; }