3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
8 * See LICENSING which should be included
9 * along with this file for more details
12 /* Compiled through trapset.cpp */
15 trapprototype::trapprototype (trapspawner Spawner
, cchar
*ClassID
) :
19 Index
= protocontainer
<trap
>::Add(this);
23 trap::trap () : entity(HAS_BE
), Next(0) {}
30 square
*trap::GetSquareUnderEntity (int) const { return LSquareUnder
; }
31 void trap::Save (outputfile
&SaveFile
) const {}
32 void trap::Load (inputfile
&) { LSquareUnder
= static_cast<lsquare
*>(game::GetSquareInLoad()); }
35 outputfile
& operator << (outputfile
&SaveFile
, const trapdata
*Data
) {
41 inputfile
&operator >> (inputfile
&SaveFile
, trapdata
*&Data
) {
48 outputfile
&operator << (outputfile
&SaveFile
, const trapdata
&Data
) {
49 SaveFile
<< Data
.TrapID
<< Data
.VictimID
<< Data
.BodyParts
;
54 inputfile
&operator >> (inputfile
&SaveFile
, trapdata
&Data
) {
55 SaveFile
>> Data
.TrapID
>> Data
.VictimID
>> Data
.BodyParts
;
60 trap
*trapprototype::SpawnAndLoad (inputfile
&SaveFile
) const {
61 trap
*Trap
= Spawner();
67 void itemtrapbase::Load (inputfile
&SaveFile
) {
68 SaveFile
>> Active
>> Team
>> DiscoveredByTeam
;
72 void itemtrapbase::Save (outputfile
&SaveFile
) const {
73 SaveFile
<< Active
<< Team
<< DiscoveredByTeam
;
77 truth
itemtrapbase::CanBeSeenBy (ccharacter
*Viewer
) const {
78 int ViewerTeam
= Viewer
->GetTeam()->GetID();
79 return !Active
|| ViewerTeam
== Team
|| DiscoveredByTeam
.find(ViewerTeam
) != DiscoveredByTeam
.end();
83 void itemtrapbase::Search (ccharacter
*Char
, int Perception
) {
84 int ViewerTeam
= Char
->GetTeam()->GetID();
85 if (Active
&& ViewerTeam
!= Team
&& DiscoveredByTeam
.find(ViewerTeam
) == DiscoveredByTeam
.end() && !RAND_N(200 / Perception
)) {
86 DiscoveredByTeam
.insert(ViewerTeam
);
87 SendNewDrawAndMemorizedUpdateRequest();
88 if (Char
->IsPlayer()) {
89 game::AskForEscPress(CONST_S("Trap found!"));
90 ADD_MESSAGE("You find %s.", CHAR_NAME(INDEFINITE
));
96 void itemtrapbase::SetIsActive (truth What
) {
99 DiscoveredByTeam
.clear();
103 void itemtrapbase::FinalProcessForBone () {
104 if (Team
== PLAYER_TEAM
) Team
= MONSTER_TEAM
;
105 std::set
<int>::iterator i
= DiscoveredByTeam
.find(PLAYER_TEAM
);
106 if (i
!= DiscoveredByTeam
.end()) DiscoveredByTeam
.erase(i
);
110 void itemtrapbase::TeleportRandomly () {
112 DiscoveredByTeam
.clear();