static void OnSelectClicked(WindowControl * Sender) { (void)Sender; if (s_selected<0 || s_selected>=MAXTHISTORY) { StartupStore(_T("... Invalid thermal selected to multitarget, out of range:%d %s"),s_selected,NEWLINE); DoStatusMessage(_T("ERR-126 invalid thermal")); return; } if (!ThermalHistory[s_selected].Valid) { DoStatusMessage(gettext(TEXT("ERR-127 invalid thermal selection"))); return; } #if TESTBENCH StartupStore(_T("... Selected thermal n.%d <%s>\n"),s_selected,ThermalHistory[s_selected].Name); #endif SetThermalMultitarget(s_selected); // update selected multitarget LockTaskData(); // now select the new one WayPointList[RESWP_LASTTHERMAL].Latitude = ThermalHistory[s_selected].Latitude; WayPointList[RESWP_LASTTHERMAL].Longitude = ThermalHistory[s_selected].Longitude; WayPointList[RESWP_LASTTHERMAL].Altitude = ThermalHistory[s_selected].HBase; wcscpy(WayPointList[RESWP_LASTTHERMAL].Name, ThermalHistory[s_selected].Name); UnlockTaskData(); // switch to L> multitarget, and force moving map mode OvertargetMode=OVT_THER; SetModeType(LKMODE_MAP,MP_MOVING); wf->SetModalResult(mrOK); }
// This function is called upon exiting a thermal, just before input event to cruise mode is issued // Functions using the ThermalHistory array should always check for Valid flag at each step, // and in any case never use the array while Circling. Because anytime we may change a value, in case // (very rare) the 100 limit is passed and we are reusing a value. // // When this function is called, the L> thermal is automatically selected as multitarget L // void InsertThermalHistory(double ThTime, double ThLat, double ThLon, double ThBase,double ThTop, double ThAvg) { int i; for (i=0; i<MAX_THERMAL_HISTORY; i++) { if (ThermalHistory[i].Valid == false) break; } if (i==MAX_THERMAL_HISTORY) { #if DEBUG_THISTORY StartupStore(_T("... no more space in thermal history\n")); #endif int oldest=0; // lets assume the 0 is the oldest, to begin for (i=1; i<MAX_THERMAL_HISTORY; i++) { if ( ThermalHistory[i].Time < ThermalHistory[oldest].Time ) { oldest=i; continue; } } #if DEBUG_THISTORY StartupStore(_T(".... oldest thermal in history is n.%d\n"),oldest); #endif i=oldest; } if (i<0 || i>=MAX_THERMAL_HISTORY) { #if DEBUG_THISTORY StartupStore(_T("..... Insert thermal history out of range: <%d>!\n"),i); #endif return; } ThermalHistory[i].Valid=false; TCHAR tstring[10]; Units::TimeToTextSimple(tstring,TimeLocal((int)ThTime)); _stprintf(ThermalHistory[i].Name,_T("th%s"),tstring); ThermalHistory[i].Time = ThTime; ThermalHistory[i].Latitude = ThLat; ThermalHistory[i].Longitude = ThLon; ThermalHistory[i].HBase = ThBase; ThermalHistory[i].HTop = ThTop; ThermalHistory[i].Lift = ThAvg; ThermalHistory[i].Valid=true; int j=FindNearestFarVisibleWayPoint(ThLon,ThLat,15000,WPT_UNKNOWN); if (j>0) { #if DEBUG_THISTORY StartupStore(_T("..... Thermal is near wp.%d <%s>\n"),j,WayPointList[j].Name); #endif TCHAR wpnear[NAME_SIZE+1]; _tcscpy(wpnear,WayPointList[j].Name); wpnear[19]='\0'; // sized 20 chars _tcscpy(ThermalHistory[i].Near,wpnear); } else { _tcscpy(ThermalHistory[i].Near,_T("")); } LockTaskData(); _tcscpy(WayPointList[RESWP_LASTTHERMAL].Name , ThermalHistory[i].Name); WayPointList[RESWP_LASTTHERMAL].Latitude = CALCULATED_INFO.ClimbStartLat; WayPointList[RESWP_LASTTHERMAL].Longitude = CALCULATED_INFO.ClimbStartLong; WayPointList[RESWP_LASTTHERMAL].Altitude = CALCULATED_INFO.ClimbStartAlt; LKASSERT(WayPointList[RESWP_LASTTHERMAL].Comment); if (j>0) _tcscpy(WayPointList[RESWP_LASTTHERMAL].Comment,ThermalHistory[i].Name); else _tcscpy(WayPointList[RESWP_LASTTHERMAL].Comment, MsgToken(1320)); // last good thermal UnlockTaskData(); // Update holder selected L> SetThermalMultitarget(i); #if DEBUG_THISTORY StartupStore(_T("... Insert new thermal in history[%d]: <%s> Base=%.0f Top=%.0f Lift=%.1f\n"), i, ThermalHistory[i].Name, ThBase, ThTop, ThAvg); #endif }