void CharacterCreation::DeleteAll() {
	cursor->SetVisibility(false);
	GridDelete();
	cEngine->DeleteComponent(background);
	for (int i = 0; i < 2; ++i) {
		cEngine->DeleteComponent(info[i]);
	}
	for (int i = 0; i < 3; ++i) {
		cEngine->DeleteComponent(controls[i]);
	}
	for (int i = 0; i < 4; ++i) {
		cEngine->DeleteComponent(names[i]);
	}
	for (int i = 0; i < 4; ++i) {
		portraits[i]->ToggleVisibility();
	}
	cEngine->DeleteComponent(sqaCursor);
	cEngine->DeleteComponent(lttrU);
	cEngine->DeleteComponent(this);
}
 int gridwrite(char *file, void **data, int datatype, int nx, int ny, float dx, 
               float dy, double bndbox[4], double csize, float nodata, int filetype)
 {
 FILE *fp;
 
     int i, j;
     char fline[MAXLN];
     float **farr;
     int **iarr;
     short **sarr;
     double adjbndbox[4],utme,utmn;
     int channel1,type;
     CELLTYPE *rowbuf;
 
 /*  File types are
     0=ASCII   
     1= ARCVIEW grid via the ESRI Application Programmers Interface  */    
   if(filetype == 0)   /*  ASCII FILE  */
   {
     /* open ARC-Info file */
     fp = fopen(file,"w");
     if(fp == NULL)
     {
         printf("\nERROR: Cannot open output file %s\n\n",file);
         return(4);
     }
     
    
     /* write ARC-Info header */
     fprintf(fp,"ncols\t%d\n",nx);
     fprintf(fp,"nrows\t%d\n",ny);
     utme=bndbox[0]+dx*0.5;
     utmn=bndbox[1]+dy*0.5;
     fprintf(fp,"xllcenter\t%f\n",utme);
     fprintf(fp,"yllcenter\t%f\n",utmn);
     fprintf(fp,"cellsize\t%f\n",csize);
     fprintf(fp,"nodata_value\t%g\n",nodata);
     
     /* write raster data to ARC/INFO file */
     /* convert depending on datatype */
     if(datatype == RPSHRDTYPE)
     {   
         sarr = (short **) data;       
         for(i=0; i< ny; i++)
         {
             for(j=0; j< nx; j++)
             {
                 fprintf(fp,"%hd ",sarr[j][i]);
                 if((j+1) % LINELEN == 0)fprintf(fp,"\n");
             }
             fprintf(fp,"\n");
         }
     }
     else if(datatype == RPINTDTYPE)
     {
         iarr = (int **) data;
         for(i=0; i< ny; i++)
         {
             for(j=0; j< nx; j++)
             {
                 fprintf(fp,"%d ",iarr[j][i]);
                 if((j+1) % LINELEN == 0)fprintf(fp,"\n");
             }
             fprintf(fp,"\n");
         }
     }
     else if(datatype == RPFLTDTYPE)
     {
         farr = (float **) data;
         for(i=0; i< ny; i++)
         {
             for(j=0; j< nx; j++)
 	    {
 		fprintf(fp,"%g ",farr[j][i]);
 		if((j+1) % LINELEN == 0)fprintf(fp,"\n");
 	    }
 	    fprintf(fp,"\n");
         }   
     }
     else
     {
         printf("\nERROR: unknown datatype (%s).\n\n",datatype);
     }
     fclose(fp);
   }
   else
   {
 /*  ESRI grid file  */
      GridIOSetup();
 	 AccessWindowClear();  /*  Forget about any window it used to have  */
      if (CellLyrExists(file))
      {
 /*  Save old file as a backup and use new file name  */
         sprintf(fline,"%s%s",file,"_b");
         if (CellLyrExists(fline))GridDelete(fline);
         GridRename(file,fline);
         printf("Output grid %s exists and will be overwritten.\n",file);
         printf("The old grid is preserved as %s\n",fline);
         GridDelete(file);
      } 
      if(datatype == RPSHRDTYPE || datatype == RPINTDTYPE) 
      {
        type=CELLINT;
      }
      else type= CELLFLOAT;
 
      if((channel1 = CellLayerCreate(file,WRITEONLY,ROWIO,type,csize,bndbox)) < 0)
      {
         printf ("ERROR: Could not cread output grid %s\n",file);
         CellLyrClose(channel1);
         GridIOExit();
         return(5);
       }
      if(AccessWindowSet(bndbox, csize, adjbndbox) < 0)
      {
         printf ("ERROR: Could not set Window\n");
         CellLyrClose(channel1);
         CellLyrDelete (file);
         GridIOExit();
         return(5);
      }
 /*  Allocate row buffer  */
     if((rowbuf = (CELLTYPE *)CAllocate1(nx,sizeof(CELLTYPE))) == NULL)
     {
         printf("ERROR: Could not allocate buffer memory\n");
         CellLyrClose(channel1);
         CellLyrDelete (file);
         GridIOExit();
         return(5);
      }
      if(type == CELLINT)
      {
           register int *buf = (int *)rowbuf;
           if(datatype == RPSHRDTYPE)
           {
              sarr = (short **)data;
             for(i=0; i < ny; i++)
             {
                    for(j=0; j < nx; j++)
                    {
                       buf[j] = (int) sarr[j][i];
                       if(buf[j] == (int) nodata)buf[j]=MISSINGINT;
                    }
                    PutWindowRow (channel1, i, rowbuf);
             }
           }
           else if(datatype == RPINTDTYPE)
           {
              iarr = (int **)data;
              for(i=0; i< ny; i++)
              {
                    for(j=0; j < nx; j++)
                    {
                       buf[j] = (int) iarr[j][i];
                       if(buf[j] == (int) nodata)buf[j]=MISSINGINT;
                    }
                    PutWindowRow (channel1, i, rowbuf);
              }
           }
        }
        else   /*  Here type is float   */
        {
           register float *buf = (float *)rowbuf;
           float floatNull;
 
           GetMissingFloat(&floatNull);
           farr = (float **)data;
           for(i=0; i < ny; i++)
           {
                    for(j=0; j < nx; j++)
                    {
                       buf[j] = farr[j][i];
                       if(buf[j] == nodata)buf[j]=floatNull;
                    }
              PutWindowRow (channel1, i, rowbuf);
           }
        }
        CFree1 ((char *)rowbuf);
        CellLyrClose(channel1);
        GridIOExit();
    }
    return(0);
 }