-+-+-+-+-+-+-+-+ START OF PART 10 -+-+-+-+-+-+-+-+
X    If (Map.Ids`5BI`5D <> Me) Then Begin
X      If (Map.Pos`5BI`5D = POS_GUARD_S) Then Begin
X        ReadEntity(Map.Ids`5BI`5D, Entity);
X        PutLine(Entity.Name+' is guarding south exit. ');
X      End Else If (Map.Pos`5BI`5D = POS_GUARD_N) Then Begin
X        ReadEntity(Map.Ids`5BI`5D, Entity);
X        PutLine(Entity.Name+' is guarding north exit. ');
X      End Else If (Map.Pos`5BI`5D = POS_GUARD_W) Then Begin
X        ReadEntity(Map.Ids`5BI`5D, Entity);
X        PutLine(Entity.Name+' is guarding west exit. ');
X      End Else If (Map.Pos`5BI`5D = POS_GUARD_E) Then Begin
X        ReadEntity(Map.Ids`5BI`5D, Entity);
X        PutLine(Entity.Name+' is guarding east exit. ');
X      End Else If (Map.Pos`5BI`5D = POS_GUARD_U) Then Begin
X        ReadEntity(Map.Ids`5BI`5D, Entity);
X        PutLine(Entity.Name+' is guarding up exit. ');
X      End Else If (Map.Pos`5BI`5D = POS_GUARD_D) Then Begin
X        ReadEntity(Map.Ids`5BI`5D, Entity);
X        PutLine(Entity.Name+' is guarding down exit. ');
X      End;
X    End;
XEnd;
X
X`5BHidden`5D
XProcedure PrintHiddenHere(Var Map : ItemMapType; Me : $UWord);
XVar Entity : EntityType; I : Integer;
XBegin
X  For I := 1 To ItemMapSize Do
X    If (Map.Pos`5BI`5D = POS_HIDDEN) And (Map.Ids`5BI`5D <> Me) Then Begin
X      ReadEntity(Map.Ids`5BI`5D, Entity);
X      PutLine(Entity.Name+' is hidding here. ');
X    End;
XEnd;
X
X`5BHidden`5D
XProcedure PrintInvisiHere(Var Map : ItemMapType; Me : $UWord);
XVar Entity : EntityType; I : Integer;
XBegin
X  For I := 1 To ItemMapSize Do
X    If (Map.Pos`5BI`5D = POS_INVISI) And (Map.Ids`5BI`5D <> Me) Then Begin
X      ReadEntity(Map.Ids`5BI`5D, Entity);
X      PutLine('Invisible '+Entity.Name+' is here. ');
X    End;
XEnd;
X
XProcedure DescExits(Var Room : RoomType);
XVar I : Integer;
XBegin
X  If Not PrintDesc(Room.ExitDesc) Then Begin
X    For I := 1 to MaxRoomExits Do
X      If (Room.Exits`5BI`5D > 0) Then
X        PutLine('There is an exit from '+DirTable`5BI`5D+'.');
X    PutLine('');
X  End;
XEnd;
X
XProcedure DescRoomIn(Var NodeIn : EntityType; Observer : $UWord;
X   Brief, SeeHidden, SeeInvisi, IsThere : Boolean := False);
XVar RoomBlk : BlockType; Map : ItemMapType; S : String_Type;
X  I : Integer; Done : Boolean := False;
XBegin
X  If IsThere Then
X    PutLine('You see '+NodeIn.Name+'.', 1)
X  Else PutLine('You are in '+NodeIn.Name+'.', 1);
X  Read_Record(FILE_BLOCK, NodeIn.RoomId, IAddress(RoomBlk));
X  If (Not (Brief Or IsThere)) Then Begin
X    PrintDesc(RoomBlk.Room.MainDesc);
X    DescExits(RoomBlk.Room);
X  End;
X  If (RoomBlk.Room.Goldhere > 0) Then Begin
X    WriteV(S, 'There are ', RoomBlk.Room.Goldhere:0, ' gold here. ');
X    PutLine(S);
X  End;
X  Read_Record(FILE_ITEMMAP, NodeIn.RoomMapId, IAddress(Map));
X  While Not Done Do Begin
X    PrintPeopleHere(Map, Observer);
X    PrintGuardianHere(Map, Observer);
X    If SeeHidden Then PrintHiddenHere(Map, Observer);
X    If SeeInvisi Then PrintInvisiHere(Map, Observer);
X    If (Not IsThere) Then Begin
X      PrintObjHere(Map);
X      PrintObjSale(Map);
X      If SeeHidden Then PrintObjHidden(Map);
X    End;
X    If (Map.Next > 0) Then
X      Read_Record(FILE_ITEMMAP, Map.Next, IAddress(Map))
X    Else Done := True;
X  End;
XEnd;
X
XProcedure DescThere(Var NodeIn : EntityType; Location, Observer, Dir: $UWord
V;
X   Brief, SeeHidden, SeeInvisi : Boolean := False);
XVar NodeSee : EntityType; RoomBlk : BlockType; AnExit : ExitType;
X  There : Integer;
XBegin
X  ReadBlock(NodeIn.RoomId, RoomBlk);
X  If (RoomBlk.Room.Exits`5BDir`5D = 0) Then
X    PutLine('You see nothing of interest in that direction. ')
X  Else Begin
X    ReadExit(RoomBlk.Room.Exits`5BDir`5D, AnExit);
X    If (AnExit.Node`5B1`5D = Location) Then
X      There := AnExit.Node`5B2`5D
X    Else There := AnExit.Node`5B1`5D;
X    If (There = 0) Then
X      PutLine('You see a dead end. ')
X    Else Begin
X      ReadEntity(There, NodeSee);
X      DescRoomIn(NodeSee, Observer, Brief, SeeHidden, SeeInvisi, TRUE);
X    End;
X  End;
XEnd;
X
X`5BHidden`5D
XProcedure DescPerson(Var Entity : EntityType);
XVar S : String_Type;
X    Cls : EntityType;
X    PersonBlk : BlockType;
XBegin
X  Read_Record(FILE_BLOCK, Entity.PersonId, IAddress(PersonBlk));
X  With PersonBlk.Person Do Begin
X    ReadEntity(Class, Cls);
X    DescHealth(Entity.Name, HealthLevel(Health, MaxHealth), FALSE);
X    WriteV(S, Entity.Name, ' is a ', Level:0, 'th level ', Cls.Name+'.');
X    PutLine(S);
X  End;
XEnd;
X
XProcedure DescEntity(EntityId : $UWord);
XVar Entity : EntityType;
XBegin
X  ReadEntity(EntityId, Entity);
X  Case Entity.EntityKind Of
X    ENTITY_PERSON : DescPerson(Entity);
X    ENTITY_OBJECT : PutLine('You see nothing special about '+Entity.Name+'.'
V);
X    Otherwise PutLine(Entity.Name+' is unknow. ');
X  End;
XEnd;
X
XProcedure ShowInventory(EntityId : $UWord);
XVar Entity, Item : EntityType;
X  Map : ItemMapType;
X  I : Integer := 0;
X  Done : Boolean := False;
X
X Procedure PrintInven;
X Begin
X   PutLine('Inventory: ');
X   For I := 1 To ItemMapSize Do
X     If (Map.Pos`5BI`5D = POS_INVEN) Then Begin
X       ReadEntity(Map.Ids`5BI`5D, Item);
X       PutLine('  '+Item.Name);
X     End;
X End;
X
X Procedure PrintEquip;
X Begin
X   PutLine('Equipment: ');
X   For I := 1 To ItemMapSize Do
X     If (Map.Pos`5BI`5D = POS_WEAPON) Or ( Map.Pos`5BI`5D = POS_ARMOR) Then
V Begin
X       ReadEntity(Map.Ids`5BI`5D, Item);
X       PutLine('  '+Item.Name);
X     End;
X End;
X
XBegin
X  ReadEntity(EntityId, Entity);
X  Read_Record(FILE_ITEMMAP, Entity.InvenId, IAddress(Map));
X  While Not Done Do Begin
X    PrintInven;
X    PrintEquip;
X    If (Map.Next > 0) Then
X      Read_Record(FILE_ITEMMAP, Map.Next, IAddress(Map))
X    Else Done := True;
X  End;
XEnd;
X
XProcedure ShowSheet(EntityId : $UWord);
XVar S : String_Type;
X    Entity, HR, Cls, Wp : EntityType;
X    PersonBlk : BlockType;
X    I : $UWord;
XBegin
X  ReadEntity(EntityId, Entity);
X  Read_Record(FILE_BLOCK, Entity.InvenId, IAddress(PersonBlk));
X  ReadEntity(PersonBlk.Person.Home, HR);
X  ReadEntity(PersonBlk.Person.Class, Cls);
X  PutLine(DivLine+DivLine);
X  If (PersonBlk.Person.Weapon > 0) Then
X    ReadEntity(PersonBlk.Person.Weapon, Wp);
X  PutLine('Name                ' + Entity.Name);
X  With PersonBlk.Person Do Begin
X    WriteV(S, 'Group               ', Group:0);
X    PutLine(S);
X    WriteV(S, 'Class               ', Cls.Name);
X    PutLine(S);
X    WriteV(S, 'Home                ', HR.Name);
X    PutLine(S);
X    WriteV(S, 'Level               ', Level:0);
X    PutLine(S);
X    WriteV(S, 'Experience          ', Exp:0);
X    PutLine(S);
X    WriteV(S, 'Gold                ', Gold:0);
X    PutLine(S);
X    WriteV(S, 'ArmorClass          ', ArmorClass:0);
X    PutLine(S);
X    WriteV(S, 'Health              ', Health:0);
X    PutLine(S);
X    WriteV(S, 'Mana                ', Mana:0);
X    PutLine(S);
X    WriteV(S, 'Maxhealth           ', Maxhealth:0);
X    PutLine(S);
X    WriteV(S, 'Maxmana             ', Maxmana:0);
X    PutLine(S);
X    WriteV(S, 'Maxspeed            ', MaxSpeed:0);
X    PutLine(S);
X    For I := 1 To MaxPersonAttri Do Begin
X      WriteV(S, PadStr(PersonAttritable`5BI`5D, 20), Attributes`5BI`5D:0);
X      PutLine(S);
X    End;
X    If (Weapon > 0) Then
X      PutLine('Weapon              '+Wp.Name);
X  End;
X  PutLine(DivLine+DivLine);
XEnd;
X
XEnd.
$ CALL UNPACK M7_2.PAS;1 1919816032
$ create 'f'
X`5BInherit('M1', 'M2', 'M3', 'M4', 'M5', 'M6', 'M7_2'),
X Environment('M7_3')`5D
X
XModule M7_3(Output);
X
X
X(* event functions *)
X
XConst
X  EVENT_BLOCK_SIZE = 20;
X  MAX_EVENT_BLOCK = 10;
X
XType
X  Event_Parm_Type = Array`5B1..5`5D Of Integer;
X
X  Event_Type = Record
X    Sender, Target, Action, Location : $UWord;
X    Msg : String_Type;
X    Parms : Event_Parm_Type;
X    LogTime : $UQuad;
X  End;
X
X  Events_Type = Record
X    Point : $UWord;
X    Events : Array`5B1..EVENT_BLOCK_SIZE`5D Of Event_Type;
X  End;
X
X`5BHidden`5D
XVar
X  Event_File : File Of Events_Type;
X
XVar
X  MyEntityId : $UWord;
X  MyEventPoint : $UWord;
X  MyLocation : $UWord;
X  MyPosition : $UWord;
X  ImDead : Boolean;
X
X`5BExternal, Hidden`5D
XProcedure InitEnemyList; external;
X
X`5BExternal, Hidden`5D
XProcedure LoadRoomNpc(Location : $UWord); External;
X
X`5BExternal, Hidden`5D
XProcedure LogNpcEvent(Var AnEvent : Event_Type; Where : $UWord); External;
X
X`5BExternal, Hidden`5D
XProcedure UpdateRoomNpc(IsLeaving : Boolean; Id : $UWord); External;
X
X`5BExternal, Hidden`5D
XProcedure DriveEnemyList; External;
X
XProcedure HandleEvent(Var AnEvent : Event_Type; EntityId, Loc : $UWord);
XForward;
X
XProcedure SetUpEvent;
XVar IsOpen : `5BStatic`5D Boolean := False;
XBegin
X  If IsOpen Then Begin
X    IsOpen := False; Close(Event_File);
X  End Else Begin
X    IsOpen := True;
X    Open_File(FILE_EVENT, Event_File, Root+'Event.Mon', Size(Events_Type));
X  End;
XEnd;
X
XProcedure InitEventFile;
XVar Events : Events_Type; I : $UWord;
XBegin
X  Events := Zero;
X  Events.Point := 1;
X  For I := 1 To MAX_EVENT_BLOCK Do Put_Record(FILE_EVENT, I, IAddress(Events
V));
XEnd;
X
XProcedure SetMyEvent;
XVar Events : Events_Type; Id : $UWord;
XBegin
X  Id := MyLocation Mod MAX_EVENT_BLOCK + 1;
X  Read_Record(FILE_EVENT, Id, IAddress(Events));
X  MyEventPoint := Events.Point;
X  LoadRoomNpc(MyLocation);
XEnd;
X
X`5BGlobal`5D
XProcedure LogEvent(S, T, A, L : $UWord;
X   M : String_Type := ''; DI : Boolean := False;
X   P1, P2, P3, P4, P5, Id : Integer := 0);
XVar Events : Events_Type; OldPoint : $UWord;
XBegin
X  If (Id = 0) Then
X    Id := L Mod MAX_EVENT_BLOCK + 1;
X  Get_Record(FILE_EVENT, Id, IAddress(Events));
X  With Events.Events`5BEvents.Point`5D Do Begin
X    Sender := S;    Target   := T;
X    Action := A;    Location := L;  Msg := M;
X    Parms`5B1`5D := P1; Parms`5B2`5D := P2;
X    Parms`5B3`5D := P3; Parms`5B4`5D := P4; Parms`5B5`5D := P5;
X    LogTime := GetRealTime;
X  End;
X  OldPoint := Events.Point;
X  If Events.Point = MAX_EVENT_BLOCK Then
X    Events.Point := 1
X  Else
X    Events.Point := Events.Point + 1;
X  Update_Record(FILE_EVENT, Id, IAddress(Events));
X  If (T = ALL_TARGET) Then
X    LogNpcEvent(Events.Events`5BOldPoint`5D, L)
X  Else If DI Then
X    HandleEvent(Events.Events`5BOldPoint`5D, T, L);
XEnd;
X
XProcedure LogGlobEvent(Sender, Target, Action : $UWord;
X   Msg : String_Type := ''; P1, P2, P3, P4, P5 : Integer := 0);
XVar I : Integer;
XBegin
X  For I := 1 To MAX_EVENT_BLOCK Do Begin
X    LogEvent(Sender, Target, Action, GLOB_LOCATION, Msg, FALSE,
X       P1, P2, P3, P4, P5, I);
X  End;
XEnd;
X
XProcedure CheckEvent;
XVar Events : Events_Type;
X    Id, OldPoint, OldLocation : $UWord;
XBegin
X  Id := MyLocation Mod MAX_EVENT_BLOCK + 1;
X  OldLocation := MyLocation;
X  Read_Record(FILE_EVENT, Id, IAddress(Events));
X  While (MyEventPoint <> Events.Point) And (OldLocation = MyLocation) Do Beg
Vin
X    OldPoint := MyEventPoint;
X    If MyEventPoint = MAX_EVENT_BLOCK Then
X      MyEventPoint := 1
X    Else
X      MyEventPoint := MyEventPoint + 1;
X    HandleEvent(Events.Events`5BOldPoint`5D, MyEntityId, MyLocation);
X(*
X * a lot of things could happen in handle event. since MyEventPoint is
X * a global variable, chances are it will get changed in handleevent.
X * There is no clean way to prevent this. Break out of the loop when
X * location is changed seem to fix most of the problem..
X *)
X  End;
XEnd;
X
XProcedure Resurrect(Var Entity : EntityType;
X  Var PersonBlk : BlockType;
X  EntityId, Where : $UWord;
X  Print : Boolean);
XVar List : Array`5B1..ItemMapSize`5D Of $UWord;
X    InvenMap, RoomMap : ItemMapType;
X    RoomBlk : BlockType;
X    NodeIn, Home, Cls : EntityType;
X    GoldDropped : Integer := 0;
X    OldPos, I : $UWord := 0;
X    Dummy1, Dummy2 : Integer := 0;
X    Dummy3 : Boolean := False;
XBegin
X  Get_Record(FILE_BLOCK, Entity.PersonId, IAddress(PersonBlk));
X  With PersonBlk.Person Do Begin
X    GoldDropped := PersonBlk.Person.Gold;
X    Exp := 1;
X    Gold := 0;
X    Level := 0;
X    Weapon := 0;
X    ArmorClass := 0;
X    Stats := Zero;
X    For I := 1 to MaxPersonAttri Do
X      Attributes`5BI`5D := 6 + Rnd(6) + Rnd(4);
X    MaxHealth := 12 + Rnd(8) + Rnd(4);
X    MaxMana := 6 + Rnd(4) + Rnd(2);
X    MaxSpeed := 100 + Rnd(40) + Rnd(20);
X    Health := MaxHealth;
X    Mana := MaxMana;
X  End;
X  Update_Record(FILE_BLOCK, Entity.PersonId, IAddress(PersonBlk));
X
X  List := Zero;
X  Get_Record(FILE_ITEMMAP, Entity.InvenId, IAddress(InvenMap));
X  For I := 1 To ItemMapSize Do
X    If (InvenMap.Ids`5BI`5D > 0) And (InvenMap.Pos`5BI`5D > 0) Then Begin
X      List`5BI`5D := InvenMap.Ids`5BI`5D;
X      InvenMap.Ids`5BI`5D := 0;
X      Invenmap.Pos`5BI`5D := 0;
X    End; `20
X  Update_Record(FILE_ITEMMAP, Entity.InvenId, IAddress(InvenMap));
X  ReadEntity(Where, NodeIn);
X  For I := 1 to ItemMapSize Do
X    If (List`5BI`5D > 0) Then
X      PutToken(List`5BI`5D, Where, NodeIn.RoomMapId, POS_OBJ_HERE, TRUE);
X
X  Get_Record(FILE_BLOCK, NodeIn.RoomId, IAddress(RoomBLK));
X  RoomBlk.Room.Goldhere := RoomBlk.Room.Goldhere + GoldDropped;
X  Update_Record(FILE_BLOCK, NodeIn.RoomId, IAddress(RoomBlk));
X
X  TakeToken(EntityId, NodeIn.RoomMapId, OldPos);
X  LogEvent(EntityId, 0, EV_INFORM, Where,`20
X  Entity.Name+'''s body disappeared in a puff of orange smoke. ');
X  ReadEntity(PersonBlk.Person.Home, Home);
X  PutToken(EntityId, PersonBlk.Person.Home, Home.RoomMapId, POS_IN_ROOM, TRU
VE);
X  LogEvent(EntityId, 0, EV_INFORM, PersonBlk.Person.Home,
X  Entity.Name+' appears in a puff of orange smoke. ');
X
X  ReadEntity(PersonBlk.Person.Class, Cls);
X  AffectPerson(Cls.ClassEffect, EntityId, Where, Entity, PersonBlk,
X  Dummy1, Dummy2, Dummy3, FALSE, FALSE);
X
X  If Print Then Begin
X    ImDead := False;
X    PutLine('You feel a great weight has been lift off you.. ');
X    PutLine('You have been resurrected! ', 1);
X    MyLocation := PersonBlk.Person.Home;
X    SetMyEvent;
X    DescRoomIn(Home, MyEntityId, False, IsWindy, IsWindy);
X  End;
XEnd;
X
XProcedure TimeHeal(EntityId, Where : $UWord);
XVar Entity : EntityType; PersonBlk : BlockType;
X  Amount, TimeTicked : Integer := 0;
X  LogHealth, LogMana : Boolean := False;
XBegin
X  ReadEntity(EntityId, Entity);
X  Get_Record(FILE_BLOCK, Entity.PersonId, IAddress(PersonBlk));
+-+-+-+-+-+-+-+-  END  OF PART 10 +-+-+-+-+-+-+-+-
