Example #1
0
void search_id()
{
    int flag=0;
    char lkf[20];
    clrscr();
    ptr=fopen("shop.dat","rb");
    design();
    gotoxy(13,4);
    printf("\xDB\xDB\xB2  Enter id to be searched:");
    scanf("%s",&lkf);
    while((!flag)&&(fread(&temp,sizeof(temp),1,ptr))==1)
    {
        if(strcmp(temp.id,lkf)==0)
            flag=1;
    }
    if(flag)
    {


        gotoxy(18,6);
        printf("Product ID   :  %s",temp.id);
        gotoxy(18,8);
        printf("Description  :  %s",temp.desc);
        gotoxy(18,10);
        printf("Rack no      :  %d",temp.rack);
        gotoxy(18,12);
        printf("Cabnit       :  %d",temp.cabnit);
        gotoxy(18,14);
        printf("Sale price   :$ %.2f",temp.sale);
        gotoxy(18,16);
        printf("Quantity     :  %d",temp.quantity);
        gotoxy(16,17);
        printf("============================");
        gotoxy(18,19);
        printf(" Total       :$ %.2f",temp.total);


    }
    else
        printf("Record not found!");
    fclose(ptr);
}
Example #2
0
/****************   class Vgui  ******************/
Vgui::Vgui()
{
     design();
}
Example #3
0
//---------------------------------------------------------
bool CResection::On_Execute(void)
{

	CSG_PointCloud			*pPoints;									// Input Point Cloud
	CSG_String				fileName;
	CSG_File				*pTabStream = NULL;
	int n					= 6;										// Number of unknowns
	CSG_Vector center(3);
	CSG_Vector target(3);

	double c			= Parameters("F")			->asDouble();		// Focal Length (mm)
	double pixWmm		= Parameters("W")			->asDouble() / 1000;// Pixel Width (mm)
	double ppOffsetX	= Parameters("ppX")			->asDouble();		// Principal Point Offset X (pixels)
	double ppOffsetY	= Parameters("ppY")			->asDouble();		// Principal Point Offset Y (pixels)
	pPoints				= Parameters("POINTS")		->asPointCloud();
	fileName			= Parameters("OUTPUT FILE")	->asString();
	center[0]			= Parameters("Xc")			->asDouble();
	center[1]			= Parameters("Yc")			->asDouble();
	center[2]			= Parameters("Zc")			->asDouble();
	target[0]			= Parameters("Xt")			->asDouble();
	target[1]			= Parameters("Yt")			->asDouble();
	target[2]			= Parameters("Zt")			->asDouble();

	int pointCount = pPoints->Get_Point_Count();

	bool estPPOffsets = false;

	if ( Parameters("EST_OFFSETS")->asBool() ) {

		estPPOffsets = true;
		n = 8;															// Increase number of unknowns by 2
	}

	bool applyDistortions = false;
	CSG_Vector K(3);

	if ( Parameters("GIVE_DISTORTIONS")->asBool() ) {

		applyDistortions = true;
		K[0]			= Parameters("K1")			->asDouble();
		K[1]			= Parameters("K2")			->asDouble();
		K[2]			= Parameters("K3")			->asDouble();

	}

	double dxapp = center [0] - target [0];
	double dyapp = center [1] - target [1];
	double dzapp = center [2] - target [2];
	double h_d	= sqrt (dxapp * dxapp + dyapp * dyapp + dzapp * dzapp);	// Distance between Proj. Center & Target (m)
	double h_dmm = h_d * 1000;											// Convert to mm

	if( fileName.Length() == 0 )
	{
		SG_UI_Msg_Add_Error(_TL("Please provide an output file name!"));
		return( false );
	}

	pTabStream = new CSG_File();

	if( !pTabStream->Open(fileName, SG_FILE_W, false) )
	{
		SG_UI_Msg_Add_Error(CSG_String::Format(_TL("Unable to open output file %s!"), fileName.c_str()));
		delete (pTabStream);
		return (false);
	}


	CSG_Vector rotns = methods::calcRotations(center,target);			// Approx. rotations omega, kappa, alpha

	CSG_String msg = "********* Initial Approximate Values *********";
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);

	msg = SG_T("Rotation Angles:");
	pTabStream->Write(SG_T("\n") + msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);

	msg = SG_T("Omega:\t") + SG_Get_String(rotns[0],6,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);
	msg = SG_T("Kappa:\t") + SG_Get_String(rotns[1],6,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);
	msg = SG_T("Alpha:\t") + SG_Get_String(rotns[2],6,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);

	msg = SG_T("Projection Center:");
	pTabStream->Write(SG_T("\n") + msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);

	msg = SG_T("Xc:\t") + SG_Get_String(center[0],4,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);
	msg = SG_T("Yc:\t") + SG_Get_String(center[1],4,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);
	msg = SG_T("Zc:\t") + SG_Get_String(center[2],4,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);
	
	if (estPPOffsets) {

		msg = SG_T("Principal Point Offsets:");
		pTabStream->Write(SG_T("\n") + msg + SG_T("\n"));
		SG_UI_Msg_Add(msg, true);

		msg = SG_T("ppX:\t") + SG_Get_String(ppOffsetX,5,false);
		pTabStream->Write(msg + SG_T("\n"));
		SG_UI_Msg_Add(msg, true);
		msg = SG_T("ppY:\t") + SG_Get_String(ppOffsetY,5,false);
		pTabStream->Write(msg + SG_T("\n"));
		SG_UI_Msg_Add(msg, true);

	}

	double itrNo = 0;
	CSG_Matrix invN;
	
	while (true) {													// Begin Iterations

		itrNo++;
		
		double omega = rotns[0];
		double kappa = rotns[1];
		double alpha = rotns[2];

		CSG_Matrix R = methods::calcRotnMatrix(rotns);				// Rotation Matrix from approximate values
		CSG_Matrix E(3,3);											// [w1;w2;w3] = E * [dw;dk;da]

		E[0][0] = -1;
		E[0][1] = E[1][0] = E[2][0] = 0;
		E[0][2] = sin(kappa);
		E[1][1] = -cos(omega);
		E[1][2] = -sin(omega) * cos(kappa);
		E[2][1] = sin(omega);
		E[2][2] = -cos(omega) * cos(kappa);

		CSG_Matrix N(n,n);											// Transpose(Design Matrix) * I * Design Matrix
		CSG_Vector ATL(n);											// Transpose(Design Matrix) * I * Shortened obs. vector

		double SS = 0;
		double sigma_naught = 0;
		
		for (int i = 0; i < pointCount; i++) {
			
			CSG_Vector pqs(3);										// Approx. pi, qi, si

			for (int j = 0; j < 3; j++) {
				pqs[j] = R[j][0] * (pPoints->Get_X(i) - center[0]) +
						 R[j][1] * (pPoints->Get_Y(i) - center[1]) +
						 R[j][2] * (pPoints->Get_Z(i) - center[2]);
			}

			double p_i = pqs[0];
			double q_i = pqs[1];
			double s_i = pqs[2];

			double dR =  0;
			
			// Undistorted
			double x_u = c * p_i / q_i;
			double y_u = c * s_i / q_i;
			
			double c_hat = c;
			
			if (applyDistortions) {
				double r2 = x_u * x_u + y_u * y_u;
				dR =  K[0] * r2 + K[1] * r2 * r2 + K[2] * r2 * r2 * r2;
				c_hat = c * (1 - dR);
			}

			// Approx. image coordinates (with distortions)
			double x_i = (1 - dR) * x_u + ppOffsetX * pixWmm;
			double z_i = (1 - dR) * y_u + ppOffsetY * pixWmm;

			// Shortened obervation vector: dxi & dzi
			double dx_i = pPoints->Get_Attribute(i,0) * pixWmm - x_i;
			double dz_i = pPoints->Get_Attribute(i,1) * pixWmm - z_i;
			SS += pow(dx_i,2) + pow(dz_i,2);

			/*
				x_i, z_i in [mm]
				p_i,q_i,s_i in [m]
				h_d in [m]
				c, c_hat in [mm]
				h_dmm in [mm]
			*/
			CSG_Matrix L(3,2);										// CSG_Matrix takes columns first and rows second
			CSG_Matrix V(3,3);
			CSG_Matrix LR(3,2);
			CSG_Matrix LVE(3,2);

			L[0][0] = L[1][2] = c_hat / (1000 * q_i);
			L[0][2] = L[1][0] = 0;
			L[0][1] = -x_u * (1 - dR) / (1000 * q_i);
			L[1][1] = -y_u * (1 - dR) / (1000 * q_i);

			V[0][0] = V[1][1] = V[2][2] = 0;
			V[0][1] =  s_i / h_d;
			V[0][2] = -q_i / h_d;
			V[1][0] = -s_i / h_d;
			V[1][2] =  p_i / h_d;
			V[2][0] =  q_i / h_d;
			V[2][1] = -p_i / h_d;

			LVE = ( L * V ) * E;
			LR = L * R;

			// Design Matrix (J)
			CSG_Matrix design(n,2);

			for(int j = 0; j < 2; j++) {
				for(int k = 0; k < 3; k++) {
					design[j][k] = LVE[j][k];
					design[j][k+3] = -LR[j][k];
				}
			}

			if ( estPPOffsets ) {
				design[0][6] = design[1][7] = 1.0;
			}

			// Build Normal Matrix
			for(int j = 0; j < n; j++) {
				for(int k = 0; k < n; k++) {
					N[j][k] += (design[0][j] * design[0][k] + design[1][j] * design[1][k]);
				}
			}

			// Build Tranpose (J) * I * (Shortened obs. vector)
			for (int m=0; m < n; m++) {
				ATL[m] += design[0][m] * dx_i + design[1][m] * dz_i;
			}

			L.Destroy();
			V.Destroy();
			LR.Destroy();
			LVE.Destroy();
			pqs.Destroy();
			design.Destroy();

		} // end looping over observations

		// Eigen values and Eigen Vectors
		CSG_Vector eigenVals(n);
		CSG_Matrix eigenVecs(n,n);
		SG_Matrix_Eigen_Reduction(N, eigenVecs, eigenVals, true);

		// One of the Eigen Values is 0
		if (std::any_of(eigenVals.cbegin(),
		                eigenVals.cend(),
		                [] (double i) { return i == 0; })) {
			msg = "The Normal Matrix has a rank defect. Please measure more points.";
			pTabStream->Write(msg + SG_T("\n"));
			SG_UI_Msg_Add(msg, true);
			break;
		}

		double mx = *std::max_element(eigenVals.cbegin(), eigenVals.cend());
		double mn = *std::min_element(eigenVals.cbegin(), eigenVals.cend());

		// Ratio of Smallest to the Biggest Eigen value is too small
		if ((mn / mx) < pow(10,-12.0)) {
			msg = SG_T("Condition of the Matrix of Normal Equations:\t") + CSG_String::Format(SG_T("  %13.5e"), mn/mx);
			pTabStream->Write(msg + SG_T("\n"));
			SG_UI_Msg_Add(msg, true);
			msg = "The Normal Matrix is weakly conditioned. Please measure more points.";
			pTabStream->Write(msg + SG_T("\n"));
			SG_UI_Msg_Add(msg, true);
			break;
		}

		// Calculate the adjustments
		double absMax = 0;
		invN = N.Get_Inverse();
		CSG_Vector est_param_incs = invN * ATL;

		for (int i = 0; i < n; i++) {
			if (abs(est_param_incs[i]) > absMax) {
				absMax = abs(est_param_incs[i]);
			}
		}

		if (absMax < thresh) {
			msg = "Solution has converged.";
			pTabStream->Write(SG_T("\n") + msg + SG_T("\n"));
			SG_UI_Msg_Add(msg, true);
			break;
		}

		for (int a = 0; a < 3; a++) {
			rotns[a] += est_param_incs[a] / h_dmm;								// New Approx. rotations omega, kappa, alpha
			center[a] += est_param_incs[a+3] / 1000;							// New Approx. Projection Center
		}

		if ( estPPOffsets ) {
			ppOffsetX += (est_param_incs[6] / pixWmm);							// New Approx. Principal Point
			ppOffsetY += (est_param_incs[7] / pixWmm);
		}

		sigma_naught = sqrt(SS / (2 * pointCount - n));

		// Writing To Output File & SAGA Console
		msg = "********* Iteration: " + SG_Get_String(itrNo,0,false) + " *********";
		pTabStream->Write(SG_T("\n") + msg + SG_T("\n"));
		SG_UI_Msg_Add(msg, true);

		msg = "Sum of Squared Residuals:\t" + SG_Get_String(SS,5,false);
		pTabStream->Write(SG_T("\n") + msg + SG_T("\n"));
		SG_UI_Msg_Add(msg, true);
		
		msg = "Sigma Naught:\t" + SG_Get_String(sigma_naught,5,false);
		pTabStream->Write(msg + SG_T("\n"));
		SG_UI_Msg_Add(msg, true);
		
		msg = SG_T("Condition of the Matrix of Normal Equations:\t") + CSG_String::Format(SG_T("  %13.5e"), mn/mx);
		pTabStream->Write(msg + SG_T("\n"));
		SG_UI_Msg_Add(msg, true);
		
		R.Destroy();
		E.Destroy();
		N.Destroy();
		ATL.Destroy();
		invN.Destroy();
		eigenVals.Destroy();
		eigenVecs.Destroy();
		est_param_incs.Destroy();

	} // end of iterations

	msg = "********* Final Estimated Parameters *********";
	pTabStream->Write(SG_T("\n") + msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);

	msg = SG_T("Rotation Angles:");
	pTabStream->Write(SG_T("\n") + msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);

	msg = SG_T("Omega:\t") + SG_Get_String(rotns[0],6,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);
	msg = SG_T("Kappa:\t") + SG_Get_String(rotns[1],6,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);
	msg = SG_T("Alpha:\t") + SG_Get_String(rotns[2],6,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);

	msg = SG_T("Projection Center:");
	pTabStream->Write(SG_T("\n") + msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);

	msg = SG_T("Xc:\t") + SG_Get_String(center[0],4,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);
	msg = SG_T("Yc:\t") + SG_Get_String(center[1],4,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);
	msg = SG_T("Zc:\t") + SG_Get_String(center[2],4,false);
	pTabStream->Write(msg + SG_T("\n"));
	SG_UI_Msg_Add(msg, true);

	if (estPPOffsets) {

		msg = SG_T("Principal Point Offsets:");
		pTabStream->Write(SG_T("\n") + msg + SG_T("\n"));
		SG_UI_Msg_Add(msg, true);

		msg = SG_T("ppX:\t") + SG_Get_String(ppOffsetX,5,false);
		pTabStream->Write(msg + SG_T("\n"));
		SG_UI_Msg_Add(msg, true);
		msg = SG_T("ppY:\t") + SG_Get_String(ppOffsetY,5,false);
		pTabStream->Write(msg + SG_T("\n"));
		SG_UI_Msg_Add(msg, true);

	}


	K.Destroy();
	rotns.Destroy();
	center.Destroy();
	target.Destroy();

	pTabStream->Close();
	
	return true;
}
Example #4
0
 menu()
{
 int x;
  do{
       {
	clrscr();
	design();
	t();
	textcolor(WHITE);
	gotoxy(24,3);
	cprintf("\xDB\xDB\xDB\xDB\xB2  SAM'S DEPARTMANTAL STORE  \xB2\xDB\xDB\xDB\xDB");
	gotoxy(3,4);
	cprintf("--------------------------------------------------------------------------");
	gotoxy(35,5);
	cprintf("MAIN MENU");
	gotoxy(26,8);
	cprintf(" 1  -   INFORMATION ABOUT PRODUCTS            ");
	gotoxy(26,9);
	cprintf(" 2  -   ENTER  PURCHASE  RECORDS            ");
	gotoxy(26,10);
	cprintf(" 3  -   ENTER PRODUCTS TO BE SALE           ");
	gotoxy(26,11);
	cprintf(" 4  -   SEARCH FOR RECORD                     ");
	gotoxy(26,12);
	cprintf(" 5  -   DELETE RECORD FROM STORE DATABASE     ");
	gotoxy(26,13);
	cprintf(" 6  -   VIEW SALES , PURCHASE & PROFIT REPORT ");
	gotoxy(26,14);
	cprintf(" 7  -   PRINT RECORDS                         ");
	gotoxy(26,15);
	cprintf(" 8  -   BAR  GRAPH OF QUANTITY / PROFIT       ");
	gotoxy(26,16);
	cprintf(" 9  -   RETRIEVE INFORMATION         ");
	gotoxy(26,17);
	cprintf(" H  -   HELP                                  ");
	gotoxy(26,18);
	cprintf(" E  -   EXIT                                  ");
	gotoxy(26,23);
	cprintf("ENTER YOUR CHOICE :: ");
	gotoxy(47,23);
	x=toupper(getch());
	switch(x)
	{
	case '1':
	infor();
	break;

	case '2':
	entry();
	break;

	case '3':
	edit();
	break;

	case '4':
	search();
	break;

	case '5':
	del();
	break;

	case '6':
	report2();
	break;

	case '7':
	print();
	break;

	case 'h': case'H':
	help();
	break;

	case'8':
	graph1();
	break;

	case '9':
	display();
	break;

	case 'e': case 'E':
	exit(0);
	break;

	default:
	clrscr();
	design();
	gotoxy(17,12);
	printf("\a\xDB\xB2  WRONG ENTRY : PRESS ANY KEY AND TRY AGAIN");
	getche();
	}
      }
    }while((x!='e')||(x!='E'));
return x;
}
Example #5
0
void entry()
{
   char ch;
  clrscr();

	   ptr=fopen("shop.dat","a+b");
  ch='y';
  while(ch=='y')
 {
  clrscr();
  design();
  textcolor(14);
  t();
  gotoxy(14,3);
  cprintf("\xDB\xDB\xDB\xDB\xDB\xB2  PURSHASE  \xB2\xDB\xDB\xDB\xDB\xDB ");
   {


     gotoxy(7,5);
    cprintf("\xDB\xDB\xB2  ENTER PRODUCT ID  : ");
     ventry(temp.id,1);
     flushall();
     gotoxy(7,7);
     cprintf("\xDB\xDB\xB2  ENTER DESCRIPTION : ");
     ventry(temp.desc,0);
     flushall();
    gotoxy(7,9);
     cprintf("\xDB\xDB\xB2  ENTER RACK NO     : ");
     ventry(a,1);
    temp.rack= atoi(a);

     flushall();
     gotoxy(7,11);
     cprintf("\xDB\xDB\xB2  ENTER CABNIT NO   : ");
     ventry(a,1);
    temp.cabnit= atoi(a);

    flushall();
    gotoxy(7,13);
     cprintf("\xDB\xDB\xB2  ENTER UNIT COST  :$ ");
     ventry(a,1);
    temp.unit= atof(a);
     flushall();

     gotoxy(7,15);
     cprintf("\xDB\xDB\xB2  ENTER SALE PRICE :$ ");
     ventry(a,1);
    temp.sale= atof(a);
     flushall();

     gotoxy(7,17);
     cprintf("\xDB\xDB\xB2  ENTER  QUANTITY  :  ");
     ventry(a,1);
    temp.quantity= atoi(a);
     flushall();

     gotoxy(7,18);
     cprintf("=====================================");
     temp.total=temp.quantity*temp.sale;

     textcolor(10);
     gotoxy(10,20);
     cprintf("\xB2\xDB\xB2  TOTAL PRICE = $ %.2f",temp.total);
     temp.cost=(temp.unit*temp.quantity);
     gotoxy(40,20);
     cprintf("\xDB\xB2  TOTAL COST = $ %.2f",temp.cost);

     }
  fwrite(&temp,sizeof(temp),1,ptr);
  textcolor(10);
  gotoxy(10,23);
  cprintf("More entries  [y/n]");
  ch=getche();
 }
fclose(ptr);

}
Example #6
0
void edit()
{
 int j,n,i,a;
 float b;
 char tar[30],ch;
 int count=0;
		ch='y';
		while(ch=='y')
		{
		ptr = fopen("shop.dat","rb");
		clrscr();
		design();
		gotoxy(15,9);
		printf("\xDB\xDB ENTER ID OF THE PRODUCT TO BE SOLD:");
		scanf("%s",&tar);
		j=0;

		while((fread(&temp,sizeof(temp),1,ptr))==1)
		{
		   if((strcmp(temp.id,tar)<0) || (strcmp(temp.id,tar)>0))
		   {
		      x[j] = temp;
		      j++;
		    }
		  else
		  {
		  design();
		  gotoxy(8,7);
		  printf("\xDB\xDB  Description       = %s",temp.desc);
		  gotoxy(8,9);
		  printf("\xDB\xDB  Quantity in stock = %d",temp.quantity);
		  gotoxy(8,11);
		  printf("\xDB\xDB  Sales price       = %.2f",temp.sale);
		  gotoxy(8,13);
		  printf("\xDB\xDB  Quantity want to sale : ");
		  scanf("%d",&a);

		  x[j]=temp;
		  x[j].quantity=(x[j].quantity-a);
		  x[j].total=(x[j].quantity*temp.sale);
		  x[j].cost=(x[j].quantity*temp.unit);
		  x[j].bye=(x[j].sale*a);
		  b=x[j].bye;
		  x[j].qty=a;
		  j++;
		  count++;
		  }
		}
		if (count==0)
		{
		 clrscr();
		 design();
		 gotoxy(33,10);
		 printf("\a\xDB\xDB\xB2  Not in stock");
		 getch();
		 return;
		}

		fclose(ptr);
		n = j;
		clrscr();
		ptr=fopen("shop.dat","wb");
		for(i=0; i<n; i++)
		fwrite(&x[i],sizeof(x[i]),1,ptr);
		fclose(ptr);
		clrscr();
		design();
		gotoxy(8,9);
		printf("\xDB\xDB  Price paid by customer = %.2f",b);
		gotoxy(8,11);
		printf("\xDB\xDB  Quantity sold          = %d",a);
		getch();
		printf("more enteries=(y/n)");
		ch=getche();
		}
}
Example #7
0
Filter::Filter(const fixed cutoff_wavelength, const bool bessel)
{
  design(cutoff_wavelength, bessel);
}
Example #8
0
int main()
{
    int t;
    scanf("%d",&t);
    design(t);
}
Example #9
0
/* load the Droid stats for the components from the Access database */
bool loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
{
	bool bDefaultTemplateFound = false;

	TableView table(pDroidData, bufferSize);

	for (unsigned i = 0; i < table.size(); ++i)
	{
		LineView line(table, i);

		DROID_TEMPLATE design(line);
		if (table.isError())
		{
			debug(LOG_ERROR, "%s", table.getError().toUtf8().constData());
			return false;
		}

		std::string const pNameCache = design.aName;
		design.pName = const_cast<char *>(pNameCache.c_str());

		if (getTemplateFromUniqueName(design.pName, 0))
		{
			debug(LOG_ERROR, "Duplicate template %s", design.pName);
			continue;
		}

		// Store translated name in aName
		char const *droidResourceName = getDroidResourceName(design.aName);
		sstrcpy(design.aName, droidResourceName != NULL? droidResourceName : GetDefaultTemplateName(&design));

		// Store global default design if found else store in the appropriate array
		if (design.droidType == DROID_ANY)
		{
			design.droidType = DROID_DEFAULT;
			// NOTE: sDefaultDesignTemplate.pName takes ownership
			//       of the memory allocated to pDroidDesign->pName
			//       here. Which is good because pDroidDesign leaves
			//       scope here anyway.
			sDefaultDesignTemplate = design;
			sDefaultDesignTemplate.pName = strdup(design.pName);
			bDefaultTemplateFound = true;
		}
		else
		{
			std::string playerType = line.s(6);
			// Give those meant for humans to all human players.
			// Also support the old template format, in which those meant
			// for humans were player 0 (in campaign) or 5 (in multiplayer).
			if ((!bMultiPlayer && playerType == "0") ||
			    ( bMultiPlayer && playerType == "5") ||
					      playerType == "YES"
			   )
			{
				for (int i = 0; i < MAX_PLAYERS; ++i)
				{
					if (NetPlay.players[i].allocated)  // human prototype template
					{
						design.prefab = false;
						addTemplateToList(&design, &apsDroidTemplates[i]);
					}
				}
				localTemplates.push_front(design);
				localTemplates.front().pName = strdup(localTemplates.front().pName);
			}
			// Add all templates to static template list
			design.prefab = true;  // prefabricated templates referenced from VLOs
			addTemplateToList(&design, &apsStaticTemplates);
		}

		debug(LOG_NEVER, "(default) Droid template found, aName: %s, MP ID: %d, ref: %u, pname: %s, prefab: %s, type:%d (loading)",
			design.aName, design.multiPlayerID, design.ref, design.pName, design.prefab ? "yes":"no", design.droidType);
	}

	ASSERT_OR_RETURN(false, bDefaultTemplateFound, "Default template not found");

	return true;
}
Example #10
0
/* load the Droid stats for the components from the Access database */
bool loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
{
	bool bDefaultTemplateFound = false;

	TableView table(pDroidData, bufferSize);

	for (unsigned i = 0; i < table.size(); ++i)
	{
		LineView line(table, i);

		DROID_TEMPLATE design(line);
		if (table.isError())
		{
			debug(LOG_ERROR, "%s", table.getError().toUtf8().constData());
			return false;
		}

		std::string const pNameCache = design.aName;
		design.pName = const_cast<char *>(pNameCache.c_str());

		if (getTemplateFromUniqueName(design.pName, 0))
		{
			debug(LOG_ERROR, "Duplicate template %s", design.pName);
			continue;
		}

		// Store translated name in aName
		char const *droidResourceName = getDroidResourceName(design.aName);
		sstrcpy(design.aName, droidResourceName != NULL? droidResourceName : GetDefaultTemplateName(&design));

		// Store global default design if found else store in the appropriate array
		if (design.droidType == DROID_ANY)
		{
			design.droidType = DROID_DEFAULT;
			// NOTE: sDefaultDesignTemplate.pName takes ownership
			//       of the memory allocated to pDroidDesign->pName
			//       here. Which is good because pDroidDesign leaves
			//       scope here anyway.
			sDefaultDesignTemplate = design;
			sDefaultDesignTemplate.pName = strdup(design.pName);
			bDefaultTemplateFound = true;
		}
		else
		{
			std::string playerType = line.s(6);

			for (int i = 0; i < MAX_PLAYERS; ++i)
			{
				// Give those meant for humans to all human players.
				// Also support the old template format, in which those meant
				// for humans were player 0 (in campaign) or 5 (in multiplayer), ("YES" is used in MP stats)
				if (NetPlay.players[i].allocated &&
					((!bMultiPlayer && playerType == "0") || (bMultiPlayer && playerType == "5") || playerType == "YES"))
				{
					debug(LOG_NEVER, "HUMAN (%d): %s id:%d enabled:%d", i, design.aName, design.multiPlayerID, design.enabled);
					design.prefab = false;
					addTemplateToList(&design, &apsDroidTemplates[i]);

					// This sets up the UI templates for display purposes ONLY--we still only use apsDroidTemplates for making them.
					// FIXME: Why are we doing this here, and not on demmand ?
					// Only add unique designs to the UI list (Note, perhaps better to use std::map instead?)
					std::list<DROID_TEMPLATE>::iterator it;
					for (it = localTemplates.begin(); it != localTemplates.end(); ++it)
					{
						DROID_TEMPLATE *psCurr = &*it;
						if (psCurr->multiPlayerID == design.multiPlayerID)
						{
							debug(LOG_NEVER, "Design id:%d (%s) *NOT* added to UI list (duplicate), player= %d", design.multiPlayerID, design.aName, i);
							break;
						}
					}
					if (it == localTemplates.end())
					{
						debug(LOG_NEVER, "Design id:%d (%s) added to UI list, player =%d", design.multiPlayerID, design.aName, i);
						localTemplates.push_front(design);
						localTemplates.front().pName = strdup(localTemplates.front().pName);
					}
				}
				else if (NetPlay.players[i].allocated)	//skip the ones not meant for puny humans
				{
					continue;
				}
				else	// assume everything else is for AI
				{
					debug(LOG_NEVER, "AI (%d): %s id:%d enabled:%d", i, design.aName, design.multiPlayerID, design.enabled);
					design.prefab = true;  // prefabricated templates referenced from VLOs
					addTemplateToList(&design, &apsDroidTemplates[i]);
				}
			}
		}
		debug(LOG_NEVER, "(default) Droid template found, aName: %s, MP ID: %d, ref: %u, pname: %s, prefab: %s, type:%d (loading)",
			design.aName, design.multiPlayerID, design.ref, design.pName, design.prefab ? "yes":"no", design.droidType);
	}

	ASSERT_OR_RETURN(false, bDefaultTemplateFound, "Default template not found");

	return true;
}
Example #11
0
void main()
{
	int sss,q,ll,gd=DETECT,p,gm,area,a=(450-(50*5)),d,cat=77,ch,dh,eh,t1,t2,t12,t22,len,cc,hh;
	char *str,*str1,*tim;
	initgraph(&gd,&gm,"");
	p=1;
	front();
	dr:
	viewport();
	q=menu();
	if(q==3)
	{
	     arun:	hh=help();
		if(hh==1)
		{
			how();
			goto arun;
		}
		if(hh==2)
		{
			select();
			goto arun;
		}
		if(hh==3)
		{
			credit();
			goto arun;
		}
		if(hh==4)
		{
			design();
			goto arun;
		}
		if(hh==5)
			goto dr;
	}
	if(q==2)
	{
	 rr:
		ll=sivakumar();
	       if(ll==1)
	       {
			p=m2();

			goto rr;
	       }
	       if(ll==2)
	       {
			a=speed();
			viewport();
			goto rr;
	       }
	       if(ll==3)
	       {
			topscore();
			goto rr;
		}
	       if(ll==4)
		    goto dr;
	}
	if(q==4)
		exit(0);
      if(q==1)
      {
	names();
	hide();
	viewport();
	x[0]=85;
	x[1]=70;
	x[2]=55;
	x[3]=40;
	y[0]=y[1]=y[2]=y[3]=35;
	setcolor(4);
	rectangle(24,19,626,396);
	ra();
	setcolor(15);
	setfillstyle(1,10);
	bar(32,32,43,43);
	area=imagesize(30,30,45,45);
	buff=malloc(area);
	getimage(30,30,45,45,buff);
	putimage(30,30,buff,XOR_PUT);
	setpos(0,0);
	setfillstyle(1,0);
	bar(100,100,500,350);
	prakash(p);
	level=p;
	putimage(40,35,buff,XOR_PUT);
	putimage(55,35,buff,XOR_PUT);
	putimage(70,35,buff,XOR_PUT);
	putimage(85,35,buff,XOR_PUT);
	textcolor(GREEN+BLINK);
	len=0;
	status("Game Play: Arrow keys       Menu: Esc         Pause (or) Play: Others key");
	while(1)
	{

	sss=getpixel(5,5);
	if(sss!=0);
	{
		setfillstyle(SOLID_FILL,0);
		bar(0,0,15,15);
	}
		if(((i-4)%11==0)&&(bon==0)&&(len!=(i-4)))
		{
			len=(i-4);
			gettime(&t);
			bonous();
				bon=1;
			t1=t.ti_sec;
			cc=10;
		}
		gettime(&t);
		if((t1!=t.ti_sec)&&(bon==1))
		{
			cc--;
			t1=t.ti_sec;
			itoa(cc,tim,10);
			setfillstyle(SOLID_FILL,0);
			bar(470,0,530,18);
			outtextxy(500,0,tim);

		}
		if((cc==0)&&(bon==1))
		{
			putimage(xc1,yc1,f2,XOR_PUT);
			bar(470,0,530,18);
			bon=0;
		}
		gotoxy(68,1);
		setcolor(6);
	       itoa(score,str,10);
	       setfillstyle(1,0);
	       settextstyle(3,0,1);
	       if(strcmp(str,str1)!=0)
	       {    bar(80,400,350,450);
		    outtextxy(100,420,"Score : ");
		    outtextxy(180,420,str);
		    strcpy(str1,str);
	       }
		if(kbhit())
		{
		       //	ch=getch();
			dh=getch();
			cat=dh;
		}
		else
		{
			arrange(x,y,i);
			if(set==0)
				food();
			if(cat!=dupli)
				cat=lock(cat,dupli);
			switch(cat)
			{
				case 72:
					     if(y[1]==20)
						  y[0]=380;
					     else
						  y[0]=y[1]-15;
					     x[0]=x[1];
					     d=getpixel(x[0]+8,y[0]+8);
					     if((d==10)||(d==14))
						doctor();
					     if((d==4)&&(bon==1))
					     {
						i++;
						sound(1000);
						delay(90);
						nosound();
						bon=0;
						score+=(cc*10);
					       putimage(xc1,yc1,f2,XOR_PUT);
					       putimage(x[0],y[0],buff,XOR_PUT);
					       putimage(x[i],y[i],buff,XOR_PUT);
					       setfillstyle(SOLID_FILL,0);
						bar(470,0,530,18);
					     }
					     else if(d==15)
					     {
						i++;
						set=0;
						sound(800);
						delay(40);
						score+=bb;
						nosound();
						putimage(x[0],y[0],buff,XOR_PUT);
					     }
					     else
					     {
						 putimage(x[0],y[0],buff,XOR_PUT);
						 putimage(x[i-1],y[i-1],buff,XOR_PUT);
					     }
						delay(a);
				     break;
				case 80:
				     if(y[1]==380)
					  y[0]=20;
				     else
					  y[0]=y[1]+15;
				     x[0]=x[1];
				      d=getpixel(x[0]+8,y[0]+8);
				      if((d==10)||(d==14))
					doctor();
					     if((d==4)&&(bon==1))
					     {
						i++;
						sound(1000);
						delay(90);
						nosound();
						bon=0;
						score+=(cc*10);
					       putimage(xc1,yc1,f2,XOR_PUT);
					       putimage(x[0],y[0],buff,XOR_PUT);
					       putimage(x[i],y[i],buff,XOR_PUT);
					       setfillstyle(SOLID_FILL,0);
						bar(470,0,530,18);
					     }
				      else if(d==15)
					     {
						i++;
						score+=bb;
						sound(800);
						delay(40);
						set=0;
						nosound();
						putimage(x[0],y[0],buff,XOR_PUT);
					     }
				       else
				      {
					     putimage(x[0],y[0],buff,XOR_PUT);
					     putimage(x[i-1],y[i-1],buff,XOR_PUT);
				      }
				     delay(a);
				     break;
				case 75:
				     if(x[1]==25)
					  x[0]=610;
				     else
					  x[0]=x[1]-15;
				     y[0]=y[1];
				     d=getpixel(x[0]+8,y[0]+8);
					if((d==10)||(d==14))
						doctor();
					     if((d==4)&&(bon==1))
					     {
						i++;
						sound(1000);
						delay(90);
						nosound();
						bon=0;
						score+=(cc*10);
					       putimage(xc1,yc1,f2,XOR_PUT);
					       putimage(x[0],y[0],buff,XOR_PUT);
					       putimage(x[i],y[i],buff,XOR_PUT);
					       setfillstyle(SOLID_FILL,0);
						bar(470,0,530,18);
					     }
					else if(d==15)
					  {
						i++;
						sound(800);
						delay(40);
						set=0;
						nosound();
						score+=bb;
						putimage(x[0],y[0],buff,XOR_PUT);
					  }
					  else
					  {
					     putimage(x[0],y[0],buff,XOR_PUT);
					     putimage(x[i-1],y[i-1],buff,XOR_PUT);
					  }
				      delay(a);
				 break;
				case 77:
				     if(x[1]==610)
					  x[0]=25;
				     else
					  x[0]=x[1]+15;
				     y[0]=y[1];
				     d=getpixel(x[0]+8,y[0]+8);
				      if((d==10)||(d==14))
					doctor();
					    if((d==4)&&(bon==1))
					     {
						i++;
						sound(1000);
						delay(90);
						nosound();
						bon=0;
						score+=(cc*10);
					       putimage(xc1,yc1,f2,XOR_PUT);
					       putimage(x[0],y[0],buff,XOR_PUT);
					       putimage(x[i],y[i],buff,XOR_PUT);
					       setfillstyle(SOLID_FILL,0);
						bar(470,0,530,18);
					     }
					else if(d==15)
					    {
						i++;
						set=0;
						sound(800);
						delay(40);
						score+=bb;
						nosound();
						putimage(x[0],y[0],buff,XOR_PUT);
					     }
					     else
					     {
						     putimage(x[0],y[0],buff,XOR_PUT);
						     putimage(x[i-1],y[i-1],buff,XOR_PUT);
					     }
				       delay(a);
					break;
				case 27:
					goto dx;
				//	break;
			}
			dupli=cat;
		}
    }
     }
     dx:
     call();
}