void CCalibrateFinePage::Display() { float alt, az; txtClear(); txtPrint("Calibration\n\n"); if (!calib_stars) { txtPrint("Getting calibration stars\n"); polaris = FindStar("Polaris"); FindCalibrationStars(); polaris->GetAltAz(time(), my_longitude, my_latitude, &alt, &az); target_alt = alt; target_az = az; txtPrint("Seeking Home Position\n\n"); laser->RecalibrateHome(); laser->PointTo(az, alt); return; } if (calibrate_second_star) { txtPrintf("Aim laser at %s\n", calib_stars[curr_calib_star]->star_name); } else { txtPrint("Aim laser at Polaris \n"); } txtPrint("and press A or Enter.\n\n"); txtPrint("Press B or Back to point the\n"); txtPrint("laser near the target star.\n\n"); txtPrintf("Star Alt: %4.1f Az: %5.1f\n", target_alt, target_az); }
// Move the Flagship to the destination of the autopilot. // Should only be called from HyperSpace/QuasiSpace. // It can be called from debugHook directly after entering HS/QS though. void doInstantMove (void) { // Move to the new location: if ((GLOBAL (autopilot)).x == ~0 || (GLOBAL (autopilot)).y == ~0) { // If no destination has been selected, use the current location // as the destination. (GLOBAL (autopilot)).x = LOGX_TO_UNIVERSE(GLOBAL_SIS (log_x)); (GLOBAL (autopilot)).y = LOGY_TO_UNIVERSE(GLOBAL_SIS (log_y)); } else { // A new destination has been selected. GLOBAL_SIS (log_x) = UNIVERSE_TO_LOGX((GLOBAL (autopilot)).x); GLOBAL_SIS (log_y) = UNIVERSE_TO_LOGY((GLOBAL (autopilot)).y); } // Check for a solar systems at the destination. if (GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1) { // If there's a solar system at the destination, enter it. CurStarDescPtr = FindStar (0, &(GLOBAL (autopilot)), 0, 0); if (CurStarDescPtr) { // Leave HyperSpace/QuasiSpace if we're there: SET_GAME_STATE (USED_BROADCASTER, 0); GLOBAL (CurrentActivity) &= ~IN_BATTLE; // Enter IP: GLOBAL (ShipFacing) = 0; GLOBAL (ip_planet) = 0; GLOBAL (in_orbit) = 0; // This causes the ship position in IP to be reset. GLOBAL (CurrentActivity) |= START_INTERPLANETARY; } } // Turn off the autopilot: (GLOBAL (autopilot)).x = ~0; (GLOBAL (autopilot)).y = ~0; }
BOOLEAN LoadGame (COUNT which_game, SUMMARY_DESC *SummPtr) { uio_Stream *in_fp; char file[PATH_MAX]; char buf[256]; SUMMARY_DESC loc_sd; GAME_STATE_FILE *fp; DECODE_REF fh; COUNT num_links; STAR_DESC SD; ACTIVITY Activity; sprintf (file, "starcon2.%02u", which_game); in_fp = res_OpenResFile (saveDir, file, "rb"); if (!in_fp) return FALSE; if (!LoadSummary (&loc_sd, in_fp)) { log_add (log_Error, "Warning: Savegame is corrupt"); res_CloseResFile (in_fp); return FALSE; } if (!SummPtr) { SummPtr = &loc_sd; } else { // only need summary for displaying to user memcpy (SummPtr, &loc_sd, sizeof (*SummPtr)); res_CloseResFile (in_fp); return TRUE; } // Crude check for big-endian/little-endian incompatibilities. // year_index is suitable as it's a multi-byte value within // a specific recognisable range. if (SummPtr->year_index < START_YEAR || SummPtr->year_index >= START_YEAR + YEARS_TO_KOHRAH_VICTORY + 1 /* Utwig intervention */ + 1 /* time to destroy all races, plenty */ + 25 /* for cheaters */) { log_add (log_Error, "Warning: Savegame corrupt or from " "an incompatible platform."); res_CloseResFile (in_fp); return FALSE; } GlobData.SIS_state = SummPtr->SS; if ((fh = copen (in_fp, FILE_STREAM, STREAM_READ)) == 0) { res_CloseResFile (in_fp); return FALSE; } ReinitQueue (&GLOBAL (GameClock.event_q)); ReinitQueue (&GLOBAL (encounter_q)); ReinitQueue (&GLOBAL (ip_group_q)); ReinitQueue (&GLOBAL (npc_built_ship_q)); ReinitQueue (&GLOBAL (built_ship_q)); memset (&GLOBAL (GameState[0]), 0, sizeof (GLOBAL (GameState))); Activity = GLOBAL (CurrentActivity); LoadGameState (&GlobData.Game_state, fh); NextActivity = GLOBAL (CurrentActivity); GLOBAL (CurrentActivity) = Activity; LoadRaceQueue (fh, &GLOBAL (avail_race_q)); // START_INTERPLANETARY is only set when saving from Homeworld // encounter screen. When the game is loaded, the // GenerateOrbitalFunction for the current star system will // create the encounter anew and populate the npc queue. if (!(NextActivity & START_INTERPLANETARY)) { if (NextActivity & START_ENCOUNTER) LoadShipQueue (fh, &GLOBAL (npc_built_ship_q)); else if (LOBYTE (NextActivity) == IN_INTERPLANETARY) // XXX: Technically, this queue does not need to be // saved/loaded at all. IP groups will be reloaded // from group state files. But the original code did, // and so will we until we can prove we do not need to. LoadGroupQueue (fh, &GLOBAL (ip_group_q)); else // XXX: The empty queue read is only needed to maintain // the savegame compatibility LoadEmptyQueue (fh); } LoadShipQueue (fh, &GLOBAL (built_ship_q)); // Load the game events (compressed) cread_16 (fh, &num_links); { #ifdef DEBUG_LOAD log_add (log_Debug, "EVENTS:"); #endif /* DEBUG_LOAD */ while (num_links--) { HEVENT hEvent; EVENT *EventPtr; hEvent = AllocEvent (); LockEvent (hEvent, &EventPtr); LoadEvent (EventPtr, fh); #ifdef DEBUG_LOAD log_add (log_Debug, "\t%u/%u/%u -- %u", EventPtr->month_index, EventPtr->day_index, EventPtr->year_index, EventPtr->func_index); #endif /* DEBUG_LOAD */ UnlockEvent (hEvent); PutEvent (hEvent); } } // Load the encounters (black globes in HS/QS (compressed)) cread_16 (fh, &num_links); { while (num_links--) { HENCOUNTER hEncounter; ENCOUNTER *EncounterPtr; hEncounter = AllocEncounter (); LockEncounter (hEncounter, &EncounterPtr); LoadEncounter (EncounterPtr, fh); UnlockEncounter (hEncounter); PutEncounter (hEncounter); } } // Copy the star info file from the compressed stream fp = OpenStateFile (STARINFO_FILE, "wb"); if (fp) { DWORD flen; cread_32 (fh, &flen); while (flen) { COUNT num_bytes; num_bytes = flen >= sizeof (buf) ? sizeof (buf) : (COUNT)flen; cread (buf, num_bytes, 1, fh); WriteStateFile (buf, num_bytes, 1, fp); flen -= num_bytes; } CloseStateFile (fp); } // Copy the defined groupinfo file from the compressed stream fp = OpenStateFile (DEFGRPINFO_FILE, "wb"); if (fp) { DWORD flen; cread_32 (fh, &flen); while (flen) { COUNT num_bytes; num_bytes = flen >= sizeof (buf) ? sizeof (buf) : (COUNT)flen; cread (buf, num_bytes, 1, fh); WriteStateFile (buf, num_bytes, 1, fp); flen -= num_bytes; } CloseStateFile (fp); } // Copy the random groupinfo file from the compressed stream fp = OpenStateFile (RANDGRPINFO_FILE, "wb"); if (fp) { DWORD flen; cread_32 (fh, &flen); while (flen) { COUNT num_bytes; num_bytes = flen >= sizeof (buf) ? sizeof (buf) : (COUNT)flen; cread (buf, num_bytes, 1, fh); WriteStateFile (buf, num_bytes, 1, fp); flen -= num_bytes; } CloseStateFile (fp); } LoadStarDesc (&SD, fh); cclose (fh); res_CloseResFile (in_fp); EncounterGroup = 0; EncounterRace = -1; ReinitQueue (&race_q[0]); ReinitQueue (&race_q[1]); CurStarDescPtr = FindStar (NULL, &SD.star_pt, 0, 0); if (!(NextActivity & START_ENCOUNTER) && LOBYTE (NextActivity) == IN_INTERPLANETARY) NextActivity |= START_INTERPLANETARY; return TRUE; }
int main() { int nprob, nstars, curprob, index, subprobs, starInd, secs, subprob; double elev, az; if(fgets(&(inbuf[0]), 255, stdin) == NULL) { fprintf(stderr, "Read failed on problem and star count\n"); return -1; } if(sscanf(&(inbuf[0]), "%d %d", &nstars, &nprob) != 2) { fprintf(stderr, "Scan failed on problem and star count\n"); return -2; } if((nstars < 5) || (nstars > MAX_STARS)) { fprintf(stderr, "star count must be in range 5 to %d\n", MAX_STARS); return -21; } for(starInd = 1; starInd <= nstars ; starInd++) { if(fgets(&(inbuf[0]), 255, stdin) == NULL) { fprintf(stderr, "Read failed on star %d data\n", starInd); return -23; } if(sscanf(&(inbuf[0]), "%d %lf %lf", &index, &az, &elev) != 3) { fprintf(stderr, "scan failed on star %d data\n", starInd); return -26; } if(starInd != index) { fprintf(stderr, "star index %d not = expected star %d\n", index, starInd); return -27; } stars[index].azimuth = (az * PI)/180.0; stars[index].elevation = (elev * PI)/180.0; } for(curprob = 1; curprob <= nprob ; curprob++) { if(fgets(&(inbuf[0]), 255, stdin) == NULL) { fprintf(stderr, "Read failed on problem header problem index %d \n", curprob); return -3; } // get prob num and subprob count if(sscanf(&(inbuf[0]), "%d %d", &index, &subprobs) != 2) { fprintf(stderr, "scan failed on problem header problem index %d\n", curprob); return -6; } if(curprob != index) { fprintf(stderr, "problem index %d not = expected %d\n", index, curprob); return -7; } if((subprobs < 1) || (subprobs > MAX_SUBPROBS)) { fprintf(stderr, "number of subproblems %d not in range 1 to %d problem %d\n", subprobs, MAX_SUBPROBS, curprob); return -8; } // get first alignment star if(fgets(&(inbuf[0]), 255, stdin) == NULL) { fprintf(stderr, "Read failed on first alignment star problem %d \n", curprob); return -10; } if(sscanf(&(inbuf[0]), "%d %d %lf %lf", &secs, &starInd, &az, &elev) != 4) { fprintf(stderr, "scan failed on on first alignment star problem %d\n", curprob); return -11; } if((starInd < 1) || (starInd > MAX_STARS)) { fprintf(stderr, "first alignment star index %d not in range 1 to %d problem %d\n", starInd, MAX_STARS, curprob); return -51; } SetStar1(secs, starInd, (PI*az)/180.0, (PI*elev)/180.0); // get second alignment star if(fgets(&(inbuf[0]), 255, stdin) == NULL) { fprintf(stderr, "Read failed on second alignment star problem %d \n", curprob); return -12; } if(sscanf(&(inbuf[0]), "%d %d %lf %lf", &secs, &starInd, &az, &elev) != 4) { fprintf(stderr, "scan failed on on second alignment star problem %d\n", curprob); return -13; } if((starInd < 1) || (starInd > MAX_STARS)) { fprintf(stderr, "second alignment star index %d not in range 1 to %d problem %d\n", starInd, MAX_STARS, curprob); return -52; } #ifdef USE_ORIG if(SetStar2(secs, starInd, (PI*az)/180.0, (PI*elev)/180.0) != 0) { fprintf(stderr, "bad alignment stars problem %d\n", curprob); return -14; } #else if(SetStar2A(secs, starInd, (PI*az)/180.0, (PI*elev)/180.0) != 0) { fprintf(stderr, "bad alignmentA stars problem %d\n", curprob); return -24; } #endif printf("%d %d\n", curprob, subprobs); for(subprob = 1 ; subprob <= subprobs ; subprob++) { if(fgets(&(inbuf[0]), 255, stdin) == NULL) { fprintf(stderr, "Read failed on sub problem %d problem %d \n", subprob, curprob); return -15; } if(sscanf(&(inbuf[0]), "%d %d %d", &index, &secs, &starInd) != 3) { fprintf(stderr, "scan failed on on sub problem %d problem %d\n", subprob, curprob); return -16; } if(index != subprob) { fprintf(stderr, "subproblem index %d not = expected %d problem %d\n", index, subprob, curprob); return -17; } if((starInd < 1) || (starInd > MAX_STARS)) { fprintf(stderr, "sub problem %d star index %d not in range 1 to %d problem %d\n", subprob, starInd, MAX_STARS, curprob); return -53; } #ifdef USE_ORIG FindStar(secs, starInd, &az, &elev); #else FindStarA(secs, starInd, &az, &elev); #endif if(elev < 0.0) { printf("%d NOT VISIBLE\n", subprob); } else { printf("%d %.1lf %.1lf\n", subprob, az, elev); } } } return 0; }