mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Fix division by zero for very close waypoints.
Fixes https://github.com/Khopa/dcs_liberation/issues/557 (cherry picked from commit 08ceb57c312467c321245b91b3a6a40c04db5096)
This commit is contained in:
parent
6455c38ff4
commit
ff0446cc12
@ -26,7 +26,7 @@ import datetime
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, List, Optional, Tuple, TYPE_CHECKING
|
from typing import Dict, List, Optional, TYPE_CHECKING, Tuple
|
||||||
|
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
from dcs.mission import Mission
|
from dcs.mission import Mission
|
||||||
@ -44,6 +44,8 @@ from .runways import RunwayData
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from game import Game
|
from game import Game
|
||||||
|
|
||||||
|
|
||||||
class KneeboardPageWriter:
|
class KneeboardPageWriter:
|
||||||
"""Creates kneeboard images."""
|
"""Creates kneeboard images."""
|
||||||
|
|
||||||
@ -191,7 +193,15 @@ class FlightPlanBuilder:
|
|||||||
waypoint.position
|
waypoint.position
|
||||||
))
|
))
|
||||||
duration = (waypoint.tot - last_time).total_seconds() / 3600
|
duration = (waypoint.tot - last_time).total_seconds() / 3600
|
||||||
return f"{int(distance / duration)} kt"
|
try:
|
||||||
|
return f"{int(distance / duration)} kt"
|
||||||
|
except ZeroDivisionError:
|
||||||
|
# TODO: Improve resolution of unit conversions.
|
||||||
|
# When waypoints are very close to each other they can end up with
|
||||||
|
# identical TOTs because our unit conversion functions truncate to
|
||||||
|
# int. When waypoints have the same TOT the duration will be zero.
|
||||||
|
# https://github.com/Khopa/dcs_liberation/issues/557
|
||||||
|
return "-"
|
||||||
|
|
||||||
def build(self) -> List[List[str]]:
|
def build(self) -> List[List[str]]:
|
||||||
return self.rows
|
return self.rows
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user