⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 waypoint.cpp

📁 空战游戏flacon源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	{
		lbox->SetValue (wp->GetWPFormation()+1);
	}

	lbox=(C_ListBox *)win->FindControl(ENR_ACTION_LISTBOX);
	if(lbox)
	{
		lbox->SetValue (wp->GetWPRouteAction()+1);
	}

	lbox=(C_ListBox *)win->FindControl(ACTION_LISTBOX);
	if(lbox)
	{
		lbox->SetValue(wp->GetWPAction()+1);
//		SteerPointTypeCB(ACTION_LISTBOX,C_TYPE_SELECT,lbox);
	}

	// Draw Error boxes
	errors = WayPointErrorCode (wp, flt);
	win->HideCluster(80);
	win->HideCluster(81);
	win->HideCluster(82);
	if (errors & WPERROR_NO_TARGET)
		win->UnHideCluster(82);
	if (errors & WPERROR_SPEED)
		win->UnHideCluster(81);
	if (errors & WPERROR_TIME)
		win->UnHideCluster(80);
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

void GotoPrevWaypointCB(long,short hittype,C_Base *control)
{
	C_Window *win;
	Flight flt;
	WayPoint wp,prevwp;
	int i;

	if (hittype != C_TYPE_LMOUSEUP)
		return;

	if(gActiveFlightID == FalconNullId)
		return;

	if(gActiveWPNum < 2)
		return;

	win=control->Parent_;

	if(win)
	{
		gActiveWPNum--;

		flt=(Flight)FindUnit(gActiveFlightID);
		if(flt == NULL) return;

		wp=flt->GetFirstUnitWP();
		i=1;
		prevwp=wp;
		while(i < gActiveWPNum && wp)
		{
			prevwp=wp;
			wp=wp->GetNextWP();
			i++;
		}
		if(wp)
		{
			UpdateWaypointWindowInfo(win,wp,i);
			win->RefreshWindow();
		}
	}
}

void GotoNextWaypointCB(long,short hittype,C_Base *control)
{
	C_Window *win;
	Flight flt;
	WayPoint wp,prevwp;
	int i;

	if (hittype != C_TYPE_LMOUSEUP)
		return;

	if(gActiveFlightID == FalconNullId)
		return;

	win=control->Parent_;

	if(win)
	{
		flt=(Flight)FindUnit(gActiveFlightID);
		if(flt == NULL)
			return;

		wp=flt->GetFirstUnitWP();
		i=0;
		prevwp=wp;
		while(i < gActiveWPNum && wp)
		{
			prevwp=wp;
			wp=wp->GetNextWP();
			i++;
		}
		if(wp)
		{
			gActiveWPNum++;
			UpdateWaypointWindowInfo(win,wp,gActiveWPNum);
			win->RefreshWindow();
		}
	}
}

void DeleteWPCB(long,short hittype,C_Base *)
{
	WayPoint		wp,nw;
	Flight			flt;

	if(hittype != C_TYPE_LMOUSEUP)
		return;

	flt=(Flight)vuDatabase->Find(gActiveFlightID);
	wp = get_current_waypoint();

	if (!wp || !flt)
		return;

	nw = wp->GetPrevWP();
	if ((wp->GetPrevWP()) && (wp->GetNextWP ()))
		{
		flt->DeleteUnitWP(wp);
		}

	recalculate_waypoints(nw);
	gMapMgr->SetCurrentWaypointList (flt->Id());
	if (TheCampaign.Flags & CAMP_TACTICAL_EDIT)
	{
		Flight	un;

		un = (Flight)vuDatabase->Find(gMapMgr->GetCurWPID());
		if(un)
		{
			fixup_unit (un);
			gGps->Update();
			gMapMgr->DrawMap();
		}
	}
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

void SetupFlightSpecificControls (Flight flt)
	{
	C_PopupList		*menu;
	C_ListBox		*lbox;
	C_Window *win;
	int				i,mission;

	if(!flt) // it is possible to this to be null... so avoid PJW
		return;

	mission = flt->GetUnitMission();
	win=gMainHandler->FindWindow(FLIGHT_PLAN_WIN);
	menu=gPopupMgr->GetMenu(STEERPOINT_POP);

	// Setup our possible waypoint actions
	lbox = (C_ListBox *)win->FindControl(ACTION_LISTBOX);
	if (lbox)
		{
		// KCK NOTE: Peter mentioned that this should eventually simply disable invalid
		// actions, not rebuild the whole thingy.
		lbox->RemoveAllItems();
		for (i=0; i<WP_LAST; i++)
			{
			if (IsValidAction(mission,i))
				{
				if (!i)
					lbox->AddItem(i+1,C_TYPE_ITEM,WPActStr[39]);
				else
					lbox->AddItem(i+1,C_TYPE_ITEM,WPActStr[i]);
				menu->SetItemFlagBitOff(i|0x200,C_BIT_INVISIBLE);
				}
			else
				{
				menu->SetItemFlagBitOn(i|0x200,C_BIT_INVISIBLE);
				}
			}
		}

	// Setup our possible enroute actions
	lbox = (C_ListBox *)win->FindControl(ENR_ACTION_LISTBOX);
	if (lbox)
		{
		lbox->RemoveAllItems();
		for (i=0; i<WP_LAST; i++)
			{
			if (IsValidEnrouteAction(mission,i))
				{
				if (!i)
					lbox->AddItem(i+1,C_TYPE_ITEM,WPActStr[39]);
				else
					lbox->AddItem(i+1,C_TYPE_ITEM,WPActStr[i]);
				menu->SetItemFlagBitOff(i|0x100,C_BIT_INVISIBLE);
				}
			else
				{
				menu->SetItemFlagBitOn(i|0x100,C_BIT_INVISIBLE);
				}
			}
		}

	}


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// ListBox Callback...
void GotoFlightCB(long ID,short hittype,C_Base *control)
{
	C_Window *win;
	WayPoint wp,prevwp=NULL;
	Package Pkg;
	Flight flt,curflt;
	int i;

	if(hittype != C_TYPE_SELECT)
		return;

	ID=((C_ListBox*)control)->GetTextID();

	win=gMainHandler->FindWindow(FLIGHT_PLAN_WIN);
	if(win)
	{
		flt=(Flight)vuDatabase->Find(gActiveFlightID);
		if(flt == NULL)
			return;

		if(flt->GetCampID() != ID)
		{
			Pkg=(Package)flt->GetUnitParent();
			if(Pkg)
			{
				curflt=(Flight)Pkg->GetFirstUnitElement();
				while(curflt && curflt->GetCampID() != ID)
					curflt=(Flight)Pkg->GetNextUnitElement();
			}
			else
				curflt=NULL;
			flt=curflt;
		}
		if(!flt)
			return;

		if (gActiveFlightID != flt->Id())
				{
				gActiveFlightID=flt->Id();
				ValidateWayPoints(flt);
				}

		wp=flt->GetFirstUnitWP();
		prevwp=wp;
		i=1;
		while(i < gActiveWPNum && wp)
		{
			prevwp=wp;
			wp=wp->GetNextWP();
			i++;
		}
		if(wp)
		{
			UpdateWaypointWindowInfo(win,wp,i, FALSE);
			win->RefreshWindow();
			gMainHandler->ShowWindow(win);
			gMainHandler->WindowToFront(win);
			gActiveWPNum=static_cast<short>(i);
		}
	}
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

void ChangeTOSCB(long ID,short hittype,C_Base *control)
{
	C_Clock *clk;
	long t; 
	WayPoint wp;

	if ((hittype != C_TYPE_LMOUSEUP) &&	(hittype != C_TYPE_LMOUSEDBLCLK) &&	(hittype != C_TYPE_REPEAT))
		return;

	clk=(C_Clock*)control->Parent_->FindControl(control->GetUserNumber(0));
	if(clk)
	{
		ChangeTimeCB(ID,hittype,control);

		wp = get_current_waypoint ();
		if (wp)
		{
			wp->SetWPFlag (WPF_TIME_LOCKED);
			t = clk->GetTime() * VU_TICS_PER_SECOND;
			wp->SetWPTimes(t);
			recalculate_waypoints(wp);
		}

		if (TheCampaign.Flags & CAMP_TACTICAL_EDIT)
		{
			Flight	un;
			un = (Flight)vuDatabase->Find(gMapMgr->GetCurWPID());
			if(un)
			{
				fixup_unit (un);
				gGps->Update();
				gMapMgr->DrawMap();
			}
		}
	}
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

void ChangeAirspeedCB (long ID, short hittype, C_Base *)
{
	WayPointClass	*wp=NULL;
	float			speed=0.0F;
	int				dir=0;

	if ((hittype != C_TYPE_LMOUSEUP) &&	(hittype != C_TYPE_REPEAT) && (hittype != C_TYPE_LMOUSEDBLCLK))
		return;

	if (ID == AIRSPEED_DECR)
		dir = -1;
	else if (ID == AIRSPEED_INC)
		dir = 1;

	wp = get_current_waypoint ();
	if (wp)
	{
		if (wp->GetPrevWP())
		{
			speed = wp->GetWPSpeed() + 10 * dir;
			wp->SetWPFlag (WPF_SPEED_LOCKED);
			wp->SetWPSpeed (speed);
			recalculate_waypoints (wp);
		}

		if (TheCampaign.Flags & CAMP_TACTICAL_EDIT)
		{
			Flight	un;

			un = (Flight)vuDatabase->Find(gMapMgr->GetCurWPID());
			if(un)
			{
				fixup_unit (un);
				gGps->Update();
				gMapMgr->DrawMap();
			}
		}
	}
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

void ChangeAltCB(long ID,short hittype,C_Base *)
{
	int				value=0,dir=0;
	WayPointClass	*wp=NULL;
	float			speed=0.0F;

	if ((hittype != C_TYPE_LMOUSEUP) &&	(hittype != C_TYPE_REPEAT) && (hittype != C_TYPE_LMOUSEDBLCLK))
		return;

	if(ID == ALT_INC)
		dir = 1;
	else if(ID == ALT_DECR)
		dir = -1;

	wp = get_current_waypoint ();

	value = wp->GetWPAltitude();
	speed = get_air_speed(wp->GetWPSpeed()*KM_TO_NM, value);

	if (value < 1000)
		value += 100 * dir;
	else if (value < 40000)
		value += 500 * dir;
	else
		value += 1000 * dir;

	if (value < 100)
		value = 100;
	else if (value > 80000)
		value = 80000;

	if (wp->GetWPAction() == WP_TAKEOFF || wp->GetWPAction() == WP_LAND)
		value = 0;

	wp->SetWPAltitude(value);

	if (wp->GetWPFlags () & WPF_SPEED_LOCKED)
	{
		// Keep IAS constant
		speed = get_ground_speed(speed, value);
		wp->SetWPSpeed (speed*NM_TO_KM);
		recalculate_waypoints(wp);
	}
	else
		refresh_waypoint(wp);

	// KCK HACK: Not sure how to just refresh this waypoint - so, I'm going to only rebuild the list 
	// once in a while for repeat, or on mouseup.
	if (hittype == C_TYPE_LMOUSEUP || !(rand()%4))
		{
		// Rebuild the Z waypoint list (would be nice to just refresh)
		gMapMgr->SetCurrentWaypointList(gActiveFlightID);
		}
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

void ChangePatrolCB(long ID,short hittype,C_Base *control)
	{
	C_Clock			*clk;
	CampaignTime	time;
	WayPoint		wp;

	if(hittype != C_TYPE_LMOUSEUP && hittype != C_TYPE_REPEAT)
		return;

	clk=(C_Clock*)control->Parent_->FindControl(control->GetUserNumber(0));
	if(clk)
		{
		ChangeTimeCB(ID,hittype,control);

		wp = get_current_waypoint();
		if (wp && !(wp->GetWPFlags() & WPF_REPEAT))
			wp = wp->GetNextWP();
		if (!wp && !(wp->GetWPFlags() & WPF_REPEAT))
			return;

		time = clk->GetTime() * VU_TICS_PER_SECOND;
		wp->SetWPStationTime(time);
		recalculate_waypoints(wp);

		if (TheCampaign.Flags & CAMP_TACTICAL_EDIT)
			{
			Flight	un = (Flight)vuDatabase->Find(gMapMgr->GetCurWPID());
			if(un)
				{
				fixup_unit (un);
				gGps->Update();
				gMapMgr->DrawMap();
				}
			}
		}
	}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

void ChangeAirspeedLockCB (long,short hittype,C_Base *)
{
	WayPointClass
		*wp;

	if(hittype != C_TYPE_LMOUSEUP)
		return;

	wp = get_current_waypoint ();

	if (wp->GetWPFlags () & WPF_SPEED_LOCKED)
		wp->UnSetWPFlag (WPF_SPEED_LOCKED);
	else
		wp->SetWPFlag (WPF_SPEED_LOCKED);
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

void ChangeTOSLockCB (long,short hittype,C_Base *)
{
	WayPointClass
		*wp;

	if(hittype != C_TYPE_LMOUSEUP)
		return;

	wp = get_current_waypoint ();

	if (wp->GetWPFlags () & WPF_TIME_LOCKED)
		wp->UnSetWPFlag (WPF_TIME_LOCKED);
	else
		wp->SetWPFlag (WPF_TIME_LOCKED);
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

static void calculate_waypoint_times_before (WayPointClass *wp);
static void calculate_waypoint_times_after (WayPointClass *wp);
static void calculate_waypoint_times_between (WayPointClass *wp1, WayPointClass *wp2);

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

void refresh_waypoint (WayPointClass * wp)
	{
	C_Window		*win=NULL;
	C_Waypoint		*cwp=NULL;
	FlightClass		*flt=NULL;
	WayPointClass	*w=NULL;
	int				i=0,campID=0;

	flt = (Flight) vuDatabase->Find(gActiveFlightID);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -