Exemple #1
0
    public void Launch(BaseUnitInfo unit, List <CarriedUnit> unitsToLaunch, GameConstants.UnitOrderType unitOrderType, Coordinate coord)
    {
        if (unit != null)
        {
            UnitOrder order = new UnitOrder(unitOrderType, unit.Id);

            StringBuilder sb = new StringBuilder();
            sb.AppendLine("Launcing Aircrafts:");

            foreach (CarriedUnit cui in unitsToLaunch)
            {
                order.ParameterList.Add(cui.UnitInfo.Id);
                sb.AppendLine(cui.UnitInfo.Id);
            }

            UnitMovementOrder moveOrder = new UnitMovementOrder();
            moveOrder.Waypoints.Add(new WaypointInfo(new PositionInfo(coord.Latitude, coord.Longitude)));
            order.UnitOrders.Add(moveOrder);



            GameManager.Instance.MessageManager.AddMessage(sb.ToString(), GameManager.MessageTypes.Game, unit.Position);

            GameManager.Instance.NetworkManager.Send(order);
        }
    }
Exemple #2
0
        private void CancelOrder(GameUnit unit, UnitOrder order)
        {
            var list = CanceledOrderList.ContainsKey(unit) ? CanceledOrderList[unit] : new List <UnitOrder>();

            list.Add(order);
            CanceledOrderList.Add(unit, list);
        }
Exemple #3
0
        public static UnitOrder CreateSetElevationOrder(string unitId, GameConstants.HeightDepthPoints heightDepth)
        {
            UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.SetElevation, unitId);

            order.HeightDepthPoints = heightDepth;
            return(order);
        }
Exemple #4
0
    void Update()
    {
        if (coolDownTimer > 0)
        {
            coolDownTimer -= Time.deltaTime;
            return;
        }
        if (!isReady || orders.Count < 1)
        {
            return;
        }

        UnitOrder   order          = orders[0];
        GameObject  newUnit        = gameManager.UnitFactory.CreateUnit(order.unitType, spawnPoint.position, spawnPoint.rotation);
        UnitControl newUnitControl = newUnit.GetComponent <UnitControl>();

        order.owner.AddUnit(newUnitControl);
        newUnitControl.TeamName = order.owner.tag;
        newUnitControl.UnitType = order.unitType;
        newUnitControl.Cluster  = order.owner;
        newUnit.name            = order.owner.tag + "-" + order.unitType;
        newUnit.layer           = LayerMask.NameToLayer(order.owner.tag);
        newUnit.GetComponent <UnitBrain>().MoveTo(order.owner.transform.position);
        order.amount--;
        coolDownTimer = coolDown;
        if (order.amount <= 0)
        {
            orders.Remove(order);
        }
    }
Exemple #5
0
        public Unit(SC2APIProtocol.Unit unit)
        {
            this.original     = unit;
            this.unitTypeData = ControllerDefault.gameData.Units[(int)unit.UnitType];

            this.name            = unitTypeData.Name;
            this.tag             = unit.Tag;
            this.unitType        = unit.UnitType;
            this.position        = new Vector3(unit.Pos.X, unit.Pos.Y, unit.Pos.Z);
            this.integrity       = (unit.Health + unit.Shield) / (unit.HealthMax + unit.ShieldMax);
            this.buildProgress   = unit.BuildProgress;
            this.idealWorkers    = unit.IdealHarvesters;
            this.assignedWorkers = unit.AssignedHarvesters;

            this.order     = unit.Orders.Count > 0 ? unit.Orders[0] : new UnitOrder();
            this.orders    = unit.Orders;
            this.isVisible = (unit.DisplayType == DisplayType.Visible);

            this.supply = (int)unitTypeData.FoodRequired;

            this.vespene  = unit.VespeneContents;
            this.minerals = unit.MineralContents;
            this.sight    = this.unitTypeData.SightRange;
            this.target   = unit.EngagedTargetTag;
        }
Exemple #6
0
        public static UnitOrder CreateSetBaseOrder(string unitId, string returnToUnitId)
        {
            UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.ReturnToBase, unitId);

            order.SecondId = returnToUnitId;
            return(order);
        }
Exemple #7
0
        public virtual void StartSkillCasting()
        {
            startAiming = false;
            if (targetPosition == null)
            {
                targetPosition = transform.position;
            }
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, Mathf.Infinity))
            {
                targetPosition = hit.point;
                targetPosition = new Vector3(targetPosition.x, owner.transform.position.y, targetPosition.z);
            }
            transform.position = targetPosition;

            if (spawnType == SpawnSkillType.FromCaster)
            {
                Debug.Log("FROM CASTER!");
                transform.position = new Vector3(owner.transform.position.x, owner.transform.position.y, owner.transform.position.z);
                activate           = true;
            }
            else
            {
                activate = true;
            }
            owner.ReceiveOrder(UnitOrder.GenerateIdleOrder(), true);
            owner.MakeUnitLookAt(targetPosition);
            transform.rotation = owner.transform.rotation;
        }
Exemple #8
0
        public static UnitOrder CreateRefuelInAirOrder(string unitId, string refuelingUnitId)
        {
            UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.RefuelInAir, unitId);

            order.SecondId = refuelingUnitId;
            return(order);
        }
        private static Unit CreateAndDeployUnit(Random seededRand, EncounterState state, FactionName faction,
                                                Lane lane, int lanePosition, UnitOrder order, FormationType type, FormationFacing facing, int size,
                                                Func <int, Unit, Entity> entityFn, CommanderAIComponent commanderAI)
        {
            var center = lane.PositionFor(facing, lanePosition);
            var unit   = new Unit(Guid.NewGuid().ToString(), faction, center, order, type, facing);

            state.AddUnit(unit);
            commanderAI.RegisterUnit(unit);
            lane.RegisterUnitAtPosition(unit, lanePosition);

            var width = (int)Math.Ceiling(Math.Sqrt(size));

            List <EncounterPosition> positions = new List <EncounterPosition>();

            for (int x = 0 - width; x < width; x++)
            {
                for (int y = 0 - width; y < width; y++)
                {
                    positions.Add(new EncounterPosition(x, y));
                }
            }
            GameUtils.Shuffle(seededRand, positions);

            for (int i = 0; i < size; i++)
            {
                var entity = entityFn(i, unit);
                state.PlaceEntity(entity, new EncounterPosition(center.X + positions[i].X, center.Y + positions[i].Y));
                unit.RegisterBattleReadyEntity(entity);
            }

            return(unit);
        }
Exemple #10
0
        public static UnitOrder CreateNewGroupFormationOrder(string unitId, Formation formation)
        {
            UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.SetNewGroupFormation, unitId);

            order.Formation = formation;
            return(order);
        }
Exemple #11
0
        public static UnitOrder CreateSetUnitFormationOrder(string unitId, string formationPositionId)
        {
            UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.SetUnitFormationOrder, unitId);

            order.SecondId = formationPositionId;
            return(order);
        }
Exemple #12
0
        public static UnitOrder CreateSetSpeedOrder(string unitId, GameConstants.UnitSpeedType unitSpeedType)
        {
            UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.SetSpeed, unitId);

            order.UnitSpeedType = unitSpeedType;
            return(order);
        }
Exemple #13
0
        public static UnitOrder CreateAcquireNewUnitOrder(string carrierId, string unitClassId, string weaponLoadName)
        {
            UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.AcquireNewUnit, carrierId);

            order.SecondId        = unitClassId;
            order.StringParameter = weaponLoadName;
            return(order);
        }
Exemple #14
0
        public static UnitOrder CreateAcquireAmmoOrder(string platformId, string weaponClassId, int count)
        {
            UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.AcquireAmmo, platformId);

            order.SecondId       = weaponClassId;
            order.ValueParameter = count;
            return(order);
        }
Exemple #15
0
        public static UnitOrder CreateSetSpeedOrder(string unitId, GameConstants.UnitSpeedType unitSpeedType, bool isGroupOrder)
        {
            UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.SetSpeed, unitId);

            order.UnitSpeedType = unitSpeedType;
            order.IsParameter   = isGroupOrder;
            return(order);
        }
Exemple #16
0
        public List <string> AllowedActions(EncounterState state, Entity parent, UnitOrder standingOrder)
        {
            var parentPos       = parent.GetComponent <PositionComponent>().EncounterPosition;
            var unit            = state.GetUnit(parent.GetComponent <UnitComponent>().UnitId);
            var actions         = new List <string>();
            var parentIsLagging = AIUtils.IsPositionTooFarBehind(parentPos, unit);

            // TODO: this is a silly place to run this check
            if (parentIsLagging)
            {
                parent.GetComponent <AIRotationComponent>().NotifyRotationCompleted();
            }

            if (standingOrder == UnitOrder.ADVANCE && !parent.GetComponent <AIRotationComponent>().IsRotating)
            {
                // Directly ahead pos available if not too far ahead OR if too far behind
                var validAheadPositions = new List <EncounterPosition>()
                {
                    AIUtils.RotateAndProject(parentPos, 0, -1, unit.UnitFacing),
                    AIUtils.RotateAndProject(parentPos, 1, -1, unit.UnitFacing),
                    AIUtils.RotateAndProject(parentPos, -1, -1, unit.UnitFacing),
                };
                foreach (var possible in validAheadPositions)
                {
                    if (positionNotTooFarAheadAndMovable(state, parentPos, unit, possible) || parentIsLagging)
                    {
                        actions.Add(ToCardinalDirection(parentPos, possible));
                    }
                }

                // Flank positions available if not too far ahead AND not too far behind
                var validFlankPositions = new List <EncounterPosition>()
                {
                    AIUtils.RotateAndProject(parentPos, 1, 0, unit.UnitFacing),
                    AIUtils.RotateAndProject(parentPos, -1, 0, unit.UnitFacing),
                };
                foreach (var possible in validFlankPositions)
                {
                    if (positionNotTooFarAheadAndMovable(state, parentPos, unit, possible) && !parentIsLagging)
                    {
                        actions.Add(ToCardinalDirection(parentPos, possible));
                    }
                }

                if (parent.GetComponent <AIRotationComponent>().BackSecure(state, parent, unit))
                {
                    actions.Add(InputHandler.ActionMapping.ROTATE);
                }
            }

            if (!parentIsLagging)
            {
                actions.Add(InputHandler.ActionMapping.WAIT);
            }
            actions.Add(InputHandler.ActionMapping.LEAVE_FORMATION);

            return(actions);
        }
Exemple #17
0
        public static UnitOrder CreateSensorActivationOrder(string unitId, string sensorId, bool isActive)
        {
            UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.SensorActivationOrder, unitId);

            order.SecondId    = sensorId;
            order.IsParameter = isActive;

            return(order);
        }
Exemple #18
0
        public static UnitOrder CreateChangeAircraftLoadoutOrder(string carrierUnitId,
                                                                 string aircraftUnitId,
                                                                 string weaponLoadoutName)
        {
            UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.ChangeAircraftLoadout, carrierUnitId);

            order.SecondId        = aircraftUnitId;
            order.StringParameter = weaponLoadoutName;
            return(order);
        }
Exemple #19
0
        public static UnitOrder CreateRadarDistortionOrder(string unitId, PositionInfo position)
        {
            UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.SpecialOrders, unitId);

            order.SpecialOrder = GameConstants.SpecialOrders.JammerRadarDistortion;
            if (position != null)
            {
                order.Position = position;
            }
            return(order);
        }
Exemple #20
0
        public static UnitOrder CreateChangeAircraftLoadoutOrder(string carrierUnitId,
                                                                 string aircraftUnitId, GameConstants.WeaponLoadType weaponLoadType, GameConstants.WeaponLoadModifier weaponLoadModifier)
        {
            UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.ChangeAircraftLoadout, carrierUnitId);

            order.SecondId           = aircraftUnitId;
            order.StringParameter    = string.Empty;
            order.WeaponLoadType     = weaponLoadType;
            order.WeaponLoadModifier = weaponLoadModifier;
            return(order);
        }
Exemple #21
0
        public static UnitOrder CreateCommunicationDegradationJammingOrder(string unitId, PositionInfo position)
        {
            UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.SpecialOrders, unitId);

            order.SpecialOrder = GameConstants.SpecialOrders.JammerCommunicationDegradation;
            if (position != null)
            {
                order.Position = position;
            }
            return(order);
        }
Exemple #22
0
 public Order(UnitOrder originalOrder)
 {
     ability   = originalOrder.AbilityId;
     progress  = originalOrder.Progress;
     targetTag = originalOrder.TargetUnitTag;
     if (originalOrder.TargetWorldSpacePos != null)
     {
         targetPosition.X = originalOrder.TargetWorldSpacePos.X;
         targetPosition.Y = originalOrder.TargetWorldSpacePos.Y;
         targetPosition.Z = originalOrder.TargetWorldSpacePos.Z;
     }
 }
Exemple #23
0
    public void ChangeLoadOut(BaseUnitInfo carrier, CarriedUnitInfo carriedUnit, string loadOutName)
    {
        UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.ChangeAircraftLoadout, carrier.Id);

        order.SecondId        = carriedUnit.Id;
        order.StringParamater = loadOutName;

        GameManager.Instance.MessageManager.AddMessage(string.Format(
                                                           "Changing loadout for {0} to {1}", carriedUnit.UnitName, loadOutName), GameManager.MessageTypes.Game, carrier.Position);

        GameManager.Instance.NetworkManager.Send(order);
    }
Exemple #24
0
    public void Launch(BaseUnitInfo unit, CarriedUnitInfo unitToLaunch, GameConstants.UnitOrderType unitOrderType)
    {
        if (unit != null)
        {
            UnitOrder order = new UnitOrder(unitOrderType, unit.Id);
            order.ParameterList.Add(unitToLaunch.Id);
            GameManager.Instance.MessageManager.AddMessage(string.Format(
                                                               "Launching aircraft: {0}", unit.UnitName), GameManager.MessageTypes.Game, unit.Position);

            GameManager.Instance.NetworkManager.Send(order);
        }
    }
Exemple #25
0
        public static UnitOrder CreateAircraftLaunchOrder(string unitId,
                                                          List <string> aircraftList, UnitMovementOrder moveOrder)
        {
            UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.LaunchAircraft, unitId);

            foreach (var id in aircraftList)
            {
                order.ParameterList.Add(id);
            }
            order.UnitOrders.Add(moveOrder);
            return(order);
        }
Exemple #26
0
 public override void EndIndividualInteraction(UnitBaseBehaviourComponent unit)
 {
     if (gathererStats.Contains(gathererStats.Find(x => x.unitSaved == unit)))
     {
         gathererStats.Remove(gathererStats.Find(x => x.unitSaved == unit));
         interactingUnit.Remove(unit);
         if (unit.interactWith == this)
         {
             unit.ReceiveOrder(UnitOrder.GenerateIdleOrder());
         }
     }
 }
Exemple #27
0
        public static UnitOrder CreateMineDeploymentOrder(string unitId, PositionInfo position, bool deployAllMines)
        {
            UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.SpecialOrders, unitId);

            order.SpecialOrder = GameConstants.SpecialOrders.DropMine;
            if (position != null)
            {
                order.Position = position;
            }
            order.IsParameter = deployAllMines;
            return(order);
        }
Exemple #28
0
        /// <summary>
        /// Creates an order to split one or more units from an existing group, forming a new group. Order can be
        /// sent to any member of the existing group. This unit will only be split from the group if it is
        /// explicitly listed in the unitIds parameter list.
        /// </summary>
        /// <param name="unitId"></param>
        /// <param name="groupId"></param>
        /// <param name="unitIds"></param>
        /// <returns></returns>
        public static UnitOrder CreateSplitGroupOrder(string unitId, List <string> unitIds)
        {
            UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.SplitGroup, unitId);

            if (unitIds != null && unitIds.Count > 0)
            {
                foreach (var uId in unitIds)
                {
                    order.ParameterList.Add(uId);
                }
            }
            return(order);
        }
Exemple #29
0
        public static UnitOrder CreateSonobuoyDeploymentOrder(string unitId, PositionInfo position, bool isActive, double radiusM)
        {
            UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.SpecialOrders, unitId);

            order.SpecialOrder = GameConstants.SpecialOrders.DropSonobuoy;
            if (position != null)
            {
                order.Position = position;
            }
            order.IsParameter    = isActive;
            order.ValueParameter = 1.0;
            order.RadiusM        = radiusM; //note: if RadiusM is > 0, order is interpreted as a "drop all sonobouys you have in this area"
            return(order);
        }
Exemple #30
0
        public static UnitOrder CreateSonobuoyDeploymentOrder(string unitId, PositionInfo position, bool isActive, bool isIntermediateDepth)
        {
            UnitOrder order = new UnitOrder(GameConstants.UnitOrderType.SpecialOrders, unitId);

            order.SpecialOrder = GameConstants.SpecialOrders.DropSonobuoy;
            if (position != null)
            {
                order.Position = position;
            }
            order.IsParameter    = isActive;
            order.ValueParameter = isIntermediateDepth ? 1.0 : 0.0;

            return(order);
        }
Exemple #31
0
 public Unit(float x, float y, string sprite, bool useAI)
 {
     X = x;
     Y = y;
     Graphic = new Image(sprite);
     IssuedOrder = UnitOrder.Wander;
     ControlledByAI = useAI;
     UnitManager.Units.Add(this);
     MovementManager.AddUnitToUnitMap(this);
     Health = 100;
     HealthMax = 100;
     RegenerationRate = 0.3f;
     if (useAI)
     {
         HealthBar = new Text(Health.ToString(), 10);
         HealthBar.OutlineThickness = 2;
         HealthBar.OutlineColor = Color.Black;
         HealthBar.Color = Color.Red;
         HealthBar.Y = -16;
         HealthBar.X = 0;
         Graphics.Add(HealthBar);
     }
 }
Exemple #32
0
 public void ProceedTurn(dynamic arg)
 {
     switch (IssuedOrder)
     {
         case UnitOrder.Chase:
             Chase();
             break;
         case UnitOrder.Wander:
             Wander();
             break;
         case UnitOrder.Attack:
             Attack(arg);
             break;
         case UnitOrder.Move:
             Move(arg);
             break;
         default:
             break;
     }
     ProceedAI();
     HealthBar.String = Convert.ToInt32(Health).ToString();
     Regenerate();
     if (this is Hero)
         IssuedOrder = UnitOrder.Idle;
 }
Exemple #33
0
 public void IssueOrder(UnitOrder unitOrder, dynamic arg)
 {
     IssuedOrder = unitOrder;
     OrderTarget = arg;
 }