diff --git a/sc2/src/uqm/planets/lander.c b/sc2/src/uqm/planets/lander.c index f06b887c1..06aa0d55d 100644 --- a/sc2/src/uqm/planets/lander.c +++ b/sc2/src/uqm/planets/lander.c @@ -48,6 +48,35 @@ // ONE_SECOND. #define PLANET_SIDE_RATE (ONE_SECOND / 35) +// This is a derived type from INPUT_STATE_DESC. +// Originally, the general MENU_STATE structure was used. Now, only the +// fields which are relevant are put in here. In the MENU_STATE structure, +// these fields were reused for all sorts of purposes, which had nothing +// to do with what the name suggests. Not all fields have been renamed yet +// in LanderInputState. +typedef struct LanderInputState LanderInputState; +struct LanderInputState { + BOOLEAN (*InputFunc) (LanderInputState *pMS); + COUNT MenuRepeatDelay; + + PLANETSIDE_DESC *planetSideDesc; + SIZE Initialized; + MENU_STATE *scanInputState; + + // The following fields need to be renamed: + BYTE CurState; + // High byte: ? + // Low byte: ? + SIZE delta_item; + // High byte: ? + // Low byte: bits 0-6: current lander crew count + // bit 7: set if damage was prevented by a shield +}; + +LanderInputState *pLanderInputState; + // Temporary, to replace the references to pMenuState. + // Eventually, this should become a parameter to everything which + // needs it. FRAME LanderFrame[8]; static SOUND LanderSounds; @@ -111,8 +140,6 @@ const LIFEFORM_DESC CreatureData[] = // Zex's Beauty }; -#define FLASH_WIDTH 9 -#define FLASH_HEIGHT 9 extern PRIM_LINKS DisplayLinks; @@ -196,7 +223,8 @@ RepairTopography (ELEMENT *ElementPtr) r.corner.x += delta; r.extent.width -= delta; } - if ((ElementPtr->current.location.x += delta) < 0) + ElementPtr->current.location.x += delta; + if (ElementPtr->current.location.x < 0) ElementPtr->current.location.x += MAP_WIDTH; else if (ElementPtr->current.location.x >= MAP_WIDTH) ElementPtr->current.location.x -= MAP_WIDTH; @@ -211,7 +239,7 @@ RepairTopography (ELEMENT *ElementPtr) } ElementPtr->current.location.y += delta; - return (FALSE); + return FALSE; } static HELEMENT AddGroundDisaster (COUNT which_disaster); @@ -261,7 +289,7 @@ object_animation (ELEMENT *ElementPtr) /* A natural disaster */ if (ElementPtr->mass_points == DEATH_EXPLOSION) { - if (++pMenuState->CurState >= EXPLOSION_LIFE) + if (++pLanderInputState->CurState >= EXPLOSION_LIFE) pPrim->Object.Stamp.frame = DecFrameIndex (pPrim->Object.Stamp.frame); } @@ -347,7 +375,7 @@ object_animation (ELEMENT *ElementPtr) DetectPercent = (((BYTE)(CreatureData[index].Attributes & AWARENESS_MASK) >> AWARENESS_SHIFT) + 1) * (30 / 6); - // XXX: Shouldn't this be dependant on + // XXX: Shouldn't this be dependent on // PLANET_SIDE_RATE somehow? And why is it // written as '30 / 6' instead of 5? Does the 30 // specify the (PC) framerate? That doesn't make @@ -442,8 +470,9 @@ DeltaLanderCrew (SIZE crew_delta, COUNT which_disaster) if (crew_delta > 0) { - crew_delta = HIBYTE (pMenuState->delta_item); - pMenuState->delta_item += MAKE_WORD (0, 1); + // Filling up the crew bar when landing. + crew_delta = HIBYTE (pLanderInputState->delta_item); + pLanderInputState->delta_item += MAKE_WORD (0, 1); s.frame = SetAbsFrameIndex (LanderFrame[0], 55); } @@ -453,20 +482,24 @@ DeltaLanderCrew (SIZE crew_delta, COUNT which_disaster) ShieldFlags = GET_GAME_STATE (LANDER_SHIELDS); ShieldFlags &= 1 << which_disaster; - crew_delta = HIBYTE (pMenuState->delta_item); + crew_delta = HIBYTE (pLanderInputState->delta_item); if (crew_delta < 1) return; if (ShieldFlags && (BYTE)TFB_Random () < 256 * 95 / 100) - pMenuState->delta_item = SHIELD_BIT; + { + // Protected by a lander shield. + pLanderInputState->delta_item = SHIELD_BIT; + } else { + // Deal damage. ShieldFlags = 0; if (--crew_delta == 0) - pMenuState->CurState = 0; - pMenuState->delta_item = 0; + pLanderInputState->CurState = 0; + pLanderInputState->delta_item = 0; } - pMenuState->delta_item |= MAKE_WORD (DAMAGE_CYCLE, crew_delta); + pLanderInputState->delta_item |= MAKE_WORD (DAMAGE_CYCLE, crew_delta); if (ShieldFlags) return; @@ -557,7 +590,7 @@ CheckObjectCollision (COUNT index) index = GetSuccLink (DisplayLinks); } - pPSD = (PLANETSIDE_DESC*)pMenuState->ModuleFrame; + pPSD = pLanderInputState->planetSideDesc; LanderControl.EndPoint = LanderControl.IntersectStamp.origin; LanderHandle = GetFrameParentDrawable (LanderControl.IntersectStamp.frame); @@ -610,7 +643,7 @@ CheckObjectCollision (COUNT index) if (pLanderPrim == 0) { /* Collision of lander with another object */ - if (HIBYTE (pMenuState->delta_item) == 0 + if (HIBYTE (pLanderInputState->delta_item) == 0 || pPSD->InTransit) break; @@ -644,10 +677,11 @@ CheckObjectCollision (COUNT index) DeltaLanderCrew (-1, LANDER_INJURED); SleepThreadUntil (TimeIn + ONE_SECOND / 20); TimeIn = GetTimeCounter(); - } while (HIBYTE (pMenuState->delta_item) && --which_node); + } while (HIBYTE (pLanderInputState->delta_item) && + --which_node); } - if (HIBYTE (pMenuState->delta_item) + if (HIBYTE (pLanderInputState->delta_item) && pSolarSysState->SysInfo.PlanetInfo.DiscoveryString && CurStarDescPtr->Index != ANDROSYNTH_DEFINED) { @@ -682,8 +716,9 @@ CheckObjectCollision (COUNT index) danger_vals[dangerLevel]) { PlaySound (SetAbsSoundIndex ( - LanderSounds, BIOLOGICAL_DISASTER - ), NotPositional (), NULL, GAME_SOUND_PRIORITY); + LanderSounds, BIOLOGICAL_DISASTER), + NotPositional (), NULL, + GAME_SOUND_PRIORITY); DeltaLanderCrew (-1, BIOLOGICAL_DISASTER); } UnlockElement (hElement); @@ -738,8 +773,7 @@ CheckObjectCollision (COUNT index) DeltaVelocityComponents ( &ElementPtr->velocity, COSINE (angle, WORLD_TO_VELOCITY (1)), - SINE (angle, WORLD_TO_VELOCITY (1)) - ); + SINE (angle, WORLD_TO_VELOCITY (1))); ElementPtr->thrust_wait = 0; ElementPtr->mass_points |= CREATURE_AWARE; } @@ -914,11 +948,10 @@ lightning_process (ELEMENT *ElementPtr) if (ElementPtr->mass_points == LIGHTNING_DISASTER) { /* This one always strikes the lander and can hurt */ - if (HIBYTE (pMenuState->delta_item) + PLANETSIDE_DESC *pPSD = pLanderInputState->planetSideDesc; + if (HIBYTE (pLanderInputState->delta_item) && (BYTE)TFB_Random () < (256 / 10) - && !( - (PLANETSIDE_DESC*)pMenuState->ModuleFrame - )->InTransit) + && !pPSD->InTransit) lander_flags |= KILL_CREW; ElementPtr->next.location = @@ -1058,7 +1091,7 @@ BuildObjectList (void) lander_flags &= ~KILL_CREW; - pPSD = (PLANETSIDE_DESC*)pMenuState->ModuleFrame; + pPSD = pLanderInputState->planetSideDesc; rand_val = TFB_Random (); if (LOBYTE (HIWORD (rand_val)) < pPSD->FireChance) { @@ -1206,7 +1239,7 @@ RepairScan (void) DrawPlanet (0, 0, 0, 0); #endif DrawScannedObjects (TRUE); - drawPlanetCursor (pMenuState, FALSE); + drawPlanetCursor (pLanderInputState->scanInputState, FALSE); UnbatchGraphics (); SetContext (OldContext); @@ -1219,9 +1252,12 @@ ScrollPlanetSide (SIZE dx, SIZE dy, SIZE CountDown) STAMP lander_s, shadow_s, shield_s; CONTEXT OldContext; signed char lander_pos[] = { -10, 1, 12, 22, 31, 39, 45, 50, 54, 57, 59 }; + MENU_STATE *scanInputState = &pSolarSysState->MenuState; + // TODO: Make a new structure ScanInputState, like + // LanderInputState, instead of using MENU_STATE. - old_pt.x = pSolarSysState->MenuState.first_item.x - (SURFACE_WIDTH >> 1); - old_pt.y = pSolarSysState->MenuState.first_item.y - (SURFACE_HEIGHT >> 1); + old_pt.x = scanInputState->first_item.x - (SURFACE_WIDTH >> 1); + old_pt.y = scanInputState->first_item.y - (SURFACE_HEIGHT >> 1); new_pt.y = old_pt.y + dy; if (new_pt.y < -(SURFACE_HEIGHT >> 1)) @@ -1245,26 +1281,25 @@ ScrollPlanetSide (SIZE dx, SIZE dy, SIZE CountDown) else if (new_pt.x >= MAP_WIDTH << MAG_SHIFT) new_pt.x -= MAP_WIDTH << MAG_SHIFT; - new_pt.x = pSolarSysState->MenuState.first_item.x + dx; + new_pt.x = scanInputState->first_item.x + dx; if (new_pt.x < 0) new_pt.x += MAP_WIDTH << MAG_SHIFT; else if (new_pt.x >= MAP_WIDTH << MAG_SHIFT) new_pt.x -= MAP_WIDTH << MAG_SHIFT; - new_pt.y = pSolarSysState->MenuState.first_item.y + dy; + new_pt.y = scanInputState->first_item.y + dy; - pSolarSysState->MenuState.first_item = new_pt; + scanInputState->first_item = new_pt; { DWORD TimeIn; SleepThreadUntil (MAKE_DWORD ( - pSolarSysState->MenuState.flash_rect1.corner.x, - pSolarSysState->MenuState.flash_rect1.corner.y - )); + scanInputState->flash_rect1.corner.x, + scanInputState->flash_rect1.corner.y)); // planet-side rate is set here TimeIn = GetTimeCounter () + PLANET_SIDE_RATE; - pSolarSysState->MenuState.flash_rect1.corner.x = LOWORD (TimeIn); - pSolarSysState->MenuState.flash_rect1.corner.y = HIWORD (TimeIn); + scanInputState->flash_rect1.corner.x = LOWORD (TimeIn); + scanInputState->flash_rect1.corner.y = HIWORD (TimeIn); } LockMutex (GraphicsLock); @@ -1292,7 +1327,7 @@ ScrollPlanetSide (SIZE dx, SIZE dy, SIZE CountDown) DrawBatch (DisplayArray, DisplayLinks, 0); - if (pMenuState->delta_item || pMenuState->CurState < 3) + if (pLanderInputState->delta_item || pLanderInputState->CurState < 3) { BYTE damage_index; @@ -1312,11 +1347,12 @@ ScrollPlanetSide (SIZE dx, SIZE dy, SIZE CountDown) DrawFilledStamp (&shadow_s); } - if ((damage_index = LOBYTE (pMenuState->delta_item)) == 0) + damage_index = LOBYTE (pLanderInputState->delta_item); + if (damage_index == 0) DrawStamp (&lander_s); else { - --pMenuState->delta_item; + --pLanderInputState->delta_item; if (!(damage_index & SHIELD_BIT)) { SetContextForeGroundColor (DamageColorCycle (0, damage_index)); @@ -1324,20 +1360,18 @@ ScrollPlanetSide (SIZE dx, SIZE dy, SIZE CountDown) } else { - if ((damage_index = - (BYTE)((damage_index & ~SHIELD_BIT) - 1)) == 0) - pMenuState->delta_item &= ~SHIELD_BIT; + damage_index = (BYTE)((damage_index & ~SHIELD_BIT) - 1); + if (damage_index == 0) + pLanderInputState->delta_item &= ~SHIELD_BIT; else { shield_s.origin = lander_s.origin; shield_s.frame = SetEquFrameIndex ( - LanderFrame[4], - lander_s.frame - ); + LanderFrame[4], lander_s.frame); - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x1F, 0x1F, 0x1F) | 0x8000, damage_index) - ); + SetContextForeGroundColor (BUILD_COLOR ( + MAKE_RGB15 (0x1F, 0x1F, 0x1F) | 0x8000, + damage_index)); DrawFilledStamp (&shield_s); } DrawStamp (&lander_s); @@ -1346,14 +1380,14 @@ ScrollPlanetSide (SIZE dx, SIZE dy, SIZE CountDown) } if (CountDown < 0 - && HIBYTE (pMenuState->delta_item) + && HIBYTE (pLanderInputState->delta_item) && GetPredLink (DisplayLinks) != END_OF_LIST) CheckObjectCollision (END_OF_LIST); { PLANETSIDE_DESC *pPSD; - pPSD = (PLANETSIDE_DESC*)pMenuState->ModuleFrame; + pPSD = pLanderInputState->planetSideDesc; if (pPSD->NumFrames) { --pPSD->NumFrames; @@ -1362,16 +1396,20 @@ ScrollPlanetSide (SIZE dx, SIZE dy, SIZE CountDown) pPSD->MineralText[0].baseline.x -= dx; pPSD->MineralText[0].baseline.y -= dy; font_DrawText (&pPSD->MineralText[0]); - pPSD->MineralText[1].baseline.x = pPSD->MineralText[0].baseline.x; - pPSD->MineralText[1].baseline.y = pPSD->MineralText[0].baseline.y + 7; + pPSD->MineralText[1].baseline.x = + pPSD->MineralText[0].baseline.x; + pPSD->MineralText[1].baseline.y = + pPSD->MineralText[0].baseline.y + 7; font_DrawText (&pPSD->MineralText[1]); - pPSD->MineralText[2].baseline.x = pPSD->MineralText[1].baseline.x; - pPSD->MineralText[2].baseline.y = pPSD->MineralText[1].baseline.y + 7; + pPSD->MineralText[2].baseline.x = + pPSD->MineralText[1].baseline.x; + pPSD->MineralText[2].baseline.y = + pPSD->MineralText[1].baseline.y + 7; font_DrawText (&pPSD->MineralText[2]); } } - setPlanetCursorLoc (pMenuState, new_pt); + setPlanetCursorLoc (pLanderInputState->scanInputState, new_pt); RepairScan (); if (lander_flags & KILL_CREW) @@ -1592,285 +1630,277 @@ InitPlanetSide (void) SET_GAME_STATE (PLANETARY_LANDING, 1); } +static void +LanderFire (LanderInputState *inputState, SIZE index) { +#define SHUTTLE_FIRE_WAIT 15 + HELEMENT hWeaponElement; + SIZE wdx, wdy; + ELEMENT *WeaponElementPtr; + + hWeaponElement = AllocElement (); + if (hWeaponElement == NULL) + return; + + LockElement (hWeaponElement, &WeaponElementPtr); + + WeaponElementPtr->playerNr = PS_HUMAN_PLAYER; + WeaponElementPtr->mass_points = 1; + WeaponElementPtr->life_span = 12; + WeaponElementPtr->state_flags = FINITE_LIFE; + WeaponElementPtr->next.location = + pSolarSysState->MenuState.first_item; + WeaponElementPtr->current.location.x = + WeaponElementPtr->next.location.x >> MAG_SHIFT; + WeaponElementPtr->current.location.y = + WeaponElementPtr->next.location.y >> MAG_SHIFT; + + SetPrimType (&DisplayArray[WeaponElementPtr->PrimIndex], STAMP_PRIM); + DisplayArray[WeaponElementPtr->PrimIndex].Object.Stamp.frame = + SetAbsFrameIndex ( + LanderFrame[0], + index + ANGLE_TO_FACING (FULL_CIRCLE)); + + if (!CurrentInputState.key[PlayerControls[0]][KEY_UP]) + { + wdx = 0; + wdy = 0; + } + else + { + GetCurrentVelocityComponents (&GLOBAL (velocity), &wdx, &wdy); + } + + index = FACING_TO_ANGLE (index); + SetVelocityComponents ( + &WeaponElementPtr->velocity, + COSINE (index, WORLD_TO_VELOCITY (2 * 3)) + wdx, + SINE (index, WORLD_TO_VELOCITY (2 * 3)) + wdy); + + UnlockElement (hWeaponElement); + + InsertElement (hWeaponElement, GetHeadElement ()); + + PlaySound (SetAbsSoundIndex (LanderSounds, LANDER_SHOOTS), + NotPositional (), NULL, GAME_SOUND_PRIORITY); + + wdx = SHUTTLE_FIRE_WAIT; + if (GET_GAME_STATE (IMPROVED_LANDER_SHOT)) + wdx >>= 1; + inputState->CurState = MAKE_BYTE (LONIBBLE (inputState->CurState), wdx); +} + static BOOLEAN -DoPlanetSide (MENU_STATE *pMS) +DoPlanetSide (LanderInputState *pMS) { #define NUM_LANDING_DELTAS 10 #define SHUTTLE_TURN_WAIT 2 -#define SHUTTLE_FIRE_WAIT 15 - SIZE index; - if (GLOBAL (CurrentActivity) & CHECK_ABORT) return (FALSE); pMS->MenuRepeatDelay = 0; if (!pMS->Initialized) { + COUNT landerSpeedNumer; + COUNT angle; + pMS->Initialized = TRUE; pMS->CurState = 0; - index = FACING_TO_ANGLE (GetFrameIndex (LanderFrame[0])); - if (!GET_GAME_STATE (IMPROVED_LANDER_SPEED)) - SetVelocityComponents ( - &GLOBAL (velocity), - COSINE (index, WORLD_TO_VELOCITY (2 * 8)) / LANDER_SPEED_DENOM, - SINE (index, WORLD_TO_VELOCITY (2 * 8)) / LANDER_SPEED_DENOM - ); - else - SetVelocityComponents ( - &GLOBAL (velocity), - COSINE (index, WORLD_TO_VELOCITY (2 * 14)) / LANDER_SPEED_DENOM, - SINE (index, WORLD_TO_VELOCITY (2 * 14)) / LANDER_SPEED_DENOM - ); + angle = FACING_TO_ANGLE (GetFrameIndex (LanderFrame[0])); + landerSpeedNumer = GET_GAME_STATE (IMPROVED_LANDER_SPEED) ? + WORLD_TO_VELOCITY (2 * 14) : + WORLD_TO_VELOCITY (2 * 8); + #ifdef FAST_FAST -SetVelocityComponents ( - &GLOBAL (velocity), - COSINE (index, WORLD_TO_VELOCITY (48)) / LANDER_SPEED_DENOM, - SINE (index, WORLD_TO_VELOCITY (48)) / LANDER_SPEED_DENOM - ); +landerSpeedNumer = WORLD_TO_VELOCITY (48); #endif + + SetVelocityComponents (&GLOBAL (velocity), + COSINE (angle, WORLD_TO_VELOCITY (2 * 8)) / LANDER_SPEED_DENOM, + SINE (angle, WORLD_TO_VELOCITY (2 * 8)) / LANDER_SPEED_DENOM); } else if (pMS->delta_item == 0 || (HIBYTE (pMS->delta_item) && ((CurrentInputState.key[PlayerControls[0]][KEY_ESCAPE] || CurrentInputState.key[PlayerControls[0]][KEY_SPECIAL]) - || ((PLANETSIDE_DESC*)pMenuState->ModuleFrame)->InTransit))) + || pLanderInputState->planetSideDesc->InTransit))) { if (pMS->delta_item || pMS->CurState > EXPLOSION_LIFE + 60) - return (FALSE); - else + return FALSE; + + if (pMS->CurState > EXPLOSION_LIFE) + ++pMS->CurState; + else if (pMS->CurState == 0) { - if (pMS->CurState > EXPLOSION_LIFE) - ++pMS->CurState; - else if (pMS->CurState == 0) + HELEMENT hExplosionElement; + + hExplosionElement = AllocElement (); + if (hExplosionElement) { - HELEMENT hExplosionElement; + ELEMENT *ExplosionElementPtr; - hExplosionElement = AllocElement (); - if (hExplosionElement) - { - ELEMENT *ExplosionElementPtr; + // Advance the state only once we've got the element + ++pMS->CurState; - // Advance the state only once we've got the element - ++pMS->CurState; + LockElement (hExplosionElement, &ExplosionElementPtr); - LockElement (hExplosionElement, &ExplosionElementPtr); + ExplosionElementPtr->playerNr = PS_HUMAN_PLAYER; + ExplosionElementPtr->mass_points = DEATH_EXPLOSION; + ExplosionElementPtr->state_flags = FINITE_LIFE; + ExplosionElementPtr->next.location = + pSolarSysState->MenuState.first_item; + ExplosionElementPtr->preprocess_func = object_animation; + ExplosionElementPtr->turn_wait = MAKE_BYTE (2, 2); + ExplosionElementPtr->life_span = + EXPLOSION_LIFE + * (LONIBBLE (ExplosionElementPtr->turn_wait) + 1); - ExplosionElementPtr->playerNr = PS_HUMAN_PLAYER; - ExplosionElementPtr->mass_points = DEATH_EXPLOSION; - ExplosionElementPtr->state_flags = FINITE_LIFE; - ExplosionElementPtr->next.location = - pSolarSysState->MenuState.first_item; - ExplosionElementPtr->preprocess_func = object_animation; - ExplosionElementPtr->turn_wait = MAKE_BYTE (2, 2); - ExplosionElementPtr->life_span = - EXPLOSION_LIFE - * (LONIBBLE (ExplosionElementPtr->turn_wait) + 1); + SetPrimType (&DisplayArray[ExplosionElementPtr->PrimIndex], + STAMP_PRIM); + DisplayArray[ExplosionElementPtr->PrimIndex].Object.Stamp.frame = + SetAbsFrameIndex (LanderFrame[0], 46); - SetPrimType (&DisplayArray[ExplosionElementPtr->PrimIndex], STAMP_PRIM); - DisplayArray[ExplosionElementPtr->PrimIndex].Object.Stamp.frame = - SetAbsFrameIndex (LanderFrame[0], 46); + UnlockElement (hExplosionElement); - UnlockElement (hExplosionElement); + InsertElement (hExplosionElement, GetHeadElement ()); - InsertElement (hExplosionElement, GetHeadElement ()); - - PlaySound (SetAbsSoundIndex ( - LanderSounds, LANDER_DESTROYED - ), NotPositional (), NULL, GAME_SOUND_PRIORITY + 1); - } - else - { // We could not allocate because the queue was full, but - // we will get another chance on the next iteration - log_add (log_Warning, "DoPlanetSide(): could not" - " allocate explosion element!"); - } + PlaySound (SetAbsSoundIndex ( + LanderSounds, LANDER_DESTROYED + ), NotPositional (), NULL, GAME_SOUND_PRIORITY + 1); + } + else + { // We could not allocate because the queue was full, but + // we will get another chance on the next iteration + log_add (log_Warning, "DoPlanetSide(): could not" + " allocate explosion element!"); } - - ScrollPlanetSide (0, 0, -1); } + + ScrollPlanetSide (0, 0, -1); } else { SIZE dx, dy; if (HIBYTE (pMS->delta_item) == 0) - dx = dy = 0; + { + dx = 0; + dy = 0; + } else { - index = GetFrameIndex (LanderFrame[0]); + SIZE index = GetFrameIndex (LanderFrame[0]); if (LONIBBLE (pMS->CurState)) pMS->CurState -= MAKE_BYTE (1, 0); else if (CurrentInputState.key[PlayerControls[0]][KEY_LEFT] || CurrentInputState.key[PlayerControls[0]][KEY_RIGHT]) { + COUNT landerSpeedNumer; + COUNT angle; + if (CurrentInputState.key[PlayerControls[0]][KEY_LEFT]) - { - dx = -1; --index; - } else - { - dx = +1; ++index; - } index = NORMALIZE_FACING (index); LanderFrame[0] = SetAbsFrameIndex (LanderFrame[0], index); - dx = FACING_TO_ANGLE (index); - if (!GET_GAME_STATE (IMPROVED_LANDER_SPEED)) - SetVelocityComponents ( - &GLOBAL (velocity), - COSINE (dx, WORLD_TO_VELOCITY (2 * 8)) / LANDER_SPEED_DENOM, - SINE (dx, WORLD_TO_VELOCITY (2 * 8)) / LANDER_SPEED_DENOM - ); - else - SetVelocityComponents ( - &GLOBAL (velocity), - COSINE (dx, WORLD_TO_VELOCITY (2 * 14)) / LANDER_SPEED_DENOM, - SINE (dx, WORLD_TO_VELOCITY (2 * 14)) / LANDER_SPEED_DENOM - ); + angle = FACING_TO_ANGLE (index); + landerSpeedNumer = GET_GAME_STATE (IMPROVED_LANDER_SPEED) ? + WORLD_TO_VELOCITY (2 * 14) : + WORLD_TO_VELOCITY (2 * 8); + #ifdef FAST_FAST -SetVelocityComponents ( - &GLOBAL (velocity), - COSINE (dx, WORLD_TO_VELOCITY (48)) / LANDER_SPEED_DENOM, - SINE (dx, WORLD_TO_VELOCITY (48)) / LANDER_SPEED_DENOM - ); +landerSpeedNumer = WORLD_TO_VELOCITY (48); #endif + SetVelocityComponents (&GLOBAL (velocity), + COSINE (angle, landerSpeedNumer) / LANDER_SPEED_DENOM, + SINE (angle, landerSpeedNumer) / LANDER_SPEED_DENOM); + pMS->CurState = MAKE_BYTE ( - SHUTTLE_TURN_WAIT, HINIBBLE (pMS->CurState) - ); + SHUTTLE_TURN_WAIT, HINIBBLE (pMS->CurState)); } if (!CurrentInputState.key[PlayerControls[0]][KEY_UP]) - dx = dy = 0; + { + dx = 0; + dy = 0; + } else - GetNextVelocityComponents ( - &GLOBAL (velocity), &dx, &dy, 1 - ); + GetNextVelocityComponents (&GLOBAL (velocity), &dx, &dy, 1); if (HINIBBLE (pMS->CurState)) pMS->CurState -= MAKE_BYTE (0, 1); else if (CurrentInputState.key[PlayerControls[0]][KEY_WEAPON]) { - HELEMENT hWeaponElement; - - hWeaponElement = AllocElement (); - if (hWeaponElement) - { - SIZE wdx, wdy; - ELEMENT *WeaponElementPtr; - - LockElement (hWeaponElement, &WeaponElementPtr); - - WeaponElementPtr->playerNr = PS_HUMAN_PLAYER; - WeaponElementPtr->mass_points = 1; - WeaponElementPtr->life_span = 12; - WeaponElementPtr->state_flags = FINITE_LIFE; - WeaponElementPtr->next.location = - pSolarSysState->MenuState.first_item; - WeaponElementPtr->current.location.x = - WeaponElementPtr->next.location.x >> MAG_SHIFT; - WeaponElementPtr->current.location.y = - WeaponElementPtr->next.location.y >> MAG_SHIFT; - - SetPrimType (&DisplayArray[WeaponElementPtr->PrimIndex], STAMP_PRIM); - DisplayArray[WeaponElementPtr->PrimIndex].Object.Stamp.frame = - SetAbsFrameIndex ( - LanderFrame[0], - index + ANGLE_TO_FACING (FULL_CIRCLE) - ); - - if (!CurrentInputState.key[PlayerControls[0]][KEY_UP]) - wdx = wdy = 0; - else - GetCurrentVelocityComponents ( - &GLOBAL (velocity), &wdx, &wdy - ); - index = FACING_TO_ANGLE (index); - SetVelocityComponents ( - &WeaponElementPtr->velocity, - COSINE (index, WORLD_TO_VELOCITY (2 * 3)) + wdx, - SINE (index, WORLD_TO_VELOCITY (2 * 3)) + wdy - ); - - UnlockElement (hWeaponElement); - - InsertElement (hWeaponElement, GetHeadElement ()); - - PlaySound (SetAbsSoundIndex ( - LanderSounds, LANDER_SHOOTS - ), NotPositional (), NULL, GAME_SOUND_PRIORITY); - - wdx = SHUTTLE_FIRE_WAIT; - if (GET_GAME_STATE (IMPROVED_LANDER_SHOT)) - wdx >>= 1; - pMS->CurState = MAKE_BYTE (LONIBBLE (pMS->CurState), wdx); - } + LanderFire (pMS, index); } } ScrollPlanetSide (dx, dy, -1); } - return (TRUE); + return TRUE; } void FreeLanderData (void) { - if (LanderFrame[0]) + COUNT i; + COUNT landerFrameCount; + + if (LanderFrame[0] == NULL) + return; + + for (i = 0; i < NUM_ORBIT_THEMES; ++i) { - COUNT i; + DestroyMusic (OrbitMusic[i]); + OrbitMusic[i] = 0; + } - for (i = 0; i < NUM_ORBIT_THEMES; ++i) - { - DestroyMusic (OrbitMusic[i]); - OrbitMusic[i] = 0; - } - DestroySound (ReleaseSound (LanderSounds)); - LanderSounds = 0; + DestroySound (ReleaseSound (LanderSounds)); + LanderSounds = 0; - for (i = 0; i < sizeof (LanderFrame) - / sizeof (LanderFrame[0]); ++i) - { - DestroyDrawable (ReleaseDrawable (LanderFrame[i])); - LanderFrame[i] = 0; - } + landerFrameCount = sizeof (LanderFrame) / sizeof (LanderFrame[0]); + for (i = 0; i < landerFrameCount; ++i) + { + DestroyDrawable (ReleaseDrawable (LanderFrame[i])); + LanderFrame[i] = 0; } } void LoadLanderData (void) { - if (LanderFrame[0] == 0) + if (LanderFrame[0] != 0) + return; + + LanderFrame[0] = + CaptureDrawable (LoadGraphic (LANDER_MASK_PMAP_ANIM)); + LanderFrame[1] = + CaptureDrawable (LoadGraphic (QUAKE_MASK_PMAP_ANIM)); + LanderFrame[2] = + CaptureDrawable (LoadGraphic (LIGHTNING_MASK_ANIM)); + LanderFrame[3] = + CaptureDrawable (LoadGraphic (LAVA_MASK_PMAP_ANIM)); + LanderFrame[4] = + CaptureDrawable (LoadGraphic (LANDER_SHIELD_MASK_ANIM)); + LanderFrame[5] = + CaptureDrawable (LoadGraphic (LANDER_LAUNCH_MASK_PMAP_ANIM)); + LanderFrame[6] = + CaptureDrawable (LoadGraphic (LANDER_RETURN_MASK_PMAP_ANIM)); + LanderFrame[7] = + CaptureDrawable (LoadGraphic (ORBIT_VIEW_ANIM)); + + LanderSounds = CaptureSound (LoadSound (LANDER_SOUNDS)); + { - LanderFrame[0] = - CaptureDrawable (LoadGraphic (LANDER_MASK_PMAP_ANIM)); - LanderFrame[1] = - CaptureDrawable (LoadGraphic (QUAKE_MASK_PMAP_ANIM)); - LanderFrame[2] = - CaptureDrawable (LoadGraphic (LIGHTNING_MASK_ANIM)); - LanderFrame[3] = - CaptureDrawable (LoadGraphic (LAVA_MASK_PMAP_ANIM)); - LanderFrame[4] = CaptureDrawable (LoadGraphic (LANDER_SHIELD_MASK_ANIM)); - LanderFrame[5] = - CaptureDrawable (LoadGraphic (LANDER_LAUNCH_MASK_PMAP_ANIM)); - LanderFrame[6] = - CaptureDrawable (LoadGraphic (LANDER_RETURN_MASK_PMAP_ANIM)); - LanderSounds = CaptureSound (LoadSound (LANDER_SOUNDS)); + COUNT i; - LanderFrame[7] = - CaptureDrawable (LoadGraphic (ORBIT_VIEW_ANIM)); - - { - COUNT i; - - for (i = 0; i < NUM_ORBIT_THEMES; ++i) - OrbitMusic[i] = load_orbit_theme (i); - } + for (i = 0; i < NUM_ORBIT_THEMES; ++i) + OrbitMusic[i] = load_orbit_theme (i); } } @@ -1910,6 +1940,7 @@ PlanetSide (MENU_STATE *pMS) { SIZE index; DWORD TimeIn; + LanderInputState landerInputState; PLANETSIDE_DESC PSD; BYTE TectonicsChanceTab[] = {0*3, 0*3, 1*3, 2*3, 4*3, 8*3, 16*3, 32*3}; BYTE WeatherChanceTab[] = {0*3, 0*3, 1*3, 2*3, 3*3, 6*3, 12*3, 24*3}; @@ -1959,7 +1990,10 @@ PlanetSide (MENU_STATE *pMS) PSD.ColorCycle[2] = BUILD_COLOR (MAKE_RGB15 (0x1F, 0x11, 0x00), 0x7B); PSD.ColorCycle[3] = BUILD_COLOR (MAKE_RGB15 (0x1F, 0x1F, 0x00), 0x71); for (index = 4; index < (NUM_TEXT_FRAMES >> 1) - 4; ++index) - PSD.ColorCycle[index] = BUILD_COLOR (MAKE_RGB15 (0x1F, 0x1F, 0x1F), 0x0F); + { + PSD.ColorCycle[index] = + BUILD_COLOR (MAKE_RGB15 (0x1F, 0x1F, 0x1F), 0x0F); + } PSD.ColorCycle[(NUM_TEXT_FRAMES >> 1) - 4] = BUILD_COLOR (MAKE_RGB15 (0x1F, 0x1F, 0x00), 0x71); PSD.ColorCycle[(NUM_TEXT_FRAMES >> 1) - 3] = @@ -1968,13 +2002,15 @@ PlanetSide (MENU_STATE *pMS) BUILD_COLOR (MAKE_RGB15 (0x1F, 0x0A, 0x00), 0x7D); PSD.ColorCycle[(NUM_TEXT_FRAMES >> 1) - 1] = BUILD_COLOR (MAKE_RGB15 (0x1F, 0x03, 0x00), 0x7F); - pMS->ModuleFrame = (FRAME)&PSD; + landerInputState.planetSideDesc = &PSD; + + // ScrollPlanetSide depends on this. Not just DoPlanetSide(). + pLanderInputState = &landerInputState; + landerInputState.scanInputState = pMS; index = NORMALIZE_FACING ((COUNT)TFB_Random ()); - LanderFrame[0] = SetAbsFrameIndex ( - LanderFrame[0], index - ); - pMS->delta_item = 0; + LanderFrame[0] = SetAbsFrameIndex (LanderFrame[0], index); + landerInputState.delta_item = 0; pSolarSysState->MenuState.Initialized += 4; InitPlanetSide (); @@ -2000,10 +2036,10 @@ PlanetSide (MENU_STATE *pMS) pSolarSysState->MenuState.flash_rect1.corner.x = LOWORD (TimeIn); pSolarSysState->MenuState.flash_rect1.corner.y = HIWORD (TimeIn); - pMS->Initialized = FALSE; - pMS->InputFunc = DoPlanetSide; + landerInputState.Initialized = FALSE; + landerInputState.InputFunc = DoPlanetSide; SetMenuSounds (MENU_SOUND_NONE, MENU_SOUND_NONE); - DoInput (pMS, FALSE); + DoInput (&landerInputState, FALSE); if (!(GLOBAL (CurrentActivity) & CHECK_ABORT)) { @@ -2011,7 +2047,7 @@ PlanetSide (MENU_STATE *pMS) RECT r; //CONTEXT OldContext; - crew_left = HIBYTE (pMS->delta_item); + crew_left = HIBYTE (landerInputState.delta_item); r.corner.x = SIS_ORG_X; r.corner.y = SIS_ORG_Y; @@ -2083,7 +2119,7 @@ PlanetSide (MENU_STATE *pMS) } } - pMS->ModuleFrame = 0; + landerInputState.planetSideDesc = NULL; { HELEMENT hElement, hNextElement; diff --git a/sc2/src/uqm/planets/lander.h b/sc2/src/uqm/planets/lander.h index 2773f19f9..21b69d3bd 100644 --- a/sc2/src/uqm/planets/lander.h +++ b/sc2/src/uqm/planets/lander.h @@ -37,8 +37,9 @@ typedef struct SOUND OldMenuSounds; - COUNT ElementLevel, MaxElementLevel, - BiologicalLevel; + COUNT ElementLevel; + COUNT MaxElementLevel; + COUNT BiologicalLevel; COUNT ElementAmounts[NUM_ELEMENT_CATEGORIES]; COUNT NumFrames; @@ -47,7 +48,9 @@ typedef struct COLOR ColorCycle[NUM_TEXT_FRAMES >> 1]; - BYTE TectonicsChance, WeatherChance, FireChance; + BYTE TectonicsChance; + BYTE WeatherChance; + BYTE FireChance; } PLANETSIDE_DESC; extern CONTEXT ScanContext; diff --git a/sc2/src/uqm/planets/scan.c b/sc2/src/uqm/planets/scan.c index 4bf8a3645..04c1ba486 100644 --- a/sc2/src/uqm/planets/scan.c +++ b/sc2/src/uqm/planets/scan.c @@ -670,8 +670,7 @@ PickPlanetSide (MENU_STATE *pMS) COUNT fuel_required; fuel_required = (COUNT)( - pSolarSysState->SysInfo.PlanetInfo.SurfaceGravity << 1 - ); + pSolarSysState->SysInfo.PlanetInfo.SurfaceGravity << 1); if (fuel_required > 3 * FUEL_TANK_SCALE) fuel_required = 3 * FUEL_TANK_SCALE;