📄 units.cpp
字号:
//
// Unit info stuff
//
//
#include <windows.h>
#include "vu2.h"
#include "falcsess.h"
#include "campbase.h"
#include "camplist.h"
#include "campstr.h"
#include "unit.h"
#include "squadron.h"
#include "flight.h"
#include "division.h"
#include "objectiv.h"
#include "chandler.h"
#include "ui95_ext.h"
#include "cmap.h"
#include "gps.h"
#include "urefresh.h"
#include "classtbl.h"
#include "uicomms.h"
#include "userids.h"
#include "textids.h"
#include "teamdata.h"
#include "logbook.h"
#include "remotelb.h"
#include "find.h"
#include "gps.h"
#include "tac_class.h"
#include "te_defs.h"
#include "F4version.h"
extern C_Map *gMapMgr;
extern C_Handler *gMainHandler;
extern GlobalPositioningSystem *gGps;
void DeleteGroupList(long ID);
_TCHAR *AddCommas(_TCHAR *buf);
void SetupFlightSpecificControls (Flight flt);
void recalculate_waypoints (WayPointClass *wp);
void tactical_set_orders(Battalion bat, VU_ID obj, GridIndex tx, GridIndex ty);
void FindMapIcon(long ID);
extern void ForeignToUpper(_TCHAR *buffer);
static long VehList[256][2]; // Max 16, [0]=ID,[1]=Count
static short Count;
VU_ID gLastSquadron=FalconNullId;
extern VU_ID gActiveFlightID,gLoadoutFlightID;
int gDragWPNum = 0;
static void ClearUnitVehicles()
{
int i;
for(i=0;i<256;i++)
{
VehList[i][0]=0;
VehList[i][1]=0;
}
Count=0;
}
static void TallyUnitVehicles(Unit un)
{
int i,j,ID;
if(!un)
return;
for(i=0;i<16;i++)
{
ID=un->GetVehicleID(i);
if(ID)
{
for(j=0;j<Count && Count < 256;j++)
if(VehList[j][0] == ID)
{
VehList[j][1]+=un->GetNumVehicles(i);
ID=0;
}
if(ID)
{
VehList[Count][0]=ID;
VehList[Count++][1]=un->GetNumVehicles(i);
}
}
}
}
void AddVehiclesToWindow(C_Window *win,long client)
{
C_Text *txt;
int i,y=4;
_TCHAR buffer[50];
VehicleClassDataType *vc;
for(i=0;i<16;i++)
{
if(VehList[i][0] && VehList[i][1])
{
vc = GetVehicleClassData (VehList[i][0]);
if(vc)
{
txt=new C_Text;
txt->Setup(C_DONT_CARE,0);
txt->SetXY(15,y);
txt->SetClient(static_cast<short>(client));
txt->SetFont(win->Font_);
txt->SetFixedWidth(50);
_stprintf(buffer,"%1ld %s",VehList[i][1],vc->Name);
txt->SetText(buffer);
txt->SetUserNumber(_UI95_DELGROUP_SLOT_,_UI95_DELGROUP_ID_);
win->AddControl(txt);
y+=txt->GetH()+2;
}
}
}
win->ScanClientArea(client);
win->RefreshClient(client);
}
// Kludge
static long CVTRange(long Value,long MaxVal,long NumSteps)
{
long step;
if(NumSteps < 1)
return(1);
step=MaxVal/NumSteps;
Value/=step;
Value++;
if(Value > NumSteps)
Value=NumSteps;
return(Value);
}
void SetupUnitInfoWindow(VU_ID unitID)
{
C_Window *win;
C_ListBox *lbox;
C_EditBox *ebox;
C_Text *txt;
C_Line *line;
C_Bitmap *bmp;
UI_Refresher *urec;
Objective obj;
long Morale=0;
long Fatigue=0;
long Supply=0;
long Strength=0;//,MaxStrength=0;
long NumUnits=0;
long y,h;
Unit un;
Unit par;
Division divpar;
WayPoint wp;
_TCHAR buffer[200];
int i;
F4CSECTIONHANDLE *Leave;
win=gMainHandler->FindWindow(UNIT_WIN);
if(!win)
return;
un=(Unit)vuDatabase->Find(unitID);
if(!un)
return;
if(!un->IsBattalion() && !un->IsBrigade())
return;
urec=(UI_Refresher*)gGps->Find(un->GetCampID());
if(!urec)
return;
Leave=UI_Enter(win);
DeleteGroupList(UNIT_WIN);
ClearUnitVehicles();
if(un->IsBrigade())
{
par=un->GetFirstUnitElement();
while(par)
{
Morale+=par->GetUnitMorale();
Fatigue+=par->GetUnitFatigue();
Supply+=par->GetUnitSupply();
Strength+=(par->GetTotalVehicles()*100)/par->GetFullstrengthVehicles();
NumUnits++;
TallyUnitVehicles(par);
par=un->GetNextUnitElement();
}
if(NumUnits)
{
Morale/=NumUnits;
Fatigue/=NumUnits;
Supply/=NumUnits;
Strength/=NumUnits;
};
}
else
{
Morale=un->GetUnitMorale();
Fatigue=un->GetUnitFatigue();
Supply=un->GetUnitSupply();
Strength=(un->GetTotalVehicles()*100)/un->GetFullstrengthVehicles();
TallyUnitVehicles(un);
}
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
un->GetName(tmp,79,FALSE);
sptr = _tcschr(tmp,' ') + 1;
_tcscpy(buffer, sptr);
// txt->Refresh();
// _tcscpy(buffer, un->GetUnitClassName());
// _tcscat(buffer,_T(" "));
// GetSizeName(un->GetDomain(),un->GetType(),tmp);
// _tcscat(buffer,tmp);
ForeignToUpper(buffer);
txt->SetText(buffer);
txt->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();
}
txt=(C_Text*)win->FindControl(UNIT_NAME);
if(txt)
{
txt->Refresh();
un->GetName(buffer,40,FALSE);
txt->SetText(buffer);
txt->Refresh();
}
par=un->GetUnitParent();
txt=(C_Text*)win->FindControl(UNIT_PARENT);
if(txt)
{
txt->Refresh();
if(un->IsBattalion())
{
par=un->GetUnitParent();
if(par)
{
par->GetName(buffer,40,FALSE);
txt->SetFlagBitOff(C_BIT_INVISIBLE);
txt->SetText(buffer);
}
else
txt->SetFlagBitOn(C_BIT_INVISIBLE);
}
else
txt->SetFlagBitOn(C_BIT_INVISIBLE);
}
txt=(C_Text*)win->FindControl(UNIT_GRANDPARENT);
if(txt)
{
txt->Refresh();
if(par)
divpar=GetDivisionByUnit(par);
else
divpar=GetDivisionByUnit(un);
if(divpar)
{
divpar->GetName(buffer,40,FALSE);
txt->SetText(buffer);
txt->SetFlagBitOff(C_BIT_INVISIBLE);
txt->Refresh();
}
else
txt->SetFlagBitOn(C_BIT_INVISIBLE);
}
/* KCK: Changed to text box
lbox=(C_ListBox*)win->FindControl(UNIT_OWNER);
if(lbox)
{
// Use flag to determine owner name to choose.
// This way TE works. Ideally, this would be a
// text box and we'd set it to the team name string
lbox->SetValue(TeamInfo[un->GetOwner()]->GetFlag()+1);
lbox->Refresh();
}
*/
txt=(C_Text*)win->FindControl(UNIT_OWNER);
if(txt)
{
txt->SetText(TeamInfo[un->GetOwner()]->GetName());
}
lbox=(C_ListBox*)win->FindControl(UNIT_EXPERIENCE);
if(lbox)
{
if (un->GetRClass() == RCLASS_AIR)
lbox->SetValue(CVTRange(TeamInfo[un->GetTeam()]->airExperience-60,40,5));
else if (un->GetRClass() == RCLASS_NAVAL)
lbox->SetValue(CVTRange(TeamInfo[un->GetTeam()]->navalExperience-60,40,5));
else if (un->GetRClass() == RCLASS_AIRDEFENSE)
lbox->SetValue(CVTRange(TeamInfo[un->GetTeam()]->airDefenseExperience-60,40,5));
else
lbox->SetValue(CVTRange(TeamInfo[un->GetTeam()]->groundExperience-60,40,5));
lbox->Refresh();
}
lbox=(C_ListBox*)win->FindControl(UNIT_SUPPLY);
if(lbox)
{
lbox->SetValue(CVTRange(Supply,100,4));
lbox->Refresh();
}
lbox=(C_ListBox*)win->FindControl(UNIT_MORALE);
if(lbox)
{
lbox->SetValue(CVTRange(Morale,100,4));
lbox->Refresh();
}
lbox=(C_ListBox*)win->FindControl(UNIT_FATIGUE);
if(lbox)
{
lbox->SetValue(CVTRange(Fatigue,100,4));
lbox->Refresh();
}
txt=(C_Text*)win->FindControl(UNIT_ETA);
if(txt)
{
txt->Refresh();
i=1;
wp=un->GetCurrentUnitWP();
if(wp)
{
GetTimeString(wp->GetWPArrivalTime(),buffer);
txt->SetText(buffer);
}
else
txt->SetText(gStringMgr->GetString(TXT_NONE));
txt->Refresh();
}
lbox=(C_ListBox*)win->FindControl(UNIT_FORMATION);
if(lbox)
{
lbox->SetValue(un->GetUnitFormation()+1);
lbox->Refresh();
}
ebox=(C_EditBox*)win->FindControl(UNIT_OBJECTIVE);
if(ebox)
{
// Orders part (Get from the old list box)
int orders = un->GetUnitOrders();
lbox=(C_ListBox*)win->FindControl(UNIT_ORDERS);
if(lbox)
{
lbox->SetValue(orders+1);
_tcscpy(buffer,lbox->GetText());
}
// Objective name part
obj=un->GetUnitObjective();
if(obj)
{
_TCHAR tmp[80];
obj->GetName(tmp,20,FALSE);
if (gLangIDNum >= F4LANG_SPANISH)
{
_tcscat(buffer,_T(" - "));
_tcscat(buffer,tmp);
}
else if (gLangIDNum == F4LANG_GERMAN)
{
_tcscat(buffer,_T(": "));
_tcscat(buffer,tmp);
}
else
{
_tcscat(buffer,_T(" "));
_tcscat(buffer,tmp);
}
}
ebox->SetText(gStringMgr->GetText(gStringMgr->AddText(buffer)));
ebox->Refresh();
}
line=(C_Line*)win->FindControl(UNIT_STRENGTH);
if(line)
{// Strength
line->Refresh();
h=line->GetUserNumber(C_STATE_1)*Strength/100;
y=line->GetUserNumber(C_STATE_0) + line->GetUserNumber(C_STATE_1)-h;
line->SetY(y);
line->SetH(h);
line->Refresh();
}
AddVehiclesToWindow(win,0);
gMainHandler->ShowWindow(win);
gMainHandler->WindowToFront(win);
UI_Leave(Leave);
}
void SetupDivisionInfoWindow(long DivID,short owner)
{
C_Window *win;
C_ListBox *lbox;
C_EditBox *ebox;
C_Text *txt;
C_Line *line;
C_Bitmap *bmp;
UI_Refresher *urec;
long Morale=0;
long Fatigue=0;
long Supply=0;
long Strength=0;//,MaxStrength=0;
long NumUnits=0;
long y,h;
Unit un,tmpun;
Unit par;
Division div;
_TCHAR buffer[200];
F4CSECTIONHANDLE *Leave;
win=gMainHandler->FindWindow(UNIT_WIN);
if(!win)
return;
div=GetFirstDivisionByCountry(owner);
while(div && div->nid != (DivID))
div=GetNextDivisionByCountry(div,owner);
if(!div)
return;
urec=(UI_Refresher*)gGps->Find(div->nid| UR_DIVISION);
if(!urec)
return;
Leave=UI_Enter(win);
DeleteGroupList(UNIT_WIN);
ClearUnitVehicles();
un=div->GetFirstUnitElement();
par=un;
while(par)
{
tmpun=par->GetFirstUnitElement();
while(tmpun)
{
Morale+=tmpun->GetUnitMorale();
Fatigue+=tmpun->GetUnitFatigue();
Supply+=tmpun->GetUnitSupply();
Strength+=(tmpun->GetTotalVehicles()*100)/tmpun->GetFullstrengthVehicles();
NumUnits++;
TallyUnitVehicles(tmpun);
tmpun=par->GetNextUnitElement();
}
par=div->GetNextUnitElement();
}
if(NumUnits)
{
Morale/=NumUnits;
Fatigue/=NumUnits;
Supply/=NumUnits;
Strength/=NumUnits;
}
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
div->GetName(tmp,79,FALSE);
sptr = _tcschr(tmp,' ') + 1;
_tcscpy(buffer, sptr);
// _tcscpy(buffer, un->GetUnitClassName());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -