📄 units.cpp
字号:
// 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++;
}
}
}
}
// Set ACE of the base
item=tree->GetRoot();
if(item)
{
ctrl=(C_Custom*)item->Item_;
switch(ctrl->GetType())
{
case FalconSessionEntity::_VS_AI_:
bmp=(C_Bitmap*)win->FindControl(PILOT_PIC);
if(bmp)
{
bmp->Refresh();
bmp->SetImage(ctrl->GetUserNumber(C_STATE_0));
bmp->Refresh();
}
txt=(C_Text*)win->FindControl(AI_MISS_FIELD);
if(txt)
{
_stprintf(buffer,"%1ld",ctrl->GetUserNumber(C_STATE_2));
txt->Refresh();
txt->SetText(buffer);
txt->Refresh();
}
txt=(C_Text*)win->FindControl(AI_RATING_FIELD);
if(txt)
{
//_stprintf(buffer,"%1ld",ctrl->GetUserNumber(C_STATE_3));
txt->Refresh();
txt->SetText(ratingstr[(short)(((float)ctrl->GetUserNumber(C_STATE_3)/25.0f + 0.5f))%5]);
txt->Refresh();
}
txt=(C_Text*)win->FindControl(AI_AA_KILLS_FIELD);
if(txt)
{
_stprintf(buffer,"%1ld",ctrl->GetUserNumber(C_STATE_4));
txt->Refresh();
txt->SetText(buffer);
txt->Refresh();
}
txt=(C_Text*)win->FindControl(AI_AG_KILLS_FIELD);
if(txt)
{
_stprintf(buffer,"%1ld",ctrl->GetUserNumber(C_STATE_5));
txt->Refresh();
txt->SetText(buffer);
txt->Refresh();
}
txt=(C_Text*)win->FindControl(AI_NAVAL_KILLS_FIELD);
if(txt)
{
_stprintf(buffer,"%1ld",ctrl->GetUserNumber(C_STATE_6));
txt->Refresh();
txt->SetText(buffer);
txt->Refresh();
}
txt=(C_Text*)win->FindControl(AI_STATIC_KILLS_FIELD);
if(txt)
{
_stprintf(buffer,"%1ld",ctrl->GetUserNumber(C_STATE_7));
txt->Refresh();
txt->SetText(buffer);
txt->Refresh();
}
win->HideCluster(1);
win->UnHideCluster(2);
break;
case FalconSessionEntity::_VS_HUMAN_:
bmp=(C_Bitmap*)win->FindControl(PILOT_PIC);
if(bmp)
{
bmp->Refresh();
bmp->SetImage(ctrl->GetUserNumber(C_STATE_0));
bmp->Refresh();
}
txt=(C_Text*)win->FindControl(COMMISSIONED_FIELD);
if(txt)
{
txt->Refresh();
txt->SetText(LogBook.Commissioned());
txt->Refresh();
}
txt=(C_Text*)win->FindControl(CAMP_CAMPAIGNS_FIELD);
if(txt)
{
kills=LogBook.GetCampaign()->GamesWon;
kills+=LogBook.GetCampaign()->GamesLost;
kills+=LogBook.GetCampaign()->GamesTied;
_stprintf(buffer,"%1ld",kills);
txt->Refresh();
txt->SetText(buffer);
txt->Refresh();
}
txt=(C_Text*)win->FindControl(HOURS_FIELD);
if(txt)
{
_stprintf(buffer,"%.1f",LogBook.FlightHours());
txt->Refresh();
txt->SetText(buffer);
txt->Refresh();
}
txt=(C_Text*)win->FindControl(CAMP_MISS_FIELD);
if(txt)
{
_stprintf(buffer,"%1ld",ctrl->GetUserNumber(C_STATE_2));
txt->Refresh();
txt->SetText(buffer);
txt->Refresh();
}
txt=(C_Text*)win->FindControl(CAMP_RATING_FIELD);
if(txt)
{
//_stprintf(buffer,"%1ld",ctrl->GetUserNumber(C_STATE_3));
txt->Refresh();
txt->SetText(ratingstr[(short)(((float)ctrl->GetUserNumber(C_STATE_3)/25.0f + 0.5f))%5]);
txt->Refresh();
}
txt=(C_Text*)win->FindControl(CAMP_AA_KILLS_FIELD);
if(txt)
{
_stprintf(buffer,"%1ld",ctrl->GetUserNumber(C_STATE_4));
txt->Refresh();
txt->SetText(buffer);
txt->Refresh();
}
txt=(C_Text*)win->FindControl(CAMP_AG_KILLS_FIELD);
if(txt)
{
_stprintf(buffer,"%1ld",ctrl->GetUserNumber(C_STATE_5));
txt->Refresh();
txt->SetText(buffer);
txt->Refresh();
}
txt=(C_Text*)win->FindControl(CAMP_NAVAL_KILLS_FIELD);
if(txt)
{
_stprintf(buffer,"%1ld",ctrl->GetUserNumber(C_STATE_6));
txt->Refresh();
txt->SetText(buffer);
txt->Refresh();
}
txt=(C_Text*)win->FindControl(CAMP_STATIC_KILLS_FIELD);
if(txt)
{
_stprintf(buffer,"%1ld",ctrl->GetUserNumber(C_STATE_7));
txt->Refresh();
txt->SetText(buffer);
txt->Refresh();
}
win->HideCluster(2);
win->UnHideCluster(1);
break;
}
item->Item_->SetFlagBitOn(C_BIT_INVISIBLE); // Hide ACE... since we show name at top
txt=(C_Text*)win->FindControl(TOP_JOCK);
if(txt)
{
txt->Refresh();
txt->SetText(((C_Custom*)item->Item_)->GetItem(0)->GetText());
txt->Refresh();
}
txt=(C_Text*)win->FindControl(TOP_SCORE);
if(txt)
{
txt->Refresh();
txt->SetText(((C_Custom*)item->Item_)->GetItem(1)->GetText());
txt->Refresh();
}
}
else
{
win->HideCluster(1);
win->HideCluster(2);
}
tree->RecalcSize();
if(tree->Parent_)
tree->Parent_->RefreshClient(tree->GetClient());
win->ScanClientArea(0);
win->RefreshClient(0);
UI_Leave(Leave);
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
WayPointClass* GetWayPointUnder(Unit unit)
{
WayPoint w = unit->GetFirstUnitWP();
GridIndex x,y,wx,wy;
unit->GetLocation(&x,&y);
gDragWPNum = 0;
if (!w)
return NULL;
while (w)
{
gDragWPNum++;
w->GetWPLocation(&wx,&wy);
if (wx == x && wy == y)
return w;
w = w->GetNextWP();
}
return NULL;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void UnitCB (long ID,short hittype,C_Base *ctrl)
{
CampEntity entity;
Unit unit;
float wx,wy;
short bx,by;
MAPICONLIST *item;
WayPointClass *wp,*pw=NULL,*nw;
if (hittype == C_TYPE_LDROP)
{
entity = GetEntityByCampID (ID);
if (entity && entity->IsUnit())
{
unit = (UnitClass *) entity;
item =((C_MapIcon*)ctrl)->FindID(ID);
if(item)
{
wx = item->worldx;
wy = gMapMgr->GetMaxY () - item->worldy;
bx = SimToGrid(wx);
by = SimToGrid(wy);
// Find any waypoints we may be sitting on
wp = GetWayPointUnder(unit);
// Change our location and our waypoint's
unit->SetLocation(bx,by);
if (unit->IsBattalion())
tactical_set_orders((Battalion)unit, unit->GetUnitObjectiveID(), bx, by);
else if (wp)
{
wp->SetWPLocation(bx,by);
recalculate_waypoints(wp);
gMapMgr->SetCurrentWaypointList(unit->Id());
}
}
}
}
else if(hittype == C_TYPE_LMOUSEUP)
{
entity = GetEntityByCampID (ID);
if (entity && entity->IsUnit())
{
unit = (UnitClass *) entity;
if((TheCampaign.Flags & CAMP_TACTICAL_EDIT) || (GetTeam(unit->GetOwner()) == FalconLocalSession->GetTeam()))
{
gMapMgr->SetCurrentWaypointList (unit->Id ());
if (entity->IsFlight())
{
gActiveFlightID=unit->Id();
gLoadoutFlightID=unit->Id();
SetupFlightSpecificControls((Flight)entity);
}
}
}
}
else if(hittype == C_TYPE_MOUSEMOVE)
{
entity = GetEntityByCampID (ID);
if (entity && entity->IsUnit())
{
unit = (UnitClass *) entity;
if (entity->IsFlight())
{
gActiveFlightID=unit->Id();
gLoadoutFlightID=unit->Id();
SetupFlightSpecificControls((Flight)entity);
}
item =((C_MapIcon*)ctrl)->FindID(ID);
if(item)
{
wx = item->worldx;
wy = gMapMgr->GetMaxY() - item->worldy;
bx = SimToGrid(wx);
by = SimToGrid(wy);
wp = GetWayPointUnder(unit);
// Change our location
unit->SetLocation(bx,by);
if (!unit->IsFlight())
return;
// Add a new waypoint at current location or move the one we were sitting on
if (wp)
wp->SetWPLocation(bx,by);
else
{
gDragWPNum = 1;
wp = unit->GetFirstUnitWP();
while (wp && wp != unit->GetCurrentUnitWP())
{
gDragWPNum++;
wp = wp->GetNextWP();
}
if (wp)
{
pw = wp->GetPrevWP();
ShiAssert(pw);
nw = new WayPointClass (bx, by, wp->GetWPAltitude(), static_cast<int>(wp->GetWPSpeed()), TheCampaign.CurrentTime, 0, WP_NOTHING, 0);
nw->SetWPSpeed(wp->GetWPSpeed());
// Lock time? basically we're saying we want the flight here at this time, so I'd guess yes
nw->SetWPFlags(WPF_TIME_LOCKED);
pw->InsertWP(nw);
}
// Rebuild the waypoint list upon this addition
recalculate_waypoints(wp);
gMapMgr->SetCurrentWaypointList (unit->Id ());
}
recalculate_waypoints(wp);
gMapMgr->GetCurWP()->UpdateInfo((unit->GetCampID()*256) + gDragWPNum,item->worldx,item->worldy);
gMapMgr->GetCurWP()->Refresh();
}
}
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void fixup_unit (Unit unit)
{
WayPointClass *wp,*pwp;
CampaignHeading h;
GridIndex x,y,dx,dy,wx,wy,pwx,pwy;
int z,ndt,dt;
CampaignTime current_time;
float heading;
current_time = TheCampaign.CurrentTime;
wp = unit->GetFirstUnitWP();
while (wp && (wp->GetWPDepartureTime() < current_time) && wp->GetWPAction() != WP_LAND)
{
// Some special case stuff for air mobile
if (wp->GetWPAction() == WP_PICKUP)
{
// Load the airborne battalion.
Unit cargo = (Unit) wp->GetWPTarget();
if (cargo)
{
unit->SetCargoId(cargo->Id());
cargo->SetCargoId(unit->Id());
cargo->SetInactive(1);
}
unit->LoadUnit(cargo);
}
else if (wp->GetWPAction() == WP_AIRDROP)
{
// Unload the airborne battalion.
Unit cargo = (Unit) wp->GetWPTarget();
unit->UnloadUnit();
if (cargo)
{
cargo->SetCargoId(FalconNullId);
cargo->SetInactive(0);
wp->GetWPLocation(&x,&y);
cargo->SetLocation(x,y);
}
}
wp = wp->GetNextWP();
}
if (wp)
{
unit->SetCurrentUnitWP(wp);
pwp = wp->GetPrevWP();
if (pwp)
{
wp->GetWPLocation(&wx,&wy);
if (wp->GetWPFlags() & WPF_HOLDCURRENT)
z = pwp->GetWPAltitude ();
else
z = wp->GetWPAltitude ();
pwp->GetWPLocation(&pwx,&pwy);
// KCK NOTE: We may want to find grid paths for battalions...
// But for now, just move in a staight line.
dx = static_cast<short>(wx - pwx);
dy = static_cast<short>(wy - pwy);
ndt = current_time - pwp->GetWPDepartureTime ();
dt = wp->GetWPDepartureTime () - pwp->GetWPDepartureTime ();
if (ndt > dt)
ndt = dt;
dx = static_cast<short>(FloatToInt32(dx * ((float)ndt / (float)dt)));
dy = static_cast<short>(FloatToInt32(dy * ((float)ndt / (float)dt)));
heading = AngleTo (pwx,pwy,wx,wy);
h = DirectionTo(pwx,pwy,wx,wy);
unit->SetYPR(heading,0.0F,0.0F);
if (unit->IsFlight())
((Flight)unit)->SetLastDirection(h);
unit->SetUnitLastMove(current_time);
unit->SetLocation(static_cast<short>(pwx + dx), static_cast<short>(pwy + dy));
unit->SetUnitAltitude(z);
}
else
{
wp->GetWPLocation(&x,&y);
unit->SetLocation(x,y);
if (unit->IsFlight())
unit->SetUnitDestination(x,y);
pwp = wp->GetNextWP();
if (pwp)
{
pwp->GetWPLocation(&wx,&wy);
heading = AngleTo(x,y,wx,wy);
unit->SetYPR(heading,0.0F,0.0F);
}
}
}
while (wp)
{
// Some special case stuff for air mobile
if (wp->GetWPAction() == WP_PICKUP)
{
Unit cargo = (Unit) wp->GetWPTarget();
if (cargo)
{
// Put airborne battalion at the pickup point.
unit->SetCargoId(cargo->Id());
cargo->SetCargoId(unit->Id());
wp->GetWPLocation(&x,&y);
cargo->SetLocation(x,y);
cargo->SetInactive(0);
}
}
wp = wp->GetNextWP();
}
}
void fixup_unit_starting_positions (void)
{
VuListIterator iter (AllRealList);
UnitClass *unit;
victory_condition *vc;
unit = GetFirstUnit (&iter);
while (unit)
{
fixup_unit(unit);
unit = GetNextUnit (&iter);
}
if (gMapMgr)
{
vc = current_tactical_mission->get_first_unfiltered_victory_condition ();
while (vc)
{
gMapMgr->UpdateVC (vc);
vc = current_tactical_mission->get_next_unfiltered_victory_condition ();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -