rem: else if (StarShipPtr->ShipInfo.crew_level > 1) { DeltaSISGauges (0, 0, GLOBAL (CrewCost) - (crew_bought == CREW_EXPENSE_THRESHOLD ? 2 : 0)); crew_delta = -1; --StarShipPtr->ShipInfo.crew_level;
add: else { if (StarShipPtr->ShipInfo.crew_level > 0) { if (StarShipPtr->ShipInfo.crew_level > 1) DeltaSISGauges (0, 0, GLOBAL (CrewCost) - (crew_bought == CREW_EXPENSE_THRESHOLD ? 2 : 0)); else DeltaSISGauges (UNDEFINED_DELTA,UNDEFINED_DELTA, (COUNT)ShipCost[GET_RACE_ID (StarShipPtr)]); crew_delta = -1; --StarShipPtr->ShipInfo.crew_level; }
context: DoModifyShips (PMENU_STATE pMS){#define MODIFY_CREW_FLAG (1 << 8)	RECT r;	HSTARSHIP hStarShip, hNextShip;	SHIP_FRAGMENTPTR StarShipPtr;	BOOLEAN select, cancel;#ifdef WANT_SHIP_SPINS	BOOLEAN special;	special = CurrentMenuState.special;#endif /* WANT_SHIP_SPINS */	select = CurrentMenuState.select;	cancel = CurrentMenuState.cancel;	if (GLOBAL (CurrentActivity) & CHECK_ABORT)	{		pMS->InputFunc = DoShipyard;		return (TRUE);	}	if (!pMS->Initialized)	{		pMS->InputFunc = DoModifyShips;		pMS->Initialized = TRUE;		pMS->CurState = MAKE_BYTE (0, 0xF);		pMS->delta_item = 0;		SetSemaphore (GraphicsSem);		SetContext (SpaceContext);		goto ChangeFlashRect;	}	else	{		SBYTE dx = 0, dy = 0;		BYTE NewState;		if (CurrentMenuState.right) dx = 1;		if (CurrentMenuState.left) dx = -1;		if (CurrentMenuState.up) dy = -1;		if (CurrentMenuState.down) dy = 1;		NewState = pMS->CurState;		if (pMS->delta_item & MODIFY_CREW_FLAG)		{		}		else if (dy)		{			if (HINIBBLE (NewState))				NewState = pMS->CurState % HANGAR_SHIPS_ROW;			else				NewState = (unsigned char)(pMS->CurState + HANGAR_SHIPS_ROW);			NewState += dy * HANGAR_SHIPS_ROW;			if (NewState / HANGAR_SHIPS_ROW > 0					&& NewState / HANGAR_SHIPS_ROW <= HANGAR_ROWS)				NewState -= HANGAR_SHIPS_ROW;			else if (NewState / HANGAR_SHIPS_ROW > HANGAR_ROWS + 1)				/* negative number - select last row */				NewState = pMS->CurState % HANGAR_SHIPS_ROW						+ HANGAR_SHIPS_ROW * (HANGAR_ROWS - 1);			else				// select SIS				NewState = MAKE_BYTE (pMS->CurState, 0xF);		}		else if (dx && !HINIBBLE (NewState))		{			NewState = NewState % HANGAR_SHIPS_ROW;			if ((dx += NewState) < 0)				NewState = (BYTE)(pMS->CurState + (HANGAR_SHIPS_ROW - 1));			else if (dx > HANGAR_SHIPS_ROW - 1)				NewState = (BYTE)(pMS->CurState - (HANGAR_SHIPS_ROW - 1));			else				NewState = (BYTE)(pMS->CurState - NewState + dx);		}#ifdef WANT_SHIP_SPINS		if (select || cancel || special#else		if (select || cancel#endif				|| NewState != pMS->CurState				|| ((pMS->delta_item & MODIFY_CREW_FLAG) && (dx || dy)))		{			for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q));					hStarShip; hStarShip = hNextShip)			{				StarShipPtr = (SHIP_FRAGMENTPTR)LockStarShip (						&GLOBAL (built_ship_q), hStarShip						);				if (GET_GROUP_LOC (StarShipPtr) == pMS->CurState)				{					UnlockStarShip (							&GLOBAL (built_ship_q), hStarShip							);					break;				}				hNextShip = _GetSuccLink (StarShipPtr);				UnlockStarShip (						&GLOBAL (built_ship_q), hStarShip						);			}			SetSemaphore (GraphicsSem);#ifdef WANT_SHIP_SPINS			if (special)			{				HSTARSHIP hSpinShip;								if ((hSpinShip = hStarShip)						|| (HINIBBLE (pMS->CurState) == 0						&& (hSpinShip = GetAvailableRaceFromIndex (								LOBYTE (pMS->delta_item)								))))				{					SetFlashRect (NULL_PTR, (FRAME)0);					SpinStarShip (hSpinShip);					if (hStarShip)						goto ChangeFlashRect;					SetFlashRect ((PRECT)~0L, (FRAME)0);				}			}			else#endif			if (select || ((pMS->delta_item & MODIFY_CREW_FLAG)					&& (dx || dy || cancel)))			{				COUNT ShipCost[] =				{					RACE_SHIP_COST				};				if (hStarShip == 0 && HINIBBLE (pMS->CurState) == 0)				{					COUNT Index;// SetFlashRect (NULL_PTR, (FRAME)0);					ClearSemaphore (GraphicsSem);					if (!(pMS->delta_item & MODIFY_CREW_FLAG))					{						pMS->delta_item = MODIFY_CREW_FLAG;						DrawRaceStrings (0);						return (TRUE);					}					else if (cancel)					{						pMS->delta_item ^= MODIFY_CREW_FLAG;						SetFlashRect ((PRECT)~0L, (FRAME)0);						DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW);					}					else if (select)					{						Index = GetIndexFromStarShip (								&GLOBAL (avail_race_q),								GetAvailableRaceFromIndex (LOBYTE (pMS->delta_item))								);						if (GLOBAL_SIS (ResUnits) >= (DWORD)ShipCost[Index]								&& CloneShipFragment (Index,								&GLOBAL (built_ship_q), 1))						{							ShowCombatShip ((COUNT)pMS->CurState, (SHIP_FRAGMENTPTR)0);							//Reset flash rectangle							SetSemaphore (GraphicsSem);							SetFlashRect ((PRECT)~0L, (FRAME)0);							ClearSemaphore (GraphicsSem);							DrawMenuStateStrings (PM_CREW, SHIPYARD_CREW);							SetSemaphore (GraphicsSem);							DeltaSISGauges (									UNDEFINED_DELTA, UNDEFINED_DELTA, -((int)ShipCost[Index])									);							r.corner.x = pMS->flash_rect0.corner.x;							r.corner.y = pMS->flash_rect0.corner.y									+ pMS->flash_rect0.extent.height - 6;							r.extent.width = SHIP_WIN_WIDTH;							r.extent.height = 5;							SetContext (SpaceContext);							SetFlashRect (&r, (FRAME)0);							ClearSemaphore (GraphicsSem);						}													return (TRUE);					}					else					{						Index = GetAvailableRaceCount ();						NewState = LOBYTE (pMS->delta_item);						if (dx < 0 || dy < 0)						{							if (NewState-- == 0)								NewState = Index - 1;						}						else if (dx > 0 || dy > 0)						{							if (++NewState == Index)								NewState = 0;						}												if (NewState != LOBYTE (pMS->delta_item))						{							DrawRaceStrings (NewState);							pMS->delta_item = NewState | MODIFY_CREW_FLAG;						}												return (TRUE);					}					SetSemaphore (GraphicsSem);					goto ChangeFlashRect;				}				else if (select || cancel)				{										if (!(pMS->delta_item ^= MODIFY_CREW_FLAG))						goto ChangeFlashRect;					else if (hStarShip == 0)					{						SetContext (StatusContext);						GetGaugeRect (&r, TRUE);						SetFlashRect (&r, (FRAME)0);						SetContext (SpaceContext);					}					else					{						r.corner.x = pMS->flash_rect0.corner.x;						r.corner.y = pMS->flash_rect0.corner.y								+ pMS->flash_rect0.extent.height - 6;						r.extent.width = SHIP_WIN_WIDTH;						r.extent.height = 5;						SetContext (SpaceContext);						SetFlashRect (&r, (FRAME)0);					}				}				else if (pMS->delta_item & MODIFY_CREW_FLAG)				{					SIZE crew_delta, crew_bought;					if (hStarShip)						StarShipPtr = (SHIP_FRAGMENTPTR)LockStarShip (								&GLOBAL (built_ship_q), hStarShip								);					crew_delta = 0;					if (dx < 0 || dy < 0)					{						if (hStarShip == 0)						{							if (GetCPodCapacity (&r.corner) > GetCrewCount ()									&& GLOBAL_SIS (ResUnits) >=									(DWORD)GLOBAL (CrewCost))							{								DrawPoint (&r.corner);								DeltaSISGauges (1, 0, -GLOBAL (CrewCost));								crew_delta = 1;								SetContext (StatusContext);								GetGaugeRect (&r, TRUE);								SetFlashRect (&r, (FRAME)0);								SetContext (SpaceContext);							}						}						else						{							HSTARSHIP hTemplate;							SHIP_FRAGMENTPTR TemplatePtr;							hTemplate = GetStarShipFromIndex (									&GLOBAL (avail_race_q),									GET_RACE_ID (StarShipPtr)									);							TemplatePtr = (SHIP_FRAGMENTPTR)LockStarShip (									&GLOBAL (avail_race_q), hTemplate									);							if (GLOBAL_SIS (ResUnits) >=									(DWORD)GLOBAL (CrewCost)									&& StarShipPtr->ShipInfo.crew_level <									StarShipPtr->ShipInfo.max_crew									&& StarShipPtr->ShipInfo.crew_level <									TemplatePtr->RaceDescPtr->ship_info.crew_level)							{								DeltaSISGauges (0, 0, -GLOBAL (CrewCost));								++StarShipPtr->ShipInfo.crew_level;								crew_delta = 1;								ShowShipCrew (StarShipPtr, &pMS->flash_rect0);								r.corner.x = pMS->flash_rect0.corner.x;								r.corner.y = pMS->flash_rect0.corner.y										+ pMS->flash_rect0.extent.height - 6;								r.extent.width = SHIP_WIN_WIDTH;								r.extent.height = 5;								SetContext (SpaceContext);								SetFlashRect (&r, (FRAME)0);							}							UnlockStarShip (									&GLOBAL (avail_race_q), hTemplate									);						}					}					else if (dx > 0 || dy > 0)					{						crew_bought = (SIZE)MAKE_WORD (								GET_GAME_STATE (CREW_PURCHASED0),								GET_GAME_STATE (CREW_PURCHASED1)								);						if (hStarShip == 0)						{							if (GetCrewCount ())							{								DeltaSISGauges (-1, 0, GLOBAL (CrewCost)										- (crew_bought == CREW_EXPENSE_THRESHOLD ? 2 : 0));								crew_delta = -1;								GetCPodCapacity (&r.corner);								SetContextForeGroundColor (BLACK_COLOR);								DrawPoint (&r.corner);								SetContext (StatusContext);								GetGaugeRect (&r, TRUE);								SetFlashRect (&r, (FRAME)0);								SetContext (SpaceContext);							}						}						else if (StarShipPtr->ShipInfo.crew_level > 1)						{							DeltaSISGauges (0, 0, GLOBAL (CrewCost)									- (crew_bought == CREW_EXPENSE_THRESHOLD ? 2 : 0));							crew_delta = -1;							--StarShipPtr->ShipInfo.crew_level;							ShowShipCrew (StarShipPtr, &pMS->flash_rect0);							r.corner.x = pMS->flash_rect0.corner.x;							r.corner.y = pMS->flash_rect0.corner.y									+ pMS->flash_rect0.extent.height - 6;							r.extent.width = SHIP_WIN_WIDTH;							r.extent.height = 5;							SetContext (SpaceContext);							SetFlashRect (&r, (FRAME)0);						}						else						{							COUNT ResUnits;							ResUnits = (COUNT)ShipCost[									GET_RACE_ID (StarShipPtr)									];							crew_delta = -(StarShipPtr->ShipInfo.crew_level - 1);							crew_bought = (SIZE)MAKE_WORD (									GET_GAME_STATE (CREW_PURCHASED0),									GET_GAME_STATE (CREW_PURCHASED1)									) - CREW_EXPENSE_THRESHOLD;							if (crew_bought <= 0 || (crew_bought += crew_delta) >= 0)								crew_bought = -crew_delta;							else							{								ResUnits += -crew_bought										* (GLOBAL (CrewCost) - 2);								crew_bought -= crew_delta;							}							ResUnits += crew_bought * GLOBAL (CrewCost);														SetFlashRect (NULL_PTR, (FRAME)0);							ClearSemaphore (GraphicsSem);														ShowCombatShip ((COUNT)pMS->CurState, StarShipPtr);														SetSemaphore (GraphicsSem);							pMS->flash_rect0.extent.width = SHIP_WIN_WIDTH;							SetFlashRect (&pMS->flash_rect0, (FRAME)0);							UnlockStarShip (									&GLOBAL (built_ship_q), hStarShip									);									RemoveQueue (									&GLOBAL (built_ship_q), hStarShip									);							FreeStarShip (									&GLOBAL (built_ship_q), hStarShip									);							DeltaSISGauges (									UNDEFINED_DELTA, UNDEFINED_DELTA, ResUnits									);							hStarShip = 0;							pMS->delta_item ^= MODIFY_CREW_FLAG;						}					}					if (hStarShip)					{						UnlockStarShip (								&GLOBAL (built_ship_q), hStarShip								);					}											CrewTransaction (crew_delta);				}			}			else if (cancel)			{				ClearSemaphore (GraphicsSem);				pMS->InputFunc = DoShipyard;				DrawMenuStateStrings (PM_CREW, pMS->CurState = SHIPYARD_CREW);				SetSemaphore (GraphicsSem);				SetFlashRect ((PRECT)~0L, (FRAME)0);				ClearSemaphore (GraphicsSem);				return (TRUE);			}			else			{				pMS->CurState = NewState;ChangeFlashRect:				if (HINIBBLE (pMS->CurState))				{					pMS->flash_rect0.corner.x =							pMS->flash_rect0.corner.y = 0;					pMS->flash_rect0.extent.width = SIS_SCREEN_WIDTH;					pMS->flash_rect0.extent.height = 61;				}				else				{					pMS->flash_rect0.corner.x = hangar_x_coords[							pMS->CurState % HANGAR_SHIPS_ROW];					pMS->flash_rect0.corner.y = HANGAR_Y + (HANGAR_DY *							(pMS->CurState / HANGAR_SHIPS_ROW));					pMS->flash_rect0.extent.width = SHIP_WIN_WIDTH;					pMS->flash_rect0.extent.height = SHIP_WIN_HEIGHT;				}				SetFlashRect (&pMS->flash_rect0, (FRAME)0);			}			ClearSemaphore (GraphicsSem);		}	}	return (TRUE);}