/* * BLITZREAD.C * Read parameters to create a blitz data file * A noxious hack */ #include #include #include #include #define MSDOS #ifdef UNIX #include char *tgetstr(char *, char **); #define TermBufSize 1024 char TermBuf[TermBufSize]; char TermData[128]; char *clscmd; #endif #ifdef MSDOS #include union REGS inregs, outregs; #endif #ifndef TRUE #define TRUE 1 #define FALSE 0 #endif #define MaxFileName 256 #define MaxSectors 21 char OneCharData[128]; int GetFirstParams(FILE *); void GetAttackerParams(FILE *); void GetDefenderParams(FILE *); void GetLastParams(FILE *); void GetReinforcements(FILE *, int); void DoError(char *); void GetClearCmd(void); void clear(void); int fputcthunk(char); int main(int argc, char *argv[]) { FILE *OutFile; char OutFileName[MaxFileName+1]; int NumDays; int MoreRuns = TRUE; if (argc < 2) strcpy(OutFileName, "blitzwar.dat"); else strcpy(OutFileName, argv[1]); OutFile = fopen(OutFileName, "w"); if (OutFile == NULL) { fprintf(stderr, "Could not open file %s for writing\n", OutFileName); exit(1); } GetClearCmd(); while (MoreRuns) { NumDays = GetFirstParams(OutFile); GetAttackerParams(OutFile); GetDefenderParams(OutFile); GetLastParams(OutFile); GetReinforcements(OutFile, NumDays); clear(); fputs("\n*** Enter another run (y/N)? ", stdout); scanf("%s", OneCharData); switch(toupper(*OneCharData)) { case 'Y': case 'T': case '1': MoreRuns = TRUE; break; default: MoreRuns = FALSE; } } fclose(OutFile); } int GetFirstParams(FILE *OutFile) { double TotalFrontLength; double BreakSectorLength; int NumBreakSectors; int NumBattleDays; int IsOK = FALSE; while (!IsOK) { clear(); fputs("\n***** GENERAL PARAMETERS *****\n", stdout); fputs("\nTotal front length (km): ", stdout); scanf("%lf", &TotalFrontLength); fputs("\nNumber of breakthrough sectors: ", stdout); scanf("%d", &NumBreakSectors); if ((NumBreakSectors << 1) + 1 > MaxSectors) { DoError("too many sectors"); continue; } fputs("\nBreakthrough sector length (km): ", stdout); scanf("%lf", &BreakSectorLength); if (NumBreakSectors * BreakSectorLength > TotalFrontLength) { DoError("overall breakthrough sector length" "is greater than total front length"); continue; } fputs("\nNumber of battle days: ", stdout); scanf("%d", &NumBattleDays); IsOK = TRUE; } fprintf(OutFile, "%.2lf %d %.2lf\n%d\n", TotalFrontLength, NumBreakSectors, BreakSectorLength, NumBattleDays); return NumBattleDays; } void GetAttackerParams(FILE *OutFile) { double InitialDE; double BreakForceToSpace; double BreakAttrThreshold; double QuietAttrThreshold; double BreakProsecutionRate; double QuietProsecutionRate; int InitialCAS; double CASAttrPerSortie; double CASSortiesPerDay; double AFVKillPerSortie; double BreakCASFraction; int ReinforceAbsolute; char ReinChar; int IsOK = FALSE; while (!IsOK) { clear(); fputs("\n***** ATTACKER PARAMETERS *****\n", stdout); fputs("\nInitial ground forces (in DE's): ", stdout); scanf("%lf", &InitialDE); fputs("\nBreakthrough force-to-space ratio (DE/segment): ", stdout); scanf("%lf", &BreakForceToSpace); fputs("\nBreakthrough attrition threshold: ", stdout); scanf("%lf", &BreakAttrThreshold); fputs("\nQuiet attrition threshold: ", stdout); scanf("%lf", &QuietAttrThreshold); fputs("\nBreakthrough prosecution rate: ", stdout); scanf("%lf", &BreakProsecutionRate); fputs("\nQuiet prosecution rate: ", stdout); scanf("%lf", &QuietProsecutionRate); fputs("\nInitial CAS units: ", stdout); scanf("%d", &InitialCAS); if (InitialCAS > 0) { fputs("\nCAS attrition rate per sortie: ", stdout); scanf("%lf", &CASAttrPerSortie); fputs("\nCAS sorties per day: ", stdout); scanf("%lf", &CASSortiesPerDay); fputs("\nAFV's killed by CAS per sortie: ", stdout); scanf("%lf", &AFVKillPerSortie); fputs("\nCAS fraction to breakthrough sectors: ", stdout); scanf("%lf", &BreakCASFraction); } else { CASAttrPerSortie = CASSortiesPerDay = AFVKillPerSortie = 0; BreakCASFraction = 0; } if (InitialDE < 0 || InitialCAS < 0 || BreakAttrThreshold > 1 || BreakAttrThreshold < 0 || QuietAttrThreshold > 1 || QuietAttrThreshold < 0 || CASAttrPerSortie > 1 || CASAttrPerSortie < 0 || CASSortiesPerDay < 0 || AFVKillPerSortie < 0 || BreakProsecutionRate < 0 || QuietProsecutionRate < 0) { DoError("ridiculous parameter value(s)"); continue; } fputs("\nReinforce absolutely (y/n)? ", stdout); scanf("%s", OneCharData); ReinChar = *OneCharData; switch(toupper(ReinChar)) { case 'Y': case 'T': case '1': ReinforceAbsolute = 1; break; case 'N': case 'F': case '0': ReinforceAbsolute = 0; break; default: DoError("invalid boolean response"); continue; } IsOK = TRUE; } fprintf(OutFile, "%.2lf %.2lf %.2lf %.2lf %.2lf %.2lf\n", InitialDE, BreakForceToSpace, BreakAttrThreshold, QuietAttrThreshold, BreakProsecutionRate, QuietProsecutionRate); fprintf(OutFile, "%d %.2lf %.2lf %.2lf %.2lf %d\n", InitialCAS, CASAttrPerSortie, CASSortiesPerDay, AFVKillPerSortie, BreakCASFraction, ReinforceAbsolute); } void GetDefenderParams(FILE *OutFile) { double InitialDE; double BreakForceToSpace; double QuietForceToSpace; double BreakAttrThreshold; double QuietAttrThreshold; double MaxWithdrawalRate; int InitialCAS; double CASAttrPerSortie; double CASSortiesPerDay; double AFVKillPerSortie; double BreakCASFraction; int ReinforceAbsolute; char ReinChar; int IsOK = FALSE; while (!IsOK) { clear(); fputs("\n***** DEFENDER PARAMETERS *****\n", stdout); fputs("\nInitial ground forces (in DE's): ", stdout); scanf("%lf", &InitialDE); fputs("\nBreakthrough force-to-space ratio (DE/segment): ", stdout); scanf("%lf", &BreakForceToSpace); fputs("\nQuiet force-to-space ratio (DE/segment): ", stdout); scanf("%lf", &QuietForceToSpace); fputs("\nBreakthrough attrition threshold: ", stdout); scanf("%lf", &BreakAttrThreshold); fputs("\nQuiet attrition threshold: ", stdout); scanf("%lf", &QuietAttrThreshold); fputs("\nMaximum withdrawal rate: ", stdout); scanf("%lf", &MaxWithdrawalRate); fputs("\nInitial CAS units: ", stdout); scanf("%d", &InitialCAS); if (InitialCAS > 0) { fputs("\nCAS attrition rate per sortie: ", stdout); scanf("%lf", &CASAttrPerSortie); fputs("\nCAS sorties per day: ", stdout); scanf("%lf", &CASSortiesPerDay); fputs("\nAFV's killed by CAS per sortie: ", stdout); scanf("%lf", &AFVKillPerSortie); fputs("\nCAS fraction to breakthrough sectors: ", stdout); scanf("%lf", &BreakCASFraction); } else { CASAttrPerSortie = CASSortiesPerDay = AFVKillPerSortie = 0; BreakCASFraction = 0; } if (InitialDE < 0 || InitialCAS < 0 || BreakAttrThreshold > 1 || BreakAttrThreshold < 0 || QuietAttrThreshold > 1 || QuietAttrThreshold < 0 || CASAttrPerSortie > 1 || CASAttrPerSortie < 0 || CASSortiesPerDay < 0 || AFVKillPerSortie < 0 || MaxWithdrawalRate < 0) { DoError("ridiculous parameter value(s)"); continue; } fputs("\nReinforce absolutely (y/n)? ", stdout); scanf("%s", OneCharData); ReinChar = *OneCharData; switch(toupper(ReinChar)) { case 'Y': case 'T': case '1': ReinforceAbsolute = 1; break; case 'N': case 'F': case '0': ReinforceAbsolute = 0; break; default: DoError("invalid boolean response"); continue; } IsOK = TRUE; } fprintf(OutFile, "%.2lf %.2lf %.2lf %.2lf %.2lf %.2lf\n", InitialDE, BreakForceToSpace, QuietForceToSpace, BreakAttrThreshold, QuietAttrThreshold, MaxWithdrawalRate); fprintf(OutFile, "%d %.2lf %.2lf %.2lf %.2lf %d\n", InitialCAS, CASAttrPerSortie, CASSortiesPerDay, AFVKillPerSortie, BreakCASFraction, ReinforceAbsolute); } void GetLastParams(FILE *OutFile) { double AFVPerDE; double LethalityPerDE; double CasualtyExchangeRate; int IsOK = FALSE; while (!IsOK) { clear(); fputs("\n***** MORE GENERAL PARAMETERS *****\n\n", stdout); fputs("\nAFV per DE: ", stdout); scanf("%lf", &AFVPerDE); fputs("\nLethality DE: ", stdout); scanf("%lf", &LethalityPerDE); fputs("\nCasualty exchange rate: ", stdout); scanf("%lf", &CasualtyExchangeRate); if (AFVPerDE < 0.0 || LethalityPerDE < 0.0 || CasualtyExchangeRate <= 0.0) { DoError("ridiculous parameter value(s)"); continue; } IsOK = TRUE; } fprintf(OutFile, "%.2lf %.2lf %.2lf\n", AFVPerDE, LethalityPerDE, CasualtyExchangeRate); } void GetReinforcements(FILE *OutFile, int NumDays) { double AtkGround, DefGround; int AtkAir, DefAir; int j; clear(); fputs("\n***** Reinforcements *****\n", stdout); printf("Enter reinforcements for %d days\n", NumDays); fputs("Format is " " \n\n", stdout); for (j = 1; j <= NumDays; j++) { printf("\n* DAY %d: ", j); scanf("%lf %d %lf %d", &AtkGround, &AtkAir, &DefGround, &DefAir); fprintf(OutFile, "%.2lf %d %.2lf %d\n", AtkGround, AtkAir, DefGround, DefAir); } } void DoError(char *ErrStr) { printf("\n\n*** Error: %s\n\n", ErrStr); fputs("Press to continue ", stdout); scanf("%s", OneCharData); fputs("\n\n", stdout); } void GetClearCmd(void) { #ifdef UNIX char *TermName; char *TermPtr = TermData; TermName = getenv("TERM"); tgetent(TermBuf, TermName); clscmd = tgetstr("cl", &TermPtr); #endif } void clear(void) { #ifdef UNIX tputs(clscmd, 1, fputcthunk); #endif #ifdef MSDOS inregs.h.ah = 15; int86(16,&inregs,&outregs); /* find current video mode */ outregs.h.ah = 0; int86(16,&outregs,&outregs); /* reset to current mode */ #endif } int fputcthunk(char outchar) { return fputc(outchar, stdout); }