-void cre8floors() {
- int a,main_ref_count;
- FILE *fp;
- struct quickroom quickroom;
- struct floor floor_rec;
-
- /*
- * first, put all existing rooms on floor 0 (the main floor) and
- * count the room records that are in use so we can set the main
- * floor's reference count
- */
- main_ref_count = 0;
- fp = fopen("quickroom", "rb+");
- for (a=0; a<MAXROOMS; ++a) {
- progress("Preparing room files for addition of floors",
- (long)a,
- (long)MAXROOMS-1);
- fseek(fp, (a*((long)sizeof(struct quickroom))), 0);
- fread((char *)&quickroom,sizeof(struct quickroom),1,fp);
- if (quickroom.QRflags & QR_INUSE) ++main_ref_count;
- quickroom.QRfloor = 0;
- fseek(fp, (a*((long)sizeof(struct quickroom))), 0);
- fwrite((char *)&quickroom,sizeof(struct quickroom),1,fp);
- }
- fclose(fp);
-
- /* Open a new floortab file */
- fp=fopen("floortab","wb");
-
- /* Create the main floor */
- floor_rec.f_flags = (F_INUSE);
- strcpy(floor_rec.f_name, "Main Floor");
- floor_rec.f_ref_count = main_ref_count;
- floor_rec.f_reserved = 0;
- fwrite((char *)&floor_rec,sizeof(struct floor),1,fp);
-
-
- /* make the remaining floors blanks */
- floor_rec.f_flags = 0;
- strcpy(floor_rec.f_name, "");
- floor_rec.f_ref_count = 0;
- floor_rec.f_reserved = 0;
-
- for (a=1; a<MAXFLOORS; ++a) {
- progress("Creating floor table (floortab)",
- (long)a,
- (long)MAXFLOORS-1
- );
- fwrite((char *)&floor_rec,sizeof(struct floor),1,fp);
- }
- fclose(fp);
-
- }
-
-
-/*
- * check (and fix) floor reference counts
- */
-void check_ref_counts() {
- int ref[MAXFLOORS];
- int a;
- FILE *fp;
- struct quickroom qrbuf;
- struct floor flbuf;
-
- for (a=0; a<MAXFLOORS; ++a) ref[a] = 0;
-
- fp = fopen("quickroom","rb");
- for (a=0; a<MAXROOMS; ++a) {
- progress("Checking reference counts - phase 1 of 2",
- a,MAXROOMS-1);
- fread((char *)&qrbuf,sizeof(struct quickroom),1,fp);
- if (qrbuf.QRflags & QR_INUSE) {
- ++ref[(int)qrbuf.QRfloor];
- }
- }
- fclose(fp);
-
- fp = fopen("floortab","rb+");
- for (a=0; a<MAXFLOORS; ++a) {
- progress("Checking reference counts - phase 2 of 2",
- a,MAXFLOORS-1);
- fseek(fp,(long)a*(long)sizeof(struct floor),0);
- fread((char *)&flbuf,sizeof(struct floor),1,fp);
- flbuf.f_ref_count = ref[a];
- fseek(fp,(long)a*(long)sizeof(struct floor),0);
- fwrite((char *)&flbuf,sizeof(struct floor),1,fp);
- }
- fclose(fp);
- }
-