?? cbctrls.cpp
字號:
if( nEndZ == 0 && codeG == MAP_DATA_NONE )
{
Assert(0);
break;
}
nEndZ--;
}
}
int MARCH_Status;
Assert( nEndZ>=0&&nEndZ<3 );
MARCH_Status=March_Interface( pUnit->Draw.nX, pUnit->Draw.nY,pUnit->Draw.nLayer, nEndx, nEndy, nEndZ );
if( bShouldDuSe == TRUE&& MARCH_Status==MARCH_ERROR_MARCH_TRACK )
{
if(MARCH_TrackForward[0]==255)
{ // 應該堵塞,而且沒找到路,則馬上堵塞
OutputDebugString( "CTRL_TASK : Find no way there!\n" );
pUnit->Status.nTaskID = DUSE; // 直接堵塞
return;
}
else
{ // 應該堵塞,而且路不完整,則預設堵塞
OutputDebugString( "not reached!\n" );
pUnit->Status.nParam4 = DUSE; // 預設堵塞
}
}
else if( bShouldDuSe == TRUE )
{
if(MARCH_TrackForward[128]!=255)
{ // 路線超界了,預設堵塞
OutputDebugString( "not reached!\n" );
pUnit->Status.nParam4 = DUSE; // 預設堵塞
}
}
else if( bShouldDuSe == FALSE && MARCH_TrackForward[0]==255 )
{ // 不應該堵塞,但是沒找到路,則馬上堵塞
OutputDebugString( "CTRL_TASK : Find no way there!\n" );
pUnit->Status.nTaskID = DUSE; // 直接堵塞
return;
}
memcpy( &pUnit->MarchTrack, &MARCH_TrackForward, sizeof(pUnit->MarchTrack) );
pUnit->StepNum=0;
}
}
// 狀態結束,Status的nTaskID為QUXIAO,bDone為TRUE
// 自動設置下一狀態
if( pUnit->Status.nTaskID != QUXIAO && pUnit->Status.bDone )
{
Assert( pUnit->Draw.ptOff.x == 0 || pUnit->Draw.ptOff.y == 0 );
#ifdef _DEBUG_OFFSET_
if( pUnit->Draw.ptOff.x != 0 || pUnit->Draw.ptOff.y != 0 )
{
// WriteLogFile( "off.log", "change\n" );
}
#endif //_DEBUGS_OFFSET_
// 注意:接受不到堵塞狀態
// 設置動畫幀狀態
if( EYE_IfUnitIsWorker( pUnit )
&& pUnit->Soldier.nResource != 0 )
{
if( pUnit->Soldier.nResType == SHULIN ) // 樹林
{
pUnit->Draw.nState = pUnit->Draw.nDir+
MAP_Lib.AniSeq[pUnit->Draw.nFile].nEventBegin[3];
}
else if( pUnit->Soldier.nResType == MAITIAN // 麥田
|| pUnit->Soldier.nResType == LIANGCANG ) // 糧倉
{
pUnit->Draw.nState = pUnit->Draw.nDir+
MAP_Lib.AniSeq[pUnit->Draw.nFile].nEventBegin[5];
}
else if( pUnit->Soldier.nResType == TIEKUANG ) // 鐵礦
{
pUnit->Draw.nState = pUnit->Draw.nDir+
MAP_Lib.AniSeq[pUnit->Draw.nFile].nEventBegin[4];
}
else // 一般狀態
{
pUnit->Draw.nState = pUnit->Draw.nDir;
}
}
else pUnit->Draw.nState = pUnit->Draw.nDir;
if( !EYE_IfUnitIsBuild( pUnit ) )
{
pUnit->Draw.nFrame = 1;
pUnit->Draw.nCol = MAP_Lib.AniSeq[pUnit->Draw.nFile].nAniSeq[pUnit->Draw.nState][pUnit->Draw.nFrame]+
MAP_Lib.AniSeq[pUnit->Draw.nFile].nOffset;
pUnit->Draw.nRow = 0;
}
if( pUnit->Status.nTaskID == pUnit->Task.nTaskID )
{ // 對于單狀態任務的狀態或多狀態的任務的第二個狀態,
// 結束后設置任務結束
Assert( pUnit->nHasShadow == 1 );
pUnit->Status.nTaskID = QUXIAO;
pUnit->Task.nTaskID = QUXIAO;
pUnit->Task.bDone = FALSE;
pUnit->Task.bIRQ = FALSE;
pUnit->nCounter = 0;
/*
pUnit->Draw.nState = pUnit->Draw.nDir+MAP_Lib.AniSeq[pUnit->Draw.nFile].nEventBegin[0];
pUnit->Draw.nCol = MAP_Lib.AniSeq[pUnit->Draw.nFile].nAniSeq[pUnit->Draw.nState][pUnit->Draw.nFrame]+
MAP_Lib.AniSeq[pUnit->Draw.nFile].nOffset;
pUnit->Draw.nRow = 0;
*/
// OutputDebugString( "CTRL_TASK : Done!\n" );
}
else
{ // 對于多狀態任務的第一個狀態,結束后設置下一個狀態
CTRL_TASK_Copy( &pUnit->Status, &pUnit->Task );
pUnit->Status.bDone = FALSE;
pUnit->nCounter = 0;
}
}
}
//////////////////////
//////////////////////
// basic functions
// 基本函數
// 產生單元,對陰影有特殊處理
// 產生單元時,調用SHADOW_Draw()同時產生陰影.
// codeU : unit code to identifies the type of the unit
// nZ, nX, nY : position to locate,產生的位置
// return : unit ID extended code if successful,
// MAP_DATA_NONE if failed
WORD CTRL_UNIT_Create( int nZ, int nX, int nY, DWORD codeU, BOOL bFind/*=TRUE*/ )
{
// 尋找附近一個合適的地方放置單元
if( bFind )
{
POINT pt;
pt = MAP_FindRegion( nZ, nX, nY, codeU );
if( pt.x == -1 )
{
OutputDebugString( "CTRL_UNIT_Create Error(0): Cannot find a place to set general!\n" );
return MAP_DATA_NONE;
}
nX = pt.x, nY = pt.y;
}
// 創建單元
WORD codeUEx = MAP_SetUnitData( nZ, nX, nY, codeU );
if( codeUEx == MAP_DATA_NONE )
{
OutputDebugString( "CTRL_UNIT_Create Error(1): Cannot create unit!\n" );
// 戰場上的物體過多,不能增加了
FACE_ShowPromptInfor( 18 );
return codeUEx;
}
// 設置單元其它信息
struct UNIT_STRUCT *pUnit = MAP_GetUnit( codeUEx );
Assert( pUnit->nType != MAP_UNIT_TYPE_NONE );
Assert( nX == pUnit->Draw.nX && nY == pUnit->Draw.nY );
// 生命值
pUnit->nLife = EYE_GetFullLife( pUnit->Draw.nPlayer, pUnit->Draw.nFile );
pUnit->nIDAttackMe = MAP_DATA_NONE;
if( !EYE_IfUnitIsBuild( pUnit ) )
{
pUnit->Draw.nFrame = 1;
#ifdef _MAP_COMPRESS_
pUnit->Draw.nCol = MAP_Lib.AniSeq[pUnit->Draw.nFile].nAniSeq[pUnit->Draw.nState][pUnit->Draw.nFrame]+MAP_Lib.AniSeq[pUnit->Draw.nFile].nOffset;
pUnit->Draw.nRow = 0;
#else
pUnit->Draw.nRow = stct.nRow;
pUnit->Draw.nCol = stct.nCol;
#endif
}
// 是主帥帳或糧倉,增加本君主的FoodStore數量
if( pUnit->Draw.nFile == 0
|| pUnit->Draw.nFile == 1
|| pUnit->Draw.nFile == 10
|| pUnit->Draw.nFile == 11 )
{
GAME.Players[pUnit->Draw.nPlayer].nFoodStore++;
}
if( EYE_IfUnitIsSoldier( pUnit ) )
{
pUnit->Soldier.nGenID = MAP_DATA_NONE;
pUnit->Soldier.nResType = QXZIYUAN; // 初始化工人的資源類型為空
}
else if( EYE_IfUnitIsGen( pUnit ) )
{
// 清空將領手下的士兵數組
memset( pUnit->Gen.wTroop, MAP_DATA_NONE, sizeof(WORD)*GENERAL_TROOP_MAX );
}
// draw shadow
// 只有我方才有陰影改變的問題
if( GAME.nMe == pUnit->Draw.nPlayer )
{
// 視野
int nVRange = EYE_GetViewRange( &pUnit->Draw );
SHADOW_Draw0( pUnit->Draw.nX, pUnit->Draw.nY,
pUnit->Draw.nXLast, pUnit->Draw.nYLast, nVRange );// Draw solid shadow
//lwc
//存在
Assert( pUnit->nHasShadow == 0 );
SHADOW_existent(pUnit->Draw.nX,pUnit->Draw.nY,nVRange);
//lwc
}
pUnit->nHasShadow++;
// draw to minimap
MINI_SetUnitData( pUnit->Draw.nX, pUnit->Draw.nY, pUnit->Draw.nPlayer, pUnit->Draw.nLocationSize ); // for minimap
return codeUEx;
}
// 刪除單元,對陰影有特殊處理
// pUnit : unit pointer to be destroyed
// return : TRUE if successful
BOOL CTRL_UNIT_Destroy( struct UNIT_STRUCT *pUnit )
{
WORD codeUEx;
// draw shadow
#ifdef _DEBUG
if( !pUnit )
{
OutputDebugString( "CTRL_UNIT_Create Error(2): Cannot find unit!\n" );
return FALSE;
}
#endif
// 是主帥帳或糧倉,減少本君主的FoodStore數量
if( pUnit->Draw.nFile == 0
|| pUnit->Draw.nFile == 1
|| pUnit->Draw.nFile == 10
|| pUnit->Draw.nFile == 11 )
{
GAME.Players[pUnit->Draw.nPlayer].nFoodStore--;
}
if( pUnit->nHasShadow > 0 )
{ // 如果不在建筑中,要刪除陰影
// erase from minimap
MINI_SetGroundData( pUnit->Draw.nXLast, pUnit->Draw.nYLast, pUnit->Draw.nLocationSize ); // for minimap
// 只有我方才有陰影改變的問題
if( GAME.nMe == pUnit->Draw.nPlayer )
{
//lwc
// 消失
int nVRange = EYE_GetViewRange( &pUnit->Draw );
Assert( pUnit->nHasShadow == 1 );
SHADOW_death (pUnit->Draw.nX,pUnit->Draw.nY,nVRange);
//lwc
}
pUnit->nHasShadow--;
codeUEx = MAP_SetUnitData( pUnit->Draw.nLayer, pUnit->Draw.nX, pUnit->Draw.nY, MAP_DATA_NONE );
}
else
{
GAME.Players[pUnit->Draw.nPlayer].wUnitCounter--;
pUnit->nType = MAP_UNIT_TYPE_NONE;
}
// 在沒找到錯誤之前,用來修正錯誤
Assert( pUnit->nType == MAP_UNIT_TYPE_NONE );
#ifndef _DEBUG
pUnit->nType = 0;
#endif
if( codeUEx != MAP_DATA_NONE )
{
OutputDebugString( "CTRL_UNIT_Destroy Error(1): Error when destroying unit!\n" );
return FALSE;
}
return TRUE;
}
///////////////////
//////////////////
// only used by CTRL_UNIT_Move()
void CTRL_UNIT_MoveShadow( struct CTRL_FRAME_STRUCT *pDraw );
// 移動單元,每當移動一個格子后,修改陰影數組的內容
// pDraw : unit to be moved
// nType : type of unit
// 返回 0,被堵住;1,可以走;2,沼澤;>2,遇到城門,返回城門的ID
int CTRL_UNIT_Move( struct CTRL_FRAME_STRUCT *pDraw, int nType )
{
BOOL ret;
ret = MAP_MoveUnit( pDraw, nType );
if( ret == FALSE )
{
int nNum = MAP_nLocationNum[pDraw->nLocationSize];
int nX[16], nY[16];
BOOL bOdd = pDraw->nY&1;
for( int i=0; i<nNum; i++ )
{
nX[i] = pDraw->nX+MAP_ptLocation[bOdd][i].x;
nY[i] = pDraw->nY+MAP_ptLocation[bOdd][i].y;
Assert( !EYE_IfOutOfRange( nX[i], nY[i] ) );
struct UNIT_STRUCT *pU = MAP_GetUnit( nX[i], nY[i] );
if( pU != NULL )
{
if( EYE_IfUnitIsDoor( pU )
&& pU->Draw.nPlayer == pDraw->nPlayer ) // 是自己的城門
{
return pU->nID;
}
}
}
return 0;
}
// 移動陰影
CTRL_UNIT_MoveShadow( pDraw );
// 檢測是否該地形是沼澤
WORD codeG = MAP_GetGroundData( pDraw->nLayer, pDraw->nX, pDraw->nY );
Assert( codeG != MAP_DATA_NONE );
struct MAP_GROUND_CODE_STRUCT stctG;
MAP_GroundDeCode( codeG, &stctG );
if( stctG.nFile == 4 ) // 沼澤
return 2;
return 1;
}
void CTRL_UNIT_MoveShadow( struct CTRL_FRAME_STRUCT *pDraw )
{
// 只有我方才有陰影改變的問題
if( GAME.nMe == pDraw->nPlayer )
{
// 視野
int nVRange = EYE_GetViewRange( pDraw );
SHADOW_Draw( pDraw->nX, pDraw->nY,
pDraw->nXLast, pDraw->nYLast,
nVRange ); // Draw solid shadow
}
// 敵人也畫
// erase from minimap
MINI_SetGroundData( pDraw->nXLast, pDraw->nYLast, pDraw->nLocationSize ); // for minimap
// draw to minimap
MINI_SetUnitData( pDraw->nX, pDraw->nY, pDraw->nPlayer, pDraw->nLocationSize ); // for minimap
}
///////////////////
///////////////////
/*
// 判斷是否該將領應該撤離戰場,在解散部隊后發生
BOOL CTRL_UNIT_ToDisapear( struct UNIT_STRUCT *pUnitG )
{
int i;
Assert( EYE_IfUnitIsGen( pUnitG ) );
// 不能直接刪除,必須下達命令
// 查看是否可以刪除將領(當將領所帶領的士兵為0時)
int bYes = TRUE;
for( i=0; i<GENERAL_TROOP_MAX; i++ )
{
if( pUnitG->Gen.wTroop[i] != MAP_DATA_NONE )
{
bYes = FALSE; break;
}
}
if( bYes )
{
struct CTRL_TASK_STRUCT Task;
CTRL_TASK_Clear( &Task );
Task.nLevel = 0; // 該命令的級別,0 is the highest, 5 is the lowest
Task.nID = pUnitG->nID;
Task.nTaskID = SHANCHU; // 任務
Task.nTaskIDEx = 1; // 只是刪除部隊
Task.bDone = TRUE;
// 下達任務到隊列中
CTRL_TASK_DeployByComputer( pUnitG->Draw.nPlayer, &Task );
return TRUE;
}
return FALSE;
}
*/
//////////////////////
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -