From: <Mee...@us...> - 2009-12-07 21:56:30
|
Revision: 3399 http://sc2.svn.sourceforge.net/sc2/?rev=3399&view=rev Author: Meep-Eep Date: 2009-12-07 21:56:24 +0000 (Mon, 07 Dec 2009) Log Message: ----------- A few cleanups. Modified Paths: -------------- trunk/sc2/src/uqm/hyper.c trunk/sc2/src/uqm/hyper.h Modified: trunk/sc2/src/uqm/hyper.c =================================================================== --- trunk/sc2/src/uqm/hyper.c 2009-12-07 21:54:22 UTC (rev 3398) +++ trunk/sc2/src/uqm/hyper.c 2009-12-07 21:56:24 UTC (rev 3399) @@ -56,7 +56,8 @@ SIZE new_dx, new_dy; new_dx = *pdx; - if ((GLOBAL_SIS (log_x) -= new_dx) < 0) + GLOBAL_SIS (log_x) -= new_dx; + if (GLOBAL_SIS (log_x) < 0) { new_dx += (SIZE)GLOBAL_SIS (log_x); GLOBAL_SIS (log_x) = 0; @@ -68,7 +69,8 @@ } new_dy = *pdy; - if ((GLOBAL_SIS (log_y) -= new_dy) < 0) + GLOBAL_SIS (log_y) -= new_dy; + if (GLOBAL_SIS (log_y) < 0) { new_dy += (SIZE)GLOBAL_SIS (log_y); GLOBAL_SIS (log_y) = 0; @@ -106,8 +108,7 @@ } } - if (GLOBAL_SIS (FuelOnBoard) - && GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1) + if (GLOBAL_SIS (FuelOnBoard) && GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1) { COUNT cur_fuel_ticks; COUNT hyper_dist; @@ -303,7 +304,9 @@ BOOLEAN LoadHyperspace (void) { - hyper_dx = hyper_dy = hyper_extra = 0; + hyper_dx = 0; + hyper_dy = 0; + hyper_extra = 0; fuel_ticks = 1; GLOBAL (ShipStamp.origin.x) = -MAX_X_UNIVERSE; @@ -357,7 +360,7 @@ ClearSISRect (CLEAR_SIS_RADAR); - return (TRUE); + return TRUE; } BOOLEAN @@ -372,7 +375,7 @@ } // FreeHyperData (); - return (TRUE); + return TRUE; } static void @@ -429,6 +432,87 @@ } TRANSITION_TYPE; static void +InterplanetaryTransition (ELEMENT *ElementPtr) +{ + GLOBAL (ip_planet) = 0; + GLOBAL (in_orbit) = 0; + GLOBAL (ShipFacing) = 0; /* Not reentering the system */ + SET_GAME_STATE (USED_BROADCASTER, 0); + if (GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1) + { + // Enter a solar system from HyperSpace. + GLOBAL (CurrentActivity) |= START_INTERPLANETARY; + SET_GAME_STATE (ESCAPE_COUNTER, 0); + } + else + { + POINT pt; + + GLOBAL (autopilot.x) = ~0; + GLOBAL (autopilot.y) = ~0; + + ElementToUniverse (ElementPtr, &pt); + CurStarDescPtr = FindStar (NULL, &pt, 5, 5); + if (CurStarDescPtr->star_pt.x == ARILOU_HOME_X + && CurStarDescPtr->star_pt.y == ARILOU_HOME_Y) + { + // Meet the Arilou. + GLOBAL (CurrentActivity) |= START_ENCOUNTER; + } + else + { + // Transition from QuasiSpace to HyperSpace through + // one of the permanent portals. + COUNT index; + const POINT portal_pt[] = QUASISPACE_PORTALS_HYPERSPACE_ENDPOINTS; + + index = CurStarDescPtr - &star_array[NUM_SOLAR_SYSTEMS + 1]; + GLOBAL_SIS (log_x) = UNIVERSE_TO_LOGX (portal_pt[index].x); + GLOBAL_SIS (log_y) = UNIVERSE_TO_LOGY (portal_pt[index].y); + + SET_GAME_STATE (ARILOU_SPACE_SIDE, 0); + } + } +} + +/* Enter QuasiSpace from HyperSpace by any portal, or HyperSpace from + * QuasiSpace through the periodically opening portal. + */ +static void +ArilouSpaceTransition (void) +{ + GLOBAL (ShipFacing) = 0; /* Not reentering the system */ + SET_GAME_STATE (USED_BROADCASTER, 0); + GLOBAL (autopilot.x) = ~0; + GLOBAL (autopilot.y) = ~0; + if (GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1) + { + // From HyperSpace to QuasiSpace. + GLOBAL_SIS (log_x) = UNIVERSE_TO_LOGX (QUASI_SPACE_X); + GLOBAL_SIS (log_y) = UNIVERSE_TO_LOGY (QUASI_SPACE_Y); + if (GET_GAME_STATE (PORTAL_COUNTER) == 0) + { + // Periodically appearing portal. + SET_GAME_STATE (ARILOU_SPACE_SIDE, 3); + } + else + { + // Player-induced portal. + SET_GAME_STATE (PORTAL_COUNTER, 0); + SET_GAME_STATE (ARILOU_SPACE_SIDE, 3); + } + } + else + { + // From QuasiSpace to HyperSpace through the periodically appearing + // portal. + GLOBAL_SIS (log_x) = UNIVERSE_TO_LOGX (ARILOU_SPACE_X); + GLOBAL_SIS (log_y) = UNIVERSE_TO_LOGY (ARILOU_SPACE_Y); + SET_GAME_STATE (ARILOU_SPACE_SIDE, 0); + } +} + +static void unhyper_transition (ELEMENT *ElementPtr) { COUNT frame_index; @@ -452,96 +536,10 @@ GLOBAL (CurrentActivity) |= START_ENCOUNTER; break; case INTERPLANETARY_TRANSITION: - GLOBAL (ip_planet) = 0; - GLOBAL (in_orbit) = 0; - GLOBAL (ShipFacing) = 0; /* Not reentering the system */ - SET_GAME_STATE (USED_BROADCASTER, 0); - if (GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1) - { - GLOBAL (CurrentActivity) |= START_INTERPLANETARY; - SET_GAME_STATE (ESCAPE_COUNTER, 0); - } - else - { - POINT pt; - - GLOBAL (autopilot.x) = ~0; - GLOBAL (autopilot.y) = ~0; - - ElementToUniverse (ElementPtr, &pt); - CurStarDescPtr = FindStar (NULL, &pt, 5, 5); - if (CurStarDescPtr->star_pt.x == ARILOU_HOME_X - && CurStarDescPtr->star_pt.y == ARILOU_HOME_Y) - { - GLOBAL (CurrentActivity) |= START_ENCOUNTER; - } - else - { - COUNT index; - POINT portal_pt[] = - { - {4091, 7748}, - {3184, 4906}, - {9211, 6104}, - {5673, 1207}, - {1910, 926}, - {8607, 151}, - { 50, 1647}, - {6117, 4131}, - {5658, 9712}, - {2302, 3988}, - { 112, 9409}, - {7752, 8906}, - { 368, 6332}, - {9735, 3153}, - {5850, 6213}, - }; - - index = CurStarDescPtr - - &star_array[NUM_SOLAR_SYSTEMS + 1]; - GLOBAL_SIS (log_x) = - UNIVERSE_TO_LOGX (portal_pt[index].x); - GLOBAL_SIS (log_y) = - UNIVERSE_TO_LOGY (portal_pt[index].y); - - SET_GAME_STATE (ARILOU_SPACE_SIDE, 0); - } - } + InterplanetaryTransition (ElementPtr); break; case ARILOU_SPACE_TRANSITION: - /* Enter QuasiSpace from HyperSpace by any portal, - * or HyperSpace from QuasiSpace through the periodically - * opening portal. - */ - GLOBAL (ShipFacing) = 0; /* Not reentering the system */ - SET_GAME_STATE (USED_BROADCASTER, 0); - GLOBAL (autopilot.x) = ~0; - GLOBAL (autopilot.y) = ~0; - if (GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1) - { - // From HyperSpace to QuasiSpace. - GLOBAL_SIS (log_x) = UNIVERSE_TO_LOGX (QUASI_SPACE_X); - GLOBAL_SIS (log_y) = UNIVERSE_TO_LOGY (QUASI_SPACE_Y); - if (GET_GAME_STATE (PORTAL_COUNTER) == 0) - { - // Periodically appearing portal. - SET_GAME_STATE (ARILOU_SPACE_SIDE, 3); - } - else - { - // Player-induced portal. - SET_GAME_STATE (PORTAL_COUNTER, 0); - SET_GAME_STATE (ARILOU_SPACE_SIDE, 3); - } - } - else - { - // From QuasiSpace to HyperSpace through the - // periodically appearing portal. - GLOBAL_SIS (log_x) = UNIVERSE_TO_LOGX (ARILOU_SPACE_X); - GLOBAL_SIS (log_y) = UNIVERSE_TO_LOGY (ARILOU_SPACE_Y); - SET_GAME_STATE (ARILOU_SPACE_SIDE, 0); - } + ArilouSpaceTransition (); break; } @@ -557,7 +555,8 @@ init_transition (ELEMENT *ElementPtr0, ELEMENT *ElementPtr1, TRANSITION_TYPE which_transition) { - SIZE dx, dy, num_turns; + SIZE dx, dy; + SIZE num_turns; STARSHIP *StarShipPtr; dx = WORLD_TO_VELOCITY (ElementPtr0->next.location.x @@ -571,10 +570,11 @@ ElementPtr1->turn_wait = (BYTE) which_transition; GetElementStarShip (ElementPtr1, &StarShipPtr); - if ((num_turns = GetFrameCount (ElementPtr1->next.image.frame) + num_turns = GetFrameCount (ElementPtr1->next.image.frame) - ANGLE_TO_FACING (FULL_CIRCLE) + NORMALIZE_FACING (ANGLE_TO_FACING (FULL_CIRCLE) - - StarShipPtr->ShipFacing)) == 0) + - StarShipPtr->ShipFacing); + if (num_turns == 0) num_turns = 1; SetVelocityComponents (&ElementPtr1->velocity, @@ -595,13 +595,12 @@ ElementPtr->state_flags |= DEFY_PHYSICS; - return (FALSE); + return FALSE; } else { ElementPtr->preprocess_func = - (void (*) (struct element - *ElementPtr))hyper_transition; + (void (*) (struct element *ElementPtr)) hyper_transition; ElementPtr->postprocess_func = NULL; ElementPtr->state_flags |= NONSOLID; ElementPtr->next.image.frame = @@ -646,7 +645,7 @@ } } - return (TRUE); + return TRUE; } static void @@ -735,7 +734,8 @@ } else { - init_transition (ElementPtr0, ElementPtr1, ARILOU_SPACE_TRANSITION); + init_transition (ElementPtr0, ElementPtr1, + ARILOU_SPACE_TRANSITION); } } @@ -764,24 +764,23 @@ long lx, ly; lx = UNIVERSE_TO_LOGX (SDPtr->star_pt.x) - + (LOG_SPACE_WIDTH >> 1) - - GLOBAL_SIS (log_x); + + (LOG_SPACE_WIDTH >> 1) - GLOBAL_SIS (log_x); HyperSpaceElementPtr->current.location.x = WRAP_X (lx); ly = UNIVERSE_TO_LOGY (SDPtr->star_pt.y) - + (LOG_SPACE_HEIGHT >> 1) - - GLOBAL_SIS (log_y); + + (LOG_SPACE_HEIGHT >> 1) - GLOBAL_SIS (log_y); HyperSpaceElementPtr->current.location.y = WRAP_Y (ly); } - SetPrimType (&DisplayArray[HyperSpaceElementPtr->PrimIndex], STAMP_PRIM); + SetPrimType (&DisplayArray[HyperSpaceElementPtr->PrimIndex], + STAMP_PRIM); HyperSpaceElementPtr->current.image.farray = &hyperstars[1 + (GET_GAME_STATE (ARILOU_SPACE_SIDE) >> 1)]; UnlockElement (hHyperSpaceElement); } - return (hHyperSpaceElement); + return hHyperSpaceElement; } static void @@ -800,7 +799,8 @@ HyperSpaceElementPtr->playerNr = NEUTRAL_PLAYER_NUM; HyperSpaceElementPtr->state_flags = APPEARING | FINITE_LIFE | NONSOLID; - SetPrimType (&DisplayArray[HyperSpaceElementPtr->PrimIndex], STAMP_PRIM); + SetPrimType (&DisplayArray[HyperSpaceElementPtr->PrimIndex], + STAMP_PRIM); HyperSpaceElementPtr->preprocess_func = animation_preprocess; rand_val = TFB_Random (); @@ -896,40 +896,39 @@ encounter_collision (ELEMENT *ElementPtr0, POINT *pPt0, ELEMENT *ElementPtr1, POINT *pPt1) { + HENCOUNTER hEncounter; + HENCOUNTER hNextEncounter; - if ((ElementPtr1->state_flags & PLAYER_SHIP) - && (GLOBAL (CurrentActivity) & IN_BATTLE)) - { - HENCOUNTER hEncounter, hNextEncounter; + if (!(ElementPtr1->state_flags & PLAYER_SHIP) + || !(GLOBAL (CurrentActivity) & IN_BATTLE)) + return; - init_transition (ElementPtr0, ElementPtr1, RANDOM_ENCOUNTER_TRANSITION); + init_transition (ElementPtr0, ElementPtr1, RANDOM_ENCOUNTER_TRANSITION); - for (hEncounter = GetHeadEncounter (); - hEncounter != 0; hEncounter = hNextEncounter) + for (hEncounter = GetHeadEncounter (); + hEncounter != 0; hEncounter = hNextEncounter) + { + ENCOUNTER *EncounterPtr; + + LockEncounter (hEncounter, &EncounterPtr); + hNextEncounter = GetSuccEncounter (EncounterPtr); + if (EncounterPtr->hElement) { - ENCOUNTER *EncounterPtr; + ELEMENT *ElementPtr; - LockEncounter (hEncounter, &EncounterPtr); - hNextEncounter = GetSuccEncounter (EncounterPtr); - if (EncounterPtr->hElement) - { - ELEMENT *ElementPtr; - - LockElement (EncounterPtr->hElement, &ElementPtr); - - ElementPtr->state_flags |= NONSOLID | IGNORE_SIMILAR; - - UnlockElement (EncounterPtr->hElement); - } - UnlockEncounter (hEncounter); + LockElement (EncounterPtr->hElement, &ElementPtr); + ElementPtr->state_flags |= NONSOLID | IGNORE_SIMILAR; + UnlockElement (EncounterPtr->hElement); } - - // Mark this element as collided with flagship - // XXX: We could simply set hTarget to 1 or to ElementPtr1, - // but that would be too hacky ;) - ElementPtr0->hTarget = getSisElement (); - ZeroVelocityComponents (&ElementPtr0->velocity); + UnlockEncounter (hEncounter); } + + // Mark this element as collided with flagship + // XXX: We could simply set hTarget to 1 or to ElementPtr1, + // but that would be too hacky ;) + ElementPtr0->hTarget = getSisElement (); + ZeroVelocityComponents (&ElementPtr0->velocity); + (void) pPt0; /* Satisfying compiler (unused parameter) */ (void) pPt1; /* Satisfying compiler (unused parameter) */ } @@ -941,9 +940,8 @@ HELEMENT hElement; STAR_DESC SD; - if (GET_GAME_STATE (ARILOU_SPACE_SIDE) >= 2) - return (0); + return 0; if (EncounterPtr->SD.Index & ENCOUNTER_REFORMING) { @@ -952,7 +950,7 @@ EncounterPtr->transition_state = 100; if ((EncounterPtr->SD.Index & ONE_SHOT_ENCOUNTER) || LONIBBLE (EncounterPtr->SD.Index) == 0) - return (0); + return 0; } if (LONIBBLE (EncounterPtr->SD.Index)) @@ -964,7 +962,8 @@ { BYTE Type; SIZE dx, dy; - COUNT i, NumShips; + COUNT i; + COUNT NumShips; DWORD radius_squared; BYTE EncounterMakeup[] = { @@ -987,16 +986,15 @@ NumShips = MAX_HYPER_SHIPS; - EncounterPtr->SD.Index = MAKE_BYTE ( - NumShips, HINIBBLE (EncounterPtr->SD.Index)); + EncounterPtr->SD.Index = + MAKE_BYTE (NumShips, HINIBBLE (EncounterPtr->SD.Index)); for (i = 0; i < NumShips; ++i) { - HFLEETINFO hStarShip; - FLEET_INFO *FleetPtr; BRIEF_SHIP_INFO *BSIPtr = &EncounterPtr->ShipList[i]; - - hStarShip = GetStarShipFromIndex (&GLOBAL (avail_race_q), Type); - FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hStarShip); + HFLEETINFO hStarShip = + GetStarShipFromIndex (&GLOBAL (avail_race_q), Type); + FLEET_INFO *FleetPtr = + LockFleetInfo (&GLOBAL (avail_race_q), hStarShip); BSIPtr->race_id = Type; BSIPtr->crew_level = FleetPtr->crew_level; BSIPtr->max_crew = FleetPtr->max_crew; @@ -1004,7 +1002,6 @@ UnlockFleetInfo (&GLOBAL (avail_race_q), hStarShip); } - do { DWORD rand_val; @@ -1041,7 +1038,8 @@ LockElement (hElement, &ElementPtr); - if ((i = EncounterPtr->transition_state) || NewEncounter) + i = EncounterPtr->transition_state; + if (i || NewEncounter) { if (i < 0) { @@ -1078,14 +1076,14 @@ InsertElement (hElement, GetTailElement ()); } - return (EncounterPtr->hElement = hElement); + EncounterPtr->hElement = hElement; + return hElement; } #define GRID_OFFSET 200 static void -DrawHyperGrid (COORD ux, COORD uy, COORD ox, - COORD oy) +DrawHyperGrid (COORD ux, COORD uy, COORD ox, COORD oy) { COORD sx, sy, ex, ey; RECT r; @@ -1094,18 +1092,22 @@ SetContextForeGroundColor ( BUILD_COLOR (MAKE_RGB15 (0x00, 0x10, 0x00), 0x6B)); - if ((sx = ux - (RADAR_SCAN_WIDTH >> 1)) < 0) + sx = ux - (RADAR_SCAN_WIDTH >> 1); + if (sx < 0) sx = 0; else sx -= sx % GRID_OFFSET; - if ((ex = ux + (RADAR_SCAN_WIDTH >> 1)) > MAX_X_UNIVERSE + 1) + ex = ux + (RADAR_SCAN_WIDTH >> 1); + if (ex > MAX_X_UNIVERSE + 1) ex = MAX_X_UNIVERSE + 1; - if ((sy = uy - (RADAR_SCAN_HEIGHT >> 1)) < 0) + sy = uy - (RADAR_SCAN_HEIGHT >> 1); + if (sy < 0) sy = 0; else sy -= sy % GRID_OFFSET; - if ((ey = uy + (RADAR_SCAN_HEIGHT >> 1)) > MAX_Y_UNIVERSE + 1) + ey = uy + (RADAR_SCAN_HEIGHT >> 1); + if (ey > MAX_Y_UNIVERSE + 1) ey = MAX_Y_UNIVERSE + 1; r.corner.y = (COORD) ((long)(MAX_Y_UNIVERSE - ey) @@ -1115,222 +1117,216 @@ * RADAR_HEIGHT / RADAR_SCAN_HEIGHT) - oy) - r.corner.y + 1; for (ux = sx; ux <= ex; ux += GRID_OFFSET) { - r.corner.x = (COORD) ((long)ux - * RADAR_WIDTH / RADAR_SCAN_WIDTH) - ox; + r.corner.x = (COORD) ((long)ux * RADAR_WIDTH / RADAR_SCAN_WIDTH) - ox; DrawFilledRectangle (&r); - } while ((ux += GRID_OFFSET) < ex); + } r.corner.x = (COORD) ((long)sx * RADAR_WIDTH / RADAR_SCAN_WIDTH) - ox; - r.extent.width = ((COORD) ((long)ex - * RADAR_WIDTH / RADAR_SCAN_WIDTH) - ox) - - r.corner.x + 1; + r.extent.width = ((COORD) ((long)ex * RADAR_WIDTH / RADAR_SCAN_WIDTH) + - ox) - r.corner.x + 1; r.extent.height = 1; for (uy = sy; uy <= ey; uy += GRID_OFFSET) { r.corner.y = (COORD)((long)(MAX_Y_UNIVERSE - uy) * RADAR_HEIGHT / RADAR_SCAN_HEIGHT) - oy; DrawFilledRectangle (&r); - } while ((uy += GRID_OFFSET) < ey); + } } - -static void -ProcessEncounters (POINT *puniverse, COORD ox, COORD oy) +// Returns false iff the encounter is to be removed. +static bool +ProcessEncounter (ENCOUNTER *EncounterPtr, POINT *puniverse, + COORD ox, COORD oy, STAMP *stamp) { - STAMP s; - HENCOUNTER hEncounter, hNextEncounter; + ELEMENT *ElementPtr; + COORD ex, ey; - s.frame = SetAbsFrameIndex (stars_in_space, 91); - for (hEncounter = GetHeadEncounter (); - hEncounter; hEncounter = hNextEncounter) - { - COORD ex, ey; - ENCOUNTER *EncounterPtr; + if (EncounterPtr->hElement == 0 + && AddEncounterElement (EncounterPtr, puniverse) == 0) + return false; - LockEncounter (hEncounter, &EncounterPtr); - hNextEncounter = GetSuccEncounter (EncounterPtr); + LockElement (EncounterPtr->hElement, &ElementPtr); - if (EncounterPtr->hElement == 0 - && AddEncounterElement (EncounterPtr, puniverse) == 0) + if (ElementPtr->death_func) + { + if (EncounterPtr->transition_state && ElementPtr->turn_wait == 0) { -DeleteEncounter: - UnlockEncounter (hEncounter); - - RemoveEncounter (hEncounter); - FreeEncounter (hEncounter); - continue; + --EncounterPtr->transition_state; + if (EncounterPtr->transition_state >= NUM_VORTEX_TRANSITIONS) + ++ElementPtr->turn_wait; + else if (EncounterPtr->transition_state == + -NUM_VORTEX_TRANSITIONS) + { + ElementPtr->death_func = NULL; + UnlockElement (EncounterPtr->hElement); + return false; + } + else + SetPrimType (&DisplayArray[ElementPtr->PrimIndex], + STAMP_PRIM); } + } + else + { + SIZE delta_x, delta_y; + COUNT encounter_radius; - { - ELEMENT *ElementPtr; + ElementPtr->life_span = 1; + GetNextVelocityComponents (&ElementPtr->velocity, + &delta_x, &delta_y, 1); + if (ElementPtr->thrust_wait) + --ElementPtr->thrust_wait; + else if (!ElementPtr->hTarget) + { // This is an encounter that did not collide with flagship + // The colliding encounter does not move + COUNT cur_facing, delta_facing; - LockElement (EncounterPtr->hElement, &ElementPtr); - - if (ElementPtr->death_func) + cur_facing = ANGLE_TO_FACING ( + GetVelocityTravelAngle (&ElementPtr->velocity)); + delta_facing = NORMALIZE_FACING (cur_facing - ANGLE_TO_FACING ( + ARCTAN (puniverse->x - EncounterPtr->SD.star_pt.x, + puniverse->y - EncounterPtr->SD.star_pt.y))); + if (delta_facing || (delta_x == 0 && delta_y == 0)) { - if (EncounterPtr->transition_state - && ElementPtr->turn_wait == 0) + SIZE speed; + const SIZE RaceHyperSpeed[] = { - --EncounterPtr->transition_state; - if (EncounterPtr->transition_state >= - NUM_VORTEX_TRANSITIONS) - ++ElementPtr->turn_wait; - else if (EncounterPtr->transition_state == - -NUM_VORTEX_TRANSITIONS) - { - ElementPtr->death_func = NULL; - UnlockElement (EncounterPtr->hElement); - goto DeleteEncounter; - } - else - SetPrimType (&DisplayArray[ElementPtr->PrimIndex], STAMP_PRIM); - } - } - else - { - SIZE delta_x, delta_y; - COUNT encounter_radius; + RACE_HYPER_SPEED + }; - ElementPtr->life_span = 1; - GetNextVelocityComponents (&ElementPtr->velocity, - &delta_x, &delta_y, 1); - if (ElementPtr->thrust_wait) - --ElementPtr->thrust_wait; - else if (!ElementPtr->hTarget) - { // This is an encounter that did not collide with flagship - // The colliding encounter does not move - COUNT cur_facing, delta_facing; - - cur_facing = ANGLE_TO_FACING ( - GetVelocityTravelAngle (&ElementPtr->velocity)); - delta_facing = NORMALIZE_FACING (cur_facing - - ANGLE_TO_FACING (ARCTAN ( - puniverse->x - EncounterPtr->SD.star_pt.x, - puniverse->y - EncounterPtr->SD.star_pt.y))); - if (delta_facing || (delta_x == 0 && delta_y == 0)) - { - SIZE s, RaceHyperSpeed[] = - { - RACE_HYPER_SPEED - }; - #define ENCOUNTER_TRACK_WAIT 3 - s = RaceHyperSpeed[EncounterPtr->SD.Type]; - if (delta_facing < ANGLE_TO_FACING (HALF_CIRCLE)) - --cur_facing; - else - ++cur_facing; - if (NORMALIZE_FACING (delta_facing - + ANGLE_TO_FACING (OCTANT)) > ANGLE_TO_FACING (QUADRANT)) - { - if (delta_facing < ANGLE_TO_FACING (HALF_CIRCLE)) - --cur_facing; - else - ++cur_facing; - s >>= 1; - } - cur_facing = FACING_TO_ANGLE (cur_facing); - SetVelocityComponents ( - &ElementPtr->velocity, - COSINE (cur_facing, s), - SINE (cur_facing, s) - ); - GetNextVelocityComponents (&ElementPtr->velocity, - &delta_x, &delta_y, 1); - - ElementPtr->thrust_wait = ENCOUNTER_TRACK_WAIT; - } - } - EncounterPtr->log_x += delta_x; - EncounterPtr->log_y -= delta_y; - EncounterPtr->SD.star_pt.x = - LOGX_TO_UNIVERSE (EncounterPtr->log_x); - EncounterPtr->SD.star_pt.y = - LOGY_TO_UNIVERSE (EncounterPtr->log_y); - - encounter_radius = EncounterPtr->radius + (GRID_OFFSET >> 1); - if ((delta_x = EncounterPtr->SD.star_pt.x - - EncounterPtr->origin.x) < 0) - delta_x = -delta_x; - if ((delta_y = EncounterPtr->SD.star_pt.y - - EncounterPtr->origin.y) < 0) - delta_y = -delta_y; - if ((COUNT)delta_x >= encounter_radius - || (COUNT)delta_y >= encounter_radius - || (DWORD)delta_x * delta_x + (DWORD)delta_y * delta_y >= - (DWORD)encounter_radius * encounter_radius) + speed = RaceHyperSpeed[EncounterPtr->SD.Type]; + if (delta_facing < ANGLE_TO_FACING (HALF_CIRCLE)) + --cur_facing; + else + ++cur_facing; + if (NORMALIZE_FACING (delta_facing + ANGLE_TO_FACING (OCTANT)) + > ANGLE_TO_FACING (QUADRANT)) { - ElementPtr->state_flags |= NONSOLID; - ElementPtr->life_span = 0; - - if (EncounterPtr->transition_state == 0) - { - ElementPtr->death_func = encounter_transition; - EncounterPtr->transition_state = -1; - ElementPtr->hit_points = 1; - } + if (delta_facing < ANGLE_TO_FACING (HALF_CIRCLE)) + --cur_facing; else - { - ElementPtr->death_func = NULL; - UnlockElement (EncounterPtr->hElement); - goto DeleteEncounter; - } + ++cur_facing; + speed >>= 1; } + cur_facing = FACING_TO_ANGLE (cur_facing); + SetVelocityComponents (&ElementPtr->velocity, + COSINE (cur_facing, speed), SINE (cur_facing, speed)); + GetNextVelocityComponents (&ElementPtr->velocity, + &delta_x, &delta_y, 1); + + ElementPtr->thrust_wait = ENCOUNTER_TRACK_WAIT; } + } + EncounterPtr->log_x += delta_x; + EncounterPtr->log_y -= delta_y; + EncounterPtr->SD.star_pt.x = LOGX_TO_UNIVERSE (EncounterPtr->log_x); + EncounterPtr->SD.star_pt.y = LOGY_TO_UNIVERSE (EncounterPtr->log_y); - ex = EncounterPtr->SD.star_pt.x; - ey = EncounterPtr->SD.star_pt.y; - if (ex - puniverse->x >= -UNIT_SCREEN_WIDTH - && ex - puniverse->x <= UNIT_SCREEN_WIDTH - && ey - puniverse->y >= -UNIT_SCREEN_HEIGHT - && ey - puniverse->y <= UNIT_SCREEN_HEIGHT) + encounter_radius = EncounterPtr->radius + (GRID_OFFSET >> 1); + delta_x = EncounterPtr->SD.star_pt.x - EncounterPtr->origin.x; + if (delta_x < 0) + delta_x = -delta_x; + delta_y = EncounterPtr->SD.star_pt.y - EncounterPtr->origin.y; + if (delta_y < 0) + delta_y = -delta_y; + if ((COUNT)delta_x >= encounter_radius + || (COUNT)delta_y >= encounter_radius + || (DWORD)delta_x * delta_x + (DWORD)delta_y * delta_y >= + (DWORD)encounter_radius * encounter_radius) + { + ElementPtr->state_flags |= NONSOLID; + ElementPtr->life_span = 0; + + if (EncounterPtr->transition_state == 0) { - ElementPtr->next.location.x = (SIZE)( - EncounterPtr->log_x - GLOBAL_SIS (log_x) - ) + (LOG_SPACE_WIDTH >> 1); - ElementPtr->next.location.y = (SIZE)( - EncounterPtr->log_y - GLOBAL_SIS (log_y) - ) + (LOG_SPACE_HEIGHT >> 1); - if ((ElementPtr->state_flags & NONSOLID) - && EncounterPtr->transition_state == 0) - { - ElementPtr->current.location = - ElementPtr->next.location; - SetPrimType (&DisplayArray[ElementPtr->PrimIndex], STAMP_PRIM); - if (ElementPtr->death_func == 0) - { - InitIntersectStartPoint (ElementPtr); - ElementPtr->state_flags &= ~NONSOLID; - } - } + ElementPtr->death_func = encounter_transition; + EncounterPtr->transition_state = -1; + ElementPtr->hit_points = 1; } else { - ElementPtr->state_flags |= NONSOLID; - if (ex - puniverse->x < -XOFFS - || ex - puniverse->x > XOFFS - || ey - puniverse->y < -YOFFS - || ey - puniverse->y > YOFFS) - { - ElementPtr->life_span = 0; - ElementPtr->death_func = NULL; - UnlockElement (EncounterPtr->hElement); - - goto DeleteEncounter; - } - - SetPrimType (&DisplayArray[ElementPtr->PrimIndex], NO_PRIM); + ElementPtr->death_func = NULL; + UnlockElement (EncounterPtr->hElement); + return false; } + } + } + ex = EncounterPtr->SD.star_pt.x; + ey = EncounterPtr->SD.star_pt.y; + if (ex - puniverse->x >= -UNIT_SCREEN_WIDTH + && ex - puniverse->x <= UNIT_SCREEN_WIDTH + && ey - puniverse->y >= -UNIT_SCREEN_HEIGHT + && ey - puniverse->y <= UNIT_SCREEN_HEIGHT) + { + ElementPtr->next.location.x = + (SIZE)(EncounterPtr->log_x - GLOBAL_SIS (log_x)) + + (LOG_SPACE_WIDTH >> 1); + ElementPtr->next.location.y = + (SIZE)(EncounterPtr->log_y - GLOBAL_SIS (log_y)) + + (LOG_SPACE_HEIGHT >> 1); + if ((ElementPtr->state_flags & NONSOLID) + && EncounterPtr->transition_state == 0) + { + ElementPtr->current.location = ElementPtr->next.location; + SetPrimType (&DisplayArray[ElementPtr->PrimIndex], + STAMP_PRIM); + if (ElementPtr->death_func == 0) + { + InitIntersectStartPoint (ElementPtr); + ElementPtr->state_flags &= ~NONSOLID; + } + } + } + else + { + ElementPtr->state_flags |= NONSOLID; + if (ex - puniverse->x < -XOFFS || ex - puniverse->x > XOFFS + || ey - puniverse->y < -YOFFS || ey - puniverse->y > YOFFS) + { + ElementPtr->life_span = 0; + ElementPtr->death_func = NULL; UnlockElement (EncounterPtr->hElement); + return false; } - s.origin.x = (COORD)((long)ex * RADAR_WIDTH - / RADAR_SCAN_WIDTH) - ox; - s.origin.y = (COORD)((long)(MAX_Y_UNIVERSE - ey) * RADAR_HEIGHT - / RADAR_SCAN_HEIGHT) - oy; - DrawStamp (&s); + SetPrimType (&DisplayArray[ElementPtr->PrimIndex], NO_PRIM); + } + UnlockElement (EncounterPtr->hElement); + + stamp->origin.x = (COORD)((long)ex * RADAR_WIDTH / RADAR_SCAN_WIDTH) - ox; + stamp->origin.y = (COORD)((long)(MAX_Y_UNIVERSE - ey) * RADAR_HEIGHT + / RADAR_SCAN_HEIGHT) - oy; + DrawStamp (stamp); + + return true; +} + +static void +ProcessEncounters (POINT *puniverse, COORD ox, COORD oy) +{ + STAMP stamp; + HENCOUNTER hEncounter, hNextEncounter; + + stamp.frame = SetAbsFrameIndex (stars_in_space, 91); + for (hEncounter = GetHeadEncounter (); + hEncounter; hEncounter = hNextEncounter) + { + ENCOUNTER *EncounterPtr; + + LockEncounter (hEncounter, &EncounterPtr); + hNextEncounter = GetSuccEncounter (EncounterPtr); + + if (!ProcessEncounter (EncounterPtr, puniverse, ox, oy, &stamp)) + { + UnlockEncounter (hEncounter); + RemoveEncounter (hEncounter); + FreeEncounter (hEncounter); + continue; + } + UnlockEncounter (hEncounter); } } @@ -1356,20 +1352,15 @@ SetContext (RadarContext); BatchGraphics (); - ox = (COORD)((long)universe.x - * RADAR_WIDTH / RADAR_SCAN_WIDTH) + ox = (COORD)((long)universe.x * RADAR_WIDTH / RADAR_SCAN_WIDTH) - (RADAR_WIDTH >> 1); oy = (COORD)((long)(MAX_Y_UNIVERSE - universe.y) - * RADAR_HEIGHT / RADAR_SCAN_HEIGHT) - - (RADAR_HEIGHT >> 1); + * RADAR_HEIGHT / RADAR_SCAN_HEIGHT) - (RADAR_HEIGHT >> 1); ex = (COORD)((long)GLOBAL (ShipStamp.origin.x) - * RADAR_WIDTH / RADAR_SCAN_WIDTH) - - (RADAR_WIDTH >> 1); - ey = (COORD)((long)(MAX_Y_UNIVERSE - - GLOBAL (ShipStamp.origin.y)) - * RADAR_HEIGHT / RADAR_SCAN_HEIGHT) - - (RADAR_HEIGHT >> 1); + * RADAR_WIDTH / RADAR_SCAN_WIDTH) - (RADAR_WIDTH >> 1); + ey = (COORD)((long)(MAX_Y_UNIVERSE - GLOBAL (ShipStamp.origin.y)) + * RADAR_HEIGHT / RADAR_SCAN_HEIGHT) - (RADAR_HEIGHT >> 1); arilouSpaceCounter = GET_GAME_STATE (ARILOU_SPACE_COUNTER); arilouSpaceSide = GET_GAME_STATE (ARILOU_SPACE_SIDE); @@ -1393,8 +1384,8 @@ s.origin.x = (COORD)((long)ex * RADAR_WIDTH / RADAR_SCAN_WIDTH) - ox; - s.origin.y = (COORD)((long)(MAX_Y_UNIVERSE - ey) * RADAR_HEIGHT - / RADAR_SCAN_HEIGHT) - oy; + s.origin.y = (COORD)((long)(MAX_Y_UNIVERSE - ey) + * RADAR_HEIGHT / RADAR_SCAN_HEIGHT) - oy; s.frame = SetRelFrameIndex (blip_frame, star_type + 2); DrawStamp (&s); @@ -1455,53 +1446,55 @@ --i; sx = SD[i].star_pt.x - universe.x + XOFFS; sy = SD[i].star_pt.y - universe.y + YOFFS; - if (sx >= 0 && sy >= 0 - && sx < (XOFFS << 1) && sy < (YOFFS << 1)) - { - ex = SD[i].star_pt.x; - ey = SD[i].star_pt.y; - s.origin.x = (COORD)((long)ex * RADAR_WIDTH - / RADAR_SCAN_WIDTH) - ox; - s.origin.y = (COORD)((long)(MAX_Y_UNIVERSE - ey) - * RADAR_HEIGHT - / RADAR_SCAN_HEIGHT) - oy; - s.frame = SetAbsFrameIndex (stars_in_space, 95); - DrawStamp (&s); + if (sx < 0 || sy < 0 || sx >= (XOFFS << 1) || sy >= (YOFFS << 1)) + continue; - if ((ex -= universe.x) < 0) - ex = -ex; - if ((ey -= universe.y) < 0) - ey = -ey; - if (ex <= (XOFFS / NUM_RADAR_SCREENS) - && ey <= (YOFFS / NUM_RADAR_SCREENS) - && (hHyperSpaceElement = - AllocHyperElement (&SD[i])) != 0) - { - LockElement (hHyperSpaceElement, &HyperSpaceElementPtr); - HyperSpaceElementPtr->current.image.frame = SetAbsFrameIndex ( - hyperstars[1 + (GET_GAME_STATE (ARILOU_SPACE_SIDE) >> 1)], - SD[i].Index - ); - HyperSpaceElementPtr->preprocess_func = - HyperSpaceElementPtr->postprocess_func = NULL; - HyperSpaceElementPtr->collision_func = arilou_space_collision; + ex = SD[i].star_pt.x; + ey = SD[i].star_pt.y; + s.origin.x = (COORD)((long)ex * RADAR_WIDTH / RADAR_SCAN_WIDTH) + - ox; + s.origin.y = (COORD)((long)(MAX_Y_UNIVERSE - ey) + * RADAR_HEIGHT / RADAR_SCAN_HEIGHT) - oy; + s.frame = SetAbsFrameIndex (stars_in_space, 95); + DrawStamp (&s); - SetUpElement (HyperSpaceElementPtr); + ex -= universe.x; + if (ex < 0) + ex = -ex; + ey -= universe.y; + if (ey < 0) + ey = -ey; - if (arilouSpaceSide == 1 || arilouSpaceSide == 2) - HyperSpaceElementPtr->death_func = arilou_space_death; - else - { - HyperSpaceElementPtr->death_func = NULL; - HyperSpaceElementPtr->IntersectControl.IntersectStamp.frame = - DecFrameIndex (stars_in_space); - } + if (ex > (XOFFS / NUM_RADAR_SCREENS) + || ey > (YOFFS / NUM_RADAR_SCREENS)) + continue; - UnlockElement (hHyperSpaceElement); + hHyperSpaceElement = AllocHyperElement (&SD[i]); + if (hHyperSpaceElement == 0) + continue; - InsertElement (hHyperSpaceElement, GetHeadElement ()); - } + LockElement (hHyperSpaceElement, &HyperSpaceElementPtr); + HyperSpaceElementPtr->current.image.frame = SetAbsFrameIndex ( + hyperstars[1 + (GET_GAME_STATE (ARILOU_SPACE_SIDE) >> 1)], + SD[i].Index); + HyperSpaceElementPtr->preprocess_func = NULL; + HyperSpaceElementPtr->postprocess_func = NULL; + HyperSpaceElementPtr->collision_func = arilou_space_collision; + + SetUpElement (HyperSpaceElementPtr); + + if (arilouSpaceSide == 1 || arilouSpaceSide == 2) + HyperSpaceElementPtr->death_func = arilou_space_death; + else + { + HyperSpaceElementPtr->death_func = NULL; + HyperSpaceElementPtr->IntersectControl.IntersectStamp.frame = + DecFrameIndex (stars_in_space); } + + UnlockElement (hHyperSpaceElement); + + InsertElement (hHyperSpaceElement, GetHeadElement ()); } while (i); } @@ -1509,46 +1502,47 @@ SDPtr = 0; while ((SDPtr = FindStar (SDPtr, &universe, XOFFS, YOFFS))) { - ex = SDPtr->star_pt.x; - ey = SDPtr->star_pt.y; - if ((ex -= universe.x) < 0) + BYTE star_type; + + ex = SDPtr->star_pt.x - universe.x; + if (ex < 0) ex = -ex; - if ((ey -= universe.y) < 0) + ey = SDPtr->star_pt.y - universe.y; + if (ey < 0) ey = -ey; - if (ex <= (XOFFS / NUM_RADAR_SCREENS) - && ey <= (YOFFS / NUM_RADAR_SCREENS) - && (hHyperSpaceElement = AllocHyperElement (SDPtr)) != 0) - { - BYTE star_type; + if (ex > (XOFFS / NUM_RADAR_SCREENS) + || ey > (YOFFS / NUM_RADAR_SCREENS)) + continue; - star_type = SDPtr->Type; + hHyperSpaceElement = AllocHyperElement (SDPtr); + if (hHyperSpaceElement == 0) + continue; - LockElement (hHyperSpaceElement, &HyperSpaceElementPtr); - HyperSpaceElementPtr->current.image.frame = SetAbsFrameIndex ( - hyperstars[1 + (GET_GAME_STATE (ARILOU_SPACE_SIDE) >> 1)], - STAR_TYPE (star_type) - * NUM_STAR_COLORS - + STAR_COLOR (star_type) - ); - HyperSpaceElementPtr->preprocess_func = - HyperSpaceElementPtr->postprocess_func = NULL; - HyperSpaceElementPtr->collision_func = hyper_collision; + star_type = SDPtr->Type; - SetUpElement (HyperSpaceElementPtr); + LockElement (hHyperSpaceElement, &HyperSpaceElementPtr); + HyperSpaceElementPtr->current.image.frame = SetAbsFrameIndex ( + hyperstars[1 + (GET_GAME_STATE (ARILOU_SPACE_SIDE) >> 1)], + STAR_TYPE (star_type) * NUM_STAR_COLORS + + STAR_COLOR (star_type)); + HyperSpaceElementPtr->preprocess_func = NULL; + HyperSpaceElementPtr->postprocess_func = NULL; + HyperSpaceElementPtr->collision_func = hyper_collision; - if (SDPtr == CurStarDescPtr - && GET_GAME_STATE (PORTAL_COUNTER) == 0) - HyperSpaceElementPtr->death_func = hyper_death; - else - { - HyperSpaceElementPtr->death_func = NULL; - HyperSpaceElementPtr->IntersectControl.IntersectStamp.frame = - DecFrameIndex (stars_in_space); - } - UnlockElement (hHyperSpaceElement); + SetUpElement (HyperSpaceElementPtr); - InsertElement (hHyperSpaceElement, GetHeadElement ()); + if (SDPtr == CurStarDescPtr + && GET_GAME_STATE (PORTAL_COUNTER) == 0) + HyperSpaceElementPtr->death_func = hyper_death; + else + { + HyperSpaceElementPtr->death_func = NULL; + HyperSpaceElementPtr->IntersectControl.IntersectStamp.frame = + DecFrameIndex (stars_in_space); } + UnlockElement (hHyperSpaceElement); + + InsertElement (hHyperSpaceElement, GetHeadElement ()); } ProcessEncounters (&universe, ox, oy); } @@ -1740,3 +1734,4 @@ GLOBAL (ShipFacing) = StarShipPtr->ShipFacing + 1; UnlockElement (hSisElement); } + Modified: trunk/sc2/src/uqm/hyper.h =================================================================== --- trunk/sc2/src/uqm/hyper.h 2009-12-07 21:54:22 UTC (rev 3398) +++ trunk/sc2/src/uqm/hyper.h 2009-12-07 21:56:24 UTC (rev 3399) @@ -40,6 +40,27 @@ #define ARILOU_HOME_X (QUASI_SPACE_X + ((RADAR_SCAN_WIDTH >> 1) * 3)) #define ARILOU_HOME_Y (QUASI_SPACE_Y + ((RADAR_SCAN_HEIGHT >> 1) * 3)) +// HyperSpace coordinates of the locations where the QuasiSpace portals +// take you. +#define QUASISPACE_PORTALS_HYPERSPACE_ENDPOINTS \ + { \ + {4091, 7748}, \ + {3184, 4906}, \ + {9211, 6104}, \ + {5673, 1207}, \ + {1910, 926}, \ + {8607, 151}, \ + { 50, 1647}, \ + {6117, 4131}, \ + {5658, 9712}, \ + {2302, 3988}, \ + { 112, 9409}, \ + {7752, 8906}, \ + { 368, 6332}, \ + {9735, 3153}, \ + {5850, 6213}, \ + } + // Hyperspace coordinates of the Sol system // Should be the same as in plandata.c #define SOL_X 1752 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |