📄 waypoint.cpp
字号:
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <ddraw.h>
#include "unit.h"
#include "team.h"
#include "CmpGlobl.h"
#include "CampCell.h"
#include "CampTerr.h"
#include "Listadt.h"
#include "objectiv.h"
#include "Campaign.h"
#include "campmap.h"
#include "campwp.h"
#include "campstr.h"
#include "squadron.h"
#include "feature.h"
#include "pilot.h"
#include "team.h"
#include "find.h"
#include "division.h"
#include "misseval.h"
#include "cmpclass.h"
#include "msginc\WingmanMsg.h"
#include "ui95_dd.h"
#include "chandler.h"
#include "ui95_ext.h"
#include "AirUnit.h"
#include "uicomms.h"
#include "userids.h"
#include "textids.h"
#include "classtbl.h"
#include "ui_cmpgn.h"
#include "cmap.h"
#include "gps.h"
#include "urefresh.h"
#pragma warning(disable : 4127)
#define WPERROR_NO_TARGET 0x01
#define WPERROR_SPEED 0x02
#define WPERROR_TIME 0x04
#define WPERROR_FUEL 0x08
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
float get_ground_speed (float speed, int altitude);
float get_air_speed (float speed, int altitude);
void tactical_set_orders(Battalion bat, VU_ID obj, GridIndex tx, GridIndex ty);
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void refresh_waypoint (WayPointClass * wp);
void recalculate_waypoints (WayPointClass *wp);
void recalculate_waypoint (WayPointClass *wp, int minSpeed, int maxSpeed);
void fixup_unit (Unit unit);
int IsValidAction (int mission, int action);
int IsValidEnrouteAction (int mission, int action);
int IsValidWP (WayPointClass *wp, Flight flt);
void ValidateWayPoints (Flight flt);
int WayPointErrorCode (WayPointClass *wp, Flight flt);
void DeleteWPCB(long ID,short hittype,C_Base *control);
void ChangeTimeCB(long ID,short hittype,C_Base *control);
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
extern C_Handler *gMainHandler;
extern GlobalPositioningSystem *gGps;
extern C_Map *gMapMgr;
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
VU_ID gActiveFlightID=FalconNullId; // Currently selected waypoint flight
short gActiveWPNum=0; // Current Waypoint in this list
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
static WayPointClass *get_current_waypoint (void)
{
int
i;
FlightClass
*flt;
WayPointClass
*wp;
flt = (Flight) vuDatabase->Find(gActiveFlightID);
if (!flt)
return NULL;
wp = flt->GetFirstUnitWP ();
i = 1;
while (wp && i < gActiveWPNum)
{
wp = wp->GetNextWP ();
i ++;
}
return wp;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// KCK: This will set up the "special" data associated with certain actions/flags
static void SetSteerPointValues(C_Window *win, WayPointClass *wp, int)
{
CampEntity ent;
Flight flt = NULL;
long hr,mn,sc,action,flags,fid;
CampaignTime time;
C_Text *txt=NULL;
C_Clock *clk;
VU_ID *tmpID;
_TCHAR buffer[130];
flt=(Flight)vuDatabase->Find(gActiveFlightID);
if (!flt || !wp)
return;
// Depending on a combination of waypoint flags and action type, we may have special
// data associated with this waypoint
action = wp->GetWPAction();
flags = wp->GetWPFlags();
if ((flags & WPF_TAKEOFF) || (flags & WPF_LAND))
{
// Associate an airbase/carrier
ent = wp->GetWPTarget();
txt=(C_Text *)win->FindControl(LANDING_FIELD); // Takeoff/landing airbase name
if(txt)
{
tmpID=(VU_ID*)txt->GetUserPtr(_UI95_VU_ID_SLOT_);
if (ent)
{
tmpID=new VU_ID;
*tmpID=ent->Id();
txt->SetUserCleanupPtr(_UI95_VU_ID_SLOT_,tmpID);
tmpID=NULL;
if (ent->IsObjective())
ent->GetName(buffer,30,TRUE);
else
ent->GetName(buffer,30,FALSE);
txt->SetText(buffer);
}
else
{
if (tmpID)
txt->SetUserPtr(_UI95_VU_ID_SLOT_,NULL);
_tcscpy(buffer,gStringMgr->GetString(TXT_NO_AIRBASE));
txt->SetText(buffer);
}
txt->Refresh();
}
}
if (((flags & WPF_TARGET) && (action == WP_INTERCEPT || action == WP_NAVSTRIKE || action == WP_GNDSTRIKE)) || action == WP_PICKUP || action == WP_AIRDROP)
{
// Associate a UNIT target
ent = wp->GetWPTarget();
if (ent)
{
if (ent->IsFlight())
GetCallsign (((Flight)ent)->callsign_id, ((Flight)ent)->callsign_num, buffer);
else if (ent->IsObjective())
ent->GetName(buffer,30,TRUE);
else
ent->GetName(buffer,30,FALSE);
}
else
_tcscpy(buffer,gStringMgr->GetString(TXT_NO_TARGET));
txt=(C_Text *)win->FindControl(UNIT_FIELD); // Target Name
if(txt)
{
tmpID=(VU_ID*)txt->GetUserPtr(_UI95_VU_ID_SLOT_);
if(ent)
{
tmpID=new VU_ID;
*tmpID=ent->Id();
txt->SetUserCleanupPtr(_UI95_VU_ID_SLOT_,tmpID);
tmpID=NULL;
}
else if(tmpID)
txt->SetUserPtr(_UI95_VU_ID_SLOT_,NULL);
txt->SetText(buffer);
txt->Refresh();
}
}
if ((flags & WPF_TARGET) && (action == WP_STRIKE || action == WP_BOMB || action == WP_RECON))
{
// Associate an OBJECTIVE target
ent = wp->GetWPTarget();
if (ent)
{
if (ent->IsObjective())
ent->GetName(buffer,30,TRUE);
else
ent->GetName(buffer,30,FALSE);
}
else
_tcscpy(buffer,gStringMgr->GetString(TXT_NO_TARGET));
txt=(C_Text *)win->FindControl(OBJECTIVE_FIELD); // Target Name
if(txt)
{
tmpID=(VU_ID*)txt->GetUserPtr(_UI95_VU_ID_SLOT_);
if(ent)
{
tmpID=new VU_ID;
*tmpID=ent->Id();
txt->SetUserCleanupPtr(_UI95_VU_ID_SLOT_,tmpID);
tmpID=NULL;
}
else if(tmpID)
txt->SetUserPtr(_UI95_VU_ID_SLOT_,NULL);
txt->SetText(buffer);
txt->Refresh();
}
txt=(C_Text *)win->FindControl(FEATURE_FIELD); // Target building
if(txt && ent && ent->IsObjective())
{
FeatureClassDataType *fc;
fid = wp->GetWPTargetBuilding();
if (fid < 255)
fc = GetFeatureClassData(((Objective)ent)->GetFeatureID(fid));
else
fc = NULL;
txt->SetUserNumber(C_STATE_0,wp->GetWPTargetBuilding());
if (fc)
txt->SetText(fc->Name);
else
{
_tcscpy(buffer,gStringMgr->GetString(TXT_NOT_ASSIGNED));
txt->SetText(buffer);
}
txt->Refresh();
}
}
if ((flags & WPF_REPEAT) || (wp->GetNextWP() && (wp->GetNextWP()->GetWPFlags() & WPF_REPEAT)))
{
// Associate a patrol/station time
if (flags & WPF_REPEAT)
time = wp->GetWPStationTime();
else
time = wp->GetNextWP()->GetWPStationTime();
hr = time / CampaignHours;
mn = (time / CampaignMinutes) % 60;
sc = (time / CampaignSeconds) % 60;
clk=(C_Clock *)win->FindControl(PATROL_FIELD);
if(clk)
{
clk->SetHour(hr);
clk->SetMinute(mn);
clk->SetSecond(sc);
clk->Refresh();
}
}
if (action == WP_PICKUP || action == WP_AIRDROP)
{
// Associate a patrol/station time
time = wp->GetWPStationTime();
hr = time / CampaignHours;
mn = (time / CampaignMinutes) % 60;
sc = (time / CampaignSeconds) % 60;
clk=(C_Clock *)win->FindControl(LOITER_FIELD);
if(clk)
{
clk->SetHour(hr);
clk->SetMinute(mn);
clk->SetSecond(sc);
clk->Refresh();
}
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void RefreshActionClusters (int action, C_Window *win)
{
win->HideCluster(13063);
win->HideCluster(13065);
win->HideCluster(13068);
win->HideCluster(13070);
win->HideCluster(13074);
win->HideCluster(13075);
win->HideCluster(13079);
switch (action)
{
case WP_TAKEOFF:
case WP_LAND:
win->UnHideCluster(13068);
break;
case WP_TANKER:
case WP_REARM:
case WP_ELINT:
case WP_JAM:
case WP_CAP:
case WP_CASCP:
win->UnHideCluster(13070);
break;
case WP_INTERCEPT:
win->UnHideCluster(13074);
break;
case WP_PICKUP:
case WP_AIRDROP:
win->UnHideCluster(13074);
win->UnHideCluster(13075);
break;
case WP_STRIKE:
case WP_BOMB:
win->UnHideCluster(13079);
break;
default:
win->UnHideCluster(13063);
break;
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void UpdateWaypointWindowInfo(C_Window *win,WayPointClass *wp,int wpnum, int callsign_update = TRUE)
{
long ispeed,errors;
long alt_delta;
CampaignTime tm;
C_Text *txt;
C_EditBox *ebox;
C_ListBox *lbox;
C_Button *btn;
C_Clock *clk;
Package Pkg;
Flight flt,curflt;
WayPointClass *prev_wp;
_TCHAR buffer[90];
flt=(Flight)vuDatabase->Find(gActiveFlightID);
if(!win || !wp || !flt)
return;
SetSteerPointValues(win, wp, wpnum);
RefreshActionClusters(wp->GetWPAction(),win);
prev_wp = wp->GetPrevWP ();
btn = (C_Button *) win->FindControl (PREV_STPT);
if (prev_wp)
btn->SetFlagBitOff (C_BIT_INVISIBLE);
else
btn->SetFlagBitOn (C_BIT_INVISIBLE);
btn = (C_Button *) win->FindControl (NEXT_STPT);
if (wp->GetNextWP ())
btn->SetFlagBitOff (C_BIT_INVISIBLE);
else
btn->SetFlagBitOn (C_BIT_INVISIBLE);
gActiveWPNum=static_cast<short>(wpnum);
txt=(C_Text *)win->FindControl(FLIGHT_TITLE);
if(txt && flt->GetUnitParent())
{
_stprintf(buffer,"%s %1d",gStringMgr->GetString(TXT_PKG),((Package)flt->GetUnitParent())->GetCampID());
txt->SetText(buffer);
}
btn = (C_Button *) win->FindControl (DELETE_WAYPOINT);
if (btn)
btn->SetCallback(DeleteWPCB);
if (callsign_update)
{
lbox=(C_ListBox*)win->FindControl(LID_FLIGHT_CALLSIGN);
if(lbox)
{
lbox->RemoveAllItems();
Pkg=(Package)flt->GetUnitParent();
if(Pkg)
{
curflt=(Flight)Pkg->GetFirstUnitElement();
while(curflt)
{
GetCallsign(curflt,buffer);
lbox->AddItem(curflt->GetCampID(),C_TYPE_ITEM,buffer);
curflt=(Flight)Pkg->GetNextUnitElement();
}
lbox->SetFlagBitOn(C_BIT_ENABLED);
}
else
{
GetCallsign(flt,buffer);
lbox->AddItem(flt->GetCampID(),C_TYPE_ITEM,buffer);
lbox->SetFlagBitOff(C_BIT_ENABLED);
}
lbox->SetValue(flt->GetCampID());
}
}
lbox=(C_ListBox *)win->FindControl(STPT_LABEL);
if(lbox)
{
if(wp->GetWPFlags() & WPF_TARGET)
lbox->SetValue(TGT_WP);
else if(wp->GetWPFlags() & WPF_IP)
lbox->SetValue(IP_WP);
else if(wp->GetWPFlags() & WPF_CP)
lbox->SetValue(CP_WP);
else
lbox->SetValue(STPT_WP);
}
ebox=(C_EditBox *)win->FindControl(STPT_FIELD);
if(ebox)
{
ebox->SetInteger(wpnum);
ebox->Refresh();
}
btn = (C_Button *) win->FindControl (TOS_LOCK);
if (btn)
{
if (wp->GetWPFlags () & WPF_TIME_LOCKED)
btn->SetState (1);
else
btn->SetState (0);
}
clk=(C_Clock *)win->FindControl(TOS_FIELD);
if(clk)
{
tm = wp->GetWPArrivalTime() / VU_TICS_PER_SECOND;
// tm += 30*CampaignMinutes; // What the hell is this about? - RH
clk->SetTime(tm);
clk->Refresh();
}
btn = (C_Button *) win->FindControl (AIRSPEED_LOCK);
if (btn)
{
if (wp->GetWPFlags () & WPF_SPEED_LOCKED)
btn->SetState (1);
else
btn->SetState (0);
}
txt=(C_Text *)win->FindControl(AIRSPEED_FIELD);
if(txt)
{
if (prev_wp)
{
float speed;
// Air Speed in nm/hr
if (wp->GetWPFlags() & WPF_HOLDCURRENT)
speed = static_cast<float>(FloatToInt32(get_air_speed (wp->GetWPSpeed()*KM_TO_NM, prev_wp->GetWPAltitude())));
else
speed = static_cast<float>(FloatToInt32(get_air_speed (wp->GetWPSpeed()*KM_TO_NM, wp->GetWPAltitude())));
ispeed=FloatToInt32(speed+2.5F)/5;
ispeed*=5;
if (speed > 999) ispeed = 999;
}
else
{
ispeed=0;
}
_stprintf(buffer,"%1ld %s",ispeed,gStringMgr->GetString(TXT_KTS));
txt->SetText(buffer);
}
txt = (C_Text *) win->FindControl (ALT_FIELD);
if (txt)
{
_stprintf (buffer, "%1ld", wp->GetWPAltitude ());
txt->SetText (buffer);
}
// Figure out wether we have an altitude change and show the appropriate choices
if (prev_wp)
alt_delta = wp->GetWPAltitude() - prev_wp->GetWPAltitude();
else
alt_delta = 0;
if (alt_delta < 0)
{
win->HideCluster(200);
win->UnHideCluster(300);
win->UnHideCluster(100);
}
else if (alt_delta > 0)
{
win->HideCluster(300);
win->UnHideCluster(200);
win->UnHideCluster(100);
}
else
{
win->HideCluster(200);
win->HideCluster(300);
win->HideCluster(100);
}
lbox=(C_ListBox *)win->FindControl(CLIMB_LISTBOX);
if(lbox)
{
if(wp->GetWPFlags() & WPF_HOLDCURRENT)
lbox->SetValue(CLIMB_DELAY);
else
lbox->SetValue(CLIMB_IMMEDIATE);
}
lbox=(C_ListBox *)win->FindControl(FORM_LISTBOX);
if(lbox)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -