Esempio n. 1
0
        void ControlPanelButton_Click( EButton sender )
        {
            int index = int.Parse( sender.Name.Substring( "ControlPanelButton".Length ) );

            TaskTargetChooseIndex = -1;

            List<RTSUnitAI.UserControlPanelTask> tasks = GetControlTasks();

            if( tasks == null || index >= tasks.Count )
                return;
            if( !tasks[ index ].Enable )
                return;

            RTSUnitAI.Task.Types taskType = tasks[ index ].Task.Type;

            switch( taskType )
            {
            //Stop, SelfDestroy
            case RTSUnitAI.Task.Types.Stop:
            case RTSUnitAI.Task.Types.SelfDestroy:
                foreach( Unit unit in selectedUnits )
                {
                    RTSUnitAI intellect = unit.Intellect as RTSUnitAI;
                    if( intellect == null )
                        continue;

                    if( IsEnableTaskTypeInTasks( intellect.GetControlPanelTasks(), taskType ) )
                        intellect.DoTask( new RTSUnitAI.Task( taskType ), false );
                }
                break;

            //ProductUnit
            case RTSUnitAI.Task.Types.ProductUnit:
                foreach( Unit unit in selectedUnits )
                {
                    RTSBuildingAI intellect = unit.Intellect as RTSBuildingAI;
                    if( intellect == null )
                        continue;

                    if( IsEnableTaskTypeInTasks( intellect.GetControlPanelTasks(), taskType ) )
                        intellect.DoTask( new RTSUnitAI.Task( taskType, tasks[ index ].Task.EntityType ), false );
                }
                break;

            //Move, Attack, Repair
            case RTSUnitAI.Task.Types.Move:
            case RTSUnitAI.Task.Types.Attack:
            case RTSUnitAI.Task.Types.Repair:
                //do taskTargetChoose
                TaskTargetChooseIndex = index;
                break;

            //BuildBuilding
            case RTSUnitAI.Task.Types.BuildBuilding:
                if( selectedUnits.Count == 1 )
                {
                    Unit unit = selectedUnits[ 0 ];
                    RTSUnitAI intellect = unit.Intellect as RTSUnitAI;
                    if( intellect != null )
                    {
                        //do taskTargetChoose
                        TaskTargetChooseIndex = index;

                        taskTargetBuildingType = (RTSBuildingType)tasks[ index ].Task.EntityType;

                        string meshName = null;
                        {
                            foreach( MapObjectTypeAttachedObject typeAttachedObject in
                                taskTargetBuildingType.AttachedObjects )
                            {
                                MapObjectTypeAttachedMesh typeMeshAttachedObject = typeAttachedObject as
                                    MapObjectTypeAttachedMesh;
                                if( typeMeshAttachedObject != null )
                                {
                                    meshName = typeMeshAttachedObject.MeshName;
                                    break;
                                }
                            }
                        }

                        taskTargetBuildMeshObject = SceneManager.Instance.CreateMeshObject( meshName );
                        taskTargetBuildSceneNode = new SceneNode();
                        taskTargetBuildSceneNode.Attach( taskTargetBuildMeshObject );
                        taskTargetBuildSceneNode.Visible = false;
                    }
                }
                break;

            }
        }
        // Build a depot
        private void BuildDepot()
        {
            if (builderAI != null)
            {
                taskTargetBuildingType = (RTSBuildingType)EntityTypes.Instance.GetByName("RTSDepot");

                string meshName = null;
                {
                    foreach (MapObjectTypeAttachedObject typeAttachedObject in
                        taskTargetBuildingType.AttachedObjects)
                    {
                        MapObjectTypeAttachedMesh typeMeshAttachedObject = typeAttachedObject as
                            MapObjectTypeAttachedMesh;
                        if (typeMeshAttachedObject != null)
                        {
                            meshName = typeMeshAttachedObject.MeshName;
                            break;
                        }
                    }
                }

                MeshObject taskTargetBuildMeshObject = SceneManager.Instance.CreateMeshObject(meshName);
                SceneNode taskTargetBuildSceneNode = new SceneNode();
                taskTargetBuildSceneNode.Attach(taskTargetBuildMeshObject);
                taskTargetBuildSceneNode.Visible = false;

                // Randomly generate positions within 25 units of the hive
                Random rand = new Random();
                Vec3 pos;
                do
                {
                    pos = new Vec3(hive.Position.X + ((float)rand.NextDouble() * 50f - 25f),
                        hive.Position.Y + ((float)rand.NextDouble() * 50f - 25f), hive.Position.Z);
                } while (!IsFreeForBuildTaskTargetBuild(pos));

                // Build the barracks
                builderAI.DoTask(new AntUnitAI.Task(AntUnitAI.Task.Types.BuildBuilding, pos,
                    (RTSBuildingType)EntityTypes.Instance.GetByName("RTSDepot")), false);

                GameEngineApp.Instance.ControlManager.PlaySound(
                    "Sounds\\Feedback\\RTSBuildBuilding.ogg");
            }
        }