| 195 | // CWorldObjectsPlayerDialog message handlers |
| 196 | |
| 197 | void CWorldObjectsPlayerDialog::OnAddPship() { |
| 198 | char filename[256], dir[256], fname[256], ext[32]; |
| 199 | char cur_name[100]; |
| 200 | int img_handle; |
| 201 | int ship_handle; |
| 202 | int c = 1, finding_name = 1; |
| 203 | |
| 204 | if (!Network_up) { |
| 205 | OutrageMessageBox("Sorry babe, the network is down. This action is a no-no.\n"); |
| 206 | return; |
| 207 | } |
| 208 | |
| 209 | // Get the filename of the representing image |
| 210 | |
| 211 | CString filter = "Descent III files (*.pof,*.oof)|*.pof;*.oof||"; |
| 212 | |
| 213 | if (!OpenFileDialog(this, (LPCTSTR)filter, filename, Current_model_dir, sizeof(Current_model_dir))) |
| 214 | return; |
| 215 | |
| 216 | ddio_SplitPath(filename, dir, fname, ext); |
| 217 | |
| 218 | // Okay, we selected a file. Lets do what needs to be done here. |
| 219 | img_handle = LoadShipImage(filename); |
| 220 | |
| 221 | if (img_handle < 0) { |
| 222 | OutrageMessageBox("Couldn't open that model file."); |
| 223 | return; |
| 224 | } |
| 225 | |
| 226 | // Alloc a ship and give a name not already taken by some other ship |
| 227 | |
| 228 | ship_handle = AllocShip(); |
| 229 | |
| 230 | while (finding_name) { |
| 231 | if (c == 1) |
| 232 | sprintf(cur_name, "%s", fname); |
| 233 | else |
| 234 | sprintf(cur_name, "%s%d", fname, c); |
| 235 | if (FindShipName(cur_name) != -1) |
| 236 | c++; |
| 237 | else |
| 238 | finding_name = 0; |
| 239 | } |
| 240 | |
| 241 | strcpy(Ships[ship_handle].name, cur_name); |
| 242 | |
| 243 | Ships[ship_handle].model_handle = img_handle; |
| 244 | |
| 245 | // Finally, save a local copy of the model/anim and alloc a tracklock |
| 246 | mprintf(0, "Making a copy of this model locally...\n"); |
| 247 | |
| 248 | std::filesystem::path destname = LocalModelsDir / Poly_models[Ships[ship_handle].model_handle].name; |
| 249 | cf_CopyFile(destname, filename); |
| 250 | |
| 251 | mng_AllocTrackLock(cur_name, PAGETYPE_SHIP); |
| 252 | |
| 253 | D3EditState.current_ship = ship_handle; |
| 254 |
nothing calls this directly
no test coverage detected