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

📄 munition.cpp

📁 空战游戏flacon源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/**********************
 *
 *
 * Munitions stuff
 *
 *
 **********************/

#include "Graphics\Include\TimeMgr.h"
#include "Graphics\Include\RViewPnt.h"
#include "Graphics\Include\render3d.h"
#include "Graphics\Include\drawbsp.h"
#include "vu2.h"
#include "F4Thread.h"
#include "cmpclass.h"
#include "campstr.h"
#include "squadron.h"
#include "flight.h"
#include "find.h"
#include "misseval.h"
#include "vehicle.h"
#include "weaplist.h"
#include "chandler.h"
#include "ui95_ext.h"
#include "uicomms.h"
#include "cbsplist.h"
#include "c3dview.h"
#include "cstores.h"
#include "userids.h"
#include "textids.h"
#include "classtbl.h"
#include "MsgInc\FalconFlightPlanMsg.h"
#include "Campaign.h"
#include "railinfo.h"

#pragma warning(disable : 4244)	 // for +=

enum
{
	POD_EMPTY             =200001,
	POD_FULL              =200002,
	POD_DIS               =200003,
	POD_DIFF              =200004,
	LAU3_EMPTY            =200005,
	LAU3_FULL             =200006,
	LAU3_DIS              =200007,
	LAU3_DIFF             =200008,
	LAU2R_EMPTY           =200009,
	LAU2R_FULL            =200010,
	LAU2R_DIS             =200011,
	LAU2R_DIFF            =200012,
	LAU2L_EMPTY           =200013,
	LAU2L_FULL            =200014,
	LAU2L_DIS             =200015,
	LAU2L_DIFF            =200016,
	SINGLE_EMPTY          =200017,
	SINGLE_FULL           =200018,
	SINGLE_DIS            =200019,
	SINGLE_DIFF           =200020,
	LAU2C_EMPTY           =200021,
	LAU2C_FULL            =200022,
	LAU2C_DIS             =200023,
	LAU2C_DIFF            =200024,
	TER_EMPTY             =200025,
	TER_FULL              =200026,
	TER_DIS               =200027,
	TER_DIFF              =200028,
	DOUBLE_TER_EMPTY      =200029,
	DOUBLE_TER_FULL       =200030,
	DOUBLE_TER_DIS        =200031,
	DOUBLE_TER_DIFF       =200032,
	TER2R_EMPTY           =200033,
	TER2R_FULL            =200034,
	TER2R_DIS             =200035,
	TER2R_DIFF            =200036,
	POD_EMPTY_DIFF        =200037,
	LAU3_EMPTY_DIFF       =200038,
	LAU2R_EMPTY_DIFF      =200039,
	LAU2L_EMPTY_DIFF      =200040,
	SINGLE_EMPTY_DIFF     =200041,
	LAU2C_EMPTY_DIFF      =200042,
	TER_EMPTY_DIFF        =200043,
	DOUBLE_TER_EMPTY_DIFF =200044,
	TER2R_EMPTY_DIFF      =200045,
	LAU1_FULL             =200046,
	LAU1_FULL_DIFF        =200047,
	TER2L_EMPTY           =200048,
	TER2L_EMPTY_DIFF      =200049,
	TER2L_FULL            =200050,
	TER2L_DIS             =200051,
	TER2L_DIFF            =200052,
	DOUBLE_TER_4_DIFF     =200053,
	DOUBLE_TER_4		  =200054,
	DOUBLE_TER_5L_DIFF    =200055,
	DOUBLE_TER_5L		  =200056,
	DOUBLE_TER_5R_DIFF    =200057,
	DOUBLE_TER_5R		  =200058,
	QUAD_EMPTY			  =200059,
	QUAD_FULL			  =200060,
	QUAD_DIS			  =200061,
	QUAD_DIFF			  =200062,
	QUAD_EMPTY_DIFF	      =200063,
	QUAD1L				  =200064,
	QUAD1L_DIS			  =200065,
	QUAD1L_DIFF		      =200066,
	QUAD1R				  =200067,
	QUAD1R_DIS			  =200068,
	QUAD1R_DIFF		      =200069,
	QUAD2L				  =200070,
	QUAD2L_DIS			  =200071,
	QUAD2L_DIFF		      =200072,
	QUAD2R				  =200073,
	QUAD2R_DIS			  =200074,
	QUAD2R_DIFF		      =200075,
	QUAD3L				  =200076,
	QUAD3L_DIS			  =200078,
	QUAD3L_DIFF		      =200079,
	QUAD3R				  =200080,
	QUAD3R_DIS			  =200081,
	QUAD3R_DIFF		      =200082,
	INT_EMPTY             =200083,
	INT_FULL              =200084,
	INT_DIS               =200085,
	INT_DIFF              =200086,
};

#define _WPN_MAX_ 6
#define STRING_BUFFER_SIZE    10

void DeleteGroupList(long ID);
short GetFlightStatusID(Flight element);
void MakeStoresList(C_Window *win,long client);
void Uni_Float(_TCHAR *buffer);
void SetCurrentLoadout(void);

StoresList *gStores=NULL;

short g3dObjectID=0;
extern C_Handler *gMainHandler;
extern VU_ID gSelectedFlightID;
extern VU_ID gPlayerFlightID;	// Flight Player is in (NULL) if not in a flight
VU_ID gLoadoutFlightID=FalconNullId;
extern short FlightStatusID[];

OBJECTINFO Object;

// Loaded stores values
LoadoutStruct gCurStores[5];		// Last slot is the Starting list for the flight (set by kevin)
LoadoutStruct gOriginalStores[5];	// Last slot is the Starting list for the flight (set by kevin)
RailList      gCurRails[4];			// per AC... four max

long HardPoints; // number of valid hardpoints
static long Quantity     [4][2][HARDPOINT_MAX]; // Totals [Aircraft][0=Weapon ID,1=qty][#slots for different types (can't have more types than hardpoints)]
static long QuantityCount[4]; // # of Quantity slots used
long PlaneEditList[4]; // Planes to modify when selecting stores
long FirstPlane=0; // 1st plane to edit
long PlaneCount=4;

static long  _MAX_WEIGHT_[4];
static long  _CLEAN_WEIGHT_[4];
static float _DRAG_FACTOR_[4];
static long  _MUNITIONS_WEIGHT_[4];
static long  _FUEL_WEIGHT_[4];
static long  _CURRENT_WEIGHT_[4];
static long  RackFlag=-1;
static long  VisFlag=-1;
long gFlightOverloaded=0;

VehicleClassDataType *gVCPtr=NULL;
int gVehID=0;

static Tpoint objPos;
static Trotation objRot;
void PositandOrientSetData (float x, float y, float z, float pitch, float roll, float yaw,
                            Tpoint* simView, Trotation* viewRotation);

void TallyStores()
{
	int i,j,k,wid;

	for(i=0;i<PlaneCount;i++)
	{
		// Zero out all stores totals
		for(j=0;j<HARDPOINT_MAX;j++)
		{
			Quantity[i][0][j]=0;
			Quantity[i][1][j]=0;
		}
		QuantityCount[i]=0;
		for(j=1;j<HardPoints;j++)
		{
			// Tally stores Types
			wid=-1;
			for(k=0;k<QuantityCount[i];k++)
				if(Quantity[i][0][k] == gCurStores[i].WeaponID[j])
				{
					wid=k;
					break;
				}
			if(wid == -1)
			{
				wid=QuantityCount[i]++;
				Quantity[i][0][wid]=gCurStores[i].WeaponID[j];
			}

			Quantity[i][1][wid]+=gCurStores[i].WeaponCount[j];

		}
	}
}

void UpdateInventoryCount()
{
	STORESLIST *store;
	short i,j;

	for(i=0;i<PlaneCount;i++)
		for(j=0;j<HARDPOINT_MAX;j++)
		{
			if(Quantity[i][1][j] > 0)
			{
				store=gStores->Find(Quantity[i][0][j]);
				if(store)
					store->Stock+=Quantity[i][1][j];
			}
		}
}

short TotalAvailable(short weaponID)
{
	STORESLIST *store;
	short avail,onboard;
	short i,j;

	store=gStores->Find(weaponID);
	if(store)
	{
		avail=store->Stock;
		onboard=0;
		for(i=0;i<PlaneCount;i++)
			for(j=0;j<HARDPOINT_MAX;j++)
			{
				if(Quantity[i][0][j] == weaponID)
					onboard+=Quantity[i][1][j];
			}
		return(static_cast<short>(max(avail - onboard,0)));
	}
	return(0);
}

void PlaceLoadedWeapons(LoadoutStruct *loadout)
{
	STORESLIST *cur;
	long i,j,count;

	for(i=0;i<4;i++)
		if(PlaneEditList[i])
			memset(&gCurStores[i],0,sizeof(LoadoutStruct));

	TallyStores();

	for(i=0;i<4;i++)
		if(PlaneEditList[i])
		{
			for(j=1;j<HardPoints;j++)
			{
				cur=gStores->Find(loadout->WeaponID[j]);
				if(cur && loadout->WeaponCount[j])
				{
					count=loadout->WeaponCount[j];

					if(count > cur->HardPoint[j])
						count=cur->HardPoint[j];

					if(count > TotalAvailable(loadout->WeaponID[j]))
						count=TotalAvailable(loadout->WeaponID[j]);

					gCurStores[i].WeaponID[j]=(loadout->WeaponID[j]);
					gCurStores[i].WeaponCount[j]=static_cast<uchar>(count);
				}
			}
		}
	TallyStores();
}


static short LastCount[4][HARDPOINT_MAX];

ushort AttachBits[]=
{
	0x0000,
	0x0001,
	0x0003,
	0x0007,
	0x000f,
	0x001f,
	0x003f,
	0x007f,
	0x00ff,
	0x01ff,
	0x03ff,
	0x07ff,
	0x0fff,
	0x1fff,
	0x3fff,
	0x7fff,
	0xffff,
};

// 0=left,1=center,2=right
struct RackData
{
	short RackID[3];
};

// Consists of... NO_RACK,
RackData HeliRacks[]=
{
	{ 0,0,0 }, // No Rack
	{ VIS_HONERACK,VIS_HONERACK,VIS_HONERACK }, // Single
	{ VIS_HBIRACK,VIS_HBIRACK,VIS_HBIRACK }, // Double
	{ VIS_HTRIRACK,VIS_HTRIRACK,VIS_HTRIRACK }, // Tripple
	{ VIS_QUAD_RACK,VIS_QUAD_RACK,VIS_QUAD_RACK }, // Quad
	{ VIS_SIX_RACK,VIS_SIX_RACK,VIS_SIX_RACK }, // Fiver
	{ VIS_SIX_RACK,VIS_SIX_RACK,VIS_SIX_RACK }, // Sixer
};

RackData ACRacks[]=
{
	{ 0,0,0 }, // No Rack
	{ VIS_SINGLE_RACK,VIS_SINGLE_RACK,VIS_SINGLE_RACK }, // Single
	{ VIS_TRIPLE_RACK,VIS_BIRACK,VIS_RTRIRACK }, // Double
	{ VIS_TRIPLE_RACK,VIS_TRIPLE_RACK,VIS_RTRIRACK }, // Tripple
	{ VIS_SIX_RACK,VIS_SIX_RACK,VIS_SIX_RACK }, // Quad
	{ VIS_SIX_RACK,VIS_SIX_RACK,VIS_SIX_RACK }, // Fiver
	{ VIS_SIX_RACK,VIS_SIX_RACK,VIS_SIX_RACK }, // Sixer
};

RackData RocketRack[]=
{
	{ 0,0,0 }, // No Rack
	{ VIS_ONELAU3A,VIS_ONELAU3A,VIS_ONELAU3A }, // Single
	{ VIS_BILAU3A,VIS_BILAU3A,VIS_BILAU3A }, // Double
	{ VIS_TRILAU3A,VIS_TRILAU3A,VIS_TRILAU3A }, // Tripple
	{ 0,0,0 }, // Quad
	{ 0,0,0 }, // Fiver
	{ 0,0,0 }, // Sixer
};

RackData Hellfires[]=
{
	{ 0,0,0 }, // No Rack
	{ VIS_QUAD_RACK,VIS_QUAD_RACK,VIS_QUAD_RACK }, // Single
	{ VIS_QUAD_RACK,VIS_QUAD_RACK,VIS_QUAD_RACK }, // Double
	{ VIS_QUAD_RACK,VIS_QUAD_RACK,VIS_QUAD_RACK }, // Tripple
	{ VIS_QUAD_RACK,VIS_QUAD_RACK,VIS_QUAD_RACK }, // Quad
	{ 0,0,0 }, // Fiver
	{ 0,0,0 }, // Sixer
};

RackData Maverick[]=
{
	{ 0,0,0 }, // No Rack
	{ VIS_MAVRACK,VIS_MAVRACK,VIS_MAVRACK }, // Single
	{ VIS_MAVRACK,VIS_MAVRACK,VIS_MAVRACK }, // Double
	{ VIS_MAVRACK,VIS_MAVRACK,VIS_MAVRACK }, // Tripple
	{ 0,0,0 }, // Quad
	{ 0,0,0 }, // Fiver
	{ 0,0,0 }, // Sixer
};

short FindRackIndex(short visID)
{
	Falcon4EntityClassType* classPtr;
	int index;

	if(!visID)
		return(0);

	for(index=0;index < NumEntities;index++)
	{
		classPtr = &Falcon4ClassTable[index];
		if(classPtr->visType[0] == visID)
			return(index);
	}
	return(0);
}
void ConvertToIndex(RackData Rack[])
{
	short i,j;

	for(i=0;i<7;i++)
	{
		for(j=0;j<3;j++)
		{
			Rack[i].RackID[j]=FindRackIndex(Rack[i].RackID[j]);
		}
	}
}

static short Validated=0;
void ValidateRackData()
{
	if(Validated)
		return;

	ConvertToIndex(HeliRacks);
	ConvertToIndex(ACRacks);
	ConvertToIndex(RocketRack);
	ConvertToIndex(Hellfires);
	ConvertToIndex(Maverick);

	Validated=1;
}

BOOL GetRackAndWeapon(VehicleClassDataType* vc,short VehID,short WeaponIndex,short count,short hardpoint,short center,RailInfo *rail)
{
	Falcon4EntityClassType* classPtr,*weapClassPtr;
	long bitflag;
	short side;
	RackData *RackList;

	memset(rail,0,sizeof(RailInfo));
	if(!count)
		return(FALSE);

	classPtr = &Falcon4ClassTable[VehID];
	weapClassPtr = &Falcon4ClassTable[WeaponDataTable[WeaponIndex].Index];

	bitflag=1 << hardpoint;

	if(!vc || !classPtr || !weapClassPtr)
		return(FALSE);

	if(!(vc->VisibleFlags & bitflag))
		return(FALSE);

	if(hardpoint < center)
		side=0;
	else if(hardpoint > center)
		side=2;
	else
		side=1;

	if((weapClassPtr->vuClassData.classInfo_[VU_TYPE] == TYPE_ROCKET || weapClassPtr->vuClassData.classInfo_[VU_TYPE] == TYPE_LAUNCHER))
	{
		// Rocket POD... virtual weapons...ALWAYS get a rack
		rail->rackID=RocketRack[count].RackID[side];
		return(TRUE);
	}
	if(weapClassPtr->visType[0] == VIS_HELLFIRE)
	{
		RackList=Hellfires;
	}
	else if((weapClassPtr->visType[0] == VIS_AGM65B) || (weapClassPtr->visType[0] == VIS_AGM65D) || (weapClassPtr->visType[0] == VIS_AGM65G))
	{
		RackList=Maverick;
	}
	else if(classPtr->vuClassData.classInfo_[VU_TYPE] == TYPE_HELICOPTER) // if Helicopters... use their racks
	{
		RackList=HeliRacks;
	}
	else
	{
		RackList=ACRacks;
	}

	if(vc->RackFlags & bitflag) // Use a rack
	{
		if(RackList[count].RackID[side])
		{
			rail->rackID=RackList[count].RackID[side];
			rail->weaponID=WeaponDataTable[WeaponIndex].Index;
			rail->startBits=AttachBits[count];
			rail->currentBits=AttachBits[count];
		}
	}
	else
	{
		if(weapClassPtr->visType[0])
		{
			rail->weaponID=WeaponDataTable[WeaponIndex].Index;
			rail->startBits=AttachBits[1];
			rail->currentBits=AttachBits[1];
		}
	}
	return(TRUE);
}

void ClearHardPoint(long plane,long hardpoint,long,RailInfo *rail)
{
	BSPLIST *Plane;
	BSPLIST *Rack;
	BSPLIST *Weapon;
	short bits,i;

	Plane=gUIViewer->Find((plane << 24));
	if(Plane == NULL) return;

	if(rail->rackID)
	{
		Rack=gUIViewer->Find((plane << 24) + (hardpoint << 16));
		if(Rack)
		{
			if(rail->weaponID && rail->startBits)
			{
				bits=rail->startBits;
				i=0;
				while(bits)
				{
					if(bits & 1)
					{
						Weapon=gUIViewer->Find((plane << 24) + (hardpoint << 16) + (i+1));
						if(Weapon)
						{
							((DrawableBSP*)Rack->object)->DetachChild(((DrawableBSP*)Weapon->object),i);
							gUIViewer->Remove((plane << 24) + (hardpoint << 16) + (i+1));
						}
					}
					bits >>= 1;
					i++;
				}
			}
			((DrawableBSP*)Plane->object)->DetachChild(((DrawableBSP*)Rack->object),hardpoint-1);
			gUIViewer->Remove((plane << 24) + (hardpoint << 16));
			Rack=NULL;
		}
	}
	else if(rail->weaponID)
	{
		if(rail->startBits)
		{
			Weapon=gUIViewer->Find((plane << 24) + (hardpoint << 16) + 1);
			if(Weapon)
			{
				((DrawableBSP*)Plane->object)->DetachChild(((DrawableBSP*)Weapon->object),hardpoint-1);
				gUIViewer->Remove((plane << 24) + (hardpoint << 16) + 1);
			}
		}
	}
}

#if 0
void Check_HTS_Tirn(DrawableBSP *plane,LoadoutStruc *stores)
{
	short hts,tirn;

	hts=0;
	tirn=0;


	for(i=1;i<HardPoints;i++)
	{
		if(stors->WeaponCount[i])
		{
			weapClassPtr = &Falcon4ClassTable[WeaponDataTable[stores->WeaponID].Index];
			if(weapClassPtr)
			{
			}
		}
	}
}
#endif

void LoadHardPoint(long plane,long hardpoint,long,RailInfo *rail)
{
	Falcon4EntityClassType* rackPtr,*weapPtr;
	BSPLIST *Plane;
	BSPLIST *Rack;
	BSPLIST *Weapon;
	short bits,i;

	Plane=gUIViewer->Find((plane << 24));
	if(Plane == NULL) return;

//	if(g3dObjectID == VIS_F16C)
//		Check_HTS_Tirn((DrawableBSP*)Plane->object,&gCurStores[plane]);

	if(rail->rackID)
	{
		rackPtr=&Falcon4ClassTable[rail->rackID];
		Rack=gUIViewer->LoadBSP((plane << 24) + (hardpoint << 16),rackPtr->visType[0]);
		if(Rack)
		{
			((DrawableBSP*)Plane->object)->AttachChild(((DrawableBSP*)Rack->object),hardpoint-1);

			if(rail->weaponID && rail->startBits)
			{
				weapPtr=&Falcon4ClassTable[rail->weaponID];
				bits=rail->startBits;
				i=0;
				while(bits)
				{
					Weapon=gUIViewer->LoadBSP((plane << 24) + (hardpoint << 16) + (i+1),weapPtr->visType[0]);

⌨️ 快捷键说明

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