📄 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 + -