All pastes #876914 Raw Edit

initiate.exe

public text v1 · immutable
#876914 ·published 2008-01-29 04:50 UTC
rendered paste body
Program Initiate;

Uses crt, sysutils, dos, windows, process;

Type
  TChar = Record //type char
    levid: String; //used for checking if current record is correct.
    name: String; //name
    password: String; //password
    weight: integer; //current weight being carried
    mweight: integer; //max weight that can be carried
    oweight: integer; //weight before equip
    hp: integer; //health point
    mhp: integer; //max hp
    mp: integer; //mind power
    mmp: integer; //max mp
    oatk: integer; //atk before weapon. used in equipping
    atk: integer; //attack
    def: integer; //defense
    ospd: integer; //spd before weapon. used in equipping
    spd: integer; //speed
    lev: integer; //level
    levup : boolean;
    race: String; //race
    location: String; //origin on map, IE, eastern, southern, western, nothern, underdark
    weapon: String; //weapon currently equipped
    armor: String; //armor set. no individual pieces
    exp: integer; //experience
    exp_rate: real; //experience rate, is multiplier of received exp
    sex: String; //sex/gender
    luck: integer; //Chance variable, luck
    weapons: Array[1..51] Of String; //all of the below must be 1 more than they actually are, so the page system will work.
    armors: Array[1..51] Of String;
    potions: Array[1..51] Of String;
    spellbooks: Array[1..51] Of String;
    items: Array[1..51] Of String;
  End;

  techar = Record //type enemy char
    weight: integer;
    mweight: integer;
    oweight: integer;
    hp: integer;
    mhp: integer;
    mp: integer;
    mmp: integer;
    atk: integer;
    oatk: integer;
    def: integer;
    spd: integer;
    ospd: integer;
    lev: integer;
    levup : boolean;
    race: String;
    weapon: String;
    armorset: String;
    exp: integer;
    exp_rate: real;
    sex: String;
    name: String;
    weapons: Array[1..51] Of String;
    armors: Array[1..51] Of String;
    potions: Array[1..51] Of String;
    spellbooks: Array[1..51] Of String;
    items: Array[1..51] Of String;
  End;

{for future reference:
A record must have a variable reference, IE, a variable of the type record, or it will not allow functions to be performed on the record. IE, var char :
tchar; is a variable char of type record tchar. You cannot reador write this, but you can use this to write to a data file :) }

Var
//records
  char              : tchar; //character
  echar             : techar; //enemy_character
  temp              : tchar;


//main menu stuff
  gametype          : integer; //1, 2, 3, 4, or 5: New, Load, Password, Quit, and Credits.

//loading stuff
  auth              : boolean; //is the user authorized?
  username          : String; //actual username in game
  user              : String; //comparison for loading
  password          : String; //actual password in game
  pass              : String; //comparison for loading
  save              : String; //used for multiple purposes, Check if user wants to save (y/n),
               //check type of save (new registration, current level/mission)

//misc stuff
  x, y, z           : integer;
  entry             : String;
  entryi            : integer;
  scroll            : Array[1..21] Of String;
  txt               : text; //for text file storage
  dat               : File Of tchar; //used for saving save files. writes record to file.
  choice            : integer; //general use, for picking menu items etc
  sec, hour, min, ms: word; //time, used for random number generation. ms = milli-seconds
  hwindow           : longword; //for opening external apps
  turncomplete      : boolean; //is players turn complete? if not, return to menu
  listnuma          : integer; //page system for the inventory
  listnumx          : integer; //page system for the inventory
  listnumz          : integer; //page system for the inventory
  xy                : integer;

//inventory functions

  weaponid          : integer; //when trying to equip a new weapon, save the weaponid to file so external dll can read it
  potionid          : integer;
  potion            : string; //name of potion
  weapon            : String; //name of weapon to equip.
  randwep           : integer; //the random weapon to be picked when you win a battle.
  randpot           : integer;
  weaponreceived    : boolean; //you received a weapon from your battle, true, else false.
  potionreceived    : boolean;

//char functions

  curturn           : integer; //current turn, p1 or p2
  spd_com           : String; //speed comparison
  spd_bool          : boolean; //speed comparison
  chance            : boolean;
//Notes:
//MP is not Magical Power as normally thought, but rather Mind Power.
//When you cast a spell, it drains your mind power, or resistance to
//magical attacks/attack ability. It does not affect your actual attack
//but rather makes you MORE vulnerable to a magical attack. As your mind
//power decreases, so does the damage dealt by magical attacks.

//battle functions
  critical          : boolean; //if it is a critical hit (triple the atk or more) then true
  atkbonus          : integer;
  mpbonus           : integer;
  defbonus          : integer;
  expbonus          : integer;
  lchar             : boolean; //did Char lose in battle?
  lechar            : boolean; //did eChar lose in battle?

//external procedures.
Procedure inventory; external 'inventory.dll';
Procedure returnweapon; external 'inventory.dll';
procedure potions; external 'inventory.dll';
procedure returnpotion; external 'inventory.dll';
procedure battledisp; forward;

//interaction stuff

Function TopMenu: Integer;
Begin
  textcolor(2);
  Write('F');
  Delay(100);
  Write('i');
  Delay(100);
  write('r');
  Delay(100);
  Write('s');
  Delay(100);
  write('t');
  Delay(100);
  Write(' ');
  Delay(100);
  write('I');
  Delay(100);
  Write('n');
  Delay(100);
  write('i');
  Delay(100);
  Write('t');
  Delay(100);
  write('i');
  Delay(100);
  Write('a');
  Delay(100);
  write('t');
  Delay(100);
  Writeln('e');
  Delay(100);
  Writeln;
  writeln('1 New Game');
  Delay(100);
  writeln('2 Load Game');
  Delay(100);
  writeln('3 Password');
  Delay(100);
  writeln('4 Quit');
  Delay(100);
  writeln('5 Credits');
  delay(100);
  textcolor(7);
  readln(topmenu);
End;

Procedure dispback;
//sets up the display for writing the backpack list to. Mostly
//just for visual effects, as its all text based, after all...
Begin
  GotoXy(1, 1);
  Writeln('+');
    {Bottom Side}
  For entryi := 2 To 79 Do
  Begin
    gotoxy(entryi, 23);
    writeln('-');
  End;
  GotoXy(80, 23);
  Writeln('+');

   {Top Side}
  For entryi := 2 To 79 Do
  Begin
    gotoxy(entryi, 1);
    writeln('-');
  End;
  GotoXy(80, 1);
  Writeln('+');

   {entrybar}
  textbackground(blue);
  For entryi := 1 To 80 Do
  Begin
    gotoxy(entryi, 24);
    writeln(' ');
  End;
  textbackground(black);
   {Right/Left Side Removed to make easier formatting}
  gotoxy(1, 23);
  writeln('+');
  GotoXy(5, 23);
  Writeln('v');
  gotoxy(5, 22);
  writeln('Press Enter Continue...');
End;

Procedure PickRandomWeapon;
begin
  echar.weapons[1] := 'Fist';
  char.weapons[1] := 'Fist';
  randomize;
  randwep := random(5);
  assign(txt,'io.dat');
  rewrite(txt);
  writeln(txt,randwep);
  close(txt);
  returnweapon;
  assign(txt,'io.dat');
  reset(txt);
  randwep := 1;
  repeat
    if char.weapons[randwep] <> '' then randwep := randwep+1;
  until char.weapons[randwep] = '';
  readln(txt,char.weapons[randwep]);
  close(txt);
  if char.weapons[randwep] = 'Fist' then begin
    WeaponReceived := false;
    char.weapons[randwep] := '';
  end else begin
    WeaponReceived := true;
  end;
end;

Procedure PickRandomPotion;
begin
  randomize;
  randpot := random(5);
  assign(txt,'io.dat');
  rewrite(txt);
  writeln(txt,randwep);
  close(txt);
  returnpotion;
  assign(txt,'io.dat');
  reset(txt);
  randpot := 1;
  repeat
    if char.potions[randpot] <> '' then randpot := randpot+1;
  until char.potions[randpot] = '';
  readln(txt,char.potions[randpot]);
  close(txt);
  if char.potions[randpot] = '' then begin
    PotionReceived := false;
    char.potions[randpot] := '';
  end else begin
    PotionReceived := true;
  end;
end;

Procedure displaybackpack(target: integer; btype: integer);
//btype is the type of contents to display. in the array,
//btype0 is your weapons, btype1 your armor sets,
//btype2 your potions, btype3 your spellbooks,
//and btype4 all misc items.
Begin
  clrscr;
  If (target = 0) And (btype = 0) Then
  Begin
    choice := 1;
    listnuma := 16;
    xy := 2;
    Repeat
      dispback;
      If char.weapons[choice] <> '' Then
      Begin
        gotoxy(1, xy);
        Writeln('Slot ', choice, ': ', char.weapons[choice]);
        xy := xy + 1;
        turncomplete := false;
        choice := choice + 1;
      End
      Else
      Begin
        turncomplete := true;
      End;
    Until (choice = listnuma + 1) Or (turncomplete = true);
    xy := 2;
    readln;
    ClrScr;
    If turncomplete = false Then
    Begin
      listnumx := listnuma;
      listnumz := listnuma + listnuma;
      Repeat
        xy := 2;
        Repeat
          dispback;
          If char.weapons[choice] = '' Then turncomplete := true;
          If char.weapons[choice] <> '' Then
          Begin
            gotoxy(1, xy);
            Writeln('Slot ', choice, ': ', char.weapons[choice]);
            xy := xy + 1;
            choice := choice + 1;
            turncomplete := false;
          End;
        Until (choice = listnumz) Or (turncomplete = true);
        listnumz := listnumz + listnuma;
        readln;
        ClrScr;
      Until turncomplete = true;
    End; //turn complete = false then begin
  End else if (target = 0) and (btype = 1) then begin //end target = 0, btype = 0

  end else if (target = 0) and (btype = 2) then begin
    choice := 1;
    listnuma := 16;
    xy := 2;
    Repeat
      dispback;
      If char.potions[choice] <> '' Then
      Begin
        gotoxy(1, xy);
        Writeln('Slot ', choice, ': ', char.potions[choice]);
        xy := xy + 1;
        turncomplete := false;
        choice := choice + 1;
      End
      Else
      Begin
        turncomplete := true;
      End;
    Until (choice = listnuma + 1) Or (turncomplete = true);
    xy := 2;
    readln;
    ClrScr;
    If turncomplete = false Then
    Begin
      listnumx := listnuma;
      listnumz := listnuma + listnuma;
      Repeat
        xy := 2;
        Repeat
          dispback;
          If char.potions[choice] = '' Then turncomplete := true;
          If char.potions[choice] <> '' Then
          Begin
            gotoxy(1, xy);
            Writeln('Slot ', choice, ': ', char.potions[choice]);
            xy := xy + 1;
            choice := choice + 1;
            turncomplete := false;
          End;
        Until (choice = listnumz) Or (turncomplete = true);
        listnumz := listnumz + listnuma;
        readln;
        ClrScr;
      Until turncomplete = true;
    End; //turn complete = false then begin
  end;
  ////////////////////////////////////////////////////
  If (target = 1) And (btype = 0) Then
  Begin
    choice := 1;
    listnuma := 16;
    xy := 2;
    Repeat
      dispback;
      If echar.weapons[choice] <> '' Then
      Begin
        gotoxy(1, xy);
        Writeln('Slot ', choice, ': ', echar.weapons[choice]);
        xy := xy + 1;
        turncomplete := false;
        choice := choice + 1;
      End
      Else
      Begin
        turncomplete := true;
      End;
    Until (choice = listnuma + 1) Or (turncomplete = true);
    xy := 2;
    readln;
    ClrScr;
    If turncomplete = false Then
    Begin
      listnumx := listnuma;
      listnumz := listnuma + listnuma;
      Repeat
        xy := 2;
        Repeat
          dispback;
          If echar.weapons[choice] = '' Then turncomplete := true;
          If echar.weapons[choice] <> '' Then
          Begin
            gotoxy(1, xy);
            Writeln('Slot ', choice, ': ', echar.weapons[choice]);
            xy := xy + 1;
            choice := choice + 1;
            turncomplete := false;
          End;
        Until (choice = listnumz) Or (turncomplete = true);
        listnumz := listnumz + listnuma;
        readln;
        ClrScr;
      Until turncomplete = true;
    End; //turn complete = false then begin
  End else if (target = 1) and (btype = 1) then begin //end target = 0, btype = 0

  end else if (target = 1) and (btype = 2) then begin
    choice := 1;
    listnuma := 16;
    xy := 2;
    Repeat
      dispback;
      If echar.potions[choice] <> '' Then
      Begin
        gotoxy(1, xy);
        Writeln('Slot ', choice, ': ', echar.potions[choice]);
        xy := xy + 1;
        turncomplete := false;
        choice := choice + 1;
      End
      Else
      Begin
        turncomplete := true;
      End;
    Until (choice = listnuma + 1) Or (turncomplete = true);
    xy := 2;
    readln;
    ClrScr;
    If turncomplete = false Then
    Begin
      listnumx := listnuma;
      listnumz := listnuma + listnuma;
      Repeat
        xy := 2;
        Repeat
          dispback;
          If echar.potions[choice] = '' Then turncomplete := true;
          If echar.potions[choice] <> '' Then
          Begin
            gotoxy(1, xy);
            Writeln('Slot ', choice, ': ', echar.potions[choice]);
            xy := xy + 1;
            choice := choice + 1;
            turncomplete := false;
          End;
        Until (choice = listnumz) Or (turncomplete = true);
        listnumz := listnumz + listnuma;
        readln;
        ClrScr;
      Until turncomplete = true;
    End; //turn complete = false then begin
  end;; //target = 1, btype = 0

  turncomplete := false;
End;

Procedure savegame;
Begin
  assign(txt, 'data.dat');
  append(txt);
  writeln(txt, '@');
  writeln(txt, char.name);
  writeln(txt, char.password);
  writeln(txt, char.levid);
  writeln(txt, char.weight);
  writeln(txt, char.mweight);
  writeln(txt, char.hp);
  writeln(txt, char.mhp);
  writeln(txt, char.mp);
  writeln(txt, char.mmp);
  writeln(txt, char.atk);
  writeln(txt, char.def);
  writeln(txt, char.spd);
  writeln(txt, char.lev);
  writeln(txt, char.race);
  writeln(txt, char.location);
  writeln(txt, char.weapon);
  writeln(txt, char.exp);
  writeln(txt, char.exp_rate);
  writeln(txt, char.sex);
  writeln(txt, '!');
  close(txt);
End;

Procedure loadchar;
Begin
  textcolor(2);
  assign(txt, 'data.dat');
  reset(txt);
  clrscr;
  writeln('Please enter your username.');
  textcolor(12);
  readln(user);
  textcolor(2);
  writeln('Please enter your password.');
  textcolor(12);
  readln(pass);
  textcolor(2);
  Repeat
    readln(txt, entry);
    If entry = '@' Then
    Begin
      readln(txt, char.name);
      readln(txt, char.password);
      //check user/pass
      If (char.name = user) And (char.password = pass) Then
      Begin
       //user and pass correct
        readln(txt, char.levid);
        readln(txt, char.weight);
        readln(txt, char.mweight);
        readln(txt, char.hp);
        readln(txt, char.mhp);
        readln(txt, char.mp);
        readln(txt, char.mmp);
        readln(txt, char.atk);
        readln(txt, char.def);
        readln(txt, char.spd);
        readln(txt, char.lev);
        readln(txt, char.race);
        readln(txt, char.location);
        readln(txt, char.weapon);
        readln(txt, char.exp);
        readln(txt, char.exp_rate);
        readln(txt, char.sex);
      End
      Else
        Repeat readln(txt, entry);
        Until entry = '!';
    End;
  Until (user = char.name) And (pass = char.password) Or (eof(txt));
  If (user = char.name) And (pass = char.password) Then auth := true;
  If (eof(txt)) Then
  Begin
    auth := false;
  End;
  //authentication complete
  close(txt);
End;

Procedure unloadchar;
//used for unloading the character before loading a new one, to prevent conflicts.
Begin
  char.name := '';
  char.password := '';
  char.levid := '';
  char.weight := 0;
  char.mweight := 0;
  char.hp := 0;
  char.mp := 0;
  char.atk := 0;
  char.def := 0;
  char.spd := 0;
  char.lev := 0;
  char.race := '';
  char.location := '';
  char.weapon := '';
  char.exp := 0;
  char.exp_rate := 0;
  char.sex := '';
End;

//Character Stuff

Procedure IOInventory(target: integer);
Begin
 ///////////////////////////
  if weapon = 'FIST' then
  begin
    weaponid := 0;
  end else if weapon = 'SWORD' Then Begin
    weaponid := 1;
  End Else If weapon = 'AXE' Then  Begin
    weaponid := 2;
  End Else If weapon = 'DAGGER' Then Begin
    weaponid := 3;
  End Else If weapon = 'TWO HANDED SWORD' Then Begin
    weaponid := 4;
  End Else If weapon = 'BASTARD SWORD' Then Begin
    weaponid := 5;
  End;
 ///////////////////////////

  assign(txt, 'io.dat');
  rewrite(txt);
  writeln(txt, target);
  writeln(txt, weaponid);
  If target = 0 Then
  Begin //char.*
    char.oatk := char.atk;
    char.ospd := char.spd;
    char.oweight := char.weight;
    writeln(txt, char.atk); //char's atk
    writeln(txt, char.spd);
    writeln(txt, char.weight);
  End
  Else If target = 1 Then
  Begin //echar.e_*
    echar.oatk := echar.atk;
    echar.ospd := echar.spd;
    echar.oweight := echar.weight;
    writeln(txt, echar.atk);
    writeln(txt, echar.spd);
    writeln(txt, echar.weight);
  End;
  close(txt);
  Inventory;
  assign(txt, 'io.dat');
  reset(txt);
  If target = 0 Then
  Begin
    readln(txt, char.weapon);
    if (char.weapon <> 'Fist') and (char.weapon <> '') then begin
      readln(txt, char.atk);
      readln(txt, char.spd);
      readln(txt, char.weight);
    end else begin
      char.atk := char.oatk;
      char.spd := char.ospd;
      char.weight := char.oweight;
    end;
  End
  Else If target = 1 Then
  Begin
    readln(txt, echar.weapon);
    if (echar.weapon <> 'Fist') and (echar.weapon <> '') then begin
      readln(txt, echar.atk);
      readln(txt, echar.spd);
      readln(txt, echar.weight);
    end else begin
      echar.atk := echar.oatk;
      echar.spd := echar.ospd;
      echar.weight := echar.oweight;
    end;
  End;
  close(txt);
End;

Procedure IOPotions(target: integer);
var potiontarget,potiontype : string;
potiondamage: integer;
begin
  //determine potionid

  if potion = 'No Potion' then potionid := 0 else if potion = 'Small HP Vial' then potionid := 1
  else if potion = 'Small MP Vial' then potionid := 2 else if potion = 'Large HP Vial' then potionid := 3
  else if potion = 'Large MP Vial' then potionid := 4 else if potion = 'Explosive Vial' then potionid := 5;

  /////////////////////
  assign(txt,'io.dat');
  rewrite(txt);
  writeln(txt,target);
  writeln(txt,potionid);
  close(txt);
  potions;
  assign(txt,'io.dat');
  reset(txt);
  readln(txt,potion);
  readln(txt,potiontype);
  readln(txt,potiontarget);
  readln(txt,potiondamage);
  close(txt);
  if potiontype = 'HEAL' then begin
    if target = 0 then begin
      battledisp;
      textcolor(12);
      Writeln('                  /________________________________\                            ');
      Writeln('                  |Type the number of your choice. |                            ');
      writeln('                  |1.. Attack With Melee           |                            ');
      writeln('                  |2.. Magic..                     |                            ');
      textcolor(2);
      Writeln('                  |3.. Use Potion..                |                            ');
      textcolor(12);
      Writeln('                  |4.. Menu..                      |                            ');
      writeln('                  \_v______________________________/                            ');
      textcolor(7);
      if potiontarget = 'HP' then begin
        gotoxy(21, 24);
        char.hp := char.hp+potiondamage;
        if char.hp > char.mhp then char.hp := char.mhp;
        write('You used a ',potion,' to heal ',potiondamage,' HP! You now have ',char.hp,' HP!');
        readln;
      end else if potiontarget = 'MP' then begin
        gotoxy(21, 24);
        char.mp := char.mp+potiondamage;
        if char.mp > char.mmp then char.mp := char.mmp;
        write('You used a ',potion,' to heal ',potiondamage,' MP! You now have ',char.mp,' MP!');
        read;
      end;
    end else if target = 1 then begin
      battledisp;
      textcolor(2);
      Writeln('                  /________________________________\                            ');
      Writeln('                  |Type the number of your choice. |                            ');
      writeln('                  |1.. Attack With Melee           |                            ');
      writeln('                  |2.. Magic..                     |                            ');
      textcolor(12);
      Writeln('                  |3.. Use Potion..                |                            ');
      textcolor(2);
      Writeln('                  |4.. Menu..                      |                            ');
      writeln('                  \_v______________________________/                            ');
      textcolor(7);
      if potiontarget = 'HP' then begin
        gotoxy(21, 24);
        echar.hp := echar.hp+potiondamage;
        if echar.hp > echar.mhp then echar.hp := echar.mhp;
        write(echar.name,' used a ',potion,' to heal ',potiondamage,'  HP! You now have ',echar.hp,' HP!');
        readln;
      end else if potiontarget = 'MP' then begin
        gotoxy(21, 24);
        echar.mp := echar.mp+potiondamage;
        if echar.mp > echar.mmp then echar.mp := echar.mmp;
        write(echar.name,' used a ',potion,' to heal ',potiondamage,' MP! You now have ',echar.mp,' MP!');
        readln;
      end;
    end;
  end;

  if potiontype = 'DAMAGE' then begin
    if target = 0 then begin  //p2 attacking p1
      battledisp;
      textcolor(2);
      Writeln('                  /________________________________\                            ');
      Writeln('                  |Type the number of your choice. |                            ');
      writeln('                  |1.. Attack With Melee           |                            ');
      writeln('                  |2.. Magic..                     |                            ');
      textcolor(12);
      Writeln('                  |3.. Use Potion..                |                            ');
      textcolor(2);
      Writeln('                  |4.. Menu..                      |                            ');
      writeln('                  \_v______________________________/                            ');
      textcolor(7);
      if potiontarget = 'HP' then begin
        gotoxy(21, 24);
        writeln(echar.name,' used a ',potion,' to inflict ',potiondamage,' damage on ',char.name,'s HP!');
        char.hp := char.hp-potiondamage;
      end else if potiontarget = 'MP' then begin
        gotoxy(21, 24);
        writeln(echar.name,' used a ',potion,' to inflict ',potiondamage,' damage on ',char.name,'s MP!');
        char.mp := char.mp-potiondamage;
      end;
    end else if target = 1 then begin  //p1 attacking p2
      battledisp;
      textcolor(12);
      Writeln('                  /________________________________\                            ');
      Writeln('                  |Type the number of your choice. |                            ');
      writeln('                  |1.. Attack With Melee           |                            ');
      writeln('                  |2.. Magic..                     |                            ');
      textcolor(2);
      Writeln('                  |3.. Use Potion..                |                            ');
      textcolor(12);
      Writeln('                  |4.. Menu..                      |                            ');
      writeln('                  \_v______________________________/                            ');
      textcolor(7);
      if potiontarget = 'HP' then begin
        gotoxy(21, 24);
        writeln(char.name,' used a ',potion,' to inflict ',potiondamage,' damage on ',echar.name,'s HP!');
        echar.hp := echar.hp-potiondamage;
      end else if potiontarget = 'MP' then begin
        gotoxy(21, 24);
        writeln(char.name,' used a ',potion,' to inflict ',potiondamage,' damage on ',echar.name,'s HP!');
        echar.mp := echar.mp-potiondamage;
      end;
    end;
  end;

end;

Procedure equipweapon(target: integer);
//if target = 0 then equip to player1, = 1 then player 2.
Begin
  clrscr;
  If target = 0 Then
  Begin
    If (char.weapon <> '') and (char.weapon <> 'Fist') Then
    Begin
      char.atk := char.oatk;
      char.spd := char.ospd;
      char.weight := char.oweight;
    End;
    clrscr;
    Writeln('Your backpack will now be displayed in a page format.');
    Writeln('Remember the slot # of the weapon you want to use,');
    writeln('as you will need it to equip your new weapon.');
    writeln('Press enter to continue.');
    readln;
    DisplayBackpack(0, 0);
  End
  Else If target = 1 Then
  Begin
    If (echar.weapon <> '') and (echar.weapon <> 'Fist') Then
    Begin
      echar.atk := echar.oatk;
      echar.spd := echar.ospd;
      echar.weight := echar.oweight;
    End;
    clrscr;
    Writeln('Your backpack will now be displayed in a page format.');
    Writeln('Remember the slot # of the weapon you want to use,');
    writeln('as you will need it to equip your new weapon.');
    writeln('Press enter to continue.');
    readln;
    DisplayBackpack(1, 0);
  End;
  clrscr;
  writeln('Ok, now what slot # do you wish to equip?');
  readln(entryi);
  If target = 0 Then
  Begin
    weapon := char.weapons[entryi];
    For entryi := 1 To length(weapon) Do
      weapon[entryi] := upcase(weapon[entryi]);
  End
  Else If target = 1 Then
  Begin
    weapon := echar.weapons[entryi];
    For entryi := 1 To length(weapon) Do
      weapon[entryi] := upcase(weapon[entryi]);
  End;
  IOInventory(target);
  If char.spd < 1 Then char.spd := 1;
  If echar.spd < 1 Then echar.spd := 3;
End;

Procedure equippotion(target: integer);
//if target = 0 then equip to player1, = 1 then player 2.
Begin
  clrscr;
  If target = 0 Then
  Begin
    clrscr;
    Writeln('Your backpack will now be displayed in a page format.');
    Writeln('Remember the slot # of the potion you want to use,');
    writeln('as you will need it to equip your new weapon.');
    writeln('Press enter to continue.');
    readln;
    DisplayBackpack(0, 2);
  End
  Else If target = 1 Then
  Begin
    clrscr;
    Writeln('Your backpack will now be displayed in a page format.');
    Writeln('Remember the slot # of the potion you want to use,');
    writeln('as you will need it to equip your new weapon.');
    writeln('Press enter to continue.');
    readln;
    DisplayBackpack(1, 2);
  End;
  clrscr;
  writeln('Ok, now what slot # do you wish to equip?');
  readln(entryi);
  If target = 0 Then
  Begin
    potion := char.potions[entryi];
    writeln('Potion : ',potion);
    delay(1500);
    {For entryi := 1 To length(potion) Do
      potion[entryi] := upcase(potion[entryi])}
  End
  Else If target = 1 Then
  Begin
    potion := echar.potions[entryi];
    writeln('Potion : ',potion);
    delay(1500);
    {For entryi := 1 To length(potion) Do
      potion[entryi] := upcase(potion[entryi]);}
  End;
  IOPotions(target);
End;

Procedure equiparmor(target: integer);
Begin

End;

Procedure AddRandNum(target: integer; stat: String);
Var
  store             : integer;
//if target is 0, then the number should be added
//to player1/char. Likewise, if it is 1, then it
//should be added to echar/player2. Stat refers
//to the stat this should be added to. Acceptable
//values are: ATK, DEF, MP, and EXP.
Begin
  DecodeTime(Time, hour, min, sec, ms);
  If target = 0 Then
  Begin
    if stat = 'CHANCE' then begin
      randomize;
      store := random(50);
      if store > 40 then store := 0 else if store > 30 then store := 1 else if store > 20 then store := 2 else if store > 10 then store := 3 else if store > 4 then store := 4;

      case store of
        0 : begin
              store := char.atk-char.spd+char.weight-char.def*char.luck;
              if store > 20+char.luck then chance := true;
              if store div 2 > 15+char.luck then chance := false;
              randomize;
              if (chance = false) and (store * 2+char.luck > 25+random(15)) and (store * 2 < random(15)) then chance := true;
              if store > random (50) then chance := false;
              if random(50) > random(250) then chance := true;
              expbonus := store;
            end;

        1 : begin
              store := char.atk-char.spd+char.weight-char.def;
              if store > 20 then chance := true;
              if store div 2 > 15 then chance := false;
              randomize;
              if (chance = false) and (store * 2 > 25) and (store * 2 < random(15)) then chance := true;
              if store > random (50) then chance := false;
              if random(50) > random(250) then chance := true;
              expbonus := store;
            end;

        2 : begin
              store := char.atk+char.spd-char.mweight+char.def;
              if store >= 20 then chance := true;
              if store div 3 > 15 then chance := false;
              randomize;
              if (chance = false) and (store * 2 > 25) and (store * 2 < random(15)) then chance := true;
              if store > random (80) then chance := false;
              randomize;
              if random(85) > random(1000) then chance := true;
              expbonus := store;
            end;

        3 : begin
              store := char.atk-char.spd+char.mweight-char.def;
              if store >= 40 then chance := true;
              if store div 5 > 15 then chance := false;
              randomize;
              if (chance = false) and (store div 3 > 25) or (store * 2 < random(100)) then chance := true;
              randomize;
              if store > random (80) then chance := false;
              randomize;
              if random(85) < random(random(1000)) then chance := true;
              expbonus := store;
            end;

        4 : begin
              randomize;
              store := random((random(100)*(random(10)) * random(random(200))));
              if store > 50 then chance := true;
              if store < 50 then chance := false;
              randomize;
              if (store * 2) > random(5000) then chance := true;
              if store div 3 > char.luck then chance := false;
              expbonus := store;
            end;
      end;
    end;
    If stat = 'ATK' Then
    Begin
      randomize;
      store := char.atk - random(echar.def)+1;
      randomize;
      store := store + random(store div 2)+1;
      if store = store + store div 2 then critical := true;
      randomize;
      store := store - random(char.spd*2)+1;
      randomize;
      store := store + random(char.atk)+1;
      atkbonus := store;
    End
    Else If stat = 'DEF' Then
    Begin
      randomize;
      store := char.def - char.atk;
      store := store + char.spd;
      store := store + sec;
      store := store - random(char.spd*2);
      store := store + random(char.def+1);
      defbonus := store;
    End
    Else If stat = 'MP' Then
    Begin
      store := char.atk - char.def - char.mp;
      store := store + char.spd;
      store := store + sec;
      store := store + ms;
      store := store Div char.spd Div 8;
      mpbonus := store;
    End
    Else If stat = 'EXP' Then
    Begin
      store := echar.atk - echar.def;
      store := store + echar.spd;
      store := store + sec;
      store := store + ms;
      store := store Div echar.spd Div 8;
      expbonus := store;
    End;
  End;

  If target = 1 Then
  Begin
    If stat = 'ATK' Then
    Begin
      randomize;
      store := echar.atk - random(char.def);
      randomize;
      store := store + random(store div 2);
      if store = store + store div 2 then critical := true;
      randomize;
      store := store - random(echar.spd*2);
      randomize;
      store := store + random(echar.atk)+1;
      atkbonus := store;
    End
    Else If stat = 'DEF' Then
    Begin
      randomize;
      store := echar.def - echar.atk;
      store := store + echar.spd;
      store := store + sec;
      store := store - random(echar.spd*2);
      store := store + random(echar.def+1);
      defbonus := store;
    End
    Else If stat = 'MP' Then
    Begin
      store := echar.atk - echar.def - echar.mp;
      store := store + echar.spd;
      store := store + sec;
      store := store + ms;
      store := store Div echar.spd Div 8;
      mpbonus := store;
    End
    Else If stat = 'EXP' Then
    Begin
      store := echar.atk - echar.def;
      store := store + echar.spd;
      store := store + sec;
      store := store + ms;
      store := store Div echar.spd Div 8;
      expbonus := store;
    End;
  End;
End;

Procedure SetupChar;
Begin
  If (char.race = 'ORC') Then
  Begin;
    char.hp := 55;
    char.mp := 4;
    char.atk := 6;
    char.def := 4;
    char.spd := 6;
    char.lev := 1;
    char.race := 'Orc';
    char.weapon := '';
    char.exp := 8;
    char.exp_rate := 2;
    If char.location = 'EASTERN' Then
    Begin
      char.race := 'Wood Orc';
      char.hp := 65;
      char.mp := 5;
      char.atk := 4;
      //add stat affects
    End
    Else If char.location = 'SOUTHERN' Then
    Begin
      char.race := 'Gray Orc';
      char.mp := 6;
      char.atk := 4;
      char.spd := 4;
      char.exp_rate := 1.5;
    End
    Else If char.location = 'WESTERN' Then
    Begin
      char.race := 'Mountain Orc';
      char.atk := 8;
      char.hp := 65;
      char.def := 3;
      char.spd := 8;
    End
    Else If char.location = 'NORTHERN' Then
    Begin
      gametype := 1; //can't have northern Orcs
    End
    Else If char.location = 'UNDERDARK' Then
    Begin
      char.race := 'Mountain Orc';
      char.atk := 8;
      char.hp := 65;
      char.def := 3;
      char.spd := 8;
    End;
  End;

  If (char.race = 'HUMAN') Then
  Begin
    char.hp := 45;
    char.mp := 5;
    char.atk := 5;
    char.def := 7;
    char.spd := 5;
    char.lev := 1;
    char.race := 'Human';
    char.weapon := '';
    char.exp := 4;
    char.exp_rate := 1.5;
    If char.location = 'EASTERN' Then
    Begin
      char.race := 'Barbarian';
      char.hp := 50;
      char.atk := 8;
      char.def := 5;
    End
    Else If char.location = 'SOUTHERN' Then
    Begin
      char.race := 'Viking';
      char.hp := 60;
      char.def := 4;
      char.spd := 6;
      char.exp_rate := 2.0;
    End
    Else If char.location = 'WESTERN' Then
    Begin
      char.race := 'Noble';
      char.hp := 50;
      char.hp := 5;
      char.atk := 5;
      char.def := 5;
      char.spd := 6;
    End
    Else If char.location = 'NORTHERN' Then
    Begin
      gametype := 1; //can't have northern humans
    End
    Else If char.location = 'UNDERDARK' Then
    Begin
      char.race := 'Drow Human';
    End;
    char.mhp := char.hp;
    char.mmp := char.mp;
    char.mweight := char.weight;

  End;

  If (char.race = 'ELF') Then
  Begin
    char.hp := 70;
    char.mp := 10;
    char.atk := 8;
    char.def := 4;
    char.spd := 8;
    char.lev := 1;
    char.race := 'Elf';
    char.weapon := '';
    char.exp := 0;
    char.exp_rate := 0.5;
    If char.location = 'EASTERN' Then
    Begin
      char.race := 'Wood Elf';
      char.atk := 7;
      char.def := 7;
      char.spd := 7;
    End
    Else If char.location = 'SOUTHERN' Then
    Begin
      char.race := 'Gray Elf';
      char.atk := 7;
      char.spd := 6;
      char.hp := 65;
      char.exp_rate := 1.0;
    End
    Else If char.location = 'WESTERN' Then
    Begin
      char.race := 'High Elf';
      char.atk := 10;
      char.spd := 10;
    End
    Else If char.location = 'NORTHERN' Then
    Begin
      gametype := 1; //can't have northern Elves
    End
    Else If char.location = 'UNDERDARK' Then
    Begin
      char.race := 'Drow Elf';
    End;
  End;

  If (char.race = 'DWARF') Then
  Begin
    char.hp := 60;
    char.mp := 4;
    char.atk := 8;
    char.def := 8;
    char.spd := 4;
    char.lev := 1;
    char.race := 'Dwarf';
    char.weapon := '';
    char.exp := 2;
    char.exp_rate := 1.2;
    If char.location = 'EASTERN' Then
    Begin
      char.race := 'Axe Dwarf';
      char.spd := 6;
      char.exp_rate := 1.0;
    End
    Else If char.location = 'SOUTHERN' Then
    Begin
      char.race := 'Gray Dwarf';
      char.atk := 7;
      char.def := 7;
      char.hp := 70;
      char.spd := 5;
    End
    Else If char.location = 'WESTERN' Then
    Begin
      char.race := 'Shield Dwarf';
      char.atk := 7;
      char.def := 10;
    End
    Else If char.location = 'NORTHERN' Then
    Begin
      gametype := 1; //can't have northern dwarves
    End
    Else If char.location = 'UNDERDARK' Then
    Begin
      char.race := 'Duergar';
      char.hp := 50;
      char.mp := 5;
      char.exp_rate := 2.0;
    End;
  End;

  If (char.race = 'HALFLING') Then
  Begin
    char.hp := 75;
    char.mp := 9;
    char.atk := 3;
    char.def := 3;
    char.spd := 9;
    char.lev := 1;
    char.race := 'Halfling';
    char.weapon := '';
    char.exp := 0;
    char.exp_rate := 3.0;
    If char.location = 'EASTERN' Then
    Begin
      char.race := 'Halfling';
      //add stat affects
    End
    Else If char.location = 'SOUTHERN' Then
    Begin
      gametype := 1; //can't have southern halflings
    End
    Else If char.location = 'WESTERN' Then
    Begin
      char.race := 'Gnome';
    End
    Else If char.location = 'NORTHERN' Then
    Begin
      gametype := 1; //can't have northern halflings
    End
    Else If char.location = 'UNDERDARK' Then
    Begin
      gametype := 1; //can't have halflings from underdark
    End;
  End;

  If (char.race = 'GIANT') Then
  Begin
    //Giants need to be limited somehow; pherhaps limit them to two-handed swords?
    char.hp := 85;
    char.mp := 8;
    char.atk := 8;
    char.def := 8;
    char.spd := 8;
    char.lev := 1;
    char.race := 'Giant';
    char.weapon := '';
    char.exp := 0;
    char.exp_rate := 0.5;
    If char.location = 'EASTERN' Then
    Begin
      char.race := 'Half Giant'; //can use all swords?
      char.hp := 65;
      char.mp := 6;
      char.atk := 7;
      char.def := 7;
      char.spd := 5;
      char.exp_rate := 0.7;
      //add stat affects
    End
    Else If char.location = 'SOUTHERN' Then
    Begin
      char.race := 'Hill Giant';
      char.hp := 95;
      char.def := 5;
      char.spd := 5;
    End
    Else If char.location = 'WESTERN' Then
    Begin
      char.race := 'Frost Giant';
      char.exp_rate := 2.0;
      char.def := 5;
      char.atk := 5;
    End
    Else If char.location = 'NORTHERN' Then
    Begin
      gametype := 1; //can't have northern giants
    End
    Else If char.location = 'UNDERDARK' Then
    Begin
      char.race := 'Drow Giant';
    End;
  End;

  If (char.race = 'UTHUD') Then
  Begin
    char.hp := 55;
    char.mp := 8;
    char.atk := 8;
    char.def := 3;
    char.spd := 8;
    char.lev := 1;
    char.race := 'Uthud';
    char.weapon := '';
    char.exp := 0;
    char.exp_rate := 1.5;
    If char.location = 'EASTERN' Then
    Begin
      char.race := 'High Uthud';
      char.atk := 10;
      char.mp := 10;
      char.hp := 35;
      char.spd := 5;
    End
    Else If char.location = 'SOUTHERN' Then
    Begin
      char.race := 'Hill Uthud';
      char.hp := 85;
      char.mp := 5;
      char.atk := 5;
      char.def := 5;
      char.spd := 5;
      char.exp_rate := 1.0;
    End
    Else If char.location = 'WESTERN' Then
    Begin
      char.race := 'Mountain Uthud';
      char.hp := 65;
      char.mp := 6;
      char.atk := 6;
      char.spd := 6;
    End
    Else If char.location = 'NORTHERN' Then
    Begin
      char.race := 'Drow Uthud';
    End
    Else If char.location = 'UNDERDARK' Then
    Begin
      char.race := 'Uthud';
    End;
  End;
  char.mhp := char.hp;
  char.mmp := char.mp;
  char.mweight := char.weight;
End;

//battle stuff

Procedure BattleDisp;
Begin
  ClrScr;
  GotoXy(1, 2);
  textcolor(12);
  Writeln(char.name, 's Level: ', char.lev);
  writeln(char.name, 's Speed: ', char.spd);
  Writeln(char.name, 's Attack: ', char.atk);
  Writeln(char.name, 's Defense: ', char.def);
  Writeln(char.name, 's HP: ', char.hp,'/',char.mhp);
  Writeln(char.name, 's MP: ', char.mp,'/',char.mmp);
  Writeln(char.name, 's Experiece: ', char.exp);
  textcolor(2);
  GotoXy(30, 2);
  Writeln(' ', echar.name, 's Level: ', echar.lev);
  GotoXy(30, 3);
  Writeln(' ', echar.name, 's Speed: ', echar.spd);
  GotoXy(30, 4);
  Writeln(' ', echar.name, 's Attack: ', echar.atk);
  GotoXy(30, 5);
  Writeln(' ', echar.name, 's Defense: ', echar.def);
  GotoXy(30, 6);
  Writeln(' ', echar.name, 's HP: ', echar.hp,'/',echar.mhp);
  GotoXy(30, 7);
  Writeln(' ', echar.name, 's MP: ', echar.mp,'/',echar.mmp);
  gotoxy(30, 8);
  Writeln(' ',echar.name, 's Experience: ', echar.exp);
  GotoXy(4, 9);
  textcolor(12);
  Write('-------------------');
  textcolor(2);
  writeln('---------------------');
  If curturn = 1 Then
    textcolor(12)
  Else
    textcolor(2);
  write('Current Turn: ');
  If curturn = 1 Then
    write(char.name, ' |  Current Weapon: ',char.weapon)
  Else
    write(echar.name, ' |  Current Weapon: ',echar.weapon);
  gotoxy(1, 17);
  textcolor(7);
End;

Procedure Player1;
Begin
  if char.weapon = '' then char.weapon := 'Fist';
  Repeat
    turncomplete := true;
    curturn := 1; //player1's turn
    BattleDisp;
    textcolor(12);
    Writeln('                  /________________________________\                            ');
    Writeln('                  |Type the number of your choice. |                            ');
    writeln('                  |1.. Attack With Melee           |                            ');
    writeln('                  |2.. Magic..                     |                            ');
    Writeln('                  |3.. Use Potion..                |                            ');
    Writeln('                  |4.. Menu..                      |                            ');
    writeln('                  \_v______________________________/                            ');
    textcolor(7);
    gotoxy(21, 24);
    readln(choice);
    Case choice Of
      1:
        Begin
          gotoxy(21, 24);
          AddRandNum(0, 'ATK');
          atkbonus := atkbonus + char.atk;
          if atkbonus > 0 then echar.hp := echar.hp - atkbonus;
          if atkbonus > 0 then Writeln('You hit ', echar.name, ' for ', atkbonus, '!') else writeln('You did no damage! ',char.atk);
        End;

      2:
        Begin
          gotoxy(21, 24);
          AddRandNum(0, 'MP');
          Writeln('MAGIC!!!!');
        End;

      3:
        Begin
          gotoxy(21, 24);
          EquipPotion(0);
          turncomplete := true;
        End;

      4:
        Begin
          clrscr;
          textcolor(12);
          Writeln('1.. Equip Weapon');
          Writeln('2.. Equip Armor');
          Writeln('3.. Go Back..');
          textcolor(7);
          readln(choice);
          Case choice Of
            1:
              Begin
                EquipWeapon(0); //player1, equip weapon
                turncomplete := false;
              End;

            2:
              Begin
                EquipArmor(0); //player1 equip armor
                turncomplete := false;
              End;

            3:
              Begin
                turncomplete := false;
              End;
          End; //end case
        End;
    End; //end case
  Until turncomplete = true;
  readln;
End;

Procedure Player2;
Begin
  if echar.weapon = '' then echar.weapon := 'Fist';
  Repeat
    turncomplete := true;
    curturn := 2; //player2's turn
    BattleDisp;
    textcolor(2);
    Writeln('                  /________________________________\                            ');
    Writeln('                  |Type the number of your choice. |                            ');
    writeln('                  |1.. Attack With Melee           |                            ');
    writeln('                  |2.. Magic..                     |                            ');
    Writeln('                  |3.. Use Potion..                |                            ');
    Writeln('                  |4.. Menu..                      |                            ');
    writeln('                  \_v______________________________/                            ');
    textcolor(7);
    gotoxy(21, 24);
    readln(choice);
    Case choice Of
      1:
        Begin
          gotoxy(21, 24);
          AddRandNum(1, 'ATK');
          atkbonus := atkbonus + echar.atk;
          if atkbonus > 0 then char.hp := char.hp - atkbonus;
          if atkbonus > 0 then Writeln('You hit ', char.name, ' for ', atkbonus, '!') else writeln('You did no damage! ',echar.atk);
        End;

      2:
        Begin
          gotoxy(21, 24);
          AddRandNum(1, 'MP');
          Writeln('MAGIC!!!!');
        End;

      3:
        Begin
          gotoxy(21, 24);
          Equippotion(1);
          turncomplete := true;
        End;

      4:
        Begin
          clrscr;
          textcolor(2);
          Writeln('1.. Equip Weapon');
          Writeln('2.. Equip Armor');
          Writeln('3.. Go Back..');
          textcolor(7);
          readln(choice);
          Case choice Of
            1:
              Begin
                EquipWeapon(1); //player2, equip weapon
                turncomplete := false;
              End;

            2:
              Begin
                EquipArmor(1); //player2 equip armor
                turncomplete := false;
              End;

            3:
              Begin
                turncomplete := false;
              End;
          End; //end case
        End;
    End; //end case
  Until turncomplete;
  readln;
End;

Procedure Battle;
Begin
//////////////
  char.potions[1] := 'Small HP Vial';
//////////////
  BattleDisp;
  If (char.spd > echar.spd) Then
  Begin
    Repeat
      If (char.hp > 0) And (echar.hp > 0) Then
      Begin
        Player1;
      End
      Else begin
        if char.hp < 1 then lchar := true;
        if echar.hp < 1 then lechar := true;
      end;
        //begin playerb's attack
      If (echar.hp > 0) And (char.hp > 0) Then
      Begin
        Player2;
      End
      Else begin
        if echar.hp < 1 then lechar := true;
        if char.hp < 1 then lchar := true;
      end;
    Until (lchar = true) Or (lechar = true); //Someone lost.
  End
  Else
  Begin
    Repeat
      If (echar.hp > 0) And (char.hp > 0) Then
      Begin
        Player2;
      End
      Else begin
        if echar.hp < 1 then lechar := true;
        if char.hp < 1 then lchar := true;
      end;
          //begin playera's attack
      If (char.hp > 0) And (echar.hp > 0) Then
      Begin
        Player1;
      End
      Else begin
        if char.hp < 1 then lchar := true;
        if echar.hp < 1 then lechar := true;
      end;
    Until (lchar) Or (lechar); //Someone lost.
  End; //end chunk
      //lchar means Char lost, so if Char wins, lechar must be true.
  clrscr;
  writeln('Battle over! Press enter to continue...');
  if (lchar = true) then begin
    writeln('You lost!');
    AddRandNum(1, 'EXP');
    echar.exp := echar.exp + expbonus;
    writeln(echar.name, ' received ',expbonus,' experience!');
  end;

  if (lechar = true) then begin
    writeln('You won!');
    writeln('You received ',expbonus,' experience!');
    AddRandNum(0, 'EXP');
    char.exp := char.exp + expbonus;
    PickRandomWeapon;
    if WeaponReceived = true then writeln('You received ',char.weapons[randwep],'!') else writeln('You received no weapons from this fight.');
    PickRandomPotion;
    if potionreceived = true then writeln('You received ',char.potions[randpot],'!') else writeln('You received no potions from this fight.');
    weaponreceived := false;
    potionreceived := false;
  end;
  lechar := false;
  lchar := false;
  readln;
End;

Procedure Mission1;
Begin
  echar.name := 'Dwarven Soldier';
  echar.hp := echar.hp + 45;
  echar.mp := echar.mp + 4;
  echar.mhp := echar.hp;
  echar.mmp := echar.mp;
  echar.atk := echar.atk + 10;
  echar.def := echar.def + 6;
  echar.spd := echar.spd + 5;
  echar.lev := echar.lev + 1;
  echar.race := 'Dwarf';
  echar.exp_rate := 1;
  Battle;
End;

Procedure Mission2;
Begin
  echar.name := 'Elven Hunter';
  echar.hp := echar.hp + 10;
  echar.mp := echar.mp + 4;
  echar.mhp := echar.hp;
  echar.mmp := echar.mp;
  echar.atk := echar.atk + 5;
  echar.def := echar.def + 3;
  echar.spd := echar.spd + 6;
  echar.lev := echar.lev + 5;
  echar.race := 'Elf';
  echar.exp_rate := 2;
  Battle;
End;


Procedure Mission3;
Begin
  echar.name := 'Giantess';
  echar.hp := echar.hp + 300;
  echar.mp := echar.mp + 3;
  echar.mhp := echar.hp;
  echar.mmp := echar.mp;
  echar.atk := echar.atk + 15;
  echar.def := echar.def + 20;
  echar.spd := echar.spd - 5;
  echar.lev := echar.lev + 10;
  echar.race := 'Giant';
  echar.exp_rate := 1;
  Battle;
End;

Begin
 { for entryi := 1 to 19 do begin
    char.weapons[entryi] := 'weapon#';
  end;
  char.weapons[1] := 'Sword';
  char.weapons[2] := 'Bastard Sword';
  char.weapons[3] := 'Axe';
  char.weapons[4] := 'Two-Handed Sword';
  char.weapons[5] := 'Dagger';
  echar.weapons[1] := 'Sword';
  echar.weapons[2] := 'Bastard Sword';
  echar.weapons[3] := 'Axe';
  echar.weapons[4] := 'Two-Handed Sword';
  echar.weapons[5] := 'Dagger';
  displaybackpack(0,0);
  readln;}

{whole main loop... restore when done testing
      ////////////}
 addrandnum(0,'CHANCE');
 char.luck := 10;
 writeln(char.luck);
 if chance = true then writeln('TRUE!!!');
 if chance = false then writeln('FALSE!!!');
 writeln('Expbonus: ',expbonus);
 readln;
{  Case topmenu Of
    1:
      Begin
        ClrScr;
        textcolor(6);
        writeln(' Welcome to the Initiative, soldier. We have an assignment for you. ');
        Writeln(' First, however, we must collect some details from you.');
        writeln;
        writeln(' End Transmission. ');
        writeln;
        gametype := 4;
        textcolor(7);
      End;

    2:
      Begin
        clrscr;
        gametype := 1;
      End;

    3:
      Begin
        writeln(' Password ');
      End;

    4:
      Begin
        writeln(' Online Play ');
      End;

    5:
      Begin
        writeln(' Quit ');
      End;

    6:
      Begin
        Writeln(' Credits ');
      End;
  End;
  //begin game loop
  //gametype = 1 : Authentication
  //gametype = 2 : Briefing
  //gametype = 3 : Game Play
  //gametype = 4 : Register
  //gametype = 5 : exit
  Repeat
    Repeat
      If gametype = 1 Then
      Begin
        //unloadchar; ;not needed?
        clrscr;
        loadchar;
        writeln;
        If auth = true Then
          Writeln('Authenticated!')
        Else
        Begin
          textcolor(12);
          Writeln('Sorry, that username/password does not exist.');
          textcolor(7);
        End;
        Writeln('Press enter to continue.');
        readln;
        clrscr;
        If auth = true Then
          gametype := 2
        Else
          gametype := 1;
      End;
    Until gametype <> 1;

    If gametype = 2 Then
    Begin
      echar.weapons[1] := 'Fist';
      char.weapons[1] := 'Fist';
      echar.weapons[2] := 'Axe';
      Mission1;
      clrscr;
      Writeln('Level Up!');
      Writeln('You are now level ',char.lev+1,'!');
      char.lev := char.lev+1;
      char.atk := char.atk + 6;
      char.def := char.def + 4;
      char.spd := char.spd - 1;
      char.hp := char.mhp + 50; //heals at same time because of Mhp and not just hp
      char.mhp := char.mhp + 50;
      Writeln('Attack: ', char.atk);
      writeln('Defense: ', char.def);
      writeln('Speed: ', char.spd);
      writeln('HP: ', char.hp);
      Writeln('Press enter to continue...');
      readln;
      clrscr;
      writeln('Ok, so you beat the dwarf.. So what... You think you can beat an Elf?');
      echar.weapons[2] := 'Sword';
      writeln('Press enter to continue...');
      readln;
      mission2;
      clrscr;
      Writeln('Level Up!');
      Writeln('You are now level ',char.lev+1,'!');
      char.lev := char.lev+1;
      char.atk := char.atk + 11;
      char.def := char.def + 11;
      char.spd := char.spd - 1;
      char.hp := char.mhp + 55; //heals at same time because of Mhp and not just hp
      char.mhp := char.mhp + 55;
      Writeln('Attack: ', char.atk);
      writeln('Defense: ', char.def);
      writeln('Speed: ', char.spd);
      writeln('HP: ', char.hp);
      Writeln('Press enter to continue...');
      readln;
      clrscr;
      writeln('Hmmmm.. Not bad, not bad. How about a giant, then?');
      Writeln('We will give you our most powerful weapon, the Bastard Sword.');
      for entryi := 1 to 4 do begin
        if char.weapons[entryi] = '' then char.weapons[entryi] := 'Bastard Sword';
      end;
      writeln('Press enter to continue.');
      readln;
      mission3;
      clrscr;
      Writeln('Level Up!');
      Writeln('You are now level ',char.lev+1,'!');
      char.lev := char.lev+1;
      char.atk := char.atk + 16;
      char.def := char.def + 16;
      char.spd := char.spd + 1;
      char.hp := char.mhp + 60; //heals at same time because of Mhp and not just hp
      char.mhp := char.mhp + 60;
      Writeln('Attack: ', char.atk);
      writeln('Defense: ', char.def);
      writeln('Speed: ', char.spd);
      writeln('HP: ', char.hp);
      Writeln('Press enter to continue...');
      readln;
      clrscr;
    End;

    If gametype = 3 Then
    Begin

    End;

    If gametype = 4 Then
    Begin
      textcolor(2);
      ClrScr;
      Writeln('So you wanna join the Initiate eh? Well, fill out this form,');
      writeln('and we will put you on your first training mission.');
      writeln;
      Repeat
        Writeln('Initiate Username: ');
        textcolor(12);
        readln(char.name);
        textcolor(2);
        writeln('Initiate Password: ');
        textcolor(12);
        readln(pass);
        textcolor(2);
        Writeln('Re-enter Password: ');
        textcolor(12);
        readln(char.password);
        textcolor(2);
      Until pass = char.password;
      ClrScr;
      Repeat
        writeln('Ok, ', char.name, ', you are now ready to begin the registration process.');
        Writeln('Please choose a race. If you forget the names of the races, type ''help''');
        textcolor(12);
        readln(char.race);
        textcolor(2);
        For entryi := 1 To length(char.race) Do
          char.race[entryi] := upcase(char.race[entryi]);
        If char.race = 'HELP' Then
        Begin
          clrscr;
          writeln('Orc');
          Writeln('Human');
          Writeln('Elf');
          Writeln('Dwarf');
          Writeln('Halfling');
          Writeln('Giant');
          Writeln('Uthud');
          Writeln('For descriptions of the races, please type ''desc'' and then press enter.');
          For entryi := 1 To length(entry) Do
            entry[entryi] := upcase(entry[entryi]);
          writeln('This will open the readme file.');
          Writeln('Press enter to continue.');
          textcolor(12);
          readln(entry);
          textcolor(2);
          If entry = 'desc' Then ShellExecute(hwindow, 'open', 'races.txt', Nil, Nil, SW_SHOWMAXIMIZED);
        End;
        clrscr;
      Until (char.race = 'ORC') Or (char.race = 'HUMAN') Or (char.race = 'ELF') Or (char.race = 'DWARF') Or (char.race = 'HALFLING') Or (char.race = 'GIANT') Or (char.race = 'UTHUD');
      Repeat
        clrscr;
        writeln('Ok, well, where on the map are you from?');
        writeln('If you are not sure, type ''help''.');
        textcolor(12);
        readln(char.location);
        textcolor(2);
        For entryi := 1 To length(char.location) Do
          char.location[entryi] := upcase(char.location[entryi]);
        If char.location = 'HELP' Then
        Begin
          clrscr;
          If char.race = 'HUMAN' Then
          Begin
            writeln('Choose one of the below, Southern, Western, Eastern, Nothern, or Underdark.');
            Writeln('Southern: Vikings');
            writeln('Eastern: Barbarians');
            writeln('Western: Nobility');
            writeln('Northern: ----');
            writeln('Underdark: Drow');
            writeln('Press Enter to continue...');
            readln;
          End;

          If char.race = 'ELF' Then
          Begin
            writeln('Choose one of the below, Southern, Western, Eastern, Nothern, or Underdark.');
            Writeln('Southern: Gray Elf');
            writeln('Eastern: Wood Elf');
            writeln('Western: High Elf');
            writeln('Northern: ----');
            writeln('Underdark: Drow Elf');
            writeln('Press Enter to continue...');
            readln;
          End;

          If char.race = 'DWARF' Then
          Begin
            writeln('Choose one of the below, Southern, Western, Eastern, Nothern, or Underdark.');
            Writeln('Southern: Gray Dwarf');
            writeln('Eastern: Axe Dwarf');
            writeln('Western: Shield Dwarf');
            writeln('Northern: ----');
            writeln('Underdark: Duergar');
            writeln('Press Enter to continue...');
            readln;
          End;

          If char.race = 'ORC' Then
          Begin
            writeln('Choose one of the below, Southern, Western, Eastern, Nothern, or Underdark.');
            Writeln('Southern: Gray Orc');
            writeln('Eastern: Wood Orc');
            writeln('Western: Mountain Orc');
            writeln('Northern: ----');
            writeln('Underdark: Mountain Orc');
            writeln('Press Enter to continue...');
            readln;
          End;

          If char.race = 'HALFLING' Then
          Begin
            writeln('Choose one of the below, Southern, Western, Eastern, Nothern, or Underdark.');
            Writeln('Southern: ----');
            writeln('Eastern: Halfling');
            writeln('Western: Gnome');
            writeln('Northern: ----');
            writeln('Underdark: ----');
            writeln('Press Enter to continue...');
            readln;

            If char.race = 'GIANT' Then
            Begin
              writeln('Choose one of the below, Southern, Western, Eastern, Nothern, or Underdark.');
              Writeln('Southern: Hill Giant');
              writeln('Eastern: Half-Giant');
              writeln('Western: Frost Giant');
              writeln('Northern: ----');
              writeln('Underdark: ----');
              writeln('Press Enter to continue...');
              readln;
            End;

            If char.race = 'UTHUD' Then
            Begin
              writeln('Choose one of the below, Southern, Western, Eastern, Nothern, or Underdark.');
              Writeln('Southern: Hill Uthud');
              writeln('Eastern: High Uthud');
              writeln('Western: Mountain Uthud');
              writeln('Northern: Drow Uthud');
              writeln('Underdark: Uthud');
              writeln('Press Enter to continue...');
              readln;
            End;

          End;
        End;
      Until (char.location = 'SOUTHERN') Or (char.location = 'EASTERN') Or (char.location = 'NORTHERN') Or (char.location = 'WESTERN') Or (char.location = 'UNDERDARK');

      Repeat
        clrscr;
        writeln('So.. What gender are you, ', char.name, '? Male or Female?');
        textcolor(12);
        readln(char.sex);
        textcolor(2);
        For entryi := 1 To length(char.sex) Do
          char.sex[entryi] := upcase(char.sex[entryi]);
        If (char.sex <> 'MALE') Or (char.sex <> 'FEMALE') Then writeln('Sorry, you must be either male or female. We do not accept trans-genders in the Initiative.');
        clrscr;
      Until (char.sex = 'MALE') Or (char.sex = 'FEMALE');
      Writeln('Ok, Initiate. Return to the briefing tent for your first mission.');
      readln;
      SetupChar;
      Save := 'SaveChar';
      SaveGame;
      gametype := 1;
      textcolor(7);
    End;

  Until gametype = 5;
  exit; }
 {////////
 DONE RESTORE}
End.