Beispiel #1
0
 private FarmObjectSetting.ExtendBuildPositionSearchResult GetExtendBuildGrid(FarmObject oneBeforeFarmObject, UserFacility oneBeforeUserFacility, FarmObjectSetting.PriorityDirection priorityDirection)
 {
     FarmGrid.GridPosition gridPosition = new FarmGrid.GridPosition
     {
         x = oneBeforeUserFacility.positionX,
         y = oneBeforeUserFacility.positionY
     };
     FarmObjectSetting.ExtendBuildPositionSearchInfo extendBuildPositionSearchInfo = new FarmObjectSetting.ExtendBuildPositionSearchInfo
     {
         farmField           = FarmRoot.Instance.Field,
         field               = FarmRoot.Instance.Field.GetField(),
         oneBeforeFarmObject = oneBeforeFarmObject,
         aroundCount         = 1,
         aroundX             = oneBeforeFarmObject.sizeX,
         aroundY             = oneBeforeFarmObject.sizeY,
         priorityDirection   = priorityDirection,
         originGrid          = gridPosition,
         resultGrid          = gridPosition
     };
     while (!this.SearchExtendBuildGrid(extendBuildPositionSearchInfo))
     {
         if (extendBuildPositionSearchInfo.isOutsideMap)
         {
             break;
         }
         extendBuildPositionSearchInfo.aroundCount++;
         extendBuildPositionSearchInfo.aroundX = oneBeforeFarmObject.sizeX + extendBuildPositionSearchInfo.aroundCount;
         extendBuildPositionSearchInfo.aroundY = oneBeforeFarmObject.sizeY + extendBuildPositionSearchInfo.aroundCount;
     }
     return(new FarmObjectSetting.ExtendBuildPositionSearchResult
     {
         grid = extendBuildPositionSearchInfo.resultGrid,
         isOutsideMap = extendBuildPositionSearchInfo.isOutsideMap
     });
 }
Beispiel #2
0
    private void AddExtendBuildPositionSearchInfo(FarmObjectSetting.ExtendBuildPositionSearchInfo searchInfo, FarmObjectSetting.PriorityDirection priorityDirection)
    {
        searchInfo.startGrid = searchInfo.originGrid;
        searchInfo.endGrid   = searchInfo.originGrid;
        switch (priorityDirection)
        {
        case FarmObjectSetting.PriorityDirection.FRONT:
            searchInfo.startGrid.y   = searchInfo.startGrid.y + searchInfo.aroundY;
            searchInfo.endGrid.x     = searchInfo.endGrid.x - searchInfo.aroundX;
            searchInfo.changeValue.x = -searchInfo.aroundX;
            searchInfo.changeValue.y = -searchInfo.aroundY;
            break;

        case FarmObjectSetting.PriorityDirection.LEFT:
            searchInfo.startGrid.x   = searchInfo.startGrid.x - searchInfo.aroundX;
            searchInfo.endGrid.y     = searchInfo.endGrid.y - searchInfo.aroundY;
            searchInfo.changeValue.x = searchInfo.aroundX;
            searchInfo.changeValue.y = -searchInfo.aroundY;
            break;

        case FarmObjectSetting.PriorityDirection.REAR:
            searchInfo.startGrid.y   = searchInfo.startGrid.y - searchInfo.aroundY;
            searchInfo.endGrid.x     = searchInfo.endGrid.x + searchInfo.aroundX;
            searchInfo.changeValue.x = searchInfo.aroundX;
            searchInfo.changeValue.y = searchInfo.aroundY;
            break;

        case FarmObjectSetting.PriorityDirection.RIGHT:
            searchInfo.startGrid.x   = searchInfo.startGrid.x + searchInfo.aroundX;
            searchInfo.endGrid.y     = searchInfo.endGrid.y + searchInfo.aroundY;
            searchInfo.changeValue.x = -searchInfo.aroundX;
            searchInfo.changeValue.y = searchInfo.aroundY;
            break;
        }
    }
Beispiel #3
0
    private bool SearchPutGrid(FarmObjectSetting.ExtendBuildPositionSearchInfo searchInfo)
    {
        bool result = false;

        searchInfo.isOutsideMap = true;
        FarmGrid.GridPosition startGrid = searchInfo.startGrid;
        while (startGrid.x != searchInfo.endGrid.x && startGrid.y != searchInfo.endGrid.y)
        {
            if (!searchInfo.farmField.IsOutsideField(startGrid))
            {
                searchInfo.isOutsideMap = false;
                int   gridIndex  = searchInfo.farmField.Grid.GetGridIndex(startGrid);
                int[] gridIndexs = searchInfo.oneBeforeFarmObject.GetGridIndexs(searchInfo.field, gridIndex);
                if (!searchInfo.oneBeforeFarmObject.IsInvalidGrid(searchInfo.farmField, gridIndexs) && !searchInfo.oneBeforeFarmObject.IsPutGrid(searchInfo.field, gridIndexs))
                {
                    result = true;
                    searchInfo.resultGrid = startGrid;
                    break;
                }
            }
            startGrid.x += searchInfo.changeValue.x;
            startGrid.y += searchInfo.changeValue.y;
        }
        return(result);
    }
Beispiel #4
0
    private bool SearchExtendBuildGrid(FarmObjectSetting.ExtendBuildPositionSearchInfo searchInfo)
    {
        bool result = false;

        for (int i = 0; i < Enum.GetNames(typeof(FarmObjectSetting.PriorityDirection)).Length; i++)
        {
            int num = (int)(i + searchInfo.priorityDirection);
            if (Enum.GetNames(typeof(FarmObjectSetting.PriorityDirection)).Length <= num)
            {
                num -= Enum.GetNames(typeof(FarmObjectSetting.PriorityDirection)).Length;
            }
            this.AddExtendBuildPositionSearchInfo(searchInfo, (FarmObjectSetting.PriorityDirection)num);
            if (this.SearchPutGrid(searchInfo))
            {
                result = true;
                break;
            }
        }
        return(result);
    }