Exemplo n.º 1
0
	void GetBorder(IplImage *img, int cid, vector<CvPoint> &border) {
		IplImage *bdmask = cvCreateImage(cvGetSize(img), 8, 1);
		cvZero(bdmask);

		int fr;// fc;
		for (fr = 0; fr < img->height; fr++) {
			for (int fc = 0; fc < img->width; fc++) {
				if (IsBorder(img, fr, fc, cid))
					CV_IMAGE_ELEM(bdmask, BYTE, fr, fc) = 255;
			}
		}

		for (int i = 0; i < bdmask->width; i++) 
			if (CV_IMAGE_ELEM(bdmask, BYTE, 0, i) == 255) 
				AddOneMask(bdmask, 0, i, border);
		for (int i = 0; i < bdmask->width; i++) 
			if (CV_IMAGE_ELEM(bdmask, BYTE, bdmask->height - 1, i) == 255) 
				AddOneMask(bdmask, bdmask->height - 1, i, border);
		for (int i = 0; i < bdmask->height; i++) 
			if (CV_IMAGE_ELEM(bdmask, BYTE, i, 0) == 255) 
				AddOneMask(bdmask, i, 0, border);
		for (int i = 0; i < bdmask->height; i++) 
			if (CV_IMAGE_ELEM(bdmask, BYTE, i, bdmask->width - 1) == 255) 
				AddOneMask(bdmask, i, bdmask->width - 1, border);

		for (fr = 0; fr < img->height; fr++) {
			for (int fc = 0; fc < img->width; fc++) {
				if (CV_IMAGE_ELEM(bdmask, BYTE, fr, fc) == 255)
					AddOneMask(bdmask, fr, fc, border);				
			}
		}	
		cvReleaseImage(&bdmask);
	}
Exemplo n.º 2
0
int AIInterface::GetResourceRating(const MapPoint pt, AIJH::Resource res) const
{
    //surface resource?
    if(res == AIJH::PLANTSPACE || res == AIJH::BORDERLAND || res == AIJH::WOOD || res == AIJH::STONES)
    {
        AIJH::Resource surfaceRes = GetSurfaceResource(pt);
        TerrainType t1 = gwb.GetNode(pt).t1, t2 = gwb.GetNode(pt).t2;
        if (surfaceRes == res ||
            (res == AIJH::PLANTSPACE && surfaceRes == AIJH::NOTHING && TerrainData::IsVital(t1)) ||
            (res == AIJH::BORDERLAND && (IsBorder(pt) || !IsOwnTerritory(pt)) && (TerrainData::IsUseable(t1) || TerrainData::IsUseable(t2))))
        {
           return AIJH::RES_RADIUS[res];
        }
        //another building using our "resource"? reduce rating!
        if(res == AIJH::WOOD && IsBuildingOnNode(pt, BLD_WOODCUTTER))
            return -40;
        if(res == AIJH::PLANTSPACE && IsBuildingOnNode(pt, BLD_FORESTER))
            return -40;
    }
    //so it's a subsurface resource or something we dont calculate (multiple,blocked,nothing)
    else
    {
        if (GetSubsurfaceResource(pt) == res)
            return AIJH::RES_RADIUS[res];
    }
    return 0;
}
Exemplo n.º 3
0
/************************************************************************
 *
 *  QueryGeometry
 *  	return width X height based on the children preferred sizes
 *
 ************************************************************************/
static XtGeometryResult 
QueryGeometry(
        Widget widget,
        XtWidgetGeometry *intended,
        XtWidgetGeometry *desired )
{
    Dimension work_width = 0, work_height = 0, work_bw = 0 ;
    Dimension title_width = 0, title_height = 0, title_bw = 0 ;
    XtWidgetGeometry child_pref ;
    XmFrameWidget fw = (XmFrameWidget) widget ;

    /* first determine what is the desired size, using the
       preferred sizes of the title and the work_area, or the
       current setting if no preference are given */
    if (fw->frame.work_area) {
	XtQueryGeometry (fw->frame.work_area, NULL, &child_pref);    
	if (IsWidth(&child_pref)) work_width = child_pref.width ;
	else work_width = XtWidth(fw->frame.work_area);
	if (IsHeight(&child_pref)) work_height = child_pref.height ;
	else work_height = XtHeight(fw->frame.work_area);
	if (IsBorder(&child_pref)) work_bw = child_pref.border_width ;
	else work_bw = XtBorderWidth(fw->frame.work_area);
    } 
    if (fw->frame.title_area) {
	XtQueryGeometry (fw->frame.title_area, NULL, &child_pref);    
	if (IsWidth(&child_pref)) title_width = child_pref.width ;
	else title_width = XtWidth(fw->frame.title_area);
	if (IsHeight(&child_pref)) title_height = child_pref.height ;
	else title_height = XtHeight(fw->frame.title_area);
	if (IsBorder(&child_pref)) title_bw = child_pref.border_width ;
	else title_bw = XtBorderWidth(fw->frame.title_area);
    }

    CalcFrameSize (fw, 
		   title_width, title_height, title_bw,
		   work_width, work_height, work_bw,
		   &desired->width, &desired->height);

    /* deal with user initial size setting */
    if (!XtIsRealized(widget))  {
	if (XtWidth(widget) != 0) desired->width = XtWidth(widget) ;
	if (XtHeight(widget) != 0) desired->height = XtHeight(widget) ;
    }	    

    return XmeReplyToQueryGeometry(widget, intended, desired) ;
}
Exemplo n.º 4
0
void GoBoard::reset()
{
  komi = 0.5;
  State.koPoint = NO_KO_POINT;


  for(int i = 0; i<(Size()*Size()); i++)
    {
      State.stones[i] = NONE;


      State.numNeighbours[S_WHITE][i] = 0;
      State.numNeighbours[S_BLACK][i] = 0;

      if(IsBorder(i))
	{
	  State.numNeighboursEmpty[i] = 3;
	}
      if(IsCorner(i))
	{
	  State.numNeighboursEmpty[i]= 2;
	}
      else if(!IsCorner(i) && !IsBorder(i)) //Mid board
	{
	  State.numNeighboursEmpty[i] = 4;
	}

    }
  State.bw_prisoners[S_BLACK] = 0;
  State.bw_prisoners[S_WHITE] = 0;

  for(int i = 0; i<=blockPointer; ++i)
    {
      blocks[i]->reset();
    }
  for(int i = 0; i<=movePointer; ++i)
    {
      moves[i]->Color= -1;
      moves[i]->Point.x=-1;
      moves[i]->Point.y=-1;
      moves[i]->Point.color=-1;
    }

  blockPointer = 0;
  movePointer = 0;
}
Exemplo n.º 5
0
/****************
 * Handle geometry requests from children.
 ****************/
XtGeometryResult
_XmGMHandleGeometryManager(Widget parent, Widget w,
                         XtWidgetGeometry * request,
                         XtWidgetGeometry * reply,
#if NeedWidePrototypes
                         int margin_width,
                         int margin_height,        
#else
                         Dimension margin_width,
                         Dimension margin_height,    
#endif /* NeedWidePrototypes */
                         int resize_policy,
                         int allow_overlap)
{

    /* Policy: Yes
         if margin is non null requests inside the margin or negative 
       are a priori almosted (or denied if the resizepolicy does not
       authorize it).
         That's the only case where almost is returned, no management
         of a limit position or size is done 
    */


    XtWidgetGeometry localReply ;
    Dimension width, height, borderWidth ;
    Position  x, y ;
    XtGeometryResult returnCode = XtGeometryNo ;
    Boolean geoFlag = False, queryonly = False ;
    XmManagerWidget manager = (XmManagerWidget) parent ;

    localReply = *request ;
    localReply.request_mode = CWX|CWY|CWWidth|CWHeight|CWBorderWidth ;

    if(!IsX(request)) localReply.x = XtX(w) ;
    if(!IsY(request)) localReply.y = XtY(w) ;
    if(!IsWidth(request)) localReply.width = XtWidth(w) ;
    if(!IsHeight(request)) localReply.height = XtHeight(w) ;
    if(!IsBorder(request)) localReply.border_width = XtBorderWidth(w) ;

    /*  check for x less than margin width
    */
    if(IsX(request) && (margin_width != 0)
       && (request->x < (int)margin_width)) {   
        localReply.x = (Position) margin_width ;
        returnCode = XtGeometryAlmost ;
    }
    /*  check for y less than margin height  */
    if(IsY(request) && (margin_height != 0)
       && (request->y < (int)margin_height)) {   
        localReply.y = (Position) margin_height ;
        returnCode = XtGeometryAlmost ;
    }

    /* Save current size and set to new size
    */
    x = XtX(w) ;
    y = XtY(w) ;
    width = XtWidth(w) ;
    height = XtHeight(w) ;
    borderWidth = XtBorderWidth(w) ;

    XtX(w) = localReply.x ;
    XtY(w) = localReply.y ;
    XtWidth(w) = localReply.width ;
    XtHeight(w) = localReply.height ;
    XtBorderWidth(w) = localReply.border_width ;

    if(!allow_overlap && _XmGMOverlap (manager, w)) {   
        returnCode = XtGeometryNo ;
    } else  {   
      /* if we already know that we are not gonna change anything */
      if ((returnCode == XtGeometryAlmost) || IsQueryOnly(request)) 
          queryonly = True ;

      /* see if the new layout is OK */
      geoFlag = _XmGMDoLayout(manager, 
                              margin_width, margin_height, 
                              resize_policy, queryonly) ;
      /* if we cannot adapt the new size but the child is still inside
	 go for it */
      if(!geoFlag && ((localReply.x + localReply.width +
		       (localReply.border_width << 1))
		      <= (XtWidth(manager) - margin_width))
	 && ((localReply.y + localReply.height +
	      (localReply.border_width << 1))
	     <= (XtHeight(manager) - margin_height)))
	  geoFlag = True ;

      if (geoFlag) {
          if (returnCode != XtGeometryAlmost)
              returnCode = XtGeometryYes ;
        } else
          returnCode = XtGeometryNo ;
            
      if  (returnCode == XtGeometryAlmost){
          if (reply) *reply = localReply ;
          else returnCode = XtGeometryNo ;
            } 
    }

    if ((returnCode != XtGeometryYes) || queryonly) {   
	/* Can't oblige, so restore previous values. */
	XtX(w) = x ;
	XtY(w) = y ;
	XtWidth(w) = width ;
	XtHeight(w) = height ;
	XtBorderWidth(w) = borderWidth ;
      } 

    return returnCode ;
}
Exemplo n.º 6
0
// protected:
BOOL COXSplashWnd::BuildRegion(POINT ptStart)
	// --- In      : ptStart, the starting point to search for region boundary
	// --- Out     :
	// --- Returns : TRUE if successful; FALSE otherwise
	// --- Effect  : calculate the region to be visible in a bitmap
{
	CArray<CPoint, CPoint&> vertexs;
	CPoint ptMax(0,0);
	CPoint pt0(0,0);
	CPoint pt1(0,0);
	CPoint pt(0,0);
	CPoint ptPrev(0,0);
	CSize sizeInc(0,0);
	int i = 0;
	int iFirst = 0;
	int iLast = 0;
	int iPrev = 0;

	// move directions: index (xInc, yInc) alternate_index
	//        0 (-1,-1) 8    1 ( 0,-1) 9    2 ( 1,-1) 10
	//		  7 (-1, 0)	15		            3 ( 1, 0) 11
	//		  6 (-1, 1) 14   5 ( 0, 1) 13   4 ( 1, 1) 12
	const int xd[] = {-1,0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1};
	const int yd[] = {-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1,1,1,0};
	const int nextdir[] = {6,0,0,2,2,4,4,6,6,0,0,2,2,4,4,6};

	BITMAP bm;
	m_dib.GetBitmapInfo(bm);
	ptMax = CPoint(bm.bmWidth - 1, bm.bmHeight - 1);

	// find a start point that's outside the region
	UNREFERENCED_PARAMETER(ptStart);
	pt0 = CPoint(0,0);
	if (!IsBorder(pt0)) 
		pt0 = CPoint(-1,-1);

	// search diagonally for first point that's within the region
	sizeInc.cx = (pt0.x > (ptMax.x / 2)) ? -1 : 1;
	sizeInc.cy = (pt0.y > (ptMax.y / 2)) ? -1 : 1;
	for (pt1 = pt0 + sizeInc; IsBorder(pt1, FALSE); pt1 += sizeInc)
		;
	pt0 = pt1 - sizeInc;
	
	// if not found after hitting the boundary, search by scan lines
	if (m_dib.GetPixel(pt1) == CLR_INVALID)
	{
		for (pt1.y = 0; pt1.y <= ptMax.y; pt1.y++)
		{
			for (pt1.x = 0; pt1.x <= ptMax.x && IsBorder(pt1); pt1.x++)
				;
			if (pt1.x <= ptMax.x) 
				break;
		}
		if (ptMax.y < pt1.y) 
			return FALSE;
		pt0 = pt1 - CSize(0, 1);
	}

	// now pt1 should be the starting point that's within the region
	// and pt0 should be a neigboring point that's outside the region
	ASSERT(IsBorder(pt0) && !IsBorder(pt1));

	// clockwise find border/region boundary
	for (i = 0; i <= 7; i++)
	{
		pt = pt1 + CSize(xd[i], yd[i]);
		if (!IsBorder(pt)) 
			break;
	}
	if (i == 8) 
		return FALSE;

	// important: assign second point as the start point to prevent
	//			  diagonal circumvent
	pt1 = pt;
	vertexs.Add(pt);
	
	// cycle until the most beginning point is found back again
	do 
	{
		iPrev = i;
		ptPrev = pt;
		iFirst = nextdir[i];
		iLast = iFirst + 6;
		for (i = iFirst; i <= iLast; i++)
		{
			pt = ptPrev + CSize(xd[i], yd[i]);
			if (!IsBorder(pt)) 
				break;
		}
		if (i == iPrev)
		{
			// moving forward on the same direction
			// replace the last point with this new one, so that region
			// definition could be simpler
			vertexs[vertexs.GetSize()-1] = pt;
		}
		else
		{
			// direction changed, has to add a new vertex
			vertexs.Add(pt);
		}
		if(vertexs.GetSize()%3000==0)
			TRACE(_T("Add point: %d,%d, number %d\n"),pt.x,pt.y,vertexs.GetSize());
	} while (pt != pt1);

	m_rgn.DeleteObject();
	if (!m_rgn.CreatePolygonRgn(vertexs.GetData(), PtrToInt(vertexs.GetSize()), ALTERNATE))
	{
		ASSERT((HRGN)m_rgn == NULL);
		return FALSE;
	}

	return TRUE;
}
Exemplo n.º 7
0
int AIInterface::CalcResourceValue(MapCoord x,MapCoord y,AIJH::Resource res,char direction,int lastval) const
{
	int returnval=0;
	if(direction==-1) //calculate complete value from scratch (3n^2+3n+1)
	{
		for(MapCoord tx=gwb->GetXA(x,y,0), r=1;r<=AIJH::RES_RADIUS[res];tx=gwb->GetXA(tx,y,0),++r)
		{
			MapCoord tx2 = tx, ty2 = y;
			for(unsigned i = 2;i<8;++i)
			{
				for(MapCoord r2=0;r2<r;gwb->GetPointA(tx2,ty2,i%6),++r2)
				{
					//surface resource?
					if(res==AIJH::PLANTSPACE||res==AIJH::BORDERLAND||res==AIJH::WOOD||res==AIJH::STONES)
					{
						AIJH::Resource tres=GetSurfaceResource(tx2,ty2);
						unsigned char t1=gwb->GetNode(tx2,ty2).t1,t2=gwb->GetNode(tx2,ty2).t2;
						if (tres==res||(res==AIJH::PLANTSPACE&&tres==AIJH::NOTHING&&t1!=TT_DESERT&&t1!=TT_MOUNTAINMEADOW&&t1!=TT_MOUNTAIN1&&t1!=TT_MOUNTAIN2&&t1!=TT_MOUNTAIN3&&t1!=TT_MOUNTAIN4)||(res==AIJH::BORDERLAND&&(IsBorder(tx2,ty2)||!IsOwnTerritory(tx2,ty2))&&((t1!=TT_SNOW&&t1!=TT_LAVA&&t1!=TT_SWAMPLAND&&t1!=TT_WATER)||(t2!=TT_SNOW&&t2!=TT_LAVA&&t2!=TT_SWAMPLAND&&t2!=TT_WATER))))
						{						
							returnval+=(AIJH::RES_RADIUS[res]);
						}
						//another building using our "resource"? reduce rating!
						if(res==AIJH::WOOD||res==AIJH::PLANTSPACE)
						{
							if((res==AIJH::WOOD&&IsBuildingOnNode(tx2,ty2,BLD_WOODCUTTER))||(res==AIJH::PLANTSPACE&&IsBuildingOnNode(tx2,ty2,BLD_FORESTER)))
								returnval-=(40);
						}
					}
					//so it's a subsurface resource or something we dont calculate (multiple,blocked,nothing)
					else
					{
						if (GetSubsurfaceResource(tx2,ty2)==res)
						{
							returnval+=(AIJH::RES_RADIUS[res]);						
						}
					}
				}
			}
		}
		//add the center point value
		//surface resource?
		if(res==AIJH::PLANTSPACE||res==AIJH::BORDERLAND||res==AIJH::WOOD||res==AIJH::STONES)
		{
			AIJH::Resource tres=GetSurfaceResource(x,y);
			unsigned char t1=gwb->GetNode(x,y).t1,t2=gwb->GetNode(x,y).t2;
			if (tres==res||(res==AIJH::PLANTSPACE&&tres==AIJH::NOTHING&&t1!=TT_DESERT&&t1!=TT_MOUNTAINMEADOW&&t1!=TT_MOUNTAIN1&&t1!=TT_MOUNTAIN2&&t1!=TT_MOUNTAIN3&&t1!=TT_MOUNTAIN4)||(res==AIJH::BORDERLAND&&(IsBorder(x,y)||!IsOwnTerritory(x,y))&&((t1!=TT_SNOW&&t1!=TT_LAVA&&t1!=TT_SWAMPLAND&&t1!=TT_WATER)||(t2!=TT_SNOW&&t2!=TT_LAVA&&t2!=TT_SWAMPLAND&&t2!=TT_WATER))))
			{
				returnval+=(AIJH::RES_RADIUS[res]);
			}
			//another building using our "resource"? reduce rating!
			if(res==AIJH::WOOD||res==AIJH::PLANTSPACE)
			{
				if((res==AIJH::WOOD&&IsBuildingOnNode(x,y,BLD_WOODCUTTER))||(res==AIJH::PLANTSPACE&&IsBuildingOnNode(x,y,BLD_FORESTER)))
				returnval-=(40);
			}
		}
		//so it's a subsurface resource or something we dont calculate (multiple,blocked,nothing)
		else
		{
			if (GetSubsurfaceResource(x,y)==res)
			{
				returnval+=(AIJH::RES_RADIUS[res]);					
			}
		}
	}
	else//calculate different nodes only (4n+2 ?anyways much faster)
	{
		returnval+=lastval;
		//add new points 
		//first: go radius steps towards direction-1  
		MapCoord tx=x,ty=y;
		for(unsigned i=0;i<AIJH::RES_RADIUS[res];i++)
			gwb->GetPointA(tx,ty,(direction+5)%6);
		//then clockwise around at radius distance to get all new points
		for(int i = direction+1;i<(direction+3);++i)
		{
			//add 1 extra step on the second side we check to complete the side
			for(MapCoord r2=0;r2<AIJH::RES_RADIUS[res]||(r2<AIJH::RES_RADIUS[res]+1&&i==direction+2);++r2)
			{
				//surface resource?
				if(res==AIJH::PLANTSPACE||res==AIJH::BORDERLAND||res==AIJH::WOOD||res==AIJH::STONES)
				{
					AIJH::Resource tres=GetSurfaceResource(tx,ty);
					unsigned char t1=gwb->GetNode(tx,ty).t1,t2=gwb->GetNode(tx,ty).t2;
					if (tres==res||(res==AIJH::PLANTSPACE&&tres==AIJH::NOTHING&&t1!=TT_DESERT&&t1!=TT_MOUNTAINMEADOW&&t1!=TT_MOUNTAIN1&&t1!=TT_MOUNTAIN2&&t1!=TT_MOUNTAIN3&&t1!=TT_MOUNTAIN4)||(res==AIJH::BORDERLAND&&(IsBorder(tx,ty)||!IsOwnTerritory(tx,ty))&&((t1!=TT_SNOW&&t1!=TT_LAVA&&t1!=TT_SWAMPLAND&&t1!=TT_WATER)||(t2!=TT_SNOW&&t2!=TT_LAVA&&t2!=TT_SWAMPLAND&&t2!=TT_WATER))))
					{						
						returnval+=(AIJH::RES_RADIUS[res]);
					}
					//another building using our "resource"? reduce rating!
					if(res==AIJH::WOOD||res==AIJH::PLANTSPACE)
					{
						if((res==AIJH::WOOD&&IsBuildingOnNode(tx,ty,BLD_WOODCUTTER))||(res==AIJH::PLANTSPACE&&IsBuildingOnNode(tx,ty,BLD_FORESTER)))
							returnval-=(40);
					}
				}
				//so it's a subsurface resource or something we dont calculate (multiple,blocked,nothing)
				else
				{
					if (GetSubsurfaceResource(tx,ty)==res)
					{						
						returnval+=(AIJH::RES_RADIUS[res]);
					}
				}
				gwb->GetPointA(tx,ty,i%6);
			}
		}
		//now substract old points not in range of new point
		//go to old center point:
		tx=x;
		ty=y;
		gwb->GetPointA(tx,ty,(direction+3)%6);
		//next: go to the first old point we have to substract
		for(unsigned i=0;i<AIJH::RES_RADIUS[res];i++)
			gwb->GetPointA(tx,ty,(direction+2)%6);
		//now clockwise around at radius distance to remove all old points
		for(int i = direction+4;i<(direction+6);++i)
		{
			for(MapCoord r2=0;r2<AIJH::RES_RADIUS[res]||(r2<AIJH::RES_RADIUS[res]+1&&i==direction+5);++r2)
			{
				//surface resource?
				if(res==AIJH::PLANTSPACE||res==AIJH::BORDERLAND||res==AIJH::WOOD||res==AIJH::STONES)
				{
					AIJH::Resource tres=GetSurfaceResource(tx,ty);
					unsigned char t1=gwb->GetNode(tx,ty).t1,t2=gwb->GetNode(tx,ty).t2;
					if (tres==res||(res==AIJH::PLANTSPACE&&tres==AIJH::NOTHING&&t1!=TT_DESERT&&t1!=TT_MOUNTAINMEADOW&&t1!=TT_MOUNTAIN1&&t1!=TT_MOUNTAIN2&&t1!=TT_MOUNTAIN3&&t1!=TT_MOUNTAIN4)||(res==AIJH::BORDERLAND&&(IsBorder(tx,ty)||!IsOwnTerritory(tx,ty))&&((t1!=TT_SNOW&&t1!=TT_LAVA&&t1!=TT_SWAMPLAND&&t1!=TT_WATER)||(t2!=TT_SNOW&&t2!=TT_LAVA&&t2!=TT_SWAMPLAND&&t2!=TT_WATER))))
					{						
						returnval-=(AIJH::RES_RADIUS[res]);
					}
					//another building using our "resource"? reduce rating!
					if(res==AIJH::WOOD||res==AIJH::PLANTSPACE)
					{
						if((res==AIJH::WOOD&&IsBuildingOnNode(tx,ty,BLD_WOODCUTTER))||(res==AIJH::PLANTSPACE&&IsBuildingOnNode(tx,ty,BLD_FORESTER)))
							returnval+=(40);
					}
				}
				//so it's a subsurface resource or something we dont calculate (multiple,blocked,nothing)
				else
				{
					if (GetSubsurfaceResource(tx,ty)==res)
					{
						returnval-=(AIJH::RES_RADIUS[res]);						
					}
				}
				gwb->GetPointA(tx,ty,i%6);
			}
		}
	}
	//if(returnval<0&&lastval>=0&&res==AIJH::BORDERLAND)
		//LOG.lprintf("AIInterface::CalcResourceValue - warning: negative returnvalue direction %i oldval %i\n", direction, lastval);
	return returnval;
}
Exemplo n.º 8
0
//window message process function
LRESULT	
SLEditCtrlProc(
	HWND hWnd, 
	int iMsg, 
	WPARAM wParam, 
	LPARAM lParam
)

{
	PWindowsTree pWin;
	char* buffer;
	POINT point;
	PSLEditData pEditData;
	HPEN hPen;
	HBRUSH hBrush;
	COLORREF crColor;
	PWNDCLASSEX pWndClass;
	LRESULT res;
	char*	passwdchar;
	int	dispLen,len,iBorder;
	char*	dispBuffer;
	HDC hDC;
	RECT rect;
	PAINTSTRUCT ps;
		
	pWin = (PWindowsTree)hWnd;
	
	switch(iMsg){
	case LMSG_CREATE:
		pWin = (PWindowsTree)hWnd;
		pEditData = (void*)malloc(sizeof(SLEditData));
		if(!pEditData)
			return false;
		if (!CreateCaret (hWnd, NULL, 1, GetSysCharHeight())){
			printerror ("EDIT: Create Caret error!\n");
			free (pEditData);
			return -1;
		}
		memset(pEditData,0,sizeof(SLEditData));	
		pEditData->iBufferLen      = LEN_EDITBOX_BUFFER;
		pEditData->passwdChar     = '*';
		pEditData->iLeftMargin     = MARGIN_EDIT_LEFT;
		pEditData->iTopMargin      = MARGIN_EDIT_TOP;
		pEditData->iRightMargin    = MARGIN_EDIT_RIGHT;
		pEditData->iBottomMargin   = MARGIN_EDIT_BOTTOM;
//		memcpy (pEditData->buffer,	pWin->lpszCaption,min (pEditData->iBufferLen, strlen(pWin->lpszCaption)+1);
		strncpy (pEditData->buffer,	pWin->lpszCaption,pEditData->iBufferLen-1);//modify
		pWin->rect.bottom = pWin->rect.top + GetSysCharHeight()
			+ MARGIN_EDIT_TOP + MARGIN_EDIT_BOTTOM + 2 * wndGetBorder(hWnd); 	
			
		pWin->dwData = (DWORD)pEditData;
		SetTimer(hWnd,1,50);
		break;
	case LMSG_TIMER:
		BlinkCaret(hWnd);
		break;
	case LMSG_DESTROY:
		free((void*)(pWin->dwData));
		DestroyCaret(hWnd);
		KillTimer(hWnd,1);
		break;		
	case LMSG_ERASEBKGND:
		pWndClass=GetRegClass(pWin->lpszClassName);
		if(!pWndClass)
			return (LRESULT)NULL;
		//is Enable ?
		hBrush=pWndClass->hbrBackground;
		crColor=((BRUSH*)hBrush)->crBrushColor;
		if(!IsEnable(hWnd))
			((BRUSH*)hBrush)->crBrushColor=RGB_SYSTEMLTGRAY;
		else
			((BRUSH*)hBrush)->crBrushColor=RGB_SYSTEMWHITE;
		res=DefWindowProc(hWnd, iMsg, wParam, lParam);
		((BRUSH*)hBrush)->crBrushColor=crColor;
		return res;
	case LMSG_KILLFOCUS:
		pEditData = (PSLEditData) (pWin->dwData);
		pEditData->dwStatus &= ~EST_FOCUSED;
		HideCaret (hWnd);
		NotifyParent (hWnd, EN_KILLFOCUS);
		break;
	case LMSG_SETFOCUS:
		pEditData = (PSLEditData) (pWin->dwData);
		if (pEditData->dwStatus & EST_FOCUSED)
			return 0;
		
		pEditData->dwStatus |= EST_FOCUSED;
		
		SetCaretPos (hWnd,
			pEditData->iCaretPos * GetSysCharWidth () + pEditData->iLeftMargin,
			pEditData->iTopMargin);
		
		ShowCaret (hWnd);
		
		NotifyParent (hWnd, EN_SETFOCUS);
		break;	
	case LMSG_GETTEXTLENGTH:
		pEditData = (PSLEditData) (pWin->dwData);
		return pEditData->iDataLen;
	case LMSG_GETTEXT:
		buffer = (char*)lParam;
		pEditData = (PSLEditData) (pWin->dwData);
		
		len = min ((int)wParam, pEditData->iDataLen);
		
		memcpy (buffer, pEditData->buffer, len);
		buffer [len] = '\0';
		return len;
	case LMSG_SETTEXT:
		pEditData = (PSLEditData)(pWin->dwData);
		if(pWin->dwStyle & ES_READONLY)
			return 0;
		pEditData = (PSLEditData) (pWin->dwData);
		len = min (strlen ((char*)lParam), pEditData->iBufferLen);
		
		pEditData->iDataLen = len;
		memcpy (pEditData->buffer, (char*)lParam, len);
		pEditData->iEditPos        = 0;
		pEditData->iCaretPos       = 0;
		pEditData->iStartPos       = 0;
		if (pEditData->dwStatus & EST_FOCUSED)
			SetCaretPos (hWnd, pEditData->iLeftMargin, pEditData->iTopMargin);
		InvalidateRect (hWnd, NULL, TRUE);
		break;
	case EM_SETREADONLY:
		if (wParam)
			pWin->dwStyle |= ES_READONLY;
		else
			pWin->dwStyle &= ~ES_READONLY;
		break;
	case EM_SETPASSWORDCHAR:
		pEditData = (PSLEditData) (pWin->dwData);
		
		if (pEditData->passwdChar != (char)wParam) {
			if (pEditData->dwStatus & ES_PASSWORD) {
			    pEditData->passwdChar = (char)wParam;
			    InvalidateRect (hWnd, NULL, TRUE);
			}
		}
		break;
	case EM_GETPASSWORDCHAR:
		pEditData = (PSLEditData) (pWin->dwData);
		passwdchar = (char*) lParam;
		
		*passwdchar = pEditData->passwdChar;
		break;
	case LMSG_PENDOWN:
	{
		int x,y;
		int iRet;
		CaptureMouse(hWnd,BYCLIENT);
		pEditData = (PSLEditData) (pWin->dwData);
		x = (int)wParam;
		y = (int)lParam;
		ScreenToClient(hWnd, &x,&y);
		iRet = edtGetCaretPos (pEditData, x);
		//printf("%d\n",x);
		
		if (iRet != pEditData->iCaretPos) {
			pEditData->iEditPos += iRet - pEditData->iCaretPos;
			pEditData->iCaretPos = iRet;
			SetCaretPos (hWnd,
				pEditData->iCaretPos * GetSysCharWidth ()
				    + pEditData->iLeftMargin,
				pEditData->iTopMargin);
		}
		NotifyParent(hWnd,EN_CLICKED);
		break;
	}
	case LMSG_PENUP:
		DisCaptureMouse();
		break;
	
	case LMSG_ENABLE:
		if((BOOL)wParam)///Enable
			pWin->dwStyle &=~WS_DISABLE;
		else//Disable
			pWin->dwStyle |=WS_DISABLE;
		break;
	case LMSG_NCPAINT:
		GetWindowRect(hWnd,&rect);
		SetRect(&rect,0,0,rect.right-rect.left,rect.bottom-rect.top);
		if(IsBorder(hWnd)){
			hDC = (HDC)wParam;
			if(!hDC)
				return false;
			hPen=CreatePen(PS_SOLID,1,RGB(88,87,81));
			SelectObject(hDC,hPen);
			DeleteObject(hPen);

			winMoveToEx(hDC,rect.left,rect.top,&point);
			winLineTo(hDC,rect.right,rect.top);

			winMoveToEx(hDC,rect.left,rect.top,&point);
			winLineTo(hDC,rect.left,rect.bottom);

			hPen=GetStockObject(LTGRAY_PEN);
			SelectObject(hDC,hPen);
			DeleteObject(hPen);

			winMoveToEx(hDC,rect.right,rect.top+1,&point);
			winLineTo(hDC,rect.right,rect.bottom);
			winMoveToEx(hDC,rect.right,rect.bottom,&point);
			winLineTo(hDC,rect.left,rect.bottom);
		}	
		break;	
	case LMSG_PAINT:
		ps.bPaintDirect=false;
		hDC=BeginPaint(hWnd, &ps);
		if(!hDC){
			return true;
		}
		if(IsFocus(hWnd)){
			HideCaret(hWnd);
		}
		GetWindowRect(hWnd,&rect);
		SetRect(&rect,0,0,rect.right-rect.left,rect.bottom-rect.top);

    		pEditData = (PSLEditData) (pWin->dwData);
		iBorder = wndGetBorder(hWnd);
		InflateRect(&rect,(-1)*iBorder,(-1)*iBorder);

		dispLen = GetEditBoxDispLen (hWnd);
		
		if (dispLen == 0) {
			EndPaint(hWnd, &ps);
			break;
		}
		
		dispBuffer = malloc (dispLen + 1);
		
		if (pWin->dwStyle & ES_PASSWORD)
			memset (dispBuffer, '*', dispLen);
		else
			memcpy (dispBuffer,
				pEditData->buffer + pEditData->iStartPos,
				dispLen);
		dispBuffer [dispLen] = '\0';
		
		rect.left += pEditData->iLeftMargin;
		rect.top += pEditData->iTopMargin;
		rect.right -= pEditData->iRightMargin;
		rect.bottom -= pEditData->iBottomMargin;

		DrawText(hDC,dispBuffer,strlen(dispBuffer),&rect,DT_LEFT);
		free(dispBuffer);//modify,this is added
		EndPaint(hWnd, &ps);
		if(IsFocus(hWnd)){
			ShowCaret(hWnd);
			SetTimer(hWnd,1,50);
		}
		break;	
	//keydown process
	case LMSG_KEYDOWN:
		edtProcessKeyDown(hWnd,wParam,lParam);
		break;	
	case LMSG_CHAR:
		edtProcessChar(hWnd,wParam,lParam);
		break;
		
	default:
		return DefWindowProc(hWnd, iMsg, wParam, lParam);		
	}
	return 0;
}
Exemplo n.º 9
0
void Init(){
	map = GetMap();
	current_time = map -> time;
	register int i,j;
	register int AE_number;
	int AEflag;//记录有无AE可以走
	int flag;//记录ae是否离devour太近
	register int ChosenAE;
	Position ChosenDevour[10];
	register double MinAEdistance;
	Position AE[50];//记录AE的位置
	register int devour_number;
	int coming_devour=0;
	Position Devour[50];//记录Devour的位置
	int Boss_Parameter=20;
	int Devour_Danger=0;
	register double border_r;
	register double F;
	register double dis;
	Vector a2;//从目标到自己的向量

	border_r=0.5*me.radius;
	me = GetStatus() -> objects[0];
	opponent_number = devour_number = see_boss = AE_number = coming_devour=0;
	speed.x = speed.y = speed.z = (double)0;
	MinAEdistance=10000;

	for (i = 0; i < map -> objects_number; ++i)
	{
		F= (double)0, dis = dist(map -> objects[i].pos, me.pos);
		switch (map -> objects[i].type){
			case PLAYER:
				/*if (map -> objects[i].team_id == GetStatus() -> team_id) break;
				opponent[opponent_number++] = map -> objects[i];
				if (me.radius < map -> objects[i].radius) 
					F = RUN_VALUE * me.radius * map -> objects[i].radius / POW(dis, 3);
				if (me.radius > map -> objects[i].radius && me.skill_level[SHORT_ATTACK]
					|| me.skill_level[SHORT_ATTACK]>=5) 
						F = CHASING_VALUE * me.radius * map -> objects[i].radius / POW(dis, 3);*/
				break;
			case ENERGY:
				F = ENERGY_VALUE * POW(me.radius, 2) / POW(dis, 3);
				if (IsBorder(border_r,map -> objects[i].pos))//如果到边界的距离小于r,力为0
					F=0;
				break;
			case ADVANCED_ENERGY:
				AE[AE_number++]=map -> objects[i].pos;
				break;
			case DEVOUR:
				Devour[devour_number++]=map -> objects[i].pos;
				break;
			case BOSS:
				boss = map -> objects[i];
				see_boss = 1;
				boss_r = boss.radius;
				boss_warning = (int)(dis < 1.2 * boss_r && me.radius<boss_r);
				break;
			default:
				break;
		}
		//printf("F=%f\n",F);//F=0.000061~0.001110
		a2=Minus(map -> objects[i].pos,me.pos);
		speed=Add(speed,Multiple(F,a2));
	}
	if (AE_number)//处理AE
	{
		AEflag=0;
		for(i=0;i<AE_number;i++)
		{
			dis=dist(AE[i], me.pos);
			//printf("AE %d dis=%f\n",i,dis);
			if (IsBorder(border_r,AE[i]))
				continue;
			for(j=0,flag=0;j<devour_number;j++)
				if (dist(AE[i],Devour[j])<me.radius && dist(AE[i],me.pos)>0.6*dist(Devour[j],me.pos))
					flag=1;
			if (flag)
				continue;
			dis=dist(AE[i], me.pos);
			if (MinAEdistance>dis)
			{
				MinAEdistance=dis;
				ChosenAE=i;
				AEflag=1;
			}
		}
		if (AEflag)
		{
			/*if (me.skill_level[SHORT_ATTACK]>=5 && me.skill_level[HEALTH_UP]>=4)
				AE_Parameter=0;
			else
				AE_Parameter=100;*/
			a2=Minus(AE[ChosenAE],me.pos);
			F = AE_Parameter * POW(me.radius, 2) / POW(MinAEdistance, 3);
			speed=Add(speed,Multiple(F,a2));
			//printf("chosen ae= %d dis=%f\n",ChosenAE,MinAEdistance);
		}
	}

	/*if (me.radius>1.2*boss_r  && see_boss)//如果比boss大,去吃
	{
		a2=Minus(boss.pos,me.pos);
		//printf("eating boss!\n");
		F=CHASING_BOSS_VALUE * POW(me.radius, 2) / POW(length(a2), 3);
		speed=Add(speed,Multiple(F,a2));
	}*/

	FBorder(1.1*me.radius);//如果碰到边界,速度置0

	Devour_Danger=!(me.shield_time>20 && me.skill_level[SHIELD]==5);
	if (Devour_Danger)
	{
		for (i=0;i<devour_number;i++)//处理吞噬者
			if (IsDevour(1.1*me.radius,Devour[i]))//如果会碰到devour,速度正交化
				ChosenDevour[coming_devour++]=Devour[i];
		if (coming_devour==1)
		{
			a2=Minus(ChosenDevour[0],me.pos);
			//printf("devour!\n");
			speed=Schmidt(speed,a2);
		}
		else if (coming_devour>=2)
		{
			a2=Minus(ChosenDevour[0],me.pos);
			//printf("devour!\n");
			speed=Schmidt(speed,a2);
		}
	}
	if (boss_warning && IsBoss(boss_r+me.radius,boss.pos))//如果碰到boss,正交化
	{
		a2=Minus(boss.pos,me.pos);
		//printf("boss!\n");
		speed=Schmidt(speed,a2);
	}
	speed.x *= 100 + rand() % 5;
	speed.y *= 100 + rand() % 5;
	speed.z *= 100 + rand() % 5;
}