+
+ if (!initial_origin_is_set)
+ {
+ initial_origin = e.origin;
+ initial_origin_is_set = true;
+ }
+
+ entity start_wp = NULL;
+ if (start_wp_is_spawned)
+ {
+ IL_EACH(g_waypoints, (start_wp_is_hardwired || it.wpflags & WPFLAGMASK_NORELINK)
+ && boxesoverlap(start_org, start_org, it.absmin, it.absmax),
+ {
+ start_wp = it; break;
+ });
+ if(!start_wp)
+ {
+ // should not happen
+ LOG_INFOF("Couldn't find start waypoint at %v\n", start_org);
+ waypoint_clear_start_wp_globals(pl, true);
+ return;
+ }
+ if (start_wp_is_hardwired)
+ {
+ if (waypoint_is_hardwiredlink(start_wp, e))
+ {
+ waypoint_unmark_hardwiredlink(start_wp, e);
+ waypoint_removelink(start_wp, e);
+ string s = strcat(vtos(start_wp.origin), "*", vtos(e.origin));
+ LOG_INFOF("^x80fRemoved hardwired link %s.\n", s);
+ }
+ else
+ {
+ if (e.createdtime == time)
+ {
+ LOG_INFO("Error: hardwired links can be created only between 2 existing (and unconnected) waypoints.\n");
+ waypoint_remove(e);
+ waypoint_clear_start_wp_globals(pl, true);
+ waypoint_spawn_fromeditor(pl, at_crosshair, is_jump_wp, is_crouch_wp, is_support_wp);
+ return;
+ }
+ if (start_wp == e)
+ {
+ LOG_INFO("Error: start and destination waypoints coincide.\n");
+ waypoint_clear_start_wp_globals(pl, true);
+ return;
+ }
+ if (waypoint_islinked(start_wp, e))
+ {
+ LOG_INFO("Error: waypoints are already linked.\n");
+ waypoint_clear_start_wp_globals(pl, true);
+ return;
+ }
+ waypoint_addlink(start_wp, e);
+ waypoint_mark_hardwiredlink(start_wp, e);
+ string s = strcat(vtos(start_wp.origin), "*", vtos(e.origin));
+ LOG_INFOF("^x80fAdded hardwired link %s.\n", s);
+ }
+ }
+ else
+ {
+ if (start_wp_is_support)
+ {
+ if (e.SUPPORT_WP)
+ {
+ LOG_INFOF("Waypoint %v has already a support waypoint, delete it first.\n", e.origin);
+ waypoint_clear_start_wp_globals(pl, true);
+ return;
+ }
+ // clear all links to e
+ IL_EACH(g_waypoints, it != e,
+ {
+ if (waypoint_islinked(it, e) && !waypoint_is_hardwiredlink(it, e))
+ waypoint_removelink(it, e);
+ });
+ }
+ waypoint_addlink(start_wp, e);
+ }
+ }
+
+ if (!(jp || is_jump_wp || is_support_wp || start_wp_is_hardwired))
+ waypoint_schedulerelink(e);
+
+ string wp_type_str = waypoint_get_type_name(e);
+
+ bprint(strcat(wp_type_str, "^7 spawned at ", vtos(e.origin), "\n"));
+
+ if (start_wp_is_spawned)
+ {
+ pl.wp_locked = NULL;
+ if (!start_wp_is_hardwired)
+ waypoint_schedulerelink(start_wp);
+ if (start_wp.wpflags & WAYPOINTFLAG_TELEPORT)
+ {
+ if (start_wp.wp00_original == start_wp.wp00)
+ start_wp.wpflags &= ~WAYPOINTFLAG_CUSTOM_JP;
+ else
+ start_wp.wpflags |= WAYPOINTFLAG_CUSTOM_JP;
+ }
+ }
+
+ if (sym)