Example #1
0
        public override void Draw()
        {
            if (timer_start_wait > 0)
            {
                return;
            }
            if (GameMain.GetInstance().is_shadowmap_draw)
            {
                return;
            }

            var t_max       = 50;
            var t_end_start = 200;
            var t_end_time  = 50;
            var t           = timer;
            var t2          = timer - t_max;

            if (t > t_max)
            {
                t = t_max;
            }
            if (t2 < 0)
            {
                t2 = 0;
            }
            var t3 = timer - t_end_start;

            if (t3 < 0)
            {
                t3 = 0;
            }
            if (t3 > t_end_time)
            {
                t3 = t_end_time;
            }
            var x = 100 + (t_max - t) * (t_max - t) * 0.5 + (t_max - t) * (t_max - t) * (t_max - t) * 0.3
                    - (t3 * t3 * 0.02 + t3 * t3 * t3 * 0.001);
            //if (x < 100) x = 100;
            var color_text       = DX.GetColor(255, 255, 255);
            var color_text_frame = DX.GetColor(80, 80, 80);
            var alpha            = 1.0;

            if (t3 > 0)
            {
                alpha = 1.0 - (double)t3 / (double)t_end_time;
            }
            DX.SetDrawBlendMode(DX.DX_BLENDMODE_ALPHA, (int)(alpha * 255));
            var text = "勝利条件";

            DX.DrawStringFToHandle((float)(x - t2 * 0.05), 120, text, color_text, font.GetHandle(), color_text_frame);

            text = "敵を全滅させろ";
            DX.DrawStringFToHandle((float)(x - t2 * 0.1), 190, text, color_text, font.GetHandle(), color_text_frame);
            DX.SetDrawBlendMode(DX.DX_BLENDMODE_NOBLEND, 0);
            //var x = ox;
            //var y = oy;
            //var text = damage_value.ToString();
            //var color_text = DX.GetColor(255, 255, 255);
            //var color_text_frame = DX.GetColor(255, 0, 0);

            //y += add_y;

            //var a_blend = 255;
            //if (timer < 50)
            //{
            //    a_blend = timer * 7;
            //}
            //else if (timer > 130)
            //{
            //    a_blend = 255 - (timer - 130) * 20;
            //}
            //if (a_blend > 255) a_blend = 255;
            //if (a_blend < 0) a_blend = 0;


            //var w = DX.GetDrawStringWidthToHandle(text, text.Count(), font_handle);

            //DX.SetDrawBlendMode(DX.DX_BLENDMODE_ALPHA, a_blend);
            //DX.DrawStringFToHandle(x - w / 2, y, text, color_text, font_handle, color_text_frame);
            //DX.SetDrawBlendMode(DX.DX_BLENDMODE_NOBLEND, 0);
        }
Example #2
0
        // 次の手番ユニットを決める
        public void NextUnitTurn()
        {
            // 旧手番ユニットのWTを調整しておく
            if (turn_owner_unit.unit_manager_status != null && turn_owner_unit.unit_manager_status.unit.bt.is_alive)
            {
                turn_owner_unit.unit_manager_status.unit.ResetWT();
            }

            var game_main    = GameMain.GetInstance();
            var unit_manager = game_main.unit_manager;

            // 戦闘不能を予定から確定にしておく(念のため)
            // 他の、行動効果の確定も個々でやったほうが良さそう
            foreach (var u in unit_manager.units)
            {
                if (u.unit.bt.is_reserve_dead)
                {
                    u.unit.SetAlive(false);
                }
            }


            if (unit_manager.active_units.Count() == 0)
            {
                while (unit_manager.active_units.Count() == 0)
                {
                    unit_manager.StepBattle();
                }
            }

            if (unit_manager.active_units.Count() > 0)
            {
                turn_owner_unit.unit_manager_status = unit_manager.active_units[0]; unit_manager.active_units.RemoveAt(0);
                turn_owner_unit.end_action          = false;
                turn_owner_unit.end_sub_action      = false;
                turn_owner_unit.end_move            = false;
                //unit_manager.active_units.RemoveAt(0);
                game_main.g3d_map.SetTurnOwnerCursor(turn_owner_unit.unit_manager_status.unit);
            }
            else
            {
                // Err?
                turn_owner_unit.unit_manager_status = null;
                turn_owner_unit.end_action          = false;
                turn_owner_unit.end_sub_action      = false;
                turn_owner_unit.end_move            = false;
            }

            if (!turn_owner_unit.unit_manager_status.unit.bt.is_alive)
            { // 生存してない
                NextUnitTurn();
                return;
            }

            // AIによる行動
            if (game_main.debug_status.is_auto_battle)
            {
                battle_ai = new BattleAI(this, turn_owner_unit.unit_manager_status.unit);
            }
            else if (!game_main.debug_status.is_battle_ui_debug_mode)
            {
                if (turn_owner_unit.unit_manager_status.group != "味方")
                {
                    battle_ai = new BattleAI(this, turn_owner_unit.unit_manager_status.unit);
                }
            }
        }
Example #3
0
        public bool _ScriptLineAnalyze(Script.ScriptLineToken t)
        {
            var game_main      = GameMain.GetInstance();
            var user_interface = game_main.user_interface;
            var game_base      = game_main.game_base;
            //var g3d_camera = game_main.g3d_camera;
            var g3d_map      = game_main.g3d_map;
            var unit_manager = game_main.unit_manager;

            //var action_manager = game_main.action_manager;

            switch (t.command[0])
            {
            case "MapLoad":
            {
                var map_path = t.GetString(1);
                g3d_map.Load(map_path);
            }
                return(true);

            case "MapData":
            {
                var size = t.command.Count();
                for (var i = 1; i < size; i++)
                {
                    setup_script_data.map_data.Add(t.GetInt(i));
                }
                setup_script_data.map_w = size - 1;
            }
                return(true);

            case "MapSetup":
            {
                setup_script_data.map_h = setup_script_data.map_data.Count() / setup_script_data.map_w;
                g3d_map.map_w           = setup_script_data.map_w;
                g3d_map.map_h           = setup_script_data.map_h;

                g3d_map.Setup(setup_script_data.map_data.ToArray());
            }
                return(true);

            case "Unit":
            {
                var x = t.GetInt(1);
                var y = t.GetInt(2);
                var unit_class_name = t.GetString(3);
                var ucd             = UnitDataManager.GetUnitClassData(unit_class_name);
                var model_path      = t.GetString(4);
                var image_face_path = t.GetString(5);

                var name      = t.GetString(6);
                var group     = t.GetString(7);
                var color_no  = t.GetInt(8);
                var direction = t.GetInt(9);

                if (!(is_continue_player_unit && group == "味方"))
                {
                    var unit = new Unit(unit_class_name, model_path, image_face_path, name, x, y, color_no, direction);
                    unit_manager.Join(unit, group);
                }
            }
                //unit_manager.Join(new Unit(path, 3, 5, 1, 0), "敵");
                return(true);
            }
            return(false);
        }
Example #4
0
        void _Update_KeyInput()
        {
            var game_main      = GameMain.GetInstance();
            var user_interface = game_main.user_interface;
            var game_base      = game_main.game_base;
            var g3d_camera     = game_main.g3d_camera;
            var g3d_map        = game_main.g3d_map;
            var unit_manager   = game_main.unit_manager;

            user_interface.Update(game_base.input.mouse_sutatus.position);

            if (game_main.action_manager.IsControlFreese() || game_main.battle_map_effect_script_conector_manager.IsControlFreese())
            {
                g3d_map.is_draw_cursor_turn_owner = false;
                return;
            }
            else
            {
                g3d_map.is_draw_cursor_turn_owner = true;
            }

            //
            if (DX.CheckHitKey(DX.KEY_INPUT_Q) == DX.TRUE)
            {
                g3d_camera.AddRot(0.03f);
            }
            if (DX.CheckHitKey(DX.KEY_INPUT_E) == DX.TRUE)
            {
                g3d_camera.AddRot(-0.03f);
            }
            if (DX.CheckHitKey(DX.KEY_INPUT_A) == DX.TRUE)
            {
                g3d_camera.MoveYRot(1.00f, 90);
            }
            if (DX.CheckHitKey(DX.KEY_INPUT_D) == DX.TRUE)
            {
                g3d_camera.MoveYRot(1.00f, -90);
            }
            if (DX.CheckHitKey(DX.KEY_INPUT_S) == DX.TRUE)
            {
                g3d_camera.MoveFront(-1.0f);
            }
            if (DX.CheckHitKey(DX.KEY_INPUT_W) == DX.TRUE)
            {
                g3d_camera.MoveFront(1.0f);
            }

            if (DX.CheckHitKey(DX.KEY_INPUT_F) == DX.TRUE)
            {
                //g3d_camera.MoveFront(1.0f);
                g3d_map.SetMoveRouteEffect(g3d_map.map_cursor_x, g3d_map.map_cursor_y);
            }

            if (game_base.input.GetKeyInputStatus((int)GameMain.KeyCode.DebugView) == Input.KeyInputStatus.Up)
            {
                game_main.debug_is_view = !game_main.debug_is_view;
            }

            //if (user_interface.mode == UserInterface.Mode.NonePlayerTurn)
            if (battle_ai != null)
            {
                if (battle_ai.GetIsEnd())
                {
                    battle_ai = null;
                    user_interface.SetMode(UserInterface.Mode.PlayerTurnFree, game_base.input.mouse_sutatus.position);
                    NextUnitTurn();
                }
            }
            else if (game_base.input.mouse_sutatus.left.key_status == Input.MouseButtonKeyStatus.OneCrick)
            {
                if (user_interface.IsHitUI()) // UIへの入力
                {
                    var command     = user_interface.GetHitUICommand();
                    var action_data = ActionDataManager.GetActionData(command.system_name);
                    switch (user_interface.mode)
                    {
                    case UserInterface.Mode.TurnTopCommandShow:
                        select_command = command;
                        switch (command.system_name)
                        {
                        default:
                            if (action_data != null)
                            {
                                user_interface.SetMode(UserInterface.Mode.AtackTargetSelect, game_base.input.mouse_sutatus.position);
                                user_interface.mode_param1 = action_data.range_type;
                                g3d_map.ClearRangeAreaEffect();
                                g3d_map.SetActionTargetAreaEffect(select_unit.map_x, select_unit.map_y, action_data.range_min, action_data.range_max, 1);
                            }
                            else
                            {
                                user_interface.SetMode(UserInterface.Mode.PlayerTurnFree, game_base.input.mouse_sutatus.position);
                                g3d_map.ClearRangeAreaEffect();
                            }
                            break;

                        case "移動":
                            user_interface.SetMode(UserInterface.Mode.MovePointSelect, game_base.input.mouse_sutatus.position);
                            break;

                        case "待機":
                            _Update_KeyInput_TurnOnwerEnd();
                            user_interface.SetMode(UserInterface.Mode.PlayerTurnFree, game_base.input.mouse_sutatus.position);
                            g3d_map.ClearRangeAreaEffect();
                            break;

                        case "ステータス":
                            user_interface.SetMode(UserInterface.Mode.UnitStatusView, game_base.input.mouse_sutatus.position);
                            user_interface.SetStatusUnit(select_unit);
                            g3d_map.ClearRangeAreaEffect();
                            break;

                        case "AI":
                            user_interface.SetMode(UserInterface.Mode.NonePlayerTurn, game_base.input.mouse_sutatus.position);
                            g3d_map.ClearRangeAreaEffect();
                            battle_ai = new BattleAI(this, select_unit);
                            break;

                        case "Game Over":
                            user_interface.SetMode(UserInterface.Mode.PlayerTurnFree, game_base.input.mouse_sutatus.position);
                            game_main.NextScene(new SceneEndBattle("Game Over", ""));
                            break;

                        case "Stage Clear":
                            user_interface.SetMode(UserInterface.Mode.PlayerTurnFree, game_base.input.mouse_sutatus.position);
                            game_main.NextScene(new SceneEndBattle("Stage Clear", ""));
                            break;
                        }
                        break;

                    case UserInterface.Mode.SubTopCommandShow:
                        select_command = command;
                        switch (command.system_name)
                        {
                        default:
                            if (action_data != null)
                            {
                                user_interface.SetMode(UserInterface.Mode.AtackTargetSelect, game_base.input.mouse_sutatus.position);
                                user_interface.mode_param1 = action_data.range_type;
                                g3d_map.ClearRangeAreaEffect();
                                g3d_map.SetActionTargetAreaEffect(select_unit.map_x, select_unit.map_y, action_data.range_min, action_data.range_max, 1);
                            }
                            else
                            {
                                user_interface.SetMode(UserInterface.Mode.PlayerTurnFree, game_base.input.mouse_sutatus.position);
                                g3d_map.ClearRangeAreaEffect();
                            }
                            break;

                        case "ステータス":
                            user_interface.SetMode(UserInterface.Mode.UnitStatusView, game_base.input.mouse_sutatus.position);
                            user_interface.SetStatusUnit(select_unit);
                            g3d_map.ClearRangeAreaEffect();
                            break;
                            //case "AI":
                            //    user_interface.SetMode(UserInterface.Mode.NonePlayerTurn, game_base.input.mouse_sutatus.position);
                            //    g3d_map.ClearRangeAreaEffect();
                            //    battle_ai = new BattleAI(this, select_unit);
                            //    break;
                        }
                        break;
                    }
                }
                else if (g3d_map.map_cursor_x >= 0 && g3d_map.map_cursor_y >= 0) // 3Dマップへの入力
                {
                    switch (user_interface.mode)
                    {
                    case UserInterface.Mode.MovePointSelect:     // 移動選択
                    {
                        var is_inside = g3d_map.move_area.IsInside(g3d_map.map_cursor_x, g3d_map.map_cursor_y);
                        if (is_inside)
                        {         // 移動範囲内
                            select_unit.Move(g3d_map.map_cursor_x, g3d_map.map_cursor_y, true);
                            user_interface.SetMode(UserInterface.Mode.PlayerTurnFree, game_base.input.mouse_sutatus.position);
                            if (!game_main.debug_status.is_battle_ui_debug_mode)
                            {
                                turn_owner_unit.end_move = true;
                            }
                        }
                        else
                        {         // 移動範囲外
                            user_interface.SetMode(UserInterface.Mode.PlayerTurnFree, game_base.input.mouse_sutatus.position);
                        }
                        g3d_map.ClearRangeAreaEffect();
                    }
                    break;

                    case UserInterface.Mode.AtackTargetSelect:     // 攻撃対象選択
                    {
                        DoAction(select_command.system_name, user_interface.mode_param1, select_unit, g3d_map.map_cursor_x, g3d_map.map_cursor_y, true);
                    }
                    break;

                    case UserInterface.Mode.UnitStatusView:
                        user_interface.SetMode(UserInterface.Mode.PlayerTurnFree, game_base.input.mouse_sutatus.position);
                        break;

                    default:
                    {
                        var u = unit_manager.GetUnit(g3d_map.map_cursor_x, g3d_map.map_cursor_y);
                        if (game_main.debug_status.is_battle_ui_debug_mode && (u != null))
                        {
                            turn_owner_unit.unit_manager_status = GetUnitManagerStatus(u);
                            g3d_map.SetMoveAreaEffect(g3d_map.map_cursor_x, g3d_map.map_cursor_y, u.bt.status["MOVE"].now, u.bt.status["JUMP"].now, "");
                            user_interface.SetMode(UserInterface.Mode.TurnTopCommandShow, game_base.input.mouse_sutatus.position, turn_owner_unit);
                            select_unit = u;
                        }
                        else if ((u != null) && (u == turn_owner_unit.unit_manager_status.unit))
                        {
                            //if (select_unit == u)
                            //{
                            //    g3d_map.ClearRangeAreaEffect();
                            //    user_interface.SetMode(UserInterface.Mode.PlayerTurnFree, game_base.input.mouse_sutatus.position);
                            //    select_unit = null;
                            //}
                            //else
                            //{
                            g3d_map.SetMoveAreaEffect(g3d_map.map_cursor_x, g3d_map.map_cursor_y, u.bt.status["MOVE"].now, u.bt.status["JUMP"].now, "");
                            user_interface.SetMode(UserInterface.Mode.TurnTopCommandShow, game_base.input.mouse_sutatus.position, turn_owner_unit);
                            select_unit = u;
                            //}
                        }
                        else if (u != null)
                        {
                            g3d_map.SetMoveAreaEffect(g3d_map.map_cursor_x, g3d_map.map_cursor_y, u.bt.status["MOVE"].now, u.bt.status["JUMP"].now, "");

                            //if(select_unit==u) // 2度クリックしたときはコマンド表示を消す
                            //{
                            //    g3d_map.ClearRangeAreaEffect();
                            //    user_interface.SetMode(UserInterface.Mode.PlayerTurnFree, game_base.input.mouse_sutatus.position);
                            //    select_unit = null;
                            //}
                            //else
                            //{
                            user_interface.SetMode(UserInterface.Mode.SubTopCommandShow, game_base.input.mouse_sutatus.position, null);
                            select_unit = u;
                            //}
                        }
                        else
                        {
                            g3d_map.ClearRangeAreaEffect();
                            user_interface.SetMode(UserInterface.Mode.PlayerTurnFree, game_base.input.mouse_sutatus.position);
                            select_unit = null;
                        }
                    }
                    break;
                    }
                }
            }
            else
            {
                switch (user_interface.mode)
                {
                case UserInterface.Mode.UnitStatusView:
                    //if (!user_interface.IsHitUI())
                    //{
                    //    user_interface.SetMode(UserInterface.Mode.PlayerTurnFree, game_base.input.mouse_sutatus.position);
                    //}
                    break;

                default:
                    if (!user_interface.IsHitUI())
                    {
                        var u = unit_manager.GetUnit(g3d_map.map_cursor_x, g3d_map.map_cursor_y);
                        user_interface.SetStatusUnit(u);
                    }
                    else
                    {
                        user_interface.SetStatusUnit(select_unit);
                    }
                    break;
                }
            }
        }
Example #5
0
        // todo: 行動させるのと、UI制御が混ざってるので、分離したほうが良さそう
        // 行動の実行できるかどうかについても判定しているからややこしい(AIのところで食い違う…多重チェックになってる)
        public void DoAction(string command, string sub_command, Unit action_unit, int target_map_x, int target_map_y, bool is_user_owner)
        {
            var game_main      = GameMain.GetInstance();
            var user_interface = game_main.user_interface;
            var game_base      = game_main.game_base;
            var g3d_map        = game_main.g3d_map;
            var unit_manager   = game_main.unit_manager;
            var target_unit    = unit_manager.GetUnit(target_map_x, target_map_y);

            var is_inside   = false;
            var action_data = ActionDataManager.GetActionData(command);

            if (!is_user_owner)
            {
                // 自動・NPCでの操作の場合
                g3d_map.ClearRangeAreaEffect();
                g3d_map.SetActionTargetAreaEffect(action_unit.map_x, action_unit.map_y, action_data.range_min, action_data.range_max, 1);
                is_inside = g3d_map.action_target_area.IsInside(target_map_x, target_map_y);
            }
            else
            {
                is_inside = g3d_map.action_target_area.IsInside(target_map_x, target_map_y);
            }

            var is_action_do_ok = false;

            switch (action_data.range_ok_type)
            {
            case "範囲内":     // 範囲内しか行動の実行を認めない
                if (is_inside)
                {
                    is_action_do_ok = true;
                }
                break;

            case "延長可":     // 射程最小値より大きければ、射程最大値外でも行動の実行を認める
                //if (is_inside) action_do_ok = true;
            {
                var range = Math.Abs(target_map_x - action_unit.map_x) + Math.Abs(target_map_y - action_unit.map_y);
                if (range >= action_data.range_min)
                {
                    is_action_do_ok = true;
                }
            }
            break;
            }
            if (!is_action_do_ok)
            {
                // 行動不可なので、中断
                if (is_user_owner)
                {
                    user_interface.SetMode(UserInterface.Mode.PlayerTurnFree, game_base.input.mouse_sutatus.position);
                    g3d_map.ClearRangeAreaEffect();
                }
                return;
            }

            // todo: 行動のモーション、サウンドに関わるため、一旦はこのまま(先に他を整理)
            switch (command)
            {
            default:     // 対象が単体のものはこれでいけるはず
            {
                var damage     = 0;
                var is_success = target_unit != null;
                if (is_success)
                {
                    damage = GetDamage(action_unit, target_unit, action_data);
                }
                if (target_unit == null)
                {
                    // ダミーの対象ユニットを作成しておく
                    target_unit = new Unit(target_map_x, target_map_y);
                }
                else
                {
                    // 攻撃の場合、ダメージでHPが0になる場合、この時点で、戦闘不能予約をしておく
                    if (action_data.type == "攻撃")
                    {
                        var hp = target_unit.bt.status["HP"].now - damage;
                        if (hp <= 0)
                        {
                            target_unit.bt.is_reserve_dead = true;
                        }
                    }
                }

                var action = new ScriptConector.BattleMapEffectScriptConector(action_data.script_path, is_success, damage, action_unit, target_unit);
                ScriptConector.BattleMapEffectScriptConectorManager.Add(action);
            }
            break;
            }
            if (is_user_owner)
            {
                user_interface.SetMode(UserInterface.Mode.PlayerTurnFree, game_base.input.mouse_sutatus.position);
                g3d_map.ClearRangeAreaEffect();
            }

            // 手番ユニットの行動済みを設定
            if (!game_main.debug_status.is_battle_ui_debug_mode)
            {
                turn_owner_unit.end_action = true;
            }
        }
Example #6
0
        public RouteAsShoot(int start_map_x, int start_map_y, float start_height_offset, int end_map_x, int end_map_y, float end_height_offset, int rot_r)
        {
            this.start_map_x = start_map_x;
            this.start_map_y = start_map_y;
            this.end_map_x   = end_map_x;
            this.end_map_y   = end_map_y;
            map_ox           = start_map_x; if (end_map_x < map_ox)
            {
                map_ox = end_map_x;
            }
            map_oy = start_map_y; if (end_map_y < map_oy)
            {
                map_oy = end_map_y;
            }

            var g3d_map = GameMain.GetInstance().g3d_map;

            g3d_map.route_as_shoot = this;

            var start_map_height = g3d_map.GetHeight(start_map_x, start_map_y);
            var end_map_height   = g3d_map.GetHeight(end_map_x, end_map_y);

            start_x = (int)(start_map_x * sq_size);
            start_z = (int)(start_map_y * sq_size);
            start_y = (int)(start_map_height * sq_size / 4.0 + sq_size * start_height_offset);
            end_x   = (int)(end_map_x * sq_size);
            end_z   = (int)(end_map_y * sq_size);
            end_y   = (int)(end_map_height * sq_size / 4.0 + sq_size * end_height_offset);

            width_x    = Math.Abs(start_x - end_x) + sq_size;
            width_z    = Math.Abs(start_z - end_z) + sq_size;
            heigth_max = 15 * 40;

            offset_x = start_x; if (offset_x > end_x)
            {
                offset_x = end_x;
            }
            offset_z = start_z; if (offset_z > end_z)
            {
                offset_z = end_z;
            }

            // 開始位置と終端位置を補正 width_x widht_z の確定後でないと補正できない
            start_x += sq_size / 2;
            start_z += sq_size / 2;
            end_x   += sq_size / 2;
            end_z   += sq_size / 2;

            // 真上から見下ろしたときの高さ情報(XZ平面空間)を作成
            height_map_xz = new int[width_x * width_z];

            var size = height_map_xz.Count();

            for (var i = 0; i < size; i++)
            {
                var x     = i % width_x;
                var z     = i / width_x;
                var map_x = map_ox + x / 40;
                var map_y = map_oy + z / 40;
                var h     = g3d_map.GetHeight(map_x, map_y) * 10;
                height_map_xz[i] = h;
            }

            // XZ平面空間での開始から終端までのルートを算出
            {
                var dm_size = 0;
                var add_x   = 1;
                var add_y   = 1;
                if (start_x > end_x)
                {
                    add_x = -1;
                }
                if (start_z > end_z)
                {
                    add_y = -1;
                }

                if (width_x > width_z)
                { // 横幅のほうが長い → 横を1ずつ計算して進める
                    dm_size = width_x - sq_size + 1;
                    var x      = start_x;
                    var y      = start_z;
                    var diff_x = end_x - start_x;
                    var diff_z = end_z - start_z;
                    for (int i = 0; i < dm_size; i++)
                    {
                        y = (int)((double)diff_z / diff_x * ((i + 0.5) * add_x) + start_z);
                        route_pos_list_xz.Add(new Point(x, y));
                        x += add_x;
                    }
                }
                else
                { // 縦幅のほうが長い → 縦を1ずつ計算して進める
                    dm_size = (width_z - sq_size + 1);
                    var x      = start_x;
                    var y      = start_z;
                    var diff_x = end_x - start_x;
                    var diff_z = end_z - start_z;
                    for (int i = 0; i < (width_z - sq_size + 1); i++)
                    {
                        x = (int)((double)diff_x / diff_z * ((i + 0.5) * add_y) + start_x);
                        route_pos_list_xz.Add(new Point(x, y));
                        y += add_y;
                    }
                }
            }

            // 断面図の算出
            width_height_map = route_pos_list_xz.Count();
            var um = GameMain.GetInstance().unit_manager;

            height_map_route = new int[width_height_map * heigth_max];
            {
                var height_map_route_w = route_pos_list_xz.Count();
                for (var j = 0; j < height_map_route.Count(); j++)
                {
                    height_map_route[j] = -2;                                                // 初期化
                }
                // 地形は-1埋め、ユニットは各番号で埋める
                //for ( var i = 0; i< route_pos_list_xz.Count(); i++)
                var i = 0;
                foreach (var p in route_pos_list_xz)
                {
                    var map_x = p.X / 40;
                    var map_y = p.Y / 40;
                    var h     = height_map_xz[p.X - offset_x + (p.Y - offset_z) * width_x];

                    //var x =
                    var u = um.GetUnit(map_x, map_y);

                    for (var y = 0; y <= h; y++)
                    {
                        height_map_route[i + y * width_height_map] = -1;
                    }

                    if (u != null)
                    {
                        var unit_height = (int)(40 * 1.5);
                        for (var y = h + 1; y < h + unit_height; y++)
                        {
                            height_map_route[i + y * width_height_map] = 0;
                        }
                    }

                    i++;
                }
            }

            // 断面図の放物線を計算
            // 2次方程式だが、頂点がわからない → 減速速度(ag)と始点、希望着地点から近似値を算出
            // 角度を少しずつずらしながら近い値を使うので、処理が重い
            // ずらし方をいったん大雑把にして、その近似付近を細かくしらべる、を繰り返すのもありだけど保留
            {
                var size_xz = route_pos_list_xz.Count();
                var start_p = route_pos_list_xz[0];
                var end_p   = route_pos_list_xz[size_xz - 1];

                var ag = 0.0025;                                                                                       // 減速速度
                var y1 = (double)height_map_xz[start_p.X - offset_x + (start_p.Y - offset_z) * width_x] + 40.0 * 0.75; //
                var y2 = (double)height_map_xz[end_p.X - offset_x + (end_p.Y - offset_z) * width_x] + 40.0 * 0.75;     //

                var rot_min     = 60.0;                                                                                // 最小角度、-45などにすると近距離で角度なしが選択されやすい
                var map_range_x = start_map_x - end_map_x;
                var map_range_y = start_map_y - end_map_y;
                var map_range   = Math.Sqrt(map_range_x * map_range_x + map_range_y * map_range_y);


                var list       = new List <Point>();
                var most_near  = -1.0;
                var most_rot_r = 89.0;
                for (var rot_r1 = 89.999; rot_r1 > rot_min; rot_r1 -= 0.1)
                {
                    var res_y = GetShootRoute(ag, rot_r1, y1, size_xz, ref route_pos_list_route, ref direction_list_route, false);
                    var near  = res_y - y2; if (near < 0)
                    {
                        near = -near;
                    }

                    if ((most_near == -1.0) || (near < most_near))
                    {
                        most_near  = near;
                        most_rot_r = rot_r1;
                    }
                }

                GetShootRoute(ag, most_rot_r, y1, size_xz, ref route_pos_list_route, ref direction_list_route, true);
            }

            // 方向を計算する
            if (end_x == start_x)
            {
                if (end_z - start_z > 0)
                {
                    direction = Math.PI * 0.5; //  90度
                }
                else
                {
                    direction = Math.PI * 1.5; // 270度
                }
            }
            else if (end_z == start_z)
            {
                if (end_x - start_x > 0)
                {
                    direction = 0; //  0度
                }
                else
                {
                    direction = Math.PI * 1.0; // 180度
                }
            }
            else
            {
                var dz = end_z - start_z;
                var dx = end_x - start_x;
                direction = Math.Atan((double)(dz) / (double)(end_x - start_x));
                if (dx > 0 && dz > 0)
                {
                    // そのまま
                }
                else if (dx < 0 && dz > 0)
                {
                    direction += Math.PI;
                }
                else if (dx < 0 && dz < 0)
                {
                    direction += Math.PI;
                }
                else // if (dx > 0 && dz < 0)
                {
                    direction += Math.PI * 2.0;
                }
            }
        }
Example #7
0
        public bool _ScriptLineAnalyze(Script.ScriptLineToken t)
        {
            var game_main = GameMain.GetInstance();
            //var user_interface = game_main.user_interface;
            //var game_base = game_main.game_base;
            //var g3d_camera = game_main.g3d_camera;
            var g3d_map      = game_main.g3d_map;
            var unit_manager = game_main.unit_manager;

            //var action_manager = game_main.action_manager;

            switch (t.command[0])
            {
            //case "MapData":
            //    {
            //        var size = t.command.Count();
            //        for (var i = 1; i < size; i++)
            //        {
            //            setup_script_data.map_data.Add(t.GetInt(i));
            //        }
            //        setup_script_data.map_w = size - 1;
            //    }
            //    break;
            //case "MapSetup":
            //    {
            //        setup_script_data.map_h = setup_script_data.map_data.Count() / setup_script_data.map_w;
            //        g3d_map.map_w = setup_script_data.map_w;
            //        g3d_map.map_h = setup_script_data.map_h;

            //        g3d_map.Setup(setup_script_data.map_data.ToArray());

            //    }
            //    break;
            case "Unit":
            {
                var x = t.GetInt(1);
                var y = t.GetInt(2);
                var unit_class_name = t.GetString(3);
                var ucd             = UnitDataManager.GetUnitClassData(unit_class_name);
                var model_path      = "data/model/" + t.GetString(4) + "/_.pmd";
                var image_face_path = "data/image/face/" + t.GetString(5);

                // 下記のifはUnitのコンストラクタで処理しても良い?
                if (t.GetString(4) == "")
                {
                    model_path = ucd.model_default_path;
                }
                if (t.GetString(5) == "")
                {
                    image_face_path = ucd.image_default_path;
                }

                var name      = t.GetString(6);
                var group     = t.GetString(7);
                var color_no  = t.GetInt(8);
                var direction = t.GetInt(9);
                var unit      = new Unit(unit_class_name, model_path, image_face_path, name, x, y, color_no, direction);
                unit_manager.Join(unit, group);
            }
                //unit_manager.Join(new Unit(path, 3, 5, 1, 0), "敵");
                break;
                //case "DebugMode":
                //    if (t.GetString(1) == "True")
                //    {
                //        is_debug_mode = true;
                //    }
                //    else
                //    {
                //        is_debug_mode = false;
                //    }
                //    break;
            }
            return(false);
        }
Example #8
0
        void _Update_KeyInput()
        {
            var game_main      = GameMain.GetInstance();
            var user_interface = game_main.user_interface;
            var game_base      = game_main.game_base;
            var g3d_camera     = game_main.g3d_camera;
            var g3d_map        = game_main.g3d_map;
            var unit_manager   = game_main.unit_manager;

            user_interface.Update(game_base.input.mouse_sutatus.position);

            if (game_base.input.mouse_sutatus.left.key_status == Input.MouseButtonKeyStatus.OneCrick)
            {
                var ui_select_side_box = GetUISelectSideBox();
                var ui_select_unit     = GetUISelectUnit();

                if (ui_select_side_box != null)
                { // UI への入力
                    switch (ui_select_side_box.GetString())
                    {
                    case "完了":
                        SoundManager.PlaySound("システム/出陣", 0.5);
                        user_interface.SetMode(UserInterface.Mode.PlayerTurnFree, game_base.input.mouse_sutatus.position);
                        user_interface.SetStatusUnit(null);
                        game_main.NextScene(new SceneBattle(next_battle_setup_script_path, true));
                        break;

                    case "ステータス":
                        if (select_unit != null)
                        {
                            if (user_interface.mode != UserInterface.Mode.UnitStatusView)
                            {
                                SoundManager.PlaySound("システム/選択", 0.5);
                                user_interface.SetMode(UserInterface.Mode.UnitStatusView, game_base.input.mouse_sutatus.position);
                                user_interface.SetStatusUnit(select_unit);
                            }
                            else
                            {
                                SoundManager.PlaySound("システム/解除", 0.5);
                                user_interface.SetMode(UserInterface.Mode.PlayerTurnFree, game_base.input.mouse_sutatus.position);
                                user_interface.SetStatusUnit(null);
                            }
                        }
                        else
                        {
                            SoundManager.PlaySound("システム/失敗", 0.5);
                        }
                        break;
                    }
                }
                else if (ui_select_unit != null)
                { // UI キャラクター一覧 への入力
                    if (select_unit == ui_select_unit)
                    {
                        if (user_interface.mode != UserInterface.Mode.UnitStatusView)
                        {
                            SetSelectUnit(null);
                        }
                        else
                        {
                            SoundManager.PlaySound("システム/失敗", 0.5);
                        }

                        //user_interface.SetMode(UserInterface.Mode.PlayerTurnFree, game_base.input.mouse_sutatus.position);
                        //user_interface.SetStatusUnit(null);
                    }
                    else
                    {
                        if (user_interface.mode == UserInterface.Mode.UnitStatusView)
                        {
                            user_interface.SetStatusUnit(ui_select_unit);
                        }
                        SetSelectUnit(ui_select_unit);
                    }
                }
                else if (g3d_map.map_cursor_x >= 0 && g3d_map.map_cursor_y >= 0)
                { // 3Dマップへの入力
                    switch (user_interface.mode)
                    {
                    case UserInterface.Mode.UnitStatusView:
                        user_interface.SetMode(UserInterface.Mode.PlayerTurnFree, game_base.input.mouse_sutatus.position);
                        user_interface.SetStatusUnit(null);
                        break;

                    default:
                    {
                        var u = unit_manager.GetUnit(g3d_map.map_cursor_x, g3d_map.map_cursor_y);
                        if (select_unit != u)
                        {
                            if (u != null)
                            {
                                if (select_unit == null)
                                {         // 選択対象を変更
                                    SetSelectUnit(u);
                                }
                                else
                                {         // 位置を入れ替え
                                    SoundManager.PlaySound("システム/入れ替え", 0.5);
                                    var select_map_x = select_unit.map_x;
                                    var select_map_y = select_unit.map_y;

                                    select_unit.SetPosOffset(0, 0, 0);
                                    select_unit.Move(u.map_x, u.map_y, true);
                                    u.Move(select_map_x, select_map_y, true);
                                    //g3d_map.SetTurnOwnerCursor(null);
                                    //select_unit = null;
                                }
                            }
                            else if (select_unit != null)
                            {         // 選択対象を移動
                                if (g3d_map.map_cursor_x >= 0 && g3d_map.map_cursor_y >= 0)
                                {
                                    SoundManager.PlaySound("システム/入れ替え", 0.5);
                                    select_unit.Move(g3d_map.map_cursor_x, g3d_map.map_cursor_y, true);
                                }
                                else
                                {
                                    SetSelectUnit(null);
                                }
                            }
                        }
                        else if (select_unit != null)
                        {         // 同じなら一旦選択解除
                            SetSelectUnit(null);
                        }
                        user_interface.SetStatusUnit(select_unit);
                    }
                    break;
                    }
                }
                else
                { // 3Dマップ領域外
                    switch (user_interface.mode)
                    {
                    case UserInterface.Mode.UnitStatusView:
                        user_interface.SetMode(UserInterface.Mode.PlayerTurnFree, game_base.input.mouse_sutatus.position);
                        user_interface.SetStatusUnit(null);
                        break;

                    default:
                        if (select_unit != null)
                        {
                            SetSelectUnit(null);
                        }
                        break;
                    }
                }
            }
        }
Example #9
0
        void _Update_KeyInput()
        {
            var game_main      = GameMain.GetInstance();
            var user_interface = game_main.user_interface;
            var game_base      = game_main.game_base;
            var g3d_camera     = game_main.g3d_camera;
            var g3d_map        = game_main.g3d_map;
            var unit_manager   = game_main.unit_manager;

            user_interface.Update(game_base.input.mouse_sutatus.position);

            if (game_main.action_manager.IsControlFreese())
            {
                g3d_map.is_draw_cursor_turn_owner = false;
                return;
            }
            else
            {
                g3d_map.is_draw_cursor_turn_owner = true;
            }

            //
            if (DX.CheckHitKey(DX.KEY_INPUT_Q) == DX.TRUE)
            {
                g3d_camera.AddRot(0.03f);
            }
            if (DX.CheckHitKey(DX.KEY_INPUT_E) == DX.TRUE)
            {
                g3d_camera.AddRot(-0.03f);
            }
            if (DX.CheckHitKey(DX.KEY_INPUT_A) == DX.TRUE)
            {
                g3d_camera.MoveYRot(1.00f, 90);
            }
            if (DX.CheckHitKey(DX.KEY_INPUT_D) == DX.TRUE)
            {
                g3d_camera.MoveYRot(1.00f, -90);
            }
            if (DX.CheckHitKey(DX.KEY_INPUT_S) == DX.TRUE)
            {
                g3d_camera.MoveFront(-1.0f);
            }
            if (DX.CheckHitKey(DX.KEY_INPUT_W) == DX.TRUE)
            {
                g3d_camera.MoveFront(1.0f);
            }

            if (DX.CheckHitKey(DX.KEY_INPUT_F) == DX.TRUE)
            {
                //g3d_camera.MoveFront(1.0f);
                g3d_map.SetMoveRouteEffect(g3d_map.map_cursor_x, g3d_map.map_cursor_y);
            }

            if (game_base.input.GetKeyInputStatus((int)GameMain.KeyCode.DebugView) == Input.KeyInputStatus.Up)
            {
                game_main.debug_is_view = !game_main.debug_is_view;
            }

            if (game_base.input.mouse_sutatus.left.key_status == Input.MouseButtonKeyStatus.OneCrick)
            {
                var keys = tool_window.select_tool_key_word.Split(' ');
                if (keys.Count() >= 0)
                {
                    switch (keys[0])
                    {
                    case "ground":
                        if (g3d_map.map_cursor_x >= 0 && g3d_map.map_cursor_y >= 0)
                        {
                            g3d_map.SetGroundMaterial(g3d_map.map_cursor_x, g3d_map.map_cursor_y, keys[1]);
                        }
                        break;

                    case "wall":
                        if (g3d_map.map_cursor_wall != null)
                        {
                            g3d_map.SetWallMaterial(g3d_map.map_cursor_wall, keys[1]);
                        }
                        break;

                    case "ground_up":
                        if (g3d_map.map_cursor_x >= 0 && g3d_map.map_cursor_y >= 0)
                        {
                            var height = g3d_map.GetHeight(g3d_map.map_cursor_x, g3d_map.map_cursor_y) + 1;
                            g3d_map.SetMapHeight(g3d_map.map_cursor_x, g3d_map.map_cursor_y, height);
                        }
                        break;

                    case "ground_down":
                        if (g3d_map.map_cursor_x >= 0 && g3d_map.map_cursor_y >= 0)
                        {
                            var height = g3d_map.GetHeight(g3d_map.map_cursor_x, g3d_map.map_cursor_y) - 1;
                            if (height < 0)
                            {
                                height = 0;
                            }
                            g3d_map.SetMapHeight(g3d_map.map_cursor_x, g3d_map.map_cursor_y, height);
                        }
                        break;
                    }
                }
            }
            switch (tool_window.select_tool_key_word)
            {
            case "save":
            {
                var sfd = new SaveFileDialog();
                sfd.FileName = "新しいファイル_map.nst";
                //sfd.InitialDirectory = @"C:\";
                //sfd.Filter = "HTMLファイル(*.html;*.htm)|*.html;*.htm|すべてのファイル(*.*)|*.*";
                sfd.Filter           = "nst|*.nst|すべてのファイル(*.*)|*.*";
                sfd.FilterIndex      = 1;    //1番目の「nst」が選択されているようにする
                sfd.Title            = "保存先のファイルを選択してください";
                sfd.RestoreDirectory = true; //ダイアログボックスを閉じる前に現在のディレクトリを復元するようにする
                sfd.OverwritePrompt  = true; //既に存在するファイル名を指定したとき警告する //デフォルトでTrueなので指定する必要はない
                sfd.CheckPathExists  = true; //存在しないパスが指定されたとき警告を表示する //デフォルトでTrueなので指定する必要はない

                //ダイアログを表示する
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    //OKボタンがクリックされたとき、選択されたファイル名を表示する
                    //Console.WriteLine(sfd.FileName);
                    g3d_map.Save(sfd.FileName);
                }
                tool_window.select_tool_key_word = "";
            }
            break;

            case "load":
            {
                var ofd = new OpenFileDialog();
                //sfd.FileName = "新しいファイル_map.nst";
                //sfd.InitialDirectory = @"C:\";
                //sfd.Filter = "HTMLファイル(*.html;*.htm)|*.html;*.htm|すべてのファイル(*.*)|*.*";
                ofd.Filter           = "nst|*.nst|すべてのファイル(*.*)|*.*";
                ofd.FilterIndex      = 1;    //1番目の「nst」が選択されているようにする
                ofd.Title            = "開くファイルを選択してください";
                ofd.RestoreDirectory = true; //ダイアログボックスを閉じる前に現在のディレクトリを復元するようにする
                //ofd.OverwritePrompt = true; //既に存在するファイル名を指定したとき警告する //デフォルトでTrueなので指定する必要はない
                ofd.CheckFileExists = true;
                ofd.CheckPathExists = true;         //存在しないパスが指定されたとき警告を表示する //デフォルトでTrueなので指定する必要はない

                //ダイアログを表示する
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    //OKボタンがクリックされたとき、選択されたファイル名を表示する
                    //Console.WriteLine(sfd.FileName);
                    //g3d_map.Save(sfd.FileName);
                    g3d_map.Load(ofd.FileName);
                }
                tool_window.select_tool_key_word = "";
            }
            break;

            case "resize_h_m1":
            {
                g3d_map.Resize(g3d_map.map_w, g3d_map.map_h - 1, 0, 0);
                tool_window.select_tool_key_word = "";
            }
            break;

            case "resize_h_m1b":
            {
                g3d_map.Resize(g3d_map.map_w, g3d_map.map_h - 1, 0, 1);
                tool_window.select_tool_key_word = "";
            }
            break;

            case "resize_w_m1":
            {
                g3d_map.Resize(g3d_map.map_w - 1, g3d_map.map_h, 1, 0);
                tool_window.select_tool_key_word = "";
            }
            break;

            case "resize_w_m1b":
            {
                g3d_map.Resize(g3d_map.map_w - 1, g3d_map.map_h, 0, 0);
                tool_window.select_tool_key_word = "";
            }
            break;

            case "resize_h_p1":
            {
                g3d_map.Resize(g3d_map.map_w, g3d_map.map_h + 1, 0, 0);
                tool_window.select_tool_key_word = "";
            }
            break;

            case "resize_h_p1b":
            {
                g3d_map.Resize(g3d_map.map_w, g3d_map.map_h + 1, 0, -1);
                tool_window.select_tool_key_word = "";
            }
            break;

            case "resize_w_p1":
            {
                g3d_map.Resize(g3d_map.map_w + 1, g3d_map.map_h, -1, 0);
                tool_window.select_tool_key_word = "";
            }
            break;

            case "resize_w_p1b":
            {
                g3d_map.Resize(g3d_map.map_w + 1, g3d_map.map_h, 0, 0);
                tool_window.select_tool_key_word = "";
            }
            break;
            }
        }
Example #10
0
        public void Run()
        {
            var game_main = GameMain.GetInstance();
            var g3d_map   = game_main.g3d_map;

            // まず移動させよう
            // 移動範囲を表示、算出して
            move_area.Check(select_unit.map_x, select_unit.map_y, select_unit.bt.status["MOVE"].now, select_unit.bt.status["JUMP"].now);

            // 移動できる場所をリストアップ
            var move_point_list = new List <MovePoint>();

            for (var mx = 0; mx < move_area.map_w; mx++)
            {
                for (var my = 0; my < move_area.map_h; my++)
                {
                    if (move_area.IsInside(mx, my))
                    {
                        var mp = new MovePoint();
                        mp.map_x      = mx;
                        mp.map_y      = my;
                        mp.evaluation = 0; //とりあえず初期値
                        move_point_list.Add(mp);
                    }
                }
            }
            { // 移動しない場合
                var mp = new MovePoint();
                mp.map_x = select_unit.map_x;
                mp.map_y = select_unit.map_y;
                move_point_list.Add(mp);
            }

            // 移動できる場所を判定
            MovePoint max_mp        = null;
            var       max_evalution = 0.0;

            foreach (var mp in move_point_list)
            {
                var evalution = 0.0;
                CalcMoveEvalution(mp);
                evalution = mp.evaluation * 3;
                var rs = CalcRangeStatus(mp.map_x, mp.map_y, false);
                evalution += (-rs.evaluation_min) / 5 + (-rs.evaluation_avg) / 10;

                //Console.WriteLine("{0},{1} ({2}) {3}  {4}", mp.map_x,mp.map_y, mp.evaluation, rs.evaluation_min, rs.evaluation_avg);

                if (max_mp == null || max_evalution < evalution)
                {
                    max_evalution = evalution;
                    max_mp        = mp;
                }
            }
            Thread.Sleep(100);

            // 移動を実行
            if (max_mp.map_x != select_unit.map_x || max_mp.map_y != select_unit.map_y)
            {
                var t = new STask((param) =>
                {
                    select_unit.Move(max_mp.map_x, max_mp.map_y, true);
                    GameMain.GetInstance().g3d_map.ClearRangeAreaEffect();
                }, null);
                STaskManager.Add(t);
                t.WaitEnd();
            }
            Console.WriteLine("pos " + select_unit.map_x + "," + select_unit.map_y);

            Thread.Sleep(100);
            // 行動を決める
            {
                var action_datas = new ActionDatas();
                int num, effective_point_avg, effective_point_max;
                if (IsExistActionTarget(max_mp.map_x, max_mp.map_y, out num, out effective_point_avg, out effective_point_max, action_datas))
                {
                    Console.WriteLine("----A");
                    Console.WriteLine("pos " + select_unit.map_x + "," + select_unit.map_y);
                    var t = new STask((param) =>
                    {
                        var a  = action_datas.actions[0];
                        var ad = ActionDataManager.GetActionData(a.command);

                        var target_unit = game_main.unit_manager.GetUnit(a.target_map_x, a.target_map_y);
                        if (target_unit != null)
                        {
                            game_main.user_interface.SetStatusUnit(target_unit);
                        }

                        Console.WriteLine("DoAction {0} {1} {2} {3}", a.command, ad.range_type, select_unit.name, a.target.name);
                        scene_battle.DoAction(a.command, ad.range_type, select_unit, a.target_map_x, a.target_map_y, false);
                    }, null);
                    Console.WriteLine("----B");
                    Console.WriteLine("pos " + select_unit.map_x + "," + select_unit.map_y);
                    STaskManager.Add(t);
                    Console.WriteLine("----C");
                    Console.WriteLine("pos " + select_unit.map_x + "," + select_unit.map_y);
                    t.WaitEnd();
                }
            }
            Thread.Sleep(100);
            g3d_map.ClearRangeAreaEffect();

            //Thread.Sleep(1000);
            //scene_battle.NextUnitTurn();

            is_thread_end = true;
            Console.WriteLine("BattleAI Run End");
        }