Exemple #1
0
        private void AddVisibleBehaviour(GameObject unit)
        {
            var             unitBehaviour = unit.GetComponent <UnitBehaviour>();
            VisibleBehavior vis           = new VisibleBehavior(unit, unitBehaviour);

            unitBehaviour.VisibleBehavior = vis;
        }
Exemple #2
0
    /*private bool notDetected(VisibleBehavior enemy, VisibleBehavior unit)
     * {
     *
     *  if (TerrainBuilder.visionScore(unit.transform, enemy.transform,maxViewDistance))
     *  {
     *      detectedHostile.Add(enemy);
     *      enemy.setDetected(unit);
     *      return true;
     *  }
     *  else
     *  {
     *      enemy.setDetected(null);
     *      return false;
     *  }
     * }*/
    /*private bool detected(VisibleBehavior vis)
     * {
     *  if (TerrainBuilder.visionScore(vis.getDetectedBy().transform, vis.transform, maxViewDistance))
     *  {
     *      return false;
     *  }
     *  else
     *  {
     *      var region=vis.getRegion();
     *      visionCells[region.x, region.y].Add(vis);
     *      return true;
     *  }
     * }*/
    public static void updateUnitRegion(VisibleBehavior unit, Point newRegion)
    {
        var currentPoint = unit.getRegion();

        getVisionCells(unit.team)[currentPoint.x, currentPoint.y].Remove(unit);
        getVisionCells(unit.team)[newRegion.x, newRegion.y].Add(unit);
    }
Exemple #3
0
    /*public override int GetHashCode()
     * {
     *  return hashCode;
     * }
     * public bool Equals(VisibleBehavior obj)
     * {
     *  return obj != null && obj.hashCode == this.hashCode;
     * }*/



    internal void addHostile(VisibleBehavior b)
    {
        if (!spottedBy.ContainsKey(b))
        {
            spottedBy.Add(b, false);
        }
        if (!spotting.ContainsKey(b))
        {
            spotting.Add(b, false);
        }
    }
Exemple #4
0
    // It is the responsibility of the defender to
    // reveal themselves if necessary. This is done here.
    private void MaybeReveal(VisibleBehavior spotter)
    {
        if (spotter.CanDetect(this))
        {
            if (_spotters.Count == 0)
            {
                ToggleUnitVisibility(true);
            }

            _spotters.Add(spotter);
        }
    }
Exemple #5
0
    public void RegisterUnitBirth(UnitBehaviour unit)
    {
        VisibleBehavior visibleBehavior = unit.VisibleBehavior;

        if (unit.Platoon.Owner.Team == LocalTeam)
        {
            AllyUnits.Add(visibleBehavior);
        }
        else
        {
            EnemyUnits.Add(visibleBehavior);
            visibleBehavior.ToggleUnitVisibility(false);
        }
    }
Exemple #6
0
 internal void setSpotting(VisibleBehavior enemy, bool p)
 {
     if (enemy == this)
     {
         Debug.LogError("error");
     }
     if (p && !spotting[enemy])
     {
         spotting[enemy] = true;
     }
     else
     {
         spotting[enemy] = false;
     }
 }
Exemple #7
0
    public static void addVisibleBehaviour(VisibleBehavior b)
    {
        var members = getTeamMembers(b.team);

        if (!members.Contains(b))
        {
            members.Add(b);
        }
        var t = Team.Blue;

        if (t == b.team)
        {
            t = Team.Red;
        }
        getTeamMembers(t).ForEach(x => x.addHostile(b));
    }
Exemple #8
0
    public void RegisterUnitDeath(UnitBehaviour unit)
    {
        VisibleBehavior visibleBehavior = unit.VisibleBehavior;

        if (visibleBehavior == null)
        {
            return;
        }


        if (unit.Platoon.Owner.Team == LocalTeam)
        {
            AllyUnits.Remove(visibleBehavior);
        }
        else
        {
            EnemyUnits.Remove(visibleBehavior);
        }
    }
Exemple #9
0
 internal void setSpottedBy(VisibleBehavior unit, bool p)
 {
     if (p && !spottedBy[unit])
     {
         if (spottedByCount == 0)
         {
             setDetected(true);
         }
         spottedByCount += 1;
         spottedBy[unit] = true;;
     }
     if (!p && spottedBy[unit])
     {
         spottedByCount -= 1;
         if (spottedByCount == 0)
         {
             setDetected(false);
         }
         spottedBy[unit] = false;
     }
 }
Exemple #10
0
 public static void UpdateUnitRegion(VisibleBehavior unit, Point newRegion)
 {
     //var currentPoint = unit.GetRegion();
 }
Exemple #11
0
    private bool CanDetect(VisibleBehavior target)
    {
        float distance = Vector3.Distance(_gameObject.transform.position, target._gameObject.transform.position);

        return(distance < max_spot_range && distance < max_spot_range * stealth_pen_factor / target.stealth_factor);
    }