From: terencehill Date: Fri, 30 Mar 2018 14:24:58 +0000 (+0200) Subject: Bot waypoints: save symmetry settings into waypoint files on waypoint save and load... X-Git-Tag: xonotic-v0.8.5~2174^2~4 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=682699baead66b0e02be04c6e6e994f4804fcd61;p=xonotic%2Fxonotic-data.pk3dir.git Bot waypoints: save symmetry settings into waypoint files on waypoint save and load them back into g_waypointeditor_symmetrical* cvars on map start --- diff --git a/qcsrc/server/autocvars.qh b/qcsrc/server/autocvars.qh index e9bacafa7..f6557275c 100644 --- a/qcsrc/server/autocvars.qh +++ b/qcsrc/server/autocvars.qh @@ -240,6 +240,7 @@ float autocvar_g_turrets_targetscan_mindelay; bool autocvar_g_use_ammunition; bool autocvar_g_waypointeditor; bool autocvar_g_waypointeditor_symmetrical; +bool autocvar_g_waypointeditor_symmetrical_allowload; vector autocvar_g_waypointeditor_symmetrical_origin; int autocvar_g_waypointeditor_symmetrical_order; vector autocvar_g_waypointeditor_symmetrical_axis; diff --git a/qcsrc/server/bot/default/waypoints.qc b/qcsrc/server/bot/default/waypoints.qc index fa82d926b..384f1e7ce 100644 --- a/qcsrc/server/bot/default/waypoints.qc +++ b/qcsrc/server/bot/default/waypoints.qc @@ -1028,10 +1028,33 @@ void waypoint_saveall() return; } - // add 3 comments to not break compatibility with older Xonotic versions + float sym = autocvar_g_waypointeditor_symmetrical; + string sym_str = ftos(sym); + if (sym == -1 || (sym == 1 && autocvar_g_waypointeditor_symmetrical_order >= 2)) + { + if (sym == 1) + { + sym_str = cons(sym_str, "-"); + sym_str = cons(sym_str, "-"); + } + else + { + sym_str = cons(sym_str, ftos(autocvar_g_waypointeditor_symmetrical_origin.x)); + sym_str = cons(sym_str, ftos(autocvar_g_waypointeditor_symmetrical_origin.y)); + } + if (autocvar_g_waypointeditor_symmetrical_order >= 2) + sym_str = cons(sym_str, ftos(autocvar_g_waypointeditor_symmetrical_order)); + } + else if (autocvar_g_waypointeditor_symmetrical == -2) + { + sym_str = cons(sym_str, ftos(autocvar_g_waypointeditor_symmetrical_axis.x)); + sym_str = cons(sym_str, ftos(autocvar_g_waypointeditor_symmetrical_axis.y)); + } + + // a group of 3 comments doesn't break compatibility with older Xonotic versions // (they are read as a waypoint with origin '0 0 0' and flag 0 though) fputs(file, strcat("//", "WAYPOINT_VERSION ", ftos_decimals(WAYPOINT_VERSION, 2), "\n")); - fputs(file, strcat("//", "\n")); + fputs(file, strcat("//", "WAYPOINT_SYMMETRY ", sym_str, "\n")); fputs(file, strcat("//", "\n")); int c = 0; @@ -1085,6 +1108,8 @@ float waypoint_loadall() bool parse_comments = true; float ver = 0; + float sym = 0; + float sym_param1 = 0, sym_param2 = 0, sym_param3 = 0; while ((s = fgets(file))) { @@ -1094,6 +1119,14 @@ float waypoint_loadall() { if(substring(s, 2, 17) == "WAYPOINT_VERSION ") ver = stof(substring(s, 19, -1)); + else if(substring(s, 2, 18) == "WAYPOINT_SYMMETRY ") + { + int tokens = tokenizebyseparator(substring(s, 20, -1), " "); + if (tokens) { sym = stof(argv(0)); } + if (tokens > 1) { sym_param1 = stof(argv(1)); } + if (tokens > 2) { sym_param2 = stof(argv(2)); } + if (tokens > 3) { sym_param3 = stof(argv(3)); } + } continue; } else @@ -1124,6 +1157,35 @@ float waypoint_loadall() fclose(file); LOG_TRACE("loaded ", ftos(cwp), " waypoints and ", ftos(cwb), " wayboxes from maps/", mapname, ".waypoints"); + if (autocvar_g_waypointeditor && autocvar_g_waypointeditor_symmetrical_allowload) + { + cvar_set("g_waypointeditor_symmetrical", ftos(sym)); + if (sym == 1 && sym_param3 < 2) + cvar_set("g_waypointeditor_symmetrical_order", "0"); // make sure this is reset if not loaded + if (sym == -1 || (sym == 1 && sym_param3 >= 2)) + { + string params; + if (sym == 1) + params = cons("-", "-"); + else + { + params = cons(ftos(sym_param1), ftos(sym_param2)); + cvar_set("g_waypointeditor_symmetrical_origin", params); + } + cvar_set("g_waypointeditor_symmetrical_order", ftos(sym_param3)); + LOG_INFO("Waypoint editor: loaded symmetry ", ftos(sym), " with origin ", params, " and order ", ftos(sym_param3)); + } + else if (sym == -2) + { + string params = strcat(ftos(sym_param1), " ", ftos(sym_param2)); + cvar_set("g_waypointeditor_symmetrical_axis", params); + LOG_INFO("Waypoint editor: loaded symmetry ", ftos(sym), " with axis ", params); + } + else + LOG_INFO("Waypoint editor: loaded symmetry ", ftos(sym)); + LOG_INFO(strcat("g_waypointeditor_symmetrical", " has been set to ", cvar_string("g_waypointeditor_symmetrical"))); + } + return cwp + cwb; } diff --git a/xonotic-server.cfg b/xonotic-server.cfg index 29d5c2f67..8200daf19 100644 --- a/xonotic-server.cfg +++ b/xonotic-server.cfg @@ -170,6 +170,7 @@ set bot_ai_timeitems_minrespawndelay 25 "bots run to items with this minimum res set g_waypointeditor 0 set g_waypointeditor_auto 0 "Automatically create waypoints for bots while playing; BEWARE, this currently creates too many of them" set g_waypointeditor_symmetrical 0 "Enable symmetrical editing of waypoints on symmetrical CTF maps (NOTE: it assumes that the map is perfectly symmetrical). 1: automatically determine origin of symmetry; -1: use custom origin (g_waypointeditor_symmetrical_origin); 2: automatically determine axis of symmetry; -2: use custom axis (g_waypointeditor_symmetrical_axis)" +set g_waypointeditor_symmetrical_allowload 1 "Allow loading symmetry settings from waypoint files into g_waypointeditor_symmetrical* cvars on map start" set g_waypointeditor_symmetrical_origin "0 0" "Custom origin of symmetry (x y)" set g_waypointeditor_symmetrical_order 0 "if >= 2 apply rotational symmetry (around origin of symmetry) of this order, otherwise apply autodetected order of symmetry" set g_waypointeditor_symmetrical_axis "0 0" "Custom axis of symmetry (m q parameters of y = mx + q)"