90 |
90 |
91 /* Find an unused waypoint number belonging to this town */ |
91 /* Find an unused waypoint number belonging to this town */ |
92 FOR_ALL_WAYPOINTS(local_wp) { |
92 FOR_ALL_WAYPOINTS(local_wp) { |
93 if (wp == local_wp) continue; |
93 if (wp == local_wp) continue; |
94 |
94 |
95 if (local_wp->xy && local_wp->string == STR_NULL && local_wp->town_index == wp->town_index) |
95 if (local_wp->xy && local_wp->name == NULL && local_wp->town_index == wp->town_index) |
96 used_waypoint[local_wp->town_cn] = true; |
96 used_waypoint[local_wp->town_cn] = true; |
97 } |
97 } |
98 |
98 |
99 /* Find an empty spot */ |
99 /* Find an empty spot */ |
100 for (i = 0; used_waypoint[i] && i < MAX_WAYPOINTS_PER_TOWN; i++) {} |
100 for (i = 0; used_waypoint[i] && i < MAX_WAYPOINTS_PER_TOWN; i++) {} |
101 |
101 |
102 wp->string = STR_NULL; |
102 wp->name = NULL; |
103 wp->town_cn = i; |
103 wp->town_cn = i; |
104 } |
104 } |
105 |
105 |
106 /** |
106 /** |
107 * Find a deleted waypoint close to a tile. |
107 * Find a deleted waypoint close to a tile. |
348 if (!CheckTileOwnership(wp->xy)) return CMD_ERROR; |
348 if (!CheckTileOwnership(wp->xy)) return CMD_ERROR; |
349 |
349 |
350 if (!StrEmpty(_cmd_text)) { |
350 if (!StrEmpty(_cmd_text)) { |
351 if (!IsUniqueWaypointName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); |
351 if (!IsUniqueWaypointName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); |
352 |
352 |
353 StringID str = AllocateName(_cmd_text, 0); |
|
354 |
|
355 if (str == 0) return CMD_ERROR; |
|
356 |
|
357 if (flags & DC_EXEC) { |
353 if (flags & DC_EXEC) { |
358 if (wp->string != STR_NULL) DeleteName(wp->string); |
354 free(wp->name); |
359 |
355 wp->name = strdup(_cmd_text); |
360 wp->string = str; |
|
361 wp->town_cn = 0; |
356 wp->town_cn = 0; |
362 |
357 |
363 UpdateWaypointSign(wp); |
358 UpdateWaypointSign(wp); |
364 MarkWholeScreenDirty(); |
359 MarkWholeScreenDirty(); |
365 } else { |
|
366 DeleteName(str); |
|
367 } |
360 } |
368 } else { |
361 } else { |
369 if (flags & DC_EXEC) { |
362 if (flags & DC_EXEC) { |
370 if (wp->string != STR_NULL) DeleteName(wp->string); |
363 free(wp->name); |
371 |
364 |
372 MakeDefaultWaypointName(wp); |
365 MakeDefaultWaypointName(wp); |
373 UpdateWaypointSign(wp); |
366 UpdateWaypointSign(wp); |
374 MarkWholeScreenDirty(); |
367 MarkWholeScreenDirty(); |
375 } |
368 } |
460 static const SaveLoad _waypoint_desc[] = { |
452 static const SaveLoad _waypoint_desc[] = { |
461 SLE_CONDVAR(Waypoint, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
453 SLE_CONDVAR(Waypoint, xy, SLE_FILE_U16 | SLE_VAR_U32, 0, 5), |
462 SLE_CONDVAR(Waypoint, xy, SLE_UINT32, 6, SL_MAX_VERSION), |
454 SLE_CONDVAR(Waypoint, xy, SLE_UINT32, 6, SL_MAX_VERSION), |
463 SLE_CONDVAR(Waypoint, town_index, SLE_UINT16, 12, SL_MAX_VERSION), |
455 SLE_CONDVAR(Waypoint, town_index, SLE_UINT16, 12, SL_MAX_VERSION), |
464 SLE_CONDVAR(Waypoint, town_cn, SLE_UINT8, 12, SL_MAX_VERSION), |
456 SLE_CONDVAR(Waypoint, town_cn, SLE_UINT8, 12, SL_MAX_VERSION), |
465 SLE_VAR(Waypoint, string, SLE_UINT16), |
457 SLE_CONDVAR(Waypoint, string, SLE_STRINGID, 0, 83), |
|
458 SLE_CONDSTR(Waypoint, name, SLE_STR, 0, 84, SL_MAX_VERSION), |
466 SLE_VAR(Waypoint, deleted, SLE_UINT8), |
459 SLE_VAR(Waypoint, deleted, SLE_UINT8), |
467 |
460 |
468 SLE_CONDVAR(Waypoint, build_date, SLE_FILE_U16 | SLE_VAR_I32, 3, 30), |
461 SLE_CONDVAR(Waypoint, build_date, SLE_FILE_U16 | SLE_VAR_I32, 3, 30), |
469 SLE_CONDVAR(Waypoint, build_date, SLE_INT32, 31, SL_MAX_VERSION), |
462 SLE_CONDVAR(Waypoint, build_date, SLE_INT32, 31, SL_MAX_VERSION), |
470 SLE_CONDVAR(Waypoint, localidx, SLE_UINT8, 3, SL_MAX_VERSION), |
463 SLE_CONDVAR(Waypoint, localidx, SLE_UINT8, 3, SL_MAX_VERSION), |