use of fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_stations_station_id in project JCELechat by guiguilechat.
the class Universe method distancesOneConstelJump.
/**
* get the distances to the sun of systems that are on the constellation, or
* the adjacent constellations, of a station.
*
* @param stationId
* the id of the station
* @return the map for each system to its tripdistance
*/
public Map<R_get_universe_systems_system_id, TripDistance> distancesOneConstelJump(int stationId) {
R_get_universe_stations_station_id station = cache.stations(stationId).get();
R_get_universe_systems_system_id system = cache.systems(station.system_id).get();
List<R_get_universe_systems_system_id> destinations = systemsWithinOneConstelJump(system).collect(Collectors.toList());
return destinations.parallelStream().collect(Collectors.toMap(sys -> sys, sys -> getDistance(station, sys).get()));
}
use of fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_stations_station_id in project JCELechat by guiguilechat.
the class NPCsTranslater method translate.
private static void translate(LinkedHashMap<Integer, Eagents> eagents, LinkedHashMap<String, Agent> agents, LinkedHashMap<String, Corporation> corporations, LinkedHashMap<Integer, LPOffer> offers) {
ESIAccess esi = ESIAccess.INSTANCE;
CacheStatic cache = ESIStatic.INSTANCE.cache();
// prefetch
MapHolder<Integer, R_get_corporations_corporation_id> corporationsHolder = ((ListHolder<Integer>) cache.corporations.npccorps().follow(l -> {
l.parallelStream().forEach(cache.corporations::get);
})).toMap(i -> i, i -> cache.corporations.get(i).get());
MapHolder<Integer, R_get_universe_factions> factionsHolder = cache.universe.factions().toMap(f -> f.faction_id);
eagents.values().parallelStream().map(ag -> ag.locationID).distinct().forEach(lid -> Location.resolve(null, lid).system());
//
LinkedHashMap<Integer, EnpcCorporations> ecorps = EnpcCorporations.load();
Map<Integer, String> idx2name = EinvNames.loadById();
Map<Integer, R_get_corporations_corporation_id> npcCorps = corporationsHolder.get();
Map<Integer, R_get_universe_factions> factionById = factionsHolder.get();
Map<Integer, Location> agentsLocation = eagents.entrySet().parallelStream().collect(Collectors.toMap(eag -> eag.getKey(), eag -> Location.resolve(null, eag.getValue().locationID)));
logger.info("NPC prefetch received");
for (Entry<Integer, Eagents> eagt : eagents.entrySet()) {
Agent agent = new Agent();
Eagents agt = eagt.getValue();
agent.id = eagt.getKey();
agent.corporation = ecorps.get(agt.corporationID).enName();
agent.name = idx2name.get(agent.id);
agent.isLocator = agt.isLocator;
agent.level = agt.level;
agent.type = AGENT_TYPE.of(agt.agentTypeID);
if (agent.type == null) {
logger.warn("no type for agent " + agent.name + " typeID=" + agt.agentTypeID);
}
agent.division = AGENT_DIVISION.of(agt.divisionID);
if (agent.division == null) {
logger.warn("no division for agent " + agent.name + " divisionID=" + agt.divisionID);
}
Location loc = agentsLocation.get(agent.id);
if (loc != null) {
agent.system = loc.system().name;
R_get_universe_stations_station_id station = loc.station();
if (station != null) {
agent.station = station.name;
agent.stationId = agt.locationID;
}
agents.put(agent.name, agent);
} else {
logger.warn("invalid location for agent " + agent.name + " locid=" + agt.locationID);
}
}
logger.info("translated agents data");
for (Entry<Integer, EnpcCorporations> e : ecorps.entrySet()) {
Corporation add = new Corporation();
add.id = e.getKey();
EnpcCorporations snpc = e.getValue();
add.name = snpc.enName();
R_get_universe_factions faction = factionById.get(snpc.factionID);
if (faction == null) {
logger.debug("can't find faction from id " + snpc.factionID + " for corporation " + add.name);
} else {
add.faction = faction.name;
}
R_get_corporations_corporation_id esicorp = npcCorps.get(add.id);
if (esicorp != null && esicorp.faction_id != 0) {
add.warfare = factionById.get(esicorp.faction_id).name;
}
add.concordRate = EnpcCorporations.concordRates().getOrDefault(add.id, 0.0);
if (add.id == EnpcCorporations.CONCORD_ID) {
add.concordRate = 1.0;
}
corporations.put(add.name, add);
}
Map<Integer, LPOffer> covertedOffers = corporations.values().stream().parallel().flatMap(c -> {
Requested<R_get_loyalty_stores_corporation_id_offers[]> req = esi.connection.get_loyalty_stores_offers(c.id, null);
return req.isOk() ? Stream.of(req.getOK()) : Stream.empty();
}).map(offer -> makeOffer(offer)).filter(o -> o != null).collect(Collectors.toMap(off -> off.id, off -> off, (o1, o2) -> o1));
offers.putAll(covertedOffers);
corporations.values().stream().parallel().forEach(c -> loadCorpOffers(c, esi.connection, offers));
}
use of fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_stations_station_id in project JCELechat by guiguilechat.
the class Location method resolve.
/**
* @see https://docs.esi.evetech.net/docs/asset_location_id
*/
public static Location resolve(ESIAccount account, long locationid) {
if (locationid < Integer.MAX_VALUE) {
R_get_universe_stations_station_id station;
int prefix = (int) locationid / 1000000;
switch(prefix) {
case // region
10:
R_get_universe_regions_region_id region = ESIStatic.INSTANCE.cache().universe.regions((int) locationid).get();
return new Location(region, locationid, region.name, LOCTYPE.REGION);
case // constellation
20:
R_get_universe_constellations_constellation_id constel = ESIStatic.INSTANCE.cache().universe.constellations((int) locationid).get();
return new Location(constel, locationid, constel.name, LOCTYPE.CONSTEL);
case 30:
case 31:
case // system
32:
R_get_universe_systems_system_id system = ESIStatic.INSTANCE.cache().universe.systems((int) locationid).get();
return new Location(system, locationid, system.name, LOCTYPE.SYSTEM);
case 60:
case 61:
case 62:
case 63:
case // station
64:
station = ESIStatic.INSTANCE.cache().universe.stations((int) locationid).get();
return new Location(station, locationid, station == null ? "missing" + locationid : station.name, LOCTYPE.STATION);
case // office id
66:
station = ESIStatic.INSTANCE.cache().universe.stations((int) locationid - 6000001).get();
return new Location(station, locationid, station == null ? "missing" + locationid : station.name, LOCTYPE.OFFICE);
case // conquerable office
67:
station = ESIStatic.INSTANCE.cache().universe.stations((int) locationid - 6000000).get();
return new Location(station, locationid, station == null ? "missing" + locationid : station.name, LOCTYPE.CONQSTATION);
default:
logger.warn("locationid not handled " + locationid + " prefix " + prefix);
return new Location(null, locationid, "unknown" + locationid, LOCTYPE.STRUCTURE);
}
} else {
// structures.
if (ESIAccess.INSTANCE.universe.isPublicStructure(locationid)) {
// can't do anything. stil need an account.
}
if (account != null) {
Requested<R_get_universe_structures_structure_id> req = account.connection().get_universe_structures(locationid, null);
if (req.isOk()) {
R_get_universe_structures_structure_id struct = req.getOK();
return new Location(struct, locationid, struct.name, LOCTYPE.STRUCTURE);
}
}
return new Location(null, locationid, "unknown" + locationid, LOCTYPE.STRUCTURE);
}
}
use of fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_stations_station_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