begintownscript;

variables;

int i,j,k,r1,choice,pc_num;

body;

beginstate INIT_STATE;
        //code called when entering
        if (get_flag(0,13) == 0) {
                reset_dialog();
                add_dialog_str(0,"You walk towards the glowing crystal you saw earlier. When you get close, you see trees you didn't see before. Something, likely the crystal, was concealing this forest from prying eyes.",0);
                add_dialog_str(1,"The forest is very dense, and you may have difficulties getting around. Of more interest, however, are the forest spirits. You can see two of them, and they don't look friendly.",0);
                run_dialog(1);
                set_flag(0,13,1);
        }
        add_range_to_group(6,24,1);
        if (get_flag(0,13) == 2) {
                set_attitude(1001,4);
        }
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
        //code called every turn
break;

beginstate 10;
        reset_dialog();
        add_dialog_str(0,"You finally reach the glowing crystal at the center of the forest, and feel  like the crystal wants to touch your mind. What effect this would have, you don't know.",0);
        add_dialog_choice(0,"Let the crystal touch your mind.");
        add_dialog_choice(1,"Push it away.");
        add_dialog_choice(2,"Try to smash the crystal.");
        choice = run_dialog(1);
        if (choice == 2) {
                reset_dialog();
                add_dialog_str(0,"Pushing the crystal out of your mind costs you some spell points.",0);
                change_char_energy(1000,5);
                run_dialog(0);
                end();
        }
        if ((choice == 1) && (get_flag(0,13) == 2)) {
                reset_dialog();
                add_dialog_str(0,"The crystal scans your mind briefly, and then withdraws. You don't feel anything different.",0);
                run_dialog(0);
                end();
        }
        if ((choice == 1) && (get_flag(0,13) < 2)) {
                reset_dialog();
                add_dialog_str(0,"The crystal scans your mind briefly, looking for something. You aren't sure what it's looking for. Eventually, it's satisfied, and withdraws.",0);
                add_dialog_str(1,"Before withdrawing, the crystal improved your knowledge of some spells, and you also get the feeling that you can pass through the forest safely.",0);
                run_dialog(1);
                set_attitude(1001,4);
                set_flag(0,13,2);
                inc_flag(0,18,1);
                pc_num = 0;
                while (pc_num < 4) {
                        if (get_stat(pc_num,11) > 1 && get_spell_level(pc_num,1,0) < 6) {
                                change_spell_level(pc_num,1,0,1);
                        }
                        if (get_stat(pc_num,11) > 1 && get_spell_level(pc_num,1,1) < 6) {
                                change_spell_level(pc_num,1,1,1);
                        }
                        if (get_stat(pc_num,11) > 1 && get_spell_level(pc_num,1,2) < 6) {
                                //change_spell_level(pc_num,1,2,1);
                        }
                        if (get_stat(pc_num,11) > 5 && get_spell_level(pc_num,1,7) < 6) {
                                change_spell_level(pc_num,1,7,1);
                        }
                        if (get_stat(pc_num,11) > 6 && get_spell_level(pc_num,1,8) < 6) {
                                change_spell_level(pc_num,1,8,1);
                        }
                        if (get_stat(pc_num,11) > 8 && get_spell_level(pc_num,1,10) < 6) {
                                change_spell_level(pc_num,1,10,1);
                        }
                        if (get_stat(pc_num,11) > 8 && get_spell_level(pc_num,1,11) < 6) {
                                change_spell_level(pc_num,1,11,1);
                        }
                        if (get_stat(pc_num,11) > 9 && get_spell_level(pc_num,1,12) < 6) {
                                change_spell_level(pc_num,1,12,1);
                        }
                        if (get_stat(pc_num,11) > 13 && get_spell_level(pc_num,1,16) < 6) {
                                change_spell_level(pc_num,1,16,1);
                        }
                        if (get_stat(pc_num,11) > 16 && get_spell_level(pc_num,1,18) < 6) {
                                change_spell_level(pc_num,1,18,1);
                        }
                        pc_num = pc_num + 1;
                }
        }
        if ((choice == 1) && (get_flag(0,13) == 3)) {
                reset_dialog();
                add_dialog_str(0,"The crystal scans your mind, and doesn't like what it finds. It quickly wipes your mind and takes control of you.",0);
                add_dialog_str(1,"After the crystal has you serve it for a few decades, you die.",0);
                run_dialog(0);
                kill_char(1000,2,0);
                end();
        }
        if (choice == 3) {
                reset_dialog();
                add_dialog_str(0,"The moment you approach the crystal with the intent to smash it, it forces its way into your mind, wipes it, and takes control of you.",0);
                add_dialog_str(1,"After the crystal has you serve it for a few decades, you die.",0);
                run_dialog(0);
                kill_char(1000,2,0);
                end();
        }
break;

beginstate 11;
        if (get_flag(0,15) == 0) {
                reset_dialog();
                add_dialog_str(0,"While walking around the forest, you trip over something. You look at the object you tripped over, and see that it's a key. You take the key.",0);
                run_dialog(1);
                change_spec_item(1,1);
                set_flag(0,15,1);
        }
break;