From d4256685867117ee9289230db91ebe1ebc469fca Mon Sep 17 00:00:00 2001 From: meep-eep Date: Mon, 25 Sep 2006 22:57:16 +0000 Subject: [PATCH] Cleanups and some documentation. git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2444 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/sc2code/comm.c | 80 ++++------ sc2/src/sc2code/comm/ilwrath/ilwrathc.c | 3 + sc2/src/sc2code/globdata.h | 11 +- sc2/src/sc2code/planets/devices.c | 203 +++++++++++++----------- 4 files changed, 157 insertions(+), 140 deletions(-) diff --git a/sc2/src/sc2code/comm.c b/sc2/src/sc2code/comm.c index 6cdf82a7d..fc5f84bee 100644 --- a/sc2/src/sc2code/comm.c +++ b/sc2/src/sc2code/comm.c @@ -716,7 +716,8 @@ ambient_anim_task (void *data) BOOLEAN FrameChanged[MAX_ANIMATIONS]; BOOLEAN ColorChange = FALSE; - while ((CommFrame = CommData.AlienFrame) == 0 && !Task_ReadState (task, TASK_EXIT)) + while ((CommFrame = CommData.AlienFrame) == 0 + && !Task_ReadState (task, TASK_EXIT)) TaskSwitch (); LockMutex (GraphicsLock); @@ -733,16 +734,12 @@ ambient_anim_task (void *data) memset (AnimFrame, 0, sizeof (AnimFrame)); for (i = 0; i <= CommData.NumAnimations; i++) if (CommData.AlienAmbientArray[i].AnimFlags & YOYO_ANIM) - AnimFrame[i] = SetAbsFrameIndex ( - CommFrame, - CommData.AlienAmbientArray[i].StartIndex - ); + AnimFrame[i] = SetAbsFrameIndex (CommFrame, + CommData.AlienAmbientArray[i].StartIndex); else - AnimFrame[i] = SetAbsFrameIndex ( - CommFrame, + AnimFrame[i] = SetAbsFrameIndex (CommFrame, (COUNT)(CommData.AlienAmbientArray[i].StartIndex - + CommData.AlienAmbientArray[i].NumFrames - 1) - ); + + CommData.AlienAmbientArray[i].NumFrames - 1)); while (!Task_ReadState (task, TASK_EXIT)) { @@ -791,30 +788,24 @@ ambient_anim_task (void *data) && pSeq->Direction == UP_DIR))) { ActiveMask |= 1L << i; - pSeq->Alarm = - ADPtr->BaseFrameRate + pSeq->Alarm = ADPtr->BaseFrameRate + ((COUNT)TFB_Random () - % (ADPtr->RandomFrameRate + 1)) - + 1; + % (ADPtr->RandomFrameRate + 1)) + 1; } else { ActiveMask &= ~(1L << i); - pSeq->Alarm = - ADPtr->BaseRestartRate + pSeq->Alarm = ADPtr->BaseRestartRate + ((COUNT)TFB_Random () - % (ADPtr->RandomRestartRate + 1)) - + 1; + % (ADPtr->RandomRestartRate + 1)) + 1; if (ActiveMask & ADPtr->BlockMask) continue; } if (pSeq->AnimType == COLOR_ANIM) { - XFormColorMap ( - GetColorMapAddress (pSeq->AnimObj.CurCMap), - (COUNT) (pSeq->Alarm - 1) - ); + XFormColorMap (GetColorMapAddress (pSeq->AnimObj.CurCMap), + (COUNT) (pSeq->Alarm - 1)); } else { @@ -837,14 +828,12 @@ ambient_anim_task (void *data) if (pSeq->AnimType == COLOR_ANIM) pSeq->AnimObj.CurCMap = SetRelColorMapIndex ( pSeq->AnimObj.CurCMap, - (SWORD) (-pSeq->FramesLeft) - ); + (SWORD) (-pSeq->FramesLeft)); else { pSeq->AnimObj.CurFrame = SetRelFrameIndex ( pSeq->AnimObj.CurFrame, - (SWORD) (-pSeq->FramesLeft) - ); + (SWORD) (-pSeq->FramesLeft)); } } } @@ -868,12 +857,10 @@ ambient_anim_task (void *data) { if (pSeq->Direction == UP_DIR) pSeq->AnimObj.CurCMap = SetRelColorMapIndex ( - pSeq->AnimObj.CurCMap, 1 - ); + pSeq->AnimObj.CurCMap, 1); else pSeq->AnimObj.CurCMap = SetRelColorMapIndex ( - pSeq->AnimObj.CurCMap, -1 - ); + pSeq->AnimObj.CurCMap, -1); } else { @@ -909,12 +896,12 @@ ambient_anim_task (void *data) && (ADPtr->AnimFlags & WAIT_TALKING) && !(CommData.AlienTransitionDesc.AnimFlags & PAUSE_TALKING)) { - BOOLEAN done = 0; + BOOLEAN done = FALSE; for (i = 0; i < CommData.NumAnimations; i++) if (ActiveMask & (1L << i) && CommData.AlienAmbientArray[i].AnimFlags & WAIT_TALKING) - done = 1; - if (! done) + done = TRUE; + if (!done) { if (ADPtr->StartIndex != TalkBuffer.StartIndex) @@ -968,12 +955,10 @@ ambient_anim_task (void *data) { CommData.AlienTransitionDesc.AnimFlags |= PAUSE_TALKING; - ADPtr->AnimFlags &= - ~PAUSE_TALKING; + ADPtr->AnimFlags &= ~PAUSE_TALKING; } else if (CommData.AlienTransitionDesc.NumFrames) - ADPtr->AnimFlags |= - TALK_DONE; + ADPtr->AnimFlags |= TALK_DONE; else ADPtr->AnimFlags &= ~(WAIT_TALKING | PAUSE_TALKING); @@ -987,15 +972,14 @@ ambient_anim_task (void *data) ADPtr = &CommData.AlienTransitionDesc; if (AFlags & TALK_INTRO) { - FrameRate = - ADPtr->BaseFrameRate + FrameRate = ADPtr->BaseFrameRate + ((COUNT)TFB_Random () % (ADPtr->RandomFrameRate + 1)); if (TalkAlarm < 0 || TransitionDone) { TalkFrame = SetAbsFrameIndex (CommFrame, ADPtr->StartIndex); - TransitionDone = 0; + TransitionDone = FALSE; } else TalkFrame = IncFrameIndex (TalkFrame); @@ -1005,14 +989,13 @@ ambient_anim_task (void *data) ADPtr->NumFrames) { CommData.AlienTalkDesc.AnimFlags &= ~TALK_INTRO; - TransitionDone = 1; + TransitionDone = TRUE; } TransitionFrame = TalkFrame; } else /* if (AFlags & TALK_DONE) */ { - FrameRate = - ADPtr->BaseFrameRate + FrameRate = ADPtr->BaseFrameRate + ((COUNT)TFB_Random () % (ADPtr->RandomFrameRate + 1)); if (TalkAlarm < 0) @@ -1031,8 +1014,7 @@ ambient_anim_task (void *data) CommData.AlienTalkDesc.AnimFlags &= ~WAIT_TALKING; else { - ADPtr->AnimFlags |= - PAUSE_TALKING; + ADPtr->AnimFlags |= PAUSE_TALKING; ADPtr->AnimFlags &= ~TALK_DONE; } FrameRate = 0; @@ -1049,7 +1031,7 @@ ambient_anim_task (void *data) } else if (done && (ADPtr->AnimFlags & PAUSE_TALKING)) { - ADPtr->AnimFlags &= ~(WAIT_TALKING | PAUSE_TALKING); + ADPtr->AnimFlags &= ~(WAIT_TALKING | PAUSE_TALKING); } } @@ -1074,7 +1056,8 @@ ambient_anim_task (void *data) FRAME F; F = CommData.AlienFrame; CommData.AlienFrame = CommFrame; - DrawAlienFrame (TalkFrame, &Sequencer[CommData.NumAnimations - 1]); + DrawAlienFrame (TalkFrame, + &Sequencer[CommData.NumAnimations - 1]); CommData.AlienFrame = F; CheckSub = TRUE; ClearSub = ClearSummary; @@ -2048,8 +2031,8 @@ InitCommunication (RESOURCE which_comm) SetResourceIndex (hIndex); LocDataPtr = (LOCDATAPTR)init_race ( - status != YEHAT_REBEL_SHIP ? which_comm : (RESOURCE)YEHAT_REBEL_CONVERSATION - ); + status != YEHAT_REBEL_SHIP ? which_comm : + (RESOURCE)YEHAT_REBEL_CONVERSATION); if (LocDataPtr) CommData = *LocDataPtr; } @@ -2156,6 +2139,7 @@ RaceCommunication (void) else if (GET_GAME_STATE (GLOBAL_FLAGS_AND_DATA) == 0) InitCommunication (TALKING_PET_CONVERSATION); else if (GET_GAME_STATE (GLOBAL_FLAGS_AND_DATA) & ((1 << 4) | (1 << 5))) + // Communicate with the Ilwrath using a Hyperwave Broadcaster. InitCommunication (ILWRATH_CONVERSATION); else InitCommunication (CHMMR_CONVERSATION); diff --git a/sc2/src/sc2code/comm/ilwrath/ilwrathc.c b/sc2/src/sc2code/comm/ilwrath/ilwrathc.c index b81f82e54..ae9f9846d 100644 --- a/sc2/src/sc2code/comm/ilwrath/ilwrathc.c +++ b/sc2/src/sc2code/comm/ilwrath/ilwrathc.c @@ -572,6 +572,7 @@ Intro (void) } else if (GET_GAME_STATE (GLOBAL_FLAGS_AND_DATA) & (1 << 5)) { + // Communicating with an Ilwrath ship using a HyperWave Broadcaster. if (GET_GAME_STATE (ILWRATH_FIGHT_THRADDASH)) NPCPhrase (BIG_FUN); else if (GET_GAME_STATE (ILWRATH_DECEIVED)) @@ -583,6 +584,8 @@ Intro (void) } else if (GET_GAME_STATE (GLOBAL_FLAGS_AND_DATA) & (1 << 4)) { + // Communicating with the Ilwrath homeworld using a + // Hyperwave Broadcaster. GodsSpeak ((RESPONSE_REF)0); } else diff --git a/sc2/src/sc2code/globdata.h b/sc2/src/sc2code/globdata.h index d885f0813..fdbab217e 100644 --- a/sc2/src/sc2code/globdata.h +++ b/sc2/src/sc2code/globdata.h @@ -457,6 +457,11 @@ START_GAME_STATE * Why this needs 8 bits I don't know. Only specific * combinations of bits seem to be used (0, 1, or all bits). * A closer investigation is desirable. - SvdB + * Bit 4 is set when initiating communication with the Ilwrath + * homeworld by means of a HyperWave Broadcaster. + * Bit 5 is set when initiating communication with an Ilwrath + * ship by means of a HyperWave Broadcaster. + * All bits are cleared when communication is over. */ ADD_GAME_STATE (ORZ_VISITS, 3) @@ -605,7 +610,7 @@ START_GAME_STATE * with RAINBOW_DEFINED, and so on. */ ADD_GAME_STATE (RAINBOW_WORLD1, 2) - /* High byte of the bit array of which RAINBOW_WORLD0 + /* High 2 bits of the bit array of which RAINBOW_WORLD0 * is the low byte. */ ADD_GAME_STATE (MELNORME_RAINBOW_COUNT, 4) @@ -701,6 +706,10 @@ START_GAME_STATE ADD_GAME_STATE (TALKING_PET_SUGGESTIONS, 3) ADD_GAME_STATE (LEARNED_TALKING_PET, 1) ADD_GAME_STATE (DNYARRI_LIED, 1) + /* Set when the Talking Pet tells you his version of their + * race's history with the Ur-Quan. + * Cleared once you confront him about this lie. + */ ADD_GAME_STATE (SHIP_TO_COMPEL, 1) ADD_GAME_STATE (ORZ_GENERAL_INFO, 2) diff --git a/sc2/src/sc2code/planets/devices.c b/sc2/src/sc2code/planets/devices.c index 37d8539e4..fa376db90 100644 --- a/sc2/src/sc2code/planets/devices.c +++ b/sc2/src/sc2code/planets/devices.c @@ -71,7 +71,8 @@ DrawDevices (PMENU_STATE pMS, BYTE OldDevice, BYTE NewDevice) r.extent.width -= 2; r.corner.y = 33; r.extent.height = 89; - SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x14), 0x01)); + SetContextForeGroundColor ( + BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x14), 0x01)); DrawFilledRectangle (&r); } else @@ -92,7 +93,8 @@ DrawDevices (PMENU_STATE pMS, BYTE OldDevice, BYTE NewDevice) ct.align = ALIGN_CENTER; ct.pStr = GAME_STRING (DEVICE_STRING_BASE); ct.CharCount = (COUNT)~0; - SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0xA, 0x1F, 0x1F), 0x0B)); + SetContextForeGroundColor ( + BUILD_COLOR (MAKE_RGB15 (0xA, 0x1F, 0x1F), 0x0B)); font_DrawText (&ct); SetContextFont (TinyFont); @@ -107,15 +109,15 @@ DrawDevices (PMENU_STATE pMS, BYTE OldDevice, BYTE NewDevice) s.origin.y = 34; cy = y; - SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x14), 0x03)); + SetContextForeGroundColor ( + BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x14), 0x03)); for (OldDevice = (BYTE)pMS->first_item.y; OldDevice < (BYTE)(pMS->first_item.y + MAX_VIS_DEVICES) && OldDevice < (BYTE)pMS->first_item.x; ++OldDevice) { s.frame = SetAbsFrameIndex ( - MiscDataFrame, 77 + pDeviceMap[OldDevice] - ); + MiscDataFrame, 77 + pDeviceMap[OldDevice]); DrawStamp (&s); if (OldDevice != NewDevice) @@ -146,10 +148,12 @@ DrawDevices (PMENU_STATE pMS, BYTE OldDevice, BYTE NewDevice) { cy = y + ((OldDevice - pMS->first_item.y) * 18); r.corner.y = cy - 6; - SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x14), 0x01)); + SetContextForeGroundColor ( + BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x14), 0x01)); DrawFilledRectangle (&r); - SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x14), 0x03)); + SetContextForeGroundColor ( + BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x14), 0x03)); t.baseline.y = cy; t.pStr = GAME_STRING (pDeviceMap[OldDevice] + DEVICE_STRING_BASE + 1); t.CharCount = utf8StringPos (t.pStr, ' '); @@ -164,10 +168,12 @@ DrawDevices (PMENU_STATE pMS, BYTE OldDevice, BYTE NewDevice) { cy = y + ((NewDevice - pMS->first_item.y) * 18); r.corner.y = cy - 6; - SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0xA, 0xA, 0x1F), 0x09)); + SetContextForeGroundColor ( + BUILD_COLOR (MAKE_RGB15 (0xA, 0xA, 0x1F), 0x09)); DrawFilledRectangle (&r); - SetContextForeGroundColor (BUILD_COLOR (MAKE_RGB15 (0xA, 0x1F, 0x1F), 0x0B)); + SetContextForeGroundColor ( + BUILD_COLOR (MAKE_RGB15 (0xA, 0x1F, 0x1F), 0x0B)); t.baseline.y = cy; t.pStr = GAME_STRING (pDeviceMap[NewDevice] + DEVICE_STRING_BASE + 1); t.CharCount = utf8StringPos (t.pStr, ' '); @@ -181,6 +187,92 @@ DrawDevices (PMENU_STATE pMS, BYTE OldDevice, BYTE NewDevice) UnlockMutex (GraphicsLock); } +// Returns TRUE if the broadcaster has been successfully activated, +// and FALSE otherwise. +static BOOLEAN +UseCaster (void) +{ + if (LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE) + { + if (GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1) + { + SET_GAME_STATE (USED_BROADCASTER, 1); + return TRUE; + } + return FALSE; + } + + if (LOBYTE (GLOBAL (CurrentActivity)) != IN_INTERPLANETARY + || pSolarSysState != NULL) + return FALSE; + + if (pSolarSysState->pOrbitalDesc == &pSolarSysState->PlanetDesc[1] + && pSolarSysState->MenuState.Initialized == 3 + && CurStarDescPtr->Index == CHMMR_DEFINED + && !GET_GAME_STATE (CHMMR_UNLEASHED)) + { + // In orbit around the Chenjesu/Mmrnmhrm home planet. + NextActivity |= CHECK_LOAD; /* fake a load game */ + GLOBAL (CurrentActivity) |= START_ENCOUNTER; + + EncounterGroup = 0; + PutGroupInfo (GROUPS_RANDOM, GROUP_SAVE_IP); + ReinitQueue (&GLOBAL (npc_built_ship_q)); + + SET_GAME_STATE (GLOBAL_FLAGS_AND_DATA, 1 << 7); + SaveFlagshipState (); + return TRUE; + } + + { + BOOLEAN FoundIlwrath; + HSTARSHIP hStarShip; + + FoundIlwrath = (BOOLEAN)(CurStarDescPtr->Index == ILWRATH_DEFINED); + // In the Ilwrath home system? + + if (!FoundIlwrath && + (hStarShip = GetHeadLink (&GLOBAL (npc_built_ship_q)))) + { + // Ilwrath ship is in the system. + SHIP_FRAGMENTPTR FragPtr; + + FragPtr = (SHIP_FRAGMENTPTR)LockStarShip ( + &GLOBAL (npc_built_ship_q), hStarShip); + FoundIlwrath = (BOOLEAN)( + GET_RACE_ID (FragPtr) == ILWRATH_SHIP); + UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip); + } + + if (FoundIlwrath) + { + NextActivity |= CHECK_LOAD; /* fake a load game */ + GLOBAL (CurrentActivity) |= START_ENCOUNTER; + + EncounterGroup = 0; + PutGroupInfo (GROUPS_RANDOM, GROUP_SAVE_IP); + ReinitQueue (&GLOBAL (npc_built_ship_q)); + + if (CurStarDescPtr->Index == ILWRATH_DEFINED) + { + // Ilwrath home system. + SET_GAME_STATE (GLOBAL_FLAGS_AND_DATA, 1 << 4); + } + else + { + // Ilwrath ship. + SET_GAME_STATE (GLOBAL_FLAGS_AND_DATA, 1 << 5); + } + + if (pSolarSysState->MenuState.Initialized >= 3) + SaveFlagshipState (); + return TRUE; + } + } + + return FALSE; +} + static UWORD DeviceFailed (BYTE which_device) { @@ -213,7 +305,8 @@ DeviceFailed (BYTE which_device) PlayMenuSound (MENU_SOUND_INVOKED); fade_buf[0] = FadeAllToWhite; - SleepThreadUntil (XFormColorMap ((COLORMAPPTR)fade_buf, ONE_SECOND * 1) + SleepThreadUntil ( + XFormColorMap ((COLORMAPPTR)fade_buf, ONE_SECOND * 1) + (ONE_SECOND * 2)); if (CurStarDescPtr->Index != CHMMR_DEFINED || pSolarSysState->pOrbitalDesc != @@ -309,81 +402,8 @@ DeviceFailed (BYTE which_device) break; case UMGAH_HYPERWAVE_DEVICE: case BURVIX_HYPERWAVE_DEVICE: - if (LOBYTE (GLOBAL (CurrentActivity)) == IN_HYPERSPACE) - { - if (GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1) - { - SET_GAME_STATE (USED_BROADCASTER, 1); - return (FALSE); - } - } - else if (LOBYTE (GLOBAL (CurrentActivity)) == IN_INTERPLANETARY - && pSolarSysState) - { - if (pSolarSysState->pOrbitalDesc == - &pSolarSysState->PlanetDesc[1] - && pSolarSysState->MenuState.Initialized == 3 - && CurStarDescPtr->Index == CHMMR_DEFINED - && !GET_GAME_STATE (CHMMR_UNLEASHED)) - { - NextActivity |= CHECK_LOAD; /* fake a load game */ - GLOBAL (CurrentActivity) |= START_ENCOUNTER; - - EncounterGroup = 0; - PutGroupInfo (GROUPS_RANDOM, GROUP_SAVE_IP); - ReinitQueue (&GLOBAL (npc_built_ship_q)); - - SET_GAME_STATE (GLOBAL_FLAGS_AND_DATA, 1 << 7); - SaveFlagshipState (); - return (FALSE); - } - else - { - BOOLEAN FoundIlwrath; - HSTARSHIP hStarShip; - - FoundIlwrath = (BOOLEAN)( - CurStarDescPtr->Index == ILWRATH_DEFINED - ); - if (!FoundIlwrath && (hStarShip = - GetHeadLink (&GLOBAL (npc_built_ship_q)))) - { - SHIP_FRAGMENTPTR FragPtr; - - FragPtr = (SHIP_FRAGMENTPTR)LockStarShip ( - &GLOBAL (npc_built_ship_q), hStarShip - ); - FoundIlwrath = (BOOLEAN)( - GET_RACE_ID (FragPtr) == ILWRATH_SHIP - ); - UnlockStarShip ( - &GLOBAL (npc_built_ship_q), hStarShip - ); - } - - if (FoundIlwrath) - { - NextActivity |= CHECK_LOAD; /* fake a load game */ - GLOBAL (CurrentActivity) |= START_ENCOUNTER; - - EncounterGroup = 0; - PutGroupInfo (GROUPS_RANDOM, GROUP_SAVE_IP); - ReinitQueue (&GLOBAL (npc_built_ship_q)); - - if (CurStarDescPtr->Index == ILWRATH_DEFINED) - { - SET_GAME_STATE (GLOBAL_FLAGS_AND_DATA, 1 << 4); - } - else - { - SET_GAME_STATE (GLOBAL_FLAGS_AND_DATA, 1 << 5); - } - if (pSolarSysState->MenuState.Initialized >= 3) - SaveFlagshipState (); - return (FALSE); - } - } - } + if (UseCaster ()) + return FALSE; break; case TAALO_PROTECTOR_DEVICE: break; @@ -403,10 +423,9 @@ DeviceFailed (BYTE which_device) && GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1 && GLOBAL_SIS (FuelOnBoard) >= PORTAL_FUEL_COST) { - /* don't want to DeltaSISGauges - * because the flagship picture - * is currently obscured - */ + /* No DeltaSISGauges because the flagship picture + * is currently obscured. + */ GLOBAL_SIS (FuelOnBoard) -= PORTAL_FUEL_COST; SET_GAME_STATE (PORTAL_COUNTER, 1); return (FALSE); @@ -428,8 +447,10 @@ DoManipulateDevices (PMENU_STATE pMS) BOOLEAN select, cancel, back, forward; select = PulsedInputState.menu[KEY_MENU_SELECT]; cancel = PulsedInputState.menu[KEY_MENU_CANCEL]; - back = PulsedInputState.menu[KEY_MENU_UP] || PulsedInputState.menu[KEY_MENU_LEFT]; - forward = PulsedInputState.menu[KEY_MENU_DOWN] || PulsedInputState.menu[KEY_MENU_RIGHT]; + back = PulsedInputState.menu[KEY_MENU_UP] || + PulsedInputState.menu[KEY_MENU_LEFT]; + forward = PulsedInputState.menu[KEY_MENU_DOWN] + || PulsedInputState.menu[KEY_MENU_RIGHT]; if (GLOBAL (CurrentActivity) & CHECK_ABORT) return (FALSE);