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

📄 flttohot.cpp

📁 空战游戏flacon源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
					myfile.writedata (buffer);
					myfile.writedata ("Type         Group\n");
					myfile.writedata ("ZZZZ\n\n");
				}
				break;
			case OPCODE_OBJECT:
				{
					flt_ObjectRecord *object;
					object = (flt_ObjectRecord *) rec;
					sprintf (buffer, "====\nObjectBead%d\nName         ", 
															tree -> counter);
					myfile.writedata (buffer);
					sprintf (buffer, "%s\n", object -> IDField);
					checkForLongID (tree);
					myfile.writedata (buffer);
					myfile.writedata ("Type         Object\n");
					sprintf (buffer,  "ID           %d\n", tree -> counter);
					myfile.writedata (buffer);
					myfile.writedata ("ZZZZ\n\n");
				}
				break;
			case OPCODE_BINARY_SEPARATING_PLANE:
				{
					flt_BinarySeparatingPlane *bsp;
					bsp = (flt_BinarySeparatingPlane *) rec;
					sprintf (buffer, "====\nBSPBead%d\nName         ", 
															tree -> counter);
					myfile.writedata (buffer);
					sprintf (buffer, "%s\n", bsp -> IDField);
					checkForLongID (tree);
					myfile.writedata (buffer);
					myfile.writedata ("Type         BSP\n");
					myfile.writedata ("Plane        ");

// BSP BUG in v1510, a is stored in b, b in c, c in d, and no d value! 
					if (fltversion == 1510)
						sprintf (buffer, "%f %f %f %f\n", 
									bsp -> b, -bsp -> d, bsp -> c, -bsp -> a);
					else
						sprintf (buffer, "%f %f %f %f\n", 
									bsp -> a, -bsp -> c, bsp -> b, -bsp -> d);
					myfile.writedata (buffer);
					myfile.writedata ("ZZZZ\n\n");
				}
				break;
			case OPCODE_BOUNDING_BOX:
				{
					flt_BoundingBoxRecord *box;
					box = (flt_BoundingBoxRecord *) rec;
					sprintf (buffer, "====\nBoundingBoxBead%d\nName         ", 
															tree -> counter);
					myfile.writedata (buffer);
					myfile.writedata ("noname\n");
					myfile.writedata ("Type         Box\n");
					sprintf (buffer,  "Minimum      %f %f %f\n", 
											box -> minx, -box -> minz, box -> miny);
					myfile.writedata (buffer);
					sprintf (buffer,  "Maximum      %f %f %f\n", 
											box -> maxx, -box -> maxz, box -> maxy);
					myfile.writedata (buffer);
					myfile.writedata ("ZZZZ\n\n");
				}
				break;
			case OPCODE_BOUNDING_SPHERE:
				{
					flt_BoundingSphereRecord *sphere;
					sphere = (flt_BoundingSphereRecord *) rec;
					sprintf (buffer, "====\nBoundingSphereBead%d\nName         ", 
															tree -> counter);
					myfile.writedata (buffer);
					myfile.writedata ("noname\n");
					myfile.writedata ("Type         Sphere\n");
					sprintf (buffer,  "Radius       %f\n", sphere -> radius);
					myfile.writedata (buffer);
					myfile.writedata ("ZZZZ\n\n");
				}
				break;
			case OPCODE_POLYGON:
				{
					if (fltversion > 1500) {//== 1520) {
						aflt_PolygonRecord *poly;
						poly = (aflt_PolygonRecord *) rec;
						sprintf (buffer, "====\nPolygonBead%d\nName         ",
															tree -> counter);
						myfile.writedata (buffer);
						sprintf (buffer, "%s\n", poly -> IDField);
						int i = checkForLongID (tree);
						myfile.writedata (buffer);
						if (polynameList.InNameList (buffer))
							myfile.writedata ("Type         Information\n");
						else
							myfile.writedata ("Type         Polygon\n");

						treePtr *curtree;
						if (i) curtree = tree -> next -> child;
						else curtree = tree -> child;
						if (curtree) {
							aflt_VertexList *vtx;
							vtx = (aflt_VertexList *) curtree -> record;
							if (vtx -> Opcode == OPCODE_VERTEX_LIST) {
								int numvtx = (vtx -> recordLen-4)/4;
								sprintf (buffer, "VertexList   %d", numvtx);
								myfile.writedata (buffer);
								int	i;
								for (i=0;i < numvtx;i++) {
									sprintf (buffer, " %d", 
												findVertexNo (vtx -> offset[i]));
									myfile.writedata (buffer);
								}
								myfile.writedata ("\n");
							}
							else {
								puts ("Error! Can not find VertexList record");
							}
						}
						if (poly -> materialCode == -1) {
							int	colindex = poly -> primaryColor >> 7;
							int polycolor = getColorFromTable (colindex);
							int	colintensity = poly -> primaryColor & 0x7f;
							polycolor = convertColor (polycolor, colintensity);
							sprintf (buffer, "Color        %d %d %d %d\n", 
									polycolor & 0xff, (polycolor >> 8) & 0xff, 
									(polycolor >> 16) & 0xff, (polycolor >> 24) & 0xff);
							myfile.writedata (buffer);
							if (poly -> transparency) {
								sprintf (buffer,     "Transparency %d\n", poly -> transparency&0xffff);
								myfile.writedata (buffer);
							}
						}
						else {
							rgbaRecord color;
							getMaterialFromTable (&color, poly -> materialCode);
							sprintf (buffer, "Color        %d %d %d 255\n", color.r, color.g, color.b);
							myfile.writedata (buffer);
							if (color.a) {
								sprintf (buffer,     "Transparency %d\n", color.a);
								myfile.writedata (buffer);
							}
						}
						sprintf (buffer, "ObjectID     %d\n", tree -> objectid);
						myfile.writedata (buffer);
						if (usetextureflag) {
							if (poly -> textureNo >= 0) {
								sprintf (buffer, "TextureNo    %d ", poly -> textureNo);
								myfile.writedata (buffer);
								if (poly -> templateTransparency & 7) // chromakey texture?
									myfile.writedata ("1\n");
								else myfile.writedata ("0\n");
							}
						}
						if (!(poly -> lightMode & 2)) {
						// might be undefined when poly is using material
							myfile.writedata ("NoShading\n");
						}
						if (poly -> howToDraw == 1) {
							myfile.writedata ("TwoSided\n");
						}
						else if (poly -> howToDraw == 3) {
							myfile.writedata ("Wireframe\n");
						}
						if (poly -> templateTransparency & 4) {			// == 5
							myfile.writedata ("Billboard\n");
						}
						else if (poly -> templateTransparency & 2) {	// == 3
							myfile.writedata ("Tree\n");
						}
						if (tree -> subface) {
							sprintf (buffer, "Subface      BeadList%d\n", tree -> subface -> beadcounter);
							myfile.writedata (buffer);
						}
						myfile.writedata ("ZZZZ\n\n");
					}
					else {
						flt_PolygonRecord *poly;
						poly = (flt_PolygonRecord *) rec;
						sprintf (buffer, "====\nPolygonBead%d\nName         ",
															tree -> counter);
						myfile.writedata (buffer);
						sprintf (buffer, "%s\n", poly -> IDField);
						int i = checkForLongID (tree);
						myfile.writedata (buffer);
						if (polynameList.InNameList (buffer))
							myfile.writedata ("Type         Information\n");
						else
							myfile.writedata ("Type         Polygon\n");

						treePtr *curtree;
						if (i) curtree = tree -> next -> child;
						else curtree = tree -> child;
						if (curtree) {
							flt_VertexList *vtx;
							vtx = (flt_VertexList *) curtree -> record;
							if (vtx -> Opcode == OPCODE_VERTEX_LIST) {
								int numvtx = (vtx -> recordLen-4)/4;
								sprintf (buffer, "VertexList   %d", numvtx);
								myfile.writedata (buffer);
								int	i;
								for (i=0;i < numvtx;i++) {
									sprintf (buffer, " %d", 
												findVertexNo (vtx -> offset[i]));
									myfile.writedata (buffer);
								}
								myfile.writedata ("\n");
							}
							else {
								puts ("Error! Can not find VertexList record");
							}
						}
						if (poly -> materialCode == -1) {
							int	colindex = poly -> primaryColor >> 7;
							int polycolor = getColorFromTable (colindex);
							int	colintensity = poly -> primaryColor & 0x7f;
							polycolor = convertColor (polycolor, colintensity);
							sprintf (buffer, "Color        %d %d %d %d\n", 
									polycolor & 0xff, (polycolor >> 8) & 0xff, 
									(polycolor >> 16) & 0xff, (polycolor >> 24) & 0xff);
							myfile.writedata (buffer);
							if (poly -> transparency) {
								sprintf (buffer,     "Transparency %d\n", poly -> transparency&0xffff);
								myfile.writedata (buffer);
							}
						}
						else {
							rgbaRecord color;
							getMaterialFromTable (&color, poly -> materialCode);
							sprintf (buffer, "Color        %d %d %d 255\n", color.r, color.g, color.b);
							myfile.writedata (buffer);
							if (color.a) {
								sprintf (buffer,     "Transparency %d\n", color.a);
								myfile.writedata (buffer);
							}
						}
						sprintf (buffer, "ObjectID     %d\n", tree -> objectid);
						myfile.writedata (buffer);
						if (usetextureflag) {
							if (poly -> textureNo >= 0) {
								sprintf (buffer, "TextureNo    %d ", poly -> textureNo);
								myfile.writedata (buffer);
								if (poly -> templateTransparency & 7) // chromakey texture?
									myfile.writedata ("1\n");
								else myfile.writedata ("0\n");
							}
						}
						if (!(poly -> lightMode & 2)) {
						// might be undefined when poly is using material
							myfile.writedata ("NoShading\n");
						}
						if (poly -> howToDraw == 1) {
							myfile.writedata ("TwoSided\n");
						}
						else if (poly -> howToDraw == 3) {
							myfile.writedata ("Wireframe\n");
						}
						if (poly -> templateTransparency & 4) {			// == 5
							myfile.writedata ("Billboard\n");
						}
						else if (poly -> templateTransparency & 2) {	// == 3
							myfile.writedata ("Tree\n");
						}
						if (tree -> subface) {
							sprintf (buffer, "Subface      BeadList%d\n", tree -> subface -> beadcounter);
							myfile.writedata (buffer);
						}
						myfile.writedata ("ZZZZ\n\n");
					}
				}
				break;
			case OPCODE_TRANSFORMATION_MATRIX:
				flt_TransformationMatrixRecord *mat = (flt_TransformationMatrixRecord *) rec;
				sprintf (buffer, "====\nMatrixBead%d\nName         noname\n", 
												tree -> counter);
				myfile.writedata (buffer);
				myfile.writedata ("Type         Matrix\n");
				sprintf (buffer,  "Element      %f %f %f %f\n",
//					mat -> matrix[0],-mat -> matrix[2],mat -> matrix[1],mat -> matrix[3]);
					mat -> matrix[5],mat -> matrix[4],-mat -> matrix[6],mat -> matrix[7]);
				myfile.writedata (buffer);
				sprintf (buffer,  "             %f %f %f %f\n",
//					-mat -> matrix[8],mat -> matrix[10],-mat -> matrix[9],-mat -> matrix[11]);
					mat -> matrix[1],mat -> matrix[0],-mat -> matrix[2],mat -> matrix[3]);
				myfile.writedata (buffer);
				sprintf (buffer,  "             %f %f %f %f\n",
//					mat -> matrix[4],-mat -> matrix[6],mat -> matrix[5],mat -> matrix[7]);
					-mat -> matrix[9],-mat -> matrix[8],mat -> matrix[10],-mat -> matrix[11]);
				myfile.writedata (buffer);
				sprintf (buffer,  "             %f %f %f %f\n",
					mat -> matrix[12],-mat -> matrix[14],mat -> matrix[13],mat -> matrix[15]);
				myfile.writedata (buffer);
				myfile.writedata ("ZZZZ\n\n");
				break;
		}
		processBeadElement (myfile, tree -> child);
		processBeadElement (myfile, tree -> next);
		processBeadElement (myfile, tree -> subface);
	}
}

int convertColor (int color, int intensity)
{
	int	r, g, b, a;

	r = color & 0xff;
	g = (color >> 8) & 0xff;
	b = (color >> 16) & 0xff;
	a = (color >> 24) & 0xff;

	r = (r * intensity) / 127;
	g = ((g * intensity) / 127) << 8;
	b = ((b * intensity) / 127) << 16;
	a = ((a * intensity) / 127) << 24;

	a = 0xff000000;		// ignored alpha blend value

	return r+g+b+a;
}

int checkForLongID (treePtr *tree)
{
	if (tree -> next) {
		short *srec = (short *) tree -> next -> record;
		short rectype = *srec;
		if (rectype == OPCODE_LONG_IDENTIFIER) {
			flt_LongIDRecord *longid;
			longid = (flt_LongIDRecord *) tree -> next -> record;
			sprintf (buffer, "%s\n", longid -> id);
			return 1;
		}
	}
	return 0;
}

int saveRecordHeader (CFileIO& myfile, char *rec)
{
	unsigned int colindex, colintensity, vertexcolor;
	short *srec = (short *) rec;
	short rectype = *srec++;
	short reclen = *srec++;

	switch (rectype) {
		case OPCODE_HEADER:
			{
				flt_HeaderRecord *header;
				header = (flt_HeaderRecord *) rec;
				myfile.writedata (header -> IDField);
				sprintf (buffer,  "\nFormat revision level = %d\n", header -> formatRev);
				myfile.writedata (buffer);
				sprintf (buffer,  "Database revision level = %d\n", header -> DBRev);
				myfile.writedata (buffer);
				myfile.writedata (" created on ");
				myfile.writedata (header -> dateRev);
				myfile.writedata ("\n\n====\nHeaderBead\n");
				myfile.writedata (    "VertexPool       VerticesList\n");
				if (usetextureflag) 
					myfile.writedata ("TexturePool      TextureList\n");
				myfile.writedata (    "Bead             BeadList0\n");
				if (ansfile[0]) {
					sprintf (buffer,  "Animation        %s\n", ansfile);
					myfile.writedata (buffer);
				}
				if (colorpatch[0]) {
					sprintf (buffer,  "PatchColor       %s\n", colorpatch);
					myfile.writedata (buffer);
				}
				if (dynamicvertex[0]) {
					sprintf (buffer,  "DynamicVertex    %s\n", dynamicvertex);
					myfile.writedata (buffer);
				}
				if (ScaleFactor != (GLfloat) 1.0) {
					sprintf (buffer,  "Scale            %f\n", ScaleFactor);
					myfile.writedata (buffer);
				}
				sprintf (buffer,      "TSetTotal        %d\n", tSetTotal);
				myfile.writedata (buffer);
				if (DisableMask) {
					sprintf (buffer,  "DisableMask      0x%08x\n", DisableMask);
					myfile.writedata (buffer);
				}
				myfile.writedata ("ZZZZ\n\n");
				if (DisableMask) {
					myfile.writedata ("DisableMask bits:\n");
					myfile.writedata ("0x01000000 --> disable shading\n");
					myfile.writedata ("0x02000000 --> disable smooth shading\n");
					myfile.writedata ("0x04000000 --> disable texture\n");
					myfile.writedata ("0x08000000 --> disable transparent texture (chromakey)\n");
					myfile.writedata ("0x10000000 --> disable alpha blend\n");
					myfile.writedata ("0x20000000 --> disable gouraud (vertex color)\n");
					myfile.writedata ("0x40000000 --> always enable perspective texture\n");
					myfile.writedata ("0x80000000 --> always enable texture\n\n\n");
				}
			}
			break;
		case OPCODE_TEXTURE_REFERENCE_RECORD:
			{
				flt_TexturePatternRecord *tex;
				tex = (flt_TexturePatternRecord *) rec;

				if (!(startflag & 2)) {
					if (startflag & 1) {
						myfile.writedata ("ZZZZ\n\n");
						startflag &= ~1;
					}
					myfile.writedata ("====\nTextureList\n");
					startflag |= 2;
				}
//				sprintf (buffer,  "TextureNum   %d\n", textureno++);
//				myfile.writedata (buffer);
				int i = getUnixFilename (tex -> filename);
				sprintf (buffer,  "Name         %s\n", &(tex -> filename[i]));
				myfile.writedata (buffer);
				sprintf (buffer,  "PatternID    %d\n", tex -> patternIndex);
				myfile.writedata (buffer);
//				sprintf (buffer,  "Offset       %d\t%d\n", 
//												tex -> xloc, tex -> yloc);
//				myfile.writedata (buffer);
//				myfile.writedata ("TextureType  0\n");	// if 1 --> texture is chromakey
			}
			break;
		case OPCODE_SHARED_VERTEX_TABLE:
			{
				if (startflag & 2) {
					myfile.writedata ("ZZZZ\n\n");
					startflag &= ~2;
				}
				myfile.writedata ("====\nVerticesList\n");
				startflag |= 1;

				flt_SharedVertex *vtx;
				vtx = (flt_SharedVertex *) rec;
				vertexOffset += vtx -> recordLen;
			}
			break;
		case OPCODE_VERTEX_COORDINATE:
			{
				if (fltversion > 1500) {//== 1520) {
					aflt_VertexCoordinate *vtx;
					vtx = (aflt_VertexCoordinate *) rec;

⌨️ 快捷键说明

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