2 CHARACTER(guard
, humanoid
)
5 guard() : NextWayPoint(0) { }
6 virtual void Save(outputfile
&) const;
7 virtual void Load(inputfile
&);
8 virtual void GetAICommand();
9 virtual void SetWayPoints(const fearray
<packv2
>&);
10 virtual truth
MoveTowardsHomePos();
11 virtual void BeTalkedTo();
13 std::vector
<v2
> WayPoints
;
22 void guard::SetWayPoints(const fearray
<packv2
>& What
) { ArrayToVector(What
, WayPoints
); }
26 void guard::Save(outputfile
& SaveFile
) const
28 humanoid::Save(SaveFile
);
29 SaveFile
<< WayPoints
<< NextWayPoint
;
34 void guard::Load(inputfile
& SaveFile
)
36 humanoid::Load(SaveFile
);
37 SaveFile
>> WayPoints
>> NextWayPoint
;
42 void guard::GetAICommand()
44 if(GetConfig() == MASTER
&& HP
<< 1 < MaxHP
&& (GetPos() - v2(30, 17)).GetLengthSquare() > 9)
46 if(CanBeSeenByPlayer())
47 ADD_MESSAGE("%s disappears.", CHAR_NAME(DEFINITE
));
49 GetLevel()->GetLSquare(30, 16)->KickAnyoneStandingHereAway();
50 Move(v2(30, 16), true);
55 if(WayPoints
.size() && !IsGoingSomeWhere())
57 if(GetPos() == WayPoints
[NextWayPoint
]) {
58 if(NextWayPoint
< WayPoints
.size() - 1) ++NextWayPoint
; else NextWayPoint
= 0;
61 GoingTo
= WayPoints
[NextWayPoint
];
64 SeekLeader(GetLeader());
66 if(CheckForEnemies(true, true, true))
69 if(CheckForUsefulItemsOnGround())
72 if(FollowLeader(GetLeader()))
78 if(MoveTowardsHomePos())
84 if(CheckForBeverage())
92 truth
guard::MoveTowardsHomePos()
94 if(GetConfig() == MASTER
&& GetPos() != v2(30, 16))
96 if(CanBeSeenByPlayer())
97 ADD_MESSAGE("%s disappears.", CHAR_NAME(DEFINITE
));
99 GetLevel()->GetLSquare(30, 16)->KickAnyoneStandingHereAway();
100 Move(v2(30, 16), true);
102 if(CanBeSeenByPlayer())
103 ADD_MESSAGE("%s appears.", CHAR_NAME(DEFINITE
));
109 return humanoid::MoveTowardsHomePos();
114 void guard::BeTalkedTo()
118 if(!PLAYER
->SelectFromPossessions(Item
, CONST_S("Do you have something to give me?"), 0, &item::IsBeverage
)
120 humanoid::BeTalkedTo();
122 for(unsigned int c
= 0; c
< Item
.size(); ++c
)
124 Item
[c
]->RemoveFromSlot();
125 GetStack()->AddItem(Item
[c
]);