📄 units.cpp
字号:
Squadron sqd;
if(hittype != C_TYPE_LMOUSEUP)
return;
sqd=(Squadron)vuDatabase->Find(gLastSquadron);
if(sqd && sqd->IsSquadron())
{
FindMapIcon(sqd->GetCampID());
}
}
BOOL SortPilotByNameCB(TREELIST *list,TREELIST *newitem)
{
C_Button *btn1,*btn2;
if(!list || !newitem)
return(FALSE);
if(!list->Item_ || !newitem->Item_)
return(FALSE);
btn1=(C_Button *)list->Item_;
btn2=(C_Button *)newitem->Item_;
if(btn2->GetUserNumber(20) > btn1->GetUserNumber(20))
return(TRUE);
else if(btn2->GetUserNumber(20) == btn1->GetUserNumber(20))
{
if(_tcsicmp(btn2->GetText(0),btn1->GetText(0)) < 0)
return(TRUE);
}
return(FALSE);
}
void SetupSquadronInfoWindow(VU_ID TheID)
{
C_Window *win;
C_Text *txt;
C_ListBox *lbox;
C_Button *btn;
C_TreeList *tree;
C_Bitmap *bmp;
UI_Refresher *urec;
Squadron sqd;
CampEntity ent;
VU_ID sqdID;
Flight flt;
long kills[4];
_TCHAR buffer[200];
short count,i;
long total;
int pilots;
F4CSECTIONHANDLE *Leave;
VuSessionsIterator sessionWalker(FalconLocalGame);
FalconSessionEntity *session;
ent=(CampEntity)vuDatabase->Find(TheID);
if(!ent)
return;
gLastSquadron=TheID;
if(ent->IsFlight())
{
flt=(Flight)ent;
sqdID=flt->GetUnitSquadronID();
sqd=(Squadron)vuDatabase->Find(sqdID);
if(!sqd)
return;
pilots = sqd->NumActivePilots();
}
else if(ent->IsSquadron())
{
sqd=(Squadron)ent;
pilots = sqd->NumActivePilots();
}
else
return;
urec=(UI_Refresher *)gGps->Find(sqd->GetCampID());
if(!urec)
return;
win=gMainHandler->FindWindow(AIR_UNIT_WIN);
if(win)
{
Leave=UI_Enter(win);
btn=(C_Button*)win->FindControl(UNIT_SQUADRON_TAB);
if(btn)
{
btn->SetState(1);
btn->Refresh();
}
btn=(C_Button*)win->FindControl(UNIT_PILOT_TAB);
if(btn)
{
btn->SetState(0);
btn->Refresh();
}
bmp=(C_Bitmap*)win->FindControl(UNIT_ICON);
if(bmp)
{
bmp->Refresh();
if(urec->MapItem_ && urec->MapItem_->Icon)
{
bmp->SetImage(urec->MapItem_->Icon->GetImage());
bmp->SetFlagBitOff(C_BIT_INVISIBLE);
}
else
bmp->SetFlagBitOn(C_BIT_INVISIBLE);
bmp->Refresh();
}
bmp=(C_Bitmap*)win->FindControl(UNIT_PATCH);
if(bmp)
{
bmp->SetImage(SquadronMatchIDs[sqd->GetPatchID()][0]);
bmp->Refresh();
}
btn=(C_Button*)win->FindControl(UNIT_SQUADRON_TAB);
if(btn)
{
win->DisableCluster(btn->GetUserNumber(C_STATE_1));
win->EnableCluster(btn->GetUserNumber(C_STATE_0));
}
txt=(C_Text*)win->FindControl(UNIT_TITLE);
if(txt)
{
_TCHAR tmp[80],*sptr;
// KCK: This is a better way of doing this, when taking into account localization
sqd->GetName(tmp,79,FALSE);
sptr = _tcschr(tmp,' ') + 1;
_tcscpy(buffer, sptr);
// _tcscpy(buffer,sqd->GetUnitClassName());
// _tcscat(buffer," ");
// _tcscat(buffer,gStringMgr->GetString(TXT_SQUADRON));
ForeignToUpper(buffer);
txt->SetText(buffer);
}
txt=(C_Text*)win->FindControl(UNIT_NAME);
if(txt)
{
sqd->GetName(buffer,40,FALSE);
txt->SetText(buffer);
}
txt=(C_Text*)win->FindControl(UNIT_OWNER);
if(txt)
{
txt->SetText(TeamInfo[sqd->GetOwner()]->GetName());
}
txt=(C_Text*)win->FindControl(UNIT_ROLE);
if(txt)
{
switch(sqd->GetUnitSpecialty())
{
case SQUADRON_SPECIALTY_AA:
txt->SetText(TXT_AIR_TO_AIR);
break;
case SQUADRON_SPECIALTY_AG:
txt->SetText(TXT_AIR_TO_GROUND);
break;
default:
txt->SetText(TXT_GENERAL);
break;
}
}
txt=(C_Text*)win->FindControl(UNIT_NUM_AIRCRAFT);
if(txt)
{
_stprintf(buffer,"%1d",sqd->GetTotalVehicles());
txt->SetText(buffer);
}
txt=(C_Text*)win->FindControl(UNIT_NUM_PILOTS);
if(txt)
{
_stprintf(buffer,"%1d",pilots);
txt->SetText(buffer);
}
txt=(C_Text*)win->FindControl(UNIT_AIRCRAFT_LOSSES);
if(txt)
{
_stprintf(buffer,"%1d",sqd->GetTotalLosses());
txt->SetText(buffer);
}
txt=(C_Text*)win->FindControl(UNIT_PILOT_LOSSES);
if(txt)
{
_stprintf(buffer,"%1d",sqd->GetPilotLosses());
txt->SetText(buffer);
}
txt=(C_Text*)win->FindControl(UNIT_PLAYERS);
if(txt)
{
count=0;
if(gCommsMgr->Online())
{
VuSessionsIterator sessionWalker(FalconLocalGame);
FalconSessionEntity *session;
session = (FalconSessionEntity*)sessionWalker.GetFirst();
while(session)
{
if(session->GetPlayerSquadronID() == sqd->Id())
count++;
session = (FalconSessionEntity*)sessionWalker.GetNext();
}
}
else
{
if(FalconLocalSession->GetPlayerSquadronID() == sqd->Id())
count++;
}
_stprintf(buffer,"%1d",count);
txt->SetText(buffer);
}
lbox=(C_ListBox*)win->FindControl(UNIT_EXPERIENCE);
if(lbox)
{
count=0;
total=0;
for(i=0;i<PILOTS_PER_SQUADRON;i++)
{
if(sqd->GetPilotData(i)->pilot_status == PILOT_IN_USE || sqd->GetPilotData(i)->pilot_status == PILOT_AVAILABLE)
{
total+=sqd->GetPilotData(i)->GetPilotSkill();
count++;
}
}
if(count)
total/=count;
lbox->SetValue(total+1);
}
lbox=(C_ListBox*)win->FindControl(UNIT_MORALE);
if(lbox)
{
// KCK: Base moral off pilot losses/active pilots..
if (pilots > (PILOTS_PER_SQUADRON * 3) / 4)
lbox->SetValue(MORALE_HIGH);
else if (pilots > PILOTS_PER_SQUADRON / 2)
lbox->SetValue(MORALE_NORMAL);
else
lbox->SetValue(MORALE_LOW);
}
txt=(C_Text*)win->FindControl(UNIT_RESUPPLY_DATE);
if(txt)
{
CampaignTime time = (sqd->GetLastResupplyTime() + sqd->GetUnitSupplyTime());
// Round to nearest hour
time = (time / CampaignHours) * CampaignHours;
GetTimeString(time, buffer, FALSE);
txt->SetText(buffer);
}
txt=(C_Text*)win->FindControl(UNIT_LAST_AIRCRAFT_RECEIVED);
if(txt)
{
_stprintf(buffer,"%d",sqd->GetLastResupply());
txt->SetText(buffer);
}
lbox=(C_ListBox*)win->FindControl(UNIT_SUPPLY);
if(lbox)
{
int supply=100,need = sqd->GetUnitSupplyNeed(FALSE);
if (need)
supply = (sqd->GetUnitSupplyNeed(TRUE)*100)/need;
if(supply < 20)
lbox->SetValue(SUPPLY_CRITICAL);
else if(supply < 45)
lbox->SetValue(SUPPLY_LOW);
else if(supply < 65)
lbox->SetValue(SUPPLY_NORMAL);
else
lbox->SetValue(SUPPLY_FULL);
}
btn=(C_Button*)win->FindControl(UNIT_AIRBASE);
if(btn)
{
ent=sqd->GetUnitAirbase();
if(ent)
{
if (ent->IsObjective())
ent->GetName(buffer,40,TRUE);
else
ent->GetName(buffer,40,FALSE);
}
else
_tcscpy(buffer,"Area 51");
btn->SetText(C_STATE_0,buffer);
}
btn=(C_Button*)win->FindControl(UNIT_SQUADRON_TAB);
if(btn)
{
total=0;
for(i=0;i<ARO_OTHER;i++)
total+=sqd->GetRating(i);
total/=ARO_OTHER;
if(total < 0)
total=0;
if(total > 4)
total=4;
kills[0]=0;
kills[1]=0;
kills[2]=0;
kills[3]=0;
session = (FalconSessionEntity*)sessionWalker.GetFirst();
while(session)
{
if(session->GetPlayerSquadronID() == sqd->Id())
{
kills[0]+=session->GetKill(FalconSessionEntity::_AIR_KILLS_);
kills[1]+=session->GetKill(FalconSessionEntity::_GROUND_KILLS_);
kills[2]+=session->GetKill(FalconSessionEntity::_NAVAL_KILLS_);
kills[3]+=session->GetKill(FalconSessionEntity::_STATIC_KILLS_);
}
session = (FalconSessionEntity*)sessionWalker.GetNext();
}
btn->SetUserNumber(C_STATE_2,sqd->GetMissionsFlown());
btn->SetUserNumber(C_STATE_3,total*25);
btn->SetUserNumber(C_STATE_4,sqd->GetAAKills()+kills[0]);
btn->SetUserNumber(C_STATE_5,sqd->GetAGKills()+kills[1]);
btn->SetUserNumber(C_STATE_6,sqd->GetANKills()+kills[2]);
btn->SetUserNumber(C_STATE_7,sqd->GetASKills()+kills[3]);
btn->SetUserNumber(10,sqd->GetPatchID());
SquadronAirUnitCB(btn->GetID(),C_TYPE_LMOUSEUP,btn);
}
tree=(C_TreeList*)win->FindControl(UNIT_PILOTLIST);
if(tree)
{
tree->SetSortType(TREE_SORT_CALLBACK);
tree->SetSortCallback(SortPilotByNameCB);
BuildPilotList(tree,sqd);
}
gMainHandler->ShowWindow(win);
gMainHandler->WindowToFront(win);
win->RefreshWindow();
UI_Leave(Leave);
}
}
// Returns TRUE if I want to insert newitem before list item
static BOOL CampHotelSortCB(TREELIST *list,TREELIST *newitem)
{
if(!list || !newitem)
return(FALSE);
if(((C_Custom*)newitem->Item_)->GetValue(1) > ((C_Custom*)list->Item_)->GetValue(1))
return(TRUE);
return(FALSE);
}
void UpdateSierraHotel()
{
C_Window *win;
C_TreeList *tree;
C_Text *txt;
C_Bitmap *bmp;
_TCHAR buffer[30];
C_Custom *ctrl;
O_Output *output;
TREELIST *item;
Squadron sqd;
short i;
long ItemID=1;
long kills;
RemoteLB *lbptr;
F4CSECTIONHANDLE *Leave;
win=gMainHandler->FindWindow(CAMP_SH);
if(win)
{
sqd=FalconLocalSession->GetPlayerSquadron();
if(!sqd)
return;
Leave=UI_Enter(win);
tree=(C_TreeList*)win->FindControl(SH_PILOT_LIST);
if(!tree)
return;
tree->SetSortCallback(CampHotelSortCB);
tree->SetSortType(TREE_SORT_CALLBACK);
tree->DeleteBranch(tree->GetRoot()); // Clear it
//if(gCommsMgr->Online())
{
VuSessionsIterator sessionWalker(FalconLocalGame);
FalconSessionEntity *session;
session = (FalconSessionEntity*)sessionWalker.GetFirst();
while(session)
{
if(session->GetPlayerSquadronID() == sqd->Id())
{
kills = 0;
kills=session->GetKill(FalconSessionEntity::_AIR_KILLS_);
// if(kills || 1)
{
ctrl=new C_Custom;
ctrl->Setup(C_DONT_CARE,FalconSessionEntity::_VS_HUMAN_,2);
if(session == FalconLocalSession)
{
if(LogBook.GetPictureResource()) // Temporary
ctrl->SetUserNumber(C_STATE_0,LogBook.GetPictureResource()); // Image ID goes here
else
{ // Need to load a file
ctrl->SetUserNumber(C_STATE_0,NOFACE); // Image ID goes here
}
}
else
{
lbptr=(RemoteLB*)gCommsMgr->GetRemoteLB(session->Id().creator_);
if(lbptr && lbptr->Pilot_.PictureResource)
{
ctrl->SetUserNumber(C_STATE_0,lbptr->Pilot_.PictureResource); // Image ID goes here
}
else
ctrl->SetUserNumber(C_STATE_0,NOFACE); // Image ID goes here
}
ctrl->SetUserNumber(C_STATE_2,session->GetMissions()); // Num Missions
ctrl->SetUserNumber(C_STATE_3,session->GetRating()); // Mission Rating
ctrl->SetUserNumber(C_STATE_4,session->GetKill(FalconSessionEntity::_AIR_KILLS_));
ctrl->SetUserNumber(C_STATE_5,session->GetKill(FalconSessionEntity::_GROUND_KILLS_));
ctrl->SetUserNumber(C_STATE_6,session->GetKill(FalconSessionEntity::_NAVAL_KILLS_));
ctrl->SetUserNumber(C_STATE_7,session->GetKill(FalconSessionEntity::_STATIC_KILLS_));
// Set pilot name
output=ctrl->GetItem(0);
output->SetTextWidth(20);
output->SetText(session->GetPlayerName());
output->SetFont(tree->GetFont());
output->SetXY(tree->GetUserNumber(C_STATE_0),0);
output->SetFgColor(0xeeeeee);
output->SetInfo();
// set pilot score (with commas)
ctrl->SetValue(1,kills); // used for sorting
_stprintf(buffer,"%1ld",kills);
AddCommas(buffer);
output=ctrl->GetItem(1);
output->SetTextWidth(15);
output->SetText(buffer);
output->SetXY(tree->GetUserNumber(C_STATE_1),0);
output->SetFgColor(0xeeeeee);
output->SetFlags(output->GetFlags() | C_BIT_RIGHT);
output->SetInfo();
item=tree->CreateItem(ItemID,C_TYPE_ITEM,ctrl);
if(item)
{
tree->AddItem(tree->GetRoot(),item);
ItemID++;
}
}
}
session = (FalconSessionEntity*)sessionWalker.GetNext();
}
}
for(i=0;i<PILOTS_PER_SQUADRON;i++)
{
if(sqd->GetPilotData(i)->pilot_status == PILOT_IN_USE || sqd->GetPilotData(i)->pilot_status == PILOT_AVAILABLE)
{
kills=sqd->GetPilotData(i)->aa_kills;
// if(kills || 1)
{
GetPilotName(sqd->GetPilotData(i)->pilot_id,buffer,25);
ctrl=new C_Custom;
ctrl->Setup(C_DONT_CARE,FalconSessionEntity::_VS_AI_,2);
if(sqd->GetOwner() == FalconLocalSession->GetCountry())
ctrl->SetUserNumber(C_STATE_0,PilotImageIDs[PilotInfo[sqd->GetPilotData(i)->pilot_id].photo_id]); // Image ID goes here
else
ctrl->SetUserNumber(C_STATE_0,FlagImageID[TeamInfo[sqd->GetOwner()]->GetFlag()][BIG_HORIZ]); // Image ID goes here
ctrl->SetUserNumber(C_STATE_2,sqd->GetPilotData(i)->missions_flown); // Num Missions
ctrl->SetUserNumber(C_STATE_3,sqd->GetPilotData(i)->GetPilotRating()*25); // Mission Rating
ctrl->SetUserNumber(C_STATE_4,sqd->GetPilotData(i)->aa_kills);
ctrl->SetUserNumber(C_STATE_5,sqd->GetPilotData(i)->ag_kills);
ctrl->SetUserNumber(C_STATE_6,sqd->GetPilotData(i)->an_kills);
ctrl->SetUserNumber(C_STATE_7,sqd->GetPilotData(i)->as_kills);
// Set pilot name
output=ctrl->GetItem(0);
output->SetTextWidth(20);
output->SetText(buffer);
output->SetFont(tree->GetFont());
output->SetXY(tree->GetUserNumber(C_STATE_0),0);
output->SetFgColor(0xeeeeee);
output->SetInfo();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -