Exemple #1
0
        private const float MinDist = 0.05f; //0.05f

        //False if countinue moving
        private static bool DoMove(UnitOrder order)
        {
            var ent    = order.GetUnit();
            var moveTo = order.GetTo();

            if (ent == null)
            {
                return(true);
            }
            var vec = ((moveTo.Pos3D + ent.ExtraPos) - ent.transform.position);

            //var idealVec = (moveTo.Pos3D - Util.Get3DPosByIndex(ent.CurrentPos)).normalized;


            if (Mathf.Abs(vec.x) <= MinDist && Mathf.Abs(vec.y) <= MinDist)
            {
                ent.transform.position = moveTo.Pos3D + ent.ExtraPos;
                ent.MovingTo           = null;

                var upperIndexFrom = ent.CurrentPos;
                var upperIndexTo   = ChunkUtil.GetUpper(moveTo.Index);

                var chunk = ChunkManager.GetChunkByNum(ent.ChunkNumber);

                chunk.MoveFromTo(upperIndexFrom, upperIndexTo);

                ent.CurrentPos = upperIndexTo;



                if (upperIndexFrom != upperIndexTo)
                {
                    PathCalcManager.CalculatePoint(upperIndexFrom);
                }


                GameOrderManager.RemoveMark(ent, moveTo.Index);

                return(true);
            }
            if (ChunkUtil.GetDovvner(ent.CurrentPos) != order.GetTo().Index&&
                PathFind.IsInvalidPath(order.GetTo().Index))
            {
                SimpleOrderManager.CancelOrders(ent);
            }

            ent.State    = EventManager.InProgressEvents.Move;
            ent.MovingTo = moveTo;
            var speedMod  = GameMoveManager.StaticMoveSpeed;
            var moveSpeed = ent.EntStats.MoveSpeed;

            var modVec = MultVector(vec, new Vector3(speedMod, speedMod, 1f));

            var speedVec =
                MultVector(modVec, new Vector3(moveSpeed, moveSpeed, 1f))
                // vec * speedMod
                * Time.deltaTime;

            if (Mathf.Abs(vec.x) <= MinDist * 3 && Mathf.Abs(vec.y) <= MinDist * 3)
            {
                speedVec *= 3;
            }


            ent.transform.Translate(speedVec);
            return(false);
        }
Exemple #2
0
        public override void KillSelf()
        {
            if (Destroyed)
            {
                return;
            }
            var chunk = ChunkManager.GetChunkByNum(ChunkNumber);

            chunk.SetIndex(CurrentPos, -1);
            chunk.RemoveObject(CurrentPos);

            if (pickUped != null)
            {
                ItemEvents.OnDeathDropItem(pickUped, this);
            }

            ClickManager.RemoveChosing(gameObject);

            GameMoveManager.CancelAllOrders(this);
            if (GroupUtil.isCreatureGroup(Group))
            {
                GameOrderManager.RemoveMarks(this);
                //SimpleOrderManager.CancelOrders(this);
                if (MovingPath != null)
                {
                    MovingPath.Clear();
                }
            }

            if (SecondaryGroundLvL.isSecondaryGroup(Group))
            {
                SecondaryGroundLvL.RemovePos(ChunkNumber, CurrentPos);
            }

            if (FlagManager.IsFlagAtPos(CurrentPos))
            {
                FlagManager.RemoveFlag(CurrentPos);
            }

            ProgressUnitBar.RemoveProgressBar(this);
            CreatureGroupManager.RemoveEntFromGroup(this);
            BuildingsGroupManager.RemoveBuildingFromGroup(this);

            RemoveAbilities();

            if (research != null)
            {
                var sameBuilds = BuildingsGroupManager.GetAllInChunkWithName(ChunkNumber, OriginalName);
                if (sameBuilds.Count == 0)
                {
                    Owner.RemoveResearch(research);
                }
            }
            Coloring.RecolorObject(ChunkUtil.GetDovvner(CurrentPos));
            Owner.foodCount -= foodCost;
            Owner.foodMax   -= foodGive;

            if (gameObject != null)
            {
                Destroy(gameObject);
            }


            Destroyed = true;
        }