📄 dogfight.cpp
字号:
if(!flt)
return(NULL);
if (flight->player_slots[ac] != 255)
{
if (FalconLocalGame)
{
// Add a player pilot
FalconSessionEntity *session;
VuSessionsIterator sit(FalconLocalGame);
// Find this player's session
session = (FalconSessionEntity*) sit.GetFirst();
while (session && !found)
{
if (session->GetAircraftNum() == ac && session->GetPlayerFlight() == flight && session->GetPilotSlot() == flight->player_slots[ac])
found = 1;
else
session = (FalconSessionEntity*) sit.GetNext();
}
if (!found)
return(NULL);
pilot=MakePilot(list,flight,session,ac,-1);
pilot->SetPlayer(1);
}
else
{
return NULL;
}
}
else
{
// Add an AI pilot
pilot=MakePilot(list,flight,NULL,ac,flight->pilots[ac]);
pilot->SetPlayer(0);
}
if(!pilot)
return(NULL);
item=list->CreateItem(ID,C_TYPE_ITEM,pilot);
list->AddChildItem(flt,item);
// Kludge to update the # planes in dogfight
fltctrl=(C_Dog_Flight*)flt->Item_;
if(fltctrl)
{
count=0;
cur=flt->Child;
while(cur)
{
count++;
cur=cur->Next;
};
if(fltctrl->GetAircraft())
{
str=fltctrl->GetAircraft()->GetText();
if(str)
str[0]=static_cast<char>(count + '0');
}
}
list->RecalcSize();
if(list->GetParent())
list->GetParent()->RefreshClient(list->GetClient());
return(pilot);
}
C_Dog_Flight *AddDogfightFlight(C_TreeList *list, Flight flight)
{
C_Dog_Flight *dfflight;
TREELIST *item;
long ID;
// Create a unique ID
ID = flight->GetTeam() << 24;
ID |= flight->callsign_id << 16;
ID |= flight->callsign_num << 8;
if (!list)
return(NULL);
item=list->Find(ID);
if(item)
{
UpdateFlight((C_Dog_Flight*)item->Item_,flight);
return((C_Dog_Flight*)item->Item_);
}
dfflight=MakeFlight(list,flight);
if(!dfflight)
return(NULL);
item=list->CreateItem(ID,C_TYPE_MENU,dfflight);
list->AddItem(list->GetRoot(),item);
list->RecalcSize();
if(list->GetParent())
list->GetParent()->RefreshClient(list->GetClient());
return(dfflight);
}
void EraseOldLimbs(C_TreeList *tree,TREELIST *first,long timestamp)
{
TREELIST *item,*cur;
cur=first;
while(cur)
{
item=cur;
cur=cur->Next;
if(item->Item_ && item->Item_->GetUserNumber(0) != timestamp)
{
if(item->Child)
tree->DeleteBranch(item->Child);
tree->DeleteItem(item);
}
else if(item->Child)
EraseOldLimbs(tree,item->Child,timestamp);
}
}
void ClearOldDFInfo(long timestamp)
{
C_Window *win;
C_TreeList *tree;
win=gMainHandler->FindWindow(DF_TEAM_WIN);
if(win)
{
tree=(C_TreeList *)win->FindControl(FURBALL_TREE);
if(tree)
{
EraseOldLimbs(tree,tree->GetRoot(),timestamp);
tree->RecalcSize();
if(tree->Parent_)
tree->Parent_->RefreshClient(tree->GetClient());
}
tree=(C_TreeList *)win->FindControl(CRIMSON_TREE);
if(tree)
{
EraseOldLimbs(tree,tree->GetRoot(),timestamp);
tree->RecalcSize();
if(tree->Parent_)
tree->Parent_->RefreshClient(tree->GetClient());
}
tree=(C_TreeList *)win->FindControl(SHARK_TREE);
if(tree)
{
EraseOldLimbs(tree,tree->GetRoot(),timestamp);
tree->RecalcSize();
if(tree->Parent_)
tree->Parent_->RefreshClient(tree->GetClient());
}
tree=(C_TreeList *)win->FindControl(TIGER_TREE);
if(tree)
{
EraseOldLimbs(tree,tree->GetRoot(),timestamp);
tree->RecalcSize();
if(tree->Parent_)
tree->Parent_->RefreshClient(tree->GetClient());
}
tree=(C_TreeList *)win->FindControl(VIPER_TREE);
if(tree)
{
EraseOldLimbs(tree,tree->GetRoot(),timestamp);
tree->RecalcSize();
if(tree->Parent_)
tree->Parent_->RefreshClient(tree->GetClient());
}
}
}
void BuildDFPlayerList()
{
VuListIterator listit(AllRealList);
Unit unit;
Flight flight;
int ac,team;
C_Window *win;
C_TreeList *flist,*tlist;
C_Pilot *furplt,*teamplt;
C_Dog_Flight *furflt,*teamflt;
long timestamp;
if(!gMainHandler)
return;
win=gMainHandler->FindWindow(DF_TEAM_WIN);
if(!win)
return;
ClearAllTreeStates();
timestamp=GetCurrentTime();
unit = (Unit)listit.GetFirst();
while (unit)
{
if (unit->IsFlight() && !unit->Dead())
{
// Add this flight and all aircraft to our trees
flight = (Flight)unit;
// Add FLIGHT to Furball Tree
flist=(C_TreeList *)win->FindControl(FURBALL_TREE);
furflt=AddDogfightFlight(flist, flight);
if(furflt)
furflt->SetUserNumber(0,timestamp);
// Add FLIGHT to Team Tree
team=flight->GetTeam();
switch(team)
{
case 1:
tlist=(C_TreeList *)win->FindControl(CRIMSON_TREE);
break;
case 2:
tlist=(C_TreeList *)win->FindControl(SHARK_TREE);
break;
case 3:
tlist=(C_TreeList *)win->FindControl(VIPER_TREE);
break;
case 4:
default:
tlist=(C_TreeList *)win->FindControl(TIGER_TREE);
break;
}
teamflt=AddDogfightFlight(tlist, flight);
if(teamflt)
teamflt->SetUserNumber(0,timestamp);
if(gCurrentFlightID == flight->Id())
{
switch (SimDogfight.GetGameType())
{
case dog_TeamFurball:
case dog_TeamMatchplay:
if(teamflt)
teamflt->SetState(1);
break;
default:
if(furflt)
furflt->SetState(1);
break;
}
}
for (ac=0; ac<PILOTS_PER_FLIGHT; ac++)
{
if (flight->pilots[ac] != NO_PILOT || flight->player_slots[ac] != NO_PILOT)
{
// Add PLAYER to Furball Tree
furplt=AddDogfightPilot(flist, flight, ac);
if(furplt)
furplt->SetUserNumber(0,timestamp);
// Add PLAYER to Team Tree
teamplt=AddDogfightPilot(tlist, flight, ac);
if(teamplt)
teamplt->SetUserNumber(0,timestamp);
if(gCurrentFlightID == flight->Id() && gCurrentAircraftNum == ac)
{
switch (SimDogfight.GetGameType())
{
case dog_TeamFurball:
case dog_TeamMatchplay:
if(teamplt)
teamplt->SetState(1);
break;
default:
if(furplt)
furplt->SetState(1);
break;
}
}
}
}
}
unit = (Unit)listit.GetNext();
}
// Erase everything with UserNumber(0) != timestamp
ClearOldDFInfo(timestamp);
CheckDelButtons();
CheckFlyButton();
}
// ==============================================
//
// KCK: Group related peter stuff
// Seems like this belongs somewhere else...
//
// ==============================================
void DeleteGroupList(long ID)
{
C_Window *win;
CONTROLLIST *winctrls;
F4CSECTIONHANDLE* Leave;
// Clear controls from window with the userdata[_UI95_DELGROUP_SLOT_] == _UI95_DELGROUP_ID_
win=gMainHandler->FindWindow(ID);
if(win)
{
Leave=UI_Enter(win);
winctrls=win->GetControlList();
while(winctrls)
{
if(winctrls->Control_->GetUserNumber(_UI95_DELGROUP_SLOT_) == _UI95_DELGROUP_ID_)
{
winctrls=win->RemoveControl(winctrls);
}
else
winctrls=winctrls->Next;
}
UI_Leave(Leave);
}
}
// ==============================================
//
// KCK: Plane related peter stuff
//
// ==============================================
uchar GetPlaneListID(long ID)
{
uchar i;
i=0;
while(DFAIPlanes[i].ID && i < 255)
{
if(DFAIPlanes[i].ID == ID)
return(i);
i++;
}
return(0);
}
long GetACIDFromFlight(Flight flight)
{
uchar i,stype = flight->GetSType(),sptype = flight->GetSPType();
i=0;
while(DFAIPlanes[i].ID && i < 255)
{
if(DFAIPlanes[i].UnitSType && DFAIPlanes[i].SPType && DFAIPlanes[i].UnitSType == stype && DFAIPlanes[i].SPType == sptype)
return(DFAIPlanes[i].ID);
i++;
}
return(0);
}
// Use ONLY as a TreeList callback!!!!!!!
static void SelectDogfightGameCB(long,short hittype,C_Base *control)
{
VU_ID *tmpID;
FalconGameEntity *game;
TREELIST *item;
if(hittype != C_TYPE_LMOUSEUP)
return;
item=((C_TreeList *)control)->GetLastItem();
if(item == NULL) return;
if(item->Item_ == NULL) return;
if(gCommsMgr->GetGame() != vuPlayerPoolGroup)
return;
if(item->Type_ == C_TYPE_MENU)
{
if(!item->Item_->GetState())
{
((C_TreeList *)control)->SetAllControlStates(0,((C_TreeList *)control)->GetRoot());
item->Item_->SetState(1);
item->Item_->Refresh();
tmpID=(VU_ID *)item->Item_->GetUserPtr(_UI95_VU_ID_SLOT_);
if(tmpID)
{
game=(FalconGameEntity*)vuDatabase->Find(*tmpID);
gCommsMgr->LookAtGame(game);
if(game)
{
// if(game->GetGameType() == game_Dogfight)
// gCommsMgr->RequestSettings(game->Id());
}
}
}
else
{
item->Item_->SetState(0);
item->Item_->Refresh();
gCommsMgr->LookAtGame(NULL);
ClearDFTeamLists();
}
}
}
short ConvertDFIDtoTeam(long ID)
{
switch(ID)
{
case DF_CRIMSON:
case ADD_CRIMSON_PLANE:
case DF_MARK_CRIMSON:
return(1);
break;
case DF_SHARK:
case ADD_SHARK_PLANE:
case DF_MARK_SHARK:
return(2);
break;
case DF_VIPER:
case ADD_USA_PLANE:
case DF_MARK_VIPER:
return(3);
break;
case DF_TIGER:
case ADD_TIGER_PLANE:
case DF_MARK_TIGER:
return(4);
break;
}
return(0);
}
void AddDogfightFlightCB(long,short hittype,C_Base *control)
{
Flight flight=NULL;
long teamid=0,skill=0,acid=0,idx=0,type=0,callgroup=0;
C_ListBox *lbox=NULL;
long value=0;
if(hittype != C_TYPE_LMOUSEUP)
return;
if (!FalconLocalGame || FalconLocalSession->Game() == vuPlayerPoolGroup)
return;
switch(AddToTeam)
{
case DF_CRIMSON_CALLS:
teamid=1;
break;
case DF_SHARK_CALLS:
teamid=2;
break;
case DF_TBIRD_CALLS:
teamid=3;
break;
case DF_TIGER_CALLS:
teamid=4;
break;
case DF_FURBALL_CALLS:
teamid=0;
break;
}
lbox=(C_ListBox*)control->Parent_->FindControl(AddToTeam);
if(lbox)
value=lbox->GetTextID();
if(teamid)
callgroup=value-1;
else
{
callgroup=0;
teamid=value;
}
lbox=(C_ListBox*)control->Parent_->FindControl(DF_AIRCRAFT_TYPE);
if(lbox)
acid=lbox->GetTextID();
else
acid=DF_AC_F16C;
lbox=(C_ListBox*)control->Parent_->FindControl(DF_SKILL);
if(lbox)
skill=lbox->GetTextID()-1;
else
skill=0;
switch (SimDogfight.GetGameType())
{
case dog_TeamMatchplay:
case dog_TeamFurball:
flight=(Flight)vuDatabase->Find(gCurrentFlightID);
if(flight && flight->GetTeam() != teamid)
flight=NULL;
break;
default:
flight=NULL;
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -