name		AllClear
type		none
lifespan	1


anim idle
@script
    void self = getlocalvar("self");
    int Compl1 = getglobalvar("Cobra");
    int Compl2 = getglobalvar("Silent");
    int Compl3 = getglobalvar("Spring");
    int Compl4 = getglobalvar("FLAGG");
    int Compl5 = getglobalvar("Defiant");
    int Compl6 = getglobalvar("Wings");
    int ComplA = getglobalvar("AllClear");

    if( Compl1==NULL() ){
      Compl1 = 0;
    }
    if( Compl2==NULL() ){
      Compl2 = 0;
    }
    if( Compl3==NULL() ){
      Compl3 = 0;
    }
    if( Compl4==NULL() ){
      Compl4 = 0;
    }
    if( Compl5==NULL() ){
      Compl5 = 0;
    }
    if( Compl6==NULL() ){
      Compl6 = 0;
    }
    if( ComplA==NULL()) {
      ComplA = 0;
    }

    if(frame==1){
      if( ComplA>=10){
      ComplA = 15;
      setglobalvar("AllClear", 15);
      } else if( Compl1>=1 && Compl2>=1 && Compl3>=1 && Compl4>=1 && Compl5>=1 && Compl6>=1){
      ComplA = 10;
      setglobalvar("AllClear", 10);
      }
    }
    if(frame==2){
      void file = createfilestream();

      //Main Mission Complete
      filestreamappend(file, Compl1, 1); //the 1 at the end is nb to make sure it starts on the first line
      //Silent Castle Complete
      filestreamappend(file, Compl2, 0);
      //Springfield Battle Complete
      filestreamappend(file, Compl3, 0);
      //Defend USS FLAGG Complete
      filestreamappend(file, Compl4, 0);
      //Defiant Space Complete
      filestreamappend(file, Compl5, 0);
      //Wings of Fury Complete
      filestreamappend(file, Compl6, 0);
      //All Missions Complete
      filestreamappend(file, ComplA, 0);
      savefilestream(file, "save.txt");
    }
    if(frame==3){
      if(ComplA==10){
        setglobalvar("AllClear", 15);
        jumptobranch("AllClear",1);
      }
    }
    if(frame==4){
      killentity(self); //Suicide!
    }
@end_script
	delay	5
	offset	1 1
	frame	data/chars/misc/empty.gif
	frame	data/chars/misc/empty.gif
	frame	data/chars/misc/empty.gif
	frame	data/chars/misc/empty.gif
