VOID PAL_WaitForKey( VOID ) /*++ Purpose: Wait for any key. Parameters: None. Return value: None. --*/ { LoginInfo("PAL_WaitForKey\n" ); PAL_ClearKeyState(); while (TRUE) { UTIL_Delay(50); if (g_InputState.dwKeyPress & (kKeySearch | kKeyMenu)) { break; } } }
VOID PAL_GameEquipItem( VOID ) /*++ Purpose: Allow player equip an item in the game. Parameters: None. Return value: None. --*/ { WORD wObject; LoginInfo("PAL_GameEquipItem\n" ); while (TRUE) { wObject = PAL_ItemSelectMenu(NULL, kItemFlagEquipable); if (wObject == 0) { return; } PAL_EquipItemMenu(wObject); } }
//登录 bool LoginCmdHandle::LoginHandle(list<string>& cmdList,bool &exit) { //登录处理需要等待 bool isWait = true; if(cmdList.size() >3) { list<string>::const_iterator iter = cmdList.begin(); iter++; // account string account = (*iter); iter++; // password string password = (*iter); iter++; // sex USER_SEX_TYPE sex = (USER_SEX_TYPE)atoi((*iter).c_str()); iter++; // authType AUTH_TYPE authType = AUTH_TYPE_PWD; if (iter != cmdList.end()) { authType = (AUTH_TYPE)atoi((*iter).c_str()); iter++; } // deviceId string deviceId = "000000000"; if (iter != cmdList.end()) { deviceId = (*iter); iter++; } bool result = g_client->Login(account, password, deviceId, CLIENT_ANDROID, sex, authType); if (!result) { printf("Login fail!\n"); } else { // set console title SetConsoleTitle(account.c_str()); } } else { LoginInfo(); } return isWait; }
static INT PAL_LoadGame(LPCSTR szFileName) /*++ Purpose: Load a saved game. Parameters: [IN] szFileName - file name of saved game. Return value: 0 if success, -1 if failed. --*/ { FILE *fp; static SAVEDGAME s; UINT32 i; // // Try to open the specified file // LoginInfo("PAL_LoadGame(%s)\n",szFileName ); fp = fopen(szFileName, "rb"); if (fp == NULL) { return -1; } // // Read all data from the file and close. // fread(&s, sizeof(SAVEDGAME), 1, fp); fclose(fp); // // Adjust endianness // DO_BYTESWAP(&s, sizeof(SAVEDGAME)); // // Cash amount is in DWORD, so do a wordswap in Big-Endian. // #if SDL_BYTEORDER == SDL_BIG_ENDIAN s.dwCash = ((s.dwCash >> 16) | (s.dwCash << 16)); #endif // // Get all the data from the saved game struct. // gpGlobals->viewport = PAL_XY(s.wViewportX, s.wViewportY); gpGlobals->wMaxPartyMemberIndex = s.nPartyMember; gpGlobals->wNumScene = s.wNumScene; gpGlobals->fNightPalette = (s.wPaletteOffset != 0); gpGlobals->wPartyDirection = s.wPartyDirection; gpGlobals->wNumMusic = s.wNumMusic; gpGlobals->wNumBattleMusic = s.wNumBattleMusic; gpGlobals->wNumBattleField = s.wNumBattleField; gpGlobals->wScreenWave = s.wScreenWave; gpGlobals->sWaveProgression = 0; gpGlobals->wCollectValue = s.wCollectValue; gpGlobals->wLayer = s.wLayer; gpGlobals->wChaseRange = s.wChaseRange; gpGlobals->wChasespeedChangeCycles = s.wChasespeedChangeCycles; gpGlobals->nFollower = s.nFollower; gpGlobals->dwCash = s.dwCash; memcpy(gpGlobals->rgParty, s.rgParty, sizeof(gpGlobals->rgParty)); memcpy(gpGlobals->rgTrail, s.rgTrail, sizeof(gpGlobals->rgTrail)); gpGlobals->Exp = s.Exp; gpGlobals->g.PlayerRoles = s.PlayerRoles; memcpy(gpGlobals->rgPoisonStatus, s.rgPoisonStatus, sizeof(gpGlobals->rgPoisonStatus)); memcpy(gpGlobals->rgInventory, s.rgInventory, sizeof(gpGlobals->rgInventory)); memcpy(gpGlobals->g.rgScene, s.rgScene, sizeof(gpGlobals->g.rgScene)); memcpy(gpGlobals->g.rgObject, s.rgObject, sizeof(gpGlobals->g.rgObject)); memcpy(gpGlobals->g.lprgEventObject, s.rgEventObject, sizeof(EVENTOBJECT) * gpGlobals->g.nEventObject); gpGlobals->fEnteringScene = FALSE; PAL_CompressInventory(); // // Success // return 0; }
VOID PAL_StartFrame( VOID ) /*++ Purpose: Starts a video frame. Called once per video frame. Parameters: None. Return value: None. --*/ { // // Run the game logic of one frame // LoginInfo("PAL_StartFrame\n" ); PAL_GameUpdate(TRUE); if (gpGlobals->fEnteringScene) { return; } // // Update the positions and gestures of party members // PAL_UpdateParty(); // // Update the scene // PAL_MakeScene(); VIDEO_UpdateScreen(NULL); if (g_InputState.dwKeyPress & kKeyMenu) { // // Show the in-game menu // PAL_InGameMenu(); } else if (g_InputState.dwKeyPress & kKeyUseItem) { // // Show the use item menu // PAL_GameUseItem(); } else if (g_InputState.dwKeyPress & kKeyStatus) { // // Show the player status // PAL_PlayerStatus(); } else if (g_InputState.dwKeyPress & kKeySearch) { // // Process search events // PAL_Search(); } if (--gpGlobals->wChasespeedChangeCycles == 0) { gpGlobals->wChaseRange = 1; } }
VOID PAL_Search( VOID ) /*++ Purpose: Process searching trigger events. Parameters: None. Return value: None. --*/ { int x, y, xOffset, yOffset, dx, dy, dh, ex, ey, eh, i, k, l; LPEVENTOBJECT p; PAL_POS rgPos[13]; LoginInfo("PAL_Search\n" ); // // Get the party location // x = PAL_X(gpGlobals->viewport) + PAL_X(gpGlobals->partyoffset); y = PAL_Y(gpGlobals->viewport) + PAL_Y(gpGlobals->partyoffset); if (gpGlobals->wPartyDirection == kDirNorth || gpGlobals->wPartyDirection == kDirEast) { xOffset = 16; } else { xOffset = -16; } if (gpGlobals->wPartyDirection == kDirEast || gpGlobals->wPartyDirection == kDirSouth) { yOffset = 8; } else { yOffset = -8; } rgPos[0] = PAL_XY(x, y); for (i = 0; i < 4; i++) { rgPos[i * 3 + 1] = PAL_XY(x + xOffset, y + yOffset); rgPos[i * 3 + 2] = PAL_XY(x, y + yOffset * 2); rgPos[i * 3 + 3] = PAL_XY(x + xOffset, y); x += xOffset; y += yOffset; } for (i = 0; i < 13; i++) { // // Convert to map location // dh = ((PAL_X(rgPos[i]) % 32) ? 1 : 0); dx = PAL_X(rgPos[i]) / 32; dy = PAL_Y(rgPos[i]) / 16; // // Loop through all event objects // for (k = gpGlobals->g.rgScene[gpGlobals->wNumScene - 1].wEventObjectIndex; k < gpGlobals->g.rgScene[gpGlobals->wNumScene].wEventObjectIndex; k++) { p = &(gpGlobals->g.lprgEventObject[k]); ex = p->x / 32; ey = p->y / 16; eh = ((p->x % 32) ? 1 : 0); if (p->sState <= 0 || p->wTriggerMode >= kTriggerTouchNear || p->wTriggerMode * 6 - 4 < i || dx != ex || dy != ey || dh != eh) { continue; } // // Adjust direction/gesture for party members and the event object // if (p->nSpriteFrames * 4 > p->wCurrentFrameNum) { p->wCurrentFrameNum = 0; // use standing gesture p->wDirection = (gpGlobals->wPartyDirection + 2) % 4; // face the party for (l = 0; l <= gpGlobals->wMaxPartyMemberIndex; l++) { // // All party members should face the event object // gpGlobals->rgParty[l].wFrame = gpGlobals->wPartyDirection * 3; } // // Redraw everything // PAL_MakeScene(); VIDEO_UpdateScreen(NULL); } // // Execute the script // p->wTriggerScript = PAL_RunTriggerScript(p->wTriggerScript, k + 1); // // Clear inputs and delay for a short time // UTIL_Delay(50); PAL_ClearKeyState(); return; // don't go further } } }
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; LoginInfo("PAL_GameUpdate\n" ); // // 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(); } // // 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++) { LPEVENTOBJECT p = &gpGlobals->g.lprgEventObject[wEventObjectID - 1]; if (p->sVanishTime != 0) { p->sVanishTime += ((p->sVanishTime < 0) ? 1 : -1); 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++) { LPEVENTOBJECT 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++; }
VOID PAL_GameUseItem( VOID ) /*++ Purpose: Allow player use an item in the game. Parameters: None. Return value: None. --*/ { WORD wObject; LoginInfo("PAL_GameUseItem\n" ); while (TRUE) { wObject = PAL_ItemSelectMenu(NULL, kItemFlagUsable); if (wObject == 0) { return; } if (!(gpGlobals->g.rgObject[wObject].item.wFlags & kItemFlagApplyToAll)) { // // Select the player to use the item on // WORD wPlayer = 0; while (TRUE) { wPlayer = PAL_ItemUseMenu(wObject); if (wPlayer == MENUITEM_VALUE_CANCELLED) { break; } // // Run the script // gpGlobals->g.rgObject[wObject].item.wScriptOnUse = PAL_RunTriggerScript(gpGlobals->g.rgObject[wObject].item.wScriptOnUse, wPlayer); // // Remove the item if the item is consuming and the script succeeded // if ((gpGlobals->g.rgObject[wObject].item.wFlags & kItemFlagConsuming) && g_fScriptSuccess) { PAL_AddItemToInventory(wObject, -1); } } } else { // // Run the script // gpGlobals->g.rgObject[wObject].item.wScriptOnUse = PAL_RunTriggerScript(gpGlobals->g.rgObject[wObject].item.wScriptOnUse, 0xFFFF); // // Remove the item if the item is consuming and the script succeeded // if ((gpGlobals->g.rgObject[wObject].item.wFlags & kItemFlagConsuming) && g_fScriptSuccess) { PAL_AddItemToInventory(wObject, -1); } return; } } }