+VG_STATIC int gate_intersect( teleport_gate *gate, v3f pos, v3f last )
+{
+ v2f xy;
+
+ if( gate_intersect_plane( gate, pos, last, xy ) )
+ {
+ if( fabsf(xy[0]) <= 1.0f && fabsf(xy[1]) <= 1.0f )
+ {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+struct gate_hit
+{
+ struct nonlocal_gate *nonlocal;
+ struct route_gate *route;
+ teleport_gate *gate;
+};
+
+/*
+ * Intersect all gates in the world
+ */
+VG_STATIC int world_intersect_gates( world_instance *world,
+ v3f pos, v3f last, struct gate_hit *hit )
+{
+ for( int i=0; i<world->gate_count; i++ )
+ {
+ struct route_gate *rg = &world->gates[i];
+ teleport_gate *gate = &rg->gate;
+
+ if( gate_intersect( gate, pos, last ) )
+ {
+ hit->gate = gate;
+ hit->nonlocal = NULL;
+ hit->route = rg;
+ return 1;
+ }
+ }
+
+ for( int i=0; i<world->nonlocalgate_count; i++ )
+ {
+ struct nonlocal_gate *nlg = &world->nonlocal_gates[i];
+ teleport_gate *gate = &nlg->gate;
+
+ if( gate_intersect( gate, pos, last ) )
+ {
+ hit->gate = gate;
+ hit->nonlocal = nlg;
+ hit->route = NULL;
+ return 1;
+ }
+ }
+
+ return 0;
+}
+