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

📄 te_units.cpp

📁 空战游戏flacon源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	MissionRequestClass	mis;

	if(hittype != C_TYPE_LMOUSEUP)
		return;

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

	// Create our package, if we don't current have one
	if (!new_package)
		tactical_make_package(ID,hittype,control);

	ShiAssert(new_package);
	if (!new_package)
		return;

	win=gMainHandler->FindWindow(TAC_FLIGHT_WIN);
	if(win)
	{
		lbox=(C_ListBox*)win->FindControl(TAC_AIRCRAFT_TYPE);
		if(lbox)
			ac_type=lbox->GetTextID();

		lbox=(C_ListBox*)win->FindControl(TAC_SQUADRON_LIST);
		if(lbox)
		{
			scampid=lbox->GetTextID();
			if(scampid == 1)
			{
				lbox=(C_ListBox*)win->FindControl(TAC_AIRBASE_LIST);
				if(lbox)
				{
					acampid=lbox->GetTextID();
					urec=(UI_Refresher*)gGps->Find(acampid);
					if(urec)
						squadron = tactical_make_squadron (urec->GetID(),ac_type);
				}
			}
			else
			{
				// Use this squadron
				urec=(UI_Refresher*)gGps->Find(scampid);
				if(!urec)
				{
					MonoPrint("Selected Squadron NOT found\n");
					return;
				}
				squadron=(Squadron)vuDatabase->Find(urec->GetID());
			}
		}
		if (!squadron)
			return;

		// Get our flight size
		lbox = (C_ListBox *) win->FindControl (TAC_FLIGHT_SIZE);
		if (lbox)
			num_vehicles = lbox->GetTextID();
		if (!num_vehicles)
			return;

		tactical_update_package();

		// Find our selected target
		lbox = (C_ListBox *) win->FindControl (TARGET_LIST);
		if (lbox)
			{
			int cid = lbox->GetTextID();
			if (cid < TAC_LOCATION)
				target = GetEntityByCampID(cid);
			else
				target = NULL;
			// Set our package targe to our target if we're the first element
			if (new_package && !new_package->GetFirstUnitElement())
				new_package_target = target;
			}

		lbox = (C_ListBox *) win->FindControl (START_AT_LIST);
		if (lbox)
			start_at = lbox->GetTextID();

		tid = GetClassID (DOMAIN_AIR,CLASS_UNIT,TYPE_FLIGHT,squadron->GetSType(),squadron->GetSPType(),0,0,0);
		if (!tid)
			return;

		tid += VU_LAST_ENTITY_TYPE;

		// Count current flights in package
		while (new_package->GetUnitElement(flights))
			flights++;

		// Add the new flight
		new_flight = NewFlight(tid, new_package, squadron);
		if (!new_flight)
			return;

		// Build the flight's mission request
		mis = *(new_package->GetMissionRequest());
		mis.aircraft = static_cast<uchar>(num_vehicles);
		mis.priority = static_cast<short>(gPackagePriority);
		lbox=(C_ListBox*)win->FindControl(TAC_ROLE);
		if(lbox)
			mis.mission = static_cast<uchar>(lbox->GetTextID());
		else
			mis.mission = AMIS_TRAINING;
		if (!mis.tx || !mis.ty)
			{
			// This is probably a package being editing, and the target x,y have got nuked.
			// We can get them from the package destination
			new_package->GetUnitDestination(&mis.tx,&mis.ty);
			}

		// Setup our 'fixed' time correctly
		mis.tot = TheCampaign.CurrentTime;
		if (gPackageTOT)
			{
			// Locked time on target
			mis.tot_type = TYPE_EQ;
			mis.tot = gPackageTOT;
			}
		else if (start_at == 1)
			{
			mis.tot_type = TOT_TAKEOFF;
			if (gTakeoffTime)
				mis.tot = gTakeoffTime;
			else
				mis.tot = TheCampaign.CurrentTime + CampaignMinutes;
			}
		else if (start_at == 2)
			mis.tot_type = TOT_ENROUTE;
		else if (start_at == 3)
			mis.tot_type = TOT_INGRESS;
		else
			{
			mis.tot_type = TYPE_EQ;
			mis.tot = TheCampaign.CurrentTime + CampaignMinutes;
			}

		if(!(TheCampaign.Flags & CAMP_TACTICAL_EDIT) && mis.tot < TheCampaign.CurrentTime)
			mis.tot = TheCampaign.CurrentTime + 3*CampaignSeconds;

		// Adjust for additional flights (flights is # of previous flights in the package)
/*		if (MissionData[mis.mission].loitertime)
			mis.tot += MissionData[mis.mission].loitertime * flights * CampaignMinutes;
		else
			mis.tot += (CampaignTime)((flights) * 10 *CampaignSeconds);
*/
		if (flights)
			mis.tot += MissionData[mis.mission].separation * CampaignSeconds;

		// Set flight's location to home base for now
		squadron->GetLocation (&x,&y);
		new_flight->SetLocation (x,y);
		new_flight->SetOwner (squadron->GetOwner ());
		squadron->FindAvailableAircraft(&mis);

		if (mis.mission == AMIS_AIRCAV)
			{
			Unit		unit = (Unit) vuDatabase->Find(mis.requesterID);
			GridIndex	ux,uy;
			if (unit)
				{
				unit->GetLocation(&ux,&uy);
				mis.tx = static_cast<short>(ux + 20);
				}
			if (start_at > 3)
				mis.tot += 10 * CampaignMinutes; // Try and get us in front of our pickup point
			}

		mis.flags |= REQF_ALLOW_ERRORS;
		error = new_flight->BuildMission(&mis);
		if (error != PRET_SUCCESS)
			{
			// Show an error message box notifying user this action was not able to be performed
			// Errors are:	PRET_NO_ASSETS - The aircraft wern't available
			//				PRET_ABORTED - Timing was impossible (takeoff before current time, for example)
			MonoPrint("Error planning flight. Aborting\n");
			AreYouSure(TXT_FLIGHT_CANCELED,TXT_ERROR,CloseWindowCB,CloseWindowCB);
			new_package->CancelFlight(new_flight);
			return;
			}

		new_flight->SetUnitMissionTarget(mis.targetID);

		// KCK: Traverse all waypoints and only lock the time of either the target or takeoff
		w = new_flight->GetFirstUnitWP();
		while (w)
			{
			if (gTakeoffTime)
				{
				if (w->GetWPAction() == WP_TAKEOFF)
					w->SetWPFlag(WPF_TIME_LOCKED);
				else
					w->UnSetWPFlag(WPF_TIME_LOCKED);
				}
			else
				{
				if ((w->GetWPFlags() & WPF_TARGET) && !done)
					{
					w->SetWPFlag(WPF_TIME_LOCKED);
					done = 1;
					}
				else
					w->UnSetWPFlag(WPF_TIME_LOCKED);
				}
			w = w->GetNextWP();
			}

		new_package->RecordFlightAddition(new_flight,&mis,0);
		new_flight->SetFinal(1);
		fixup_unit(new_flight);
		gGps->Update();

		gMapMgr->SetCurrentWaypointList(new_flight->Id());
		SetupFlightSpecificControls(new_flight);
		gMapMgr->DrawMap();
		gCurrentFlightID = new_flight->Id();
		gSelectedFlightID = new_flight->Id();

		if(WeAreAddingPackage)
		{
			win=gMainHandler->FindWindow(PACKAGE_WIN);
			if(win)
			{
				C_ATO_Flight *atoflt;
				C_TreeList *tree;
				TREELIST *item;
				tree=(C_TreeList *)win->FindControl(ATO_PACKAGE_TREE);
				if(tree)
				{
					tree->SetCallback(tactical_new_flight_select);

					atoflt=BuildATOFlightInfo(new_flight);
					if(atoflt)
					{
						item=tree->CreateItem(new_flight->GetCampID(),C_TYPE_ITEM,atoflt);
						if(item)
							tree->AddItem (tree->GetRoot (), item);
					}
					tree->RecalcSize();
					tree->Parent_->RefreshClient(tree->GetClient());
				}
				else
					new_package->SetLocation (MapX, MapY);
			}
		}
		else
		{
			new_package->SetFinal(1);
			new_package=NULL;
		}
	}
	display_air_units(new_flight);
	new_flight=NULL;
}

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

void display_air_units (Unit u)
{
	int			stype;
	C_PopupList *menu;

	menu=gPopupMgr->GetMenu(MAP_POP);
	if (!menu)
		return;

	// Make sure we can see this unit
	stype = u->GetSType();
	if (stype == STYPE_UNIT_FIGHTER || stype == STYPE_UNIT_FIGHTER_BOMBER)
	{
		menu->SetItemState(MID_UNITS_SQUAD_FIGHTER,1);
		MenuToggleUnitCB(MID_UNITS_SQUAD_FIGHTER,0,menu);
	}
	else if (stype == STYPE_UNIT_BOMBER)
	{
		menu->SetItemState(MID_UNITS_SQUAD_BOMBER,1);
		MenuToggleUnitCB(MID_UNITS_SQUAD_BOMBER,0,menu);
	}
	else if (stype == STYPE_UNIT_ATTACK_HELO || stype == STYPE_UNIT_RECON_HELO || stype == STYPE_UNIT_TRANSPORT_HELO)
	{
		menu->SetItemState(MID_UNITS_SQUAD_HELI,1);
		MenuToggleUnitCB(MID_UNITS_SQUAD_HELI,0,menu);
	}
	else if (stype == STYPE_UNIT_ATTACK)
	{
		menu->SetItemState(MID_UNITS_SQUAD_ATTACK,1);
		MenuToggleUnitCB(MID_UNITS_SQUAD_ATTACK,0,menu);
	}
	else
	{
		menu->SetItemState(MID_UNITS_SQUAD_SUPPORT,1);
		MenuToggleUnitCB(MID_UNITS_SQUAD_SUPPORT,0,menu);
	}
}

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

void tactical_cancel_package (long, short hittype, C_Base *ctrl)
{
	Flight flt;
	if (hittype != C_TYPE_LMOUSEUP)
	{
		return;
	}

	gMainHandler->DisableWindowGroup (ctrl->Parent_->GetGroup());

//  Delete the unwanted package
	if (new_package)
	{
		flt=(Flight)new_package->GetFirstUnitElement();
		while(flt)
		{
			if(flt->IsFlight())
			{
				RegroupFlight(flt);
				flt=(Flight)new_package->GetNextUnitElement();
			}
		}
		new_package = NULL;
	}
	gGps->Update();
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Battalion Stuff
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

// The id passed in should be the id of any objective we clicked on
void tactical_add_battalion (VU_ID id, C_Base *caller)
{
	C_ListBox		*lbox=NULL;
	C_Window		*win=NULL;
	short			x=0,y=0;
	float			mx,my,maxy,scale;
	CampBaseClass	*ent=NULL;

	win=gMainHandler->FindWindow(NEW_BATT_WIN);
	if (!win)
		return;

	if(caller->_GetCType_() == _CNTL_POPUPLIST_)
	{
		gPopupMgr->GetCurrentXY (&x, &y);
		gMapMgr->GetMapRelativeXY (&x, &y);
	}
	else if(caller->_GetCType_() == _CNTL_MAP_MOVER_)
	{
		x=static_cast<short>(((C_MapMover*)caller)->GetRelX() + caller->GetX() + caller->Parent_->GetX());
		y=static_cast<short>(((C_MapMover*)caller)->GetRelY() + caller->GetY() + caller->Parent_->GetY());
		gMapMgr->GetMapRelativeXY (&x, &y);
	}

	scale = gMapMgr->GetMapScale ();
	maxy = gMapMgr->GetMaxY ();
	mx = x / scale;
	my = maxy - y / scale;

	MapX = SimToGrid (mx);
	MapY = SimToGrid (my);

	// Determine target (or target location)
	ent=(CampEntity) vuDatabase->Find(id);
	if (ent && ent->IsObjective())
		{
		ent->GetLocation(&MapX,&MapY);
		gLastBattalionObjID = ent->Id();
		}
	else
		{
		gLastBattalionObjID = FalconNullId;
		MapX = SimToGrid (mx);
		MapY = SimToGrid (my);
		}

	// Setup list box for our team (or last equipment choice)
	lbox = (C_ListBox *) win->FindControl (UNIT_TOE);
	if (lbox)
		{
		// KCK Hack: Convert from flags to his equipment table
		if (gLastEquipment)
			lbox->SetValue (gLastEquipment);
		else if (TeamInfo[gSelectedTeam]->GetFlag() == COUN_RUSSIA)
			lbox->SetValue (toe_soviet);
		else if (TeamInfo[gSelectedTeam]->GetFlag() == COUN_CHINA)
			lbox->SetValue (toe_chinese);
		else if (TeamInfo[gSelectedTeam]->GetFlag() == COUN_SOUTH_KOREA)
			lbox->SetValue (toe_rok);
		else if (TeamInfo[gSelectedTeam]->GetFlag() == COUN_NORTH_KOREA)
			lbox->SetValue (toe_dprk);
		else
			lbox->SetValue (toe_us);
		}

	if (gLastEquipment && gLastUnitType != -1)
		{
		lbox = (C_ListBox *) win->FindControl (UNIT_TYPE);
		if (lbox)
			lbox->SetValue(gLastUnitType);
		}

	update_new_battalion_window ();
	gMainHandler->EnableWindowGroup (32000);
	}

Objective FindValidObjective (Battalion bat, VU_ID current_obj, GridIndex x, GridIndex y)
	{
	Objective		o = (Objective)vuDatabase->Find(current_obj);
//	float			last=-1.0F;

	// Non-mobile battalions always snap to their objectives
	// So clear their objective
	if (bat->GetMovementType() == NoMove)
		{
		gLastBattalionObjID = FalconNullId;
		o = NULL;
		}

	// Snap battalion to nearest objective
/*	KCK: Commented out as per a beta-tester request. Let's see how it works
	if (bat->GetUnitNormalRole() == GRO_AIRDEFENSE)
		{
		// Air defense units need to snap to SAM sites
		if (!o)
			o = FindNearestObjective(x,y,&last,999);
		while (o && !o->SamSite())
			o = FindNearestObjective(x,y,&last,999);
		}
*/
	if (!o)
		o = FindNearestObjective(x,y,NULL,999);
	return o;
	}

void tactical_set_orders(Battalion bat, VU_ID obj, GridIndex tx, GridIndex ty)
	{
	Objective		o;
	WayPoint		wp,nw;
	GridIndex		x,y,xd,yd;
	int				role,oldgs;

	o = FindValidObjective(bat, obj, tx, ty);
	if (!o || !bat)
		return;

	CampEnterCriticalSection();

	if (o->GetTeam() == bat->GetTeam())
		{
		role = bat->GetUnitNormalRole();
		if (role == GRO_AIRDEFENSE && o->SamSite())
			bat->SetUnitOrders(GORD_AIRDEFENSE,o->Id());
		else if (role == GRO_FIRESUPPORT)
			bat->SetUnitOrders(GORD_SUPPORT,o->Id());
		else if (role == GRO_DEFENSE || role == GRO_ATTACK || role == GRO_RECON)
			bat->SetUnitOrders(GORD_DEFEND,o->Id());
		else
			bat->SetUnitOrders(GORD

⌨️ 快捷键说明

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