beginoutdoorscript;

variables;

int choice;
short w;

body;

beginstate INIT_STATE;
// This state called whenever this section is loaded into memory.
break;

beginstate START_STATE;

break;

beginstate 10;
        if (get_flag(2,9) == 1) {
                reset_dialog();
                add_dialog_str(0,"You return to the former troglodyte camp. The place has been completely cleaned out. A quick search reveals nothing of value.",0);
                run_dialog(1);
                end();
        }
        if (get_flag(2,9) == 0) {
                reset_dialog();
                add_dialog_str(0,"There is a partially-completed troglodyte encampment here. Shortly after arriving, a small band of troglodytes marches out and blocks you from entering. What happens next is up to you.",0);
                add_dialog_choice(0,"Attack the troglodytes.");
                add_dialog_choice(1,"Leave the troglodytes.");
                set_flag(2,9,1);
                choice = run_dialog(1);
        }
        if (choice == 1) {
                create_out_spec_enc(1);
                end();
        }
        if (choice == 2) {
                reset_dialog();
                add_dialog_str(0,"You walk away from the troglodytes, keeping an eye on them as you leave. Suddenly, a blast of cold hits near you. A pack of eyebeasts has flown out of the cloud, intent on smashing the encampment.",0);
                add_dialog_str(1,"When the eyebeasts saw you, they added you to their target list. The troglodytes rush over to you, intending to join the fight against the common enemy.",0);
                run_dialog(1);
                create_out_spec_enc(0);
                end();
        }
break;

beginstate 11;
        reset_dialog();
        //add_dialog_str(0,"The troglodytes defeated, you search their camp for loot. Unfortunately, they didn't have much. Just after exiting the camp, a blast of cold hits near you. A pack of eyebeasts intended to destroy the camp, but decide that you're a better target. They rapidly descend.",0);
        add_dialog_str(0,"The troglodytes defeated, you search their camp for loot. Unfortunately, they didn't have much. Just after exiting the camp, a blast of cold hits near you. A pack of eyebeasts intended to destroy the camp, but decide to attack you instead.",0);
        run_dialog(1);
        create_out_spec_enc(2);
break;

beginstate 12;
        reset_dialog();
        //add_dialog_str(0,"You run away from the camp, and successfully escape. Looking back, you see the eyebeasts pounding the camp into rubble. You don't think any of the troglodytes survived. The eyebeasts are more interested in destroying the camp than they are in hunting you down.",0);
        add_dialog_str(0,"You successfully escape from the camp. Looking back, you see the eyebeasts pounding the camp into rubble. You don't think any of the troglodytes survived. The eyebeasts are more interested in destroying the camp than they are in hunting you down.",0);
        run_dialog(1);
break;

beginstate 13;
        reset_dialog();
        add_dialog_str(0,"After defeating the eyebeasts, the few remaining troglodytes come over to you and thank you for your assistance. They inform you that they will be leaving soon, but can strengthen your knowledge with several spells for 5000 coins.",0);
        if (coins_amount() >= 5000) {
                add_dialog_choice(0,"Pay 5000 coins for magical training.");
        }
        add_dialog_choice(1,"Decline the offer.");
        choice = run_dialog(1);
        if (choice == 1) {
                reset_dialog();
                add_dialog_str(0,"The troglodytes spend a couple of hours improving your skill with several offensive spells. If you aren't too trained in those spells already, you will be able to do more damage to your enemies.",0);
                pay_coins(5000);
                while (w < 4) {
                        if (get_spell_level(w,0,0) < 8) {
                                change_spell_level(w,0,0,1); //firebolt
                        }
                        if (get_spell_level(w,0,6) < 7) {
                                change_spell_level(w,0,6,1); //ice lances
                        }
                        if (get_spell_level(w,0,10) < 6) {
                                change_spell_level(w,0,10,1); //lightning spray
                        }
                        if (get_spell_level(w,0,16) < 5) {
                                change_spell_level(w,0,10,1); //fireblast
                        }
                        if (get_spell_level(w,0,19) < 4) {
                                change_spell_level(w,0,10,1); //arcane blow
                        }
                        w = w + 1;
                }
                end();
        }
        if (choice == 2) {
                end();
        }
break;