📄 game.cpp
字号:
counter+=size;
size=TOTAL_SUIT*TOTAL_PLAYER*sizeof(boolean);
MEMCPY(m_money.unlockedSuits,data+counter,size);
counter+=size;
// synchronize the unlock system
updateMoneyUnlock(m_money);
}
if(LoadStory!=0)//only for load story info
{
moneyMatchInit(m_money);
m_money.currStrikeCount=data[counter];
m_money.currSpareCount=data[counter+1];
counter+=2;
}
IFILE_Release( pIFile );
m_pEngine->GetMem()->StackFree(NULL);
DBGPRINTF("load data complete.");
return true;
}
// save record info into a save file
int CGame::saveGeneralRecord(saveType type, int firstTime)
{
int counter = 0;
int i,j;
int bytenum = 6+BALL_COUNT+BONUS_COUNT+PLAYER_COUNT;
bytenum+=PLAYER_COUNT*CLOTH_COUNT+BALLICON_COUNT+LANE_COUNT*2;
bytenum+=23+sizeof(ScoreInfo)*2+40;
bytenum+=12+24+1; //// for coin system
int byteMoney=sizeof(long)+(TOTAL_BALL+TOTAL_PLAYER+TOTAL_SUIT*TOTAL_PLAYER)*sizeof(boolean);// for money system;
bytenum+=byteMoney;// for money system
bytenum+=2;
saveType svtype=type;
if(m_saveFlag>0)return m_saveFlag;
// allocate the memory
//char data[SAVE_DATA_LENGTH];
unsigned char * data;
data = (unsigned char *)m_pEngine->GetMem()->StackMalloc(bytenum);
DBGPRINTF("began to save data.");
if(firstTime==1 || firstTime == 2)
{
uint32 freespace=IFILEMGR_GetFreeSpace( (IFileMgr*)m_pEngine->pFileMgr,NULL);
DBGPRINTF("the freespace is %d .",freespace);
int error =IFILEMGR_GetLastError((IFileMgr*)m_pEngine->pFileMgr);
DBGPRINTF("the last error for the file system is %d. ",error);
if (freespace<=(uint32)(bytenum*2) && firstTime ==1)// first time run
return SAVE_CREATE_ERROR;
if (firstTime == 2 && freespace <= (uint32)bytenum)//every time the game begin to run(test if there exist free space)
return SAVE_CREATE_ERROR;
}
//read the file first
IFile * pIFile = NULL;
pIFile = IFILEMGR_OpenFile ( (IFileMgr*)m_pEngine->pFileMgr, SAVEFILE_NAME1, _OFM_READWRITE);
if(pIFile == NULL)
{
IFILEMGR_Remove( (IFileMgr*)m_pEngine->pFileMgr, SAVEFILE_NAME);
pIFile=IFILEMGR_OpenFile((IFileMgr*)m_pEngine->pFileMgr, SAVEFILE_NAME1, _OFM_CREATE);
if (!pIFile)
{
IFILEMGR_Remove( (IFileMgr*)m_pEngine->pFileMgr, SAVEFILE_NAME1);
DBGPRINTF("the file can not open. line %d.",__LINE__);
return SAVE_CREATE_ERROR;
}
svtype=SAVE_GENERAL;
}else{
IFILE_Seek( pIFile, _SEEK_START, 0);
}
if (NULL != pIFile&&svtype!=SAVE_GENERAL)// read the exist file
{
unsigned int count = IFILE_Read(pIFile, data,bytenum);// read the files
if (count==0)// error, no data is readed
{
svtype=SAVE_GENERAL;
}
}
if((svtype&SAVE_OPTION)!=0)// save the option
{
// data[0] = m_pEngine->GetSound()->soundOn;
data[1] = m_pEngine->GetSound()->GetVibOn();
data[2] = m_bIsShowHint;
data[3] = m_pEngine->GetSound()->playerSoundOn;
data[4] = m_pScene->GetTutorialStage();
data[5]= m_pEngine->GetSound()->m_soundVolume;
}
if((svtype&SAVE_STORY)!=0)//save story
{
// ball select
counter+=6;
for(i =0; i< BALL_COUNT; ++i)
{
data[counter+i] = m_SaveBallCanSel[i];
}
counter+=BALL_COUNT;
// bonus select
for(i =0; i< BONUS_COUNT; ++i)
{
data[counter+i] = m_SaveBonusCanSel[i];
}
counter+=BONUS_COUNT;
// player select
for(i =0; i< PLAYER_COUNT; ++i)
{
data[counter+i] = m_SavePlayerCanSel[i];
}
counter+=PLAYER_COUNT;
// player cloth select
for(i=0; i<PLAYER_COUNT; i++)
for(j=0;j<CLOTH_COUNT;j++)
data[counter+i*CLOTH_COUNT+j] =m_SaveClothCanSel[i][j];
counter+=PLAYER_COUNT*CLOTH_COUNT;
// ball icon select
for(i=0;i<BALLICON_COUNT;i++)
data[counter+i]=m_SaveBallIconCanSel[i];
counter+=BALL_COUNT;
// lane select
for(i=0;i<LANE_COUNT;i++)
data[counter+i]=m_SaveLaneCanSel[i];
counter+=LANE_COUNT;
// lane, camera view
for(i=0;i<LANE_COUNT;i++)
data[counter+i]=m_SaveLaneCanView[i];
counter+=LANE_COUNT;
///////////////////////////////////////////////////////////////////////////
data[counter]=m_SaveStoryPassed;
data[counter+1]=m_SavePlayerId;
data[counter+2]=m_SaveStageIndex;
data[counter+3]=m_SaveCurPlayer;
data[counter+4]=m_SavePlayerRound[0]; //current round of the match
data[counter+5]=m_SavePlayerRound[1]; //current round of the match
data[counter+6]=m_SavePlayerBall[0];
data[counter+7]=m_SavePlayerBall[1];
data[counter+8]=m_SavePlayerBallIcon[0];
data[counter+9]=m_SavePlayerBallIcon[1];
data[counter+10]=((byte)(m_SavePlayerPinMode[0]&0x00ff)&0xff)&0xff;
data[counter+11]=((byte)((m_SavePlayerPinMode[0]&0xff00)>>8)&0xff)&0xff;
data[counter+12]=((byte)(m_SavePlayerPinMode[1]&0x00ff)&0xff)&0xff;
data[counter+13]=((byte)((m_SavePlayerPinMode[1]&0xff00)>>8)&0xff)&0xff;
data[counter+14]=m_SavePlayerClothesID[0];
data[counter+15]=m_SavePlayerClothesID[1];
data[counter+16]=m_SaveCanContinue;
data[counter+17]=m_SaveQMFinishTime;
data[counter+18]=m_SaveCanCamView;
data[counter+19]=m_SavesmCoinPassed;
data[counter+20]=m_SaveIsDraw;
data[counter+21]=m_SaveGameFinish;
data[counter+22]=m_SaveDrawCount;
counter+=23;
int t=sizeof(ScoreInfo);
MEMCPY(&data[counter],&m_SaveScores[0],t);
MEMCPY(&data[counter]+t,&m_SaveScores[1],t);
counter+=t*2;
for(i=0;i<10;i++)
for(j=0;j<4;j++)
data[counter+i*4+j]=m_SaveCoinPassed[i][j];
counter+=40;//i*j;
//// for coin system <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
data[counter] = m_pMatch->m_cnMatchCount;
data[counter+1] = m_pMatch->m_cnNextUCoinMatch;
data[counter+2] = m_pMatch->m_cnNextFCoinMatch;
data[counter+3] = m_pMatch->m_hasUnlockCoin;
data[counter+4] = m_pMatch->m_hasFuncCoin;
data[counter+5] = m_pMatch->m_uCoinRound;
data[counter+6] = m_pMatch->m_uCoinPassed;
data[counter+7] = m_pMatch->m_uCoinType;
data[counter+8] = m_pMatch->m_uCoinInfo;
data[counter+9] = m_pMatch->m_fCoinRound;
data[counter+10] = m_pMatch->m_fCoinPassed;
data[counter+11] = m_pMatch->m_fCoinType;
counter+=12;
int temp;
temp=(int)m_pMatch->m_uCoinPos.x;
MEMCPY(&data[counter],&temp, 4);
temp=(int)m_pMatch->m_uCoinPos.y;
MEMCPY(&data[counter+4],&temp, 4);
temp=(int)m_pMatch->m_uCoinPos.z;
MEMCPY(&data[counter+8],&temp, 4);
temp=(int)m_pMatch->m_fCoinPos.x;
MEMCPY(&data[counter+12],&temp, 4);
temp=(int)m_pMatch->m_fCoinPos.y;
MEMCPY(&data[counter+16],&temp, 4);
temp=(int)m_pMatch->m_fCoinPos.z;
MEMCPY(&data[counter+20],&temp, 4);
counter+=24;
//// for coin system >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//// for BUG 3854 store isNextDeliveryDone
/*if(m_pScene->GetIsInTenpinArea() && m_bNextDeliDone != 1)
{
m_pMatch->NextDelivery();
m_bNextDeliDone = 1;
}
data[counter] = m_pScene->GetCheatMode() != WITHOUT_CHEAT ? 1 : m_bNextDeliDone;////true;//m_bNextDeliDone;//m_pScene->GetCheatMode() == WITHOUT_CHEAT ? m_bNextDeliDone : true;
*/++counter;
}
if((svtype&SAVE_MONEY)!=0)//save story
{
int size=0;
counter=bytenum-byteMoney-3;
size=sizeof(long);
MEMCPY(data+counter,&(m_money.totalMoney),size);
counter+=size;
size=TOTAL_BALL*sizeof(boolean);
MEMCPY(data+counter,m_money.unlockedBall,size);
counter+=size;
size=TOTAL_PLAYER*sizeof(boolean);
MEMCPY(data+counter,m_money.unlockedCharacters,size);
counter+=size;
size=TOTAL_SUIT*TOTAL_PLAYER*sizeof(boolean);
MEMCPY(data+counter,m_money.unlockedSuits,size);
counter+=size;
}
if ((svtype&SAVE_STORY)!=0)
{
counter=bytenum-2-1;
data[counter]=(byte)m_money.currStrikeCount;
data[counter+1]=(byte)m_money.currSpareCount;
counter+=2;
}
DBGPRINTF("counter %d bytes.",counter);
IFILE_Seek( pIFile, _SEEK_START, 0);
int writtenNum=IFILE_Write( pIFile, data, bytenum);
IFILE_Release( pIFile );
m_pEngine->GetMem()->StackFree(NULL);
DBGPRINTF("written %d bytes.",writtenNum);
if(writtenNum!=bytenum )
{
int a;
if (firstTime == 1) {
a=IFILEMGR_Remove( (IFileMgr*)m_pEngine->pFileMgr, SAVEFILE_NAME1);
}
DBGPRINTF("a== %d ",a);
return SAVE_READ_ERROR;
}
DBGPRINTF("save success!");
return SAVE_SUCCESS;
}
//// << ==========================================================================
//// 2005.1.11 YI WEN HU
// game logic
void CGame::update()
{
// process for suspend
if(m_isSuspend){
m_isSuspend=0;
if(((m_GameState==GS_MATCH||m_GameState==GS_STORYMODE)&&(m_MatchState==MS_DELIVERY||MS_ONLINE_WAIT==m_MatchState))
|| m_GameState==GS_CAMERAVIEW
){
pauseMIDI();
if (!m_pause) {
m_pMenu->ResetState();
m_pMenu->SetState(STATE_PAUSE);
}
m_pause=true;
if(m_pMatch->m_mode==MODE_BONUS||m_GameState==GS_CAMERAVIEW)
{
m_pMenu->SetState(STATE_BONUSMODE);
}
if(m_pMatch->m_mode==MODE_STORY||m_pMatch->m_mode==MODE_STORY_CONTINUE)
{
m_pMenu->SetState(STATE_STORYMODE);
}
}
}
////
// process for special effect
if (m_pEngine->GetInput()->KeyPressed(gk_DOWN) && m_pEngine->GetInput()->KeyPressed(gk_NUM0))
m_pScene->m_render3D.GetG3d()->m_skeleton = !m_pScene->m_render3D.GetG3d()->m_skeleton;
// process for pause state
if(m_pause)
{
if(m_pMatch->m_mode==MODE_STORY)
{
m_storySave = false;
}
m_pMenu->Update();
if (m_pMenu->GetState() == STATE_STARTGAME)
{
m_pause=false;
if(m_GameState != GS_CAMERAVIEW)
{
resumeMIDI();
//m_pEngine->GetSound()->playMIDI(ConvertSoundID(ID_SOUND_AMBIENCE),1);
}
}
if (m_pMenu->GetState() == STATE_SUSPEND) {
m_pause=false;
// saveStoryInfo();
// saveGeneralRecord(SAVE_GENERAL);
ReleaseLocalResource();
m_GameState=GS_MENU;
m_pMenu->ResetState();
m_pMenu->SetState(STATE_MAINMENU);
m_pEngine->GetSound()->playMIDI(ConvertSoundID(ID_SOUND_MENU),1);
#ifdef ONLINE
if(m_bOnlineMode)//online mode back
{
onlineClear();
m_pEngine->GetNetwork()->stopConnect();
}
#endif
}
return;
}
// update game state
switch(m_GameState)
{
case GS_MENU:
{
int ret=UpdateMenu(); //// menu logic
if(ret>0)
m_pMatch->m_mode=ret;
if(ret==-1)
m_GameState=GS_END;
else if(ret==MODE_STORY)
{
m_GameState=GS_STORYMODE;
InitStoryState(); // New Game, Story mode
m_step=0;
}
else if(ret==MODE_STORY_CONTINUE)
{
m_GameState=GS_STORYMODE; // Continue, Story mode
m_StoryModeState=SMS_CONTINUE;
m_pMatch->m_mode=MODE_STORY;
loadGeneralRecord(1);
m_step=0;
return;
}
else if(ret==MODE_CAMERA)
{ // loading for CameraView
m_GameState=GS_CAMERAVIEW_LOADING;
m_step=0;
}
else if(ret>0)
{
m_GameState=GS_LOADING;
m_step=0;
}
break;
}
case GS_LOADING: // loading state
// load match resource
if(Loading(m_step))
{
if( m_pScene->m_object[RENDER_BALL] )
m_pScene->m_object[RENDER_BALL]->SetHideProperty(TRUE);
if( m_pScene->m_object[RENDER_SETTING_TENPIN] )
m_pScene->m_object[RENDER_SETTING_TENPIN]->SetHideProperty(TRUE);
if( m_pScene->m_object[RENDER_GRABBING_TENPIN] )
m_pScene->m_object[RENDER_GRABBING_TENPIN]->SetHideProperty(TRUE);
if( m_pScene->m_object[RENDER_PLAYER] )
m_pScene->m_object[RENDER_PLAYER]->SetHideProperty(TRUE);
if( m_pScene->m_object[RENDER_PLAYER2] )
m_pScene->m_object[RENDER_PLAYER2]->SetHideProperty(TRUE);
if(0==m_pMatch->GetLane())
m_pEngine->GetSound()->playMIDI(ConvertSoundID(ID_SOUND_CLUB_1), 0);
else if(1==m_pMatch->GetLane())
m_pEngine->GetSound()->playMIDI(ConvertSoundID(ID_SOUND_CLUB_2), 0);
else if(2==m_pMatch->GetLane())
m_pEngine->GetSound()->playMIDI(ConvertSoundID(ID_SOUND_CLUB_3), 0);
m_pScene->m_render3D.GetG3d()->setZDist(FOV_CAMERA_VIEW);
m_pScene->m_cCamera->SetStage(CCSS_INTRODUCTION);
m_pScene->m_cCamera->UpdateCamera();
#ifdef ONLINE
// for online mode
if(!m_bOnlineMode)
m_GameState=GS_LEVEL_INTRODUCTION;
else
{
m_GameState=GS_MATCH;
InitMatchState();
}
#else
m_GameState=GS_LEVEL_INTRODUCTION;
#endif
}
m_step++;
//Milo 03-30
if(m_pEngine->GetInput()->KeyPressed(VKEY_MENU_CLR))
{
m_step = 0;
ReleaseLocalResource();
m_pMenu->ResetState();
m_pMenu->SetState(STATE_MAINMENU); // back to main menu
m_GameState=GS_MENU;
resumeMIDI();
m_pEngine->GetSound()->playMIDI(ConvertSoundID(ID_SOUND_MENU),1);
}
break;
case GS_LEVEL_INTRODUCTION:
// call camera and update
m_pScene->m_cCamera->UpdateCamera();
if(m_pScene->m_cCamera->m_bFinished || m_pEngine->GetInput()->KeyPressed(VKEY_MENU_SKIP | VKEY_MENU_CLR))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -