📄 cbrunot.cpp
字号:
/////////////
// CBRunOT.cpp : v0020
// Written by : Liu Gang
// Compiler : Microsoft Visual C++ 4.2
// Copyright (C) : 1996 WayAhead Corporation
// v0010 : Nov.18.1996
// v0020 : Mar.24.1997, seperated from CBRun.cpp
/////////////
// implementation file
// components of CBRun
// 对CBRun.cpp的辅助功能模块
#include "stdafx.h"
#include "Assert.h"
#include "CBRun.h"
#include "CBGame.h"
#include "CBMap.h"
#include "CBData.h"
#include "CBOther.h"
#include "CBEyes.h"
#include "CBMini.h" // MINI_SetBlink()
//-- LHJ
#include "cbprompt.h" // FACE_UpdateGrade()
#include "interfac.h"
//-- LHJ
#include <math.h> // sqrt()
#include "CBRDelay.h" // defines
/////////////
extern POINT DRAW_ptScreenOffset; // defined in CBDraw.cpp
extern int GFWI_bUpdate; // defined in CBDRAW.cpp, for test only
extern RECT DRAW_rcScreen; // defined in CBDraw.cpp
// 用于音效,每隔一定时间该开关打开,当屏幕以外的我方单元(部队/建筑)
// 受到攻击时,由画外音提醒游戏者We are under attack!
// 为真时,开关打开,可以发出消息
BOOL RUN_SOUND_bWeAreUnderAttack = TRUE;
// defined in CBCTRl.cpp, debug for do not die
extern BOOL CTRL_bDebugDie;
/////////////
/////////////
// Local functions
// 判断如果单元生命小于0,对该单元下达删除命令
// 但只有当动画显示完全后,才真正调用CTRL_UNIT_Detroy()删除它
void RUN_UNIT_ToDie( struct UNIT_STRUCT *pUnit );
/////////////
/////////////
// 攻击音效
// nX, nY : 位置
// nFile : 单元文件号
void RUN_SOUND_Hit( int nX, int nY, int nFile );
// 弓箭攻击音效
// nX, nY : 位置
// nFile : 单元文件号
void RUN_SOUND_HitF( int nX, int nY, int nFile );
// 死亡音效
// nX, nY : 位置
// nFile : 单元文件号
void RUN_SOUND_Die( int nX, int nY, int nFile );
// 受伤音效
// nX, nY : 位置
// nFile : 单元文件号
void RUN_SOUND_Wounded( int nX, int nY, int nFile );
// 用于音效,每隔一定时间该开关打开,当屏幕以外的我方单元(部队/建筑)
// 受到攻击时,由画外音提醒游戏者We are under attack!
// 注:要在函数外面判断游戏者
// nX, nY : 被攻击单元位置坐标
// nFile : 被攻击单元文件号
void RUN_SOUND_UnderAttack( int nX, int nY, int nFile );
/////////////
/////////////
// 计算攻击点数,内部使用
int RUN_FIGHT_calcHitPoint( struct UNIT_STRUCT *pUnit, struct UNIT_STRUCT *pU );
int RUN_FIGHT_calcHitPointF( struct UNIT_STRUCT *pUnit, struct UNIT_STRUCT *pU );
// 攻击力=基本攻击力+提升系数+将领系数+阵型系数
// 防御力=基本防御力+提升系数+将领系数+阵型系数
// 近程
int RUN_FIGHT_calcHitPoint( struct UNIT_STRUCT *pUnit, struct UNIT_STRUCT *pU )
{
// 攻击
//--------------------攻击计算--------------------
int nHit, nAttack, nDefend;
Assert( EYE_IfUnitIsSoldier( pUnit )
|| EYE_IfUnitIsGen( pUnit ) );
nAttack = EYE_GetNearAttack( pUnit );
nDefend = EYE_GetNearDefend( pU );
// adjust hit
nHit = nAttack - nDefend;
if( nHit <= 0 ) nHit = 1;
// 调试不死状态
// July.17.1997, Liu Gang
if( CTRL_bDebugDie == TRUE && GAME.nMe == pU->Draw.nPlayer )
nHit = 0;
//--------------------攻击计算--------------------
return nHit;
}
// 远程
int RUN_FIGHT_calcHitPointF( struct UNIT_STRUCT *pUnit, struct UNIT_STRUCT *pU )
{
// 攻击
//--------------------攻击计算--------------------
int nHit, nAttack, nDefend;
Assert( EYE_IfUnitIsSoldier( pUnit )
|| EYE_IfUnitIsGen( pUnit )
|| EYE_IfUnitIsTower( pUnit ) );
nAttack = EYE_GetFarAttack( pUnit );
nDefend = EYE_GetFarDefend( pU );
// adjust hit
nHit = nAttack - nDefend;
if( nHit <= 0 ) nHit = 1;
// 调试不死状态
// July.17.1997, Liu Gang
if( CTRL_bDebugDie == TRUE && GAME.nMe == pU->Draw.nPlayer )
nHit = 0;
//--------------------攻击计算--------------------
return nHit;
}
/////////////
// 是否钱够花
BOOL RUN_CREATE_IfEnoughMoney( int nPlayer, int nFile )
{
// 消耗资源
if( GAME.Players[nPlayer].nFood < DATA_Lib.Unit[nFile].nCreateFood
|| GAME.Players[nPlayer].nWood < DATA_Lib.Unit[nFile].nCreateWood
|| GAME.Players[nPlayer].nGold < DATA_Lib.Unit[nFile].nCreateGold
|| GAME.Players[nPlayer].nIron < DATA_Lib.Unit[nFile].nCreateIron )
{
OutputDebugString( "RUN_CreateUnit Error: Short of Resource!\n" );
//------------提示
if( GAME.nMe == nPlayer )
{
if( nFile >= 0 && nFile < 27 )
{ //军费不够,无法建造
FACE_ShowPromptInfor( 6 );
}
else
{ //军费不够,无法训练
FACE_ShowPromptInfor( 8 );
}
//---- 否定音效
// noselect.wav
DATA_WAVE_EffectPlay( 99 );
//---- 否定音效
}
//------------提示
return FALSE;
}
return TRUE;
}
// 花钱
BOOL RUN_CREATE_Consume( int nPlayer, int nFile )
{
if( !RUN_CREATE_IfEnoughMoney( nPlayer, nFile ) )
return FALSE;
// 花钱
GAME.Players[nPlayer].nGold -= DATA_Lib.Unit[nFile].nCreateGold;
GAME.Players[nPlayer].nFood -= DATA_Lib.Unit[nFile].nCreateFood;
GAME.Players[nPlayer].nWood -= DATA_Lib.Unit[nFile].nCreateWood;
GAME.Players[nPlayer].nIron -= DATA_Lib.Unit[nFile].nCreateIron;
GFWI_bUpdate = TRUE;
return TRUE;
}
// 建造、生产取消后找钱
BOOL RUN_CREATE_PayBack( int nPlayer, int nFile )
{
// 找钱
GAME.Players[nPlayer].nGold += DATA_Lib.Unit[nFile].nCreateGold*RUN_CREATE_PAYBACK/100;
GAME.Players[nPlayer].nFood += DATA_Lib.Unit[nFile].nCreateFood*RUN_CREATE_PAYBACK/100;
GAME.Players[nPlayer].nWood += DATA_Lib.Unit[nFile].nCreateWood*RUN_CREATE_PAYBACK/100;
GAME.Players[nPlayer].nIron += DATA_Lib.Unit[nFile].nCreateIron*RUN_CREATE_PAYBACK/100;
GFWI_bUpdate = TRUE;
return TRUE;
}
// 设置单元死亡后的动画
// pUnit : 即将死亡的单元的指针
void RUN_DESTROY_SetAfterLife( struct UNIT_STRUCT *pUnit )
{
struct CTRL_FRAME_STRUCT *pDraw = &pUnit->Draw;
// detect if should really draw
// if( pUnit->Draw.nFile >= 27 ) // 是士兵才判断是否真的画
// 都要判断
POINT ptPOS[2][25]=
{
{{-1,0,},{1,0},{-1,1},{0,1},
{-1,2},{0,2},{1,2},{-1,3},{0,3},
{-1,4},{0,4},{1,4},{-1,5},{0,5},
{-1,6},{0,6},{1,6},{-1,7},{0,7},
{-1,8},{0,8},{1,8},{-1,9},{0,9},{0,10}},
{{-1,0,},{1,0},{1,1},{0,1},
{-1,2},{0,2},{1,2},{1,3},{0,3},
{-1,4},{0,4},{1,4},{1,5},{0,5},
{-1,6},{0,6},{1,6},{1,7},{0,7},
{-1,8},{0,8},{1,8},{1,9},{0,9},{0,10}},
};
BOOL bSet = TRUE; //为真时要显示死后的状态(血迹)
int nX, nY;
BOOL bOdd = pUnit->Draw.nY&1;
for( int y=0; y<25; y++ )
{
nX = pUnit->Draw.nX + ptPOS[bOdd][y].x,
nY = pUnit->Draw.nY + ptPOS[bOdd][y].y;
if( EYE_IfOutOfRange( nX, nY ) )
break;//出界
struct MAP_GROUND_CODE_STRUCT stctG;
WORD codeG = MAP_GetGroundData( pUnit->Draw.nLayer, nX, nY );
MAP_GroundDeCode( codeG, &stctG );
if( stctG.nAttr != MAP_SPECIAL_NONE )
{
if( (stctG.nAttr == MAP_SPECIAL_WOOD
|| stctG.nAttr == MAP_SPECIAL_DO_WOOD)
&& y<6 ) // 是树木,在两格范围内不显示
{
bSet = FALSE;//是资源,不显示
break;
}
else if( (stctG.nAttr == MAP_SPECIAL_WHEAT
|| stctG.nAttr == MAP_SPECIAL_DO_WHEAT)
&& y<4 ) // 是树木,在一格范围内不显示
{
bSet = FALSE;//是资源,不显示
break;
}
}
if( pUnit->Draw.nLayer < 2 )
{
codeG = MAP_GetGroundData( pUnit->Draw.nLayer+1, nX, nY );
if( codeG != MAP_DATA_NONE )
{ // 有第二层地形,不显示
bSet = FALSE;
break;
}
}
if( pUnit->Draw.nLayer < 1 )
{
codeG = MAP_GetGroundData( pUnit->Draw.nLayer+2, nX, nY );
if( codeG != MAP_DATA_NONE )
{ // 有第三层地形
bSet = FALSE;
break;
}
}
}
if( pUnit->Draw.nFile < 27 // 是建筑才爆炸
|| pUnit->Draw.nFile == 34 ) // 或是投石车
{
// 设置爆炸
struct OTHER_STRUCT otherBomb;
OTHER_ClearData( &otherBomb );
otherBomb.nFile = 1;
otherBomb.nType = OTHER_TYPE_BOMB;
otherBomb.nDelay = RUN_TIMEDELAY_BOMB;
RECT rect = MAP_GetOtherRect( DRAW_ptScreenOffset,
pDraw->nLayer, pDraw->nX, pDraw->nY, 1 );
otherBomb.ptBegin.x = rect.left+DRAW_ptScreenOffset.x;
otherBomb.ptBegin.y = rect.top+DRAW_ptScreenOffset.y;
if( pDraw->nLocationSize == 1 )
otherBomb.ptBegin.y -= MAP_Lib.szItem.cy;
else if( pDraw->nLocationSize == 2 )
otherBomb.ptBegin.y -= MAP_Lib.szItem.cy*3>>1;
otherBomb.szItem.cx = MAP_Lib.Other[otherBomb.nFile].szItem.cx;
otherBomb.szItem.cy = MAP_Lib.Other[otherBomb.nFile].szItem.cy;
for( int i=0; i<8; i++ )
{
otherBomb.nCol[i] = i;
}
otherBomb.nMaxFrame = 8;
OTHER_CreateData( &otherBomb );
//--音效
// 24: obreak04.wav,爆炸声
POINT pt;
pt.x = pUnit->Draw.nX, pt.y = pUnit->Draw.nY;
if( PtInRect( &DRAW_rcScreen, pt ) )
{
DATA_WAVE_EffectPlay( 24 );
}
else
{
DATA_WAVE_EffectPlayLow( 24 );
}
//--音效
if( pUnit->Draw.nFile == 16 || pUnit->Draw.nFile == 17 )
{ // 城门不显示血迹,只爆炸
return;
}
}
if( bSet == FALSE ) return; // 不能显示血迹
// set after life
struct OTHER_STRUCT other;
OTHER_ClearData( &other );
other.nType = OTHER_TYPE_BLOOD;
other.nDelay = RUN_TIMEDELAY_DIE;
RECT rect = MAP_GetUnitRect( DRAW_ptScreenOffset, pDraw );
other.ptBegin.x = rect.left+DRAW_ptScreenOffset.x;
other.ptBegin.y = rect.top+DRAW_ptScreenOffset.y;
other.szItem.cx = rect.right - rect.left;
other.szItem.cy = rect.bottom - rect.top;
if( EYE_IfUnitIsBuild( pUnit )
|| pDraw->nFile == 34 ) // 建筑或投石车
{ // 建筑
if( pDraw->nFile != 34 )
{ // 只有是建筑时设置死后状态
if( pDraw->nFile == 0 || pDraw->nFile == 1 )
{
other.nCol[0] = 8 + MAP_Lib.AniSeq[0].nOffset;
other.nCol[1] = 9 + MAP_Lib.AniSeq[0].nOffset;
}
else if( pDraw->nLocationSize == 0 )
{
other.nCol[0] = 1 + MAP_Lib.AniSeq[26].nOffset;
other.nCol[1] = 1 + MAP_Lib.AniSeq[26].nOffset;
}
else if( pDraw->nLocationSize == 1 )
{
other.nCol[0] = 1 + MAP_Lib.AniSeq[24].nOffset;
other.nCol[1] = 2 + MAP_Lib.AniSeq[24].nOffset;
}
else if( pDraw->nFile == 20 ) // 船坞
{
other.nCol[0] = 1 + MAP_Lib.AniSeq[pDraw->nFile].nOffset;
other.nCol[1] = 2 + MAP_Lib.AniSeq[pDraw->nFile].nOffset;
}
else
{
other.nCol[0] = 1 + MAP_Lib.AniSeq[22].nOffset;
other.nCol[1] = 1 + MAP_Lib.AniSeq[22].nOffset;
}
other.nMaxFrame = 2;
}
}
else
{ // 部队
if( pDraw->nFile >= 37 && pDraw->nFile <= 44 )
{ // 有自己的死亡画面
// 状态为原来的状态
// 最大帧
int nMaxFrame = MAP_Lib.AniSeq[pDraw->nFile].nMaxSequence[pDraw->nState];
for( int i=0; i< nMaxFrame-6; i++ )
{
other.nCol[i] = MAP_Lib.AniSeq[pDraw->nFile].nAniSeq[pDraw->nState][i+6]
+ MAP_Lib.AniSeq[pDraw->nFile].nOffset;
}
other.nMaxFrame = i;
}
else
{
int nFile = 29;
// 最大帧
int nMaxFrame = 7; // 特殊
for( int i=0; i< nMaxFrame; i++ )
{
other.nCol[i] = MAP_Lib.AniSeq[nFile].nOffset-1 + ((i+1)*5);
}
other.nMaxFrame = i;
SIZE sz;
sz.cx = MAP_Lib.Unit[nFile].szItem.cx;
sz.cy = MAP_Lib.Unit[nFile].szItem.cy;
other.ptBegin.x += (other.szItem.cx - sz.cx)>>1;
other.ptBegin.y = other.ptBegin.y + other.szItem.cy - sz.cy;
}
}
Assert( other.nFrame == 0 );
if( pDraw->nFile != 34 )
{ // 投石车不设置死后状态
if( OTHER_CreateData( &other ) == -1 )
OutputDebugString( "RUN_SetAfterLife Error: max number reached!\n" );
}
}
// 当建筑被攻击时,要着火
// pU : 被攻击的建筑的指针
void RUN_FIGHT_SetFire( struct UNIT_STRUCT *pU )
{
if( pU->nLife < EYE_GetFullLife( pU->Draw.nPlayer, pU->Draw.nFile)/3
&& pU->Build.nFireLvl < 2 )
//&& pU->Draw.nLocationSize > 0 )
{ // 增加第二个火
struct OTHER_STRUCT other;
OTHER_ClearData( &other );
other.nType = OTHER_TYPE_FIRE;
other.nFile = 3;
other.nCol[0] = 0;
other.nCol[1] = 1;
other.nCol[2] = 2;
other.nCol[3] = 3;
other.nMaxFrame = 4;
other.nDelay = 4;
other.szItem.cx = MAP_Lib.Other[other.nFile].szItem.cx;
other.szItem.cy = MAP_Lib.Other[other.nFile].szItem.cy;
RECT rect = MAP_GetUnitRect( DRAW_ptScreenOffset, &pU->Draw );
other.ptBegin.x = rect.right-other.szItem.cx+DRAW_ptScreenOffset.x-8;
other.ptBegin.y = rect.top+DRAW_ptScreenOffset.y+10;
pU->Build.nFireID[pU->Build.nFireLvl] = OTHER_CreateData( &other );
pU->Build.nFireLvl++;
}
else if( pU->nLife >= EYE_GetFullLife( pU->Draw.nPlayer, pU->Draw.nFile)/3
&& pU->nLife < EYE_GetFullLife( pU->Draw.nPlayer, pU->Draw.nFile)*2/3
&& pU->Build.nFireLvl != 1 )
{ // 第一个火
if( pU->Build.nFireLvl == 0 )
{ // 增加第一个火
struct OTHER_STRUCT other;
OTHER_ClearData( &other );
other.nType = OTHER_TYPE_FIRE;
other.nFile = 3;
other.nCol[0] = 0;
other.nCol[1] = 1;
other.nCol[2] = 2;
other.nCol[3] = 3;
other.nMaxFrame = 4;
other.nDelay = 4;
other.szItem.cx = MAP_Lib.Other[other.nFile].szItem.cx;
other.szItem.cy = MAP_Lib.Other[other.nFile].szItem.cy;
RECT rect = MAP_GetUnitRect( DRAW_ptScreenOffset, &pU->Draw );
if( pU->Draw.nLocationSize == 0 )
{ // center
other.ptBegin.x = (rect.right+rect.left)/2 - other.szItem.cx/2+DRAW_ptScreenOffset.x;
}
else other.ptBegin.x = rect.left+DRAW_ptScreenOffset.x+10;
other.ptBegin.y = rect.top+DRAW_ptScreenOffset.y-5;
pU->Build.nFireID[pU->Build.nFireLvl] = OTHER_CreateData( &other );
pU->Build.nFireLvl++;
}
else
{ // 减少第二个火
OTHER_DestroyData( pU->Build.nFireID[pU->Build.nFireLvl-1] );
pU->Build.nFireLvl--;
}
}
else if( pU->nLife >= EYE_GetFullLife( pU->Draw.nPlayer, pU->Draw.nFile)*2/3
&& pU->Build.nFireLvl > 0 )
{ // 减少第一个火,所有火
for( int i=0; i<pU->Build.nFireLvl; i++ )
{
OTHER_DestroyData( pU->Build.nFireID[i] );
}
pU->Build.nFireLvl=0;
}
}
// 对于投石车,要投石
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -