Beispiel #1
0
        public PathFinderTask(int playerIndex, long unitId, long targetId, MapRoot map, int mapSize, VoxelData controlledData, Coordinate coordinate, VoxelAbilities ablilities, Coordinate[] waypoints, PathMatrixPool[] pools, Action <long, Coordinate[]> callback, Action <long> terminateCallback)
        {
            m_waypoints         = waypoints;
            m_callback          = callback;
            m_terminateCallback = terminateCallback;

            m_playerIndex = playerIndex;
            m_unitId      = unitId;
            m_targetId    = targetId;

            Map                         = map;
            MapSize                     = mapSize;
            m_controlledData            = new VoxelData(controlledData);
            m_controlledData.Unit.State = VoxelDataState.Idle;
            m_coordinate                = coordinate;
            m_abilities                 = new VoxelAbilities(ablilities);

            m_matrixPool = pools[m_controlledData.Weight - ablilities.MinWeight];
            m_hopsMatrix = m_matrixPool.Acquire();
            m_hopsMatrix[m_coordinate.Row, m_coordinate.Col] = 0;

            ClosestToGoal = m_coordinate;
            m_dataQueue   = new Queue <Data>();
            m_dataQueue.Enqueue(new Data(m_coordinate, 0));
        }
        private void CreateAsset(VoxelData voxelData, VoxelAbilities abilities, MapCell cell)
        {
            if (voxelData.IsNeutral)
            {
                return;
            }

            voxelData.UnitOrAssetIndex = m_identity;
            MatchAssetCli asset = new MatchAssetCli(voxelData, abilities, cell);

            m_voxelDataToId.Add(voxelData, m_identity);
            m_idToAsset.Add(m_identity, asset);

            unchecked
            {
                m_identity++;
            }

            if (voxelData.Weight >= GameConstants.MinVoxelActorWeight)
            {
                Coordinate coordinate = new Coordinate(cell, voxelData);
                int        radius     = abilities.VisionRadius;
                m_voxelMap.Map.ForEachInRadius(coordinate, radius, (observedCell, pos) =>
                {
                    ObserveCell(asset.VoxelData.Owner, observedCell, pos, coordinate.Weight);
                });

                m_minimap.Spawn(voxelData, new Coordinate(cell, voxelData));
            }

            if (AssetCreated != null)
            {
                AssetCreated(asset);
            }
        }
Beispiel #3
0
        private void ExecuteEatCommand(long tick, EatCmd eatCmd)
        {
            Voxel eater = eatCmd.Eater.VoxelRef;

            if (eater == null || !eater.IsAcquired)
            {
                if (eatCmd.Voxel.VoxelRef != null)
                {
                    eatCmd.Voxel.VoxelRef.Kill();
                }
                return;
            }

            int   deltaHealth = eatCmd.EaterDeltaHealth;
            Voxel voxel       = eatCmd.Voxel.VoxelRef; //this change may break eat process. Possible that VoxelRef set to null previously

            if (voxel == null)
            {
                Debug.Assert(deltaHealth == 0);
                //if deltaHealth > 0 set texture directly
                return;
            }

            if (!voxel.IsAcquired)
            {
                Debug.Assert(deltaHealth == 0);
                //if deltaHealth > 0 set texture directly
                return;
            }

            if (deltaHealth == 0)
            {
                VoxelAbilities abilities = m_dataController.AllAbilities[eater.Owner][eater.Type];
                voxel.Smash(abilities.MovementDuration * GameConstants.MatchEngineTick / 3, eatCmd.VoxelHealth);
            }
            else if (deltaHealth == 1)
            {
                if (voxel.Type == (int)KnownVoxelTypes.Eater)
                {
                    SplitAndEat(tick, eater, deltaHealth, voxel);
                }
                else
                {
                    eater.BeginEat(voxel, tick);
                }
            }
            else if (deltaHealth > 1 && deltaHealth <= 8)
            {
                SplitAndEat(tick, eater, deltaHealth, voxel);
            }
            else
            {
                throw new NotImplementedException("deltaHealth " + deltaHealth);
            }
        }
        private VoxelAbilities[] CreateDefaultAbilities()
        {
            List <VoxelAbilities> abilities = new List <VoxelAbilities>();
            Array voxelTypes = Enum.GetValues(typeof(KnownVoxelTypes));

            for (int typeIndex = 0; typeIndex < voxelTypes.Length; ++typeIndex)
            {
                VoxelAbilities ability = new VoxelAbilities((int)voxelTypes.GetValue(typeIndex));
                abilities.Add(ability);
            }
            return(abilities.ToArray());
        }
        public MatchAssetCli(VoxelData data, VoxelAbilities abilities, MapCell cell)
        {
            m_voxelData = data;
            m_abilities = abilities;
            m_cell      = cell;
            m_pos       = cell.GetPosition();

            if (m_voxelData.VoxelRef != null)
            {
                m_voxel = m_voxelData.VoxelRef;
            }
            m_voxelData.VoxelRefSet   += OnVoxelRefSet;
            m_voxelData.VoxelRefReset += OnVoxelRefReset;
        }
        private void OnSelected(object sender, System.EventArgs e)
        {
            if (m_selectedPrefab != null)
            {
                m_selectedPrefab.IsSelected = false;
            }
            m_selectedPrefab    = (MapEditorPrefab)sender;
            m_selectedAbilities = new VoxelAbilities(m_selectedPrefab.Prefab.Type);

            SetupTools();

            BrushHeight = m_selectedAbilities.MinHeight;
            BrushWeight = m_selectedAbilities.MinWeight;
        }
Beispiel #7
0
        private void SplitAndEat(long tick, Voxel eater, int deltaHealth, Voxel voxel)
        {
            Debug.Assert(voxel.Weight > 0);

            int     weight   = voxel.Weight;
            int     owner    = voxel.Owner;
            Vector3 position = voxel.transform.position;

            m_voxelFactory.Release(voxel);

            for (int i = 0; i < deltaHealth; i++)
            {
                Voxel part = m_voxelFactory.Acquire((int)KnownVoxelTypes.Eatable);

                VoxelAbilities abilities = m_dataController.AllAbilities[m_dataController.PlayerIndex][part.Type];

                part.Owner  = owner;
                part.Weight = weight - 1;
                part.Height = abilities.EvaluateHeight(part.Weight);

                float voxelSideSize = Mathf.Pow(2, weight) * GameConstants.UnitSize;

                Vector3 partPostion = position;

                int   imod4   = i % 4;
                int   imod2   = i % 2;
                float vssDiv4 = voxelSideSize / 4.0f;
                float vssDiv2 = voxelSideSize / 2.0f;
                bool  bx      = (imod4 == 0 || imod4 == 1);
                bool  bz      = (imod2 == 1);
                partPostion.x += bx ? -vssDiv4 : vssDiv4;
                partPostion.z += bz ? -vssDiv4 : vssDiv4;
                partPostion.y += i < 4 ? 0 : vssDiv2; // (bx || !bz) && (!bx || bz) ? 0 : vssDiv2;

                part.transform.position = partPostion;

                eater.BeginEat(part, tick);
            }
        }
        public VoxelAbilities(VoxelAbilities abilities)
        {
            Type = abilities.Type;

            CanMove = abilities.CanMove;

            MaxJumpHeight = abilities.MaxJumpHeight;
            MaxFallHeight = abilities.MaxFallHeight;
            JumpDuration  = abilities.JumpDuration;
            //FallDuration = abilities.FallDuration;

            MinMoveDistance     = abilities.MinMoveDistance;
            MaxMoveDistance     = abilities.MaxMoveDistance;
            MovementDuration    = abilities.MovementDuration;
            RotationDuration    = abilities.RotationDuration;
            SplitDuration       = abilities.SplitDuration;
            GrowDuration        = abilities.GrowDuration;
            DiminishDuration    = abilities.DiminishDuration;
            ActionInterval      = abilities.ActionInterval;
            TargetCheckInterval = abilities.TargetCheckInterval;

            SplitDelay    = abilities.SplitDelay;
            GrowDelay     = abilities.GrowDelay;
            DiminishDelay = abilities.DiminishDelay;
            ConvertDelay  = abilities.ConvertDelay;

            MinWeight = abilities.MinWeight;
            MaxWeight = abilities.MaxWeight;

            MinHealth     = abilities.MinHealth;
            MaxHealth     = abilities.MaxHealth;
            DefaultHealth = abilities.DefaultHealth;

            MinHeight      = abilities.MinHeight;
            MaxHeight      = abilities.MaxHeight;
            VariableHeight = abilities.VariableHeight;

            VisionRadius = abilities.VisionRadius;
        }
        private void Start()
        {
            GetDependencies();

            Voxel[] prefabs = m_factory.GetPrefabs();
            for (int i = 0; i < prefabs.Length; ++i)
            {
                MapEditorPrefab mapEditorPrefab = Instantiate(m_mapEditorPrefab);
                mapEditorPrefab.Prefab = prefabs[i];
                mapEditorPrefab.transform.SetParent(m_prefabPanel);
                if (prefabs[i].Type == (int)KnownVoxelTypes.Ground)
                {
                    VoxelAbilities abilities = new VoxelAbilities(prefabs[i].Type);

                    mapEditorPrefab.IsSelected         = true;
                    mapEditorPrefab.AllowHeightEditing = true;
                    m_selectedPrefab    = mapEditorPrefab;
                    m_selectedAbilities = abilities;

                    BrushHeight = abilities.MinHeight;
                    BrushWeight = abilities.MinWeight;// m_selectedPrefab.Prefab.Weight;
                }

                m_mapEditorPrefabs.Add(mapEditorPrefab);
                mapEditorPrefab.Selected   += OnSelected;
                mapEditorPrefab.Unselected += OnUnselected;
            }

            //OnIsOpenedChanged(IsOpened);
            SetupTools();

            if (m_isOpened)
            {
                m_pivot.transform.position = Vector3.zero;
                OnTopView();
            }

            if (m_closeButton != null)
            {
                m_closeButton.onClick.AddListener(OnClose);
            }
            if (m_topViewButton != null)
            {
                m_topViewButton.onClick.AddListener(OnTopView);
            }
            if (m_brushSizeSlider != null)
            {
                m_brushSizeSlider.onValueChanged.AddListener(OnBrushSizeChanged);
            }
            if (m_brushWeightSlider != null)
            {
                m_brushWeightSlider.onValueChanged.AddListener(OnBrushWeightChanged);
            }
            if (m_brushHeightInput != null)
            {
                m_brushHeightInput.onValidateInput += OnBrushHeightValidateInput;
                m_brushHeightInput.onValueChanged.AddListener(OnBrushHeightChanged);
                m_brushHeightInput.onEndEdit.AddListener(OnBrushHeightEndEdit);
            }
            if (m_ownerInput != null)
            {
                m_ownerInput.onValidateInput += OnOwnerValidateInput;
                m_ownerInput.onValueChanged.AddListener(OnOwnerChanged);
            }
        }