Search in sources :

Example 1 with M_3_xnumber_ynumber_znumber

use of fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.M_3_xnumber_ynumber_znumber 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;
}
Also used : IntStream(java.util.stream.IntStream) R_get_universe_stations_station_id(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_stations_station_id) Accessors(lombok.experimental.Accessors) Getter(lombok.Getter) ObjHolderSimple(fr.lelouet.tools.holders.impl.ObjHolderSimple) HashMap(java.util.HashMap) ESIStatic(fr.guiguilechat.jcelechat.jcesi.disconnected.ESIStatic) MapHolder(fr.lelouet.tools.holders.interfaces.collections.MapHolder) R_get_universe_factions(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_factions) M_3_xnumber_ynumber_znumber(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.M_3_xnumber_ynumber_znumber) fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.flag(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.flag) Map(java.util.Map) R_get_universe_planets_planet_id(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_planets_planet_id) ListHolder(fr.lelouet.tools.holders.interfaces.collections.ListHolder) R_post_universe_names(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_post_universe_names) R_get_universe_stargates_stargate_id(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_stargates_stargate_id) ObjHolder(fr.lelouet.tools.holders.interfaces.ObjHolder) R_get_universe_constellations_constellation_id(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_constellations_constellation_id) SetHolder(fr.lelouet.tools.holders.interfaces.collections.SetHolder) Collectors(java.util.stream.Collectors) Requested(fr.guiguilechat.jcelechat.jcesi.interfaces.Requested) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) R_get_universe_system_kills(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_system_kills) R_get_universe_systems_system_id(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_systems_system_id) ObjHolder(fr.lelouet.tools.holders.interfaces.ObjHolder) R_get_universe_stargates_stargate_id(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_stargates_stargate_id) R_get_universe_systems_system_id(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_systems_system_id) M_3_xnumber_ynumber_znumber(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.M_3_xnumber_ynumber_znumber)

Aggregations

ESIStatic (fr.guiguilechat.jcelechat.jcesi.disconnected.ESIStatic)1 Requested (fr.guiguilechat.jcelechat.jcesi.interfaces.Requested)1 M_3_xnumber_ynumber_znumber (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.M_3_xnumber_ynumber_znumber)1 R_get_universe_constellations_constellation_id (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_constellations_constellation_id)1 R_get_universe_factions (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_factions)1 R_get_universe_planets_planet_id (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_planets_planet_id)1 R_get_universe_stargates_stargate_id (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_stargates_stargate_id)1 R_get_universe_stations_station_id (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_stations_station_id)1 R_get_universe_system_kills (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_system_kills)1 R_get_universe_systems_system_id (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_systems_system_id)1 R_post_universe_names (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_post_universe_names)1 fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.flag (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.structures.flag)1 ObjHolderSimple (fr.lelouet.tools.holders.impl.ObjHolderSimple)1 ObjHolder (fr.lelouet.tools.holders.interfaces.ObjHolder)1 ListHolder (fr.lelouet.tools.holders.interfaces.collections.ListHolder)1 MapHolder (fr.lelouet.tools.holders.interfaces.collections.MapHolder)1 SetHolder (fr.lelouet.tools.holders.interfaces.collections.SetHolder)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1