示例#1
0
 private bool Foreach(int key, float3 position, ref FightersHashMap.MyData output, bool found, Fighter me)
 {
     if (targetMap.TryGetFirstValue(key, out FightersHashMap.MyData other, out NativeMultiHashMapIterator <int> iterator))
     {
         do
         {
             if (other.data.groupId == me.groupId)
             {
                 continue;
             }
             var nowDistance = math.length(other.position - position);
             if (!found && nowDistance < me.viewRadius)
             {
                 output = other;
                 found  = true;
             }
             else
             {
                 var prevDist = math.length(output.position - position);
                 if (prevDist > nowDistance)
                 {
                     output = other;
                 }
             }
         } while (targetMap.TryGetNextValue(out other, ref iterator));
     }
     return(found);
 }
示例#2
0
        public void Execute(ref Fighter fighter, ref Condition condition, ref PathFindingData pathFindingData,
                            [ReadOnly] ref Translation translation, ref Rotation walker)
        {
            var selected = new FightersHashMap.MyData();
            var found    = ForeachAround(translation.Value, ref selected, fighter);

            if (found)
            {
                var direction = selected.position - translation.Value;
                fighter.targetId       = selected.data.Id;
                pathFindingData.radius = fighter.attackRadius * 0.5f;
                if (math.length(direction) < fighter.attackRadius)
                {
                    pathFindingData.decidedGoal = translation.Value + direction * 0.01f;
                    RotateForward(direction, ref walker);
                    fighter.state = FightState.Fight;
                }
                else
                {
                    pathFindingData.decidedGoal = translation.Value + direction * 0.5f;
                    fighter.state = FightState.GoToFight;
                }
            }
            else
            {
                fighter.targetId = -1;
                var isNear = GetNear(fighter.goalPos, fighter.goalRadius, translation, ref pathFindingData);
                fighter.state = isNear ? FightState.Standing : FightState.GoToPlace;
            }
        }
示例#3
0
        private bool ForeachAround(float3 position, ref FightersHashMap.MyData output, Fighter myBroId)
        {
            var found = false;
            var key   = QuadrantVariables.GetPositionHashMapKey(position);

            found = found || Foreach(key, position, ref output, found, myBroId);
            key   = QuadrantVariables.GetPositionHashMapKey(position, new float3(1, 0, 0));
            found = found || Foreach(key, position, ref output, found, myBroId);
            key   = QuadrantVariables.GetPositionHashMapKey(position, new float3(-1, 0, 0));
            found = found || Foreach(key, position, ref output, found, myBroId);
            key   = QuadrantVariables.GetPositionHashMapKey(position, new float3(0, 0, 1));
            found = found || Foreach(key, position, ref output, found, myBroId);
            key   = QuadrantVariables.GetPositionHashMapKey(position, new float3(0, 0, -1));
            found = found || Foreach(key, position, ref output, found, myBroId);
            return(found);
        }