Exemple #1
0
 public void addWaypoint(long time, Path path)
 {
     if (Sim.enableNonLivePaths && type.speed > 0) {
         if (!new SegmentUnit(path.segmentWhen(time), this).canBeUnambiguousParent(time)) time++;
         Tile tile = path.tileWhen (time);
         if (!Waypoint.active (tile.waypointLatest (this))) {
             List<UnitSelection> start = new List<UnitSelection> { new UnitSelection(path, this, time) };
             SegmentUnit prev = start[0].segmentUnit();
             do {
                 // remember segments that unit was previously on in case unit is later removed from them
                 SegmentUnit cur = prev;
                 prev = cur.prev ().FirstOrDefault ();
                 if (prev.g == null || prev.segment.path != cur.segment.path || !prev.segment.unseen) {
                     start.Add (new UnitSelection(cur.segment.path, this, cur.segment.timeStart));
                 }
             } while (prev.g != null && prev.segment.unseen);
             g.events.addEvt (new WaypointAddEvt(time + (tile.centerPos() - path.posWhen(time)).length () / type.speed,
                 this, tile, null, start));
         }
     }
 }
Exemple #2
0
 // methods above involve commanding selected units
 /// <summary>
 /// sets pos to where base of path should be drawn at, and returns whether it should be drawn
 /// </summary>
 private bool pathDrawPos(Path path, ref Vector3 pos)
 {
     if (g.timeGame < path.moves[0].timeStart) return false;
     if (selPlayer != path.player) {
         if (path.timeSimPast != long.MaxValue) return false;
         if (!path.tileWhen (g.timeGame).playerVisWhen(selPlayer, g.timeGame)) return false;
     }
     pos = simToDrawPos(path.posWhen(g.timeGame), unitDepth);
     return true;
 }
Exemple #3
0
 /// <summary>
 /// returns where new unit of specified type can move out of the way after specified path makes it
 /// </summary>
 /// <remarks>chooses a random location between makeUnitMinDist and makeUnitMaxDist away from path</remarks>
 private FP.Vector makeUnitMovePos(long time, Path path, UnitType type)
 {
     FP.Vector ret;
     do {
         ret = new FP.Vector((long)((UnityEngine.Random.value - 0.5) * type.makeUnitMaxDist * 2),
             (long)((UnityEngine.Random.value - 0.5) * type.makeUnitMaxDist * 2));
     } while (ret.lengthSq() < type.makeUnitMinDist * type.makeUnitMinDist
         || ret.lengthSq() > type.makeUnitMaxDist * type.makeUnitMaxDist);
     return ret + path.posWhen(time);
 }
Exemple #4
0
 /// <summary>
 /// returns where new path with specified units can move out of the way after specified path makes it
 /// </summary>
 /// <remarks>chooses a random location between makePathMinDist() and makePathMaxDist() away from path</remarks>
 private FP.Vector makePathMovePos(long time, Path path, List<Unit> units)
 {
     long makePathMinDist = path.makePathMinDist (time, units);
     long makePathMaxDist = path.makePathMaxDist (time, units);
     FP.Vector ret;
     do {
         ret = new FP.Vector((long)((UnityEngine.Random.value - 0.5) * makePathMaxDist * 2),
             (long)((UnityEngine.Random.value - 0.5) * makePathMaxDist * 2));
     } while (ret.lengthSq() < makePathMinDist * makePathMinDist
         || ret.lengthSq() > makePathMaxDist * makePathMaxDist);
     return ret + path.posWhen(time);
 }