示例#1
0
文件: itemmenu.c 项目: ashurasunny/PA
WORD
PAL_ItemSelectMenuUpdate(
   VOID
)
/*++
  Purpose:

    Initialize the item selection menu.

  Parameters:

    None.

  Return value:

    The object ID of the selected item. 0 if cancelled, 0xFFFF if not confirmed.

--*/
{
#ifndef PAL_WIN95
   int                i, j, k;
   WORD               wObject;
#else
   int                i, j, k, line;
   WORD               wObject, wScript;
#endif
   BYTE               bColor;
   static BYTE        bufImage[2048];
   static WORD        wPrevImageIndex = 0xFFFF;

   //
   // Process input
   //
   if (g_InputState.dwKeyPress & kKeyUp)
   {
      gpGlobals->iCurInvMenuItem -= 3;
   }
   else if (g_InputState.dwKeyPress & kKeyDown)
   {
      gpGlobals->iCurInvMenuItem += 3;
   }
   else if (g_InputState.dwKeyPress & kKeyLeft)
   {
      gpGlobals->iCurInvMenuItem--;
   }
   else if (g_InputState.dwKeyPress & kKeyRight)
   {
      gpGlobals->iCurInvMenuItem++;
   }
   else if (g_InputState.dwKeyPress & kKeyPgUp)
   {
      gpGlobals->iCurInvMenuItem -= 3 * 7;
   }
   else if (g_InputState.dwKeyPress & kKeyPgDn)
   {
      gpGlobals->iCurInvMenuItem += 3 * 7;
   }
   else if (g_InputState.dwKeyPress & kKeyMenu)
   {
      return 0;
   }

   //
   // Make sure the current menu item index is in bound
   //
   if (gpGlobals->iCurInvMenuItem < 0)
   {
      gpGlobals->iCurInvMenuItem = 0;
   }
   else if (gpGlobals->iCurInvMenuItem >= g_iNumInventory)
   {
      gpGlobals->iCurInvMenuItem = g_iNumInventory - 1;
   }

   //
   // Redraw the box
   //
   PAL_CreateBox(PAL_XY(2, 0), 6, 17, 1, FALSE);

   //
   // Draw the texts in the current page
   //
   i = gpGlobals->iCurInvMenuItem / 3 * 3 - 3 * 4;
   if (i < 0)
   {
      i = 0;
   }

   for (j = 0; j < 7; j++)
   {
      for (k = 0; k < 3; k++)
      {
         wObject = gpGlobals->rgInventory[i].wItem;
         bColor = MENUITEM_COLOR;

         if (i >= MAX_INVENTORY || wObject == 0)
         {
            //
            // End of the list reached
            //
            j = 7;
            break;
         }

         if (i == gpGlobals->iCurInvMenuItem)
         {
            if (!(gpGlobals->g.rgObject[wObject].item.wFlags & g_wItemFlags) ||
               (SHORT)gpGlobals->rgInventory[i].nAmount <= (SHORT)gpGlobals->rgInventory[i].nAmountInUse)
            {
               //
               // This item is not selectable
               //
               bColor = MENUITEM_COLOR_SELECTED_INACTIVE;
            }
            else
            {
               //
               // This item is selectable
               //
               if (gpGlobals->rgInventory[i].nAmount == 0)
               {
                  bColor = MENUITEM_COLOR_EQUIPPEDITEM;
               }
               else
               {
                  bColor = MENUITEM_COLOR_SELECTED;
               }
            }
         }
         else if (!(gpGlobals->g.rgObject[wObject].item.wFlags & g_wItemFlags) ||
            (SHORT)gpGlobals->rgInventory[i].nAmount <= (SHORT)gpGlobals->rgInventory[i].nAmountInUse)
         {
            //
            // This item is not selectable
            //
            bColor = MENUITEM_COLOR_INACTIVE;
         }
         else if (gpGlobals->rgInventory[i].nAmount == 0)
         {
            bColor = MENUITEM_COLOR_EQUIPPEDITEM;
         }

         //
         // Draw the text
         //
         PAL_DrawText(PAL_GetWord(wObject), PAL_XY(15 + k * 100, 12 + j * 18),
            bColor, TRUE, FALSE);

         //
         // Draw the cursor on the current selected item
         //
         if (i == gpGlobals->iCurInvMenuItem)
         {
            PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_CURSOR),
               gpScreen, PAL_XY(40 + k * 100, 22 + j * 18));
         }

         //
         // Draw the amount of this item
         //
		 if ((SHORT)gpGlobals->rgInventory[i].nAmount - (SHORT)gpGlobals->rgInventory[i].nAmountInUse > 1)
		 {
            PAL_DrawNumber(gpGlobals->rgInventory[i].nAmount - gpGlobals->rgInventory[i].nAmountInUse,
               2, PAL_XY(96 + k * 100, 17 + j * 18), kNumColorCyan, kNumAlignRight);
		 }

         i++;
      }
   }

   //
   // Draw the picture of current selected item
   //
   PAL_RLEBlitToSurface(PAL_SpriteGetFrame(gpSpriteUI, SPRITENUM_ITEMBOX), gpScreen,
      PAL_XY(5, 140));

   wObject = gpGlobals->rgInventory[gpGlobals->iCurInvMenuItem].wItem;

   if (gpGlobals->g.rgObject[wObject].item.wBitmap != wPrevImageIndex)
   {
      if (PAL_MKFReadChunk(bufImage, 2048,
         gpGlobals->g.rgObject[wObject].item.wBitmap, gpGlobals->f.fpBALL) > 0)
      {
         wPrevImageIndex = gpGlobals->g.rgObject[wObject].item.wBitmap;
      }
      else
      {
         wPrevImageIndex = 0xFFFF;
      }
   }

   if (wPrevImageIndex != 0xFFFF)
   {
      PAL_RLEBlitToSurface(bufImage, gpScreen, PAL_XY(12, 148));
   }

   //
   // Draw the description of the selected item
   //
#ifndef PAL_WIN95
   if (!g_fNoDesc && gpGlobals->lpObjectDesc != NULL)
   {
      char szDesc[512], *next;
      const char *d = PAL_GetObjectDesc(gpGlobals->lpObjectDesc, wObject);

      if (d != NULL)
      {
         k = 150;
         strcpy(szDesc, d);
         d = szDesc;

         while (TRUE)
         {
            next = strchr(d, '*');
            if (next != NULL)
            {
               *next = '\0';
               next++;
            }

            PAL_DrawText(d, PAL_XY(75, k), DESCTEXT_COLOR, TRUE, FALSE);
            k += 16;

            if (next == NULL)
            {
               break;
            }

            d = next;
         }
      }
   }
#else
   if (!g_fNoDesc)
   {
      wScript = gpGlobals->g.rgObject[wObject].item.wScriptDesc;
      line = 0;
      while (wScript && gpGlobals->g.lprgScriptEntry[wScript].wOperation != 0)
      {
         if (gpGlobals->g.lprgScriptEntry[wScript].wOperation == 0xFFFF)
         {
            wScript = PAL_RunAutoScript(wScript, (1 << 15) | line);
            line++;
         }
         else
         {
            wScript = PAL_RunAutoScript(wScript, 0);
         }
      }
   }
#endif

   if (g_InputState.dwKeyPress & kKeySearch)
   {
      if ((gpGlobals->g.rgObject[wObject].item.wFlags & g_wItemFlags) &&
         (SHORT)gpGlobals->rgInventory[gpGlobals->iCurInvMenuItem].nAmount >
         (SHORT)gpGlobals->rgInventory[gpGlobals->iCurInvMenuItem].nAmountInUse)
      {
         if (gpGlobals->rgInventory[gpGlobals->iCurInvMenuItem].nAmount > 0)
         {
            j = (gpGlobals->iCurInvMenuItem < 3 * 4) ? (gpGlobals->iCurInvMenuItem / 3) : 4;
            k = gpGlobals->iCurInvMenuItem % 3;

            PAL_DrawText(PAL_GetWord(wObject), PAL_XY(15 + k * 100, 12 + j * 18),
               MENUITEM_COLOR_CONFIRMED, FALSE, FALSE);
         }

         return wObject;
      }
   }

   return 0xFFFF;
}
示例#2
0
VOID
PAL_GameUpdate(
BOOL       fTrigger
)
/*++
  Purpose:

  The main game logic routine. Update the status of everything.

  Parameters:

  [IN]  fTrigger - whether to process trigger events or not.

  Return value:

  None.

  --*/
{
	WORD            wEventObjectID, wDir;
	int             i;
	LPEVENTOBJECT   p;

	//
	// Check for trigger events
	//
	if (fTrigger)
	{
		//
		// Check if we are entering a new scene
		//
		if (gpGlobals->fEnteringScene)
		{
			//
			// Run the script for entering the scene
			//
			gpGlobals->fEnteringScene = FALSE;

			i = gpGlobals->wNumScene - 1;
			gpGlobals->g.rgScene[i].wScriptOnEnter =
				PAL_RunTriggerScript(gpGlobals->g.rgScene[i].wScriptOnEnter, 0xFFFF);

			if (gpGlobals->fEnteringScene || gpGlobals->fGameStart)
			{
				//
				// Don't go further as we're switching to another scene
				//
				return;
			}

			PAL_ClearKeyState();
			PAL_MakeScene();
		}

		//
		// Update the vanish time for all event objects
		//
		for (wEventObjectID = 0; wEventObjectID < gpGlobals->g.nEventObject; wEventObjectID++)
		{
			p = &gpGlobals->g.lprgEventObject[wEventObjectID];

			if (p->sVanishTime != 0)
			{
				p->sVanishTime += ((p->sVanishTime < 0) ? 1 : -1);
			}
		}

		//
		// Loop through all event objects in the current scene
		//
		for (wEventObjectID = gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wEventObjectIndex + 1;
			wEventObjectID <= gpGlobals->g.rgScene[gpGlobals->wNumScene].wEventObjectIndex;
			wEventObjectID++)
		{
			p = &gpGlobals->g.lprgEventObject[wEventObjectID - 1];

			if (p->sVanishTime != 0)
			{
				continue;
			}

			if (p->sState < 0)
			{
				if (p->x < PAL_X(gpGlobals->viewport) ||
					p->x > PAL_X(gpGlobals->viewport) + 320 ||
					p->y < PAL_Y(gpGlobals->viewport) ||
					p->y > PAL_Y(gpGlobals->viewport) + 320)
				{
					p->sState = abs(p->sState);
					p->wCurrentFrameNum = 0;
				}
			}
			else if (p->sState > 0 && p->wTriggerMode >= kTriggerTouchNear)
			{
				//
				// This event object can be triggered without manually exploring
				//
				if (abs(PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset) - p->x) +
					abs(PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset) - p->y) * 2 <
					(p->wTriggerMode - kTriggerTouchNear) * 32 + 16)
				{
					//
					// Player is in the trigger zone.
					//

					if (p->nSpriteFrames)
					{
						//
						// The sprite has multiple frames. Try to adjust the direction.
						//
						int                xOffset, yOffset;

						p->wCurrentFrameNum = 0;

						xOffset = PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset) - p->x;
						yOffset = PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset) - p->y;

						if (xOffset > 0)
						{
							p->wDirection = ((yOffset > 0) ? kDirEast : kDirNorth);
						}
						else
						{
							p->wDirection = ((yOffset > 0) ? kDirSouth : kDirWest);
						}

						//
						// Redraw the scene
						//
						PAL_UpdatePartyGestures(FALSE);

						PAL_MakeScene();
						VIDEO_UpdateScreen(NULL);
					}

					//
					// Execute the script.
					//
					p->wTriggerScript = PAL_RunTriggerScript(p->wTriggerScript, wEventObjectID);

					PAL_ClearKeyState();

					if (gpGlobals->fEnteringScene || gpGlobals->fGameStart)
					{
						//
						// Don't go further on scene switching
						//
						return;
					}
				}
			}
		}
	}

	//
	// Run autoscript for each event objects
	//
	for (wEventObjectID = gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wEventObjectIndex + 1;
		wEventObjectID <= gpGlobals->g.rgScene[gpGlobals->wNumScene].wEventObjectIndex;
		wEventObjectID++)
	{
		p = &gpGlobals->g.lprgEventObject[wEventObjectID - 1];

		if (p->sState > 0 && p->sVanishTime == 0)
		{
			WORD wScriptEntry = p->wAutoScript;
			if (wScriptEntry != 0)
			{
				p->wAutoScript = PAL_RunAutoScript(wScriptEntry, wEventObjectID);
				if (gpGlobals->fEnteringScene || gpGlobals->fGameStart)
				{
					//
					// Don't go further on scene switching
					//
					return;
				}
			}
		}

		//
		// Check if the player is in the way
		//
		if (fTrigger && p->sState >= kObjStateBlocker && p->wSpriteNum != 0 &&
			abs(p->x - PAL_X(gpGlobals->viewport) - PAL_X(gpGlobals->partyoffset)) +
			abs(p->y - PAL_Y(gpGlobals->viewport) - PAL_Y(gpGlobals->partyoffset)) * 2 <= 12)
		{
			//
			// Player is in the way, try to move a step
			//
			wDir = (p->wDirection + 1) % 4;
			for (i = 0; i < 4; i++)
			{
				int              x, y;
				PAL_POS          pos;

				x = PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset);
				y = PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset);

				x += ((wDir == kDirWest || wDir == kDirSouth) ? -16 : 16);
				y += ((wDir == kDirWest || wDir == kDirNorth) ? -8 : 8);

				pos = PAL_XY(x, y);

				if (!PAL_CheckObstacle(pos, TRUE, 0))
				{
					//
					// move here
					//
					gpGlobals->viewport = PAL_XY(
						PAL_X(pos) - PAL_X(gpGlobals->partyoffset),
						PAL_Y(pos) - PAL_Y(gpGlobals->partyoffset));

					break;
				}

				wDir = (wDir + 1) % 4;
			}
		}
	}

	gpGlobals->dwFrameNum++;
}