📄 te_units.cpp
字号:
while (element)
{
element->DoFullUpdate();
element->FalconEntity::SetOwner(host);
element = (FalconEntity*) new_package->GetNextUnitElement();
}
}
new_package=NULL;
}
EdittingPackage=0;
new_package=NULL;
WeAreAddingPackage=0;
gMainHandler->DisableWindowGroup(control->Parent_->GetGroup());
}
// KCK: This is called when we've decided to create a package -
// which just before we're planning on creating a flight with no current parent package
void tactical_make_package (long,short hittype,C_Base *)
{
C_Window *win;
C_ListBox *lbox;
C_TreeList *tree;
long type=0;//start_day=0,;
if(hittype != C_TYPE_LMOUSEUP)
return;
win=gMainHandler->FindWindow(PACKAGE_WIN);
if(win)
{
// Clear any previous lists
gNewSelectFlight=FalconNullId;
tree=(C_TreeList *)win->FindControl(ATO_PACKAGE_TREE);
if(tree)
{
tree->DeleteBranch(tree->GetRoot());
tree->RecalcSize();
tree->Parent_->RefreshClient(tree->GetClient());
}
// Find type
lbox=(C_ListBox *)win->FindControl(TAC_PACKAGE_TYPE);
if(lbox)
type = lbox->GetTextID();
new_package = (Package) NewUnit (DOMAIN_AIR,TYPE_PACKAGE,0,0,NULL);
if (new_package)
{
MissionRequestClass mis;
// Set up our mission request
mis.who = gSelectedTeam;
if (new_package_target)
{
mis.targetID = mis.requesterID = new_package_target->Id();
if (new_package_target->IsObjective())
mis.target_num = ((Objective)new_package_target)->GetBestTarget();
mis.vs = new_package_target->GetTeam();
}
mis.tot = gPackageTOT;
if (gPackageTOT)
mis.tot_type = TYPE_EQ;
else
mis.tot_type = TYPE_NE;
mis.tx = MapX;
mis.ty = MapY;
mis.mission = static_cast<uchar>(type);
mis.priority = static_cast<short>(gPackagePriority);
mis.aircraft = 2;
mis.flags |= REQF_ALLOW_ERRORS;
new_package->SetUnitDestination(MapX,MapY);
new_package->SetLocation(MapX,MapY);
*(new_package->GetMissionRequest()) = mis;
new_package->SetPackageFlags(MissionData[mis.mission].flags);
new_package->SetFinal(0);
new_package->SetOwner (gSelectedTeam);
}
}
}
void SetPackageTimes(Package new_package, CampaignTime takeoffTime, CampaignTime targetTime)
{
Flight flight;
WayPoint w;
int delta = 0, count = 0;
if (!new_package)
return;
flight = (Flight) new_package->GetFirstUnitElement();
while (flight)
{
w = flight->GetFirstUnitWP();
if (w && !flight->Moving())
{
if (takeoffTime)
delta = takeoffTime - w->GetWPDepartureTime();
if (count)
delta += MissionData[flight->GetUnitMission()].separation * CampaignSeconds;
else if (targetTime)
{
while (w && !(w->GetWPFlags() & WPF_TARGET))
w = w->GetNextWP();
if (w)
delta = (targetTime + MissionData[flight->GetUnitMission()].separation*CampaignSeconds) - w->GetWPArrivalTime();
}
if (delta)
SetWPTimes (flight->GetFirstUnitWP(), delta, 0);
}
count++;
flight = (Flight) new_package->GetNextUnitElement();
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//Flight Stuff
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void tac_select_aircraft(long,short hittype,C_Base *control)
{
C_ListBox *lbox;
int i,ac_type,mission = -1;
C_Window *win;
if(hittype != C_TYPE_SELECT)
return;
win=gMainHandler->FindWindow(TAC_FLIGHT_WIN);
if (!win)
return;
gLastAircraftType = ((C_ListBox*)control)->GetTextID();
ac_type = gLastAircraftType-VU_LAST_ENTITY_TYPE;
// Everything else is based off of aircraft type
// Setup role listbox
lbox=(C_ListBox *)win->FindControl(TAC_ROLE);
if(lbox)
{
// Clear old roles
lbox->RemoveAllItems();
for (i=1;i<AMIS_OTHER;i++)
{
if (IsValidMission(ac_type,i))
{
lbox->AddItem(i,C_TYPE_ITEM,MissStr[i]);
if (mission < 0)
mission = i;
if (i == gLastRole)
lbox->SetValue(i);
}
}
lbox->SetCallback(tac_select_role);
tac_select_role(mission,C_TYPE_SELECT,lbox);
}
// Setup Squadron listbox - list all squadrons of aircraft type above, plus "new"
lbox=(C_ListBox*)win->FindControl(TAC_SQUADRON_LIST);
if(lbox)
{
lbox->RemoveAllItems();
FillListBoxWithSquadrons(lbox,gSelectedTeam,ac_type);
lbox->SetCallback(tac_select_squadron);
// Now setup the airbase list (result of squadron selection)
tac_select_squadron(lbox->GetTextID(),C_TYPE_SELECT,lbox);
}
}
void tac_select_role(long,short hittype,C_Base *control)
{
C_ListBox *lbox;
C_Window *win;
int mission;
if(hittype != C_TYPE_SELECT)
return;
win=gMainHandler->FindWindow(TAC_FLIGHT_WIN);
if (!win)
return;
gLastRole = mission = ((C_ListBox*)control)->GetTextID();
// Setup target listbox (based off of role)
lbox=(C_ListBox *)win->FindControl(TARGET_LIST);
if(lbox)
{
VuListIterator cit(AllCampList);
CampEntity ent;
_TCHAR buffer[80] = {0};
int gott=0;
// Clear old targets
lbox->RemoveAllItems();
// Check for location target
if (IsValidTarget(gSelectedTeam, mission, NULL))
{
AddLocationToBuffer ('n', MapX, MapY, buffer);
lbox->AddItem(TAC_LOCATION,C_TYPE_ITEM,buffer);
if (!gLastTarget)
lbox->SetValue(TAC_LOCATION);
gott++;
}
// Check all entities
ent = (CampEntity) cit.GetFirst();
while (ent)
{
if (IsValidTarget(gSelectedTeam,mission,ent))
{
if (ent->IsFlight())
GetCallsign (((Flight)ent)->callsign_id, ((Flight)ent)->callsign_num, buffer);
else if (ent->IsObjective())
ent->GetName(buffer,79,TRUE);
else
ent->GetName(buffer,79,FALSE);
lbox->AddItem(ent->GetCampID(),C_TYPE_ITEM,buffer);
if (ent == gLastTarget)
lbox->SetValue(ent->GetCampID());
gott++;
}
ent = (CampEntity) cit.GetNext();
}
if (!gott)
{
_TCHAR tmp[40];
ReadIndexedString(257,tmp,39);
lbox->AddItem(TAC_NOTARGET,C_TYPE_ITEM,tmp);
lbox->SetValue(TAC_NOTARGET);
}
lbox->SetCallback(tac_select_target);
}
}
void tac_select_squadron(long ID,short hittype,C_Base *control)
{
C_ListBox *lbox;
UI_Refresher *urec;
Squadron sqd;
C_Window *win;
_TCHAR buffer[50];
if(hittype != C_TYPE_SELECT)
return;
win=gMainHandler->FindWindow(TAC_FLIGHT_WIN);
if (!win)
return;
ID=((C_ListBox*)control)->GetTextID();
// Now setup the airbase list
lbox=(C_ListBox*)win->FindControl(TAC_AIRBASE_LIST);
if(lbox)
{
lbox->RemoveAllItems();
// If we have a specific squadron selected, just show this airbase)
if (ID > 1)
{
CampEntity airbase;
urec=(UI_Refresher*)gGps->Find(ID);
if(urec)
sqd=(Squadron)vuDatabase->Find(urec->GetID());
else
sqd=NULL;
if(sqd) // Don't use sqd if NULL
{
airbase = sqd->GetUnitAirbase();
if(airbase)
{
airbase->GetName(buffer,40,TRUE);
lbox->AddItem(airbase->GetCampID(),C_TYPE_ITEM,buffer);
lbox->SetValue(airbase->GetCampID());
}
}
}
// Otherwise, show all airbases owned by our team
else
{
VuListIterator ait(AllObjList);
Objective o;
_TCHAR name[80];
GridIndex x,y;
float dsq,bdsq=FLT_MAX;
o = (Objective) ait.GetFirst();
while (o)
{
if (o->GetType() == TYPE_AIRBASE && GetRoE(gSelectedTeam,o->GetTeam(),ROE_AIR_USE_BASES) == ROE_ALLOWED)
{
// Add airbase name to listbox
o->GetName(name,79,TRUE);
lbox->AddItem(o->GetCampID(),C_TYPE_ITEM,name);
o->GetLocation(&x,&y);
dsq = static_cast<float>(DistSqu(MapX,MapY,x,y));
if (dsq < bdsq)
{
gLastAirbase = o->GetCampID();
bdsq = dsq;
}
if (o->GetCampID() == gLastAirbase)
lbox->SetValue(gLastAirbase);
}
o = (Objective) ait.GetNext();
}
}
gLastAirbase = lbox->GetTextID();
lbox->Refresh();
}
}
void tac_select_airbase(long,short hittype,C_Base *control)
{
C_ListBox *lbox;
if(hittype != C_TYPE_SELECT)
return;
lbox=(C_ListBox*)control->Parent_->FindControl(TAC_AIRBASE_LIST);
if(lbox)
gLastAirbase = lbox->GetTextID();
}
void tac_select_target(long,short hittype,C_Base *control)
{
C_ListBox *lbox;
int cid;
if(hittype != C_TYPE_SELECT)
return;
lbox=(C_ListBox*)control->Parent_->FindControl(TARGET_LIST);
if(lbox)
{
cid = lbox->GetTextID();
if (cid < TAC_LOCATION)
gLastTarget = GetEntityByCampID(cid);
}
}
// This is called as a result of choosing to create a flight -
// either after a map click in flight add mode, or from within the tactical_add_package() function
void tactical_add_flight (VU_ID id, C_Base *caller)
{
C_Window *win=NULL;
C_ListBox *lbox=NULL;
C_Button *btn=NULL;
CampEntity ent=NULL;
short x=0,y=0;
float mx,my,maxy,scale;
win=gMainHandler->FindWindow(TAC_FLIGHT_WIN);
if(caller->_GetCType_() == _CNTL_BUTTON_)
{
mx = GridToSim(MapX);
my = GridToSim(MapY);
if (win)
{
lbox = (C_ListBox *) win->FindControl (START_AT_LIST);
if (lbox)
lbox->SetValue(1); // Default to "start at takeoff" for package add mode
}
}
else
{
if(caller->_GetCType_() == _CNTL_POPUPLIST_)
{
gPopupMgr->GetCurrentXY (&x, &y);
gMapMgr->GetMapRelativeXY (&x, &y);
}
else if(caller->_GetCType_() == _CNTL_MAP_MOVER_)
{
x=static_cast<short>(((C_MapMover*)caller)->GetRelX() + caller->GetX() + caller->Parent_->GetX());
y=static_cast<short>(((C_MapMover*)caller)->GetRelY() + caller->GetY() + caller->Parent_->GetY());
gMapMgr->GetMapRelativeXY (&x, &y);
}
gTakeoffTime = 0;
gPackageTOT = TheCampaign.CurrentTime + CampaignMinutes;
scale = gMapMgr->GetMapScale ();
maxy = gMapMgr->GetMaxY ();
mx = x / scale;
my = maxy - y / scale;
new_package = NULL;
if (win)
{
lbox = (C_ListBox *) win->FindControl (START_AT_LIST);
if (lbox)
lbox->SetValue(4); // Default to "start at target" for direct add mode
}
}
// Determine target (or target location)
ent=(CampEntity) vuDatabase->Find(id);
if (ent)
{
gLastTarget = new_package_target = ent;
new_package_target->GetLocation(&MapX,&MapY);
}
else
{
MapX = SimToGrid (mx);
MapY = SimToGrid (my);
new_package_target = NULL;
}
// Determine default mission type
if (!gLastAircraftType)
gLastAircraftType = GetClassID(DOMAIN_AIR,CLASS_UNIT,TYPE_SQUADRON,STYPE_UNIT_FIGHTER_BOMBER,SPTYPE_F16C,VU_ANY,VU_ANY,VU_ANY) + VU_LAST_ENTITY_TYPE;
gLastRole = GetMissionFromTarget (gSelectedTeam, gLastAircraftType-VU_LAST_ENTITY_TYPE, ent);
if(win)
{
// Setup aircraft type listbox
lbox=(C_ListBox*)win->FindControl(TAC_AIRCRAFT_TYPE);
if(lbox)
{
lbox->RemoveAllItems();
FillListBoxWithACTypes(lbox);
if(!lbox->GetRoot())
{
AreYouSure(TXT_ERROR,TXT_NO_SQUADRONS_AVAIL,NULL,CloseWindowCB);
return;
}
// Select last type selected
lbox->SetValue(gLastAircraftType);
lbox->SetCallback(tac_select_aircraft);
// Everything else is based off of aircraft type
tac_select_aircraft(0,C_TYPE_SELECT,lbox);
}
// Setup cancel and ok
btn=(C_Button*)win->FindControl(CANCEL_FLIGHT);
if(btn)
btn->SetCallback(CloseWindowCB);
btn=(C_Button*)win->FindControl(OK_FLIGHT);
if(btn)
btn->SetCallback(tactical_make_flight);
gMainHandler->EnableWindowGroup(win->GetGroup());
}
}
// This is called when we've decided to actually create a requested flight
void tactical_make_flight (long ID,short hittype,C_Base *control)
{
C_Window *win;
UI_Refresher *urec=NULL;
Flight new_flight=NULL;
Squadron squadron=NULL;
WayPoint w;
C_ListBox *lbox;
int tid;
GridIndex x,y;
int num_vehicles=0,start_at=1,done=0,flights=0,error;
VU_ID pid,sid;
long scampid,acampid,ac_type=0;
// VehicleClassDataType *vc=NULL;
CampEntity target=NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -