Esempio n. 1
0
    public List <DiscreteDomainRangeList <LightColumn> > columnsOnBorderOfQuadInDirection(Quad areaXZ, Direction dir, bool wantWithin)
    {
        SimpleRange xRange = areaXZ.sSimpleRange();
        SimpleRange zRange = areaXZ.tSimpleRange();
        SimpleRange longRange;
        SimpleRange shortRange;
        int         shortRangeStart;
        Axis        axis = DirectionUtil.AxisForDirection(dir);

        if (axis == Axis.X)
        {
            longRange  = zRange;
            shortRange = xRange;
        }
        else
        {
            longRange  = xRange;
            shortRange = zRange;
        }
        if (DirectionUtil.IsPosDirection(dir))
        {
            shortRangeStart = wantWithin ? shortRange.extentMinusOne() : shortRange.extent();
        }
        else
        {
            shortRangeStart = wantWithin ? shortRange.start : shortRange.start - 1;
        }
        shortRange = new SimpleRange(shortRangeStart, 1);

        Quad area = (axis == Axis.X) ? new Quad(new PTwo(shortRange.start, longRange.start), new PTwo(shortRange.range, longRange.range)) :
                    new Quad(new PTwo(longRange.start, shortRange.start), new PTwo(longRange.range, shortRange.range));

        return(columnsWithin(area));
    }
Esempio n. 2
0
        public bool IsInRadius(ref Vector3 pt, SimpleRange range)
        {
            var distSq = GetDistanceSq(ref pt);

            return(distSq <= range.MaxDist * range.MaxDist &&
                   (range.MinDist < 1 || distSq >= range.MinDist * range.MinDist));
        }
Esempio n. 3
0
    public void editLightWithAdjacentNonTerminatingSurfaceHeightAtPatchRelativeZ(int surfaceHeight, int patchRelZ)
    {
        if (!this.spanContainsZ(patchRelZ))
        {
            return;
        }

        int  heightAt      = this.lightLevelTrapezoid.heightAt(patchRelZ).extent();
        byte lightAtBefore = this.lightLevelAt(patchRelZ);

        if (surfaceHeight < heightAt)
        {
            this.addLightLevelsWithAdjacentSurfaceHeightSpanOffset(surfaceHeight, patchRelZ - this.spanStart);
        }
        else
        {
            this.lightLevelTrapezoid.removeLightLevelsBySubtractingAdjacentSurface(patchRelZ);
        }

        //INFLUENCE...
        int deltaLight = (int)(lightAtBefore - this.lightLevelAt(patchRelZ));

        if (Mathf.Abs(deltaLight) > (int)UNIT_FALL_OFF_BYTE)
        {
            SimpleRange influenceRange = SimpleRange.SimpleRangeWithStartAndExtent(patchRelZ - INFLUENCE_RADIUS, patchRelZ + INFLUENCE_RADIUS);
            influenceRange = SimpleRange.IntersectingRange(influenceRange, new SimpleRange(0, NoisePatch.patchDimensions.z));             //wimp out (need other noisepatch windows too)
            influenceNeighborsInDirectionWithinZRange(Direction.xpos, influenceRange, INFLUENCE_RADIUS, deltaLight > 0);
            influenceNeighborsInDirectionWithinZRange(Direction.xneg, influenceRange, INFLUENCE_RADIUS, deltaLight > 0);
        }
    }
Esempio n. 4
0
        public bool IsInRange(SimpleRange range, WorldObject obj)
        {
            var distSq = GetDistanceSq(obj);

            return(distSq <= range.MaxDist * range.MaxDist &&
                   (range.MinDist < 1 || distSq >= range.MinDist * range.MinDist));
        }
Esempio n. 5
0
    public static List <PTwo> PointsInsideBorderOfQuad(Quad area, int inset)
    {
        List <PTwo> result = new List <PTwo>();
        SimpleRange sRange = area.sSimpleRange();
        SimpleRange tRange = area.tSimpleRange();

        if (inset > sRange.range / 2 || inset > tRange.range / 2)
        {
            return(result);
        }

        int outerNudge = inset + 1;

        int start         = sRange.start + inset;
        int otherDim      = tRange.start + inset;
        int otherDimOuter = tRange.extent() - outerNudge;

        for (int i = start; i < sRange.extent() - outerNudge; ++i)
        {
            result.Add(new PTwo(i, otherDim));
            result.Add(new PTwo(i, otherDimOuter));
        }

        start         = tRange.start + inset + 1;
        otherDim      = sRange.start + inset;
        otherDimOuter = sRange.extent() - outerNudge;

        for (int i = start; i < tRange.extent() - outerNudge - 1; ++i)
        {
            result.Add(new PTwo(otherDim, i));
            result.Add(new PTwo(otherDimOuter, i));
        }

        return(result);
    }
Esempio n. 6
0
    /*
     * this somewhat (totally?) does the same thing as updatewithadjacentwindowsreturnaddedLightRating
     * except its limited to a local area.
     * within a given z span
     * get your neighbors in one of four dir xz pos neg
     * impart influence by subtracting or adding on the neighbors (if within the span)
     * you're given a counter, which if its pos, you should call this func on each neighbor (who was influenced at all
     * within a spanOfInfluence that you were keeping track of whil you imparted influence)
     * if the sOI has range zero, stop
     * if counter is zero stop
     */
    private void influenceNeighborsInDirectionWithinZRange(Direction dir, SimpleRange zSpanOfInfluence, int counter, bool wantSubtract)
    {
        if (counter <= 0)
        {
            return;
        }

        List <Window> neisInDirection = neighborsForDirection(dir);

        if (neisInDirection == null || neisInDirection.Count == 0)
        {
            return;
        }

        SimpleRange nextZSpanOfInfluence = new SimpleRange(257, 0);
        Window      neib = null;

        for (int i = 0; i < neisInDirection.Count; ++i)
        {
            neib = neisInDirection[i];

            // lilTraps work togethr. return nextZSOI
            nextZSpanOfInfluence = neib.lightLevelTrapezoid.considerLightValuesFromOther(this.lightLevelTrapezoid,
                                                                                         wantSubtract, zSpanOfInfluence, (float)(counter / (float)INFLUENCE_RADIUS));

            if (nextZSpanOfInfluence.range > 0)
            {
                neib.influenceNeighborsInDirectionWithinZRange(dir, nextZSpanOfInfluence, counter - 1, wantSubtract);
            }
        }
    }
Esempio n. 7
0
        private void button14_Click(object sender, EventArgs e)
        {
            double[] expertTrust = GetExpertTrust();
            int      objCount    = Decimal.ToInt32(objCount1.Value);

            ArrayList expertOpinions = arrayListFromMatrix(rangeTable1, objCount1);

            Method method = new SimpleRange();

            double efficiency = 0;
            Object result;

            method.Execute(expertsCount, expertTrust, expertOpinions, out efficiency, out result);
            int[] resultRange = result as int[];


            rangeResult1.Columns.Clear();

            concordResult1.Text = efficiency.ToString();
            for (int i = 0; i < objCount; i++)
            {
                rangeResult1.Columns.Add("Column" + i.ToString(), "Oб`єкт " + Convert.ToString(i + 1));
                rangeResult1[i, 0].Value = resultRange[i];
            }
        }
Esempio n. 8
0
    private LightColumn lightestNeightbor(SimpleRange colRange, PTwo co)
    {
        LightColumn lightest = null;

        List <LightColumn> neighbors = m_lightColumnMap.lightColumnsAdjacentToAndFlushWithSimpleRangeAndPoint(colRange, co);

        if (neighbors.Count == 0)
        {
            return(null);
        }

        lightest = neighbors[0];

        //CONSIDER: could be a little faster if we iterated over directions ourselves here...
        for (int i = 1; i < neighbors.Count; ++i)
        {
            LightColumn neicol = neighbors[i];
            if (neicol.lightLevel > lightest.lightLevel)
            {
                lightest = neicol;
            }
        }

        return(lightest);
    }
Esempio n. 9
0
    public List <LightColumn> lightColumnsAdjacentToAndFlushWithSimpleRangeAndPoint(SimpleRange colmRange, PTwo coord)
    {
//		PTwo coord = colm.coord;
        List <LightColumn> result = new List <LightColumn>();

        foreach (PTwo surroundingCo in DirectionUtil.SurroundingPTwoCoordsFromPTwo(coord))
        {
            DiscreteDomainRangeList <LightColumn> adjRangeList = this.lightColumnListAtOrNull(surroundingCo.s, surroundingCo.t);
            if (adjRangeList == null)
            {
                continue;
            }
            for (int i = 0; i < adjRangeList.Count; ++i)
            {
                LightColumn adjLightColumn = adjRangeList[i];

                OverlapState overlap = colmRange.overlapStateWith(adjLightColumn.range);
                if (OverLapUtil.OverlapExists(overlap))
                {
                    result.Add(adjLightColumn);
                }
            }
        }
        return(result);
    }
Esempio n. 10
0
 public AIMoveIntoRangeOfGOThenExecAction(Unit owner, GameObject go, SimpleRange range,
                                          UnitActionCallback actionCallback)
     : base(owner, actionCallback)
 {
     this._gameObject = go;
     this.m_Range     = range;
 }
Esempio n. 11
0
 public void ShouldNotThrowUserExceptionOnInsert()
 {
     using (var executionContext = new CommonTestExecutionContext())
     {
         var repository = new Common.DomRepository(executionContext);
         var entity = new SimpleRange { FromValue = (decimal)1.1, ToValue = (decimal)2.0 };
         repository.TestRange.SimpleRange.Insert(new[] { entity });
     }
 }
Esempio n. 12
0
 public void ShouldNotThrowUserExceptionOnInsert()
 {
     using (var container = new RhetosTestContainer())
     {
         var repository = container.Resolve<Common.DomRepository>();
         var entity = new SimpleRange { FromValue = (decimal)1.1, ToValue = (decimal)2.0 };
         repository.TestRange.SimpleRange.Insert(new[] { entity });
     }
 }
Esempio n. 13
0
    //do we need a new func. to edit around a new surface height?

    //INCORP DISCONTINUITY *UPDATING WINDOWS VERSION*
    private Window incorporateUpdatedDiscontinuityAt(SimpleRange disRange, int x, int z, bool allowEditing)
    {
        return(incorporateDiscontinuityAt(disRange, x, z, allowEditing));
        //at this point (we pray)
        //windows could have gaps (one z wide)
        //therefore, we want to add a discont to the MIDDLE of a window first if we can.
        //But, not if there already is a discont in that z column (that is non-overlapping or contig with the column)
        //in other words, we can't have two disRanges at one z
        //COME TO THINK OF IT...this will work anyway with the adding version.? not quite, but it should?
    }
Esempio n. 14
0
 /// <summary>
 /// Moves to the given target and once within the given range, executes the given action
 /// </summary>
 /// <remarks>Requires Brain</remarks>
 public void MoveToThenExecute(GameObject go, SimpleRange range, UnitActionCallback actionCallback, int millisTimeout)
 {
     if (CheckBrain())
     {
         m_brain.CurrentAction = new AIMoveIntoRangeOfGOThenExecAction(this, go, range, actionCallback)
         {
             TimeoutMillis = millisTimeout
         };
     }
 }
Esempio n. 15
0
    public void addHeightRangesAsColumns(int debugInteger)
    {
        for (int i = 0; i < NoisePatch.patchDimensions.z / 4; ++i)
        {
            SimpleRange r = lightLevelTrapezoid.heightAt(i);
//			if (r.range > 0)
//			{
            ChunkManager.debugLinesAssistant.addColumn(r, new PTwo(xCoord, i), debugInteger);
//			}
        }
    }
Esempio n. 16
0
    public void addDiscontinuityRangeAtEnd(SimpleRange newDisRange)
    {
        int zIndex = trapezoid.span.extent();         //not minus one since this is new

        this.zHeightRanges[zIndex] = newDisRange;

        this.trapezoid.endRange = SimpleRange.Average(this.trapezoid.endRange, newDisRange);
        this.trapezoid.span.range++;

        assertSpanDebug();
    }
Esempio n. 17
0
 public void ShouldNotThrowUserExceptionOnInsert()
 {
     using (var container = new RhetosTestContainer())
     {
         var repository = container.Resolve <Common.DomRepository>();
         var entity     = new SimpleRange {
             FromValue = (decimal)1.1, ToValue = (decimal)2.0
         };
         repository.TestRange.SimpleRange.Insert(new[] { entity });
     }
 }
Esempio n. 18
0
    private void constructorSetupWindow(WindowMap _windowMap, SimpleRange startDisRange, int startX, int startZ)
    {
        this.m_windowMap = _windowMap;
        Trapezoid atrapezoid = new Trapezoid(startDisRange, startZ);

        this.lightLevelTrapezoid = new LightLevelTrapezoid(TrapLight.MediumLightQuad(), atrapezoid);

//		this.heights.Add(startDisRange);

        this.xLevel = startX;
    }
Esempio n. 19
0
 public void ShouldNotThrowUserExceptionOnInsert()
 {
     using (var scope = TestScope.Create())
     {
         var repository = scope.Resolve <Common.DomRepository>();
         var entity     = new SimpleRange {
             FromValue = (decimal)1.1, ToValue = (decimal)2.0
         };
         repository.TestRange.SimpleRange.Insert(new[] { entity });
     }
 }
Esempio n. 20
0
        public void RangeWithDisallowedTouchingIntersect(
            decimal from1,
            decimal to1,
            decimal from2,
            decimal to2,
            bool shouldIntersect)
        {
            SimpleRange range1 = new SimpleRange(from1, to1, false);
            SimpleRange range2 = new SimpleRange(from2, to2, false);

            Assert.Equal(shouldIntersect, range1.Intersects(range2));
        }
Esempio n. 21
0
        public void ShouldThowUserExceptionOnUpdate()
        {
            using (var container = new RhetosTestContainer())
            {
                var repository = container.Resolve<Common.DomRepository>();
                var entity = new SimpleRange { FromValue = 1, ToValue = 5 };
                repository.TestRange.SimpleRange.Insert(new[] { entity });

                entity.ToValue = 0;
                repository.TestRange.SimpleRange.Update(new[] { entity });
            }
        }
Esempio n. 22
0
 public void RemoveWithRangeEqualTo(SimpleRange withinRange)
 {
     for (int i = 0; i < _ranges.Count; ++i)
     {
         T r = _ranges[i];
         if (r.rangeP == withinRange.range && r.startP == withinRange.startP)
         {
             _ranges.RemoveAt(i);
             return;
         }
     }
 }
Esempio n. 23
0
    public void addDiscontinuityRangeAtStart(SimpleRange newDisRange)
    {
        int zIndex = trapezoid.span.start - 1;

        this.zHeightRanges[zIndex] = newDisRange;

        this.trapezoid.endRange = SimpleRange.Average(this.trapezoid.startRange, newDisRange);
        this.trapezoid.span.range++;
        this.trapezoid.span.start--;

        assertSpanDebug();
    }
Esempio n. 24
0
 /// <summary>
 /// Moves to the given target and once within the given range, executes the given action
 /// </summary>
 /// <remarks>Requires Brain</remarks>
 public void MoveToThenExecute(Unit unit, SimpleRange range, UnitActionCallback actionCallback, int millisTimeout)
 {
     if (CheckBrain())
     {
         //m_brain.StopCurrentAction();
         Target = unit;
         m_brain.CurrentAction = new AIMoveIntoRangeThenExecAction(this, range, actionCallback)
         {
             TimeoutMillis = millisTimeout
         };
     }
 }
Esempio n. 25
0
    public SimpleRange considerLightValuesFromOther(LightLevelTrapezoid other, bool subtract, SimpleRange withinRange, float influenceFactor)
    {
        int minInfluenceIndex = 258;
        int maxInfluenceIndex = 0;

        if (!SimpleRange.RangesIntersect(trapezoid.span, withinRange))
        {
            return(new SimpleRange(0, 0));
        }

        byte influenceFromOther = (byte)(Window.LIGHT_LEVEL_MAX * influenceFactor - Window.UNIT_FALL_OFF_BYTE);

        withinRange = SimpleRange.IntersectingRange(withinRange, new SimpleRange(0, NoisePatch.patchDimensions.z));         // safer...
        if (withinRange.isErsatzNull())
        {
            return(new SimpleRange(0, 0));
        }

        for (int i = withinRange.start; i < withinRange.extent(); ++i)
        {
            byte myCurrentLightLevel = zLightLevels[i];
            byte othersLightLevel    = other.zLightLevels[i];

//			if (myCurrentLightLevel == Window.LIGHT_LEVEL_MAX_BYTE)
//				continue;

            byte influenceAmount = 0;

            if (myCurrentLightLevel <= influenceFromOther)
            {
//				if (subtract) {
//				} else {
                influenceAmount = (byte)(other.zLightLevels[i] - Window.UNIT_FALL_OFF_BYTE);
//				}
            }
            else
            {
                //cheap0
                influenceAmount = (byte)(myCurrentLightLevel + (influenceFromOther / 2f * (subtract? -1 : 1)));
            }
            zLightLevels[i] = (byte)Mathf.Clamp(influenceAmount, 0, (int)Window.LIGHT_LEVEL_MAX_BYTE);

            minInfluenceIndex = Mathf.Min(minInfluenceIndex, i);
            maxInfluenceIndex = Mathf.Max(maxInfluenceIndex, i + 1);
        }

        if (maxInfluenceIndex == 0)
        {
            return(new SimpleRange(0, 0));
        }

        return(SimpleRange.SimpleRangeWithStartAndExtent(minInfluenceIndex, maxInfluenceIndex));
    }
Esempio n. 26
0
 private static bool RangeAboveSurface(SimpleRange range, SurroundingSurfaceValues ssvs)
 {
     foreach (Direction dir in DirectionUtil.TheDirectionsXZ())
     {
         int height = ssvs.valueForDirection(dir);
         if (height < range.extent())
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 27
0
    private void updateRangeListAtXZ(List <Range1D> heightRanges, Coord pRelCoord, bool solidBlockRemoved, SurroundingSurfaceValues ssvs)
    {
        DiscreteDomainRangeList <LightColumn> liCols = m_lightColumnMap[pRelCoord.x, pRelCoord.z];

        if (!solidBlockRemoved && heightRanges.Count <= 1)        // equal zero would be down right silly.
        {
            return;
        }
        // y above highest extent?
        int highestDiscontinuity = liCols.highestExtent();

        int lowestSurroundingLevel = ssvs.lowestValue();

        //CASE WHERE A BLOCK IS ADDED TO THE TOP OF OR OVER TOP OF THE SURFACE
        if (pRelCoord.y > highestDiscontinuity && !solidBlockRemoved)
        {
            // Y MUST BE THE TOP BLOCK?
            int hRangeCount = heightRanges.Count;

            SimpleRange between = discontinuityBetween(heightRanges[hRangeCount - 2], heightRanges[hRangeCount - 1]);
            if (!between.isErsatzNull())
            {
                AssertUtil.Assert(pRelCoord.y == between.extentMinusOne(), "confused. y is " + pRelCoord.y + " between range is " + between.toString());
                int         lightValue = pRelCoord.y >= lowestSurroundingLevel? (int)Window.LIGHT_LEVEL_MAX_BYTE : 0;
                LightColumn licol      = new LightColumn(PTwo.PTwoXZFromCoord(pRelCoord), (byte)lightValue, between);
                liCols.Add(licol);
                return;                 // licol;
            }
            throw new Exception("don't want to be here. we think a block couldn't be placed vertically in between at this point");
        }

        //TODO handle case where y is above surface, solid block removed
        // need to destroy some discon ranges (not incorporate y).
        Range1D highest = heightRanges[heightRanges.Count - 1];

        if (pRelCoord.y > highest.extent())
        {
            liCols.RemoveStartAbove(highest.extent());
        }
        else
        {
            LightColumn newCol = liCols.Incorporate(pRelCoord.y, solidBlockRemoved);
            if (newCol != null)
            {
                newCol.coord = new PTwo(pRelCoord.x, pRelCoord.z);
            }
//			throw new Exception("lots of exceptions. we failed to incorp a solid block added.");
        }
        b.bug("we incorporated a pRelCOord: " + pRelCoord.toString() + "solid removed was: " + solidBlockRemoved);

        m_lightColumnMap[pRelCoord.x, pRelCoord.z] = liCols;
    }
Esempio n. 28
0
    public void addColumn(SimpleRange range, PTwo _xz, int debugInteger)
    {
        Column column = new Column();

        column.range        = range;
        column.xz           = _xz;
        column.handyInteger = debugInteger;

        if (!columns.Contains(column))
        {
            columns.Add(column);
        }
    }
Esempio n. 29
0
    private static SimpleRange discontinuityBetween(Range1D belowRange, Range1D aboveRange)
    {
        int gap = aboveRange.start - belowRange.extent();

        if (gap > 0)
        {
            return(new SimpleRange(belowRange.extent(), gap));
        }

//		throw new Exception("good to know if this happens. discon between got a null range. no gap?");

        return(SimpleRange.theErsatzNullRange());
    }
Esempio n. 30
0
        public void ShouldThowUserExceptionOnUpdate()
        {
            using (var container = new RhetosTestContainer())
            {
                var repository = container.Resolve <Common.DomRepository>();
                var entity     = new SimpleRange {
                    FromValue = 1, ToValue = 5
                };
                repository.TestRange.SimpleRange.Insert(new[] { entity });

                entity.ToValue = 0;
                repository.TestRange.SimpleRange.Update(new[] { entity });
            }
        }
Esempio n. 31
0
    public bool isContiguityAtZ(int patchRelZ, bool wantPosDir)
    {
        int nudge         = (wantPosDir ? 1 : -1);
        int adjacentIndex = patchRelZ + nudge;

        if (adjacentIndex >= zHeightRanges.Length || adjacentIndex < 0)
        {
            return(true);
        }

        SimpleRange intersection = SimpleRange.IntersectingRange(heightAt(patchRelZ), heightAt(adjacentIndex));

        return(intersection.range > 0);
    }
Esempio n. 32
0
        public void ShouldThowUserExceptionOnUpdate()
        {
            using (var scope = TestScope.Create())
            {
                var repository = scope.Resolve <Common.DomRepository>();
                var entity     = new SimpleRange {
                    FromValue = 1, ToValue = 5
                };
                repository.TestRange.SimpleRange.Insert(new[] { entity });

                entity.ToValue = 0;
                repository.TestRange.SimpleRange.Update(new[] { entity });
            }
        }
Esempio n. 33
0
    private static List <SimpleRange> discontinuitiesFromHeightRanges(List <Range1D> heightRanges)
    {
        List <SimpleRange> result = new List <SimpleRange>();

        for (int i = 1; i < heightRanges.Count; ++i)
        {
            SimpleRange between = discontinuityBetween(heightRanges[i - 1], heightRanges[i]);
            if (!between.isErsatzNull())
            {
                result.Add(between);
            }
        }
        return(result);
    }
Esempio n. 34
0
        public void ShouldInsertEntityWithoutRangeTo()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                executionContext.SqlExecuter.ExecuteSql(new[]
                    {
                        "DELETE FROM TestRange.SimpleRange;",
                    });

                var repository = new Common.DomRepository(executionContext);
                var entity = new SimpleRange { FromValue = 1 };
                var entity2 = new SimpleRange { ToValue = 1 };
                repository.TestRange.SimpleRange.Insert(new[] { entity, entity2 });
            }
        }
Esempio n. 35
0
        public void ShouldInsertEntityWithoutRangeTo()
        {
            using (var container = new RhetosTestContainer())
            {
                container.Resolve<ISqlExecuter>().ExecuteSql(new[]
                    {
                        "DELETE FROM TestRange.SimpleRange;",
                    });

                var repository = container.Resolve<Common.DomRepository>();
                var entity = new SimpleRange { FromValue = 1 };
                var entity2 = new SimpleRange { ToValue = 1 };
                repository.TestRange.SimpleRange.Insert(new[] { entity, entity2 });
            }
        }
Esempio n. 36
0
        public void ShouldThowUserExceptionOnUpdate()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                var repository = new Common.DomRepository(executionContext);
                var entity = new SimpleRange { FromValue = 1, ToValue = 5 };
                repository.TestRange.SimpleRange.Insert(new[] { entity });

                entity.ToValue = 0;
                repository.TestRange.SimpleRange.Update(new[] { entity });
            }
        }