📄 mainfrm.cpp
字号:
#include "havoc.h"
#include"draw.h"
#include"mymedia.h"
extern "C"{
#include"sfx.h"
#include"lobby.h"
#include"comm.h"
#include"input.h"
//
}
#include"wizard.h"
#define FLOORNUM 6
#define ARMYNUM 2
#define BUILDNUM 2
#define MYARMYNUM 2
#define ENEMYNUM 1
#define EXPNUM 2
#define OTHERSNUM 12
#define BULLETNUM 1
#define TREENUM 3
#define HILLNUM 2
#define TIMER_ID 1
#define TIMER_RATE 50
BOOL BackgroundEdit(POINT cell);
void ViewTreeInfo(int type);
void DestroyTree(POINT cell);
void CheckResult(void);
//void DoSystemMessage( LPDPMSG_GENERIC lpMsg, DWORD dwMsgSize, DPID idFrom, DPID idTo );
//void DoApplicationMessage( LPGENERICMSG lpMsg, DWORD dwMsgSize, DPID idFrom, DPID idTo );
//void SendGameMessage( LPGENERICMSG lpMsg, DPID idTo );
static void finiGlob(void);
//HRESULT ReceiveMessages( void );
void Flip(void);
HANDLE ghThread; // handle to wizard thread
HINSTANCE ghinst; // program instance
HWND ghWndMain; // main window
DWORD gdwKeys; // gameplay keys
WORD ProgramState=SPLASH;
DWORD gwKeys=0;
BOOL gbIsActive=FALSE;
BOOL bWeActive=FALSE;
BOOL bMud=FALSE;
int animEscnum=0;
HDC FAR panelDC=NULL;
int greenernum=2;
GUID Guid;
LPVOID pv;
LPVOID glpvReceiveBuffer = NULL; // buffer to store received messages
DWORD gdwReceiveBufferSize = 0; // size of buffer
LPDIRECTDRAWSURFACE lpGround;
LPDIRECTDRAWSURFACE lpShape;
LPDIRECTDRAWSURFACE Floor[FLOORNUM]; // DirectDraw
LPDIRECTDRAWSURFACE Build[BUILDNUM]; //offscreen
LPDIRECTDRAWSURFACE Myarmy[MYARMYNUM];
LPDIRECTDRAWSURFACE Enemy[ENEMYNUM];
LPDIRECTDRAWSURFACE PicExp[EXPNUM];
LPDIRECTDRAWSURFACE Others[OTHERSNUM]; //others
LPDIRECTDRAWSURFACE PicRect;
LPDIRECTDRAWSURFACE PicShape;
LPDIRECTDRAWSURFACE PicBullet[BULLETNUM];
LPDIRECTDRAWSURFACE RadarBack;//Buffer for Radar
LPDIRECTDRAWSURFACE lpDDPP;//Operative Plan and Radar surface;
LPDIRECTDRAWSURFACE PicBlack;
LPDIRECTDRAWSURFACE PicWhite;
LPDIRECTDRAWSURFACE Army[ARMYNUM];
LPDIRECTDRAWSURFACE PicTree[TREENUM];
LPDIRECTDRAWSURFACE PicHill[HILLNUM];
LPDIRECTDRAWSURFACE lpIntrbk;
LPDIRECTSOUNDBUFFER lpDirectSoundBuffer [MAX_SOUNDS]; // SoundBuffer interface
LPDIRECTSOUND3DBUFFER lpDirectSound3DBuffer[MAX_SOUNDS]; // 3D interface (to same buffer)
int SoundedNum[MAX_SOUNDS]={0,0,0,0,0,0};
//LPDIRECTDRAWPALETTE lpDDPal; // DirectDraw palette
BOOL bActive; // is application active?
DWORD avitimer=0;
WORD wAviID;
DWORD resttime=450;
DWORD NowTime=0;
DWORD treegot=0;
BOOL Finished1=FALSE,Finished2=FALSE,Finished3=FALSE;
DWORD treelost=0;
DWORD treebasicnum=305;
float greenity=((float)treebasicnum)/50.0;
int activenum=0;
int Dir32(POINT fir,POINT sec);
void FillColor(LPDIRECTDRAWSURFACE lpsurf,DWORD color)
{ DDBLTFX ddbltfx;
ddbltfx.dwSize = sizeof(ddbltfx);
ddbltfx.dwFillColor = color;
lpsurf->Blt(
NULL, // Destination
NULL, NULL, // Source rectangle
DDBLT_COLORFILL, &ddbltfx);
}
void intro::InitIntro()
{
time=timeGetTime();
lpIntr=DDLoadBitmap(lpDD,"bmp\\intr0.bmp",0,0);
lpIntrbk=DDLoadBitmap(lpDD,"bmp\\introbk.bmp",0,0);
DDSetColorKey(lpIntr,CLR_INVALID);
//lpDDPal = DDLoadPalette(lpDD, "bmp\\intr0.bmp");
//if (lpDDPal)
// lpIntr->SetPalette(lpDDPal);
//if(lpIntr==NULL)return initFail(NULL);
p.x=120;
p.y=0;
bplay=TRUE;
}
void intro::FreeIntro()
{if(lpIntr != NULL )
{
lpIntr->Release();
lpIntr = NULL;
}
if(lpIntrbk != NULL )
{
lpIntrbk->Release();
lpIntrbk = NULL;
}
/*if( lpDDPal != NULL )
{
lpDDPal->Release();
lpDDPal = NULL;
}*/
bplay=FALSE;
}
BOOL intro::Intro()
{int y;
//int i;
// PALETTEENTRY pe[256];
if((timeGetTime()-time)>40)
{time=timeGetTime();
FillColor(lpDDSBack,0);
/*if(lpDDPal->GetEntries( 0, 0, 256, pe ) != DD_OK)
{
}
for(i=1; i<256; i++)
{
pe[i].peRed =0;
pe[i].peGreen = 0;
pe[i].peBlue = 0;
}
if(lpDDPal->SetEntries( 0, 0, 256, pe) != DD_OK)
{
} */
//lpDDSPrimary->SetPalette(lpDDPal);
p.y++;
if(p.y<=320)
{y=400-p.y;
Blt(lpDDSBack,0,0,640,480,lpIntrbk,0,0);
JFBlt(lpDDSBack,p.x,y,400,p.y,lpIntr,0,0,DDBLTFAST_SRCCOLORKEY);
}
/*else if((p.y>320)&&(p.y<=800))
{
Blt(lpDDSBack,p.x,80,400,320,lpIntr,0,p.y-300);
}
else
{Blt(lpDDSBack,p.x,80,400,1120-p.y,lpIntr,0,p.y-300);
}*/
}
if(p.y<=320)
Flip();
else if(p.y<400)
return TRUE;
else return FALSE;
return TRUE;
}
void ViewInfo(myarmy *m)
{int d=20,s=2;
int i;
int x;
if(m!=NULL)
{//if(m->family==GREENER)
//Blt(lpDDPP,13,151,134,145,Others[8],0,0);
{if(m->type>=ENEMY)
d=50;
if(activenum==1)
{
if((m!=tankinfo.tanknum)&&(m->family==TANK))
{Blt(lpDDPP,13,151,134,145,Others[9],0,0);
JFBlt(lpDDPP,24,228,52,62,Others[2],0,0,DDBLTFAST_SRCCOLORKEY);
tankinfo.tanknum=m;
tankinfo.blood=m->blood;
tankinfo.protect=m->protect;
tankinfo.attack=m->attack;
tankinfo.speed=m->speed;
if(tankinfo.tanknum->type==WE)
{JFBlt(lpDDPP,23,165,50,50,Army[0],0,0,DDBLTFAST_SRCCOLORKEY);
JFBlt(lpDDPP,80,170,60,50,Others[3],0,0,DDBLTFAST_SRCCOLORKEY);
}
else
{JFBlt(lpDDPP,23,165,50,50,Army[1],0,0,DDBLTFAST_SRCCOLORKEY);
JFBlt(lpDDPP,80,170,60,50,Others[4],0,0,DDBLTFAST_SRCCOLORKEY);
}
x=m->blood/10;
if(x>12)x=12;
for(i=0;i<x;i++)
{
Blt(lpDDPP,78+i*5,235,4,4,PicRect,0,d);
}
x=m->attack/2;
if(x>12)x=12;
for(i=0;i<x;i++)
{
Blt(lpDDPP,78+i*5,250,4,4,PicRect,0,d);
}
x=m->protect/10;
if(x>12)x=12;
for(i=0;i<x;i++)
{
Blt(lpDDPP,78+i*5,263,4,4,PicRect,0,d);
}
x=(int)m->speed*2;
if(x>12)x=12;
for(i=0;i<x;i++)
{
Blt(lpDDPP,78+i*5,278,4,4,PicRect,0,d);
}
}
else if((m->blood!=tankinfo.blood)&&(m->family==TANK))
{tankinfo.blood=m->blood;
Blt(lpDDPP,78,235,60,4,Others[0],78,235);
// Blt(lpDDPP,24,233,52,62,Others[2],52,62);
x=m->blood/10;
if(x>12)x=12;
for(i=0;i<x+1;i++)
{
Blt(lpDDPP,78+i*5,235,4,4,PicRect,0,d);
}
}
}
}
}
else Blt(lpDDPP,12,152,134,145,Others[0],12,152);
}
void Blt(LPDIRECTDRAWSURFACE lpDDSuf,LONG x,LONG y,LONG w,LONG h,LPDIRECTDRAWSURFACE lpDDSrc,LONG sx,LONG sy)
{HRESULT ddrval;
RECT des,src;
DDBLTFX ddbltfx;
ddbltfx.dwSize=sizeof(DDBLTFX);
des.left=x;des.top=y;des.right=x+w;des.bottom=y+h;
src.left=sx;src.top=sy;src.right=sx+w;src.bottom=sy+h;
if((lpDDSuf==NULL)||(lpDDSrc==NULL))return;
if((des.right<0)||(des.left>640)||(des.top>480)
||(des.bottom<0))
return;
if((des.left<0)&&(des.right>0))
{des.right=w+des.left;
src.left-=des.left;
des.left=0;
}
else if((des.right>640)&&(des.left<640))
{ src.right-=des.right-640;
des.right=640;
}
if((des.top<0)&&(des.bottom>0))
{des.bottom=h+des.top;
src.top-=des.top;
des.top=0;
}
else if((des.bottom>480)&&(des.top<480))
{src.bottom-=des.bottom-480;
des.bottom=640;
}
while(1)
{ddrval=lpDDSuf->Blt(&des,lpDDSrc,&src,DDBLT_ALPHASRC,&ddbltfx);
if(ddrval==DD_OK)
return;
if( ddrval == DDERR_SURFACELOST )
{if(restoreAll()!=DD_OK)
return;
}
if( ddrval != DDERR_WASSTILLDRAWING )
{
return;
}
}
}
void JFBlt(LPDIRECTDRAWSURFACE lpDDSuf,LONG x,LONG y,LONG w,LONG h,LPDIRECTDRAWSURFACE lpDDSrc,LONG sx,LONG sy,DWORD flag)
{HRESULT ddrval;
RECT src;
src.left=sx;src.top=sy;src.right=sx+w;src.bottom=sy+h;
if((lpDDSuf==NULL)||(lpDDSrc==NULL))return;
if((x+w<0)||(x>640)||(y>480)
||(y+h<0))
return;
if((x<0)&&(x+w>0))
{src.left-=x;
x=0;
}
else if((x+w>640)&&(x<640))
{
src.right-=x+w-640;
}
if((y<0)&&(y+h>0))
{src.top-=y;
y=0;
}
else if((y+h>480)&&(y<480))
{
src.bottom-=y+h-480;
}
while(1)
{ddrval=lpDDSuf->BltFast(x,y,lpDDSrc,&src,flag);
if(ddrval==DD_OK)
return;
if( ddrval == DDERR_SURFACELOST )
{if(restoreAll()!=DD_OK)
return;
}
if( ddrval != DDERR_WASSTILLDRAWING )
{
return;
}
}
}
void InitBuild()
{ build=new Building(57,1,HOUSEA,WE);
build->Prev=firstbuild;
firstbuild->Next=build;
build->Next=new Building(36,32,HOUSEA,WE);
build->Next->Prev=build;
build=build->Next;
build->Next=new Building(4,7,GREENFACTORY,WE);
build->Next->Prev=build;
build=build->Next;
build->Next=new Building(8,54,HOUSEA,WE);
build->Next->Prev=build;
build=build->Next;
build->Next=NULL;
}
void StopSound(int ID)
{IDirectSoundBuffer_Stop(lpDirectSoundBuffer[ID]);
}
///////////
//
//Sound(POINT,int ID)
///////////
void Sound(POINT nowHL,int ID,BOOL bLoop)
{
//IDirectSoundBuffer_Stop(lpDirectSoundBuffer[ID]);
if((nowHL.x-posite.L>20)||(nowHL.y-posite.H>23))
IDirectSound3DBuffer_SetPosition(lpDirectSound3DBuffer[ID],
-P2M(-(nowHL.x-posite.L)*CS+640),
+P2M(-(nowHL.y-posite.H)*CS+480),
D3DVAL(0),
DS3D_DEFERRED);
else if((nowHL.x-posite.L<0)||(nowHL.y-posite.H<0))
IDirectSound3DBuffer_SetPosition(lpDirectSound3DBuffer[ID],
-P2M((nowHL.x-posite.L)*CS),
+P2M((nowHL.y-posite.H)*CS),
D3DVAL(0),
DS3D_DEFERRED);
else IDirectSound3DBuffer_SetPosition(lpDirectSound3DBuffer[ID],
0.0,
0.0,
D3DVAL(0),
DS3D_DEFERRED);
IDirectSoundBuffer_SetCurrentPosition(lpDirectSoundBuffer[ID], 0);
IDirectSound3DListener_CommitDeferredSettings(glpDirectSound3DListener);
if (DSERR_BUFFERLOST==IDirectSoundBuffer_Play(lpDirectSoundBuffer[ID],
0,
0,
(bLoop)? DSBPLAY_LOOPING : 0 ))
{
WaveReload(gSoundEffect[ID]);
}
}
/*
*FUNCTION: InitPlayerLocalSoundData
*
*
*NOTES: Takes a ship and initializes ONLY its soundbuffers and sound flags.
* It leaves everything else alone. Good for when going to
* full-screen mode, when we need to get rid of the sound buffers
* for a bit, but don't want to change the data.
*/
void InitSoundData()
{
int i;
if (InitSfx(ghWndMain))
{
for (i=0; i<MAX_SOUNDS; i++)
{
if (FALSE == WaveGetBuffers(gSoundEffect[i],&lpDirectSoundBuffer[i], &lpDirectSound3DBuffer[i]))
{//if it didn't work, get rid of all the other sound buffers
// ShowError(IDS_DSOUND_DUPBUF);
for (--i; i>=0; i--)
{
IDirectSoundBuffer_Release(lpDirectSoundBuffer [i]);
IDirectSoundBuffer_Release(lpDirectSound3DBuffer[i]);
lpDirectSoundBuffer [i] = NULL;
lpDirectSound3DBuffer[i] = NULL;
}
return;
}
}
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -