static COUNT DeltaCredit (SIZE delta_credit) { COUNT Credit; Credit = MAKE_WORD ( GET_GAME_STATE (MELNORME_CREDIT0), GET_GAME_STATE (MELNORME_CREDIT1) ); if ((int)delta_credit >= 0 || ((int)(-delta_credit) <= (int)(Credit))) { Credit += delta_credit; SET_GAME_STATE (MELNORME_CREDIT0, LOBYTE (Credit)); SET_GAME_STATE (MELNORME_CREDIT1, HIBYTE (Credit)); LockMutex (GraphicsLock); DrawStatusMessage ((UNICODE *)~0); UnlockMutex (GraphicsLock); } else { NPCPhrase (NEED_MORE_CREDIT0); NPCPhrase (delta_credit + (int)Credit); NPCPhrase (NEED_MORE_CREDIT1); } return (Credit); }
static void post_melnorme_enc (void) { LockMutex (GraphicsLock); DrawStatusMessage (0); UnlockMutex (GraphicsLock); }
static void post_melnorme_enc (void) { if (prevMsgMode != SMM_UNDEFINED) SetStatusMessageMode (prevMsgMode); DrawStatusMessage (NULL); }
static BOOLEAN DeltaSupportCrew (SIZE crew_delta) { BOOLEAN ret = FALSE; UNICODE buf[40]; HSTARSHIP hTemplate; SHIP_FRAGMENTPTR StarShipPtr, TemplatePtr; StarShipPtr = (SHIP_FRAGMENTPTR)LockStarShip ( &GLOBAL (built_ship_q), (HSTARSHIP)pMenuState->CurFrame); hTemplate = GetStarShipFromIndex (&GLOBAL (avail_race_q), GET_RACE_ID (StarShipPtr)); TemplatePtr = (SHIP_FRAGMENTPTR)LockStarShip ( &GLOBAL (avail_race_q), hTemplate); StarShipPtr->ShipInfo.crew_level += crew_delta; if (StarShipPtr->ShipInfo.crew_level == 0) StarShipPtr->ShipInfo.crew_level = 1; else if (StarShipPtr->ShipInfo.crew_level > TemplatePtr->RaceDescPtr->ship_info.crew_level && crew_delta > 0) StarShipPtr->ShipInfo.crew_level -= crew_delta; else { if (StarShipPtr->ShipInfo.crew_level >= TemplatePtr->RaceDescPtr->ship_info.crew_level) sprintf (buf, "%u", StarShipPtr->ShipInfo.crew_level); else sprintf (buf, "%u/%u", StarShipPtr->ShipInfo.crew_level, TemplatePtr->RaceDescPtr->ship_info.crew_level); DrawStatusMessage (buf); DeltaSISGauges (-crew_delta, 0, 0); if (crew_delta) { RECT r; r.corner.x = 2; r.corner.y = 130; r.extent.width = STATUS_MESSAGE_WIDTH; r.extent.height = STATUS_MESSAGE_HEIGHT; SetContext (StatusContext); SetFlashRect (&r, (FRAME)0); } ret = TRUE; } UnlockStarShip (&GLOBAL (avail_race_q), hTemplate); UnlockStarShip (&GLOBAL (built_ship_q), (HSTARSHIP)pMenuState->CurFrame); return ret; }
static BOOLEAN DeltaSupportCrew (ROSTER_STATE *rosterState, SIZE crew_delta) { BOOLEAN ret = FALSE; UNICODE buf[40]; HFLEETINFO hTemplate; HSHIPFRAG hShipFrag; SHIP_FRAGMENT *StarShipPtr; FLEET_INFO *TemplatePtr; StarShipPtr = LockSupportShip (rosterState, &hShipFrag); if (!StarShipPtr) return FALSE; hTemplate = GetStarShipFromIndex (&GLOBAL (avail_race_q), StarShipPtr->race_id); TemplatePtr = LockFleetInfo (&GLOBAL (avail_race_q), hTemplate); StarShipPtr->crew_level += crew_delta; if (StarShipPtr->crew_level == 0) StarShipPtr->crew_level = 1; else if (StarShipPtr->crew_level > TemplatePtr->crew_level && crew_delta > 0) StarShipPtr->crew_level -= crew_delta; else { if (StarShipPtr->crew_level >= TemplatePtr->crew_level) sprintf (buf, "%u", StarShipPtr->crew_level); else sprintf (buf, "%u/%u", StarShipPtr->crew_level, TemplatePtr->crew_level); PreUpdateFlashRect (); DrawStatusMessage (buf); PostUpdateFlashRect (); DeltaSISGauges (-crew_delta, 0, 0); if (crew_delta) { flashSupportShipCrew (); } ret = TRUE; } UnlockFleetInfo (&GLOBAL (avail_race_q), hTemplate); UnlockShipFrag (&GLOBAL (built_ship_q), hShipFrag); return ret; }
// Now returns whether the purchase succeeded instead of the remaining // credit balance. Use GetAvailableCredits() to get the latter. static bool DeltaCredit (SIZE delta_credit) { COUNT Credit = GetAvailableCredits (); // Can they afford it? if ((int)delta_credit >= 0 || ((int)(-delta_credit) <= (int)(Credit))) { Credit += delta_credit; SetAvailableCredits (Credit); DrawStatusMessage (NULL); return true; } // Fail NPCPhrase (NEED_MORE_CREDIT0); NPCNumber (-delta_credit - Credit, NULL); NPCPhrase (NEED_MORE_CREDIT1); return false; }
BOOLEAN RosterMenu (void) { MENU_STATE MenuState; ROSTER_STATE RosterState; memset (&MenuState, 0, sizeof MenuState); MenuState.privData = &RosterState; memset (&RosterState, 0, sizeof RosterState); RosterState.count = CountLinks (&GLOBAL (built_ship_q)); if (!RosterState.count) return FALSE; // Get the escort positions we will use and sort on X then Y assert (sizeof (RosterState.shipPos) == sizeof (ship_pos)); memcpy (RosterState.shipPos, ship_pos, sizeof (ship_pos)); qsort (RosterState.shipPos, RosterState.count, sizeof (RosterState.shipPos[0]), compShipPos); LockMutex (GraphicsLock); SetContext (StatusContext); selectSupportShip (&RosterState, MenuState.CurState); UnlockMutex (GraphicsLock); SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT); MenuState.InputFunc = DoModifyRoster; DoInput (&MenuState, TRUE); LockMutex (GraphicsLock); SetContext (StatusContext); // unselect the last ship drawSupportShip (&RosterState, FALSE); DrawStatusMessage (NULL); UnlockMutex (GraphicsLock); return TRUE; }
static BOOLEAN DeltaSupportCrew (SIZE crew_delta) { BOOLEAN ret = FALSE; UNICODE buf[40]; HFLEETINFO hTemplate; SHIP_FRAGMENT *StarShipPtr; FLEET_INFO *TemplatePtr; StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), (HSHIPFRAG)pMenuState->CurFrame); hTemplate = GetStarShipFromIndex (&GLOBAL (avail_race_q), StarShipPtr->race_id); TemplatePtr = LockFleetInfo (&GLOBAL (avail_race_q), hTemplate); if (crew_delta > 0) { while (crew_delta && (StarShipPtr->crew_level + crew_delta) > StarShipPtr->max_crew) crew_delta--; } else if (crew_delta < 0) { while (crew_delta && (StarShipPtr->crew_level + crew_delta) < 1) crew_delta++; } StarShipPtr->crew_level += crew_delta; if (StarShipPtr->crew_level == 0) StarShipPtr->crew_level = 1; else if (StarShipPtr->crew_level > TemplatePtr->crew_level && crew_delta > 0) StarShipPtr->crew_level -= crew_delta; else { if (StarShipPtr->crew_level >= TemplatePtr->crew_level) sprintf (buf, "%u", StarShipPtr->crew_level); else sprintf (buf, "%u/%u", StarShipPtr->crew_level, TemplatePtr->crew_level); DrawStatusMessage (buf); DeltaSISGauges (-crew_delta, 0, 0); if (crew_delta) { RECT r; r.corner.x = 2; r.corner.y = 130; r.extent.width = STATUS_MESSAGE_WIDTH; r.extent.height = STATUS_MESSAGE_HEIGHT; SetContext (StatusContext); SetFlashRect (&r, (FRAME)0); } ret = TRUE; } UnlockFleetInfo (&GLOBAL (avail_race_q), hTemplate); UnlockShipFrag (&GLOBAL (built_ship_q), (HSHIPFRAG)pMenuState->CurFrame); return ret; }
static BOOLEAN DoModifyRoster (MENU_STATE *pMS) { BYTE NewState; SBYTE sx, sy; RECT r; STAMP s; SHIP_FRAGMENT *StarShipPtr; BOOLEAN select, cancel, up, down, pgup, pgdn, horiz; if (GLOBAL (CurrentActivity) & CHECK_ABORT) { LockMutex (GraphicsLock); RosterCleanup (pMS); UnlockMutex (GraphicsLock); pMS->CurFrame = 0; return FALSE; } select = PulsedInputState.menu[KEY_MENU_SELECT]; cancel = PulsedInputState.menu[KEY_MENU_CANCEL]; up = PulsedInputState.menu[KEY_MENU_UP]; down = PulsedInputState.menu[KEY_MENU_DOWN]; horiz = PulsedInputState.menu[KEY_MENU_LEFT] || PulsedInputState.menu[KEY_MENU_RIGHT]; pgup = PulsedInputState.menu[KEY_MENU_PAGE_UP]; pgdn = PulsedInputState.menu[KEY_MENU_PAGE_DOWN]; if (pMS->Initialized && (pMS->CurState & SHIP_TOGGLE)) { SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN | MENU_SOUND_PAGEUP | MENU_SOUND_PAGEDOWN, MENU_SOUND_SELECT | MENU_SOUND_CANCEL); } else { SetMenuSounds (MENU_SOUND_ARROWS | MENU_SOUND_PAGEUP | MENU_SOUND_PAGEDOWN, MENU_SOUND_SELECT); } if (!pMS->Initialized) { pMS->InputFunc = DoModifyRoster; pMS->Initialized = TRUE; pMS->CurState = NewState = 0; LockMutex (GraphicsLock); SetContext (StatusContext); goto SelectSupport; } else if (cancel && !(pMS->CurState & SHIP_TOGGLE)) { LockMutex (GraphicsLock); SetFlashRect (NULL, (FRAME)0); RosterCleanup (pMS); pMS->CurFrame = 0; DrawStatusMessage (NULL); UnlockMutex (GraphicsLock); return FALSE; } else if (select || cancel) { LockMutex (GraphicsLock); pMS->CurState ^= SHIP_TOGGLE; if (!(pMS->CurState & SHIP_TOGGLE)) SetFlashRect (NULL, (FRAME)0); else { RosterCleanup (pMS); r.corner.x = 2; r.corner.y = 130; r.extent.width = STATUS_MESSAGE_WIDTH; r.extent.height = STATUS_MESSAGE_HEIGHT; SetContext (StatusContext); SetFlashRect (&r, (FRAME)0); } UnlockMutex (GraphicsLock); } else if (pMS->CurState & SHIP_TOGGLE) { SIZE delta = 0; BOOLEAN failed = FALSE; if (up || pgup) { if (GLOBAL_SIS (CrewEnlisted)) delta = pgup ? 10 : 1; else failed = TRUE; } else if (down || pgdn) { if (GLOBAL_SIS (CrewEnlisted) < GetCPodCapacity (NULL)) delta = pgdn ? -10 : -1; else failed = TRUE; } if (delta != 0) { LockMutex (GraphicsLock); failed = !DeltaSupportCrew (delta); UnlockMutex (GraphicsLock); } if (failed) { // not enough room or crew PlayMenuSound (MENU_SOUND_FAILURE); } } else { POINT *pship_pos; NewState = pMS->CurState; sx = (SBYTE)((pMS->delta_item + 1) >> 1); if (horiz) { pship_pos = (POINT*)pMS->flash_frame1; if (NewState == (BYTE)(sx - 1)) NewState = (BYTE)(pMS->delta_item - 1); else if (NewState >= (BYTE)sx) { NewState -= sx; if (pship_pos[NewState].y < pship_pos[pMS->CurState].y) ++NewState; } else { NewState += sx; if (NewState != (BYTE)sx && pship_pos[NewState].y > pship_pos[pMS->CurState].y) --NewState; } } else if (down) { sy = 1; if (++NewState == (BYTE)pMS->delta_item) NewState = (BYTE)(sx - 1); else if (NewState == (BYTE)sx) NewState = 0; } else if (up) { sy = -1; if (NewState == 0) NewState += sx - 1; else if (NewState == (BYTE)sx) NewState = (BYTE)(pMS->delta_item - 1); else --NewState; } if (NewState != pMS->CurState) { LockMutex (GraphicsLock); SetContext (StatusContext); s.origin = pMS->first_item; StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), (HSHIPFRAG)pMS->CurFrame); s.frame = StarShipPtr->icons; UnlockShipFrag (&GLOBAL (built_ship_q), (HSHIPFRAG)pMS->CurFrame); DrawStamp (&s); SelectSupport: pship_pos = (POINT*)pMS->flash_frame1; pMS->first_item = pship_pos[NewState]; pMS->CurFrame = (FRAME)MatchSupportShip (pMS); DeltaSupportCrew (0); UnlockMutex (GraphicsLock); pMS->CurState = NewState; } if (pMS->flash_task == 0) pMS->flash_task = AssignTask (flash_ship_task, 2048, "flash roster menu"); } return TRUE; }
static void FeedbackSetting (BYTE which_setting) { UNICODE buf[128]; const char *tmpstr; buf[0] = '\0'; // pre-terminate buffer in case snprintf() overflows buf[sizeof (buf) - 1] = '\0'; switch (which_setting) { case SOUND_ON_SETTING: case SOUND_OFF_SETTING: snprintf (buf, sizeof (buf) - 1, "%s %s", GAME_STRING (OPTION_STRING_BASE + 0), GLOBAL (glob_flags) & SOUND_DISABLED ? GAME_STRING (OPTION_STRING_BASE + 4) : GAME_STRING (OPTION_STRING_BASE + 5)); break; case MUSIC_ON_SETTING: case MUSIC_OFF_SETTING: snprintf (buf, sizeof (buf) - 1, "%s %s", GAME_STRING (OPTION_STRING_BASE + 1), GLOBAL (glob_flags) & MUSIC_DISABLED ? GAME_STRING (OPTION_STRING_BASE + 4) : GAME_STRING (OPTION_STRING_BASE + 5)); break; case VOICE_ON_SETTING: case VOICE_OFF_SETTING: snprintf (buf, sizeof (buf) - 1, "%s %s", GAME_STRING (OPTION_STRING_BASE + 2), GLOBAL (glob_flags) & VOICE_DISABLED ? GAME_STRING (OPTION_STRING_BASE + 4) : GAME_STRING (OPTION_STRING_BASE + 5)); break; case CYBORG_OFF_SETTING: case CYBORG_NORMAL_SETTING: case CYBORG_DOUBLE_SETTING: case CYBORG_SUPER_SETTING: if (optWhichMenu == OPT_PC && which_setting > CYBORG_NORMAL_SETTING) { if (which_setting == CYBORG_DOUBLE_SETTING) tmpstr = "+"; else tmpstr = "++"; } else tmpstr = ""; snprintf (buf, sizeof (buf) - 1, "%s %s%s", GAME_STRING (OPTION_STRING_BASE + 3), !(GLOBAL (glob_flags) & CYBORG_ENABLED) ? GAME_STRING (OPTION_STRING_BASE + 4) : GAME_STRING (OPTION_STRING_BASE + 5), tmpstr); break; case CHANGE_CAPTAIN_SETTING: case CHANGE_SHIP_SETTING: utf8StringCopy (buf, sizeof (buf), GAME_STRING (NAMING_STRING_BASE + 0)); break; } LockMutex (GraphicsLock); DrawStatusMessage (buf); UnlockMutex (GraphicsLock); }
static void DrawElementDescription (COUNT element) { DrawStatusMessage (GAME_STRING (element + (CARGO_STRING_BASE + 2))); }