int main() { int array[10] = {4, 2, 9, 7, 0, 1, 5, 3, 6, 8}; int array2[5] = {2, 3, 8, 6, 1}; divide_array(array, 0, 9); printf("The number of inverses are: %d \n", inverses); return 0; }
//--------- Begin of function UnitArray::move_to ---------// // // Order the unit to move to a specific location following the // shortest path. // // <int> destXLoc, destYLoc - the location of the destination. // <int> divided - whether the units are divided by their mobile type // <short*> selectedUnitArray - an array of recno of selected units. // <int> selectedCount - no. of selected units. // [char] remoteAction - whether this is an action carried out by a remote machine or not. // (default: 0) // // Note: the caller function must make sure all units in selectedUnitArray are validate (non-deleted) // void UnitArray::move_to(int destXLoc, int destYLoc, int divided, short* selectedUnitArray, int selectedCount, char remoteAction) { err_when(destXLoc<0 || destYLoc<0 || destXLoc>MAX_WORLD_X_LOC-1 || destYLoc>MAX_WORLD_Y_LOC-1); //-------- if it's a multiplayer game --------// if( !remoteAction && remote.is_enable() ) { short* shortPtr = (short*) remote.new_send_queue_msg(MSG_UNIT_MOVE, sizeof(short) * (4+selectedCount) ); shortPtr[0] = destXLoc; shortPtr[1] = destYLoc; shortPtr[2] = selectedCount; shortPtr[3] = divided; memcpy( shortPtr+4, selectedUnitArray, sizeof(short) * selectedCount ); } else { err_when( selectedCount > 10000 ); // error if(!divided) { //----------- divide units ------------// divide_array(destXLoc, destYLoc, selectedUnitArray, selectedCount); //---------- process group move --------------// // ##### patch begin Gilbert 18/8 ######// if(selected_land_unit_count) move_to(destXLoc, destYLoc, 1, selected_land_unit_array, selected_land_unit_count, COMMAND_AUTO); if(selected_sea_unit_count) { Location *locPtr = world.get_loc(destXLoc, destYLoc); if(terrain_res[locPtr->terrain_id]->average_type == TERRAIN_OCEAN) move_to(destXLoc, destYLoc, 1, selected_sea_unit_array, selected_sea_unit_count, COMMAND_AUTO); else ship_to_beach(destXLoc, destYLoc, 1, selected_sea_unit_array, selected_sea_unit_count, COMMAND_AUTO); } if(selected_air_unit_count) move_to(destXLoc, destYLoc, 1, selected_air_unit_array, selected_air_unit_count, COMMAND_AUTO); // ##### patch end Gilbert 18/8 ######// //---------------- deinit static parameters ------------------// selected_land_unit_count = selected_sea_unit_count = selected_air_unit_count = 0; mem_del(selected_land_unit_array); mem_del(selected_sea_unit_array); mem_del(selected_air_unit_array); return; } else { //---------------------------------------------------------// // set the unit_group_id //---------------------------------------------------------// Unit* unitPtr; DWORD curGroupId = unit_array.cur_group_id++; for(int k=0; k<selectedCount; k++) { unitPtr = (Unit*) get_ptr(selectedUnitArray[k]); err_when(!unitPtr); err_when(!unitPtr->is_visible() || unitPtr->hit_points<=0); unitPtr->unit_group_id = curGroupId; unitPtr->action_mode = ACTION_MOVE; unitPtr->action_para = 0; if(unitPtr->action_mode2!=ACTION_MOVE) { unitPtr->action_mode2 = ACTION_MOVE; unitPtr->action_para2 = 0; unitPtr->action_x_loc2 = unitPtr->action_y_loc2 = -1; }// else keep the data to check whether same action mode is ordered } //--------------------------------------------------------------// // if only the leader unit is moving, no need to use formation // movement although the button is pushed //--------------------------------------------------------------// if(selectedCount==1) { unitPtr = (Unit*) get_ptr(selectedUnitArray[0]); unitPtr->move_to(destXLoc, destYLoc, 1); } else { Unit *firstUnitPtr = operator[](selectedUnitArray[0]); if(firstUnitPtr->mobile_type==UNIT_LAND) { move_to_now_with_filter(destXLoc, destYLoc, selectedUnitArray, selectedCount); seek_path.set_sub_mode(); // reset sub_mode searching seek_path_reuse.set_sub_mode(); //------ reset sub mode of path reuse searching } else move_to_now_with_filter(destXLoc, destYLoc, selectedUnitArray, selectedCount); } } } }