ROAField.cpp
资源名称:ROA3.40.rar [点击查看]
上传用户:tianheyiqi
上传日期:2010-04-16
资源大小:282k
文件大小:4k
源码类别:
外挂编程
开发平台:
Visual C++
- // ROAField.cpp: implementation of the CROAField class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "ROA.h"
- #include "ROAField.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CROAField::CROAField()
- {
- m_bLoaded = false;
- m_strAlias = "";
- m_strFieldname = "";
- m_szField.cx = 0;
- m_szField.cy = 0;
- m_byFields = NULL;
- }
- CROAField::~CROAField()
- {
- if(NULL != m_byFields)
- {
- delete m_byFields;
- m_byFields = NULL;
- }
- m_bmpField.DeleteObject();
- m_dcField.DeleteDC();
- }
- int CROAField::init(LPCTSTR lpszFieldName, LPCTSTR lpszAlias)
- {
- CString strFieldName;
- WORD wSize[2];
- strFieldName = "..\fields\";
- strFieldName += lpszFieldName;
- strFieldName += ".fld";
- CFile fField;
- int nFileLength;
- m_bLoaded = false;
- m_strAlias = "";
- if(NULL != m_byFields)
- {
- delete m_byFields;
- m_byFields = NULL;
- }
- if(fField.Open(strFieldName, CFile::modeRead))
- {
- if(fField.Read(&wSize, 4))
- {
- m_szField.cx = wSize[0];
- m_szField.cy = wSize[1];
- nFileLength = fField.GetLength();
- if(nFileLength >= (m_szField.cx * m_szField.cy +4))
- {
- m_byFields = new BYTE[m_szField.cx * m_szField.cy];
- fField.ReadHuge(m_byFields, m_szField.cx * m_szField.cy);
- m_strAlias = lpszAlias;
- m_strFieldname = lpszFieldName;
- CreateFieldImage();
- m_bLoaded = true;
- }
- }
- fField.Close();
- }
- // utlSetAutoSearchMvp(false);
- return(0);
- }
- void CROAField::CreateFieldImage()
- {
- CRect rect;
- m_dcField.DeleteDC();
- m_dcField.CreateCompatibleDC(AfxGetMainWnd()->GetDC());
- m_bmpField.DeleteObject();
- m_bmpField.CreateCompatibleBitmap(AfxGetMainWnd()->GetDC(), m_szField.cx, m_szField.cy);
- m_dcField.SelectObject(&m_bmpField);
- rect.SetRect(0, 0, m_szField.cx-1, m_szField.cy-1);
- m_dcField.FillRect(rect, &CBrush(RGB(128, 128, 128)));
- for(int y=0; y < m_szField.cy; y++)
- for(int x=0; x < m_szField.cx; x++)
- if((m_byFields[y*m_szField.cx + x]) == 0)
- m_dcField.SetPixel(x, m_szField.cy-y, RGB(255,255,255));
- else
- {
- if((m_byFields[y*m_szField.cx + x]) == 5)
- m_dcField.SetPixel(x, m_szField.cy-y, RGB(0,0,255));
- }
- return;
- }
- POINT nearPoint[8] =
- {
- {1, 0},
- {1, 1},
- {0, 1},
- {-1, 1},
- {-1, 0},
- {-1, -1},
- {0, -1},
- {1, -1}
- };
- BOOL CROAField::FindNearestPoint(POINT pntFrom, POINT pntTo, POINT *pNearest)
- {
- POINT pnt;
- BOOL bFound = false;
- if(!m_bLoaded || pNearest == NULL)
- {
- ASSERT(false);
- return(false);
- }
- pNearest->x = -1;
- pNearest->y = -1;
- if(pntTo.x > m_szField.cx || pntTo.y > m_szField.cy)
- return(false);
- for(int i=0; i<8; i++)
- {
- pnt.x = pntTo.x + nearPoint[i].x;
- pnt.y = pntTo.y + nearPoint[i].y;
- if(pnt.x < 0 || pnt.y < 0 || pnt.x > m_szField.cx || pnt.y > m_szField.cy)
- continue;
- BOOL bWarpFound = false;
- for(int j=0; j<spells.GetSize(); j++)
- {
- if((spells[j].wSkill == 129 || spells[j].wSkill == 130 ) && spells[j].pntPos.x == pnt.x && spells[j].pntPos.y == pnt.y)
- {
- bWarpFound = true;
- break;
- }
- }
- if(bWarpFound)
- continue;
- // TRACE("%d): %d ", i+1, m_byFields[pnt.x+pnt.y*m_szField.cx]);
- if(!m_byFields[pnt.x+pnt.y*m_szField.cx])
- {
- if(pNearest->x == -1 && pNearest->y == -1)
- {
- *pNearest = pnt;
- }
- else
- {
- if(utlDistanceFrom(pntFrom, pnt) < utlDistanceFrom(pntFrom, *pNearest))
- {
- *pNearest = pnt;
- }
- }
- bFound = true;
- }
- }
- // TRACE("n");
- return(bFound);
- }
- #define ANTIWARPSTEP 2
- POINT CROAField::GetAntiWarpPoint(void)
- {
- POINT pntRtn;
- POINT pntOffset;
- while(true)
- {
- pntOffset.x = int(float(rand())/RAND_MAX*ANTIWARPSTEP*2)-ANTIWARPSTEP;
- pntOffset.y = int(float(rand())/RAND_MAX*ANTIWARPSTEP*2)-ANTIWARPSTEP;
- if(pntOffset.x == 0 && pntOffset.y == 0)
- continue;
- pntRtn.x = you.pntTo.x + pntOffset.x;
- pntRtn.y = you.pntTo.y + pntOffset.y;
- if(pntRtn.x < 0 || pntRtn.y < 0 || pntRtn.x > m_szField.cx || pntRtn.y > m_szField.cy)
- continue;
- if(m_byFields[pntRtn.x+pntRtn.y*m_szField.cx])
- {
- continue;
- }
- break;
- }
- return(pntRtn);
- }