?? cbeyes.cpp
字號:
{
return TRUE;
}
return FALSE;
}
// 查看該單元是否是船
inline BOOL EYE_IfUnitIsShip( struct UNIT_STRUCT *pUnit )
{
Assert( pUnit );
if( pUnit->nType == MAP_UNIT_TYPE_SHIP
|| pUnit->nType == MAP_UNIT_TYPE_SGEN )
return TRUE;
return FALSE;
}
// 查看該單元是否是戰船
inline BOOL EYE_IfUnitIsBattleShip( struct UNIT_STRUCT *pUnit )
{
Assert( pUnit );
if( (pUnit->nType == MAP_UNIT_TYPE_SHIP
|| pUnit->nType == MAP_UNIT_TYPE_SGEN )
&& pUnit->Draw.nFile != 47 ) // 不是運輸船
return TRUE;
return FALSE;
}
// 查看該單元是否是運輸船
inline BOOL EYE_IfUnitIsTransport( struct UNIT_STRUCT *pUnit )
{
Assert( pUnit );
if( pUnit->Draw.nFile == 47 ) // 運輸船
return TRUE;
else
return FALSE;
}
// 查看該單元是否是投石車
inline BOOL EYE_IfUnitIsCatapult( struct UNIT_STRUCT *pUnit )
{
Assert( pUnit );
if( pUnit->Draw.nFile == 34 ) // 車兵
return TRUE;
return FALSE;
}
// 查看該單元是否是騎兵
inline BOOL EYE_IfUnitIsCavalry( struct UNIT_STRUCT *pUnit )
{
Assert( pUnit );
if( pUnit->Draw.nFile == 36 // 騎兵100
|| pUnit->Draw.nFile == 37 // 騎兵200
|| pUnit->Draw.nFile == 40 // 騎兵500
|| pUnit->Draw.nFile == 35 )// 騎將
return TRUE;
return FALSE;
}
// 查看該單元是否是城門
inline BOOL EYE_IfUnitIsDoor( struct UNIT_STRUCT *pUnit )
{
Assert( pUnit );
if( pUnit->Draw.nFile == 16
|| pUnit->Draw.nFile == 17 )
return TRUE;
return FALSE;
}
/////////////
/////////////
// 查看兩個君主是否同盟
// 根據網絡需要修改,Aug 20, 1997
// nPlayer1, nPlayer2 : 兩個游戲者
// return : TRUE if is
inline BOOL EYE_PlayerIsAllied( int nPlayer1, int nPlayer2 )
{
if( nPlayer1 == nPlayer2 ) return TRUE;
if( GAME.Players[nPlayer1].nAllies[nPlayer2] == TRUE )
{
Assert( GAME.Players[nPlayer2].nAllies[nPlayer1] == TRUE );
return TRUE;
}
/*
for( int i=0; i< GAME_PLAYER_MAX; i++ )
{
if( GAME.Players[nPlayer1].nAllies[i] == nPlayer2 )
{
return TRUE;
}
}
*/
return FALSE;
}
// 查看該坐標是否超過的地圖的界限
inline BOOL EYE_IfOutOfRange( int nX, int nY )
{
// 從0變為3,July 18, 1997
if( nX <= 1 || nX >= MAP_Lib.szNum.cx-1 || nY <= 3 || nY >= MAP_Lib.szNum.cy-3 )
return TRUE;
return FALSE;
}
// 查看該單元是否已經死了
inline BOOL EYE_IfUnitIsDead( struct UNIT_STRUCT *pUnit )
{
Assert( pUnit );
if( pUnit->nType == MAP_UNIT_TYPE_NONE
|| pUnit->Status.nTaskID == SHANCHU )
return TRUE;
return FALSE;
}
// 查看該單元是否是自己的
inline BOOL EYE_IfSheIsMine( struct UNIT_STRUCT *pUnit )
{
Assert( pUnit );
if( pUnit->Draw.nPlayer == GAME.nMe )
return TRUE;
return FALSE;
}
// 查看是否該單元處于焦點狀態
extern int DRAW_BLINK_nSave; // defined in CBDraw.cpp
inline BOOL EYE_IfFocusOnUnit( struct UNIT_STRUCT *pUnit )
{
if( pUnit->Draw.bUpdate >= 5
&& DRAW_BLINK_nSave == 0 )
{
return FALSE;
}
return pUnit->Draw.bUpdate;
}
// 查看該單元是否到達目的地了
inline int EYE_IfArrived( struct UNIT_STRUCT *pUnit )
{
struct CTRL_FRAME_STRUCT *pDraw = &pUnit->Draw;
int bOdd = pDraw->nY&1;
int nNum = MAP_nLocationNum[pDraw->nLocationSize];
int nNewX, nNewY;
WORD codeUEx;
for( int i=0; i< nNum; i++ )
{
nNewX = pDraw->nX+MAP_ptLocation[bOdd][i].x;
nNewY = pDraw->nY+MAP_ptLocation[bOdd][i].y;
codeUEx = MAP_GetUnitDataEx( nNewX, nNewY ) ;
// test if there is some one (not me) in front of me
if( codeUEx != MAP_DATA_NONE &&
codeUEx != pUnit->nID )
{
if( pUnit->Status.nTaskIDEx == 2 // 目的地是單元
&& pUnit->Status.nParam1 == codeUEx )
{
return TRUE;
}
}
}
return FALSE; // someone blocked him
}
// 查看該地形點是否有地形型資源
// 麥田或樹林
// nZ, nX, nY : position on ground map
// return : resource type
inline int EYE_GetGResType( int nZ, int nX, int nY )
{
WORD codeG = MAP_GetGroundData( nZ, nX, nY );
struct MAP_GROUND_CODE_STRUCT stctG;
MAP_GroundDeCode( codeG, &stctG );
if( stctG.nAttr == 0 ) return SHULIN; // 樹林
if( stctG.nAttr == 1 ) return MAITIAN; // 麥田
return QXZIYUAN; // 無效
}
// 檢測該單元是否是資源
// 對于建筑“糧倉”也被認為是資源
// return : 返回該資源的類型,一定是建筑型類型,為QXZIYUAN時無效
inline int EYE_GetUResType( struct UNIT_STRUCT *pUnit, int nPlayer )
{
if( pUnit->Draw.nFile == 22 ) return TIEKUANG; // 鐵礦
if( pUnit->Draw.nFile == 24
|| pUnit->Draw.nFile == 25 ) return MINJU; // 民居
// 敵人的糧倉
if( nPlayer ==-1 ) return QXZIYUAN; // debug only
if( (pUnit->Draw.nFile == 10
|| pUnit->Draw.nFile == 11)
&& pUnit->Draw.nPlayer != nPlayer ) return LIANGCANG;
return QXZIYUAN;
}
// 查看一個格子周圍是否有資源,只尋找地形型資源
// nFind : 要找的資源
// return : 找到資源的方向,0-7,為-1時無效
inline int EYE_IfResIsInRange( struct UNIT_STRUCT *pUnit, int nFind )
{
// 對于近程攻擊部隊,要判斷該部隊所占據的所有點
int bOdd;
int nXNext, nYNext;
int nGet;
Assert( pUnit->Draw.nLocationSize == 0 );
bOdd = pUnit->Draw.nY&1;
for( int i=0 ;i<8; i++ )
{
nXNext = pUnit->Draw.nX + MAP_ptSenser[bOdd][0][i].x,
nYNext = pUnit->Draw.nY + MAP_ptSenser[bOdd][0][i].y;
if( EYE_IfOutOfRange( nXNext, nYNext ) )
continue;
nGet = EYE_GetGResType( pUnit->Draw.nLayer, nXNext, nYNext );
if( nGet == nFind )
{ // 需要的資源
return i;
}
}
return -1;
}
// 查看視野范圍內是否有資源,只尋找地形型資源
// nZ,nX, nY : 啟始位置
// nSight : 視野
// nFind : 要找的資源
// return : 找到資源的坐標位置,等于nX和nY時為未找到
inline POINT EYE_IfResIsInSight( int nZ, int nX, int nY, int nSight, int nFind )
{
// 對于近程攻擊部隊,要判斷該部隊所占據的所有點
POINT pt;
int bOdd;
int nXNext, nYNext;
// int nSight;
int nGet;
// nSight = DATA_Lib.Unit[pUnit->Draw.nFile].nViewRange;
pt.x = nX, pt.y = nY;
bOdd = nY&1;
for( int i=0; i<nSight; i++ )
for( int j=0; j<((i+1)<<3); j++ )
{
nXNext = nX + MAP_ptSenser[bOdd][i][j].x,
nYNext = nY + MAP_ptSenser[bOdd][i][j].y;
if( EYE_IfOutOfRange( nXNext, nYNext ) )
continue;
nGet = EYE_GetGResType( nZ, nXNext, nYNext );
if( nGet == nFind )
{
pt.x = nXNext,pt.y = nYNext;
return pt;
}
}
return pt;
}
// 尋找最近的家
// nPlayer : 君主
// nType : 0, 對于帶有糧食的工人,是主帥帳,糧倉
// 1, 對于帶有木材的工人,是主帥帳,木工房
// return : building ID, MAP_DATA_NONE為沒有
inline WORD EYE_FindNearestHome( int nPlayer, int nType )
{
int n2, n3;
if( nType == 0 )
{
n2 = 10, n3 = 11;
}
else
{
n2 = 4, n3 = 5;
}
struct UNIT_STRUCT *pUnit;
for( int i=0; i< GAME.Players[nPlayer].wUnitCounter; i++ )
{
pUnit = &GAME.Players[nPlayer].Unit[i];
if( !EYE_IfUnitIsDead( pUnit )
&& (pUnit->Draw.nFile == 0
|| pUnit->Draw.nFile == 1
|| pUnit->Draw.nFile == n2
|| pUnit->Draw.nFile == n3) )
{
return pUnit->nID;
}
}
return MAP_DATA_NONE;
}
// 得到該建筑是否可以接受資源
// pU : 被檢測的建筑
// return : 可以接受的資源的類型,QXZIYUAN為無效
inline int EYE_GetUResHome( struct UNIT_STRUCT *pU )
{
if( pU->Draw.nFile == 0 || pU->Draw.nFile == 1 )
return SUOYOUZY;
if( pU->Draw.nFile == 2 || pU->Draw.nFile == 3 )
return TIEKUANG;
if( pU->Draw.nFile == 4 || pU->Draw.nFile == 5 )
return SHULIN;
if( pU->Draw.nFile == 10 || pU->Draw.nFile == 11 )
return MAITIAN;
return QXZIYUAN;
}
// 得到單元的士兵數量級別,官、曲、部、校
// return : -1 如果該兵種沒有士兵
inline int EYE_GetUnitPerson( struct UNIT_STRUCT *pU )
{
int nPerson = -1;
switch( pU->Draw.nFile )
{
case 32: // 步兵100
case 36: // 騎兵100
case 45: // 弓兵100
case 46: // 小戰船
nPerson = 0;
break;
case 37: // 騎兵200
case 38: // 步兵200
case 39: // 弓兵200
case 48: // 大戰船
nPerson = 1;
break;
case 40: // 騎兵500
case 41: // 弓兵500
case 42: // 步兵500
nPerson = 2;
break;
case 43: // 步兵1000
case 44: // 弓兵1000
nPerson = 3;
break;
}
return nPerson;
}
/////////////
/////////////
// 得到某個單元的全滿生命值
// nPlayer : 游戲君主,為-1時不加附加值
// nFile : 文件號
inline int EYE_GetFullLife( int nPlayer, int nFile )
{
int nLife;
nLife = (int)DATA_Lib.Unit[nFile].dwLife;
if( nPlayer < 0 ) return nLife; // 得到原始血格
if( nFile == 18 || nFile == 19 ) return nLife; // 箭樓永遠不加血
if( nFile < 27 )
nLife += GAME.Players[nPlayer].dwLifeUp; // 建筑升級加血
if( nFile == 52 ) return nLife>>1; // 旗艦的血減半
return nLife;
}
// 查看該地形點是否有水
inline int EYE_GetWater(int nZ, int nX,int nY)
{
WORD codeG = MAP_GetGroundData( nZ, nX, nY );
struct MAP_GROUND_CODE_STRUCT stctG;
MAP_GroundDeCode( codeG, &stctG );
if( stctG.nFile == 3 )
{
if (stctG.nCol != 12)
{
return TRUE;
}
}
return FALSE;
}
// 得到某個單元的將領,無或非法時為空
inline struct UNIT_STRUCT *EYE_GetGeneral( struct UNIT_STRUCT * pUnit )
{
struct UNIT_STRUCT *pU = NULL;
// 對于士兵要設置他的將領
if( EYE_IfUnitIsSoldier( pUnit )
&& pUnit->Soldier.nGenID != MAP_DATA_NONE )
{
pU = MAP_GetUnit( pUnit->Soldier.nGenID );
}
else if( EYE_IfUnitIsGen( pUnit ) )
pU = pUnit;
return pU;
}
// 得到近程攻擊力
inline int EYE_GetNearAttack( struct UNIT_STRUCT *pUnit )
{
int nAttack;
if( EYE_IfUnitIsGen( pUnit ) )
{
nAttack = EYE_GetWuLi( pUnit->Gen.nID )*DATA_Lib.Unit[pUnit->Draw.nFile].nNearAttack/100;
}
else
{
int nPerson = EYE_GetUnitPerson( pUnit );
nAttack = DATA_Lib.Unit[pUnit->Draw.nFile].nNearAttack
+GAME.Players[pUnit->Draw.nPlayer].nAddNearAttack[nPerson];// 近程士兵的附加攻擊力
}
// 將領能力修正
struct UNIT_STRUCT *pUG = EYE_GetGeneral( pUnit );
if( pUG && pUG != pUnit )
{
// nAttack = int(nAttack*(
// 1+(DATA_Lib.Gen[pUG->Gen.nID].nWuLi*
// DATA_Lib.Unit[pUG->Draw.nFile].nNearAttack/100.0
// -70)/70.0+(EYE_GetMorale(pUG)-70)/300.0
// ));
nAttack = int(nAttack*(
1+(DATA_Lib.Gen[pUG->Gen.nID].nWuLi
-70)/70.0+(EYE_GetMorale(pUG)-70)/200.0
));
}
return nAttack;
}
// 得到遠程攻擊力
inline int EYE_GetFarAttack( struct UNIT_STRUCT *pUnit )
{
int nAttack;
if( EYE_IfUnitIsGen( pUnit ) )
{
nAttack = EYE_GetWuLi( pUnit->Gen.nID )*DATA_Lib.Unit[pUnit->Draw.nFile].nFarAttack/100;
}
else if( EYE_IfUnitIsCatapult( pUnit ) )
{
nAttack = DATA_Lib.Unit[pUnit->Draw.nFile].nFarAttack
+GAME.Players[pUnit->Draw.nPlayer].nAddSFarAttack; // 投石車的附加攻擊力
}
else if( EYE_IfUnitIsBattleShip( pUnit ) )
{
int nPerson = EYE_GetUnitPerson( pUnit );
Assert( nPerson < 2 );
nAttack = DATA_Lib.Unit[pUnit->Draw.nFile].nFarAttack
+GAME.Players[pUnit->Draw.nPlayer].nAddWaterAttack[nPerson]; // 戰船的附加攻擊力
}
else
{
int nPerson = EYE_GetUnitPerson( pUnit );
nAttack = DATA_Lib.Unit[pUnit->Draw.nFile].nFarAttack
+GAME.Players[pUnit->Draw.nPlayer].nAddFarAttack[nPerson];// 近程士兵的附加攻擊力
}
// 將領能力修正
struct UNIT_STRUCT *pUG = EYE_GetGeneral( pUnit );
if( pUG && pUG != pUnit )
{
// nAttack = int(nAttack*(
// 1+(DATA_Lib.Gen[pUG->Gen.nID].nWuLi*
// DATA_Lib.Unit[pUG->Draw.nFile].nNearAttack/100.0
// -70)/70.0+(EYE_GetMorale(pUG)-70)/300.0
// ));
nAttack = int(nAttack*(
1+(DATA_Lib.Gen[pUG->Gen.nID].nWuLi
-70)/70.0+(EYE_GetMorale(pUG)-70)/200.0
));
}
return nAttack;
}
// 得到近程防御力
inline int EYE_GetNearDefend( struct UNIT_STRUCT *pU )
{
int nDefend;
if( EYE_IfUnitIsGen( pU ) )
{
nDefend = DATA_Lib.Gen[pU->Gen.nID].nWuLi*DATA_Lib.Unit[pU->Draw.nFile].nNearDefend/100;
}
else if( EYE_IfUnitIsBattleShip( pU ) )
{
int nPerson = EYE_GetUnitPerson( pU );
Assert( nPerson < 2 );
nDefend = DATA_Lib.Unit[pU->Draw.nFile].nNearDefend
+GAME.Players[pU->Draw.nPlayer].nAddWaterDefend[nPerson]; // 戰船的附加防御力
}
else
{
int nPerson = EYE_GetUnitPerson( pU );
nDefend = DATA_Lib.Unit[pU->Draw.nFile].nNearDefend;
if( nDefend != -1 )
{
nDefend += GAME.Players[pU->Draw.nPlayer].nAddNearDefend[nPerson];// 遠程士兵的附加防御力
}
}
// 將領能力修正
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -