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

📄 dogfight.cpp

📁 空战游戏flacon源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	}
	idx = GetPlaneListID(acid);
	type = GetClassID(DOMAIN_AIR,CLASS_UNIT,TYPE_FLIGHT,DFAIPlanes[idx].UnitSType,DFAIPlanes[idx].SPType,VU_ANY,VU_ANY,VU_ANY) + VU_LAST_ENTITY_TYPE;
	AddDogfightAIPlane (flight, type, skill, teamid);

	gMainHandler->DisableWindowGroup(control->GetGroup());
}

void AddDogfightAICB(long ID,short hittype,C_Base *control)
{
	C_Window *win;
	C_ListBox *lbox;
	if(hittype != C_TYPE_LMOUSEUP)
		return;

	if(gCommsMgr->Online() && SimDogfight.GetDogfightGameStatus() != dog_Waiting)
	{
		GameHasStarted();
		gMainHandler->DropControl();
		CopyDFSettingsToWindow();
		return;
	}

	switch(ID)
	{
		case ADD_CRIMSON_PLANE:
			AddToTeam=DF_CRIMSON_CALLS;
			break;
		case ADD_SHARK_PLANE:
			AddToTeam=DF_SHARK_CALLS;
			break;
		case ADD_USA_PLANE:
			AddToTeam=DF_TBIRD_CALLS;
			break;
		case ADD_TIGER_PLANE:
			AddToTeam=DF_TIGER_CALLS;
			break;
		case ADD_FURBALL_PLANE:
			AddToTeam=DF_FURBALL_CALLS;
			break;
	}

	win=gMainHandler->FindWindow(DF_FLIGHT_WIN);
	if(win)
	{
		lbox=(C_ListBox*)win->FindControl(AddToTeam);
		if(lbox)
		{
			win->HideCluster(lbox->GetUserNumber(1));
			win->HideCluster(lbox->GetUserNumber(2));
			win->HideCluster(lbox->GetUserNumber(3));
			win->HideCluster(lbox->GetUserNumber(4));
			win->UnHideCluster(lbox->GetUserNumber(0));
		}
	}
	gMainHandler->EnableWindowGroup(control->GetGroup());
}

void RemoveAICB(long ID,short hittype,C_Base *)
{
	Flight flight;
	short teamid=0;
	if(hittype != C_TYPE_LMOUSEUP)
		return;

	flight=(Flight)vuDatabase->Find(gCurrentFlightID);
	if(!flight)
		return;

	if(gCommsMgr->Online() && SimDogfight.GetDogfightGameStatus() != dog_Waiting)
	{
		GameHasStarted();
		gMainHandler->DropControl();
		CopyDFSettingsToWindow();
		return;
	}

	switch(ID)
	{
		case DEL_CRIMSON_PLANE:
			teamid=1;
			break;
		case DEL_SHARK_PLANE:
			teamid=2;
			break;
		case DEL_TBIRD_PLANE:
			teamid=3;
			break;
		case DEL_TIGER_PLANE:
			teamid=4;
			break;
		case DEL_FURBALL_PLANE:
			teamid=-1;
			break;
	}

	if(teamid == -1)
		RemoveDogfightPlane();
	else if(flight->GetTeam() == teamid)
		RemoveDogfightPlane();
}

void PositionSlider(C_Slider *slider,long value,long minv,long maxv)
{
	int pos;
	if(slider)
	{
		pos=((slider->GetSliderMax()-slider->GetSliderMin()) * (value-minv)) / (maxv-minv+1) + 1;
		slider->Refresh();
		slider->SetSliderPos(pos);
		slider->Refresh();
	}
}

void UpdateDogfightWindows (void)
	{
	C_Window *win;
	C_Button *btn;

	win=gMainHandler->FindWindow(DF_GAME_HEADER_WIN);
	if (win)
		{
		btn=(C_Button *)win->FindControl(DF_GAME_TITLE);
		if (btn)
			{
			switch (SimDogfight.GetGameType())
				{
				case dog_TeamFurball:
					btn->SetState(1);
					break;
				case dog_TeamMatchplay:
					btn->SetState(2);
					break;
				default:
					btn->SetState(0);
					break;
				}
			}
		btn->Refresh();
		}
	win=gMainHandler->FindWindow(DF_TEAM_WIN);
	if(win)
		{
		if(SimDogfight.GetGameType() != dog_Furball)
			{
			win->HideCluster(200);
			win->UnHideCluster(100);
			win->SetClientFlags(C_STATE_0,C_BIT_ENABLED);
			win->SetClientFlags(C_STATE_1,C_BIT_ENABLED);
			win->SetClientFlags(C_STATE_2,C_BIT_ENABLED);
			win->SetClientFlags(C_STATE_3,C_BIT_ENABLED);
			win->SetClientFlags(C_STATE_4,0);
			}
		else
			{
			win->HideCluster(100);
			win->UnHideCluster(200);
			win->SetClientFlags(C_STATE_0,0);
			win->SetClientFlags(C_STATE_1,0);
			win->SetClientFlags(C_STATE_2,0);
			win->SetClientFlags(C_STATE_3,0);
			win->SetClientFlags(C_STATE_4,C_BIT_ENABLED);
			}
		win->RefreshWindow();
		}
	}

void CopyDFSettingsToWindow (void)
{
	C_Window *win;
	C_EditBox *ebox;
	C_Button *btn;
	C_Slider *sldr;
	C_ListBox *lbox;
	C_Cursor *crsr;
	C_Clock *clk;

	if (!gMainHandler)
		return;

	gMainHandler->EnterCritical();
	win=gMainHandler->FindWindow(DF_SETTINGS_WIN);
	if(win)
	{
		ebox=(C_EditBox *)win->FindControl(RADAR_READOUT);
		ebox->Refresh();
		if(ebox)
		{
			ebox->SetInteger(SimDogfight.numRadarMissiles);
			ebox->Refresh();
			sldr=(C_Slider *)win->FindControl(RADAR_SLIDER);
			if(sldr)
				PositionSlider(sldr,ebox->GetInteger(),ebox->GetMinInteger(),ebox->GetMaxInteger());
		}
		ebox=(C_EditBox *)win->FindControl(ALLIR_READOUT);
		if(ebox)
		{
			ebox->SetInteger(SimDogfight.numAllAspectMissiles);
			ebox->Refresh();
			sldr=(C_Slider *)win->FindControl(ALLIR_SLIDER);
			if(sldr)
				PositionSlider(sldr,ebox->GetInteger(),ebox->GetMinInteger(),ebox->GetMaxInteger());
		}
		ebox=(C_EditBox *)win->FindControl(RIR_READOUT);
		if(ebox)
		{
			ebox->SetInteger(SimDogfight.numRearAspectMissiles);
			ebox->Refresh();
			sldr=(C_Slider *)win->FindControl(RIR_SLIDER);
			if(sldr)
				PositionSlider(sldr,ebox->GetInteger(),ebox->GetMinInteger(),ebox->GetMaxInteger());
		}
		ebox=(C_EditBox *)win->FindControl(RANGE_READOUT);
		if(ebox)
		{
			ebox->SetInteger(static_cast<long>(SimDogfight.startRange * FT_TO_NM));
			ebox->Refresh();
			sldr=(C_Slider *)win->FindControl(RANGE_SLIDER);
			if(sldr)
				PositionSlider(sldr,ebox->GetInteger(),ebox->GetMinInteger(),ebox->GetMaxInteger());
		}
		ebox=(C_EditBox *)win->FindControl(ALTITUDE_READOUT);
		if(ebox)
		{
			ebox->SetInteger(FloatToInt32(-1.0F*SimDogfight.startAltitude));
			ebox->Refresh();
			sldr=(C_Slider *)win->FindControl(ALTITUDE_SLIDER);
			if(sldr)
				PositionSlider(sldr,ebox->GetInteger(),ebox->GetMinInteger(),ebox->GetMaxInteger());
		}
		ebox=(C_EditBox *)win->FindControl(MP_READOUT);
		if(ebox)
		{
			if(SimDogfight.rounds)
				ebox->SetInteger(SimDogfight.rounds);
			else
				ebox->SetText("Unlimited");
			ebox->Refresh();
			sldr=(C_Slider *)win->FindControl(MP_SLIDER);
			if(sldr)
				PositionSlider(sldr,ebox->GetInteger(),ebox->GetMinInteger(),ebox->GetMaxInteger());
		}

		lbox=(C_ListBox *)win->FindControl(DF_GAME_TYPE);
		if(lbox)
		{
			switch(SimDogfight.GetGameType())
			{
				case dog_Furball:
					lbox->SetValue(DF_GAME_FURBALL);
					break;
				case dog_TeamFurball:
					lbox->SetValue(DF_GAME_TEAM_FURBALL);
					break;
				case dog_TeamMatchplay:
					lbox->SetValue(DF_GAME_TEAM_MATCH);
					break;
			}
			lbox->Refresh();
		}
		btn=(C_Button *)win->FindControl(GUN_CTRL);
		if(btn)
		{
			if(SimDogfight.IsSetFlag(DF_UNLIMITED_GUNS))
				btn->SetState(1);
			else
				btn->SetState(0);
			btn->Refresh();
		}
		btn=(C_Button *)win->FindControl(ECM_CTRL);
		if(btn)
		{
			if(SimDogfight.IsSetFlag(DF_ECM_AVAIL))
				btn->SetState(1);
			else
				btn->SetState(0);
			btn->Refresh();
		}
	}
	win=gMainHandler->FindWindow(DF_MAP_WIN);
	if(win)
	{
		crsr=(C_Cursor*)win->FindControl(DF_MAP_CURSOR);
		if(crsr)
		{
			crsr->SetXY(RatiotoMapX(SimDogfight.xRatio,crsr),RatiotoMapY(SimDogfight.yRatio,crsr));
			crsr->Refresh();
		}
	}
	win=gMainHandler->FindWindow(DF_PLAY_SUA_WIN);
	if(win)
	{
		clk=(C_Clock*)win->FindControl(TIME_ID);
		if(clk)
		{
			clk->SetHour(SimDogfight.startTime/CampaignHours);
			clk->SetMinute((SimDogfight.startTime/CampaignMinutes)%60);
			clk->SetSecond((SimDogfight.startTime/CampaignSeconds)%60);
			clk->Refresh();
		}
	}
	UpdateDogfightWindows();

	if (TheCampaign.IsLoaded())
		BuildDFPlayerList();

	DogfightMenuSetup();
	gMainHandler->LeaveCritical();
}

// Same as above function, but only copys in the time, essentially
// (for the preloaded dogfight selection).
// Later we should also apply # of player, etc.. But I think Joe axed the window 
// to display this.
void CopyDFSettingsToSelectWindow(void)
{
	C_Window *win;
	C_Clock *clk;
	C_Cursor *crsr;

	if (!gMainHandler)
		return;

	gMainHandler->EnterCritical();
	win=gMainHandler->FindWindow(DF_SUA_WIN);
	if(win)
	{
		// Copy in the time
		clk=(C_Clock*)win->FindControl(TIME_ID);
		if(clk)
		{
			clk->SetHour(SimDogfight.startTime/CampaignHours);
			clk->SetMinute((SimDogfight.startTime/CampaignMinutes)%60);
			clk->SetSecond((SimDogfight.startTime/CampaignSeconds)%60);
			clk->Refresh();
		}
	}
	// Update the map too.
	win=gMainHandler->FindWindow(DF_MAP_WIN);
	if(win)
	{
		crsr=(C_Cursor*)win->FindControl(DF_MAP_CURSOR);
		if(crsr)
		{
			crsr->SetXY(RatiotoMapX(SimDogfight.xRatio,crsr),RatiotoMapY(SimDogfight.yRatio,crsr));
			crsr->Refresh();
		}
	}
	UpdateDogfightWindows();
	gMainHandler->LeaveCritical();
}

void CopyDFSettingsFromWindow(void)
{
	C_Window *win;
	C_Cursor *crsr;
	C_ListBox *lbox;
	C_EditBox *ebox;
	C_Button *btn;
	C_Clock *clk;

	if(!gMainHandler) return;

	if(gCommsMgr->Online() && SimDogfight.GetDogfightGameStatus() != dog_Waiting)
		return;

	gMainHandler->EnterCritical();

	// Now the main window
	win=gMainHandler->FindWindow(DF_SETTINGS_WIN);
	if(win)
	{
		ebox=(C_EditBox *)win->FindControl(RADAR_READOUT);
		ebox->Refresh();
		if(ebox)
			SimDogfight.numRadarMissiles = static_cast<uchar>(ebox->GetInteger());
		ebox=(C_EditBox *)win->FindControl(ALLIR_READOUT);
		if(ebox)
			SimDogfight.numAllAspectMissiles = static_cast<uchar>(ebox->GetInteger());
		ebox=(C_EditBox *)win->FindControl(RIR_READOUT);
		if(ebox)
			SimDogfight.numRearAspectMissiles = static_cast<uchar>(ebox->GetInteger());
		ebox=(C_EditBox *)win->FindControl(RANGE_READOUT);
		if(ebox)
			SimDogfight.startRange = ebox->GetInteger() * NM_TO_FT;
		ebox=(C_EditBox *)win->FindControl(ALTITUDE_READOUT);
		if(ebox)
			SimDogfight.startAltitude = ebox->GetInteger() * -1.0F;
		ebox=(C_EditBox *)win->FindControl(MP_READOUT);
		if(ebox)
			SimDogfight.rounds = static_cast<uchar>(ebox->GetInteger());
		btn=(C_Button *)win->FindControl(GUN_CTRL);
		if(btn)
		{
			if (btn->GetState())
				SimDogfight.SetFlag(DF_UNLIMITED_GUNS);
			else
				SimDogfight.UnSetFlag(DF_UNLIMITED_GUNS);
		}
		btn=(C_Button *)win->FindControl(ECM_CTRL);
		if(btn)
		{
			if (btn->GetState())
				SimDogfight.SetFlag(DF_ECM_AVAIL);
			else
				SimDogfight.UnSetFlag(DF_ECM_AVAIL);
		}
	}
	win=gMainHandler->FindWindow(DF_MAP_WIN);
	if(win)
	{
		crsr=(C_Cursor*)win->FindControl(DF_MAP_CURSOR);
		if(crsr)
		{
			SimDogfight.xRatio = MapXtoRatio(crsr);
			SimDogfight.yRatio = MapYtoRatio(crsr);
		}
	}
	win=gMainHandler->FindWindow(DF_SETTINGS_WIN);
	if(win)
	{
		lbox=(C_ListBox *)win->FindControl(DF_GAME_TYPE);
		if(lbox)
		{
			switch (lbox->GetTextID())
			{
				case DF_GAME_TEAM_MATCH:
					SimDogfight.SetGameType(dog_TeamMatchplay);
					break;
				case DF_GAME_TEAM_FURBALL:
					SimDogfight.SetGameType(dog_TeamFurball);
					break;
				default: 
					SimDogfight.SetGameType(dog_Furball);
					break;
			}
		}
	}
	win=gMainHandler->FindWindow(DF_PLAY_SUA_WIN);
	if(win)
	{
		clk=(C_Clock*)win->FindControl(TIME_ID);
		if(clk)
			SimDogfight.startTime = clk->GetHour() * CampaignHours + clk->GetMinute() * CampaignMinutes + clk->GetSecond() * CampaignSeconds;
	}
	UpdateDogfightWindows();

	if (TheCampaign.IsLoaded())
	{
		SimDogfight.ApplySettings();
		SimDogfight.SendSettings(NULL);
	}
	DogfightMenuSetup();
	gMainHandler->LeaveCritical();
}

static void DFGameModeCB(long,short hittype,C_Base *)
{
	if(hittype != C_TYPE_SELECT)
		return;

	if(gCommsMgr->Online() && SimDogfight.GetDogfightGameStatus() != dog_Waiting)
	{
		GameHasStarted();
		gMainHandler->DropControl();
		CopyDFSettingsToWindow();
		return;
	}

	CopyDFSettingsFromWindow();
	CheckFlyButton();
}

void CheckFlyButton()
{
	C_Window *win;
	C_Button *btn1,*btn2;
	BOOL Enabled;

	win=gMainHandler->FindWindow(DF_PLAY_TOOLBAR_WIN);
	if(win == NULL)
		return;

	btn1=(C_Button *)win->FindControl(SINGLE_FLY_CTRL);
	btn2=(C_Button *)win->FindControl(COMMS_FLY_CTRL);

	if(btn1 == NULL || btn2 == NULL)
		return;

	btn1->SetFlagBitOff(C_BIT_ENABLED);
	btn2->SetFlagBitOff(C_BIT_ENABLED);

	Enabled=FALSE;

	if (VuLocalGame != vuPlayerPoolGroup && FalconLocalSession->GetTeam() != 255 && FalconLocalSession->GetPilotSlot() != 255)
		Enabled=TRUE;

	// In dogfight games, check ready state

⌨️ 快捷键说明

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