void RouteLink::CalcSpeedups(const TaskProjection& proj) { const fixed scale = proj.GetApproximateScale(); const fixed dx = fixed(first.longitude - second.longitude); const fixed dy = fixed(first.latitude - second.latitude); if (!positive(fabs(dx)) && !positive(fabs(dy))) { d = fixed(0); inv_d = fixed(0); polar_index = 0; return; } mag_rmag(dx, dy, d, inv_d); polar_index = XYToIndex(dx, dy); d *= scale; inv_d /= scale; }
std::pair<bool, DirectionFlags> canChangeMap(const Ndk::EntityHandle& p) { TealAssert(isMapUtilityInitialized(), "Map Utility hasn't been initialized !"); TealAssert(hasComponentsToChangeMap(p), "Entity doesn't have the required components to change map !"); Nz::Vector2i mapPos = m_currentMap->getCurrentMap()->getPosition(); auto& pos = p->GetComponent<PositionComponent>(); TealAssert(isPositionValid(pos.xy), "Position isn't valid"); // Where is the entity in the map ? At the right, left, top, or bottom ? DirectionFlags entExt = 0; // Entity Extremity if (pos.xy.x == 0u && isLineEven(pos.xy.y) && MapDataLibrary::Has(mapXYToString(mapPos.x - 1, mapPos.y))) // Left entExt = Dir::Left; else if (pos.xy.x == Def::MapX && MapDataLibrary::Has(mapXYToString(mapPos.x + 1, mapPos.y))) // Right entExt = Dir::Right; else if (pos.xy.y == 0u && MapDataLibrary::Has(mapXYToString(mapPos.x, mapPos.y - 1))) // Top entExt = Dir::Up; else if (pos.xy.y == Def::ArrayMapY && MapDataLibrary::Has(mapXYToString(mapPos.x, mapPos.y + 1))) // Bottom entExt = Dir::Down; if (!entExt) return std::make_pair(false, entExt); // Entity isn't even at an extremity // Okay, now, let's check if the position where the entity // will move to is valid (no obstacle) MapDataRef map; // Map the entity will move to unsigned x {}, y {}; // New position of the entity after changing map if (entExt & Dir::Left) { map = MapDataLibrary::Get(mapXYToString(mapPos.x - 1, mapPos.y)); x = Def::MapX; y = pos.xy.y; } else if (entExt & Dir::Right) { map = MapDataLibrary::Get(mapXYToString(mapPos.x + 1, mapPos.y)); x = 0u; y = pos.xy.y; } else if (entExt & Dir::Up) { map = MapDataLibrary::Get(mapXYToString(mapPos.x, mapPos.y - 1)); x = pos.xy.x; y = Def::MapY; } else if (entExt & Dir::Down) { map = MapDataLibrary::Get(mapXYToString(mapPos.x, mapPos.y + 1)); x = pos.xy.x; y = 1u; } else { NazaraError("Bad direction value"); return std::make_pair(false, entExt); } TealAssert(map, "new map null !"); if (!map->getTile(XYToIndex(x, y)).isWalkable()) return std::make_pair(false, entExt); // It's an obstacle. return std::make_pair(true, entExt); }