+ else if(nav_action == NAV_SWIM_UNDERWATER)
+ {
+ if (move.z >= org.z) // swimming upwards or horiz.
+ {
+ tracebox(org, m1, m2, move, movemode, e); // swim
+
+ bool stepswimmed = false;
+
+ // hit something
+ if (trace_fraction < 1)
+ {
+ // stepswim
+ vector stepswim_move = move + stepheightvec;
+ if (flatdist > 0 && stepswim_move.z > end2.z) // don't allow stepswim to go higher than destination
+ stepswim_move.z = end2.z;
+
+ tracebox(org + stepheightvec, m1, m2, stepswim_move, movemode, e);
+
+ // hit something
+ if (trace_startsolid)
+ {
+ if(autocvar_bot_debug_tracewalk)
+ debugnodestatus(org, DEBUG_NODE_FAIL);
+
+ //print("tracewalk: ", vtos(start), " hit something when trying to reach ", vtos(end), "\n");
+ return false;
+ }
+
+ if (trace_fraction < 1)
+ {
+ float org_z_prev = org.z;
+ RESURFACE_LIMITED(org, end2.z);
+ if(org.z == org_z_prev)
+ {
+ if(autocvar_bot_debug_tracewalk)
+ debugnodestatus(org, DEBUG_NODE_FAIL);
+
+ //print("tracewalk: ", vtos(start), " can't reach ", vtos(end), "\n");
+ return false;
+ }
+ if(SUBMERGED(org))
+ nav_action = NAV_SWIM_UNDERWATER;
+ else
+ nav_action = NAV_SWIM_ONWATER;
+
+ // we didn't advance horiz. in this step, flatdist decrease should be reverted
+ // but we can't do it properly right now... apply this workaround instead
+ if (flatdist <= 0)
+ flatdist = 1;
+
+ continue;
+ }
+
+ //succesful stepswim
+
+ if (flatdist <= 0)
+ {
+ org = trace_endpos;
+ continue;
+ }
+
+ stepswimmed = true;
+ }
+
+ if (!WETFEET(trace_endpos))
+ {
+ tracebox(trace_endpos, m1, m2, trace_endpos - eZ * (stepdist + (m2.z - m1.z)), movemode, e);
+ // if stepswimmed we'll land on the obstacle, avoid the SUBMERGED check
+ if (!stepswimmed && SUBMERGED(trace_endpos))
+ {
+ RESURFACE_LIMITED(trace_endpos, end2.z);
+ org = trace_endpos;
+ nav_action = NAV_SWIM_ONWATER;
+ continue;
+ }
+
+ // not submerged
+ org = trace_endpos;
+ nav_action = NAV_WALK;
+ continue;
+ }
+
+ // wetfeet
+ org = trace_endpos;
+ nav_action = NAV_SWIM_UNDERWATER;
+ continue;
+ }
+ else //if (move.z < org.z) // swimming downwards
+ {
+ tracebox(org, m1, m2, move, movemode, e); // swim
+
+ // hit something
+ if (trace_fraction < 1)
+ {
+ // stepswim
+ tracebox(org + stepheightvec, m1, m2, move + stepheightvec, movemode, e);
+
+ // hit something
+ if (trace_fraction < 1 || trace_startsolid) // can't jump obstacle out of water
+ {
+ if(autocvar_bot_debug_tracewalk)
+ debugnodestatus(move, DEBUG_NODE_FAIL);
+
+ //print("tracewalk: ", vtos(start), " hit something when trying to reach ", vtos(end), "\n");
+ return false;
+ }
+
+ //succesful stepswim
+
+ if (flatdist <= 0)
+ {
+ org = trace_endpos;
+ continue;
+ }
+
+ if (trace_endpos.z > org.z && !SUBMERGED(trace_endpos))
+ {
+ // stepswim caused upwards direction
+ tracebox(trace_endpos, m1, m2, trace_endpos - stepheightvec, movemode, e);
+ if (!SUBMERGED(trace_endpos))
+ {
+ org = trace_endpos;
+ nav_action = NAV_WALK;
+ continue;
+ }
+ }
+ }
+
+ org = trace_endpos;
+ nav_action = NAV_SWIM_UNDERWATER;
+ continue;
+ }
+ }
+ else if(nav_action == NAV_WALK)