use of fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_stargates_stargate_id in project JCELechat by guiguilechat.
the class Universe method computeDistance.
/**
* get the trip distance, from one station to the sun of a system
*
* @param systemOrigin
* @param systemDest
* @return the number of jumps and the total amount of UA to jump
*/
protected TripDistance computeDistance(R_get_universe_stations_station_id station, R_get_universe_systems_system_id destination) {
TripDistance ret = new TripDistance();
if (pochvenSystems == null) {
synchronized (this) {
if (pochvenSystems == null) {
List<ObjHolder<R_get_universe_constellations_constellation_id>> constellations = IntStream.of(con.cache().universe.regions(10000070).get().constellations).mapToObj(c -> con.cache().universe.constellations(c)).collect(Collectors.toList());
pochvenSystems = constellations.parallelStream().flatMapToInt(c -> IntStream.of(c.get().systems)).toArray();
log.debug("pochven systems are " + IntStream.of(pochvenSystems).boxed().collect(Collectors.toList()));
}
}
}
List<R_get_universe_systems_system_id> systems = con.cache().route.get(pochvenSystems, null, destination.system_id, flag.secure, station.system_id).get().parallelStream().map(si -> cache.systems(si).get()).collect(Collectors.toList());
M_3_xnumber_ynumber_znumber lastPos = station.position;
R_get_universe_systems_system_id lastSys = cache.systems(station.system_id).get();
// System.err.println("starting from " + station.name);
for (R_get_universe_systems_system_id nextSys : systems) {
if (nextSys.system_id == lastSys.system_id) {
continue;
}
R_get_universe_systems_system_id flastSys = lastSys;
R_get_universe_stargates_stargate_id nextGate = IntStream.of(lastSys.stargates).mapToObj(stargate -> cache.stargates(stargate).get()).filter(sg -> sg.destination.system_id == nextSys.system_id).findFirst().orElseThrow(() -> new RuntimeException("can't find gate from " + flastSys.name + " to " + nextSys.name));
double dist_AU = distance(lastPos, nextGate.position) / M_PER_AU;
// System.err.println("dist to " + nextSys.name + " is " + dist_AU);
ret.AU += dist_AU;
ret.jumps++;
lastSys = nextSys;
lastPos = cache.stargates(nextGate.destination.stargate_id).get().position;
}
double dist_AU = distance(lastPos, SUN_POS) / M_PER_AU;
// System.err.println("dist to sun is " + dist_AU);
ret.AU += dist_AU;
return ret;
}
Aggregations