@@ -3555,33 +3555,31 @@ int Fred_mission_save::save_objects()
35553555 fout (" \n $Arrival Anchor:" );
35563556 }
35573557
3558- z = shipp->arrival_anchor ;
3558+ z = shipp->arrival_anchor . value () ;
35593559 if (z < 0 ) {
35603560 fout (" <error>" );
3561- } else if (z & SPECIAL_ARRIVAL_ANCHOR_FLAG ) {
3561+ } else if (z & ANCHOR_SPECIAL_ARRIVAL ) {
35623562 // get name
35633563 char tmp[NAME_LENGTH + 15 ];
35643564 stuff_special_arrival_anchor_name (tmp, z, save_config.save_format == MissionFormat::RETAIL );
35653565
35663566 // save it
35673567 fout (" %s" , tmp);
35683568 } else {
3569- fout (" %s" , Ships[z].ship_name );
3569+ auto anchor_entry = ship_registry_get (z);
3570+ fout (" %s" , anchor_entry ? anchor_entry->name : " <error>" );
35703571 }
35713572 }
35723573
35733574 // Goober5000
35743575 if (save_config.save_format != MissionFormat::RETAIL ) {
35753576 if ((shipp->arrival_location == ArrivalLocation::FROM_DOCK_BAY ) && (shipp->arrival_path_mask > 0 )) {
3576- int anchor_shipnum;
3577- polymodel* pm;
3578-
3579- anchor_shipnum = shipp->arrival_anchor ;
3580- Assert (anchor_shipnum >= 0 && anchor_shipnum < MAX_SHIPS );
3577+ auto anchor_entry = ship_registry_get (shipp->arrival_anchor );
3578+ Assertion (anchor_entry, " Could not find arrival anchor for ship %s!" , shipp->ship_name );
3579+ auto pm = model_get (anchor_entry->sip ()->model_num );
35813580
35823581 fout (" \n +Arrival Paths: ( " );
35833582
3584- pm = model_get (Ship_info[Ships[anchor_shipnum].ship_info_index ].model_num );
35853583 for (auto n = 0 ; n < pm->ship_bay ->num_paths ; n++) {
35863584 if (shipp->arrival_path_mask & (1 << n)) {
35873585 fout (" \" %s\" " , pm->paths [pm->ship_bay ->path_indexes [n]].name );
@@ -3618,24 +3616,19 @@ int Fred_mission_save::save_objects()
36183616 required_string_fred (" $Departure Anchor:" );
36193617 parse_comments ();
36203618
3621- if (shipp->departure_anchor >= 0 )
3622- fout (" %s" , Ships[shipp->departure_anchor ].ship_name );
3623- else
3624- fout (" <error>" );
3619+ auto anchor_entry = ship_registry_get (shipp->departure_anchor );
3620+ fout (" %s" , anchor_entry ? anchor_entry->name : " <error>" );
36253621 }
36263622
36273623 // Goober5000
36283624 if (save_config.save_format != MissionFormat::RETAIL ) {
36293625 if ((shipp->departure_location == DepartureLocation::TO_DOCK_BAY ) && (shipp->departure_path_mask > 0 )) {
3630- int anchor_shipnum;
3631- polymodel* pm;
3632-
3633- anchor_shipnum = shipp->departure_anchor ;
3634- Assert (anchor_shipnum >= 0 && anchor_shipnum < MAX_SHIPS );
3626+ auto anchor_entry = ship_registry_get (shipp->departure_anchor );
3627+ Assertion (anchor_entry, " Could not find departure anchor for ship %s!" , shipp->ship_name );
3628+ auto pm = model_get (anchor_entry->sip ()->model_num );
36353629
36363630 fout (" \n +Departure Paths: ( " );
36373631
3638- pm = model_get (Ship_info[Ships[anchor_shipnum].ship_info_index ].model_num );
36393632 for (auto n = 0 ; n < pm->ship_bay ->num_paths ; n++) {
36403633 if (shipp->departure_path_mask & (1 << n)) {
36413634 fout (" \" %s\" " , pm->paths [pm->ship_bay ->path_indexes [n]].name );
@@ -4932,33 +4925,31 @@ int Fred_mission_save::save_wings()
49324925 else
49334926 fout (" \n $Arrival Anchor:" );
49344927
4935- int z = w.arrival_anchor ;
4928+ int z = w.arrival_anchor . value () ;
49364929 if (z < 0 ) {
49374930 fout (" <error>" );
4938- } else if (z & SPECIAL_ARRIVAL_ANCHOR_FLAG ) {
4931+ } else if (z & ANCHOR_SPECIAL_ARRIVAL ) {
49394932 // get name
49404933 char tmp[NAME_LENGTH + 15 ];
49414934 stuff_special_arrival_anchor_name (tmp, z, save_config.save_format == MissionFormat::RETAIL );
49424935
49434936 // save it
49444937 fout (" %s" , tmp);
49454938 } else {
4946- fout (" %s" , Ships[z].ship_name );
4939+ auto anchor_entry = ship_registry_get (z);
4940+ fout (" %s" , anchor_entry ? anchor_entry->name : " <error>" );
49474941 }
49484942 }
49494943
49504944 // Goober5000
49514945 if (save_config.save_format != MissionFormat::RETAIL ) {
49524946 if ((w.arrival_location == ArrivalLocation::FROM_DOCK_BAY ) && (w.arrival_path_mask > 0 )) {
4953- int anchor_shipnum;
4954- polymodel* pm;
4955-
4956- anchor_shipnum = w.arrival_anchor ;
4957- Assert (anchor_shipnum >= 0 && anchor_shipnum < MAX_SHIPS );
4947+ auto anchor_entry = ship_registry_get (w.arrival_anchor );
4948+ Assertion (anchor_entry, " Could not find arrival anchor for wing %s!" , w.name );
4949+ auto pm = model_get (anchor_entry->sip ()->model_num );
49584950
49594951 fout (" \n +Arrival Paths: ( " );
49604952
4961- pm = model_get (Ship_info[Ships[anchor_shipnum].ship_info_index ].model_num );
49624953 for (auto n = 0 ; n < pm->ship_bay ->num_paths ; n++) {
49634954 if (w.arrival_path_mask & (1 << n)) {
49644955 fout (" \" %s\" " , pm->paths [pm->ship_bay ->path_indexes [n]].name );
@@ -4991,24 +4982,19 @@ int Fred_mission_save::save_wings()
49914982 required_string_fred (" $Departure Anchor:" );
49924983 parse_comments ();
49934984
4994- if (w.departure_anchor >= 0 )
4995- fout (" %s" , Ships[w.departure_anchor ].ship_name );
4996- else
4997- fout (" <error>" );
4985+ auto anchor_entry = ship_registry_get (w.departure_anchor );
4986+ fout (" %s" , anchor_entry ? anchor_entry->name : " <error>" );
49984987 }
49994988
50004989 // Goober5000
50014990 if (save_config.save_format != MissionFormat::RETAIL ) {
50024991 if ((w.departure_location == DepartureLocation::TO_DOCK_BAY ) && (w.departure_path_mask > 0 )) {
5003- int anchor_shipnum;
5004- polymodel* pm;
5005-
5006- anchor_shipnum = w.departure_anchor ;
5007- Assert (anchor_shipnum >= 0 && anchor_shipnum < MAX_SHIPS );
4992+ auto anchor_entry = ship_registry_get (w.departure_anchor );
4993+ Assertion (anchor_entry, " Could not find departure anchor for wing %s!" , w.name );
4994+ auto pm = model_get (anchor_entry->sip ()->model_num );
50084995
50094996 fout (" \n +Departure Paths: ( " );
50104997
5011- pm = model_get (Ship_info[Ships[anchor_shipnum].ship_info_index ].model_num );
50124998 for (auto n = 0 ; n < pm->ship_bay ->num_paths ; n++) {
50134999 if (w.departure_path_mask & (1 << n)) {
50145000 fout (" \" %s\" " , pm->paths [pm->ship_bay ->path_indexes [n]].name );
0 commit comments